generated from dellevin/template
1
This commit is contained in:
14
node_modules/webpack-chain/src/Chainable.js
generated
vendored
Normal file
14
node_modules/webpack-chain/src/Chainable.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
module.exports = class {
|
||||
constructor(parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
batch(handler) {
|
||||
handler(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
end() {
|
||||
return this.parent;
|
||||
}
|
||||
};
|
||||
151
node_modules/webpack-chain/src/ChainedMap.js
generated
vendored
Normal file
151
node_modules/webpack-chain/src/ChainedMap.js
generated
vendored
Normal file
@@ -0,0 +1,151 @@
|
||||
const merge = require('deepmerge');
|
||||
const Chainable = require('./Chainable');
|
||||
|
||||
module.exports = class extends Chainable {
|
||||
constructor(parent) {
|
||||
super(parent);
|
||||
this.store = new Map();
|
||||
}
|
||||
|
||||
extend(methods) {
|
||||
this.shorthands = methods;
|
||||
methods.forEach((method) => {
|
||||
this[method] = (value) => this.set(method, value);
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.store.clear();
|
||||
return this;
|
||||
}
|
||||
|
||||
delete(key) {
|
||||
this.store.delete(key);
|
||||
return this;
|
||||
}
|
||||
|
||||
order() {
|
||||
const entries = [...this.store].reduce((acc, [key, value]) => {
|
||||
acc[key] = value;
|
||||
return acc;
|
||||
}, {});
|
||||
const names = Object.keys(entries);
|
||||
const order = [...names];
|
||||
|
||||
names.forEach((name) => {
|
||||
if (!entries[name]) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { __before, __after } = entries[name];
|
||||
|
||||
if (__before && order.includes(__before)) {
|
||||
order.splice(order.indexOf(name), 1);
|
||||
order.splice(order.indexOf(__before), 0, name);
|
||||
} else if (__after && order.includes(__after)) {
|
||||
order.splice(order.indexOf(name), 1);
|
||||
order.splice(order.indexOf(__after) + 1, 0, name);
|
||||
}
|
||||
});
|
||||
|
||||
return { entries, order };
|
||||
}
|
||||
|
||||
entries() {
|
||||
const { entries, order } = this.order();
|
||||
|
||||
if (order.length) {
|
||||
return entries;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
values() {
|
||||
const { entries, order } = this.order();
|
||||
|
||||
return order.map((name) => entries[name]);
|
||||
}
|
||||
|
||||
get(key) {
|
||||
return this.store.get(key);
|
||||
}
|
||||
|
||||
getOrCompute(key, fn) {
|
||||
if (!this.has(key)) {
|
||||
this.set(key, fn());
|
||||
}
|
||||
return this.get(key);
|
||||
}
|
||||
|
||||
has(key) {
|
||||
return this.store.has(key);
|
||||
}
|
||||
|
||||
set(key, value) {
|
||||
this.store.set(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
merge(obj, omit = []) {
|
||||
Object.keys(obj).forEach((key) => {
|
||||
if (omit.includes(key)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const value = obj[key];
|
||||
|
||||
if (
|
||||
(!Array.isArray(value) && typeof value !== 'object') ||
|
||||
value === null ||
|
||||
!this.has(key)
|
||||
) {
|
||||
this.set(key, value);
|
||||
} else {
|
||||
this.set(key, merge(this.get(key), value));
|
||||
}
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
clean(obj) {
|
||||
return Object.keys(obj).reduce((acc, key) => {
|
||||
const value = obj[key];
|
||||
|
||||
if (value === undefined) {
|
||||
return acc;
|
||||
}
|
||||
|
||||
if (Array.isArray(value) && !value.length) {
|
||||
return acc;
|
||||
}
|
||||
|
||||
if (
|
||||
Object.prototype.toString.call(value) === '[object Object]' &&
|
||||
!Object.keys(value).length
|
||||
) {
|
||||
return acc;
|
||||
}
|
||||
|
||||
acc[key] = value;
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
|
||||
when(
|
||||
condition,
|
||||
whenTruthy = Function.prototype,
|
||||
whenFalsy = Function.prototype,
|
||||
) {
|
||||
if (condition) {
|
||||
whenTruthy(this);
|
||||
} else {
|
||||
whenFalsy(this);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
};
|
||||
55
node_modules/webpack-chain/src/ChainedSet.js
generated
vendored
Normal file
55
node_modules/webpack-chain/src/ChainedSet.js
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
const Chainable = require('./Chainable');
|
||||
|
||||
module.exports = class extends Chainable {
|
||||
constructor(parent) {
|
||||
super(parent);
|
||||
this.store = new Set();
|
||||
}
|
||||
|
||||
add(value) {
|
||||
this.store.add(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
prepend(value) {
|
||||
this.store = new Set([value, ...this.store]);
|
||||
return this;
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.store.clear();
|
||||
return this;
|
||||
}
|
||||
|
||||
delete(value) {
|
||||
this.store.delete(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
values() {
|
||||
return [...this.store];
|
||||
}
|
||||
|
||||
has(value) {
|
||||
return this.store.has(value);
|
||||
}
|
||||
|
||||
merge(arr) {
|
||||
this.store = new Set([...this.store, ...arr]);
|
||||
return this;
|
||||
}
|
||||
|
||||
when(
|
||||
condition,
|
||||
whenTruthy = Function.prototype,
|
||||
whenFalsy = Function.prototype,
|
||||
) {
|
||||
if (condition) {
|
||||
whenTruthy(this);
|
||||
} else {
|
||||
whenFalsy(this);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
};
|
||||
176
node_modules/webpack-chain/src/Config.js
generated
vendored
Normal file
176
node_modules/webpack-chain/src/Config.js
generated
vendored
Normal file
@@ -0,0 +1,176 @@
|
||||
const ChainedMap = require('./ChainedMap');
|
||||
const ChainedSet = require('./ChainedSet');
|
||||
const Resolve = require('./Resolve');
|
||||
const ResolveLoader = require('./ResolveLoader');
|
||||
const Output = require('./Output');
|
||||
const DevServer = require('./DevServer');
|
||||
const Plugin = require('./Plugin');
|
||||
const Module = require('./Module');
|
||||
const Optimization = require('./Optimization');
|
||||
const Performance = require('./Performance');
|
||||
|
||||
module.exports = class extends ChainedMap {
|
||||
constructor() {
|
||||
super();
|
||||
this.devServer = new DevServer(this);
|
||||
this.entryPoints = new ChainedMap(this);
|
||||
this.module = new Module(this);
|
||||
this.node = new ChainedMap(this);
|
||||
this.optimization = new Optimization(this);
|
||||
this.output = new Output(this);
|
||||
this.performance = new Performance(this);
|
||||
this.plugins = new ChainedMap(this);
|
||||
this.resolve = new Resolve(this);
|
||||
this.resolveLoader = new ResolveLoader(this);
|
||||
this.extend([
|
||||
'amd',
|
||||
'bail',
|
||||
'cache',
|
||||
'context',
|
||||
'devtool',
|
||||
'externals',
|
||||
'loader',
|
||||
'mode',
|
||||
'name',
|
||||
'parallelism',
|
||||
'profile',
|
||||
'recordsInputPath',
|
||||
'recordsPath',
|
||||
'recordsOutputPath',
|
||||
'stats',
|
||||
'target',
|
||||
'watch',
|
||||
'watchOptions',
|
||||
]);
|
||||
}
|
||||
|
||||
static toString(config, { verbose = false, configPrefix = 'config' } = {}) {
|
||||
// eslint-disable-next-line global-require
|
||||
const { stringify } = require('javascript-stringify');
|
||||
|
||||
return stringify(
|
||||
config,
|
||||
(value, indent, stringify) => {
|
||||
// improve plugin output
|
||||
if (value && value.__pluginName) {
|
||||
const prefix = `/* ${configPrefix}.${value.__pluginType}('${value.__pluginName}') */\n`;
|
||||
const constructorExpression = value.__pluginPath
|
||||
? // The path is stringified to ensure special characters are escaped
|
||||
// (such as the backslashes in Windows-style paths).
|
||||
`(require(${stringify(value.__pluginPath)}))`
|
||||
: value.__pluginConstructorName;
|
||||
|
||||
if (constructorExpression) {
|
||||
// get correct indentation for args by stringifying the args array and
|
||||
// discarding the square brackets.
|
||||
const args = stringify(value.__pluginArgs).slice(1, -1);
|
||||
return `${prefix}new ${constructorExpression}(${args})`;
|
||||
}
|
||||
return (
|
||||
prefix +
|
||||
stringify(
|
||||
value.__pluginArgs && value.__pluginArgs.length
|
||||
? { args: value.__pluginArgs }
|
||||
: {},
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// improve rule/use output
|
||||
if (value && value.__ruleNames) {
|
||||
const ruleTypes = value.__ruleTypes;
|
||||
const prefix = `/* ${configPrefix}.module${value.__ruleNames
|
||||
.map(
|
||||
(r, index) => `.${ruleTypes ? ruleTypes[index] : 'rule'}('${r}')`,
|
||||
)
|
||||
.join('')}${
|
||||
value.__useName ? `.use('${value.__useName}')` : ``
|
||||
} */\n`;
|
||||
return prefix + stringify(value);
|
||||
}
|
||||
|
||||
if (value && value.__expression) {
|
||||
return value.__expression;
|
||||
}
|
||||
|
||||
// shorten long functions
|
||||
if (typeof value === 'function') {
|
||||
if (!verbose && value.toString().length > 100) {
|
||||
return `function () { /* omitted long function */ }`;
|
||||
}
|
||||
}
|
||||
|
||||
return stringify(value);
|
||||
},
|
||||
2,
|
||||
);
|
||||
}
|
||||
|
||||
entry(name) {
|
||||
return this.entryPoints.getOrCompute(name, () => new ChainedSet(this));
|
||||
}
|
||||
|
||||
plugin(name) {
|
||||
return this.plugins.getOrCompute(name, () => new Plugin(this, name));
|
||||
}
|
||||
|
||||
toConfig() {
|
||||
const entryPoints = this.entryPoints.entries() || {};
|
||||
|
||||
return this.clean(
|
||||
Object.assign(this.entries() || {}, {
|
||||
node: this.node.entries(),
|
||||
output: this.output.entries(),
|
||||
resolve: this.resolve.toConfig(),
|
||||
resolveLoader: this.resolveLoader.toConfig(),
|
||||
devServer: this.devServer.toConfig(),
|
||||
module: this.module.toConfig(),
|
||||
optimization: this.optimization.toConfig(),
|
||||
plugins: this.plugins.values().map((plugin) => plugin.toConfig()),
|
||||
performance: this.performance.entries(),
|
||||
entry: Object.keys(entryPoints).reduce(
|
||||
(acc, key) =>
|
||||
Object.assign(acc, { [key]: entryPoints[key].values() }),
|
||||
{},
|
||||
),
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
toString(options) {
|
||||
return module.exports.toString(this.toConfig(), options);
|
||||
}
|
||||
|
||||
merge(obj = {}, omit = []) {
|
||||
const omissions = [
|
||||
'node',
|
||||
'output',
|
||||
'resolve',
|
||||
'resolveLoader',
|
||||
'devServer',
|
||||
'optimization',
|
||||
'performance',
|
||||
'module',
|
||||
];
|
||||
|
||||
if (!omit.includes('entry') && 'entry' in obj) {
|
||||
Object.keys(obj.entry).forEach((name) =>
|
||||
this.entry(name).merge([].concat(obj.entry[name])),
|
||||
);
|
||||
}
|
||||
|
||||
if (!omit.includes('plugin') && 'plugin' in obj) {
|
||||
Object.keys(obj.plugin).forEach((name) =>
|
||||
this.plugin(name).merge(obj.plugin[name]),
|
||||
);
|
||||
}
|
||||
|
||||
omissions.forEach((key) => {
|
||||
if (!omit.includes(key) && key in obj) {
|
||||
this[key].merge(obj[key]);
|
||||
}
|
||||
});
|
||||
|
||||
return super.merge(obj, [...omit, ...omissions, 'entry', 'plugin']);
|
||||
}
|
||||
};
|
||||
73
node_modules/webpack-chain/src/DevServer.js
generated
vendored
Normal file
73
node_modules/webpack-chain/src/DevServer.js
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
const ChainedMap = require('./ChainedMap');
|
||||
const ChainedSet = require('./ChainedSet');
|
||||
|
||||
module.exports = class extends ChainedMap {
|
||||
constructor(parent) {
|
||||
super(parent);
|
||||
|
||||
this.allowedHosts = new ChainedSet(this);
|
||||
|
||||
this.extend([
|
||||
'after',
|
||||
'before',
|
||||
'bonjour',
|
||||
'clientLogLevel',
|
||||
'color',
|
||||
'compress',
|
||||
'contentBase',
|
||||
'disableHostCheck',
|
||||
'filename',
|
||||
'headers',
|
||||
'historyApiFallback',
|
||||
'host',
|
||||
'hot',
|
||||
'hotOnly',
|
||||
'http2',
|
||||
'https',
|
||||
'index',
|
||||
'info',
|
||||
'inline',
|
||||
'lazy',
|
||||
'mimeTypes',
|
||||
'noInfo',
|
||||
'open',
|
||||
'openPage',
|
||||
'overlay',
|
||||
'pfx',
|
||||
'pfxPassphrase',
|
||||
'port',
|
||||
'proxy',
|
||||
'progress',
|
||||
'public',
|
||||
'publicPath',
|
||||
'quiet',
|
||||
'setup',
|
||||
'socket',
|
||||
'sockHost',
|
||||
'sockPath',
|
||||
'sockPort',
|
||||
'staticOptions',
|
||||
'stats',
|
||||
'stdin',
|
||||
'useLocalIp',
|
||||
'watchContentBase',
|
||||
'watchOptions',
|
||||
'writeToDisk',
|
||||
]);
|
||||
}
|
||||
|
||||
toConfig() {
|
||||
return this.clean({
|
||||
allowedHosts: this.allowedHosts.values(),
|
||||
...(this.entries() || {}),
|
||||
});
|
||||
}
|
||||
|
||||
merge(obj, omit = []) {
|
||||
if (!omit.includes('allowedHosts') && 'allowedHosts' in obj) {
|
||||
this.allowedHosts.merge(obj.allowedHosts);
|
||||
}
|
||||
|
||||
return super.merge(obj, ['allowedHosts']);
|
||||
}
|
||||
};
|
||||
47
node_modules/webpack-chain/src/Module.js
generated
vendored
Normal file
47
node_modules/webpack-chain/src/Module.js
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
const ChainedMap = require('./ChainedMap');
|
||||
const Rule = require('./Rule');
|
||||
|
||||
module.exports = class extends ChainedMap {
|
||||
constructor(parent) {
|
||||
super(parent);
|
||||
this.rules = new ChainedMap(this);
|
||||
this.defaultRules = new ChainedMap(this);
|
||||
this.extend(['noParse', 'strictExportPresence']);
|
||||
}
|
||||
|
||||
defaultRule(name) {
|
||||
return this.defaultRules.getOrCompute(
|
||||
name,
|
||||
() => new Rule(this, name, 'defaultRule'),
|
||||
);
|
||||
}
|
||||
|
||||
rule(name) {
|
||||
return this.rules.getOrCompute(name, () => new Rule(this, name, 'rule'));
|
||||
}
|
||||
|
||||
toConfig() {
|
||||
return this.clean(
|
||||
Object.assign(this.entries() || {}, {
|
||||
defaultRules: this.defaultRules.values().map((r) => r.toConfig()),
|
||||
rules: this.rules.values().map((r) => r.toConfig()),
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
merge(obj, omit = []) {
|
||||
if (!omit.includes('rule') && 'rule' in obj) {
|
||||
Object.keys(obj.rule).forEach((name) =>
|
||||
this.rule(name).merge(obj.rule[name]),
|
||||
);
|
||||
}
|
||||
|
||||
if (!omit.includes('defaultRule') && 'defaultRule' in obj) {
|
||||
Object.keys(obj.defaultRule).forEach((name) =>
|
||||
this.defaultRule(name).merge(obj.defaultRule[name]),
|
||||
);
|
||||
}
|
||||
|
||||
return super.merge(obj, ['rule', 'defaultRule']);
|
||||
}
|
||||
};
|
||||
61
node_modules/webpack-chain/src/Optimization.js
generated
vendored
Normal file
61
node_modules/webpack-chain/src/Optimization.js
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
const ChainedMap = require('./ChainedMap');
|
||||
const Plugin = require('./Plugin');
|
||||
|
||||
module.exports = class extends ChainedMap {
|
||||
constructor(parent) {
|
||||
super(parent);
|
||||
this.minimizers = new ChainedMap(this);
|
||||
this.extend([
|
||||
'concatenateModules',
|
||||
'flagIncludedChunks',
|
||||
'mergeDuplicateChunks',
|
||||
'minimize',
|
||||
'namedChunks',
|
||||
'namedModules',
|
||||
'nodeEnv',
|
||||
'noEmitOnErrors',
|
||||
'occurrenceOrder',
|
||||
'portableRecords',
|
||||
'providedExports',
|
||||
'removeAvailableModules',
|
||||
'removeEmptyChunks',
|
||||
'runtimeChunk',
|
||||
'sideEffects',
|
||||
'splitChunks',
|
||||
'usedExports',
|
||||
]);
|
||||
}
|
||||
|
||||
minimizer(name) {
|
||||
if (Array.isArray(name)) {
|
||||
throw new Error(
|
||||
'optimization.minimizer() no longer supports being passed an array. ' +
|
||||
'Either switch to the new syntax (https://github.com/neutrinojs/webpack-chain#config-optimization-minimizers-adding) or downgrade to webpack-chain 4. ' +
|
||||
'If using Vue this likely means a Vue plugin has not yet been updated to support Vue CLI 4+.',
|
||||
);
|
||||
}
|
||||
|
||||
return this.minimizers.getOrCompute(
|
||||
name,
|
||||
() => new Plugin(this, name, 'optimization.minimizer'),
|
||||
);
|
||||
}
|
||||
|
||||
toConfig() {
|
||||
return this.clean(
|
||||
Object.assign(this.entries() || {}, {
|
||||
minimizer: this.minimizers.values().map((plugin) => plugin.toConfig()),
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
merge(obj, omit = []) {
|
||||
if (!omit.includes('minimizer') && 'minimizer' in obj) {
|
||||
Object.keys(obj.minimizer).forEach((name) =>
|
||||
this.minimizer(name).merge(obj.minimizer[name]),
|
||||
);
|
||||
}
|
||||
|
||||
return super.merge(obj, [...omit, 'minimizer']);
|
||||
}
|
||||
};
|
||||
40
node_modules/webpack-chain/src/Orderable.js
generated
vendored
Normal file
40
node_modules/webpack-chain/src/Orderable.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
module.exports = (Class) =>
|
||||
class extends Class {
|
||||
before(name) {
|
||||
if (this.__after) {
|
||||
throw new Error(
|
||||
`Unable to set .before(${JSON.stringify(
|
||||
name,
|
||||
)}) with existing value for .after()`,
|
||||
);
|
||||
}
|
||||
|
||||
this.__before = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
after(name) {
|
||||
if (this.__before) {
|
||||
throw new Error(
|
||||
`Unable to set .after(${JSON.stringify(
|
||||
name,
|
||||
)}) with existing value for .before()`,
|
||||
);
|
||||
}
|
||||
|
||||
this.__after = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
merge(obj, omit = []) {
|
||||
if (obj.before) {
|
||||
this.before(obj.before);
|
||||
}
|
||||
|
||||
if (obj.after) {
|
||||
this.after(obj.after);
|
||||
}
|
||||
|
||||
return super.merge(obj, [...omit, 'before', 'after']);
|
||||
}
|
||||
};
|
||||
40
node_modules/webpack-chain/src/Output.js
generated
vendored
Normal file
40
node_modules/webpack-chain/src/Output.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
const ChainedMap = require('./ChainedMap');
|
||||
|
||||
module.exports = class extends ChainedMap {
|
||||
constructor(parent) {
|
||||
super(parent);
|
||||
this.extend([
|
||||
'auxiliaryComment',
|
||||
'chunkCallbackName',
|
||||
'chunkFilename',
|
||||
'chunkLoadTimeout',
|
||||
'crossOriginLoading',
|
||||
'devtoolFallbackModuleFilenameTemplate',
|
||||
'devtoolLineToLine',
|
||||
'devtoolModuleFilenameTemplate',
|
||||
'devtoolNamespace',
|
||||
'filename',
|
||||
'futureEmitAssets',
|
||||
'globalObject',
|
||||
'hashDigest',
|
||||
'hashDigestLength',
|
||||
'hashFunction',
|
||||
'hashSalt',
|
||||
'hotUpdateChunkFilename',
|
||||
'hotUpdateFunction',
|
||||
'hotUpdateMainFilename',
|
||||
'jsonpFunction',
|
||||
'library',
|
||||
'libraryExport',
|
||||
'libraryTarget',
|
||||
'path',
|
||||
'pathinfo',
|
||||
'publicPath',
|
||||
'sourceMapFilename',
|
||||
'sourcePrefix',
|
||||
'strictModuleExceptionHandling',
|
||||
'umdNamedDefine',
|
||||
'webassemblyModuleFilename',
|
||||
]);
|
||||
}
|
||||
};
|
||||
8
node_modules/webpack-chain/src/Performance.js
generated
vendored
Normal file
8
node_modules/webpack-chain/src/Performance.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
const ChainedMap = require('./ChainedMap');
|
||||
|
||||
module.exports = class extends ChainedMap {
|
||||
constructor(parent) {
|
||||
super(parent);
|
||||
this.extend(['assetFilter', 'hints', 'maxAssetSize', 'maxEntrypointSize']);
|
||||
}
|
||||
};
|
||||
91
node_modules/webpack-chain/src/Plugin.js
generated
vendored
Normal file
91
node_modules/webpack-chain/src/Plugin.js
generated
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
const ChainedMap = require('./ChainedMap');
|
||||
const Orderable = require('./Orderable');
|
||||
|
||||
module.exports = Orderable(
|
||||
class extends ChainedMap {
|
||||
constructor(parent, name, type = 'plugin') {
|
||||
super(parent);
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.extend(['init']);
|
||||
|
||||
this.init((Plugin, args = []) => {
|
||||
if (typeof Plugin === 'function') {
|
||||
return new Plugin(...args);
|
||||
}
|
||||
return Plugin;
|
||||
});
|
||||
}
|
||||
|
||||
use(plugin, args = []) {
|
||||
return this.set('plugin', plugin).set('args', args);
|
||||
}
|
||||
|
||||
tap(f) {
|
||||
if (!this.has('plugin')) {
|
||||
throw new Error(
|
||||
`Cannot call .tap() on a plugin that has not yet been defined. Call ${this.type}('${this.name}').use(<Plugin>) first.`,
|
||||
);
|
||||
}
|
||||
this.set('args', f(this.get('args') || []));
|
||||
return this;
|
||||
}
|
||||
|
||||
set(key, value) {
|
||||
if (key === 'args' && !Array.isArray(value)) {
|
||||
throw new Error('args must be an array of arguments');
|
||||
}
|
||||
return super.set(key, value);
|
||||
}
|
||||
|
||||
merge(obj, omit = []) {
|
||||
if ('plugin' in obj) {
|
||||
this.set('plugin', obj.plugin);
|
||||
}
|
||||
|
||||
if ('args' in obj) {
|
||||
this.set('args', obj.args);
|
||||
}
|
||||
|
||||
return super.merge(obj, [...omit, 'args', 'plugin']);
|
||||
}
|
||||
|
||||
toConfig() {
|
||||
const init = this.get('init');
|
||||
let plugin = this.get('plugin');
|
||||
const args = this.get('args');
|
||||
let pluginPath = null;
|
||||
|
||||
if (plugin === undefined) {
|
||||
throw new Error(
|
||||
`Invalid ${this.type} configuration: ${this.type}('${this.name}').use(<Plugin>) was not called to specify the plugin`,
|
||||
);
|
||||
}
|
||||
|
||||
// Support using the path to a plugin rather than the plugin itself,
|
||||
// allowing expensive require()s to be skipped in cases where the plugin
|
||||
// or webpack configuration won't end up being used.
|
||||
if (typeof plugin === 'string') {
|
||||
pluginPath = plugin;
|
||||
// eslint-disable-next-line global-require, import/no-dynamic-require
|
||||
plugin = require(pluginPath);
|
||||
}
|
||||
|
||||
const constructorName = plugin.__expression
|
||||
? `(${plugin.__expression})`
|
||||
: plugin.name;
|
||||
|
||||
const config = init(plugin, args);
|
||||
|
||||
Object.defineProperties(config, {
|
||||
__pluginName: { value: this.name },
|
||||
__pluginType: { value: this.type },
|
||||
__pluginArgs: { value: args },
|
||||
__pluginConstructorName: { value: constructorName },
|
||||
__pluginPath: { value: pluginPath },
|
||||
});
|
||||
|
||||
return config;
|
||||
}
|
||||
},
|
||||
);
|
||||
74
node_modules/webpack-chain/src/Resolve.js
generated
vendored
Normal file
74
node_modules/webpack-chain/src/Resolve.js
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
const ChainedMap = require('./ChainedMap');
|
||||
const ChainedSet = require('./ChainedSet');
|
||||
const Plugin = require('./Plugin');
|
||||
|
||||
module.exports = class extends ChainedMap {
|
||||
constructor(parent) {
|
||||
super(parent);
|
||||
this.alias = new ChainedMap(this);
|
||||
this.aliasFields = new ChainedSet(this);
|
||||
this.descriptionFiles = new ChainedSet(this);
|
||||
this.extensions = new ChainedSet(this);
|
||||
this.mainFields = new ChainedSet(this);
|
||||
this.mainFiles = new ChainedSet(this);
|
||||
this.modules = new ChainedSet(this);
|
||||
this.plugins = new ChainedMap(this);
|
||||
this.extend([
|
||||
'cachePredicate',
|
||||
'cacheWithContext',
|
||||
'concord',
|
||||
'enforceExtension',
|
||||
'enforceModuleExtension',
|
||||
'symlinks',
|
||||
'unsafeCache',
|
||||
]);
|
||||
}
|
||||
|
||||
plugin(name) {
|
||||
return this.plugins.getOrCompute(
|
||||
name,
|
||||
() => new Plugin(this, name, 'resolve.plugin'),
|
||||
);
|
||||
}
|
||||
|
||||
toConfig() {
|
||||
return this.clean(
|
||||
Object.assign(this.entries() || {}, {
|
||||
alias: this.alias.entries(),
|
||||
aliasFields: this.aliasFields.values(),
|
||||
descriptionFiles: this.descriptionFiles.values(),
|
||||
extensions: this.extensions.values(),
|
||||
mainFields: this.mainFields.values(),
|
||||
mainFiles: this.mainFiles.values(),
|
||||
modules: this.modules.values(),
|
||||
plugins: this.plugins.values().map((plugin) => plugin.toConfig()),
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
merge(obj, omit = []) {
|
||||
const omissions = [
|
||||
'alias',
|
||||
'aliasFields',
|
||||
'descriptionFiles',
|
||||
'extensions',
|
||||
'mainFields',
|
||||
'mainFiles',
|
||||
'modules',
|
||||
];
|
||||
|
||||
if (!omit.includes('plugin') && 'plugin' in obj) {
|
||||
Object.keys(obj.plugin).forEach((name) =>
|
||||
this.plugin(name).merge(obj.plugin[name]),
|
||||
);
|
||||
}
|
||||
|
||||
omissions.forEach((key) => {
|
||||
if (!omit.includes(key) && key in obj) {
|
||||
this[key].merge(obj[key]);
|
||||
}
|
||||
});
|
||||
|
||||
return super.merge(obj, [...omit, ...omissions, 'plugin']);
|
||||
}
|
||||
};
|
||||
30
node_modules/webpack-chain/src/ResolveLoader.js
generated
vendored
Normal file
30
node_modules/webpack-chain/src/ResolveLoader.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
const Resolve = require('./Resolve');
|
||||
const ChainedSet = require('./ChainedSet');
|
||||
|
||||
module.exports = class extends Resolve {
|
||||
constructor(parent) {
|
||||
super(parent);
|
||||
this.moduleExtensions = new ChainedSet(this);
|
||||
this.packageMains = new ChainedSet(this);
|
||||
}
|
||||
|
||||
toConfig() {
|
||||
return this.clean({
|
||||
moduleExtensions: this.moduleExtensions.values(),
|
||||
packageMains: this.packageMains.values(),
|
||||
...super.toConfig(),
|
||||
});
|
||||
}
|
||||
|
||||
merge(obj, omit = []) {
|
||||
const omissions = ['moduleExtensions', 'packageMains'];
|
||||
|
||||
omissions.forEach((key) => {
|
||||
if (!omit.includes(key) && key in obj) {
|
||||
this[key].merge(obj[key]);
|
||||
}
|
||||
});
|
||||
|
||||
return super.merge(obj, [...omit, ...omissions]);
|
||||
}
|
||||
};
|
||||
141
node_modules/webpack-chain/src/Rule.js
generated
vendored
Normal file
141
node_modules/webpack-chain/src/Rule.js
generated
vendored
Normal file
@@ -0,0 +1,141 @@
|
||||
const ChainedMap = require('./ChainedMap');
|
||||
const ChainedSet = require('./ChainedSet');
|
||||
const Orderable = require('./Orderable');
|
||||
const Use = require('./Use');
|
||||
const Resolve = require('./Resolve');
|
||||
|
||||
function toArray(arr) {
|
||||
return Array.isArray(arr) ? arr : [arr];
|
||||
}
|
||||
|
||||
const Rule = Orderable(
|
||||
class extends ChainedMap {
|
||||
constructor(parent, name, ruleType = 'rule') {
|
||||
super(parent);
|
||||
this.name = name;
|
||||
this.names = [];
|
||||
this.ruleType = ruleType;
|
||||
this.ruleTypes = [];
|
||||
|
||||
let rule = this;
|
||||
while (rule instanceof Rule) {
|
||||
this.names.unshift(rule.name);
|
||||
this.ruleTypes.unshift(rule.ruleType);
|
||||
rule = rule.parent;
|
||||
}
|
||||
|
||||
this.uses = new ChainedMap(this);
|
||||
this.include = new ChainedSet(this);
|
||||
this.exclude = new ChainedSet(this);
|
||||
this.rules = new ChainedMap(this);
|
||||
this.oneOfs = new ChainedMap(this);
|
||||
this.resolve = new Resolve(this);
|
||||
this.extend([
|
||||
'enforce',
|
||||
'issuer',
|
||||
'parser',
|
||||
'resource',
|
||||
'resourceQuery',
|
||||
'sideEffects',
|
||||
'test',
|
||||
'type',
|
||||
]);
|
||||
}
|
||||
|
||||
use(name) {
|
||||
return this.uses.getOrCompute(name, () => new Use(this, name));
|
||||
}
|
||||
|
||||
rule(name) {
|
||||
return this.rules.getOrCompute(name, () => new Rule(this, name, 'rule'));
|
||||
}
|
||||
|
||||
oneOf(name) {
|
||||
return this.oneOfs.getOrCompute(
|
||||
name,
|
||||
() => new Rule(this, name, 'oneOf'),
|
||||
);
|
||||
}
|
||||
|
||||
pre() {
|
||||
return this.enforce('pre');
|
||||
}
|
||||
|
||||
post() {
|
||||
return this.enforce('post');
|
||||
}
|
||||
|
||||
toConfig() {
|
||||
const config = this.clean(
|
||||
Object.assign(this.entries() || {}, {
|
||||
include: this.include.values(),
|
||||
exclude: this.exclude.values(),
|
||||
rules: this.rules.values().map((rule) => rule.toConfig()),
|
||||
oneOf: this.oneOfs.values().map((oneOf) => oneOf.toConfig()),
|
||||
use: this.uses.values().map((use) => use.toConfig()),
|
||||
resolve: this.resolve.toConfig(),
|
||||
}),
|
||||
);
|
||||
|
||||
Object.defineProperties(config, {
|
||||
__ruleNames: { value: this.names },
|
||||
__ruleTypes: { value: this.ruleTypes },
|
||||
});
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
merge(obj, omit = []) {
|
||||
if (!omit.includes('include') && 'include' in obj) {
|
||||
this.include.merge(toArray(obj.include));
|
||||
}
|
||||
|
||||
if (!omit.includes('exclude') && 'exclude' in obj) {
|
||||
this.exclude.merge(toArray(obj.exclude));
|
||||
}
|
||||
|
||||
if (!omit.includes('use') && 'use' in obj) {
|
||||
Object.keys(obj.use).forEach((name) =>
|
||||
this.use(name).merge(obj.use[name]),
|
||||
);
|
||||
}
|
||||
|
||||
if (!omit.includes('rules') && 'rules' in obj) {
|
||||
Object.keys(obj.rules).forEach((name) =>
|
||||
this.rule(name).merge(obj.rules[name]),
|
||||
);
|
||||
}
|
||||
|
||||
if (!omit.includes('oneOf') && 'oneOf' in obj) {
|
||||
Object.keys(obj.oneOf).forEach((name) =>
|
||||
this.oneOf(name).merge(obj.oneOf[name]),
|
||||
);
|
||||
}
|
||||
|
||||
if (!omit.includes('resolve') && 'resolve' in obj) {
|
||||
this.resolve.merge(obj.resolve);
|
||||
}
|
||||
|
||||
if (!omit.includes('test') && 'test' in obj) {
|
||||
this.test(
|
||||
obj.test instanceof RegExp || typeof obj.test === 'function'
|
||||
? obj.test
|
||||
: new RegExp(obj.test),
|
||||
);
|
||||
}
|
||||
|
||||
return super.merge(obj, [
|
||||
...omit,
|
||||
'include',
|
||||
'exclude',
|
||||
'use',
|
||||
'rules',
|
||||
'oneOf',
|
||||
'resolve',
|
||||
'test',
|
||||
]);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
module.exports = Rule;
|
||||
42
node_modules/webpack-chain/src/Use.js
generated
vendored
Normal file
42
node_modules/webpack-chain/src/Use.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
const merge = require('deepmerge');
|
||||
const ChainedMap = require('./ChainedMap');
|
||||
const Orderable = require('./Orderable');
|
||||
|
||||
module.exports = Orderable(
|
||||
class extends ChainedMap {
|
||||
constructor(parent, name) {
|
||||
super(parent);
|
||||
this.name = name;
|
||||
this.extend(['loader', 'options']);
|
||||
}
|
||||
|
||||
tap(f) {
|
||||
this.options(f(this.get('options')));
|
||||
return this;
|
||||
}
|
||||
|
||||
merge(obj, omit = []) {
|
||||
if (!omit.includes('loader') && 'loader' in obj) {
|
||||
this.loader(obj.loader);
|
||||
}
|
||||
|
||||
if (!omit.includes('options') && 'options' in obj) {
|
||||
this.options(merge(this.store.get('options') || {}, obj.options));
|
||||
}
|
||||
|
||||
return super.merge(obj, [...omit, 'loader', 'options']);
|
||||
}
|
||||
|
||||
toConfig() {
|
||||
const config = this.clean(this.entries() || {});
|
||||
|
||||
Object.defineProperties(config, {
|
||||
__useName: { value: this.name },
|
||||
__ruleNames: { value: this.parent && this.parent.names },
|
||||
__ruleTypes: { value: this.parent && this.parent.ruleTypes },
|
||||
});
|
||||
|
||||
return config;
|
||||
}
|
||||
},
|
||||
);
|
||||
Reference in New Issue
Block a user