@modern-js/app-tools 2.53.1-alpha.4 → 2.54.1-alpha.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. package/bin/modern.js +0 -2
  2. package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +2 -1
  3. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +2 -2
  4. package/dist/cjs/commands/build.js +2 -0
  5. package/dist/cjs/commands/deploy.js +2 -2
  6. package/dist/cjs/commands/dev.js +19 -5
  7. package/dist/cjs/commands/index.js +113 -7
  8. package/dist/cjs/commands/serve.js +19 -5
  9. package/dist/cjs/hooks.js +5 -0
  10. package/dist/cjs/index.js +14 -83
  11. package/dist/cjs/plugins/analyze/constants.js +56 -0
  12. package/dist/cjs/{analyze → plugins/analyze}/generateCode.js +11 -84
  13. package/dist/cjs/{analyze → plugins/analyze}/getBundleEntry.js +11 -20
  14. package/dist/cjs/{analyze → plugins/analyze}/getFileSystemEntry.js +33 -47
  15. package/dist/cjs/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
  16. package/dist/cjs/{analyze → plugins/analyze}/index.js +9 -24
  17. package/dist/cjs/plugins/analyze/templates.js +101 -0
  18. package/dist/cjs/{analyze → plugins/analyze}/utils.js +12 -55
  19. package/dist/cjs/plugins/deploy/platforms/netlify.js +2 -2
  20. package/dist/cjs/plugins/deploy/platforms/node.js +2 -2
  21. package/dist/cjs/plugins/deploy/platforms/vercel.js +2 -2
  22. package/dist/cjs/{initialize → plugins/initialize}/index.js +1 -1
  23. package/dist/cjs/plugins/serverBuild.js +10 -4
  24. package/dist/cjs/utils/createServer.js +1 -1
  25. package/dist/cjs/utils/{getServerInternalPlugins.js → loadPlugins.js} +18 -11
  26. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +4 -1
  27. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +2 -2
  28. package/dist/esm/commands/build.js +16 -9
  29. package/dist/esm/commands/deploy.js +2 -2
  30. package/dist/esm/commands/dev.js +13 -9
  31. package/dist/esm/commands/index.js +411 -3
  32. package/dist/esm/commands/serve.js +12 -8
  33. package/dist/esm/hooks.js +5 -0
  34. package/dist/esm/index.js +12 -394
  35. package/dist/esm/plugins/analyze/constants.js +24 -0
  36. package/dist/esm/{analyze → plugins/analyze}/generateCode.js +27 -169
  37. package/dist/esm/plugins/analyze/getBundleEntry.js +101 -0
  38. package/dist/esm/plugins/analyze/getFileSystemEntry.js +195 -0
  39. package/dist/esm/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
  40. package/dist/esm/{analyze → plugins/analyze}/index.js +42 -70
  41. package/dist/esm/plugins/analyze/templates.js +22 -0
  42. package/dist/esm/{analyze → plugins/analyze}/utils.js +13 -135
  43. package/dist/esm/plugins/deploy/platforms/netlify.js +5 -3
  44. package/dist/esm/plugins/deploy/platforms/node.js +5 -3
  45. package/dist/esm/plugins/deploy/platforms/vercel.js +5 -3
  46. package/dist/esm/{initialize → plugins/initialize}/index.js +1 -1
  47. package/dist/esm/plugins/serverBuild.js +13 -6
  48. package/dist/esm/utils/createServer.js +2 -2
  49. package/dist/esm/utils/loadPlugins.js +64 -0
  50. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +2 -1
  51. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +2 -2
  52. package/dist/esm-node/commands/build.js +2 -0
  53. package/dist/esm-node/commands/deploy.js +2 -2
  54. package/dist/esm-node/commands/dev.js +11 -7
  55. package/dist/esm-node/commands/index.js +92 -3
  56. package/dist/esm-node/commands/serve.js +10 -6
  57. package/dist/esm-node/hooks.js +5 -0
  58. package/dist/esm-node/index.js +12 -79
  59. package/dist/esm-node/plugins/analyze/constants.js +24 -0
  60. package/dist/esm-node/{analyze → plugins/analyze}/generateCode.js +14 -87
  61. package/dist/esm-node/{analyze → plugins/analyze}/getBundleEntry.js +11 -20
  62. package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +75 -0
  63. package/dist/esm-node/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
  64. package/dist/esm-node/{analyze → plugins/analyze}/index.js +10 -25
  65. package/dist/esm-node/plugins/analyze/templates.js +75 -0
  66. package/dist/esm-node/{analyze → plugins/analyze}/utils.js +13 -52
  67. package/dist/esm-node/plugins/deploy/platforms/netlify.js +3 -3
  68. package/dist/esm-node/plugins/deploy/platforms/node.js +3 -3
  69. package/dist/esm-node/plugins/deploy/platforms/vercel.js +3 -3
  70. package/dist/esm-node/{initialize → plugins/initialize}/index.js +1 -1
  71. package/dist/esm-node/plugins/serverBuild.js +11 -5
  72. package/dist/esm-node/utils/createServer.js +2 -2
  73. package/dist/esm-node/utils/loadPlugins.js +21 -0
  74. package/dist/types/builder/builder-webpack/createCopyPattern.d.ts +2 -2
  75. package/dist/types/commands/index.d.ts +10 -3
  76. package/dist/types/config/initialize/inits.d.ts +1 -1
  77. package/dist/types/exports/server.d.ts +4 -0
  78. package/dist/types/index.d.ts +2 -5
  79. package/dist/types/plugins/analyze/constants.d.ts +9 -0
  80. package/dist/types/{analyze → plugins/analyze}/generateCode.d.ts +1 -1
  81. package/dist/types/plugins/analyze/getBundleEntry.d.ts +4 -0
  82. package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +5 -0
  83. package/dist/types/{analyze → plugins/analyze}/getHtmlTemplate.d.ts +1 -1
  84. package/dist/types/{analyze → plugins/analyze}/getServerRoutes.d.ts +1 -1
  85. package/dist/types/{analyze → plugins/analyze}/index.d.ts +1 -1
  86. package/dist/types/plugins/analyze/templates.d.ts +19 -0
  87. package/dist/types/{analyze → plugins/analyze}/utils.d.ts +4 -6
  88. package/dist/types/{initialize → plugins/initialize}/index.d.ts +1 -1
  89. package/dist/types/types/hooks.d.ts +11 -1
  90. package/dist/types/utils/loadPlugins.d.ts +5 -0
  91. package/package.json +22 -22
  92. package/dist/cjs/analyze/constants.js +0 -122
  93. package/dist/cjs/analyze/getClientRoutes/getRoutes.js +0 -197
  94. package/dist/cjs/analyze/getClientRoutes/getRoutesLegacy.js +0 -195
  95. package/dist/cjs/analyze/getClientRoutes/index.js +0 -31
  96. package/dist/cjs/analyze/getClientRoutes/utils.js +0 -59
  97. package/dist/cjs/analyze/makeLegalIdentifier.js +0 -37
  98. package/dist/cjs/analyze/nestedRoutes.js +0 -295
  99. package/dist/cjs/analyze/templates.js +0 -444
  100. package/dist/esm/analyze/constants.js +0 -76
  101. package/dist/esm/analyze/getBundleEntry.js +0 -75
  102. package/dist/esm/analyze/getClientRoutes/getRoutes.js +0 -185
  103. package/dist/esm/analyze/getClientRoutes/getRoutesLegacy.js +0 -183
  104. package/dist/esm/analyze/getClientRoutes/index.js +0 -6
  105. package/dist/esm/analyze/getClientRoutes/utils.js +0 -28
  106. package/dist/esm/analyze/getFileSystemEntry.js +0 -113
  107. package/dist/esm/analyze/makeLegalIdentifier.js +0 -15
  108. package/dist/esm/analyze/nestedRoutes.js +0 -398
  109. package/dist/esm/analyze/templates.js +0 -435
  110. package/dist/esm/utils/getServerInternalPlugins.js +0 -40
  111. package/dist/esm-node/analyze/constants.js +0 -76
  112. package/dist/esm-node/analyze/getClientRoutes/getRoutes.js +0 -163
  113. package/dist/esm-node/analyze/getClientRoutes/getRoutesLegacy.js +0 -161
  114. package/dist/esm-node/analyze/getClientRoutes/index.js +0 -6
  115. package/dist/esm-node/analyze/getClientRoutes/utils.js +0 -22
  116. package/dist/esm-node/analyze/getFileSystemEntry.js +0 -89
  117. package/dist/esm-node/analyze/makeLegalIdentifier.js +0 -13
  118. package/dist/esm-node/analyze/nestedRoutes.js +0 -259
  119. package/dist/esm-node/analyze/templates.js +0 -405
  120. package/dist/esm-node/utils/getServerInternalPlugins.js +0 -15
  121. package/dist/types/analyze/constants.d.ts +0 -42
  122. package/dist/types/analyze/getBundleEntry.d.ts +0 -3
  123. package/dist/types/analyze/getClientRoutes/getRoutes.d.ts +0 -8
  124. package/dist/types/analyze/getClientRoutes/getRoutesLegacy.d.ts +0 -9
  125. package/dist/types/analyze/getClientRoutes/index.d.ts +0 -2
  126. package/dist/types/analyze/getClientRoutes/utils.d.ts +0 -5
  127. package/dist/types/analyze/getFileSystemEntry.d.ts +0 -4
  128. package/dist/types/analyze/makeLegalIdentifier.d.ts +0 -1
  129. package/dist/types/analyze/nestedRoutes.d.ts +0 -7
  130. package/dist/types/analyze/templates.d.ts +0 -30
  131. package/dist/types/utils/getServerInternalPlugins.d.ts +0 -2
  132. /package/dist/cjs/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
  133. /package/dist/cjs/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
  134. /package/dist/esm/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
  135. /package/dist/esm/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
  136. /package/dist/esm-node/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
  137. /package/dist/esm-node/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
  138. /package/dist/types/{analyze → plugins/analyze}/isDefaultExportFunction.d.ts +0 -0
