@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,355 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.Service = void 0;
16
+ const utils_1 = require("@umijs/utils");
17
+ const assert_1 = __importDefault(require("assert"));
18
+ const fs_1 = require("fs");
19
+ const path_1 = require("path");
20
+ const tapable_1 = require("../../compiled/tapable");
21
+ const config_1 = require("../config/config");
22
+ const constants_1 = require("../constants");
23
+ const types_1 = require("../types");
24
+ const env_1 = require("./env");
25
+ const path_2 = require("./path");
26
+ const plugin_1 = require("./plugin");
27
+ const pluginAPI_1 = require("./pluginAPI");
28
+ const utils_2 = require("./utils");
29
+ class Service {
30
+ constructor(opts) {
31
+ this.appData = {};
32
+ this.args = { _: [], $0: '' };
33
+ this.commands = {};
34
+ this.generators = {};
35
+ this.config = {};
36
+ this.configSchemas = {};
37
+ this.configDefaults = {};
38
+ this.configOnChanges = {};
39
+ this.hooks = {};
40
+ this.name = '';
41
+ this.paths = {};
42
+ // preset is plugin with different type
43
+ this.plugins = {};
44
+ this.pluginMethods = {};
45
+ this.skipPluginIds = new Set();
46
+ this.stage = types_1.ServiceStage.uninitialized;
47
+ this.userConfig = {};
48
+ this.configManager = null;
49
+ this.pkg = {};
50
+ this.cwd = opts.cwd;
51
+ this.env = opts.env;
52
+ this.opts = opts;
53
+ (0, assert_1.default)((0, fs_1.existsSync)(this.cwd), `Invalid cwd ${this.cwd}, it's not found.`);
54
+ }
55
+ applyPlugins(opts) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ const hooks = this.hooks[opts.key] || [];
58
+ let type = opts.type;
59
+ // guess type from key
60
+ if (!type) {
61
+ if (opts.key.startsWith('on')) {
62
+ type = types_1.ApplyPluginsType.event;
63
+ }
64
+ else if (opts.key.startsWith('modify')) {
65
+ type = types_1.ApplyPluginsType.modify;
66
+ }
67
+ else if (opts.key.startsWith('add')) {
68
+ type = types_1.ApplyPluginsType.add;
69
+ }
70
+ else {
71
+ throw new Error(`Invalid applyPlugins arguments, type must be supplied for key ${opts.key}.`);
72
+ }
73
+ }
74
+ switch (type) {
75
+ case types_1.ApplyPluginsType.add:
76
+ (0, assert_1.default)(!('initialValue' in opts) || Array.isArray(opts.initialValue), `applyPlugins failed, opts.initialValue must be Array if opts.type is add.`);
77
+ const tAdd = new tapable_1.AsyncSeriesWaterfallHook(['memo']);
78
+ for (const hook of hooks) {
79
+ if (!this.isPluginEnable(hook))
80
+ continue;
81
+ tAdd.tapPromise({
82
+ name: hook.plugin.id,
83
+ stage: hook.stage,
84
+ before: hook.before,
85
+ }, (memo) => __awaiter(this, void 0, void 0, function* () {
86
+ const items = yield hook.fn(opts.args);
87
+ return memo.concat(items);
88
+ }));
89
+ }
90
+ return (yield tAdd.promise(opts.initialValue || []));
91
+ case types_1.ApplyPluginsType.modify:
92
+ const tModify = new tapable_1.AsyncSeriesWaterfallHook(['memo']);
93
+ for (const hook of hooks) {
94
+ if (!this.isPluginEnable(hook))
95
+ continue;
96
+ tModify.tapPromise({
97
+ name: hook.plugin.id,
98
+ stage: hook.stage,
99
+ before: hook.before,
100
+ }, (memo) => __awaiter(this, void 0, void 0, function* () {
101
+ return yield hook.fn(memo, opts.args);
102
+ }));
103
+ }
104
+ return (yield tModify.promise(opts.initialValue));
105
+ case types_1.ApplyPluginsType.event:
106
+ const tEvent = new tapable_1.AsyncSeriesWaterfallHook(['_']);
107
+ for (const hook of hooks) {
108
+ if (!this.isPluginEnable(hook))
109
+ continue;
110
+ tEvent.tapPromise({
111
+ name: hook.plugin.id,
112
+ stage: hook.stage || 0,
113
+ before: hook.before,
114
+ }, () => __awaiter(this, void 0, void 0, function* () {
115
+ yield hook.fn(opts.args);
116
+ }));
117
+ }
118
+ return (yield tEvent.promise(1));
119
+ default:
120
+ throw new Error(`applyPlugins failed, type is not defined or is not matched, got ${opts.type}.`);
121
+ }
122
+ });
123
+ }
124
+ run(opts) {
125
+ return __awaiter(this, void 0, void 0, function* () {
126
+ const { name, args = {} } = opts;
127
+ args._ = args._ || [];
128
+ // shift the command itself
129
+ if (args._[0] === name)
130
+ args._.shift();
131
+ this.args = args;
132
+ this.name = name;
133
+ // loadEnv
134
+ this.stage = types_1.ServiceStage.init;
135
+ (0, env_1.loadEnv)({ cwd: this.cwd, envFile: '.env' });
136
+ // get pkg from package.json
137
+ let pkg = {};
138
+ try {
139
+ pkg = require((0, path_1.join)(this.cwd, 'package.json'));
140
+ }
141
+ catch (_e) {
142
+ // APP_ROOT
143
+ if (this.cwd !== process.cwd()) {
144
+ try {
145
+ pkg = require((0, path_1.join)(process.cwd(), 'package.json'));
146
+ }
147
+ catch (_e) { }
148
+ }
149
+ }
150
+ this.pkg = pkg;
151
+ // get user config
152
+ const configManager = new config_1.Config({
153
+ cwd: this.cwd,
154
+ env: this.env,
155
+ defaultConfigFiles: this.opts.defaultConfigFiles,
156
+ });
157
+ this.configManager = configManager;
158
+ this.userConfig = configManager.getUserConfig().config;
159
+ // get paths (move after?)
160
+ // resolve initial presets and plugins
161
+ const { plugins, presets } = plugin_1.Plugin.getPluginsAndPresets({
162
+ cwd: this.cwd,
163
+ pkg,
164
+ plugins: [require.resolve('./generatePlugin')].concat(this.opts.plugins || []),
165
+ presets: [require.resolve('./servicePlugin')].concat(this.opts.presets || []),
166
+ userConfig: this.userConfig,
167
+ prefix: this.opts.frameworkName || constants_1.DEFAULT_FRAMEWORK_NAME,
168
+ });
169
+ // register presets and plugins
170
+ this.stage = types_1.ServiceStage.initPresets;
171
+ const presetPlugins = [];
172
+ while (presets.length) {
173
+ yield this.initPreset({
174
+ preset: presets.shift(),
175
+ presets,
176
+ plugins: presetPlugins,
177
+ });
178
+ }
179
+ plugins.unshift(...presetPlugins);
180
+ this.stage = types_1.ServiceStage.initPlugins;
181
+ while (plugins.length) {
182
+ yield this.initPlugin({ plugin: plugins.shift(), plugins });
183
+ }
184
+ // collect configSchemas and configDefaults
185
+ for (const id of Object.keys(this.plugins)) {
186
+ const { config, key } = this.plugins[id];
187
+ if (config.schema)
188
+ this.configSchemas[key] = config.schema;
189
+ if (config.default !== undefined) {
190
+ this.configDefaults[key] = config.default;
191
+ }
192
+ this.configOnChanges[key] = config.onChange || types_1.ConfigChangeType.reload;
193
+ }
194
+ // setup api.config from modifyConfig and modifyDefaultConfig
195
+ const paths = (0, path_2.getPaths)({
196
+ cwd: this.cwd,
197
+ env: this.env,
198
+ prefix: this.opts.frameworkName || constants_1.DEFAULT_FRAMEWORK_NAME,
199
+ });
200
+ if (this.config.outputPath) {
201
+ paths.absOutputPath = (0, path_1.join)(this.cwd, this.config.outputPath);
202
+ }
203
+ this.stage = types_1.ServiceStage.resolveConfig;
204
+ const config = yield this.applyPlugins({
205
+ key: 'modifyConfig',
206
+ initialValue: configManager.getConfig({
207
+ schemas: this.configSchemas,
208
+ }).config,
209
+ args: { paths },
210
+ });
211
+ const defaultConfig = yield this.applyPlugins({
212
+ key: 'modifyDefaultConfig',
213
+ initialValue: this.configDefaults,
214
+ });
215
+ this.config = utils_1.lodash.merge(defaultConfig, config);
216
+ this.paths = yield this.applyPlugins({
217
+ key: 'modifyPaths',
218
+ initialValue: paths,
219
+ });
220
+ // applyPlugin collect app data
221
+ // TODO: some data is mutable
222
+ this.stage = types_1.ServiceStage.collectAppData;
223
+ this.appData = yield this.applyPlugins({
224
+ key: 'modifyAppData',
225
+ initialValue: {
226
+ // base
227
+ cwd: this.cwd,
228
+ pkg,
229
+ plugins,
230
+ presets,
231
+ name,
232
+ args,
233
+ // config
234
+ userConfig: this.userConfig,
235
+ mainConfigFile: configManager.mainConfigFile,
236
+ config,
237
+ defaultConfig: defaultConfig,
238
+ // TODO
239
+ // moduleGraph,
240
+ // routes,
241
+ // npmClient,
242
+ // nodeVersion,
243
+ // gitInfo,
244
+ // gitBranch,
245
+ // debugger info,
246
+ // devPort,
247
+ // devHost,
248
+ // env
249
+ },
250
+ });
251
+ // applyPlugin onCheck
252
+ this.stage = types_1.ServiceStage.onCheck;
253
+ yield this.applyPlugins({
254
+ key: 'onCheck',
255
+ });
256
+ // applyPlugin onStart
257
+ this.stage = types_1.ServiceStage.onStart;
258
+ yield this.applyPlugins({
259
+ key: 'onStart',
260
+ });
261
+ // run command
262
+ this.stage = types_1.ServiceStage.runCommand;
263
+ const command = this.commands[name];
264
+ (0, assert_1.default)(command, `Invalid command ${name}, it's not registered.`);
265
+ return command.fn({ args });
266
+ });
267
+ }
268
+ initPreset(opts) {
269
+ return __awaiter(this, void 0, void 0, function* () {
270
+ const { presets, plugins } = yield this.initPlugin({
271
+ plugin: opts.preset,
272
+ presets: opts.presets,
273
+ plugins: opts.plugins,
274
+ });
275
+ opts.presets.unshift(...(presets || []));
276
+ opts.plugins.push(...(plugins || []));
277
+ });
278
+ }
279
+ initPlugin(opts) {
280
+ var _a;
281
+ return __awaiter(this, void 0, void 0, function* () {
282
+ // register to this.plugins
283
+ (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.`);
284
+ this.plugins[opts.plugin.id] = opts.plugin;
285
+ // apply with PluginAPI
286
+ const pluginAPI = new pluginAPI_1.PluginAPI({
287
+ plugin: opts.plugin,
288
+ service: this,
289
+ });
290
+ pluginAPI.registerPresets = pluginAPI.registerPresets.bind(pluginAPI, opts.presets || []);
291
+ pluginAPI.registerPlugins = pluginAPI.registerPlugins.bind(pluginAPI, opts.plugins);
292
+ const proxyPluginAPI = pluginAPI_1.PluginAPI.proxyPluginAPI({
293
+ service: this,
294
+ pluginAPI,
295
+ serviceProps: [
296
+ 'appData',
297
+ 'applyPlugins',
298
+ 'args',
299
+ 'config',
300
+ 'cwd',
301
+ 'pkg',
302
+ 'name',
303
+ 'paths',
304
+ 'userConfig',
305
+ ],
306
+ staticProps: {
307
+ ApplyPluginsType: types_1.ApplyPluginsType,
308
+ ConfigChangeType: types_1.ConfigChangeType,
309
+ EnableBy: types_1.EnableBy,
310
+ ServiceStage: types_1.ServiceStage,
311
+ service: this,
312
+ },
313
+ });
314
+ let ret = opts.plugin.apply()(proxyPluginAPI);
315
+ if ((0, utils_2.isPromise)(ret)) {
316
+ ret = yield ret;
317
+ }
318
+ if (ret === null || ret === void 0 ? void 0 : ret.presets) {
319
+ ret.presets = ret.presets.map((preset) => new plugin_1.Plugin({
320
+ path: preset,
321
+ type: types_1.PluginType.preset,
322
+ cwd: this.cwd,
323
+ }));
324
+ }
325
+ if (ret === null || ret === void 0 ? void 0 : ret.plugins) {
326
+ ret.plugins = ret.plugins.map((plugin) => new plugin_1.Plugin({
327
+ path: plugin,
328
+ type: types_1.PluginType.plugin,
329
+ cwd: this.cwd,
330
+ }));
331
+ }
332
+ return ret || {};
333
+ });
334
+ }
335
+ isPluginEnable(hook) {
336
+ const { id, key, enableBy } = hook.plugin;
337
+ if (this.skipPluginIds.has(id))
338
+ return false;
339
+ if (this.userConfig[key] === false)
340
+ return false;
341
+ if (enableBy === types_1.EnableBy.config &&
342
+ // this.config is not ready when modifyConfig or modifyDefaultConfig is called
343
+ // fallback to this.userConfig
344
+ !(key in
345
+ (['modifyConfig', 'modifyDefaultConfig'].includes(hook.key)
346
+ ? this.userConfig
347
+ : this.config)))
348
+ return false;
349
+ if (typeof enableBy === 'function')
350
+ return enableBy({ config: this.config, env: this.env });
351
+ // EnableBy.register
352
+ return true;
353
+ }
354
+ }
355
+ exports.Service = Service;
@@ -0,0 +1,3 @@
1
+ import { PluginAPI } from './pluginAPI';
2
+ declare const _default: (api: PluginAPI) => void;
3
+ export default _default;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = (api) => {
4
+ [
5
+ 'onCheck',
6
+ 'onStart',
7
+ 'modifyAppData',
8
+ 'modifyConfig',
9
+ 'modifyDefaultConfig',
10
+ 'modifyPaths',
11
+ ].forEach((name) => {
12
+ api.registerMethod({ name });
13
+ });
14
+ };
@@ -0,0 +1,2 @@
1
+ export declare function isPromise(obj: any): boolean;
2
+ export declare function makeArray(item: any): any[];
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeArray = exports.isPromise = void 0;
4
+ function isPromise(obj) {
5
+ return ((typeof obj === 'object' || typeof obj === 'function') &&
6
+ typeof obj.then === 'function');
7
+ }
8
+ exports.isPromise = isPromise;
9
+ function makeArray(item) {
10
+ return Array.isArray(item) ? item : [item];
11
+ }
12
+ exports.makeArray = makeArray;
@@ -0,0 +1,108 @@
1
+ import joi from '../compiled/@hapi/joi';
2
+ export declare enum Env {
3
+ development = "development",
4
+ production = "production",
5
+ test = "test"
6
+ }
7
+ export declare enum PluginType {
8
+ preset = "preset",
9
+ plugin = "plugin"
10
+ }
11
+ export interface IPluginConfig {
12
+ default?: any;
13
+ schema?: {
14
+ (joi: joi.Root): joi.Schema;
15
+ };
16
+ onChange?: string | Function;
17
+ }
18
+ export declare enum ServiceStage {
19
+ uninitialized = 0,
20
+ init = 1,
21
+ initPresets = 2,
22
+ initPlugins = 3,
23
+ resolveConfig = 4,
24
+ collectAppData = 5,
25
+ onCheck = 6,
26
+ onStart = 7,
27
+ runCommand = 8
28
+ }
29
+ export declare enum ConfigChangeType {
30
+ reload = "reload",
31
+ regenerateTmpFiles = "regenerateTmpFiles"
32
+ }
33
+ export declare enum ApplyPluginsType {
34
+ add = "add",
35
+ modify = "modify",
36
+ event = "event"
37
+ }
38
+ export declare enum EnableBy {
39
+ register = "register",
40
+ config = "config"
41
+ }
42
+ export interface IRoute {
43
+ path: string;
44
+ file: string;
45
+ id: string;
46
+ parentId?: string;
47
+ }
48
+ export interface IEvent<T> {
49
+ (fn: {
50
+ (args: T): void;
51
+ }): void;
52
+ (args: {
53
+ fn: {
54
+ (args: T): void;
55
+ };
56
+ name?: string;
57
+ before?: string | string[];
58
+ stage?: number;
59
+ }): void;
60
+ }
61
+ export interface IModify<T, U> {
62
+ (fn: {
63
+ (initialValue: T, args: U): T;
64
+ }): void;
65
+ (fn: {
66
+ (initialValue: T, args: U): Promise<T>;
67
+ }): void;
68
+ (args: {
69
+ fn: {
70
+ (initialValue: T, args: U): T;
71
+ };
72
+ name?: string;
73
+ before?: string | string[];
74
+ stage?: number;
75
+ }): void;
76
+ (args: {
77
+ fn: {
78
+ (initialValue: T, args: U): Promise<T>;
79
+ };
80
+ name?: string;
81
+ before?: string | string[];
82
+ stage?: number;
83
+ }): void;
84
+ }
85
+ export interface IAdd<T, U> {
86
+ (fn: {
87
+ (args: T): U | U[];
88
+ }): void;
89
+ (fn: {
90
+ (args: T): Promise<U | U[]>;
91
+ }): void;
92
+ (args: {
93
+ fn: {
94
+ (args: T): U | U[];
95
+ };
96
+ name?: string;
97
+ before?: string | string[];
98
+ stage?: number;
99
+ }): void;
100
+ (args: {
101
+ fn: {
102
+ (args: T): Promise<U | U[]>;
103
+ name?: string;
104
+ before?: string | string[];
105
+ stage?: number;
106
+ };
107
+ }): void;
108
+ }
package/dist/types.js ADDED
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EnableBy = exports.ApplyPluginsType = exports.ConfigChangeType = exports.ServiceStage = exports.PluginType = exports.Env = void 0;
4
+ var Env;
5
+ (function (Env) {
6
+ Env["development"] = "development";
7
+ Env["production"] = "production";
8
+ Env["test"] = "test";
9
+ })(Env = exports.Env || (exports.Env = {}));
10
+ var PluginType;
11
+ (function (PluginType) {
12
+ PluginType["preset"] = "preset";
13
+ PluginType["plugin"] = "plugin";
14
+ })(PluginType = exports.PluginType || (exports.PluginType = {}));
15
+ var ServiceStage;
16
+ (function (ServiceStage) {
17
+ ServiceStage[ServiceStage["uninitialized"] = 0] = "uninitialized";
18
+ ServiceStage[ServiceStage["init"] = 1] = "init";
19
+ ServiceStage[ServiceStage["initPresets"] = 2] = "initPresets";
20
+ ServiceStage[ServiceStage["initPlugins"] = 3] = "initPlugins";
21
+ ServiceStage[ServiceStage["resolveConfig"] = 4] = "resolveConfig";
22
+ ServiceStage[ServiceStage["collectAppData"] = 5] = "collectAppData";
23
+ ServiceStage[ServiceStage["onCheck"] = 6] = "onCheck";
24
+ ServiceStage[ServiceStage["onStart"] = 7] = "onStart";
25
+ ServiceStage[ServiceStage["runCommand"] = 8] = "runCommand";
26
+ })(ServiceStage = exports.ServiceStage || (exports.ServiceStage = {}));
27
+ var ConfigChangeType;
28
+ (function (ConfigChangeType) {
29
+ ConfigChangeType["reload"] = "reload";
30
+ ConfigChangeType["regenerateTmpFiles"] = "regenerateTmpFiles";
31
+ })(ConfigChangeType = exports.ConfigChangeType || (exports.ConfigChangeType = {}));
32
+ var ApplyPluginsType;
33
+ (function (ApplyPluginsType) {
34
+ ApplyPluginsType["add"] = "add";
35
+ ApplyPluginsType["modify"] = "modify";
36
+ ApplyPluginsType["event"] = "event";
37
+ })(ApplyPluginsType = exports.ApplyPluginsType || (exports.ApplyPluginsType = {}));
38
+ var EnableBy;
39
+ (function (EnableBy) {
40
+ EnableBy["register"] = "register";
41
+ EnableBy["config"] = "config";
42
+ })(EnableBy = exports.EnableBy || (exports.EnableBy = {}));
package/package.json CHANGED
@@ -1,32 +1,53 @@
1
1
  {
2
2
  "name": "@umijs/core",
3
- "version": "3.5.20",
4
- "description": "@umijs/core",
5
- "main": "lib/index.js",
6
- "types": "lib/index.d.ts",
7
- "files": [
8
- "lib"
9
- ],
3
+ "version": "4.0.0-beta.12",
4
+ "homepage": "https://github.com/umijs/umi-next/tree/master/packages/core#readme",
5
+ "bugs": "https://github.com/umijs/umi-next/issues",
10
6
  "repository": {
11
7
  "type": "git",
12
- "url": "https://github.com/umijs/umi"
8
+ "url": "https://github.com/umijs/umi-next"
13
9
  },
14
- "keywords": [
15
- "umi"
16
- ],
17
- "authors": [
18
- "chencheng <sorrycc@gmail.com> (https://github.com/sorrycc)"
19
- ],
20
10
  "license": "MIT",
21
- "bugs": "http://github.com/umijs/umi/issues",
22
- "homepage": "https://github.com/umijs/umi/tree/master/packages/core#readme",
11
+ "main": "dist/index.js",
12
+ "types": "dist/index.d.ts",
13
+ "files": [
14
+ "dist",
15
+ "compiled"
16
+ ],
17
+ "scripts": {
18
+ "build": "pnpm tsc",
19
+ "build:deps": "pnpm esno ../../scripts/bundleDeps.ts",
20
+ "dev": "pnpm build -- --watch"
21
+ },
22
+ "dependencies": {
23
+ "@umijs/bundler-utils": "4.0.0-beta.12",
24
+ "@umijs/utils": "4.0.0-beta.12"
25
+ },
26
+ "devDependencies": {
27
+ "@hapi/joi": "17.1.1",
28
+ "@types/hapi__joi": "17.1.7",
29
+ "dotenv": "10.0.0",
30
+ "just-diff": "3.1.1",
31
+ "tapable": "2.2.1"
32
+ },
23
33
  "publishConfig": {
24
34
  "access": "public"
25
35
  },
26
- "dependencies": {
27
- "@umijs/ast": "3.5.20",
28
- "@umijs/babel-preset-umi": "3.5.20",
29
- "@umijs/deps": "3.5.20",
30
- "@umijs/utils": "3.5.20"
36
+ "authors": [
37
+ "chencheng <sorrycc@gmail.com> (https://github.com/sorrycc)"
38
+ ],
39
+ "compiledConfig": {
40
+ "deps": [
41
+ "@hapi/joi",
42
+ "dotenv",
43
+ "just-diff",
44
+ "tapable"
45
+ ],
46
+ "externals": {
47
+ "@hapi/joi": "$$LOCAL",
48
+ "dotenv": "$$LOCAL",
49
+ "just-diff": "$$LOCAL",
50
+ "tapable": "$$LOCAL"
51
+ }
31
52
  }
32
53
  }
@@ -1,39 +0,0 @@
1
- import Service from '../Service/Service';
2
- interface IChanged {
3
- key: string;
4
- pluginId: string;
5
- }
6
- interface IOpts {
7
- cwd: string;
8
- service: Service;
9
- localConfig?: boolean;
10
- configFiles?: string[];
11
- }
12
- export default class Config {
13
- cwd: string;
14
- service: Service;
15
- config?: object;
16
- localConfig?: boolean;
17
- configFile?: string | null;
18
- configFiles: string[];
19
- constructor(opts: IOpts);
20
- getDefaultConfig(): Promise<{}>;
21
- getConfig({ defaultConfig }: {
22
- defaultConfig: object;
23
- }): {};
24
- getUserConfig(): {};
25
- addAffix(file: string, affix: string): string;
26
- requireConfigs(configFiles: string[]): any[];
27
- mergeConfig(...configs: object[]): {};
28
- getConfigFile(): string | null;
29
- getWatchFilesAndDirectories(): string[];
30
- watch(opts: {
31
- userConfig: object;
32
- onChange: (args: {
33
- userConfig: any;
34
- pluginChanged: IChanged[];
35
- valueChanged: IChanged[];
36
- }) => void;
37
- }): () => void;
38
- }
39
- export {};