@modern-js/app-tools 2.63.1 → 2.63.3

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -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,
@@ -33,8 +33,8 @@ __export(netlify_exports, {
33
33
  module.exports = __toCommonJS(netlify_exports);
34
34
  var import_node_path = __toESM(require("node:path"));
35
35
  var import_utils = require("@modern-js/utils");
36
+ var import_ndepe = require("ndepe");
36
37
  var import_routes = require("../../../utils/routes");
37
- var import_dependencies = require("../dependencies");
38
38
  var import_utils2 = require("../utils");
39
39
  async function cleanDistDirectory(dir) {
40
40
  try {
@@ -136,12 +136,15 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
136
136
  if (!needModernServer) {
137
137
  return;
138
138
  }
139
- await (0, import_dependencies.handleDependencies)({
139
+ await (0, import_ndepe.nodeDepEmit)({
140
140
  appDir: appDirectory,
141
- serverRootDir: funcsDirectory,
141
+ sourceDir: funcsDirectory,
142
142
  includeEntries: [
143
143
  require.resolve("@modern-js/prod-server")
144
- ]
144
+ ],
145
+ copyWholePackage(pkgName) {
146
+ return pkgName === "@modern-js/utils";
147
+ }
145
148
  });
146
149
  }
147
150
  };
@@ -33,7 +33,7 @@ __export(node_exports, {
33
33
  module.exports = __toCommonJS(node_exports);
34
34
  var import_node_path = __toESM(require("node:path"));
35
35
  var import_utils = require("@modern-js/utils");
36
- var import_dependencies = require("../dependencies");
36
+ var import_ndepe = require("ndepe");
37
37
  var import_utils2 = require("../utils");
38
38
  const createNodePreset = (appContext, config) => {
39
39
  const { appDirectory, distDirectory, serverPlugins, moduleType } = appContext;
@@ -90,12 +90,15 @@ const createNodePreset = (appContext, config) => {
90
90
  const filter = (filePath) => {
91
91
  return !filePath.startsWith(staticDirectory);
92
92
  };
93
- await (0, import_dependencies.handleDependencies)({
93
+ await (0, import_ndepe.nodeDepEmit)({
94
94
  appDir: appDirectory,
95
- serverRootDir: outputDirectory,
95
+ sourceDir: outputDirectory,
96
96
  includeEntries: [
97
97
  require.resolve("@modern-js/prod-server")
98
98
  ],
99
+ copyWholePackage(pkgName) {
100
+ return pkgName === "@modern-js/utils";
101
+ },
99
102
  entryFilter: filter
100
103
  });
101
104
  }
@@ -33,8 +33,8 @@ __export(vercel_exports, {
33
33
  module.exports = __toCommonJS(vercel_exports);
34
34
  var import_node_path = __toESM(require("node:path"));
35
35
  var import_utils = require("@modern-js/utils");
36
+ var import_ndepe = require("ndepe");
36
37
  var import_routes = require("../../../utils/routes");
37
- var import_dependencies = require("../dependencies");
38
38
  var import_utils2 = require("../utils");
39
39
  const createVercelPreset = (appContext, modernConfig, needModernServer) => {
40
40
  const { appDirectory, distDirectory, entrypoints, serverPlugins, moduleType } = appContext;
@@ -148,12 +148,15 @@ const createVercelPreset = (appContext, modernConfig, needModernServer) => {
148
148
  if (!needModernServer) {
149
149
  return;
150
150
  }
151
- await (0, import_dependencies.handleDependencies)({
151
+ await (0, import_ndepe.nodeDepEmit)({
152
152
  appDir: appDirectory,
153
- serverRootDir: funcsDirectory,
153
+ sourceDir: funcsDirectory,
154
154
  includeEntries: [
155
155
  require.resolve("@modern-js/prod-server")
156
- ]
156
+ ],
157
+ copyWholePackage(pkgName) {
158
+ return pkgName === "@modern-js/utils";
159
+ }
157
160
  });
158
161
  }
159
162
  };
@@ -50,39 +50,37 @@ function checkHasConfig(appDir, metaName = "modern-js") {
50
50
  var serverBuild_default = () => ({
51
51
  name: "@modern-js/server-build",
52
52
  setup(api) {
53
- return {
54
- async afterBuild() {
55
- const { appDirectory, distDirectory, metaName } = api.useAppContext();
56
- if (!checkHasCache(appDirectory) && !checkHasConfig(appDirectory, metaName)) {
57
- return;
58
- }
59
- const modernConfig = api.useResolvedConfigContext();
60
- const distDir = import_path.default.resolve(distDirectory);
61
- const serverDir = import_path.default.resolve(appDirectory, import_utils.SERVER_DIR);
62
- const sharedDir = import_path.default.resolve(appDirectory, import_utils.SHARED_DIR);
63
- const tsconfigPath = import_path.default.resolve(appDirectory, TS_CONFIG_FILENAME);
64
- const sourceDirs = [];
65
- if (import_fs.default.existsSync(serverDir)) {
66
- sourceDirs.push(serverDir);
67
- if (import_fs.default.existsSync(sharedDir)) {
68
- sourceDirs.push(sharedDir);
69
- }
70
- }
71
- const { server } = modernConfig;
72
- const { alias } = modernConfig.source;
73
- const { babel } = modernConfig.tools;
74
- if (sourceDirs.length > 0) {
75
- await (0, import_server_utils.compile)(appDirectory, {
76
- server,
77
- alias,
78
- babelConfig: babel
79
- }, {
80
- sourceDirs,
81
- distDir,
82
- tsconfigPath
83
- });
53
+ api.onAfterBuild(async () => {
54
+ const { appDirectory, distDirectory, metaName } = api.getAppContext();
55
+ if (!checkHasCache(appDirectory) && !checkHasConfig(appDirectory, metaName)) {
56
+ return;
57
+ }
58
+ const modernConfig = api.getNormalizedConfig();
59
+ const distDir = import_path.default.resolve(distDirectory);
60
+ const serverDir = import_path.default.resolve(appDirectory, import_utils.SERVER_DIR);
61
+ const sharedDir = import_path.default.resolve(appDirectory, import_utils.SHARED_DIR);
62
+ const tsconfigPath = import_path.default.resolve(appDirectory, TS_CONFIG_FILENAME);
63
+ const sourceDirs = [];
64
+ if (import_fs.default.existsSync(serverDir)) {
65
+ sourceDirs.push(serverDir);
66
+ if (import_fs.default.existsSync(sharedDir)) {
67
+ sourceDirs.push(sharedDir);
84
68
  }
85
69
  }
86
- };
70
+ const { server } = modernConfig;
71
+ const { alias } = modernConfig.source;
72
+ const { babel } = modernConfig.tools;
73
+ if (sourceDirs.length > 0) {
74
+ await (0, import_server_utils.compile)(appDirectory, {
75
+ server,
76
+ alias,
77
+ babelConfig: babel
78
+ }, {
79
+ sourceDirs,
80
+ distDir,
81
+ tsconfigPath
82
+ });
83
+ }
84
+ });
87
85
  }
88
86
  });
@@ -24,11 +24,11 @@ module.exports = __toCommonJS(run_exports);
24
24
  var import_cli = require("@modern-js/plugin-v2/cli");
25
25
  var import_run = require("@modern-js/plugin-v2/run");
26
26
  var import_utils = require("@modern-js/utils");
27
- var import_hooks = require("./compat/hooks");
28
- var import_constants = require("./constants");
29
- var import_getConfigFile = require("./getConfigFile");
30
- var import_loadPlugins = require("./loadPlugins");
31
- var import_utils2 = require("./utils");
27
+ var import_hooks = require("../compat/hooks");
28
+ var import_constants = require("../constants");
29
+ var import_getConfigFile = require("../utils/getConfigFile");
30
+ var import_isAutoLoadPlugins = require("../utils/isAutoLoadPlugins");
31
+ var import_loadPlugins = require("../utils/loadPlugins");
32
32
  async function run({ cwd, initialLog, version, internalPlugins, packageJsonConfig, configFile }) {
33
33
  const command = process.argv[2];
34
34
  const cliParams = (0, import_utils.minimist)(process.argv.slice(2));
@@ -50,7 +50,7 @@ async function run({ cwd, initialLog, version, internalPlugins, packageJsonConfi
50
50
  }
51
51
  const appDirectory = await (0, import_cli.initAppDir)(cwd);
52
52
  const finalConfigFile = customConfigFile || (0, import_getConfigFile.getConfigFile)(configFile);
53
- const autoLoadPlugins = await (0, import_utils2.getIsAutoLoadPlugins)(appDirectory, finalConfigFile);
53
+ const autoLoadPlugins = await (0, import_isAutoLoadPlugins.isAutoLoadPlugins)(appDirectory, finalConfigFile);
54
54
  const plugins = await (0, import_loadPlugins.loadInternalPlugins)(appDirectory, internalPlugins === null || internalPlugins === void 0 ? void 0 : internalPlugins.cli, internalPlugins === null || internalPlugins === void 0 ? void 0 : internalPlugins.autoLoad, autoLoadPlugins);
55
55
  await (0, import_run.run)({
56
56
  cwd,
@@ -33,7 +33,7 @@ __export(getConfigFile_exports, {
33
33
  module.exports = __toCommonJS(getConfigFile_exports);
34
34
  var import_path = __toESM(require("path"));
35
35
  var import_utils = require("@modern-js/utils");
36
- var import_constants = require("./constants");
36
+ var import_constants = require("../constants");
37
37
  const getConfigFile = (configFile) => (0, import_utils.findExists)(import_utils.CONFIG_FILE_EXTENSIONS.map((extension) => import_path.default.resolve(process.cwd(), `${configFile || import_constants.DEFAULT_CONFIG_FILE}${extension}`)));
38
38
  // Annotate the CommonJS export names for ESM import in node:
39
39
  0 && (module.exports = {
@@ -26,11 +26,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var context_exports = {};
30
- __export(context_exports, {
29
+ var initAppContext_exports = {};
30
+ __export(initAppContext_exports, {
31
31
  initAppContext: () => initAppContext
32
32
  });
33
- module.exports = __toCommonJS(context_exports);
33
+ module.exports = __toCommonJS(initAppContext_exports);
34
34
  var import_path = __toESM(require("path"));
35
35
  var import_utils = require("@modern-js/utils");
36
36
  const initAppContext = ({ appDirectory, runtimeConfigFile, options, serverConfigFile, tempDir }) => {
@@ -16,13 +16,13 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var utils_exports = {};
20
- __export(utils_exports, {
21
- getIsAutoLoadPlugins: () => getIsAutoLoadPlugins
19
+ var isAutoLoadPlugins_exports = {};
20
+ __export(isAutoLoadPlugins_exports, {
21
+ isAutoLoadPlugins: () => isAutoLoadPlugins
22
22
  });
23
- module.exports = __toCommonJS(utils_exports);
23
+ module.exports = __toCommonJS(isAutoLoadPlugins_exports);
24
24
  var import_cli = require("@modern-js/plugin-v2/cli");
25
- async function getIsAutoLoadPlugins(appDirectory, configFile = "modern.config.ts", packageJsonConfig = "ModernConfig") {
25
+ async function isAutoLoadPlugins(appDirectory, configFile = "modern.config.ts", packageJsonConfig = "ModernConfig") {
26
26
  var _loaded_config;
27
27
  const loaded = await (0, import_cli.createLoadedConfig)(appDirectory, configFile, packageJsonConfig);
28
28
  const autoLoadPlugins = (_loaded_config = loaded.config) === null || _loaded_config === void 0 ? void 0 : _loaded_config.autoLoadPlugins;
@@ -30,5 +30,5 @@ async function getIsAutoLoadPlugins(appDirectory, configFile = "modern.config.ts
30
30
  }
31
31
  // Annotate the CommonJS export names for ESM import in node:
32
32
  0 && (module.exports = {
33
- getIsAutoLoadPlugins
33
+ isAutoLoadPlugins
34
34
  });
@@ -19,18 +19,20 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var loadPlugins_exports = {};
20
20
  __export(loadPlugins_exports, {
21
21
  getServerPlugins: () => getServerPlugins,
22
+ loadInternalPlugins: () => loadInternalPlugins,
22
23
  loadServerPlugins: () => loadServerPlugins
23
24
  });
24
25
  module.exports = __toCommonJS(loadPlugins_exports);
25
26
  var import_prod_server = require("@modern-js/prod-server");
27
+ var import_utils = require("@modern-js/utils");
28
+ const debug = (0, import_utils.createDebugger)("load-plugins");
26
29
  async function getServerPlugins(api, metaName = "modern-js") {
27
- const runner = api.useHookRunners();
28
- const { plugins } = await runner._internalServerPlugins({
30
+ const hooks = api.getHooks();
31
+ const { plugins } = await hooks._internalServerPlugins.call({
29
32
  plugins: []
30
33
  });
31
34
  const filtedPlugins = plugins.filter((plugin) => plugin.name.includes(metaName));
32
- api.setAppContext({
33
- ...api.useAppContext(),
35
+ api.updateAppContext({
34
36
  serverPlugins: filtedPlugins
35
37
  });
36
38
  return filtedPlugins;
@@ -40,8 +42,37 @@ async function loadServerPlugins(api, appDirectory, metaName) {
40
42
  const instances = await (0, import_prod_server.loadServerPlugins)(plugins, appDirectory);
41
43
  return instances;
42
44
  }
45
+ const resolveCliPlugin = async (p, appDirectory) => {
46
+ const pkg = typeof p === "string" ? p : p[0];
47
+ const pluginOptions = typeof p === "string" ? void 0 : p[1];
48
+ const path = (0, import_utils.tryResolve)(pkg, appDirectory);
49
+ let module2;
50
+ try {
51
+ module2 = await (0, import_utils.compatibleRequire)(path);
52
+ } catch (e) {
53
+ ({ default: module2 } = await (0, import_utils.dynamicImport)(path));
54
+ }
55
+ if (typeof module2 === "function") {
56
+ const result = module2(pluginOptions);
57
+ return result;
58
+ }
59
+ return module2;
60
+ };
61
+ const loadInternalPlugins = async (appDirectory, internalPlugins, autoLoad, autoLoadPlugins) => {
62
+ const plugins = [
63
+ ...autoLoadPlugins ? (0, import_utils.getInternalPlugins)(appDirectory, internalPlugins) : [],
64
+ ...autoLoad ? (0, import_utils.getInternalPlugins)(appDirectory, autoLoad) : []
65
+ ];
66
+ const loadedPlugins = await Promise.all(plugins.map((plugin) => {
67
+ const loadedPlugin = resolveCliPlugin(plugin, appDirectory);
68
+ debug(`resolve plugin %s: %s`, plugin, loadedPlugin);
69
+ return loadedPlugin;
70
+ }));
71
+ return loadedPlugins;
72
+ };
43
73
  // Annotate the CommonJS export names for ESM import in node:
44
74
  0 && (module.exports = {
45
75
  getServerPlugins,
76
+ loadInternalPlugins,
46
77
  loadServerPlugins
47
78
  });
@@ -18,8 +18,7 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var printInstructions_exports = {};
20
20
  __export(printInstructions_exports, {
21
- printInstructions: () => printInstructions,
22
- printInstructionsCompat: () => printInstructionsCompat
21
+ printInstructions: () => printInstructions
23
22
  });
24
23
  module.exports = __toCommonJS(printInstructions_exports);
25
24
  var import_utils = require("@modern-js/utils");
@@ -30,15 +29,7 @@ const printInstructions = async (hooks, appContext, config) => {
30
29
  });
31
30
  import_utils.logger.log(instructions);
32
31
  };
33
- const printInstructionsCompat = async (hookRunners, appContext, config) => {
34
- const message = (0, import_utils.prettyInstructions)(appContext, config);
35
- const { instructions } = await hookRunners.beforePrintInstructions({
36
- instructions: message
37
- });
38
- import_utils.logger.log(instructions);
39
- };
40
32
  // Annotate the CommonJS export names for ESM import in node:
41
33
  0 && (module.exports = {
42
- printInstructions,
43
- printInstructionsCompat
34
+ printInstructions
44
35
  });
@@ -24,12 +24,12 @@ module.exports = __toCommonJS(restart_exports);
24
24
  var import_cli = require("@modern-js/plugin-v2/cli");
25
25
  var import_utils = require("@modern-js/utils");
26
26
  var import_commander = require("@modern-js/utils/commander");
27
- async function restart(hooksRunner, filename) {
27
+ async function restart(hooks, filename) {
28
28
  (0, import_utils.clearConsole)();
29
29
  import_utils.logger.info(`Restart because ${import_utils.chalk.yellow(filename)} is changed...
30
30
  `);
31
31
  let hasGetError = false;
32
- await hooksRunner.beforeRestart();
32
+ await hooks.onBeforeRestart.call();
33
33
  try {
34
34
  await import_cli.cli.init(import_cli.cli.getPrevInitOptions());
35
35
  } catch (err) {
@@ -2,7 +2,6 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
3
  import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
4
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
- import { ResolvedConfigContext } from "@modern-js/core";
6
5
  import { logger } from "@modern-js/utils";
7
6
  import { buildServerConfig } from "../utils/config";
8
7
  import { loadServerPlugins } from "../utils/loadPlugins";
@@ -10,16 +9,16 @@ import { registerCompiler } from "../utils/register";
10
9
  import { generateRoutes } from "../utils/routes";
11
10
  var build = function() {
12
11
  var _ref = _async_to_generator(function(api, options) {
13
- var _resolvedConfig_source, resolvedConfig, appContext, hookRunners, _resolvedConfig_source1, registerEsm, apiOnly, appDirectory, distDirectory, serverConfigFile, distDirectory1, appDirectory1, serverConfigFile1;
12
+ var _resolvedConfig_source, resolvedConfig, appContext, hooks, _resolvedConfig_source1, registerEsm, apiOnly, appDirectory, distDirectory, serverConfigFile, distDirectory1, appDirectory1, serverConfigFile1;
14
13
  return _ts_generator(this, function(_state) {
15
14
  switch (_state.label) {
16
15
  case 0:
17
16
  if (options === null || options === void 0 ? void 0 : options.analyze) {
18
17
  process.env.BUNDLE_ANALYZE = "true";
19
18
  }
20
- resolvedConfig = api.useResolvedConfigContext();
21
- appContext = api.useAppContext();
22
- hookRunners = api.useHookRunners();
19
+ resolvedConfig = api.getNormalizedConfig();
20
+ appContext = api.getAppContext();
21
+ hooks = api.getHooks();
23
22
  return [
24
23
  4,
25
24
  loadServerPlugins(api, appContext.appDirectory, appContext.metaName)
@@ -64,9 +63,12 @@ var build = function() {
64
63
  appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverConfigFile = appContext.serverConfigFile;
65
64
  return [
66
65
  4,
67
- hookRunners.beforeBuild({
66
+ hooks.onBeforeBuild.call({
67
+ environments: {},
68
68
  // "null" bundlerConfigs
69
- bundlerConfigs: void 0
69
+ bundlerConfigs: void 0,
70
+ isFirstCompile: false,
71
+ isWatch: false
70
72
  })
71
73
  ];
72
74
  case 6:
@@ -89,9 +91,12 @@ var build = function() {
89
91
  _state.sent();
90
92
  return [
91
93
  4,
92
- hookRunners.afterBuild({
94
+ hooks.onAfterBuild.call({
95
+ environments: {},
93
96
  // "null" stats
94
- stats: void 0
97
+ stats: void 0,
98
+ isFirstCompile: false,
99
+ isWatch: false
95
100
  })
96
101
  ];
97
102
  case 9:
@@ -100,10 +105,11 @@ var build = function() {
100
105
  2
101
106
  ];
102
107
  case 10:
103
- resolvedConfig = _object_spread_props(_object_spread({}, resolvedConfig), {
104
- cliOptions: options
108
+ api.modifyResolvedConfig(function(config) {
109
+ return _object_spread_props(_object_spread({}, config), {
110
+ cliOptions: options
111
+ });
105
112
  });
106
- ResolvedConfigContext.set(resolvedConfig);
107
113
  distDirectory1 = appContext.distDirectory, appDirectory1 = appContext.appDirectory, serverConfigFile1 = appContext.serverConfigFile;
108
114
  return [
109
115
  4,
@@ -3,12 +3,12 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import { getServerPlugins } from "../utils/loadPlugins";
4
4
  var deploy = function() {
5
5
  var _ref = _async_to_generator(function(api, options) {
6
- var hookRunners, metaName;
6
+ var hooks, metaName;
7
7
  return _ts_generator(this, function(_state) {
8
8
  switch (_state.label) {
9
9
  case 0:
10
- hookRunners = api.useHookRunners();
11
- metaName = api.useAppContext().metaName;
10
+ hooks = api.getHooks();
11
+ metaName = api.getAppContext().metaName;
12
12
  return [
13
13
  4,
14
14
  getServerPlugins(api, metaName)
@@ -17,19 +17,19 @@ var deploy = function() {
17
17
  _state.sent();
18
18
  return [
19
19
  4,
20
- hookRunners.beforeDeploy(options)
20
+ hooks.onBeforeDeploy.call(options)
21
21
  ];
22
22
  case 2:
23
23
  _state.sent();
24
24
  return [
25
25
  4,
26
- hookRunners.deploy(options)
26
+ hooks.deploy.call()
27
27
  ];
28
28
  case 3:
29
29
  _state.sent();
30
30
  return [
31
31
  4,
32
- hookRunners.afterDeploy(options)
32
+ hooks.onAfterDeploy.call(options)
33
33
  ];
34
34
  case 4:
35
35
  _state.sent();
@@ -3,28 +3,27 @@ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
3
  import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
4
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
5
  import path from "node:path";
6
- import { ResolvedConfigContext } from "@modern-js/core";
7
6
  import { applyPlugins } from "@modern-js/prod-server";
8
7
  import { createDevServer } from "@modern-js/server";
9
8
  import { DEFAULT_DEV_HOST, SERVER_DIR, getMeta, logger } from "@modern-js/utils";
10
9
  import { buildServerConfig } from "../utils/config";
11
10
  import { setServer } from "../utils/createServer";
12
11
  import { loadServerPlugins } from "../utils/loadPlugins";
13
- import { printInstructionsCompat } from "../utils/printInstructions";
12
+ import { printInstructions } from "../utils/printInstructions";
14
13
  import { registerCompiler } from "../utils/register";
15
14
  import { generateRoutes } from "../utils/routes";
16
15
  var dev = function() {
17
16
  var _ref = _async_to_generator(function(api, options, devServerOptions) {
18
- var _normalizedConfig_source, _normalizedConfig_tools, _normalizedConfig_dev, normalizedConfig, appContext, hookRunners, _normalizedConfig_source1, registerEsm, appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverRoutes, meta, serverConfigPath, pluginInstances, serverOptions, host, server, _ref2, server1, afterListen;
17
+ var _normalizedConfig_source, _normalizedConfig_tools, _normalizedConfig_dev, normalizedConfig, appContext, hooks, _normalizedConfig_source1, registerEsm, appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverRoutes, meta, serverConfigPath, pluginInstances, serverOptions, host, server, _ref2, server1, afterListen;
19
18
  return _ts_generator(this, function(_state) {
20
19
  switch (_state.label) {
21
20
  case 0:
22
21
  if (options.analyze) {
23
22
  process.env.BUNDLE_ANALYZE = "true";
24
23
  }
25
- normalizedConfig = api.useResolvedConfigContext();
26
- appContext = api.useAppContext();
27
- hookRunners = api.useHookRunners();
24
+ normalizedConfig = api.getNormalizedConfig();
25
+ appContext = api.getAppContext();
26
+ hooks = api.getHooks();
28
27
  if (!(appContext.moduleType && appContext.moduleType === "module"))
29
28
  return [
30
29
  3,
@@ -54,10 +53,11 @@ var dev = function() {
54
53
  ];
55
54
  case 4:
56
55
  _state.sent();
57
- normalizedConfig = _object_spread_props(_object_spread({}, normalizedConfig), {
58
- cliOptions: options
56
+ api.modifyResolvedConfig(function(config) {
57
+ return _object_spread_props(_object_spread({}, config), {
58
+ cliOptions: options
59
+ });
59
60
  });
60
- ResolvedConfigContext.set(normalizedConfig);
61
61
  appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, port = appContext.port, apiOnly = appContext.apiOnly, serverConfigFile = appContext.serverConfigFile, metaName = appContext.metaName, serverRoutes = appContext.serverRoutes;
62
62
  return [
63
63
  4,
@@ -74,7 +74,7 @@ var dev = function() {
74
74
  serverConfigPath = path.resolve(appDirectory, SERVER_DIR, "".concat(meta, ".server"));
75
75
  return [
76
76
  4,
77
- hookRunners.beforeDev()
77
+ hooks.onBeforeDev.call()
78
78
  ];
79
79
  case 6:
80
80
  _state.sent();
@@ -132,7 +132,7 @@ var dev = function() {
132
132
  port,
133
133
  host
134
134
  }, function() {
135
- printInstructionsCompat(hookRunners, appContext, normalizedConfig);
135
+ printInstructions(hooks, appContext, normalizedConfig);
136
136
  });
137
137
  return [
138
138
  3,
@@ -7,14 +7,14 @@ import { newAction, upgradeAction } from "@modern-js/utils";
7
7
  import { i18n, localeKeys } from "../locale";
8
8
  var devCommand = function() {
9
9
  var _ref = _async_to_generator(function(program, api) {
10
- var runner, devToolMetas, devProgram, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _loop, _iterator, _step;
10
+ var hooks, devToolMetas, devProgram, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _loop, _iterator, _step;
11
11
  return _ts_generator(this, function(_state) {
12
12
  switch (_state.label) {
13
13
  case 0:
14
- runner = api.useHookRunners();
14
+ hooks = api.getHooks();
15
15
  return [
16
16
  4,
17
- runner.registerDev()
17
+ hooks.registerDev.call()
18
18
  ];
19
19
  case 1:
20
20
  devToolMetas = _state.sent();
@@ -64,7 +64,7 @@ var devCommand = function() {
64
64
  switch (_state2.label) {
65
65
  case 0:
66
66
  options = _arguments.length > 0 && _arguments[0] !== void 0 ? _arguments[0] : {};
67
- appDirectory = api.useAppContext().appDirectory;
67
+ appDirectory = api.getAppContext().appDirectory;
68
68
  return [
69
69
  4,
70
70
  import("@modern-js/utils")
@@ -129,14 +129,14 @@ var devCommand = function() {
129
129
  }();
130
130
  var buildCommand = function() {
131
131
  var _ref = _async_to_generator(function(program, api) {
132
- var runner, platformBuilders, buildProgram, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _loop, _iterator, _step;
132
+ var hooks, platformBuilders, buildProgram, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _loop, _iterator, _step;
133
133
  return _ts_generator(this, function(_state) {
134
134
  switch (_state.label) {
135
135
  case 0:
136
- runner = api.useHookRunners();
136
+ hooks = api.getHooks();
137
137
  return [
138
138
  4,
139
- runner.registerBuildPlatform()
139
+ hooks.registerBuildPlatform.call()
140
140
  ];
141
141
  case 1:
142
142
  platformBuilders = _state.sent();
@@ -182,7 +182,7 @@ var buildCommand = function() {
182
182
  return _ts_generator(this, function(_state2) {
183
183
  switch (_state2.label) {
184
184
  case 0:
185
- appDirectory = api.useAppContext().appDirectory;
185
+ appDirectory = api.getAppContext().appDirectory;
186
186
  return [
187
187
  4,
188
188
  import("@modern-js/utils")