@modern-js/app-tools 2.0.0-beta.4 → 2.0.0-beta.7

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 (151) hide show
  1. package/CHANGELOG.md +366 -0
  2. package/bin/modern.js +2 -0
  3. package/dist/js/modern/analyze/constants.js +10 -0
  4. package/dist/js/modern/analyze/generateCode.js +7 -9
  5. package/dist/js/modern/analyze/getBundleEntry.js +2 -1
  6. package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +9 -6
  7. package/dist/js/modern/analyze/getFileSystemEntry.js +11 -3
  8. package/dist/js/modern/analyze/index.js +7 -5
  9. package/dist/js/modern/analyze/nestedRoutes.js +29 -22
  10. package/dist/js/modern/analyze/templates.js +8 -1
  11. package/dist/js/modern/analyze/utils.js +21 -4
  12. package/dist/js/modern/builder/builderPlugins/compatModern.js +8 -2
  13. package/dist/js/modern/builder/index.js +9 -9
  14. package/dist/js/modern/commands/dev.js +6 -9
  15. package/dist/js/modern/commands/index.js +1 -1
  16. package/dist/js/modern/commands/{start.js → serve.js} +3 -1
  17. package/dist/js/modern/config/default.js +38 -61
  18. package/dist/js/modern/config/initial/createOutputConfig.js +1 -3
  19. package/dist/js/modern/config/initial/createSourceConfig.js +5 -1
  20. package/dist/js/modern/config/initial/transformNormalizedConfig.js +5 -1
  21. package/dist/js/modern/hooks.js +1 -0
  22. package/dist/js/modern/index.js +5 -5
  23. package/dist/js/modern/initialize/index.js +5 -4
  24. package/dist/js/modern/locale/en.js +1 -1
  25. package/dist/js/modern/locale/zh.js +1 -1
  26. package/dist/js/modern/schema/index.js +5 -7
  27. package/dist/js/modern/schema/legacy.js +1 -2
  28. package/dist/js/modern/utils/commands.js +6 -1
  29. package/dist/js/modern/utils/getServerInternalPlugins.js +58 -0
  30. package/dist/js/node/analyze/Builder.js +14 -8
  31. package/dist/js/node/analyze/constants.js +35 -3
  32. package/dist/js/node/analyze/generateCode.js +27 -24
  33. package/dist/js/node/analyze/getBundleEntry.js +9 -4
  34. package/dist/js/node/analyze/getClientRoutes/getRoutes.js +33 -28
  35. package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +24 -22
  36. package/dist/js/node/analyze/getClientRoutes/index.js +8 -3
  37. package/dist/js/node/analyze/getClientRoutes/utils.js +10 -3
  38. package/dist/js/node/analyze/getFileSystemEntry.js +18 -6
  39. package/dist/js/node/analyze/getHtmlTemplate.js +18 -14
  40. package/dist/js/node/analyze/getServerRoutes.js +36 -34
  41. package/dist/js/node/analyze/index.js +45 -59
  42. package/dist/js/node/analyze/isDefaultExportFunction.js +7 -3
  43. package/dist/js/node/analyze/makeLegalIdentifier.js +7 -3
  44. package/dist/js/node/analyze/nestedRoutes.js +58 -49
  45. package/dist/js/node/analyze/templates.js +45 -32
  46. package/dist/js/node/analyze/utils.js +41 -18
  47. package/dist/js/node/builder/builderPlugins/compatModern.js +32 -24
  48. package/dist/js/node/builder/index.js +38 -49
  49. package/dist/js/node/builder/loaders/routerLoader.js +5 -3
  50. package/dist/js/node/builder/loaders/serverModuleLoader.js +5 -3
  51. package/dist/js/node/builder/share.js +7 -3
  52. package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +7 -3
  53. package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +7 -3
  54. package/dist/js/node/builder/webpackPlugins/routerPlugin.js +9 -7
  55. package/dist/js/node/commands/build.js +30 -28
  56. package/dist/js/node/commands/deploy.js +9 -5
  57. package/dist/js/node/commands/dev.js +39 -40
  58. package/dist/js/node/commands/index.js +5 -5
  59. package/dist/js/node/commands/inspect.js +10 -6
  60. package/dist/js/node/commands/{start.js → serve.js} +16 -10
  61. package/dist/js/node/config/default.js +44 -64
  62. package/dist/js/node/config/index.js +10 -3
  63. package/dist/js/node/config/initial/createHtmlConfig.js +7 -3
  64. package/dist/js/node/config/initial/createOutputConfig.js +8 -6
  65. package/dist/js/node/config/initial/createSourceConfig.js +12 -4
  66. package/dist/js/node/config/initial/createToolsConfig.js +7 -3
  67. package/dist/js/node/config/initial/index.js +9 -3
  68. package/dist/js/node/config/initial/inits.js +26 -22
  69. package/dist/js/node/config/initial/transformNormalizedConfig.js +12 -4
  70. package/dist/js/node/defineConfig.js +25 -22
  71. package/dist/js/node/exports/server.js +7 -3
  72. package/dist/js/node/hooks.js +8 -3
  73. package/dist/js/node/index.js +56 -69
  74. package/dist/js/node/initialize/index.js +33 -32
  75. package/dist/js/node/locale/en.js +8 -4
  76. package/dist/js/node/locale/index.js +8 -3
  77. package/dist/js/node/locale/zh.js +8 -4
  78. package/dist/js/node/schema/Schema.js +7 -3
  79. package/dist/js/node/schema/index.js +13 -10
  80. package/dist/js/node/schema/legacy.js +6 -5
  81. package/dist/js/node/types/config/deploy.js +15 -0
  82. package/dist/js/node/types/config/dev.js +15 -0
  83. package/dist/js/node/types/config/experiments.js +15 -0
  84. package/dist/js/node/types/config/html.js +15 -0
  85. package/dist/js/node/types/config/index.js +3 -3
  86. package/dist/js/node/types/config/output.js +15 -0
  87. package/dist/js/node/types/config/performance.js +15 -0
  88. package/dist/js/node/types/config/security.js +15 -0
  89. package/dist/js/node/types/config/source.js +15 -0
  90. package/dist/js/node/types/config/tools.js +15 -0
  91. package/dist/js/node/types/hooks.js +15 -0
  92. package/dist/js/node/types/index.js +5 -5
  93. package/dist/js/node/types/legacyConfig/deploy.js +15 -0
  94. package/dist/js/node/types/legacyConfig/dev.js +15 -0
  95. package/dist/js/node/types/legacyConfig/index.js +15 -0
  96. package/dist/js/node/types/legacyConfig/output.js +15 -0
  97. package/dist/js/node/types/legacyConfig/source.js +15 -0
  98. package/dist/js/node/types/legacyConfig/tools.js +15 -0
  99. package/dist/js/node/utils/commands.js +14 -4
  100. package/dist/js/node/utils/config.js +35 -30
  101. package/dist/js/node/utils/createFileWatcher.js +15 -10
  102. package/dist/js/node/utils/createServer.js +35 -29
  103. package/dist/js/node/utils/getServerInternalPlugins.js +79 -0
  104. package/dist/js/node/utils/getSpecifiedEntries.js +10 -6
  105. package/dist/js/node/utils/language.js +7 -3
  106. package/dist/js/node/utils/printInstructions.js +10 -6
  107. package/dist/js/node/utils/restart.js +11 -7
  108. package/dist/js/node/utils/routes.js +11 -7
  109. package/dist/js/node/utils/types.js +15 -0
  110. package/dist/js/treeshaking/analyze/constants.js +10 -1
  111. package/dist/js/treeshaking/analyze/generateCode.js +7 -11
  112. package/dist/js/treeshaking/analyze/getBundleEntry.js +2 -1
  113. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +9 -6
  114. package/dist/js/treeshaking/analyze/getFileSystemEntry.js +11 -3
  115. package/dist/js/treeshaking/analyze/index.js +7 -4
  116. package/dist/js/treeshaking/analyze/nestedRoutes.js +30 -23
  117. package/dist/js/treeshaking/analyze/templates.js +6 -1
  118. package/dist/js/treeshaking/analyze/utils.js +14 -4
  119. package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +6 -2
  120. package/dist/js/treeshaking/builder/index.js +4 -9
  121. package/dist/js/treeshaking/commands/dev.js +19 -24
  122. package/dist/js/treeshaking/commands/index.js +1 -1
  123. package/dist/js/treeshaking/commands/{start.js → serve.js} +10 -3
  124. package/dist/js/treeshaking/config/default.js +53 -56
  125. package/dist/js/treeshaking/config/initial/createOutputConfig.js +1 -3
  126. package/dist/js/treeshaking/config/initial/createSourceConfig.js +5 -1
  127. package/dist/js/treeshaking/config/initial/transformNormalizedConfig.js +5 -1
  128. package/dist/js/treeshaking/hooks.js +1 -0
  129. package/dist/js/treeshaking/index.js +5 -5
  130. package/dist/js/treeshaking/initialize/index.js +6 -5
  131. package/dist/js/treeshaking/locale/en.js +1 -1
  132. package/dist/js/treeshaking/locale/zh.js +1 -1
  133. package/dist/js/treeshaking/schema/index.js +10 -11
  134. package/dist/js/treeshaking/schema/legacy.js +0 -3
  135. package/dist/js/treeshaking/utils/commands.js +5 -1
  136. package/dist/js/treeshaking/utils/getServerInternalPlugins.js +210 -0
  137. package/dist/types/analyze/constants.d.ts +10 -1
  138. package/dist/types/analyze/utils.d.ts +2 -1
  139. package/dist/types/commands/index.d.ts +1 -1
  140. package/dist/types/commands/{start.d.ts → serve.d.ts} +0 -0
  141. package/dist/types/index.d.ts +1 -0
  142. package/dist/types/locale/en.d.ts +1 -1
  143. package/dist/types/locale/index.d.ts +2 -2
  144. package/dist/types/locale/zh.d.ts +1 -1
  145. package/dist/types/types/config/index.d.ts +3 -0
  146. package/dist/types/types/config/source.d.ts +2 -1
  147. package/dist/types/types/hooks.d.ts +3 -0
  148. package/dist/types/types/legacyConfig/source.d.ts +0 -1
  149. package/dist/types/utils/commands.d.ts +2 -1
  150. package/dist/types/utils/getServerInternalPlugins.d.ts +2 -0
  151. package/package.json +25 -22
