aboutsummaryrefslogtreecommitdiff
path: root/node_modules/webpack-chain/src
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/webpack-chain/src')
-rw-r--r--node_modules/webpack-chain/src/Chainable.js14
-rw-r--r--node_modules/webpack-chain/src/ChainedMap.js151
-rw-r--r--node_modules/webpack-chain/src/ChainedSet.js55
-rw-r--r--node_modules/webpack-chain/src/Config.js176
-rw-r--r--node_modules/webpack-chain/src/DevServer.js68
-rw-r--r--node_modules/webpack-chain/src/Module.js44
-rw-r--r--node_modules/webpack-chain/src/Optimization.js27
-rw-r--r--node_modules/webpack-chain/src/Orderable.js40
-rw-r--r--node_modules/webpack-chain/src/Output.js39
-rw-r--r--node_modules/webpack-chain/src/Performance.js8
-rw-r--r--node_modules/webpack-chain/src/Plugin.js71
-rw-r--r--node_modules/webpack-chain/src/Resolve.js71
-rw-r--r--node_modules/webpack-chain/src/ResolveLoader.js34
-rw-r--r--node_modules/webpack-chain/src/Rule.js98
-rw-r--r--node_modules/webpack-chain/src/Use.js41
15 files changed, 937 insertions, 0 deletions
diff --git a/node_modules/webpack-chain/src/Chainable.js b/node_modules/webpack-chain/src/Chainable.js
new file mode 100644
index 00000000..f5704ae4
--- /dev/null
+++ b/node_modules/webpack-chain/src/Chainable.js
@@ -0,0 +1,14 @@
+module.exports = class {
+ constructor(parent) {
+ this.parent = parent;
+ }
+
+ batch(handler) {
+ handler(this);
+ return this;
+ }
+
+ end() {
+ return this.parent;
+ }
+};
diff --git a/node_modules/webpack-chain/src/ChainedMap.js b/node_modules/webpack-chain/src/ChainedMap.js
new file mode 100644
index 00000000..d7dff756
--- /dev/null
+++ b/node_modules/webpack-chain/src/ChainedMap.js
@@ -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;
+ }
+};
diff --git a/node_modules/webpack-chain/src/ChainedSet.js b/node_modules/webpack-chain/src/ChainedSet.js
new file mode 100644
index 00000000..ea469daa
--- /dev/null
+++ b/node_modules/webpack-chain/src/ChainedSet.js
@@ -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;
+ }
+};
diff --git a/node_modules/webpack-chain/src/Config.js b/node_modules/webpack-chain/src/Config.js
new file mode 100644
index 00000000..39ea6df0
--- /dev/null
+++ b/node_modules/webpack-chain/src/Config.js
@@ -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',
+ '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}.plugin('${
+ 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 prefix = `/* ${configPrefix}.module.rule('${
+ value.__ruleNames[0]
+ }')${value.__ruleNames
+ .slice(1)
+ .map(r => `.oneOf('${r}')`)
+ .join('')}${
+ value.__useName ? `.use('${value.__useName}')` : ``
+ } */\n`;
+ return prefix + stringify(value);
+ }
+
+ // shorten long functions
+ if (typeof value === 'function') {
+ if (value.__expression) {
+ return value.__expression;
+ }
+ 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.entries(),
+ 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']);
+ }
+};
diff --git a/node_modules/webpack-chain/src/DevServer.js b/node_modules/webpack-chain/src/DevServer.js
new file mode 100644
index 00000000..23c13639
--- /dev/null
+++ b/node_modules/webpack-chain/src/DevServer.js
@@ -0,0 +1,68 @@
+const ChainedMap = require('./ChainedMap');
+const ChainedSet = require('./ChainedSet');
+
+module.exports = class extends ChainedMap {
+ constructor(parent) {
+ super(parent);
+
+ this.allowedHosts = new ChainedSet(this);
+
+ this.extend([
+ 'bonjour',
+ 'clientLogLevel',
+ 'color',
+ 'compress',
+ 'contentBase',
+ 'disableHostCheck',
+ 'filename',
+ 'headers',
+ 'historyApiFallback',
+ 'host',
+ 'hot',
+ 'hotOnly',
+ 'https',
+ 'info',
+ 'inline',
+ 'lazy',
+ 'noInfo',
+ 'open',
+ 'openPage',
+ 'overlay',
+ 'pfx',
+ 'pfxPassphrase',
+ 'port',
+ 'proxy',
+ 'progress',
+ 'public',
+ 'publicPath',
+ 'quiet',
+ 'setup',
+ 'socket',
+ 'staticOptions',
+ 'stats',
+ 'stdin',
+ 'useLocalIp',
+ 'watchContentBase',
+ 'watchOptions',
+ ]);
+ }
+
+ toConfig() {
+ return this.clean(
+ Object.assign(
+ {
+ 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']);
+ }
+};
diff --git a/node_modules/webpack-chain/src/Module.js b/node_modules/webpack-chain/src/Module.js
new file mode 100644
index 00000000..01993227
--- /dev/null
+++ b/node_modules/webpack-chain/src/Module.js
@@ -0,0 +1,44 @@
+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']);
+ }
+
+ defaultRule(name) {
+ return this.defaultRules.getOrCompute(name, () => new Rule(this, name));
+ }
+
+ rule(name) {
+ return this.rules.getOrCompute(name, () => new Rule(this, name));
+ }
+
+ 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']);
+ }
+};
diff --git a/node_modules/webpack-chain/src/Optimization.js b/node_modules/webpack-chain/src/Optimization.js
new file mode 100644
index 00000000..cb061f87
--- /dev/null
+++ b/node_modules/webpack-chain/src/Optimization.js
@@ -0,0 +1,27 @@
+const ChainedMap = require('./ChainedMap');
+
+module.exports = class extends ChainedMap {
+ constructor(parent) {
+ super(parent);
+ this.extend([
+ 'concatenateModules',
+ 'flagIncludedChunks',
+ 'mergeDuplicateChunks',
+ 'minimize',
+ 'minimizer',
+ 'namedChunks',
+ 'namedModules',
+ 'nodeEnv',
+ 'noEmitOnErrors',
+ 'occurrenceOrder',
+ 'portableRecords',
+ 'providedExports',
+ 'removeAvailableModules',
+ 'removeEmptyChunks',
+ 'runtimeChunk',
+ 'sideEffects',
+ 'splitChunks',
+ 'usedExports',
+ ]);
+ }
+};
diff --git a/node_modules/webpack-chain/src/Orderable.js b/node_modules/webpack-chain/src/Orderable.js
new file mode 100644
index 00000000..abb8a079
--- /dev/null
+++ b/node_modules/webpack-chain/src/Orderable.js
@@ -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']);
+ }
+ };
diff --git a/node_modules/webpack-chain/src/Output.js b/node_modules/webpack-chain/src/Output.js
new file mode 100644
index 00000000..296c3674
--- /dev/null
+++ b/node_modules/webpack-chain/src/Output.js
@@ -0,0 +1,39 @@
+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',
+ 'globalObject',
+ 'hashDigest',
+ 'hashDigestLength',
+ 'hashFunction',
+ 'hashSalt',
+ 'hotUpdateChunkFilename',
+ 'hotUpdateFunction',
+ 'hotUpdateMainFilename',
+ 'jsonpFunction',
+ 'library',
+ 'libraryExport',
+ 'libraryTarget',
+ 'path',
+ 'pathinfo',
+ 'publicPath',
+ 'sourceMapFilename',
+ 'sourcePrefix',
+ 'strictModuleExceptionHandling',
+ 'umdNamedDefine',
+ 'webassemblyModuleFilename',
+ ]);
+ }
+};
diff --git a/node_modules/webpack-chain/src/Performance.js b/node_modules/webpack-chain/src/Performance.js
new file mode 100644
index 00000000..79c23fa8
--- /dev/null
+++ b/node_modules/webpack-chain/src/Performance.js
@@ -0,0 +1,8 @@
+const ChainedMap = require('./ChainedMap');
+
+module.exports = class extends ChainedMap {
+ constructor(parent) {
+ super(parent);
+ this.extend(['assetFilter', 'hints', 'maxAssetSize', 'maxEntrypointSize']);
+ }
+};
diff --git a/node_modules/webpack-chain/src/Plugin.js b/node_modules/webpack-chain/src/Plugin.js
new file mode 100644
index 00000000..418b32d4
--- /dev/null
+++ b/node_modules/webpack-chain/src/Plugin.js
@@ -0,0 +1,71 @@
+const ChainedMap = require('./ChainedMap');
+const Orderable = require('./Orderable');
+
+module.exports = Orderable(
+ class extends ChainedMap {
+ constructor(parent, name) {
+ super(parent);
+ this.name = name;
+ 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) {
+ this.set('args', f(this.get('args') || []));
+ return this;
+ }
+
+ 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;
+
+ // 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 },
+ __pluginArgs: { value: args },
+ __pluginConstructorName: { value: constructorName },
+ __pluginPath: { value: pluginPath },
+ });
+
+ return config;
+ }
+ }
+);
diff --git a/node_modules/webpack-chain/src/Resolve.js b/node_modules/webpack-chain/src/Resolve.js
new file mode 100644
index 00000000..48360714
--- /dev/null
+++ b/node_modules/webpack-chain/src/Resolve.js
@@ -0,0 +1,71 @@
+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));
+ }
+
+ 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']);
+ }
+};
diff --git a/node_modules/webpack-chain/src/ResolveLoader.js b/node_modules/webpack-chain/src/ResolveLoader.js
new file mode 100644
index 00000000..e1491a38
--- /dev/null
+++ b/node_modules/webpack-chain/src/ResolveLoader.js
@@ -0,0 +1,34 @@
+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(
+ Object.assign(
+ {
+ 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]);
+ }
+};
diff --git a/node_modules/webpack-chain/src/Rule.js b/node_modules/webpack-chain/src/Rule.js
new file mode 100644
index 00000000..45e16955
--- /dev/null
+++ b/node_modules/webpack-chain/src/Rule.js
@@ -0,0 +1,98 @@
+const ChainedMap = require('./ChainedMap');
+const ChainedSet = require('./ChainedSet');
+const Use = require('./Use');
+
+module.exports = class Rule extends ChainedMap {
+ constructor(parent, name) {
+ super(parent);
+ this.name = name;
+ this.names = [];
+
+ let rule = this;
+ while (rule instanceof Rule) {
+ this.names.unshift(rule.name);
+ rule = rule.parent;
+ }
+
+ this.uses = new ChainedMap(this);
+ this.include = new ChainedSet(this);
+ this.exclude = new ChainedSet(this);
+ this.oneOfs = new ChainedMap(this);
+ this.extend([
+ 'enforce',
+ 'issuer',
+ 'parser',
+ 'resource',
+ 'resourceQuery',
+ 'sideEffects',
+ 'test',
+ 'type',
+ ]);
+ }
+
+ use(name) {
+ return this.uses.getOrCompute(name, () => new Use(this, name));
+ }
+
+ oneOf(name) {
+ return this.oneOfs.getOrCompute(name, () => new Rule(this, name));
+ }
+
+ 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(),
+ oneOf: this.oneOfs.values().map(oneOf => oneOf.toConfig()),
+ use: this.uses.values().map(use => use.toConfig()),
+ })
+ );
+
+ Object.defineProperties(config, {
+ __ruleNames: { value: this.names },
+ });
+
+ return config;
+ }
+
+ merge(obj, omit = []) {
+ if (!omit.includes('include') && 'include' in obj) {
+ this.include.merge(obj.include);
+ }
+
+ if (!omit.includes('exclude') && 'exclude' in obj) {
+ this.exclude.merge(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('oneOf') && 'oneOf' in obj) {
+ Object.keys(obj.oneOf).forEach(name =>
+ this.oneOf(name).merge(obj.oneOf[name])
+ );
+ }
+
+ if (!omit.includes('test') && 'test' in obj) {
+ this.test(obj.test instanceof RegExp ? obj.test : new RegExp(obj.test));
+ }
+
+ return super.merge(obj, [
+ ...omit,
+ 'include',
+ 'exclude',
+ 'use',
+ 'oneOf',
+ 'test',
+ ]);
+ }
+};
diff --git a/node_modules/webpack-chain/src/Use.js b/node_modules/webpack-chain/src/Use.js
new file mode 100644
index 00000000..8ab3078e
--- /dev/null
+++ b/node_modules/webpack-chain/src/Use.js
@@ -0,0 +1,41 @@
+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 },
+ });
+
+ return config;
+ }
+ }
+);