@umijs/core 4.0.5 → 4.0.8
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/compiled/dotenv-expand/LICENSE +24 -0
- package/compiled/dotenv-expand/index.js +1 -0
- package/compiled/dotenv-expand/lib/main.d.ts +29 -0
- package/compiled/dotenv-expand/package.json +1 -0
- package/dist/config/config.d.ts +0 -0
- package/dist/config/config.js +197 -176
- package/dist/config/utils.d.ts +0 -0
- package/dist/config/utils.js +36 -11
- package/dist/constants.d.ts +0 -0
- package/dist/constants.js +44 -11
- package/dist/index.d.ts +0 -0
- package/dist/index.js +46 -24
- package/dist/route/defineRoutes.d.ts +0 -0
- package/dist/route/defineRoutes.js +52 -28
- package/dist/route/route.d.ts +0 -0
- package/dist/route/route.js +20 -22
- package/dist/route/routeUtils.d.ts +0 -0
- package/dist/route/routeUtils.js +40 -20
- package/dist/route/routesConfig.d.ts +0 -0
- package/dist/route/routesConfig.js +120 -73
- package/dist/route/routesConvention.d.ts +0 -0
- package/dist/route/routesConvention.js +89 -62
- package/dist/route/utils.d.ts +0 -0
- package/dist/route/utils.js +48 -23
- package/dist/service/command.d.ts +0 -0
- package/dist/service/command.js +39 -15
- package/dist/service/env.d.ts +0 -0
- package/dist/service/env.js +44 -18
- package/dist/service/generatePlugin.d.ts +0 -0
- package/dist/service/generatePlugin.js +98 -77
- package/dist/service/generator.d.ts +0 -0
- package/dist/service/generator.js +50 -12
- package/dist/service/hook.d.ts +0 -0
- package/dist/service/hook.js +41 -17
- package/dist/service/path.d.ts +0 -0
- package/dist/service/path.js +51 -29
- package/dist/service/plugin.d.ts +0 -0
- package/dist/service/plugin.js +137 -140
- package/dist/service/pluginAPI.d.ts +0 -0
- package/dist/service/pluginAPI.js +183 -160
- package/dist/service/service.d.ts +0 -0
- package/dist/service/service.js +385 -420
- package/dist/service/servicePlugin.d.ts +0 -0
- package/dist/service/servicePlugin.js +37 -13
- package/dist/service/utils.d.ts +0 -0
- package/dist/service/utils.js +32 -8
- package/dist/types.d.ts +0 -0
- package/dist/types.js +77 -42
- package/package.json +6 -5
package/dist/service/service.js
CHANGED
|
@@ -1,434 +1,399 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
4
10
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
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));
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
|
|
22
|
+
// service.ts
|
|
23
|
+
var service_exports = {};
|
|
24
|
+
__export(service_exports, {
|
|
25
|
+
Service: () => Service
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(service_exports);
|
|
28
|
+
var import_tapable = require("@umijs/bundler-utils/compiled/tapable");
|
|
29
|
+
var import_utils = require("@umijs/utils");
|
|
30
|
+
var import_assert = __toESM(require("assert"));
|
|
31
|
+
var import_fs = require("fs");
|
|
32
|
+
var import_path = require("path");
|
|
33
|
+
var import_config = require("../config/config");
|
|
34
|
+
var import_constants = require("../constants");
|
|
35
|
+
var import_types = require("../types");
|
|
36
|
+
var import_env = require("./env");
|
|
37
|
+
var import_path2 = require("./path");
|
|
38
|
+
var import_plugin = require("./plugin");
|
|
39
|
+
var import_pluginAPI = require("./pluginAPI");
|
|
40
|
+
var Service = class {
|
|
41
|
+
constructor(opts) {
|
|
42
|
+
this.appData = {};
|
|
43
|
+
this.args = { _: [], $0: "" };
|
|
44
|
+
this.commands = {};
|
|
45
|
+
this.generators = {};
|
|
46
|
+
this.config = {};
|
|
47
|
+
this.configSchemas = {};
|
|
48
|
+
this.configDefaults = {};
|
|
49
|
+
this.configOnChanges = {};
|
|
50
|
+
this.hooks = {};
|
|
51
|
+
this.name = "";
|
|
52
|
+
this.paths = {};
|
|
53
|
+
this.plugins = {};
|
|
54
|
+
this.keyToPluginMap = {};
|
|
55
|
+
this.pluginMethods = {};
|
|
56
|
+
this.skipPluginIds = /* @__PURE__ */ new Set();
|
|
57
|
+
this.stage = import_types.ServiceStage.uninitialized;
|
|
58
|
+
this.userConfig = {};
|
|
59
|
+
this.configManager = null;
|
|
60
|
+
this.pkg = {};
|
|
61
|
+
this.pkgPath = "";
|
|
62
|
+
this.cwd = opts.cwd;
|
|
63
|
+
this.env = opts.env;
|
|
64
|
+
this.opts = opts;
|
|
65
|
+
(0, import_assert.default)((0, import_fs.existsSync)(this.cwd), `Invalid cwd ${this.cwd}, it's not found.`);
|
|
66
|
+
}
|
|
67
|
+
applyPlugins(opts) {
|
|
68
|
+
const hooks = this.hooks[opts.key] || [];
|
|
69
|
+
let type = opts.type;
|
|
70
|
+
if (!type) {
|
|
71
|
+
if (opts.key.startsWith("on")) {
|
|
72
|
+
type = import_types.ApplyPluginsType.event;
|
|
73
|
+
} else if (opts.key.startsWith("modify")) {
|
|
74
|
+
type = import_types.ApplyPluginsType.modify;
|
|
75
|
+
} else if (opts.key.startsWith("add")) {
|
|
76
|
+
type = import_types.ApplyPluginsType.add;
|
|
77
|
+
} else {
|
|
78
|
+
throw new Error(`Invalid applyPlugins arguments, type must be supplied for key ${opts.key}.`);
|
|
79
|
+
}
|
|
46
80
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
case types_1.ApplyPluginsType.add:
|
|
67
|
-
(0, assert_1.default)(!('initialValue' in opts) || Array.isArray(opts.initialValue), `applyPlugins failed, opts.initialValue must be Array if opts.type is add.`);
|
|
68
|
-
const tAdd = new tapable_1.AsyncSeriesWaterfallHook(['memo']);
|
|
69
|
-
for (const hook of hooks) {
|
|
70
|
-
if (!this.isPluginEnable(hook))
|
|
71
|
-
continue;
|
|
72
|
-
tAdd.tapPromise({
|
|
73
|
-
name: hook.plugin.key,
|
|
74
|
-
stage: hook.stage || 0,
|
|
75
|
-
before: hook.before,
|
|
76
|
-
}, async (memo) => {
|
|
77
|
-
var _a, _b;
|
|
78
|
-
const dateStart = new Date();
|
|
79
|
-
const items = await hook.fn(opts.args);
|
|
80
|
-
(_a = hook.plugin.time.hooks)[_b = opts.key] || (_a[_b] = []);
|
|
81
|
-
hook.plugin.time.hooks[opts.key].push(new Date().getTime() - dateStart.getTime());
|
|
82
|
-
return memo.concat(items);
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
return tAdd.promise(opts.initialValue || []);
|
|
86
|
-
case types_1.ApplyPluginsType.modify:
|
|
87
|
-
const tModify = new tapable_1.AsyncSeriesWaterfallHook(['memo']);
|
|
88
|
-
for (const hook of hooks) {
|
|
89
|
-
if (!this.isPluginEnable(hook))
|
|
90
|
-
continue;
|
|
91
|
-
tModify.tapPromise({
|
|
92
|
-
name: hook.plugin.key,
|
|
93
|
-
stage: hook.stage || 0,
|
|
94
|
-
before: hook.before,
|
|
95
|
-
}, async (memo) => {
|
|
96
|
-
var _a, _b;
|
|
97
|
-
const dateStart = new Date();
|
|
98
|
-
const ret = await hook.fn(memo, opts.args);
|
|
99
|
-
(_a = hook.plugin.time.hooks)[_b = opts.key] || (_a[_b] = []);
|
|
100
|
-
hook.plugin.time.hooks[opts.key].push(new Date().getTime() - dateStart.getTime());
|
|
101
|
-
return ret;
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
return tModify.promise(opts.initialValue);
|
|
105
|
-
case types_1.ApplyPluginsType.event:
|
|
106
|
-
if (opts.sync) {
|
|
107
|
-
const tEvent = new tapable_1.SyncWaterfallHook(['_']);
|
|
108
|
-
hooks.forEach((hook) => {
|
|
109
|
-
if (this.isPluginEnable(hook)) {
|
|
110
|
-
tEvent.tap({
|
|
111
|
-
name: hook.plugin.key,
|
|
112
|
-
stage: hook.stage || 0,
|
|
113
|
-
before: hook.before,
|
|
114
|
-
}, () => {
|
|
115
|
-
var _a, _b;
|
|
116
|
-
const dateStart = new Date();
|
|
117
|
-
hook.fn(opts.args);
|
|
118
|
-
(_a = hook.plugin.time.hooks)[_b = opts.key] || (_a[_b] = []);
|
|
119
|
-
hook.plugin.time.hooks[opts.key].push(new Date().getTime() - dateStart.getTime());
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
return tEvent.call(1);
|
|
124
|
-
}
|
|
125
|
-
const tEvent = new tapable_1.AsyncSeriesWaterfallHook(['_']);
|
|
126
|
-
for (const hook of hooks) {
|
|
127
|
-
if (!this.isPluginEnable(hook))
|
|
128
|
-
continue;
|
|
129
|
-
tEvent.tapPromise({
|
|
130
|
-
name: hook.plugin.key,
|
|
131
|
-
stage: hook.stage || 0,
|
|
132
|
-
before: hook.before,
|
|
133
|
-
}, async () => {
|
|
134
|
-
var _a, _b;
|
|
135
|
-
const dateStart = new Date();
|
|
136
|
-
await hook.fn(opts.args);
|
|
137
|
-
(_a = hook.plugin.time.hooks)[_b = opts.key] || (_a[_b] = []);
|
|
138
|
-
hook.plugin.time.hooks[opts.key].push(new Date().getTime() - dateStart.getTime());
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
return tEvent.promise(1);
|
|
142
|
-
default:
|
|
143
|
-
throw new Error(`applyPlugins failed, type is not defined or is not matched, got ${opts.type}.`);
|
|
81
|
+
switch (type) {
|
|
82
|
+
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.`);
|
|
84
|
+
const tAdd = new import_tapable.AsyncSeriesWaterfallHook(["memo"]);
|
|
85
|
+
for (const hook of hooks) {
|
|
86
|
+
if (!this.isPluginEnable(hook))
|
|
87
|
+
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
|
+
});
|
|
144
100
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
101
|
+
return tAdd.promise(opts.initialValue || []);
|
|
102
|
+
case import_types.ApplyPluginsType.modify:
|
|
103
|
+
const tModify = new import_tapable.AsyncSeriesWaterfallHook(["memo"]);
|
|
104
|
+
for (const hook of hooks) {
|
|
105
|
+
if (!this.isPluginEnable(hook))
|
|
106
|
+
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
|
+
});
|
|
163
119
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
120
|
+
return tModify.promise(opts.initialValue);
|
|
121
|
+
case import_types.ApplyPluginsType.event:
|
|
122
|
+
if (opts.sync) {
|
|
123
|
+
const tEvent2 = new import_tapable.SyncWaterfallHook(["_"]);
|
|
124
|
+
hooks.forEach((hook) => {
|
|
125
|
+
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
|
+
});
|
|
172
137
|
}
|
|
138
|
+
});
|
|
139
|
+
return tEvent2.call(1);
|
|
173
140
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
env: this.env,
|
|
190
|
-
prefix: this.opts.frameworkName || constants_1.DEFAULT_FRAMEWORK_NAME,
|
|
191
|
-
});
|
|
192
|
-
// temporary paths for use by function generateFinalConfig.
|
|
193
|
-
// the value of paths may be updated by plugins later
|
|
194
|
-
this.paths = paths;
|
|
195
|
-
// resolve initial presets and plugins
|
|
196
|
-
const { plugins, presets } = plugin_1.Plugin.getPluginsAndPresets({
|
|
197
|
-
cwd: this.cwd,
|
|
198
|
-
pkg,
|
|
199
|
-
plugins: [require.resolve('./generatePlugin')].concat(this.opts.plugins || []),
|
|
200
|
-
presets: [require.resolve('./servicePlugin')].concat(this.opts.presets || []),
|
|
201
|
-
userConfig: this.userConfig,
|
|
202
|
-
prefix,
|
|
203
|
-
});
|
|
204
|
-
// register presets and plugins
|
|
205
|
-
this.stage = types_1.ServiceStage.initPresets;
|
|
206
|
-
const presetPlugins = [];
|
|
207
|
-
while (presets.length) {
|
|
208
|
-
await this.initPreset({
|
|
209
|
-
preset: presets.shift(),
|
|
210
|
-
presets,
|
|
211
|
-
plugins: presetPlugins,
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
plugins.unshift(...presetPlugins);
|
|
215
|
-
this.stage = types_1.ServiceStage.initPlugins;
|
|
216
|
-
while (plugins.length) {
|
|
217
|
-
await this.initPlugin({ plugin: plugins.shift(), plugins });
|
|
218
|
-
}
|
|
219
|
-
const command = this.commands[name];
|
|
220
|
-
(0, assert_1.default)(command, `Invalid command ${name}, it's not registered.`);
|
|
221
|
-
// collect configSchemas and configDefaults
|
|
222
|
-
for (const id of Object.keys(this.plugins)) {
|
|
223
|
-
const { config, key } = this.plugins[id];
|
|
224
|
-
if (config.schema)
|
|
225
|
-
this.configSchemas[key] = config.schema;
|
|
226
|
-
if (config.default !== undefined) {
|
|
227
|
-
this.configDefaults[key] = config.default;
|
|
228
|
-
}
|
|
229
|
-
this.configOnChanges[key] = config.onChange || types_1.ConfigChangeType.reload;
|
|
141
|
+
const tEvent = new import_tapable.AsyncSeriesWaterfallHook(["_"]);
|
|
142
|
+
for (const hook of hooks) {
|
|
143
|
+
if (!this.isPluginEnable(hook))
|
|
144
|
+
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
|
+
});
|
|
230
156
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
157
|
+
return tEvent.promise(1);
|
|
158
|
+
default:
|
|
159
|
+
throw new Error(`applyPlugins failed, type is not defined or is not matched, got ${opts.type}.`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
async run(opts) {
|
|
163
|
+
const { name, args = {} } = opts;
|
|
164
|
+
args._ = args._ || [];
|
|
165
|
+
if (args._[0] === name)
|
|
166
|
+
args._.shift();
|
|
167
|
+
this.args = args;
|
|
168
|
+
this.name = name;
|
|
169
|
+
this.stage = import_types.ServiceStage.init;
|
|
170
|
+
(0, import_env.loadEnv)({ cwd: this.cwd, envFile: ".env" });
|
|
171
|
+
let pkg = {};
|
|
172
|
+
let pkgPath = "";
|
|
173
|
+
try {
|
|
174
|
+
pkg = require((0, import_path.join)(this.cwd, "package.json"));
|
|
175
|
+
pkgPath = (0, import_path.join)(this.cwd, "package.json");
|
|
176
|
+
} catch (_e) {
|
|
177
|
+
if (this.cwd !== process.cwd()) {
|
|
178
|
+
try {
|
|
179
|
+
pkg = require((0, import_path.join)(process.cwd(), "package.json"));
|
|
180
|
+
pkgPath = (0, import_path.join)(process.cwd(), "package.json");
|
|
181
|
+
} catch (_e2) {
|
|
238
182
|
}
|
|
239
|
-
|
|
240
|
-
key: 'modifyPaths',
|
|
241
|
-
initialValue: paths,
|
|
242
|
-
});
|
|
243
|
-
// applyPlugin collect app data
|
|
244
|
-
// TODO: some data is mutable
|
|
245
|
-
this.stage = types_1.ServiceStage.collectAppData;
|
|
246
|
-
this.appData = await this.applyPlugins({
|
|
247
|
-
key: 'modifyAppData',
|
|
248
|
-
initialValue: {
|
|
249
|
-
// base
|
|
250
|
-
cwd: this.cwd,
|
|
251
|
-
pkg,
|
|
252
|
-
pkgPath,
|
|
253
|
-
plugins,
|
|
254
|
-
presets,
|
|
255
|
-
name,
|
|
256
|
-
args,
|
|
257
|
-
// config
|
|
258
|
-
userConfig: this.userConfig,
|
|
259
|
-
mainConfigFile: configManager.mainConfigFile,
|
|
260
|
-
config,
|
|
261
|
-
defaultConfig: defaultConfig,
|
|
262
|
-
// TODO
|
|
263
|
-
// moduleGraph,
|
|
264
|
-
// routes,
|
|
265
|
-
// npmClient,
|
|
266
|
-
// nodeVersion,
|
|
267
|
-
// gitInfo,
|
|
268
|
-
// gitBranch,
|
|
269
|
-
// debugger info,
|
|
270
|
-
// devPort,
|
|
271
|
-
// devHost,
|
|
272
|
-
// env
|
|
273
|
-
},
|
|
274
|
-
});
|
|
275
|
-
// applyPlugin onCheck
|
|
276
|
-
this.stage = types_1.ServiceStage.onCheck;
|
|
277
|
-
await this.applyPlugins({
|
|
278
|
-
key: 'onCheck',
|
|
279
|
-
});
|
|
280
|
-
// applyPlugin onStart
|
|
281
|
-
this.stage = types_1.ServiceStage.onStart;
|
|
282
|
-
await this.applyPlugins({
|
|
283
|
-
key: 'onStart',
|
|
284
|
-
});
|
|
285
|
-
// run command
|
|
286
|
-
this.stage = types_1.ServiceStage.runCommand;
|
|
287
|
-
let ret = await command.fn({ args });
|
|
288
|
-
this._baconPlugins();
|
|
289
|
-
return ret;
|
|
183
|
+
}
|
|
290
184
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
185
|
+
this.pkg = pkg;
|
|
186
|
+
this.pkgPath = pkgPath || (0, import_path.join)(this.cwd, "package.json");
|
|
187
|
+
const prefix = this.opts.frameworkName || import_constants.DEFAULT_FRAMEWORK_NAME;
|
|
188
|
+
const configManager = new import_config.Config({
|
|
189
|
+
cwd: this.cwd,
|
|
190
|
+
env: this.env,
|
|
191
|
+
defaultConfigFiles: this.opts.defaultConfigFiles,
|
|
192
|
+
specifiedEnv: process.env[`${prefix}_ENV`.toUpperCase()]
|
|
193
|
+
});
|
|
194
|
+
this.configManager = configManager;
|
|
195
|
+
this.userConfig = configManager.getUserConfig().config;
|
|
196
|
+
const paths = (0, import_path2.getPaths)({
|
|
197
|
+
cwd: this.cwd,
|
|
198
|
+
env: this.env,
|
|
199
|
+
prefix: this.opts.frameworkName || import_constants.DEFAULT_FRAMEWORK_NAME
|
|
200
|
+
});
|
|
201
|
+
this.paths = paths;
|
|
202
|
+
const { plugins, presets } = import_plugin.Plugin.getPluginsAndPresets({
|
|
203
|
+
cwd: this.cwd,
|
|
204
|
+
pkg,
|
|
205
|
+
plugins: [require.resolve("./generatePlugin")].concat(this.opts.plugins || []),
|
|
206
|
+
presets: [require.resolve("./servicePlugin")].concat(this.opts.presets || []),
|
|
207
|
+
userConfig: this.userConfig,
|
|
208
|
+
prefix
|
|
209
|
+
});
|
|
210
|
+
this.stage = import_types.ServiceStage.initPresets;
|
|
211
|
+
const presetPlugins = [];
|
|
212
|
+
while (presets.length) {
|
|
213
|
+
await this.initPreset({
|
|
214
|
+
preset: presets.shift(),
|
|
215
|
+
presets,
|
|
216
|
+
plugins: presetPlugins
|
|
217
|
+
});
|
|
313
218
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
for (const id of Object.keys(this.plugins)) {
|
|
319
|
-
const plugin = this.plugins[id];
|
|
320
|
-
console.log(utils_1.chalk.green('plugin'), plugin.id, plugin.time);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
219
|
+
plugins.unshift(...presetPlugins);
|
|
220
|
+
this.stage = import_types.ServiceStage.initPlugins;
|
|
221
|
+
while (plugins.length) {
|
|
222
|
+
await this.initPlugin({ plugin: plugins.shift(), plugins });
|
|
323
223
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
224
|
+
const command = this.commands[name];
|
|
225
|
+
(0, import_assert.default)(command, `Invalid command ${name}, it's not registered.`);
|
|
226
|
+
for (const id of Object.keys(this.plugins)) {
|
|
227
|
+
const { config: config2, key } = this.plugins[id];
|
|
228
|
+
if (config2.schema)
|
|
229
|
+
this.configSchemas[key] = config2.schema;
|
|
230
|
+
if (config2.default !== void 0) {
|
|
231
|
+
this.configDefaults[key] = config2.default;
|
|
232
|
+
}
|
|
233
|
+
this.configOnChanges[key] = config2.onChange || import_types.ConfigChangeType.reload;
|
|
332
234
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
this.plugins[opts.plugin.id] = opts.plugin;
|
|
338
|
-
// apply with PluginAPI
|
|
339
|
-
const pluginAPI = new pluginAPI_1.PluginAPI({
|
|
340
|
-
plugin: opts.plugin,
|
|
341
|
-
service: this,
|
|
342
|
-
});
|
|
343
|
-
pluginAPI.registerPresets = pluginAPI.registerPresets.bind(pluginAPI, opts.presets || []);
|
|
344
|
-
pluginAPI.registerPlugins = pluginAPI.registerPlugins.bind(pluginAPI, opts.plugins);
|
|
345
|
-
const proxyPluginAPI = pluginAPI_1.PluginAPI.proxyPluginAPI({
|
|
346
|
-
service: this,
|
|
347
|
-
pluginAPI,
|
|
348
|
-
serviceProps: [
|
|
349
|
-
'appData',
|
|
350
|
-
'applyPlugins',
|
|
351
|
-
'args',
|
|
352
|
-
'config',
|
|
353
|
-
'cwd',
|
|
354
|
-
'pkg',
|
|
355
|
-
'pkgPath',
|
|
356
|
-
'name',
|
|
357
|
-
'paths',
|
|
358
|
-
'userConfig',
|
|
359
|
-
'env',
|
|
360
|
-
'isPluginEnable',
|
|
361
|
-
],
|
|
362
|
-
staticProps: {
|
|
363
|
-
ApplyPluginsType: types_1.ApplyPluginsType,
|
|
364
|
-
ConfigChangeType: types_1.ConfigChangeType,
|
|
365
|
-
EnableBy: types_1.EnableBy,
|
|
366
|
-
ServiceStage: types_1.ServiceStage,
|
|
367
|
-
service: this,
|
|
368
|
-
},
|
|
369
|
-
});
|
|
370
|
-
let dateStart = new Date();
|
|
371
|
-
let ret = await opts.plugin.apply()(proxyPluginAPI);
|
|
372
|
-
opts.plugin.time.register = new Date().getTime() - dateStart.getTime();
|
|
373
|
-
if (opts.plugin.type === 'plugin') {
|
|
374
|
-
(0, assert_1.default)(!ret, `plugin should return nothing`);
|
|
375
|
-
}
|
|
376
|
-
// key should be unique
|
|
377
|
-
(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.`);
|
|
378
|
-
this.keyToPluginMap[opts.plugin.key] = opts.plugin;
|
|
379
|
-
if (ret === null || ret === void 0 ? void 0 : ret.presets) {
|
|
380
|
-
ret.presets = ret.presets.map((preset) => new plugin_1.Plugin({
|
|
381
|
-
path: preset,
|
|
382
|
-
type: types_1.PluginType.preset,
|
|
383
|
-
cwd: this.cwd,
|
|
384
|
-
}));
|
|
385
|
-
}
|
|
386
|
-
if (ret === null || ret === void 0 ? void 0 : ret.plugins) {
|
|
387
|
-
ret.plugins = ret.plugins.map((plugin) => new plugin_1.Plugin({
|
|
388
|
-
path: plugin,
|
|
389
|
-
type: types_1.PluginType.plugin,
|
|
390
|
-
cwd: this.cwd,
|
|
391
|
-
}));
|
|
392
|
-
}
|
|
393
|
-
return ret || {};
|
|
235
|
+
this.stage = import_types.ServiceStage.resolveConfig;
|
|
236
|
+
const { config, defaultConfig } = await this.resolveConfig();
|
|
237
|
+
if (this.config.outputPath) {
|
|
238
|
+
paths.absOutputPath = (0, import_path.isAbsolute)(this.config.outputPath) ? this.config.outputPath : (0, import_path.join)(this.cwd, this.config.outputPath);
|
|
394
239
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
240
|
+
this.paths = await this.applyPlugins({
|
|
241
|
+
key: "modifyPaths",
|
|
242
|
+
initialValue: paths
|
|
243
|
+
});
|
|
244
|
+
this.stage = import_types.ServiceStage.collectAppData;
|
|
245
|
+
this.appData = await this.applyPlugins({
|
|
246
|
+
key: "modifyAppData",
|
|
247
|
+
initialValue: {
|
|
248
|
+
cwd: this.cwd,
|
|
249
|
+
pkg,
|
|
250
|
+
pkgPath,
|
|
251
|
+
plugins,
|
|
252
|
+
presets,
|
|
253
|
+
name,
|
|
254
|
+
args,
|
|
255
|
+
userConfig: this.userConfig,
|
|
256
|
+
mainConfigFile: configManager.mainConfigFile,
|
|
257
|
+
config,
|
|
258
|
+
defaultConfig
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
this.stage = import_types.ServiceStage.onCheck;
|
|
262
|
+
await this.applyPlugins({
|
|
263
|
+
key: "onCheck"
|
|
264
|
+
});
|
|
265
|
+
this.stage = import_types.ServiceStage.onStart;
|
|
266
|
+
await this.applyPlugins({
|
|
267
|
+
key: "onStart"
|
|
268
|
+
});
|
|
269
|
+
this.stage = import_types.ServiceStage.runCommand;
|
|
270
|
+
let ret = await command.fn({ args });
|
|
271
|
+
this._baconPlugins();
|
|
272
|
+
return ret;
|
|
273
|
+
}
|
|
274
|
+
async resolveConfig() {
|
|
275
|
+
(0, import_assert.default)(this.stage > import_types.ServiceStage.init, `Can't generate final config before init stage`);
|
|
276
|
+
const resolveMode = this.commands[this.name].configResolveMode;
|
|
277
|
+
const config = await this.applyPlugins({
|
|
278
|
+
key: "modifyConfig",
|
|
279
|
+
initialValue: import_utils.lodash.cloneDeep(resolveMode === "strict" ? this.configManager.getConfig({
|
|
280
|
+
schemas: this.configSchemas
|
|
281
|
+
}).config : this.configManager.getUserConfig().config),
|
|
282
|
+
args: { paths: this.paths }
|
|
283
|
+
});
|
|
284
|
+
const defaultConfig = await this.applyPlugins({
|
|
285
|
+
key: "modifyDefaultConfig",
|
|
286
|
+
initialValue: this.configDefaults
|
|
287
|
+
});
|
|
288
|
+
this.config = import_utils.lodash.merge(defaultConfig, config);
|
|
289
|
+
return { config, defaultConfig };
|
|
290
|
+
}
|
|
291
|
+
_baconPlugins() {
|
|
292
|
+
if (this.args.baconPlugins) {
|
|
293
|
+
console.log();
|
|
294
|
+
for (const id of Object.keys(this.plugins)) {
|
|
295
|
+
const plugin = this.plugins[id];
|
|
296
|
+
console.log(import_utils.chalk.green("plugin"), plugin.id, plugin.time);
|
|
297
|
+
}
|
|
432
298
|
}
|
|
433
|
-
}
|
|
434
|
-
|
|
299
|
+
}
|
|
300
|
+
async initPreset(opts) {
|
|
301
|
+
const { presets, plugins } = await this.initPlugin({
|
|
302
|
+
plugin: opts.preset,
|
|
303
|
+
presets: opts.presets,
|
|
304
|
+
plugins: opts.plugins
|
|
305
|
+
});
|
|
306
|
+
opts.presets.unshift(...presets || []);
|
|
307
|
+
opts.plugins.push(...plugins || []);
|
|
308
|
+
}
|
|
309
|
+
async initPlugin(opts) {
|
|
310
|
+
var _a, _b;
|
|
311
|
+
(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.`);
|
|
312
|
+
this.plugins[opts.plugin.id] = opts.plugin;
|
|
313
|
+
const pluginAPI = new import_pluginAPI.PluginAPI({
|
|
314
|
+
plugin: opts.plugin,
|
|
315
|
+
service: this
|
|
316
|
+
});
|
|
317
|
+
pluginAPI.registerPresets = pluginAPI.registerPresets.bind(pluginAPI, opts.presets || []);
|
|
318
|
+
pluginAPI.registerPlugins = pluginAPI.registerPlugins.bind(pluginAPI, opts.plugins);
|
|
319
|
+
const proxyPluginAPI = import_pluginAPI.PluginAPI.proxyPluginAPI({
|
|
320
|
+
service: this,
|
|
321
|
+
pluginAPI,
|
|
322
|
+
serviceProps: [
|
|
323
|
+
"appData",
|
|
324
|
+
"applyPlugins",
|
|
325
|
+
"args",
|
|
326
|
+
"config",
|
|
327
|
+
"cwd",
|
|
328
|
+
"pkg",
|
|
329
|
+
"pkgPath",
|
|
330
|
+
"name",
|
|
331
|
+
"paths",
|
|
332
|
+
"userConfig",
|
|
333
|
+
"env",
|
|
334
|
+
"isPluginEnable"
|
|
335
|
+
],
|
|
336
|
+
staticProps: {
|
|
337
|
+
ApplyPluginsType: import_types.ApplyPluginsType,
|
|
338
|
+
ConfigChangeType: import_types.ConfigChangeType,
|
|
339
|
+
EnableBy: import_types.EnableBy,
|
|
340
|
+
ServiceStage: import_types.ServiceStage,
|
|
341
|
+
service: this
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
let dateStart = new Date();
|
|
345
|
+
let ret = await opts.plugin.apply()(proxyPluginAPI);
|
|
346
|
+
opts.plugin.time.register = new Date().getTime() - dateStart.getTime();
|
|
347
|
+
if (opts.plugin.type === "plugin") {
|
|
348
|
+
(0, import_assert.default)(!ret, `plugin should return nothing`);
|
|
349
|
+
}
|
|
350
|
+
(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.`);
|
|
351
|
+
this.keyToPluginMap[opts.plugin.key] = opts.plugin;
|
|
352
|
+
if (ret == null ? void 0 : ret.presets) {
|
|
353
|
+
ret.presets = ret.presets.map((preset) => new import_plugin.Plugin({
|
|
354
|
+
path: preset,
|
|
355
|
+
type: import_types.PluginType.preset,
|
|
356
|
+
cwd: this.cwd
|
|
357
|
+
}));
|
|
358
|
+
}
|
|
359
|
+
if (ret == null ? void 0 : ret.plugins) {
|
|
360
|
+
ret.plugins = ret.plugins.map((plugin) => new import_plugin.Plugin({
|
|
361
|
+
path: plugin,
|
|
362
|
+
type: import_types.PluginType.plugin,
|
|
363
|
+
cwd: this.cwd
|
|
364
|
+
}));
|
|
365
|
+
}
|
|
366
|
+
return ret || {};
|
|
367
|
+
}
|
|
368
|
+
isPluginEnable(hook) {
|
|
369
|
+
let plugin;
|
|
370
|
+
if (hook.plugin) {
|
|
371
|
+
plugin = hook.plugin;
|
|
372
|
+
} else {
|
|
373
|
+
plugin = this.keyToPluginMap[hook];
|
|
374
|
+
if (!plugin)
|
|
375
|
+
return false;
|
|
376
|
+
}
|
|
377
|
+
const { id, key, enableBy } = plugin;
|
|
378
|
+
if (this.skipPluginIds.has(id))
|
|
379
|
+
return false;
|
|
380
|
+
if (this.userConfig[key] === false)
|
|
381
|
+
return false;
|
|
382
|
+
if (this.config[key] === false)
|
|
383
|
+
return false;
|
|
384
|
+
if (enableBy === import_types.EnableBy.config) {
|
|
385
|
+
return key in this.userConfig || this.config && key in this.config;
|
|
386
|
+
}
|
|
387
|
+
if (typeof enableBy === "function")
|
|
388
|
+
return enableBy({
|
|
389
|
+
userConfig: this.userConfig,
|
|
390
|
+
config: this.config,
|
|
391
|
+
env: this.env
|
|
392
|
+
});
|
|
393
|
+
return true;
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
397
|
+
0 && (module.exports = {
|
|
398
|
+
Service
|
|
399
|
+
});
|