@modern-js/app-tools 3.0.0-alpha.1 → 3.0.0-alpha.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 (193) hide show
  1. package/bin/modern.js +27 -4
  2. package/dist/cjs/builder/shared/builderPlugins/adapterBasic.js +55 -34
  3. package/dist/cjs/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +3 -3
  4. package/dist/cjs/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +3 -3
  5. package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +1 -1
  6. package/dist/cjs/commands/build.js +3 -3
  7. package/dist/cjs/commands/dev.js +3 -3
  8. package/dist/cjs/commands/index.js +10 -1
  9. package/dist/cjs/commands/info.js +110 -0
  10. package/dist/cjs/commands/serve.js +1 -0
  11. package/dist/cjs/esm/register-esm.js +21 -37
  12. package/dist/cjs/esm/register-esm.mjs +19 -35
  13. package/dist/cjs/esm/utils.js +1 -1
  14. package/dist/cjs/esm/utils.mjs +2 -2
  15. package/dist/cjs/index.js +1 -0
  16. package/dist/cjs/locale/en.js +3 -0
  17. package/dist/cjs/locale/zh.js +3 -0
  18. package/dist/cjs/plugins/deploy/platforms/netlify.js +3 -2
  19. package/dist/cjs/plugins/deploy/platforms/vercel.js +3 -2
  20. package/dist/cjs/plugins/serverBuild.js +1 -3
  21. package/dist/cjs/run/index.js +1 -0
  22. package/dist/cjs/utils/initAppContext.js +2 -1
  23. package/dist/cjs/utils/register.js +28 -42
  24. package/dist/esm/builder/builder-rspack/index.mjs +1 -1
  25. package/dist/esm/builder/generator/adapterCopy.mjs +2 -2
  26. package/dist/esm/builder/generator/createBuilderProviderConfig.mjs +1 -1
  27. package/dist/esm/builder/generator/createCopyPattern.mjs +1 -1
  28. package/dist/esm/builder/generator/index.mjs +4 -4
  29. package/dist/esm/builder/index.mjs +2 -2
  30. package/dist/esm/builder/shared/builderPlugins/adapterBasic.mjs +45 -34
  31. package/dist/esm/builder/shared/builderPlugins/adapterHtml.mjs +1 -1
  32. package/dist/esm/builder/shared/builderPlugins/adapterSSR.mjs +2 -2
  33. package/dist/esm/builder/shared/builderPlugins/index.mjs +4 -4
  34. package/dist/esm/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.mjs +3 -3
  35. package/dist/esm/builder/shared/bundlerPlugins/HtmlBottomTemplate.mjs +3 -3
  36. package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.mjs +1 -1
  37. package/dist/esm/builder/shared/bundlerPlugins/index.mjs +3 -3
  38. package/dist/esm/builder/shared/index.mjs +3 -3
  39. package/dist/esm/commands/build.mjs +6 -6
  40. package/dist/esm/commands/deploy.mjs +1 -1
  41. package/dist/esm/commands/dev.mjs +8 -8
  42. package/dist/esm/commands/index.mjs +14 -8
  43. package/dist/esm/commands/info.mjs +76 -0
  44. package/dist/esm/commands/serve.mjs +3 -2
  45. package/dist/esm/compat/hooks.mjs +2 -2
  46. package/dist/esm/compat/index.mjs +1 -1
  47. package/dist/esm/compat/utils.mjs +1 -1
  48. package/dist/esm/config/default.mjs +1 -1
  49. package/dist/esm/config/index.mjs +2 -2
  50. package/dist/esm/config/initialize/index.mjs +1 -1
  51. package/dist/esm/esm/register-esm.mjs +20 -36
  52. package/dist/esm/esm/utils.mjs +4 -4
  53. package/dist/esm/index.mjs +19 -18
  54. package/dist/esm/locale/en.mjs +3 -0
  55. package/dist/esm/locale/index.mjs +2 -2
  56. package/dist/esm/locale/zh.mjs +3 -0
  57. package/dist/esm/plugins/analyze/getBundleEntry.mjs +2 -2
  58. package/dist/esm/plugins/analyze/getFileSystemEntry.mjs +1 -1
  59. package/dist/esm/plugins/analyze/getHtmlTemplate.mjs +2 -2
  60. package/dist/esm/plugins/analyze/getServerRoutes.mjs +2 -2
  61. package/dist/esm/plugins/analyze/index.mjs +11 -11
  62. package/dist/esm/plugins/deploy/index.mjs +5 -5
  63. package/dist/esm/plugins/deploy/platforms/netlify-entry.mjs +1 -1
  64. package/dist/esm/plugins/deploy/platforms/netlify.mjs +5 -4
  65. package/dist/esm/plugins/deploy/platforms/node.mjs +1 -1
  66. package/dist/esm/plugins/deploy/platforms/vercel-entry.mjs +1 -1
  67. package/dist/esm/plugins/deploy/platforms/vercel.mjs +5 -4
  68. package/dist/esm/plugins/initialize/index.mjs +1 -1
  69. package/dist/esm/plugins/serverBuild.mjs +1 -3
  70. package/dist/esm/run/index.mjs +4 -3
  71. package/dist/esm/types/config/index.mjs +1 -1
  72. package/dist/esm/types/index.mjs +1 -1
  73. package/dist/esm/utils/getConfigFile.mjs +1 -1
  74. package/dist/esm/utils/getSelectedEntries.mjs +1 -1
  75. package/dist/esm/utils/initAppContext.mjs +2 -1
  76. package/dist/esm/utils/register.mjs +27 -41
  77. package/dist/esm-node/builder/builder-rspack/index.mjs +2 -0
  78. package/dist/esm-node/builder/generator/adapterCopy.mjs +2 -0
  79. package/dist/esm-node/builder/generator/createBuilderProviderConfig.mjs +2 -0
  80. package/dist/esm-node/builder/generator/createCopyPattern.mjs +2 -0
  81. package/dist/esm-node/builder/generator/getBuilderEnvironments.mjs +2 -0
  82. package/dist/esm-node/builder/generator/index.mjs +2 -0
  83. package/dist/esm-node/builder/index.mjs +2 -0
  84. package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.mjs +50 -34
  85. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.mjs +2 -0
  86. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.mjs +2 -0
  87. package/dist/esm-node/builder/shared/builderPlugins/builderHooks.mjs +2 -0
  88. package/dist/esm-node/builder/shared/builderPlugins/index.mjs +2 -0
  89. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.mjs +5 -3
  90. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlBottomTemplate.mjs +5 -3
  91. package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.mjs +3 -1
  92. package/dist/esm-node/builder/shared/bundlerPlugins/index.mjs +2 -0
  93. package/dist/esm-node/builder/shared/createCopyInfo.mjs +2 -0
  94. package/dist/esm-node/builder/shared/index.mjs +2 -0
  95. package/dist/esm-node/builder/shared/loaders/serverModuleLoader.mjs +2 -0
  96. package/dist/esm-node/builder/shared/types.mjs +2 -0
  97. package/dist/esm-node/commands/build.mjs +6 -4
  98. package/dist/esm-node/commands/deploy.mjs +2 -0
  99. package/dist/esm-node/commands/dev.mjs +6 -4
  100. package/dist/esm-node/commands/index.mjs +9 -1
  101. package/dist/esm-node/commands/info.mjs +78 -0
  102. package/dist/esm-node/commands/inspect.mjs +2 -0
  103. package/dist/esm-node/commands/serve.mjs +3 -0
  104. package/dist/esm-node/compat/hooks.mjs +2 -0
  105. package/dist/esm-node/compat/index.mjs +2 -0
  106. package/dist/esm-node/compat/utils.mjs +2 -0
  107. package/dist/esm-node/config/default.mjs +2 -0
  108. package/dist/esm-node/config/index.mjs +2 -0
  109. package/dist/esm-node/config/initialize/index.mjs +2 -0
  110. package/dist/esm-node/config/initialize/inits.mjs +2 -0
  111. package/dist/esm-node/constants.mjs +2 -0
  112. package/dist/esm-node/defineConfig.mjs +2 -0
  113. package/dist/esm-node/esm/register-esm.mjs +22 -36
  114. package/dist/esm-node/esm/ts-node-loader.mjs +2 -0
  115. package/dist/esm-node/esm/utils.mjs +6 -4
  116. package/dist/esm-node/exports/server.mjs +2 -0
  117. package/dist/esm-node/index.mjs +4 -1
  118. package/dist/esm-node/locale/en.mjs +5 -0
  119. package/dist/esm-node/locale/index.mjs +2 -0
  120. package/dist/esm-node/locale/zh.mjs +5 -0
  121. package/dist/esm-node/plugins/analyze/constants.mjs +2 -0
  122. package/dist/esm-node/plugins/analyze/getBundleEntry.mjs +2 -0
  123. package/dist/esm-node/plugins/analyze/getFileSystemEntry.mjs +2 -0
  124. package/dist/esm-node/plugins/analyze/getHtmlTemplate.mjs +2 -0
  125. package/dist/esm-node/plugins/analyze/getServerRoutes.mjs +2 -0
  126. package/dist/esm-node/plugins/analyze/index.mjs +2 -0
  127. package/dist/esm-node/plugins/analyze/isDefaultExportFunction.mjs +2 -0
  128. package/dist/esm-node/plugins/analyze/templates.mjs +2 -0
  129. package/dist/esm-node/plugins/analyze/utils.mjs +2 -0
  130. package/dist/esm-node/plugins/deploy/index.mjs +2 -0
  131. package/dist/esm-node/plugins/deploy/platforms/gh-pages.mjs +2 -0
  132. package/dist/esm-node/plugins/deploy/platforms/netlify-entry.mjs +2 -0
  133. package/dist/esm-node/plugins/deploy/platforms/netlify-handler.mjs +5 -0
  134. package/dist/esm-node/plugins/deploy/platforms/netlify.mjs +11 -5
  135. package/dist/esm-node/plugins/deploy/platforms/node-entry.mjs +5 -0
  136. package/dist/esm-node/plugins/deploy/platforms/node.mjs +6 -1
  137. package/dist/esm-node/plugins/deploy/platforms/platform.mjs +2 -0
  138. package/dist/esm-node/plugins/deploy/platforms/vercel-entry.mjs +2 -0
  139. package/dist/esm-node/plugins/deploy/platforms/vercel-handler.mjs +5 -0
  140. package/dist/esm-node/plugins/deploy/platforms/vercel.mjs +11 -5
  141. package/dist/esm-node/plugins/deploy/utils.mjs +2 -0
  142. package/dist/esm-node/plugins/initialize/index.mjs +2 -0
  143. package/dist/esm-node/plugins/serverBuild.mjs +3 -3
  144. package/dist/esm-node/plugins/serverRuntime.mjs +2 -0
  145. package/dist/esm-node/run/index.mjs +3 -0
  146. package/dist/esm-node/types/config/deploy.mjs +2 -0
  147. package/dist/esm-node/types/config/dev.mjs +2 -0
  148. package/dist/esm-node/types/config/experiments.mjs +2 -0
  149. package/dist/esm-node/types/config/html.mjs +2 -0
  150. package/dist/esm-node/types/config/index.mjs +2 -0
  151. package/dist/esm-node/types/config/output.mjs +2 -0
  152. package/dist/esm-node/types/config/performance.mjs +2 -0
  153. package/dist/esm-node/types/config/resolve.mjs +2 -0
  154. package/dist/esm-node/types/config/security.mjs +2 -0
  155. package/dist/esm-node/types/config/source.mjs +2 -0
  156. package/dist/esm-node/types/config/testing.mjs +2 -0
  157. package/dist/esm-node/types/config/tools.mjs +2 -0
  158. package/dist/esm-node/types/index.mjs +2 -0
  159. package/dist/esm-node/types/plugin.mjs +2 -0
  160. package/dist/esm-node/types/utils.mjs +2 -0
  161. package/dist/esm-node/utils/config.mjs +2 -0
  162. package/dist/esm-node/utils/createServer.mjs +2 -0
  163. package/dist/esm-node/utils/env.mjs +2 -0
  164. package/dist/esm-node/utils/generateWatchFiles.mjs +2 -0
  165. package/dist/esm-node/utils/getConfigFile.mjs +2 -0
  166. package/dist/esm-node/utils/getSelectedEntries.mjs +2 -0
  167. package/dist/esm-node/utils/initAppContext.mjs +4 -1
  168. package/dist/esm-node/utils/loadPlugins.mjs +2 -0
  169. package/dist/esm-node/utils/printInstructions.mjs +2 -0
  170. package/dist/esm-node/utils/register.mjs +29 -41
  171. package/dist/esm-node/utils/restart.mjs +2 -0
  172. package/dist/esm-node/utils/routes.mjs +2 -0
  173. package/dist/esm-node/utils/types.mjs +2 -0
  174. package/dist/types/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.d.ts +2 -2
  175. package/dist/types/builder/shared/bundlerPlugins/HtmlBottomTemplate.d.ts +2 -2
  176. package/dist/types/commands/index.d.ts +1 -0
  177. package/dist/types/commands/info.d.ts +18 -0
  178. package/dist/types/commands/inspect.d.ts +1 -1
  179. package/dist/types/esm/register-esm.d.mts +1 -1
  180. package/dist/types/esm/utils.d.mts +1 -2
  181. package/dist/types/locale/en.d.ts +3 -0
  182. package/dist/types/locale/index.d.ts +6 -0
  183. package/dist/types/locale/zh.d.ts +3 -0
  184. package/dist/types/types/config/index.d.ts +1 -0
  185. package/dist/types/utils/register.d.ts +5 -1
  186. package/dist/types/utils/types.d.ts +4 -0
  187. package/package.json +20 -44
  188. package/rstest.config.ts +24 -0
  189. package/dist/cjs/esm/esbuild-loader.js +0 -62
  190. package/dist/cjs/esm/esbuild-loader.mjs +0 -21
  191. package/dist/esm/esm/esbuild-loader.mjs +0 -22
  192. package/dist/esm-node/esm/esbuild-loader.mjs +0 -22
  193. package/dist/types/esm/esbuild-loader.d.mts +0 -7