@@ -1,5 +1,5 @@
1
1
  import type { AsyncWaterfall, AsyncWorkflow, ParallelWorkflow } from '@modern-js/plugin';
2
- import type { Entrypoint, HtmlPartials, NestedRouteForCli, PageRoute, RouteLegacy, ServerRoute } from '@modern-js/types';
2
+ import type { Entrypoint, HtmlPartials, NestedRouteForCli, PageRoute, RouteLegacy, ServerPlugin, ServerRoute } from '@modern-js/types';
3
3
  import type { RegisterBuildPlatformResult, DevToolData } from '@modern-js/core';
4
4
  import type { Stats, MultiStats } from '@rsbuild/shared';
5
5
  import type { Rspack, webpack } from '@modern-js/uni-builder';
@@ -47,6 +47,13 @@ export type AppToolsHooks<B extends Bundler = 'webpack'> = {
47
47
  modifyServerRoutes: AsyncWaterfall<{
48
48
  routes: ServerRoute[];
49
49
  }>;
50
+ modifyEntrypoints: AsyncWaterfall<{
51
+ entrypoints: Entrypoint[];
52
+ }>;
53
+ checkEntryPoint: AsyncWaterfall<{
54
+ path: string;
55
+ entry: false | string;
56
+ }>;
50
57
  htmlPartials: AsyncWaterfall<{
51
58
  entrypoint: Entrypoint;
52
59
  partials: HtmlPartials;
@@ -59,6 +66,9 @@ export type AppToolsHooks<B extends Bundler = 'webpack'> = {
59
66
  collectServerPlugins: AsyncWaterfall<{
60
67
  plugins: Array<Record<string, string>>;
61
68
  }>;
69
+ _internalServerPlugins: AsyncWaterfall<{
70
+ plugins: ServerPlugin[];
71
+ }>;
62
72
  beforeDev: AsyncWorkflow<void, unknown>;
63
73
  afterDev: AsyncWorkflow<{
64
74
  isFirstCompile: boolean;
@@ -0,0 +1,5 @@
1
+ import { ServerPlugin as ServerPluginInstance } from '@modern-js/server-core';
2
+ import { ServerPlugin } from '@modern-js/types';
3
+ import { AppTools, PluginAPI } from '../types';
4
+ export declare function getServerPlugins(api: PluginAPI<AppTools<'shared'>>): Promise<ServerPlugin[]>;
5
+ export declare function loadServerPlugins(api: PluginAPI<AppTools<'shared'>>, appDirectory: string): Promise<ServerPluginInstance[]>;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.53.1-alpha.4",
18
+ "version": "2.54.1-alpha.0",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -77,9 +77,9 @@
77
77
  "@babel/parser": "^7.22.15",
78
78
  "@babel/traverse": "^7.23.2",
79
79
  "@babel/types": "^7.23.0",
80
- "@rsbuild/plugin-node-polyfill": "0.7.3",
81
- "@rsbuild/shared": "0.7.3",
82
- "@rsbuild/core": "0.7.3",
80
+ "@rsbuild/plugin-node-polyfill": "0.7.9",
81
+ "@rsbuild/shared": "0.7.9",
82
+ "@rsbuild/core": "0.7.9",
83
83
  "@swc/helpers": "0.5.3",
84
84
  "@vercel/nft": "^0.26.4",
85
85
  "es-module-lexer": "^1.1.0",
@@ -88,23 +88,23 @@
88
88
  "mlly": "^1.6.1",
89
89
  "pkg-types": "^1.1.0",
90
90
  "std-env": "^3.7.0",
91
- "@modern-js/plugin-data-loader": "2.53.0",
92
- "@modern-js/core": "2.53.0",
93
- "@modern-js/node-bundle-require": "2.53.0",
94
- "@modern-js/prod-server": "2.53.0",
95
- "@modern-js/plugin-i18n": "2.53.0",
96
- "@modern-js/plugin": "2.53.0",
97
- "@modern-js/server-core": "2.53.0",
98
- "@modern-js/types": "2.53.0",
99
- "@modern-js/rsbuild-plugin-esbuild": "2.53.0",
100
- "@modern-js/utils": "2.53.0",
101
- "@modern-js/server": "2.53.0",
102
- "@modern-js/server-utils": "2.53.0",
103
- "@modern-js/uni-builder": "2.53.0",
104
- "@modern-js/plugin-lint": "2.53.0"
91
+ "@modern-js/core": "2.54.0",
92
+ "@modern-js/plugin": "2.54.0",
93
+ "@modern-js/node-bundle-require": "2.54.0",
94
+ "@modern-js/plugin-i18n": "2.54.0",
95
+ "@modern-js/prod-server": "2.54.0",
96
+ "@modern-js/plugin-lint": "2.54.0",
97
+ "@modern-js/rsbuild-plugin-esbuild": "2.54.0",
98
+ "@modern-js/server": "2.54.0",
99
+ "@modern-js/server-core": "2.54.0",
100
+ "@modern-js/server-utils": "2.54.0",
101
+ "@modern-js/plugin-data-loader": "2.54.0",
102
+ "@modern-js/types": "2.54.0",
103
+ "@modern-js/uni-builder": "2.54.0",
104
+ "@modern-js/utils": "2.54.0"
105
105
  },
106
106
  "devDependencies": {
107
- "@rsbuild/plugin-swc": "0.7.3",
107
+ "@rsbuild/plugin-swc": "0.7.9",
108
108
  "@types/babel__traverse": "7.18.5",
109
109
  "@types/jest": "^29",
110
110
  "@types/node": "^14",
@@ -112,9 +112,9 @@
112
112
  "ts-node": "^10.9.1",
113
113
  "tsconfig-paths": "^4.2.0",
114
114
  "typescript": "^5",
115
- "webpack": "^5.91.0",
116
- "@scripts/build": "2.53.0",
117
- "@scripts/jest-config": "2.53.0"
115
+ "webpack": "^5.92.0",
116
+ "@scripts/build": "2.54.0",
117
+ "@scripts/jest-config": "2.54.0"
118
118
  },
119
119
  "sideEffects": false,
120
120
  "publishConfig": {
@@ -1,122 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var constants_exports = {};
20
- __export(constants_exports, {
21
- ACTION_EXPORT_NAME: () => ACTION_EXPORT_NAME,
22
- APP_CONFIG_NAME: () => APP_CONFIG_NAME,
23
- APP_FILE_NAME: () => APP_FILE_NAME,
24
- APP_INIT_EXPORTED: () => APP_INIT_EXPORTED,
25
- APP_INIT_IMPORTED: () => APP_INIT_IMPORTED,
26
- ENTRY_BOOTSTRAP_FILE_NAME: () => ENTRY_BOOTSTRAP_FILE_NAME,
27
- ENTRY_POINT_FILE_NAME: () => ENTRY_POINT_FILE_NAME,
28
- FILE_SYSTEM_ROUTES_COMPONENTS_DIR: () => FILE_SYSTEM_ROUTES_COMPONENTS_DIR,
29
- FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP: () => FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP,
30
- FILE_SYSTEM_ROUTES_FILE_NAME: () => FILE_SYSTEM_ROUTES_FILE_NAME,
31
- FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT: () => FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT,
32
- FILE_SYSTEM_ROUTES_IGNORED_REGEX: () => FILE_SYSTEM_ROUTES_IGNORED_REGEX,
33
- FILE_SYSTEM_ROUTES_INDEX: () => FILE_SYSTEM_ROUTES_INDEX,
34
- FILE_SYSTEM_ROUTES_LAYOUT: () => FILE_SYSTEM_ROUTES_LAYOUT,
35
- HTML_PARTIALS_EXTENSIONS: () => HTML_PARTIALS_EXTENSIONS,
36
- HTML_PARTIALS_FOLDER: () => HTML_PARTIALS_FOLDER,
37
- INDEX_FILE_NAME: () => INDEX_FILE_NAME,
38
- JS_EXTENSIONS: () => JS_EXTENSIONS,
39
- LOADER_EXPORT_NAME: () => LOADER_EXPORT_NAME,
40
- NESTED_ROUTE: () => NESTED_ROUTE,
41
- NESTED_ROUTES_DIR: () => NESTED_ROUTES_DIR,
42
- PAGES_DIR_NAME: () => PAGES_DIR_NAME,
43
- TEMP_LOADERS_DIR: () => TEMP_LOADERS_DIR
44
- });
45
- module.exports = __toCommonJS(constants_exports);
46
- const JS_EXTENSIONS = [
47
- ".js",
48
- ".ts",
49
- ".jsx",
50
- ".tsx"
51
- ];
52
- const INDEX_FILE_NAME = "index";
53
- const APP_FILE_NAME = "App";
54
- const PAGES_DIR_NAME = "pages";
55
- const NESTED_ROUTES_DIR = "routes";
56
- const FILE_SYSTEM_ROUTES_FILE_NAME = "routes.js";
57
- const LOADER_EXPORT_NAME = "loader";
58
- const ACTION_EXPORT_NAME = "action";
59
- const TEMP_LOADERS_DIR = "__loaders__";
60
- const ENTRY_POINT_FILE_NAME = "index.jsx";
61
- const ENTRY_BOOTSTRAP_FILE_NAME = "bootstrap.jsx";
62
- const FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP = /^\[(\S+)\]([*+?]?)$/;
63
- const FILE_SYSTEM_ROUTES_LAYOUT = "_layout";
64
- const FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT = "_app";
65
- const FILE_SYSTEM_ROUTES_INDEX = "index";
66
- const FILE_SYSTEM_ROUTES_IGNORED_REGEX = /\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/;
67
- const HTML_PARTIALS_FOLDER = "html";
68
- const HTML_PARTIALS_EXTENSIONS = [
69
- ".htm",
70
- ".html",
71
- ".ejs"
72
- ];
73
- const FILE_SYSTEM_ROUTES_COMPONENTS_DIR = "internal_components";
74
- const NESTED_ROUTE = {
75
- LAYOUT_FILE: "layout",
76
- LAYOUT_CONFIG_FILE: "layout.config",
77
- LAYOUT_LOADER_FILE: "layout.loader",
78
- LAYOUT_DATA_FILE: "layout.data",
79
- LAYOUT_CLIENT_LOADER: "layout.data.client",
80
- PAGE_FILE: "page",
81
- PAGE_CONFIG_FILE: "page.config",
82
- PAGE_LOADER_FILE: "page.loader",
83
- PAGE_DATA_FILE: "page.data",
84
- PAGE_CLIENT_LOADER: "page.data.client",
85
- SPLATE_FILE: "$",
86
- SPLATE_CONFIG_FILE: "$.config",
87
- SPLATE_LOADER_FILE: "$.loader",
88
- SPLATE_DATA_FILE: "$.data",
89
- SPLATE_CLIENT_DATA: "$.data.client",
90
- LOADING_FILE: "loading",
91
- ERROR_FILE: "error",
92
- LOADER_FILE: "loader"
93
- };
94
- const APP_CONFIG_NAME = "config";
95
- const APP_INIT_EXPORTED = "init";
96
- const APP_INIT_IMPORTED = "appInit";
97
- // Annotate the CommonJS export names for ESM import in node:
98
- 0 && (module.exports = {
99
- ACTION_EXPORT_NAME,
100
- APP_CONFIG_NAME,
101
- APP_FILE_NAME,
102
- APP_INIT_EXPORTED,
103
- APP_INIT_IMPORTED,
104
- ENTRY_BOOTSTRAP_FILE_NAME,
105
- ENTRY_POINT_FILE_NAME,
106
- FILE_SYSTEM_ROUTES_COMPONENTS_DIR,
107
- FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP,
108
- FILE_SYSTEM_ROUTES_FILE_NAME,
109
- FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT,
110
- FILE_SYSTEM_ROUTES_IGNORED_REGEX,
111
- FILE_SYSTEM_ROUTES_INDEX,
112
- FILE_SYSTEM_ROUTES_LAYOUT,
113
- HTML_PARTIALS_EXTENSIONS,
114
- HTML_PARTIALS_FOLDER,
115
- INDEX_FILE_NAME,
116
- JS_EXTENSIONS,
117
- LOADER_EXPORT_NAME,
118
- NESTED_ROUTE,
119
- NESTED_ROUTES_DIR,
120
- PAGES_DIR_NAME,
121
- TEMP_LOADERS_DIR
122
- });
@@ -1,197 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var getRoutes_exports = {};
30
- __export(getRoutes_exports, {
31
- getClientRoutes: () => getClientRoutes
32
- });
33
- module.exports = __toCommonJS(getRoutes_exports);
34
- var import_path = __toESM(require("path"));
35
- var import_utils = require("@modern-js/utils");
36
- var import_makeLegalIdentifier = require("../makeLegalIdentifier");
37
- var import_constants = require("../constants");
38
- var import_utils2 = require("../utils");
39
- var import_utils3 = require("./utils");
40
- const compName = (srcDirectory, filePath) => {
41
- const legalCompName = (0, import_makeLegalIdentifier.makeLegalIdentifier)(import_path.default.relative(srcDirectory, filePath));
42
- return `Comp_${legalCompName}`;
43
- };
44
- const layoutNameAbbr = (filePath) => {
45
- const prefix = "L_";
46
- const dirName = import_path.default.dirname(filePath).split("/").pop() || "";
47
- return `${prefix}${(0, import_makeLegalIdentifier.makeLegalIdentifier)(dirName)}`;
48
- };
49
- const parents = [];
50
- const recursiveReadDir = ({ dir, routes, basePath = "/", srcDirectory, srcAlias }) => {
51
- let hasDynamicRoute = false;
52
- let resetParent = false;
53
- let parent = parents[parents.length - 1];
54
- const layout = (0, import_utils3.findLayout)(dir);
55
- if (layout) {
56
- if (basePath === "/") {
57
- throw new Error(`should use _app instead of _layout in ${dir}`);
58
- } else {
59
- const alias = (0, import_utils2.replaceWithAlias)(srcDirectory, layout, srcAlias);
60
- const componentName = compName(srcDirectory, layout);
61
- const route = {
62
- path: `${basePath.substring(0, basePath.length - 1)}`,
63
- children: [],
64
- _component: alias,
65
- component: componentName,
66
- parent,
67
- type: "page"
68
- };
69
- parent = route;
70
- resetParent = true;
71
- routes.push(route);
72
- parents.push(route);
73
- routes = route.children;
74
- }
75
- }
76
- for (const relative of import_utils.fs.readdirSync(dir)) {
77
- const filePath = import_path.default.join(dir, relative);
78
- if (!(0, import_utils3.shouldSkip)(filePath)) {
79
- const filename = import_path.default.basename(filePath, import_path.default.extname(filePath));
80
- const alias = (0, import_utils2.replaceWithAlias)(srcDirectory, filePath, srcAlias);
81
- const componentName = compName(srcDirectory, filePath);
82
- const dynamicRouteMatched = import_constants.FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP.exec(filename);
83
- if (dynamicRouteMatched) {
84
- if (hasDynamicRoute) {
85
- throw new Error(`Can't set two dynamic route in one directory: ${dir}`);
86
- } else {
87
- hasDynamicRoute = true;
88
- }
89
- }
90
- const route = {
91
- path: `${basePath}${dynamicRouteMatched ? `:${dynamicRouteMatched[1].replace(/\$$/, "?")}${dynamicRouteMatched[2]}` : filename}`,
92
- _component: alias,
93
- component: componentName,
94
- parent,
95
- type: "page"
96
- };
97
- if (import_utils.fs.statSync(filePath).isDirectory()) {
98
- recursiveReadDir({
99
- dir: filePath,
100
- routes,
101
- basePath: `${route.path}/`,
102
- srcDirectory,
103
- srcAlias
104
- });
105
- continue;
106
- }
107
- if (filename === import_constants.FILE_SYSTEM_ROUTES_LAYOUT) {
108
- continue;
109
- }
110
- if (filename === import_constants.FILE_SYSTEM_ROUTES_INDEX) {
111
- route.path = basePath === "/" ? basePath : `${basePath.substring(0, basePath.length - 1)}`;
112
- }
113
- if (filename === "404" && basePath === "/") {
114
- route.path = "*";
115
- }
116
- routes.push(route);
117
- }
118
- }
119
- if (resetParent) {
120
- parents.pop();
121
- }
122
- };
123
- const normalizeNestedRoutes = (nested, internalComponentsDir, internalDirectory, internalDirAlias) => {
124
- const flat = (routes) => routes.reduce((memo, route) => memo.concat(Array.isArray(route.children) ? flat(route.children) : [
125
- route
126
- ]), []);
127
- const generate = (route) => {
128
- const codes = [];
129
- let lastComponent = route.component;
130
- const imports = [
131
- `import React from 'react';`,
132
- `import ${lastComponent} from '${route._component}'`
133
- ];
134
- while (route = route.parent) {
135
- const layoutComponent = route.component;
136
- const layoutComponentAbbr = layoutNameAbbr(route._component);
137
- imports.push(`import ${layoutComponent} from '${route._component}';`);
138
- const currentComponent = `${layoutComponentAbbr}_${lastComponent}`;
139
- codes.push(`const ${currentComponent} = props => <${layoutComponent} Component={${lastComponent}} {...props} />;`);
140
- lastComponent = currentComponent;
141
- }
142
- const file = import_path.default.resolve(internalComponentsDir, `${lastComponent}.jsx`);
143
- import_utils.fs.outputFileSync(file, `${imports.join("\n")}
144
- ${codes.join("\n")}
145
- export default ${lastComponent}`);
146
- return {
147
- component: lastComponent,
148
- _component: (0, import_utils2.replaceWithAlias)(internalDirectory, file, internalDirAlias)
149
- };
150
- };
151
- const normalized = flat(nested).map((route) => route.parent ? {
152
- ...route,
153
- ...generate(route),
154
- parent: void 0
155
- } : {
156
- ...route,
157
- parent: void 0
158
- });
159
- return normalized;
160
- };
161
- const getClientRoutes = ({ entrypoint, srcDirectory, srcAlias, internalDirectory, internalDirAlias }) => {
162
- const { entryName, pageRoutesEntry } = entrypoint;
163
- if (!pageRoutesEntry) {
164
- return [];
165
- }
166
- if (!import_utils.fs.existsSync(pageRoutesEntry)) {
167
- throw new Error(`generate file system routes error, ${pageRoutesEntry} directory not found.`);
168
- }
169
- if (!(import_utils.fs.existsSync(pageRoutesEntry) && import_utils.fs.statSync(pageRoutesEntry).isDirectory())) {
170
- throw new Error(`generate file system routes error, ${pageRoutesEntry} should be directory.`);
171
- }
172
- let routes = [];
173
- recursiveReadDir({
174
- dir: pageRoutesEntry,
175
- routes,
176
- basePath: "/",
177
- srcDirectory,
178
- srcAlias
179
- });
180
- const internalComponentsDir = import_path.default.resolve(internalDirectory, `${entryName}/${import_constants.FILE_SYSTEM_ROUTES_COMPONENTS_DIR}`);
181
- import_utils.fs.emptyDirSync(internalComponentsDir);
182
- routes = normalizeNestedRoutes(routes, internalComponentsDir, internalDirectory, internalDirAlias);
183
- parents.length = 0;
184
- routes.sort((a, b) => {
185
- const delta = (0, import_utils3.getRouteWeight)(a.path) - (0, import_utils3.getRouteWeight)(b.path);
186
- if (delta === 0) {
187
- return a.path.length - b.path.length;
188
- }
189
- return delta;
190
- });
191
- (0, import_utils3.debug)(`fileSystem routes: %o`, routes);
192
- return routes;
193
- };
194
- // Annotate the CommonJS export names for ESM import in node:
195
- 0 && (module.exports = {
196
- getClientRoutes
197
- });
@@ -1,195 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var getRoutesLegacy_exports = {};
30
- __export(getRoutesLegacy_exports, {
31
- getClientRoutes: () => getClientRoutes
32
- });
33
- module.exports = __toCommonJS(getRoutesLegacy_exports);
34
- var import_path = __toESM(require("path"));
35
- var import_utils = require("@modern-js/utils");
36
- var import_makeLegalIdentifier = require("../makeLegalIdentifier");
37
- var import_constants = require("../constants");
38
- var import_utils2 = require("../utils");
39
- var import_utils3 = require("./utils");
40
- const compName = (srcDirectory, filePath) => {
41
- const legalCompName = (0, import_makeLegalIdentifier.makeLegalIdentifier)(import_path.default.relative(srcDirectory, filePath));
42
- return `Comp_${legalCompName}`;
43
- };
44
- const layoutNameAbbr = (filePath) => {
45
- const prefix = "L_";
46
- const dirName = import_path.default.dirname(filePath).split("/").pop() || "";
47
- return `${prefix}${(0, import_makeLegalIdentifier.makeLegalIdentifier)(dirName)}`;
48
- };
49
- const parents = [];
50
- const recursiveReadDirLegacy = ({ dir, routes, basePath = "/", srcDirectory, srcAlias }) => {
51
- let hasDynamicRoute = false;
52
- let resetParent = false;
53
- let parent = parents[parents.length - 1];
54
- const layout = (0, import_utils3.findLayout)(dir);
55
- if (layout) {
56
- if (basePath === "/") {
57
- throw new Error(`should use _app instead of _layout in ${dir}`);
58
- } else {
59
- const alias = (0, import_utils2.replaceWithAlias)(srcDirectory, layout, srcAlias);
60
- const componentName = compName(srcDirectory, layout);
61
- const route = {
62
- path: `${basePath.substring(0, basePath.length - 1)}`,
63
- exact: false,
64
- routes: [],
65
- _component: alias,
66
- component: componentName,
67
- parent
68
- };
69
- parent = route;
70
- resetParent = true;
71
- routes.push(route);
72
- parents.push(route);
73
- routes = route.routes;
74
- }
75
- }
76
- for (const relative of import_utils.fs.readdirSync(dir)) {
77
- const filePath = import_path.default.join(dir, relative);
78
- if (!(0, import_utils3.shouldSkip)(filePath)) {
79
- const filename = import_path.default.basename(filePath, import_path.default.extname(filePath));
80
- const alias = (0, import_utils2.replaceWithAlias)(srcDirectory, filePath, srcAlias);
81
- const componentName = compName(srcDirectory, filePath);
82
- const dynamicRouteMatched = import_constants.FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP.exec(filename);
83
- if (dynamicRouteMatched) {
84
- if (hasDynamicRoute) {
85
- throw new Error(`Can't set two dynamic route in one directory: ${dir}`);
86
- } else {
87
- hasDynamicRoute = true;
88
- }
89
- }
90
- const route = {
91
- path: `${basePath}${dynamicRouteMatched ? `:${dynamicRouteMatched[1].replace(/\$$/, "?")}${dynamicRouteMatched[2]}` : filename}`,
92
- _component: alias,
93
- component: componentName,
94
- exact: true,
95
- parent
96
- };
97
- if (import_utils.fs.statSync(filePath).isDirectory()) {
98
- recursiveReadDirLegacy({
99
- dir: filePath,
100
- routes,
101
- basePath: `${route.path}/`,
102
- srcDirectory,
103
- srcAlias
104
- });
105
- continue;
106
- }
107
- if (filename === import_constants.FILE_SYSTEM_ROUTES_LAYOUT) {
108
- continue;
109
- }
110
- if (filename === import_constants.FILE_SYSTEM_ROUTES_INDEX) {
111
- route.path = basePath === "/" ? basePath : `${basePath.substring(0, basePath.length - 1)}`;
112
- }
113
- if (filename === "404" && basePath === "/") {
114
- route.path = "*";
115
- route.exact = false;
116
- }
117
- routes.push(route);
118
- }
119
- }
120
- if (resetParent) {
121
- parents.pop();
122
- }
123
- };
124
- const normalizeNestedRoutes = (nested, internalComponentsDir, internalDirectory, internalDirAlias) => {
125
- const flat = (routes) => routes.reduce((memo, route) => memo.concat(Array.isArray(route.routes) ? flat(route.routes) : [
126
- route
127
- ]), []);
128
- const generate = (route) => {
129
- const codes = [];
130
- let lastComponent = route.component;
131
- const imports = [
132
- `import React from 'react';`,
133
- `import ${lastComponent} from '${route._component}'`
134
- ];
135
- while (route = route.parent) {
136
- const layoutComponent = route.component;
137
- const layoutComponentAbbr = layoutNameAbbr(route._component);
138
- imports.push(`import ${layoutComponent} from '${route._component}';`);
139
- const currentComponent = `${layoutComponentAbbr}_${lastComponent}`;
140
- codes.push(`const ${currentComponent} = props => <${layoutComponent} Component={${lastComponent}} {...props} />;`);
141
- lastComponent = currentComponent;
142
- }
143
- const file = import_path.default.resolve(internalComponentsDir, `${lastComponent}.jsx`);
144
- import_utils.fs.outputFileSync(file, `${imports.join("\n")}
145
- ${codes.join("\n")}
146
- export default ${lastComponent}`);
147
- return {
148
- component: lastComponent,
149
- _component: (0, import_utils2.replaceWithAlias)(internalDirectory, file, internalDirAlias)
150
- };
151
- };
152
- const normalized = flat(nested).map((route) => route.parent ? {
153
- ...route,
154
- ...generate(route),
155
- parent: void 0
156
- } : {
157
- ...route,
158
- parent: void 0
159
- });
160
- return normalized;
161
- };
162
- const getClientRoutes = ({ entrypoint, srcDirectory, srcAlias, internalDirectory, internalDirAlias }) => {
163
- const { entry, entryName } = entrypoint;
164
- if (!import_utils.fs.existsSync(entry)) {
165
- throw new Error(`generate file system routes error, ${entry} directory not found.`);
166
- }
167
- if (!(import_utils.fs.existsSync(entry) && import_utils.fs.statSync(entry).isDirectory())) {
168
- throw new Error(`generate file system routes error, ${entry} should be directory.`);
169
- }
170
- let routes = [];
171
- recursiveReadDirLegacy({
172
- dir: entry,
173
- routes,
174
- basePath: "/",
175
- srcDirectory,
176
- srcAlias
177
- });
178
- const internalComponentsDir = import_path.default.resolve(internalDirectory, `${entryName}/${import_constants.FILE_SYSTEM_ROUTES_COMPONENTS_DIR}`);
179
- import_utils.fs.emptyDirSync(internalComponentsDir);
180
- routes = normalizeNestedRoutes(routes, internalComponentsDir, internalDirectory, internalDirAlias);
181
- parents.length = 0;
182
- routes.sort((a, b) => {
183
- const delta = (0, import_utils3.getRouteWeight)(a.path) - (0, import_utils3.getRouteWeight)(b.path);
184
- if (delta === 0) {
185
- return a.path.length - b.path.length;
186
- }
187
- return delta;
188
- });
189
- (0, import_utils3.debug)(`fileSystem routes: %o`, routes);
190
- return routes;
191
- };
192
- // Annotate the CommonJS export names for ESM import in node:
193
- 0 && (module.exports = {
194
- getClientRoutes
195
- });
@@ -1,31 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var getClientRoutes_exports = {};
20
- __export(getClientRoutes_exports, {
21
- getClientRoutes: () => import_getRoutes.getClientRoutes,
22
- getClientRoutesLegacy: () => import_getRoutesLegacy.getClientRoutes
23
- });
24
- module.exports = __toCommonJS(getClientRoutes_exports);
25
- var import_getRoutes = require("./getRoutes");
26
- var import_getRoutesLegacy = require("./getRoutesLegacy");
27
- // Annotate the CommonJS export names for ESM import in node:
28
- 0 && (module.exports = {
29
- getClientRoutes,
30
- getClientRoutesLegacy
31
- });