@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
@@ -1,5 +1,143 @@
1
- import { appTools } from "./new/index";
2
- import { initAppContext } from "./new/index";
1
+ import { getLocaleLanguage } from "@modern-js/plugin-i18n/language-detector";
2
+ import { createAsyncHook, createCollectAsyncHook } from "@modern-js/plugin-v2";
3
+ import { castArray } from "@modern-js/uni-builder";
4
+ import { cleanRequireCache, deprecatedCommands, emptyDir, getArgv, getCommand } from "@modern-js/utils";
5
+ import { buildCommand, deployCommand, devCommand, inspectCommand, newCommand, serverCommand, upgradeCommand } from "./commands";
6
+ import { compatPlugin } from "./compat";
7
+ import { DEFAULT_RUNTIME_CONFIG_FILE, DEFAULT_SERVER_CONFIG_FILE } from "./constants";
8
+ import { i18n } from "./locale";
9
+ import analyzePlugin from "./plugins/analyze";
10
+ import deployPlugin from "./plugins/deploy";
11
+ import initializePlugin from "./plugins/initialize";
12
+ import serverBuildPlugin from "./plugins/serverBuild";
13
+ import { generateWatchFiles } from "./utils/generateWatchFiles";
14
+ import { initAppContext } from "./utils/initAppContext";
15
+ import { restart } from "./utils/restart";
16
+ export * from "./defineConfig";
17
+ const appTools = (options = {
18
+ // default webpack to be compatible with original projects
19
+ bundler: "webpack"
20
+ }) => ({
21
+ name: "@modern-js/app-tools",
22
+ usePlugins: [
23
+ compatPlugin(),
24
+ initializePlugin({
25
+ bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
26
+ "rspack",
27
+ "experimental-rspack"
28
+ ].includes(options.bundler) ? "rspack" : "webpack"
29
+ }),
30
+ analyzePlugin({
31
+ bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
32
+ "rspack",
33
+ "experimental-rspack"
34
+ ].includes(options.bundler) ? "rspack" : "webpack"
35
+ }),
36
+ serverBuildPlugin(),
37
+ deployPlugin()
38
+ ],
39
+ post: [
40
+ "@modern-js/plugin-initialize",
41
+ "@modern-js/plugin-analyze",
42
+ "@modern-js/plugin-ssr",
43
+ "@modern-js/plugin-document",
44
+ "@modern-js/plugin-state",
45
+ "@modern-js/plugin-router",
46
+ "@modern-js/plugin-router-v5",
47
+ "@modern-js/plugin-polyfill"
48
+ ],
49
+ registryHooks: {
50
+ onBeforeConfig: createAsyncHook(),
51
+ onAfterPrepare: createAsyncHook(),
52
+ deploy: createAsyncHook(),
53
+ _internalRuntimePlugins: createAsyncHook(),
54
+ _internalServerPlugins: createAsyncHook(),
55
+ checkEntryPoint: createAsyncHook(),
56
+ modifyEntrypoints: createAsyncHook(),
57
+ modifyFileSystemRoutes: createAsyncHook(),
58
+ modifyServerRoutes: createAsyncHook(),
59
+ generateEntryCode: createAsyncHook(),
60
+ onBeforeGenerateRoutes: createAsyncHook(),
61
+ onBeforePrintInstructions: createAsyncHook(),
62
+ registerDev: createCollectAsyncHook(),
63
+ registerBuildPlatform: createCollectAsyncHook(),
64
+ addRuntimeExports: createAsyncHook()
65
+ },
66
+ setup: (api) => {
67
+ var _userConfig_output;
68
+ const context = api.getAppContext();
69
+ const userConfig = api.getConfig();
70
+ const locale = getLocaleLanguage();
71
+ i18n.changeLanguage({
72
+ locale
73
+ });
74
+ api.updateAppContext(initAppContext({
75
+ appDirectory: context.appDirectory,
76
+ options: {},
77
+ serverConfigFile: DEFAULT_SERVER_CONFIG_FILE,
78
+ runtimeConfigFile: DEFAULT_RUNTIME_CONFIG_FILE,
79
+ tempDir: (_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir
80
+ }));
81
+ api.addCommand(async ({ program }) => {
82
+ await devCommand(program, api);
83
+ await buildCommand(program, api);
84
+ serverCommand(program, api);
85
+ deployCommand(program, api);
86
+ newCommand(program, locale);
87
+ inspectCommand(program, api);
88
+ upgradeCommand(program);
89
+ deprecatedCommands(program);
90
+ });
91
+ api.onPrepare(async () => {
92
+ const command = getCommand();
93
+ if (command === "deploy") {
94
+ const isSkipBuild = [
95
+ "-s",
96
+ "--skip-build"
97
+ ].some((tag) => {
98
+ return getArgv().includes(tag);
99
+ });
100
+ if (isSkipBuild) {
101
+ return;
102
+ }
103
+ }
104
+ if (command === "dev" || command === "start" || command === "build" || command === "deploy") {
105
+ const resolvedConfig = api.getNormalizedConfig();
106
+ if (resolvedConfig.output.cleanDistPath) {
107
+ const appContext = api.getAppContext();
108
+ await emptyDir(appContext.distDirectory);
109
+ }
110
+ }
111
+ });
112
+ api.addWatchFiles(async () => {
113
+ const appContext = api.getAppContext();
114
+ const config = api.getNormalizedConfig();
115
+ const files = await generateWatchFiles(appContext, config.source.configDir);
116
+ const watchFiles = castArray(config.dev.watchFiles);
117
+ watchFiles.forEach(({ type, paths }) => {
118
+ if (type === "reload-server") {
119
+ files.push(...Array.isArray(paths) ? paths : [
120
+ paths
121
+ ]);
122
+ }
123
+ });
124
+ return files;
125
+ });
126
+ api.onFileChanged(async (e) => {
127
+ const { filename, eventType, isPrivate } = e;
128
+ if (!isPrivate && (eventType === "change" || eventType === "unlink")) {
129
+ const { closeServer } = await import("./utils/createServer.js");
130
+ await closeServer();
131
+ await restart(api.getHooks(), filename);
132
+ }
133
+ });
134
+ api.onBeforeRestart(() => {
135
+ cleanRequireCache([
136
+ require.resolve("./plugins/analyze")
137
+ ]);
138
+ });
139
+ }
140
+ });
3
141
  import { defineConfig, defineLegacyConfig } from "./defineConfig";
