@modern-js/app-tools 2.0.0-beta.3 → 2.0.0-canary.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 (221) hide show
  1. package/dist/js/modern/analyze/constants.js +38 -18
  2. package/dist/js/modern/analyze/generateCode.js +261 -221
  3. package/dist/js/modern/analyze/getBundleEntry.js +31 -32
  4. package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +93 -49
  5. package/dist/js/modern/analyze/getClientRoutes/getRoutesLegacy.js +89 -47
  6. package/dist/js/modern/analyze/getClientRoutes/index.js +6 -2
  7. package/dist/js/modern/analyze/getClientRoutes/utils.js +23 -10
  8. package/dist/js/modern/analyze/getFileSystemEntry.js +43 -22
  9. package/dist/js/modern/analyze/getHtmlTemplate.js +89 -49
  10. package/dist/js/modern/analyze/getServerRoutes.js +122 -126
  11. package/dist/js/modern/analyze/index.js +193 -159
  12. package/dist/js/modern/analyze/isDefaultExportFunction.js +30 -16
  13. package/dist/js/modern/analyze/makeLegalIdentifier.js +10 -11
  14. package/dist/js/modern/analyze/nestedRoutes.js +106 -60
  15. package/dist/js/modern/analyze/templates.js +161 -80
  16. package/dist/js/modern/analyze/utils.js +87 -66
  17. package/dist/js/modern/builder/builderPlugins/compatModern.js +121 -109
  18. package/dist/js/modern/builder/index.js +122 -83
  19. package/dist/js/modern/builder/loaders/routerLoader.js +9 -12
  20. package/dist/js/modern/builder/loaders/serverModuleLoader.js +4 -1
  21. package/dist/js/modern/builder/share.js +22 -20
  22. package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +23 -22
  23. package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +31 -27
  24. package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +98 -84
  25. package/dist/js/modern/commands/build.js +67 -42
  26. package/dist/js/modern/commands/deploy.js +27 -4
  27. package/dist/js/modern/commands/dev.js +77 -27
  28. package/dist/js/modern/commands/index.js +1 -1
  29. package/dist/js/modern/commands/inspect.js +30 -5
  30. package/dist/js/modern/commands/start.js +37 -15
  31. package/dist/js/modern/config/default.js +103 -113
  32. package/dist/js/modern/config/index.js +8 -2
  33. package/dist/js/modern/config/initial/createHtmlConfig.js +5 -2
  34. package/dist/js/modern/config/initial/createOutputConfig.js +9 -10
  35. package/dist/js/modern/config/initial/createSourceConfig.js +5 -2
  36. package/dist/js/modern/config/initial/createToolsConfig.js +7 -6
  37. package/dist/js/modern/config/initial/index.js +9 -4
  38. package/dist/js/modern/config/initial/inits.js +109 -73
  39. package/dist/js/modern/config/initial/transformNormalizedConfig.js +6 -3
  40. package/dist/js/modern/defineConfig.js +26 -11
  41. package/dist/js/modern/exports/server.js +4 -1
  42. package/dist/js/modern/hooks.js +10 -3
  43. package/dist/js/modern/index.js +140 -89
  44. package/dist/js/modern/initialize/index.js +98 -51
  45. package/dist/js/modern/locale/en.js +20 -21
  46. package/dist/js/modern/locale/index.js +6 -6
  47. package/dist/js/modern/locale/zh.js +21 -22
  48. package/dist/js/modern/schema/Schema.js +6 -5
  49. package/dist/js/modern/schema/index.js +51 -100
  50. package/dist/js/modern/schema/legacy.js +96 -231
  51. package/dist/js/modern/types/config/index.js +0 -1
  52. package/dist/js/modern/types/index.js +0 -1
  53. package/dist/js/modern/types/legacyConfig/output.js +0 -1
  54. package/dist/js/modern/utils/commands.js +5 -2
  55. package/dist/js/modern/utils/config.js +102 -41
  56. package/dist/js/modern/utils/createFileWatcher.js +84 -51
  57. package/dist/js/modern/utils/createServer.js +63 -17
  58. package/dist/js/modern/utils/getSpecifiedEntries.js +46 -19
  59. package/dist/js/modern/utils/language.js +6 -3
  60. package/dist/js/modern/utils/printInstructions.js +27 -8
  61. package/dist/js/modern/utils/restart.js +43 -16
  62. package/dist/js/modern/utils/routes.js +29 -12
  63. package/dist/js/node/analyze/constants.js +54 -39
  64. package/dist/js/node/analyze/generateCode.js +281 -239
  65. package/dist/js/node/analyze/getBundleEntry.js +55 -44
  66. package/dist/js/node/analyze/getClientRoutes/getRoutes.js +132 -76
  67. package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +128 -74
  68. package/dist/js/node/analyze/getClientRoutes/index.js +23 -17
  69. package/dist/js/node/analyze/getClientRoutes/utils.js +44 -21
  70. package/dist/js/node/analyze/getFileSystemEntry.js +70 -39
  71. package/dist/js/node/analyze/getHtmlTemplate.js +116 -61
  72. package/dist/js/node/analyze/getServerRoutes.js +143 -137
  73. package/dist/js/node/analyze/index.js +240 -174
  74. package/dist/js/node/analyze/isDefaultExportFunction.js +55 -26
  75. package/dist/js/node/analyze/makeLegalIdentifier.js +27 -15
  76. package/dist/js/node/analyze/nestedRoutes.js +137 -75
  77. package/dist/js/node/analyze/templates.js +183 -89
  78. package/dist/js/node/analyze/utils.js +114 -81
  79. package/dist/js/node/builder/builderPlugins/compatModern.js +149 -122
  80. package/dist/js/node/builder/index.js +150 -92
  81. package/dist/js/node/builder/loaders/routerLoader.js +27 -18
  82. package/dist/js/node/builder/loaders/serverModuleLoader.js +22 -7
  83. package/dist/js/node/builder/share.js +45 -25
  84. package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +39 -26
  85. package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +47 -31
  86. package/dist/js/node/builder/webpackPlugins/routerPlugin.js +116 -90
  87. package/dist/js/node/commands/build.js +89 -52
  88. package/dist/js/node/commands/deploy.js +45 -10
  89. package/dist/js/node/commands/dev.js +99 -41
  90. package/dist/js/node/commands/index.js +19 -38
  91. package/dist/js/node/commands/inspect.js +48 -11
  92. package/dist/js/node/commands/start.js +65 -26
  93. package/dist/js/node/config/default.js +119 -117
  94. package/dist/js/node/config/index.js +25 -29
  95. package/dist/js/node/config/initial/createHtmlConfig.js +22 -6
  96. package/dist/js/node/config/initial/createOutputConfig.js +26 -14
  97. package/dist/js/node/config/initial/createSourceConfig.js +22 -6
  98. package/dist/js/node/config/initial/createToolsConfig.js +24 -10
  99. package/dist/js/node/config/initial/index.js +28 -17
  100. package/dist/js/node/config/initial/inits.js +126 -81
  101. package/dist/js/node/config/initial/transformNormalizedConfig.js +31 -15
  102. package/dist/js/node/defineConfig.js +43 -17
  103. package/dist/js/node/exports/server.js +21 -10
  104. package/dist/js/node/hooks.js +44 -29
  105. package/dist/js/node/index.js +190 -130
  106. package/dist/js/node/initialize/index.js +116 -61
  107. package/dist/js/node/locale/en.js +36 -25
  108. package/dist/js/node/locale/index.js +27 -15
  109. package/dist/js/node/locale/zh.js +37 -26
  110. package/dist/js/node/schema/Schema.js +23 -10
  111. package/dist/js/node/schema/index.js +77 -114
  112. package/dist/js/node/schema/legacy.js +117 -240
  113. package/dist/js/node/types/config/index.js +17 -16
  114. package/dist/js/node/types/index.js +19 -38
  115. package/dist/js/node/types/legacyConfig/output.js +0 -5
  116. package/dist/js/node/utils/commands.js +21 -6
  117. package/dist/js/node/utils/config.js +120 -51
  118. package/dist/js/node/utils/createFileWatcher.js +104 -61
  119. package/dist/js/node/utils/createServer.js +86 -25
  120. package/dist/js/node/utils/getSpecifiedEntries.js +64 -25
  121. package/dist/js/node/utils/language.js +24 -8
  122. package/dist/js/node/utils/printInstructions.js +47 -16
  123. package/dist/js/node/utils/restart.js +61 -21
  124. package/dist/js/node/utils/routes.js +53 -18
  125. package/dist/js/treeshaking/analyze/constants.js +28 -18
  126. package/dist/js/treeshaking/analyze/generateCode.js +599 -406
  127. package/dist/js/treeshaking/analyze/getBundleEntry.js +52 -63
  128. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +214 -168
  129. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +215 -169
  130. package/dist/js/treeshaking/analyze/getClientRoutes/index.js +3 -2
  131. package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +19 -20
  132. package/dist/js/treeshaking/analyze/getFileSystemEntry.js +89 -86
  133. package/dist/js/treeshaking/analyze/getHtmlTemplate.js +298 -125
  134. package/dist/js/treeshaking/analyze/getServerRoutes.js +210 -147
  135. package/dist/js/treeshaking/analyze/index.js +558 -303
  136. package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +45 -26
  137. package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +13 -16
  138. package/dist/js/treeshaking/analyze/nestedRoutes.js +411 -200
  139. package/dist/js/treeshaking/analyze/templates.js +433 -236
  140. package/dist/js/treeshaking/analyze/utils.js +358 -153
  141. package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +281 -200
  142. package/dist/js/treeshaking/builder/index.js +371 -163
  143. package/dist/js/treeshaking/builder/loaders/routerLoader.js +11 -12
  144. package/dist/js/treeshaking/builder/loaders/serverModuleLoader.js +3 -2
  145. package/dist/js/treeshaking/builder/share.js +41 -44
  146. package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +108 -44
  147. package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +70 -39
  148. package/dist/js/treeshaking/builder/webpackPlugins/routerPlugin.js +332 -112
  149. package/dist/js/treeshaking/commands/build.js +286 -88
  150. package/dist/js/treeshaking/commands/deploy.js +153 -25
  151. package/dist/js/treeshaking/commands/dev.js +318 -131
  152. package/dist/js/treeshaking/commands/index.js +1 -1
  153. package/dist/js/treeshaking/commands/inspect.js +147 -32
  154. package/dist/js/treeshaking/commands/start.js +190 -67
  155. package/dist/js/treeshaking/config/default.js +210 -198
  156. package/dist/js/treeshaking/config/index.js +3 -2
  157. package/dist/js/treeshaking/config/initial/createHtmlConfig.js +19 -31
  158. package/dist/js/treeshaking/config/initial/createOutputConfig.js +43 -70
  159. package/dist/js/treeshaking/config/initial/createSourceConfig.js +37 -40
  160. package/dist/js/treeshaking/config/initial/createToolsConfig.js +23 -38
  161. package/dist/js/treeshaking/config/initial/index.js +10 -9
  162. package/dist/js/treeshaking/config/initial/inits.js +205 -106
  163. package/dist/js/treeshaking/config/initial/transformNormalizedConfig.js +27 -34
  164. package/dist/js/treeshaking/defineConfig.js +60 -13
  165. package/dist/js/treeshaking/exports/server.js +2 -1
  166. package/dist/js/treeshaking/hooks.js +26 -25
  167. package/dist/js/treeshaking/index.js +465 -257
  168. package/dist/js/treeshaking/initialize/index.js +290 -112
  169. package/dist/js/treeshaking/locale/en.js +34 -33
  170. package/dist/js/treeshaking/locale/index.js +5 -5
  171. package/dist/js/treeshaking/locale/zh.js +34 -33
  172. package/dist/js/treeshaking/schema/Schema.js +267 -69
  173. package/dist/js/treeshaking/schema/index.js +165 -121
  174. package/dist/js/treeshaking/schema/legacy.js +323 -256
  175. package/dist/js/treeshaking/types/config/deploy.js +1 -0
  176. package/dist/js/treeshaking/types/config/dev.js +1 -0
  177. package/dist/js/treeshaking/types/config/experiments.js +1 -0
  178. package/dist/js/treeshaking/types/config/html.js +1 -0
  179. package/dist/js/treeshaking/types/config/index.js +0 -1
  180. package/dist/js/treeshaking/types/config/output.js +1 -0
  181. package/dist/js/treeshaking/types/config/performance.js +1 -0
  182. package/dist/js/treeshaking/types/config/security.js +1 -0
  183. package/dist/js/treeshaking/types/config/source.js +1 -0
  184. package/dist/js/treeshaking/types/config/tools.js +1 -0
  185. package/dist/js/treeshaking/types/hooks.js +1 -0
  186. package/dist/js/treeshaking/types/index.js +0 -1
  187. package/dist/js/treeshaking/types/legacyConfig/deploy.js +1 -0
  188. package/dist/js/treeshaking/types/legacyConfig/dev.js +1 -0
  189. package/dist/js/treeshaking/types/legacyConfig/index.js +1 -0
  190. package/dist/js/treeshaking/types/legacyConfig/output.js +1 -1
  191. package/dist/js/treeshaking/types/legacyConfig/source.js +1 -0
  192. package/dist/js/treeshaking/types/legacyConfig/tools.js +1 -0
  193. package/dist/js/treeshaking/utils/commands.js +6 -5
  194. package/dist/js/treeshaking/utils/config.js +295 -117
  195. package/dist/js/treeshaking/utils/createFileWatcher.js +278 -118
  196. package/dist/js/treeshaking/utils/createServer.js +252 -67
  197. package/dist/js/treeshaking/utils/getSpecifiedEntries.js +182 -55
  198. package/dist/js/treeshaking/utils/language.js +6 -5
  199. package/dist/js/treeshaking/utils/printInstructions.js +151 -29
  200. package/dist/js/treeshaking/utils/restart.js +184 -42
  201. package/dist/js/treeshaking/utils/routes.js +151 -27
  202. package/dist/js/treeshaking/utils/types.js +1 -0
  203. package/dist/types/analyze/index.d.ts +2 -0
  204. package/dist/types/builder/builderPlugins/compatModern.d.ts +2 -1
  205. package/dist/types/builder/index.d.ts +2 -2
  206. package/dist/types/builder/webpackPlugins/routerPlugin.d.ts +1 -7
  207. package/dist/types/defineConfig.d.ts +1 -0
  208. package/dist/types/index.d.ts +2 -0
  209. package/dist/types/initialize/index.d.ts +2 -0
  210. package/dist/types/types/config/index.d.ts +1 -0
  211. package/dist/types/types/config/output.d.ts +0 -1
  212. package/dist/types/types/config/source.d.ts +1 -0
  213. package/dist/types/types/config/tools.d.ts +2 -0
  214. package/dist/types/types/legacyConfig/dev.d.ts +1 -0
  215. package/dist/types/types/legacyConfig/output.d.ts +1 -1
  216. package/dist/types/types/legacyConfig/source.d.ts +1 -0
  217. package/dist/types/types/legacyConfig/tools.d.ts +1 -0
  218. package/dist/types/utils/config.d.ts +1 -0
  219. package/dist/types/utils/createServer.d.ts +1 -0
  220. package/dist/types/utils/restart.d.ts +1 -1
  221. package/package.json +9 -8
