@modern-js/app-tools 2.63.1 → 2.63.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 (138) hide show
  1. package/bin/modern.js +1 -1
  2. package/dist/cjs/commands/build.js +19 -13
  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/{new/compat → compat}/hooks.js +21 -6
  9. package/dist/cjs/{new/compat → compat}/index.js +7 -2
  10. package/dist/cjs/{new/compat → compat}/utils.js +29 -8
  11. package/dist/cjs/config/default.js +6 -1
  12. package/dist/cjs/config/legacy/index.js +0 -1
  13. package/dist/cjs/index.js +154 -5
  14. package/dist/cjs/plugins/analyze/getServerRoutes.js +12 -2
  15. package/dist/cjs/plugins/analyze/index.js +25 -10
  16. package/dist/cjs/plugins/analyze/utils.js +6 -0
  17. package/dist/cjs/plugins/deploy/platforms/netlify.js +7 -4
  18. package/dist/cjs/plugins/deploy/platforms/node.js +6 -3
  19. package/dist/cjs/plugins/deploy/platforms/vercel.js +7 -4
  20. package/dist/cjs/plugins/serverBuild.js +30 -32
  21. package/dist/cjs/{new/run.js → run/index.js} +6 -6
  22. package/dist/cjs/{new → utils}/getConfigFile.js +1 -1
  23. package/dist/cjs/{new/context.js → utils/initAppContext.js} +3 -3
  24. package/dist/cjs/{new/utils/index.js → utils/isAutoLoadPlugins.js} +6 -6
  25. package/dist/cjs/utils/loadPlugins.js +35 -4
  26. package/dist/cjs/utils/printInstructions.js +2 -11
  27. package/dist/cjs/utils/restart.js +2 -2
  28. package/dist/esm/commands/build.js +18 -12
  29. package/dist/esm/commands/deploy.js +6 -6
  30. package/dist/esm/commands/dev.js +11 -11
  31. package/dist/esm/commands/index.js +8 -8
  32. package/dist/esm/commands/inspect.js +1 -1
  33. package/dist/esm/commands/serve.js +6 -6
  34. package/dist/esm/{new/compat → compat}/hooks.js +98 -49
  35. package/dist/esm/{new/compat → compat}/index.js +8 -3
  36. package/dist/esm/{new/compat → compat}/utils.js +29 -8
  37. package/dist/esm/config/default.js +12 -1
  38. package/dist/esm/config/legacy/index.js +0 -1
  39. package/dist/esm/index.js +245 -2
  40. package/dist/esm/plugins/analyze/getServerRoutes.js +11 -2
  41. package/dist/esm/plugins/analyze/index.js +76 -34
  42. package/dist/esm/plugins/analyze/utils.js +5 -0
  43. package/dist/esm/plugins/deploy/platforms/netlify.js +6 -3
  44. package/dist/esm/plugins/deploy/platforms/node.js +5 -2
  45. package/dist/esm/plugins/deploy/platforms/vercel.js +6 -3
  46. package/dist/esm/plugins/serverBuild.js +52 -56
  47. package/dist/esm/{new/run.js → run/index.js} +6 -6
  48. package/dist/esm/{new → utils}/getConfigFile.js +1 -1
  49. package/dist/esm/{new/utils/index.js → utils/isAutoLoadPlugins.js} +6 -6
  50. package/dist/esm/utils/loadPlugins.js +95 -7
  51. package/dist/esm/utils/printInstructions.js +1 -28
  52. package/dist/esm/utils/restart.js +3 -3
  53. package/dist/esm-node/commands/build.js +19 -13
  54. package/dist/esm-node/commands/deploy.js +5 -5
  55. package/dist/esm-node/commands/dev.js +12 -12
  56. package/dist/esm-node/commands/index.js +6 -6
  57. package/dist/esm-node/commands/inspect.js +1 -1
  58. package/dist/esm-node/commands/serve.js +5 -5
  59. package/dist/esm-node/{new/compat → compat}/hooks.js +21 -6
  60. package/dist/esm-node/{new/compat → compat}/index.js +8 -3
  61. package/dist/esm-node/{new/compat → compat}/utils.js +29 -8
  62. package/dist/esm-node/config/default.js +6 -1
  63. package/dist/esm-node/config/legacy/index.js +0 -1
  64. package/dist/esm-node/index.js +140 -2
  65. package/dist/esm-node/plugins/analyze/getServerRoutes.js +11 -2
  66. package/dist/esm-node/plugins/analyze/index.js +26 -11
  67. package/dist/esm-node/plugins/analyze/utils.js +5 -0
  68. package/dist/esm-node/plugins/deploy/platforms/netlify.js +6 -3
  69. package/dist/esm-node/plugins/deploy/platforms/node.js +5 -2
  70. package/dist/esm-node/plugins/deploy/platforms/vercel.js +6 -3
  71. package/dist/esm-node/plugins/serverBuild.js +30 -32
  72. package/dist/esm-node/{new/run.js → run/index.js} +6 -6
  73. package/dist/esm-node/{new → utils}/getConfigFile.js +1 -1
  74. package/dist/esm-node/{new/utils/index.js → utils/isAutoLoadPlugins.js} +2 -2
  75. package/dist/esm-node/utils/loadPlugins.js +34 -4
  76. package/dist/esm-node/utils/printInstructions.js +1 -9
  77. package/dist/esm-node/utils/restart.js +2 -2
  78. package/dist/types/commands/build.d.ts +2 -2
  79. package/dist/types/commands/deploy.d.ts +2 -2
  80. package/dist/types/commands/dev.d.ts +2 -2
  81. package/dist/types/commands/index.d.ts +6 -6
  82. package/dist/types/commands/inspect.d.ts +2 -2
  83. package/dist/types/commands/serve.d.ts +2 -2
  84. package/dist/types/{new/compat → compat}/hooks.d.ts +2 -2
  85. package/dist/types/compat/index.d.ts +2 -0
  86. package/dist/types/{new/compat → compat}/utils.d.ts +8 -1
  87. package/dist/types/index.d.ts +5 -3
  88. package/dist/types/plugins/analyze/getServerRoutes.d.ts +1 -0
  89. package/dist/types/plugins/analyze/utils.d.ts +1 -0
  90. package/dist/types/plugins/serverBuild.d.ts +2 -2
  91. package/dist/types/types/config/index.d.ts +0 -1
  92. package/dist/types/types/index.d.ts +2 -0
  93. package/dist/types/types/new.d.ts +11 -16
  94. package/dist/types/utils/generateWatchFiles.d.ts +2 -2
  95. package/dist/types/utils/isAutoLoadPlugins.d.ts +1 -0
  96. package/dist/types/utils/loadPlugins.d.ts +13 -3
  97. package/dist/types/utils/printInstructions.d.ts +1 -3
  98. package/dist/types/utils/restart.d.ts +2 -3
  99. package/package.json +24 -28
  100. package/dist/cjs/hooks.js +0 -60
  101. package/dist/cjs/new/index.js +0 -79
  102. package/dist/cjs/new/loadPlugins.js +0 -57
  103. package/dist/cjs/old.js +0 -179
  104. package/dist/cjs/plugins/deploy/dependencies/index.js +0 -237
  105. package/dist/cjs/plugins/deploy/dependencies/utils.js +0 -179
  106. package/dist/cjs/plugins/deploy/exports.js +0 -28
  107. package/dist/esm/hooks.js +0 -36
  108. package/dist/esm/new/index.js +0 -55
  109. package/dist/esm/new/loadPlugins.js +0 -94
  110. package/dist/esm/old.js +0 -258
  111. package/dist/esm/plugins/deploy/dependencies/index.js +0 -615
  112. package/dist/esm/plugins/deploy/dependencies/utils.js +0 -421
  113. package/dist/esm/plugins/deploy/exports.js +0 -4
  114. package/dist/esm-node/hooks.js +0 -36
  115. package/dist/esm-node/new/index.js +0 -52
  116. package/dist/esm-node/new/loadPlugins.js +0 -33
  117. package/dist/esm-node/old.js +0 -140
  118. package/dist/esm-node/plugins/deploy/dependencies/index.js +0 -202
  119. package/dist/esm-node/plugins/deploy/dependencies/utils.js +0 -137
  120. package/dist/esm-node/plugins/deploy/exports.js +0 -4
  121. package/dist/types/hooks.d.ts +0 -2
  122. package/dist/types/new/compat/index.d.ts +0 -2
  123. package/dist/types/new/index.d.ts +0 -6
  124. package/dist/types/new/loadPlugins.d.ts +0 -9
  125. package/dist/types/new/utils/index.d.ts +0 -1
  126. package/dist/types/old.d.ts +0 -13
  127. package/dist/types/plugins/deploy/dependencies/index.d.ts +0 -20
  128. package/dist/types/plugins/deploy/dependencies/utils.d.ts +0 -44
  129. package/dist/types/plugins/deploy/exports.d.ts +0 -1
  130. /package/dist/cjs/{new/constants.js → constants.js} +0 -0
  131. /package/dist/esm/{new/constants.js → constants.js} +0 -0
  132. /package/dist/esm/{new/context.js → utils/initAppContext.js} +0 -0
  133. /package/dist/esm-node/{new/constants.js → constants.js} +0 -0
  134. /package/dist/esm-node/{new/context.js → utils/initAppContext.js} +0 -0
  135. /package/dist/types/{new/constants.d.ts → constants.d.ts} +0 -0
  136. /package/dist/types/{new/run.d.ts → run/index.d.ts} +0 -0
  137. /package/dist/types/{new → utils}/getConfigFile.d.ts +0 -0
  138. /package/dist/types/{new/context.d.ts → utils/initAppContext.d.ts} +0 -0
