@modern-js/plugin-v2 2.67.1-alpha.4 → 2.67.1-alpha.6

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.
@@ -25,29 +25,30 @@ var import_lodash = require("@modern-js/utils/lodash");
25
25
  var import_context = require("./context");
26
26
  var import_debug = require("./run/utils/debug");
27
27
  function initPluginAPI({ context, pluginManager }) {
28
- const { hooks, extendsHooks, plugins } = context;
28
+ let internalContext = context;
29
+ const { hooks, extendsHooks, plugins } = internalContext;
29
30
  function getAppContext() {
30
- if (context) {
31
- const { hooks: hooks2, extendsHooks: extendsHooks2, config, normalizedConfig, pluginAPI: pluginAPI2, ...appContext } = context;
32
- appContext._internalContext = context;
31
+ if (internalContext) {
32
+ const { hooks: hooks2, extendsHooks: extendsHooks2, config, normalizedConfig, pluginAPI: pluginAPI2, ...appContext } = internalContext;
33
+ appContext._internalContext = internalContext;
33
34
  return appContext;
34
35
  }
35
36
  throw new Error("Cannot access context");
36
37
  }
37
38
  function getConfig() {
38
- if (context.config) {
39
- return context.config;
39
+ if (internalContext.config) {
40
+ return internalContext.config;
40
41
  }
41
42
  throw new Error("Cannot access config");
42
43
  }
43
44
  function getNormalizedConfig() {
44
- if (context.normalizedConfig) {
45
- return context.normalizedConfig;
45
+ if (internalContext.normalizedConfig) {
46
+ return internalContext.normalizedConfig;
46
47
  }
47
48
  throw new Error("Cannot access normalized config");
48
49
  }
49
50
  function getHooks() {
50
- return context.hooks;
51
+ return internalContext.hooks;
51
52
  }
52
53
  const extendsPluginApi = {};
53
54
  plugins.forEach((plugin) => {
@@ -65,11 +66,11 @@ function initPluginAPI({ context, pluginManager }) {
65
66
  });
66
67
  }
67
68
  function updateAppContext(updateContext) {
68
- context = (0, import_lodash.assign)(context, updateContext);
69
+ internalContext = (0, import_lodash.assign)(internalContext, updateContext);
69
70
  }
70
- async function _internal_resetAppContext({ appContext, config, normalizedConfig }) {
71
- const { packageName, configFile, command, appDirectory, metaName } = context;
72
- context = await (0, import_context.createContext)({
71
+ function _internal_resetAppContext({ appContext, config, normalizedConfig }) {
72
+ const { packageName, configFile, command, appDirectory, metaName } = internalContext;
73
+ internalContext = (0, import_context.createContext)({
73
74
  appContext: (0, import_lodash.assign)({}, (0, import_context.initAppContext)({
74
75
  packageName,
75
76
  configFile,
@@ -49,7 +49,7 @@ function initAppContext(params) {
49
49
  plugins: params.plugins
50
50
  };
51
51
  }
52
- async function createContext({ appContext, config, normalizedConfig }) {
52
+ function createContext({ appContext, config, normalizedConfig }) {
53
53
  const { plugins } = appContext;
54
54
  const extendsHooks = {};
55
55
  plugins.forEach((plugin) => {
@@ -73,7 +73,7 @@ const createCli = () => {
73
73
  pluginManager.addPlugins(allPlugins);
74
74
  const plugins = await pluginManager.getPlugins();
75
75
  debug("CLI Plugins:", plugins.map((p) => p.name));
76
- const context = await (0, import_context.createContext)({
76
+ const context = (0, import_context.createContext)({
77
77
  appContext: (0, import_context.initAppContext)({
78
78
  packageName: loaded.packageName,
79
79
  configFile: loaded.configFile,
@@ -1,41 +1,40 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
1
  import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
2
  import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties";
4
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
3
  import { assign } from "@modern-js/utils/lodash";
6
4
  import { createContext, initAppContext } from "./context";
7
5
  import { debug } from "./run/utils/debug";
8
6
  function initPluginAPI(param) {
9
7
  var context = param.context, pluginManager = param.pluginManager;
10
- var hooks = context.hooks, extendsHooks = context.extendsHooks, plugins = context.plugins;
8
+ var internalContext = context;
9
+ var hooks = internalContext.hooks, extendsHooks = internalContext.extendsHooks, plugins = internalContext.plugins;
11
10
  function getAppContext() {
12
- if (context) {
13
- var hooks2 = context.hooks, extendsHooks2 = context.extendsHooks, config = context.config, normalizedConfig = context.normalizedConfig, pluginAPI2 = context.pluginAPI, appContext = _object_without_properties(context, [
11
+ if (internalContext) {
12
+ var hooks2 = internalContext.hooks, extendsHooks2 = internalContext.extendsHooks, config = internalContext.config, normalizedConfig = internalContext.normalizedConfig, pluginAPI2 = internalContext.pluginAPI, appContext = _object_without_properties(internalContext, [
14
13
  "hooks",
15
14
  "extendsHooks",
16
15
  "config",
17
16
  "normalizedConfig",
18
17
  "pluginAPI"
19
18
  ]);
20
- appContext._internalContext = context;
19
+ appContext._internalContext = internalContext;
21
20
  return appContext;
22
21
  }
23
22
  throw new Error("Cannot access context");
24
23
  }
25
24
  function getConfig() {
26
- if (context.config) {
27
- return context.config;
25
+ if (internalContext.config) {
26
+ return internalContext.config;
28
27
  }
29
28
  throw new Error("Cannot access config");
30
29
  }
31
30
  function getNormalizedConfig() {
32
- if (context.normalizedConfig) {
33
- return context.normalizedConfig;
31
+ if (internalContext.normalizedConfig) {
32
+ return internalContext.normalizedConfig;
34
33
  }
35
34
  throw new Error("Cannot access normalized config");
36
35
  }
37
36
  function getHooks() {
38
- return context.hooks;
37
+ return internalContext.hooks;
39
38
  }
40
39
  var extendsPluginApi = {};
41
40
  plugins.forEach(function(plugin) {
@@ -53,43 +52,23 @@ function initPluginAPI(param) {
53
52
  });
54
53
  }
55
54
  function updateAppContext(updateContext) {
56
- context = assign(context, updateContext);
55
+ internalContext = assign(internalContext, updateContext);
57
56
  }
58
- function _internal_resetAppContext(_) {
59
- return __internal_resetAppContext.apply(this, arguments);
60
- }
61
- function __internal_resetAppContext() {
62
- __internal_resetAppContext = _async_to_generator(function(param2) {
63
- var appContext, config, normalizedConfig, packageName, configFile, command, appDirectory, metaName;
64
- return _ts_generator(this, function(_state) {
65
- switch (_state.label) {
66
- case 0:
67
- appContext = param2.appContext, config = param2.config, normalizedConfig = param2.normalizedConfig;
68
- packageName = context.packageName, configFile = context.configFile, command = context.command, appDirectory = context.appDirectory, metaName = context.metaName;
69
- return [
70
- 4,
71
- createContext({
72
- appContext: assign({}, initAppContext({
73
- packageName,
74
- configFile,
75
- command,
76
- appDirectory,
77
- plugins,
78
- metaName
79
- }), appContext),
80
- config,
81
- normalizedConfig
82
- })
83
- ];
84
- case 1:
85
- context = _state.sent();
86
- return [
87
- 2
88
- ];
89
- }
90
- });
57
+ function _internal_resetAppContext(param2) {
58
+ var appContext = param2.appContext, config = param2.config, normalizedConfig = param2.normalizedConfig;
59
+ var packageName = internalContext.packageName, configFile = internalContext.configFile, command = internalContext.command, appDirectory = internalContext.appDirectory, metaName = internalContext.metaName;
60
+ internalContext = createContext({
61
+ appContext: assign({}, initAppContext({
62
+ packageName,
63
+ configFile,
64
+ command,
65
+ appDirectory,
66
+ plugins,
67
+ metaName
68
+ }), appContext),
69
+ config,
70
+ normalizedConfig
91
71
  });
92
- return __internal_resetAppContext.apply(this, arguments);
93
72
  }
94
73
  var pluginAPI = _object_spread({
95
74
  isPluginExists: pluginManager.isPluginExists,
@@ -1,7 +1,5 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
1
  import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
2
  import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
3
  import path from "path";
6
4
  import { initHooks } from "./hooks";
7
5
  function initAppContext(params) {
@@ -19,34 +17,22 @@ function initAppContext(params) {
19
17
  plugins: params.plugins
20
18
  };
21
19
  }
22
- function createContext(_) {
23
- return _createContext.apply(this, arguments);
24
- }
25
- function _createContext() {
26
- _createContext = _async_to_generator(function(param) {
27
- var appContext, config, normalizedConfig, plugins, extendsHooks;
28
- return _ts_generator(this, function(_state) {
29
- appContext = param.appContext, config = param.config, normalizedConfig = param.normalizedConfig;
30
- plugins = appContext.plugins;
31
- extendsHooks = {};
32
- plugins.forEach(function(plugin) {
33
- var _plugin_registryHooks = plugin.registryHooks, registryHooks = _plugin_registryHooks === void 0 ? {} : _plugin_registryHooks;
34
- Object.keys(registryHooks).forEach(function(hookName) {
35
- extendsHooks[hookName] = registryHooks[hookName];
36
- });
37
- });
38
- return [
39
- 2,
40
- _object_spread_props(_object_spread({}, appContext), {
41
- hooks: _object_spread({}, initHooks(), extendsHooks),
42
- extendsHooks,
43
- config,
44
- normalizedConfig
45
- })
46
- ];
20
+ function createContext(param) {
21
+ var appContext = param.appContext, config = param.config, normalizedConfig = param.normalizedConfig;
22
+ var plugins = appContext.plugins;
23
+ var extendsHooks = {};
24
+ plugins.forEach(function(plugin) {
25
+ var _plugin_registryHooks = plugin.registryHooks, registryHooks = _plugin_registryHooks === void 0 ? {} : _plugin_registryHooks;
26
+ Object.keys(registryHooks).forEach(function(hookName) {
27
+ extendsHooks[hookName] = registryHooks[hookName];
47
28
  });
48
29
  });
49
- return _createContext.apply(this, arguments);
30
+ return _object_spread_props(_object_spread({}, appContext), {
31
+ hooks: _object_spread({}, initHooks(), extendsHooks),
32
+ extendsHooks,
33
+ config,
34
+ normalizedConfig
35
+ });
50
36
  }
51
37
  export {
52
38
  createContext,
@@ -99,84 +99,79 @@ var createCli = function() {
99
99
  debug("CLI Plugins:", plugins.map(function(p) {
100
100
  return p.name;
101
101
  }));
102
- return [
103
- 4,
104
- createContext({
105
- appContext: initAppContext({
106
- packageName: loaded.packageName,
107
- configFile: loaded.configFile,
108
- command,
109
- appDirectory,
110
- plugins,
111
- metaName
112
- }),
113
- config: loaded.config,
114
- normalizedConfig: {}
115
- })
116
- ];
117
- case 4:
118
- context = _state.sent();
102
+ context = createContext({
103
+ appContext: initAppContext({
104
+ packageName: loaded.packageName,
105
+ configFile: loaded.configFile,
106
+ command,
107
+ appDirectory,
108
+ plugins,
109
+ metaName
110
+ }),
111
+ config: loaded.config,
112
+ normalizedConfig: {}
113
+ });
119
114
  pluginAPI = initPluginAPI({
120
115
  context,
121
116
  pluginManager
122
117
  });
123
118
  context.pluginAPI = pluginAPI;
124
119
  _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
125
- _state.label = 5;
126
- case 5:
120
+ _state.label = 4;
121
+ case 4:
127
122
  _state.trys.push([
128
- 5,
123
+ 4,
124
+ 10,
129
125
  11,
130
- 12,
131
- 13
126
+ 12
132
127
  ]);
133
128
  _iterator = plugins[Symbol.iterator]();
134
- _state.label = 6;
135
- case 6:
129
+ _state.label = 5;
130
+ case 5:
136
131
  if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done))
137
132
  return [
138
133
  3,
139
- 10
134
+ 9
140
135
  ];
141
136
  plugin = _step.value;
142
137
  return [
143
138
  4,
144
139
  (_plugin_setup = plugin.setup) === null || _plugin_setup === void 0 ? void 0 : _plugin_setup.call(plugin, pluginAPI)
145
140
  ];
146
- case 7:
141
+ case 6:
147
142
  setupResult = _state.sent();
148
143
  if (!handleSetupResult)
149
144
  return [
150
145
  3,
151
- 9
146
+ 8
152
147
  ];
153
148
  return [
154
149
  4,
155
150
  handleSetupResult(setupResult, pluginAPI)
156
151
  ];
157
- case 8:
152
+ case 7:
158
153
  _state.sent();
159
- _state.label = 9;
160
- case 9:
154
+ _state.label = 8;
155
+ case 8:
161
156
  _iteratorNormalCompletion = true;
162
157
  return [
163
158
  3,
164
- 6
159
+ 5
165
160
  ];
166
- case 10:
161
+ case 9:
167
162
  return [
168
163
  3,
169
- 13
164
+ 12
170
165
  ];
171
- case 11:
166
+ case 10:
172
167
  err = _state.sent();
173
168
  _didIteratorError = true;
174
169
  _iteratorError = err;
175
170
  return [
176
171
  3,
177
- 13
172
+ 12
178
173
  ];
179
- case 12:
174
+ case 11:
180
175
  try {
181
176
  if (!_iteratorNormalCompletion && _iterator.return != null) {
182
177
  _iterator.return();
@@ -189,7 +184,7 @@ var createCli = function() {
189
184
  return [
190
185
  7
191
186
  ];
192
- case 13:
187
+ case 12:
193
188
  [
194
189
  "SIGINT",
195
190
  "SIGTERM",
@@ -207,38 +202,38 @@ var createCli = function() {
207
202
  4,
208
203
  context.hooks.config.call()
209
204
  ];
210
- case 14:
205
+ case 13:
211
206
  extraConfigs = _state.sent();
212
207
  return [
213
208
  4,
214
209
  createResolveConfig(loaded, extraConfigs)
215
210
  ];
216
- case 15:
211
+ case 14:
217
212
  normalizedConfig = _state.sent();
218
213
  return [
219
214
  4,
220
215
  context.hooks.modifyResolvedConfig.call(normalizedConfig)
221
216
  ];
222
- case 16:
217
+ case 15:
223
218
  resolved = _state.sent();
224
219
  context.normalizedConfig = resolved || normalizedConfig;
225
220
  return [
226
221
  4,
227
222
  pluginAPI.updateAppContext(context)
228
223
  ];
229
- case 17:
224
+ case 16:
230
225
  _state.sent();
231
226
  return [
232
227
  4,
233
228
  context.hooks.onPrepare.call()
234
229
  ];
235
- case 18:
230
+ case 17:
236
231
  _state.sent();
237
232
  return [
238
233
  4,
239
234
  (_context_hooks = context.hooks) === null || _context_hooks === void 0 ? void 0 : (_context_hooks_onAfterPrepare = _context_hooks.onAfterPrepare) === null || _context_hooks_onAfterPrepare === void 0 ? void 0 : _context_hooks_onAfterPrepare.call()
240
235
  ];
241
- case 19:
236
+ case 18:
242
237
  _state.sent();
243
238
  return [
244
239
  2,
@@ -2,29 +2,30 @@ import { assign } from "@modern-js/utils/lodash";
2
2
  import { createContext, initAppContext } from "./context";
3
3
  import { debug } from "./run/utils/debug";
4
4
  function initPluginAPI({ context, pluginManager }) {
5
- const { hooks, extendsHooks, plugins } = context;
5
+ let internalContext = context;
6
+ const { hooks, extendsHooks, plugins } = internalContext;
6
7
  function getAppContext() {
7
- if (context) {
8
- const { hooks: hooks2, extendsHooks: extendsHooks2, config, normalizedConfig, pluginAPI: pluginAPI2, ...appContext } = context;
9
- appContext._internalContext = context;
8
+ if (internalContext) {
9
+ const { hooks: hooks2, extendsHooks: extendsHooks2, config, normalizedConfig, pluginAPI: pluginAPI2, ...appContext } = internalContext;
10
+ appContext._internalContext = internalContext;
10
11
  return appContext;
11
12
  }
12
13
  throw new Error("Cannot access context");
13
14
  }
14
15
  function getConfig() {
15
- if (context.config) {
16
- return context.config;
16
+ if (internalContext.config) {
17
+ return internalContext.config;
17
18
  }
18
19
  throw new Error("Cannot access config");
19
20
  }
20
21
  function getNormalizedConfig() {
21
- if (context.normalizedConfig) {
22
- return context.normalizedConfig;
22
+ if (internalContext.normalizedConfig) {
23
+ return internalContext.normalizedConfig;
23
24
  }
24
25
  throw new Error("Cannot access normalized config");
25
26
  }
26
27
  function getHooks() {
27
- return context.hooks;
28
+ return internalContext.hooks;
28
29
  }
29
30
  const extendsPluginApi = {};
30
31
  plugins.forEach((plugin) => {
@@ -42,11 +43,11 @@ function initPluginAPI({ context, pluginManager }) {
42
43
  });
43
44
  }
44
45
  function updateAppContext(updateContext) {
45
- context = assign(context, updateContext);
46
+ internalContext = assign(internalContext, updateContext);
46
47
  }
47
- async function _internal_resetAppContext({ appContext, config, normalizedConfig }) {
48
- const { packageName, configFile, command, appDirectory, metaName } = context;
49
- context = await createContext({
48
+ function _internal_resetAppContext({ appContext, config, normalizedConfig }) {
49
+ const { packageName, configFile, command, appDirectory, metaName } = internalContext;
50
+ internalContext = createContext({
50
51
  appContext: assign({}, initAppContext({
51
52
  packageName,
52
53
  configFile,
@@ -15,7 +15,7 @@ function initAppContext(params) {
15
15
  plugins: params.plugins
16
16
  };
17
17
  }
18
- async function createContext({ appContext, config, normalizedConfig }) {
18
+ function createContext({ appContext, config, normalizedConfig }) {
19
19
  const { plugins } = appContext;
20
20
  const extendsHooks = {};
21
21
  plugins.forEach((plugin) => {
@@ -50,7 +50,7 @@ const createCli = () => {
50
50
  pluginManager.addPlugins(allPlugins);
51
51
  const plugins = await pluginManager.getPlugins();
52
52
  debug("CLI Plugins:", plugins.map((p) => p.name));
53
- const context = await createContext({
53
+ const context = createContext({
54
54
  appContext: initAppContext({
55
55
  packageName: loaded.packageName,
56
56
  configFile: loaded.configFile,
@@ -15,4 +15,4 @@ export declare function initAppContext<Extends extends CLIPluginExtends>(params:
15
15
  srcDir?: string;
16
16
  distDir?: string;
17
17
  }): AppContext<Extends>;
18
- export declare function createContext<Extends extends CLIPluginExtends>({ appContext, config, normalizedConfig, }: ContextParams<Extends>): Promise<InternalContext<Extends>>;
18
+ export declare function createContext<Extends extends CLIPluginExtends>({ appContext, config, normalizedConfig, }: ContextParams<Extends>): InternalContext<Extends>;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.67.1-alpha.4",
18
+ "version": "2.67.1-alpha.6",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -81,8 +81,8 @@
81
81
  "dependencies": {
82
82
  "@swc/helpers": "0.5.13",
83
83
  "jiti": "1.21.7",
84
- "@modern-js/utils": "2.67.0",
85
- "@modern-js/runtime-utils": "2.67.0"
84
+ "@modern-js/runtime-utils": "2.67.0",
85
+ "@modern-js/utils": "2.67.0"
86
86
  },
87
87
  "devDependencies": {
88
88
  "@rsbuild/core": "1.3.2",