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