@umijs/core 4.0.42 → 4.0.44

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.
@@ -1 +1 @@
1
- (function(){var e={277: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__(277);module.exports=t})();
1
+ (function(){var e={696: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}const a=getDiff(e,r,[],{remove:[],replace:[],add:[]});return a.remove.reverse().concat(a.replace).concat(a.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__(696);module.exports=t})();
@@ -1 +1 @@
1
- {"name":"just-diff","author":"Angus Croll","license":"MIT","types":"index.d.ts"}
1
+ {"name":"just-diff","version":"5.2.0","author":"Angus Croll","license":"MIT","types":"index.d.ts"}
@@ -1,4 +1,4 @@
1
- import { Env } from '../types';
1
+ import { Env, type IOnChangeTypes } from '../types';
2
2
  interface IOpts {
3
3
  cwd: string;
4
4
  env: Env;
@@ -6,7 +6,6 @@ interface IOpts {
6
6
  defaultConfigFiles?: string[];
7
7
  }
8
8
  declare type ISchema = Record<string, any>;
9
- declare type IOnChangeTypes = Record<string, string | Function>;
10
9
  export declare class Config {
11
10
  opts: IOpts;
12
11
  mainConfigFile: string | null;
@@ -16,7 +16,10 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
18
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
20
23
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
24
 
22
25
  // src/config/config.ts
@@ -65,35 +68,41 @@ var Config = class {
65
68
  };
66
69
  }
67
70
  watch(opts) {
68
- const watcher = import_utils.chokidar.watch([
69
- ...this.files,
70
- ...this.mainConfigFile ? [] : (0, import_utils2.getAbsFiles)({
71
- files: this.opts.defaultConfigFiles || import_constants.DEFAULT_CONFIG_FILES,
71
+ const watcher = import_utils.chokidar.watch(
72
+ [
73
+ ...this.files,
74
+ ...this.mainConfigFile ? [] : (0, import_utils2.getAbsFiles)({
75
+ files: this.opts.defaultConfigFiles || import_constants.DEFAULT_CONFIG_FILES,
76
+ cwd: this.opts.cwd
77
+ })
78
+ ],
79
+ {
80
+ ignoreInitial: true,
72
81
  cwd: this.opts.cwd
73
- })
74
- ], {
75
- ignoreInitial: true,
76
- cwd: this.opts.cwd
77
- });
78
- watcher.on("all", import_utils.lodash.debounce((event, path) => {
79
- const { config: origin } = this.prevConfig;
80
- const { config: updated, files } = this.getConfig({
81
- schemas: opts.schemas
82
- });
83
- watcher.add(files);
84
- const data = Config.diffConfigs({
85
- origin,
86
- updated,
87
- onChangeTypes: opts.onChangeTypes
88
- });
89
- opts.onChange({
90
- data,
91
- event,
92
- path
93
- }).catch((e) => {
94
- throw e;
95
- });
96
- }, import_constants.WATCH_DEBOUNCE_STEP));
82
+ }
83
+ );
84
+ watcher.on(
85
+ "all",
86
+ import_utils.lodash.debounce((event, path) => {
87
+ const { config: origin } = this.prevConfig;
88
+ const { config: updated, files } = this.getConfig({
89
+ schemas: opts.schemas
90
+ });
91
+ watcher.add(files);
92
+ const data = Config.diffConfigs({
93
+ origin,
94
+ updated,
95
+ onChangeTypes: opts.onChangeTypes
96
+ });
97
+ opts.onChange({
98
+ data,
99
+ event,
100
+ path
101
+ }).catch((e) => {
102
+ throw e;
103
+ });
104
+ }, import_constants.WATCH_DEBOUNCE_STEP)
105
+ );
97
106
  return () => watcher.close();
98
107
  }
99
108
  static getMainConfigFile(opts) {
@@ -113,15 +122,17 @@ var Config = class {
113
122
  const specifiedEnv = opts.specifiedEnv || "";
114
123
  if (mainConfigFile) {
115
124
  const env = import_constants.SHORT_ENV[opts.env] || opts.env;
116
- ret.push(...[
117
- mainConfigFile,
118
- specifiedEnv && (0, import_utils2.addExt)({ file: mainConfigFile, ext: `.${specifiedEnv}` }),
119
- (0, import_utils2.addExt)({ file: mainConfigFile, ext: `.${env}` }),
120
- specifiedEnv && (0, import_utils2.addExt)({
121
- file: mainConfigFile,
122
- ext: `.${env}.${specifiedEnv}`
123
- })
124
- ].filter(Boolean));
125
+ ret.push(
126
+ ...[
127
+ mainConfigFile,
128
+ specifiedEnv && (0, import_utils2.addExt)({ file: mainConfigFile, ext: `.${specifiedEnv}` }),
129
+ (0, import_utils2.addExt)({ file: mainConfigFile, ext: `.${env}` }),
130
+ specifiedEnv && (0, import_utils2.addExt)({
131
+ file: mainConfigFile,
132
+ ext: `.${env}.${specifiedEnv}`
133
+ })
134
+ ].filter(Boolean)
135
+ );
125
136
  if (opts.env === import_types.Env.development) {
126
137
  ret.push((0, import_utils2.addExt)({ file: mainConfigFile, ext: import_constants.LOCAL_EXT }));
127
138
  }
@@ -174,12 +185,18 @@ var Config = class {
174
185
  if (error)
175
186
  errors.set(key, error);
176
187
  }
177
- (0, import_assert.default)(errors.size === 0, `Invalid config values: ${Array.from(errors.keys()).join(", ")}
188
+ (0, import_assert.default)(
189
+ errors.size === 0,
190
+ `Invalid config values: ${Array.from(errors.keys()).join(", ")}
178
191
  ${Array.from(errors.keys()).map((key) => {
179
- return `Invalid value for ${key}:
192
+ return `Invalid value for ${key}:
180
193
  ${errors.get(key).message}`;
181
- })}`);
182
- (0, import_assert.default)(configKeys.size === 0, `Invalid config keys: ${Array.from(configKeys).join(", ")}`);
194
+ })}`
195
+ );
196
+ (0, import_assert.default)(
197
+ configKeys.size === 0,
198
+ `Invalid config keys: ${Array.from(configKeys).join(", ")}`
199
+ );
183
200
  }
184
201
  static diffConfigs(opts) {
185
202
  const patch = (0, import_just_diff.diff)(opts.origin, opts.updated);
@@ -34,7 +34,9 @@ function addParentRoute(opts) {
34
34
  opts.routes[opts.id].parentId = opts.target.id;
35
35
  }
36
36
  } else {
37
- throw new Error(`addParentRoute failed, opts.addToAll or opts.id must be supplied.`);
37
+ throw new Error(
38
+ `addParentRoute failed, opts.addToAll or opts.id must be supplied.`
39
+ );
38
40
  }
39
41
  opts.routes[opts.target.id] = opts.target;
40
42
  }
@@ -16,7 +16,10 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
18
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
20
23
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
24
 
22
25
  // src/route/routesConfig.ts
@@ -47,7 +50,10 @@ function transformRoutes(opts) {
47
50
  });
48
51
  }
49
52
  function transformRoute(opts) {
50
- (0, import_assert.default)(!opts.route.children, "children is not allowed in route props, use routes instead.");
53
+ (0, import_assert.default)(
54
+ !opts.route.children,
55
+ "children is not allowed in route props, use routes instead."
56
+ );
51
57
  const id = String(opts.memo.id++);
52
58
  const { routes, component, wrappers, ...routeProps } = opts.route;
53
59
  let absPath = opts.route.path;
@@ -43,9 +43,13 @@ function getConventionRoutes(opts) {
43
43
  });
44
44
  const routeIds = Object.keys(files).sort(import_utils2.byLongestFirst);
45
45
  function defineNestedRoutes(defineRoute, parentId) {
46
- const childRouteIds = routeIds.filter((id) => (0, import_utils2.findParentRouteId)(routeIds, id) === parentId);
46
+ const childRouteIds = routeIds.filter(
47
+ (id) => (0, import_utils2.findParentRouteId)(routeIds, id) === parentId
48
+ );
47
49
  for (let routeId of childRouteIds) {
48
- let routePath = createRoutePath(parentId ? routeId.slice(parentId.length + 1) : routeId);
50
+ let routePath = createRoutePath(
51
+ parentId ? routeId.slice(parentId.length + 1) : routeId
52
+ );
49
53
  defineRoute({
50
54
  path: routePath,
51
55
  file: `${opts.prefix || ""}${files[routeId]}`,
@@ -64,7 +68,9 @@ function visitFiles(opts) {
64
68
  let stat = (0, import_fs.lstatSync)(file);
65
69
  if (stat.isDirectory()) {
66
70
  visitFiles({ ...opts, dir: file });
67
- } else if (stat.isFile() && [".tsx", ".ts", ".js", ".jsx", ".md", ".mdx", ".vue"].includes((0, import_path.extname)(file))) {
71
+ } else if (stat.isFile() && [".tsx", ".ts", ".js", ".jsx", ".md", ".mdx", ".vue"].includes(
72
+ (0, import_path.extname)(file)
73
+ )) {
68
74
  opts.visitor((0, import_path.relative)(opts.baseDir, file));
69
75
  }
70
76
  }
@@ -16,7 +16,10 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
18
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
20
23
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
24
 
22
25
  // src/service/hook.ts
@@ -28,7 +31,10 @@ module.exports = __toCommonJS(hook_exports);
28
31
  var import_assert = __toESM(require("assert"));
29
32
  var Hook = class {
30
33
  constructor(opts) {
31
- (0, import_assert.default)(opts.key && opts.fn, `Invalid hook ${opts}, key and fn must supplied.`);
34
+ (0, import_assert.default)(
35
+ opts.key && opts.fn,
36
+ `Invalid hook ${opts}, key and fn must supplied.`
37
+ );
32
38
  this.plugin = opts.plugin;
33
39
  this.key = opts.key;
34
40
  this.fn = opts.fn;
@@ -16,7 +16,10 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
18
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
20
23
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
24
 
22
25
  // src/service/plugin.ts
@@ -43,7 +46,10 @@ var Plugin = class {
43
46
  this.type = opts.type;
44
47
  this.path = (0, import_utils.winPath)(opts.path);
45
48
  this.cwd = opts.cwd;
46
- (0, import_assert.default)((0, import_fs.existsSync)(this.path), `Invalid ${this.type} ${this.path}, it's not exists.`);
49
+ (0, import_assert.default)(
50
+ (0, import_fs.existsSync)(this.path),
51
+ `Invalid ${this.type} ${this.path}, it's not exists.`
52
+ );
47
53
  let pkg = null;
48
54
  let isPkgEntry = false;
49
55
  const pkgJSONPath = import_utils.pkgUp.pkgUpSync({ cwd: this.path });
@@ -63,7 +69,10 @@ var Plugin = class {
63
69
  try {
64
70
  ret = require(this.path);
65
71
  } catch (e) {
66
- throw new Error(`Register ${this.type} ${this.path} failed, since ${e.message}`, { cause: e });
72
+ throw new Error(
73
+ `Register ${this.type} ${this.path} failed, since ${e.message}`,
74
+ { cause: e }
75
+ );
67
76
  } finally {
68
77
  import_utils.register.restore();
69
78
  }
@@ -85,7 +94,9 @@ var Plugin = class {
85
94
  } else if ((0, import_utils.winPath)(this.path).startsWith((0, import_utils.winPath)(this.cwd))) {
86
95
  id = `./${(0, import_utils.winPath)((0, import_path.relative)(this.cwd, this.path))}`;
87
96
  } else if (opts.pkgJSONPath) {
88
- id = (0, import_utils.winPath)((0, import_path.join)(opts.pkg.name, (0, import_path.relative)((0, import_path.dirname)(opts.pkgJSONPath), this.path)));
97
+ id = (0, import_utils.winPath)(
98
+ (0, import_path.join)(opts.pkg.name, (0, import_path.relative)((0, import_path.dirname)(opts.pkgJSONPath), this.path))
99
+ );
89
100
  } else {
90
101
  id = (0, import_utils.winPath)(this.path);
91
102
  }
@@ -97,7 +108,9 @@ var Plugin = class {
97
108
  function nameToKey(name) {
98
109
  return name.split(".").map((part) => import_utils.lodash.camelCase(part)).join(".");
99
110
  }
100
- return nameToKey(opts.isPkgEntry ? Plugin.stripNoneUmiScope(opts.pkg.name).replace(RE[this.type], "") : (0, import_path.basename)(this.path, (0, import_path.extname)(this.path)));
111
+ return nameToKey(
112
+ opts.isPkgEntry ? Plugin.stripNoneUmiScope(opts.pkg.name).replace(RE[this.type], "") : (0, import_path.basename)(this.path, (0, import_path.extname)(this.path))
113
+ );
101
114
  }
102
115
  static isPluginOrPreset(type, name) {
103
116
  return RE[type].test(Plugin.stripNoneUmiScope(name));
@@ -116,7 +129,10 @@ var Plugin = class {
116
129
  ...(process.env[`${opts.prefix}_${types}`.toUpperCase()] || "").split(",").filter(Boolean),
117
130
  ...opts.userConfig[types] || []
118
131
  ].map((path) => {
119
- (0, import_assert.default)(typeof path === "string", `Invalid plugin ${path}, it must be string.`);
132
+ (0, import_assert.default)(
133
+ typeof path === "string",
134
+ `Invalid plugin ${path}, it must be string.`
135
+ );
120
136
  let resolved;
121
137
  try {
122
138
  resolved = import_utils.resolve.sync(path, {
@@ -16,7 +16,10 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
18
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
20
23
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
24
 
22
25
  // src/service/pluginAPI.ts
@@ -67,7 +70,9 @@ var PluginAPI = class {
67
70
  describe(opts) {
68
71
  var _a;
69
72
  if (opts.enableBy === import_types.EnableBy.config && ((_a = opts.config) == null ? void 0 : _a.default)) {
70
- throw new Error(`[plugin: ${this.plugin.id}] The config.default is not allowed when enableBy is EnableBy.config.`);
73
+ throw new Error(
74
+ `[plugin: ${this.plugin.id}] The config.default is not allowed when enableBy is EnableBy.config.`
75
+ );
71
76
  }
72
77
  this.plugin.merge(opts);
73
78
  }
@@ -77,8 +82,16 @@ var PluginAPI = class {
77
82
  const registerCommand = (commandOpts) => {
78
83
  var _a;
79
84
  const { name, configResolveMode } = commandOpts;
80
- (0, import_assert.default)(!configResolveMode || resolveConfigModes.indexOf(configResolveMode) >= 0, `configResolveMode must be one of ${resolveConfigModes.join(",")}, but got ${configResolveMode}`);
81
- (0, import_assert.default)(!this.service.commands[name], `api.registerCommand() failed, the command ${name} is exists from ${(_a = this.service.commands[name]) == null ? void 0 : _a.plugin.id}.`);
85
+ (0, import_assert.default)(
86
+ !configResolveMode || resolveConfigModes.indexOf(configResolveMode) >= 0,
87
+ `configResolveMode must be one of ${resolveConfigModes.join(
88
+ ","
89
+ )}, but got ${configResolveMode}`
90
+ );
91
+ (0, import_assert.default)(
92
+ !this.service.commands[name],
93
+ `api.registerCommand() failed, the command ${name} is exists from ${(_a = this.service.commands[name]) == null ? void 0 : _a.plugin.id}.`
94
+ );
82
95
  this.service.commands[name] = new import_command.Command({
83
96
  ...commandOpts,
84
97
  plugin: this.plugin
@@ -95,7 +108,10 @@ var PluginAPI = class {
95
108
  registerGenerator(opts) {
96
109
  var _a;
97
110
  const { key } = opts;
98
- (0, import_assert.default)(!this.service.generators[key], `api.registerGenerator() failed, the generator ${key} is exists from ${(_a = this.service.generators[key]) == null ? void 0 : _a.plugin.id}.`);
111
+ (0, import_assert.default)(
112
+ !this.service.generators[key],
113
+ `api.registerGenerator() failed, the generator ${key} is exists from ${(_a = this.service.generators[key]) == null ? void 0 : _a.plugin.id}.`
114
+ );
99
115
  this.service.generators[key] = (0, import_generator.makeGenerator)({
100
116
  ...opts,
101
117
  plugin: this.plugin
@@ -103,12 +119,20 @@ var PluginAPI = class {
103
119
  }
104
120
  register(opts) {
105
121
  var _a, _b;
106
- (0, import_assert.default)(this.service.stage <= import_types.ServiceStage.initPlugins, "api.register() should not be called after plugin register stage.");
122
+ (0, import_assert.default)(
123
+ this.service.stage <= import_types.ServiceStage.initPlugins,
124
+ "api.register() should not be called after plugin register stage."
125
+ );
107
126
  (_a = this.service.hooks)[_b = opts.key] || (_a[_b] = []);
108
- this.service.hooks[opts.key].push(new import_hook.Hook({ ...opts, plugin: this.plugin }));
127
+ this.service.hooks[opts.key].push(
128
+ new import_hook.Hook({ ...opts, plugin: this.plugin })
129
+ );
109
130
  }
110
131
  registerMethod(opts) {
111
- (0, import_assert.default)(!this.service.pluginMethods[opts.name], `api.registerMethod() failed, method ${opts.name} is already exist.`);
132
+ (0, import_assert.default)(
133
+ !this.service.pluginMethods[opts.name],
134
+ `api.registerMethod() failed, method ${opts.name} is already exist.`
135
+ );
112
136
  this.service.pluginMethods[opts.name] = {
113
137
  plugin: this.plugin,
114
138
  fn: opts.fn || function(fn) {
@@ -120,20 +144,33 @@ var PluginAPI = class {
120
144
  };
121
145
  }
122
146
  registerPresets(source, presets) {
123
- (0, import_assert.default)(this.service.stage === import_types.ServiceStage.initPresets, `api.registerPresets() failed, it should only used in presets.`);
124
- source.splice(0, 0, ...presets.map((preset) => {
125
- return new import_plugin.Plugin({
126
- path: preset,
127
- cwd: this.service.cwd,
128
- type: import_types.PluginType.preset
129
- });
130
- }));
147
+ (0, import_assert.default)(
148
+ this.service.stage === import_types.ServiceStage.initPresets,
149
+ `api.registerPresets() failed, it should only used in presets.`
150
+ );
151
+ source.splice(
152
+ 0,
153
+ 0,
154
+ ...presets.map((preset) => {
155
+ return new import_plugin.Plugin({
156
+ path: preset,
157
+ cwd: this.service.cwd,
158
+ type: import_types.PluginType.preset
159
+ });
160
+ })
161
+ );
131
162
  }
132
163
  registerPlugins(source, plugins) {
133
- (0, import_assert.default)(this.service.stage === import_types.ServiceStage.initPresets || this.service.stage === import_types.ServiceStage.initPlugins, `api.registerPlugins() failed, it should only be used in registering stage.`);
164
+ (0, import_assert.default)(
165
+ this.service.stage === import_types.ServiceStage.initPresets || this.service.stage === import_types.ServiceStage.initPlugins,
166
+ `api.registerPlugins() failed, it should only be used in registering stage.`
167
+ );
134
168
  const mappedPlugins = plugins.map((plugin) => {
135
169
  if (import_utils.lodash.isPlainObject(plugin)) {
136
- (0, import_assert.default)(plugin.id && plugin.key, `Invalid plugin object, id and key must supplied.`);
170
+ (0, import_assert.default)(
171
+ plugin.id && plugin.key,
172
+ `Invalid plugin object, id and key must supplied.`
173
+ );
137
174
  plugin.type = import_types.PluginType.plugin;
138
175
  plugin.enableBy = plugin.enableBy || import_types.EnableBy.register;
139
176
  plugin.apply = plugin.apply || (() => () => {
@@ -158,7 +195,10 @@ var PluginAPI = class {
158
195
  skipPlugins(keys) {
159
196
  keys.forEach((key) => {
160
197
  (0, import_assert.default)(!(this.plugin.key === key), `plugin ${key} can't skip itself!`);
161
- (0, import_assert.default)(this.service.keyToPluginMap[key], `key: ${key} is not be registered by any plugin. You can't skip it!`);
198
+ (0, import_assert.default)(
199
+ this.service.keyToPluginMap[key],
200
+ `key: ${key} is not be registered by any plugin. You can't skip it!`
201
+ );
162
202
  this.service.skipPluginIds.add(this.service.keyToPluginMap[key].id);
163
203
  });
164
204
  }
@@ -16,7 +16,10 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
18
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
20
23
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
24
 
22
25
  // src/service/service.ts
@@ -75,28 +78,38 @@ var Service = class {
75
78
  } else if (opts.key.startsWith("add")) {
76
79
  type = import_types.ApplyPluginsType.add;
77
80
  } else {
78
- throw new Error(`Invalid applyPlugins arguments, type must be supplied for key ${opts.key}.`);
81
+ throw new Error(
82
+ `Invalid applyPlugins arguments, type must be supplied for key ${opts.key}.`
83
+ );
79
84
  }
80
85
  }
81
86
  switch (type) {
82
87
  case import_types.ApplyPluginsType.add:
83
- (0, import_assert.default)(!("initialValue" in opts) || Array.isArray(opts.initialValue), `applyPlugins failed, opts.initialValue must be Array if opts.type is add.`);
88
+ (0, import_assert.default)(
89
+ !("initialValue" in opts) || Array.isArray(opts.initialValue),
90
+ `applyPlugins failed, opts.initialValue must be Array if opts.type is add.`
91
+ );
84
92
  const tAdd = new import_tapable.AsyncSeriesWaterfallHook(["memo"]);
85
93
  for (const hook of hooks) {
86
94
  if (!this.isPluginEnable(hook))
87
95
  continue;
88
- tAdd.tapPromise({
89
- name: hook.plugin.key,
90
- stage: hook.stage || 0,
91
- before: hook.before
92
- }, async (memo) => {
93
- var _a, _b;
94
- const dateStart = new Date();
95
- const items = await hook.fn(opts.args);
96
- (_a = hook.plugin.time.hooks)[_b = opts.key] || (_a[_b] = []);
97
- hook.plugin.time.hooks[opts.key].push(new Date().getTime() - dateStart.getTime());
98
- return memo.concat(items);
99
- });
96
+ tAdd.tapPromise(
97
+ {
98
+ name: hook.plugin.key,
99
+ stage: hook.stage || 0,
100
+ before: hook.before
101
+ },
102
+ async (memo) => {
103
+ var _a, _b;
104
+ const dateStart = new Date();
105
+ const items = await hook.fn(opts.args);
106
+ (_a = hook.plugin.time.hooks)[_b = opts.key] || (_a[_b] = []);
107
+ hook.plugin.time.hooks[opts.key].push(
108
+ new Date().getTime() - dateStart.getTime()
109
+ );
110
+ return memo.concat(items);
111
+ }
112
+ );
100
113
  }
101
114
  return tAdd.promise(opts.initialValue || []);
102
115
  case import_types.ApplyPluginsType.modify:
@@ -104,18 +117,23 @@ var Service = class {
104
117
  for (const hook of hooks) {
105
118
  if (!this.isPluginEnable(hook))
106
119
  continue;
107
- tModify.tapPromise({
108
- name: hook.plugin.key,
109
- stage: hook.stage || 0,
110
- before: hook.before
111
- }, async (memo) => {
112
- var _a, _b;
113
- const dateStart = new Date();
114
- const ret = await hook.fn(memo, opts.args);
115
- (_a = hook.plugin.time.hooks)[_b = opts.key] || (_a[_b] = []);
116
- hook.plugin.time.hooks[opts.key].push(new Date().getTime() - dateStart.getTime());
117
- return ret;
118
- });
120
+ tModify.tapPromise(
121
+ {
122
+ name: hook.plugin.key,
123
+ stage: hook.stage || 0,
124
+ before: hook.before
125
+ },
126
+ async (memo) => {
127
+ var _a, _b;
128
+ const dateStart = new Date();
129
+ const ret = await hook.fn(memo, opts.args);
130
+ (_a = hook.plugin.time.hooks)[_b = opts.key] || (_a[_b] = []);
131
+ hook.plugin.time.hooks[opts.key].push(
132
+ new Date().getTime() - dateStart.getTime()
133
+ );
134
+ return ret;
135
+ }
136
+ );
119
137
  }
120
138
  return tModify.promise(opts.initialValue);
121
139
  case import_types.ApplyPluginsType.event:
@@ -123,17 +141,22 @@ var Service = class {
123
141
  const tEvent2 = new import_tapable.SyncWaterfallHook(["_"]);
124
142
  hooks.forEach((hook) => {
125
143
  if (this.isPluginEnable(hook)) {
126
- tEvent2.tap({
127
- name: hook.plugin.key,
128
- stage: hook.stage || 0,
129
- before: hook.before
130
- }, () => {
131
- var _a, _b;
132
- const dateStart = new Date();
133
- hook.fn(opts.args);
134
- (_a = hook.plugin.time.hooks)[_b = opts.key] || (_a[_b] = []);
135
- hook.plugin.time.hooks[opts.key].push(new Date().getTime() - dateStart.getTime());
136
- });
144
+ tEvent2.tap(
145
+ {
146
+ name: hook.plugin.key,
147
+ stage: hook.stage || 0,
148
+ before: hook.before
149
+ },
150
+ () => {
151
+ var _a, _b;
152
+ const dateStart = new Date();
153
+ hook.fn(opts.args);
154
+ (_a = hook.plugin.time.hooks)[_b = opts.key] || (_a[_b] = []);
155
+ hook.plugin.time.hooks[opts.key].push(
156
+ new Date().getTime() - dateStart.getTime()
157
+ );
158
+ }
159
+ );
137
160
  }
138
161
  });
139
162
  return tEvent2.call(1);
@@ -142,21 +165,28 @@ var Service = class {
142
165
  for (const hook of hooks) {
143
166
  if (!this.isPluginEnable(hook))
144
167
  continue;
145
- tEvent.tapPromise({
146
- name: hook.plugin.key,
147
- stage: hook.stage || 0,
148
- before: hook.before
149
- }, async () => {
150
- var _a, _b;
151
- const dateStart = new Date();
152
- await hook.fn(opts.args);
153
- (_a = hook.plugin.time.hooks)[_b = opts.key] || (_a[_b] = []);
154
- hook.plugin.time.hooks[opts.key].push(new Date().getTime() - dateStart.getTime());
155
- });
168
+ tEvent.tapPromise(
169
+ {
170
+ name: hook.plugin.key,
171
+ stage: hook.stage || 0,
172
+ before: hook.before
173
+ },
174
+ async () => {
175
+ var _a, _b;
176
+ const dateStart = new Date();
177
+ await hook.fn(opts.args);
178
+ (_a = hook.plugin.time.hooks)[_b = opts.key] || (_a[_b] = []);
179
+ hook.plugin.time.hooks[opts.key].push(
180
+ new Date().getTime() - dateStart.getTime()
181
+ );
182
+ }
183
+ );
156
184
  }
157
185
  return tEvent.promise(1);
158
186
  default:
159
- throw new Error(`applyPlugins failed, type is not defined or is not matched, got ${opts.type}.`);
187
+ throw new Error(
188
+ `applyPlugins failed, type is not defined or is not matched, got ${opts.type}.`
189
+ );
160
190
  }
161
191
  }
162
192
  async run(opts) {
@@ -198,8 +228,12 @@ var Service = class {
198
228
  const { plugins, presets } = import_plugin.Plugin.getPluginsAndPresets({
199
229
  cwd: this.cwd,
200
230
  pkg,
201
- plugins: [require.resolve("./generatePlugin")].concat(this.opts.plugins || []),
202
- presets: [require.resolve("./servicePlugin")].concat(this.opts.presets || []),
231
+ plugins: [require.resolve("./generatePlugin")].concat(
232
+ this.opts.plugins || []
233
+ ),
234
+ presets: [require.resolve("./servicePlugin")].concat(
235
+ this.opts.presets || []
236
+ ),
203
237
  userConfig: this.userConfig,
204
238
  prefix
205
239
  });
@@ -279,13 +313,18 @@ var Service = class {
279
313
  return paths;
280
314
  }
281
315
  async resolveConfig() {
282
- (0, import_assert.default)(this.stage > import_types.ServiceStage.init, `Can't generate final config before init stage`);
316
+ (0, import_assert.default)(
317
+ this.stage > import_types.ServiceStage.init,
318
+ `Can't generate final config before init stage`
319
+ );
283
320
  const resolveMode = this.commands[this.name].configResolveMode;
284
321
  const config = await this.applyPlugins({
285
322
  key: "modifyConfig",
286
- initialValue: import_utils.lodash.cloneDeep(resolveMode === "strict" ? this.configManager.getConfig({
287
- schemas: this.configSchemas
288
- }).config : this.configManager.getUserConfig().config),
323
+ initialValue: import_utils.lodash.cloneDeep(
324
+ resolveMode === "strict" ? this.configManager.getConfig({
325
+ schemas: this.configSchemas
326
+ }).config : this.configManager.getUserConfig().config
327
+ ),
289
328
  args: { paths: this.paths }
290
329
  });
291
330
  const defaultConfig = await this.applyPlugins({
@@ -315,14 +354,23 @@ var Service = class {
315
354
  }
316
355
  async initPlugin(opts) {
317
356
  var _a, _b;
318
- (0, import_assert.default)(!this.plugins[opts.plugin.id], `${opts.plugin.type} ${opts.plugin.id} is already registered by ${(_a = this.plugins[opts.plugin.id]) == null ? void 0 : _a.path}, ${opts.plugin.type} from ${opts.plugin.path} register failed.`);
357
+ (0, import_assert.default)(
358
+ !this.plugins[opts.plugin.id],
359
+ `${opts.plugin.type} ${opts.plugin.id} is already registered by ${(_a = this.plugins[opts.plugin.id]) == null ? void 0 : _a.path}, ${opts.plugin.type} from ${opts.plugin.path} register failed.`
360
+ );
319
361
  this.plugins[opts.plugin.id] = opts.plugin;
320
362
  const pluginAPI = new import_pluginAPI.PluginAPI({
321
363
  plugin: opts.plugin,
322
364
  service: this
323
365
  });
324
- pluginAPI.registerPresets = pluginAPI.registerPresets.bind(pluginAPI, opts.presets || []);
325
- pluginAPI.registerPlugins = pluginAPI.registerPlugins.bind(pluginAPI, opts.plugins);
366
+ pluginAPI.registerPresets = pluginAPI.registerPresets.bind(
367
+ pluginAPI,
368
+ opts.presets || []
369
+ );
370
+ pluginAPI.registerPlugins = pluginAPI.registerPlugins.bind(
371
+ pluginAPI,
372
+ opts.plugins
373
+ );
326
374
  const proxyPluginAPI = import_pluginAPI.PluginAPI.proxyPluginAPI({
327
375
  service: this,
328
376
  pluginAPI,
@@ -354,21 +402,28 @@ var Service = class {
354
402
  if (opts.plugin.type === "plugin") {
355
403
  (0, import_assert.default)(!ret, `plugin should return nothing`);
356
404
  }
357
- (0, import_assert.default)(!this.keyToPluginMap[opts.plugin.key], `key ${opts.plugin.key} is already registered by ${(_b = this.keyToPluginMap[opts.plugin.key]) == null ? void 0 : _b.path}, ${opts.plugin.type} from ${opts.plugin.path} register failed.`);
405
+ (0, import_assert.default)(
406
+ !this.keyToPluginMap[opts.plugin.key],
407
+ `key ${opts.plugin.key} is already registered by ${(_b = this.keyToPluginMap[opts.plugin.key]) == null ? void 0 : _b.path}, ${opts.plugin.type} from ${opts.plugin.path} register failed.`
408
+ );
358
409
  this.keyToPluginMap[opts.plugin.key] = opts.plugin;
359
410
  if (ret == null ? void 0 : ret.presets) {
360
- ret.presets = ret.presets.map((preset) => new import_plugin.Plugin({
361
- path: preset,
362
- type: import_types.PluginType.preset,
363
- cwd: this.cwd
364
- }));
411
+ ret.presets = ret.presets.map(
412
+ (preset) => new import_plugin.Plugin({
413
+ path: preset,
414
+ type: import_types.PluginType.preset,
415
+ cwd: this.cwd
416
+ })
417
+ );
365
418
  }
366
419
  if (ret == null ? void 0 : ret.plugins) {
367
- ret.plugins = ret.plugins.map((plugin) => new import_plugin.Plugin({
368
- path: plugin,
369
- type: import_types.PluginType.plugin,
370
- cwd: this.cwd
371
- }));
420
+ ret.plugins = ret.plugins.map(
421
+ (plugin) => new import_plugin.Plugin({
422
+ path: plugin,
423
+ type: import_types.PluginType.plugin,
424
+ cwd: this.cwd
425
+ })
426
+ );
372
427
  }
373
428
  return ret || {};
374
429
  }
@@ -408,10 +463,14 @@ var Service = class {
408
463
  }).join("\n");
409
464
  if (altCmds.length) {
410
465
  console.log();
411
- console.log([
412
- import_utils.chalk.cyan(altCmds.length === 1 ? "Did you mean this command ?" : "Did you mean one of these commands ?"),
413
- printHelper
414
- ].join("\n"));
466
+ console.log(
467
+ [
468
+ import_utils.chalk.cyan(
469
+ altCmds.length === 1 ? "Did you mean this command ?" : "Did you mean one of these commands ?"
470
+ ),
471
+ printHelper
472
+ ].join("\n")
473
+ );
415
474
  console.log();
416
475
  }
417
476
  }
package/dist/types.d.ts CHANGED
@@ -30,6 +30,8 @@ export declare enum ConfigChangeType {
30
30
  reload = "reload",
31
31
  regenerateTmpFiles = "regenerateTmpFiles"
32
32
  }
33
+ export declare type ChangeTypeValue = string | `${ConfigChangeType}` | Function;
34
+ export declare type IOnChangeTypes = Record<string, ChangeTypeValue>;
33
35
  export declare enum ApplyPluginsType {
34
36
  add = "add",
35
37
  modify = "modify",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/core",
3
- "version": "4.0.42",
3
+ "version": "4.0.44",
4
4
  "homepage": "https://github.com/umijs/umi/tree/master/packages/core#readme",
5
5
  "bugs": "https://github.com/umijs/umi/issues",
6
6
  "repository": {
@@ -21,13 +21,13 @@
21
21
  "test": "umi-scripts jest-turbo"
22
22
  },
23
23
  "dependencies": {
24
- "@umijs/bundler-utils": "4.0.42",
25
- "@umijs/utils": "4.0.42"
24
+ "@umijs/bundler-utils": "4.0.44",
25
+ "@umijs/utils": "4.0.44"
26
26
  },
27
27
  "devDependencies": {
28
28
  "dotenv": "16.0.0",
29
29
  "dotenv-expand": "8.0.3",
30
- "just-diff": "5.0.1"
30
+ "just-diff": "5.2.0"
31
31
  },
32
32
  "publishConfig": {
33
33
  "access": "public"