@modern-js/app-tools 2.63.1 → 2.63.2

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 (117) 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 +5 -5
  9. package/dist/cjs/{new/compat → compat}/index.js +4 -1
  10. package/dist/cjs/config/default.js +6 -1
  11. package/dist/cjs/config/legacy/index.js +0 -1
  12. package/dist/cjs/index.js +154 -5
  13. package/dist/cjs/plugins/analyze/getServerRoutes.js +12 -2
  14. package/dist/cjs/plugins/analyze/index.js +25 -10
  15. package/dist/cjs/plugins/analyze/utils.js +6 -0
  16. package/dist/cjs/plugins/serverBuild.js +30 -32
  17. package/dist/cjs/{new/run.js → run/index.js} +6 -6
  18. package/dist/cjs/{new → utils}/getConfigFile.js +1 -1
  19. package/dist/cjs/{new/context.js → utils/initAppContext.js} +3 -3
  20. package/dist/cjs/{new/utils/index.js → utils/isAutoLoadPlugins.js} +6 -6
  21. package/dist/cjs/utils/loadPlugins.js +35 -4
  22. package/dist/cjs/utils/printInstructions.js +2 -11
  23. package/dist/cjs/utils/restart.js +2 -2
  24. package/dist/esm/commands/build.js +18 -12
  25. package/dist/esm/commands/deploy.js +6 -6
  26. package/dist/esm/commands/dev.js +11 -11
  27. package/dist/esm/commands/index.js +8 -8
  28. package/dist/esm/commands/inspect.js +1 -1
  29. package/dist/esm/commands/serve.js +6 -6
  30. package/dist/esm/{new/compat → compat}/hooks.js +15 -25
  31. package/dist/esm/{new/compat → compat}/index.js +4 -1
  32. package/dist/esm/config/default.js +12 -1
  33. package/dist/esm/config/legacy/index.js +0 -1
  34. package/dist/esm/index.js +245 -2
  35. package/dist/esm/plugins/analyze/getServerRoutes.js +11 -2
  36. package/dist/esm/plugins/analyze/index.js +76 -34
  37. package/dist/esm/plugins/analyze/utils.js +5 -0
  38. package/dist/esm/plugins/serverBuild.js +52 -56
  39. package/dist/esm/{new/run.js → run/index.js} +6 -6
  40. package/dist/esm/{new → utils}/getConfigFile.js +1 -1
  41. package/dist/esm/{new/utils/index.js → utils/isAutoLoadPlugins.js} +6 -6
  42. package/dist/esm/utils/loadPlugins.js +95 -7
  43. package/dist/esm/utils/printInstructions.js +1 -28
  44. package/dist/esm/utils/restart.js +3 -3
  45. package/dist/esm-node/commands/build.js +19 -13
  46. package/dist/esm-node/commands/deploy.js +5 -5
  47. package/dist/esm-node/commands/dev.js +12 -12
  48. package/dist/esm-node/commands/index.js +6 -6
  49. package/dist/esm-node/commands/inspect.js +1 -1
  50. package/dist/esm-node/commands/serve.js +5 -5
  51. package/dist/esm-node/{new/compat → compat}/hooks.js +5 -5
  52. package/dist/esm-node/{new/compat → compat}/index.js +4 -1
  53. package/dist/esm-node/config/default.js +6 -1
  54. package/dist/esm-node/config/legacy/index.js +0 -1
  55. package/dist/esm-node/index.js +140 -2
  56. package/dist/esm-node/plugins/analyze/getServerRoutes.js +11 -2
  57. package/dist/esm-node/plugins/analyze/index.js +26 -11
  58. package/dist/esm-node/plugins/analyze/utils.js +5 -0
  59. package/dist/esm-node/plugins/serverBuild.js +30 -32
  60. package/dist/esm-node/{new/run.js → run/index.js} +6 -6
  61. package/dist/esm-node/{new → utils}/getConfigFile.js +1 -1
  62. package/dist/esm-node/{new/utils/index.js → utils/isAutoLoadPlugins.js} +2 -2
  63. package/dist/esm-node/utils/loadPlugins.js +34 -4
  64. package/dist/esm-node/utils/printInstructions.js +1 -9
  65. package/dist/esm-node/utils/restart.js +2 -2
  66. package/dist/types/commands/build.d.ts +2 -2
  67. package/dist/types/commands/deploy.d.ts +2 -2
  68. package/dist/types/commands/dev.d.ts +2 -2
  69. package/dist/types/commands/index.d.ts +6 -6
  70. package/dist/types/commands/inspect.d.ts +2 -2
  71. package/dist/types/commands/serve.d.ts +2 -2
  72. package/dist/types/{new/compat → compat}/hooks.d.ts +2 -2
  73. package/dist/types/compat/index.d.ts +2 -0
  74. package/dist/types/index.d.ts +5 -3
  75. package/dist/types/plugins/analyze/getServerRoutes.d.ts +1 -0
  76. package/dist/types/plugins/analyze/utils.d.ts +1 -0
  77. package/dist/types/plugins/serverBuild.d.ts +2 -2
  78. package/dist/types/types/config/index.d.ts +0 -1
  79. package/dist/types/types/index.d.ts +2 -0
  80. package/dist/types/types/new.d.ts +11 -16
  81. package/dist/types/utils/generateWatchFiles.d.ts +2 -2
  82. package/dist/types/utils/isAutoLoadPlugins.d.ts +1 -0
  83. package/dist/types/utils/loadPlugins.d.ts +13 -3
  84. package/dist/types/utils/printInstructions.d.ts +1 -3
  85. package/dist/types/utils/restart.d.ts +2 -3
  86. package/package.json +23 -23
  87. package/dist/cjs/hooks.js +0 -60
  88. package/dist/cjs/new/index.js +0 -79
  89. package/dist/cjs/new/loadPlugins.js +0 -57
  90. package/dist/cjs/old.js +0 -179
  91. package/dist/esm/hooks.js +0 -36
  92. package/dist/esm/new/index.js +0 -55
  93. package/dist/esm/new/loadPlugins.js +0 -94
  94. package/dist/esm/old.js +0 -258
  95. package/dist/esm-node/hooks.js +0 -36
  96. package/dist/esm-node/new/index.js +0 -52
  97. package/dist/esm-node/new/loadPlugins.js +0 -33
  98. package/dist/esm-node/old.js +0 -140
  99. package/dist/types/hooks.d.ts +0 -2
  100. package/dist/types/new/compat/index.d.ts +0 -2
  101. package/dist/types/new/index.d.ts +0 -6
  102. package/dist/types/new/loadPlugins.d.ts +0 -9
  103. package/dist/types/new/utils/index.d.ts +0 -1
  104. package/dist/types/old.d.ts +0 -13
  105. /package/dist/cjs/{new/compat → compat}/utils.js +0 -0
  106. /package/dist/cjs/{new/constants.js → constants.js} +0 -0
  107. /package/dist/esm/{new/compat → compat}/utils.js +0 -0
  108. /package/dist/esm/{new/constants.js → constants.js} +0 -0
  109. /package/dist/esm/{new/context.js → utils/initAppContext.js} +0 -0
  110. /package/dist/esm-node/{new/compat → compat}/utils.js +0 -0
  111. /package/dist/esm-node/{new/constants.js → constants.js} +0 -0
  112. /package/dist/esm-node/{new/context.js → utils/initAppContext.js} +0 -0
  113. /package/dist/types/{new/compat → compat}/utils.d.ts +0 -0
  114. /package/dist/types/{new/constants.d.ts → constants.d.ts} +0 -0
  115. /package/dist/types/{new/run.d.ts → run/index.d.ts} +0 -0
  116. /package/dist/types/{new → utils}/getConfigFile.d.ts +0 -0
  117. /package/dist/types/{new/context.d.ts → utils/initAppContext.d.ts} +0 -0
