umi 4.0.0-beta.8 → 4.0.0-canary-20240513.3

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.
Files changed (59) hide show
  1. package/LICENSE +21 -0
  2. package/bin/forkedDev.js +1 -1
  3. package/bin/umi.js +20 -1
  4. package/client/client/plugin.js +213 -116
  5. package/client/client/utils.js +16 -10
  6. package/dist/cli/cli.d.ts +0 -1
  7. package/dist/cli/cli.js +68 -56
  8. package/dist/cli/dev.js +49 -23
  9. package/dist/cli/fork.js +86 -36
  10. package/dist/cli/forkedDev.d.ts +0 -1
  11. package/dist/cli/forkedDev.js +35 -50
  12. package/dist/constants.d.ts +2 -2
  13. package/dist/constants.js +45 -12
  14. package/dist/defineConfig.d.ts +10 -0
  15. package/dist/defineConfig.js +31 -0
  16. package/dist/defineMock.d.ts +8 -0
  17. package/dist/defineMock.js +31 -0
  18. package/dist/index.d.ts +5 -4
  19. package/dist/index.js +39 -26
  20. package/dist/pluginUtils.d.ts +5 -0
  21. package/dist/pluginUtils.js +48 -0
  22. package/dist/service/cwd.js +35 -11
  23. package/dist/service/requireHook.d.ts +1 -0
  24. package/dist/service/requireHook.js +14 -0
  25. package/dist/service/service.d.ts +0 -1
  26. package/dist/service/service.js +69 -40
  27. package/dist/test-setup.d.ts +1 -0
  28. package/dist/test-setup.js +3 -0
  29. package/dist/test.d.ts +119 -0
  30. package/dist/test.js +82 -0
  31. package/eslint.js +7 -0
  32. package/index.d.ts +10 -3
  33. package/package.json +45 -27
  34. package/plugin-utils.d.ts +1 -0
  35. package/plugin-utils.js +1 -0
  36. package/plugin.js +1 -0
  37. package/prettier.js +13 -0
  38. package/stylelint.js +7 -0
  39. package/test-setup.js +1 -0
  40. package/test.d.ts +1 -0
  41. package/test.js +1 -0
  42. package/dist/cli/cli.d.ts.map +0 -1
  43. package/dist/cli/dev.d.ts.map +0 -1
  44. package/dist/cli/fork.d.ts.map +0 -1
  45. package/dist/cli/forkedDev.d.ts.map +0 -1
  46. package/dist/cli/node.d.ts +0 -4
  47. package/dist/cli/node.d.ts.map +0 -1
  48. package/dist/cli/node.js +0 -32
  49. package/dist/client/plugin.d.ts +0 -34
  50. package/dist/client/plugin.d.ts.map +0 -1
  51. package/dist/client/plugin.js +0 -125
  52. package/dist/client/utils.d.ts +0 -6
  53. package/dist/client/utils.d.ts.map +0 -1
  54. package/dist/client/utils.js +0 -20
  55. package/dist/constants.d.ts.map +0 -1
  56. package/dist/index.d.ts.map +0 -1
  57. package/dist/service/cwd.d.ts.map +0 -1
  58. package/dist/service/service.d.ts.map +0 -1
  59. package/index.esm.js +0 -2
