@umijs/core 4.6.2 → 4.6.4

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