@@ -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.useAppContext();
7
+ appContext = api.getAppContext();
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 { printInstructionsCompat } from "../utils/printInstructions";
9
+ import { printInstructions } 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, hookRunners, distDirectory, appDirectory, internalDirectory, port, metaName, serverRoutes, serverConfigFile, apiOnly, runMode, meta, serverConfigPath, pluginInstances, app;
12
+ var _userConfig_source, _userConfig_output_distPath, appContext, userConfig, hooks, 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.useAppContext();
17
- userConfig = api.useResolvedConfigContext();
18
- hookRunners = api.useHookRunners();
16
+ appContext = api.getAppContext();
17
+ userConfig = api.getNormalizedConfig();
18
+ hooks = api.getHooks();
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
- printInstructionsCompat(hookRunners, appContext, userConfig)
72
+ printInstructions(hooks, appContext, userConfig)
73
73
  ];
74
74
  case 1:
75
75
  _state2.sent();
@@ -1,6 +1,7 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
2
3
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
- import { getModifyHtmlPartials } from "../../plugins/analyze/getHtmlTemplate";
4
+ import { getModifyHtmlPartials } from "../plugins/analyze/getHtmlTemplate";
4
5
  import { transformHookParams, transformHookResult, transformHookRunner } from "./utils";
5
6
  function getHookRunners(context) {
6
7
  var hooks = context.hooks;
@@ -173,6 +174,40 @@ function getHookRunners(context) {
173
174
  return _ref.apply(this, arguments);
174
175
  };
175
176
  }(),
