@umijs/core 4.6.0 → 4.6.2

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.
@@ -42,23 +42,20 @@ var import_just_diff = require("../../compiled/just-diff");
42
42
  var import_constants = require("../constants");
43
43
  var import_types = require("../types");
44
44
  var import_utils2 = require("./utils");
45
- var Config = class _Config {
46
- opts;
47
- mainConfigFile;
48
- prevConfig;
49
- files = [];
45
+ var Config = class {
50
46
  constructor(opts) {
47
+ this.files = [];
51
48
  this.opts = opts;
52
- this.mainConfigFile = _Config.getMainConfigFile(this.opts);
49
+ this.mainConfigFile = Config.getMainConfigFile(this.opts);
53
50
  this.prevConfig = null;
54
51
  }
55
52
  getUserConfig() {
56
- const configFiles = _Config.getConfigFiles({
53
+ const configFiles = Config.getConfigFiles({
57
54
  mainConfigFile: this.mainConfigFile,
58
55
  env: this.opts.env,
59
56
  specifiedEnv: this.opts.specifiedEnv
60
57
  });
61
- return _Config.getUserConfig({
58
+ return Config.getUserConfig({
62
59
  configFiles: (0, import_utils2.getAbsFiles)({
63
60
  files: configFiles,
64
61
  cwd: this.opts.cwd
@@ -67,7 +64,7 @@ var Config = class _Config {
67
64
  }
68
65
  getConfig(opts) {
69
66
  const { config, files } = this.getUserConfig();
70
- _Config.validateConfig({ config, schemas: opts.schemas });
67
+ Config.validateConfig({ config, schemas: opts.schemas });
71
68
  this.files = files;
72
69
  return this.prevConfig = {
73
70
  config,
@@ -96,7 +93,7 @@ var Config = class _Config {
96
93
  schemas: opts.schemas
97
94
  });
98
95
  watcher.add(files);
99
- const data = _Config.diffConfigs({
96
+ const data = Config.diffConfigs({
100
97
  origin,
101
98
  updated,
102
99
  onChangeTypes: opts.onChangeTypes
@@ -184,18 +181,21 @@ var Config = class _Config {
184
181
  const configKeys = new Set(Object.keys(opts.config));
185
182
  for (const key of Object.keys(opts.schemas)) {
186
183
  configKeys.delete(key);
187
- if (!opts.config[key]) continue;
184
+ if (!opts.config[key])
185
+ continue;
188
186
  const schema = opts.schemas[key]({ ...import_joi.default, zod: import_utils.zod });
189
187
  if (import_joi.default.isSchema(schema)) {
190
188
  const { error } = schema.validate(opts.config[key]);
191
- if (error) errors.set(key, error);
189
+ if (error)
190
+ errors.set(key, error);
192
191
  } else {
193
192
  (0, import_assert.default)(
194
193
  (0, import_utils.isZodSchema)(schema),
195
194
  `schema for config ${key} is not valid, neither joi nor zod.`
196
195
  );
197
196
  const { error } = schema.safeParse(opts.config[key]);
198
- if (error) errors.set(key, error);
197
+ if (error)
198
+ errors.set(key, error);
199
199
  }
200
200
  }
201
201
  (0, import_assert.default)(
@@ -23,13 +23,6 @@ __export(command_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(command_exports);
25
25
  var Command = class {
26
- name;
27
- description;
28
- options;
29
- details;
30
- configResolveMode;
31
- fn;
32
- plugin;
33
26
  constructor(opts) {
34
27
  this.name = opts.name;
35
28
  this.description = opts.description;
@@ -32,7 +32,8 @@ function loadEnv(opts) {
32
32
  (0, import_path.join)(opts.cwd, `${opts.envFile}.local`)
33
33
  ];
34
34
  for (const file of files) {
35
- if (!(0, import_fs.existsSync)(file)) continue;
35
+ if (!(0, import_fs.existsSync)(file))
36
+ continue;
36
37
  const parsed = (0, import_dotenv.parse)((0, import_fs.readFileSync)(file)) || {};
37
38
  (0, import_dotenv_expand.expand)({ parsed, ignoreProcessEnv: true });
38
39
  for (const key of Object.keys(parsed)) {
@@ -34,11 +34,6 @@ __export(hook_exports, {
34
34
  module.exports = __toCommonJS(hook_exports);
35
35
  var import_assert = __toESM(require("assert"));
36
36
  var Hook = class {
37
- plugin;
38
- key;
39
- fn;
40
- before;
41
- stage;
42
37
  constructor(opts) {
43
38
  (0, import_assert.default)(
44
39
  opts.key && opts.fn,
@@ -42,17 +42,11 @@ var RE = {
42
42
  plugin: /^(@umijs\/|umi-)plugin-/,
43
43
  preset: /^(@umijs\/|umi-)preset-/
44
44
  };
45
- var Plugin = class _Plugin {
46
- cwd;
47
- type;
48
- path;
49
- id;
50
- key;
51
- apply;
52
- config = {};
53
- time = { hooks: {} };
54
- enableBy = import_types.EnableBy.register;
45
+ var Plugin = class {
55
46
  constructor(opts) {
47
+ this.config = {};
48
+ this.time = { hooks: {} };
49
+ this.enableBy = import_types.EnableBy.register;
56
50
  this.type = opts.type;
57
51
  this.path = (0, import_utils.winPath)(opts.path);
58
52
  this.cwd = opts.cwd;
@@ -90,9 +84,12 @@ var Plugin = class _Plugin {
90
84
  };
91
85
  }
92
86
  merge(opts) {
93
- if (opts.key) this.key = opts.key;
94
- if (opts.config) this.config = opts.config;
95
- if (opts.enableBy) this.enableBy = opts.enableBy;
87
+ if (opts.key)
88
+ this.key = opts.key;
89
+ if (opts.config)
90
+ this.config = opts.config;
91
+ if (opts.enableBy)
92
+ this.enableBy = opts.enableBy;
96
93
  }
97
94
  getId(opts) {
98
95
  let id;
@@ -116,11 +113,11 @@ var Plugin = class _Plugin {
116
113
  return name.split(".").map((part) => import_utils.lodash.camelCase(part)).join(".");
117
114
  }
118
115
  return nameToKey(
119
- opts.isPkgEntry ? _Plugin.stripNoneUmiScope(opts.pkg.name).replace(RE[this.type], "") : (0, import_path.basename)(this.path, (0, import_path.extname)(this.path))
116
+ opts.isPkgEntry ? Plugin.stripNoneUmiScope(opts.pkg.name).replace(RE[this.type], "") : (0, import_path.basename)(this.path, (0, import_path.extname)(this.path))
120
117
  );
121
118
  }
122
119
  static isPluginOrPreset(type, name) {
123
- return RE[type].test(_Plugin.stripNoneUmiScope(name));
120
+ return RE[type].test(Plugin.stripNoneUmiScope(name));
124
121
  }
125
122
  static stripNoneUmiScope(name) {
126
123
  if (name.charAt(0) === "@" && !name.startsWith("@umijs/")) {
@@ -158,7 +155,7 @@ var Plugin = class _Plugin {
158
155
  cause: _e
159
156
  });
160
157
  }
161
- return new _Plugin({
158
+ return new Plugin({
162
159
  path: resolved,
163
160
  type,
164
161
  cwd: opts.cwd
@@ -42,10 +42,6 @@ var import_plugin = require("./plugin");
42
42
  var import_utils2 = require("./utils");
43
43
  var resolveConfigModes = ["strict", "loose"];
44
44
  var PluginAPI = class {
45
- service;
46
- plugin;
47
- logger;
48
- telemetry;
49
45
  constructor(opts) {
50
46
  this.service = opts.service;
51
47
  this.plugin = opts.plugin;
@@ -46,32 +46,29 @@ var import_plugin = require("./plugin");
46
46
  var import_pluginAPI = require("./pluginAPI");
47
47
  var import_telemetry = require("./telemetry");
48
48
  var Service = class {
49
- opts;
50
- appData = {};
51
- args = { _: [], $0: "" };
52
- commands = {};
53
- generators = {};
54
- config = {};
55
- configSchemas = {};
56
- configDefaults = {};
57
- configOnChanges = {};
58
- cwd;
59
- env;
60
- hooks = {};
61
- name = "";
62
- paths = {};
63
- // preset is plugin with different type
64
- plugins = {};
65
- keyToPluginMap = {};
66
- pluginMethods = {};
67
- skipPluginIds = /* @__PURE__ */ new Set();
68
- stage = import_types.ServiceStage.uninitialized;
69
- userConfig = {};
70
- configManager = null;
71
- pkg = {};
72
- pkgPath = "";
73
- telemetry = new import_telemetry.Telemetry();
74
49
  constructor(opts) {
50
+ this.appData = {};
51
+ this.args = { _: [], $0: "" };
52
+ this.commands = {};
53
+ this.generators = {};
54
+ this.config = {};
55
+ this.configSchemas = {};
56
+ this.configDefaults = {};
57
+ this.configOnChanges = {};
58
+ this.hooks = {};
59
+ this.name = "";
60
+ this.paths = {};
61
+ // preset is plugin with different type
62
+ this.plugins = {};
63
+ this.keyToPluginMap = {};
64
+ this.pluginMethods = {};
65
+ this.skipPluginIds = /* @__PURE__ */ new Set();
66
+ this.stage = import_types.ServiceStage.uninitialized;
67
+ this.userConfig = {};
68
+ this.configManager = null;
69
+ this.pkg = {};
70
+ this.pkgPath = "";
71
+ this.telemetry = new import_telemetry.Telemetry();
75
72
  this.cwd = opts.cwd;
76
73
  this.env = opts.env;
77
74
  this.opts = opts;
@@ -101,7 +98,8 @@ var Service = class {
101
98
  );
102
99
  const tAdd = new import_tapable.AsyncSeriesWaterfallHook(["memo"]);
103
100
  for (const hook of hooks) {
104
- if (!this.isPluginEnable(hook)) continue;
101
+ if (!this.isPluginEnable(hook))
102
+ continue;
105
103
  tAdd.tapPromise(
106
104
  {
107
105
  name: hook.plugin.key,
@@ -124,7 +122,8 @@ var Service = class {
124
122
  case import_types.ApplyPluginsType.modify:
125
123
  const tModify = new import_tapable.AsyncSeriesWaterfallHook(["memo"]);
126
124
  for (const hook of hooks) {
127
- if (!this.isPluginEnable(hook)) continue;
125
+ if (!this.isPluginEnable(hook))
126
+ continue;
128
127
  tModify.tapPromise(
129
128
  {
130
129
  name: hook.plugin.key,
@@ -171,7 +170,8 @@ var Service = class {
171
170
  }
172
171
  const tEvent = new import_tapable.AsyncSeriesWaterfallHook(["_"]);
173
172
  for (const hook of hooks) {
174
- if (!this.isPluginEnable(hook)) continue;
173
+ if (!this.isPluginEnable(hook))
174
+ continue;
175
175
  tEvent.tapPromise(
176
176
  {
177
177
  name: hook.plugin.key,
@@ -199,7 +199,8 @@ var Service = class {
199
199
  async run(opts) {
200
200
  const { name, args = {} } = opts;
201
201
  args._ = args._ || [];
202
- if (args._[0] === name) args._.shift();
202
+ if (args._[0] === name)
203
+ args._.shift();
203
204
  this.args = args;
204
205
  this.name = name;
205
206
  this.stage = import_types.ServiceStage.init;
@@ -264,7 +265,8 @@ var Service = class {
264
265
  }
265
266
  for (const id of Object.keys(this.plugins)) {
266
267
  const { config, key } = this.plugins[id];
267
- if (config.schema) this.configSchemas[key] = config.schema;
268
+ if (config.schema)
269
+ this.configSchemas[key] = config.schema;
268
270
  if (config.default !== void 0) {
269
271
  this.configDefaults[key] = config.default;
270
272
  }
@@ -494,12 +496,16 @@ var Service = class {
494
496
  plugin = hook.plugin;
495
497
  } else {
496
498
  plugin = this.keyToPluginMap[hook];
497
- if (!plugin) return false;
499
+ if (!plugin)
500
+ return false;
498
501
  }
499
502
  const { id, key, enableBy } = plugin;
500
- if (this.skipPluginIds.has(id)) return false;
501
- if (this.userConfig[key] === false) return false;
502
- if (this.config[key] === false) return false;
503
+ if (this.skipPluginIds.has(id))
504
+ return false;
505
+ if (this.userConfig[key] === false)
506
+ return false;
507
+ if (this.config[key] === false)
508
+ return false;
503
509
  if (enableBy === import_types.EnableBy.config) {
504
510
  return key in this.userConfig || this.config && key in this.config;
505
511
  }
@@ -24,9 +24,17 @@ __export(telemetry_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(telemetry_exports);
26
26
  var Telemetry = class {
27
- queuedEvents = [];
28
- storage = new NoopStorage();
29
27
  constructor() {
28
+ this.queuedEvents = [];
29
+ this.storage = new NoopStorage();
30
+ this.afterFlush = () => {
31
+ const un = this.unFinishedEvents();
32
+ if (un.length) {
33
+ this.scheduleFlush();
34
+ } else {
35
+ this.queuedEvents = [];
36
+ }
37
+ };
30
38
  }
31
39
  prefixWith(prefix) {
32
40
  const upStream = this;
@@ -91,14 +99,6 @@ var Telemetry = class {
91
99
  this.flush().then(this.afterFlush, this.afterFlush);
92
100
  }, 5e3);
93
101
  }
94
- afterFlush = () => {
95
- const un = this.unFinishedEvents();
96
- if (un.length) {
97
- this.scheduleFlush();
98
- } else {
99
- this.queuedEvents = [];
100
- }
101
- };
102
102
  unFinishedEvents() {
103
103
  return this.queuedEvents.filter((e) => {
104
104
  if (e.status === "sent") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/core",
3
- "version": "4.6.0",
3
+ "version": "4.6.2",
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": {
@@ -15,8 +15,8 @@
15
15
  "compiled"
16
16
  ],
17
17
  "dependencies": {
18
- "@umijs/bundler-utils": "4.6.0",
19
- "@umijs/utils": "4.6.0"
18
+ "@umijs/utils": "4.6.2",
19
+ "@umijs/bundler-utils": "4.6.2"
20
20
  },
21
21
  "devDependencies": {
22
22
  "dotenv": "16.0.0",