@empjs/chain 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1337 -0
- package/dist/index.cjs +4 -0
- package/dist/index.d.cts +122 -0
- package/dist/index.d.ts +122 -0
- package/dist/index.js +4 -0
- package/package.json +59 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"use strict";var L=Object.create;var _=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var D=Object.getPrototypeOf,U=Object.prototype.hasOwnProperty;var q=(n,e)=>{for(var t in e)_(n,t,{get:e[t],enumerable:!0})},P=(n,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of I(e))!U.call(n,i)&&i!==t&&_(n,i,{get:()=>e[i],enumerable:!(s=H(e,i))||s.enumerable});return n};var T=(n,e,t)=>(t=n!=null?L(D(n)):{},P(e||!n||!n.__esModule?_(t,"default",{value:n,enumerable:!0}):t,n)),V=n=>P(_({},"__esModule",{value:!0}),n);var B={};q(B,{default:()=>O});module.exports=V(B);var k=T(require("deepmerge"),1);var p=class{parent;constructor(e){this.parent=e}batch(e){return e(this),this}end(){return this.parent}};var o=class extends p{store;shorthands;constructor(e){super(e),this.store=new Map}extend(e){return this.shorthands=e,e.forEach(t=>{this[t]=s=>this.set(t,s)}),this}clear(){return this.store.clear(),this}delete(e){return this.store.delete(e),this}order(){let e=[...this.store].reduce((i,[r,l])=>(i[r]=l,i),{}),t=Object.keys(e),s=[...t];return t.forEach(i=>{if(!e[i])return;let{__before:r,__after:l}=e[i];r&&s.includes(r)?(s.splice(s.indexOf(i),1),s.splice(s.indexOf(r),0,i)):l&&s.includes(l)&&(s.splice(s.indexOf(i),1),s.splice(s.indexOf(l)+1,0,i))}),{entries:e,order:s}}entries(){let{entries:e,order:t}=this.order();if(t.length)return e}values(){let{entries:e,order:t}=this.order();return t.map(s=>e[s])}get(e){return this.store.get(e)}getOrCompute(e,t){return this.has(e)||this.set(e,t()),this.get(e)}has(e){return this.store.has(e)}set(e,t){return this.store.set(e,t),this}merge(e,t=[]){return Object.keys(e).forEach(s=>{if(t.includes(s))return;let i=e[s];!Array.isArray(i)&&typeof i!="object"||i===null||!this.has(s)?this.set(s,i):this.set(s,(0,k.default)(this.get(s),i))}),this}clean(e){return Object.keys(e).reduce((t,s)=>{let i=e[s];return i===void 0||Array.isArray(i)&&!i.length||Object.prototype.toString.call(i)==="[object Object]"&&!Object.keys(i).length||(t[s]=i),t},{})}when(e,t=Function.prototype,s=Function.prototype){return e?t(this):s(this),this}};var a=class extends p{store;constructor(e){super(e),this.store=new Set}add(e){return this.store.add(e),this}prepend(e){return this.store=new Set([e,...this.store]),this}clear(){return this.store.clear(),this}delete(e){return this.store.delete(e),this}values(){return[...this.store]}has(e){return this.store.has(e)}merge(e){return this.store=new Set([...this.store,...e]),this}when(e,t=Function.prototype,s=Function.prototype){return e?t(this):s(this),this}};var m=class extends o{allowedHosts;constructor(e){super(e),this.allowedHosts=new a(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(e,t=[]){return!t.includes("allowedHosts")&&"allowedHosts"in e&&this.allowedHosts.merge(e.allowedHosts),super.merge(e,["allowedHosts"])}};function d(n){return class extends n{__before;__after;before(e){if(this.__after)throw new Error(`Unable to set .before(${JSON.stringify(e)}) with existing value for .after()`);return this.__before=e,this}after(e){if(this.__before)throw new Error(`Unable to set .after(${JSON.stringify(e)}) with existing value for .before()`);return this.__after=e,this}merge(e,t=[]){return e.before&&this.before(e.before),e.after&&this.after(e.after),super.merge(e,[...t,"before","after"])}}}var F=class extends o{name;type;init;constructor(e,t,s="plugin"){super(e),this.name=t,this.type=s,this.extend(["init"]),this.init((i,r=[])=>typeof i=="function"?new i(...r):i)}use(e,t=[]){return this.set("plugin",e).set("args",t)}tap(e){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.`);return this.set("args",e(this.get("args")||[])),this}set(e,t){if(e==="args"&&!Array.isArray(t))throw new Error("args must be an array of arguments");return super.set(e,t)}merge(e,t=[]){return"plugin"in e&&this.set("plugin",e.plugin),"args"in e&&this.set("args",e.args),super.merge(e,[...t,"args","plugin"])}toConfig(){let e=this.get("init"),t=this.get("plugin"),s=this.get("args"),i=null;if(t===void 0)throw new Error(`Invalid ${this.type} configuration: ${this.type}('${this.name}').use(<Plugin>) was not called to specify the plugin`);typeof t=="string"&&(i=t,t=require(i));let r=t.__expression?`(${t.__expression})`:t.name,l=e(t,s);return Object.defineProperties(l,{__pluginName:{value:this.name},__pluginType:{value:this.type},__pluginArgs:{value:s},__pluginConstructorName:{value:r},__pluginPath:{value:i}}),l}},c=d(F);var h=class extends o{alias;aliasFields;descriptionFiles;extensions;mainFields;mainFiles;modules;plugins;constructor(e){super(e),this.alias=new o(this),this.aliasFields=new a(this),this.descriptionFiles=new a(this),this.extensions=new a(this),this.mainFields=new a(this),this.mainFiles=new a(this),this.modules=new a(this),this.plugins=new o(this),this.extend(["cachePredicate","cacheWithContext","concord","enforceExtension","enforceModuleExtension","symlinks","unsafeCache"])}plugin(e){return this.plugins.getOrCompute(e,()=>new c(this,e,"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(e=>e.toConfig())}))}merge(e,t=[]){let s=["alias","aliasFields","descriptionFiles","extensions","mainFields","mainFiles","modules"];return!t.includes("plugin")&&"plugin"in e&&Object.keys(e.plugin).forEach(i=>this.plugin(i).merge(e.plugin[i])),s.forEach(i=>{!t.includes(i)&&i in e&&this[i].merge(e[i])}),super.merge(e,[...t,...s,"plugin"])}};var $=T(require("deepmerge"),1);var S=class extends o{name;options;loader;constructor(e,t){super(e),this.name=t,this.extend(["loader","options"])}tap(e){return this.options(e(this.get("options"))),this}merge(e,t=[]){return!t.includes("loader")&&"loader"in e&&this.loader(e.loader),!t.includes("options")&&"options"in e&&this.options((0,$.default)(this.store.get("options")||{},e.options)),super.merge(e,[...t,"loader","options"])}toConfig(){let e=this.clean(this.entries()||{});return Object.defineProperties(e,{__useName:{value:this.name},__ruleNames:{value:this.parent?.names},__ruleTypes:{value:this.parent?.ruleTypes}}),e}},A=d(S);function N(n){return Array.isArray(n)?n:[n]}var R=class n extends o{name;names;ruleType;ruleTypes;uses;include;exclude;rules;oneOfs;resolve;enforce;test;constructor(e,t,s="rule"){super(e),this.name=t,this.names=[],this.ruleType=s,this.ruleTypes=[];let i=this;for(;i instanceof n;)this.names.unshift(i.name),this.ruleTypes.unshift(i.ruleType),i=i.parent;this.uses=new o(this),this.include=new a(this),this.exclude=new a(this),this.rules=new o(this),this.oneOfs=new o(this),this.resolve=new h(this),this.extend(["enforce","issuer","parser","resource","resourceQuery","sideEffects","test","type"])}use(e){return this.uses.getOrCompute(e,()=>new A(this,e))}rule(e){return this.rules.getOrCompute(e,()=>new n(this,e,"rule"))}oneOf(e){return this.oneOfs.getOrCompute(e,()=>new n(this,e,"oneOf"))}pre(){return this.enforce("pre")}post(){return this.enforce("post")}toConfig(){let e=this.clean(Object.assign(this.entries()||{},{include:this.include.values(),exclude:this.exclude.values(),rules:this.rules.values().map(t=>t.toConfig()),oneOf:this.oneOfs.values().map(t=>t.toConfig()),use:this.uses.values().map(t=>t.toConfig()),resolve:this.resolve.toConfig()}));return Object.defineProperties(e,{__ruleNames:{value:this.names},__ruleTypes:{value:this.ruleTypes}}),e}merge(e,t=[]){return!t.includes("include")&&"include"in e&&this.include.merge(N(e.include)),!t.includes("exclude")&&"exclude"in e&&this.exclude.merge(N(e.exclude)),!t.includes("use")&&"use"in e&&Object.keys(e.use).forEach(s=>this.use(s).merge(e.use[s])),!t.includes("rules")&&"rules"in e&&Object.keys(e.rules).forEach(s=>this.rule(s).merge(e.rules[s])),!t.includes("oneOf")&&"oneOf"in e&&Object.keys(e.oneOf).forEach(s=>this.oneOf(s).merge(e.oneOf[s])),!t.includes("resolve")&&"resolve"in e&&this.resolve.merge(e.resolve),!t.includes("test")&&"test"in e&&this.test(e.test instanceof RegExp||typeof e.test=="function"?e.test:new RegExp(e.test)),super.merge(e,[...t,"include","exclude","use","rules","oneOf","resolve","test"])}},J=d(R),z=J;var y=class extends o{rules;defaultRules;constructor(e){super(e),this.rules=new o(this),this.defaultRules=new o(this),this.extend(["noParse","strictExportPresence"])}defaultRule(e){return this.defaultRules.getOrCompute(e,()=>new z(this,e,"defaultRule"))}rule(e){return this.rules.getOrCompute(e,()=>new z(this,e,"rule"))}toConfig(){return this.clean(Object.assign(this.entries()||{},{defaultRules:this.defaultRules.values().map(e=>e.toConfig()),rules:this.rules.values().map(e=>e.toConfig())}))}merge(e,t=[]){return!t.includes("rule")&&"rule"in e&&Object.keys(e.rule).forEach(s=>this.rule(s).merge(e.rule[s])),!t.includes("defaultRule")&&"defaultRule"in e&&Object.keys(e.defaultRule).forEach(s=>this.defaultRule(s).merge(e.defaultRule[s])),super.merge(e,["rule","defaultRule"])}};var x=class extends o{minimizers;constructor(e){super(e),this.minimizers=new o(this),this.extend(["concatenateModules","flagIncludedChunks","mergeDuplicateChunks","minimize","namedChunks","namedModules","nodeEnv","noEmitOnErrors","occurrenceOrder","portableRecords","providedExports","removeAvailableModules","removeEmptyChunks","runtimeChunk","sideEffects","splitChunks","usedExports"])}minimizer(e){if(Array.isArray(e))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(e,()=>new c(this,e,"optimization.minimizer"))}toConfig(){return this.clean(Object.assign(this.entries()||{},{minimizer:this.minimizers.values().map(e=>e.toConfig())}))}merge(e,t=[]){return!t.includes("minimizer")&&"minimizer"in e&&Object.keys(e.minimizer).forEach(s=>this.minimizer(s).merge(e.minimizer[s])),super.merge(e,[...t,"minimizer"])}};var C=class extends o{constructor(e){super(e),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"])}};var w=class extends o{constructor(e){super(e),this.extend(["assetFilter","hints","maxAssetSize","maxEntrypointSize"])}};var v=class extends h{moduleExtensions;packageMains;constructor(e){super(e),this.moduleExtensions=new a(this),this.packageMains=new a(this)}toConfig(){return this.clean({moduleExtensions:this.moduleExtensions.values(),packageMains:this.packageMains.values(),...super.toConfig()})}merge(e,t=[]){let s=["moduleExtensions","packageMains"];return s.forEach(i=>{!t.includes(i)&&i in e&&this[i].merge(e[i])}),super.merge(e,[...t,...s])}};var O=class n extends o{devServer;entryPoints;module;node;optimization;output;performance;plugins;resolve;resolveLoader;constructor(){super({}),this.devServer=new m(this),this.entryPoints=new o(this),this.module=new y(this),this.node=new o(this),this.optimization=new x(this),this.output=new C(this),this.performance=new w(this),this.plugins=new o(this),this.resolve=new h(this),this.resolveLoader=new v(this),this.extend(["amd","bail","cache","context","devtool","externals","loader","mode","name","parallelism","profile","recordsInputPath","recordsPath","recordsOutputPath","stats","target","watch","watchOptions"])}static toString(e,{verbose:t=!1,configPrefix:s="config"}={}){let{stringify:i}=require("javascript-stringify");return i(e,(r,l,g)=>{if(r&&r.__pluginName){let f=`/* ${s}.${r.__pluginType}('${r.__pluginName}') */
|
|
2
|
+
`,E=r.__pluginPath?`(require(${g(r.__pluginPath)}))`:r.__pluginConstructorName;if(E){let M=g(r.__pluginArgs).slice(1,-1);return`${f}new ${E}(${M})`}return f+g(r.__pluginArgs&&r.__pluginArgs.length?{args:r.__pluginArgs}:{})}if(r&&r.__ruleNames){let f=r.__ruleTypes;return`/* ${s}.module${r.__ruleNames.map((M,b)=>`.${f?f[b]:"rule"}('${M}')`).join("")}${r.__useName?`.use('${r.__useName}')`:""} */
|
|
3
|
+
`+g(r)}return r&&r.__expression?r.__expression:typeof r=="function"&&!t&&r.toString().length>100?"function () { /* omitted long function */ }":g(r)},2)}entry(e){return this.entryPoints.getOrCompute(e,()=>new a(this))}plugin(e){return this.plugins.getOrCompute(e,()=>new c(this,e))}toConfig(){let e=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(t=>t.toConfig()),performance:this.performance.entries(),entry:Object.keys(e).reduce((t,s)=>Object.assign(t,{[s]:e[s].values()}),{})}))}toString(e){return n.toString(this.toConfig(),e)}merge(e={},t=[]){let s=["node","output","resolve","resolveLoader","devServer","optimization","performance","module"];return!t.includes("entry")&&"entry"in e&&Object.keys(e.entry).forEach(i=>this.entry(i).merge([].concat(e.entry[i]))),!t.includes("plugin")&&"plugin"in e&&Object.keys(e.plugin).forEach(i=>this.plugin(i).merge(e.plugin[i])),s.forEach(i=>{!t.includes(i)&&i in e&&this[i].merge(e[i])}),super.merge(e,[...t,...s,"entry","plugin"])}};
|
|
4
|
+
if (module.exports.default) module.exports = module.exports.default;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
declare class Chainable {
|
|
2
|
+
parent: any;
|
|
3
|
+
constructor(parent: any);
|
|
4
|
+
batch(handler: (instance: this) => void): this;
|
|
5
|
+
end(): any;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
declare class ChainedMap extends Chainable {
|
|
9
|
+
store: Map<string, any>;
|
|
10
|
+
shorthands?: string[];
|
|
11
|
+
constructor(parent: any);
|
|
12
|
+
extend(methods: string[]): this;
|
|
13
|
+
clear(): this;
|
|
14
|
+
delete(key: string): this;
|
|
15
|
+
order(): {
|
|
16
|
+
entries: Record<string, any>;
|
|
17
|
+
order: string[];
|
|
18
|
+
};
|
|
19
|
+
entries(): Record<string, any> | undefined;
|
|
20
|
+
values(): any[];
|
|
21
|
+
get(key: string): any;
|
|
22
|
+
getOrCompute(key: string, fn: () => any): any;
|
|
23
|
+
has(key: string): boolean;
|
|
24
|
+
set(key: string, value: any): this;
|
|
25
|
+
merge(obj: Record<string, any>, omit?: string[]): this;
|
|
26
|
+
clean(obj: Record<string, any>): Record<string, any>;
|
|
27
|
+
when(condition: any, whenTruthy?: (instance: this) => void, whenFalsy?: (instance: this) => void): this;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
declare class ChainedSet extends Chainable {
|
|
31
|
+
store: Set<any>;
|
|
32
|
+
constructor(parent: any);
|
|
33
|
+
add(value: any): this;
|
|
34
|
+
prepend(value: any): this;
|
|
35
|
+
clear(): this;
|
|
36
|
+
delete(value: any): this;
|
|
37
|
+
values(): any[];
|
|
38
|
+
has(value: any): boolean;
|
|
39
|
+
merge(arr: any[]): this;
|
|
40
|
+
when(condition: any, whenTruthy?: (instance: this) => void, whenFalsy?: (instance: this) => void): this;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
declare class DevServer extends ChainedMap {
|
|
44
|
+
allowedHosts: ChainedSet;
|
|
45
|
+
constructor(parent: any);
|
|
46
|
+
toConfig(): any;
|
|
47
|
+
merge(obj: any, omit?: string[]): this;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
declare class Module extends ChainedMap {
|
|
51
|
+
rules: ChainedMap;
|
|
52
|
+
defaultRules: ChainedMap;
|
|
53
|
+
constructor(parent: any);
|
|
54
|
+
defaultRule(name: string): any;
|
|
55
|
+
rule(name: string): any;
|
|
56
|
+
toConfig(): any;
|
|
57
|
+
merge(obj: any, omit?: string[]): this;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
declare class Optimization extends ChainedMap {
|
|
61
|
+
minimizers: ChainedMap;
|
|
62
|
+
constructor(parent: any);
|
|
63
|
+
minimizer(name: string | any[]): any;
|
|
64
|
+
toConfig(): any;
|
|
65
|
+
merge(obj: any, omit?: string[]): this;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
declare class Output extends ChainedMap {
|
|
69
|
+
constructor(parent: any);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
declare class Performance extends ChainedMap {
|
|
73
|
+
constructor(parent: any);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
declare class Resolve extends ChainedMap {
|
|
77
|
+
alias: ChainedMap;
|
|
78
|
+
aliasFields: ChainedSet;
|
|
79
|
+
descriptionFiles: ChainedSet;
|
|
80
|
+
extensions: ChainedSet;
|
|
81
|
+
mainFields: ChainedSet;
|
|
82
|
+
mainFiles: ChainedSet;
|
|
83
|
+
modules: ChainedSet;
|
|
84
|
+
plugins: ChainedMap;
|
|
85
|
+
constructor(parent: any);
|
|
86
|
+
plugin(name: string): any;
|
|
87
|
+
toConfig(): any;
|
|
88
|
+
merge(obj: any, omit?: string[]): this;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
declare class ResolveLoader extends Resolve {
|
|
92
|
+
moduleExtensions: ChainedSet;
|
|
93
|
+
packageMains: ChainedSet;
|
|
94
|
+
constructor(parent: any);
|
|
95
|
+
toConfig(): any;
|
|
96
|
+
merge(obj: any, omit?: string[]): this;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
declare class Config extends ChainedMap {
|
|
100
|
+
devServer: DevServer;
|
|
101
|
+
entryPoints: ChainedMap;
|
|
102
|
+
module: Module;
|
|
103
|
+
node: ChainedMap;
|
|
104
|
+
optimization: Optimization;
|
|
105
|
+
output: Output;
|
|
106
|
+
performance: Performance;
|
|
107
|
+
plugins: ChainedMap;
|
|
108
|
+
resolve: Resolve;
|
|
109
|
+
resolveLoader: ResolveLoader;
|
|
110
|
+
constructor();
|
|
111
|
+
static toString(config: any, { verbose, configPrefix }?: {
|
|
112
|
+
verbose?: boolean | undefined;
|
|
113
|
+
configPrefix?: string | undefined;
|
|
114
|
+
}): string;
|
|
115
|
+
entry(name: string): ChainedSet;
|
|
116
|
+
plugin(name: string): any;
|
|
117
|
+
toConfig(): any;
|
|
118
|
+
toString(options?: any): string;
|
|
119
|
+
merge(obj?: any, omit?: string[]): this;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export { Config as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
declare class Chainable {
|
|
2
|
+
parent: any;
|
|
3
|
+
constructor(parent: any);
|
|
4
|
+
batch(handler: (instance: this) => void): this;
|
|
5
|
+
end(): any;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
declare class ChainedMap extends Chainable {
|
|
9
|
+
store: Map<string, any>;
|
|
10
|
+
shorthands?: string[];
|
|
11
|
+
constructor(parent: any);
|
|
12
|
+
extend(methods: string[]): this;
|
|
13
|
+
clear(): this;
|
|
14
|
+
delete(key: string): this;
|
|
15
|
+
order(): {
|
|
16
|
+
entries: Record<string, any>;
|
|
17
|
+
order: string[];
|
|
18
|
+
};
|
|
19
|
+
entries(): Record<string, any> | undefined;
|
|
20
|
+
values(): any[];
|
|
21
|
+
get(key: string): any;
|
|
22
|
+
getOrCompute(key: string, fn: () => any): any;
|
|
23
|
+
has(key: string): boolean;
|
|
24
|
+
set(key: string, value: any): this;
|
|
25
|
+
merge(obj: Record<string, any>, omit?: string[]): this;
|
|
26
|
+
clean(obj: Record<string, any>): Record<string, any>;
|
|
27
|
+
when(condition: any, whenTruthy?: (instance: this) => void, whenFalsy?: (instance: this) => void): this;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
declare class ChainedSet extends Chainable {
|
|
31
|
+
store: Set<any>;
|
|
32
|
+
constructor(parent: any);
|
|
33
|
+
add(value: any): this;
|
|
34
|
+
prepend(value: any): this;
|
|
35
|
+
clear(): this;
|
|
36
|
+
delete(value: any): this;
|
|
37
|
+
values(): any[];
|
|
38
|
+
has(value: any): boolean;
|
|
39
|
+
merge(arr: any[]): this;
|
|
40
|
+
when(condition: any, whenTruthy?: (instance: this) => void, whenFalsy?: (instance: this) => void): this;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
declare class DevServer extends ChainedMap {
|
|
44
|
+
allowedHosts: ChainedSet;
|
|
45
|
+
constructor(parent: any);
|
|
46
|
+
toConfig(): any;
|
|
47
|
+
merge(obj: any, omit?: string[]): this;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
declare class Module extends ChainedMap {
|
|
51
|
+
rules: ChainedMap;
|
|
52
|
+
defaultRules: ChainedMap;
|
|
53
|
+
constructor(parent: any);
|
|
54
|
+
defaultRule(name: string): any;
|
|
55
|
+
rule(name: string): any;
|
|
56
|
+
toConfig(): any;
|
|
57
|
+
merge(obj: any, omit?: string[]): this;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
declare class Optimization extends ChainedMap {
|
|
61
|
+
minimizers: ChainedMap;
|
|
62
|
+
constructor(parent: any);
|
|
63
|
+
minimizer(name: string | any[]): any;
|
|
64
|
+
toConfig(): any;
|
|
65
|
+
merge(obj: any, omit?: string[]): this;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
declare class Output extends ChainedMap {
|
|
69
|
+
constructor(parent: any);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
declare class Performance extends ChainedMap {
|
|
73
|
+
constructor(parent: any);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
declare class Resolve extends ChainedMap {
|
|
77
|
+
alias: ChainedMap;
|
|
78
|
+
aliasFields: ChainedSet;
|
|
79
|
+
descriptionFiles: ChainedSet;
|
|
80
|
+
extensions: ChainedSet;
|
|
81
|
+
mainFields: ChainedSet;
|
|
82
|
+
mainFiles: ChainedSet;
|
|
83
|
+
modules: ChainedSet;
|
|
84
|
+
plugins: ChainedMap;
|
|
85
|
+
constructor(parent: any);
|
|
86
|
+
plugin(name: string): any;
|
|
87
|
+
toConfig(): any;
|
|
88
|
+
merge(obj: any, omit?: string[]): this;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
declare class ResolveLoader extends Resolve {
|
|
92
|
+
moduleExtensions: ChainedSet;
|
|
93
|
+
packageMains: ChainedSet;
|
|
94
|
+
constructor(parent: any);
|
|
95
|
+
toConfig(): any;
|
|
96
|
+
merge(obj: any, omit?: string[]): this;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
declare class Config extends ChainedMap {
|
|
100
|
+
devServer: DevServer;
|
|
101
|
+
entryPoints: ChainedMap;
|
|
102
|
+
module: Module;
|
|
103
|
+
node: ChainedMap;
|
|
104
|
+
optimization: Optimization;
|
|
105
|
+
output: Output;
|
|
106
|
+
performance: Performance;
|
|
107
|
+
plugins: ChainedMap;
|
|
108
|
+
resolve: Resolve;
|
|
109
|
+
resolveLoader: ResolveLoader;
|
|
110
|
+
constructor();
|
|
111
|
+
static toString(config: any, { verbose, configPrefix }?: {
|
|
112
|
+
verbose?: boolean | undefined;
|
|
113
|
+
configPrefix?: string | undefined;
|
|
114
|
+
}): string;
|
|
115
|
+
entry(name: string): ChainedSet;
|
|
116
|
+
plugin(name: string): any;
|
|
117
|
+
toConfig(): any;
|
|
118
|
+
toString(options?: any): string;
|
|
119
|
+
merge(obj?: any, omit?: string[]): this;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export { Config as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import {createRequire as __createRequire} from 'module';var require=__createRequire(import.meta.url);
|
|
2
|
+
var M=(o=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(o,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):o)(function(o){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+o+'" is not supported')});import A from"deepmerge";var d=class{parent;constructor(e){this.parent=e}batch(e){return e(this),this}end(){return this.parent}};var r=class extends d{store;shorthands;constructor(e){super(e),this.store=new Map}extend(e){return this.shorthands=e,e.forEach(t=>{this[t]=s=>this.set(t,s)}),this}clear(){return this.store.clear(),this}delete(e){return this.store.delete(e),this}order(){let e=[...this.store].reduce((i,[n,h])=>(i[n]=h,i),{}),t=Object.keys(e),s=[...t];return t.forEach(i=>{if(!e[i])return;let{__before:n,__after:h}=e[i];n&&s.includes(n)?(s.splice(s.indexOf(i),1),s.splice(s.indexOf(n),0,i)):h&&s.includes(h)&&(s.splice(s.indexOf(i),1),s.splice(s.indexOf(h)+1,0,i))}),{entries:e,order:s}}entries(){let{entries:e,order:t}=this.order();if(t.length)return e}values(){let{entries:e,order:t}=this.order();return t.map(s=>e[s])}get(e){return this.store.get(e)}getOrCompute(e,t){return this.has(e)||this.set(e,t()),this.get(e)}has(e){return this.store.has(e)}set(e,t){return this.store.set(e,t),this}merge(e,t=[]){return Object.keys(e).forEach(s=>{if(t.includes(s))return;let i=e[s];!Array.isArray(i)&&typeof i!="object"||i===null||!this.has(s)?this.set(s,i):this.set(s,A(this.get(s),i))}),this}clean(e){return Object.keys(e).reduce((t,s)=>{let i=e[s];return i===void 0||Array.isArray(i)&&!i.length||Object.prototype.toString.call(i)==="[object Object]"&&!Object.keys(i).length||(t[s]=i),t},{})}when(e,t=Function.prototype,s=Function.prototype){return e?t(this):s(this),this}};var a=class extends d{store;constructor(e){super(e),this.store=new Set}add(e){return this.store.add(e),this}prepend(e){return this.store=new Set([e,...this.store]),this}clear(){return this.store.clear(),this}delete(e){return this.store.delete(e),this}values(){return[...this.store]}has(e){return this.store.has(e)}merge(e){return this.store=new Set([...this.store,...e]),this}when(e,t=Function.prototype,s=Function.prototype){return e?t(this):s(this),this}};var y=class extends r{allowedHosts;constructor(e){super(e),this.allowedHosts=new a(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(e,t=[]){return!t.includes("allowedHosts")&&"allowedHosts"in e&&this.allowedHosts.merge(e.allowedHosts),super.merge(e,["allowedHosts"])}};function c(o){return class extends o{__before;__after;before(e){if(this.__after)throw new Error(`Unable to set .before(${JSON.stringify(e)}) with existing value for .after()`);return this.__before=e,this}after(e){if(this.__before)throw new Error(`Unable to set .after(${JSON.stringify(e)}) with existing value for .before()`);return this.__after=e,this}merge(e,t=[]){return e.before&&this.before(e.before),e.after&&this.after(e.after),super.merge(e,[...t,"before","after"])}}}var F=class extends r{name;type;init;constructor(e,t,s="plugin"){super(e),this.name=t,this.type=s,this.extend(["init"]),this.init((i,n=[])=>typeof i=="function"?new i(...n):i)}use(e,t=[]){return this.set("plugin",e).set("args",t)}tap(e){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.`);return this.set("args",e(this.get("args")||[])),this}set(e,t){if(e==="args"&&!Array.isArray(t))throw new Error("args must be an array of arguments");return super.set(e,t)}merge(e,t=[]){return"plugin"in e&&this.set("plugin",e.plugin),"args"in e&&this.set("args",e.args),super.merge(e,[...t,"args","plugin"])}toConfig(){let e=this.get("init"),t=this.get("plugin"),s=this.get("args"),i=null;if(t===void 0)throw new Error(`Invalid ${this.type} configuration: ${this.type}('${this.name}').use(<Plugin>) was not called to specify the plugin`);typeof t=="string"&&(i=t,t=M(i));let n=t.__expression?`(${t.__expression})`:t.name,h=e(t,s);return Object.defineProperties(h,{__pluginName:{value:this.name},__pluginType:{value:this.type},__pluginArgs:{value:s},__pluginConstructorName:{value:n},__pluginPath:{value:i}}),h}},g=c(F);var p=class extends r{alias;aliasFields;descriptionFiles;extensions;mainFields;mainFiles;modules;plugins;constructor(e){super(e),this.alias=new r(this),this.aliasFields=new a(this),this.descriptionFiles=new a(this),this.extensions=new a(this),this.mainFields=new a(this),this.mainFiles=new a(this),this.modules=new a(this),this.plugins=new r(this),this.extend(["cachePredicate","cacheWithContext","concord","enforceExtension","enforceModuleExtension","symlinks","unsafeCache"])}plugin(e){return this.plugins.getOrCompute(e,()=>new g(this,e,"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(e=>e.toConfig())}))}merge(e,t=[]){let s=["alias","aliasFields","descriptionFiles","extensions","mainFields","mainFiles","modules"];return!t.includes("plugin")&&"plugin"in e&&Object.keys(e.plugin).forEach(i=>this.plugin(i).merge(e.plugin[i])),s.forEach(i=>{!t.includes(i)&&i in e&&this[i].merge(e[i])}),super.merge(e,[...t,...s,"plugin"])}};import N from"deepmerge";var S=class extends r{name;options;loader;constructor(e,t){super(e),this.name=t,this.extend(["loader","options"])}tap(e){return this.options(e(this.get("options"))),this}merge(e,t=[]){return!t.includes("loader")&&"loader"in e&&this.loader(e.loader),!t.includes("options")&&"options"in e&&this.options(N(this.store.get("options")||{},e.options)),super.merge(e,[...t,"loader","options"])}toConfig(){let e=this.clean(this.entries()||{});return Object.defineProperties(e,{__useName:{value:this.name},__ruleNames:{value:this.parent?.names},__ruleTypes:{value:this.parent?.ruleTypes}}),e}},T=c(S);function k(o){return Array.isArray(o)?o:[o]}var R=class o extends r{name;names;ruleType;ruleTypes;uses;include;exclude;rules;oneOfs;resolve;enforce;test;constructor(e,t,s="rule"){super(e),this.name=t,this.names=[],this.ruleType=s,this.ruleTypes=[];let i=this;for(;i instanceof o;)this.names.unshift(i.name),this.ruleTypes.unshift(i.ruleType),i=i.parent;this.uses=new r(this),this.include=new a(this),this.exclude=new a(this),this.rules=new r(this),this.oneOfs=new r(this),this.resolve=new p(this),this.extend(["enforce","issuer","parser","resource","resourceQuery","sideEffects","test","type"])}use(e){return this.uses.getOrCompute(e,()=>new T(this,e))}rule(e){return this.rules.getOrCompute(e,()=>new o(this,e,"rule"))}oneOf(e){return this.oneOfs.getOrCompute(e,()=>new o(this,e,"oneOf"))}pre(){return this.enforce("pre")}post(){return this.enforce("post")}toConfig(){let e=this.clean(Object.assign(this.entries()||{},{include:this.include.values(),exclude:this.exclude.values(),rules:this.rules.values().map(t=>t.toConfig()),oneOf:this.oneOfs.values().map(t=>t.toConfig()),use:this.uses.values().map(t=>t.toConfig()),resolve:this.resolve.toConfig()}));return Object.defineProperties(e,{__ruleNames:{value:this.names},__ruleTypes:{value:this.ruleTypes}}),e}merge(e,t=[]){return!t.includes("include")&&"include"in e&&this.include.merge(k(e.include)),!t.includes("exclude")&&"exclude"in e&&this.exclude.merge(k(e.exclude)),!t.includes("use")&&"use"in e&&Object.keys(e.use).forEach(s=>this.use(s).merge(e.use[s])),!t.includes("rules")&&"rules"in e&&Object.keys(e.rules).forEach(s=>this.rule(s).merge(e.rules[s])),!t.includes("oneOf")&&"oneOf"in e&&Object.keys(e.oneOf).forEach(s=>this.oneOf(s).merge(e.oneOf[s])),!t.includes("resolve")&&"resolve"in e&&this.resolve.merge(e.resolve),!t.includes("test")&&"test"in e&&this.test(e.test instanceof RegExp||typeof e.test=="function"?e.test:new RegExp(e.test)),super.merge(e,[...t,"include","exclude","use","rules","oneOf","resolve","test"])}},b=c(R),z=b;var x=class extends r{rules;defaultRules;constructor(e){super(e),this.rules=new r(this),this.defaultRules=new r(this),this.extend(["noParse","strictExportPresence"])}defaultRule(e){return this.defaultRules.getOrCompute(e,()=>new z(this,e,"defaultRule"))}rule(e){return this.rules.getOrCompute(e,()=>new z(this,e,"rule"))}toConfig(){return this.clean(Object.assign(this.entries()||{},{defaultRules:this.defaultRules.values().map(e=>e.toConfig()),rules:this.rules.values().map(e=>e.toConfig())}))}merge(e,t=[]){return!t.includes("rule")&&"rule"in e&&Object.keys(e.rule).forEach(s=>this.rule(s).merge(e.rule[s])),!t.includes("defaultRule")&&"defaultRule"in e&&Object.keys(e.defaultRule).forEach(s=>this.defaultRule(s).merge(e.defaultRule[s])),super.merge(e,["rule","defaultRule"])}};var C=class extends r{minimizers;constructor(e){super(e),this.minimizers=new r(this),this.extend(["concatenateModules","flagIncludedChunks","mergeDuplicateChunks","minimize","namedChunks","namedModules","nodeEnv","noEmitOnErrors","occurrenceOrder","portableRecords","providedExports","removeAvailableModules","removeEmptyChunks","runtimeChunk","sideEffects","splitChunks","usedExports"])}minimizer(e){if(Array.isArray(e))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(e,()=>new g(this,e,"optimization.minimizer"))}toConfig(){return this.clean(Object.assign(this.entries()||{},{minimizer:this.minimizers.values().map(e=>e.toConfig())}))}merge(e,t=[]){return!t.includes("minimizer")&&"minimizer"in e&&Object.keys(e.minimizer).forEach(s=>this.minimizer(s).merge(e.minimizer[s])),super.merge(e,[...t,"minimizer"])}};var w=class extends r{constructor(e){super(e),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"])}};var v=class extends r{constructor(e){super(e),this.extend(["assetFilter","hints","maxAssetSize","maxEntrypointSize"])}};var _=class extends p{moduleExtensions;packageMains;constructor(e){super(e),this.moduleExtensions=new a(this),this.packageMains=new a(this)}toConfig(){return this.clean({moduleExtensions:this.moduleExtensions.values(),packageMains:this.packageMains.values(),...super.toConfig()})}merge(e,t=[]){let s=["moduleExtensions","packageMains"];return s.forEach(i=>{!t.includes(i)&&i in e&&this[i].merge(e[i])}),super.merge(e,[...t,...s])}};var P=class o extends r{devServer;entryPoints;module;node;optimization;output;performance;plugins;resolve;resolveLoader;constructor(){super({}),this.devServer=new y(this),this.entryPoints=new r(this),this.module=new x(this),this.node=new r(this),this.optimization=new C(this),this.output=new w(this),this.performance=new v(this),this.plugins=new r(this),this.resolve=new p(this),this.resolveLoader=new _(this),this.extend(["amd","bail","cache","context","devtool","externals","loader","mode","name","parallelism","profile","recordsInputPath","recordsPath","recordsOutputPath","stats","target","watch","watchOptions"])}static toString(e,{verbose:t=!1,configPrefix:s="config"}={}){let{stringify:i}=M("javascript-stringify");return i(e,(n,h,f)=>{if(n&&n.__pluginName){let m=`/* ${s}.${n.__pluginType}('${n.__pluginName}') */
|
|
3
|
+
`,O=n.__pluginPath?`(require(${f(n.__pluginPath)}))`:n.__pluginConstructorName;if(O){let E=f(n.__pluginArgs).slice(1,-1);return`${m}new ${O}(${E})`}return m+f(n.__pluginArgs&&n.__pluginArgs.length?{args:n.__pluginArgs}:{})}if(n&&n.__ruleNames){let m=n.__ruleTypes;return`/* ${s}.module${n.__ruleNames.map((E,$)=>`.${m?m[$]:"rule"}('${E}')`).join("")}${n.__useName?`.use('${n.__useName}')`:""} */
|
|
4
|
+
`+f(n)}return n&&n.__expression?n.__expression:typeof n=="function"&&!t&&n.toString().length>100?"function () { /* omitted long function */ }":f(n)},2)}entry(e){return this.entryPoints.getOrCompute(e,()=>new a(this))}plugin(e){return this.plugins.getOrCompute(e,()=>new g(this,e))}toConfig(){let e=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(t=>t.toConfig()),performance:this.performance.entries(),entry:Object.keys(e).reduce((t,s)=>Object.assign(t,{[s]:e[s].values()}),{})}))}toString(e){return o.toString(this.toConfig(),e)}merge(e={},t=[]){let s=["node","output","resolve","resolveLoader","devServer","optimization","performance","module"];return!t.includes("entry")&&"entry"in e&&Object.keys(e.entry).forEach(i=>this.entry(i).merge([].concat(e.entry[i]))),!t.includes("plugin")&&"plugin"in e&&Object.keys(e.plugin).forEach(i=>this.plugin(i).merge(e.plugin[i])),s.forEach(i=>{!t.includes(i)&&i in e&&this[i].merge(e[i])}),super.merge(e,[...t,...s,"entry","plugin"])}};export{P as default};
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@empjs/chain",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "emp chain",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"maintainers": [
|
|
11
|
+
"xuhongbin",
|
|
12
|
+
"ckken"
|
|
13
|
+
],
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/empjs/emp.git",
|
|
17
|
+
"directory": "packages/emp-chain"
|
|
18
|
+
},
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"webpack",
|
|
24
|
+
"config",
|
|
25
|
+
"chain",
|
|
26
|
+
"fluent",
|
|
27
|
+
"api"
|
|
28
|
+
],
|
|
29
|
+
"main": "dist/index.js",
|
|
30
|
+
"types": "dist/index.d.ts",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"import": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"default": "./dist/index.js"
|
|
36
|
+
},
|
|
37
|
+
"require": {
|
|
38
|
+
"types": "./dist/index.d.cts",
|
|
39
|
+
"default": "./dist/index.cjs"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=16.0.0"
|
|
45
|
+
},
|
|
46
|
+
"author": "Ken",
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/node": "^24.1.0",
|
|
49
|
+
"tsup": "^8.1.0"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"deepmerge": "^1.5.2",
|
|
53
|
+
"javascript-stringify": "^2.0.1"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "tsup",
|
|
57
|
+
"dev": "tsup --watch"
|
|
58
|
+
}
|
|
59
|
+
}
|