@umijs/core 4.0.0-rc.2 → 4.0.0-rc.20
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/index.d.ts +1 -1
- package/dist/index.js +5 -1
- package/dist/route/defineRoutes.js +6 -3
- package/dist/route/route.js +5 -1
- package/dist/route/routesConfig.d.ts +1 -0
- package/dist/route/routesConfig.js +54 -15
- package/dist/route/routesConvention.js +2 -2
- package/dist/route/utils.js +1 -1
- package/dist/service/command.d.ts +3 -0
- package/dist/service/command.js +1 -0
- package/dist/service/generatePlugin.js +59 -67
- package/dist/service/generator.d.ts +40 -29
- package/dist/service/generator.js +6 -12
- package/dist/service/path.d.ts +2 -0
- package/dist/service/path.js +2 -0
- package/dist/service/plugin.d.ts +4 -0
- package/dist/service/plugin.js +4 -3
- package/dist/service/pluginAPI.d.ts +6 -3
- package/dist/service/pluginAPI.js +31 -10
- package/dist/service/service.d.ts +16 -1
- package/dist/service/service.js +338 -290
- package/dist/types.d.ts +2 -0
- package/package.json +9 -10
- package/compiled/tapable/LICENSE +0 -21
- package/compiled/tapable/index.js +0 -1
- package/compiled/tapable/package.json +0 -1
- package/compiled/tapable/tapable.d.ts +0 -116
|
@@ -12,6 +12,7 @@ const generator_1 = require("./generator");
|
|
|
12
12
|
const hook_1 = require("./hook");
|
|
13
13
|
const plugin_1 = require("./plugin");
|
|
14
14
|
const utils_2 = require("./utils");
|
|
15
|
+
const resolveConfigModes = ['strict', 'loose'];
|
|
15
16
|
class PluginAPI {
|
|
16
17
|
constructor(opts) {
|
|
17
18
|
this.service = opts.service;
|
|
@@ -36,6 +37,11 @@ class PluginAPI {
|
|
|
36
37
|
}, {});
|
|
37
38
|
}
|
|
38
39
|
describe(opts) {
|
|
40
|
+
var _a;
|
|
41
|
+
// default 值 + 配置开启冲突,会导致就算用户没有配 key,插件也会生效
|
|
42
|
+
if (opts.enableBy === types_1.EnableBy.config && ((_a = opts.config) === null || _a === void 0 ? void 0 : _a.default)) {
|
|
43
|
+
throw new Error(`[plugin: ${this.plugin.id}] The config.default is not allowed when enableBy is EnableBy.config.`);
|
|
44
|
+
}
|
|
39
45
|
this.plugin.merge(opts);
|
|
40
46
|
}
|
|
41
47
|
registerCommand(opts) {
|
|
@@ -43,15 +49,20 @@ class PluginAPI {
|
|
|
43
49
|
delete opts.alias;
|
|
44
50
|
const registerCommand = (commandOpts) => {
|
|
45
51
|
var _a;
|
|
46
|
-
const { name } = commandOpts;
|
|
52
|
+
const { name, configResolveMode } = commandOpts;
|
|
53
|
+
(0, assert_1.default)(!configResolveMode ||
|
|
54
|
+
resolveConfigModes.indexOf(configResolveMode) >= 0, `configResolveMode must be one of ${resolveConfigModes.join(',')}, but got ${configResolveMode}`);
|
|
47
55
|
(0, assert_1.default)(!this.service.commands[name], `api.registerCommand() failed, the command ${name} is exists from ${(_a = this.service.commands[name]) === null || _a === void 0 ? void 0 : _a.plugin.id}.`);
|
|
48
|
-
this.service.commands[name] = new command_1.Command(
|
|
56
|
+
this.service.commands[name] = new command_1.Command({
|
|
57
|
+
...commandOpts,
|
|
58
|
+
plugin: this.plugin,
|
|
59
|
+
});
|
|
49
60
|
};
|
|
50
61
|
registerCommand(opts);
|
|
51
62
|
if (alias) {
|
|
52
63
|
const aliases = (0, utils_2.makeArray)(alias);
|
|
53
64
|
aliases.forEach((alias) => {
|
|
54
|
-
registerCommand(
|
|
65
|
+
registerCommand({ ...opts, name: alias });
|
|
55
66
|
});
|
|
56
67
|
}
|
|
57
68
|
}
|
|
@@ -59,12 +70,16 @@ class PluginAPI {
|
|
|
59
70
|
var _a;
|
|
60
71
|
const { key } = opts;
|
|
61
72
|
(0, assert_1.default)(!this.service.generators[key], `api.registerGenerator() failed, the generator ${key} is exists from ${(_a = this.service.generators[key]) === null || _a === void 0 ? void 0 : _a.plugin.id}.`);
|
|
62
|
-
this.service.generators[key] =
|
|
73
|
+
this.service.generators[key] = (0, generator_1.makeGenerator)({
|
|
74
|
+
...opts,
|
|
75
|
+
plugin: this.plugin,
|
|
76
|
+
});
|
|
63
77
|
}
|
|
64
78
|
register(opts) {
|
|
65
79
|
var _a, _b;
|
|
80
|
+
(0, assert_1.default)(this.service.stage <= types_1.ServiceStage.initPlugins, 'api.register() should not be called after plugin register stage.');
|
|
66
81
|
(_a = this.service.hooks)[_b = opts.key] || (_a[_b] = []);
|
|
67
|
-
this.service.hooks[opts.key].push(new hook_1.Hook(
|
|
82
|
+
this.service.hooks[opts.key].push(new hook_1.Hook({ ...opts, plugin: this.plugin }));
|
|
68
83
|
}
|
|
69
84
|
registerMethod(opts) {
|
|
70
85
|
(0, assert_1.default)(!this.service.pluginMethods[opts.name], `api.registerMethod() failed, method ${opts.name} is already exist.`);
|
|
@@ -75,7 +90,10 @@ class PluginAPI {
|
|
|
75
90
|
// 否则 pluginId 会不会,导致不能正确 skip plugin
|
|
76
91
|
function (fn) {
|
|
77
92
|
// @ts-ignore
|
|
78
|
-
this.register(
|
|
93
|
+
this.register({
|
|
94
|
+
key: opts.name,
|
|
95
|
+
...(utils_1.lodash.isPlainObject(fn) ? fn : { fn }),
|
|
96
|
+
});
|
|
79
97
|
},
|
|
80
98
|
};
|
|
81
99
|
}
|
|
@@ -85,7 +103,7 @@ class PluginAPI {
|
|
|
85
103
|
return new plugin_1.Plugin({
|
|
86
104
|
path: preset,
|
|
87
105
|
cwd: this.service.cwd,
|
|
88
|
-
type: types_1.PluginType.
|
|
106
|
+
type: types_1.PluginType.preset,
|
|
89
107
|
});
|
|
90
108
|
}));
|
|
91
109
|
}
|
|
@@ -99,6 +117,7 @@ class PluginAPI {
|
|
|
99
117
|
plugin.enableBy = plugin.enableBy || types_1.EnableBy.register;
|
|
100
118
|
plugin.apply = plugin.apply || (() => () => { });
|
|
101
119
|
plugin.config = plugin.config || {};
|
|
120
|
+
plugin.time = { hooks: {} };
|
|
102
121
|
return plugin;
|
|
103
122
|
}
|
|
104
123
|
else {
|
|
@@ -116,9 +135,11 @@ class PluginAPI {
|
|
|
116
135
|
source.splice(0, 0, ...mappedPlugins);
|
|
117
136
|
}
|
|
118
137
|
}
|
|
119
|
-
skipPlugins(
|
|
120
|
-
|
|
121
|
-
this.
|
|
138
|
+
skipPlugins(keys) {
|
|
139
|
+
keys.forEach((key) => {
|
|
140
|
+
(0, assert_1.default)(!(this.plugin.key === key), `plugin ${key} can't skip itself!`);
|
|
141
|
+
(0, assert_1.default)(this.service.keyToPluginMap[key], `key: ${key} is not be registered by any plugin. You can't skip it!`);
|
|
142
|
+
this.service.skipPluginIds.add(this.service.keyToPluginMap[key].id);
|
|
122
143
|
});
|
|
123
144
|
}
|
|
124
145
|
static proxyPluginAPI(opts) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { yParser } from '@umijs/utils';
|
|
2
2
|
import { Config } from '../config/config';
|
|
3
|
-
import { ApplyPluginsType, ConfigChangeType, EnableBy, Env, IEvent, IModify, ServiceStage } from '../types';
|
|
3
|
+
import { ApplyPluginsType, ConfigChangeType, EnableBy, Env, IEvent, IFrameworkType, IModify, ServiceStage } from '../types';
|
|
4
4
|
import { Command } from './command';
|
|
5
5
|
import { Generator } from './generator';
|
|
6
6
|
import { Hook } from './hook';
|
|
@@ -22,6 +22,7 @@ export declare class Service {
|
|
|
22
22
|
subpaths: string[];
|
|
23
23
|
external?: boolean;
|
|
24
24
|
}>;
|
|
25
|
+
framework?: IFrameworkType;
|
|
25
26
|
[key: string]: any;
|
|
26
27
|
};
|
|
27
28
|
args: yParser.Arguments;
|
|
@@ -39,6 +40,7 @@ export declare class Service {
|
|
|
39
40
|
cwd?: string;
|
|
40
41
|
absSrcPath?: string;
|
|
41
42
|
absPagesPath?: string;
|
|
43
|
+
absApiRoutesPath?: string;
|
|
42
44
|
absTmpPath?: string;
|
|
43
45
|
absNodeModulesPath?: string;
|
|
44
46
|
absOutputPath?: string;
|
|
@@ -62,6 +64,13 @@ export declare class Service {
|
|
|
62
64
|
};
|
|
63
65
|
pkgPath: string;
|
|
64
66
|
constructor(opts: IOpts);
|
|
67
|
+
applyPlugins<T>(opts: {
|
|
68
|
+
key: string;
|
|
69
|
+
type?: ApplyPluginsType.event;
|
|
70
|
+
initialValue?: any;
|
|
71
|
+
args?: any;
|
|
72
|
+
sync: true;
|
|
73
|
+
}): typeof opts.initialValue | T;
|
|
65
74
|
applyPlugins<T>(opts: {
|
|
66
75
|
key: string;
|
|
67
76
|
type?: ApplyPluginsType;
|
|
@@ -72,6 +81,11 @@ export declare class Service {
|
|
|
72
81
|
name: string;
|
|
73
82
|
args?: any;
|
|
74
83
|
}): Promise<void>;
|
|
84
|
+
resolveConfig(): Promise<{
|
|
85
|
+
config: any;
|
|
86
|
+
defaultConfig: any;
|
|
87
|
+
}>;
|
|
88
|
+
_baconPlugins(): void;
|
|
75
89
|
initPreset(opts: {
|
|
76
90
|
preset: Plugin;
|
|
77
91
|
presets: Plugin[];
|
|
@@ -110,6 +124,7 @@ export interface IServicePluginAPI {
|
|
|
110
124
|
ConfigChangeType: typeof ConfigChangeType;
|
|
111
125
|
EnableBy: typeof EnableBy;
|
|
112
126
|
ServiceStage: typeof ServiceStage;
|
|
127
|
+
registerPresets: (presets: any[]) => void;
|
|
113
128
|
registerPlugins: (plugins: (Plugin | {})[]) => void;
|
|
114
129
|
}
|
|
115
130
|
export {};
|