4
142
  import { mergeConfig } from "@modern-js/core";
5
143
  import { dev } from "./commands/dev";
@@ -1,6 +1,5 @@
1
- import fs from "fs";
2
1
  import path from "path";
3
- import { SERVER_BUNDLE_DIRECTORY, SERVER_WORKER_BUNDLE_DIRECTORY, getEntryOptions, isPlainObject, removeLeadingSlash, removeTailSlash, urlJoin } from "@modern-js/utils";
2
+ import { fs, ROUTE_SPEC_FILE, SERVER_BUNDLE_DIRECTORY, SERVER_WORKER_BUNDLE_DIRECTORY, getEntryOptions, isPlainObject, removeLeadingSlash, removeTailSlash, urlJoin } from "@modern-js/utils";
4
3
  import { isMainEntry } from "../../utils/routes";
5
4
  import { walkDirectory } from "./utils";
6
5
  const applyBaseUrl = (baseUrl, routes) => {
@@ -130,6 +129,16 @@ const getServerRoutes = (entrypoints, { appContext, config }) => [
130
129
  ...collectStaticRoutes(appContext, config)
131
130
  ];
132
131
  const toPosix = (pathStr) => pathStr.split(path.sep).join(path.posix.sep);
132
+ const getProdServerRoutes = (distDirectory) => {
133
+ const routeJSON = path.join(distDirectory, ROUTE_SPEC_FILE);
134
+ try {
135
+ const { routes } = fs.readJSONSync(routeJSON);
136
+ return routes;
137
+ } catch (e) {
138
+ throw new Error(`Failed to read routes from ${routeJSON}, please check if the file exists.`);
139
+ }
140
+ };
133
141
  export {
142
+ getProdServerRoutes,
134
143
  getServerRoutes
135
144
  };
@@ -6,7 +6,7 @@ import { emitResolvedConfig } from "../../utils/config";
6
6
  import { getSelectedEntries } from "../../utils/getSelectedEntries";
7
7
  import { printInstructions } from "../../utils/printInstructions";
8
8
  import { generateRoutes } from "../../utils/routes";
9
- import { checkIsBuildCommands } from "./utils";
9
+ import { checkIsBuildCommands, checkIsServeCommand } from "./utils";
10
10
  const debug = createDebugger("plugin-analyze");
11
11
  var analyze_default = ({ bundler }) => ({
12
12
  name: "@modern-js/plugin-analyze",
@@ -29,10 +29,19 @@ var analyze_default = ({ bundler }) => ({
29
29
  }
30
30
  const apiOnly = await isApiOnly(appContext.appDirectory, (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.entriesDir, appContext.apiDirectory);
31
31
  await hooks.addRuntimeExports.call();
32
+ const [{ getProdServerRoutes }] = await Promise.all([
33
+ import("./getServerRoutes.js")
34
+ ]);
32
35
  if (apiOnly) {
33
- const { routes: routes2 } = await hooks.modifyServerRoutes.call({
34
- routes: []
35
- });
36
+ const routes2 = [];
37
+ if (checkIsServeCommand()) {
38
+ routes2.push(...getProdServerRoutes(appContext.distDirectory));
39
+ } else {
40
+ const { routes: modifiedRoutes } = await hooks.modifyServerRoutes.call({
41
+ routes: []
42
+ });
43
+ routes2.push(...modifiedRoutes);
44
+ }
36
45
  debug(`server routes: %o`, routes2);
37
46
  api.updateAppContext({
38
47
  apiOnly,
@@ -49,13 +58,19 @@ var analyze_default = ({ bundler }) => ({
49
58
  entrypoints: await getBundleEntry(hooks, appContext, resolvedConfig)
50
59
  });
51
60
  debug(`entrypoints: %o`, entrypoints);
52
- const initialRoutes = getServerRoutes(entrypoints, {
53
- appContext,
54
- config: resolvedConfig
55
- });
56
- const { routes } = await hooks.modifyServerRoutes.call({
57
- routes: initialRoutes
58
- });
61
+ const routes = [];
62
+ if (checkIsServeCommand()) {
63
+ routes.push(...getProdServerRoutes(appContext.distDirectory));
64
+ } else {
65
+ const initialRoutes = getServerRoutes(entrypoints, {
66
+ appContext,
67
+ config: resolvedConfig
68
+ });
69
+ const { routes: modifiedRoutes } = await hooks.modifyServerRoutes.call({
70
+ routes: initialRoutes
71
+ });
72
+ routes.push(...modifiedRoutes);
73
+ }
59
74
  debug(`server routes: %o`, routes);
60
75
  appContext = {
61
76
  ...api.getAppContext(),
@@ -50,6 +50,10 @@ const checkIsBuildCommands = () => {
50
50
  const command = getCommand();
51
51
  return buildCommands.includes(command);
52
52
  };
53
+ const checkIsServeCommand = () => {
54
+ const command = getCommand();
55
+ return command === "serve";
56
+ };
53
57
  const isSubDirOrEqual = (parent, child) => {
54
58
  if (parent === child) {
55
59
  return true;
@@ -60,6 +64,7 @@ const isSubDirOrEqual = (parent, child) => {
60
64
  };
61
65
  export {
62
66
  checkIsBuildCommands,
67
+ checkIsServeCommand,
63
68
  getServerCombinedModueFile,
64
69
  isSubDirOrEqual,
65
70
  parseModule,
@@ -17,40 +17,38 @@ function checkHasConfig(appDir, metaName = "modern-js") {
17
17
  var serverBuild_default = () => ({
18
18
  name: "@modern-js/server-build",
19
19
  setup(api) {
20
- return {
21
- async afterBuild() {
22
- const { appDirectory, distDirectory, metaName } = api.useAppContext();
23
- if (!checkHasCache(appDirectory) && !checkHasConfig(appDirectory, metaName)) {
24
- return;
25
- }
26
- const modernConfig = api.useResolvedConfigContext();
27
- const distDir = path.resolve(distDirectory);
28
- const serverDir = path.resolve(appDirectory, SERVER_DIR);
29
- const sharedDir = path.resolve(appDirectory, SHARED_DIR);
30
- const tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
31
- const sourceDirs = [];
32
- if (fs.existsSync(serverDir)) {
33
- sourceDirs.push(serverDir);
34
- if (fs.existsSync(sharedDir)) {
35
- sourceDirs.push(sharedDir);
36
- }
37
- }
38
- const { server } = modernConfig;
39
- const { alias } = modernConfig.source;
40
- const { babel } = modernConfig.tools;
41
- if (sourceDirs.length > 0) {
42
- await compile(appDirectory, {
43
- server,
44
- alias,
45
- babelConfig: babel
46
- }, {
47
- sourceDirs,
48
- distDir,
49
- tsconfigPath
50
- });
20
+ api.onAfterBuild(async () => {
21
+ const { appDirectory, distDirectory, metaName } = api.getAppContext();
22
+ if (!checkHasCache(appDirectory) && !checkHasConfig(appDirectory, metaName)) {
23
+ return;
24
+ }
25
+ const modernConfig = api.getNormalizedConfig();
26
+ const distDir = path.resolve(distDirectory);
27
+ const serverDir = path.resolve(appDirectory, SERVER_DIR);
28
+ const sharedDir = path.resolve(appDirectory, SHARED_DIR);
29
+ const tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
30
+ const sourceDirs = [];
31
+ if (fs.existsSync(serverDir)) {
32
+ sourceDirs.push(serverDir);
33
+ if (fs.existsSync(sharedDir)) {
34
+ sourceDirs.push(sharedDir);
51
35
  }
52
36
  }
53
- };
37
+ const { server } = modernConfig;
38
+ const { alias } = modernConfig.source;
39
+ const { babel } = modernConfig.tools;
40
+ if (sourceDirs.length > 0) {
41
+ await compile(appDirectory, {
42
+ server,
43
+ alias,
44
+ babelConfig: babel
45
+ }, {
46
+ sourceDirs,
47
+ distDir,
48
+ tsconfigPath
49
+ });
50
+ }
51
+ });
54
52
  }
55
53
  });
56
54
  export {
@@ -1,11 +1,11 @@
1
1
  import { initAppDir } from "@modern-js/plugin-v2/cli";
2
2
  import { run as CLIPluginRun } from "@modern-js/plugin-v2/run";
3
3
  import { minimist } from "@modern-js/utils";
4
- import { handleSetupResult } from "./compat/hooks";
5
- import { PACKAGE_JSON_CONFIG_NAME } from "./constants";
6
- import { getConfigFile } from "./getConfigFile";
7
- import { loadInternalPlugins } from "./loadPlugins";
8
- import { getIsAutoLoadPlugins } from "./utils";
4
+ import { handleSetupResult } from "../compat/hooks";
5
+ import { PACKAGE_JSON_CONFIG_NAME } from "../constants";
6
+ import { getConfigFile } from "../utils/getConfigFile";
7
+ import { isAutoLoadPlugins } from "../utils/isAutoLoadPlugins";
8
+ import { loadInternalPlugins } from "../utils/loadPlugins";
9
9
  async function run({ cwd, initialLog, version, internalPlugins, packageJsonConfig, configFile }) {
10
10
  const command = process.argv[2];
11
11
  const cliParams = minimist(process.argv.slice(2));
@@ -27,7 +27,7 @@ async function run({ cwd, initialLog, version, internalPlugins, packageJsonConfi
27
27
  }
28
28
  const appDirectory = await initAppDir(cwd);
29
29
  const finalConfigFile = customConfigFile || getConfigFile(configFile);
30
- const autoLoadPlugins = await getIsAutoLoadPlugins(appDirectory, finalConfigFile);
30
+ const autoLoadPlugins = await isAutoLoadPlugins(appDirectory, finalConfigFile);
31
31
  const plugins = await loadInternalPlugins(appDirectory, internalPlugins === null || internalPlugins === void 0 ? void 0 : internalPlugins.cli, internalPlugins === null || internalPlugins === void 0 ? void 0 : internalPlugins.autoLoad, autoLoadPlugins);
32
32
  await CLIPluginRun({
33
33
  cwd,
@@ -1,6 +1,6 @@
1
1
  import path from "path";
2
2
  import { CONFIG_FILE_EXTENSIONS, findExists } from "@modern-js/utils";
3
- import { DEFAULT_CONFIG_FILE } from "./constants";
3
+ import { DEFAULT_CONFIG_FILE } from "../constants";
4
4
  const getConfigFile = (configFile) => findExists(CONFIG_FILE_EXTENSIONS.map((extension) => path.resolve(process.cwd(), `${configFile || DEFAULT_CONFIG_FILE}${extension}`)));
5
5
  export {
6
6
  getConfigFile
@@ -1,10 +1,10 @@
1
1
  import { createLoadedConfig } from "@modern-js/plugin-v2/cli";
2
- async function getIsAutoLoadPlugins(appDirectory, configFile = "modern.config.ts", packageJsonConfig = "ModernConfig") {
2
+ async function isAutoLoadPlugins(appDirectory, configFile = "modern.config.ts", packageJsonConfig = "ModernConfig") {
3
3
  var _loaded_config;
4
4
  const loaded = await createLoadedConfig(appDirectory, configFile, packageJsonConfig);
5
5
  const autoLoadPlugins = (_loaded_config = loaded.config) === null || _loaded_config === void 0 ? void 0 : _loaded_config.autoLoadPlugins;
6
6
  return autoLoadPlugins || false;
7
7
  }
8
8
  export {
9
- getIsAutoLoadPlugins
9
+ isAutoLoadPlugins
10
10
  };
@@ -1,12 +1,13 @@
1
1
  import { loadServerPlugins as loadServerPluginInstances } from "@modern-js/prod-server";
2
+ import { compatibleRequire, createDebugger, dynamicImport, getInternalPlugins, tryResolve } from "@modern-js/utils";
3
+ const debug = createDebugger("load-plugins");
2
4
  async function getServerPlugins(api, metaName = "modern-js") {
3
- const runner = api.useHookRunners();
4
- const { plugins } = await runner._internalServerPlugins({
5
+ const hooks = api.getHooks();
6
+ const { plugins } = await hooks._internalServerPlugins.call({
5
7
  plugins: []
6
8
  });
7
9
  const filtedPlugins = plugins.filter((plugin) => plugin.name.includes(metaName));
8
- api.setAppContext({
9
- ...api.useAppContext(),
10
+ api.updateAppContext({
10
11
  serverPlugins: filtedPlugins
11
12
  });
12
13
  return filtedPlugins;
@@ -16,7 +17,36 @@ async function loadServerPlugins(api, appDirectory, metaName) {
16
17
  const instances = await loadServerPluginInstances(plugins, appDirectory);
17
18
  return instances;
18
19
  }
20
+ const resolveCliPlugin = async (p, appDirectory) => {
21
+ const pkg = typeof p === "string" ? p : p[0];
22
+ const pluginOptions = typeof p === "string" ? void 0 : p[1];
23
+ const path = tryResolve(pkg, appDirectory);
24
+ let module;
25
+ try {
26
+ module = await compatibleRequire(path);
27
+ } catch (e) {
28
+ ({ default: module } = await dynamicImport(path));
29
+ }
30
+ if (typeof module === "function") {
31
+ const result = module(pluginOptions);
32
+ return result;
33
+ }
34
+ return module;
35
+ };
36
+ const loadInternalPlugins = async (appDirectory, internalPlugins, autoLoad, autoLoadPlugins) => {
37
+ const plugins = [
38
+ ...autoLoadPlugins ? getInternalPlugins(appDirectory, internalPlugins) : [],
39
+ ...autoLoad ? getInternalPlugins(appDirectory, autoLoad) : []
40
+ ];
41
+ const loadedPlugins = await Promise.all(plugins.map((plugin) => {
42
+ const loadedPlugin = resolveCliPlugin(plugin, appDirectory);
43
+ debug(`resolve plugin %s: %s`, plugin, loadedPlugin);
44
+ return loadedPlugin;
45
+ }));
46
+ return loadedPlugins;
47
+ };
19
48
  export {
20
49
  getServerPlugins,
50
+ loadInternalPlugins,
21
51
  loadServerPlugins
22
52
  };
@@ -6,14 +6,6 @@ const printInstructions = async (hooks, appContext, config) => {
6
6
  });
7
7
  logger.log(instructions);
8
8
  };
9
- const printInstructionsCompat = async (hookRunners, appContext, config) => {
10
- const message = prettyInstructions(appContext, config);
11
- const { instructions } = await hookRunners.beforePrintInstructions({
12
- instructions: message
13
- });
14
- logger.log(instructions);
15
- };
16
9
  export {
17
- printInstructions,
18
- printInstructionsCompat
10
+ printInstructions
19
11
  };
@@ -1,12 +1,12 @@
1
1
  import { cli } from "@modern-js/plugin-v2/cli";
2
2
  import { chalk, clearConsole, getFullArgv, logger } from "@modern-js/utils";
3
3
  import { program } from "@modern-js/utils/commander";
4
- async function restart(hooksRunner, filename) {
4
+ async function restart(hooks, filename) {
5
5
  clearConsole();
6
6
  logger.info(`Restart because ${chalk.yellow(filename)} is changed...
7
7
  `);
8
8
  let hasGetError = false;
9
- await hooksRunner.beforeRestart();
9
+ await hooks.onBeforeRestart.call();
10
10
  try {
11
11
  await cli.init(cli.getPrevInitOptions());
12
12
  } catch (err) {
@@ -1,4 +1,4 @@
1
- import { type PluginAPI } from '@modern-js/core';
1
+ import type { CLIPluginAPI } from '@modern-js/plugin-v2';
2
2
  import type { AppTools } from '../types';
3
3
  import type { BuildOptions } from '../utils/types';
4
- export declare const build: (api: PluginAPI<AppTools<'shared'>>, options?: BuildOptions) => Promise<void>;
4
+ export declare const build: (api: CLIPluginAPI<AppTools<'shared'>>, options?: BuildOptions) => Promise<void>;
@@ -1,3 +1,3 @@
1
- import type { PluginAPI } from '@modern-js/core';
1
+ import type { CLIPluginAPI } from '@modern-js/plugin-v2';
2
2
  import type { AppTools } from '../types';
3
- export declare const deploy: (api: PluginAPI<AppTools<'shared'>>, options: any) => Promise<void>;
3
+ export declare const deploy: (api: CLIPluginAPI<AppTools<'shared'>>, options: any) => Promise<void>;
@@ -1,8 +1,8 @@
1
- import { type PluginAPI } from '@modern-js/core';
1
+ import type { CLIPluginAPI } from '@modern-js/plugin-v2';
2
2
  import { type ApplyPlugins } from '@modern-js/server';
3
3
  import type { AppTools } from '../types';
4
4
  import type { DevOptions } from '../utils/types';
5
5
  export interface ExtraServerOptions {
6
6
  applyPlugins?: ApplyPlugins;
7
7
  }
8
- export declare const dev: (api: PluginAPI<AppTools<'shared'>>, options: DevOptions, devServerOptions?: ExtraServerOptions) => Promise<void>;
8
+ export declare const dev: (api: CLIPluginAPI<AppTools<'shared'>>, options: DevOptions, devServerOptions?: ExtraServerOptions) => Promise<void>;
@@ -1,10 +1,10 @@
1
- import type { PluginAPI } from '@modern-js/core';
1
+ import type { CLIPluginAPI } from '@modern-js/plugin-v2';
2
2
  import { type Command } from '@modern-js/utils';
3
3
  import type { AppTools } from '../types';
4
- export declare const devCommand: (program: Command, api: PluginAPI<AppTools<'shared'>>) => Promise<void>;
5
- export declare const buildCommand: (program: Command, api: PluginAPI<AppTools<'shared'>>) => Promise<void>;
6
- export declare const serverCommand: (program: Command, api: PluginAPI<AppTools<'shared'>>) => void;
7
- export declare const deployCommand: (program: Command, api: PluginAPI<AppTools<'shared'>>) => void;
4
+ export declare const devCommand: (program: Command, api: CLIPluginAPI<AppTools<'shared'>>) => Promise<void>;
5
+ export declare const buildCommand: (program: Command, api: CLIPluginAPI<AppTools<'shared'>>) => Promise<void>;
6
+ export declare const serverCommand: (program: Command, api: CLIPluginAPI<AppTools<'shared'>>) => void;
7
+ export declare const deployCommand: (program: Command, api: CLIPluginAPI<AppTools<'shared'>>) => void;
8
8
  export declare const newCommand: (program: Command, locale: string) => void;
9
- export declare const inspectCommand: (program: Command, api: PluginAPI<AppTools<'shared'>>) => void;
9
+ export declare const inspectCommand: (program: Command, api: CLIPluginAPI<AppTools<'shared'>>) => void;
10
10
  export declare const upgradeCommand: (program: Command) => void;
@@ -1,4 +1,4 @@
1
- import type { PluginAPI } from '@modern-js/core';
1
+ import type { CLIPluginAPI } from '@modern-js/plugin-v2';
2
2
  import type { AppTools } from '../types';
3
3
  import type { InspectOptions } from '../utils/types';
4
- export declare const inspect: (api: PluginAPI<AppTools<'shared'>>, options: InspectOptions) => Promise<import("@rsbuild/core").InspectConfigResult<"rspack">>;
4
+ export declare const inspect: (api: CLIPluginAPI<AppTools<'shared'>>, options: InspectOptions) => Promise<import("@rsbuild/core").InspectConfigResult<"rspack">>;
@@ -1,3 +1,3 @@
1
- import type { PluginAPI } from '@modern-js/core';
1
+ import type { CLIPluginAPI } from '@modern-js/plugin-v2';
2
2
  import type { AppTools } from '../types';
3
- export declare const start: (api: PluginAPI<AppTools<'shared'>>) => Promise<void>;
3
+ export declare const start: (api: CLIPluginAPI<AppTools<'shared'>>) => Promise<void>;
@@ -1,7 +1,7 @@
1
1
  import type { InternalContext } from '@modern-js/plugin-v2';
2
- import type { AppTools } from '../../types';
2
+ import type { AppTools } from '../types';
3
3
  /**
4
4
  * old plugin useHookRunners function result
5
5
  */
6
- export declare function getHookRunners(context: InternalContext<AppTools>): Record<string, any>;
6
+ export declare function getHookRunners(context: InternalContext<AppTools<'shared'>>): Record<string, any>;
7
7
  export declare function handleSetupResult(setupResult: Record<string, (...args: any) => any>, api: Record<string, any>): void;
@@ -0,0 +1,2 @@
1
+ import type { AppTools, CliPluginFuture } from '../types';
2
+ export declare const compatPlugin: () => CliPluginFuture<AppTools<'shared'>>;
@@ -1,10 +1,12 @@
1
- import { appTools } from './new/index';
2
- export { appTools };
3
- export { initAppContext } from './new/index';
1
+ import type { AppTools, AppToolsOptions, CliPluginFuture } from './types';
2
+ import { initAppContext } from './utils/initAppContext';
3
+ export * from './defineConfig';
4
+ export declare const appTools: (options?: AppToolsOptions) => CliPluginFuture<AppTools<'shared'>>;
4
5
  export { defineConfig, defineLegacyConfig } from './defineConfig';
5
6
  export { mergeConfig } from '@modern-js/core';
6
7
  export type { RuntimeUserConfig } from './types/config';
7
8
  export { dev } from './commands/dev';
8
9
  export type { DevOptions } from './utils/types';
9
10
  export * from './types';
11
+ export { initAppContext };
10
12
  export default appTools;
@@ -5,3 +5,4 @@ export declare const getServerRoutes: (entrypoints: Entrypoint[], { appContext,
5
5
  appContext: AppToolsContext<'shared'>;
6
6
  config: AppNormalizedConfig<'shared'>;
7
7
  }) => ServerRoute[];
8
+ export declare const getProdServerRoutes: (distDirectory: string) => any;
@@ -6,4 +6,5 @@ export declare const parseModule: ({ source, filename, }: {
6
6
  }) => Promise<readonly [imports: readonly import("es-module-lexer").ImportSpecifier[], exports: readonly import("es-module-lexer").ExportSpecifier[], facade: boolean]>;
7
7
  export declare const getServerCombinedModueFile: (internalDirectory: string, entryName: string) => string;
8
8
  export declare const checkIsBuildCommands: () => boolean;
9
+ export declare const checkIsServeCommand: () => boolean;
9
10
  export declare const isSubDirOrEqual: (parent: string, child: string) => boolean;
@@ -1,3 +1,3 @@
1
- import type { AppTools, CliPlugin } from '../types';
2
- declare const _default: () => CliPlugin<AppTools>;
1
+ import type { AppTools, CliPluginFuture } from '../types';
2
+ declare const _default: () => CliPluginFuture<AppTools<'shared'>>;
3
3
  export default _default;
@@ -40,7 +40,6 @@ export interface AppToolsUserConfig<B extends Bundler> {
40
40
  testing?: TestingUserConfig;
41
41
  builderPlugins?: Array<LooseRsbuildPlugin | UniBuilderPlugin>;
42
42
  performance?: PerformanceUserConfig;
43
- devtools?: any;
44
43
  environments?: RsbuildConfig['environments'];
45
44
  }
46
45
  interface SharedNormalizedConfig<RawConfig> {
@@ -5,6 +5,7 @@ import type { AppToolsHooks } from './hooks';
5
5
  import type { AppToolsLegacyNormalizedConfig, AppToolsLegacyUserConfig } from './legacyConfig';
6
6
  import type { AppToolsExtendAPI, AppToolsExtendContext, AppToolsExtendHooks } from './new';
7
7
  import type { Bundler } from './utils';
8
+ export type { CLIPluginExtends };
8
9
  export * from './hooks';
9
10
  export * from './config';
10
11
  export * from './legacyConfig';
@@ -33,3 +34,4 @@ export type AppToolsOptions = {
33
34
  * */
34
35
  bundler?: 'rspack' | 'webpack' | 'experimental-rspack';
35
36
  };
37
+ export type { AppToolsExtendAPI, AppToolsExtendContext, AppToolsExtendHooks, AppToolsContext, AppToolsHooks as AppToolsFeatureHooks, } from './new';