177
+ // test plugin hooks
178
+ jestConfig: function() {
179
+ var _ref = _async_to_generator(function(utils) {
180
+ var result;
181
+ return _ts_generator(this, function(_state) {
182
+ switch (_state.label) {
183
+ case 0:
184
+ return [
185
+ 4,
186
+ hooks === null || hooks === void 0 ? void 0 : hooks.jestConfig.call(utils, function(utils2) {
187
+ return utils2;
188
+ })
189
+ ];
190
+ case 1:
191
+ result = _state.sent();
192
+ return [
193
+ 2,
194
+ result
195
+ ];
196
+ }
197
+ });
198
+ });
199
+ return function(utils) {
200
+ return _ref.apply(this, arguments);
201
+ };
202
+ }(),
203
+ afterTest: /* @__PURE__ */ _async_to_generator(function() {
204
+ return _ts_generator(this, function(_state) {
205
+ return [
206
+ 2,
207
+ hooks.afterTest.call()
208
+ ];
209
+ });
210
+ }),
176
211
  /**
177
212
  * common hooks
178
213
  */
@@ -374,35 +409,25 @@ function getHookRunners(context) {
374
409
  /**
375
410
  * @deprecated
376
411
  */
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
- });
412
+ registerDev: /* @__PURE__ */ _async_to_generator(function() {
413
+ return _ts_generator(this, function(_state) {
414
+ return [
415
+ 2,
416
+ hooks.registerDev.call()
417
+ ];
385
418
  });
386
- return function(params) {
387
- return _ref.apply(this, arguments);
388
- };
389
- }(),
419
+ }),
390
420
  /**
391
421
  * @deprecated
392
422
  */
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
- });
423
+ registerBuildPlatform: /* @__PURE__ */ _async_to_generator(function() {
424
+ return _ts_generator(this, function(_state) {
425
+ return [
426
+ 2,
427
+ hooks.registerBuildPlatform.call()
428
+ ];
401
429
  });
402
- return function(params) {
403
- return _ref.apply(this, arguments);
404
- };
405
- }(),
430
+ }),
406
431
  /**
407
432
  * @deprecated
408
433
  */