package/bin/modern.js CHANGED
@@ -10,7 +10,7 @@ if (!process.env.MODERN_JS_VERSION) {
10
10
  process.env.MODERN_JS_VERSION = version;
11
11
  }
12
12
 
13
- require('../dist/cjs/new/run.js').run({
13
+ require('../dist/cjs/run/index.js').run({
14
14
  internalPlugins: {
15
15
  cli: INTERNAL_APP_TOOLS_PLUGINS,
16
16
  autoLoad: INTERNAL_APP_TOOLS_RUNTIME_PLUGINS,
@@ -31,7 +31,6 @@ __export(build_exports, {
31
31
  build: () => build
32
32
  });
33
33
  module.exports = __toCommonJS(build_exports);
34
- var import_core = require("@modern-js/core");
35
34
  var import_utils = require("@modern-js/utils");
36
35
  var import_config = require("../utils/config");
37
36
  var import_loadPlugins = require("../utils/loadPlugins");
@@ -42,9 +41,9 @@ const build = async (api, options) => {
42
41
  if (options === null || options === void 0 ? void 0 : options.analyze) {
43
42
  process.env.BUNDLE_ANALYZE = "true";
44
43
  }
45
- let resolvedConfig = api.useResolvedConfigContext();
46
- const appContext = api.useAppContext();
47
- const hookRunners = api.useHookRunners();
44
+ const resolvedConfig = api.getNormalizedConfig();
45
+ const appContext = api.getAppContext();
46
+ const hooks = api.getHooks();
48
47
  await (0, import_loadPlugins.loadServerPlugins)(api, appContext.appDirectory, appContext.metaName);
49
48
  if (appContext.moduleType && appContext.moduleType === "module") {
50
49
  var _resolvedConfig_source1;
@@ -59,9 +58,12 @@ const build = async (api, options) => {
59
58
  const { apiOnly } = appContext;
60
59
  if (apiOnly) {
61
60
  const { appDirectory: appDirectory2, distDirectory: distDirectory2, serverConfigFile: serverConfigFile2 } = appContext;
62
- await hookRunners.beforeBuild({
61
+ await hooks.onBeforeBuild.call({
62
+ environments: {},
63
63
  // "null" bundlerConfigs
64
- bundlerConfigs: void 0
64
+ bundlerConfigs: void 0,
65
+ isFirstCompile: false,
66
+ isWatch: false
65
67
  });
66
68
  await (0, import_config.buildServerConfig)({
67
69
  appDirectory: appDirectory2,
@@ -69,17 +71,21 @@ const build = async (api, options) => {
69
71
  configFile: serverConfigFile2
70
72
  });
71
73
  await (0, import_routes.generateRoutes)(appContext);
72
- await hookRunners.afterBuild({
74
+ await hooks.onAfterBuild.call({
75
+ environments: {},
73
76
  // "null" stats
74
- stats: void 0
77
+ stats: void 0,
78
+ isFirstCompile: false,
79
+ isWatch: false
75
80
  });
76
81
  return;
77
82
  }
78
- resolvedConfig = {
79
- ...resolvedConfig,
80
- cliOptions: options
81
- };
82
- import_core.ResolvedConfigContext.set(resolvedConfig);
83
+ api.modifyResolvedConfig((config) => {
84
+ return {
85
+ ...config,
86
+ cliOptions: options
87
+ };
88
+ });
83
89
  const { distDirectory, appDirectory, serverConfigFile } = appContext;
84
90
  await (0, import_config.buildServerConfig)({
85
91
  appDirectory,
@@ -23,12 +23,12 @@ __export(deploy_exports, {
23
23
  module.exports = __toCommonJS(deploy_exports);
24
24
  var import_loadPlugins = require("../utils/loadPlugins");
25
25
  const deploy = async (api, options) => {
26
- const hookRunners = api.useHookRunners();
27
- const { metaName } = api.useAppContext();
26
+ const hooks = api.getHooks();
27
+ const { metaName } = api.getAppContext();
28
28
  await (0, import_loadPlugins.getServerPlugins)(api, metaName);
29
- await hookRunners.beforeDeploy(options);
30
- await hookRunners.deploy(options);
31
- await hookRunners.afterDeploy(options);
29
+ await hooks.onBeforeDeploy.call(options);
30
+ await hooks.deploy.call();
31
+ await hooks.onAfterDeploy.call(options);
32
32
  };
33
33
  // Annotate the CommonJS export names for ESM import in node:
34
34
  0 && (module.exports = {
@@ -32,7 +32,6 @@ __export(dev_exports, {
32
32
  });
33
33
  module.exports = __toCommonJS(dev_exports);
34
34
  var import_node_path = __toESM(require("node:path"));
35
- var import_core = require("@modern-js/core");
36
35
  var import_prod_server = require("@modern-js/prod-server");
37
36
  var import_server = require("@modern-js/server");
38
37
  var import_utils = require("@modern-js/utils");
@@ -47,9 +46,9 @@ const dev = async (api, options, devServerOptions) => {
47
46
  if (options.analyze) {
48
47
  process.env.BUNDLE_ANALYZE = "true";
49
48
  }
50
- let normalizedConfig = api.useResolvedConfigContext();
51
- const appContext = api.useAppContext();
52
- const hookRunners = api.useHookRunners();
49
+ const normalizedConfig = api.getNormalizedConfig();
50
+ const appContext = api.getAppContext();
51
+ const hooks = api.getHooks();
53
52
  if (appContext.moduleType && appContext.moduleType === "module") {
54
53
  var _normalizedConfig_source1;
55
54
  const { registerEsm } = await import("../esm/register-esm.mjs");
@@ -60,11 +59,12 @@ const dev = async (api, options, devServerOptions) => {
60
59
  });
61
60
  }
62
61
  await (0, import_register.registerCompiler)(appContext.appDirectory, appContext.distDirectory, normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_source = normalizedConfig.source) === null || _normalizedConfig_source === void 0 ? void 0 : _normalizedConfig_source.alias);
63
- normalizedConfig = {
64
- ...normalizedConfig,
65
- cliOptions: options
66
- };
67
- import_core.ResolvedConfigContext.set(normalizedConfig);
62
+ api.modifyResolvedConfig((config) => {
63
+ return {
64
+ ...config,
65
+ cliOptions: options
66
+ };
67
+ });
68
68
  const { appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverRoutes } = appContext;
69
69
  await (0, import_config.buildServerConfig)({
70
70
  appDirectory,
@@ -74,7 +74,7 @@ const dev = async (api, options, devServerOptions) => {
74
74
  });
75
75
  const meta = (0, import_utils.getMeta)(metaName);
76
76
  const serverConfigPath = import_node_path.default.resolve(appDirectory, import_utils.SERVER_DIR, `${meta}.server`);
77
- await hookRunners.beforeDev();
77
+ await hooks.onBeforeDev.call();
78
78
  if (!appContext.builder && !apiOnly) {
79
79
  throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
80
80
  }
@@ -113,7 +113,7 @@ const dev = async (api, options, devServerOptions) => {
113
113
  port,
114
114
  host
115
115
  }, () => {
116
- (0, import_printInstructions.printInstructionsCompat)(hookRunners, appContext, normalizedConfig);
116
+ (0, import_printInstructions.printInstructions)(hooks, appContext, normalizedConfig);
117
117
  });
118
118
  } else {
119
119
  const { server, afterListen } = await (0, import_server.createDevServer)({
@@ -41,8 +41,8 @@ var import_uni_builder = require("@modern-js/uni-builder");
41
41
  var import_utils = require("@modern-js/utils");
42
42
  var import_locale = require("../locale");
43
43
  const devCommand = async (program, api) => {
44
- const runner = api.useHookRunners();
45
- const devToolMetas = await runner.registerDev();
44
+ const hooks = api.getHooks();
45
+ const devToolMetas = await hooks.registerDev.call();
46
46
  const devProgram = program.command("dev").alias("start").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.dev.describe)).option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).option("-e --entry [entry...]", import_locale.i18n.t(import_locale.localeKeys.command.dev.entry)).option("--analyze", import_locale.i18n.t(import_locale.localeKeys.command.shared.analyze)).option("--api-only", import_locale.i18n.t(import_locale.localeKeys.command.dev.apiOnly)).option("--web-only", import_locale.i18n.t(import_locale.localeKeys.command.dev.webOnly)).action(async (options) => {
47
47
  const { dev } = await import("./dev.js");
48
48
  await dev(api, options);
@@ -53,7 +53,7 @@ const devCommand = async (program, api) => {
53
53
  }
54
54
  for (const subCmd of meta.subCommands) {
55
55
  devProgram.command(subCmd).action(async (options = {}) => {
56
- const { appDirectory } = api.useAppContext();
56
+ const { appDirectory } = api.getAppContext();
57
57
  const { isTypescript } = await import("@modern-js/utils");
58
58
  await meta.action(options, {
59
59
  isTsProject: isTypescript(appDirectory)
@@ -63,8 +63,8 @@ const devCommand = async (program, api) => {
63
63
  }
64
64
  };
65
65
  const buildCommand = async (program, api) => {
66
- const runner = api.useHookRunners();
67
- const platformBuilders = await runner.registerBuildPlatform();
66
+ const hooks = api.getHooks();
67
+ const platformBuilders = await hooks.registerBuildPlatform.call();
68
68
  const buildProgram = program.command("build").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.build.describe)).option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).option("--analyze", import_locale.i18n.t(import_locale.localeKeys.command.shared.analyze)).action(async (options) => {
69
69
  const { build } = await import("./build.js");
70
70
  await build(api, options);
@@ -73,7 +73,7 @@ const buildCommand = async (program, api) => {
73
73
  const platforms = (0, import_uni_builder.castArray)(platformBuilder.platform);
74
74
  for (const platform of platforms) {
75
75
  buildProgram.command(platform).action(async () => {
76
- const { appDirectory } = api.useAppContext();
76
+ const { appDirectory } = api.getAppContext();
77
77
  const { isTypescript } = await import("@modern-js/utils");
78
78
  await platformBuilder.build(platform, {
79
79
  isTsProject: isTypescript(appDirectory)
@@ -22,7 +22,7 @@ __export(inspect_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(inspect_exports);
24
24
  const inspect = async (api, options) => {
25
- const appContext = api.useAppContext();
25
+ const appContext = api.getAppContext();
26
26
  if (!appContext.builder) {
27
27
  throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
28
28
  }
@@ -38,9 +38,9 @@ var import_loadPlugins = require("../utils/loadPlugins");
38
38
  var import_printInstructions = require("../utils/printInstructions");
39
39
  const start = async (api) => {
40
40
  var _userConfig_source, _userConfig_output_distPath;
41
- const appContext = api.useAppContext();
42
- const userConfig = api.useResolvedConfigContext();
43
- const hookRunners = api.useHookRunners();
41
+ const appContext = api.getAppContext();
42
+ const userConfig = api.getNormalizedConfig();
43
+ const hooks = api.getHooks();
44
44
  const { distDirectory, appDirectory, internalDirectory, port, metaName, serverRoutes, serverConfigFile } = appContext;
45
45
  import_utils.logger.info(`Starting production server...`);
46
46
  const apiOnly = await (0, import_utils.isApiOnly)(appContext.appDirectory, userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_source = userConfig.source) === null || _userConfig_source === void 0 ? void 0 : _userConfig_source.entriesDir, appContext.apiDirectory);
@@ -77,7 +77,7 @@ const start = async (api) => {
77
77
  runMode
78
78
  });
79
79
  app.listen(port, async () => {
80
- await (0, import_printInstructions.printInstructionsCompat)(hookRunners, appContext, userConfig);
80
+ await (0, import_printInstructions.printInstructions)(hooks, appContext, userConfig);
81
81
  });
82
82
  };
83
83
  // Annotate the CommonJS export names for ESM import in node:
@@ -22,7 +22,7 @@ __export(hooks_exports, {
22
22
  handleSetupResult: () => handleSetupResult
23
23
  });
24
24
  module.exports = __toCommonJS(hooks_exports);
25
- var import_getHtmlTemplate = require("../../plugins/analyze/getHtmlTemplate");
25
+ var import_getHtmlTemplate = require("../plugins/analyze/getHtmlTemplate");
26
26
  var import_utils = require("./utils");
27
27
  function getHookRunners(context) {
28
28
  const { hooks } = context;
@@ -134,14 +134,14 @@ function getHookRunners(context) {
134
134
  /**
135
135
  * @deprecated
136
136
  */
137
- registerDev: async (params) => {
138
- return hooks.registerDev.call(params);
137
+ registerDev: async () => {
138
+ return hooks.registerDev.call();
139
139
  },
140
140
  /**
141
141
  * @deprecated
142
142
  */
143
- registerBuildPlatform: async (params) => {
144
- return hooks.registerBuildPlatform.call(params);
143
+ registerBuildPlatform: async () => {
144
+ return hooks.registerBuildPlatform.call();
145
145
  },
146
146
  /**
147
147
  * @deprecated
@@ -51,7 +51,10 @@ const compatPlugin = () => ({
51
51
  registryHooks: {
52
52
  appendEntryCode: (0, import_plugin_v2.createCollectAsyncHook)()
53
53
  },
54
- setup: (_api) => {
54
+ setup: (api) => {
55
+ api.updateAppContext({
56
+ toolsType: "app-tools"
57
+ });
55
58
  }
56
59
  });
57
60
  // Annotate the CommonJS export names for ESM import in node:
@@ -28,7 +28,12 @@ function createDefaultConfig(appContext) {
28
28
  const dev = {
29
29
  // `dev.port` should not have a default value
30
30
  // because we will use `server.port` by default
31
- port: void 0
31
+ port: void 0,
32
+ cliShortcuts: {
33
+ help: false,
34
+ // does not support restart server and print urls yet
35
+ custom: (shortcuts = []) => shortcuts.filter(({ key }) => key !== "r" && key !== "u")
36
+ }
32
37
  };
33
38
  const output = {
34
39
  distPath: {
@@ -45,7 +45,6 @@ function transformNormalizedConfig(config) {
45
45
  server,
46
46
  cliOptions,
47
47
  testing,
48
- devtools: {},
49
48
  builderPlugins: [],
50
49
  plugins,
51
50
  security: {},
package/dist/cjs/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -16,25 +18,171 @@ var __copyProps = (to, from, except, desc) => {
16
18
  return to;
17
19
  };
18
20
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
19
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
30
  var src_exports = {};
21
31
  __export(src_exports, {
22
- appTools: () => import_new.appTools,
32
+ appTools: () => appTools,
23
33
  default: () => src_default,
24
34
  defineConfig: () => import_defineConfig.defineConfig,
25
35
  defineLegacyConfig: () => import_defineConfig.defineLegacyConfig,
26
36
  dev: () => import_dev.dev,
27
- initAppContext: () => import_new2.initAppContext,
37
+ initAppContext: () => import_initAppContext.initAppContext,
28
38
  mergeConfig: () => import_core.mergeConfig
29
39
  });
30
40
  module.exports = __toCommonJS(src_exports);
31
- var import_new = require("./new/index");
32
- var import_new2 = require("./new/index");
41
+ var import_language_detector = require("@modern-js/plugin-i18n/language-detector");
42
+ var import_plugin_v2 = require("@modern-js/plugin-v2");
43
+ var import_uni_builder = require("@modern-js/uni-builder");
44
+ var import_utils = require("@modern-js/utils");
45
+ var import_commands = require("./commands");
46
+ var import_compat = require("./compat");
47
+ var import_constants = require("./constants");
48
+ var import_locale = require("./locale");
49
+ var import_analyze = __toESM(require("./plugins/analyze"));
50
+ var import_deploy = __toESM(require("./plugins/deploy"));
51
+ var import_initialize = __toESM(require("./plugins/initialize"));
52
+ var import_serverBuild = __toESM(require("./plugins/serverBuild"));
53
+ var import_generateWatchFiles = require("./utils/generateWatchFiles");
54
+ var import_initAppContext = require("./utils/initAppContext");
55
+ var import_restart = require("./utils/restart");
56
+ __reExport(src_exports, require("./defineConfig"), module.exports);
33
57
  var import_defineConfig = require("./defineConfig");
34
58
  var import_core = require("@modern-js/core");
35
59
  var import_dev = require("./commands/dev");
36
60
  __reExport(src_exports, require("./types"), module.exports);
37
- var src_default = import_new.appTools;
61
+ const appTools = (options = {
62
+ // default webpack to be compatible with original projects
63
+ bundler: "webpack"
64
+ }) => ({
65
+ name: "@modern-js/app-tools",
66
+ usePlugins: [
67
+ (0, import_compat.compatPlugin)(),
68
+ (0, import_initialize.default)({
69
+ bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
70
+ "rspack",
71
+ "experimental-rspack"
72
+ ].includes(options.bundler) ? "rspack" : "webpack"
73
+ }),
74
+ (0, import_analyze.default)({
75
+ bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
76
+ "rspack",
77
+ "experimental-rspack"
78
+ ].includes(options.bundler) ? "rspack" : "webpack"
79
+ }),
80
+ (0, import_serverBuild.default)(),
81
+ (0, import_deploy.default)()
82
+ ],
83
+ post: [
84
+ "@modern-js/plugin-initialize",
85
+ "@modern-js/plugin-analyze",
86
+ "@modern-js/plugin-ssr",
87
+ "@modern-js/plugin-document",
88
+ "@modern-js/plugin-state",
89
+ "@modern-js/plugin-router",
90
+ "@modern-js/plugin-router-v5",
91
+ "@modern-js/plugin-polyfill"
92
+ ],
93
+ registryHooks: {
94
+ onBeforeConfig: (0, import_plugin_v2.createAsyncHook)(),
95
+ onAfterPrepare: (0, import_plugin_v2.createAsyncHook)(),
96
+ deploy: (0, import_plugin_v2.createAsyncHook)(),
97
+ _internalRuntimePlugins: (0, import_plugin_v2.createAsyncHook)(),
98
+ _internalServerPlugins: (0, import_plugin_v2.createAsyncHook)(),
99
+ checkEntryPoint: (0, import_plugin_v2.createAsyncHook)(),
100
+ modifyEntrypoints: (0, import_plugin_v2.createAsyncHook)(),
101
+ modifyFileSystemRoutes: (0, import_plugin_v2.createAsyncHook)(),
102
+ modifyServerRoutes: (0, import_plugin_v2.createAsyncHook)(),
103
+ generateEntryCode: (0, import_plugin_v2.createAsyncHook)(),
104
+ onBeforeGenerateRoutes: (0, import_plugin_v2.createAsyncHook)(),
105
+ onBeforePrintInstructions: (0, import_plugin_v2.createAsyncHook)(),
106
+ registerDev: (0, import_plugin_v2.createCollectAsyncHook)(),
107
+ registerBuildPlatform: (0, import_plugin_v2.createCollectAsyncHook)(),
108
+ addRuntimeExports: (0, import_plugin_v2.createAsyncHook)()
109
+ },
110
+ setup: (api) => {
111
+ var _userConfig_output;
112
+ const context = api.getAppContext();
113
+ const userConfig = api.getConfig();
114
+ const locale = (0, import_language_detector.getLocaleLanguage)();
115
+ import_locale.i18n.changeLanguage({
116
+ locale
117
+ });
118
+ api.updateAppContext((0, import_initAppContext.initAppContext)({
119
+ appDirectory: context.appDirectory,
120
+ options: {},
121
+ serverConfigFile: import_constants.DEFAULT_SERVER_CONFIG_FILE,
122
+ runtimeConfigFile: import_constants.DEFAULT_RUNTIME_CONFIG_FILE,
123
+ tempDir: (_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir
124
+ }));
125
+ api.addCommand(async ({ program }) => {
126
+ await (0, import_commands.devCommand)(program, api);
127
+ await (0, import_commands.buildCommand)(program, api);
128
+ (0, import_commands.serverCommand)(program, api);
129
+ (0, import_commands.deployCommand)(program, api);
130
+ (0, import_commands.newCommand)(program, locale);
131
+ (0, import_commands.inspectCommand)(program, api);
132
+ (0, import_commands.upgradeCommand)(program);
133
+ (0, import_utils.deprecatedCommands)(program);
134
+ });
135
+ api.onPrepare(async () => {
136
+ const command = (0, import_utils.getCommand)();
137
+ if (command === "deploy") {
138
+ const isSkipBuild = [
139
+ "-s",
140
+ "--skip-build"
141
+ ].some((tag) => {
142
+ return (0, import_utils.getArgv)().includes(tag);
143
+ });
144
+ if (isSkipBuild) {
145
+ return;
146
+ }
147
+ }
148
+ if (command === "dev" || command === "start" || command === "build" || command === "deploy") {
149
+ const resolvedConfig = api.getNormalizedConfig();
150
+ if (resolvedConfig.output.cleanDistPath) {
151
+ const appContext = api.getAppContext();
152
+ await (0, import_utils.emptyDir)(appContext.distDirectory);
153
+ }
154
+ }
155
+ });
156
+ api.addWatchFiles(async () => {
157
+ const appContext = api.getAppContext();
158
+ const config = api.getNormalizedConfig();
159
+ const files = await (0, import_generateWatchFiles.generateWatchFiles)(appContext, config.source.configDir);
160
+ const watchFiles = (0, import_uni_builder.castArray)(config.dev.watchFiles);
161
+ watchFiles.forEach(({ type, paths }) => {
162
+ if (type === "reload-server") {
163
+ files.push(...Array.isArray(paths) ? paths : [
164
+ paths
165
+ ]);
166
+ }
167
+ });
168
+ return files;
169
+ });
170
+ api.onFileChanged(async (e) => {
171
+ const { filename, eventType, isPrivate } = e;
172
+ if (!isPrivate && (eventType === "change" || eventType === "unlink")) {
173
+ const { closeServer } = await import("./utils/createServer.js");
174
+ await closeServer();
175
+ await (0, import_restart.restart)(api.getHooks(), filename);
176
+ }
177
+ });
178
+ api.onBeforeRestart(() => {
179
+ (0, import_utils.cleanRequireCache)([
180
+ require.resolve("./plugins/analyze")
181
+ ]);
182
+ });
183
+ }
184
+ });
185
+ var src_default = appTools;
38
186
  // Annotate the CommonJS export names for ESM import in node:
39
187
  0 && (module.exports = {
40
188
  appTools,
@@ -43,5 +191,6 @@ var src_default = import_new.appTools;
43
191
  dev,
44
192
  initAppContext,
45
193
  mergeConfig,
194
+ ...require("./defineConfig"),
46
195
  ...require("./types")
47
196
  });
@@ -28,10 +28,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var getServerRoutes_exports = {};
30
30
  __export(getServerRoutes_exports, {
31
+ getProdServerRoutes: () => getProdServerRoutes,
31
32
  getServerRoutes: () => getServerRoutes
32
33
  });
33
34
  module.exports = __toCommonJS(getServerRoutes_exports);
34
- var import_fs = __toESM(require("fs"));
35
35
  var import_path = __toESM(require("path"));
36
36
  var import_utils = require("@modern-js/utils");
37
37
  var import_routes = require("../../utils/routes");
@@ -148,7 +148,7 @@ const collectStaticRoutes = (appContext, config) => {
148
148
  const ignoreFiles = [
149
149
  ".gitkeep"
150
150
  ];
151
- return import_fs.default.existsSync(publicFolder) ? (0, import_utils2.walkDirectory)(publicFolder).filter((filePath) => !ignoreFiles.includes(import_path.default.basename(filePath))).map((filePath) => {
151
+ return import_utils.fs.existsSync(publicFolder) ? (0, import_utils2.walkDirectory)(publicFolder).filter((filePath) => !ignoreFiles.includes(import_path.default.basename(filePath))).map((filePath) => {
152
152
  const urlPath = `${(0, import_utils.urlJoin)(toPosix(filePath).slice(toPosix(publicFolder).length))}`;
153
153
  return {
154
154
  urlPath: publicRoutes[(0, import_utils.removeLeadingSlash)(urlPath)] || urlPath,
@@ -163,7 +163,17 @@ const getServerRoutes = (entrypoints, { appContext, config }) => [
163
163
  ...collectStaticRoutes(appContext, config)
164
164
  ];
165
165
  const toPosix = (pathStr) => pathStr.split(import_path.default.sep).join(import_path.default.posix.sep);
166
+ const getProdServerRoutes = (distDirectory) => {
167
+ const routeJSON = import_path.default.join(distDirectory, import_utils.ROUTE_SPEC_FILE);
168
+ try {
169
+ const { routes } = import_utils.fs.readJSONSync(routeJSON);
170
+ return routes;
171
+ } catch (e) {
172
+ throw new Error(`Failed to read routes from ${routeJSON}, please check if the file exists.`);
173
+ }
174
+ };
166
175
  // Annotate the CommonJS export names for ESM import in node:
167
176
  0 && (module.exports = {
177
+ getProdServerRoutes,
168
178
  getServerRoutes
169
179
  });
@@ -62,10 +62,19 @@ var analyze_default = ({ bundler }) => ({
62
62
  }
63
63
  const apiOnly = await (0, import_utils.isApiOnly)(appContext.appDirectory, (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.entriesDir, appContext.apiDirectory);
64
64
  await hooks.addRuntimeExports.call();
65
+ const [{ getProdServerRoutes }] = await Promise.all([
66
+ import("./getServerRoutes.js")
67
+ ]);
65
68
  if (apiOnly) {
66
- const { routes: routes2 } = await hooks.modifyServerRoutes.call({
67
- routes: []
68
- });
69
+ const routes2 = [];
70
+ if ((0, import_utils2.checkIsServeCommand)()) {
71
+ routes2.push(...getProdServerRoutes(appContext.distDirectory));
72
+ } else {
73
+ const { routes: modifiedRoutes } = await hooks.modifyServerRoutes.call({
74
+ routes: []
75
+ });
76
+ routes2.push(...modifiedRoutes);
77
+ }
69
78
  debug(`server routes: %o`, routes2);
70
79
  api.updateAppContext({
71
80
  apiOnly,
@@ -82,13 +91,19 @@ var analyze_default = ({ bundler }) => ({
82
91
  entrypoints: await getBundleEntry(hooks, appContext, resolvedConfig)
83
92
  });
84
93
  debug(`entrypoints: %o`, entrypoints);
85
- const initialRoutes = getServerRoutes(entrypoints, {
86
- appContext,
87
- config: resolvedConfig
88
- });
89
- const { routes } = await hooks.modifyServerRoutes.call({
90
- routes: initialRoutes
91
- });
94
+ const routes = [];
95
+ if ((0, import_utils2.checkIsServeCommand)()) {
96
+ routes.push(...getProdServerRoutes(appContext.distDirectory));
97
+ } else {
98
+ const initialRoutes = getServerRoutes(entrypoints, {
99
+ appContext,
100
+ config: resolvedConfig
101
+ });
102
+ const { routes: modifiedRoutes } = await hooks.modifyServerRoutes.call({
103
+ routes: initialRoutes
104
+ });
105
+ routes.push(...modifiedRoutes);
106
+ }
92
107
  debug(`server routes: %o`, routes);
93
108
  appContext = {
94
109
  ...api.getAppContext(),
@@ -29,6 +29,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  var utils_exports = {};
30
30
  __export(utils_exports, {
31
31
  checkIsBuildCommands: () => checkIsBuildCommands,
32
+ checkIsServeCommand: () => checkIsServeCommand,
32
33
  getServerCombinedModueFile: () => getServerCombinedModueFile,
33
34
  isSubDirOrEqual: () => isSubDirOrEqual,
34
35
  parseModule: () => parseModule,
@@ -88,6 +89,10 @@ const checkIsBuildCommands = () => {
88
89
  const command = (0, import_utils.getCommand)();
89
90
  return buildCommands.includes(command);
90
91
  };
92
+ const checkIsServeCommand = () => {
93
+ const command = (0, import_utils.getCommand)();
94
+ return command === "serve";
95
+ };
91
96
  const isSubDirOrEqual = (parent, child) => {
92
97
  if (parent === child) {
93
98
  return true;
@@ -99,6 +104,7 @@ const isSubDirOrEqual = (parent, child) => {
99
104
  // Annotate the CommonJS export names for ESM import in node:
100
105
  0 && (module.exports = {
101
106
  checkIsBuildCommands,
107
+ checkIsServeCommand,
102
108
  getServerCombinedModueFile,
103
109
  isSubDirOrEqual,
104
110
  parseModule,