@modern-js/app-tools 2.23.1 → 2.24.0

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 (44) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/dist/cjs/analyze/generateCode.js +5 -5
  3. package/dist/cjs/analyze/getBundleEntry.js +7 -2
  4. package/dist/cjs/analyze/getFileSystemEntry.js +4 -0
  5. package/dist/cjs/analyze/getHtmlTemplate.js +2 -2
  6. package/dist/cjs/analyze/getServerRoutes.js +4 -3
  7. package/dist/cjs/analyze/nestedRoutes.js +36 -12
  8. package/dist/cjs/analyze/templates.js +2 -2
  9. package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +4 -2
  10. package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +1 -1
  11. package/dist/cjs/config/default.js +3 -0
  12. package/dist/cjs/config/legacy/createSourceConfig.js +2 -1
  13. package/dist/cjs/schema/index.js +3 -0
  14. package/dist/cjs/schema/legacy.js +3 -0
  15. package/dist/esm/analyze/generateCode.js +7 -7
  16. package/dist/esm/analyze/getBundleEntry.js +7 -2
  17. package/dist/esm/analyze/getFileSystemEntry.js +4 -0
  18. package/dist/esm/analyze/getHtmlTemplate.js +4 -4
  19. package/dist/esm/analyze/getServerRoutes.js +4 -3
  20. package/dist/esm/analyze/nestedRoutes.js +26 -11
  21. package/dist/esm/analyze/templates.js +2 -2
  22. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +5 -3
  23. package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +1 -1
  24. package/dist/esm/config/default.js +3 -0
  25. package/dist/esm/config/legacy/createSourceConfig.js +2 -1
  26. package/dist/esm/schema/index.js +3 -0
  27. package/dist/esm/schema/legacy.js +3 -0
  28. package/dist/esm-node/analyze/generateCode.js +5 -5
  29. package/dist/esm-node/analyze/getBundleEntry.js +7 -2
  30. package/dist/esm-node/analyze/getFileSystemEntry.js +4 -0
  31. package/dist/esm-node/analyze/getHtmlTemplate.js +3 -3
  32. package/dist/esm-node/analyze/getServerRoutes.js +4 -3
  33. package/dist/esm-node/analyze/nestedRoutes.js +25 -10
  34. package/dist/esm-node/analyze/templates.js +2 -2
  35. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +5 -3
  36. package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +1 -1
  37. package/dist/esm-node/config/default.js +3 -0
  38. package/dist/esm-node/config/legacy/createSourceConfig.js +2 -1
  39. package/dist/esm-node/schema/index.js +3 -0
  40. package/dist/esm-node/schema/legacy.js +3 -0
  41. package/dist/types/analyze/nestedRoutes.d.ts +2 -1
  42. package/dist/types/types/config/source.d.ts +1 -0
  43. package/dist/types/types/legacyConfig/source.d.ts +1 -0
  44. package/package.json +24 -24
package/CHANGELOG.md CHANGED
@@ -1,5 +1,41 @@
1
1
  # @modern-js/app-tools
2
2
 
3
+ ## 2.24.0
4
+
5
+ ### Patch Changes
6
+
7
+ - c882fbd: feat: support config main entry name
8
+
9
+ feat: 支持配置主入口名称
10
+
11
+ - 36c3982: fix: fix the line number mapping offset between the sourcemap and the source code
12
+ fix: 修复 sourcemap 到源代码行号映射偏移问题
13
+ - Updated dependencies [c882fbd]
14
+ - Updated dependencies [8c9923f]
15
+ - Updated dependencies [ef041c0]
16
+ - Updated dependencies [4fdd868]
17
+ - Updated dependencies [36f5bdf]
18
+ - Updated dependencies [0424a2d]
19
+ - Updated dependencies [4a82c3b]
20
+ - @modern-js/types@2.24.0
21
+ - @modern-js/utils@2.24.0
22
+ - @modern-js/server@2.24.0
23
+ - @modern-js/builder-webpack-provider@2.24.0
24
+ - @modern-js/builder-rspack-provider@2.24.0
25
+ - @modern-js/builder-shared@2.24.0
26
+ - @modern-js/builder@2.24.0
27
+ - @modern-js/plugin-data-loader@2.24.0
28
+ - @modern-js/core@2.24.0
29
+ - @modern-js/prod-server@2.24.0
30
+ - @modern-js/builder-plugin-esbuild@2.24.0
31
+ - @modern-js/builder-plugin-node-polyfill@2.24.0
32
+ - @modern-js/plugin-i18n@2.24.0
33
+ - @modern-js/plugin-lint@2.24.0
34
+ - @modern-js/new-action@2.24.0
35
+ - @modern-js/node-bundle-require@2.24.0
36
+ - @modern-js/plugin@2.24.0
37
+ - @modern-js/upgrade@2.24.0
38
+
3
39
  ## 2.23.1
4
40
 
5
41
  ### Patch Changes
@@ -84,7 +84,7 @@ const generateCode = async (appContext, config, entrypoints, api) => {
84
84
  importsStatemets
85
85
  };