@@ -425,33 +450,57 @@ function handleSetupResult(setupResult, api) {
425
450
  if (typeof fn === "function") {
426
451
  var newAPI = transformHookRunner(key);
427
452
  if (api[newAPI]) {
428
- api[newAPI](function() {
429
- var _ref = _async_to_generator(function(params) {
430
- var _tmp;
431
- return _ts_generator(this, function(_state) {
432
- switch (_state.label) {
433
- case 0:
434
- _tmp = [
435
- key
436
- ];
437
- return [
438
- 4,
439
- fn(transformHookParams(key, params))
440
- ];
441
- case 1:
453
+ api[newAPI](/* @__PURE__ */ _async_to_generator(function() {
454
+ var _len, params, _key, _transformHookParams, isMultiple, transformParams, _tmp, _tmp1;
455
+ var _arguments = arguments;
456
+ return _ts_generator(this, function(_state) {
457
+ switch (_state.label) {
458
+ case 0:
459
+ for (_len = _arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
460
+ params[_key] = _arguments[_key];
461
+ }
462
+ _transformHookParams = transformHookParams(key, params), isMultiple = _transformHookParams.isMultiple, transformParams = _transformHookParams.params;
463
+ if (!isMultiple)
442
464
  return [
443
- 2,
444
- transformHookResult.apply(void 0, _tmp.concat([
445
- _state.sent()
446
- ]))
465
+ 3,
466
+ 2
447
467
  ];
448
- }
449
- });
468
+ _tmp = [
469
+ key
470
+ ];
471
+ return [
472
+ 4,
473
+ fn.apply(void 0, _to_consumable_array(transformParams))
474
+ ];
475
+ case 1:
476
+ return [
477
+ 2,
478
+ transformHookResult.apply(void 0, _tmp.concat([
479
+ _state.sent()
480
+ ]))
481
+ ];
482
+ case 2:
483
+ _tmp1 = [
484
+ key
485
+ ];
486
+ return [
487
+ 4,
488
+ fn(transformParams)
489
+ ];
490
+ case 3:
491
+ return [
492
+ 2,
493
+ transformHookResult.apply(void 0, _tmp1.concat([
494
+ _state.sent()
495
+ ]))
496
+ ];
497
+ case 4:
498
+ return [
499
+ 2
500
+ ];
501
+ }
450
502
  });
451
- return function(params) {
452
- return _ref.apply(this, arguments);
453
- };
454
- }());
503
+ }));
455
504
  }
456
505
  }
457
506
  });
@@ -1,5 +1,5 @@
1
1
  import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties";
2
- import { createCollectAsyncHook } from "@modern-js/plugin-v2";
2
+ import { createAsyncHook, createCollectAsyncHook } from "@modern-js/plugin-v2";
3
3
  import { getHookRunners } from "./hooks";
4
4
  var compatPlugin = function() {
5
5
  return {
@@ -30,9 +30,14 @@ var compatPlugin = function() {
30
30
  };
31
31
  },
32
32
  registryHooks: {
33
- appendEntryCode: createCollectAsyncHook()
33
+ appendEntryCode: createCollectAsyncHook(),
34
+ jestConfig: createAsyncHook(),
35
+ afterTest: createAsyncHook()
34
36
  },
35
- setup: function(_api) {
37
+ setup: function(api) {
38
+ api.updateAppContext({
39
+ toolsType: "app-tools"
40
+ });
36
41
  }
37
42
  };
38
43
  };
@@ -1,3 +1,4 @@
1
+ import { getModifyHtmlPartials } from "../plugins/analyze/getHtmlTemplate";
1
2
  function transformHookRunner(hookRunnerName) {
2
3
  switch (hookRunnerName) {
3
4
  case "beforeConfig":
@@ -48,25 +49,45 @@ function transformHookParams(hookRunnerName, params) {
48
49
  switch (hookRunnerName) {
49
50
  case "resolvedConfig":
50
51
  return {
51
- resolved: params
52
+ isMultiple: false,
53
+ params: {
54
+ resolved: params[0]
55
+ }
52
56
  };
53
57
  case "htmlPartials":
54
58
  return {
55
- partials: {
56
- top: params.partials.top.current,
57
- head: params.partials.head.current,
58
- body: params.partials.body.current
59
- },
60
- entrypoint: params.entrypoint
59
+ isMultiple: false,
60
+ params: {
61
+ partials: {
62
+ top: params[0].partials.top.current,
63
+ head: params[0].partials.head.current,
64
+ body: params[0].partials.body.current
65
+ },
66
+ entrypoint: params[0].entrypoint
67
+ }
61
68
  };
69
+ case "jestConfig": {
70
+ return {
71
+ isMultiple: true,
72
+ params
73
+ };
74
+ }
62
75
  default:
63
- return params;
76
+ return {
77
+ isMultiple: false,
78
+ params: params[0]
79
+ };
64
80
  }
65
81
  }
66
82
  function transformHookResult(hookRunnerName, result) {
67
83
  switch (hookRunnerName) {
68
84
  case "resolvedConfig":
69
85
  return result.resolved;
86
+ case "htmlPartials":
87
+ return {
88
+ partials: getModifyHtmlPartials(result.partials),
89
+ entrypoint: result.entrypoint
90
+ };
70
91
  default:
71
92
  return result;
72
93
  }
@@ -5,7 +5,18 @@ function createDefaultConfig(appContext) {
5
5
  var dev = {
6
6
  // `dev.port` should not have a default value
7
7
  // because we will use `server.port` by default
8
- port: void 0
8
+ port: void 0,
9
+ cliShortcuts: {
10
+ help: false,
11
+ // does not support restart server and print urls yet
12
+ custom: function() {
13
+ var shortcuts = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
14
+ return shortcuts.filter(function(param) {
15
+ var key = param.key;
16
+ return key !== "r" && key !== "u";
17
+ });
18
+ }
19
+ }
9
20
  };
10
21
  var output = {
11
22
  distPath: {
@@ -21,7 +21,6 @@ function transformNormalizedConfig(config) {
21
21
  server,
22
22
  cliOptions,
23
23
  testing,
24
- devtools: {},
25
24
  builderPlugins: [],
26
25
  plugins,
27
26
  security: {},
package/dist/esm/index.js CHANGED
@@ -1,5 +1,248 @@
1
- import { appTools } from "./new/index";
2
- import { initAppContext } from "./new/index";
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
+ };
3
246
  import { defineConfig, defineLegacyConfig } from "./defineConfig";
4
247
  import { mergeConfig } from "@modern-js/core";
5
248
  import { dev } from "./commands/dev";
@@ -3,9 +3,8 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
3
3
  import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties";
4
4
  import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
5
5
  import { _ as _type_of } from "@swc/helpers/_/_type_of";
6
- import fs from "fs";
7
6
  import path from "path";
8
- import { SERVER_BUNDLE_DIRECTORY, SERVER_WORKER_BUNDLE_DIRECTORY, getEntryOptions, isPlainObject, removeLeadingSlash, removeTailSlash, urlJoin } from "@modern-js/utils";
7
+ import { fs, ROUTE_SPEC_FILE, SERVER_BUNDLE_DIRECTORY, SERVER_WORKER_BUNDLE_DIRECTORY, getEntryOptions, isPlainObject, removeLeadingSlash, removeTailSlash, urlJoin } from "@modern-js/utils";
9
8
  import { isMainEntry } from "../../utils/routes";
10
9
  import { walkDirectory } from "./utils";
11
10
  var applyBaseUrl = function(baseUrl, routes) {
@@ -132,6 +131,16 @@ var getServerRoutes = function(entrypoints, param) {
132
131
  var toPosix = function(pathStr) {
133
132
  return pathStr.split(path.sep).join(path.posix.sep);
134
133
  };
134
+ var getProdServerRoutes = function(distDirectory) {
135
+ var routeJSON = path.join(distDirectory, ROUTE_SPEC_FILE);
136
+ try {
137
+ var routes = fs.readJSONSync(routeJSON).routes;
138
+ return routes;
139
+ } catch (e) {
140
+ throw new Error("Failed to read routes from ".concat(routeJSON, ", please check if the file exists."));
141
+ }
142
+ };
135
143
  export {
144
+ getProdServerRoutes,
136
145
  getServerRoutes
137
146
  };