@bleedingdev/modern-js-app-tools 3.9.0-ultramodern.8 → 3.9.3-ultramodern.1

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 (149) hide show
  1. package/bin/modern-bundle-docs.js +2 -2
  2. package/bin/modern.js +2 -2
  3. package/dist/cjs/builder/generator/adapterCopy.js +26 -0
  4. package/dist/cjs/builder/generator/createCopyPattern.js +2 -1
  5. package/dist/cjs/builder/index.js +4 -0
  6. package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +2 -1
  7. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +11 -6
  8. package/dist/cjs/builder/shared/lazyCompilation.js +26 -0
  9. package/dist/cjs/commands/build.js +1 -2
  10. package/dist/cjs/commands/deploy.js +1 -3
  11. package/dist/cjs/commands/index.js +10 -2
  12. package/dist/cjs/compat/hooks.js +1 -1
  13. package/dist/cjs/esm/ts-paths-loader.js +5 -4
  14. package/dist/cjs/esm/ts-paths-loader.mjs +5 -4
  15. package/dist/cjs/index.js +89 -110
  16. package/dist/cjs/plugins/analyze/getFileSystemEntry.js +1 -1
  17. package/dist/cjs/plugins/analyze/getServerRoutes.js +1 -1
  18. package/dist/cjs/plugins/analyze/index.js +2 -2
  19. package/dist/cjs/plugins/analyze/utils.js +6 -6
  20. package/dist/cjs/plugins/deploy/index.js +7 -28
  21. package/dist/cjs/plugins/deploy/platforms/netlify.js +2 -1
  22. package/dist/cjs/plugins/deploy/platforms/node.js +12 -3
  23. package/dist/cjs/plugins/deploy/platforms/templates/node-entry.cjs +3 -2
  24. package/dist/cjs/plugins/deploy/platforms/templates/node-entry.mjs +3 -2
  25. package/dist/cjs/plugins/deploy/platforms/vercel.js +2 -1
  26. package/dist/cjs/plugins/deploy/utils/index.js +15 -12
  27. package/dist/cjs/plugins/initialize/index.js +6 -5
  28. package/dist/cjs/plugins/serverBuild.js +0 -2
  29. package/dist/cjs/run/index.js +5 -5
  30. package/dist/cjs/{plugins/serverRuntime.js → server-plugin.js} +13 -16
  31. package/dist/cjs/types/config/base.js +62 -0
  32. package/dist/cjs/types/plugin-base.js +18 -0
  33. package/dist/cjs/types/plugin.js +46 -2
  34. package/dist/cjs/utils/initAppContext.js +1 -1
  35. package/dist/cjs/utils/loadPlugins.js +13 -7
  36. package/dist/cjs/utils/register.js +1 -1
  37. package/dist/esm/builder/generator/adapterCopy.mjs +23 -1
  38. package/dist/esm/builder/generator/createCopyPattern.mjs +2 -1
  39. package/dist/esm/builder/index.mjs +1 -0
  40. package/dist/esm/builder/shared/builderPlugins/adapterHtml.mjs +2 -1
  41. package/dist/esm/builder/shared/builderPlugins/adapterSSR.mjs +9 -7
  42. package/dist/esm/builder/shared/lazyCompilation.mjs +14 -1
  43. package/dist/esm/commands/build.mjs +1 -2
  44. package/dist/esm/commands/deploy.mjs +1 -3
  45. package/dist/esm/commands/index.mjs +10 -2
  46. package/dist/esm/compat/hooks.mjs +1 -1
  47. package/dist/esm/esm/ts-paths-loader.mjs +5 -4
  48. package/dist/esm/index.mjs +13 -20
  49. package/dist/esm/plugins/analyze/getFileSystemEntry.mjs +1 -1
  50. package/dist/esm/plugins/analyze/getServerRoutes.mjs +1 -1
  51. package/dist/esm/plugins/analyze/index.mjs +2 -2
  52. package/dist/esm/plugins/analyze/utils.mjs +7 -7
  53. package/dist/esm/plugins/deploy/index.mjs +5 -21
  54. package/dist/esm/plugins/deploy/platforms/netlify.mjs +2 -1
  55. package/dist/esm/plugins/deploy/platforms/node.mjs +12 -3
  56. package/dist/esm/plugins/deploy/platforms/templates/node-entry.cjs +3 -2
  57. package/dist/esm/plugins/deploy/platforms/templates/node-entry.mjs +3 -2
  58. package/dist/esm/plugins/deploy/platforms/vercel.mjs +2 -1
  59. package/dist/esm/plugins/deploy/utils/index.mjs +17 -14
  60. package/dist/esm/plugins/initialize/index.mjs +6 -5
  61. package/dist/esm/plugins/serverBuild.mjs +0 -2
  62. package/dist/esm/run/index.mjs +5 -5
  63. package/dist/esm/server-plugin.mjs +1 -0
  64. package/dist/esm/types/config/base.mjs +1 -0
  65. package/dist/esm/types/plugin-base.mjs +0 -0
  66. package/dist/esm/types/plugin.mjs +1 -0
  67. package/dist/esm/utils/initAppContext.mjs +2 -2
  68. package/dist/esm/utils/loadPlugins.mjs +4 -8
  69. package/dist/esm/utils/register.mjs +1 -1
  70. package/dist/esm-node/builder/generator/adapterCopy.mjs +23 -1
  71. package/dist/esm-node/builder/generator/createCopyPattern.mjs +2 -1
  72. package/dist/esm-node/builder/index.mjs +1 -0
  73. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.mjs +2 -1
  74. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.mjs +9 -7
  75. package/dist/esm-node/builder/shared/lazyCompilation.mjs +14 -1
  76. package/dist/esm-node/commands/build.mjs +1 -2
  77. package/dist/esm-node/commands/deploy.mjs +1 -3
  78. package/dist/esm-node/commands/index.mjs +10 -2
  79. package/dist/esm-node/compat/hooks.mjs +1 -1
  80. package/dist/esm-node/esm/ts-paths-loader.mjs +5 -4
  81. package/dist/esm-node/index.mjs +14 -22
  82. package/dist/esm-node/plugins/analyze/getFileSystemEntry.mjs +1 -1
  83. package/dist/esm-node/plugins/analyze/getServerRoutes.mjs +1 -1
  84. package/dist/esm-node/plugins/analyze/index.mjs +2 -2
  85. package/dist/esm-node/plugins/analyze/utils.mjs +7 -7
  86. package/dist/esm-node/plugins/deploy/index.mjs +5 -21
  87. package/dist/esm-node/plugins/deploy/platforms/netlify.mjs +2 -1
  88. package/dist/esm-node/plugins/deploy/platforms/node.mjs +12 -3
  89. package/dist/esm-node/plugins/deploy/platforms/templates/node-entry.cjs +3 -2
  90. package/dist/esm-node/plugins/deploy/platforms/templates/node-entry.mjs +3 -2
  91. package/dist/esm-node/plugins/deploy/platforms/vercel.mjs +2 -1
  92. package/dist/esm-node/plugins/deploy/utils/index.mjs +17 -15
  93. package/dist/esm-node/plugins/initialize/index.mjs +6 -5
  94. package/dist/esm-node/plugins/serverBuild.mjs +0 -2
  95. package/dist/esm-node/run/index.mjs +5 -5
  96. package/dist/esm-node/server-plugin.mjs +2 -0
  97. package/dist/esm-node/types/config/base.mjs +2 -0
  98. package/dist/esm-node/types/plugin-base.mjs +1 -0
  99. package/dist/esm-node/types/plugin.mjs +1 -0
  100. package/dist/esm-node/utils/initAppContext.mjs +2 -2
  101. package/dist/esm-node/utils/loadPlugins.mjs +4 -8
  102. package/dist/esm-node/utils/register.mjs +1 -1
  103. package/dist/types/builder/generator/adapterCopy.d.ts +13 -1
  104. package/dist/types/builder/index.d.ts +1 -0
  105. package/dist/types/builder/shared/builderPlugins/adapterBasic.d.ts +4 -2
  106. package/dist/types/builder/shared/builderPlugins/adapterSSR.d.ts +2 -1
  107. package/dist/types/builder/shared/builderPlugins/builderHooks.d.ts +10 -2
  108. package/dist/types/builder/shared/lazyCompilation.d.ts +15 -0
  109. package/dist/types/compat/hooks.d.ts +3 -2
  110. package/dist/types/index.d.ts +3 -4
  111. package/dist/types/plugins/analyze/getBundleEntry.d.ts +5 -4
  112. package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +5 -4
  113. package/dist/types/plugins/analyze/utils.d.ts +2 -2
  114. package/dist/types/plugins/deploy/index.d.ts +1 -4
  115. package/dist/types/plugins/deploy/utils/generator.d.ts +1 -1
  116. package/dist/types/plugins/deploy/utils/index.d.ts +1 -1
  117. package/dist/types/run/index.d.ts +1 -1
  118. package/dist/types/server-plugin.d.ts +10 -0
  119. package/dist/types/types/config/base.d.ts +58 -0
  120. package/dist/types/types/config/deploy.d.ts +2 -50
  121. package/dist/types/types/config/dev.d.ts +1 -1
  122. package/dist/types/types/config/index.d.ts +18 -42
  123. package/dist/types/types/config/output.d.ts +2 -2
  124. package/dist/types/types/config/testing.d.ts +1 -1
  125. package/dist/types/types/config/tools.d.ts +1 -1
  126. package/dist/types/types/plugin-base.d.ts +188 -0
  127. package/dist/types/types/plugin.d.ts +9 -183
  128. package/dist/types/utils/initAppContext.d.ts +2 -2
  129. package/docs/apis/app/commands.md +1 -0
  130. package/docs/configure/app/bff/effect.md +5 -12
  131. package/docs/configure/app/output/disable-svgr.md +4 -0
  132. package/docs/configure/app/output/svg-default-export.md +4 -0
  133. package/docs/configure/app/source/react-compiler.md +2 -0
  134. package/docs/configure/app/tools/less.md +94 -19
  135. package/docs/configure/app/tools/sass.md +87 -18
  136. package/docs/configure/app/tools/svgr.md +91 -0
  137. package/docs/configure/app/tools/ts-checker.md +7 -21
  138. package/docs/guides/basic-features/render/ssr-cache.md +14 -1
  139. package/docs/guides/basic-features/static-assets/svg-assets.md +29 -17
  140. package/docs/guides/basic-features/testing/rstest.md +0 -2
  141. package/docs/guides/get-started/quick-start.md +1 -1
  142. package/docs/guides/get-started/ultramodern.md +45 -14
  143. package/docs/llms.txt +4 -3
  144. package/docs/plugin/introduction.md +10 -10
  145. package/docs/plugin/server-plugins/api.md +1 -0
  146. package/package.json +67 -30
  147. package/dist/esm/plugins/serverRuntime.mjs +0 -15
  148. package/dist/esm-node/plugins/serverRuntime.mjs +0 -16
  149. package/dist/types/plugins/serverRuntime.d.ts +0 -3