package/bin/modern.js CHANGED
@@ -7,7 +7,30 @@ if (!process.env.MODERN_JS_VERSION) {
7
7
  process.env.MODERN_JS_VERSION = version;
8
8
  }
9
9
 
10
- require('../dist/cjs/run/index.js').run({
11
- internalPlugins: INTERNAL_RUNTIME_PLUGINS,
12
- version,
13
- });
10
+ // is esm project?
11
+ let isESM = false;
12
+ try {
13
+ const { readFileSync } = require('fs');
14
+ const { join } = require('path');
15
+ const { cwd } = require('process');
16
+ const pkg = JSON.parse(
17
+ readFileSync(join(cwd(), 'package.json'), { encoding: 'utf-8' }),
18
+ );
19
+ isESM = pkg.type === 'module';
20
+ } catch (e) {
21
+ // ignore
22
+ }
23
+
24
+ if (isESM) {
25
+ import('../dist/esm-node/run/index.mjs').then(({ run }) => {
26
+ run({
27
+ internalPlugins: INTERNAL_RUNTIME_PLUGINS,
28
+ version,
29
+ });
30
+ });
31
+ } else {
32
+ require('../dist/cjs/run/index.js').run({
33
+ internalPlugins: INTERNAL_RUNTIME_PLUGINS,
34
+ version,
35
+ });
36
+ }
@@ -1,5 +1,14 @@
1
1
  "use strict";
