@umijs/core 4.0.0-rc.3 → 4.0.0-rc.6

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/dist/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -5,7 +5,11 @@
5
5
  // programming route
6
6
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
7
  if (k2 === undefined) k2 = k;
8
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
9
13
  }) : (function(o, m, k, k2) {
10
14
  if (k2 === undefined) k2 = k;
11
15
  o[k2] = m[k];
@@ -7,6 +7,7 @@ export declare function getPaths(opts: {
7
7
  cwd: string;
8
8
  absSrcPath: string;
9
9
  absPagesPath: string;
10
+ absApiRoutesPath: string;
10
11
  absTmpPath: string;
11
12
  absNodeModulesPath: string;
12
13
  absOutputPath: string;
@@ -13,6 +13,7 @@ function getPaths(opts) {
13
13
  const src = winJoin(cwd, 'src');
14
14
  const absSrcPath = (0, fs_1.existsSync)(src) && (0, fs_1.statSync)(src).isDirectory() ? src : cwd;
15
15
  const absPagesPath = winJoin(absSrcPath, 'pages');
16
+ const absApiRoutesPath = winJoin(absSrcPath, 'api');
16
17
  const tmp = opts.env === types_1.Env.development
17
18
  ? `.${opts.prefix}`
18
19
  : `.${opts.prefix}-${opts.env}`;
@@ -23,6 +24,7 @@ function getPaths(opts) {
23
24
  cwd,
24
25
  absSrcPath,
25
26
  absPagesPath,
27
+ absApiRoutesPath,
26
28
  absTmpPath,
27
29
  absNodeModulesPath,
28
30
  absOutputPath,
@@ -33,7 +33,7 @@ export declare class PluginAPI {
33
33
  }): void;
34
34
  registerPresets(source: Plugin[], presets: any[]): void;
35
35
  registerPlugins(source: Plugin[], plugins: any[]): void;
36
- skipPlugins(ids: string[]): void;
36
+ skipPlugins(keys: string[]): void;
37
37
  static proxyPluginAPI(opts: {
38
38
  pluginAPI: PluginAPI;
39
39
  service: Service;
@@ -116,9 +116,11 @@ class PluginAPI {
116
116
  source.splice(0, 0, ...mappedPlugins);
117
117
  }
118
118
  }
119
- skipPlugins(ids) {
120
- ids.forEach((id) => {
121
- this.service.skipPluginIds.add(id);
119
+ skipPlugins(keys) {
120
+ keys.forEach((key) => {
121
+ (0, assert_1.default)(!(this.plugin.key === key), `plugin ${key} can't skip itself!`);
122
+ (0, assert_1.default)(this.service.keyToPluginMap[key], `key: ${key} is not be registered by any plugin. You can't skip it!`);
123
+ this.service.skipPluginIds.add(this.service.keyToPluginMap[key].id);
122
124
  });
123
125
  }
124
126
  static proxyPluginAPI(opts) {
@@ -39,6 +39,7 @@ export declare class Service {
39
39
  cwd?: string;
40
40
  absSrcPath?: string;
41
41
  absPagesPath?: string;
42
+ absApiRoutesPath?: string;
42
43
  absTmpPath?: string;
43
44
  absNodeModulesPath?: string;
44
45
  absOutputPath?: string;
@@ -110,6 +111,7 @@ export interface IServicePluginAPI {
110
111
  ConfigChangeType: typeof ConfigChangeType;
111
112
  EnableBy: typeof EnableBy;
112
113
  ServiceStage: typeof ServiceStage;
114
+ registerPresets: (presets: any[]) => void;
113
115
  registerPlugins: (plugins: (Plugin | {})[]) => void;
114
116
  }
115
117
  export {};
@@ -81,7 +81,7 @@ class Service {
81
81
  if (!this.isPluginEnable(hook))
82
82
  continue;
83
83
  tAdd.tapPromise({
84
- name: hook.plugin.id,
84
+ name: hook.plugin.key,
85
85
  stage: hook.stage,
86
86
  before: hook.before,
87
87
  }, (memo) => __awaiter(this, void 0, void 0, function* () {
@@ -96,7 +96,7 @@ class Service {
96
96
  if (!this.isPluginEnable(hook))
97
97
  continue;
98
98
  tModify.tapPromise({
99
- name: hook.plugin.id,
99
+ name: hook.plugin.key,
100
100
  stage: hook.stage,
101
101
  before: hook.before,
102
102
  }, (memo) => __awaiter(this, void 0, void 0, function* () {
@@ -110,7 +110,7 @@ class Service {
110
110
  if (!this.isPluginEnable(hook))
111
111
  continue;
112
112
  tEvent.tapPromise({
113
- name: hook.plugin.id,
113
+ name: hook.plugin.key,
114
114
  stage: hook.stage || 0,
115
115
  before: hook.before,
116
116
  }, () => __awaiter(this, void 0, void 0, function* () {
@@ -187,10 +187,6 @@ class Service {
187
187
  while (plugins.length) {
188
188
  yield this.initPlugin({ plugin: plugins.shift(), plugins });
189
189
  }
190
- // keyToPluginMap
191
- for (const id of Object.keys(this.plugins)) {
192
- this.keyToPluginMap[this.plugins[id].key] = this.plugins[id];
193
- }
194
190
  // collect configSchemas and configDefaults
195
191
  for (const id of Object.keys(this.plugins)) {
196
192
  const { config, key } = this.plugins[id];
@@ -291,7 +287,7 @@ class Service {
291
287
  });
292
288
  }
293
289
  initPlugin(opts) {
294
- var _a;
290
+ var _a, _b;
295
291
  return __awaiter(this, void 0, void 0, function* () {
296
292
  // register to this.plugins
297
293
  (0, assert_1.default)(!this.plugins[opts.plugin.id], `${opts.plugin.type} ${opts.plugin.id} is already registered by ${(_a = this.plugins[opts.plugin.id]) === null || _a === void 0 ? void 0 : _a.path}, ${opts.plugin.type} from ${opts.plugin.path} register failed.`);
@@ -335,6 +331,9 @@ class Service {
335
331
  if (opts.plugin.type === 'plugin') {
336
332
  (0, assert_1.default)(!ret, `plugin should return nothing`);
337
333
  }
334
+ // key should be unique
335
+ (0, assert_1.default)(!this.keyToPluginMap[opts.plugin.key], `key ${opts.plugin.key} is already registered by ${(_b = this.keyToPluginMap[opts.plugin.key]) === null || _b === void 0 ? void 0 : _b.path}, ${opts.plugin.type} from ${opts.plugin.path} register failed.`);
336
+ this.keyToPluginMap[opts.plugin.key] = opts.plugin;
338
337
  if (ret === null || ret === void 0 ? void 0 : ret.presets) {
339
338
  ret.presets = ret.presets.map((preset) => new plugin_1.Plugin({
340
339
  path: preset,
@@ -369,7 +368,15 @@ class Service {
369
368
  return false;
370
369
  if (enableBy === types_1.EnableBy.config) {
371
370
  // TODO: 提供单独的命令用于启用插件
372
- return key in this.userConfig;
371
+ // this.userConfig 中如果存在,启用
372
+ // this.config 好了之后如果存在,启用
373
+ // this.config 在 modifyConfig 和 modifyDefaultConfig 之后才会 ready
374
+ // 这意味着 modifyConfig 和 modifyDefaultConfig 只能判断 api.userConfig
375
+ // 举个具体场景:
376
+ // - p1 enableBy config, p2 modifyDefaultConfig p1 = {}
377
+ // - p1 里 modifyConfig 和 modifyDefaultConfig 仅 userConfig 里有 p1 有效,其他 p2 开启时即有效
378
+ // - p2 里因为用了 modifyDefaultConfig,如果 p2 是 enableBy config,需要 userConfig 里配 p2,p2 和 p1 才有效
379
+ return key in this.userConfig || (this.config && key in this.config);
373
380
  }
374
381
  if (typeof enableBy === 'function')
375
382
  return enableBy({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/core",
3
- "version": "4.0.0-rc.3",
3
+ "version": "4.0.0-rc.6",
4
4
  "homepage": "https://github.com/umijs/umi-next/tree/master/packages/core#readme",
5
5
  "bugs": "https://github.com/umijs/umi-next/issues",
6
6
  "repository": {
@@ -20,8 +20,8 @@
20
20
  "dev": "pnpm build -- --watch"
21
21
  },
22
22
  "dependencies": {
23
- "@umijs/bundler-utils": "4.0.0-rc.3",
24
- "@umijs/utils": "4.0.0-rc.3"
23
+ "@umijs/bundler-utils": "4.0.0-rc.6",
24
+ "@umijs/utils": "4.0.0-rc.6"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@hapi/joi": "17.1.1",