@@ -1,4 +1,5 @@
1
1
  import "node:module";
2
+ import node_path from "node:path";
2
3
  import { collectRouteComponentFiles, normalizeModulePath } from "@modern-js/utils";
3
4
  function aggregateEagerRouteComponentFiles(byEntry) {
4
5
  const files = new Set();
@@ -21,6 +22,18 @@ function buildSSRLazyCompilationTest(eagerRouteFiles, userTest) {
21
22
  return userTestFn(m);
22
23
  };
23
24
  }
25
+ function buildDefaultLazyCompilationTest(appDirectory, internalDirectory) {
26
+ let dirs;
27
+ return (m)=>{
28
+ if (!('resource' in m) || 'string' != typeof m.resource) return true;
29
+ dirs ??= {
30
+ app: normalizeModulePath(appDirectory),
31
+ internal: normalizeModulePath(internalDirectory)
32
+ };
33
+ const file = m.resource.split('?')[0].split(node_path.sep).join('/');
34
+ return file.startsWith(`${dirs.app}/`) && !file.startsWith(`${dirs.internal}/`) && !file.slice(dirs.app.length).includes('/node_modules/');
35
+ };
36
+ }
24
37
  function planSSRLazyCompilation(current, info) {
25
38
  if (!current) return {
26
39
  apply: false
@@ -42,4 +55,4 @@ function planSSRLazyCompilation(current, info) {
42
55
  }
43
56
  };
44
57
  }
