@umijs/core 4.0.0-beta.5 → 4.0.0-beta.9
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/config/config.js +1 -0
- package/dist/route/route.d.ts +1 -0
- package/dist/route/route.js +1 -0
- package/dist/route/routesConfig.d.ts +5 -0
- package/dist/route/routesConfig.js +36 -0
- package/dist/route/routesConvention.d.ts +1 -0
- package/dist/route/routesConvention.js +1 -1
- package/dist/service/generatePlugin.js +6 -6
- package/dist/service/plugin.d.ts +3 -1
- package/dist/service/plugin.js +14 -4
- package/dist/service/pluginAPI.d.ts +4 -0
- package/dist/service/pluginAPI.js +22 -3
- package/dist/service/service.d.ts +3 -1
- package/dist/service/service.js +10 -9
- package/package.json +16 -16
package/dist/config/config.js
CHANGED
package/dist/route/route.d.ts
CHANGED
package/dist/route/route.js
CHANGED
|
@@ -14,5 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./routesConfig"), exports);
|
|
17
18
|
__exportStar(require("./routesConvention"), exports);
|
|
18
19
|
__exportStar(require("./routeUtils"), exports);
|
|
@@ -1 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.getConfigRoutes = void 0;
|
|
15
|
+
function getConfigRoutes(opts) {
|
|
16
|
+
const memo = { ret: {}, id: 1 };
|
|
17
|
+
transformRoutes({ routes: opts.routes, parentId: undefined, memo });
|
|
18
|
+
return memo.ret;
|
|
19
|
+
}
|
|
20
|
+
exports.getConfigRoutes = getConfigRoutes;
|
|
21
|
+
function transformRoutes(opts) {
|
|
22
|
+
opts.routes.forEach((route) => {
|
|
23
|
+
transformRoute({ route, parentId: opts.parentId, memo: opts.memo });
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function transformRoute(opts) {
|
|
27
|
+
const id = String(opts.memo.id++);
|
|
28
|
+
const _a = opts.route, { routes, component } = _a, routeProps = __rest(_a, ["routes", "component"]);
|
|
29
|
+
opts.memo.ret[id] = Object.assign(Object.assign(Object.assign(Object.assign({}, routeProps), { path: opts.route.path }), (component ? { file: component } : {})), { parentId: opts.parentId, id });
|
|
30
|
+
if (opts.route.routes) {
|
|
31
|
+
transformRoutes({
|
|
32
|
+
routes: opts.route.routes,
|
|
33
|
+
parentId: id,
|
|
34
|
+
memo: opts.memo,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -33,7 +33,7 @@ function getConventionRoutes(opts) {
|
|
|
33
33
|
let routePath = createRoutePath(parentId ? routeId.slice(parentId.length + 1) : routeId);
|
|
34
34
|
defineRoute({
|
|
35
35
|
path: routePath,
|
|
36
|
-
file: files[routeId]
|
|
36
|
+
file: `${opts.prefix || ''}${files[routeId]}`,
|
|
37
37
|
children() {
|
|
38
38
|
defineNestedRoutes(defineRoute, routeId);
|
|
39
39
|
},
|
|
@@ -23,15 +23,15 @@ umi generate
|
|
|
23
23
|
var _a;
|
|
24
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
25
25
|
const [type] = args._;
|
|
26
|
-
const runGenerator = (generator) => {
|
|
27
|
-
generator === null || generator === void 0 ? void 0 : generator.fn({
|
|
26
|
+
const runGenerator = (generator) => __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
yield (generator === null || generator === void 0 ? void 0 : generator.fn({
|
|
28
28
|
api,
|
|
29
29
|
args,
|
|
30
30
|
generateFile: utils_1.generateFile,
|
|
31
31
|
installDeps: utils_1.installDeps,
|
|
32
32
|
updatePackageJSON: utils_1.updatePackageJSON,
|
|
33
|
-
});
|
|
34
|
-
};
|
|
33
|
+
}));
|
|
34
|
+
});
|
|
35
35
|
if (type) {
|
|
36
36
|
const generator = api.service.generators[type];
|
|
37
37
|
if (!generator) {
|
|
@@ -46,7 +46,7 @@ umi generate
|
|
|
46
46
|
throw new Error(`Generator ${type} is unable.The corresponding function has been turned on or is not available.`);
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
runGenerator(generator);
|
|
49
|
+
yield runGenerator(generator);
|
|
50
50
|
}
|
|
51
51
|
else {
|
|
52
52
|
const getEnableGenerators = (generators) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -83,7 +83,7 @@ umi generate
|
|
|
83
83
|
message: 'Pick generator type',
|
|
84
84
|
choices: questions,
|
|
85
85
|
});
|
|
86
|
-
runGenerator(api.service.generators[gType]);
|
|
86
|
+
yield runGenerator(api.service.generators[gType]);
|
|
87
87
|
}
|
|
88
88
|
});
|
|
89
89
|
},
|
package/dist/service/plugin.d.ts
CHANGED
|
@@ -20,7 +20,9 @@ export declare class Plugin {
|
|
|
20
20
|
key: string;
|
|
21
21
|
apply: Function;
|
|
22
22
|
config: IPluginConfig;
|
|
23
|
-
enableBy: EnableBy | ((
|
|
23
|
+
enableBy: EnableBy | ((opts: {
|
|
24
|
+
config: any;
|
|
25
|
+
}) => boolean);
|
|
24
26
|
constructor(opts: IOpts);
|
|
25
27
|
merge(opts: {
|
|
26
28
|
key?: string;
|
package/dist/service/plugin.js
CHANGED
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Plugin = void 0;
|
|
7
|
+
const esbuild_1 = __importDefault(require("@umijs/bundler-utils/compiled/esbuild"));
|
|
7
8
|
const utils_1 = require("@umijs/utils");
|
|
8
9
|
const assert_1 = __importDefault(require("assert"));
|
|
9
10
|
const fs_1 = require("fs");
|
|
@@ -34,14 +35,23 @@ class Plugin {
|
|
|
34
35
|
this.id = this.getId({ pkg, isPkgEntry, pkgJSONPath });
|
|
35
36
|
this.key = this.getKey({ pkg, isPkgEntry });
|
|
36
37
|
this.apply = () => {
|
|
38
|
+
utils_1.register.register({
|
|
39
|
+
implementor: esbuild_1.default,
|
|
40
|
+
});
|
|
41
|
+
utils_1.register.clearFiles();
|
|
42
|
+
let ret;
|
|
37
43
|
try {
|
|
38
|
-
|
|
39
|
-
// use the default member for es modules
|
|
40
|
-
return ret.__esModule ? ret.default : ret;
|
|
44
|
+
ret = require(this.path);
|
|
41
45
|
}
|
|
42
46
|
catch (e) {
|
|
43
47
|
throw new Error(`Register ${this.type} ${this.path} failed, since ${e.message}`);
|
|
44
48
|
}
|
|
49
|
+
for (const file of utils_1.register.getFiles()) {
|
|
50
|
+
delete require.cache[file];
|
|
51
|
+
}
|
|
52
|
+
utils_1.register.restore();
|
|
53
|
+
// use the default member for es modules
|
|
54
|
+
return ret.__esModule ? ret.default : ret;
|
|
45
55
|
};
|
|
46
56
|
}
|
|
47
57
|
merge(opts) {
|
|
@@ -66,7 +76,7 @@ class Plugin {
|
|
|
66
76
|
else {
|
|
67
77
|
id = (0, utils_1.winPath)(this.path);
|
|
68
78
|
}
|
|
69
|
-
id = id.replace('@umijs/preset-
|
|
79
|
+
id = id.replace('@umijs/preset-umi/lib/plugins', '@@');
|
|
70
80
|
id = id.replace(/\.js$/, '');
|
|
71
81
|
return id;
|
|
72
82
|
}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import { logger } from '@umijs/utils';
|
|
1
2
|
import { EnableBy, IPluginConfig } from '../types';
|
|
2
3
|
import { IOpts as ICommandOpts } from './command';
|
|
3
4
|
import { IGeneratorOpts } from './generator';
|
|
4
5
|
import { IOpts as IHookOpts } from './hook';
|
|
5
6
|
import { Plugin } from './plugin';
|
|
6
7
|
import { Service } from './service';
|
|
8
|
+
declare type Logger = typeof logger;
|
|
7
9
|
export declare class PluginAPI {
|
|
8
10
|
service: Service;
|
|
9
11
|
plugin: Plugin;
|
|
12
|
+
logger: Logger;
|
|
10
13
|
constructor(opts: {
|
|
11
14
|
service: Service;
|
|
12
15
|
plugin: Plugin;
|
|
@@ -35,3 +38,4 @@ export declare class PluginAPI {
|
|
|
35
38
|
staticProps: Record<string, any>;
|
|
36
39
|
}): PluginAPI;
|
|
37
40
|
}
|
|
41
|
+
export {};
|
|
@@ -16,8 +16,24 @@ class PluginAPI {
|
|
|
16
16
|
constructor(opts) {
|
|
17
17
|
this.service = opts.service;
|
|
18
18
|
this.plugin = opts.plugin;
|
|
19
|
-
// TODO
|
|
20
19
|
// logger
|
|
20
|
+
const loggerKeys = [
|
|
21
|
+
'wait',
|
|
22
|
+
'error',
|
|
23
|
+
'warn',
|
|
24
|
+
'ready',
|
|
25
|
+
'info',
|
|
26
|
+
'event',
|
|
27
|
+
];
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
this.logger = loggerKeys.reduce((memo, key) => {
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
memo[key] = (...message) => {
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
utils_1.logger[key](utils_1.chalk.green(`[plugin: ${this.plugin.id}]`), ...message);
|
|
34
|
+
};
|
|
35
|
+
return memo;
|
|
36
|
+
}, {});
|
|
21
37
|
}
|
|
22
38
|
describe(opts) {
|
|
23
39
|
this.plugin.merge(opts);
|
|
@@ -55,9 +71,12 @@ class PluginAPI {
|
|
|
55
71
|
this.service.pluginMethods[opts.name] = {
|
|
56
72
|
plugin: this.plugin,
|
|
57
73
|
fn: opts.fn ||
|
|
58
|
-
|
|
74
|
+
// 这里不能用 arrow function,this 需指向执行此方法的 PluginAPI
|
|
75
|
+
// 否则 pluginId 会不会,导致不能正确 skip plugin
|
|
76
|
+
function (fn) {
|
|
77
|
+
// @ts-ignore
|
|
59
78
|
this.register(Object.assign({ key: opts.name }, (utils_1.lodash.isPlainObject(fn) ? fn : { fn })));
|
|
60
|
-
}
|
|
79
|
+
},
|
|
61
80
|
};
|
|
62
81
|
}
|
|
63
82
|
registerPresets(source, presets) {
|
|
@@ -82,7 +82,9 @@ export interface IServicePluginAPI {
|
|
|
82
82
|
onCheck: IEvent<null>;
|
|
83
83
|
onStart: IEvent<null>;
|
|
84
84
|
modifyAppData: IModify<typeof Service.prototype.appData, null>;
|
|
85
|
-
modifyConfig: IModify<typeof Service.prototype.config,
|
|
85
|
+
modifyConfig: IModify<typeof Service.prototype.config, {
|
|
86
|
+
paths: Record<string, string>;
|
|
87
|
+
}>;
|
|
86
88
|
modifyDefaultConfig: IModify<typeof Service.prototype.config, null>;
|
|
87
89
|
modifyPaths: IModify<typeof Service.prototype.paths, null>;
|
|
88
90
|
ApplyPluginsType: typeof ApplyPluginsType;
|
package/dist/service/service.js
CHANGED
|
@@ -192,26 +192,27 @@ class Service {
|
|
|
192
192
|
this.configOnChanges[key] = config.onChange || types_1.ConfigChangeType.reload;
|
|
193
193
|
}
|
|
194
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
|
+
}
|
|
195
203
|
this.stage = types_1.ServiceStage.resolveConfig;
|
|
196
204
|
const config = yield this.applyPlugins({
|
|
197
205
|
key: 'modifyConfig',
|
|
198
206
|
initialValue: configManager.getConfig({
|
|
199
207
|
schemas: this.configSchemas,
|
|
200
208
|
}).config,
|
|
209
|
+
args: { paths },
|
|
201
210
|
});
|
|
202
211
|
const defaultConfig = yield this.applyPlugins({
|
|
203
212
|
key: 'modifyDefaultConfig',
|
|
204
213
|
initialValue: this.configDefaults,
|
|
205
214
|
});
|
|
206
215
|
this.config = utils_1.lodash.merge(defaultConfig, config);
|
|
207
|
-
const paths = (0, path_2.getPaths)({
|
|
208
|
-
cwd: this.cwd,
|
|
209
|
-
env: this.env,
|
|
210
|
-
prefix: this.opts.frameworkName || constants_1.DEFAULT_FRAMEWORK_NAME,
|
|
211
|
-
});
|
|
212
|
-
if (this.config.outputPath) {
|
|
213
|
-
paths.absOutputPath = (0, path_1.join)(this.cwd, this.config.outputPath);
|
|
214
|
-
}
|
|
215
216
|
this.paths = yield this.applyPlugins({
|
|
216
217
|
key: 'modifyPaths',
|
|
217
218
|
initialValue: paths,
|
|
@@ -340,7 +341,7 @@ class Service {
|
|
|
340
341
|
if (enableBy === types_1.EnableBy.config && !(key in this.config))
|
|
341
342
|
return false;
|
|
342
343
|
if (typeof enableBy === 'function')
|
|
343
|
-
return enableBy();
|
|
344
|
+
return enableBy({ config: this.config });
|
|
344
345
|
// EnableBy.register
|
|
345
346
|
return true;
|
|
346
347
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/core",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.9",
|
|
4
|
+
"homepage": "https://github.com/umijs/umi-next/tree/master/packages/core#readme",
|
|
5
|
+
"bugs": "https://github.com/umijs/umi-next/issues",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/umijs/umi-next"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
4
11
|
"main": "dist/index.js",
|
|
5
12
|
"types": "dist/index.d.ts",
|
|
6
13
|
"files": [
|
|
@@ -12,22 +19,9 @@
|
|
|
12
19
|
"build:deps": "pnpm esno ../../scripts/bundleDeps.ts",
|
|
13
20
|
"dev": "pnpm build -- --watch"
|
|
14
21
|
},
|
|
15
|
-
"repository": {
|
|
16
|
-
"type": "git",
|
|
17
|
-
"url": "https://github.com/umijs/umi-next"
|
|
18
|
-
},
|
|
19
|
-
"authors": [
|
|
20
|
-
"chencheng <sorrycc@gmail.com> (https://github.com/sorrycc)"
|
|
21
|
-
],
|
|
22
|
-
"license": "MIT",
|
|
23
|
-
"bugs": "https://github.com/umijs/umi-next/issues",
|
|
24
|
-
"homepage": "https://github.com/umijs/umi-next/tree/master/packages/core#readme",
|
|
25
|
-
"publishConfig": {
|
|
26
|
-
"access": "public"
|
|
27
|
-
},
|
|
28
22
|
"dependencies": {
|
|
29
|
-
"@umijs/bundler-utils": "4.0.0-beta.
|
|
30
|
-
"@umijs/utils": "4.0.0-beta.
|
|
23
|
+
"@umijs/bundler-utils": "4.0.0-beta.9",
|
|
24
|
+
"@umijs/utils": "4.0.0-beta.9"
|
|
31
25
|
},
|
|
32
26
|
"devDependencies": {
|
|
33
27
|
"@hapi/joi": "17.1.1",
|
|
@@ -36,6 +30,12 @@
|
|
|
36
30
|
"just-diff": "3.1.1",
|
|
37
31
|
"tapable": "2.2.1"
|
|
38
32
|
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"authors": [
|
|
37
|
+
"chencheng <sorrycc@gmail.com> (https://github.com/sorrycc)"
|
|
38
|
+
],
|
|
39
39
|
"compiledConfig": {
|
|
40
40
|
"deps": [
|
|
41
41
|
"@hapi/joi",
|