@modern-js/plugin-v2 2.63.7 → 2.63.8-alpha.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.
Files changed (101) hide show
  1. package/dist/cjs/cli/run/create.js +25 -14
  2. package/dist/cjs/hooks.js +74 -2
  3. package/dist/cjs/index.js +8 -2
  4. package/dist/cjs/manager.js +3 -5
  5. package/dist/cjs/runtime/api.js +79 -0
  6. package/dist/cjs/runtime/context.js +51 -0
  7. package/dist/cjs/runtime/hooks.js +36 -0
  8. package/dist/cjs/runtime/index.js +39 -0
  9. package/dist/cjs/runtime/run/create.js +74 -0
  10. package/dist/cjs/runtime/run/index.js +29 -0
  11. package/dist/cjs/runtime/run/types.js +16 -0
  12. package/dist/cjs/types/runtime/api.js +16 -0
  13. package/dist/cjs/types/runtime/context.js +16 -0
  14. package/dist/cjs/types/runtime/hooks.js +16 -0
  15. package/dist/cjs/types/runtime/index.js +16 -0
  16. package/dist/cjs/types/runtime/plugin.js +16 -0
  17. package/dist/esm/cli/api.js +103 -0
  18. package/dist/esm/cli/context.js +53 -0
  19. package/dist/esm/cli/hooks.js +42 -0
  20. package/dist/esm/cli/index.js +14 -0
  21. package/dist/esm/cli/run/config/createLoadedConfig.js +190 -0
  22. package/dist/esm/cli/run/config/createResolvedConfig.js +30 -0
  23. package/dist/esm/cli/run/config/loadConfig.js +210 -0
  24. package/dist/esm/cli/run/create.js +300 -0
  25. package/dist/esm/cli/run/index.js +10 -0
  26. package/dist/esm/cli/run/run.js +60 -0
  27. package/dist/esm/cli/run/types.js +0 -0
  28. package/dist/esm/cli/run/utils/checkIsDuplicationPlugin.js +24 -0
  29. package/dist/esm/cli/run/utils/commander.js +42 -0
  30. package/dist/esm/cli/run/utils/createFileWatcher.js +110 -0
  31. package/dist/esm/cli/run/utils/debug.js +5 -0
  32. package/dist/esm/cli/run/utils/initAppDir.js +36 -0
  33. package/dist/esm/cli/run/utils/loadEnv.js +24 -0
  34. package/dist/esm/cli/run/utils/mergeConfig.js +43 -0
  35. package/dist/esm/hooks.js +378 -0
  36. package/dist/esm/index.js +6 -357
  37. package/dist/esm/manager.js +161 -0
  38. package/dist/esm/runtime/api.js +59 -0
  39. package/dist/esm/runtime/context.js +25 -0
  40. package/dist/esm/runtime/hooks.js +12 -0
  41. package/dist/esm/runtime/index.js +11 -0
  42. package/dist/esm/runtime/run/create.js +72 -0
  43. package/dist/esm/runtime/run/index.js +5 -0
  44. package/dist/esm/runtime/run/types.js +0 -0
  45. package/dist/esm/types/cli/api.js +0 -0
  46. package/dist/esm/types/cli/context.js +0 -0
  47. package/dist/esm/types/cli/hooks.js +0 -0
  48. package/dist/esm/types/cli/index.js +0 -0
  49. package/dist/esm/types/cli/plugin.js +0 -0
  50. package/dist/esm/types/hooks.js +0 -0
  51. package/dist/esm/types/index.js +0 -0
  52. package/dist/esm/types/plugin.js +0 -0
  53. package/dist/esm/types/runtime/api.js +0 -0
  54. package/dist/esm/types/runtime/context.js +0 -0
  55. package/dist/esm/types/runtime/hooks.js +0 -0
  56. package/dist/esm/types/runtime/index.js +0 -0
  57. package/dist/esm/types/runtime/plugin.js +0 -0
  58. package/dist/esm/types/utils.js +0 -0
  59. package/dist/esm-node/cli/run/create.js +26 -15
  60. package/dist/esm-node/hooks.js +70 -1
  61. package/dist/esm-node/index.js +5 -2
  62. package/dist/esm-node/manager.js +2 -4
  63. package/dist/esm-node/runtime/api.js +55 -0
  64. package/dist/esm-node/runtime/context.js +26 -0
  65. package/dist/esm-node/runtime/hooks.js +12 -0
  66. package/dist/esm-node/runtime/index.js +11 -0
  67. package/dist/esm-node/runtime/run/create.js +50 -0
  68. package/dist/esm-node/runtime/run/index.js +5 -0
  69. package/dist/esm-node/runtime/run/types.js +0 -0
  70. package/dist/esm-node/types/runtime/api.js +0 -0
  71. package/dist/esm-node/types/runtime/context.js +0 -0
  72. package/dist/esm-node/types/runtime/hooks.js +0 -0
  73. package/dist/esm-node/types/runtime/index.js +0 -0
  74. package/dist/esm-node/types/runtime/plugin.js +0 -0
  75. package/dist/types/cli/hooks.d.ts +3 -3
  76. package/dist/types/cli/run/create.d.ts +2 -1
  77. package/dist/types/cli/run/index.d.ts +4 -4
  78. package/dist/types/hooks.d.ts +4 -1
  79. package/dist/types/index.d.ts +2 -1
  80. package/dist/types/manager.d.ts +3 -0
  81. package/dist/types/runtime/api.d.ts +9 -0
  82. package/dist/types/runtime/context.d.ts +11 -0
  83. package/dist/types/runtime/hooks.d.ts +2 -0
  84. package/dist/types/runtime/index.d.ts +5 -0
  85. package/dist/types/runtime/run/create.d.ts +7 -0
  86. package/dist/types/runtime/run/index.d.ts +5 -0
  87. package/dist/types/runtime/run/types.d.ts +6 -0
  88. package/dist/types/types/cli/api.d.ts +2 -2
  89. package/dist/types/types/cli/context.d.ts +1 -1
  90. package/dist/types/types/cli/hooks.d.ts +3 -3
  91. package/dist/types/types/cli/plugin.d.ts +2 -1
  92. package/dist/types/types/hooks.d.ts +14 -2
  93. package/dist/types/types/index.d.ts +1 -0
  94. package/dist/types/types/plugin.d.ts +1 -1
  95. package/dist/types/types/runtime/api.d.ts +15 -0
  96. package/dist/types/types/runtime/context.d.ts +13 -0
  97. package/dist/types/types/runtime/hooks.d.ts +12 -0
  98. package/dist/types/types/runtime/index.d.ts +4 -0
  99. package/dist/types/types/runtime/plugin.d.ts +14 -0
  100. package/dist/types/types/utils.d.ts +1 -0
  101. package/package.json +13 -9
