@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/plugin.js
CHANGED
|
@@ -1,148 +1,145 @@
|
|
|
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
|
-
const types_1 = require("../types");
|
|
13
|
-
const RE = {
|
|
14
|
-
plugin: /^(@umijs\/|umi-)plugin-/,
|
|
15
|
-
preset: /^(@umijs\/|umi-)preset-/,
|
|
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;
|
|
16
18
|
};
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
finally {
|
|
52
|
-
utils_1.register.restore();
|
|
53
|
-
}
|
|
54
|
-
// use the default member for es modules
|
|
55
|
-
return ret.__esModule ? ret.default : ret;
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
merge(opts) {
|
|
59
|
-
if (opts.key)
|
|
60
|
-
this.key = opts.key;
|
|
61
|
-
if (opts.config)
|
|
62
|
-
this.config = opts.config;
|
|
63
|
-
if (opts.enableBy)
|
|
64
|
-
this.enableBy = opts.enableBy;
|
|
65
|
-
}
|
|
66
|
-
getId(opts) {
|
|
67
|
-
let id;
|
|
68
|
-
if (opts.isPkgEntry) {
|
|
69
|
-
id = opts.pkg.name;
|
|
70
|
-
}
|
|
71
|
-
else if ((0, utils_1.winPath)(this.path).startsWith((0, utils_1.winPath)(this.cwd))) {
|
|
72
|
-
id = `./${(0, utils_1.winPath)((0, path_1.relative)(this.cwd, this.path))}`;
|
|
73
|
-
}
|
|
74
|
-
else if (opts.pkgJSONPath) {
|
|
75
|
-
id = (0, utils_1.winPath)((0, path_1.join)(opts.pkg.name, (0, path_1.relative)((0, path_1.dirname)(opts.pkgJSONPath), this.path)));
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
id = (0, utils_1.winPath)(this.path);
|
|
79
|
-
}
|
|
80
|
-
id = id.replace('@umijs/preset-umi/lib/plugins', '@@');
|
|
81
|
-
id = id.replace(/\.js$/, '');
|
|
82
|
-
return id;
|
|
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
|
+
// plugin.ts
|
|
23
|
+
var plugin_exports = {};
|
|
24
|
+
__export(plugin_exports, {
|
|
25
|
+
Plugin: () => Plugin
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(plugin_exports);
|
|
28
|
+
var import_esbuild = __toESM(require("@umijs/bundler-utils/compiled/esbuild"));
|
|
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_types = require("../types");
|
|
34
|
+
var RE = {
|
|
35
|
+
plugin: /^(@umijs\/|umi-)plugin-/,
|
|
36
|
+
preset: /^(@umijs\/|umi-)preset-/
|
|
37
|
+
};
|
|
38
|
+
var Plugin = class {
|
|
39
|
+
constructor(opts) {
|
|
40
|
+
this.config = {};
|
|
41
|
+
this.time = { hooks: {} };
|
|
42
|
+
this.enableBy = import_types.EnableBy.register;
|
|
43
|
+
this.type = opts.type;
|
|
44
|
+
this.path = (0, import_utils.winPath)(opts.path);
|
|
45
|
+
this.cwd = opts.cwd;
|
|
46
|
+
(0, import_assert.default)((0, import_fs.existsSync)(this.path), `Invalid ${this.type} ${this.path}, it's not exists.`);
|
|
47
|
+
let pkg = null;
|
|
48
|
+
let isPkgEntry = false;
|
|
49
|
+
const pkgJSONPath = import_utils.pkgUp.pkgUpSync({ cwd: this.path });
|
|
50
|
+
if (pkgJSONPath) {
|
|
51
|
+
pkg = require(pkgJSONPath);
|
|
52
|
+
isPkgEntry = (0, import_utils.winPath)((0, import_path.join)((0, import_path.dirname)(pkgJSONPath), pkg.main || "index.js")) === (0, import_utils.winPath)(this.path);
|
|
83
53
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
54
|
+
this.id = this.getId({ pkg, isPkgEntry, pkgJSONPath });
|
|
55
|
+
this.key = this.getKey({ pkg, isPkgEntry });
|
|
56
|
+
this.apply = () => {
|
|
57
|
+
import_utils.register.register({
|
|
58
|
+
implementor: import_esbuild.default,
|
|
59
|
+
exts: [".ts", ".mjs"]
|
|
60
|
+
});
|
|
61
|
+
import_utils.register.clearFiles();
|
|
62
|
+
let ret;
|
|
63
|
+
try {
|
|
64
|
+
ret = require(this.path);
|
|
65
|
+
} catch (e) {
|
|
66
|
+
throw new Error(`Register ${this.type} ${this.path} failed, since ${e.message}`);
|
|
67
|
+
} finally {
|
|
68
|
+
import_utils.register.restore();
|
|
69
|
+
}
|
|
70
|
+
return ret.__esModule ? ret.default : ret;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
merge(opts) {
|
|
74
|
+
if (opts.key)
|
|
75
|
+
this.key = opts.key;
|
|
76
|
+
if (opts.config)
|
|
77
|
+
this.config = opts.config;
|
|
78
|
+
if (opts.enableBy)
|
|
79
|
+
this.enableBy = opts.enableBy;
|
|
80
|
+
}
|
|
81
|
+
getId(opts) {
|
|
82
|
+
let id;
|
|
83
|
+
if (opts.isPkgEntry) {
|
|
84
|
+
id = opts.pkg.name;
|
|
85
|
+
} else if ((0, import_utils.winPath)(this.path).startsWith((0, import_utils.winPath)(this.cwd))) {
|
|
86
|
+
id = `./${(0, import_utils.winPath)((0, import_path.relative)(this.cwd, this.path))}`;
|
|
87
|
+
} else if (opts.pkgJSONPath) {
|
|
88
|
+
id = (0, import_utils.winPath)((0, import_path.join)(opts.pkg.name, (0, import_path.relative)((0, import_path.dirname)(opts.pkgJSONPath), this.path)));
|
|
89
|
+
} else {
|
|
90
|
+
id = (0, import_utils.winPath)(this.path);
|
|
97
91
|
}
|
|
98
|
-
|
|
99
|
-
|
|
92
|
+
id = id.replace("@umijs/preset-umi/lib/plugins", "@@");
|
|
93
|
+
id = id.replace(/\.js$/, "");
|
|
94
|
+
return id;
|
|
95
|
+
}
|
|
96
|
+
getKey(opts) {
|
|
97
|
+
function nameToKey(name) {
|
|
98
|
+
return name.split(".").map((part) => import_utils.lodash.camelCase(part)).join(".");
|
|
100
99
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
100
|
+
return nameToKey(opts.isPkgEntry ? Plugin.stripNoneUmiScope(opts.pkg.name).replace(RE[this.type], "") : (0, import_path.basename)(this.path, (0, import_path.extname)(this.path)));
|
|
101
|
+
}
|
|
102
|
+
static isPluginOrPreset(type, name) {
|
|
103
|
+
return RE[type].test(Plugin.stripNoneUmiScope(name));
|
|
104
|
+
}
|
|
105
|
+
static stripNoneUmiScope(name) {
|
|
106
|
+
if (name.charAt(0) === "@" && !name.startsWith("@umijs/")) {
|
|
107
|
+
name = name.split("/")[1];
|
|
106
108
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
try {
|
|
127
|
-
resolved = utils_1.resolve.sync(path, {
|
|
128
|
-
basedir: opts.cwd,
|
|
129
|
-
extensions: ['.tsx', '.ts', '.mjs', '.jsx', '.js'],
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
catch (_e) {
|
|
133
|
-
throw new Error(`Invalid plugin ${path}, can not be resolved.`);
|
|
134
|
-
}
|
|
135
|
-
return new Plugin({
|
|
136
|
-
path: resolved,
|
|
137
|
-
type,
|
|
138
|
-
cwd: opts.cwd,
|
|
139
|
-
});
|
|
140
|
-
});
|
|
109
|
+
return name;
|
|
110
|
+
}
|
|
111
|
+
static getPluginsAndPresets(opts) {
|
|
112
|
+
function get(type) {
|
|
113
|
+
const types = `${type}s`;
|
|
114
|
+
return [
|
|
115
|
+
...opts[types] || [],
|
|
116
|
+
...(process.env[`${opts.prefix}_${types}`.toUpperCase()] || "").split(",").filter(Boolean),
|
|
117
|
+
...opts.userConfig[types] || []
|
|
118
|
+
].map((path) => {
|
|
119
|
+
(0, import_assert.default)(typeof path === "string", `Invalid plugin ${path}, it must be string.`);
|
|
120
|
+
let resolved;
|
|
121
|
+
try {
|
|
122
|
+
resolved = import_utils.resolve.sync(path, {
|
|
123
|
+
basedir: opts.cwd,
|
|
124
|
+
extensions: [".tsx", ".ts", ".mjs", ".jsx", ".js"]
|
|
125
|
+
});
|
|
126
|
+
} catch (_e) {
|
|
127
|
+
throw new Error(`Invalid plugin ${path}, can not be resolved.`);
|
|
141
128
|
}
|
|
142
|
-
return {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
129
|
+
return new Plugin({
|
|
130
|
+
path: resolved,
|
|
131
|
+
type,
|
|
132
|
+
cwd: opts.cwd
|
|
133
|
+
});
|
|
134
|
+
});
|
|
146
135
|
}
|
|
147
|
-
|
|
148
|
-
|
|
136
|
+
return {
|
|
137
|
+
presets: get("preset"),
|
|
138
|
+
plugins: get("plugin")
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
143
|
+
0 && (module.exports = {
|
|
144
|
+
Plugin
|
|
145
|
+
});
|
|
File without changes
|
|
@@ -1,167 +1,190 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __export = (target, all) => {
|
|
25
|
+
for (var name in all)
|
|
26
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
27
|
+
};
|
|
28
|
+
var __copyProps = (to, from, except, desc) => {
|
|
29
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
30
|
+
for (let key of __getOwnPropNames(from))
|
|
31
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
32
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
33
|
+
}
|
|
34
|
+
return to;
|
|
4
35
|
};
|
|
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
|
-
|
|
36
|
+
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));
|
|
37
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
|
+
|
|
39
|
+
// pluginAPI.ts
|
|
40
|
+
var pluginAPI_exports = {};
|
|
41
|
+
__export(pluginAPI_exports, {
|
|
42
|
+
PluginAPI: () => PluginAPI
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(pluginAPI_exports);
|
|
45
|
+
var import_utils = require("@umijs/utils");
|
|
46
|
+
var import_assert = __toESM(require("assert"));
|
|
47
|
+
var import_types = require("../types");
|
|
48
|
+
var import_command = require("./command");
|
|
49
|
+
var import_generator = require("./generator");
|
|
50
|
+
var import_hook = require("./hook");
|
|
51
|
+
var import_plugin = require("./plugin");
|
|
52
|
+
var import_utils2 = require("./utils");
|
|
53
|
+
var resolveConfigModes = ["strict", "loose"];
|
|
54
|
+
var PluginAPI = class {
|
|
55
|
+
constructor(opts) {
|
|
56
|
+
this.service = opts.service;
|
|
57
|
+
this.plugin = opts.plugin;
|
|
58
|
+
const loggerKeys = [
|
|
59
|
+
"wait",
|
|
60
|
+
"error",
|
|
61
|
+
"warn",
|
|
62
|
+
"ready",
|
|
63
|
+
"info",
|
|
64
|
+
"event",
|
|
65
|
+
"debug"
|
|
66
|
+
];
|
|
67
|
+
this.logger = loggerKeys.reduce((memo, key) => {
|
|
68
|
+
memo[key] = (...message) => {
|
|
69
|
+
import_utils.logger[key](import_utils.chalk.green(`[plugin: ${this.plugin.id}]`), ...message);
|
|
70
|
+
};
|
|
71
|
+
return memo;
|
|
72
|
+
}, {});
|
|
73
|
+
}
|
|
74
|
+
describe(opts) {
|
|
75
|
+
var _a;
|
|
76
|
+
if (opts.enableBy === import_types.EnableBy.config && ((_a = opts.config) == null ? void 0 : _a.default)) {
|
|
77
|
+
throw new Error(`[plugin: ${this.plugin.id}] The config.default is not allowed when enableBy is EnableBy.config.`);
|
|
38
78
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
79
|
+
this.plugin.merge(opts);
|
|
80
|
+
}
|
|
81
|
+
registerCommand(opts) {
|
|
82
|
+
const { alias } = opts;
|
|
83
|
+
delete opts.alias;
|
|
84
|
+
const registerCommand = (commandOpts) => {
|
|
85
|
+
var _a;
|
|
86
|
+
const { name, configResolveMode } = commandOpts;
|
|
87
|
+
(0, import_assert.default)(!configResolveMode || resolveConfigModes.indexOf(configResolveMode) >= 0, `configResolveMode must be one of ${resolveConfigModes.join(",")}, but got ${configResolveMode}`);
|
|
88
|
+
(0, import_assert.default)(!this.service.commands[name], `api.registerCommand() failed, the command ${name} is exists from ${(_a = this.service.commands[name]) == null ? void 0 : _a.plugin.id}.`);
|
|
89
|
+
this.service.commands[name] = new import_command.Command(__spreadProps(__spreadValues({}, commandOpts), {
|
|
90
|
+
plugin: this.plugin
|
|
91
|
+
}));
|
|
92
|
+
};
|
|
93
|
+
registerCommand(opts);
|
|
94
|
+
if (alias) {
|
|
95
|
+
const aliases = (0, import_utils2.makeArray)(alias);
|
|
96
|
+
aliases.forEach((alias2) => {
|
|
97
|
+
registerCommand(__spreadProps(__spreadValues({}, opts), { name: alias2 }));
|
|
98
|
+
});
|
|
46
99
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
100
|
+
}
|
|
101
|
+
registerGenerator(opts) {
|
|
102
|
+
var _a;
|
|
103
|
+
const { key } = opts;
|
|
104
|
+
(0, import_assert.default)(!this.service.generators[key], `api.registerGenerator() failed, the generator ${key} is exists from ${(_a = this.service.generators[key]) == null ? void 0 : _a.plugin.id}.`);
|
|
105
|
+
this.service.generators[key] = (0, import_generator.makeGenerator)(__spreadProps(__spreadValues({}, opts), {
|
|
106
|
+
plugin: this.plugin
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
register(opts) {
|
|
110
|
+
var _a, _b;
|
|
111
|
+
(0, import_assert.default)(this.service.stage <= import_types.ServiceStage.initPlugins, "api.register() should not be called after plugin register stage.");
|
|
112
|
+
(_a = this.service.hooks)[_b = opts.key] || (_a[_b] = []);
|
|
113
|
+
this.service.hooks[opts.key].push(new import_hook.Hook(__spreadProps(__spreadValues({}, opts), { plugin: this.plugin })));
|
|
114
|
+
}
|
|
115
|
+
registerMethod(opts) {
|
|
116
|
+
(0, import_assert.default)(!this.service.pluginMethods[opts.name], `api.registerMethod() failed, method ${opts.name} is already exist.`);
|
|
117
|
+
this.service.pluginMethods[opts.name] = {
|
|
118
|
+
plugin: this.plugin,
|
|
119
|
+
fn: opts.fn || function(fn) {
|
|
120
|
+
this.register(__spreadValues({
|
|
121
|
+
key: opts.name
|
|
122
|
+
}, import_utils.lodash.isPlainObject(fn) ? fn : { fn }));
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
registerPresets(source, presets) {
|
|
127
|
+
(0, import_assert.default)(this.service.stage === import_types.ServiceStage.initPresets, `api.registerPresets() failed, it should only used in presets.`);
|
|
128
|
+
source.splice(0, 0, ...presets.map((preset) => {
|
|
129
|
+
return new import_plugin.Plugin({
|
|
130
|
+
path: preset,
|
|
131
|
+
cwd: this.service.cwd,
|
|
132
|
+
type: import_types.PluginType.preset
|
|
133
|
+
});
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
136
|
+
registerPlugins(source, plugins) {
|
|
137
|
+
(0, import_assert.default)(this.service.stage === import_types.ServiceStage.initPresets || this.service.stage === import_types.ServiceStage.initPlugins, `api.registerPlugins() failed, it should only be used in registering stage.`);
|
|
138
|
+
const mappedPlugins = plugins.map((plugin) => {
|
|
139
|
+
if (import_utils.lodash.isPlainObject(plugin)) {
|
|
140
|
+
(0, import_assert.default)(plugin.id && plugin.key, `Invalid plugin object, id and key must supplied.`);
|
|
141
|
+
plugin.type = import_types.PluginType.plugin;
|
|
142
|
+
plugin.enableBy = plugin.enableBy || import_types.EnableBy.register;
|
|
143
|
+
plugin.apply = plugin.apply || (() => () => {
|
|
76
144
|
});
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
(0, assert_1.default)(!this.service.pluginMethods[opts.name], `api.registerMethod() failed, method ${opts.name} is already exist.`);
|
|
86
|
-
this.service.pluginMethods[opts.name] = {
|
|
87
|
-
plugin: this.plugin,
|
|
88
|
-
fn: opts.fn ||
|
|
89
|
-
// 这里不能用 arrow function,this 需指向执行此方法的 PluginAPI
|
|
90
|
-
// 否则 pluginId 会不会,导致不能正确 skip plugin
|
|
91
|
-
function (fn) {
|
|
92
|
-
// @ts-ignore
|
|
93
|
-
this.register({
|
|
94
|
-
key: opts.name,
|
|
95
|
-
...(utils_1.lodash.isPlainObject(fn) ? fn : { fn }),
|
|
96
|
-
});
|
|
97
|
-
},
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
registerPresets(source, presets) {
|
|
101
|
-
(0, assert_1.default)(this.service.stage === types_1.ServiceStage.initPresets, `api.registerPresets() failed, it should only used in presets.`);
|
|
102
|
-
source.splice(0, 0, ...presets.map((preset) => {
|
|
103
|
-
return new plugin_1.Plugin({
|
|
104
|
-
path: preset,
|
|
105
|
-
cwd: this.service.cwd,
|
|
106
|
-
type: types_1.PluginType.preset,
|
|
107
|
-
});
|
|
108
|
-
}));
|
|
109
|
-
}
|
|
110
|
-
registerPlugins(source, plugins) {
|
|
111
|
-
(0, assert_1.default)(this.service.stage === types_1.ServiceStage.initPresets ||
|
|
112
|
-
this.service.stage === types_1.ServiceStage.initPlugins, `api.registerPlugins() failed, it should only be used in registering stage.`);
|
|
113
|
-
const mappedPlugins = plugins.map((plugin) => {
|
|
114
|
-
if (utils_1.lodash.isPlainObject(plugin)) {
|
|
115
|
-
(0, assert_1.default)(plugin.id && plugin.key, `Invalid plugin object, id and key must supplied.`);
|
|
116
|
-
plugin.type = types_1.PluginType.plugin;
|
|
117
|
-
plugin.enableBy = plugin.enableBy || types_1.EnableBy.register;
|
|
118
|
-
plugin.apply = plugin.apply || (() => () => { });
|
|
119
|
-
plugin.config = plugin.config || {};
|
|
120
|
-
plugin.time = { hooks: {} };
|
|
121
|
-
return plugin;
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
return new plugin_1.Plugin({
|
|
125
|
-
path: plugin,
|
|
126
|
-
cwd: this.service.cwd,
|
|
127
|
-
type: types_1.PluginType.plugin,
|
|
128
|
-
});
|
|
129
|
-
}
|
|
145
|
+
plugin.config = plugin.config || {};
|
|
146
|
+
plugin.time = { hooks: {} };
|
|
147
|
+
return plugin;
|
|
148
|
+
} else {
|
|
149
|
+
return new import_plugin.Plugin({
|
|
150
|
+
path: plugin,
|
|
151
|
+
cwd: this.service.cwd,
|
|
152
|
+
type: import_types.PluginType.plugin
|
|
130
153
|
});
|
|
131
|
-
|
|
132
|
-
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
if (this.service.stage === import_types.ServiceStage.initPresets) {
|
|
157
|
+
source.push(...mappedPlugins);
|
|
158
|
+
} else {
|
|
159
|
+
source.splice(0, 0, ...mappedPlugins);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
skipPlugins(keys) {
|
|
163
|
+
keys.forEach((key) => {
|
|
164
|
+
(0, import_assert.default)(!(this.plugin.key === key), `plugin ${key} can't skip itself!`);
|
|
165
|
+
(0, import_assert.default)(this.service.keyToPluginMap[key], `key: ${key} is not be registered by any plugin. You can't skip it!`);
|
|
166
|
+
this.service.skipPluginIds.add(this.service.keyToPluginMap[key].id);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
static proxyPluginAPI(opts) {
|
|
170
|
+
return new Proxy(opts.pluginAPI, {
|
|
171
|
+
get: (target, prop) => {
|
|
172
|
+
if (opts.service.pluginMethods[prop]) {
|
|
173
|
+
return opts.service.pluginMethods[prop].fn;
|
|
133
174
|
}
|
|
134
|
-
|
|
135
|
-
|
|
175
|
+
if (opts.serviceProps.includes(prop)) {
|
|
176
|
+
const serviceProp = opts.service[prop];
|
|
177
|
+
return typeof serviceProp === "function" ? serviceProp.bind(opts.service) : serviceProp;
|
|
136
178
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
return opts.service.pluginMethods[prop].fn;
|
|
150
|
-
}
|
|
151
|
-
if (opts.serviceProps.includes(prop)) {
|
|
152
|
-
// @ts-ignore
|
|
153
|
-
const serviceProp = opts.service[prop];
|
|
154
|
-
return typeof serviceProp === 'function'
|
|
155
|
-
? serviceProp.bind(opts.service)
|
|
156
|
-
: serviceProp;
|
|
157
|
-
}
|
|
158
|
-
if (prop in opts.staticProps) {
|
|
159
|
-
return opts.staticProps[prop];
|
|
160
|
-
}
|
|
161
|
-
// @ts-ignore
|
|
162
|
-
return target[prop];
|
|
163
|
-
},
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
exports.PluginAPI = PluginAPI;
|
|
179
|
+
if (prop in opts.staticProps) {
|
|
180
|
+
return opts.staticProps[prop];
|
|
181
|
+
}
|
|
182
|
+
return target[prop];
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
188
|
+
0 && (module.exports = {
|
|
189
|
+
PluginAPI
|
|
190
|
+
});
|
|
File without changes
|