2
2
  var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
3
12
  (()=>{
4
13
  __webpack_require__.d = (exports1, definition)=>{
5
14
  for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
@@ -26,6 +35,8 @@ __webpack_require__.r(__webpack_exports__);
26
35
  __webpack_require__.d(__webpack_exports__, {
27
36
  builderPluginAdapterBasic: ()=>builderPluginAdapterBasic
28
37
  });
38
+ const external_node_path_namespaceObject = require("node:path");
39
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
29
40
  const builder_namespaceObject = require("@modern-js/builder");
30
41
  const builderPluginAdapterBasic = (options)=>({
31
42
  name: 'builder-plugin-adapter-modern-basic',
@@ -35,8 +46,9 @@ const builderPluginAdapterBasic = (options)=>({
35
46
  if ('node' === target || isServiceWorker) applyNodeCompat(isServiceWorker, chain);
36
47
  if ('web' === target) {
37
48
  const bareServerModuleReg = /\.(server|node)\.[tj]sx?$/;
49
+ const depExt = 'js';
38
50
  chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(bareServerModuleReg);
39
- chain.module.rule('bare-server-module').test(bareServerModuleReg).use('server-module-loader').loader(require.resolve('../loaders/serverModuleLoader'));
51
+ chain.module.rule('bare-server-module').test(bareServerModuleReg).use('server-module-loader').loader(external_node_path_default().join(__dirname, `../loaders/serverModuleLoader.${depExt}`));
40
52
  }
41
53
  const { appContext } = options;
42
54
  const { metaName } = appContext;
@@ -46,6 +58,48 @@ const builderPluginAdapterBasic = (options)=>({
46
58
  ]
47
59
  });
48
60
  });
61
+ api.modifyRspackConfig((config, { target, environment })=>{
62
+ const isServiceWorker = environment.name === builder_namespaceObject.SERVICE_WORKER_ENVIRONMENT_NAME;
63
+ if ('node' === target || isServiceWorker) {
64
+ const extensionAlias = {
65
+ '.js': [
66
+ '.node.js',
67
+ '.server.js',
68
+ '.js'
69
+ ],
70
+ '.jsx': [
71
+ '.node.jsx',
72
+ '.server.jsx',
73
+ '.jsx'
74
+ ],
75
+ '.ts': [
76
+ '.node.ts',
77
+ '.server.ts',
78
+ '.ts'
79
+ ],
80
+ '.tsx': [
81
+ '.node.tsx',
82
+ '.server.tsx',
83
+ '.tsx'
84
+ ],
85
+ '.mjs': [
86
+ '.node.mjs',
87
+ '.server.mjs',
88
+ '.mjs'
89
+ ],
90
+ '.json': [
91
+ '.node.json',
92
+ '.server.json',
93
+ '.json'
94
+ ]
95
+ };
96
+ config.resolve ??= {};
97
+ config.resolve.extensionAlias = {
98
+ ...config.resolve.extensionAlias,
99
+ ...extensionAlias
100
+ };
101
+ }
102
+ });
49
103
  }
50
104
  });
51
105
  function applyNodeCompat(isServiceWorker, chain) {
@@ -69,39 +123,6 @@ function applyNodeCompat(isServiceWorker, chain) {
69
123
  ];
70
124
  for (const ext of nodeExts)chain.resolve.extensions.prepend(ext);
71
125
  if (isServiceWorker) for (const ext of webWorkerExts)chain.resolve.extensions.prepend(ext);
72
- const extensionAlias = {
73
- '.js': [
74
- '.node.js',
75
- '.server.js',
76
- '.js'
77
- ],
78
- '.jsx': [
79
- '.node.jsx',
80
- '.server.jsx',
81
- '.jsx'
82
- ],
83
- '.ts': [
84
- '.node.ts',
85
- '.server.ts',
86
- '.ts'
87
- ],
88
- '.tsx': [
89
- '.node.tsx',
90
- '.server.tsx',
91
- '.tsx'
92
- ],
93
- '.mjs': [
94
- '.node.mjs',
95
- '.server.mjs',
96
- '.mjs'
97
- ],
98
- '.json': [
99
- '.node.json',
100
- '.server.json',
101
- '.json'
102
- ]
103
- };
104
- chain.resolve.extensionAlias.merge(extensionAlias);
105
126
  }
106
127
  exports.builderPluginAdapterBasic = __webpack_exports__.builderPluginAdapterBasic;
107
128
  for(var __rspack_i in __webpack_exports__)if (-1 === [
@@ -30,7 +30,7 @@ const builder_namespaceObject = require("@modern-js/builder");
30
30
  class HtmlAsyncChunkPlugin {
31
31
  apply(compiler) {
32
32
  compiler.hooks.compilation.tap(this.name, (compilation)=>{
33
- const hooks = this.htmlWebpackPlugin.getHooks(compilation);
33
+ const hooks = this.htmlPlugin.getCompilationHooks(compilation);
34
34
  hooks.alterAssetTagGroups.tap(this.name, (assets)=>{
35
35
  const headTags = [];
36
36
  const bodyTags = [];
@@ -57,9 +57,9 @@ class HtmlAsyncChunkPlugin {
57
57
  });
58
58
  });
59
59
  }
60
- constructor(htmlWebpackPlugin){
60
+ constructor(htmlPlugin){
61
61
  this.name = 'HtmlAsyncChunkPlugin';
62
- this.htmlWebpackPlugin = htmlWebpackPlugin;
62
+ this.htmlPlugin = htmlPlugin;
63
63
  }
64
64
  }
65
65
  exports.HtmlAsyncChunkPlugin = __webpack_exports__.HtmlAsyncChunkPlugin;
@@ -29,7 +29,7 @@ __webpack_require__.d(__webpack_exports__, {
29
29
  class BottomTemplatePlugin {
30
30
  apply(compiler) {
31
31
  compiler.hooks.compilation.tap(this.name, (compilation)=>{
32
- this.htmlWebpackPlugin.getHooks(compilation).beforeEmit.tap(this.name, (data)=>{
32
+ this.htmlPlugin.getCompilationHooks(compilation).beforeEmit.tap(this.name, (data)=>{
33
33
  if (!data.plugin.options?.__internal__) return data;
34
34
  if (this.bottomTemplateReg.test(data.html)) {
35
35
  data.html = data.html.replace(this.bottomTemplateReg, '');
@@ -40,10 +40,10 @@ class BottomTemplatePlugin {
40
40
  });
41
41
  });
42
42
  }
43
- constructor(htmlWebpackPlugin){
43
+ constructor(htmlPlugin){
44
44
  this.bottomTemplateReg = /<!--<\?-\s*bottomTemplate\s*\?>-->/;
45
45
  this.bodyRegExp = /(<\/\s*body\s*>)/i;
46
- this.htmlWebpackPlugin = htmlWebpackPlugin;
46
+ this.htmlPlugin = htmlPlugin;
47
47
  this.name = 'bottom-template';
48
48
  }
49
49
  }
@@ -65,7 +65,7 @@ class RouterPlugin {
65
65
  const ROUTE_MANIFEST_HOLDER = "route-manifest";
66
66
  const placeholder = `<!--<?- ${ROUTE_MANIFEST_HOLDER} ?>-->`;
67
67
  compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation)=>{
68
- this.HtmlBundlerPlugin.getHooks(compilation).beforeEmit.tapAsync('RouterManifestPlugin', (data, callback)=>{
68
+ this.HtmlBundlerPlugin.getCompilationHooks(compilation).beforeEmit.tapAsync('RouterManifestPlugin', (data, callback)=>{
69
69
  const { outputName } = data;
70
70
  const { chunks } = data.plugin.options;
71
71
  chunksToHtmlName.set(chunks, outputName);
@@ -71,14 +71,14 @@ const build = async (api, options)=>{
71
71
  const combinedAlias = [].concat(resolvedConfig?.resolve?.alias ?? []).concat(resolvedConfig?.source?.alias ?? []);
72
72
  await (0, loadPlugins_js_namespaceObject.loadServerPlugins)(api, appContext.appDirectory, appContext.metaName);
73
73
  if (appContext.moduleType && 'module' === appContext.moduleType) {
74
- const { registerEsm } = await import("../esm/register-esm.js");
75
- await registerEsm({
74
+ const { registerModuleHooks } = await import("../esm/register-esm.js");
75
+ await registerModuleHooks({
76
76
  appDir: appContext.appDirectory,
77
77
  distDir: appContext.distDirectory,
78
78
  alias: {}
79
79
  });
80
80
  }
81
- await (0, register_js_namespaceObject.registerCompiler)(appContext.appDirectory, appContext.distDirectory, combinedAlias);
81
+ await (0, register_js_namespaceObject.setupTsRuntime)(appContext.appDirectory, appContext.distDirectory, combinedAlias);
82
82
  const { apiOnly } = appContext;
83
83
  if (apiOnly) {
84
84
  await hooks.onBeforeBuild.call({
@@ -52,14 +52,14 @@ const dev = async (api, options, devServerOptions)=>{
52
52
  const hooks = api.getHooks();
53
53
  const combinedAlias = [].concat(normalizedConfig?.resolve?.alias ?? []).concat(normalizedConfig?.source?.alias ?? []);
54
54
  if (appContext.moduleType && 'module' === appContext.moduleType) {
55
- const { registerEsm } = await import("../esm/register-esm.js");
56
- await registerEsm({
55
+ const { registerModuleHooks } = await import("../esm/register-esm.js");
56
+ await registerModuleHooks({
57
57
  appDir: appContext.appDirectory,
58
58
  distDir: appContext.distDirectory,
59
59
  alias: {}
60
60
  });
61
61
  }
62
- await (0, register_js_namespaceObject.registerCompiler)(appContext.appDirectory, appContext.distDirectory, combinedAlias);
62
+ await (0, register_js_namespaceObject.setupTsRuntime)(appContext.appDirectory, appContext.distDirectory, combinedAlias);
63
63
  const { appDirectory, port, apiOnly, metaName, serverRoutes } = appContext;
64
64
  const meta = (0, utils_namespaceObject.getMeta)(metaName);
65
65
  const serverConfigPath = external_node_path_default().resolve(appDirectory, utils_namespaceObject.SERVER_DIR, `${meta}.server`);
@@ -26,8 +26,9 @@ __webpack_require__.r(__webpack_exports__);
26
26
  __webpack_require__.d(__webpack_exports__, {
27
27
  deployCommand: ()=>deployCommand,
28
28
  devCommand: ()=>devCommand,
29
- serverCommand: ()=>serverCommand,
29
+ infoCommand: ()=>infoCommand,
30
30
  inspectCommand: ()=>inspectCommand,
31
+ serverCommand: ()=>serverCommand,
31
32
  buildCommand: ()=>buildCommand
32
33
  });
33
34
  const index_js_namespaceObject = require("../locale/index.js");
@@ -66,15 +67,23 @@ const inspectCommand = (program, api)=>{
66
67
  inspect(api, options);
67
68
  });
68
69
  };
70
+ const infoCommand = (program, api)=>{
71
+ program.command('info').usage('[options]').description(index_js_namespaceObject.i18n.t(index_js_namespaceObject.localeKeys.command.info.describe)).option('-c --config <config>', index_js_namespaceObject.i18n.t(index_js_namespaceObject.localeKeys.command.shared.config)).option('--json', 'output as JSON format for machine reading').action(async (options)=>{
72
+ const { info } = await import("./info.js");
73
+ await info(api, options);
74
+ });
75
+ };
69
76
  exports.buildCommand = __webpack_exports__.buildCommand;
70
77
  exports.deployCommand = __webpack_exports__.deployCommand;
71
78
  exports.devCommand = __webpack_exports__.devCommand;
79
+ exports.infoCommand = __webpack_exports__.infoCommand;
72
80
  exports.inspectCommand = __webpack_exports__.inspectCommand;
73
81
  exports.serverCommand = __webpack_exports__.serverCommand;
74
82
  for(var __rspack_i in __webpack_exports__)if (-1 === [
75
83
  "buildCommand",
76
84
  "deployCommand",
77
85
  "devCommand",
86
+ "infoCommand",
78
87
  "inspectCommand",
79
88
  "serverCommand"
80
89
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ info: ()=>info
28
+ });
29
+ const utils_namespaceObject = require("@modern-js/utils");
30
+ const routes_js_namespaceObject = require("../utils/routes.js");
31
+ const info = async (api, options = {})=>{
32
+ const normalizedConfig = api.getNormalizedConfig();
33
+ const appContext = api.getAppContext();
34
+ const hooks = api.getHooks();
35
+ const apiOnly = await (0, utils_namespaceObject.isApiOnly)(appContext.appDirectory, normalizedConfig.source?.entriesDir, appContext.apiDirectory);
36
+ if (apiOnly) {
37
+ const projectInfo = {
38
+ entries: [],
39
+ apiOnly: true
40
+ };
41
+ printProjectInfo(projectInfo, options.json);
42
+ return;
43
+ }
44
+ const [{ getBundleEntry }] = await Promise.all([
45
+ import("../plugins/analyze/getBundleEntry.js")
46
+ ]);
47
+ const { entrypoints } = await hooks.modifyEntrypoints.call({
48
+ entrypoints: await getBundleEntry(hooks, appContext, normalizedConfig)
49
+ });
50
+ const { source: { mainEntryName }, server: { ssr, ssrByEntries }, output: { ssg, ssgByEntries } } = normalizedConfig;
51
+ const { packageName } = appContext;
52
+ const entries = entrypoints.map((entrypoint)=>{
53
+ const { entryName, entry, isAutoMount, isCustomSourceEntry, customEntry } = entrypoint;
54
+ const isMain = (0, routes_js_namespaceObject.isMainEntry)(entryName, mainEntryName);
55
+ const ssrOptions = (0, utils_namespaceObject.getEntryOptions)(entryName, isMain, ssr, ssrByEntries, packageName);
56
+ const ssgOptions = (0, utils_namespaceObject.getEntryOptions)(entryName, isMain, ssg, ssgByEntries, packageName);
57
+ let ssrMode = false;
58
+ if (ssrOptions) {
59
+ if ('boolean' == typeof ssrOptions) ssrMode = 'stream';
60
+ else if ('object' == typeof ssrOptions) ssrMode = 'string' === ssrOptions.mode ? 'string' : 'stream';
61
+ }
62
+ return {
63
+ entryName,
64
+ isMainEntry: isMain,
65
+ entry,
66
+ isAutoMount: isAutoMount ?? true,
67
+ isCustomSourceEntry: isCustomSourceEntry ?? false,
68
+ customEntry: customEntry ?? false,
69
+ ssr: ssrMode,
70
+ ssg: Boolean(ssgOptions)
71
+ };
72
+ });
73
+ const projectInfo = {
74
+ entries,
75
+ apiOnly: false
76
+ };
77
+ printProjectInfo(projectInfo, options.json);
78
+ };
79
+ function printProjectInfo(projectInfo, jsonOnly) {
80
+ if (jsonOnly) return void console.log(JSON.stringify(projectInfo, null, 2));
81
+ console.log('');
82
+ console.log('===== Modern.js Project Info =====');
83
+ console.log('');
84
+ console.log(JSON.stringify(projectInfo, null, 2));
85
+ console.log('');
86
+ console.log('===== Entry Details =====');
87
+ console.log('');
88
+ if (projectInfo.apiOnly) return void console.log('This is an API-only project (no page entries).');
89
+ if (0 === projectInfo.entries.length) return void console.log('No entries found.');
90
+ for (const entry of projectInfo.entries){
91
+ console.log(`Entry: ${entry.entryName}`);
92
+ console.log(` - Path: ${entry.entry}`);
93
+ console.log(` - Main Entry: ${entry.isMainEntry}`);
94
+ console.log(` - Auto Mount: ${entry.isAutoMount}`);
95
+ console.log(` - Custom Entry: ${entry.customEntry}`);
96
+ console.log(` - Custom Source Entry: ${entry.isCustomSourceEntry}`);
97
+ console.log(" - Rendering Mode:");
98
+ if (entry.ssg) console.log(" - SSG: enabled");
99
+ else if (entry.ssr) console.log(` - SSR: ${entry.ssr} mode`);
100
+ else console.log(" - CSR: enabled (default)");
101
+ console.log('');
102
+ }
103
+ }
104
+ exports.info = __webpack_exports__.info;
105
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
106
+ "info"
107
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
108
+ Object.defineProperty(exports, '__esModule', {
109
+ value: true
110
+ });
@@ -60,6 +60,7 @@ const serve = async (api, serverOptions)=>{
60
60
  config: {
61
61
  ...userConfig,
62
62
  dev: userConfig.dev,
63
+ tools: userConfig.tools,
63
64
  output: {
64
65
  path: userConfig.output.distPath?.root,
65
66
  ...userConfig.output || {}
@@ -27,58 +27,42 @@ var __webpack_require__ = {};
27
27
  var __webpack_exports__ = {};
28
28
  __webpack_require__.r(__webpack_exports__);
29
29
  __webpack_require__.d(__webpack_exports__, {
30
- registerEsm: ()=>registerEsm
30
+ registerModuleHooks: ()=>registerModuleHooks
31
31
  });
32
- const external_node_assert_namespaceObject = require("node:assert");
33
32
  const external_node_path_namespaceObject = require("node:path");
34
33
  const utils_namespaceObject = require("@modern-js/utils");
35
- const checkDep = async (dep)=>{
34
+ const checkDepExist = async (dep)=>{
36
35
  try {
37
36
  await import(dep);
38
37
  return true;
39
- } catch (error) {
38
+ } catch {
40
39
  return false;
41
40
  }
42
41
  };
43
- const registerEsm = async ({ appDir, distDir, alias })=>{
44
- const nodeVersion = process.versions.node;
45
- nodeVersion.split('.').map(Number);
46
- external_node_assert_namespaceObject((0, utils_namespaceObject.isVersionAtLeast1819)(nodeVersion), `The node version of the esm project must be greater than 18.19.0, current version is ${nodeVersion}`);
47
- const hasTsNode = await checkDep('ts-node');
42
+ const registerModuleHooks = async ({ appDir, distDir, alias })=>{
48
43
  const TS_CONFIG_FILENAME = "tsconfig.json";
49
44
  const tsconfigPath = external_node_path_namespaceObject.resolve(appDir, TS_CONFIG_FILENAME);
50
45
  const hasTsconfig = await utils_namespaceObject.fs.pathExists(tsconfigPath);
46
+ const hasTsNode = await checkDepExist('ts-node');
47
+ if (!hasTsconfig || !hasTsNode) return;
51
48
  const { register } = await import("node:module");
52
- if (hasTsNode && hasTsconfig) {
53
- process.env.TS_NODE_TRANSPILE_ONLY = true;
54
- process.env.TS_NODE_PROJECT = tsconfigPath;
55
- process.env.TS_NODE_SCOPE = true;
56
- process.env.TS_NODE_FILES = true;
57
- process.env.TS_NODE_IGNORE = `(?:^|/)node_modules/,(?:^|/)${external_node_path_namespaceObject.relative(appDir, distDir)}/`;
58
- register('./ts-node-loader.mjs', __rslib_import_meta_url__, {
59
- data: {
60
- appDir,
61
- distDir,
62
- alias,
63
- tsconfigPath
64
- }
65
- });
66
- } else {
67
- process.env.MODERN_NODE_LOADER = 'esbuild';
68
- if (hasTsconfig) (0, utils_namespaceObject.readTsConfigByFile)(tsconfigPath);
69
- register('./esbuild-loader.mjs', __rslib_import_meta_url__, {
70
- data: {
71
- appDir,
72
- distDir,
73
- alias,
74
- tsconfigPath
75
- }
76
- });
77
- }
49
+ process.env.TS_NODE_TRANSPILE_ONLY = true;
50
+ process.env.TS_NODE_PROJECT = tsconfigPath;
51
+ process.env.TS_NODE_SCOPE = true;
52
+ process.env.TS_NODE_FILES = true;
53
+ process.env.TS_NODE_IGNORE = `(?:^|/)node_modules/,(?:^|/)${external_node_path_namespaceObject.relative(appDir, distDir)}/`;
54
+ register('./ts-node-loader.mjs', __rslib_import_meta_url__, {
55
+ data: {
56
+ appDir,
57
+ distDir,
58
+ alias,
59
+ tsconfigPath
60
+ }
61
+ });
78
62
  };
79
- exports.registerEsm = __webpack_exports__.registerEsm;
63
+ exports.registerModuleHooks = __webpack_exports__.registerModuleHooks;
80
64
  for(var __rspack_i in __webpack_exports__)if (-1 === [
81
- "registerEsm"
65
+ "registerModuleHooks"
82
66
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
83
67
  Object.defineProperty(exports, '__esModule', {
84
68
  value: true
@@ -1,47 +1,31 @@
1
- import assert from 'node:assert';
2
1
  import path from 'node:path';
3
- import { fs, isVersionAtLeast1819, readTsConfigByFile } from '@modern-js/utils';
4
- const checkDep = async (dep)=>{
2
+ import { fs } from '@modern-js/utils';
3
+ const checkDepExist = async (dep)=>{
5
4
  try {
6
5
  await import(dep);
7
6
  return true;
8
- } catch (error) {
7
+ } catch {
9
8
  return false;
10
9
  }
11
10
  };
12
- export const registerEsm = async ({ appDir, distDir, alias })=>{
13
- const nodeVersion = process.versions.node;
14
- nodeVersion.split('.').map(Number);
15
- assert(isVersionAtLeast1819(nodeVersion), `The node version of the esm project must be greater than 18.19.0, current version is ${nodeVersion}`);
16
- const hasTsNode = await checkDep('ts-node');
11
+ export const registerModuleHooks = async ({ appDir, distDir, alias })=>{
17
12
  const TS_CONFIG_FILENAME = "tsconfig.json";
18
13
  const tsconfigPath = path.resolve(appDir, TS_CONFIG_FILENAME);
19
14
  const hasTsconfig = await fs.pathExists(tsconfigPath);
15
+ const hasTsNode = await checkDepExist('ts-node');
16
+ if (!hasTsconfig || !hasTsNode) return;
20
17
  const { register } = await import('node:module');
21
- if (hasTsNode && hasTsconfig) {
22
- process.env.TS_NODE_TRANSPILE_ONLY = true;
23
- process.env.TS_NODE_PROJECT = tsconfigPath;
24
- process.env.TS_NODE_SCOPE = true;
25
- process.env.TS_NODE_FILES = true;
26
- process.env.TS_NODE_IGNORE = `(?:^|/)node_modules/,(?:^|/)${path.relative(appDir, distDir)}/`;
27
- register('./ts-node-loader.mjs', import.meta.url, {
28
- data: {
29
- appDir,
30
- distDir,
31
- alias,
32
- tsconfigPath
33
- }
34
- });
35
- } else {
36
- process.env.MODERN_NODE_LOADER = 'esbuild';
37
- if (hasTsconfig) readTsConfigByFile(tsconfigPath);
38
- register('./esbuild-loader.mjs', import.meta.url, {
39
- data: {
40
- appDir,
41
- distDir,
42
- alias,
43
- tsconfigPath
44
- }
45
- });
46
- }
18
+ process.env.TS_NODE_TRANSPILE_ONLY = true;
19
+ process.env.TS_NODE_PROJECT = tsconfigPath;
20
+ process.env.TS_NODE_SCOPE = true;
21
+ process.env.TS_NODE_FILES = true;
22
+ process.env.TS_NODE_IGNORE = `(?:^|/)node_modules/,(?:^|/)${path.relative(appDir, distDir)}/`;
23
+ register('./ts-node-loader.mjs', import.meta.url, {
24
+ data: {
25
+ appDir,
26
+ distDir,
27
+ alias,
28
+ tsconfigPath
29
+ }
30
+ });
47
31
  };
@@ -58,7 +58,7 @@ function createMatchPath({ alias, appDir, tsconfigPath }) {
58
58
  [`${key}`]: tsPath
59
59
  };
60
60
  }, {});
61
- return tsconfig_paths_namespaceObject.createMatchPath(absoluteBaseUrl, tsPaths);
61
+ return (0, tsconfig_paths_namespaceObject.createMatchPath)(absoluteBaseUrl, tsPaths);
62
62
  }
63
63
  exports.createMatchPath = __webpack_exports__.createMatchPath;
64
64
  for(var __rspack_i in __webpack_exports__)if (-1 === [
@@ -1,7 +1,7 @@
1
1
  import { createRequire } from 'module';
2
2
  import path from 'path';
3
3
  import { getAliasConfig } from '@modern-js/utils';
4
- import tsConfigPaths from '@modern-js/utils/tsconfig-paths';
4
+ import { createMatchPath as oCreateMatchPath } from '@modern-js/utils/tsconfig-paths';
5
5
  const require = createRequire(import.meta.url);
6
6
  export function createMatchPath({ alias, appDir, tsconfigPath }) {
7
7
  const aliasConfig = getAliasConfig(alias, {
@@ -27,5 +27,5 @@ export function createMatchPath({ alias, appDir, tsconfigPath }) {
27
27
  [`${key}`]: tsPath
28
28
  };
29
29
  }, {});
30
- return tsConfigPaths.createMatchPath(absoluteBaseUrl, tsPaths);
30
+ return oCreateMatchPath(absoluteBaseUrl, tsPaths);
31
31
  }
package/dist/cjs/index.js CHANGED
@@ -219,6 +219,7 @@ var __webpack_exports__ = {};
219
219
  (0, _commands__rspack_import_5.serverCommand)(program, api);
220
220
  (0, _commands__rspack_import_5.deployCommand)(program, api);
221
221
  (0, _commands__rspack_import_5.inspectCommand)(program, api);
222
+ (0, _commands__rspack_import_5.infoCommand)(program, api);
222
223
  (0, _modern_js_utils__rspack_import_4.deprecatedCommands)(program);
223
224
  });
224
225
  api.onPrepare(async ()=>{
@@ -64,6 +64,9 @@ const EN_LOCALE = {
64
64
  env: 'specify env mode',
65
65
  output: 'specify inspect content output path',
66
66
  verbose: 'show full function definitions in output'
67
+ },
68
+ info: {
69
+ describe: 'show project information'
67
70
  }
68
71
  }
69
72
  };
@@ -64,6 +64,9 @@ const ZH_LOCALE = {
64
64
  env: '查看指定环境下的配置',
65
65
  output: '指定在 dist 目录下输出的路径',
66
66
  verbose: '在结果中展示函数的完整内容'
67
+ },
68
+ info: {
69
+ describe: '展示项目信息'
67
70
  }
68
71
  }
69
72
  };
@@ -69,7 +69,7 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer)=>{
69
69
  },
70
70
  async writeOutput () {
71
71
  const routes = [];
72
- const { source: { mainEntryName } } = modernConfig;
72
+ const { source: { mainEntryName }, html: { outputStructure } } = modernConfig;
73
73
  if (needModernServer) routes.push({
74
74
  src: '/*',
75
75
  dest: "/.netlify/functions/index",
@@ -77,9 +77,10 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer)=>{
77
77
  });
78
78
  else entrypoints.forEach((entry)=>{
79
79
  const isMain = (0, routes_js_namespaceObject.isMainEntry)(entry.entryName, mainEntryName);
80
+ const htmlPath = 'flat' === outputStructure ? `/html/${entry.entryName}.html` : `/html/${entry.entryName}/index.html`;
80
81
  routes.push({
81
82
  src: `/${isMain ? '' : `${entry.entryName}/`}*`,
82
- dest: `/html/${entry.entryName}/index.html`,
83
+ dest: htmlPath,
83
84
  status: 200
84
85
  });
85
86
  });
@@ -78,15 +78,16 @@ const createVercelPreset = (appContext, modernConfig, needModernServer)=>{
78
78
  dest: "/index"
79
79
  });
80
80
  else {
81
- const { source: { mainEntryName } } = modernConfig;
81
+ const { source: { mainEntryName }, html: { outputStructure } } = modernConfig;
82
82
  entrypoints.forEach((entry)=>{
83
83
  const isMain = (0, routes_js_namespaceObject.isMainEntry)(entry.entryName, mainEntryName);
84
+ const htmlPath = 'flat' === outputStructure ? `/html/${entry.entryName}.html` : `/html/${entry.entryName}/index.html`;
84
85
  config.routes.push({
85
86
  src: `/${isMain ? '' : entry.entryName}(?:/.*)?`,
86
87
  headers: {
87
88
  'cache-control': 's-maxage=0'
88
89
  },
89
- dest: `/html/${entry.entryName}/index.html`
90
+ dest: htmlPath
90
91
  });
91
92
  });
92
93
  }