package/dist/esm/index.js CHANGED
@@ -1,361 +1,10 @@
1
- // src/manager.ts
2
- import { _ as _type_of } from "@swc/helpers/_/_type_of";
3
- import { isFunction, logger } from "@modern-js/utils";
4
-
5
- // src/cli/run/utils/debug.ts
6
- import { createDebugger } from "@modern-js/utils";
7
- var debug = createDebugger("plugin-v2");
8
-
9
- // src/manager.ts
10
- function validatePlugin(plugin) {
11
- var type = typeof plugin === "undefined" ? "undefined" : _type_of(plugin);
12
- if (type !== "object" || plugin === null) {
13
- throw new Error("Expect CLI Plugin instance to be an object, but got ".concat(type, "."));
14
- }
15
- if (!plugin.setup)
16
- return;
17
- if (isFunction(plugin.setup)) {
18
- return;
19
- }
20
- throw new Error("Expect CLI Plugin plugin.setup to be a function, but got ".concat(type, "."));
21
- }
22
- function createPluginManager() {
23
- var plugins = /* @__PURE__ */ new Map();
24
- var dependencies = /* @__PURE__ */ new Map();
25
- var addDependency = function(plugin, dependency, type) {
26
- if (!dependencies.has(dependency)) {
27
- dependencies.set(dependency, {
28
- pre: /* @__PURE__ */ new Map(),
29
- post: /* @__PURE__ */ new Map()
30
- });
31
- }
32
- if (type === "pre") {
33
- dependencies.get(plugin).pre.set(dependency, {
34
- name: dependency,
35
- isUse: false
36
- });
37
- } else if (type === "post") {
38
- dependencies.get(plugin).post.set(dependency, {
39
- name: dependency
40
- });
41
- } else if (type === "use") {
42
- if (!dependencies.get(plugin).post.has(dependency) && !dependencies.get(dependency).pre.has(plugin)) {
43
- dependencies.get(plugin).pre.set(dependency, {
44
- name: dependency,
45
- isUse: true
46
- });
47
- }
48
- }
49
- };
50
- var addPlugin = function(newPlugin) {
51
- if (!newPlugin) {
52
- return;
53
- }
54
- validatePlugin(newPlugin);
55
- var name = newPlugin.name, _newPlugin_usePlugins = newPlugin.usePlugins, usePlugins = _newPlugin_usePlugins === void 0 ? [] : _newPlugin_usePlugins, _newPlugin_pre = newPlugin.pre, pre = _newPlugin_pre === void 0 ? [] : _newPlugin_pre, _newPlugin_post = newPlugin.post, post = _newPlugin_post === void 0 ? [] : _newPlugin_post;
56
- if (plugins.has(name)) {
57
- logger.warn("Plugin ".concat(name, " already exists."));
58
- return;
59
- }
60
- plugins.set(name, newPlugin);
61
- dependencies.set(name, {
62
- pre: /* @__PURE__ */ new Map(),
63
- post: /* @__PURE__ */ new Map()
64
- });
65
- pre.forEach(function(dep) {
66
- addDependency(name, dep, "pre");
67
- });
68
- post.forEach(function(dep) {
69
- addDependency(name, dep, "post");
70
- });
71
- usePlugins.forEach(function(plugin) {
72
- if (!plugins.has(plugin.name)) {
73
- addPlugin(plugin);
74
- }
75
- addDependency(name, plugin.name, "use");
76
- });
77
- };
78
- var addPlugins = function(newPlugins) {
79
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
80
- try {
81
- for (var _iterator = newPlugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
82
- var newPlugin = _step.value;
83
- addPlugin(newPlugin);
84
- }
85
- } catch (err) {
86
- _didIteratorError = true;
87
- _iteratorError = err;
88
- } finally {
89
- try {
90
- if (!_iteratorNormalCompletion && _iterator.return != null) {
91
- _iterator.return();
92
- }
93
- } finally {
94
- if (_didIteratorError) {
95
- throw _iteratorError;
96
- }
97
- }
98
- }
99
- };
100
- var getPlugins = function() {
101
- var visited = /* @__PURE__ */ new Set();
102
- var temp = /* @__PURE__ */ new Set();
103
- var result = [];
104
- var visit = function(name) {
105
- if (temp.has(name)) {
106
- throw new Error("Circular dependency detected: ".concat(name));
107
- }
108
- if (!visited.has(name) && plugins.get(name)) {
109
- temp.add(name);
110
- var _plugins_get = plugins.get(name), _plugins_get_required = _plugins_get.required, required = _plugins_get_required === void 0 ? [] : _plugins_get_required;
111
- required.forEach(function(dep) {
112
- if (!plugins.get(dep)) {
113
- throw new Error("".concat(name, " plugin required plugin ").concat(dep, ", but not found."));
114
- }
115
- });
116
- var pre = dependencies.get(name).pre;
117
- Array.from(pre.values()).filter(function(dep) {
118
- return !dep.isUse;
119
- }).forEach(function(dep) {
120
- return visit(dep.name);
121
- });
122
- Array.from(pre.values()).filter(function(dep) {
123
- return dep.isUse;
124
- }).forEach(function(dep) {
125
- return visit(dep.name);
126
- });
127
- temp.delete(name);
128
- visited.add(name);
129
- result.push(plugins.get(name));
130
- }
131
- };
132
- plugins.forEach(function(_, name) {
133
- var post = dependencies.get(name).post;
134
- post.forEach(function(dep) {
135
- if (!dependencies.get(dep.name).pre.has(name)) {
136
- dependencies.get(dep.name).pre.set(name, {
137
- name,
138
- isUse: false
139
- });
140
- }
141
- });
142
- });
143
- plugins.forEach(function(_, name) {
144
- visit(name);
145
- });
146
- result = result.filter(function(result2) {
147
- return result2;
148
- });
149
- debug("CLI Plugins:", result.map(function(p) {
150
- return p.name;
151
- }));
152
- return result;
153
- };
154
- var clear = function() {
155
- plugins.clear();
156
- dependencies.clear();
157
- };
158
- return {
159
- getPlugins,
160
- addPlugins,
161
- clear,
162
- isPluginExists: function(name) {
163
- return plugins.has(name);
164
- }
165
- };
166
- }
167
-
168
- // src/hooks.ts
169
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
170
- import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
171
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
172
- function createAsyncHook() {
173
- var callbacks = [];
174
- var tap = function(cb) {
175
- callbacks.push(cb);
176
- };
177
- var call = function() {
178
- var _ref = _async_to_generator(function() {
179
- var _len, params, _key, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, callback, result, err;
180
- var _arguments = arguments;
181
- return _ts_generator(this, function(_state) {
182
- switch (_state.label) {
183
- case 0:
184
- for (_len = _arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
185
- params[_key] = _arguments[_key];
186
- }
187
- _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
188
- _state.label = 1;
189
- case 1:
190
- _state.trys.push([
191
- 1,
192
- 6,
193
- 7,
194
- 8
195
- ]);
196
- _iterator = callbacks[Symbol.iterator]();
197
- _state.label = 2;
198
- case 2:
199
- if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done))
200
- return [
201
- 3,
202
- 5
203
- ];
204
- callback = _step.value;
205
- return [
206
- 4,
207
- callback.apply(void 0, _to_consumable_array(params))
208
- ];
209
- case 3:
210
- result = _state.sent();
211
- if (result !== void 0) {
212
- params[0] = result;
213
- }
214
- _state.label = 4;
215
- case 4:
216
- _iteratorNormalCompletion = true;
217
- return [
218
- 3,
219
- 2
220
- ];
221
- case 5:
222
- return [
223
- 3,
224
- 8
225
- ];
226
- case 6:
227
- err = _state.sent();
228
- _didIteratorError = true;
229
- _iteratorError = err;
230
- return [
231
- 3,
232
- 8
233
- ];
234
- case 7:
235
- try {
236
- if (!_iteratorNormalCompletion && _iterator.return != null) {
237
- _iterator.return();
238
- }
239
- } finally {
240
- if (_didIteratorError) {
241
- throw _iteratorError;
242
- }
243
- }
244
- return [
245
- 7
246
- ];
247
- case 8:
248
- return [
249
- 2,
250
- params[0] || []
251
- ];
252
- }
253
- });
254
- });
255
- return function call2() {
256
- return _ref.apply(this, arguments);
257
- };
258
- }();
259
- return {
260
- tap,
261
- call
262
- };
263
- }
264
- function createCollectAsyncHook() {
265
- var callbacks = [];
266
- var tap = function(cb) {
267
- callbacks.push(cb);
268
- };
269
- var call = function() {
270
- var _ref = _async_to_generator(function() {
271
- var _len, params, _key, results, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, callback, result, err;
272
- var _arguments = arguments;
273
- return _ts_generator(this, function(_state) {
274
- switch (_state.label) {
275
- case 0:
276
- for (_len = _arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
277
- params[_key] = _arguments[_key];
278
- }
279
- results = [];
280
- _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
281
- _state.label = 1;
282
- case 1:
283
- _state.trys.push([
284
- 1,
285
- 6,
286
- 7,
287
- 8
288
- ]);
289
- _iterator = callbacks[Symbol.iterator]();
290
- _state.label = 2;
291
- case 2:
292
- if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done))
293
- return [
294
- 3,
295
- 5
296
- ];
297
- callback = _step.value;
298
- return [
299
- 4,
300
- callback(params)
301
- ];
302
- case 3:
303
- result = _state.sent();
304
- if (result !== void 0) {
305
- results.push(result);
306
- }
307
- _state.label = 4;
308
- case 4:
309
- _iteratorNormalCompletion = true;
310
- return [
311
- 3,
312
- 2
313
- ];
314
- case 5:
315
- return [
316
- 3,
317
- 8
318
- ];
319
- case 6:
320
- err = _state.sent();
321
- _didIteratorError = true;
322
- _iteratorError = err;
323
- return [
324
- 3,
325
- 8
326
- ];
327
- case 7:
328
- try {
329
- if (!_iteratorNormalCompletion && _iterator.return != null) {
330
- _iterator.return();
331
- }
332
- } finally {
333
- if (_didIteratorError) {
334
- throw _iteratorError;
335
- }
336
- }
337
- return [
338
- 7
339
- ];
340
- case 8:
341
- return [
342
- 2,
343
- results
344
- ];
345
- }
346
- });
347
- });
348
- return function call2() {
349
- return _ref.apply(this, arguments);
350
- };
351
- }();
352
- return {
353
- tap,
354
- call
355
- };
356
- }
1
+ import { createPluginManager } from "./manager";
2
+ import { createSyncHook, createAsyncHook, createCollectSyncHook, createCollectAsyncHook, createAsyncInterruptHook } from "./hooks";
357
3
  export {
358
4
  createAsyncHook,
5
+ createAsyncInterruptHook,
359
6
  createCollectAsyncHook,
360
- createPluginManager
7
+ createCollectSyncHook,
8
+ createPluginManager,
9
+ createSyncHook
361
10
  };