@@ -1,18 +1,38 @@
1
- export const JS_EXTENSIONS = ['.js', '.ts', '.jsx', '.tsx'];
2
- export const INDEX_FILE_NAME = 'index';
3
- export const APP_FILE_NAME = 'App';
4
- export const PAGES_DIR_NAME = 'pages';
5
- export const NESTED_ROUTES_DIR = 'routes';
6
- export const FILE_SYSTEM_ROUTES_FILE_NAME = 'routes.js';
7
- export const LOADER_EXPORT_NAME = 'loader';
8
- export const TEMP_LOADERS_DIR = '__loaders__';
9
- export const ENTRY_POINT_FILE_NAME = 'index.js';
10
- export const ENTRY_BOOTSTRAP_FILE_NAME = 'bootstrap.js';
11
- export const FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP = /^\[(\S+)\]([*+?]?)$/;
12
- export const FILE_SYSTEM_ROUTES_LAYOUT = '_layout';
13
- export const FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT = '_app';
14
- export const FILE_SYSTEM_ROUTES_INDEX = 'index';
15
- export const FILE_SYSTEM_ROUTES_IGNORED_REGEX = /\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/;
16
- export const HTML_PARTIALS_FOLDER = 'html';
17
- export const HTML_PARTIALS_EXTENSIONS = ['.htm', '.html', '.ejs'];
18
- export const FILE_SYSTEM_ROUTES_COMPONENTS_DIR = 'internal_components';
1
+ const JS_EXTENSIONS = [".js", ".ts", ".jsx", ".tsx"];
2
+ const INDEX_FILE_NAME = "index";
3
+ const APP_FILE_NAME = "App";
4
+ const PAGES_DIR_NAME = "pages";
5
+ const NESTED_ROUTES_DIR = "routes";
6
+ const FILE_SYSTEM_ROUTES_FILE_NAME = "routes.js";
7
+ const LOADER_EXPORT_NAME = "loader";
8
+ const TEMP_LOADERS_DIR = "__loaders__";
9
+ const ENTRY_POINT_FILE_NAME = "index.js";
10
+ const ENTRY_BOOTSTRAP_FILE_NAME = "bootstrap.js";
11
+ const FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP = /^\[(\S+)\]([*+?]?)$/;
12
+ const FILE_SYSTEM_ROUTES_LAYOUT = "_layout";
13
+ const FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT = "_app";
14
+ const FILE_SYSTEM_ROUTES_INDEX = "index";
15
+ const FILE_SYSTEM_ROUTES_IGNORED_REGEX = /\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/;
16
+ const HTML_PARTIALS_FOLDER = "html";
17
+ const HTML_PARTIALS_EXTENSIONS = [".htm", ".html", ".ejs"];
18
+ const FILE_SYSTEM_ROUTES_COMPONENTS_DIR = "internal_components";
19
+ export {
20
+ APP_FILE_NAME,
21
+ ENTRY_BOOTSTRAP_FILE_NAME,
22
+ ENTRY_POINT_FILE_NAME,
23
+ FILE_SYSTEM_ROUTES_COMPONENTS_DIR,
24
+ FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP,
25
+ FILE_SYSTEM_ROUTES_FILE_NAME,
26
+ FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT,
27
+ FILE_SYSTEM_ROUTES_IGNORED_REGEX,
28
+ FILE_SYSTEM_ROUTES_INDEX,
29
+ FILE_SYSTEM_ROUTES_LAYOUT,
30
+ HTML_PARTIALS_EXTENSIONS,
31
+ HTML_PARTIALS_FOLDER,
32
+ INDEX_FILE_NAME,
33
+ JS_EXTENSIONS,
34
+ LOADER_EXPORT_NAME,
35
+ NESTED_ROUTES_DIR,
36
+ PAGES_DIR_NAME,
37
+ TEMP_LOADERS_DIR
38
+ };
@@ -1,25 +1,54 @@
1
- import path from 'path';
2
- import { fs, LOADER_ROUTES_DIR, logger } from '@modern-js/utils';
3
- import { useResolvedConfigContext } from '@modern-js/core';
4
- import esbuild from 'esbuild';
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+ import path from "path";
22
+ import {
23
+ fs,
24
+ getEntryOptions,
25
+ LOADER_ROUTES_DIR,
26
+ logger
27
+ } from "@modern-js/utils";
28
+ import {
29
+ useResolvedConfigContext
30
+ } from "@modern-js/core";
31
+ import { build } from "esbuild";
5
32
  import { getCommand } from "../utils/commands";
