@modern-js/app-tools 2.4.0 → 2.5.0-alpha.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.
- package/CHANGELOG.md +59 -0
- package/dist/cjs/analyze/constants.js +100 -0
- package/dist/cjs/analyze/generateCode.js +251 -0
- package/dist/cjs/analyze/getBundleEntry.js +101 -0
- package/dist/cjs/analyze/getClientRoutes/getRoutes.js +225 -0
- package/dist/cjs/analyze/getClientRoutes/getRoutesLegacy.js +221 -0
- package/dist/cjs/analyze/getClientRoutes/index.js +30 -0
- package/dist/cjs/analyze/getClientRoutes/utils.js +58 -0
- package/dist/cjs/analyze/getFileSystemEntry.js +131 -0
- package/dist/cjs/analyze/getHtmlTemplate.js +124 -0
- package/dist/cjs/analyze/getServerRoutes.js +174 -0
- package/dist/cjs/analyze/index.js +294 -0
- package/dist/cjs/analyze/isDefaultExportFunction.js +71 -0
- package/dist/cjs/analyze/makeLegalIdentifier.js +36 -0
- package/dist/cjs/analyze/nestedRoutes.js +179 -0
- package/dist/cjs/analyze/templates.js +330 -0
- package/dist/cjs/analyze/utils.js +152 -0
- package/dist/cjs/builder/builder-rspack/index.js +31 -0
- package/dist/cjs/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
- package/dist/cjs/builder/builder-webpack/index.js +78 -0
- package/dist/cjs/builder/builder-webpack/webpackPlugins/RouterPlugin.js +120 -0
- package/dist/cjs/builder/builder-webpack/webpackPlugins/index.js +17 -0
- package/dist/cjs/builder/generator/createBuilderOptions.js +47 -0
- package/dist/cjs/builder/generator/createBuilderProviderConfig.js +49 -0
- package/dist/cjs/builder/generator/getBuilderTargets.js +39 -0
- package/dist/cjs/builder/generator/index.js +58 -0
- package/dist/cjs/builder/index.js +46 -0
- package/dist/cjs/builder/shared/builderPlugins/adapterModern.js +230 -0
- package/dist/cjs/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +50 -0
- package/dist/cjs/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +57 -0
- package/dist/cjs/builder/shared/createCopyPattern.js +75 -0
- package/dist/cjs/builder/shared/index.js +19 -0
- package/dist/cjs/builder/shared/loaders/serverModuleLoader.js +28 -0
- package/dist/cjs/builder/shared/types.js +15 -0
- package/dist/cjs/commands/build.js +75 -0
- package/dist/cjs/commands/deploy.js +31 -0
- package/dist/cjs/commands/dev.js +91 -0
- package/dist/cjs/commands/index.js +19 -0
- package/dist/cjs/commands/inspect.js +41 -0
- package/dist/cjs/commands/serve.js +63 -0
- package/dist/cjs/config/default.js +186 -0
- package/dist/cjs/config/index.js +19 -0
- package/dist/cjs/config/initialize/index.js +35 -0
- package/dist/cjs/config/initialize/inits.js +161 -0
- package/dist/cjs/config/legacy/createHtmlConfig.js +58 -0
- package/dist/cjs/config/legacy/createOutputConfig.js +91 -0
- package/dist/cjs/config/legacy/createSourceConfig.js +62 -0
- package/dist/cjs/config/legacy/createToolsConfig.js +65 -0
- package/dist/cjs/config/legacy/index.js +75 -0
- package/dist/cjs/defineConfig.js +33 -0
- package/dist/cjs/exports/server.js +27 -0
- package/dist/cjs/hooks.js +54 -0
- package/dist/cjs/index.js +198 -0
- package/dist/cjs/initialize/index.js +102 -0
- package/dist/cjs/locale/en.js +59 -0
- package/dist/cjs/locale/index.js +33 -0
- package/dist/cjs/locale/zh.js +59 -0
- package/dist/cjs/schema/Schema.js +63 -0
- package/dist/cjs/schema/index.js +118 -0
- package/dist/cjs/schema/legacy.js +169 -0
- package/dist/cjs/types/config/deploy.js +15 -0
- package/dist/cjs/types/config/dev.js +15 -0
- package/dist/cjs/types/config/experiments.js +15 -0
- package/dist/cjs/types/config/html.js +15 -0
- package/dist/cjs/types/config/index.js +17 -0
- package/dist/cjs/types/config/output.js +15 -0
- package/dist/cjs/types/config/performance.js +15 -0
- package/dist/cjs/types/config/security.js +15 -0
- package/dist/cjs/types/config/source.js +15 -0
- package/dist/cjs/types/config/tools.js +15 -0
- package/dist/cjs/types/hooks.js +15 -0
- package/dist/cjs/types/index.js +19 -0
- package/dist/cjs/types/legacyConfig/deploy.js +15 -0
- package/dist/cjs/types/legacyConfig/dev.js +15 -0
- package/dist/cjs/types/legacyConfig/index.js +15 -0
- package/dist/cjs/types/legacyConfig/output.js +15 -0
- package/dist/cjs/types/legacyConfig/source.js +15 -0
- package/dist/cjs/types/legacyConfig/tools.js +15 -0
- package/dist/cjs/types/utils.js +15 -0
- package/dist/cjs/utils/config.js +115 -0
- package/dist/cjs/utils/createServer.js +70 -0
- package/dist/cjs/utils/env.js +38 -0
- package/dist/cjs/utils/generateWatchFiles.js +63 -0
- package/dist/cjs/utils/getSelectedEntries.js +61 -0
- package/dist/cjs/utils/getServerInternalPlugins.js +41 -0
- package/dist/cjs/utils/language.js +31 -0
- package/dist/cjs/utils/printInstructions.js +34 -0
- package/dist/cjs/utils/restart.js +45 -0
- package/dist/cjs/utils/routes.js +39 -0
- package/dist/cjs/utils/types.js +15 -0
- package/dist/esm/analyze/constants.js +42 -0
- package/dist/esm/analyze/generateCode.js +486 -0
- package/dist/esm/analyze/getBundleEntry.js +64 -0
- package/dist/esm/analyze/getClientRoutes/getRoutes.js +233 -0
- package/dist/esm/analyze/getClientRoutes/getRoutesLegacy.js +231 -0
- package/dist/esm/analyze/getClientRoutes/index.js +3 -0
- package/dist/esm/analyze/getClientRoutes/utils.js +23 -0
- package/dist/esm/analyze/getFileSystemEntry.js +107 -0
- package/dist/esm/analyze/getHtmlTemplate.js +302 -0
- package/dist/esm/analyze/getServerRoutes.js +224 -0
- package/dist/esm/analyze/index.js +703 -0
- package/dist/esm/analyze/isDefaultExportFunction.js +47 -0
- package/dist/esm/analyze/makeLegalIdentifier.js +13 -0
- package/dist/esm/analyze/nestedRoutes.js +409 -0
- package/dist/esm/analyze/templates.js +466 -0
- package/dist/esm/analyze/utils.js +374 -0
- package/dist/esm/builder/builder-rspack/index.js +6 -0
- package/dist/esm/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
- package/dist/esm/builder/builder-webpack/index.js +301 -0
- package/dist/esm/builder/builder-webpack/webpackPlugins/RouterPlugin.js +346 -0
- package/dist/esm/builder/builder-webpack/webpackPlugins/index.js +1 -0
- package/dist/esm/builder/generator/createBuilderOptions.js +41 -0
- package/dist/esm/builder/generator/createBuilderProviderConfig.js +70 -0
- package/dist/esm/builder/generator/getBuilderTargets.js +16 -0
- package/dist/esm/builder/generator/index.js +199 -0
- package/dist/esm/builder/index.js +175 -0
- package/dist/esm/builder/shared/builderPlugins/adapterModern.js +300 -0
- package/dist/esm/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +110 -0
- package/dist/esm/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +72 -0
- package/dist/esm/builder/shared/createCopyPattern.js +40 -0
- package/dist/esm/builder/shared/index.js +3 -0
- package/dist/esm/builder/shared/loaders/serverModuleLoader.js +5 -0
- package/dist/esm/builder/shared/types.js +1 -0
- package/dist/esm/commands/build.js +291 -0
- package/dist/esm/commands/deploy.js +154 -0
- package/dist/esm/commands/dev.js +301 -0
- package/dist/esm/commands/index.js +3 -0
- package/dist/esm/commands/inspect.js +149 -0
- package/dist/esm/commands/serve.js +199 -0
- package/dist/esm/config/default.js +210 -0
- package/dist/esm/config/index.js +3 -0
- package/dist/esm/config/initialize/index.js +10 -0
- package/dist/esm/config/initialize/inits.js +211 -0
- package/dist/esm/config/legacy/createHtmlConfig.js +19 -0
- package/dist/esm/config/legacy/createOutputConfig.js +41 -0
- package/dist/esm/config/legacy/createSourceConfig.js +42 -0
- package/dist/esm/config/legacy/createToolsConfig.js +23 -0
- package/dist/esm/config/legacy/index.js +38 -0
- package/dist/esm/defineConfig.js +61 -0
- package/dist/esm/exports/server.js +2 -0
- package/dist/esm/hooks.js +29 -0
- package/dist/esm/index.js +713 -0
- package/dist/esm/initialize/index.js +284 -0
- package/dist/esm/locale/en.js +38 -0
- package/dist/esm/locale/index.js +9 -0
- package/dist/esm/locale/zh.js +38 -0
- package/dist/esm/schema/Schema.js +273 -0
- package/dist/esm/schema/index.js +181 -0
- package/dist/esm/schema/legacy.js +337 -0
- package/dist/esm/types/config/deploy.js +1 -0
- package/dist/esm/types/config/dev.js +1 -0
- package/dist/esm/types/config/experiments.js +1 -0
- package/dist/esm/types/config/html.js +1 -0
- package/dist/esm/types/config/index.js +1 -0
- package/dist/esm/types/config/output.js +1 -0
- package/dist/esm/types/config/performance.js +1 -0
- package/dist/esm/types/config/security.js +1 -0
- package/dist/esm/types/config/source.js +1 -0
- package/dist/esm/types/config/tools.js +1 -0
- package/dist/esm/types/hooks.js +1 -0
- package/dist/esm/types/index.js +3 -0
- package/dist/esm/types/legacyConfig/deploy.js +1 -0
- package/dist/esm/types/legacyConfig/dev.js +1 -0
- package/dist/esm/types/legacyConfig/index.js +1 -0
- package/dist/esm/types/legacyConfig/output.js +1 -0
- package/dist/esm/types/legacyConfig/source.js +1 -0
- package/dist/esm/types/legacyConfig/tools.js +1 -0
- package/dist/esm/types/utils.js +1 -0
- package/dist/esm/utils/config.js +302 -0
- package/dist/esm/utils/createServer.js +258 -0
- package/dist/esm/utils/env.js +13 -0
- package/dist/esm/utils/generateWatchFiles.js +214 -0
- package/dist/esm/utils/getSelectedEntries.js +186 -0
- package/dist/esm/utils/getServerInternalPlugins.js +210 -0
- package/dist/esm/utils/language.js +6 -0
- package/dist/esm/utils/printInstructions.js +152 -0
- package/dist/esm/utils/restart.js +187 -0
- package/dist/esm/utils/routes.js +153 -0
- package/dist/esm/utils/types.js +1 -0
- package/dist/esm-node/analyze/constants.js +56 -0
- package/dist/esm-node/analyze/generateCode.js +227 -0
- package/dist/esm-node/analyze/getBundleEntry.js +77 -0
- package/dist/esm-node/analyze/getClientRoutes/getRoutes.js +201 -0
- package/dist/esm-node/analyze/getClientRoutes/getRoutesLegacy.js +197 -0
- package/dist/esm-node/analyze/getClientRoutes/index.js +6 -0
- package/dist/esm-node/analyze/getClientRoutes/utils.js +31 -0
- package/dist/esm-node/analyze/getFileSystemEntry.js +109 -0
- package/dist/esm-node/analyze/getHtmlTemplate.js +95 -0
- package/dist/esm-node/analyze/getServerRoutes.js +154 -0
- package/dist/esm-node/analyze/index.js +285 -0
- package/dist/esm-node/analyze/isDefaultExportFunction.js +42 -0
- package/dist/esm-node/analyze/makeLegalIdentifier.js +13 -0
- package/dist/esm-node/analyze/nestedRoutes.js +150 -0
- package/dist/esm-node/analyze/templates.js +297 -0
- package/dist/esm-node/analyze/utils.js +121 -0
- package/dist/esm-node/builder/builder-rspack/index.js +8 -0
- package/dist/esm-node/builder/builder-webpack/builderPlugins/compatModern.js +41 -0
- package/dist/esm-node/builder/builder-webpack/index.js +51 -0
- package/dist/esm-node/builder/builder-webpack/webpackPlugins/RouterPlugin.js +96 -0
- package/dist/esm-node/builder/builder-webpack/webpackPlugins/index.js +1 -0
- package/dist/esm-node/builder/generator/createBuilderOptions.js +24 -0
- package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +26 -0
- package/dist/esm-node/builder/generator/getBuilderTargets.js +21 -0
- package/dist/esm-node/builder/generator/index.js +29 -0
- package/dist/esm-node/builder/index.js +17 -0
- package/dist/esm-node/builder/shared/builderPlugins/adapterModern.js +202 -0
- package/dist/esm-node/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +27 -0
- package/dist/esm-node/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +34 -0
- package/dist/esm-node/builder/shared/createCopyPattern.js +46 -0
- package/dist/esm-node/builder/shared/index.js +3 -0
- package/dist/esm-node/builder/shared/loaders/serverModuleLoader.js +7 -0
- package/dist/esm-node/builder/shared/types.js +0 -0
- package/dist/esm-node/commands/build.js +52 -0
- package/dist/esm-node/commands/deploy.js +8 -0
- package/dist/esm-node/commands/dev.js +72 -0
- package/dist/esm-node/commands/index.js +3 -0
- package/dist/esm-node/commands/inspect.js +18 -0
- package/dist/esm-node/commands/serve.js +34 -0
- package/dist/esm-node/config/default.js +162 -0
- package/dist/esm-node/config/index.js +3 -0
- package/dist/esm-node/config/initialize/index.js +12 -0
- package/dist/esm-node/config/initialize/inits.js +136 -0
- package/dist/esm-node/config/legacy/createHtmlConfig.js +35 -0
- package/dist/esm-node/config/legacy/createOutputConfig.js +68 -0
- package/dist/esm-node/config/legacy/createSourceConfig.js +39 -0
- package/dist/esm-node/config/legacy/createToolsConfig.js +42 -0
- package/dist/esm-node/config/legacy/index.js +51 -0
- package/dist/esm-node/defineConfig.js +9 -0
- package/dist/esm-node/exports/server.js +4 -0
- package/dist/esm-node/hooks.js +35 -0
- package/dist/esm-node/index.js +172 -0
- package/dist/esm-node/initialize/index.js +91 -0
- package/dist/esm-node/locale/en.js +36 -0
- package/dist/esm-node/locale/index.js +9 -0
- package/dist/esm-node/locale/zh.js +36 -0
- package/dist/esm-node/schema/Schema.js +40 -0
- package/dist/esm-node/schema/index.js +88 -0
- package/dist/esm-node/schema/legacy.js +148 -0
- package/dist/esm-node/types/config/deploy.js +0 -0
- package/dist/esm-node/types/config/dev.js +0 -0
- package/dist/esm-node/types/config/experiments.js +0 -0
- package/dist/esm-node/types/config/html.js +0 -0
- package/dist/esm-node/types/config/index.js +1 -0
- package/dist/esm-node/types/config/output.js +0 -0
- package/dist/esm-node/types/config/performance.js +0 -0
- package/dist/esm-node/types/config/security.js +0 -0
- package/dist/esm-node/types/config/source.js +0 -0
- package/dist/esm-node/types/config/tools.js +0 -0
- package/dist/esm-node/types/hooks.js +0 -0
- package/dist/esm-node/types/index.js +3 -0
- package/dist/esm-node/types/legacyConfig/deploy.js +0 -0
- package/dist/esm-node/types/legacyConfig/dev.js +0 -0
- package/dist/esm-node/types/legacyConfig/index.js +0 -0
- package/dist/esm-node/types/legacyConfig/output.js +0 -0
- package/dist/esm-node/types/legacyConfig/source.js +0 -0
- package/dist/esm-node/types/legacyConfig/tools.js +0 -0
- package/dist/esm-node/types/utils.js +0 -0
- package/dist/esm-node/utils/config.js +88 -0
- package/dist/esm-node/utils/createServer.js +37 -0
- package/dist/esm-node/utils/env.js +15 -0
- package/dist/esm-node/utils/generateWatchFiles.js +33 -0
- package/dist/esm-node/utils/getSelectedEntries.js +38 -0
- package/dist/esm-node/utils/getServerInternalPlugins.js +18 -0
- package/dist/esm-node/utils/language.js +8 -0
- package/dist/esm-node/utils/printInstructions.js +11 -0
- package/dist/esm-node/utils/restart.js +22 -0
- package/dist/esm-node/utils/routes.js +10 -0
- package/dist/esm-node/utils/types.js +0 -0
- package/dist/js/modern/analyze/nestedRoutes.js +1 -10
- package/dist/js/node/analyze/nestedRoutes.js +1 -10
- package/dist/js/treeshaking/analyze/nestedRoutes.js +1 -10
- package/dist/types/analyze/templates.d.ts +3 -1
- package/dist/types/types/config/tools.d.ts +1 -1
- package/dist/types/types/hooks.d.ts +5 -4
- package/dist/types/types/index.d.ts +3 -1
- package/package.json +30 -31
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var makeLegalIdentifier_exports = {};
|
|
19
|
+
__export(makeLegalIdentifier_exports, {
|
|
20
|
+
makeLegalIdentifier: () => makeLegalIdentifier
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(makeLegalIdentifier_exports);
|
|
23
|
+
const reservedWords = "break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public";
|
|
24
|
+
const builtins = "arguments Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl";
|
|
25
|
+
const forbidList = new Set(`${reservedWords} ${builtins}`.split(" "));
|
|
26
|
+
function makeLegalIdentifier(str) {
|
|
27
|
+
const identifier = str.replace(/-(\w)/g, (_, letter) => letter.toUpperCase()).replace(/[^$_a-zA-Z0-9]/g, "_");
|
|
28
|
+
if (/\d/.test(identifier[0]) || forbidList.has(identifier)) {
|
|
29
|
+
return `_${identifier}`;
|
|
30
|
+
}
|
|
31
|
+
return identifier || "_";
|
|
32
|
+
}
|
|
33
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
+
0 && (module.exports = {
|
|
35
|
+
makeLegalIdentifier
|
|
36
|
+
});
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var nestedRoutes_exports = {};
|
|
25
|
+
__export(nestedRoutes_exports, {
|
|
26
|
+
walk: () => walk
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(nestedRoutes_exports);
|
|
29
|
+
var path = __toESM(require("path"));
|
|
30
|
+
var import_utils = require("@modern-js/utils");
|
|
31
|
+
var import_constants = require("./constants");
|
|
32
|
+
var import_utils2 = require("./utils");
|
|
33
|
+
const conventionNames = Object.values(import_constants.NESTED_ROUTE);
|
|
34
|
+
const replaceDynamicPath = (routePath) => {
|
|
35
|
+
return routePath.replace(/\[(.*?)\]/g, ":$1");
|
|
36
|
+
};
|
|
37
|
+
const createIndexRoute = (routeInfo, rootDir, filename, entryName) => {
|
|
38
|
+
return createRoute(
|
|
39
|
+
{
|
|
40
|
+
...routeInfo,
|
|
41
|
+
index: true,
|
|
42
|
+
children: void 0
|
|
43
|
+
},
|
|
44
|
+
rootDir,
|
|
45
|
+
filename,
|
|
46
|
+
entryName
|
|
47
|
+
);
|
|
48
|
+
};
|
|
49
|
+
const createRoute = (routeInfo, rootDir, filename, entryName) => {
|
|
50
|
+
const id = (0, import_utils.getRouteId)(filename, rootDir, entryName);
|
|
51
|
+
return {
|
|
52
|
+
...routeInfo,
|
|
53
|
+
id,
|
|
54
|
+
type: "nested"
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
const walk = async (dirname, rootDir, alias, entryName) => {
|
|
58
|
+
var _a, _b, _c, _d;
|
|
59
|
+
if (!await import_utils.fs.pathExists(dirname)) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
const isDirectory = (await import_utils.fs.stat(dirname)).isDirectory();
|
|
63
|
+
if (!isDirectory) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
const relativeDir = path.relative(rootDir, dirname);
|
|
67
|
+
const pathSegments = relativeDir.split(path.sep);
|
|
68
|
+
const lastSegment = pathSegments[pathSegments.length - 1];
|
|
69
|
+
const isRoot = lastSegment === "";
|
|
70
|
+
const isPathlessLayout = lastSegment.startsWith("__");
|
|
71
|
+
const isWithoutLayoutPath = lastSegment.includes(".");
|
|
72
|
+
let routePath = isRoot || isPathlessLayout ? "/" : `${lastSegment}`;
|
|
73
|
+
if (isWithoutLayoutPath) {
|
|
74
|
+
routePath = lastSegment.split(".").join("/");
|
|
75
|
+
}
|
|
76
|
+
routePath = replaceDynamicPath(routePath);
|
|
77
|
+
const route = {
|
|
78
|
+
path: routePath,
|
|
79
|
+
children: [],
|
|
80
|
+
isRoot
|
|
81
|
+
};
|
|
82
|
+
let pageLoaderFile = "";
|
|
83
|
+
let pageRoute = null;
|
|
84
|
+
let splatLoaderFile = "";
|
|
85
|
+
let splatRoute = null;
|
|
86
|
+
const items = await import_utils.fs.readdir(dirname);
|
|
87
|
+
for (const item of items) {
|
|
88
|
+
const itemPath = path.join(dirname, item);
|
|
89
|
+
const extname = path.extname(item);
|
|
90
|
+
const itemWithoutExt = item.slice(0, -extname.length);
|
|
91
|
+
const isDirectory2 = (await import_utils.fs.stat(itemPath)).isDirectory();
|
|
92
|
+
if (isDirectory2) {
|
|
93
|
+
const childRoute = await walk(itemPath, rootDir, alias, entryName);
|
|
94
|
+
if (childRoute) {
|
|
95
|
+
(_a = route.children) == null ? void 0 : _a.push(childRoute);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (extname && (!import_constants.JS_EXTENSIONS.includes(extname) || !conventionNames.includes(itemWithoutExt))) {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if (itemWithoutExt === import_constants.NESTED_ROUTE.LAYOUT_LOADER_FILE) {
|
|
102
|
+
if (!route.loader) {
|
|
103
|
+
route.loader = itemPath;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (itemWithoutExt === import_constants.NESTED_ROUTE.LAYOUT_FILE) {
|
|
107
|
+
route._component = (0, import_utils2.replaceWithAlias)(alias.basename, itemPath, alias.name);
|
|
108
|
+
}
|
|
109
|
+
if (itemWithoutExt === import_constants.NESTED_ROUTE.PAGE_LOADER_FILE) {
|
|
110
|
+
pageLoaderFile = itemPath;
|
|
111
|
+
}
|
|
112
|
+
if (itemWithoutExt === import_constants.NESTED_ROUTE.PAGE_FILE) {
|
|
113
|
+
pageRoute = createIndexRoute(
|
|
114
|
+
{
|
|
115
|
+
_component: (0, import_utils2.replaceWithAlias)(alias.basename, itemPath, alias.name)
|
|
116
|
+
},
|
|
117
|
+
rootDir,
|
|
118
|
+
itemPath,
|
|
119
|
+
entryName
|
|
120
|
+
);
|
|
121
|
+
if (pageLoaderFile) {
|
|
122
|
+
pageRoute.loader = pageLoaderFile;
|
|
123
|
+
}
|
|
124
|
+
(_b = route.children) == null ? void 0 : _b.push(pageRoute);
|
|
125
|
+
}
|
|
126
|
+
if (itemWithoutExt === import_constants.NESTED_ROUTE.SPLATE_LOADER_FILE) {
|
|
127
|
+
splatLoaderFile = itemPath;
|
|
128
|
+
}
|
|
129
|
+
if (itemWithoutExt === import_constants.NESTED_ROUTE.SPLATE_FILE) {
|
|
130
|
+
splatRoute = createRoute(
|
|
131
|
+
{
|
|
132
|
+
_component: (0, import_utils2.replaceWithAlias)(alias.basename, itemPath, alias.name),
|
|
133
|
+
path: "*"
|
|
134
|
+
},
|
|
135
|
+
rootDir,
|
|
136
|
+
itemPath,
|
|
137
|
+
entryName
|
|
138
|
+
);
|
|
139
|
+
if (splatLoaderFile) {
|
|
140
|
+
splatRoute.loader = splatLoaderFile;
|
|
141
|
+
}
|
|
142
|
+
(_c = route.children) == null ? void 0 : _c.push(splatRoute);
|
|
143
|
+
}
|
|
144
|
+
if (itemWithoutExt === import_constants.NESTED_ROUTE.LOADING_FILE) {
|
|
145
|
+
route.loading = (0, import_utils2.replaceWithAlias)(alias.basename, itemPath, alias.name);
|
|
146
|
+
}
|
|
147
|
+
if (itemWithoutExt === import_constants.NESTED_ROUTE.ERROR_FILE) {
|
|
148
|
+
route.error = (0, import_utils2.replaceWithAlias)(alias.basename, itemPath, alias.name);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
let finalRoute = createRoute(
|
|
152
|
+
route,
|
|
153
|
+
rootDir,
|
|
154
|
+
path.join(dirname, `${import_constants.NESTED_ROUTE.LAYOUT_FILE}.ts`),
|
|
155
|
+
entryName
|
|
156
|
+
);
|
|
157
|
+
if (isPathlessLayout) {
|
|
158
|
+
delete finalRoute.path;
|
|
159
|
+
}
|
|
160
|
+
route.children = (_d = route.children) == null ? void 0 : _d.filter((childRoute) => childRoute);
|
|
161
|
+
if (route.children && route.children.length === 0 && !route.index) {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
if (finalRoute.children && finalRoute.children.length === 1 && !finalRoute._component) {
|
|
165
|
+
const childRoute = finalRoute.children[0];
|
|
166
|
+
if (childRoute.path === "*") {
|
|
167
|
+
const path2 = `${finalRoute.path || ""}/${childRoute.path || ""}`;
|
|
168
|
+
finalRoute = {
|
|
169
|
+
...childRoute,
|
|
170
|
+
path: path2
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return finalRoute;
|
|
175
|
+
};
|
|
176
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
177
|
+
0 && (module.exports = {
|
|
178
|
+
walk
|
|
179
|
+
});
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var templates_exports = {};
|
|
25
|
+
__export(templates_exports, {
|
|
26
|
+
fileSystemRoutes: () => fileSystemRoutes,
|
|
27
|
+
html: () => html,
|
|
28
|
+
index: () => index,
|
|
29
|
+
renderFunction: () => renderFunction,
|
|
30
|
+
routesForServer: () => routesForServer
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(templates_exports);
|
|
33
|
+
var import_path = __toESM(require("path"));
|
|
34
|
+
var import_utils = require("@modern-js/utils");
|
|
35
|
+
var import_constants = require("./constants");
|
|
36
|
+
const index = ({
|
|
37
|
+
mountId,
|
|
38
|
+
imports,
|
|
39
|
+
renderFunction: renderFunction2,
|
|
40
|
+
exportStatement
|
|
41
|
+
}) => `
|
|
42
|
+
const IS_BROWSER = typeof window !== 'undefined' && window.name !== 'nodejs';
|
|
43
|
+
const IS_REACT18 = process.env.IS_REACT18 === 'true';
|
|
44
|
+
const MOUNT_ID = '${mountId}';
|
|
45
|
+
|
|
46
|
+
${imports}
|
|
47
|
+
|
|
48
|
+
let AppWrapper = null;
|
|
49
|
+
|
|
50
|
+
let root = null;
|
|
51
|
+
|
|
52
|
+
function render() {
|
|
53
|
+
${renderFunction2}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
AppWrapper = render();
|
|
57
|
+
|
|
58
|
+
${exportStatement};
|
|
59
|
+
`;
|
|
60
|
+
const renderFunction = ({
|
|
61
|
+
plugins,
|
|
62
|
+
customBootstrap,
|
|
63
|
+
fileSystemRoutes: fileSystemRoutes2
|
|
64
|
+
}) => {
|
|
65
|
+
const bootstrap = "bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM)";
|
|
66
|
+
return `
|
|
67
|
+
const finalAppConfig = {
|
|
68
|
+
...App.config,
|
|
69
|
+
...typeof ${import_constants.APP_CONFIG_NAME} === 'function' ? ${import_constants.APP_CONFIG_NAME}() : {},
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
AppWrapper = createApp({
|
|
73
|
+
plugins: [
|
|
74
|
+
${plugins.map(
|
|
75
|
+
({ name, options, args }) => `${name}({...${options}, ...finalAppConfig?.${args || name}}),`
|
|
76
|
+
).join("\n")}
|
|
77
|
+
]
|
|
78
|
+
})(${fileSystemRoutes2 ? "" : `App`})
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
if(!AppWrapper.init && typeof appInit !== 'undefined') {
|
|
82
|
+
AppWrapper.init = appInit;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
if (IS_BROWSER) {
|
|
87
|
+
${customBootstrap ? `customBootstrap(AppWrapper, () => ${bootstrap});` : `${bootstrap};`}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return AppWrapper
|
|
91
|
+
`;
|
|
92
|
+
};
|
|
93
|
+
const html = (partials) => `
|
|
94
|
+
<!DOCTYPE html>
|
|
95
|
+
<html>
|
|
96
|
+
<head>
|
|
97
|
+
<%= meta %>
|
|
98
|
+
<title><%= title %></title>
|
|
99
|
+
|
|
100
|
+
${partials.top.join("\n")}
|
|
101
|
+
|
|
102
|
+
<script>
|
|
103
|
+
window.__assetPrefix__ = '<%= assetPrefix %>';
|
|
104
|
+
<\/script>
|
|
105
|
+
${partials.head.join("\n")}
|
|
106
|
+
|
|
107
|
+
<!--<?- chunksMap.css ?>-->
|
|
108
|
+
</head>
|
|
109
|
+
|
|
110
|
+
<body>
|
|
111
|
+
<noscript>
|
|
112
|
+
We're sorry but react app doesn't work properly without JavaScript enabled. Please enable it to continue.
|
|
113
|
+
</noscript>
|
|
114
|
+
<div id="<%= mountId %>"><!--<?- html ?>--></div>
|
|
115
|
+
${partials.body.join("\n")}
|
|
116
|
+
<!--<?- chunksMap.js ?>-->
|
|
117
|
+
<!--<?- SSRDataScript ?>-->
|
|
118
|
+
<!--<?- bottomTemplate ?>-->
|
|
119
|
+
</body>
|
|
120
|
+
|
|
121
|
+
</html>
|
|
122
|
+
`;
|
|
123
|
+
const routesForServer = ({
|
|
124
|
+
routes,
|
|
125
|
+
metaName
|
|
126
|
+
}) => {
|
|
127
|
+
const loaders = [];
|
|
128
|
+
const traverseRouteTree = (route) => {
|
|
129
|
+
var _a;
|
|
130
|
+
let children;
|
|
131
|
+
if ("children" in route && route.children) {
|
|
132
|
+
children = (_a = route == null ? void 0 : route.children) == null ? void 0 : _a.map(traverseRouteTree);
|
|
133
|
+
}
|
|
134
|
+
let loader;
|
|
135
|
+
if (route.type === "nested") {
|
|
136
|
+
if (route.loader) {
|
|
137
|
+
loaders.push(route.loader);
|
|
138
|
+
loader = `loader_${loaders.length - 1}`;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const finalRoute = {
|
|
142
|
+
...route,
|
|
143
|
+
loader,
|
|
144
|
+
children
|
|
145
|
+
};
|
|
146
|
+
return finalRoute;
|
|
147
|
+
};
|
|
148
|
+
let routesCode = `
|
|
149
|
+
export const routes = [
|
|
150
|
+
`;
|
|
151
|
+
for (const route of routes) {
|
|
152
|
+
if ("type" in route) {
|
|
153
|
+
const newRoute = traverseRouteTree(route);
|
|
154
|
+
routesCode += `${JSON.stringify(newRoute, null, 2).replace(
|
|
155
|
+
/"(loader_[^"])"/g,
|
|
156
|
+
"$1"
|
|
157
|
+
)},`;
|
|
158
|
+
} else {
|
|
159
|
+
routesCode += `${JSON.stringify(route, null, 2)}`;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
routesCode += `
|
|
163
|
+
];`;
|
|
164
|
+
let importLoadersCode = "";
|
|
165
|
+
if (loaders.length > 0) {
|
|
166
|
+
importLoadersCode = loaders.map((loader, index2) => {
|
|
167
|
+
return `import loader_${index2} from "${(0, import_utils.slash)(loader)}"`;
|
|
168
|
+
}).join("\n");
|
|
169
|
+
}
|
|
170
|
+
const exportCode = `
|
|
171
|
+
export { handleRequest } from '@modern-js/plugin-data-loader/runtime';
|
|
172
|
+
`;
|
|
173
|
+
return `
|
|
174
|
+
${importLoadersCode}
|
|
175
|
+
${routesCode}
|
|
176
|
+
${exportCode}
|
|
177
|
+
`;
|
|
178
|
+
};
|
|
179
|
+
const fileSystemRoutes = async ({
|
|
180
|
+
routes,
|
|
181
|
+
ssrMode,
|
|
182
|
+
nestedRoutesEntry,
|
|
183
|
+
entryName,
|
|
184
|
+
internalDirectory
|
|
185
|
+
}) => {
|
|
186
|
+
const loadings = [];
|
|
187
|
+
const errors = [];
|
|
188
|
+
const loaders = [];
|
|
189
|
+
const loadersMap = {};
|
|
190
|
+
const loadersMapFile = import_path.default.join(
|
|
191
|
+
internalDirectory,
|
|
192
|
+
entryName,
|
|
193
|
+
import_constants.TEMP_LOADERS_DIR,
|
|
194
|
+
"map.json"
|
|
195
|
+
);
|
|
196
|
+
const importLazyCode = `
|
|
197
|
+
import { lazy } from "react";
|
|
198
|
+
import loadable, { lazy as loadableLazy } from "@modern-js/runtime/loadable"
|
|
199
|
+
`;
|
|
200
|
+
let rootLayoutCode = ``;
|
|
201
|
+
const getDataLoaderPath = (loaderId) => {
|
|
202
|
+
if (!ssrMode) {
|
|
203
|
+
return "";
|
|
204
|
+
}
|
|
205
|
+
let dataLoaderPath = require.resolve("@modern-js/plugin-data-loader/loader");
|
|
206
|
+
if (nestedRoutesEntry) {
|
|
207
|
+
dataLoaderPath = `${(0, import_utils.slash)(dataLoaderPath)}?mapFile=${(0, import_utils.slash)(
|
|
208
|
+
loadersMapFile
|
|
209
|
+
)}&loaderId=${loaderId}!`;
|
|
210
|
+
}
|
|
211
|
+
return dataLoaderPath;
|
|
212
|
+
};
|
|
213
|
+
const traverseRouteTree = (route) => {
|
|
214
|
+
var _a;
|
|
215
|
+
let children;
|
|
216
|
+
if ("children" in route && route.children) {
|
|
217
|
+
children = (_a = route == null ? void 0 : route.children) == null ? void 0 : _a.map(traverseRouteTree);
|
|
218
|
+
}
|
|
219
|
+
let loading;
|
|
220
|
+
let error;
|
|
221
|
+
let loader;
|
|
222
|
+
let component = "";
|
|
223
|
+
let lazyImport = null;
|
|
224
|
+
if (route.type === "nested") {
|
|
225
|
+
if (route.loading) {
|
|
226
|
+
loadings.push(route.loading);
|
|
227
|
+
loading = `loading_${loadings.length - 1}`;
|
|
228
|
+
}
|
|
229
|
+
if (route.error) {
|
|
230
|
+
errors.push(route.error);
|
|
231
|
+
error = `error_${errors.length - 1}`;
|
|
232
|
+
}
|
|
233
|
+
if (route.loader) {
|
|
234
|
+
loaders.push(route.loader);
|
|
235
|
+
const loaderId = loaders.length - 1;
|
|
236
|
+
loader = `loader_${loaderId}`;
|
|
237
|
+
loadersMap[loader] = {
|
|
238
|
+
routeId: route.id,
|
|
239
|
+
filePath: route.loader,
|
|
240
|
+
inline: false
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
if (route._component) {
|
|
244
|
+
if (route.isRoot) {
|
|
245
|
+
rootLayoutCode = `import RootLayout from '${route._component}'`;
|
|
246
|
+
component = `RootLayout`;
|
|
247
|
+
} else if (ssrMode === "string") {
|
|
248
|
+
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
|
|
249
|
+
component = `loadable(${lazyImport})`;
|
|
250
|
+
} else {
|
|
251
|
+
lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
|
|
252
|
+
component = `lazy(${lazyImport})`;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
} else if (route._component) {
|
|
256
|
+
lazyImport = `() => import('${route._component}')`;
|
|
257
|
+
component = `loadable(${lazyImport})`;
|
|
258
|
+
}
|
|
259
|
+
const finalRoute = {
|
|
260
|
+
...route,
|
|
261
|
+
lazyImport,
|
|
262
|
+
loading,
|
|
263
|
+
loader,
|
|
264
|
+
error,
|
|
265
|
+
children
|
|
266
|
+
};
|
|
267
|
+
if (route._component) {
|
|
268
|
+
finalRoute.component = component;
|
|
269
|
+
}
|
|
270
|
+
return finalRoute;
|
|
271
|
+
};
|
|
272
|
+
let routeComponentsCode = `
|
|
273
|
+
export const routes = [
|
|
274
|
+
`;
|
|
275
|
+
for (const route of routes) {
|
|
276
|
+
if ("type" in route) {
|
|
277
|
+
const newRoute = traverseRouteTree(route);
|
|
278
|
+
routeComponentsCode += `${JSON.stringify(newRoute, null, 2).replace(/"(loadable.*\))"/g, "$1").replace(/"(loadableLazy.*\))"/g, "$1").replace(/"(\(\)[^,]+)",/g, "$1,").replace(/"(lazy\(.*\))"/g, "$1").replace(/"(loading_[^"])"/g, "$1").replace(/"(loader_[^"])"/g, "$1").replace(/"(RootLayout)"/g, "$1").replace(/"(error_[^"])"/g, "$1").replace(/\\"/g, '"')},`;
|
|
279
|
+
} else {
|
|
280
|
+
const component = `loadable(() => import('${route._component}'))`;
|
|
281
|
+
const finalRoute = {
|
|
282
|
+
...route,
|
|
283
|
+
component
|
|
284
|
+
};
|
|
285
|
+
routeComponentsCode += `${JSON.stringify(finalRoute, null, 2).replace(/"(loadable[^"]*)"/g, "$1").replace(/"(lazy[^"]*)"/g, "$1")},`;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
routeComponentsCode += `
|
|
289
|
+
];`;
|
|
290
|
+
const importLoadingCode = loadings.map((loading, index2) => {
|
|
291
|
+
return `import loading_${index2} from '${loading}';
|
|
292
|
+
`;
|
|
293
|
+
}).join("");
|
|
294
|
+
const importErrorComponentsCode = errors.map((error, index2) => {
|
|
295
|
+
return `import error_${index2} from '${error}';
|
|
296
|
+
`;
|
|
297
|
+
}).join("");
|
|
298
|
+
let importLoadersCode = "";
|
|
299
|
+
for (const [key, loaderInfo] of Object.entries(loadersMap)) {
|
|
300
|
+
if (loaderInfo.inline) {
|
|
301
|
+
importLoadersCode += `import { loader as ${key} } from "${getDataLoaderPath(
|
|
302
|
+
key
|
|
303
|
+
)}${(0, import_utils.slash)(loaderInfo.filePath)}";
|
|
304
|
+
`;
|
|
305
|
+
} else {
|
|
306
|
+
importLoadersCode += `import ${key} from "${getDataLoaderPath(
|
|
307
|
+
key
|
|
308
|
+
)}${(0, import_utils.slash)(loaderInfo.filePath)}";
|
|
309
|
+
`;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
await import_utils.fs.ensureFile(loadersMapFile);
|
|
313
|
+
await import_utils.fs.writeJSON(loadersMapFile, loadersMap);
|
|
314
|
+
return `
|
|
315
|
+
${importLazyCode}
|
|
316
|
+
${rootLayoutCode}
|
|
317
|
+
${importLoadingCode}
|
|
318
|
+
${importErrorComponentsCode}
|
|
319
|
+
${importLoadersCode}
|
|
320
|
+
${routeComponentsCode}
|
|
321
|
+
`;
|
|
322
|
+
};
|
|
323
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
324
|
+
0 && (module.exports = {
|
|
325
|
+
fileSystemRoutes,
|
|
326
|
+
html,
|
|
327
|
+
index,
|
|
328
|
+
renderFunction,
|
|
329
|
+
routesForServer
|
|
330
|
+
});
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var utils_exports = {};
|
|
25
|
+
__export(utils_exports, {
|
|
26
|
+
getDefaultImports: () => getDefaultImports,
|
|
27
|
+
getServerLoadersFile: () => getServerLoadersFile,
|
|
28
|
+
hasLoader: () => hasLoader,
|
|
29
|
+
isPageComponentFile: () => isPageComponentFile,
|
|
30
|
+
parseModule: () => parseModule,
|
|
31
|
+
replaceWithAlias: () => replaceWithAlias,
|
|
32
|
+
walkDirectory: () => walkDirectory
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(utils_exports);
|
|
35
|
+
var import_fs = __toESM(require("fs"));
|
|
36
|
+
var import_path = __toESM(require("path"));
|
|
37
|
+
var import_utils = require("@modern-js/utils");
|
|
38
|
+
var import_esbuild = require("esbuild");
|
|
39
|
+
var import_es_module_lexer = require("es-module-lexer");
|
|
40
|
+
var import_constants = require("./constants");
|
|
41
|
+
const walkDirectory = (dir) => import_fs.default.readdirSync(dir).reduce((previous, filename) => {
|
|
42
|
+
const filePath = import_path.default.join(dir, filename);
|
|
43
|
+
if (import_fs.default.statSync(filePath).isDirectory()) {
|
|
44
|
+
return [...previous, ...walkDirectory(filePath)];
|
|
45
|
+
} else {
|
|
46
|
+
return [...previous, filePath];
|
|
47
|
+
}
|
|
48
|
+
}, []);
|
|
49
|
+
const getDefaultImports = ({
|
|
50
|
+
entrypoint,
|
|
51
|
+
srcDirectory,
|
|
52
|
+
internalSrcAlias,
|
|
53
|
+
internalDirAlias,
|
|
54
|
+
internalDirectory
|
|
55
|
+
}) => {
|
|
56
|
+
const { entryName, fileSystemRoutes, customBootstrap, entry } = entrypoint;
|
|
57
|
+
const imports = [
|
|
58
|
+
{
|
|
59
|
+
specifiers: [{ local: "React" }],
|
|
60
|
+
value: "react"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
specifiers: [{ local: "ReactDOM" }],
|
|
64
|
+
value: (0, import_utils.isReact18)(import_path.default.join(internalDirectory, "../../")) ? "react-dom/client" : "react-dom"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
specifiers: [{ imported: "createApp" }, { imported: "bootstrap" }],
|
|
68
|
+
value: "@modern-js/runtime"
|
|
69
|
+
},
|
|
70
|
+
customBootstrap && {
|
|
71
|
+
specifiers: [{ local: "customBootstrap" }],
|
|
72
|
+
value: (0, import_utils.normalizeToPosixPath)(
|
|
73
|
+
customBootstrap.replace(srcDirectory, internalSrcAlias)
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
].filter(Boolean);
|
|
77
|
+
if (fileSystemRoutes) {
|
|
78
|
+
const route = {
|
|
79
|
+
specifiers: [{ imported: "routes" }],
|
|
80
|
+
value: (0, import_utils.normalizeToPosixPath)(
|
|
81
|
+
`${internalDirAlias}/${entryName}/${import_constants.FILE_SYSTEM_ROUTES_FILE_NAME.replace(
|
|
82
|
+
".js",
|
|
83
|
+
""
|
|
84
|
+
)}`
|
|
85
|
+
)
|
|
86
|
+
};
|
|
87
|
+
if (fileSystemRoutes.globalApp) {
|
|
88
|
+
imports.push({
|
|
89
|
+
specifiers: [{ local: "App" }],
|
|
90
|
+
value: (0, import_utils.normalizeToPosixPath)(
|
|
91
|
+
fileSystemRoutes.globalApp.replace(srcDirectory, internalSrcAlias)
|
|
92
|
+
)
|
|
93
|
+
});
|
|
94
|
+
} else {
|
|
95
|
+
route.initialize = "const App = false;";
|
|
96
|
+
}
|
|
97
|
+
imports.push(route);
|
|
98
|
+
} else {
|
|
99
|
+
imports.push({
|
|
100
|
+
specifiers: [{ local: "App" }],
|
|
101
|
+
value: (0, import_utils.normalizeToPosixPath)(
|
|
102
|
+
entry.replace(srcDirectory, internalSrcAlias)
|
|
103
|
+
)
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return imports;
|
|
107
|
+
};
|
|
108
|
+
const isPageComponentFile = (filePath) => {
|
|
109
|
+
if (/\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/.test(filePath)) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
if ([".js", ".jsx", ".ts", ".tsx"].includes(import_path.default.extname(filePath))) {
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
return false;
|
|
116
|
+
};
|
|
117
|
+
const replaceWithAlias = (base, filePath, alias) => (0, import_utils.normalizeToPosixPath)(import_path.default.join(alias, import_path.default.relative(base, filePath)));
|
|
118
|
+
const parseModule = async ({
|
|
119
|
+
source,
|
|
120
|
+
filename
|
|
121
|
+
}) => {
|
|
122
|
+
let content = source;
|
|
123
|
+
if (import_constants.JS_EXTENSIONS.some((ext) => filename.endsWith(ext))) {
|
|
124
|
+
const result = await (0, import_esbuild.transform)(content, {
|
|
125
|
+
loader: import_path.default.extname(filename).slice(1),
|
|
126
|
+
format: "esm"
|
|
127
|
+
});
|
|
128
|
+
content = result.code;
|
|
129
|
+
}
|
|
130
|
+
return await (0, import_es_module_lexer.parse)(content);
|
|
131
|
+
};
|
|
132
|
+
const hasLoader = async (filename) => {
|
|
133
|
+
const source = await import_utils.fs.readFile(filename);
|
|
134
|
+
const [, moduleExports] = await parseModule({
|
|
135
|
+
source: source.toString(),
|
|
136
|
+
filename
|
|
137
|
+
});
|
|
138
|
+
return moduleExports.some((e) => e.n === import_constants.LOADER_EXPORT_NAME);
|
|
139
|
+
};
|
|
140
|
+
const getServerLoadersFile = (internalDirectory, entryName) => {
|
|
141
|
+
return import_path.default.join(internalDirectory, entryName, "route-server-loaders.js");
|
|
142
|
+
};
|
|
143
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
144
|
+
0 && (module.exports = {
|
|
145
|
+
getDefaultImports,
|
|
146
|
+
getServerLoadersFile,
|
|
147
|
+
hasLoader,
|
|
148
|
+
isPageComponentFile,
|
|
149
|
+
parseModule,
|
|
150
|
+
replaceWithAlias,
|
|
151
|
+
walkDirectory
|
|
152
|
+
});
|