@@ -1,125 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.PluginManager = exports.ApplyPluginsType = void 0;
13
- const utils_1 = require("./utils");
14
- var ApplyPluginsType;
15
- (function (ApplyPluginsType) {
16
- ApplyPluginsType["compose"] = "compose";
17
- ApplyPluginsType["modify"] = "modify";
18
- ApplyPluginsType["event"] = "event";
19
- })(ApplyPluginsType = exports.ApplyPluginsType || (exports.ApplyPluginsType = {}));
20
- class PluginManager {
21
- constructor(opts) {
22
- this.hooks = {};
23
- this.opts = opts;
24
- }
25
- register(plugin) {
26
- (0, utils_1.assert)(plugin.apply && plugin.path, `plugin register failed, apply and path must supplied`);
27
- Object.keys(plugin.apply).forEach((key) => {
28
- (0, utils_1.assert)(this.opts.validKeys.indexOf(key) > -1, `register failed, invalid key ${key} from plugin ${plugin.path}.`);
29
- this.hooks[key] = (this.hooks[key] || []).concat(plugin.apply[key]);
30
- });
31
- }
32
- getHooks(keyWithDot) {
33
- const [key, ...memberKeys] = keyWithDot.split('.');
34
- let hooks = this.hooks[key] || [];
35
- if (memberKeys.length) {
36
- hooks = hooks
37
- .map((hook) => {
38
- try {
39
- let ret = hook;
40
- for (const memberKey of memberKeys) {
41
- ret = ret[memberKey];
42
- }
43
- return ret;
44
- }
45
- catch (e) {
46
- return null;
47
- }
48
- })
49
- .filter(Boolean);
50
- }
51
- return hooks;
52
- }
53
- applyPlugins({ key, type, initialValue, args, async, }) {
54
- const hooks = this.getHooks(key) || [];
55
- if (args) {
56
- (0, utils_1.assert)(typeof args === 'object', `applyPlugins failed, args must be plain object.`);
57
- }
58
- switch (type) {
59
- case ApplyPluginsType.modify:
60
- if (async) {
61
- return hooks.reduce((memo, hook) => __awaiter(this, void 0, void 0, function* () {
62
- (0, utils_1.assert)(typeof hook === 'function' ||
63
- typeof hook === 'object' ||
64
- (0, utils_1.isPromiseLike)(hook), `applyPlugins failed, all hooks for key ${key} must be function, plain object or Promise.`);
65
- if ((0, utils_1.isPromiseLike)(memo)) {
66
- memo = yield memo;
67
- }
68
- if (typeof hook === 'function') {
69
- const ret = hook(memo, args);
70
- if ((0, utils_1.isPromiseLike)(ret)) {
71
- return yield ret;
72
- }
73
- else {
74
- return ret;
75
- }
76
- }
77
- else {
78
- if ((0, utils_1.isPromiseLike)(hook)) {
79
- hook = yield hook;
80
- }
81
- return Object.assign(Object.assign({}, memo), hook);
82
- }
83
- }), (0, utils_1.isPromiseLike)(initialValue)
84
- ? initialValue
85
- : Promise.resolve(initialValue));
86
- }
87
- else {
88
- return hooks.reduce((memo, hook) => {
89
- (0, utils_1.assert)(typeof hook === 'function' || typeof hook === 'object', `applyPlugins failed, all hooks for key ${key} must be function or plain object.`);
90
- if (typeof hook === 'function') {
91
- return hook(memo, args);
92
- }
93
- else {
94
- // TODO: deepmerge?
95
- return Object.assign(Object.assign({}, memo), hook);
96
- }
97
- }, initialValue);
98
- }
99
- case ApplyPluginsType.event:
100
- return hooks.forEach((hook) => {
101
- (0, utils_1.assert)(typeof hook === 'function', `applyPlugins failed, all hooks for key ${key} must be function.`);
102
- hook(args);
103
- });
104
- case ApplyPluginsType.compose:
105
- return () => {
106
- return (0, utils_1.compose)({
107
- fns: hooks.concat(initialValue),
108
- args,
109
- })();
110
- };
111
- }
112
- }
113
- static create(opts) {
114
- const pluginManager = new PluginManager({
115
- validKeys: opts.validKeys,
116
- });
117
- opts.plugins.forEach((plugin) => {
118
- pluginManager.register(plugin);
119
- });
120
- return pluginManager;
121
- }
122
- }
123
- exports.PluginManager = PluginManager;
124
- // plugins meta info (in tmp file)
125
- // hooks api: usePlugin
@@ -1,6 +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;
@@ -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"}
@@ -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;
@@ -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,oBAAoB,KAAK,CAAC;AACvC,eAAO,MAAM,WAAW,QAAQ,CAAC;AACjC,eAAO,MAAM,oBAAoB,UAKhC,CAAC;AACF,eAAO,MAAM,cAAc,QAAQ,CAAC"}
@@ -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;AAC3D,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,oBAAY,IAAI,GAAG,SAAS,GAAG,iBAAiB,CAAC;AACjD,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,KAAK,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":"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;IAiBhB,IAAI,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,GAAG,CAAA;KAAE;CAa9C"}
package/index.esm.js DELETED
@@ -1,2 +0,0 @@
1
- export { Link, Outlet } from '@umijs/renderer-react';
2
- export { PluginManager } from './client/client/plugin';