86
86
  async function generateEntryCode(entrypoint) {
87
- const { entryName, isAutoMount, fileSystemRoutes } = entrypoint;
87
+ const { entryName, isMainEntry, isAutoMount, fileSystemRoutes } = entrypoint;
88
88
  if (isAutoMount) {
89
89
  if (fileSystemRoutes) {
90
90
  var _config_output;
@@ -103,7 +103,7 @@ const generateCode = async (appContext, config, entrypoints, api) => {
103
103
  nestedRoute = await (0, _nestedRoutes.walk)(entrypoint.nestedRoutesEntry, entrypoint.nestedRoutesEntry, {
104
104
  name: internalSrcAlias,
105
105
  basename: srcDirectory
106
- }, entrypoint.entryName);
106
+ }, entrypoint.entryName, entrypoint.isMainEntry);
107
107
  if (nestedRoute) {
108
108
  initialRoutes.unshift(nestedRoute);
109
109
  }
@@ -113,7 +113,7 @@ const generateCode = async (appContext, config, entrypoints, api) => {
113
113
  routes: initialRoutes
114
114
  });
115
115
  const config2 = api.useResolvedConfigContext();
116
- const ssr = (0, _utils.getEntryOptions)(entryName, config2.server.ssr, config2.server.ssrByEntries, packageName);
116
+ const ssr = (0, _utils.getEntryOptions)(entryName, isMainEntry, config2.server.ssr, config2.server.ssrByEntries, packageName);
117
117
  const useSSG = (0, _utils.isSSGEntry)(config2, entryName, entrypoints);
118
118
  let mode;
119
119
  if (ssr) {
@@ -173,7 +173,7 @@ const generateIndexCode = async ({ appContext, api, entrypoints, config, imports
173
173
  const { mountId } = config.html;
174
174
  const { internalDirectory, packageName } = appContext;
175
175
  await Promise.all(entrypoints.map(async (entrypoint) => {
176
- const { entryName, isAutoMount, customBootstrap, fileSystemRoutes } = entrypoint;
176
+ const { entryName, isMainEntry, isAutoMount, customBootstrap, fileSystemRoutes } = entrypoint;
177
177
  if (isAutoMount) {
178
178
  const { plugins } = await hookRunners.modifyEntryRuntimePlugins({
179
179
  entrypoint,
@@ -202,7 +202,7 @@ const generateIndexCode = async ({ appContext, api, entrypoints, config, imports
202
202
  const entryFile = _path.default.resolve(internalDirectory, `./${entryName}/${_constants.ENTRY_POINT_FILE_NAME}`);
203
203
  if (config.source.enableAsyncEntry) {
204
204
  let rawAsyncEntryCode = `import('./${_constants.ENTRY_BOOTSTRAP_FILE_NAME}');`;
205
- const ssr = (0, _utils.getEntryOptions)(entryName, config.server.ssr, config.server.ssrByEntries, packageName);
205
+ const ssr = (0, _utils.getEntryOptions)(entryName, isMainEntry, config.server.ssr, config.server.ssrByEntries, packageName);
206
206
  if (ssr) {
207
207
  rawAsyncEntryCode = `
208
208
  export const ${_utils.SERVER_RENDER_FUNCTION_NAME} = async (...args) => {
@@ -35,19 +35,21 @@ const ifAlreadyExists = (entrypoints, checked) => entrypoints.some((entrypoint)
35
35
  });
36
36
  const getBundleEntry = (appContext, config) => {
37
37
  const { appDirectory, packageName } = appContext;
38
- const { disableDefaultEntries, entries, entriesDir } = config.source;
38
+ const { disableDefaultEntries, entries, entriesDir, mainEntryName } = config.source;
39
39
  const defaults = disableDefaultEntries ? [] : (0, _getFileSystemEntry.getFileSystemEntry)(appContext, config);
40
40
  if (entries) {
41
41
  Object.keys(entries).forEach((name) => {
42
42
  const value = entries[name];
43
43
  const entrypoint = typeof value === "string" ? {
44
44
  entryName: name,
45
+ isMainEntry: false,
45
46
  entry: (0, _utils.ensureAbsolutePath)(appDirectory, value),
46
47
  absoluteEntryDir: isDirectory((0, _utils.ensureAbsolutePath)(appDirectory, value)) ? (0, _utils.ensureAbsolutePath)(appDirectory, value) : _path.default.dirname((0, _utils.ensureAbsolutePath)(appDirectory, value)),
47
48
  isAutoMount: true,
48
49
  fileSystemRoutes: _utils.fs.statSync((0, _utils.ensureAbsolutePath)(appDirectory, value)).isDirectory() ? {} : void 0
49
50
  } : {
50
51
  entryName: name,
52
+ isMainEntry: false,
51
53
  entry: (0, _utils.ensureAbsolutePath)(appDirectory, value.entry),
52
54
  absoluteEntryDir: isDirectory((0, _utils.ensureAbsolutePath)(appDirectory, value.entry)) ? (0, _utils.ensureAbsolutePath)(appDirectory, value.entry) : _path.default.dirname((0, _utils.ensureAbsolutePath)(appDirectory, value.entry)),
53
55
  isAutoMount: !value.disableMount,
@@ -65,7 +67,10 @@ const getBundleEntry = (appContext, config) => {
65
67
  if (!disableDefaultEntries) {
66
68
  const entriesDirAbs = (0, _utils.ensureAbsolutePath)(appDirectory, entriesDir || "");
67
69
  const found = defaults.find(({ entryName, entry, nestedRoutesEntry = "" }) => entryName === packageName || _path.default.dirname(entry) === entriesDirAbs || _path.default.dirname(nestedRoutesEntry) === entriesDirAbs);
68
- found && (found.entryName = _utils.MAIN_ENTRY_NAME);
70
+ if (found) {
71
+ found.entryName = mainEntryName || _utils.MAIN_ENTRY_NAME;
72
+ found.isMainEntry = true;
73
+ }
69
74
  }
70
75
  return defaults;
71
76
  };
@@ -26,6 +26,7 @@ const scanDir = (dirs) => dirs.map((dir) => {
26
26
  if (indexFile && !customBootstrap) {
27
27
  return {
28
28
  entryName,
29
+ isMainEntry: false,
29
30
  entry: indexFile,
30
31
  absoluteEntryDir: _path.default.resolve(dir),
31
32
  isAutoMount: false
@@ -35,6 +36,7 @@ const scanDir = (dirs) => dirs.map((dir) => {
35
36
  if (isHasApp) {
36
37
  return {
37
38
  entryName,
39
+ isMainEntry: false,
38
40
  entry: _path.default.join(dir, _constants.APP_FILE_NAME),
39
41
  isAutoMount: true,
40
42
  absoluteEntryDir: _path.default.resolve(dir),
@@ -46,6 +48,7 @@ const scanDir = (dirs) => dirs.map((dir) => {
46
48
  if (isHasNestedRoutes || isHasPages) {
47
49
  const entrypoint = {
48
50
  entryName,
51
+ isMainEntry: false,
49
52
  entry: "",
50
53
  fileSystemRoutes: {
51
54
  globalApp: (0, _utils.findExists)(_constants.JS_EXTENSIONS.map((ext) => _path.default.resolve(dir, `./${_constants.PAGES_DIR_NAME}/${_constants.FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT}${ext}`)))
@@ -66,6 +69,7 @@ const scanDir = (dirs) => dirs.map((dir) => {
66
69
  }
67
70
  return {
68
71
  entryName,
72
+ isMainEntry: false,
69
73
  entry: indexFile,
70
74
  absoluteEntryDir: _path.default.resolve(dir),
71
75
  isAutoMount: false
@@ -39,8 +39,8 @@ const getHtmlTemplate = async (entrypoints, api, { appContext, config }) => {
39
39
  const htmlDir = _path.default.resolve(appDirectory, configDir || "", _constants.HTML_PARTIALS_FOLDER);
40
40
  const htmlTemplates = {};
41
41
  for (const entrypoint of entrypoints) {
42
- const { entryName } = entrypoint;
43
- const name = entrypoints.length === 1 && entryName === _utils.MAIN_ENTRY_NAME ? "" : entryName;
42
+ const { entryName, isMainEntry } = entrypoint;
43
+ const name = entrypoints.length === 1 && isMainEntry ? "" : entryName;
44
44
  const customIndexTemplate = findPartials(htmlDir, name, PartialPosition.INDEX);
45
45
  if (customIndexTemplate) {
46
46
  htmlTemplates[entryName] = customIndexTemplate.file;
@@ -80,17 +80,18 @@ const applyRouteOptions = (original, routeOptions) => {
80
80
  };
81
81
  const collectHtmlRoutes = (entrypoints, appContext, config) => {
82
82
  var _deploy_worker;
83
- const { html: { disableHtmlFolder }, output: { distPath: { html: htmlPath } = {} }, server: { baseUrl, routes, ssr, ssrByEntries }, deploy } = config;
83
+ const { source: { mainEntryName }, html: { disableHtmlFolder }, output: { distPath: { html: htmlPath } = {} }, server: { baseUrl, routes, ssr, ssrByEntries }, deploy } = config;
84
84
  const { packageName } = appContext;
85
85
  const workerSSR = deploy === null || deploy === void 0 ? void 0 : (_deploy_worker = deploy.worker) === null || _deploy_worker === void 0 ? void 0 : _deploy_worker.ssr;
86
86
  let htmlRoutes = entrypoints.reduce((previous, { entryName }) => {
87
- const entryOptions = (0, _utils.getEntryOptions)(entryName, ssr, ssrByEntries, packageName);
87
+ const isMainEntry = entryName === (mainEntryName || _utils.MAIN_ENTRY_NAME);
88
+ const entryOptions = (0, _utils.getEntryOptions)(entryName, isMainEntry, ssr, ssrByEntries, packageName);
88
89
  const isSSR = Boolean(entryOptions);
89
90
  const isWorker = Boolean(workerSSR);
90
91
  const isStream = typeof entryOptions === "object" && entryOptions.mode === "stream";
91
92
  const { resHeaders } = (routes === null || routes === void 0 ? void 0 : routes[entryName]) || {};
92
93
  let route = {
93
- urlPath: `/${entryName === _utils.MAIN_ENTRY_NAME ? "" : entryName}`,
94
+ urlPath: `/${isMainEntry ? "" : entryName}`,
94
95
  entryName,
95
96
  entryPath: (0, _utils.removeLeadingSlash)(_path.default.posix.normalize(`${htmlPath}/${entryName}${disableHtmlFolder ? ".html" : "/index.html"}`)),
96
97
  isSPA: true,
@@ -2,9 +2,18 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- Object.defineProperty(exports, "walk", {
6
- enumerable: true,
7
- get: function() {
5
+ function _export(target, all) {
6
+ for (var name in all)
7
+ Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name]
10
+ });
11
+ }
12
+ _export(exports, {
13
+ getRouteId: function() {
14
+ return getRouteId;
15
+ },
16
+ walk: function() {
8
17
  return walk;
9
18
  }
10
19
  });
@@ -17,22 +26,37 @@ const conventionNames = Object.values(_constants.NESTED_ROUTE);
17
26
  const replaceDynamicPath = (routePath) => {
18
27
  return routePath.replace(/\[(.*?)\]/g, ":$1");
19
28
  };
20
- const createIndexRoute = (routeInfo, rootDir, filename, entryName) => {
29
+ const getPathWithoutExt = (filename) => {
30
+ const extname = _path.extname(filename);
31
+ return filename.slice(0, -extname.length);
32
+ };
33
+ const getRouteId = (componentPath, routesDir, entryName, isMainEntry) => {
34
+ const relativePath = (0, _utils.normalizeToPosixPath)(_path.relative(routesDir, componentPath));
35
+ const pathWithoutExt = getPathWithoutExt(relativePath);
36
+ let id = ``;
37
+ if (isMainEntry) {
38
+ id = pathWithoutExt;
39
+ } else {
40
+ id = `${entryName}_${pathWithoutExt}`;
41
+ }
42
+ return id.replace(/\[(.*?)\]/g, "($1)");
43
+ };
44
+ const createIndexRoute = (routeInfo, rootDir, filename, entryName, isMainEntry) => {
21
45
  return createRoute({
22
46
  ...routeInfo,
23
47
  index: true,
24
48
  children: void 0
25
- }, rootDir, filename, entryName);
49
+ }, rootDir, filename, entryName, isMainEntry);
26
50
  };
27
- const createRoute = (routeInfo, rootDir, filename, entryName) => {
28
- const id = (0, _utils.getRouteId)(filename, rootDir, entryName);
51
+ const createRoute = (routeInfo, rootDir, filename, entryName, isMainEntry) => {
52
+ const id = getRouteId(filename, rootDir, entryName, isMainEntry);
29
53
  return {
30
54
  ...routeInfo,
31
55
  id,
32
56
  type: "nested"
33
57
  };
34
58
  };
35
- const walk = async (dirname, rootDir, alias, entryName) => {
59
+ const walk = async (dirname, rootDir, alias, entryName, isMainEntry) => {
36
60
  var _route_children;
37
61
  if (!await _utils.fs.pathExists(dirname)) {
38
62
  return null;
@@ -69,7 +93,7 @@ const walk = async (dirname, rootDir, alias, entryName) => {
69
93
  const itemWithoutExt = item.slice(0, -extname.length);
70
94
  const isDirectory2 = (await _utils.fs.stat(itemPath)).isDirectory();
71
95
  if (isDirectory2) {
72
- const childRoute = await walk(itemPath, rootDir, alias, entryName);
96
+ const childRoute = await walk(itemPath, rootDir, alias, entryName, isMainEntry);
73
97
  if (childRoute) {
74
98
  var _route_children1;
75
99
  (_route_children1 = route.children) === null || _route_children1 === void 0 ? void 0 : _route_children1.push(childRoute);
@@ -101,7 +125,7 @@ const walk = async (dirname, rootDir, alias, entryName) => {
101
125
  var _route_children2;
102
126
  pageRoute = createIndexRoute({
103
127
  _component: (0, _utils1.replaceWithAlias)(alias.basename, itemPath, alias.name)
104
- }, rootDir, itemPath, entryName);
128
+ }, rootDir, itemPath, entryName, isMainEntry);
105
129
  if (pageLoaderFile) {
106
130
  pageRoute.loader = pageLoaderFile;
107
131
  }
@@ -118,7 +142,7 @@ const walk = async (dirname, rootDir, alias, entryName) => {
118
142
  splatRoute = createRoute({
119
143
  _component: (0, _utils1.replaceWithAlias)(alias.basename, itemPath, alias.name),
120
144
  path: "*"
121
- }, rootDir, itemPath, entryName);
145
+ }, rootDir, itemPath, entryName, isMainEntry);
122
146
  if (splatLoaderFile) {
123
147
  splatRoute.loader = splatLoaderFile;
124
148
  }
@@ -131,7 +155,7 @@ const walk = async (dirname, rootDir, alias, entryName) => {
131
155
  route.error = (0, _utils1.replaceWithAlias)(alias.basename, itemPath, alias.name);
132
156
  }
133
157
  }
134
- let finalRoute = createRoute(route, rootDir, _path.join(dirname, `${_constants.NESTED_ROUTE.LAYOUT_FILE}.ts`), entryName);
158
+ let finalRoute = createRoute(route, rootDir, _path.join(dirname, `${_constants.NESTED_ROUTE.LAYOUT_FILE}.ts`), entryName, isMainEntry);
135
159
  if (isPathlessLayout) {
136
160
  delete finalRoute.path;
137
161
  }
@@ -330,9 +330,9 @@ const fileSystemRoutes = async ({ routes, ssrMode, nestedRoutesEntry, entryName,
330
330
  `;
331
331
  };
332
332
  function ssrLoaderCombinedModule(entrypoints, entrypoint, config, appContext) {
333
- const { entryName } = entrypoint;
333
+ const { entryName, isMainEntry } = entrypoint;
334
334
  const { packageName, internalDirectory } = appContext;
335
- const ssr = (0, _utils.getEntryOptions)(entryName, config.server.ssr, config.server.ssrByEntries, packageName);
335
+ const ssr = (0, _utils.getEntryOptions)(entryName, isMainEntry, config.server.ssr, config.server.ssrByEntries, packageName);
336
336
  const ssg = (0, _utils.isSSGEntry)(config, entryName, entrypoints);
337
337
  if (entrypoint.nestedRoutesEntry && (ssr || ssg)) {
338
338
  const serverLoaderRuntime = require.resolve("@modern-js/plugin-data-loader/runtime");
@@ -60,11 +60,13 @@ async function injectAssetPrefix({ api, chain }) {
60
60
  function applyBottomHtmlPlugin({ api, chain, options, CHAIN_ID, HtmlBundlerPlugin }) {
61
61
  const { normalizedConfig: modernConfig, appContext } = options;
62
62
  for (const entryName of Object.keys(api.context.entry)) {
63
+ const { source: { mainEntryName } } = modernConfig;
64
+ const isMainEntry = entryName === (mainEntryName || _utils.MAIN_ENTRY_NAME);
63
65
  const baseTemplateParams = {
64
66
  entryName,
65
- title: (0, _utils.getEntryOptions)(entryName, modernConfig.html.title, modernConfig.html.titleByEntries, appContext.packageName),
67
+ title: (0, _utils.getEntryOptions)(entryName, isMainEntry, modernConfig.html.title, modernConfig.html.titleByEntries, appContext.packageName),
66
68
  mountId: modernConfig.html.mountId,
67
- ...(0, _utils.getEntryOptions)(entryName, modernConfig.html.templateParameters, modernConfig.html.templateParametersByEntries, appContext.packageName)
69
+ ...(0, _utils.getEntryOptions)(entryName, isMainEntry, modernConfig.html.templateParameters, modernConfig.html.templateParametersByEntries, appContext.packageName)
68
70
  };
69
71
  chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).tap((args) => [
70
72
  {
@@ -109,7 +109,7 @@ class RouterPlugin {
109
109
  if (!asset) {
110
110
  continue;
111
111
  }
112
- const newContent = `${injectedContent}${asset.source().toString()}`;
112
+ const newContent = `${asset.source().toString()}${injectedContent}`;
113
113
  newAssetsMap.set(_path.default.join(outputPath, file), newContent);
114
114
  compilation.updateAsset(
115
115
  file,
@@ -18,6 +18,7 @@ _export(exports, {
18
18
  }
19
19
  });
20
20
  const _builderwebpackprovider = require("@modern-js/builder-webpack-provider");
21
+ const _utils = require("@modern-js/utils");
21
22
  const _env = require("../utils/env");
22
23
  function createDefaultConfig(appContext, bundler) {
23
24
  const defaultBuilderConfig = (0, _builderwebpackprovider.createDefaultConfig)();
@@ -34,6 +35,7 @@ function createDefaultConfig(appContext, bundler) {
34
35
  const source = {
35
36
  ...defaultBuilderConfig.source,
36
37
  entries: void 0,
38
+ mainEntryName: _utils.MAIN_ENTRY_NAME,
37
39
  enableAsyncEntry: false,
38
40
  disableDefaultEntries: false,
39
41
  entriesDir: "./src",
@@ -98,6 +100,7 @@ function createLegacyDefaultConfig(appContext) {
98
100
  } : {};
99
101
  const sourceDefaults = {
100
102
  entries: void 0,
103
+ mainEntryName: _utils.MAIN_ENTRY_NAME,
101
104
  enableAsyncEntry: false,
102
105
  disableDefaultEntries: false,
103
106
  entriesDir: "./src",
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "createSourceConfig", {
9
9
  }
10
10
  });
11
11
  function createSourceConfig(config) {
12
- const { alias, envVars, globalVars, include, moduleScopes, preEntry, entries, enableAsyncEntry, disableDefaultEntries, entriesDir, configDir } = config.source;
12
+ const { alias, envVars, globalVars, include, moduleScopes, preEntry, entries, mainEntryName, enableAsyncEntry, disableDefaultEntries, entriesDir, configDir } = config.source;
13
13
  const builderGlobalVars = globalVars || {};
14
14
  for (const envVar of envVars || []) {
15
15
  const envVarValue = process.env[envVar];
@@ -22,6 +22,7 @@ function createSourceConfig(config) {
22
22
  include,
23
23
  preEntry,
24
24
  entries,
25
+ mainEntryName,
25
26
  enableAsyncEntry,
26
27
  disableDefaultEntries,
27
28
  entriesDir,
@@ -58,6 +58,9 @@ const source = {
58
58
  }
59
59
  }
60
60
  },
61
+ mainEntryName: {
62
+ type: "string"
63
+ },
61
64
  enableAsyncEntry: {
62
65
  type: "boolean"
63
66
  },
@@ -44,6 +44,9 @@ const source = {
44
44
  }
45
45
  }
46
46
  },
47
+ mainEntryName: {
48
+ type: "string"
49
+ },
47
50
  preEntry: {
48
51
  type: [
49
52
  "string",
@@ -100,11 +100,11 @@ export var generateCode = function() {
100
100
  }
101
101
  function _generateEntryCode() {
102
102
  _generateEntryCode = _async_to_generator(function(entrypoint) {
103
- var entryName, isAutoMount, fileSystemRoutes, _config_output, initialRoutes, nestedRoute, routes, _$config, ssr, useSSG, mode, hasPageRoute, code, _, _tmp, routesServerFile, code1, serverLoaderCombined, serverLoaderFile, imports, entryFile;
103
+ var entryName, isMainEntry, isAutoMount, fileSystemRoutes, _config_output, initialRoutes, nestedRoute, routes, _$config, ssr, useSSG, mode, hasPageRoute, code, _, _tmp, routesServerFile, code1, serverLoaderCombined, serverLoaderFile, imports, entryFile;
104
104
  return _ts_generator(this, function(_state) {
105
105
  switch (_state.label) {
106
106
  case 0:
107
- entryName = entrypoint.entryName, isAutoMount = entrypoint.isAutoMount, fileSystemRoutes = entrypoint.fileSystemRoutes;
107
+ entryName = entrypoint.entryName, isMainEntry = entrypoint.isMainEntry, isAutoMount = entrypoint.isAutoMount, fileSystemRoutes = entrypoint.fileSystemRoutes;
108
108
  if (!isAutoMount)
109
109
  return [
110
110
  3,
@@ -136,7 +136,7 @@ export var generateCode = function() {
136
136
  walk(entrypoint.nestedRoutesEntry, entrypoint.nestedRoutesEntry, {
137
137
  name: internalSrcAlias,
138
138
  basename: srcDirectory
139
- }, entrypoint.entryName)
139
+ }, entrypoint.entryName, entrypoint.isMainEntry)
140
140
  ];
141
141
  case 1:
142
142
  nestedRoute = _state.sent();
@@ -155,7 +155,7 @@ export var generateCode = function() {
155
155
  case 3:
156
156
  routes = _state.sent().routes;
157
157
  _$config = api.useResolvedConfigContext();
158
- ssr = getEntryOptions(entryName, _$config.server.ssr, _$config.server.ssrByEntries, packageName);
158
+ ssr = getEntryOptions(entryName, isMainEntry, _$config.server.ssr, _$config.server.ssrByEntries, packageName);
159
159
  useSSG = isSSGEntry(_$config, entryName, entrypoints);
160
160
  if (ssr) {
161
161
  mode = typeof ssr === "object" ? ssr.mode || "string" : "string";
@@ -303,11 +303,11 @@ export var generateIndexCode = function() {
303
303
  4,
304
304
  Promise.all(entrypoints.map(function() {
305
305
  var _ref2 = _async_to_generator(function(entrypoint) {
306
- var entryName, isAutoMount, customBootstrap, fileSystemRoutes, plugins, _ref3, renderFunction, exportStatement, imports, code, entryFile, rawAsyncEntryCode, ssr, _ref1, asyncEntryCode, bootstrapFile;
306
+ var entryName, isMainEntry, isAutoMount, customBootstrap, fileSystemRoutes, plugins, _ref3, renderFunction, exportStatement, imports, code, entryFile, rawAsyncEntryCode, ssr, _ref1, asyncEntryCode, bootstrapFile;
307
307
  return _ts_generator(this, function(_state2) {
308
308
  switch (_state2.label) {
309
309
  case 0:
310
- entryName = entrypoint.entryName, isAutoMount = entrypoint.isAutoMount, customBootstrap = entrypoint.customBootstrap, fileSystemRoutes = entrypoint.fileSystemRoutes;
310
+ entryName = entrypoint.entryName, isMainEntry = entrypoint.isMainEntry, isAutoMount = entrypoint.isAutoMount, customBootstrap = entrypoint.customBootstrap, fileSystemRoutes = entrypoint.fileSystemRoutes;
311
311
  if (!isAutoMount)
312
312
  return [
313
313
  3,
@@ -359,7 +359,7 @@ export var generateIndexCode = function() {
359
359
  5
360
360
  ];
361
361
  rawAsyncEntryCode = "import('./".concat(ENTRY_BOOTSTRAP_FILE_NAME, "');");
362
- ssr = getEntryOptions(entryName, config.server.ssr, config.server.ssrByEntries, packageName);
362
+ ssr = getEntryOptions(entryName, isMainEntry, config.server.ssr, config.server.ssrByEntries, packageName);
363
363
  if (ssr) {
364
364
  rawAsyncEntryCode = "\n export const ".concat(SERVER_RENDER_FUNCTION_NAME, " = async (...args) => {\n let entry = await ").concat(rawAsyncEntryCode, ";\n if (entry.default instanceof Promise){\n entry = await entry.default;\n return entry.default.").concat(SERVER_RENDER_FUNCTION_NAME, ".apply(null, args);\n }\n return entry.").concat(SERVER_RENDER_FUNCTION_NAME, ".apply(null, args);\n };\n if(typeof window!=='undefined'){\n ").concat(rawAsyncEntryCode, "\n }\n ");
365
365
  }
@@ -27,19 +27,21 @@ var ifAlreadyExists = function(entrypoints, checked) {
27
27
  };
28
28
  export var getBundleEntry = function(appContext, config) {
29
29
  var appDirectory = appContext.appDirectory, packageName = appContext.packageName;
30
- var _config_source = config.source, disableDefaultEntries = _config_source.disableDefaultEntries, entries = _config_source.entries, entriesDir = _config_source.entriesDir;
30
+ var _config_source = config.source, disableDefaultEntries = _config_source.disableDefaultEntries, entries = _config_source.entries, entriesDir = _config_source.entriesDir, mainEntryName = _config_source.mainEntryName;
31
31
  var defaults = disableDefaultEntries ? [] : getFileSystemEntry(appContext, config);
32
32
  if (entries) {
33
33
  Object.keys(entries).forEach(function(name) {
34
34
  var value = entries[name];
35
35
  var entrypoint = typeof value === "string" ? {
36
36
  entryName: name,
37
+ isMainEntry: false,
37
38
  entry: ensureAbsolutePath(appDirectory, value),
38
39
  absoluteEntryDir: isDirectory(ensureAbsolutePath(appDirectory, value)) ? ensureAbsolutePath(appDirectory, value) : path.dirname(ensureAbsolutePath(appDirectory, value)),
39
40
  isAutoMount: true,
40
41
  fileSystemRoutes: fs.statSync(ensureAbsolutePath(appDirectory, value)).isDirectory() ? {} : void 0
41
42
  } : {
42
43
  entryName: name,
44
+ isMainEntry: false,
43
45
  entry: ensureAbsolutePath(appDirectory, value.entry),
44
46
  absoluteEntryDir: isDirectory(ensureAbsolutePath(appDirectory, value.entry)) ? ensureAbsolutePath(appDirectory, value.entry) : path.dirname(ensureAbsolutePath(appDirectory, value.entry)),
45
47
  isAutoMount: !value.disableMount,
@@ -60,7 +62,10 @@ export var getBundleEntry = function(appContext, config) {
60
62
  var entryName = param.entryName, entry = param.entry, _param_nestedRoutesEntry = param.nestedRoutesEntry, nestedRoutesEntry = _param_nestedRoutesEntry === void 0 ? "" : _param_nestedRoutesEntry;
61
63
  return entryName === packageName || path.dirname(entry) === entriesDirAbs || path.dirname(nestedRoutesEntry) === entriesDirAbs;
62
64
  });
63
- found && (found.entryName = MAIN_ENTRY_NAME);
65
+ if (found) {
66
+ found.entryName = mainEntryName || MAIN_ENTRY_NAME;
67
+ found.isMainEntry = true;
68
+ }
64
69
  }
65
70
  return defaults;
66
71
  };
@@ -30,6 +30,7 @@ var scanDir = function(dirs) {
30
30
  if (indexFile && !customBootstrap) {
31
31
  return {
32
32
  entryName: entryName,
33
+ isMainEntry: false,
33
34
  entry: indexFile,
34
35
  absoluteEntryDir: path.resolve(dir),
35
36
  isAutoMount: false
@@ -39,6 +40,7 @@ var scanDir = function(dirs) {
39
40
  if (isHasApp) {
40
41
  return {
41
42
  entryName: entryName,
43
+ isMainEntry: false,
42
44
  entry: path.join(dir, APP_FILE_NAME),
43
45
  isAutoMount: true,
44
46
  absoluteEntryDir: path.resolve(dir),
@@ -50,6 +52,7 @@ var scanDir = function(dirs) {
50
52
  if (isHasNestedRoutes || isHasPages) {
51
53
  var entrypoint = {
52
54
  entryName: entryName,
55
+ isMainEntry: false,
53
56
  entry: "",
54
57
  fileSystemRoutes: {
55
58
  globalApp: findExists(JS_EXTENSIONS.map(function(ext) {
@@ -72,6 +75,7 @@ var scanDir = function(dirs) {
72
75
  }
73
76
  return {
74
77
  entryName: entryName,
78
+ isMainEntry: false,
75
79
  entry: indexFile,
76
80
  absoluteEntryDir: path.resolve(dir),
77
81
  isAutoMount: false
@@ -2,7 +2,7 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import { _ as _ts_values } from "@swc/helpers/_/_ts_values";
4
4
  import path from "path";
5
- import { fs, findExists, MAIN_ENTRY_NAME } from "@modern-js/utils";
5
+ import { fs, findExists } from "@modern-js/utils";
6
6
  import { HTML_PARTIALS_EXTENSIONS, HTML_PARTIALS_FOLDER } from "./constants";
7
7
  import * as templates from "./templates";
8
8
  var PartialPosition;
@@ -49,13 +49,13 @@ export var getHtmlTemplate = function() {
49
49
  8
50
50
  ]);
51
51
  _loop = function() {
52
- var entrypoint, entryName, name, customIndexTemplate, hookRunners, partials, templatePath, bottomTemplate;
52
+ var entrypoint, entryName, isMainEntry, name, customIndexTemplate, hookRunners, partials, templatePath, bottomTemplate;
53
53
  return _ts_generator(this, function(_state2) {
54
54
  switch (_state2.label) {
55
55
  case 0:
56
56
  entrypoint = _step.value;
57
- entryName = entrypoint.entryName;
58
- name = entrypoints.length === 1 && entryName === MAIN_ENTRY_NAME ? "" : entryName;
57
+ entryName = entrypoint.entryName, isMainEntry = entrypoint.isMainEntry;
58
+ name = entrypoints.length === 1 && isMainEntry ? "" : entryName;
59
59
  customIndexTemplate = findPartials(htmlDir, name, PartialPosition.INDEX);
60
60
  if (!customIndexTemplate)
61
61
  return [
@@ -70,18 +70,19 @@ var applyRouteOptions = function(original, routeOptions) {
70
70
  };
71
71
  var collectHtmlRoutes = function(entrypoints, appContext, config) {
72
72
  var _deploy_worker;
73
- var disableHtmlFolder = config.html.disableHtmlFolder, _config_output = config.output, tmp = _config_output.distPath, _ref = tmp === void 0 ? {} : tmp, htmlPath = _ref.html, _config_server = config.server, baseUrl = _config_server.baseUrl, routes = _config_server.routes, ssr = _config_server.ssr, ssrByEntries = _config_server.ssrByEntries, deploy = config.deploy;
73
+ var mainEntryName = config.source.mainEntryName, disableHtmlFolder = config.html.disableHtmlFolder, _config_output = config.output, tmp = _config_output.distPath, _ref = tmp === void 0 ? {} : tmp, htmlPath = _ref.html, _config_server = config.server, baseUrl = _config_server.baseUrl, routes = _config_server.routes, ssr = _config_server.ssr, ssrByEntries = _config_server.ssrByEntries, deploy = config.deploy;
74
74
  var packageName = appContext.packageName;
75
75
  var workerSSR = deploy === null || deploy === void 0 ? void 0 : (_deploy_worker = deploy.worker) === null || _deploy_worker === void 0 ? void 0 : _deploy_worker.ssr;
76
76
  var htmlRoutes = entrypoints.reduce(function(previous, param) {
77
77
  var entryName = param.entryName;
78
- var entryOptions = getEntryOptions(entryName, ssr, ssrByEntries, packageName);
78
+ var isMainEntry = entryName === (mainEntryName || MAIN_ENTRY_NAME);
79
+ var entryOptions = getEntryOptions(entryName, isMainEntry, ssr, ssrByEntries, packageName);
79
80
  var isSSR = Boolean(entryOptions);
80
81
  var isWorker = Boolean(workerSSR);
81
82
  var isStream = typeof entryOptions === "object" && entryOptions.mode === "stream";
82
83
  var resHeaders = ((routes === null || routes === void 0 ? void 0 : routes[entryName]) || {}).resHeaders;
83
84
  var route = {
84
- urlPath: "/".concat(entryName === MAIN_ENTRY_NAME ? "" : entryName),
85
+ urlPath: "/".concat(isMainEntry ? "" : entryName),
85
86
  entryName: entryName,
86
87
  entryPath: removeLeadingSlash(path.posix.normalize("".concat(htmlPath, "/").concat(entryName).concat(disableHtmlFolder ? ".html" : "/index.html"))),
87
88
  isSPA: true,