umi 4.0.0-canary.20220718.1 → 4.0.0-canary.20220727.1
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.d.ts +0 -1
- package/dist/cli/cli.js +66 -45
- package/dist/cli/dev.d.ts +0 -1
- package/dist/cli/dev.js +42 -23
- package/dist/cli/fork.d.ts +0 -1
- package/dist/cli/fork.js +59 -37
- package/dist/cli/forkedDev.d.ts +0 -1
- package/dist/cli/forkedDev.js +34 -40
- package/dist/cli/node.d.ts +0 -1
- package/dist/cli/node.js +48 -24
- package/dist/constants.d.ts +0 -1
- package/dist/constants.js +42 -11
- package/dist/defineConfig.d.ts +0 -1
- package/dist/defineConfig.js +29 -5
- package/dist/defineMock.d.ts +0 -1
- package/dist/defineMock.js +29 -5
- package/dist/index.d.ts +0 -1
- package/dist/index.js +36 -23
- package/dist/pluginUtils.d.ts +0 -1
- package/dist/pluginUtils.js +38 -37
- package/dist/service/cwd.d.ts +0 -1
- package/dist/service/cwd.js +35 -11
- package/dist/service/requireHook.d.ts +0 -1
- package/dist/service/requireHook.js +12 -13
- package/dist/service/service.d.ts +0 -1
- package/dist/service/service.js +78 -42
- package/dist/test.d.ts +0 -1
- package/dist/test.js +69 -59
- package/package.json +13 -14
- package/dist/cli/cli.d.ts.map +0 -1
- package/dist/cli/dev.d.ts.map +0 -1
- package/dist/cli/fork.d.ts.map +0 -1
- package/dist/cli/forkedDev.d.ts.map +0 -1
- package/dist/cli/node.d.ts.map +0 -1
- package/dist/client/plugin.d.ts +0 -35
- package/dist/client/plugin.d.ts.map +0 -1
- package/dist/client/plugin.js +0 -124
- package/dist/client/utils.d.ts +0 -7
- package/dist/client/utils.d.ts.map +0 -1
- package/dist/client/utils.js +0 -20
- package/dist/constants.d.ts.map +0 -1
- package/dist/defineConfig.d.ts.map +0 -1
- package/dist/defineMock.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/pluginUtils.d.ts.map +0 -1
- package/dist/service/cwd.d.ts.map +0 -1
- package/dist/service/requireHook.d.ts.map +0 -1
- package/dist/service/service.d.ts.map +0 -1
- package/dist/test.d.ts.map +0 -1
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
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare function assert(value: unknown, message: string): void;
|
|
2
|
-
export declare function compose({ fns, args, }: {
|
|
3
|
-
fns: (Function | any)[];
|
|
4
|
-
args?: object;
|
|
5
|
-
}): any;
|
|
6
|
-
export declare function isPromiseLike(obj: any): boolean;
|
|
7
|
-
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/client/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,QAErD;AAED,wBAAgB,OAAO,CAAC,EACtB,GAAG,EACH,IAAI,GACL,EAAE;IACD,GAAG,EAAE,CAAC,QAAQ,GAAG,GAAG,CAAC,EAAE,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,OAMA;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,GAAG,WAErC"}
|
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;
|
package/dist/constants.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,KAAK,CAAC;AACnC,eAAO,MAAM,WAAW,QAAQ,CAAC;AACjC,eAAO,MAAM,oBAAoB,UAKhC,CAAC;AACF,eAAO,MAAM,cAAc,QAAQ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defineConfig.d.ts","sourceRoot":"","sources":["../src/defineConfig.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjD,aAAK,UAAU,GAAG,kBAAkB,GAAG,OAAO,CAAC;AAE/C,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAE3D"}
|
package/dist/defineMock.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defineMock.d.ts","sourceRoot":"","sources":["../src/defineMock.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AAE9E,aAAK,WAAW,GACZ,MAAM,GACN,MAAM,GACN,IAAI,GACJ,SAAS,GACT,OAAO,GACP,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACnB,cAAc,CAAC;AAEnB,wBAAgB,UAAU,CAAC,QAAQ,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAAA;CAAE;;EAElE"}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE3D,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,oBAAY,IAAI,GAAG,SAAS,GAAG,iBAAiB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pluginUtils.d.ts","sourceRoot":"","sources":["../src/pluginUtils.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,uCAAuC,CAAC;AAC5D,OAAO,KAAK,mBAAmB,MAAM,uDAAuD,CAAC;AAC7F,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cwd.d.ts","sourceRoot":"","sources":["../../src/service/cwd.ts"],"names":[],"mappings":"AAEA,wBAAgB,MAAM,WAOrB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"requireHook.d.ts","sourceRoot":"","sources":["../../src/service/requireHook.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/service/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;AAMrD,qBAAa,OAAQ,SAAQ,WAAW;gBAC1B,IAAI,CAAC,EAAE,GAAG;IAsBhB,IAAI,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,GAAG,CAAA;KAAE;CAa9C"}
|
package/dist/test.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAIrC,cAAc,aAAa,CAAC;AAE5B,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC7B,GAAG,EAAE,MAAM,GACV,MAAM,CAkBR;AAID,wBAAsB,WAAW,iBAShC;AAED,wBAAsB,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAejE"}
|