@@ -0,0 +1,161 @@
1
+ import { _ as _type_of } from "@swc/helpers/_/_type_of";
2
+ var isFunction = function(obj) {
3
+ return typeof obj === "function";
4
+ };
5
+ function validatePlugin(plugin) {
6
+ var type = typeof plugin === "undefined" ? "undefined" : _type_of(plugin);
7
+ if (type !== "object" || plugin === null) {
8
+ throw new Error("Expect CLI Plugin instance to be an object, but got ".concat(type, "."));
9
+ }
10
+ if (!plugin.setup)
11
+ return;
12
+ if (isFunction(plugin.setup)) {
13
+ return;
14
+ }
15
+ throw new Error("Expect CLI Plugin plugin.setup to be a function, but got ".concat(type, "."));
16
+ }
17
+ function createPluginManager() {
18
+ var plugins = /* @__PURE__ */ new Map();
19
+ var dependencies = /* @__PURE__ */ new Map();
20
+ var addDependency = function(plugin, dependency, type) {
21
+ if (!dependencies.has(dependency)) {
22
+ dependencies.set(dependency, {
23
+ pre: /* @__PURE__ */ new Map(),
24
+ post: /* @__PURE__ */ new Map()
25
+ });
26
+ }
27
+ if (type === "pre") {
28
+ dependencies.get(plugin).pre.set(dependency, {
29
+ name: dependency,
30
+ isUse: false
31
+ });
32
+ } else if (type === "post") {
33
+ dependencies.get(plugin).post.set(dependency, {
34
+ name: dependency
35
+ });
36
+ } else if (type === "use") {
37
+ if (!dependencies.get(plugin).post.has(dependency) && !dependencies.get(dependency).pre.has(plugin)) {
38
+ dependencies.get(plugin).pre.set(dependency, {
39
+ name: dependency,
40
+ isUse: true
41
+ });
42
+ }
43
+ }
44
+ };
45
+ var addPlugin = function(newPlugin) {
46
+ if (!newPlugin) {
47
+ return;
48
+ }
49
+ validatePlugin(newPlugin);
50
+ var name = newPlugin.name, _newPlugin_usePlugins = newPlugin.usePlugins, usePlugins = _newPlugin_usePlugins === void 0 ? [] : _newPlugin_usePlugins, _newPlugin_pre = newPlugin.pre, pre = _newPlugin_pre === void 0 ? [] : _newPlugin_pre, _newPlugin_post = newPlugin.post, post = _newPlugin_post === void 0 ? [] : _newPlugin_post;
51
+ if (plugins.has(name)) {
52
+ console.warn("Plugin ".concat(name, " already exists."));
53
+ return;
54
+ }
55
+ plugins.set(name, newPlugin);
56
+ dependencies.set(name, {
57
+ pre: /* @__PURE__ */ new Map(),
58
+ post: /* @__PURE__ */ new Map()
59
+ });
60
+ pre.forEach(function(dep) {
61
+ addDependency(name, dep, "pre");
62
+ });
63
+ post.forEach(function(dep) {
64
+ addDependency(name, dep, "post");
65
+ });
66
+ usePlugins.forEach(function(plugin) {
67
+ if (!plugins.has(plugin.name)) {
68
+ addPlugin(plugin);
69
+ }
70
+ addDependency(name, plugin.name, "use");
71
+ });
72
+ };
73
+ var addPlugins = function(newPlugins) {
74
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
75
+ try {
76
+ for (var _iterator = newPlugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
77
+ var newPlugin = _step.value;
78
+ addPlugin(newPlugin);
79
+ }
80
+ } catch (err) {
81
+ _didIteratorError = true;
82
+ _iteratorError = err;
83
+ } finally {
84
+ try {
85
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
86
+ _iterator.return();
87
+ }
88
+ } finally {
89
+ if (_didIteratorError) {
90
+ throw _iteratorError;
91
+ }
92
+ }
93
+ }
94
+ };
95
+ var getPlugins = function() {
96
+ var visited = /* @__PURE__ */ new Set();
97
+ var temp = /* @__PURE__ */ new Set();
98
+ var result = [];
99
+ var visit = function(name) {
100
+ if (temp.has(name)) {
101
+ throw new Error("Circular dependency detected: ".concat(name));
102
+ }
103
+ if (!visited.has(name) && plugins.get(name)) {
104
+ temp.add(name);
105
+ var _plugins_get = plugins.get(name), _plugins_get_required = _plugins_get.required, required = _plugins_get_required === void 0 ? [] : _plugins_get_required;
106
+ required.forEach(function(dep) {
107
+ if (!plugins.get(dep)) {
108
+ throw new Error("".concat(name, " plugin required plugin ").concat(dep, ", but not found."));
109
+ }
110
+ });
111
+ var pre = dependencies.get(name).pre;
112
+ Array.from(pre.values()).filter(function(dep) {
113
+ return !dep.isUse;
114
+ }).forEach(function(dep) {
115
+ return visit(dep.name);
116
+ });
117
+ Array.from(pre.values()).filter(function(dep) {
118
+ return dep.isUse;
119
+ }).forEach(function(dep) {
120
+ return visit(dep.name);
121
+ });
122
+ temp.delete(name);
123
+ visited.add(name);
124
+ result.push(plugins.get(name));
125
+ }
126
+ };
127
+ plugins.forEach(function(_, name) {
128
+ var post = dependencies.get(name).post;
129
+ post.forEach(function(dep) {
130
+ if (!dependencies.get(dep.name).pre.has(name)) {
131
+ dependencies.get(dep.name).pre.set(name, {
132
+ name,
133
+ isUse: false
134
+ });
135
+ }
136
+ });
137
+ });
138
+ plugins.forEach(function(_, name) {
139
+ visit(name);
140
+ });
141
+ result = result.filter(function(result2) {
142
+ return result2;
143
+ });
144
+ return result;
145
+ };
146
+ var clear = function() {
147
+ plugins.clear();
148
+ dependencies.clear();
149
+ };
150
+ return {
151
+ getPlugins,
152
+ addPlugins,
153
+ clear,
154
+ isPluginExists: function(name) {
155
+ return plugins.has(name);
156
+ }
157
+ };
158
+ }
159
+ export {
160
+ createPluginManager
161
+ };
@@ -0,0 +1,59 @@
1
+ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
2
+ import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties";
3
+ import { merge } from "@modern-js/runtime-utils/merge";
4
+ function initPluginAPI(param) {
5
+ var context = param.context, plugins = param.plugins;
6
+ var hooks = context.hooks, extendsHooks = context.extendsHooks;
7
+ function getRuntimeContext() {
8
+ if (context) {
9
+ var hooks2 = context.hooks, extendsHooks2 = context.extendsHooks, config = context.config, pluginAPI = context.pluginAPI, runtimeContext = _object_without_properties(context, [
10
+ "hooks",
11
+ "extendsHooks",
12
+ "config",
13
+ "pluginAPI"
14
+ ]);
15
+ runtimeContext._internalContext = context;
16
+ return runtimeContext;
17
+ }
18
+ throw new Error("Cannot access context");
19
+ }
20
+ function updateRuntimeContext(updateContext) {
21
+ context = merge(context, updateContext);
22
+ }
23
+ function getHooks() {
24
+ return _object_spread({}, hooks, extendsHooks);
25
+ }
26
+ function getRuntimeConfig() {
27
+ if (context.config) {
28
+ return context.config;
29
+ }
30
+ throw new Error("Cannot access config");
31
+ }
32
+ var extendsPluginApi = {};
33
+ plugins.forEach(function(plugin) {
34
+ var _registryApi = plugin._registryApi;
35
+ if (_registryApi) {
36
+ var apis = _registryApi(getRuntimeContext, updateRuntimeContext);
37
+ Object.keys(apis).forEach(function(apiName) {
38
+ extendsPluginApi[apiName] = apis[apiName];
39
+ });
40
+ }
41
+ });
42
+ if (extendsHooks) {
43
+ Object.keys(extendsHooks).forEach(function(hookName) {
44
+ extendsPluginApi[hookName] = extendsHooks[hookName].tap;
45
+ });
46
+ }
47
+ return _object_spread({
48
+ updateRuntimeContext,
49
+ getHooks,
50
+ getRuntimeConfig,
51
+ modifyRuntimeConfig: hooks.modifyRuntimeConfig.tap,
52
+ onBeforeRender: hooks.onBeforeRender.tap,
53
+ wrapRoot: hooks.wrapRoot.tap,
54
+ pickContext: hooks.pickContext.tap
55
+ }, extendsPluginApi);
56
+ }
57
+ export {
58
+ initPluginAPI
59
+ };
@@ -0,0 +1,25 @@
1
+ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
2
+ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
3
+ import { initHooks } from "./hooks";
4
+ function initRuntimeContext() {
5
+ return {};
6
+ }
7
+ function createRuntimeContext(param) {
8
+ var runtimeContext = param.runtimeContext, config = param.config, plugins = param.plugins;
9
+ var extendsHooks = {};
10
+ plugins.forEach(function(plugin) {
11
+ var _plugin_registryHooks = plugin.registryHooks, registryHooks = _plugin_registryHooks === void 0 ? {} : _plugin_registryHooks;
12
+ Object.keys(registryHooks).forEach(function(hookName) {
13
+ extendsHooks[hookName] = registryHooks[hookName];
14
+ });
15
+ });
16
+ return _object_spread_props(_object_spread({}, runtimeContext), {
17
+ hooks: _object_spread({}, initHooks(), extendsHooks),
18
+ extendsHooks,
19
+ config
20
+ });
21
+ }
22
+ export {
23
+ createRuntimeContext,
24
+ initRuntimeContext
25
+ };
@@ -0,0 +1,12 @@
1
+ import { createAsyncInterruptHook, createCollectSyncHook, createSyncHook } from "../hooks";
2
+ function initHooks() {
3
+ return {
4
+ onBeforeRender: createAsyncInterruptHook(),
5
+ wrapRoot: createSyncHook(),
6
+ pickContext: createSyncHook(),
7
+ modifyRuntimeConfig: createCollectSyncHook()
8
+ };
9
+ }
10
+ export {
11
+ initHooks
12
+ };
@@ -0,0 +1,11 @@
1
+ import { initPluginAPI } from "./api";
2
+ import { initRuntimeContext, createRuntimeContext } from "./context";
3
+ import { initHooks } from "./hooks";
4
+ import { runtime } from "./run";
5
+ export {
6
+ createRuntimeContext,
7
+ initHooks,
8
+ initPluginAPI,
9
+ initRuntimeContext,
10
+ runtime
11
+ };