@umijs/core 4.0.0-rc.6 → 4.0.0-rc.7
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/route/defineRoutes.js +6 -3
- package/dist/route/routesConfig.js +10 -0
- package/dist/service/generatePlugin.js +0 -3
- package/dist/service/generator.d.ts +1 -5
- package/dist/service/plugin.d.ts +4 -0
- package/dist/service/plugin.js +1 -0
- package/dist/service/pluginAPI.js +8 -1
- package/dist/service/service.d.ts +1 -0
- package/dist/service/service.js +33 -3
- package/dist/types.d.ts +1 -0
- package/package.json +5 -4
|
@@ -7,13 +7,16 @@ function defineRoutes(callback) {
|
|
|
7
7
|
const parentRoutes = [];
|
|
8
8
|
const defineRoute = (opts) => {
|
|
9
9
|
opts.options = opts.options || {};
|
|
10
|
+
const parentRoute = parentRoutes.length > 0 ? parentRoutes[parentRoutes.length - 1] : null;
|
|
11
|
+
const parentId = parentRoute === null || parentRoute === void 0 ? void 0 : parentRoute.id;
|
|
12
|
+
const parentAbsPath = parentRoute === null || parentRoute === void 0 ? void 0 : parentRoute.absPath;
|
|
13
|
+
const absPath = [parentAbsPath, opts.path].join('/');
|
|
10
14
|
const route = {
|
|
11
15
|
path: opts.path || '/',
|
|
12
16
|
id: (0, utils_1.createRouteId)(opts.file),
|
|
13
|
-
parentId
|
|
14
|
-
? parentRoutes[parentRoutes.length - 1].id
|
|
15
|
-
: undefined,
|
|
17
|
+
parentId,
|
|
16
18
|
file: opts.file,
|
|
19
|
+
absPath,
|
|
17
20
|
};
|
|
18
21
|
routes[route.id] = route;
|
|
19
22
|
if (opts.children) {
|
|
@@ -31,7 +31,17 @@ function transformRoute(opts) {
|
|
|
31
31
|
(0, assert_1.default)(!opts.route.children, 'children is not allowed in route props, use routes instead.');
|
|
32
32
|
const id = String(opts.memo.id++);
|
|
33
33
|
const _a = opts.route, { routes, component } = _a, routeProps = __rest(_a, ["routes", "component"]);
|
|
34
|
+
let absPath = opts.route.path;
|
|
35
|
+
if ((absPath === null || absPath === void 0 ? void 0 : absPath.charAt(0)) !== '/') {
|
|
36
|
+
const parentAbsPath = opts.parentId
|
|
37
|
+
? opts.memo.ret[opts.parentId].absPath.replace(/\/*$/, '/') // to remove '/'s on the tail
|
|
38
|
+
: '/';
|
|
39
|
+
absPath = parentAbsPath + absPath;
|
|
40
|
+
}
|
|
34
41
|
opts.memo.ret[id] = Object.assign(Object.assign(Object.assign(Object.assign({}, routeProps), { path: opts.route.path }), (component ? { file: component } : {})), { parentId: opts.parentId, id });
|
|
42
|
+
if (absPath) {
|
|
43
|
+
opts.memo.ret[id].absPath = absPath;
|
|
44
|
+
}
|
|
35
45
|
if (opts.route.routes) {
|
|
36
46
|
transformRoutes({
|
|
37
47
|
routes: opts.route.routes,
|
|
@@ -25,7 +25,6 @@ umi generate
|
|
|
25
25
|
const [type] = args._;
|
|
26
26
|
const runGenerator = (generator) => __awaiter(this, void 0, void 0, function* () {
|
|
27
27
|
yield (generator === null || generator === void 0 ? void 0 : generator.fn({
|
|
28
|
-
api,
|
|
29
28
|
args,
|
|
30
29
|
generateFile: utils_1.generateFile,
|
|
31
30
|
installDeps: utils_1.installDeps,
|
|
@@ -39,7 +38,6 @@ umi generate
|
|
|
39
38
|
}
|
|
40
39
|
if (generator.type === generator_1.GeneratorType.enable) {
|
|
41
40
|
const enable = yield ((_a = generator.checkEnable) === null || _a === void 0 ? void 0 : _a.call(generator, {
|
|
42
|
-
api,
|
|
43
41
|
args,
|
|
44
42
|
}));
|
|
45
43
|
if (!enable) {
|
|
@@ -62,7 +60,6 @@ umi generate
|
|
|
62
60
|
}
|
|
63
61
|
else {
|
|
64
62
|
const enable = yield ((_c = (_b = generators[key]) === null || _b === void 0 ? void 0 : _b.checkEnable) === null || _c === void 0 ? void 0 : _c.call(_b, {
|
|
65
|
-
api,
|
|
66
63
|
args,
|
|
67
64
|
}));
|
|
68
65
|
if (enable) {
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { prompts } from '@umijs/utils';
|
|
2
2
|
import { Plugin } from './plugin';
|
|
3
|
-
import { PluginAPI } from './pluginAPI';
|
|
4
|
-
import { IServicePluginAPI } from './service';
|
|
5
3
|
export declare enum GeneratorType {
|
|
6
4
|
generate = "generate",
|
|
7
5
|
enable = "enable"
|
|
@@ -14,20 +12,18 @@ export interface IGeneratorOpts {
|
|
|
14
12
|
checkEnable?: {
|
|
15
13
|
(opts: {
|
|
16
14
|
args: any;
|
|
17
|
-
api: PluginAPI & IServicePluginAPI;
|
|
18
15
|
}): boolean;
|
|
19
16
|
};
|
|
20
17
|
fn: {
|
|
21
18
|
(opts: {
|
|
22
19
|
args: any;
|
|
23
|
-
api: PluginAPI & IServicePluginAPI;
|
|
24
20
|
generateFile: {
|
|
25
21
|
(opts: {
|
|
26
22
|
path: string;
|
|
27
23
|
target: string;
|
|
28
24
|
data?: any;
|
|
29
25
|
questions?: prompts.PromptObject[];
|
|
30
|
-
}): void
|
|
26
|
+
}): Promise<void>;
|
|
31
27
|
};
|
|
32
28
|
updatePackageJSON: {
|
|
33
29
|
(opts: {
|
package/dist/service/plugin.d.ts
CHANGED
package/dist/service/plugin.js
CHANGED
|
@@ -36,6 +36,11 @@ class PluginAPI {
|
|
|
36
36
|
}, {});
|
|
37
37
|
}
|
|
38
38
|
describe(opts) {
|
|
39
|
+
var _a;
|
|
40
|
+
// default 值 + 配置开启冲突,会导致就算用户没有配 key,插件也会生效
|
|
41
|
+
if (opts.enableBy === types_1.EnableBy.config && ((_a = opts.config) === null || _a === void 0 ? void 0 : _a.default)) {
|
|
42
|
+
throw new Error(`[plugin: ${this.plugin.id}] The config.default is not allowed when enableBy is EnableBy.config.`);
|
|
43
|
+
}
|
|
39
44
|
this.plugin.merge(opts);
|
|
40
45
|
}
|
|
41
46
|
registerCommand(opts) {
|
|
@@ -63,6 +68,7 @@ class PluginAPI {
|
|
|
63
68
|
}
|
|
64
69
|
register(opts) {
|
|
65
70
|
var _a, _b;
|
|
71
|
+
(0, assert_1.default)(this.service.stage <= types_1.ServiceStage.initPlugins, 'api.register() should not be called after plugin register stage.');
|
|
66
72
|
(_a = this.service.hooks)[_b = opts.key] || (_a[_b] = []);
|
|
67
73
|
this.service.hooks[opts.key].push(new hook_1.Hook(Object.assign(Object.assign({}, opts), { plugin: this.plugin })));
|
|
68
74
|
}
|
|
@@ -85,7 +91,7 @@ class PluginAPI {
|
|
|
85
91
|
return new plugin_1.Plugin({
|
|
86
92
|
path: preset,
|
|
87
93
|
cwd: this.service.cwd,
|
|
88
|
-
type: types_1.PluginType.
|
|
94
|
+
type: types_1.PluginType.preset,
|
|
89
95
|
});
|
|
90
96
|
}));
|
|
91
97
|
}
|
|
@@ -99,6 +105,7 @@ class PluginAPI {
|
|
|
99
105
|
plugin.enableBy = plugin.enableBy || types_1.EnableBy.register;
|
|
100
106
|
plugin.apply = plugin.apply || (() => () => { });
|
|
101
107
|
plugin.config = plugin.config || {};
|
|
108
|
+
plugin.time = { hooks: {} };
|
|
102
109
|
return plugin;
|
|
103
110
|
}
|
|
104
111
|
else {
|
package/dist/service/service.js
CHANGED
|
@@ -85,7 +85,11 @@ class Service {
|
|
|
85
85
|
stage: hook.stage,
|
|
86
86
|
before: hook.before,
|
|
87
87
|
}, (memo) => __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
var _a, _b;
|
|
89
|
+
const dateStart = new Date();
|
|
88
90
|
const items = yield hook.fn(opts.args);
|
|
91
|
+
(_a = hook.plugin.time.hooks)[_b = opts.key] || (_a[_b] = []);
|
|
92
|
+
hook.plugin.time.hooks[opts.key].push(new Date().getTime() - dateStart.getTime());
|
|
89
93
|
return memo.concat(items);
|
|
90
94
|
}));
|
|
91
95
|
}
|
|
@@ -100,7 +104,12 @@ class Service {
|
|
|
100
104
|
stage: hook.stage,
|
|
101
105
|
before: hook.before,
|
|
102
106
|
}, (memo) => __awaiter(this, void 0, void 0, function* () {
|
|
103
|
-
|
|
107
|
+
var _c, _d;
|
|
108
|
+
const dateStart = new Date();
|
|
109
|
+
const ret = yield hook.fn(memo, opts.args);
|
|
110
|
+
(_c = hook.plugin.time.hooks)[_d = opts.key] || (_c[_d] = []);
|
|
111
|
+
hook.plugin.time.hooks[opts.key].push(new Date().getTime() - dateStart.getTime());
|
|
112
|
+
return ret;
|
|
104
113
|
}));
|
|
105
114
|
}
|
|
106
115
|
return (yield tModify.promise(opts.initialValue));
|
|
@@ -114,7 +123,11 @@ class Service {
|
|
|
114
123
|
stage: hook.stage || 0,
|
|
115
124
|
before: hook.before,
|
|
116
125
|
}, () => __awaiter(this, void 0, void 0, function* () {
|
|
126
|
+
var _f, _g;
|
|
127
|
+
const dateStart = new Date();
|
|
117
128
|
yield hook.fn(opts.args);
|
|
129
|
+
(_f = hook.plugin.time.hooks)[_g = opts.key] || (_f[_g] = []);
|
|
130
|
+
hook.plugin.time.hooks[opts.key].push(new Date().getTime() - dateStart.getTime());
|
|
118
131
|
}));
|
|
119
132
|
}
|
|
120
133
|
return (yield tEvent.promise(1));
|
|
@@ -153,7 +166,7 @@ class Service {
|
|
|
153
166
|
}
|
|
154
167
|
}
|
|
155
168
|
this.pkg = pkg;
|
|
156
|
-
this.pkgPath = pkgPath;
|
|
169
|
+
this.pkgPath = pkgPath || (0, path_1.join)(this.cwd, 'package.json');
|
|
157
170
|
// get user config
|
|
158
171
|
const configManager = new config_1.Config({
|
|
159
172
|
cwd: this.cwd,
|
|
@@ -272,9 +285,24 @@ class Service {
|
|
|
272
285
|
this.stage = types_1.ServiceStage.runCommand;
|
|
273
286
|
const command = this.commands[name];
|
|
274
287
|
(0, assert_1.default)(command, `Invalid command ${name}, it's not registered.`);
|
|
275
|
-
|
|
288
|
+
let ret = command.fn({ args });
|
|
289
|
+
if ((0, utils_2.isPromise)(ret)) {
|
|
290
|
+
ret = yield ret;
|
|
291
|
+
}
|
|
292
|
+
this._baconPlugins();
|
|
293
|
+
return ret;
|
|
276
294
|
});
|
|
277
295
|
}
|
|
296
|
+
_baconPlugins() {
|
|
297
|
+
// TODO: prettier
|
|
298
|
+
if (this.args.baconPlugins) {
|
|
299
|
+
console.log();
|
|
300
|
+
for (const id of Object.keys(this.plugins)) {
|
|
301
|
+
const plugin = this.plugins[id];
|
|
302
|
+
console.log(utils_1.chalk.green('plugin'), plugin.id, plugin.time);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
278
306
|
initPreset(opts) {
|
|
279
307
|
return __awaiter(this, void 0, void 0, function* () {
|
|
280
308
|
const { presets, plugins } = yield this.initPlugin({
|
|
@@ -324,10 +352,12 @@ class Service {
|
|
|
324
352
|
service: this,
|
|
325
353
|
},
|
|
326
354
|
});
|
|
355
|
+
let dateStart = new Date();
|
|
327
356
|
let ret = opts.plugin.apply()(proxyPluginAPI);
|
|
328
357
|
if ((0, utils_2.isPromise)(ret)) {
|
|
329
358
|
ret = yield ret;
|
|
330
359
|
}
|
|
360
|
+
opts.plugin.time.register = new Date().getTime() - dateStart.getTime();
|
|
331
361
|
if (opts.plugin.type === 'plugin') {
|
|
332
362
|
(0, assert_1.default)(!ret, `plugin should return nothing`);
|
|
333
363
|
}
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/core",
|
|
3
|
-
"version": "4.0.0-rc.
|
|
3
|
+
"version": "4.0.0-rc.7",
|
|
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": {
|
|
@@ -17,11 +17,12 @@
|
|
|
17
17
|
"scripts": {
|
|
18
18
|
"build": "pnpm tsc",
|
|
19
19
|
"build:deps": "pnpm esno ../../scripts/bundleDeps.ts",
|
|
20
|
-
"dev": "pnpm build -- --watch"
|
|
20
|
+
"dev": "pnpm build -- --watch",
|
|
21
|
+
"test": "jest -c ../../jest.turbo.config.ts"
|
|
21
22
|
},
|
|
22
23
|
"dependencies": {
|
|
23
|
-
"@umijs/bundler-utils": "4.0.0-rc.
|
|
24
|
-
"@umijs/utils": "4.0.0-rc.
|
|
24
|
+
"@umijs/bundler-utils": "4.0.0-rc.7",
|
|
25
|
+
"@umijs/utils": "4.0.0-rc.7"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
28
|
"@hapi/joi": "17.1.1",
|