@@ -15,13 +15,17 @@ var __copyProps = (to, from, except, desc) => {
15
15
  return to;
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var stdin_exports = {};
19
- __export(stdin_exports, {
18
+ var language_exports = {};
19
+ __export(language_exports, {
20
20
  getLocaleLanguage: () => getLocaleLanguage
21
21
  });
22
- module.exports = __toCommonJS(stdin_exports);
22
+ module.exports = __toCommonJS(language_exports);
23
23
  var import_language_detector = require("@modern-js/plugin-i18n/language-detector");
24
24
  function getLocaleLanguage() {
25
25
  const detector = new import_language_detector.I18CLILanguageDetector();
26
26
  return detector.detect();
27
27
  }
28
+ // Annotate the CommonJS export names for ESM import in node:
29
+ 0 && (module.exports = {
30
+ getLocaleLanguage
31
+ });
@@ -15,12 +15,6 @@ var __copyProps = (to, from, except, desc) => {
15
15
  return to;
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var stdin_exports = {};
19
- __export(stdin_exports, {
20
- printInstructions: () => printInstructions
21
- });
22
- module.exports = __toCommonJS(stdin_exports);
23
- var import_utils = require("@modern-js/utils");
24
18
  var __async = (__this, __arguments, generator) => {
25
19
  return new Promise((resolve, reject) => {
26
20
  var fulfilled = (value) => {
@@ -41,6 +35,12 @@ var __async = (__this, __arguments, generator) => {
41
35
  step((generator = generator.apply(__this, __arguments)).next());
42
36
  });
43
37
  };
38
+ var printInstructions_exports = {};
39
+ __export(printInstructions_exports, {
40
+ printInstructions: () => printInstructions
41
+ });
42
+ module.exports = __toCommonJS(printInstructions_exports);
43
+ var import_utils = require("@modern-js/utils");
44
44
  const printInstructions = (hookRunners, appContext, config) => __async(void 0, null, function* () {
45
45
  const message = (0, import_utils.prettyInstructions)(appContext, config);
46
46
  const { instructions } = yield hookRunners.beforePrintInstructions({
@@ -48,3 +48,7 @@ const printInstructions = (hookRunners, appContext, config) => __async(void 0, n
48
48
  });
49
49
  import_utils.logger.info(instructions);
50
50
  });
51
+ // Annotate the CommonJS export names for ESM import in node:
52
+ 0 && (module.exports = {
53
+ printInstructions
54
+ });
@@ -15,13 +15,6 @@ var __copyProps = (to, from, except, desc) => {
15
15
  return to;
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var stdin_exports = {};
19
- __export(stdin_exports, {
20
- restart: () => restart
21
- });
22
- module.exports = __toCommonJS(stdin_exports);
23
- var import_core = require("@modern-js/core");
24
- var import_utils = require("@modern-js/utils");
25
18
  var __async = (__this, __arguments, generator) => {
26
19
  return new Promise((resolve, reject) => {
27
20
  var fulfilled = (value) => {
@@ -42,6 +35,13 @@ var __async = (__this, __arguments, generator) => {
42
35
  step((generator = generator.apply(__this, __arguments)).next());
43
36
  });
44
37
  };
38
+ var restart_exports = {};
39
+ __export(restart_exports, {
40
+ restart: () => restart
41
+ });
42
+ module.exports = __toCommonJS(restart_exports);
43
+ var import_core = require("@modern-js/core");
44
+ var import_utils = require("@modern-js/utils");
45
45
  function restart(hooksRunner, filename) {
46
46
  return __async(this, null, function* () {
47
47
  (0, import_utils.clearConsole)();
@@ -61,3 +61,7 @@ function restart(hooksRunner, filename) {
61
61
  }
62
62
  });
63
63
  }
64
+ // Annotate the CommonJS export names for ESM import in node:
65
+ 0 && (module.exports = {
66
+ restart
67
+ });
@@ -21,13 +21,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
21
  mod
22
22
  ));
23
23
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
- var stdin_exports = {};
25
- __export(stdin_exports, {
26
- generateRoutes: () => generateRoutes
27
- });
28
- module.exports = __toCommonJS(stdin_exports);
29
- var import_path = __toESM(require("path"));
30
- var import_utils = require("@modern-js/utils");
31
24
  var __async = (__this, __arguments, generator) => {
32
25
  return new Promise((resolve, reject) => {
33
26
  var fulfilled = (value) => {
@@ -48,8 +41,19 @@ var __async = (__this, __arguments, generator) => {
48
41
  step((generator = generator.apply(__this, __arguments)).next());
49
42
  });
50
43
  };
44
+ var routes_exports = {};
45
+ __export(routes_exports, {
46
+ generateRoutes: () => generateRoutes
47
+ });
48
+ module.exports = __toCommonJS(routes_exports);
49
+ var import_path = __toESM(require("path"));
50
+ var import_utils = require("@modern-js/utils");
51
51
  const generateRoutes = (appContext) => __async(void 0, null, function* () {
52
52
  const { serverRoutes, distDirectory } = appContext;
53
53
  const output = JSON.stringify({ routes: serverRoutes }, null, 2);
54
54
  yield import_utils.fs.outputFile(import_path.default.join(distDirectory, import_utils.ROUTE_SPEC_FILE), output);
55
55
  });
56
+ // Annotate the CommonJS export names for ESM import in node:
57
+ 0 && (module.exports = {
58
+ generateRoutes
59
+ });
@@ -0,0 +1,15 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+ var types_exports = {};
15
+ module.exports = __toCommonJS(types_exports);
@@ -25,4 +25,13 @@ var HTML_PARTIALS_EXTENSIONS = [
25
25
  ".ejs"
26
26
  ];
27
27
  var FILE_SYSTEM_ROUTES_COMPONENTS_DIR = "internal_components";
28
- export { APP_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME, ENTRY_POINT_FILE_NAME, FILE_SYSTEM_ROUTES_COMPONENTS_DIR, FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP, FILE_SYSTEM_ROUTES_FILE_NAME, FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT, FILE_SYSTEM_ROUTES_IGNORED_REGEX, FILE_SYSTEM_ROUTES_INDEX, FILE_SYSTEM_ROUTES_LAYOUT, HTML_PARTIALS_EXTENSIONS, HTML_PARTIALS_FOLDER, INDEX_FILE_NAME, JS_EXTENSIONS, LOADER_EXPORT_NAME, NESTED_ROUTES_DIR, PAGES_DIR_NAME, TEMP_LOADERS_DIR };
28
+ var NESTED_ROUTE = {
29
+ LAYOUT_FILE: "layout",
30
+ LAYOUT_LOADER_FILE: "layout.loader",
31
+ PAGE_FILE: "page",
32
+ PAGE_LOADER_FILE: "page.loader",
33
+ LOADING_FILE: "loading",
34
+ ERROR_FILE: "error",
35
+ LOADER_FILE: "loader"
36
+ };
37
+ export { APP_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME, ENTRY_POINT_FILE_NAME, FILE_SYSTEM_ROUTES_COMPONENTS_DIR, FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP, FILE_SYSTEM_ROUTES_FILE_NAME, FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT, FILE_SYSTEM_ROUTES_IGNORED_REGEX, FILE_SYSTEM_ROUTES_INDEX, FILE_SYSTEM_ROUTES_LAYOUT, HTML_PARTIALS_EXTENSIONS, HTML_PARTIALS_FOLDER, INDEX_FILE_NAME, JS_EXTENSIONS, LOADER_EXPORT_NAME, NESTED_ROUTE, NESTED_ROUTES_DIR, PAGES_DIR_NAME, TEMP_LOADERS_DIR };
@@ -150,7 +150,7 @@ var __generator = this && this.__generator || function(thisArg, body) {
150
150
  import path from "path";
151
151
  import { fs, getEntryOptions, LOADER_ROUTES_DIR, logger } from "@modern-js/utils";
152
152
  import { useResolvedConfigContext } from "@modern-js/core";
153
- import { getCommand } from "../utils/commands";
153
+ import { isDevCommand } from "../utils/commands";
154
154
  import * as templates from "./templates";
155
155
  import { getClientRoutes, getClientRoutesLegacy } from "./getClientRoutes";
156
156
  import { FILE_SYSTEM_ROUTES_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME, TEMP_LOADERS_DIR } from "./constants";
@@ -247,11 +247,9 @@ var createImportStatements = function(statements) {
247
247
  };
248
248
  var buildLoader = function() {
249
249
  var _ref = _asyncToGenerator(function(entry, outfile) {
250
- var command;
251
250
  return __generator(this, function(_state) {
252
251
  switch(_state.label){
253
252
  case 0:
254
- command = getCommand();
255
253
  return [
256
254
  4,
257
255
  loaderBuilder.build({
@@ -259,7 +257,7 @@ var buildLoader = function() {
259
257
  platform: "browser",
260
258
  target: "esnext",
261
259
  loader: loader,
262
- watch: command === "dev" && {},
260
+ watch: isDevCommand() && {},
263
261
  bundle: true,
264
262
  logLevel: "error",
265
263
  entryPoints: [
@@ -301,11 +299,9 @@ var buildLoader = function() {
301
299
  }();
302
300
  var buildServerLoader = function() {
303
301
  var _ref = _asyncToGenerator(function(entry, outfile) {
304
- var command;
305
302
  return __generator(this, function(_state) {
306
303
  switch(_state.label){
307
304
  case 0:
308
- command = getCommand();
309
305
  return [
310
306
  4,
311
307
  serverLoaderBuilder.build({
@@ -313,7 +309,7 @@ var buildServerLoader = function() {
313
309
  platform: "node",
314
310
  target: "esnext",
315
311
  loader: loader,
316
- watch: command === "dev" && {},
312
+ watch: isDevCommand() && {},
317
313
  bundle: true,
318
314
  logLevel: "error",
319
315
  entryPoints: [
@@ -336,7 +332,7 @@ var buildServerLoader = function() {
336
332
  }();
337
333
  var generateCode = function() {
338
334
  var _ref = _asyncToGenerator(function(appContext, config, entrypoints, api) {
339
- var ref, ref1, internalDirectory, distDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName, hookRunners, islegacy, mountId, getRoutes;
335
+ var ref, ref1, ref2, internalDirectory, distDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName, hookRunners, isV5, mountId, getRoutes;
340
336
  function generateEntryCode(entrypoint) {
341
337
  return _generateEntryCode.apply(this, arguments);
342
338
  }
@@ -370,7 +366,7 @@ var generateCode = function() {
370
366
  3,
371
367
  3
372
368
  ];
373
- if (!!islegacy) return [
369
+ if (!!isV5) return [
374
370
  3,
375
371
  2
376
372
  ];
@@ -597,9 +593,9 @@ var generateCode = function() {
597
593
  case 0:
598
594
  internalDirectory = appContext.internalDirectory, distDirectory = appContext.distDirectory, srcDirectory = appContext.srcDirectory, internalDirAlias = appContext.internalDirAlias, internalSrcAlias = appContext.internalSrcAlias, packageName = appContext.packageName;
599
595
  hookRunners = api.useHookRunners();
600
- islegacy = Boolean(config === null || config === void 0 ? void 0 : (ref = config.runtime) === null || ref === void 0 ? void 0 : (ref1 = ref.router) === null || ref1 === void 0 ? void 0 : ref1.legacy);
596
+ isV5 = typeof ((ref = config.runtime) === null || ref === void 0 ? void 0 : ref.router) !== "boolean" && (config === null || config === void 0 ? void 0 : (ref1 = config.runtime) === null || ref1 === void 0 ? void 0 : (ref2 = ref1.router) === null || ref2 === void 0 ? void 0 : ref2.mode) === "react-router-5";
601
597
  mountId = config.html.mountId;
602
- getRoutes = islegacy ? getClientRoutesLegacy : getClientRoutes;
598
+ getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
603
599
  return [
604
600
  4,
605
601
  Promise.all(entrypoints.map(generateEntryCode))
@@ -38,7 +38,8 @@ var getBundleEntry = function(appContext, config) {
38
38
  entryName: name,
39
39
  entry: ensureAbsolutePath(appDirectory, value.entry),
40
40
  isAutoMount: !value.disableMount,
41
- fileSystemRoutes: value.enableFileSystemRoutes ? {} : void 0
41
+ customBootstrap: value.customBootstrap && ensureAbsolutePath(appDirectory, value.customBootstrap),
42
+ fileSystemRoutes: fs.statSync(ensureAbsolutePath(appDirectory, value.entry)).isDirectory() ? {} : void 0
42
43
  };
43
44
  if (entrypoint.fileSystemRoutes) {
44
45
  entrypoint.nestedRoutesEntry = entrypoint.entry;
@@ -198,16 +198,19 @@ var normalizeNestedRoutes = function(nested, internalComponentsDir, internalDire
198
198
  };
199
199
  var getClientRoutes = function(param) {
200
200
  var entrypoint = param.entrypoint, srcDirectory = param.srcDirectory, srcAlias = param.srcAlias, internalDirectory = param.internalDirectory, internalDirAlias = param.internalDirAlias;
201
- var entry = entrypoint.entry, entryName = entrypoint.entryName;
202
- if (!fs.existsSync(entry)) {
203
- throw new Error("generate file system routes error, ".concat(entry, " directory not found."));
201
+ var entryName = entrypoint.entryName, pageRoutesEntry = entrypoint.pageRoutesEntry;
202
+ if (!pageRoutesEntry) {
203
+ return [];
204
204
  }
205
- if (!(fs.existsSync(entry) && fs.statSync(entry).isDirectory())) {
206
- throw new Error("generate file system routes error, ".concat(entry, " should be directory."));
205
+ if (!fs.existsSync(pageRoutesEntry)) {
206
+ throw new Error("generate file system routes error, ".concat(pageRoutesEntry, " directory not found."));
207
+ }
208
+ if (!(fs.existsSync(pageRoutesEntry) && fs.statSync(pageRoutesEntry).isDirectory())) {
209
+ throw new Error("generate file system routes error, ".concat(pageRoutesEntry, " should be directory."));
207
210
  }
208
211
  var routes = [];
209
212
  recursiveReadDir({
210
- dir: entry,
213
+ dir: pageRoutesEntry,
211
214
  routes: routes,
212
215
  basePath: "/",
213
216
  srcDirectory: srcDirectory,
@@ -62,9 +62,11 @@ var scanDir = function(dirs) {
62
62
  };
63
63
  if (isHasPages) {
64
64
  entrypoint.entry = path.join(dir, PAGES_DIR_NAME);
65
+ entrypoint.pageRoutesEntry = entrypoint.entry;
65
66
  }
66
67
  if (isHasNestedRoutes) {
67
- entrypoint.nestedRoutesEntry = path.join(dir, NESTED_ROUTES_DIR);
68
+ entrypoint.entry = path.join(dir, NESTED_ROUTES_DIR);
69
+ entrypoint.nestedRoutesEntry = entrypoint.entry;
68
70
  }
69
71
  return entrypoint;
70
72
  }
@@ -78,7 +80,13 @@ var scanDir = function(dirs) {
78
80
  };
79
81
  var getFileSystemEntry = function(appContext, config) {
80
82
  var appDirectory = appContext.appDirectory;
81
- var entriesDir = config.source.entriesDir;
83
+ var _source = config.source, entriesDir = _source.entriesDir, disableEntryDirs = _source.disableEntryDirs;
84
+ var disabledDirs = [];
85
+ if (disableEntryDirs && Array.isArray(disableEntryDirs)) {
86
+ disabledDirs = disableEntryDirs === null || disableEntryDirs === void 0 ? void 0 : disableEntryDirs.map(function(dir) {
87
+ return ensureAbsolutePath(appDirectory, dir);
88
+ });
89
+ }
82
90
  var src = ensureAbsolutePath(appDirectory, entriesDir || "");
83
91
  if (fs.existsSync(src)) {
84
92
  if (fs.statSync(src).isDirectory()) {
@@ -87,7 +95,7 @@ var getFileSystemEntry = function(appContext, config) {
87
95
  ] : fs.readdirSync(src).map(function(file) {
88
96
  return path.join(src, file);
89
97
  }).filter(function(file) {
90
- return fs.statSync(file).isDirectory() && isBundleEntry(file);
98
+ return fs.statSync(file).isDirectory() && isBundleEntry(file) && !disabledDirs.includes(file);
91
99
  }));
92
100
  } else {
93
101
  throw Error("source.entriesDir accept a directory.");
@@ -229,7 +229,7 @@ import { generateRoutes } from "../utils/routes";
229
229
  import { emitResolvedConfig } from "../utils/config";
230
230
  import { getCommand } from "../utils/commands";
231
231
  import { initialNormalizedConfig } from "../config";
232
- import { isRouteComponentFile } from "./utils";
232
+ import { isNestedRouteComponent, isPageComponentFile } from "./utils";
233
233
  import { loaderBuilder, serverLoaderBuilder } from "./Builder";
234
234
  var debug = createDebugger("plugin-analyze");
235
235
  var analyze_default = function() {
@@ -237,11 +237,12 @@ var analyze_default = function() {
237
237
  name: "@modern-js/plugin-analyze",
238
238
  setup: function(api) {
239
239
  var pagesDir = [];
240
+ var nestedRouteEntries = [];
240
241
  var originEntrypoints = [];
241
242
  return {
242
243
  prepare: function prepare() {
243
244
  return _asyncToGenerator(function() {
244
- var ref, appContext, resolvedConfig, hookRunners, apiOnly, ref1, routes2, ref2, getBundleEntry, getServerRoutes, generateCode, getHtmlTemplate, entrypoints, defaultChecked, initialRoutes, routes, nestedRouteEntries, htmlTemplates, command, buildCommands, normalizedConfig, builder;
245
+ var ref, appContext, resolvedConfig, hookRunners, apiOnly, ref1, routes2, ref2, getBundleEntry, getServerRoutes, generateCode, getHtmlTemplate, entrypoints, defaultChecked, initialRoutes, routes, htmlTemplates, command, buildCommands, normalizedConfig, builder;
245
246
  return __generator(this, function(_state) {
246
247
  switch(_state.label){
247
248
  case 0:
@@ -363,6 +364,7 @@ var analyze_default = function() {
363
364
  command = getCommand();
364
365
  buildCommands = [
365
366
  "dev",
367
+ "start",
366
368
  "build",
367
369
  "inspect",
368
370
  "deploy"
@@ -505,6 +507,7 @@ var analyze_default = function() {
505
507
  ];
506
508
  case 10:
507
509
  builder = _state.sent();
510
+ builder.addPlugins(resolvedConfig.builderPlugins);
508
511
  appContext = _objectSpreadProps(_objectSpread({}, appContext), {
509
512
  builder: builder
510
513
  });
@@ -555,8 +558,8 @@ var analyze_default = function() {
555
558
  });
556
559
  };
557
560
  absoluteFilePath = path.resolve(appDirectory, filename);
558
- isRouteComponent = isPageFile(absoluteFilePath) && isRouteComponentFile(absoluteFilePath);
559
- if (!(isRouteComponent && (eventType === "add" || eventType === "unlink"))) return [
561
+ isRouteComponent = isPageFile(absoluteFilePath) && isPageComponentFile(absoluteFilePath);
562
+ if (!(isRouteComponent && (eventType === "add" || eventType === "unlink") || isNestedRouteComponent(nestedRouteEntries, absoluteFilePath) && eventType === "change")) return [
560
563
  3,
561
564
  2
562
565
  ];
@@ -176,20 +176,9 @@ var __generator = this && this.__generator || function(thisArg, body) {
176
176
  };
177
177
  import * as path from "path";
178
178
  import { fs, getRouteId } from "@modern-js/utils";
179
- import { JS_EXTENSIONS } from "./constants";
179
+ import { JS_EXTENSIONS, NESTED_ROUTE } from "./constants";
180
180
  import { hasLoader, replaceWithAlias } from "./utils";
181
- var LAYOUT_FILE = "layout";
182
- var PAGE_FILE = "page";
183
- var LOADING_FILE = "loading";
184
- var ERROR_FILE = "error";
185
- var LOADER_FILE = "loader";
186
- var conventionNames = [
187
- LAYOUT_FILE,
188
- PAGE_FILE,
189
- LOADING_FILE,
190
- ERROR_FILE,
191
- LOADER_FILE
192
- ];
181
+ var conventionNames = Object.values(NESTED_ROUTE);
193
182
  var getLoaderPath = function() {
194
183
  var _ref = _asyncToGenerator(function(filename) {
195
184
  return __generator(this, function(_state) {
@@ -235,7 +224,7 @@ var createRoute = function(routeInfo, rootDir, filename, entryName) {
235
224
  };
236
225
  var walk = function() {
237
226
  var _ref = _asyncToGenerator(function(dirname, rootDir, alias, entryName) {
238
- var isDirectory, relativeDir, pathSegments, lastSegment, isRoot, isPathlessLayout, isWithoutLayoutPath, routePath, route, items, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, itemPath, extname, itemWithoutExt, isDirectory2, childRoute, ref, ref1, childRoute1, err, finalRoute;
227
+ var isDirectory, relativeDir, pathSegments, lastSegment, isRoot, isPathlessLayout, isWithoutLayoutPath, routePath, route, pageLoaderFile, pageRoute, items, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, itemPath, extname, itemWithoutExt, isDirectory2, childRoute, ref, loaderPath, ref1, loaderPath1, err, finalRoute;
239
228
  return __generator(this, function(_state) {
240
229
  switch(_state.label){
241
230
  case 0:
@@ -278,6 +267,8 @@ var walk = function() {
278
267
  children: [],
279
268
  isRoot: isRoot
280
269
  };
270
+ pageLoaderFile = "";
271
+ pageRoute = null;
281
272
  return [
282
273
  4,
283
274
  fs.readdir(dirname)
@@ -332,7 +323,12 @@ var walk = function() {
332
323
  13
333
324
  ];
334
325
  }
335
- if (!(itemWithoutExt === LAYOUT_FILE)) return [
326
+ if (itemWithoutExt === NESTED_ROUTE.LAYOUT_LOADER_FILE) {
327
+ if (!route.loader) {
328
+ route.loader = itemPath;
329
+ }
330
+ }
331
+ if (!(itemWithoutExt === NESTED_ROUTE.LAYOUT_FILE)) return [
336
332
  3,
337
333
  10
338
334
  ];
@@ -342,14 +338,20 @@ var walk = function() {
342
338
  getLoaderPath(itemPath)
343
339
  ];
344
340
  case 9:
345
- route.loader = _state.sent();
341
+ loaderPath = _state.sent();
342
+ if (loaderPath) {
343
+ route.loader = loaderPath;
344
+ }
346
345
  _state.label = 10;
347
346
  case 10:
348
- if (!(itemWithoutExt === PAGE_FILE)) return [
347
+ if (itemWithoutExt === NESTED_ROUTE.PAGE_LOADER_FILE) {
348
+ pageLoaderFile = itemPath;
349
+ }
350
+ if (!(itemWithoutExt === NESTED_ROUTE.PAGE_FILE)) return [
349
351
  3,
350
352
  12
351
353
  ];
352
- childRoute1 = createIndexRoute({
354
+ pageRoute = createIndexRoute({
353
355
  _component: replaceWithAlias(alias.basename, itemPath, alias.name)
354
356
  }, rootDir, itemPath, entryName);
355
357
  return [
@@ -357,14 +359,19 @@ var walk = function() {
357
359
  getLoaderPath(itemPath)
358
360
  ];
359
361
  case 11:
360
- childRoute1.loader = _state.sent();
361
- (ref1 = route.children) === null || ref1 === void 0 ? void 0 : ref1.push(childRoute1);
362
+ loaderPath1 = _state.sent();
363
+ if (loaderPath1) {
364
+ pageRoute.loader = loaderPath1;
365
+ } else if (pageLoaderFile) {
366
+ pageRoute.loader = pageLoaderFile;
367
+ }
368
+ (ref1 = route.children) === null || ref1 === void 0 ? void 0 : ref1.push(pageRoute);
362
369
  _state.label = 12;
363
370
  case 12:
364
- if (itemWithoutExt === LOADING_FILE) {
371
+ if (itemWithoutExt === NESTED_ROUTE.LOADING_FILE) {
365
372
  route.loading = replaceWithAlias(alias.basename, itemPath, alias.name);
366
373
  }
367
- if (itemWithoutExt === ERROR_FILE) {
374
+ if (itemWithoutExt === NESTED_ROUTE.ERROR_FILE) {
368
375
  route.error = replaceWithAlias(alias.basename, itemPath, alias.name);
369
376
  }
370
377
  _state.label = 13;
@@ -401,7 +408,7 @@ var walk = function() {
401
408
  7
402
409
  ];
403
410
  case 17:
404
- finalRoute = createRoute(route, rootDir, path.join(dirname, "".concat(LAYOUT_FILE, ".ts")), entryName);
411
+ finalRoute = createRoute(route, rootDir, path.join(dirname, "".concat(NESTED_ROUTE.LAYOUT_FILE, ".ts")), entryName);
405
412
  if (isPathlessLayout) {
406
413
  delete finalRoute.path;
407
414
  }
@@ -399,7 +399,12 @@ var fileSystemRoutes = function() {
399
399
  case 0:
400
400
  name = "loader_".concat(index2);
401
401
  filename = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, "".concat(name, ".js"));
402
- code = "\n export { loader as ".concat(name, " } from '").concat(slash(loader), "'\n ");
402
+ code = "";
403
+ if (loader.includes(".loader.")) {
404
+ code = "\n export { default as ".concat(name, " } from '").concat(slash(loader), "'\n ");
405
+ } else {
406
+ code = "\n export { loader as ".concat(name, " } from '").concat(slash(loader), "'\n ");
407
+ }
403
408
  return [
404
409
  4,
405
410
  fs.ensureFile(filename)
@@ -185,7 +185,7 @@ import path from "path";
185
185
  import { isReact18, normalizeToPosixPath, fs as fse } from "@modern-js/utils";
186
186
  import { transform } from "esbuild";
187
187
  import { parse } from "es-module-lexer";
188
- import { FILE_SYSTEM_ROUTES_FILE_NAME, LOADER_EXPORT_NAME } from "./constants";
188
+ import { FILE_SYSTEM_ROUTES_FILE_NAME, LOADER_EXPORT_NAME, NESTED_ROUTE } from "./constants";
189
189
  var walkDirectory = function(dir) {
190
190
  return fs.readdirSync(dir).reduce(function(previous, filename) {
191
191
  var filePath = path.join(dir, filename);
@@ -235,6 +235,7 @@ var getDefaultImports = function(param) {
235
235
  local: "customBootstrap"
236
236
  }
237
237
  ],
238
+ initialize: "const App = false;",
238
239
  value: normalizeToPosixPath(customBootstrap.replace(srcDirectory, internalSrcAlias))
239
240
  }
240
241
  ].filter(Boolean);
@@ -260,7 +261,7 @@ var getDefaultImports = function(param) {
260
261
  route.initialize = "const App = false;";
261
262
  }
262
263
  imports.push(route);
263
- } else {
264
+ } else if (!customBootstrap) {
264
265
  imports.push({
265
266
  specifiers: [
266
267
  {
@@ -272,7 +273,7 @@ var getDefaultImports = function(param) {
272
273
  }
273
274
  return imports;
274
275
  };
275
- var isRouteComponentFile = function(filePath) {
276
+ var isPageComponentFile = function(filePath) {
276
277
  if (/\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/.test(filePath)) {
277
278
  return false;
278
279
  }
@@ -286,6 +287,15 @@ var isRouteComponentFile = function(filePath) {
286
287
  }
287
288
  return false;
288
289
  };
290
+ var isNestedRouteComponent = function(nestedRouteEntries, absoluteFilePath) {
291
+ var reg = new RegExp("(".concat(NESTED_ROUTE.LAYOUT_FILE, "|").concat(NESTED_ROUTE.PAGE_FILE, "})\\.tsx?$"));
292
+ return nestedRouteEntries.some(function(nestedRoutesEntry) {
293
+ if (absoluteFilePath.includes(nestedRoutesEntry) && reg.test(absoluteFilePath)) {
294
+ return true;
295
+ }
296
+ return false;
297
+ });
298
+ };
289
299
  var replaceWithAlias = function(base, filePath, alias) {
290
300
  return normalizeToPosixPath(path.join(alias, path.relative(base, filePath)));
291
301
  };
@@ -366,4 +376,4 @@ var hasLoader = function() {
366
376
  return _ref.apply(this, arguments);
367
377
  };
368
378
  }();
369
- export { getDefaultImports, hasLoader, isRouteComponentFile, parseModule, replaceWithAlias, walkDirectory };
379
+ export { getDefaultImports, hasLoader, isNestedRouteComponent, isPageComponentFile, parseModule, replaceWithAlias, walkDirectory };
@@ -104,7 +104,7 @@ var PluginCompatModern = function(appContext, modernConfig, options) {
104
104
  var ref;
105
105
  return ((ref = config.tools) === null || ref === void 0 ? void 0 : ref.htmlPlugin) !== false && target2 !== "node" && target2 !== "web-worker";
106
106
  };
107
- var ref, ref1;
107
+ var ref;
108
108
  var builderNormalizedConfig = api.getNormalizedConfig();
109
109
  if (target === "node") {
110
110
  chain.name("server");
@@ -148,7 +148,8 @@ var PluginCompatModern = function(appContext, modernConfig, options) {
148
148
  var existNestedRoutes = entrypoints.some(function(entrypoint) {
149
149
  return entrypoint.nestedRoutesEntry;
150
150
  });
151
- var routerManifest = Boolean(modernConfig === null || modernConfig === void 0 ? void 0 : (ref = modernConfig.runtime) === null || ref === void 0 ? void 0 : (ref1 = ref.router) === null || ref1 === void 0 ? void 0 : ref1.manifest);
151
+ var routerConfig = modernConfig === null || modernConfig === void 0 ? void 0 : (ref = modernConfig.runtime) === null || ref === void 0 ? void 0 : ref.router;
152
+ var routerManifest = Boolean(routerConfig === null || routerConfig === void 0 ? void 0 : routerConfig.manifest);
152
153
  if (existNestedRoutes || routerManifest) {
153
154
  chain.plugin("route-plugin").use(RouterPlugin);
154
155
  }
@@ -181,6 +182,9 @@ function applyNodeCompat(chain, modernConfig, isProd) {
181
182
  if (isProd2 && ((outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg) === true || typeof (outputConfig === null || outputConfig === void 0 ? void 0 : (ref = outputConfig.ssg) === null || ref === void 0 ? void 0 : ref[0]) === "function")) {
182
183
  return;
183
184
  }
185
+ if (typeof entries === "undefined") {
186
+ throw new Error("No entry found, one of src/routes/layout.tsx, src/App.tsx, src/index.tsx is required");
187
+ }
184
188
  var entryNames = Object.keys(entries);
185
189
  if (isProd2 && entryNames.length === 1 && (outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg)) {
186
190
  return;
@@ -201,14 +201,15 @@ var __generator = this && this.__generator || function(thisArg, body) {
201
201
  };
202
202
  import { createBuilder } from "@modern-js/builder";
203
203
  import { builderWebpackProvider } from "@modern-js/builder-webpack-provider";
204
- import { applyOptionsChain, isUseSSRBundle } from "@modern-js/utils";
204
+ import { applyOptionsChain, isProd, isSSR, isUseSSRBundle } from "@modern-js/utils";
205
205
  import { PluginCompatModern } from "./builderPlugins/compatModern";
206
206
  import { createCopyPattern } from "./share";
207
207
  function getBuilderTargets(normalizedConfig) {
208
208
  var targets = [
209
209
  "web"
210
210
  ];
211
- if (isUseSSRBundle(normalizedConfig)) {
211
+ var useNodeTarget = isProd() ? isUseSSRBundle(normalizedConfig) : isSSR(normalizedConfig);
212
+ if (useNodeTarget) {
212
213
  targets.push("node");
213
214
  }
214
215
  return targets;
@@ -270,17 +271,11 @@ function createBuilderProviderConfig(normalizedConfig, appContext) {
270
271
  htmlConfig.templateByEntries = _objectSpread({}, htmlConfig.templateByEntries, appContext.htmlTemplates);
271
272
  }
272
273
  return _objectSpreadProps(_objectSpread({}, normalizedConfig), {
273
- source: _objectSpreadProps(_objectSpread({}, normalizedConfig.source), {
274
- resolveExtensionPrefix: ".web"
275
- }),
276
274
  output: output,
277
275
  dev: _objectSpreadProps(_objectSpread({}, normalizedConfig.dev), {
278
276
  port: (ref = normalizedConfig.server) === null || ref === void 0 ? void 0 : ref.port
279
277
  }),
280
- html: htmlConfig,
281
- performance: _objectSpreadProps(_objectSpread({}, normalizedConfig.performance), {
282
- removeMomentLocale: true
283
- })
278
+ html: htmlConfig
284
279
  });
285
280
  }
286
281
  function createBuilderOptions(target, appContext) {