@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
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;
@@ -71,6 +71,14 @@ function getHookRunners(context) {
71
71
  const result = await (hooks === null || hooks === void 0 ? void 0 : hooks.appendEntryCode.call(params));
72
72
  return result;
73
73
  },
74
+ // test plugin hooks
75
+ jestConfig: async (utils) => {
76
+ const result = await (hooks === null || hooks === void 0 ? void 0 : hooks.jestConfig.call(utils, (utils2) => utils2));
77
+ return result;
78
+ },
79
+ afterTest: async () => {
80
+ return hooks.afterTest.call();
81
+ },
74
82
  /**
75
83
  * common hooks
76
84
  */
@@ -134,14 +142,14 @@ function getHookRunners(context) {
134
142
  /**
135
143
  * @deprecated
136
144
  */
137
- registerDev: async (params) => {
138
- return hooks.registerDev.call(params);
145
+ registerDev: async () => {
146
+ return hooks.registerDev.call();
139
147
  },
140
148
  /**
141
149
  * @deprecated
142
150
  */
143
- registerBuildPlatform: async (params) => {
144
- return hooks.registerBuildPlatform.call(params);
151
+ registerBuildPlatform: async () => {
152
+ return hooks.registerBuildPlatform.call();
145
153
  },
146
154
  /**
147
155
  * @deprecated
@@ -160,7 +168,14 @@ function handleSetupResult(setupResult, api) {
160
168
  if (typeof fn === "function") {
161
169
  const newAPI = (0, import_utils.transformHookRunner)(key);
162
170
  if (api[newAPI]) {
163
- api[newAPI](async (params) => (0, import_utils.transformHookResult)(key, await fn((0, import_utils.transformHookParams)(key, params))));
171
+ api[newAPI](async (...params) => {
172
+ const { isMultiple, params: transformParams } = (0, import_utils.transformHookParams)(key, params);
173
+ if (isMultiple) {
174
+ return (0, import_utils.transformHookResult)(key, await fn(...transformParams));
175
+ } else {
176
+ return (0, import_utils.transformHookResult)(key, await fn(transformParams));
177
+ }
178
+ });
164
179
  }
165
180
  }
166
181
  });
@@ -49,9 +49,14 @@ const compatPlugin = () => ({
49
49
  };
50
50
  },
51
51
  registryHooks: {
52
- appendEntryCode: (0, import_plugin_v2.createCollectAsyncHook)()
52
+ appendEntryCode: (0, import_plugin_v2.createCollectAsyncHook)(),
53
+ jestConfig: (0, import_plugin_v2.createAsyncHook)(),
54
+ afterTest: (0, import_plugin_v2.createAsyncHook)()
53
55
  },
54
- setup: (_api) => {
56
+ setup: (api) => {
57
+ api.updateAppContext({
58
+ toolsType: "app-tools"
59
+ });
55
60
  }
56
61
  });
57
62
  // Annotate the CommonJS export names for ESM import in node:
@@ -23,6 +23,7 @@ __export(utils_exports, {
23
23
  transformHookRunner: () => transformHookRunner
24
24
  });
25
25
  module.exports = __toCommonJS(utils_exports);
26
+ var import_getHtmlTemplate = require("../plugins/analyze/getHtmlTemplate");
26
27
  function transformHookRunner(hookRunnerName) {
27
28
  switch (hookRunnerName) {
28
29
  case "beforeConfig":
@@ -73,25 +74,45 @@ function transformHookParams(hookRunnerName, params) {
73
74
  switch (hookRunnerName) {
74
75
  case "resolvedConfig":
75
76
  return {
76
- resolved: params
77
+ isMultiple: false,
78
+ params: {
79
+ resolved: params[0]
80
+ }
77
81
  };
78
82
  case "htmlPartials":
79
83
  return {
80
- partials: {
81
- top: params.partials.top.current,
82
- head: params.partials.head.current,
83
- body: params.partials.body.current
84
- },
85
- entrypoint: params.entrypoint
84
+ isMultiple: false,
85
+ params: {
86
+ partials: {
87
+ top: params[0].partials.top.current,
88
+ head: params[0].partials.head.current,
89
+ body: params[0].partials.body.current
90
+ },
91
+ entrypoint: params[0].entrypoint
92
+ }
86
93
  };
94
+ case "jestConfig": {
95
+ return {
96
+ isMultiple: true,
97
+ params
98
+ };
99
+ }
87
100
  default:
88
- return params;
101
+ return {
102
+ isMultiple: false,
103
+ params: params[0]
104
+ };
89
105
  }
90
106
  }
91
107
  function transformHookResult(hookRunnerName, result) {
92
108
  switch (hookRunnerName) {
93
109
  case "resolvedConfig":
94
110
  return result.resolved;
111
+ case "htmlPartials":
112
+ return {
113
+ partials: (0, import_getHtmlTemplate.getModifyHtmlPartials)(result.partials),
114
+ entrypoint: result.entrypoint
115
+ };
95
116
  default:
96
117
  return result;
97
118
  }
@@ -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
  });