6
33
  import * as templates from "./templates";
7
34
  import { getClientRoutes, getClientRoutesLegacy } from "./getClientRoutes";
8
- import { FILE_SYSTEM_ROUTES_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME, TEMP_LOADERS_DIR } from "./constants";
35
+ import {
36
+ FILE_SYSTEM_ROUTES_FILE_NAME,
37
+ ENTRY_POINT_FILE_NAME,
38
+ ENTRY_BOOTSTRAP_FILE_NAME,
39
+ TEMP_LOADERS_DIR
40
+ } from "./constants";
9
41
  import { getDefaultImports } from "./utils";
10
42
  import { walk } from "./nestedRoutes";
11
43
  const loader = {
12
- '.js': 'jsx',
13
- '.ts': 'tsx'
44
+ ".js": "jsx",
45
+ ".ts": "tsx"
14
46
  };
15
47
  const EXTERNAL_REGEXP = /^[^./]|^\.[^./]|^\.\.[^/]/;
16
- const createImportSpecifier = specifiers => {
17
- let defaults = '';
48
+ const createImportSpecifier = (specifiers) => {
49
+ let defaults = "";
18
50
  const named = [];
19
- for (const {
20
- local,
21
- imported
22
- } of specifiers) {
51
+ for (const { local, imported } of specifiers) {
23
52
  if (local && imported) {
24
53
  named.push(`${imported} as ${local}`);
25
54
  } else if (local) {
@@ -29,22 +58,18 @@ const createImportSpecifier = specifiers => {
29
58
  }
30
59
  }
31
60
  if (defaults && named.length) {
32
- return `${defaults}, { ${named.join(', ')} }`;
61
+ return `${defaults}, { ${named.join(", ")} }`;
33
62
  } else if (defaults) {
34
63
  return defaults;
35
64
  } else {
36
- return `{ ${named.join(', ')} }`;
65
+ return `{ ${named.join(", ")} }`;
37
66
  }
38
67
  };
39
- export const createImportStatements = statements => {
40
- // merge import statements with the same value.
68
+ const createImportStatements = (statements) => {
69
+ var _a, _b;
41
70
  const deDuplicated = [];
42
- const seen = new Map();
43
- for (const {
44
- value,
45
- specifiers,
46
- initialize
47
- } of statements) {
71
+ const seen = /* @__PURE__ */ new Map();
72
+ for (const { value, specifiers, initialize } of statements) {
48
73
  if (!seen.has(value)) {
49
74
  deDuplicated.push({
50
75
  value,
@@ -53,241 +78,256 @@ export const createImportStatements = statements => {
53
78
  });
54
79
  seen.set(value, specifiers);
55
80
  } else {
56
- var _deDuplicated$modifyI, _deDuplicated$modifyI2;
57
81
  seen.get(value).push(...specifiers);
58
- // make "initialize" param can be connected when multiple plugins were imported from same package
59
- const modifyIndex = deDuplicated.findIndex(v => v.value === value);
60
- const originInitialize = (_deDuplicated$modifyI = (_deDuplicated$modifyI2 = deDuplicated[modifyIndex]) === null || _deDuplicated$modifyI2 === void 0 ? void 0 : _deDuplicated$modifyI2.initialize) !== null && _deDuplicated$modifyI !== void 0 ? _deDuplicated$modifyI : '';
61
- deDuplicated[modifyIndex].initialize = originInitialize.concat(`\n${initialize || ''}`);
82
+ const modifyIndex = deDuplicated.findIndex((v) => v.value === value);
83
+ const originInitialize = (_b = (_a = deDuplicated[modifyIndex]) == null ? void 0 : _a.initialize) != null ? _b : "";
84
+ deDuplicated[modifyIndex].initialize = originInitialize.concat(
85
+ `
86
+ ${initialize || ""}`
87
+ );
62
88
  }
63
89
  }
64
- return deDuplicated.map(({
65
- value,
66
- specifiers,
67
- initialize
68
- }) => `import ${createImportSpecifier(specifiers)} from '${value}';\n${initialize || ''}`).join('\n');
90
+ return deDuplicated.map(
91
+ ({ value, specifiers, initialize }) => `import ${createImportSpecifier(specifiers)} from '${value}';
92
+ ${initialize || ""}`
93
+ ).join("\n");
69
94
  };
70
- const buildLoader = async (entry, outfile) => {
95
+ const buildLoader = (entry, outfile) => __async(void 0, null, function* () {
71
96
  const command = getCommand();
72
- await esbuild.build({
73
- format: 'esm',
74
- platform: 'browser',
75
- target: 'esnext',
97
+ yield build({
98
+ format: "esm",
99
+ platform: "browser",
100
+ target: "esnext",
76
101
  loader,
77
- watch: command === 'dev' && {},
102
+ watch: command === "dev" && {},
78
103
  bundle: true,
79
- logLevel: 'error',
104
+ logLevel: "error",
80
105
  entryPoints: [entry],
81
106
  outfile,
82
- plugins: [{
83
- name: 'make-all-packages-external',
84
- setup(build) {
85
- // https://github.com/evanw/esbuild/issues/619#issuecomment-751995294
86
- build.onResolve({
87
- filter: EXTERNAL_REGEXP
88
- }, args => {
89
- let external = true;
90
- // FIXME: windows external entrypoint
91
- if (args.kind === 'entry-point') {
92
- external = false;
93
- }
94
- return {
95
- path: args.path,
96
- external
97
- };
98
- });
107
+ plugins: [
108
+ {
109
+ name: "make-all-packages-external",
110
+ setup(build2) {
111
+ build2.onResolve({ filter: EXTERNAL_REGEXP }, (args) => {
112
+ let external = true;
113
+ if (args.kind === "entry-point") {
114
+ external = false;
115
+ }
116
+ return {
117
+ path: args.path,
118
+ external
119
+ };
120
+ });
121
+ }
99
122
  }
100
- }]
123
+ ]
101
124
  });
102
- };
103
- const buildServerLoader = async (entry, outfile) => {
125
+ });
126
+ const buildServerLoader = (entry, outfile) => __async(void 0, null, function* () {
104
127
  const command = getCommand();
105
- await esbuild.build({
106
- format: 'cjs',
107
- platform: 'node',
108
- target: 'esnext',
128
+ yield build({
129
+ format: "cjs",
130
+ platform: "node",
131
+ target: "esnext",
109
132
  loader,
110
- watch: command === 'dev' && {},
133
+ watch: command === "dev" && {},
111
134
  bundle: true,
112
- logLevel: 'error',
135
+ logLevel: "error",
113
136
  entryPoints: [entry],
114
137
  outfile
115
138
  });
116
- };
117
- export const generateCode = async (appContext, config, entrypoints, api) => {
118
- var _config$runtime, _config$runtime$route;
139
+ });
140
+ const generateCode = (appContext, config, entrypoints, api) => __async(void 0, null, function* () {
141
+ var _a, _b;
119
142
  const {
120
143
  internalDirectory,
121
144
  distDirectory,
122
145
  srcDirectory,
123
146
  internalDirAlias,
124
- internalSrcAlias
147
+ internalSrcAlias,
148
+ packageName
125
149
  } = appContext;
126
150
  const hookRunners = api.useHookRunners();
127
- const islegacy = Boolean(config === null || config === void 0 ? void 0 : (_config$runtime = config.runtime) === null || _config$runtime === void 0 ? void 0 : (_config$runtime$route = _config$runtime.router) === null || _config$runtime$route === void 0 ? void 0 : _config$runtime$route.legacy);
128
- const {
129
- mountId
130
- } = config.html;
151
+ const islegacy = Boolean((_b = (_a = config == null ? void 0 : config.runtime) == null ? void 0 : _a.router) == null ? void 0 : _b.legacy);
152
+ const { mountId } = config.html;
131
153
  const getRoutes = islegacy ? getClientRoutesLegacy : getClientRoutes;
132
- await Promise.all(entrypoints.map(generateEntryCode));
133
- async function generateEntryCode(entrypoint) {
134
- const {
135
- entryName,
136
- isAutoMount,
137
- customBootstrap,
138
- fileSystemRoutes
139
- } = entrypoint;
140
- if (isAutoMount) {
141
- // generate routes file for file system routes entrypoint.
142
- if (fileSystemRoutes) {
143
- let initialRoutes = [];
144
- let nestedRoute = null;
145
- if (entrypoint.entry) {
146
- initialRoutes = getRoutes({
154
+ yield Promise.all(entrypoints.map(generateEntryCode));
155
+ function generateEntryCode(entrypoint) {
156
+ return __async(this, null, function* () {
157
+ const { entryName, isAutoMount, customBootstrap, fileSystemRoutes } = entrypoint;
158
+ if (isAutoMount) {
159
+ if (fileSystemRoutes) {
160
+ let initialRoutes = [];
161
+ let nestedRoute = null;
162
+ if (entrypoint.entry) {
163
+ initialRoutes = getRoutes({
164
+ entrypoint,
165
+ srcDirectory,
166
+ srcAlias: internalSrcAlias,
167
+ internalDirectory,
168
+ internalDirAlias
169
+ });
170
+ }
171
+ if (entrypoint.nestedRoutesEntry) {
172
+ if (!islegacy) {
173
+ nestedRoute = yield walk(
174
+ entrypoint.nestedRoutesEntry,
175
+ entrypoint.nestedRoutesEntry,
176
+ {
177
+ name: internalSrcAlias,
178
+ basename: srcDirectory
179
+ },
180
+ entrypoint.entryName
181
+ );
182
+ if (nestedRoute) {
183
+ initialRoutes.unshift(nestedRoute);
184
+ }
185
+ } else {
186
+ logger.error("Nested routes is not supported in legacy mode.");
187
+ process.exit(1);
188
+ }
189
+ }
190
+ const { routes } = yield hookRunners.modifyFileSystemRoutes({
147
191
  entrypoint,
148
- srcDirectory,
149
- srcAlias: internalSrcAlias,
150
- internalDirectory,
151
- internalDirAlias
192
+ routes: initialRoutes
152
193
  });
153
- }
154
- if (entrypoint.nestedRoutesEntry) {
155
- if (!islegacy) {
156
- nestedRoute = await walk(entrypoint.nestedRoutesEntry, entrypoint.nestedRoutesEntry, {
157
- name: internalSrcAlias,
158
- basename: srcDirectory
159
- }, entrypoint.entryName);
160
- if (nestedRoute) {
161
- initialRoutes.unshift(nestedRoute);
162
- }
194
+ const config2 = useResolvedConfigContext();
195
+ const ssr = getEntryOptions(
196
+ entryName,
197
+ config2.server.ssr,
198
+ config2.server.ssrByEntries,
199
+ packageName
200
+ );
201
+ let mode;
202
+ if (ssr) {
203
+ mode = typeof ssr === "object" ? ssr.mode || "string" : "string";
163
204
  } else {
164
- logger.error('Nested routes is not supported in legacy mode.');
165
- // eslint-disable-next-line no-process-exit
166
- process.exit(1);
205
+ mode = false;
167
206
  }
168
- }
169
- const {
170
- routes
171
- } = await hookRunners.modifyFileSystemRoutes({
172
- entrypoint,
173
- routes: initialRoutes
174
- });
175
- const config = useResolvedConfigContext();
176
- const ssr = config === null || config === void 0 ? void 0 : config.server.ssr;
177
- let mode;
178
- if (ssr) {
179
- mode = typeof ssr === 'object' ? ssr.mode || 'string' : 'string';
180
- } else {
181
- mode = false;
182
- }
183
- if (mode === 'stream') {
184
- const hasPageRoute = routes.some(route => 'type' in route && route.type === 'page');
185
- if (hasPageRoute) {
186
- logger.error('streaming ssr is not supported when pages dir exists');
187
- // eslint-disable-next-line no-process-exit
188
- process.exit(1);
207
+ if (mode === "stream") {
208
+ const hasPageRoute = routes.some(
209
+ (route) => "type" in route && route.type === "page"
210
+ );
211
+ if (hasPageRoute) {
212
+ logger.error(
213
+ "Streaming ssr is not supported when pages dir exists"
214
+ );
215
+ process.exit(1);
216
+ }
189
217
  }
218
+ const { code: code2 } = yield hookRunners.beforeGenerateRoutes({
219
+ entrypoint,
220
+ code: yield templates.fileSystemRoutes({
221
+ routes,
222
+ ssrMode: mode,
223
+ nestedRoutesEntry: entrypoint.nestedRoutesEntry,
224
+ entryName: entrypoint.entryName,
225
+ internalDirectory
226
+ })
227
+ });
228
+ if (entrypoint.nestedRoutesEntry) {
229
+ const routesServerFile = path.join(
230
+ internalDirectory,
231
+ entryName,
232
+ "route-server-loaders.js"
233
+ );
234
+ const outputRoutesServerFile = path.join(
235
+ distDirectory,
236
+ LOADER_ROUTES_DIR,
237
+ entryName,
238
+ "index.js"
239
+ );
240
+ const code3 = templates.routesForServer({
241
+ routes,
242
+ internalDirectory,
243
+ entryName
244
+ });
245
+ yield fs.ensureFile(routesServerFile);
246
+ yield fs.writeFile(routesServerFile, code3);
247
+ const loaderEntryFile = path.join(
248
+ internalDirectory,
249
+ entryName,
250
+ TEMP_LOADERS_DIR,
251
+ "entry.js"
252
+ );
253
+ const loaderIndexFile = path.join(
254
+ internalDirectory,
255
+ entryName,
256
+ TEMP_LOADERS_DIR,
257
+ "index.js"
258
+ );
259
+ if (yield fs.pathExists(loaderEntryFile)) {
260
+ yield buildLoader(loaderEntryFile, loaderIndexFile);
261
+ }
262
+ if (yield fs.pathExists(routesServerFile)) {
263
+ yield buildServerLoader(routesServerFile, outputRoutesServerFile);
264
+ }
265
+ }
266
+ fs.outputFileSync(
267
+ path.resolve(
268
+ internalDirectory,
269
+ `./${entryName}/${FILE_SYSTEM_ROUTES_FILE_NAME}`
270
+ ),
271
+ code2,
272
+ "utf8"
273
+ );
190
274
  }
191
- const {
192
- code
193
- } = await hookRunners.beforeGenerateRoutes({
275
+ const { imports: importStatements } = yield hookRunners.modifyEntryImports({
194
276
  entrypoint,
195
- code: await templates.fileSystemRoutes({
196
- routes,
197
- ssrMode: mode,
198
- nestedRoutesEntry: entrypoint.nestedRoutesEntry,
199
- entryName: entrypoint.entryName,
277
+ imports: getDefaultImports({
278
+ entrypoint,
279
+ srcDirectory,
280
+ internalSrcAlias,
281
+ internalDirAlias,
200
282
  internalDirectory
201
283
  })
202
284
  });
203
-
204
- // extract nested router loaders
205
- if (entrypoint.nestedRoutesEntry) {
206
- const routesServerFile = path.join(internalDirectory, entryName, 'route-server-loaders.js');
207
- const outputRoutesServerFile = path.join(distDirectory, LOADER_ROUTES_DIR, entryName, 'index.js');
208
- const code = templates.routesForServer({
209
- routes: routes,
210
- internalDirectory,
211
- entryName
212
- });
213
- await fs.ensureFile(routesServerFile);
214
- await fs.writeFile(routesServerFile, code);
215
- const loaderEntryFile = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, 'entry.js');
216
- const loaderIndexFile = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, 'index.js');
217
- if (await fs.pathExists(loaderEntryFile)) {
218
- await buildLoader(loaderEntryFile, loaderIndexFile);
219
- }
220
- if (await fs.pathExists(routesServerFile)) {
221
- await buildServerLoader(routesServerFile, outputRoutesServerFile);
222
- }
223
- }
224
- fs.outputFileSync(path.resolve(internalDirectory, `./${entryName}/${FILE_SYSTEM_ROUTES_FILE_NAME}`), code, 'utf8');
225
- }
226
-
227
- // call modifyEntryImports hook
228
- const {
229
- imports: importStatements
230
- } = await hookRunners.modifyEntryImports({
231
- entrypoint,
232
- imports: getDefaultImports({
285
+ const { plugins } = yield hookRunners.modifyEntryRuntimePlugins({
233
286
  entrypoint,
234
- srcDirectory,
235
- internalSrcAlias,
236
- internalDirAlias,
237
- internalDirectory
238
- })
239
- });
240
-
241
- // call modifyEntryRuntimePlugins hook
242
- const {
243
- plugins
244
- } = await hookRunners.modifyEntryRuntimePlugins({
245
- entrypoint,
246
- plugins: []
247
- });
248
-
249
- // call modifyEntryRenderFunction hook
250
- const {
251
- code: renderFunction
252
- } = await hookRunners.modifyEntryRenderFunction({
253
- entrypoint,
254
- code: templates.renderFunction({
255
- plugins,
256
- customBootstrap,
257
- fileSystemRoutes
258
- })
259
- });
260
-
261
- // call modifyEntryExport hook
262
- const {
263
- exportStatement
264
- } = await hookRunners.modifyEntryExport({
265
- entrypoint,
266
- exportStatement: 'export default AppWrapper;'
267
- });
268
- const code = templates.index({
269
- mountId: mountId,
270
- imports: createImportStatements(importStatements),
271
- renderFunction,
272
- exportStatement
273
- });
274
- const entryFile = path.resolve(internalDirectory, `./${entryName}/${ENTRY_POINT_FILE_NAME}`);
275
- entrypoint.entry = entryFile;
276
-
277
- // generate entry file.
278
- if (config.source.enableAsyncEntry) {
279
- const {
280
- code: asyncEntryCode
281
- } = await hookRunners.modifyAsyncEntry({
287
+ plugins: []
288
+ });
289
+ const { code: renderFunction } = yield hookRunners.modifyEntryRenderFunction({
282
290
  entrypoint,
283
- code: `import('./${ENTRY_BOOTSTRAP_FILE_NAME}');`
291
+ code: templates.renderFunction({
292
+ plugins,
293
+ customBootstrap,
294
+ fileSystemRoutes
295
+ })
284
296
  });
285
- fs.outputFileSync(entryFile, asyncEntryCode, 'utf8');
286
- const bootstrapFile = path.resolve(internalDirectory, `./${entryName}/${ENTRY_BOOTSTRAP_FILE_NAME}`);
287
- fs.outputFileSync(bootstrapFile, code, 'utf8');
288
- } else {
289
- fs.outputFileSync(entryFile, code, 'utf8');
297
+ const { exportStatement } = yield hookRunners.modifyEntryExport({
298
+ entrypoint,
299
+ exportStatement: "export default AppWrapper;"
300
+ });
301
+ const code = templates.index({
302
+ mountId,
303
+ imports: createImportStatements(importStatements),
304
+ renderFunction,
305
+ exportStatement
306
+ });
307
+ const entryFile = path.resolve(
308
+ internalDirectory,
309
+ `./${entryName}/${ENTRY_POINT_FILE_NAME}`
310
+ );
311
+ entrypoint.entry = entryFile;
312
+ if (config.source.enableAsyncEntry) {
313
+ const { code: asyncEntryCode } = yield hookRunners.modifyAsyncEntry({
314
+ entrypoint,
315
+ code: `import('./${ENTRY_BOOTSTRAP_FILE_NAME}');`
316
+ });
317
+ fs.outputFileSync(entryFile, asyncEntryCode, "utf8");
318
+ const bootstrapFile = path.resolve(
319
+ internalDirectory,
320
+ `./${entryName}/${ENTRY_BOOTSTRAP_FILE_NAME}`
321
+ );
322
+ fs.outputFileSync(bootstrapFile, code, "utf8");
323
+ } else {
324
+ fs.outputFileSync(entryFile, code, "utf8");
325
+ }
290
326
  }
291
- }
327
+ });
292
328
  }
293
- };
329
+ });
330
+ export {
331
+ createImportStatements,
332
+ generateCode
333
+ };