umi 4.0.6 → 4.0.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/client/client/plugin.js +263 -190
- package/client/client/utils.js +18 -11
- package/dist/cli/cli.js +66 -46
- package/dist/cli/dev.js +42 -23
- package/dist/cli/fork.js +59 -37
- package/dist/cli/forkedDev.js +34 -41
- package/dist/cli/node.js +48 -24
- package/dist/constants.js +42 -11
- package/dist/defineConfig.js +29 -5
- package/dist/defineMock.js +29 -5
- package/dist/index.js +36 -23
- package/dist/pluginUtils.js +38 -37
- package/dist/service/cwd.js +35 -11
- package/dist/service/requireHook.d.ts +1 -0
- package/dist/service/requireHook.js +14 -0
- package/dist/service/service.js +78 -37
- package/dist/test.js +69 -59
- package/package.json +13 -14
- package/dist/cli/printHelp.d.ts +0 -1
- package/dist/cli/printHelp.js +0 -10
- package/dist/client/plugin.d.ts +0 -34
- package/dist/client/plugin.js +0 -124
- package/dist/client/utils.d.ts +0 -6
- package/dist/client/utils.js +0 -20
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// requireHook.ts
|
|
2
|
+
var import_path = require("path");
|
|
3
|
+
var hookPropertyMap = /* @__PURE__ */ new Map([
|
|
4
|
+
["umi", (0, import_path.join)(__dirname, "../index.js")],
|
|
5
|
+
["umi/plugin-utils", (0, import_path.join)(__dirname, "../../plugin-utils.js")]
|
|
6
|
+
]);
|
|
7
|
+
var mod = require("module");
|
|
8
|
+
var resolveFilename = mod._resolveFilename;
|
|
9
|
+
mod._resolveFilename = function(request, parent, isMain, options) {
|
|
10
|
+
const hookResolved = hookPropertyMap.get(request);
|
|
11
|
+
if (hookResolved)
|
|
12
|
+
request = hookResolved;
|
|
13
|
+
return resolveFilename.call(mod, request, parent, isMain, options);
|
|
14
|
+
};
|
package/dist/service/service.js
CHANGED
|
@@ -1,39 +1,80 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
plugins: [
|
|
21
|
-
(0, fs_1.existsSync)((0, path_1.join)(cwd, 'plugin.ts')) && (0, path_1.join)(cwd, 'plugin.ts'),
|
|
22
|
-
(0, fs_1.existsSync)((0, path_1.join)(cwd, 'plugin.js')) && (0, path_1.join)(cwd, 'plugin.js'),
|
|
23
|
-
].filter(Boolean),
|
|
24
|
-
});
|
|
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]);
|
|
25
20
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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;
|
|
35
|
+
};
|
|
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
|
+
// service.ts
|
|
40
|
+
var service_exports = {};
|
|
41
|
+
__export(service_exports, {
|
|
42
|
+
Service: () => Service
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(service_exports);
|
|
45
|
+
var import_core = require("@umijs/core");
|
|
46
|
+
var import_fs = require("fs");
|
|
47
|
+
var import_path = require("path");
|
|
48
|
+
var import_constants = require("../constants");
|
|
49
|
+
var import_cwd = require("./cwd");
|
|
50
|
+
var Service = class extends import_core.Service {
|
|
51
|
+
constructor(opts) {
|
|
52
|
+
process.env.UMI_DIR = (0, import_path.dirname)(require.resolve("../../package"));
|
|
53
|
+
const cwd = (0, import_cwd.getCwd)();
|
|
54
|
+
require("./requireHook");
|
|
55
|
+
super(__spreadProps(__spreadValues({}, opts), {
|
|
56
|
+
env: process.env.NODE_ENV,
|
|
57
|
+
cwd,
|
|
58
|
+
defaultConfigFiles: import_constants.DEFAULT_CONFIG_FILES,
|
|
59
|
+
frameworkName: import_constants.FRAMEWORK_NAME,
|
|
60
|
+
presets: [require.resolve("@umijs/preset-umi"), ...(opts == null ? void 0 : opts.presets) || []],
|
|
61
|
+
plugins: [
|
|
62
|
+
(0, import_fs.existsSync)((0, import_path.join)(cwd, "plugin.ts")) && (0, import_path.join)(cwd, "plugin.ts"),
|
|
63
|
+
(0, import_fs.existsSync)((0, import_path.join)(cwd, "plugin.js")) && (0, import_path.join)(cwd, "plugin.js")
|
|
64
|
+
].filter(Boolean)
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
async run2(opts) {
|
|
68
|
+
let name = opts.name;
|
|
69
|
+
if ((opts == null ? void 0 : opts.args.version) || name === "v") {
|
|
70
|
+
name = "version";
|
|
71
|
+
} else if ((opts == null ? void 0 : opts.args.help) || !name || name === "h") {
|
|
72
|
+
name = "help";
|
|
37
73
|
}
|
|
38
|
-
}
|
|
39
|
-
|
|
74
|
+
return await this.run(__spreadProps(__spreadValues({}, opts), { name }));
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
78
|
+
0 && (module.exports = {
|
|
79
|
+
Service
|
|
80
|
+
});
|
package/dist/test.js
CHANGED
|
@@ -1,67 +1,77 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
15
16
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// test.ts
|
|
21
|
+
var test_exports = {};
|
|
22
|
+
__export(test_exports, {
|
|
23
|
+
configUmiAlias: () => configUmiAlias,
|
|
24
|
+
getAliasPathWithKey: () => getAliasPathWithKey,
|
|
25
|
+
getUmiAlias: () => getUmiAlias
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(test_exports);
|
|
28
|
+
var import_fs = require("fs");
|
|
29
|
+
var import_service = require("./service/service");
|
|
30
|
+
__reExport(test_exports, require("@umijs/test"), module.exports);
|
|
21
31
|
function getAliasPathWithKey(alias, key) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
32
|
+
if (alias[key]) {
|
|
33
|
+
return getAliasPathWithKey(alias, alias[key]);
|
|
34
|
+
}
|
|
35
|
+
const aliasKeys = Object.keys(alias);
|
|
36
|
+
const keyStartedWith = aliasKeys.find((k) => !k.endsWith("$") && key.startsWith(`${k}/`));
|
|
37
|
+
if (keyStartedWith) {
|
|
38
|
+
const realPath = alias[keyStartedWith];
|
|
39
|
+
const newKey = realPath + key.slice(keyStartedWith.length);
|
|
40
|
+
return getAliasPathWithKey(alias, newKey);
|
|
41
|
+
} else {
|
|
42
|
+
return key;
|
|
43
|
+
}
|
|
35
44
|
}
|
|
36
|
-
|
|
37
|
-
let service;
|
|
45
|
+
var service;
|
|
38
46
|
async function getUmiAlias() {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
if (!service) {
|
|
48
|
+
service = new import_service.Service();
|
|
49
|
+
await service.run2({
|
|
50
|
+
name: "setup",
|
|
51
|
+
args: { quiet: true }
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return service.config.alias;
|
|
47
55
|
}
|
|
48
|
-
exports.getUmiAlias = getUmiAlias;
|
|
49
56
|
async function configUmiAlias(config) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
else {
|
|
62
|
-
config.moduleNameMapper[`^${key}$`] = aliasPath;
|
|
63
|
-
}
|
|
57
|
+
config.moduleNameMapper || (config.moduleNameMapper = {});
|
|
58
|
+
const alias = await getUmiAlias();
|
|
59
|
+
for (const key of Object.keys(alias)) {
|
|
60
|
+
const aliasPath = getAliasPathWithKey(alias, key);
|
|
61
|
+
if (key.endsWith("$")) {
|
|
62
|
+
config.moduleNameMapper[`^${key}`] = aliasPath;
|
|
63
|
+
} else if ((0, import_fs.existsSync)(aliasPath) && (0, import_fs.statSync)(aliasPath).isDirectory()) {
|
|
64
|
+
config.moduleNameMapper[`^${key}/(.*)$`] = `${aliasPath}/$1`;
|
|
65
|
+
config.moduleNameMapper[`^${key}$`] = aliasPath;
|
|
66
|
+
} else {
|
|
67
|
+
config.moduleNameMapper[`^${key}$`] = aliasPath;
|
|
64
68
|
}
|
|
65
|
-
|
|
69
|
+
}
|
|
70
|
+
return config;
|
|
66
71
|
}
|
|
67
|
-
|
|
72
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
73
|
+
0 && (module.exports = {
|
|
74
|
+
configUmiAlias,
|
|
75
|
+
getAliasPathWithKey,
|
|
76
|
+
getUmiAlias
|
|
77
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "umi",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.9",
|
|
4
4
|
"description": "umi",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi/tree/master/packages/umi#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi/issues",
|
|
@@ -30,23 +30,22 @@
|
|
|
30
30
|
"stylelint.js"
|
|
31
31
|
],
|
|
32
32
|
"scripts": {
|
|
33
|
-
"build": "
|
|
34
|
-
"build:client": "pnpm tsc --project ./tsconfig.client.json",
|
|
33
|
+
"build": "umi-scripts father build",
|
|
35
34
|
"build:deps": "umi-scripts bundleDeps",
|
|
36
|
-
"dev": "
|
|
37
|
-
"dev:client": "pnpm build:client -- --watch",
|
|
35
|
+
"dev": "umi-scripts father dev",
|
|
38
36
|
"test": "umi-scripts jest-turbo"
|
|
39
37
|
},
|
|
40
38
|
"dependencies": {
|
|
41
|
-
"@
|
|
42
|
-
"@umijs/bundler-
|
|
43
|
-
"@umijs/
|
|
44
|
-
"@umijs/
|
|
45
|
-
"@umijs/
|
|
46
|
-
"@umijs/
|
|
47
|
-
"@umijs/
|
|
48
|
-
"@umijs/
|
|
49
|
-
"@umijs/
|
|
39
|
+
"@babel/runtime": "7.18.9",
|
|
40
|
+
"@umijs/bundler-utils": "4.0.9",
|
|
41
|
+
"@umijs/bundler-webpack": "4.0.9",
|
|
42
|
+
"@umijs/core": "4.0.9",
|
|
43
|
+
"@umijs/lint": "4.0.9",
|
|
44
|
+
"@umijs/preset-umi": "4.0.9",
|
|
45
|
+
"@umijs/renderer-react": "4.0.9",
|
|
46
|
+
"@umijs/server": "4.0.9",
|
|
47
|
+
"@umijs/test": "4.0.9",
|
|
48
|
+
"@umijs/utils": "4.0.9",
|
|
50
49
|
"prettier-plugin-organize-imports": "^2.3.4",
|
|
51
50
|
"prettier-plugin-packagejson": "^2.2.17"
|
|
52
51
|
},
|
package/dist/cli/printHelp.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function printHelp(): void;
|
package/dist/cli/printHelp.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.printHelp = void 0;
|
|
4
|
-
const utils_1 = require("@umijs/utils");
|
|
5
|
-
function printHelp() {
|
|
6
|
-
utils_1.logger.fatal('A complete log of this run can be found in:');
|
|
7
|
-
utils_1.logger.fatal(utils_1.logger.getLatestLogFilePath());
|
|
8
|
-
utils_1.logger.fatal('Consider reporting a GitHub issue on https://github.com/umijs/umi/issues');
|
|
9
|
-
}
|
|
10
|
-
exports.printHelp = printHelp;
|
package/dist/client/plugin.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export declare enum ApplyPluginsType {
|
|
2
|
-
compose = "compose",
|
|
3
|
-
modify = "modify",
|
|
4
|
-
event = "event"
|
|
5
|
-
}
|
|
6
|
-
interface IPlugin {
|
|
7
|
-
path?: string;
|
|
8
|
-
apply: Record<string, any>;
|
|
9
|
-
}
|
|
10
|
-
export declare class PluginManager {
|
|
11
|
-
opts: {
|
|
12
|
-
validKeys: string[];
|
|
13
|
-
};
|
|
14
|
-
hooks: {
|
|
15
|
-
[key: string]: any;
|
|
16
|
-
};
|
|
17
|
-
constructor(opts: {
|
|
18
|
-
validKeys: string[];
|
|
19
|
-
});
|
|
20
|
-
register(plugin: IPlugin): void;
|
|
21
|
-
getHooks(keyWithDot: string): any;
|
|
22
|
-
applyPlugins({ key, type, initialValue, args, async, }: {
|
|
23
|
-
key: string;
|
|
24
|
-
type: ApplyPluginsType;
|
|
25
|
-
initialValue?: any;
|
|
26
|
-
args?: object;
|
|
27
|
-
async?: boolean;
|
|
28
|
-
}): any;
|
|
29
|
-
static create(opts: {
|
|
30
|
-
validKeys: string[];
|
|
31
|
-
plugins: IPlugin[];
|
|
32
|
-
}): PluginManager;
|
|
33
|
-
}
|
|
34
|
-
export {};
|
package/dist/client/plugin.js
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PluginManager = exports.ApplyPluginsType = void 0;
|
|
4
|
-
const utils_1 = require("./utils");
|
|
5
|
-
var ApplyPluginsType;
|
|
6
|
-
(function (ApplyPluginsType) {
|
|
7
|
-
ApplyPluginsType["compose"] = "compose";
|
|
8
|
-
ApplyPluginsType["modify"] = "modify";
|
|
9
|
-
ApplyPluginsType["event"] = "event";
|
|
10
|
-
})(ApplyPluginsType = exports.ApplyPluginsType || (exports.ApplyPluginsType = {}));
|
|
11
|
-
class PluginManager {
|
|
12
|
-
constructor(opts) {
|
|
13
|
-
this.hooks = {};
|
|
14
|
-
this.opts = opts;
|
|
15
|
-
}
|
|
16
|
-
register(plugin) {
|
|
17
|
-
(0, utils_1.assert)(plugin.apply, `plugin register failed, apply must supplied`);
|
|
18
|
-
Object.keys(plugin.apply).forEach((key) => {
|
|
19
|
-
(0, utils_1.assert)(this.opts.validKeys.indexOf(key) > -1, `register failed, invalid key ${key} ${plugin.path ? `from plugin ${plugin.path}` : ''}.`);
|
|
20
|
-
this.hooks[key] = (this.hooks[key] || []).concat(plugin.apply[key]);
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
getHooks(keyWithDot) {
|
|
24
|
-
const [key, ...memberKeys] = keyWithDot.split('.');
|
|
25
|
-
let hooks = this.hooks[key] || [];
|
|
26
|
-
if (memberKeys.length) {
|
|
27
|
-
hooks = hooks
|
|
28
|
-
.map((hook) => {
|
|
29
|
-
try {
|
|
30
|
-
let ret = hook;
|
|
31
|
-
for (const memberKey of memberKeys) {
|
|
32
|
-
ret = ret[memberKey];
|
|
33
|
-
}
|
|
34
|
-
return ret;
|
|
35
|
-
}
|
|
36
|
-
catch (e) {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
})
|
|
40
|
-
.filter(Boolean);
|
|
41
|
-
}
|
|
42
|
-
return hooks;
|
|
43
|
-
}
|
|
44
|
-
applyPlugins({ key, type, initialValue, args, async, }) {
|
|
45
|
-
const hooks = this.getHooks(key) || [];
|
|
46
|
-
if (args) {
|
|
47
|
-
(0, utils_1.assert)(typeof args === 'object', `applyPlugins failed, args must be plain object.`);
|
|
48
|
-
}
|
|
49
|
-
if (async) {
|
|
50
|
-
(0, utils_1.assert)(type === ApplyPluginsType.modify || type === ApplyPluginsType.event, `async only works with modify and event type.`);
|
|
51
|
-
}
|
|
52
|
-
switch (type) {
|
|
53
|
-
case ApplyPluginsType.modify:
|
|
54
|
-
if (async) {
|
|
55
|
-
return hooks.reduce(async (memo, hook) => {
|
|
56
|
-
(0, utils_1.assert)(typeof hook === 'function' ||
|
|
57
|
-
typeof hook === 'object' ||
|
|
58
|
-
(0, utils_1.isPromiseLike)(hook), `applyPlugins failed, all hooks for key ${key} must be function, plain object or Promise.`);
|
|
59
|
-
if ((0, utils_1.isPromiseLike)(memo)) {
|
|
60
|
-
memo = await memo;
|
|
61
|
-
}
|
|
62
|
-
if (typeof hook === 'function') {
|
|
63
|
-
const ret = hook(memo, args);
|
|
64
|
-
if ((0, utils_1.isPromiseLike)(ret)) {
|
|
65
|
-
return await ret;
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
return ret;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
if ((0, utils_1.isPromiseLike)(hook)) {
|
|
73
|
-
hook = await hook;
|
|
74
|
-
}
|
|
75
|
-
return { ...memo, ...hook };
|
|
76
|
-
}
|
|
77
|
-
}, (0, utils_1.isPromiseLike)(initialValue)
|
|
78
|
-
? initialValue
|
|
79
|
-
: Promise.resolve(initialValue));
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
return hooks.reduce((memo, hook) => {
|
|
83
|
-
(0, utils_1.assert)(typeof hook === 'function' || typeof hook === 'object', `applyPlugins failed, all hooks for key ${key} must be function or plain object.`);
|
|
84
|
-
if (typeof hook === 'function') {
|
|
85
|
-
return hook(memo, args);
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
// TODO: deepmerge?
|
|
89
|
-
return { ...memo, ...hook };
|
|
90
|
-
}
|
|
91
|
-
}, initialValue);
|
|
92
|
-
}
|
|
93
|
-
case ApplyPluginsType.event:
|
|
94
|
-
return (async () => {
|
|
95
|
-
for (const hook of hooks) {
|
|
96
|
-
(0, utils_1.assert)(typeof hook === 'function', `applyPlugins failed, all hooks for key ${key} must be function.`);
|
|
97
|
-
const ret = hook(args);
|
|
98
|
-
if (async && (0, utils_1.isPromiseLike)(ret)) {
|
|
99
|
-
await ret;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
})();
|
|
103
|
-
case ApplyPluginsType.compose:
|
|
104
|
-
return () => {
|
|
105
|
-
return (0, utils_1.compose)({
|
|
106
|
-
fns: hooks.concat(initialValue),
|
|
107
|
-
args,
|
|
108
|
-
})();
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
static create(opts) {
|
|
113
|
-
const pluginManager = new PluginManager({
|
|
114
|
-
validKeys: opts.validKeys,
|
|
115
|
-
});
|
|
116
|
-
opts.plugins.forEach((plugin) => {
|
|
117
|
-
pluginManager.register(plugin);
|
|
118
|
-
});
|
|
119
|
-
return pluginManager;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
exports.PluginManager = PluginManager;
|
|
123
|
-
// plugins meta info (in tmp file)
|
|
124
|
-
// hooks api: usePlugin
|
package/dist/client/utils.d.ts
DELETED
package/dist/client/utils.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isPromiseLike = exports.compose = exports.assert = void 0;
|
|
4
|
-
function assert(value, message) {
|
|
5
|
-
if (!value)
|
|
6
|
-
throw new Error(message);
|
|
7
|
-
}
|
|
8
|
-
exports.assert = assert;
|
|
9
|
-
function compose({ fns, args, }) {
|
|
10
|
-
if (fns.length === 1) {
|
|
11
|
-
return fns[0];
|
|
12
|
-
}
|
|
13
|
-
const last = fns.pop();
|
|
14
|
-
return fns.reduce((a, b) => () => b(a, args), last);
|
|
15
|
-
}
|
|
16
|
-
exports.compose = compose;
|
|
17
|
-
function isPromiseLike(obj) {
|
|
18
|
-
return !!obj && typeof obj === 'object' && typeof obj.then === 'function';
|
|
19
|
-
}
|
|
20
|
-
exports.isPromiseLike = isPromiseLike;
|