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