mirror of
https://github.com/idanoo/GoScrobble
synced 2025-07-02 14:12:19 +00:00
0.2.0 - Mid migration
This commit is contained in:
parent
139e6a915e
commit
7e38fdbd7d
42393 changed files with 5358157 additions and 62 deletions
134
web/node_modules/terser-webpack-plugin/dist/Webpack4Cache.js
generated
vendored
Normal file
134
web/node_modules/terser-webpack-plugin/dist/Webpack4Cache.js
generated
vendored
Normal file
|
@ -0,0 +1,134 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _os = _interopRequireDefault(require("os"));
|
||||
|
||||
var _cacache = _interopRequireDefault(require("cacache"));
|
||||
|
||||
var _findCacheDir = _interopRequireDefault(require("find-cache-dir"));
|
||||
|
||||
var _serializeJavascript = _interopRequireDefault(require("serialize-javascript"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
class Webpack4Cache {
|
||||
constructor(compilation, options, weakCache) {
|
||||
this.cache = options.cache === true ? Webpack4Cache.getCacheDirectory() : options.cache;
|
||||
this.weakCache = weakCache;
|
||||
}
|
||||
|
||||
static getCacheDirectory() {
|
||||
return (0, _findCacheDir.default)({
|
||||
name: 'terser-webpack-plugin'
|
||||
}) || _os.default.tmpdir();
|
||||
}
|
||||
|
||||
async get(cacheData, {
|
||||
RawSource,
|
||||
ConcatSource,
|
||||
SourceMapSource
|
||||
}) {
|
||||
if (!this.cache) {
|
||||
// eslint-disable-next-line no-undefined
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const weakOutput = this.weakCache.get(cacheData.inputSource);
|
||||
|
||||
if (weakOutput) {
|
||||
return weakOutput;
|
||||
} // eslint-disable-next-line no-param-reassign
|
||||
|
||||
|
||||
cacheData.cacheIdent = cacheData.cacheIdent || (0, _serializeJavascript.default)(cacheData.cacheKeys);
|
||||
let cachedResult;
|
||||
|
||||
try {
|
||||
cachedResult = await _cacache.default.get(this.cache, cacheData.cacheIdent);
|
||||
} catch (ignoreError) {
|
||||
// eslint-disable-next-line no-undefined
|
||||
return undefined;
|
||||
}
|
||||
|
||||
cachedResult = JSON.parse(cachedResult.data);
|
||||
|
||||
if (cachedResult.target === 'comments') {
|
||||
return new ConcatSource(cachedResult.value);
|
||||
}
|
||||
|
||||
const {
|
||||
code,
|
||||
name,
|
||||
map,
|
||||
input,
|
||||
inputSourceMap,
|
||||
extractedComments,
|
||||
banner,
|
||||
shebang
|
||||
} = cachedResult;
|
||||
|
||||
if (map) {
|
||||
cachedResult.source = new SourceMapSource(code, name, map, input, inputSourceMap, true);
|
||||
} else {
|
||||
cachedResult.source = new RawSource(code);
|
||||
}
|
||||
|
||||
if (banner) {
|
||||
cachedResult.source = new ConcatSource(shebang ? `${shebang}\n` : '', `/*! ${banner} */\n`, cachedResult.source);
|
||||
}
|
||||
|
||||
if (extractedComments) {
|
||||
cachedResult.extractedCommentsSource = new RawSource(extractedComments);
|
||||
}
|
||||
|
||||
return cachedResult;
|
||||
}
|
||||
|
||||
async store(cacheData) {
|
||||
if (!this.cache) {
|
||||
// eslint-disable-next-line no-undefined
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (!this.weakCache.has(cacheData.inputSource)) {
|
||||
if (cacheData.target === 'comments') {
|
||||
this.weakCache.set(cacheData.inputSource, cacheData.output);
|
||||
} else {
|
||||
this.weakCache.set(cacheData.inputSource, cacheData);
|
||||
}
|
||||
}
|
||||
|
||||
let data;
|
||||
|
||||
if (cacheData.target === 'comments') {
|
||||
data = {
|
||||
target: cacheData.target,
|
||||
value: cacheData.output.source()
|
||||
};
|
||||
} else {
|
||||
data = {
|
||||
code: cacheData.code,
|
||||
name: cacheData.name,
|
||||
map: cacheData.map,
|
||||
input: cacheData.input,
|
||||
inputSourceMap: cacheData.inputSourceMap,
|
||||
banner: cacheData.banner,
|
||||
shebang: cacheData.shebang
|
||||
};
|
||||
|
||||
if (cacheData.extractedCommentsSource) {
|
||||
data.extractedComments = cacheData.extractedCommentsSource.source();
|
||||
data.commentsFilename = cacheData.commentsFilename;
|
||||
}
|
||||
}
|
||||
|
||||
return _cacache.default.put(this.cache, cacheData.cacheIdent, JSON.stringify(data));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exports.default = Webpack4Cache;
|
37
web/node_modules/terser-webpack-plugin/dist/Webpack5Cache.js
generated
vendored
Normal file
37
web/node_modules/terser-webpack-plugin/dist/Webpack5Cache.js
generated
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
class Cache {
|
||||
constructor(compilation) {
|
||||
this.cache = compilation.getCache('TerserWebpackPlugin');
|
||||
}
|
||||
|
||||
async get(cacheData) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
cacheData.eTag = cacheData.eTag || Array.isArray(cacheData.inputSource) ? cacheData.inputSource.map(item => this.cache.getLazyHashedEtag(item)).reduce((previousValue, currentValue) => this.cache.mergeEtags(previousValue, currentValue)) : this.cache.getLazyHashedEtag(cacheData.inputSource);
|
||||
return this.cache.getPromise(cacheData.name, cacheData.eTag);
|
||||
}
|
||||
|
||||
async store(cacheData) {
|
||||
let data;
|
||||
|
||||
if (cacheData.target === 'comments') {
|
||||
data = cacheData.output;
|
||||
} else {
|
||||
data = {
|
||||
source: cacheData.source,
|
||||
extractedCommentsSource: cacheData.extractedCommentsSource,
|
||||
commentsFilename: cacheData.commentsFilename
|
||||
};
|
||||
}
|
||||
|
||||
return this.cache.storePromise(cacheData.name, cacheData.eTag, data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exports.default = Cache;
|
5
web/node_modules/terser-webpack-plugin/dist/cjs.js
generated
vendored
Normal file
5
web/node_modules/terser-webpack-plugin/dist/cjs.js
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
"use strict";
|
||||
|
||||
const plugin = require('./index');
|
||||
|
||||
module.exports = plugin.default;
|
594
web/node_modules/terser-webpack-plugin/dist/index.js
generated
vendored
Normal file
594
web/node_modules/terser-webpack-plugin/dist/index.js
generated
vendored
Normal file
|
@ -0,0 +1,594 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _path = _interopRequireDefault(require("path"));
|
||||
|
||||
var _os = _interopRequireDefault(require("os"));
|
||||
|
||||
var _sourceMap = require("source-map");
|
||||
|
||||
var _webpack = _interopRequireWildcard(require("webpack"));
|
||||
|
||||
var _RequestShortener = _interopRequireDefault(require("webpack/lib/RequestShortener"));
|
||||
|
||||
var _schemaUtils = require("schema-utils");
|
||||
|
||||
var _serializeJavascript = _interopRequireDefault(require("serialize-javascript"));
|
||||
|
||||
var _package = _interopRequireDefault(require("terser/package.json"));
|
||||
|
||||
var _pLimit = _interopRequireDefault(require("p-limit"));
|
||||
|
||||
var _jestWorker = _interopRequireDefault(require("jest-worker"));
|
||||
|
||||
var _options = _interopRequireDefault(require("./options.json"));
|
||||
|
||||
var _minify = require("./minify");
|
||||
|
||||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// webpack 5 exposes the sources property to ensure the right version of webpack-sources is used
|
||||
const {
|
||||
SourceMapSource,
|
||||
RawSource,
|
||||
ConcatSource
|
||||
} = // eslint-disable-next-line global-require
|
||||
_webpack.default.sources || require('webpack-sources');
|
||||
|
||||
class TerserPlugin {
|
||||
constructor(options = {}) {
|
||||
(0, _schemaUtils.validate)(_options.default, options, {
|
||||
name: 'Terser Plugin',
|
||||
baseDataPath: 'options'
|
||||
});
|
||||
const {
|
||||
minify,
|
||||
terserOptions = {},
|
||||
test = /\.[cm]?js(\?.*)?$/i,
|
||||
extractComments = true,
|
||||
sourceMap,
|
||||
cache = true,
|
||||
cacheKeys = defaultCacheKeys => defaultCacheKeys,
|
||||
parallel = true,
|
||||
include,
|
||||
exclude
|
||||
} = options;
|
||||
this.options = {
|
||||
test,
|
||||
extractComments,
|
||||
sourceMap,
|
||||
cache,
|
||||
cacheKeys,
|
||||
parallel,
|
||||
include,
|
||||
exclude,
|
||||
minify,
|
||||
terserOptions
|
||||
};
|
||||
}
|
||||
|
||||
static isSourceMap(input) {
|
||||
// All required options for `new SourceMapConsumer(...options)`
|
||||
// https://github.com/mozilla/source-map#new-sourcemapconsumerrawsourcemap
|
||||
return Boolean(input && input.version && input.sources && Array.isArray(input.sources) && typeof input.mappings === 'string');
|
||||
}
|
||||
|
||||
static buildError(error, file, sourceMap, requestShortener) {
|
||||
if (error.line) {
|
||||
const original = sourceMap && sourceMap.originalPositionFor({
|
||||
line: error.line,
|
||||
column: error.col
|
||||
});
|
||||
|
||||
if (original && original.source && requestShortener) {
|
||||
return new Error(`${file} from Terser\n${error.message} [${requestShortener.shorten(original.source)}:${original.line},${original.column}][${file}:${error.line},${error.col}]${error.stack ? `\n${error.stack.split('\n').slice(1).join('\n')}` : ''}`);
|
||||
}
|
||||
|
||||
return new Error(`${file} from Terser\n${error.message} [${file}:${error.line},${error.col}]${error.stack ? `\n${error.stack.split('\n').slice(1).join('\n')}` : ''}`);
|
||||
}
|
||||
|
||||
if (error.stack) {
|
||||
return new Error(`${file} from Terser\n${error.stack}`);
|
||||
}
|
||||
|
||||
return new Error(`${file} from Terser\n${error.message}`);
|
||||
}
|
||||
|
||||
static isWebpack4() {
|
||||
return _webpack.version[0] === '4';
|
||||
}
|
||||
|
||||
static getAvailableNumberOfCores(parallel) {
|
||||
// In some cases cpus() returns undefined
|
||||
// https://github.com/nodejs/node/issues/19022
|
||||
const cpus = _os.default.cpus() || {
|
||||
length: 1
|
||||
};
|
||||
return parallel === true ? cpus.length - 1 : Math.min(Number(parallel) || 0, cpus.length - 1);
|
||||
} // eslint-disable-next-line consistent-return
|
||||
|
||||
|
||||
static getAsset(compilation, name) {
|
||||
// New API
|
||||
if (compilation.getAsset) {
|
||||
return compilation.getAsset(name);
|
||||
}
|
||||
/* istanbul ignore next */
|
||||
|
||||
|
||||
if (compilation.assets[name]) {
|
||||
return {
|
||||
name,
|
||||
source: compilation.assets[name],
|
||||
info: {}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
static emitAsset(compilation, name, source, assetInfo) {
|
||||
// New API
|
||||
if (compilation.emitAsset) {
|
||||
compilation.emitAsset(name, source, assetInfo);
|
||||
} // eslint-disable-next-line no-param-reassign
|
||||
|
||||
|
||||
compilation.assets[name] = source;
|
||||
}
|
||||
|
||||
static updateAsset(compilation, name, newSource, assetInfo) {
|
||||
// New API
|
||||
if (compilation.updateAsset) {
|
||||
compilation.updateAsset(name, newSource, assetInfo);
|
||||
} // eslint-disable-next-line no-param-reassign
|
||||
|
||||
|
||||
compilation.assets[name] = newSource;
|
||||
}
|
||||
|
||||
async optimize(compiler, compilation, assets, CacheEngine, weakCache) {
|
||||
let assetNames;
|
||||
|
||||
if (TerserPlugin.isWebpack4()) {
|
||||
assetNames = [].concat(Array.from(compilation.additionalChunkAssets || [])).concat( // In webpack@4 it is `chunks`
|
||||
Array.from(assets).reduce((acc, chunk) => acc.concat(Array.from(chunk.files || [])), [])).concat(Object.keys(compilation.assets)).filter((assetName, index, existingAssets) => existingAssets.indexOf(assetName) === index).filter(assetName => _webpack.ModuleFilenameHelpers.matchObject.bind( // eslint-disable-next-line no-undefined
|
||||
undefined, this.options)(assetName));
|
||||
} else {
|
||||
assetNames = Object.keys(assets).filter(assetName => _webpack.ModuleFilenameHelpers.matchObject.bind( // eslint-disable-next-line no-undefined
|
||||
undefined, this.options)(assetName));
|
||||
}
|
||||
|
||||
if (assetNames.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const availableNumberOfCores = TerserPlugin.getAvailableNumberOfCores(this.options.parallel);
|
||||
let concurrency = Infinity;
|
||||
let worker;
|
||||
|
||||
if (availableNumberOfCores > 0) {
|
||||
// Do not create unnecessary workers when the number of files is less than the available cores, it saves memory
|
||||
const numWorkers = Math.min(assetNames.length, availableNumberOfCores);
|
||||
concurrency = numWorkers;
|
||||
worker = new _jestWorker.default(require.resolve('./minify'), {
|
||||
numWorkers
|
||||
}); // https://github.com/facebook/jest/issues/8872#issuecomment-524822081
|
||||
|
||||
const workerStdout = worker.getStdout();
|
||||
|
||||
if (workerStdout) {
|
||||
workerStdout.on('data', chunk => {
|
||||
return process.stdout.write(chunk);
|
||||
});
|
||||
}
|
||||
|
||||
const workerStderr = worker.getStderr();
|
||||
|
||||
if (workerStderr) {
|
||||
workerStderr.on('data', chunk => {
|
||||
return process.stderr.write(chunk);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const limit = (0, _pLimit.default)(concurrency);
|
||||
const cache = new CacheEngine(compilation, {
|
||||
cache: this.options.cache
|
||||
}, weakCache);
|
||||
const allExtractedComments = new Map();
|
||||
const scheduledTasks = [];
|
||||
|
||||
for (const name of assetNames) {
|
||||
scheduledTasks.push(limit(async () => {
|
||||
const {
|
||||
info,
|
||||
source: inputSource
|
||||
} = TerserPlugin.getAsset(compilation, name); // Skip double minimize assets from child compilation
|
||||
|
||||
if (info.minimized) {
|
||||
return;
|
||||
}
|
||||
|
||||
let input;
|
||||
let inputSourceMap; // TODO refactor after drop webpack@4, webpack@5 always has `sourceAndMap` on sources
|
||||
|
||||
if (this.options.sourceMap && inputSource.sourceAndMap) {
|
||||
const {
|
||||
source,
|
||||
map
|
||||
} = inputSource.sourceAndMap();
|
||||
input = source;
|
||||
|
||||
if (map) {
|
||||
if (TerserPlugin.isSourceMap(map)) {
|
||||
inputSourceMap = map;
|
||||
} else {
|
||||
inputSourceMap = map;
|
||||
compilation.warnings.push(new Error(`${name} contains invalid source map`));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
input = inputSource.source();
|
||||
inputSourceMap = null;
|
||||
}
|
||||
|
||||
if (Buffer.isBuffer(input)) {
|
||||
input = input.toString();
|
||||
}
|
||||
|
||||
const cacheData = {
|
||||
name,
|
||||
inputSource
|
||||
};
|
||||
|
||||
if (TerserPlugin.isWebpack4()) {
|
||||
if (this.options.cache) {
|
||||
const {
|
||||
outputOptions: {
|
||||
hashSalt,
|
||||
hashDigest,
|
||||
hashDigestLength,
|
||||
hashFunction
|
||||
}
|
||||
} = compilation;
|
||||
|
||||
const hash = _webpack.util.createHash(hashFunction);
|
||||
|
||||
if (hashSalt) {
|
||||
hash.update(hashSalt);
|
||||
}
|
||||
|
||||
hash.update(input);
|
||||
const digest = hash.digest(hashDigest);
|
||||
cacheData.input = input;
|
||||
cacheData.inputSourceMap = inputSourceMap;
|
||||
cacheData.cacheKeys = this.options.cacheKeys({
|
||||
terser: _package.default.version,
|
||||
// eslint-disable-next-line global-require
|
||||
'terser-webpack-plugin': require('../package.json').version,
|
||||
'terser-webpack-plugin-options': this.options,
|
||||
name,
|
||||
contentHash: digest.substr(0, hashDigestLength)
|
||||
}, name);
|
||||
}
|
||||
}
|
||||
|
||||
let output = await cache.get(cacheData, {
|
||||
RawSource,
|
||||
ConcatSource,
|
||||
SourceMapSource
|
||||
});
|
||||
|
||||
if (!output) {
|
||||
const minimizerOptions = {
|
||||
name,
|
||||
input,
|
||||
inputSourceMap,
|
||||
minify: this.options.minify,
|
||||
minimizerOptions: this.options.terserOptions,
|
||||
extractComments: this.options.extractComments
|
||||
};
|
||||
|
||||
if (/\.mjs(\?.*)?$/i.test(name)) {
|
||||
this.options.terserOptions.module = true;
|
||||
}
|
||||
|
||||
try {
|
||||
output = await (worker ? worker.transform((0, _serializeJavascript.default)(minimizerOptions)) : (0, _minify.minify)(minimizerOptions));
|
||||
} catch (error) {
|
||||
compilation.errors.push(TerserPlugin.buildError(error, name, inputSourceMap && TerserPlugin.isSourceMap(inputSourceMap) ? new _sourceMap.SourceMapConsumer(inputSourceMap) : null, new _RequestShortener.default(compiler.context)));
|
||||
return;
|
||||
}
|
||||
|
||||
let shebang;
|
||||
|
||||
if (this.options.extractComments.banner !== false && output.extractedComments && output.extractedComments.length > 0 && output.code.startsWith('#!')) {
|
||||
const firstNewlinePosition = output.code.indexOf('\n');
|
||||
shebang = output.code.substring(0, firstNewlinePosition);
|
||||
output.code = output.code.substring(firstNewlinePosition + 1);
|
||||
}
|
||||
|
||||
if (output.map) {
|
||||
output.source = new SourceMapSource(output.code, name, output.map, input, inputSourceMap, true);
|
||||
} else {
|
||||
output.source = new RawSource(output.code);
|
||||
}
|
||||
|
||||
let commentsFilename;
|
||||
|
||||
if (output.extractedComments && output.extractedComments.length > 0) {
|
||||
commentsFilename = this.options.extractComments.filename || '[file].LICENSE.txt[query]';
|
||||
let query = '';
|
||||
let filename = name;
|
||||
const querySplit = filename.indexOf('?');
|
||||
|
||||
if (querySplit >= 0) {
|
||||
query = filename.substr(querySplit);
|
||||
filename = filename.substr(0, querySplit);
|
||||
}
|
||||
|
||||
const lastSlashIndex = filename.lastIndexOf('/');
|
||||
const basename = lastSlashIndex === -1 ? filename : filename.substr(lastSlashIndex + 1);
|
||||
const data = {
|
||||
filename,
|
||||
basename,
|
||||
query
|
||||
};
|
||||
commentsFilename = compilation.getPath(commentsFilename, data);
|
||||
output.commentsFilename = commentsFilename;
|
||||
let banner; // Add a banner to the original file
|
||||
|
||||
if (this.options.extractComments.banner !== false) {
|
||||
banner = this.options.extractComments.banner || `For license information please see ${_path.default.relative(_path.default.dirname(name), commentsFilename).replace(/\\/g, '/')}`;
|
||||
|
||||
if (typeof banner === 'function') {
|
||||
banner = banner(commentsFilename);
|
||||
}
|
||||
|
||||
if (banner) {
|
||||
output.source = new ConcatSource(shebang ? `${shebang}\n` : '', `/*! ${banner} */\n`, output.source);
|
||||
output.banner = banner;
|
||||
output.shebang = shebang;
|
||||
}
|
||||
}
|
||||
|
||||
const extractedCommentsString = output.extractedComments.sort().join('\n\n');
|
||||
output.extractedCommentsSource = new RawSource(`${extractedCommentsString}\n`);
|
||||
}
|
||||
|
||||
await cache.store({ ...output,
|
||||
...cacheData
|
||||
});
|
||||
} // TODO `...` required only for webpack@4
|
||||
|
||||
|
||||
const newInfo = { ...info,
|
||||
minimized: true
|
||||
};
|
||||
const {
|
||||
source,
|
||||
extractedCommentsSource
|
||||
} = output; // Write extracted comments to commentsFilename
|
||||
|
||||
if (extractedCommentsSource) {
|
||||
const {
|
||||
commentsFilename
|
||||
} = output; // TODO `...` required only for webpack@4
|
||||
|
||||
newInfo.related = {
|
||||
license: commentsFilename,
|
||||
...info.related
|
||||
};
|
||||
allExtractedComments.set(name, {
|
||||
extractedCommentsSource,
|
||||
commentsFilename
|
||||
});
|
||||
}
|
||||
|
||||
TerserPlugin.updateAsset(compilation, name, source, newInfo);
|
||||
}));
|
||||
}
|
||||
|
||||
await Promise.all(scheduledTasks);
|
||||
|
||||
if (worker) {
|
||||
await worker.end();
|
||||
}
|
||||
|
||||
await Array.from(allExtractedComments).sort().reduce(async (previousPromise, [from, value]) => {
|
||||
const previous = await previousPromise;
|
||||
const {
|
||||
commentsFilename,
|
||||
extractedCommentsSource
|
||||
} = value;
|
||||
|
||||
if (previous && previous.commentsFilename === commentsFilename) {
|
||||
const {
|
||||
from: previousFrom,
|
||||
source: prevSource
|
||||
} = previous;
|
||||
const mergedName = `${previousFrom}|${from}`;
|
||||
const cacheData = {
|
||||
target: 'comments'
|
||||
};
|
||||
|
||||
if (TerserPlugin.isWebpack4()) {
|
||||
const {
|
||||
outputOptions: {
|
||||
hashSalt,
|
||||
hashDigest,
|
||||
hashDigestLength,
|
||||
hashFunction
|
||||
}
|
||||
} = compilation;
|
||||
|
||||
const previousHash = _webpack.util.createHash(hashFunction);
|
||||
|
||||
const hash = _webpack.util.createHash(hashFunction);
|
||||
|
||||
if (hashSalt) {
|
||||
previousHash.update(hashSalt);
|
||||
hash.update(hashSalt);
|
||||
}
|
||||
|
||||
previousHash.update(prevSource.source());
|
||||
hash.update(extractedCommentsSource.source());
|
||||
const previousDigest = previousHash.digest(hashDigest);
|
||||
const digest = hash.digest(hashDigest);
|
||||
cacheData.cacheKeys = {
|
||||
mergedName,
|
||||
previousContentHash: previousDigest.substr(0, hashDigestLength),
|
||||
contentHash: digest.substr(0, hashDigestLength)
|
||||
};
|
||||
cacheData.inputSource = extractedCommentsSource;
|
||||
} else {
|
||||
const mergedInputSource = [prevSource, extractedCommentsSource];
|
||||
cacheData.name = `${commentsFilename}|${mergedName}`;
|
||||
cacheData.inputSource = mergedInputSource;
|
||||
}
|
||||
|
||||
let output = await cache.get(cacheData, {
|
||||
ConcatSource
|
||||
});
|
||||
|
||||
if (!output) {
|
||||
output = new ConcatSource(Array.from(new Set([...prevSource.source().split('\n\n'), ...extractedCommentsSource.source().split('\n\n')])).join('\n\n'));
|
||||
await cache.store({ ...cacheData,
|
||||
output
|
||||
});
|
||||
}
|
||||
|
||||
TerserPlugin.updateAsset(compilation, commentsFilename, output);
|
||||
return {
|
||||
commentsFilename,
|
||||
from: mergedName,
|
||||
source: output
|
||||
};
|
||||
}
|
||||
|
||||
const existingAsset = TerserPlugin.getAsset(compilation, commentsFilename);
|
||||
|
||||
if (existingAsset) {
|
||||
return {
|
||||
commentsFilename,
|
||||
from: commentsFilename,
|
||||
source: existingAsset.source
|
||||
};
|
||||
}
|
||||
|
||||
TerserPlugin.emitAsset(compilation, commentsFilename, extractedCommentsSource);
|
||||
return {
|
||||
commentsFilename,
|
||||
from,
|
||||
source: extractedCommentsSource
|
||||
};
|
||||
}, Promise.resolve());
|
||||
}
|
||||
|
||||
static getEcmaVersion(environment) {
|
||||
// ES 6th
|
||||
if (environment.arrowFunction || environment.const || environment.destructuring || environment.forOf || environment.module) {
|
||||
return 2015;
|
||||
} // ES 11th
|
||||
|
||||
|
||||
if (environment.bigIntLiteral || environment.dynamicImport) {
|
||||
return 2020;
|
||||
}
|
||||
|
||||
return 5;
|
||||
}
|
||||
|
||||
apply(compiler) {
|
||||
const {
|
||||
devtool,
|
||||
output,
|
||||
plugins
|
||||
} = compiler.options;
|
||||
this.options.sourceMap = typeof this.options.sourceMap === 'undefined' ? devtool && !devtool.includes('eval') && !devtool.includes('cheap') && (devtool.includes('source-map') || // Todo remove when `webpack@4` support will be dropped
|
||||
devtool.includes('sourcemap')) || plugins && plugins.some(plugin => plugin instanceof _webpack.SourceMapDevToolPlugin && plugin.options && plugin.options.columns) : Boolean(this.options.sourceMap);
|
||||
|
||||
if (typeof this.options.terserOptions.module === 'undefined' && typeof output.module !== 'undefined') {
|
||||
this.options.terserOptions.module = output.module;
|
||||
}
|
||||
|
||||
if (typeof this.options.terserOptions.ecma === 'undefined') {
|
||||
this.options.terserOptions.ecma = TerserPlugin.getEcmaVersion(output.environment || {});
|
||||
}
|
||||
|
||||
const pluginName = this.constructor.name;
|
||||
const weakCache = TerserPlugin.isWebpack4() && (this.options.cache === true || typeof this.options.cache === 'string') ? new WeakMap() : // eslint-disable-next-line no-undefined
|
||||
undefined;
|
||||
compiler.hooks.compilation.tap(pluginName, compilation => {
|
||||
if (this.options.sourceMap) {
|
||||
compilation.hooks.buildModule.tap(pluginName, moduleArg => {
|
||||
// to get detailed location info about errors
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
moduleArg.useSourceMap = true;
|
||||
});
|
||||
}
|
||||
|
||||
if (TerserPlugin.isWebpack4()) {
|
||||
// eslint-disable-next-line global-require
|
||||
const CacheEngine = require('./Webpack4Cache').default;
|
||||
|
||||
const {
|
||||
mainTemplate,
|
||||
chunkTemplate
|
||||
} = compilation;
|
||||
const data = (0, _serializeJavascript.default)({
|
||||
terser: _package.default.version,
|
||||
terserOptions: this.options.terserOptions
|
||||
}); // Regenerate `contenthash` for minified assets
|
||||
|
||||
for (const template of [mainTemplate, chunkTemplate]) {
|
||||
template.hooks.hashForChunk.tap(pluginName, hash => {
|
||||
hash.update('TerserPlugin');
|
||||
hash.update(data);
|
||||
});
|
||||
}
|
||||
|
||||
compilation.hooks.optimizeChunkAssets.tapPromise(pluginName, assets => this.optimize(compiler, compilation, assets, CacheEngine, weakCache));
|
||||
} else {
|
||||
// eslint-disable-next-line global-require
|
||||
const CacheEngine = require('./Webpack5Cache').default; // eslint-disable-next-line global-require
|
||||
|
||||
|
||||
const Compilation = require('webpack/lib/Compilation');
|
||||
|
||||
const hooks = _webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(compilation);
|
||||
|
||||
const data = (0, _serializeJavascript.default)({
|
||||
terser: _package.default.version,
|
||||
terserOptions: this.options.terserOptions
|
||||
});
|
||||
hooks.chunkHash.tap(pluginName, (chunk, hash) => {
|
||||
hash.update('TerserPlugin');
|
||||
hash.update(data);
|
||||
});
|
||||
compilation.hooks.processAssets.tapPromise({
|
||||
name: pluginName,
|
||||
stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE
|
||||
}, assets => this.optimize(compiler, compilation, assets, CacheEngine));
|
||||
compilation.hooks.statsPrinter.tap(pluginName, stats => {
|
||||
stats.hooks.print.for('asset.info.minimized').tap('terser-webpack-plugin', (minimized, {
|
||||
green,
|
||||
formatFlag
|
||||
}) => // eslint-disable-next-line no-undefined
|
||||
minimized ? green(formatFlag('minimized')) : undefined);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var _default = TerserPlugin;
|
||||
exports.default = _default;
|
179
web/node_modules/terser-webpack-plugin/dist/minify.js
generated
vendored
Normal file
179
web/node_modules/terser-webpack-plugin/dist/minify.js
generated
vendored
Normal file
|
@ -0,0 +1,179 @@
|
|||
"use strict";
|
||||
|
||||
const {
|
||||
minify: terserMinify
|
||||
} = require('terser');
|
||||
|
||||
const buildTerserOptions = ({
|
||||
ecma,
|
||||
parse = {},
|
||||
compress = {},
|
||||
mangle,
|
||||
module,
|
||||
output,
|
||||
toplevel,
|
||||
nameCache,
|
||||
ie8,
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
keep_classnames,
|
||||
keep_fnames,
|
||||
|
||||
/* eslint-enable camelcase */
|
||||
safari10
|
||||
} = {}) => ({
|
||||
parse: { ...parse
|
||||
},
|
||||
compress: typeof compress === 'boolean' ? compress : { ...compress
|
||||
},
|
||||
// eslint-disable-next-line no-nested-ternary
|
||||
mangle: mangle == null ? true : typeof mangle === 'boolean' ? mangle : { ...mangle
|
||||
},
|
||||
output: {
|
||||
beautify: false,
|
||||
...output
|
||||
},
|
||||
// Ignoring sourceMap from options
|
||||
sourceMap: null,
|
||||
ecma,
|
||||
keep_classnames,
|
||||
keep_fnames,
|
||||
ie8,
|
||||
module,
|
||||
nameCache,
|
||||
safari10,
|
||||
toplevel
|
||||
});
|
||||
|
||||
function isObject(value) {
|
||||
const type = typeof value;
|
||||
return value != null && (type === 'object' || type === 'function');
|
||||
}
|
||||
|
||||
const buildComments = (extractComments, terserOptions, extractedComments) => {
|
||||
const condition = {};
|
||||
const {
|
||||
comments
|
||||
} = terserOptions.output;
|
||||
condition.preserve = typeof comments !== 'undefined' ? comments : false;
|
||||
|
||||
if (typeof extractComments === 'boolean' && extractComments) {
|
||||
condition.extract = 'some';
|
||||
} else if (typeof extractComments === 'string' || extractComments instanceof RegExp) {
|
||||
condition.extract = extractComments;
|
||||
} else if (typeof extractComments === 'function') {
|
||||
condition.extract = extractComments;
|
||||
} else if (isObject(extractComments)) {
|
||||
condition.extract = typeof extractComments.condition === 'boolean' && extractComments.condition ? 'some' : typeof extractComments.condition !== 'undefined' ? extractComments.condition : 'some';
|
||||
} else {
|
||||
// No extract
|
||||
// Preserve using "commentsOpts" or "some"
|
||||
condition.preserve = typeof comments !== 'undefined' ? comments : 'some';
|
||||
condition.extract = false;
|
||||
} // Ensure that both conditions are functions
|
||||
|
||||
|
||||
['preserve', 'extract'].forEach(key => {
|
||||
let regexStr;
|
||||
let regex;
|
||||
|
||||
switch (typeof condition[key]) {
|
||||
case 'boolean':
|
||||
condition[key] = condition[key] ? () => true : () => false;
|
||||
break;
|
||||
|
||||
case 'function':
|
||||
break;
|
||||
|
||||
case 'string':
|
||||
if (condition[key] === 'all') {
|
||||
condition[key] = () => true;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (condition[key] === 'some') {
|
||||
condition[key] = (astNode, comment) => {
|
||||
return (comment.type === 'comment2' || comment.type === 'comment1') && /@preserve|@lic|@cc_on|^\**!/i.test(comment.value);
|
||||
};
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
regexStr = condition[key];
|
||||
|
||||
condition[key] = (astNode, comment) => {
|
||||
return new RegExp(regexStr).test(comment.value);
|
||||
};
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
regex = condition[key];
|
||||
|
||||
condition[key] = (astNode, comment) => regex.test(comment.value);
|
||||
|
||||
}
|
||||
}); // Redefine the comments function to extract and preserve
|
||||
// comments according to the two conditions
|
||||
|
||||
return (astNode, comment) => {
|
||||
if (condition.extract(astNode, comment)) {
|
||||
const commentText = comment.type === 'comment2' ? `/*${comment.value}*/` : `//${comment.value}`; // Don't include duplicate comments
|
||||
|
||||
if (!extractedComments.includes(commentText)) {
|
||||
extractedComments.push(commentText);
|
||||
}
|
||||
}
|
||||
|
||||
return condition.preserve(astNode, comment);
|
||||
};
|
||||
};
|
||||
|
||||
async function minify(options) {
|
||||
const {
|
||||
name,
|
||||
input,
|
||||
inputSourceMap,
|
||||
minify: minifyFn,
|
||||
minimizerOptions
|
||||
} = options;
|
||||
|
||||
if (minifyFn) {
|
||||
return minifyFn({
|
||||
[name]: input
|
||||
}, inputSourceMap, minimizerOptions);
|
||||
} // Copy terser options
|
||||
|
||||
|
||||
const terserOptions = buildTerserOptions(minimizerOptions); // Let terser generate a SourceMap
|
||||
|
||||
if (inputSourceMap) {
|
||||
terserOptions.sourceMap = {
|
||||
asObject: true
|
||||
};
|
||||
}
|
||||
|
||||
const extractedComments = [];
|
||||
const {
|
||||
extractComments
|
||||
} = options;
|
||||
terserOptions.output.comments = buildComments(extractComments, terserOptions, extractedComments);
|
||||
const result = await terserMinify({
|
||||
[name]: input
|
||||
}, terserOptions);
|
||||
return { ...result,
|
||||
extractedComments
|
||||
};
|
||||
}
|
||||
|
||||
function transform(options) {
|
||||
// 'use strict' => this === undefined (Clean Scope)
|
||||
// Safer for possible security issues, albeit not critical at all here
|
||||
// eslint-disable-next-line no-new-func, no-param-reassign
|
||||
options = new Function('exports', 'require', 'module', '__filename', '__dirname', `'use strict'\nreturn ${options}`)(exports, require, module, __filename, __dirname);
|
||||
return minify(options);
|
||||
}
|
||||
|
||||
module.exports.minify = minify;
|
||||
module.exports.transform = transform;
|
166
web/node_modules/terser-webpack-plugin/dist/options.json
generated
vendored
Normal file
166
web/node_modules/terser-webpack-plugin/dist/options.json
generated
vendored
Normal file
|
@ -0,0 +1,166 @@
|
|||
{
|
||||
"definitions": {
|
||||
"Rule": {
|
||||
"description": "Filtering rule as regex or string.",
|
||||
"anyOf": [
|
||||
{
|
||||
"instanceof": "RegExp",
|
||||
"tsType": "RegExp"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"minLength": 1
|
||||
}
|
||||
]
|
||||
},
|
||||
"Rules": {
|
||||
"description": "Filtering rules.",
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "array",
|
||||
"items": {
|
||||
"description": "A rule condition.",
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/definitions/Rule"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/Rule"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"title": "TerserPluginOptions",
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"test": {
|
||||
"description": "Include all modules that pass test assertion.",
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/definitions/Rules"
|
||||
}
|
||||
]
|
||||
},
|
||||
"include": {
|
||||
"description": "Include all modules matching any of these conditions.",
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/definitions/Rules"
|
||||
}
|
||||
]
|
||||
},
|
||||
"exclude": {
|
||||
"description": "Exclude all modules matching any of these conditions.",
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/definitions/Rules"
|
||||
}
|
||||
]
|
||||
},
|
||||
"cache": {
|
||||
"description": "Enable file caching. Ignored in webpack 5, for webpack 5 please use https://webpack.js.org/configuration/other-options/#cache.",
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "boolean"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"cacheKeys": {
|
||||
"description": "Allows you to override default cache keys. Ignored in webpack 5, for webpack 5 please use https://webpack.js.org/configuration/other-options/#cache.",
|
||||
"instanceof": "Function"
|
||||
},
|
||||
"parallel": {
|
||||
"description": "Use multi-process parallel running to improve the build speed.",
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "boolean"
|
||||
},
|
||||
{
|
||||
"type": "integer"
|
||||
}
|
||||
]
|
||||
},
|
||||
"sourceMap": {
|
||||
"description": "Enables/Disables generation of source maps.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"minify": {
|
||||
"description": "Allows you to override default minify function.",
|
||||
"instanceof": "Function"
|
||||
},
|
||||
"terserOptions": {
|
||||
"description": "Options for `terser`.",
|
||||
"additionalProperties": true,
|
||||
"type": "object"
|
||||
},
|
||||
"extractComments": {
|
||||
"description": "Whether comments shall be extracted to a separate file.",
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "boolean"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"instanceof": "RegExp"
|
||||
},
|
||||
{
|
||||
"instanceof": "Function"
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"condition": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "boolean"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"instanceof": "RegExp"
|
||||
},
|
||||
{
|
||||
"instanceof": "Function"
|
||||
}
|
||||
]
|
||||
},
|
||||
"filename": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"instanceof": "Function"
|
||||
}
|
||||
]
|
||||
},
|
||||
"banner": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "boolean"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"instanceof": "Function"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue