@modern-js/app-tools 2.63.1-alpha.0 → 2.63.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 (99) hide show
  1. package/bin/modern.js +1 -1
  2. package/dist/cjs/commands/build.js +13 -19
  3. package/dist/cjs/commands/deploy.js +5 -5
  4. package/dist/cjs/commands/dev.js +11 -11
  5. package/dist/cjs/commands/index.js +6 -6
  6. package/dist/cjs/commands/inspect.js +1 -1
  7. package/dist/cjs/commands/serve.js +4 -4
  8. package/dist/cjs/hooks.js +60 -0
  9. package/dist/cjs/index.js +5 -154
  10. package/dist/cjs/{compat → new/compat}/hooks.js +5 -5
  11. package/dist/cjs/{compat → new/compat}/index.js +1 -4
  12. package/dist/cjs/{utils/initAppContext.js → new/context.js} +3 -3
  13. package/dist/cjs/{utils → new}/getConfigFile.js +1 -1
  14. package/dist/cjs/new/index.js +79 -0
  15. package/dist/cjs/new/loadPlugins.js +57 -0
  16. package/dist/cjs/{run/index.js → new/run.js} +6 -6
  17. package/dist/cjs/{utils/isAutoLoadPlugins.js → new/utils/index.js} +6 -6
  18. package/dist/cjs/old.js +179 -0
  19. package/dist/cjs/plugins/serverBuild.js +32 -30
  20. package/dist/cjs/utils/loadPlugins.js +4 -35
  21. package/dist/cjs/utils/printInstructions.js +11 -2
  22. package/dist/cjs/utils/restart.js +2 -2
  23. package/dist/esm/commands/build.js +12 -18
  24. package/dist/esm/commands/deploy.js +6 -6
  25. package/dist/esm/commands/dev.js +11 -11
  26. package/dist/esm/commands/index.js +8 -8
  27. package/dist/esm/commands/inspect.js +1 -1
  28. package/dist/esm/commands/serve.js +6 -6
  29. package/dist/esm/hooks.js +36 -0
  30. package/dist/esm/index.js +2 -245
  31. package/dist/esm/{compat → new/compat}/hooks.js +25 -15
  32. package/dist/esm/{compat → new/compat}/index.js +1 -4
  33. package/dist/esm/{utils → new}/getConfigFile.js +1 -1
  34. package/dist/esm/new/index.js +55 -0
  35. package/dist/esm/new/loadPlugins.js +94 -0
  36. package/dist/esm/{run/index.js → new/run.js} +6 -6
  37. package/dist/esm/{utils/isAutoLoadPlugins.js → new/utils/index.js} +6 -6
  38. package/dist/esm/old.js +258 -0
  39. package/dist/esm/plugins/serverBuild.js +56 -52
  40. package/dist/esm/utils/loadPlugins.js +7 -95
  41. package/dist/esm/utils/printInstructions.js +28 -1
  42. package/dist/esm/utils/restart.js +3 -3
  43. package/dist/esm-node/commands/build.js +13 -19
  44. package/dist/esm-node/commands/deploy.js +5 -5
  45. package/dist/esm-node/commands/dev.js +12 -12
  46. package/dist/esm-node/commands/index.js +6 -6
  47. package/dist/esm-node/commands/inspect.js +1 -1
  48. package/dist/esm-node/commands/serve.js +5 -5
  49. package/dist/esm-node/hooks.js +36 -0
  50. package/dist/esm-node/index.js +2 -140
  51. package/dist/esm-node/{compat → new/compat}/hooks.js +5 -5
  52. package/dist/esm-node/{compat → new/compat}/index.js +1 -4
  53. package/dist/esm-node/{utils → new}/getConfigFile.js +1 -1
  54. package/dist/esm-node/new/index.js +52 -0
  55. package/dist/esm-node/new/loadPlugins.js +33 -0
  56. package/dist/esm-node/{run/index.js → new/run.js} +6 -6
  57. package/dist/esm-node/{utils/isAutoLoadPlugins.js → new/utils/index.js} +2 -2
  58. package/dist/esm-node/old.js +140 -0
  59. package/dist/esm-node/plugins/serverBuild.js +32 -30
  60. package/dist/esm-node/utils/loadPlugins.js +4 -34
  61. package/dist/esm-node/utils/printInstructions.js +9 -1
  62. package/dist/esm-node/utils/restart.js +2 -2
  63. package/dist/types/commands/build.d.ts +2 -2
  64. package/dist/types/commands/deploy.d.ts +2 -2
  65. package/dist/types/commands/dev.d.ts +2 -2
  66. package/dist/types/commands/index.d.ts +6 -6
  67. package/dist/types/commands/inspect.d.ts +2 -2
  68. package/dist/types/commands/serve.d.ts +2 -2
  69. package/dist/types/hooks.d.ts +2 -0
  70. package/dist/types/index.d.ts +3 -5
  71. package/dist/types/{compat → new/compat}/hooks.d.ts +2 -2
  72. package/dist/types/new/compat/index.d.ts +2 -0
  73. package/dist/types/new/index.d.ts +6 -0
  74. package/dist/types/new/loadPlugins.d.ts +9 -0
  75. package/dist/types/new/utils/index.d.ts +1 -0
  76. package/dist/types/old.d.ts +13 -0
  77. package/dist/types/plugins/serverBuild.d.ts +2 -2
  78. package/dist/types/types/index.d.ts +0 -2
  79. package/dist/types/types/new.d.ts +16 -11
  80. package/dist/types/utils/generateWatchFiles.d.ts +2 -2
  81. package/dist/types/utils/loadPlugins.d.ts +3 -13
  82. package/dist/types/utils/printInstructions.d.ts +3 -1
  83. package/dist/types/utils/restart.d.ts +3 -2
  84. package/package.json +23 -22
  85. package/dist/types/compat/index.d.ts +0 -2
  86. package/dist/types/utils/isAutoLoadPlugins.d.ts +0 -1
  87. /package/dist/cjs/{compat → new/compat}/utils.js +0 -0
  88. /package/dist/cjs/{constants.js → new/constants.js} +0 -0
  89. /package/dist/esm/{compat → new/compat}/utils.js +0 -0
  90. /package/dist/esm/{constants.js → new/constants.js} +0 -0
  91. /package/dist/esm/{utils/initAppContext.js → new/context.js} +0 -0
  92. /package/dist/esm-node/{compat → new/compat}/utils.js +0 -0
  93. /package/dist/esm-node/{constants.js → new/constants.js} +0 -0
  94. /package/dist/esm-node/{utils/initAppContext.js → new/context.js} +0 -0
  95. /package/dist/types/{compat → new/compat}/utils.d.ts +0 -0
  96. /package/dist/types/{constants.d.ts → new/constants.d.ts} +0 -0
  97. /package/dist/types/{utils/initAppContext.d.ts → new/context.d.ts} +0 -0
  98. /package/dist/types/{utils → new}/getConfigFile.d.ts +0 -0
  99. /package/dist/types/{run/index.d.ts → new/run.d.ts} +0 -0
@@ -7,14 +7,14 @@ import { newAction, upgradeAction } from "@modern-js/utils";
7
7
  import { i18n, localeKeys } from "../locale";
8
8
  var devCommand = function() {
9
9
  var _ref = _async_to_generator(function(program, api) {
10
- var hooks, devToolMetas, devProgram, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _loop, _iterator, _step;
10
+ var runner, devToolMetas, devProgram, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _loop, _iterator, _step;
11
11
  return _ts_generator(this, function(_state) {
12
12
  switch (_state.label) {
13
13
  case 0:
14
- hooks = api.getHooks();
14
+ runner = api.useHookRunners();
15
15
  return [
16
16
  4,
17
- hooks.registerDev.call()
17
+ runner.registerDev()
18
18
  ];
19
19
  case 1:
20
20
  devToolMetas = _state.sent();
@@ -64,7 +64,7 @@ var devCommand = function() {
64
64
  switch (_state2.label) {
65
65
  case 0:
66
66
  options = _arguments.length > 0 && _arguments[0] !== void 0 ? _arguments[0] : {};
67
- appDirectory = api.getAppContext().appDirectory;
67
+ appDirectory = api.useAppContext().appDirectory;
68
68
  return [
69
69
  4,
70
70
  import("@modern-js/utils")
@@ -129,14 +129,14 @@ var devCommand = function() {
129
129
  }();
130
130
  var buildCommand = function() {
131
131
  var _ref = _async_to_generator(function(program, api) {
132
- var hooks, platformBuilders, buildProgram, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _loop, _iterator, _step;
132
+ var runner, platformBuilders, buildProgram, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _loop, _iterator, _step;
133
133
  return _ts_generator(this, function(_state) {
134
134
  switch (_state.label) {
135
135
  case 0:
136
- hooks = api.getHooks();
136
+ runner = api.useHookRunners();
137
137
  return [
138
138
  4,
139
- hooks.registerBuildPlatform.call()
139
+ runner.registerBuildPlatform()
140
140
  ];
141
141
  case 1:
142
142
  platformBuilders = _state.sent();
@@ -182,7 +182,7 @@ var buildCommand = function() {
182
182
  return _ts_generator(this, function(_state2) {
183
183
  switch (_state2.label) {
184
184
  case 0:
185
- appDirectory = api.getAppContext().appDirectory;
185
+ appDirectory = api.useAppContext().appDirectory;
186
186
  return [
187
187
  4,
188
188
  import("@modern-js/utils")
@@ -4,7 +4,7 @@ var inspect = function() {
4
4
  var _ref = _async_to_generator(function(api, options) {
5
5
  var appContext;
6
6
  return _ts_generator(this, function(_state) {
7
- appContext = api.getAppContext();
7
+ appContext = api.useAppContext();
8
8
  if (!appContext.builder) {
9
9
  throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
10
10
  }
@@ -6,16 +6,16 @@ import path from "path";
6
6
  import { createProdServer } from "@modern-js/prod-server";
7
7
  import { SERVER_DIR, getMeta, getTargetDir, isApiOnly, logger } from "@modern-js/utils";
8
8
  import { loadServerPlugins } from "../utils/loadPlugins";
9
- import { printInstructions } from "../utils/printInstructions";
9
+ import { printInstructionsCompat } from "../utils/printInstructions";
10
10
  var start = function() {
11
11
  var _ref = _async_to_generator(function(api) {
12
- var _userConfig_source, _userConfig_output_distPath, appContext, userConfig, hooks, distDirectory, appDirectory, internalDirectory, port, metaName, serverRoutes, serverConfigFile, apiOnly, runMode, meta, serverConfigPath, pluginInstances, app;
12
+ var _userConfig_source, _userConfig_output_distPath, appContext, userConfig, hookRunners, distDirectory, appDirectory, internalDirectory, port, metaName, serverRoutes, serverConfigFile, apiOnly, runMode, meta, serverConfigPath, pluginInstances, app;
13
13
  return _ts_generator(this, function(_state) {
14
14
  switch (_state.label) {
15
15
  case 0:
16
- appContext = api.getAppContext();
17
- userConfig = api.getNormalizedConfig();
18
- hooks = api.getHooks();
16
+ appContext = api.useAppContext();
17
+ userConfig = api.useResolvedConfigContext();
18
+ hookRunners = api.useHookRunners();
19
19
  distDirectory = appContext.distDirectory, appDirectory = appContext.appDirectory, internalDirectory = appContext.internalDirectory, port = appContext.port, metaName = appContext.metaName, serverRoutes = appContext.serverRoutes, serverConfigFile = appContext.serverConfigFile;
20
20
  logger.info("Starting production server...");
21
21
  return [
@@ -69,7 +69,7 @@ var start = function() {
69
69
  case 0:
70
70
  return [
71
71
  4,
72
- printInstructions(hooks, appContext, userConfig)
72
+ printInstructionsCompat(hookRunners, appContext, userConfig)
73
73
  ];
74
74
  case 1:
75
75
  _state2.sent();
@@ -0,0 +1,36 @@
1
+ import { createAsyncWaterfall, createAsyncWorkflow, createParallelWorkflow } from "@modern-js/plugin";
2
+ var hooks = {
3
+ _internalRuntimePlugins: createAsyncWaterfall(),
4
+ modifyFileSystemRoutes: createAsyncWaterfall(),
5
+ modifyServerRoutes: createAsyncWaterfall(),
6
+ /** add entry point info to entrypoints array */
7
+ modifyEntrypoints: createAsyncWaterfall(),
8
+ /** add entry type */
9
+ checkEntryPoint: createAsyncWaterfall(),
10
+ generateEntryCode: createAsyncWorkflow(),
11
+ htmlPartials: createAsyncWaterfall(),
12
+ beforeGenerateRoutes: createAsyncWaterfall(),
13
+ _internalServerPlugins: createAsyncWaterfall(),
14
+ beforeDev: createAsyncWorkflow(),
15
+ afterDev: createAsyncWorkflow(),
16
+ beforeCreateCompiler: createAsyncWorkflow(),
17
+ afterCreateCompiler: createAsyncWorkflow(),
18
+ beforePrintInstructions: createAsyncWaterfall(),
19
+ beforeBuild: createAsyncWorkflow(),
20
+ afterBuild: createAsyncWorkflow(),
21
+ beforeDeploy: createAsyncWorkflow(),
22
+ deploy: createAsyncWorkflow(),
23
+ afterDeploy: createAsyncWorkflow(),
24
+ beforeRestart: createAsyncWorkflow(),
25
+ /**
26
+ * @deprecated
27
+ */
28
+ registerDev: createParallelWorkflow(),
29
+ /**
30
+ * @deprecated
31
+ */
32
+ registerBuildPlatform: createParallelWorkflow()
33
+ };
34
+ export {
35
+ hooks
36
+ };
package/dist/esm/index.js CHANGED
@@ -1,248 +1,5 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
3
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
- import { getLocaleLanguage } from "@modern-js/plugin-i18n/language-detector";
5
- import { createAsyncHook, createCollectAsyncHook } from "@modern-js/plugin-v2";
6
- import { castArray } from "@modern-js/uni-builder";
7
- import { cleanRequireCache, deprecatedCommands, emptyDir, getArgv, getCommand } from "@modern-js/utils";
8
- import { buildCommand, deployCommand, devCommand, inspectCommand, newCommand, serverCommand, upgradeCommand } from "./commands";
9
- import { compatPlugin } from "./compat";
10
- import { DEFAULT_RUNTIME_CONFIG_FILE, DEFAULT_SERVER_CONFIG_FILE } from "./constants";
11
- import { i18n } from "./locale";
12
- import analyzePlugin from "./plugins/analyze";
13
- import deployPlugin from "./plugins/deploy";
14
- import initializePlugin from "./plugins/initialize";
15
- import serverBuildPlugin from "./plugins/serverBuild";
16
- import { generateWatchFiles } from "./utils/generateWatchFiles";
17
- import { initAppContext } from "./utils/initAppContext";
18
- import { restart } from "./utils/restart";
19
- export * from "./defineConfig";
20
- var appTools = function() {
21
- var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
22
- // default webpack to be compatible with original projects
23
- bundler: "webpack"
24
- };
25
- return {
26
- name: "@modern-js/app-tools",
27
- usePlugins: [
28
- compatPlugin(),
29
- initializePlugin({
30
- bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
31
- "rspack",
32
- "experimental-rspack"
33
- ].includes(options.bundler) ? "rspack" : "webpack"
34
- }),
35
- analyzePlugin({
36
- bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
37
- "rspack",
38
- "experimental-rspack"
39
- ].includes(options.bundler) ? "rspack" : "webpack"
40
- }),
41
- serverBuildPlugin(),
42
- deployPlugin()
43
- ],
44
- post: [
45
- "@modern-js/plugin-initialize",
46
- "@modern-js/plugin-analyze",
47
- "@modern-js/plugin-ssr",
48
- "@modern-js/plugin-document",
49
- "@modern-js/plugin-state",
50
- "@modern-js/plugin-router",
51
- "@modern-js/plugin-router-v5",
52
- "@modern-js/plugin-polyfill"
53
- ],
54
- registryHooks: {
55
- onBeforeConfig: createAsyncHook(),
56
- onAfterPrepare: createAsyncHook(),
57
- deploy: createAsyncHook(),
58
- _internalRuntimePlugins: createAsyncHook(),
59
- _internalServerPlugins: createAsyncHook(),
60
- checkEntryPoint: createAsyncHook(),
61
- modifyEntrypoints: createAsyncHook(),
62
- modifyFileSystemRoutes: createAsyncHook(),
63
- modifyServerRoutes: createAsyncHook(),
64
- generateEntryCode: createAsyncHook(),
65
- onBeforeGenerateRoutes: createAsyncHook(),
66
- onBeforePrintInstructions: createAsyncHook(),
67
- registerDev: createCollectAsyncHook(),
68
- registerBuildPlatform: createCollectAsyncHook(),
69
- addRuntimeExports: createAsyncHook()
70
- },
71
- setup: function(api) {
72
- var _userConfig_output;
73
- var context = api.getAppContext();
74
- var userConfig = api.getConfig();
75
- var locale = getLocaleLanguage();
76
- i18n.changeLanguage({
77
- locale
78
- });
79
- api.updateAppContext(initAppContext({
80
- appDirectory: context.appDirectory,
81
- options: {},
82
- serverConfigFile: DEFAULT_SERVER_CONFIG_FILE,
83
- runtimeConfigFile: DEFAULT_RUNTIME_CONFIG_FILE,
84
- tempDir: (_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir
85
- }));
86
- api.addCommand(function() {
87
- var _ref = _async_to_generator(function(param) {
88
- var program;
89
- return _ts_generator(this, function(_state) {
90
- switch (_state.label) {
91
- case 0:
92
- program = param.program;
93
- return [
94
- 4,
95
- devCommand(program, api)
96
- ];
97
- case 1:
98
- _state.sent();
99
- return [
100
- 4,
101
- buildCommand(program, api)
102
- ];
103
- case 2:
104
- _state.sent();
105
- serverCommand(program, api);
106
- deployCommand(program, api);
107
- newCommand(program, locale);
108
- inspectCommand(program, api);
109
- upgradeCommand(program);
110
- deprecatedCommands(program);
111
- return [
112
- 2
113
- ];
114
- }
115
- });
116
- });
117
- return function(_) {
118
- return _ref.apply(this, arguments);
119
- };
120
- }());
121
- api.onPrepare(/* @__PURE__ */ _async_to_generator(function() {
122
- var command, isSkipBuild, resolvedConfig, appContext;
123
- return _ts_generator(this, function(_state) {
124
- switch (_state.label) {
125
- case 0:
126
- command = getCommand();
127
- if (command === "deploy") {
128
- isSkipBuild = [
129
- "-s",
130
- "--skip-build"
131
- ].some(function(tag) {
132
- return getArgv().includes(tag);
133
- });
134
- if (isSkipBuild) {
135
- return [
136
- 2
137
- ];
138
- }
139
- }
140
- if (!(command === "dev" || command === "start" || command === "build" || command === "deploy"))
141
- return [
142
- 3,
143
- 2
144
- ];
145
- resolvedConfig = api.getNormalizedConfig();
146
- if (!resolvedConfig.output.cleanDistPath)
147
- return [
148
- 3,
149
- 2
150
- ];
151
- appContext = api.getAppContext();
152
- return [
153
- 4,
154
- emptyDir(appContext.distDirectory)
155
- ];
156
- case 1:
157
- _state.sent();
158
- _state.label = 2;
159
- case 2:
160
- return [
161
- 2
162
- ];
163
- }
164
- });
165
- }));
166
- api.addWatchFiles(/* @__PURE__ */ _async_to_generator(function() {
167
- var appContext, config, files, watchFiles;
168
- return _ts_generator(this, function(_state) {
169
- switch (_state.label) {
170
- case 0:
171
- appContext = api.getAppContext();
172
- config = api.getNormalizedConfig();
173
- return [
174
- 4,
175
- generateWatchFiles(appContext, config.source.configDir)
176
- ];
177
- case 1:
178
- files = _state.sent();
179
- watchFiles = castArray(config.dev.watchFiles);
180
- watchFiles.forEach(function(param) {
181
- var type = param.type, paths = param.paths;
182
- if (type === "reload-server") {
183
- var _files;
184
- (_files = files).push.apply(_files, _to_consumable_array(Array.isArray(paths) ? paths : [
185
- paths
186
- ]));
187
- }
188
- });
189
- return [
190
- 2,
191
- files
192
- ];
193
- }
194
- });
195
- }));
196
- api.onFileChanged(function() {
197
- var _ref = _async_to_generator(function(e) {
198
- var filename, eventType, isPrivate, closeServer;
199
- return _ts_generator(this, function(_state) {
200
- switch (_state.label) {
201
- case 0:
202
- filename = e.filename, eventType = e.eventType, isPrivate = e.isPrivate;
203
- if (!(!isPrivate && (eventType === "change" || eventType === "unlink")))
204
- return [
205
- 3,
206
- 4
207
- ];
208
- return [
209
- 4,
210
- import("./utils/createServer.js")
211
- ];
212
- case 1:
213
- closeServer = _state.sent().closeServer;
214
- return [
215
- 4,
216
- closeServer()
217
- ];
218
- case 2:
219
- _state.sent();
220
- return [
221
- 4,
222
- restart(api.getHooks(), filename)
223
- ];
224
- case 3:
225
- _state.sent();
226
- _state.label = 4;
227
- case 4:
228
- return [
229
- 2
230
- ];
231
- }
232
- });
233
- });
234
- return function(e) {
235
- return _ref.apply(this, arguments);
236
- };
237
- }());
238
- api.onBeforeRestart(function() {
239
- cleanRequireCache([
240
- require.resolve("./plugins/analyze")
241
- ]);
242
- });
243
- }
244
- };
245
- };
1
+ import { appTools } from "./new/index";
2
+ import { initAppContext } from "./new/index";
246
3
  import { defineConfig, defineLegacyConfig } from "./defineConfig";
247
4
  import { mergeConfig } from "@modern-js/core";
248
5
  import { dev } from "./commands/dev";
@@ -1,6 +1,6 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
- import { getModifyHtmlPartials } from "../plugins/analyze/getHtmlTemplate";
3
+ import { getModifyHtmlPartials } from "../../plugins/analyze/getHtmlTemplate";
4
4
  import { transformHookParams, transformHookResult, transformHookRunner } from "./utils";
5
5
  function getHookRunners(context) {
6
6
  var hooks = context.hooks;
@@ -374,25 +374,35 @@ function getHookRunners(context) {
374
374
  /**
375
375
  * @deprecated
376
376
  */
377
- registerDev: /* @__PURE__ */ _async_to_generator(function() {
378
- return _ts_generator(this, function(_state) {
379
- return [
380
- 2,
381
- hooks.registerDev.call()
382
- ];
377
+ registerDev: function() {
378
+ var _ref = _async_to_generator(function(params) {
379
+ return _ts_generator(this, function(_state) {
380
+ return [
381
+ 2,
382
+ hooks.registerDev.call(params)
383
+ ];
384
+ });
383
385
  });
384
- }),
386
+ return function(params) {
387
+ return _ref.apply(this, arguments);
388
+ };
389
+ }(),
385
390
  /**
386
391
  * @deprecated
387
392
  */
388
- registerBuildPlatform: /* @__PURE__ */ _async_to_generator(function() {
389
- return _ts_generator(this, function(_state) {
390
- return [
391
- 2,
392
- hooks.registerBuildPlatform.call()
393
- ];
393
+ registerBuildPlatform: function() {
394
+ var _ref = _async_to_generator(function(params) {
395
+ return _ts_generator(this, function(_state) {
396
+ return [
397
+ 2,
398
+ hooks.registerBuildPlatform.call(params)
399
+ ];
400
+ });
394
401
  });
395
- }),
402
+ return function(params) {
403
+ return _ref.apply(this, arguments);
404
+ };
405
+ }(),
396
406
  /**
397
407
  * @deprecated
398
408
  */
@@ -32,10 +32,7 @@ var compatPlugin = function() {
32
32
  registryHooks: {
33
33
  appendEntryCode: createCollectAsyncHook()
34
34
  },
35
- setup: function(api) {
36
- api.updateAppContext({
37
- toolsType: "app-tools"
38
- });
35
+ setup: function(_api) {
39
36
  }
40
37
  };
41
38
  };
@@ -1,6 +1,6 @@
1
1
  import path from "path";
2
2
  import { CONFIG_FILE_EXTENSIONS, findExists } from "@modern-js/utils";
3
- import { DEFAULT_CONFIG_FILE } from "../constants";
3
+ import { DEFAULT_CONFIG_FILE } from "./constants";
4
4
  var getConfigFile = function(configFile) {
5
5
  return findExists(CONFIG_FILE_EXTENSIONS.map(function(extension) {
6
6
  return path.resolve(process.cwd(), "".concat(configFile || DEFAULT_CONFIG_FILE).concat(extension));
@@ -0,0 +1,55 @@
1
+ import { createAsyncHook } from "@modern-js/plugin-v2";
2
+ import { appTools as oldAppTools } from "../old";
3
+ import { compatPlugin } from "./compat";
4
+ import { DEFAULT_RUNTIME_CONFIG_FILE, DEFAULT_SERVER_CONFIG_FILE } from "./constants";
5
+ import { initAppContext } from "./context";
6
+ export * from "../defineConfig";
7
+ var appTools = function() {
8
+ var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
9
+ // default webpack to be compatible with original projects
10
+ bundler: "webpack"
11
+ };
12
+ return {
13
+ name: "@modern-js/app-tools",
14
+ usePlugins: [
15
+ compatPlugin(),
16
+ oldAppTools(options)
17
+ ],
18
+ post: [
19
+ "@modern-js/app-tools-old"
20
+ ],
21
+ registryHooks: {
22
+ onBeforeConfig: createAsyncHook(),
23
+ onAfterPrepare: createAsyncHook(),
24
+ deploy: createAsyncHook(),
25
+ _internalRuntimePlugins: createAsyncHook(),
26
+ _internalServerPlugins: createAsyncHook(),
27
+ checkEntryPoint: createAsyncHook(),
28
+ modifyEntrypoints: createAsyncHook(),
29
+ modifyFileSystemRoutes: createAsyncHook(),
30
+ modifyServerRoutes: createAsyncHook(),
31
+ generateEntryCode: createAsyncHook(),
32
+ onBeforeGenerateRoutes: createAsyncHook(),
33
+ onBeforePrintInstructions: createAsyncHook(),
34
+ registerDev: createAsyncHook(),
35
+ registerBuildPlatform: createAsyncHook(),
36
+ addRuntimeExports: createAsyncHook()
37
+ },
38
+ setup: function(api) {
39
+ var _userConfig_output;
40
+ var context = api.getAppContext();
41
+ var userConfig = api.getConfig();
42
+ api.updateAppContext(initAppContext({
43
+ appDirectory: context.appDirectory,
44
+ options: {},
45
+ serverConfigFile: DEFAULT_SERVER_CONFIG_FILE,
46
+ runtimeConfigFile: DEFAULT_RUNTIME_CONFIG_FILE,
47
+ tempDir: (_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir
48
+ }));
49
+ }
50
+ };
51
+ };
52
+ export {
53
+ appTools,
54
+ initAppContext
55
+ };
@@ -0,0 +1,94 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
3
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
+ import { compatibleRequire, createDebugger, dynamicImport, getInternalPlugins, tryResolve } from "@modern-js/utils";
5
+ var debug = createDebugger("load-plugins");
6
+ var resolveCliPlugin = function() {
7
+ var _ref = _async_to_generator(function(p, appDirectory) {
8
+ var pkg, pluginOptions, path, module, e, ref, result;
9
+ return _ts_generator(this, function(_state) {
10
+ switch (_state.label) {
11
+ case 0:
12
+ pkg = typeof p === "string" ? p : p[0];
13
+ pluginOptions = typeof p === "string" ? void 0 : p[1];
14
+ path = tryResolve(pkg, appDirectory);
15
+ _state.label = 1;
16
+ case 1:
17
+ _state.trys.push([
18
+ 1,
19
+ 3,
20
+ ,
21
+ 5
22
+ ]);
23
+ return [
24
+ 4,
25
+ compatibleRequire(path)
26
+ ];
27
+ case 2:
28
+ module = _state.sent();
29
+ return [
30
+ 3,
31
+ 5
32
+ ];
33
+ case 3:
34
+ e = _state.sent();
35
+ return [
36
+ 4,
37
+ dynamicImport(path)
38
+ ];
39
+ case 4:
40
+ ref = _state.sent(), module = ref.default, ref;
41
+ return [
42
+ 3,
43
+ 5
44
+ ];
45
+ case 5:
46
+ if (typeof module === "function") {
47
+ result = module(pluginOptions);
48
+ return [
49
+ 2,
50
+ result
51
+ ];
52
+ }
53
+ return [
54
+ 2,
55
+ module
56
+ ];
57
+ }
58
+ });
59
+ });
60
+ return function resolveCliPlugin2(p, appDirectory) {
61
+ return _ref.apply(this, arguments);
62
+ };
63
+ }();
64
+ var loadInternalPlugins = function() {
65
+ var _ref = _async_to_generator(function(appDirectory, internalPlugins, autoLoad, autoLoadPlugins) {
66
+ var plugins, loadedPlugins;
67
+ return _ts_generator(this, function(_state) {
68
+ switch (_state.label) {
69
+ case 0:
70
+ plugins = _to_consumable_array(autoLoadPlugins ? getInternalPlugins(appDirectory, internalPlugins) : []).concat(_to_consumable_array(autoLoad ? getInternalPlugins(appDirectory, autoLoad) : []));
71
+ return [
72
+ 4,
73
+ Promise.all(plugins.map(function(plugin) {
74
+ var loadedPlugin = resolveCliPlugin(plugin, appDirectory);
75
+ debug("resolve plugin %s: %s", plugin, loadedPlugin);
76
+ return loadedPlugin;
77
+ }))
78
+ ];
79
+ case 1:
80
+ loadedPlugins = _state.sent();
81
+ return [
82
+ 2,
83
+ loadedPlugins
84
+ ];
85
+ }
86
+ });
87
+ });
88
+ return function loadInternalPlugins2(appDirectory, internalPlugins, autoLoad, autoLoadPlugins) {
89
+ return _ref.apply(this, arguments);
90
+ };
91
+ }();
92
+ export {
93
+ loadInternalPlugins
94
+ };
@@ -3,11 +3,11 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import { initAppDir } from "@modern-js/plugin-v2/cli";
4
4
  import { run as CLIPluginRun } from "@modern-js/plugin-v2/run";
5
5
  import { minimist } from "@modern-js/utils";
6
- import { handleSetupResult } from "../compat/hooks";
7
- import { PACKAGE_JSON_CONFIG_NAME } from "../constants";
8
- import { getConfigFile } from "../utils/getConfigFile";
9
- import { isAutoLoadPlugins } from "../utils/isAutoLoadPlugins";
10
- import { loadInternalPlugins } from "../utils/loadPlugins";
6
+ import { handleSetupResult } from "./compat/hooks";
7
+ import { PACKAGE_JSON_CONFIG_NAME } from "./constants";
8
+ import { getConfigFile } from "./getConfigFile";
9
+ import { loadInternalPlugins } from "./loadPlugins";
10
+ import { getIsAutoLoadPlugins } from "./utils";
11
11
  function run(_) {
12
12
  return _run.apply(this, arguments);
13
13
  }
@@ -44,7 +44,7 @@ function _run() {
44
44
  finalConfigFile = customConfigFile || getConfigFile(configFile);
45
45
  return [
46
46
  4,
47
- isAutoLoadPlugins(appDirectory, finalConfigFile)
47
+ getIsAutoLoadPlugins(appDirectory, finalConfigFile)
48
48
  ];
49
49
  case 2:
50
50
  autoLoadPlugins = _state.sent();
@@ -1,11 +1,11 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import { createLoadedConfig } from "@modern-js/plugin-v2/cli";
4
- function isAutoLoadPlugins(appDirectory) {
5
- return _isAutoLoadPlugins.apply(this, arguments);
4
+ function getIsAutoLoadPlugins(appDirectory) {
5
+ return _getIsAutoLoadPlugins.apply(this, arguments);
6
6
  }
7
- function _isAutoLoadPlugins() {
8
- _isAutoLoadPlugins = _async_to_generator(function(appDirectory) {
7
+ function _getIsAutoLoadPlugins() {
8
+ _getIsAutoLoadPlugins = _async_to_generator(function(appDirectory) {
9
9
  var configFile, packageJsonConfig, _loaded_config, loaded, autoLoadPlugins;
10
10
  var _arguments = arguments;
11
11
  return _ts_generator(this, function(_state) {
@@ -26,8 +26,8 @@ function _isAutoLoadPlugins() {
26
26
  }
27
27
  });
28
28
  });
29
- return _isAutoLoadPlugins.apply(this, arguments);
29
+ return _getIsAutoLoadPlugins.apply(this, arguments);
30
30
  }
31
31
  export {
32
- isAutoLoadPlugins
32
+ getIsAutoLoadPlugins
33
33
  };