45
- export { aggregateEagerRouteComponentFiles, buildSSRLazyCompilationTest, collectRouteComponentFiles, normalizeModulePath, planSSRLazyCompilation };
58
+ export { aggregateEagerRouteComponentFiles, buildDefaultLazyCompilationTest, buildSSRLazyCompilationTest, collectRouteComponentFiles, normalizeModulePath, planSSRLazyCompilation };
@@ -57,9 +57,8 @@ const build = async (api, options)=>{
57
57
  logger.info('Starting production build...');
58
58
  if (!appContext.builder) throw new Error('Expect the Builder to have been initialized, But the appContext.builder received `undefined`');
59
59
  await appContext.builder.onAfterBuild(async ()=>copyEnvFiles(appContext.appDirectory, appContext.distDirectory));
60
- const buildResult = await appContext.builder.build({
60
+ await appContext.builder.build({
61
61
  watch: options?.watch
62
62
  });
63
- if (!options?.watch) await buildResult?.close();
64
63
  };
65
64
  export { build };
@@ -1,11 +1,9 @@
1
1
  import "node:module";
2
2
  import { getServerPlugins } from "../utils/loadPlugins.mjs";
3
- import { build } from "./build.mjs";
4
3
  const deploy = async (api, options = {})=>{
5
4
  const hooks = api.getHooks();
6
5
  const { metaName } = api.getAppContext();
7
- if (options.skipBuild) await getServerPlugins(api, metaName);
8
- else await build(api);
6
+ await getServerPlugins(api, metaName);
9
7
  await hooks.onBeforeDeploy.call(options);
10
8
  await hooks.deploy.call();
11
9
  await hooks.onAfterDeploy.call(options);
@@ -1,5 +1,9 @@
1
1
  import "node:module";
2
2
  import { i18n, localeKeys } from "../locale/index.mjs";
3
+ const deployTargetOption = [
4
+ '--deploy-target <target>',
5
+ 'deploy target; overrides deploy.target and MODERNJS_DEPLOY'
6
+ ];
3
7
  const devCommand = async (program, api)=>{
4
8
  program.command('dev').alias('start').usage('[options]').description(i18n.t(localeKeys.command.dev.describe)).option('-c --config <config>', i18n.t(localeKeys.command.shared.config)).option('-e --entry [entry...]', i18n.t(localeKeys.command.dev.entry)).option('--analyze', i18n.t(localeKeys.command.shared.analyze)).option('--api-only', i18n.t(localeKeys.command.dev.apiOnly)).option('--web-only', i18n.t(localeKeys.command.dev.webOnly)).action(async (options)=>{
5
9
  const { dev } = await import("./dev.mjs");
@@ -7,7 +11,7 @@ const devCommand = async (program, api)=>{
7
11
  });
8
12
  };
9
13
  const buildCommand = async (program, api)=>{
10
- program.command('build').usage('[options]').description(i18n.t(localeKeys.command.build.describe)).option('-c --config <config>', i18n.t(localeKeys.command.shared.config)).option('--analyze', i18n.t(localeKeys.command.shared.analyze)).option('-w --watch', i18n.t(localeKeys.command.build.watch)).action(async (options)=>{
14
+ program.command('build').usage('[options]').description(i18n.t(localeKeys.command.build.describe)).option('-c --config <config>', i18n.t(localeKeys.command.shared.config)).option('--analyze', i18n.t(localeKeys.command.shared.analyze)).option('-w --watch', i18n.t(localeKeys.command.build.watch)).option(...deployTargetOption).action(async (options)=>{
11
15
  const { build } = await import("./build.mjs");
12
16
  await build(api, options);
13
17
  });
@@ -19,7 +23,11 @@ const serverCommand = (program, api)=>{
19
23
  });
20
24
  };
21
25
  const deployCommand = (program, api)=>{
22
- program.command('deploy').usage('[options]').option('-c --config <config>', i18n.t(localeKeys.command.shared.config)).option('-s --skip-build', i18n.t(localeKeys.command.shared.skipBuild)).description(i18n.t(localeKeys.command.deploy.describe)).action(async (options)=>{
26
+ program.command('deploy').usage('[options]').option('-c --config <config>', i18n.t(localeKeys.command.shared.config)).option('-s --skip-build', i18n.t(localeKeys.command.shared.skipBuild)).option(...deployTargetOption).description(i18n.t(localeKeys.command.deploy.describe)).action(async (options)=>{
27
+ if (!options.skipBuild) {
28
+ const { build } = await import("./build.mjs");
29
+ await build(api);
30
+ }
23
31
  const { deploy } = await import("./deploy.mjs");
24
32
  await deploy(api, options);
25
33
  process.exit(0);
@@ -60,7 +60,7 @@ function handleSetupResult(setupResult, api) {
60
60
  if (newAPI && api[newAPI]) api[newAPI](async (...params)=>{
61
61
  const { isMultiple, params: transformParams } = transformHookParams(key, params);
62
62
  if (isMultiple) return transformHookResult(key, await fn(...transformParams));
63
- return transformHookResult(key, await fn(transformParams));
63
+ else return transformHookResult(key, await fn(transformParams));
64
64
  });
65
65
  }
66
66
  });
@@ -15,8 +15,9 @@ const getParentPath = (parentURL)=>{
15
15
  } catch {}
16
16
  return process.cwd();
17
17
  };
18
+ const resolveSourcePath = (resolvedPath, context, defaultResolve)=>defaultResolve(context.conditions?.find((condition)=>'require' === condition || 'import' === condition) === 'require' ? resolvedPath : pathToFileURL(resolvedPath).href, context, defaultResolve);
18
19
  async function initialize({ appDir: currentAppDir, baseUrl, paths }) {
19
- appDir = node_path.resolve(currentAppDir);
20
+ appDir = node_fs.existsSync(currentAppDir) ? node_fs.realpathSync(currentAppDir) : node_path.resolve(currentAppDir);
20
21
  matchPath = createMatchPath(baseUrl || './', paths || {});
21
22
  }
22
23
  function resolve(specifier, context, defaultResolve) {
@@ -26,12 +27,12 @@ function resolve(specifier, context, defaultResolve) {
26
27
  if ((specifier.startsWith('./') || specifier.startsWith('../')) && !node_path.extname(specifier) && isAppFile) {
27
28
  const matchedPath = node_path.resolve(parentPath, specifier);
28
29
  const resolvedPath = findSourceEntry(matchedPath) || matchedPath;
29
- if (resolvedPath && node_fs.existsSync(resolvedPath)) return defaultResolve(pathToFileURL(resolvedPath).href, context, defaultResolve);
30
+ if (resolvedPath && node_fs.existsSync(resolvedPath)) return resolveSourcePath(resolvedPath, context, defaultResolve);
30
31
  }
31
- if (!matchPath) return defaultResolve(specifier, context, defaultResolve);
32
+ if (!matchPath || !isAppFile) return defaultResolve(specifier, context, defaultResolve);
32
33
  const match = findMatchedSourcePath(matchPath, specifier);
33
34
  if (!match) return defaultResolve(specifier, context, defaultResolve);
34
35
  const resolvedPath = findSourceEntry(match) || match;
35
- return defaultResolve(pathToFileURL(resolvedPath).href, context, defaultResolve);
36
+ return resolveSourcePath(resolvedPath, context, defaultResolve);
36
37
  }
37
38
  export { initialize, resolve };
@@ -1,9 +1,10 @@
1
- import __rslib_shim_module__ from "node:module";
2
- const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(/*#__PURE__*/ (()=>import.meta.url)());
1
+ import "node:module";
2
+ import { resolveDeployTarget } from "@modern-js/app-tools-extensions/deploy-output/target";
3
+ import { createPolicyDefaultsPlugin } from "@modern-js/app-tools-extensions/policy-defaults";
3
4
  import { castArray } from "@modern-js/builder";
4
5
  import { getLocaleLanguage } from "@modern-js/i18n-utils/language-detector";
5
6
  import { createAsyncHook } from "@modern-js/plugin";
6
- import { cleanRequireCache, deprecatedCommands, emptyDir, getArgv, getCommand } from "@modern-js/utils";
7
+ import { deprecatedCommands, emptyDir, getArgv, getCommand } from "@modern-js/utils";
7
8
  import path from "path";
8
9
  import { buildCommand, deployCommand, devCommand, infoCommand, inspectCommand, serverCommand } from "./commands/index.mjs";
9
10
  import { compatPlugin } from "./compat/index.mjs";
@@ -13,21 +14,20 @@ import analyze from "./plugins/analyze/index.mjs";
13
14
  import deploy from "./plugins/deploy/index.mjs";
14
15
  import initialize from "./plugins/initialize/index.mjs";
15
16
  import serverBuild from "./plugins/serverBuild.mjs";
16
- import serverRuntime from "./plugins/serverRuntime.mjs";
17
17
  import { generateWatchFiles } from "./utils/generateWatchFiles.mjs";
18
18
  import { initAppContext } from "./utils/initAppContext.mjs";
19
19
  import { restart } from "./utils/restart.mjs";
20
20
  export * from "./defineConfig.mjs";
21
21
  export * from "./types/index.mjs";
22
- const appTools = ()=>({
22
+ const appTools = (options = {})=>({
23
23
  name: '@modern-js/app-tools',
24
24
  usePlugins: [
25
- serverRuntime(),
26
25
  compatPlugin(),
27
26
  initialize(),
28
27
  analyze(),
29
28
  serverBuild(),
30
- deploy()
29
+ deploy(),
30
+ createPolicyDefaultsPlugin(options)
31
31
  ],
32
32
  post: [
33
33
  '@modern-js/plugin-initialize',
@@ -74,6 +74,11 @@ const appTools = ()=>({
74
74
  deprecatedCommands(program);
75
75
  });
76
76
  api.onPrepare(async ()=>{
77
+ api.updateAppContext({
78
+ deployTarget: resolveDeployTarget({
79
+ configTarget: api.getNormalizedConfig().deploy?.target
80
+ })
81
+ });
77
82
  const command = getCommand();
78
83
  if ('deploy' === command) {
79
84
  const isSkipBuild = [
@@ -82,18 +87,12 @@ const appTools = ()=>({
82
87
  ].some((tag)=>getArgv().includes(tag));
83
88
  if (isSkipBuild) return;
84
89
  }
85
- const { command: contextCommand } = api.getAppContext();
86
- const shouldClean = [
90
+ if ([
87
91
  'dev',
88
92
  'start',
89
93
  'build',
90
94
  'deploy'
91
- ].includes(command) || [
92
- 'dev',
93
- 'start',
94
- 'build'
95
- ].includes(contextCommand);
96
- if (shouldClean) {
95
+ ].includes(command)) {
97
96
  const resolvedConfig = api.getNormalizedConfig();
98
97
  if (resolvedConfig.output.cleanDistPath) {
99
98
  const appContext = api.getAppContext();
@@ -124,17 +123,10 @@ const appTools = ()=>({
124
123
  await restart(api.getHooks(), filename);
125
124
  }
126
125
  });
127
- api.onBeforeRestart(()=>{
128
- cleanRequireCache([
129
- require.resolve('./plugins/analyze')
130
- ]);
131
- });
132
126
  }
133
127
  });
134
128
  const src = appTools;
135
129
  export { defineConfig } from "./defineConfig.mjs";
136
- export { build } from "./commands/build.mjs";
137
- export { deploy } from "./commands/deploy.mjs";
138
130
  export { dev } from "./commands/dev.mjs";
139
131
  export { serve } from "./commands/serve.mjs";
140
132
  export { resolveModernRsbuildConfig } from "./rsbuild.mjs";
@@ -62,6 +62,6 @@ const getFileSystemEntry = async (hooks, appContext, config)=>{
62
62
  }));
63
63
  return scanDir(hooks, dirs);
64
64
  } else throw Error("source.entriesDir accept a directory.");
65
- throw Error(`src dir ${entriesDir} not found.`);
65
+ else throw Error(`src dir ${entriesDir} not found.`);
66
66
  };
67
67
  export { getFileSystemEntry, hasEntry, hasServerEntry };
@@ -27,7 +27,7 @@ const applyRouteOptions = (original, routeOptions)=>{
27
27
  ...original,
28
28
  urlPath: url
29
29
  };
30
- {
30
+ else {
31
31
  const { path: urlPath, ...other } = url;
32
32
  return {
33
33
  ...original,
@@ -24,7 +24,7 @@ const analyze = ()=>({
24
24
  const resolvedConfig = api.getNormalizedConfig();
25
25
  const hooks = api.getHooks();
26
26
  try {
27
- if (checkIsBuildCommands(appContext.command)) fs.emptydirSync(appContext.internalDirectory);
27
+ if (checkIsBuildCommands()) fs.emptydirSync(appContext.internalDirectory);
28
28
  } catch {}
29
29
  const apiOnly = await isApiOnly(appContext.appDirectory, resolvedConfig.source?.entriesDir, appContext.apiDirectory);
30
30
  const [{ getProdEntrypoints, getProdServerRoutes }] = await Promise.all([
@@ -126,7 +126,7 @@ const analyze = ()=>({
126
126
  htmlTemplates
127
127
  };
128
128
  api.updateAppContext(appContext);
129
- if (checkIsBuildCommands(appContext.command)) {
129
+ if (checkIsBuildCommands()) {
130
130
  await hooks.generateEntryCode.call({
131
131
  entrypoints
132
132
  });
@@ -1,6 +1,6 @@
1
1
  import "node:module";
2
2
  import { JS_EXTENSIONS, getCommand, normalizeToPosixPath } from "@modern-js/utils";
3
- import { parse } from "es-module-lexer";
3
+ import { init, parse } from "es-module-lexer";
4
4
  import { transform } from "esbuild";
5
5
  import fs from "fs";
6
6
  import path from "path";
@@ -10,14 +10,14 @@ const walkDirectory = (dir)=>fs.readdirSync(dir).reduce((previous, filename)=>{
10
10
  ...previous,
11
11
  ...walkDirectory(filePath)
12
12
  ];
13
- return [
13
+ else return [
14
14
  ...previous,
15
15
  filePath
16
16
  ];
17
17
  }, []);
18
18
  const replaceWithAlias = (base, filePath, alias)=>{
19
19
  if (filePath.includes(base)) return normalizeToPosixPath(path.join(alias, path.relative(base, filePath)));
20
- return filePath;
20
+ else return filePath;
21
21
  };
22
22
  const parseModule = async ({ source, filename })=>{
23
23
  let content = source;
@@ -36,10 +36,11 @@ const parseModule = async ({ source, filename })=>{
36
36
  });
37
37
  content = result.code;
38
38
  }
39
- return await parse(content);
39
+ await init();
40
+ return parse(content);
40
41
  };
41
42
  const getServerCombinedModuleFile = (internalDirectory, entryName)=>path.join(internalDirectory, entryName, 'server-loader-combined.js');
42
- const checkIsBuildCommands = (contextCommand)=>{
43
+ const checkIsBuildCommands = ()=>{
43
44
  const buildCommands = [
44
45
  'dev',
45
46
  'start',
@@ -49,8 +50,7 @@ const checkIsBuildCommands = (contextCommand)=>{
49
50
  'dev-worker'
50
51
  ];
51
52
  const command = getCommand();
52
- if (buildCommands.includes(command)) return true;
53
- return 'dev' === contextCommand || 'start' === contextCommand || 'build' === contextCommand || 'deploy' === contextCommand;
53
+ return buildCommands.includes(command);
54
54
  };
55
55
  const checkIsServeCommand = ()=>{
56
56
  const command = getCommand();
@@ -1,6 +1,6 @@
1
1
  import "node:module";
2
2
  import { createCloudflarePreset } from "@modern-js/app-tools-extensions/cloudflare";
3
- import { provider } from "std-env";
3
+ import { getDeployingTarget } from "@modern-js/app-tools-extensions/deploy-output/target";
4
4
  import { createGhPagesPreset } from "./platforms/gh-pages.mjs";
5
5
  import { createNetlifyPreset } from "./platforms/netlify.mjs";
6
6
  import { createNodePreset } from "./platforms/node.mjs";
@@ -13,24 +13,11 @@ const deployPresets = {
13
13
  ghPages: createGhPagesPreset,
14
14
  cloudflare: createCloudflarePreset
15
15
  };
16
- const getSupportedDeployTargets = ()=>Object.keys(deployPresets);
17
- const isDeployTarget = (target)=>Object.prototype.hasOwnProperty.call(deployPresets, target);
18
- const providerDeployTargets = {
19
- vercel: 'vercel',
20
- netlify: 'netlify',
21
- cloudflare: 'cloudflare',
22
- cloudflare_pages: 'cloudflare',
23
- cloudflare_workers: 'cloudflare'
24
- };
25
- const normalizeDetectedProvider = (value)=>value ? providerDeployTargets[value] : void 0;
26
- const resolveDeployTarget = (modernConfig, envDeployTarget = process.env.MODERNJS_DEPLOY, detectedProvider = provider)=>modernConfig.deploy?.target || envDeployTarget || normalizeDetectedProvider(detectedProvider) || 'node';
27
16
  async function getDeployPreset(appContext, modernConfig, deployTarget, api) {
28
17
  const { appDirectory, distDirectory, metaName } = appContext;
29
18
  const { useSSR, useAPI, useWebServer } = getProjectUsage(appDirectory, distDirectory, metaName);
30
19
  const needModernServer = useSSR || useAPI || useWebServer;
31
- if (!isDeployTarget(deployTarget)) throw new Error(`Unknown deploy target: '${deployTarget}'. deploy.target or MODERNJS_DEPLOY should be one of: ${getSupportedDeployTargets().join(', ')}.`);
32
- const createPreset = deployPresets[deployTarget];
33
- return createPreset({
20
+ return deployPresets[deployTarget]({
34
21
  appContext,
35
22
  modernConfig,
36
23
  needModernServer,
@@ -42,11 +29,9 @@ const deploy = ()=>({
42
29
  setup: (api)=>{
43
30
  api.deploy(async ()=>{
44
31
  const appContext = api.getAppContext();
45
- const { metaName } = appContext;
46
- const modernConfig = api.getNormalizedConfig();
47
- const deployTarget = resolveDeployTarget(modernConfig);
48
- if ('modern-js' !== metaName && !modernConfig.deploy?.target && !process.env.MODERNJS_DEPLOY) return;
49
- const deployPreset = await getDeployPreset(appContext, modernConfig, deployTarget, api);
32
+ const deployTarget = getDeployingTarget(appContext);
33
+ if (!deployTarget) return;
34
+ const deployPreset = await getDeployPreset(appContext, api.getNormalizedConfig(), deployTarget, api);
50
35
  deployPreset?.prepare && await deployPreset?.prepare();
51
36
  deployPreset?.writeOutput && await deployPreset?.writeOutput();
52
37
  deployPreset?.genEntry && await deployPreset?.genEntry();
@@ -55,4 +40,3 @@ const deploy = ()=>({
55
40
  }
56
41
  });
57
42
  export default deploy;
58
- export { getSupportedDeployTargets, resolveDeployTarget };
@@ -1,6 +1,7 @@
1
1
  import __rslib_shim_module__ from "node:module";
2
2
  const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(/*#__PURE__*/ (()=>import.meta.url)());
3
3
  import node_path from "node:path";
4
+ import { traceDeployFiles } from "@modern-js/app-tools-extensions/deploy-output/trace-files";
4
5
  import { fs, removeModuleSyncFromExports } from "@modern-js/utils";
5
6
  import { nodeDepEmit } from "ndepe";
6
7
  import { isMainEntry } from "../../../utils/routes.mjs";
@@ -73,8 +74,8 @@ const createNetlifyPreset = ({ appContext, modernConfig, needModernServer })=>{
73
74
  if (!needModernServer) return;
74
75
  const entry = isEsmProject ? await resolveESMDependency('@modern-js/prod-server') : require.resolve('@modern-js/prod-server');
75
76
  const netlifyEntry = isEsmProject ? await resolveESMDependency('@modern-js/prod-server/netlify') : require.resolve('@modern-js/prod-server/netlify');
76
- if (!entry || !netlifyEntry) throw new Error('Cannot find @modern-js/prod-server');
77
77
  await nodeDepEmit({
78
+ traceFiles: traceDeployFiles,
78
79
  appDir: appDirectory,
79
80
  sourceDir: funcsDirectory,
80
81
  includeEntries: [
@@ -1,12 +1,14 @@
1
1
  import __rslib_shim_module__ from "node:module";
2
2
  const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(/*#__PURE__*/ (()=>import.meta.url)());
3
+ import { createRequire } from "node:module";
3
4
  import node_path from "node:path";
5
+ import { traceDeployFiles } from "@modern-js/app-tools-extensions/deploy-output/trace-files";
4
6
  import { chalk, fs, removeModuleSyncFromExports } from "@modern-js/utils";
5
7
  import { nodeDepEmit } from "ndepe";
6
8
  import { readTemplate, resolveESMDependency } from "../utils/index.mjs";
7
9
  import { generateHandler } from "../utils/generator.mjs";
8
10
  const createNodePreset = ({ appContext, modernConfig })=>{
9
- const { appDirectory, distDirectory, moduleType } = appContext;
11
+ const { appDirectory, distDirectory, moduleType, serverPlugins } = appContext;
10
12
  const isEsmProject = 'module' === moduleType;
11
13
  const outputDirectory = node_path.join(appDirectory, '.output');
12
14
  const staticDirectory = node_path.join(outputDirectory, 'static');
@@ -36,12 +38,19 @@ const createNodePreset = ({ appContext, modernConfig })=>{
36
38
  async end () {
37
39
  const filter = (filePath)=>!filePath.startsWith(staticDirectory) && !filePath.endsWith('.map');
38
40
  const entry = isEsmProject ? await resolveESMDependency('@modern-js/prod-server') : require.resolve('@modern-js/prod-server');
39
- if (!entry) throw new Error('Cannot find @modern-js/prod-server');
41
+ const requireFromApp = createRequire(node_path.join(appDirectory, 'package.json'));
42
+ const pluginEntries = new Set();
43
+ for (const plugin of serverPlugins)for (const specifier of plugin.includeEntries ?? []){
44
+ pluginEntries.add(requireFromApp.resolve(specifier));
45
+ if (isEsmProject) pluginEntries.add(await resolveESMDependency(specifier, appDirectory));
46
+ }
40
47
  await nodeDepEmit({
48
+ traceFiles: traceDeployFiles,
41
49
  appDir: appDirectory,
42
50
  sourceDir: outputDirectory,
43
51
  includeEntries: [
44
- entry
52
+ entry,
53
+ ...pluginEntries
45
54
  ],
46
55
  copyWholePackage (pkgName) {
47
56
  return '@modern-js/utils' === pkgName;
@@ -35,10 +35,11 @@ async function main() {
35
35
  const app = await createProdServer(prodServerOptions);
36
36
  const port = process.env.PORT || 8080;
37
37
  app.listen({
38
- host: '::',
39
38
  port
40
39
  }, ()=>{
41
- console.log(`\x1b[32mServer is listening on http://[::]:${port}`, '\x1b[0m');
40
+ const address = app.address();
41
+ const loopback = 'IPv6' === address.family ? '[::1]' : '127.0.0.1';
42
+ console.log(`\x1b[32mServer is listening on http://${loopback}:${address.port}`, '\x1b[0m');
42
43
  });
43
44
  }
44
45
  main();
@@ -37,10 +37,11 @@ async function main() {
37
37
  const app = await createProdServer(prodServerOptions);
38
38
  const port = process.env.PORT || 8080;
39
39
  app.listen({
40
- host: '::',
41
40
  port
42
41
  }, ()=>{
43
- console.log(`\x1b[32mServer is listening on http://[::]:${port}`, '\x1b[0m');
42
+ const address = app.address();
43
+ const loopback = 'IPv6' === address.family ? '[::1]' : '127.0.0.1';
44
+ console.log(`\x1b[32mServer is listening on http://${loopback}:${address.port}`, '\x1b[0m');
44
45
  });
45
46
  }
46
47
  main();
@@ -1,6 +1,7 @@
1
1
  import __rslib_shim_module__ from "node:module";
2
2
  const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(/*#__PURE__*/ (()=>import.meta.url)());
3
3
  import node_path from "node:path";
4
+ import { traceDeployFiles } from "@modern-js/app-tools-extensions/deploy-output/trace-files";
4
5
  import { fs, removeModuleSyncFromExports } from "@modern-js/utils";
5
6
  import { nodeDepEmit } from "ndepe";
6
7
  import { isMainEntry } from "../../../utils/routes.mjs";
@@ -93,8 +94,8 @@ const createVercelPreset = ({ appContext, modernConfig, needModernServer })=>{
93
94
  async end () {
94
95
  if (!needModernServer) return;
95
96
  const entry = isEsmProject ? await resolveESMDependency('@modern-js/prod-server') : require.resolve('@modern-js/prod-server');
96
- if (!entry) throw new Error('Cannot find @modern-js/prod-server');
97
97
  await nodeDepEmit({
98
+ traceFiles: traceDeployFiles,
98
99
  appDir: appDirectory,
99
100
  sourceDir: funcsDirectory,
100
101
  includeEntries: [
@@ -1,12 +1,11 @@
1
1
  import "node:module";
2
- import { createRequire } from "node:module";
3
- import { pathToFileURL } from "node:url";
4
- import { ROUTE_SPEC_FILE, SERVER_DIR, dynamicImport, fs, getMeta } from "@modern-js/utils";
2
+ import { fileURLToPath, pathToFileURL } from "node:url";
3
+ import { ROUTE_SPEC_FILE, SERVER_DIR, fs, getMeta } from "@modern-js/utils";
4
+ import { moduleResolve } from "import-meta-resolve";
5
5
  import path from "path";
6
6
  import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
7
7
  import { dirname as __rspack_dirname } from "node:path";
8
8
  var __rspack_import_meta_dirname__ = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
9
- var __rspack_import_meta_filename__ = __rspack_fileURLToPath(import.meta.url);
10
9
  const normalizePath = (filePath)=>filePath.replace(/\\/g, '/');
11
10
  const getProjectUsage = (appDirectory, distDirectory, metaName)=>{
12
11
  const routeJSON = path.join(distDirectory, ROUTE_SPEC_FILE);
@@ -31,17 +30,20 @@ const getProjectUsage = (appDirectory, distDirectory, metaName)=>{
31
30
  };
32
31
  const getTemplatePath = (file)=>path.join(__rspack_import_meta_dirname__, '../platforms/templates', file);
33
32
  const readTemplate = async (file)=>(await fs.readFile(getTemplatePath(file))).toString();
34
- const resolveESMDependency = async (entry)=>{
35
- const conditions = new Set([
36
- 'node',
37
- 'import',
38
- 'module',
39
- 'default'
40
- ]);
33
+ const DEPLOY_CONDITIONS = [
34
+ 'node',
35
+ 'import',
36
+ 'module',
37
+ 'default'
38
+ ];
39
+ const resolveESMDependency = async (entry, fromDirectory)=>{
40
+ const base = fromDirectory ? pathToFileURL(path.join(fromDirectory, 'package.json')) : pathToFileURL(`${__rspack_import_meta_dirname__}/`);
41
41
  try {
42
- const resolverPath = pathToFileURL(createRequire(__rspack_import_meta_filename__).resolve('import-meta-resolve')).href;
43
- const { moduleResolve } = await dynamicImport(resolverPath);
44
- return normalizePath(moduleResolve(entry, pathToFileURL(`${__rspack_import_meta_dirname__}/`), conditions, false).pathname.replace(/^\/(\w):/, '$1:'));
45
- } catch (err) {}
42
+ return normalizePath(fileURLToPath(moduleResolve(entry, base, new Set(DEPLOY_CONDITIONS), false)));
43
+ } catch (cause) {
44
+ throw new Error(`Cannot resolve "${entry}" with conditions [${DEPLOY_CONDITIONS.join(', ')}] from ${base.href}: ${cause.message}`, {
45
+ cause
46
+ });
47
+ }
46
48
  };
47
49
  export { getProjectUsage, getTemplatePath, normalizePath, readTemplate, resolveESMDependency };
@@ -1,5 +1,6 @@
1
1
  import "node:module";
2
2
  import { ensureAbsolutePath, getPort, isDev, isDevCommand } from "@modern-js/utils";
3
+ import { buildDefaultLazyCompilationTest } from "../../builder/shared/lazyCompilation.mjs";
3
4
  import { createDefaultConfig, isLazyCompilationSafeByDefault } from "../../config/index.mjs";
4
5
  const initialize = ()=>({
5
6
  name: '@modern-js/plugin-initialize',
@@ -18,7 +19,8 @@ const initialize = ()=>({
18
19
  ...defaultConfig.dev,
19
20
  lazyCompilation: {
20
21
  imports: true,
21
- entries: false
22
+ entries: false,
23
+ test: buildDefaultLazyCompilationTest(appContext.appDirectory, appContext.internalDirectory)
22
24
  }
23
25
  };
24
26
  return defaultConfig;
@@ -26,7 +28,7 @@ const initialize = ()=>({
26
28
  api.modifyResolvedConfig(async (resolved)=>{
27
29
  let appContext = api.getAppContext();
28
30
  const userConfig = api.getConfig();
29
- const port = await getServerPort(resolved, appContext.command);
31
+ const port = await getServerPort(resolved);
30
32
  appContext = {
31
33
  ...appContext,
32
34
  port,
@@ -61,10 +63,9 @@ function stabilizeConfig(resolve, config, keys) {
61
63
  resolve[key] = config[key] || {};
62
64
  });
63
65
  }
64
- async function getServerPort(config, contextCommand) {
66
+ async function getServerPort(config) {
65
67
  const prodPort = Number(process.env.PORT) || config.server.port || 8080;
66
- const isProgrammaticDev = 'dev' === contextCommand || 'start' === contextCommand;
67
- if (isDev() && (isDevCommand() || isProgrammaticDev)) return getPort(Number(process.env.PORT) || prodPort);
68
+ if (isDev() && isDevCommand()) return getPort(Number(process.env.PORT) || prodPort);
68
69
  return prodPort;
69
70
  }
70
71
  export default initialize;
@@ -30,10 +30,8 @@ const serverBuild = ()=>({
30
30
  sourceDirs.push(serverDir);
31
31
  if (fs.existsSync(sharedDir)) sourceDirs.push(sharedDir);
32
32
  }
33
- const { server } = modernConfig;
34
33
  const { alias } = modernConfig.source;
35
34
  if (sourceDirs.length > 0) await compile(appDirectory, {
36
- server,
37
35
  alias
38
36
  }, {
39
37
  sourceDirs,
@@ -8,21 +8,21 @@ import { loadInternalPlugins } from "../utils/loadPlugins.mjs";
8
8
  async function createRunOptions({ cwd, initialLog, metaName = 'modern-js', version, internalPlugins, configFile }) {
9
9
  const nodeVersion = process.versions.node;
10
10
  const versionArr = nodeVersion.split('.').map(Number);
11
- if (versionArr[0] < 26 || 26 === versionArr[0] && versionArr[1] < 7) throw new Error(`
11
+ if (versionArr[0] < 26 || 26 === versionArr[0] && versionArr[1] < 10) throw new Error(`
12
12
  ${chalk.bgRed.white.bold(' UNSUPPORTED NODE.JS RUNTIME ')}
13
13
 
14
- ${chalk.red.bold(`UltraModern.js requires Node.js >=26.7.0; detected v${nodeVersion}.`)}
14
+ ${chalk.red.bold(`UltraModern.js requires Node.js >=26.10.0; detected v${nodeVersion}.`)}
15
15
  ${chalk.red('- Legacy Node runtimes and TypeScript transpiler fallbacks are unsupported.')}
16
16
 
17
17
  ${chalk.yellow('▸ Detected Runtime:')} ${chalk.yellow.bold(`Node.js v${nodeVersion}`)}
18
- ${chalk.green('▸ Required Minimum:')} ${chalk.green.bold('Node.js v26.7.0 or higher')}
19
- ${chalk.green('▸ Pinned Runtime:')} ${chalk.green.bold('Node.js v26.7.0')}
18
+ ${chalk.green('▸ Required Minimum:')} ${chalk.green.bold('Node.js v26.10.0 or higher')}
19
+ ${chalk.green('▸ Pinned Runtime:')} ${chalk.green.bold('Node.js v26.10.0')}
20
20
 
21
21
  ${chalk.cyan('Immediate Action Required:')}
22
22
  ${chalk.gray('├──')} ${chalk.yellow('Recommended Upgrade')}
23
23
  ${chalk.bold('mise install && mise exec -- node --version')}
24
24
  ${chalk.gray('├──')} ${chalk.yellow('Manual Installation')}
25
- ${chalk.underline('https://nodejs.org/download/release/v26.7.0/')}
25
+ ${chalk.underline('https://nodejs.org/download/release/v26.10.0/')}
26
26
  ${chalk.gray('└──')} ${chalk.yellow('Environment Verification')}
27
27
  ${chalk.bold('node -v && npm -v')}
28
28
 
@@ -0,0 +1,2 @@
1
+ import "node:module";
2
+ export { default } from "@modern-js/server-runtime-extensions/server-plugin";
@@ -0,0 +1,2 @@
1
+ import "node:module";
2
+ export * from "./output.mjs";
@@ -0,0 +1 @@
1
+ import "node:module";
@@ -1 +1,2 @@
1
1
  import "node:module";
2
+ export * from "./plugin-base.mjs";
@@ -1,5 +1,5 @@
1
1
  import "node:module";
2
- import { address, fs } from "@modern-js/utils";
2
+ import { fs, ip } from "@modern-js/utils";
3
3
  import path from "path";
4
4
  function isSymlinkedNodeModules(appDirectory) {
5
5
  try {
@@ -18,7 +18,7 @@ const initAppContext = ({ metaName, appDirectory, runtimeConfigFile, options, te
18
18
  const moduleType = fs.existsSync(pkgPath) ? fs.readJSONSync(pkgPath).type || 'commonjs' : 'commonjs';
19
19
  return {
20
20
  runtimeConfigFile,
21
- ip: address.ip(),
21
+ ip: ip(),
22
22
  port: 0,
23
23
  moduleType,
24
24
  apiDirectory: path.resolve(appDirectory, apiDir),