@umijs/core 3.5.20 → 4.0.0-beta.12

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.
Files changed (103) hide show
  1. package/README.md +2 -0
  2. package/compiled/@hapi/joi/index.d.ts +2219 -0
  3. package/compiled/@hapi/joi/index.js +1 -0
  4. package/compiled/@hapi/joi/package.json +1 -0
  5. package/compiled/dotenv/LICENSE +23 -0
  6. package/compiled/dotenv/index.js +1 -0
  7. package/compiled/dotenv/package.json +1 -0
  8. package/compiled/dotenv/types/index.d.ts +59 -0
  9. package/compiled/just-diff/LICENSE +21 -0
  10. package/compiled/just-diff/index.d.ts +20 -0
  11. package/compiled/just-diff/index.js +1 -0
  12. package/compiled/just-diff/package.json +1 -0
  13. package/compiled/tapable/LICENSE +21 -0
  14. package/compiled/tapable/index.js +1 -0
  15. package/compiled/tapable/package.json +1 -0
  16. package/compiled/tapable/tapable.d.ts +116 -0
  17. package/dist/config/config.d.ts +63 -0
  18. package/dist/config/config.js +183 -0
  19. package/dist/config/utils.d.ts +8 -0
  20. package/dist/config/utils.js +15 -0
  21. package/dist/constants.d.ts +9 -0
  22. package/dist/constants.js +12 -0
  23. package/dist/index.d.ts +6 -0
  24. package/dist/index.js +21 -0
  25. package/dist/route/defineRoutes.d.ts +1 -0
  26. package/dist/route/defineRoutes.js +28 -0
  27. package/dist/route/route.d.ts +3 -0
  28. package/dist/route/route.js +19 -0
  29. package/dist/route/routeUtils.d.ts +7 -0
  30. package/dist/route/routeUtils.js +21 -0
  31. package/dist/route/routesConfig.d.ts +5 -0
  32. package/dist/route/routesConfig.js +37 -0
  33. package/dist/route/routesConvention.d.ts +4 -0
  34. package/dist/route/routesConvention.js +73 -0
  35. package/dist/route/utils.d.ts +7 -0
  36. package/dist/route/utils.js +26 -0
  37. package/dist/service/command.d.ts +27 -0
  38. package/dist/service/command.js +14 -0
  39. package/dist/service/env.d.ts +4 -0
  40. package/dist/service/env.js +21 -0
  41. package/dist/service/generatePlugin.d.ts +4 -0
  42. package/dist/service/generatePlugin.js +91 -0
  43. package/dist/service/generator.d.ts +60 -0
  44. package/dist/service/generator.js +20 -0
  45. package/dist/service/hook.d.ts +16 -0
  46. package/dist/service/hook.js +18 -0
  47. package/dist/service/path.d.ts +13 -0
  48. package/dist/service/path.js +31 -0
  49. package/dist/service/plugin.d.ts +56 -0
  50. package/dist/service/plugin.js +147 -0
  51. package/dist/service/pluginAPI.d.ts +44 -0
  52. package/dist/service/pluginAPI.js +146 -0
  53. package/dist/service/service.d.ts +99 -0
  54. package/dist/service/service.js +355 -0
  55. package/dist/service/servicePlugin.d.ts +3 -0
  56. package/dist/service/servicePlugin.js +14 -0
  57. package/dist/service/utils.d.ts +2 -0
  58. package/dist/service/utils.js +12 -0
  59. package/dist/types.d.ts +108 -0
  60. package/dist/types.js +42 -0
  61. package/package.json +42 -21
  62. package/lib/Config/Config.d.ts +0 -39
  63. package/lib/Config/Config.js +0 -348
  64. package/lib/Config/types.d.ts +0 -21
  65. package/lib/Config/utils/configUtils.d.ts +0 -9
  66. package/lib/Config/utils/configUtils.js +0 -54
  67. package/lib/Config/utils/isEqual.d.ts +0 -1
  68. package/lib/Config/utils/isEqual.js +0 -45
  69. package/lib/Config/utils/mergeDefault.d.ts +0 -6
  70. package/lib/Config/utils/mergeDefault.js +0 -41
  71. package/lib/Html/Html.d.ts +0 -16
  72. package/lib/Html/Html.js +0 -292
  73. package/lib/Html/document.ejs +0 -12
  74. package/lib/Html/types.d.ts +0 -55
  75. package/lib/Logger/Common.d.ts +0 -13
  76. package/lib/Logger/Common.js +0 -53
  77. package/lib/Logger/Logger.d.ts +0 -17
  78. package/lib/Logger/Logger.js +0 -87
  79. package/lib/Route/Route.d.ts +0 -32
  80. package/lib/Route/Route.js +0 -228
  81. package/lib/Route/getConventionalRoutes.d.ts +0 -10
  82. package/lib/Route/getConventionalRoutes.js +0 -259
  83. package/lib/Route/routesToJSON.d.ts +0 -9
  84. package/lib/Route/routesToJSON.js +0 -140
  85. package/lib/Route/types.d.ts +0 -11
  86. package/lib/Service/PluginAPI.d.ts +0 -38
  87. package/lib/Service/PluginAPI.js +0 -193
  88. package/lib/Service/Service.d.ts +0 -96
  89. package/lib/Service/Service.js +0 -694
  90. package/lib/Service/enums.d.ts +0 -29
  91. package/lib/Service/enums.js +0 -67
  92. package/lib/Service/getPaths.d.ts +0 -6
  93. package/lib/Service/getPaths.js +0 -79
  94. package/lib/Service/types.d.ts +0 -52
  95. package/lib/Service/types.js +0 -17
  96. package/lib/Service/utils/isPromise.d.ts +0 -1
  97. package/lib/Service/utils/isPromise.js +0 -22
  98. package/lib/Service/utils/loadDotEnv.d.ts +0 -5
  99. package/lib/Service/utils/loadDotEnv.js +0 -54
  100. package/lib/Service/utils/pluginUtils.d.ts +0 -42
  101. package/lib/Service/utils/pluginUtils.js +0 -201
  102. package/lib/index.d.ts +0 -14
  103. package/lib/index.js +0 -81
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 angus croll
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,20 @@
1
+ // Definitions by: Cameron Hunter <https://github.com/cameronhunter>
2
+ // Modified by: Angus Croll <https://github.com/angus-c>
3
+ type Operation = "add" | "replace" | "remove";
4
+
5
+ type JSONPatchPathConverter<OUTPUT> = (
6
+ arrayPath: Array<string | number>
7
+ ) => OUTPUT;
8
+
9
+ export function diff(
10
+ a: object | Array<any>,
11
+ b: object | Array<any>,
12
+ ): Array<{ op: Operation; path: Array<string | number>; value: any }>;
13
+
14
+ export function diff<PATH>(
15
+ a: object | Array<any>,
16
+ b: object | Array<any>,
17
+ jsonPatchPathConverter: JSONPatchPathConverter<PATH>
18
+ ): Array<{ op: Operation; path: PATH; value: any }>;
19
+
20
+ export const jsonPatchPathConverter: JSONPatchPathConverter<string>;
@@ -0,0 +1 @@
1
+ (function(){var e={784:function(e){e.exports={diff:diff,jsonPatchPathConverter:jsonPatchPathConverter};function diff(e,r,t){if(!e||typeof e!="object"||!r||typeof r!="object"){throw new Error("both arguments must be objects or arrays")}t||(t=function(e){return e});function getDiff(e,r,a,n){var o=Object.keys(e);var c=o.length;var i=Object.keys(r);var f=i.length;var u;for(var p=0;p<c;p++){var s=Array.isArray(e)?Number(o[p]):o[p];if(!(s in r)){u=a.concat(s);n.remove.push({op:"remove",path:t(u)})}}for(var p=0;p<f;p++){var s=Array.isArray(r)?Number(i[p]):i[p];var v=e[s];var _=r[s];if(!(s in e)){u=a.concat(s);var h=r[s];n.add.push({op:"add",path:t(u),value:h})}else if(v!==_){if(Object(v)!==v||Object(_)!==_){u=pushReplace(u,a,s,n,t,r)}else{if(!Object.keys(v).length&&!Object.keys(_).length&&String(v)!=String(_)){u=pushReplace(u,a,s,n,t,r)}else{getDiff(e[s],r[s],a.concat(s),n)}}}}return n.remove.reverse().concat(n.replace).concat(n.add)}return getDiff(e,r,[],{remove:[],replace:[],add:[]})}function pushReplace(e,r,t,a,n,o){e=r.concat(t);a.replace.push({op:"replace",path:n(e),value:o[t]});return e}function jsonPatchPathConverter(e){return[""].concat(e).join("/")}}};var r={};function __nccwpck_require__(t){var a=r[t];if(a!==undefined){return a.exports}var n=r[t]={exports:{}};var o=true;try{e[t](n,n.exports,__nccwpck_require__);o=false}finally{if(o)delete r[t]}return n.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var t=__nccwpck_require__(784);module.exports=t})();
@@ -0,0 +1 @@
1
+ {"name":"just-diff","author":"Angus Croll","license":"MIT","types":"index.d.ts"}
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright JS Foundation and other contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1 @@
1
+ (function(){"use strict";var e={131:function(e,t,n){const o=n(246);const r=n(431);class AsyncParallelBailHookCodeFactory extends r{content({onError:e,onResult:t,onDone:n}){let o="";o+=`var _results = new Array(${this.options.taps.length});\n`;o+="var _checkDone = function() {\n";o+="for(var i = 0; i < _results.length; i++) {\n";o+="var item = _results[i];\n";o+="if(item === undefined) return false;\n";o+="if(item.result !== undefined) {\n";o+=t("item.result");o+="return true;\n";o+="}\n";o+="if(item.error) {\n";o+=e("item.error");o+="return true;\n";o+="}\n";o+="}\n";o+="return false;\n";o+="}\n";o+=this.callTapsParallel({onError:(e,t,n,o)=>{let r="";r+=`if(${e} < _results.length && ((_results.length = ${e+1}), (_results[${e}] = { error: ${t} }), _checkDone())) {\n`;r+=o(true);r+="} else {\n";r+=n();r+="}\n";return r},onResult:(e,t,n,o)=>{let r="";r+=`if(${e} < _results.length && (${t} !== undefined && (_results.length = ${e+1}), (_results[${e}] = { result: ${t} }), _checkDone())) {\n`;r+=o(true);r+="} else {\n";r+=n();r+="}\n";return r},onTap:(e,t,n,o)=>{let r="";if(e>0){r+=`if(${e} >= _results.length) {\n`;r+=n();r+="} else {\n"}r+=t();if(e>0)r+="}\n";return r},onDone:n});return o}}const s=new AsyncParallelBailHookCodeFactory;const COMPILE=function(e){s.setup(this,e);return s.create(e)};function AsyncParallelBailHook(e=[],t=undefined){const n=new o(e,t);n.constructor=AsyncParallelBailHook;n.compile=COMPILE;n._call=undefined;n.call=undefined;return n}AsyncParallelBailHook.prototype=null;e.exports=AsyncParallelBailHook},834:function(e,t,n){const o=n(246);const r=n(431);class AsyncParallelHookCodeFactory extends r{content({onError:e,onDone:t}){return this.callTapsParallel({onError:(t,n,o,r)=>e(n)+r(true),onDone:t})}}const s=new AsyncParallelHookCodeFactory;const COMPILE=function(e){s.setup(this,e);return s.create(e)};function AsyncParallelHook(e=[],t=undefined){const n=new o(e,t);n.constructor=AsyncParallelHook;n.compile=COMPILE;n._call=undefined;n.call=undefined;return n}AsyncParallelHook.prototype=null;e.exports=AsyncParallelHook},179:function(e,t,n){const o=n(246);const r=n(431);class AsyncSeriesBailHookCodeFactory extends r{content({onError:e,onResult:t,resultReturns:n,onDone:o}){return this.callTapsSeries({onError:(t,n,o,r)=>e(n)+r(true),onResult:(e,n,o)=>`if(${n} !== undefined) {\n${t(n)}\n} else {\n${o()}}\n`,resultReturns:n,onDone:o})}}const s=new AsyncSeriesBailHookCodeFactory;const COMPILE=function(e){s.setup(this,e);return s.create(e)};function AsyncSeriesBailHook(e=[],t=undefined){const n=new o(e,t);n.constructor=AsyncSeriesBailHook;n.compile=COMPILE;n._call=undefined;n.call=undefined;return n}AsyncSeriesBailHook.prototype=null;e.exports=AsyncSeriesBailHook},1:function(e,t,n){const o=n(246);const r=n(431);class AsyncSeriesHookCodeFactory extends r{content({onError:e,onDone:t}){return this.callTapsSeries({onError:(t,n,o,r)=>e(n)+r(true),onDone:t})}}const s=new AsyncSeriesHookCodeFactory;const COMPILE=function(e){s.setup(this,e);return s.create(e)};function AsyncSeriesHook(e=[],t=undefined){const n=new o(e,t);n.constructor=AsyncSeriesHook;n.compile=COMPILE;n._call=undefined;n.call=undefined;return n}AsyncSeriesHook.prototype=null;e.exports=AsyncSeriesHook},843:function(e,t,n){const o=n(246);const r=n(431);class AsyncSeriesLoopHookCodeFactory extends r{content({onError:e,onDone:t}){return this.callTapsLooping({onError:(t,n,o,r)=>e(n)+r(true),onDone:t})}}const s=new AsyncSeriesLoopHookCodeFactory;const COMPILE=function(e){s.setup(this,e);return s.create(e)};function AsyncSeriesLoopHook(e=[],t=undefined){const n=new o(e,t);n.constructor=AsyncSeriesLoopHook;n.compile=COMPILE;n._call=undefined;n.call=undefined;return n}AsyncSeriesLoopHook.prototype=null;e.exports=AsyncSeriesLoopHook},371:function(e,t,n){const o=n(246);const r=n(431);class AsyncSeriesWaterfallHookCodeFactory extends r{content({onError:e,onResult:t,onDone:n}){return this.callTapsSeries({onError:(t,n,o,r)=>e(n)+r(true),onResult:(e,t,n)=>{let o="";o+=`if(${t} !== undefined) {\n`;o+=`${this._args[0]} = ${t};\n`;o+=`}\n`;o+=n();return o},onDone:()=>t(this._args[0])})}}const s=new AsyncSeriesWaterfallHookCodeFactory;const COMPILE=function(e){s.setup(this,e);return s.create(e)};function AsyncSeriesWaterfallHook(e=[],t=undefined){if(e.length<1)throw new Error("Waterfall hooks must have at least one argument");const n=new o(e,t);n.constructor=AsyncSeriesWaterfallHook;n.compile=COMPILE;n._call=undefined;n.call=undefined;return n}AsyncSeriesWaterfallHook.prototype=null;e.exports=AsyncSeriesWaterfallHook},246:function(e,t,n){const o=n(669);const r=o.deprecate((()=>{}),"Hook.context is deprecated and will be removed");const CALL_DELEGATE=function(...e){this.call=this._createCall("sync");return this.call(...e)};const CALL_ASYNC_DELEGATE=function(...e){this.callAsync=this._createCall("async");return this.callAsync(...e)};const PROMISE_DELEGATE=function(...e){this.promise=this._createCall("promise");return this.promise(...e)};class Hook{constructor(e=[],t=undefined){this._args=e;this.name=t;this.taps=[];this.interceptors=[];this._call=CALL_DELEGATE;this.call=CALL_DELEGATE;this._callAsync=CALL_ASYNC_DELEGATE;this.callAsync=CALL_ASYNC_DELEGATE;this._promise=PROMISE_DELEGATE;this.promise=PROMISE_DELEGATE;this._x=undefined;this.compile=this.compile;this.tap=this.tap;this.tapAsync=this.tapAsync;this.tapPromise=this.tapPromise}compile(e){throw new Error("Abstract: should be overridden")}_createCall(e){return this.compile({taps:this.taps,interceptors:this.interceptors,args:this._args,type:e})}_tap(e,t,n){if(typeof t==="string"){t={name:t.trim()}}else if(typeof t!=="object"||t===null){throw new Error("Invalid tap options")}if(typeof t.name!=="string"||t.name===""){throw new Error("Missing name for tap")}if(typeof t.context!=="undefined"){r()}t=Object.assign({type:e,fn:n},t);t=this._runRegisterInterceptors(t);this._insert(t)}tap(e,t){this._tap("sync",e,t)}tapAsync(e,t){this._tap("async",e,t)}tapPromise(e,t){this._tap("promise",e,t)}_runRegisterInterceptors(e){for(const t of this.interceptors){if(t.register){const n=t.register(e);if(n!==undefined){e=n}}}return e}withOptions(e){const mergeOptions=t=>Object.assign({},e,typeof t==="string"?{name:t}:t);return{name:this.name,tap:(e,t)=>this.tap(mergeOptions(e),t),tapAsync:(e,t)=>this.tapAsync(mergeOptions(e),t),tapPromise:(e,t)=>this.tapPromise(mergeOptions(e),t),intercept:e=>this.intercept(e),isUsed:()=>this.isUsed(),withOptions:e=>this.withOptions(mergeOptions(e))}}isUsed(){return this.taps.length>0||this.interceptors.length>0}intercept(e){this._resetCompilation();this.interceptors.push(Object.assign({},e));if(e.register){for(let t=0;t<this.taps.length;t++){this.taps[t]=e.register(this.taps[t])}}}_resetCompilation(){this.call=this._call;this.callAsync=this._callAsync;this.promise=this._promise}_insert(e){this._resetCompilation();let t;if(typeof e.before==="string"){t=new Set([e.before])}else if(Array.isArray(e.before)){t=new Set(e.before)}let n=0;if(typeof e.stage==="number"){n=e.stage}let o=this.taps.length;while(o>0){o--;const e=this.taps[o];this.taps[o+1]=e;const r=e.stage||0;if(t){if(t.has(e.name)){t.delete(e.name);continue}if(t.size>0){continue}}if(r>n){continue}o++;break}this.taps[o]=e}}Object.setPrototypeOf(Hook.prototype,null);e.exports=Hook},431:function(e){class HookCodeFactory{constructor(e){this.config=e;this.options=undefined;this._args=undefined}create(e){this.init(e);let t;switch(this.options.type){case"sync":t=new Function(this.args(),'"use strict";\n'+this.header()+this.contentWithInterceptors({onError:e=>`throw ${e};\n`,onResult:e=>`return ${e};\n`,resultReturns:true,onDone:()=>"",rethrowIfPossible:true}));break;case"async":t=new Function(this.args({after:"_callback"}),'"use strict";\n'+this.header()+this.contentWithInterceptors({onError:e=>`_callback(${e});\n`,onResult:e=>`_callback(null, ${e});\n`,onDone:()=>"_callback();\n"}));break;case"promise":let e=false;const n=this.contentWithInterceptors({onError:t=>{e=true;return`_error(${t});\n`},onResult:e=>`_resolve(${e});\n`,onDone:()=>"_resolve();\n"});let o="";o+='"use strict";\n';o+=this.header();o+="return new Promise((function(_resolve, _reject) {\n";if(e){o+="var _sync = true;\n";o+="function _error(_err) {\n";o+="if(_sync)\n";o+="_resolve(Promise.resolve().then((function() { throw _err; })));\n";o+="else\n";o+="_reject(_err);\n";o+="};\n"}o+=n;if(e){o+="_sync = false;\n"}o+="}));\n";t=new Function(this.args(),o);break}this.deinit();return t}setup(e,t){e._x=t.taps.map((e=>e.fn))}init(e){this.options=e;this._args=e.args.slice()}deinit(){this.options=undefined;this._args=undefined}contentWithInterceptors(e){if(this.options.interceptors.length>0){const t=e.onError;const n=e.onResult;const o=e.onDone;let r="";for(let e=0;e<this.options.interceptors.length;e++){const t=this.options.interceptors[e];if(t.call){r+=`${this.getInterceptor(e)}.call(${this.args({before:t.context?"_context":undefined})});\n`}}r+=this.content(Object.assign(e,{onError:t&&(e=>{let n="";for(let t=0;t<this.options.interceptors.length;t++){const o=this.options.interceptors[t];if(o.error){n+=`${this.getInterceptor(t)}.error(${e});\n`}}n+=t(e);return n}),onResult:n&&(e=>{let t="";for(let n=0;n<this.options.interceptors.length;n++){const o=this.options.interceptors[n];if(o.result){t+=`${this.getInterceptor(n)}.result(${e});\n`}}t+=n(e);return t}),onDone:o&&(()=>{let e="";for(let t=0;t<this.options.interceptors.length;t++){const n=this.options.interceptors[t];if(n.done){e+=`${this.getInterceptor(t)}.done();\n`}}e+=o();return e})}));return r}else{return this.content(e)}}header(){let e="";if(this.needContext()){e+="var _context = {};\n"}else{e+="var _context;\n"}e+="var _x = this._x;\n";if(this.options.interceptors.length>0){e+="var _taps = this.taps;\n";e+="var _interceptors = this.interceptors;\n"}return e}needContext(){for(const e of this.options.taps)if(e.context)return true;return false}callTap(e,{onError:t,onResult:n,onDone:o,rethrowIfPossible:r}){let s="";let i=false;for(let t=0;t<this.options.interceptors.length;t++){const n=this.options.interceptors[t];if(n.tap){if(!i){s+=`var _tap${e} = ${this.getTap(e)};\n`;i=true}s+=`${this.getInterceptor(t)}.tap(${n.context?"_context, ":""}_tap${e});\n`}}s+=`var _fn${e} = ${this.getTapFn(e)};\n`;const c=this.options.taps[e];switch(c.type){case"sync":if(!r){s+=`var _hasError${e} = false;\n`;s+="try {\n"}if(n){s+=`var _result${e} = _fn${e}(${this.args({before:c.context?"_context":undefined})});\n`}else{s+=`_fn${e}(${this.args({before:c.context?"_context":undefined})});\n`}if(!r){s+="} catch(_err) {\n";s+=`_hasError${e} = true;\n`;s+=t("_err");s+="}\n";s+=`if(!_hasError${e}) {\n`}if(n){s+=n(`_result${e}`)}if(o){s+=o()}if(!r){s+="}\n"}break;case"async":let i="";if(n)i+=`(function(_err${e}, _result${e}) {\n`;else i+=`(function(_err${e}) {\n`;i+=`if(_err${e}) {\n`;i+=t(`_err${e}`);i+="} else {\n";if(n){i+=n(`_result${e}`)}if(o){i+=o()}i+="}\n";i+="})";s+=`_fn${e}(${this.args({before:c.context?"_context":undefined,after:i})});\n`;break;case"promise":s+=`var _hasResult${e} = false;\n`;s+=`var _promise${e} = _fn${e}(${this.args({before:c.context?"_context":undefined})});\n`;s+=`if (!_promise${e} || !_promise${e}.then)\n`;s+=` throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise${e} + ')');\n`;s+=`_promise${e}.then((function(_result${e}) {\n`;s+=`_hasResult${e} = true;\n`;if(n){s+=n(`_result${e}`)}if(o){s+=o()}s+=`}), function(_err${e}) {\n`;s+=`if(_hasResult${e}) throw _err${e};\n`;s+=t(`_err${e}`);s+="});\n";break}return s}callTapsSeries({onError:e,onResult:t,resultReturns:n,onDone:o,doneReturns:r,rethrowIfPossible:s}){if(this.options.taps.length===0)return o();const i=this.options.taps.findIndex((e=>e.type!=="sync"));const c=n||r;let a="";let l=o;let p=0;for(let n=this.options.taps.length-1;n>=0;n--){const r=n;const u=l!==o&&(this.options.taps[r].type!=="sync"||p++>20);if(u){p=0;a+=`function _next${r}() {\n`;a+=l();a+=`}\n`;l=()=>`${c?"return ":""}_next${r}();\n`}const f=l;const doneBreak=e=>{if(e)return"";return o()};const h=this.callTap(r,{onError:t=>e(r,t,f,doneBreak),onResult:t&&(e=>t(r,e,f,doneBreak)),onDone:!t&&f,rethrowIfPossible:s&&(i<0||r<i)});l=()=>h}a+=l();return a}callTapsLooping({onError:e,onDone:t,rethrowIfPossible:n}){if(this.options.taps.length===0)return t();const o=this.options.taps.every((e=>e.type==="sync"));let r="";if(!o){r+="var _looper = (function() {\n";r+="var _loopAsync = false;\n"}r+="var _loop;\n";r+="do {\n";r+="_loop = false;\n";for(let e=0;e<this.options.interceptors.length;e++){const t=this.options.interceptors[e];if(t.loop){r+=`${this.getInterceptor(e)}.loop(${this.args({before:t.context?"_context":undefined})});\n`}}r+=this.callTapsSeries({onError:e,onResult:(e,t,n,r)=>{let s="";s+=`if(${t} !== undefined) {\n`;s+="_loop = true;\n";if(!o)s+="if(_loopAsync) _looper();\n";s+=r(true);s+=`} else {\n`;s+=n();s+=`}\n`;return s},onDone:t&&(()=>{let e="";e+="if(!_loop) {\n";e+=t();e+="}\n";return e}),rethrowIfPossible:n&&o});r+="} while(_loop);\n";if(!o){r+="_loopAsync = true;\n";r+="});\n";r+="_looper();\n"}return r}callTapsParallel({onError:e,onResult:t,onDone:n,rethrowIfPossible:o,onTap:r=((e,t)=>t())}){if(this.options.taps.length<=1){return this.callTapsSeries({onError:e,onResult:t,onDone:n,rethrowIfPossible:o})}let s="";s+="do {\n";s+=`var _counter = ${this.options.taps.length};\n`;if(n){s+="var _done = (function() {\n";s+=n();s+="});\n"}for(let i=0;i<this.options.taps.length;i++){const done=()=>{if(n)return"if(--_counter === 0) _done();\n";else return"--_counter;"};const doneBreak=e=>{if(e||!n)return"_counter = 0;\n";else return"_counter = 0;\n_done();\n"};s+="if(_counter <= 0) break;\n";s+=r(i,(()=>this.callTap(i,{onError:t=>{let n="";n+="if(_counter > 0) {\n";n+=e(i,t,done,doneBreak);n+="}\n";return n},onResult:t&&(e=>{let n="";n+="if(_counter > 0) {\n";n+=t(i,e,done,doneBreak);n+="}\n";return n}),onDone:!t&&(()=>done()),rethrowIfPossible:o})),done,doneBreak)}s+="} while(false);\n";return s}args({before:e,after:t}={}){let n=this._args;if(e)n=[e].concat(n);if(t)n=n.concat(t);if(n.length===0){return""}else{return n.join(", ")}}getTapFn(e){return`_x[${e}]`}getTap(e){return`_taps[${e}]`}getInterceptor(e){return`_interceptors[${e}]`}}e.exports=HookCodeFactory},278:function(e,t,n){const o=n(669);const defaultFactory=(e,t)=>t;class HookMap{constructor(e,t=undefined){this._map=new Map;this.name=t;this._factory=e;this._interceptors=[]}get(e){return this._map.get(e)}for(e){const t=this.get(e);if(t!==undefined){return t}let n=this._factory(e);const o=this._interceptors;for(let t=0;t<o.length;t++){n=o[t].factory(e,n)}this._map.set(e,n);return n}intercept(e){this._interceptors.push(Object.assign({factory:defaultFactory},e))}}HookMap.prototype.tap=o.deprecate((function(e,t,n){return this.for(e).tap(t,n)}),"HookMap#tap(key,…) is deprecated. Use HookMap#for(key).tap(…) instead.");HookMap.prototype.tapAsync=o.deprecate((function(e,t,n){return this.for(e).tapAsync(t,n)}),"HookMap#tapAsync(key,…) is deprecated. Use HookMap#for(key).tapAsync(…) instead.");HookMap.prototype.tapPromise=o.deprecate((function(e,t,n){return this.for(e).tapPromise(t,n)}),"HookMap#tapPromise(key,…) is deprecated. Use HookMap#for(key).tapPromise(…) instead.");e.exports=HookMap},310:function(e,t,n){const o=n(246);class MultiHook{constructor(e,t=undefined){this.hooks=e;this.name=t}tap(e,t){for(const n of this.hooks){n.tap(e,t)}}tapAsync(e,t){for(const n of this.hooks){n.tapAsync(e,t)}}tapPromise(e,t){for(const n of this.hooks){n.tapPromise(e,t)}}isUsed(){for(const e of this.hooks){if(e.isUsed())return true}return false}intercept(e){for(const t of this.hooks){t.intercept(e)}}withOptions(e){return new MultiHook(this.hooks.map((t=>t.withOptions(e))),this.name)}}e.exports=MultiHook},487:function(e,t,n){const o=n(246);const r=n(431);class SyncBailHookCodeFactory extends r{content({onError:e,onResult:t,resultReturns:n,onDone:o,rethrowIfPossible:r}){return this.callTapsSeries({onError:(t,n)=>e(n),onResult:(e,n,o)=>`if(${n} !== undefined) {\n${t(n)};\n} else {\n${o()}}\n`,resultReturns:n,onDone:o,rethrowIfPossible:r})}}const s=new SyncBailHookCodeFactory;const TAP_ASYNC=()=>{throw new Error("tapAsync is not supported on a SyncBailHook")};const TAP_PROMISE=()=>{throw new Error("tapPromise is not supported on a SyncBailHook")};const COMPILE=function(e){s.setup(this,e);return s.create(e)};function SyncBailHook(e=[],t=undefined){const n=new o(e,t);n.constructor=SyncBailHook;n.tapAsync=TAP_ASYNC;n.tapPromise=TAP_PROMISE;n.compile=COMPILE;return n}SyncBailHook.prototype=null;e.exports=SyncBailHook},75:function(e,t,n){const o=n(246);const r=n(431);class SyncHookCodeFactory extends r{content({onError:e,onDone:t,rethrowIfPossible:n}){return this.callTapsSeries({onError:(t,n)=>e(n),onDone:t,rethrowIfPossible:n})}}const s=new SyncHookCodeFactory;const TAP_ASYNC=()=>{throw new Error("tapAsync is not supported on a SyncHook")};const TAP_PROMISE=()=>{throw new Error("tapPromise is not supported on a SyncHook")};const COMPILE=function(e){s.setup(this,e);return s.create(e)};function SyncHook(e=[],t=undefined){const n=new o(e,t);n.constructor=SyncHook;n.tapAsync=TAP_ASYNC;n.tapPromise=TAP_PROMISE;n.compile=COMPILE;return n}SyncHook.prototype=null;e.exports=SyncHook},667:function(e,t,n){const o=n(246);const r=n(431);class SyncLoopHookCodeFactory extends r{content({onError:e,onDone:t,rethrowIfPossible:n}){return this.callTapsLooping({onError:(t,n)=>e(n),onDone:t,rethrowIfPossible:n})}}const s=new SyncLoopHookCodeFactory;const TAP_ASYNC=()=>{throw new Error("tapAsync is not supported on a SyncLoopHook")};const TAP_PROMISE=()=>{throw new Error("tapPromise is not supported on a SyncLoopHook")};const COMPILE=function(e){s.setup(this,e);return s.create(e)};function SyncLoopHook(e=[],t=undefined){const n=new o(e,t);n.constructor=SyncLoopHook;n.tapAsync=TAP_ASYNC;n.tapPromise=TAP_PROMISE;n.compile=COMPILE;return n}SyncLoopHook.prototype=null;e.exports=SyncLoopHook},303:function(e,t,n){const o=n(246);const r=n(431);class SyncWaterfallHookCodeFactory extends r{content({onError:e,onResult:t,resultReturns:n,rethrowIfPossible:o}){return this.callTapsSeries({onError:(t,n)=>e(n),onResult:(e,t,n)=>{let o="";o+=`if(${t} !== undefined) {\n`;o+=`${this._args[0]} = ${t};\n`;o+=`}\n`;o+=n();return o},onDone:()=>t(this._args[0]),doneReturns:n,rethrowIfPossible:o})}}const s=new SyncWaterfallHookCodeFactory;const TAP_ASYNC=()=>{throw new Error("tapAsync is not supported on a SyncWaterfallHook")};const TAP_PROMISE=()=>{throw new Error("tapPromise is not supported on a SyncWaterfallHook")};const COMPILE=function(e){s.setup(this,e);return s.create(e)};function SyncWaterfallHook(e=[],t=undefined){if(e.length<1)throw new Error("Waterfall hooks must have at least one argument");const n=new o(e,t);n.constructor=SyncWaterfallHook;n.tapAsync=TAP_ASYNC;n.tapPromise=TAP_PROMISE;n.compile=COMPILE;return n}SyncWaterfallHook.prototype=null;e.exports=SyncWaterfallHook},669:function(e){e.exports=require("util")}};var t={};function __nccwpck_require__(n){var o=t[n];if(o!==undefined){return o.exports}var r=t[n]={exports:{}};var s=true;try{e[n](r,r.exports,__nccwpck_require__);s=false}finally{if(s)delete t[n]}return r.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var n={};!function(){var e=n;e.__esModule=true;e.SyncHook=__nccwpck_require__(75);e.SyncBailHook=__nccwpck_require__(487);e.SyncWaterfallHook=__nccwpck_require__(303);e.SyncLoopHook=__nccwpck_require__(667);e.AsyncParallelHook=__nccwpck_require__(834);e.AsyncParallelBailHook=__nccwpck_require__(131);e.AsyncSeriesHook=__nccwpck_require__(1);e.AsyncSeriesBailHook=__nccwpck_require__(179);e.AsyncSeriesLoopHook=__nccwpck_require__(843);e.AsyncSeriesWaterfallHook=__nccwpck_require__(371);e.HookMap=__nccwpck_require__(278);e.MultiHook=__nccwpck_require__(310)}();module.exports=n})();
@@ -0,0 +1 @@
1
+ {"name":"tapable","author":"Tobias Koppers @sokra","license":"MIT","types":"./tapable.d.ts"}
@@ -0,0 +1,116 @@
1
+ type FixedSizeArray<T extends number, U> = T extends 0
2
+ ? void[]
3
+ : ReadonlyArray<U> & {
4
+ 0: U;
5
+ length: T;
6
+ };
7
+ type Measure<T extends number> = T extends 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8
8
+ ? T
9
+ : never;
10
+ type Append<T extends any[], U> = {
11
+ 0: [U];
12
+ 1: [T[0], U];
13
+ 2: [T[0], T[1], U];
14
+ 3: [T[0], T[1], T[2], U];
15
+ 4: [T[0], T[1], T[2], T[3], U];
16
+ 5: [T[0], T[1], T[2], T[3], T[4], U];
17
+ 6: [T[0], T[1], T[2], T[3], T[4], T[5], U];
18
+ 7: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], U];
19
+ 8: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7], U];
20
+ }[Measure<T["length"]>];
21
+ type AsArray<T> = T extends any[] ? T : [T];
22
+
23
+ declare class UnsetAdditionalOptions {
24
+ _UnsetAdditionalOptions: true
25
+ }
26
+ type IfSet<X> = X extends UnsetAdditionalOptions ? {} : X;
27
+
28
+ type Callback<E, T> = (error: E | null, result?: T) => void;
29
+ type InnerCallback<E, T> = (error?: E | null | false, result?: T) => void;
30
+
31
+ type FullTap = Tap & {
32
+ type: "sync" | "async" | "promise",
33
+ fn: Function
34
+ }
35
+
36
+ type Tap = TapOptions & {
37
+ name: string;
38
+ };
39
+
40
+ type TapOptions = {
41
+ before?: string;
42
+ stage?: number;
43
+ };
44
+
45
+ interface HookInterceptor<T, R, AdditionalOptions = UnsetAdditionalOptions> {
46
+ name?: string;
47
+ tap?: (tap: FullTap & IfSet<AdditionalOptions>) => void;
48
+ call?: (...args: any[]) => void;
49
+ loop?: (...args: any[]) => void;
50
+ error?: (err: Error) => void;
51
+ result?: (result: R) => void;
52
+ done?: () => void;
53
+ register?: (tap: FullTap & IfSet<AdditionalOptions>) => FullTap & IfSet<AdditionalOptions>;
54
+ }
55
+
56
+ type ArgumentNames<T extends any[]> = FixedSizeArray<T["length"], string>;
57
+
58
+ declare class Hook<T, R, AdditionalOptions = UnsetAdditionalOptions> {
59
+ constructor(args?: ArgumentNames<AsArray<T>>, name?: string);
60
+ name: string | undefined;
61
+ taps: FullTap[];
62
+ intercept(interceptor: HookInterceptor<T, R, AdditionalOptions>): void;
63
+ isUsed(): boolean;
64
+ callAsync(...args: Append<AsArray<T>, Callback<Error, R>>): void;
65
+ promise(...args: AsArray<T>): Promise<R>;
66
+ tap(options: string | Tap & IfSet<AdditionalOptions>, fn: (...args: AsArray<T>) => R): void;
67
+ withOptions(options: TapOptions & IfSet<AdditionalOptions>): Omit<this, "call" | "callAsync" | "promise">;
68
+ }
69
+
70
+ export class SyncHook<T, R = void, AdditionalOptions = UnsetAdditionalOptions> extends Hook<T, R, AdditionalOptions> {
71
+ call(...args: AsArray<T>): R;
72
+ }
73
+
74
+ export class SyncBailHook<T, R, AdditionalOptions = UnsetAdditionalOptions> extends SyncHook<T, R, AdditionalOptions> {}
75
+ export class SyncLoopHook<T, AdditionalOptions = UnsetAdditionalOptions> extends SyncHook<T, void, AdditionalOptions> {}
76
+ export class SyncWaterfallHook<T, AdditionalOptions = UnsetAdditionalOptions> extends SyncHook<T, AsArray<T>[0], AdditionalOptions> {}
77
+
78
+ declare class AsyncHook<T, R, AdditionalOptions = UnsetAdditionalOptions> extends Hook<T, R, AdditionalOptions> {
79
+ tapAsync(
80
+ options: string | Tap & IfSet<AdditionalOptions>,
81
+ fn: (...args: Append<AsArray<T>, InnerCallback<Error, R>>) => void
82
+ ): void;
83
+ tapPromise(
84
+ options: string | Tap & IfSet<AdditionalOptions>,
85
+ fn: (...args: AsArray<T>) => Promise<R>
86
+ ): void;
87
+ }
88
+
89
+ export class AsyncParallelHook<T, AdditionalOptions = UnsetAdditionalOptions> extends AsyncHook<T, void, AdditionalOptions> {}
90
+ export class AsyncParallelBailHook<T, R, AdditionalOptions = UnsetAdditionalOptions> extends AsyncHook<T, R, AdditionalOptions> {}
91
+ export class AsyncSeriesHook<T, AdditionalOptions = UnsetAdditionalOptions> extends AsyncHook<T, void, AdditionalOptions> {}
92
+ export class AsyncSeriesBailHook<T, R, AdditionalOptions = UnsetAdditionalOptions> extends AsyncHook<T, R, AdditionalOptions> {}
93
+ export class AsyncSeriesLoopHook<T, AdditionalOptions = UnsetAdditionalOptions> extends AsyncHook<T, void, AdditionalOptions> {}
94
+ export class AsyncSeriesWaterfallHook<T, AdditionalOptions = UnsetAdditionalOptions> extends AsyncHook<T, AsArray<T>[0], AdditionalOptions> {}
95
+
96
+ type HookFactory<H> = (key: any, hook?: H) => H;
97
+
98
+ interface HookMapInterceptor<H> {
99
+ factory?: HookFactory<H>;
100
+ }
101
+
102
+ export class HookMap<H> {
103
+ constructor(factory: HookFactory<H>, name?: string);
104
+ name: string | undefined;
105
+ get(key: any): H | undefined;
106
+ for(key: any): H;
107
+ intercept(interceptor: HookMapInterceptor<H>): void;
108
+ }
109
+
110
+ export class MultiHook<H> {
111
+ constructor(hooks: H[], name?: string);
112
+ name: string | undefined;
113
+ tap(options: string | Tap, fn?: Function): void;
114
+ tapAsync(options: string | Tap, fn?: Function): void;
115
+ tapPromise(options: string | Tap, fn?: Function): void;
116
+ }
@@ -0,0 +1,63 @@
1
+ import { Env } from '../types';
2
+ interface IOpts {
3
+ cwd: string;
4
+ env: Env;
5
+ specifiedEnv?: string;
6
+ defaultConfigFiles?: string[];
7
+ }
8
+ declare type ISchema = Record<string, any>;
9
+ declare type IOnChangeTypes = Record<string, string | Function>;
10
+ export declare class Config {
11
+ opts: IOpts;
12
+ mainConfigFile: string | null;
13
+ prevConfig: any;
14
+ files: string[];
15
+ constructor(opts: IOpts);
16
+ getUserConfig(): {
17
+ config: {};
18
+ files: string[];
19
+ };
20
+ getConfig(opts: {
21
+ schemas: ISchema;
22
+ }): {
23
+ config: {};
24
+ files: string[];
25
+ };
26
+ watch(opts: {
27
+ schemas: ISchema;
28
+ onChangeTypes: IOnChangeTypes;
29
+ onChange: (opts: {
30
+ data: ReturnType<typeof Config.diffConfigs>;
31
+ event: string;
32
+ path: string;
33
+ }) => Promise<void>;
34
+ }): () => Promise<void>;
35
+ static getMainConfigFile(opts: {
36
+ cwd: string;
37
+ defaultConfigFiles?: string[];
38
+ }): string | null;
39
+ static getConfigFiles(opts: {
40
+ mainConfigFile: string | null;
41
+ env: Env;
42
+ specifiedEnv?: string;
43
+ }): string[];
44
+ static getUserConfig(opts: {
45
+ configFiles: string[];
46
+ }): {
47
+ config: {};
48
+ files: string[];
49
+ };
50
+ static validateConfig(opts: {
51
+ config: any;
52
+ schemas: ISchema;
53
+ }): void;
54
+ static diffConfigs(opts: {
55
+ origin: any;
56
+ updated: any;
57
+ onChangeTypes: IOnChangeTypes;
58
+ }): {
59
+ changes: Record<string, string[]>;
60
+ fns: Function[];
61
+ };
62
+ }
63
+ export {};
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Config = void 0;
7
+ const esbuild_1 = __importDefault(require("@umijs/bundler-utils/compiled/esbuild"));
8
+ const utils_1 = require("@umijs/utils");
9
+ const assert_1 = __importDefault(require("assert"));
10
+ const fs_1 = require("fs");
11
+ const path_1 = require("path");
12
+ const joi_1 = __importDefault(require("../../compiled/@hapi/joi"));
13
+ const just_diff_1 = require("../../compiled/just-diff");
14
+ const constants_1 = require("../constants");
15
+ const utils_2 = require("./utils");
16
+ class Config {
17
+ constructor(opts) {
18
+ this.files = [];
19
+ this.opts = opts;
20
+ this.mainConfigFile = Config.getMainConfigFile(this.opts);
21
+ this.prevConfig = null;
22
+ }
23
+ getUserConfig() {
24
+ const configFiles = Config.getConfigFiles({
25
+ mainConfigFile: this.mainConfigFile,
26
+ env: this.opts.env,
27
+ specifiedEnv: this.opts.specifiedEnv,
28
+ });
29
+ return Config.getUserConfig({
30
+ configFiles: (0, utils_2.getAbsFiles)({
31
+ files: configFiles,
32
+ cwd: this.opts.cwd,
33
+ }),
34
+ });
35
+ }
36
+ getConfig(opts) {
37
+ const { config, files } = this.getUserConfig();
38
+ Config.validateConfig({ config, schemas: opts.schemas });
39
+ this.files = files;
40
+ return (this.prevConfig = {
41
+ config: config,
42
+ files,
43
+ });
44
+ }
45
+ watch(opts) {
46
+ const watcher = utils_1.chokidar.watch([
47
+ ...this.files,
48
+ ...(this.mainConfigFile
49
+ ? []
50
+ : (0, utils_2.getAbsFiles)({
51
+ files: this.opts.defaultConfigFiles || constants_1.DEFAULT_CONFIG_FILES,
52
+ cwd: this.opts.cwd,
53
+ })),
54
+ ], {
55
+ ignoreInitial: true,
56
+ cwd: this.opts.cwd,
57
+ });
58
+ watcher.on('all', utils_1.lodash.debounce((event, path) => {
59
+ const { config: origin } = this.prevConfig;
60
+ const { config: updated, files } = this.getConfig({
61
+ schemas: opts.schemas,
62
+ });
63
+ watcher.add(files);
64
+ const data = Config.diffConfigs({
65
+ origin,
66
+ updated,
67
+ onChangeTypes: opts.onChangeTypes,
68
+ });
69
+ opts
70
+ .onChange({
71
+ data,
72
+ event,
73
+ path,
74
+ })
75
+ .catch((e) => {
76
+ throw new Error(e);
77
+ });
78
+ }, constants_1.WATCH_DEBOUNCE_STEP));
79
+ return () => watcher.close();
80
+ }
81
+ static getMainConfigFile(opts) {
82
+ let mainConfigFile = null;
83
+ for (const configFile of opts.defaultConfigFiles || constants_1.DEFAULT_CONFIG_FILES) {
84
+ const absConfigFile = (0, path_1.join)(opts.cwd, configFile);
85
+ if ((0, fs_1.existsSync)(absConfigFile)) {
86
+ mainConfigFile = absConfigFile;
87
+ break;
88
+ }
89
+ }
90
+ return mainConfigFile;
91
+ }
92
+ static getConfigFiles(opts) {
93
+ const ret = [];
94
+ const { mainConfigFile } = opts;
95
+ const specifiedEnv = opts.specifiedEnv || '';
96
+ if (mainConfigFile) {
97
+ const env = constants_1.SHORT_ENV[opts.env] || opts.env;
98
+ ret.push(...[
99
+ mainConfigFile,
100
+ specifiedEnv &&
101
+ (0, utils_2.addExt)({ file: mainConfigFile, ext: `.${specifiedEnv}` }),
102
+ (0, utils_2.addExt)({ file: mainConfigFile, ext: `.${env}` }),
103
+ specifiedEnv &&
104
+ (0, utils_2.addExt)({
105
+ file: mainConfigFile,
106
+ ext: `.${env}.${specifiedEnv}`,
107
+ }),
108
+ (0, utils_2.addExt)({ file: mainConfigFile, ext: constants_1.LOCAL_EXT }),
109
+ ].filter(Boolean));
110
+ }
111
+ return ret;
112
+ }
113
+ static getUserConfig(opts) {
114
+ let config = {};
115
+ let files = [];
116
+ for (const configFile of opts.configFiles) {
117
+ files.push(configFile);
118
+ if ((0, fs_1.existsSync)(configFile)) {
119
+ utils_1.register.register({
120
+ implementor: esbuild_1.default,
121
+ });
122
+ utils_1.register.clearFiles();
123
+ config = utils_1.lodash.merge(config, require(configFile).default);
124
+ for (const file of utils_1.register.getFiles()) {
125
+ delete require.cache[file];
126
+ }
127
+ files.push(...utils_1.register.getFiles());
128
+ utils_1.register.restore();
129
+ }
130
+ }
131
+ return {
132
+ config,
133
+ files,
134
+ };
135
+ }
136
+ static validateConfig(opts) {
137
+ const errors = new Map();
138
+ const configKeys = new Set(Object.keys(opts.config));
139
+ for (const key of Object.keys(opts.schemas)) {
140
+ configKeys.delete(key);
141
+ if (!opts.config[key])
142
+ continue;
143
+ const schema = opts.schemas[key](joi_1.default);
144
+ // invalid schema
145
+ (0, assert_1.default)(joi_1.default.isSchema(schema), `schema for config ${key} is not valid.`);
146
+ const { error } = schema.validate(opts.config[key]);
147
+ if (error)
148
+ errors.set(key, error);
149
+ }
150
+ // invalid config values
151
+ (0, assert_1.default)(errors.size === 0, `Invalid config values: ${Array.from(errors.keys()).join(', ')}
152
+ ${Array.from(errors.keys()).map((key) => {
153
+ return `Invalid value for ${key}:\n${errors.get(key).message}`;
154
+ })}`);
155
+ // invalid config keys
156
+ (0, assert_1.default)(configKeys.size === 0, `Invalid config keys: ${Array.from(configKeys).join(', ')}`);
157
+ }
158
+ static diffConfigs(opts) {
159
+ const patch = (0, just_diff_1.diff)(opts.origin, opts.updated);
160
+ const changes = {};
161
+ const fns = [];
162
+ for (const item of patch) {
163
+ const key = item.path[0];
164
+ const onChange = opts.onChangeTypes[key];
165
+ (0, assert_1.default)(onChange, `Invalid onChange config for key ${key}`);
166
+ if (typeof onChange === 'string') {
167
+ changes[onChange] || (changes[onChange] = []);
168
+ changes[onChange].push(String(key));
169
+ }
170
+ else if (typeof onChange === 'function') {
171
+ fns.push(onChange);
172
+ }
173
+ else {
174
+ throw new Error(`Invalid onChange value for key ${key}`);
175
+ }
176
+ }
177
+ return {
178
+ changes,
179
+ fns,
180
+ };
181
+ }
182
+ }
183
+ exports.Config = Config;
@@ -0,0 +1,8 @@
1
+ export declare function addExt(opts: {
2
+ file: string;
3
+ ext: string;
4
+ }): string;
5
+ export declare function getAbsFiles(opts: {
6
+ files: string[];
7
+ cwd: string;
8
+ }): string[];
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAbsFiles = exports.addExt = void 0;
4
+ const path_1 = require("path");
5
+ function addExt(opts) {
6
+ const index = opts.file.lastIndexOf('.');
7
+ return `${opts.file.slice(0, index)}${opts.ext}${opts.file.slice(index)}`;
8
+ }
9
+ exports.addExt = addExt;
10
+ function getAbsFiles(opts) {
11
+ return opts.files.map((file) => {
12
+ return (0, path_1.isAbsolute)(file) ? file : (0, path_1.join)(opts.cwd, file);
13
+ });
14
+ }
15
+ exports.getAbsFiles = getAbsFiles;
@@ -0,0 +1,9 @@
1
+ export declare const DEFAULT_CONFIG_FILES: string[];
2
+ export declare const SHORT_ENV: {
3
+ development: string;
4
+ production: string;
5
+ test: string;
6
+ };
7
+ export declare const LOCAL_EXT = ".local";
8
+ export declare const WATCH_DEBOUNCE_STEP = 300;
9
+ export declare const DEFAULT_FRAMEWORK_NAME = "umi";
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_FRAMEWORK_NAME = exports.WATCH_DEBOUNCE_STEP = exports.LOCAL_EXT = exports.SHORT_ENV = exports.DEFAULT_CONFIG_FILES = void 0;
4
+ exports.DEFAULT_CONFIG_FILES = ['config.ts', 'config.js'];
5
+ exports.SHORT_ENV = {
6
+ development: 'dev',
7
+ production: 'prod',
8
+ test: 'test',
9
+ };
10
+ exports.LOCAL_EXT = '.local';
11
+ exports.WATCH_DEBOUNCE_STEP = 300;
12
+ exports.DEFAULT_FRAMEWORK_NAME = 'umi';
@@ -0,0 +1,6 @@
1
+ export * from './config/config';
2
+ export * from './route/route';
3
+ export { GeneratorType, IGeneratorOpts } from './service/generator';
4
+ export * from './service/pluginAPI';
5
+ export * from './service/service';
6
+ export { Env, IAdd, IEvent, IModify, IRoute } from './types';
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.Env = exports.GeneratorType = void 0;
14
+ __exportStar(require("./config/config"), exports);
15
+ __exportStar(require("./route/route"), exports);
16
+ var generator_1 = require("./service/generator");
17
+ Object.defineProperty(exports, "GeneratorType", { enumerable: true, get: function () { return generator_1.GeneratorType; } });
18
+ __exportStar(require("./service/pluginAPI"), exports);
19
+ __exportStar(require("./service/service"), exports);
20
+ var types_1 = require("./types");
21
+ Object.defineProperty(exports, "Env", { enumerable: true, get: function () { return types_1.Env; } });
@@ -0,0 +1 @@
1
+ export declare function defineRoutes(callback: (defineRoute: Function) => void): any;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defineRoutes = void 0;
4
+ const utils_1 = require("./utils");
5
+ function defineRoutes(callback) {
6
+ const routes = Object.create(null);
7
+ const parentRoutes = [];
8
+ const defineRoute = (opts) => {
9
+ opts.options = opts.options || {};
10
+ const route = {
11
+ path: opts.path || '/',
12
+ id: (0, utils_1.createRouteId)(opts.file),
13
+ parentId: parentRoutes.length > 0
14
+ ? parentRoutes[parentRoutes.length - 1].id
15
+ : undefined,
16
+ file: opts.file,
17
+ };
18
+ routes[route.id] = route;
19
+ if (opts.children) {
20
+ parentRoutes.push(route);
21
+ opts.children();
22
+ parentRoutes.pop();
23
+ }
24
+ };
25
+ callback(defineRoute);
26
+ return routes;
27
+ }
28
+ exports.defineRoutes = defineRoutes;
@@ -0,0 +1,3 @@
1
+ export * from './routesConfig';
2
+ export * from './routesConvention';
3
+ export * from './routeUtils';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ // TODO
3
+ // [x] convention route
4
+ // config route
5
+ // programming route
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./routesConfig"), exports);
18
+ __exportStar(require("./routesConvention"), exports);
19
+ __exportStar(require("./routeUtils"), exports);
@@ -0,0 +1,7 @@
1
+ import { IRoute } from '../types';
2
+ export declare function addParentRoute(opts: {
3
+ id?: string;
4
+ addToAll?: boolean;
5
+ target: IRoute;
6
+ routes: Record<string, IRoute>;
7
+ }): void;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addParentRoute = void 0;
4
+ function addParentRoute(opts) {
5
+ if (opts.addToAll) {
6
+ for (const id of Object.keys(opts.routes)) {
7
+ if (opts.routes[id].parentId === undefined) {
8
+ opts.routes[id].parentId = opts.target.id;
9
+ }
10
+ }
11
+ }
12
+ else if (opts.id) {
13
+ opts.routes[opts.id].parentId = opts.target.id;
14
+ }
15
+ else {
16
+ throw new Error(`addParentRoute failed, opts.addToAll or opts.id must be supplied.`);
17
+ }
18
+ // add new route
19
+ opts.routes[opts.target.id] = opts.target;
20
+ }
21
+ exports.addParentRoute = addParentRoute;