@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,425 +1,615 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
function _arrayLikeToArray(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _arrayWithoutHoles(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
8
|
+
}
|
|
9
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
10
|
+
try {
|
|
11
|
+
var info = gen[key](arg);
|
|
12
|
+
var value = info.value;
|
|
13
|
+
} catch (error) {
|
|
14
|
+
reject(error);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (info.done) {
|
|
18
|
+
resolve(value);
|
|
19
|
+
} else {
|
|
20
|
+
Promise.resolve(value).then(_next, _throw);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function _asyncToGenerator(fn) {
|
|
24
|
+
return function() {
|
|
25
|
+
var self = this, args = arguments;
|
|
26
|
+
return new Promise(function(resolve, reject) {
|
|
27
|
+
var gen = fn.apply(self, args);
|
|
28
|
+
function _next(value) {
|
|
29
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
30
|
+
}
|
|
31
|
+
function _throw(err) {
|
|
32
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
33
|
+
}
|
|
34
|
+
_next(undefined);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function _iterableToArray(iter) {
|
|
39
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
40
|
+
}
|
|
41
|
+
function _nonIterableSpread() {
|
|
42
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
43
|
+
}
|
|
44
|
+
function _toConsumableArray(arr) {
|
|
45
|
+
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
46
|
+
}
|
|
47
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
48
|
+
if (!o) return;
|
|
49
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
50
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
51
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
52
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
53
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
54
|
+
}
|
|
55
|
+
var __generator = this && this.__generator || function(thisArg, body) {
|
|
56
|
+
var f, y, t, g, _ = {
|
|
57
|
+
label: 0,
|
|
58
|
+
sent: function() {
|
|
59
|
+
if (t[0] & 1) throw t[1];
|
|
60
|
+
return t[1];
|
|
61
|
+
},
|
|
62
|
+
trys: [],
|
|
63
|
+
ops: []
|
|
64
|
+
};
|
|
65
|
+
return(g = {
|
|
66
|
+
next: verb(0),
|
|
67
|
+
"throw": verb(1),
|
|
68
|
+
"return": verb(2)
|
|
69
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
70
|
+
return this;
|
|
71
|
+
}), g);
|
|
72
|
+
function verb(n) {
|
|
73
|
+
return function(v) {
|
|
74
|
+
return step([
|
|
75
|
+
n,
|
|
76
|
+
v
|
|
77
|
+
]);
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function step(op) {
|
|
81
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
82
|
+
while(_)try {
|
|
83
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
84
|
+
if (y = 0, t) op = [
|
|
85
|
+
op[0] & 2,
|
|
86
|
+
t.value
|
|
87
|
+
];
|
|
88
|
+
switch(op[0]){
|
|
89
|
+
case 0:
|
|
90
|
+
case 1:
|
|
91
|
+
t = op;
|
|
92
|
+
break;
|
|
93
|
+
case 4:
|
|
94
|
+
_.label++;
|
|
95
|
+
return {
|
|
96
|
+
value: op[1],
|
|
97
|
+
done: false
|
|
98
|
+
};
|
|
99
|
+
case 5:
|
|
100
|
+
_.label++;
|
|
101
|
+
y = op[1];
|
|
102
|
+
op = [
|
|
103
|
+
0
|
|
104
|
+
];
|
|
105
|
+
continue;
|
|
106
|
+
case 7:
|
|
107
|
+
op = _.ops.pop();
|
|
108
|
+
_.trys.pop();
|
|
109
|
+
continue;
|
|
110
|
+
default:
|
|
111
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
112
|
+
_ = 0;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
116
|
+
_.label = op[1];
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
120
|
+
_.label = t[1];
|
|
121
|
+
t = op;
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
if (t && _.label < t[2]) {
|
|
125
|
+
_.label = t[2];
|
|
126
|
+
_.ops.push(op);
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
if (t[2]) _.ops.pop();
|
|
130
|
+
_.trys.pop();
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
op = body.call(thisArg, _);
|
|
134
|
+
} catch (e) {
|
|
135
|
+
op = [
|
|
136
|
+
6,
|
|
137
|
+
e
|
|
138
|
+
];
|
|
139
|
+
y = 0;
|
|
140
|
+
} finally{
|
|
141
|
+
f = t = 0;
|
|
142
|
+
}
|
|
143
|
+
if (op[0] & 5) throw op[1];
|
|
144
|
+
return {
|
|
145
|
+
value: op[0] ? op[1] : void 0,
|
|
146
|
+
done: true
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
import path from "path";
|
|
151
|
+
import { fs, getEntryOptions, LOADER_ROUTES_DIR, logger } from "@modern-js/utils";
|
|
152
|
+
import { useResolvedConfigContext } from "@modern-js/core";
|
|
153
|
+
import { isDevCommand } from "../utils/commands";
|
|
11
154
|
import * as templates from "./templates";
|
|
12
155
|
import { getClientRoutes, getClientRoutesLegacy } from "./getClientRoutes";
|
|
13
156
|
import { FILE_SYSTEM_ROUTES_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME, TEMP_LOADERS_DIR } from "./constants";
|
|
14
157
|
import { getDefaultImports } from "./utils";
|
|
15
158
|
import { walk } from "./nestedRoutes";
|
|
159
|
+
import { loaderBuilder, serverLoaderBuilder } from "./Builder";
|
|
16
160
|
var loader = {
|
|
17
|
-
|
|
18
|
-
|
|
161
|
+
".js": "jsx",
|
|
162
|
+
".ts": "tsx"
|
|
19
163
|
};
|
|
20
164
|
var EXTERNAL_REGEXP = /^[^./]|^\.[^./]|^\.\.[^/]/;
|
|
21
|
-
var createImportSpecifier = function
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
165
|
+
var createImportSpecifier = function(specifiers) {
|
|
166
|
+
var defaults = "";
|
|
167
|
+
var named = [];
|
|
168
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
169
|
+
try {
|
|
170
|
+
for(var _iterator = specifiers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
171
|
+
var _value = _step.value, local = _value.local, imported = _value.imported;
|
|
172
|
+
if (local && imported) {
|
|
173
|
+
named.push("".concat(imported, " as ").concat(local));
|
|
174
|
+
} else if (local) {
|
|
175
|
+
defaults = local;
|
|
176
|
+
} else {
|
|
177
|
+
named.push(imported);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
} catch (err) {
|
|
181
|
+
_didIteratorError = true;
|
|
182
|
+
_iteratorError = err;
|
|
183
|
+
} finally{
|
|
184
|
+
try {
|
|
185
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
186
|
+
_iterator.return();
|
|
187
|
+
}
|
|
188
|
+
} finally{
|
|
189
|
+
if (_didIteratorError) {
|
|
190
|
+
throw _iteratorError;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (defaults && named.length) {
|
|
195
|
+
return "".concat(defaults, ", { ").concat(named.join(", "), " }");
|
|
196
|
+
} else if (defaults) {
|
|
197
|
+
return defaults;
|
|
198
|
+
} else {
|
|
199
|
+
return "{ ".concat(named.join(", "), " }");
|
|
38
200
|
}
|
|
39
|
-
} catch (err) {
|
|
40
|
-
_iterator.e(err);
|
|
41
|
-
} finally {
|
|
42
|
-
_iterator.f();
|
|
43
|
-
}
|
|
44
|
-
if (defaults && named.length) {
|
|
45
|
-
return "".concat(defaults, ", { ").concat(named.join(', '), " }");
|
|
46
|
-
} else if (defaults) {
|
|
47
|
-
return defaults;
|
|
48
|
-
} else {
|
|
49
|
-
return "{ ".concat(named.join(', '), " }");
|
|
50
|
-
}
|
|
51
201
|
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
202
|
+
var createImportStatements = function(statements) {
|
|
203
|
+
var deDuplicated = [];
|
|
204
|
+
var seen = /* @__PURE__ */ new Map();
|
|
205
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
206
|
+
try {
|
|
207
|
+
var _loop = function() {
|
|
208
|
+
var _value = _step.value, value = _value.value, specifiers = _value.specifiers, initialize = _value.initialize;
|
|
209
|
+
if (!seen.has(value)) {
|
|
210
|
+
deDuplicated.push({
|
|
211
|
+
value: value,
|
|
212
|
+
specifiers: specifiers,
|
|
213
|
+
initialize: initialize
|
|
214
|
+
});
|
|
215
|
+
seen.set(value, specifiers);
|
|
216
|
+
} else {
|
|
217
|
+
var _instance;
|
|
218
|
+
var ref;
|
|
219
|
+
(_instance = seen.get(value)).push.apply(_instance, _toConsumableArray(specifiers));
|
|
220
|
+
var modifyIndex = deDuplicated.findIndex(function(v) {
|
|
221
|
+
return v.value === value;
|
|
222
|
+
});
|
|
223
|
+
var ref1;
|
|
224
|
+
var originInitialize = (ref1 = (ref = deDuplicated[modifyIndex]) === null || ref === void 0 ? void 0 : ref.initialize) !== null && ref1 !== void 0 ? ref1 : "";
|
|
225
|
+
deDuplicated[modifyIndex].initialize = originInitialize.concat("\n".concat(initialize || ""));
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
for(var _iterator = statements[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
|
|
229
|
+
} catch (err) {
|
|
230
|
+
_didIteratorError = true;
|
|
231
|
+
_iteratorError = err;
|
|
232
|
+
} finally{
|
|
233
|
+
try {
|
|
234
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
235
|
+
_iterator.return();
|
|
236
|
+
}
|
|
237
|
+
} finally{
|
|
238
|
+
if (_didIteratorError) {
|
|
239
|
+
throw _iteratorError;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return deDuplicated.map(function(param) {
|
|
244
|
+
var value = param.value, specifiers = param.specifiers, initialize = param.initialize;
|
|
245
|
+
return "import ".concat(createImportSpecifier(specifiers), " from '").concat(value, "';\n").concat(initialize || "");
|
|
246
|
+
}).join("\n");
|
|
247
|
+
};
|
|
248
|
+
var buildLoader = function() {
|
|
249
|
+
var _ref = _asyncToGenerator(function(entry, outfile) {
|
|
250
|
+
return __generator(this, function(_state) {
|
|
251
|
+
switch(_state.label){
|
|
252
|
+
case 0:
|
|
253
|
+
return [
|
|
254
|
+
4,
|
|
255
|
+
loaderBuilder.build({
|
|
256
|
+
format: "esm",
|
|
257
|
+
platform: "browser",
|
|
258
|
+
target: "esnext",
|
|
259
|
+
loader: loader,
|
|
260
|
+
watch: isDevCommand() && {},
|
|
261
|
+
bundle: true,
|
|
262
|
+
logLevel: "error",
|
|
263
|
+
entryPoints: [
|
|
264
|
+
entry
|
|
265
|
+
],
|
|
266
|
+
outfile: outfile,
|
|
267
|
+
plugins: [
|
|
268
|
+
{
|
|
269
|
+
name: "make-all-packages-external",
|
|
270
|
+
setup: function setup(build) {
|
|
271
|
+
build.onResolve({
|
|
272
|
+
filter: EXTERNAL_REGEXP
|
|
273
|
+
}, function(args) {
|
|
274
|
+
var external = true;
|
|
275
|
+
if (args.kind === "entry-point") {
|
|
276
|
+
external = false;
|
|
277
|
+
}
|
|
278
|
+
return {
|
|
279
|
+
path: args.path,
|
|
280
|
+
external: external
|
|
281
|
+
};
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
]
|
|
286
|
+
})
|
|
287
|
+
];
|
|
288
|
+
case 1:
|
|
289
|
+
_state.sent();
|
|
290
|
+
return [
|
|
291
|
+
2
|
|
292
|
+
];
|
|
293
|
+
}
|
|
69
294
|
});
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
295
|
+
});
|
|
296
|
+
return function buildLoader(entry, outfile) {
|
|
297
|
+
return _ref.apply(this, arguments);
|
|
298
|
+
};
|
|
299
|
+
}();
|
|
300
|
+
var buildServerLoader = function() {
|
|
301
|
+
var _ref = _asyncToGenerator(function(entry, outfile) {
|
|
302
|
+
return __generator(this, function(_state) {
|
|
303
|
+
switch(_state.label){
|
|
304
|
+
case 0:
|
|
305
|
+
return [
|
|
306
|
+
4,
|
|
307
|
+
serverLoaderBuilder.build({
|
|
308
|
+
format: "cjs",
|
|
309
|
+
platform: "node",
|
|
310
|
+
target: "esnext",
|
|
311
|
+
loader: loader,
|
|
312
|
+
watch: isDevCommand() && {},
|
|
313
|
+
bundle: true,
|
|
314
|
+
logLevel: "error",
|
|
315
|
+
entryPoints: [
|
|
316
|
+
entry
|
|
317
|
+
],
|
|
318
|
+
outfile: outfile
|
|
319
|
+
})
|
|
320
|
+
];
|
|
321
|
+
case 1:
|
|
322
|
+
_state.sent();
|
|
323
|
+
return [
|
|
324
|
+
2
|
|
325
|
+
];
|
|
326
|
+
}
|
|
77
327
|
});
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
328
|
+
});
|
|
329
|
+
return function buildServerLoader(entry, outfile) {
|
|
330
|
+
return _ref.apply(this, arguments);
|
|
81
331
|
};
|
|
82
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
83
|
-
_loop();
|
|
84
|
-
}
|
|
85
|
-
} catch (err) {
|
|
86
|
-
_iterator2.e(err);
|
|
87
|
-
} finally {
|
|
88
|
-
_iterator2.f();
|
|
89
|
-
}
|
|
90
|
-
return deDuplicated.map(function (_ref) {
|
|
91
|
-
var value = _ref.value,
|
|
92
|
-
specifiers = _ref.specifiers,
|
|
93
|
-
initialize = _ref.initialize;
|
|
94
|
-
return "import ".concat(createImportSpecifier(specifiers), " from '").concat(value, "';\n").concat(initialize || '');
|
|
95
|
-
}).join('\n');
|
|
96
|
-
};
|
|
97
|
-
var buildLoader = /*#__PURE__*/function () {
|
|
98
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(entry, outfile) {
|
|
99
|
-
var command;
|
|
100
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
101
|
-
while (1) {
|
|
102
|
-
switch (_context.prev = _context.next) {
|
|
103
|
-
case 0:
|
|
104
|
-
command = getCommand();
|
|
105
|
-
_context.next = 3;
|
|
106
|
-
return esbuild.build({
|
|
107
|
-
format: 'esm',
|
|
108
|
-
platform: 'browser',
|
|
109
|
-
target: 'esnext',
|
|
110
|
-
loader: loader,
|
|
111
|
-
watch: command === 'dev' && {},
|
|
112
|
-
bundle: true,
|
|
113
|
-
logLevel: 'error',
|
|
114
|
-
entryPoints: [entry],
|
|
115
|
-
outfile: outfile,
|
|
116
|
-
plugins: [{
|
|
117
|
-
name: 'make-all-packages-external',
|
|
118
|
-
setup: function setup(build) {
|
|
119
|
-
// https://github.com/evanw/esbuild/issues/619#issuecomment-751995294
|
|
120
|
-
build.onResolve({
|
|
121
|
-
filter: EXTERNAL_REGEXP
|
|
122
|
-
}, function (args) {
|
|
123
|
-
var external = true;
|
|
124
|
-
// FIXME: windows external entrypoint
|
|
125
|
-
if (args.kind === 'entry-point') {
|
|
126
|
-
external = false;
|
|
127
|
-
}
|
|
128
|
-
return {
|
|
129
|
-
path: args.path,
|
|
130
|
-
external: external
|
|
131
|
-
};
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
}]
|
|
135
|
-
});
|
|
136
|
-
case 3:
|
|
137
|
-
case "end":
|
|
138
|
-
return _context.stop();
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}, _callee);
|
|
142
|
-
}));
|
|
143
|
-
return function buildLoader(_x, _x2) {
|
|
144
|
-
return _ref2.apply(this, arguments);
|
|
145
|
-
};
|
|
146
332
|
}();
|
|
147
|
-
var
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
switch (_context2.prev = _context2.next) {
|
|
153
|
-
case 0:
|
|
154
|
-
command = getCommand();
|
|
155
|
-
_context2.next = 3;
|
|
156
|
-
return esbuild.build({
|
|
157
|
-
format: 'cjs',
|
|
158
|
-
platform: 'node',
|
|
159
|
-
target: 'esnext',
|
|
160
|
-
loader: loader,
|
|
161
|
-
watch: command === 'dev' && {},
|
|
162
|
-
bundle: true,
|
|
163
|
-
logLevel: 'error',
|
|
164
|
-
entryPoints: [entry],
|
|
165
|
-
outfile: outfile
|
|
166
|
-
});
|
|
167
|
-
case 3:
|
|
168
|
-
case "end":
|
|
169
|
-
return _context2.stop();
|
|
333
|
+
var generateCode = function() {
|
|
334
|
+
var _ref = _asyncToGenerator(function(appContext, config, entrypoints, api) {
|
|
335
|
+
var ref, ref1, ref2, internalDirectory, distDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName, hookRunners, isV5, mountId, getRoutes;
|
|
336
|
+
function generateEntryCode(entrypoint) {
|
|
337
|
+
return _generateEntryCode.apply(this, arguments);
|
|
170
338
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
name: internalSrcAlias,
|
|
224
|
-
basename: srcDirectory
|
|
225
|
-
}, entrypoint.entryName);
|
|
226
|
-
case 10:
|
|
227
|
-
nestedRoute = _context3.sent;
|
|
228
|
-
if (nestedRoute) {
|
|
229
|
-
initialRoutes.unshift(nestedRoute);
|
|
230
|
-
}
|
|
231
|
-
_context3.next = 16;
|
|
232
|
-
break;
|
|
233
|
-
case 14:
|
|
234
|
-
logger.error('Nested routes is not supported in legacy mode.');
|
|
235
|
-
// eslint-disable-next-line no-process-exit
|
|
236
|
-
process.exit(1);
|
|
237
|
-
case 16:
|
|
238
|
-
_context3.next = 18;
|
|
239
|
-
return hookRunners.modifyFileSystemRoutes({
|
|
240
|
-
entrypoint: entrypoint,
|
|
241
|
-
routes: initialRoutes
|
|
242
|
-
});
|
|
243
|
-
case 18:
|
|
244
|
-
_yield$hookRunners$mo = _context3.sent;
|
|
245
|
-
routes = _yield$hookRunners$mo.routes;
|
|
246
|
-
_config = useResolvedConfigContext();
|
|
247
|
-
ssr = _config === null || _config === void 0 ? void 0 : _config.server.ssr;
|
|
248
|
-
if (ssr) {
|
|
249
|
-
mode = _typeof(ssr) === 'object' ? ssr.mode || 'string' : 'string';
|
|
250
|
-
} else {
|
|
251
|
-
mode = false;
|
|
252
|
-
}
|
|
253
|
-
if (mode === 'stream') {
|
|
254
|
-
hasPageRoute = routes.some(function (route) {
|
|
255
|
-
return 'type' in route && route.type === 'page';
|
|
256
|
-
});
|
|
257
|
-
if (hasPageRoute) {
|
|
258
|
-
logger.error('streaming ssr is not supported when pages dir exists');
|
|
259
|
-
// eslint-disable-next-line no-process-exit
|
|
339
|
+
function _generateEntryCode() {
|
|
340
|
+
_generateEntryCode = _asyncToGenerator(function(entrypoint) {
|
|
341
|
+
var entryName, isAutoMount, customBootstrap, fileSystemRoutes, initialRoutes, nestedRoute, routes, config2, ssr, mode, hasPageRoute, ref, code2, _, _tmp, routesServerFile, outputRoutesServerFile, code3, loaderEntryFile, loaderIndexFile, ref1, importStatements, plugins, ref2, renderFunction, exportStatement, code, entryFile, ref3, asyncEntryCode, bootstrapFile;
|
|
342
|
+
return __generator(this, function(_state) {
|
|
343
|
+
switch(_state.label){
|
|
344
|
+
case 0:
|
|
345
|
+
entryName = entrypoint.entryName, isAutoMount = entrypoint.isAutoMount, customBootstrap = entrypoint.customBootstrap, fileSystemRoutes = entrypoint.fileSystemRoutes;
|
|
346
|
+
if (!isAutoMount) return [
|
|
347
|
+
3,
|
|
348
|
+
22
|
|
349
|
+
];
|
|
350
|
+
if (!fileSystemRoutes) return [
|
|
351
|
+
3,
|
|
352
|
+
15
|
|
353
|
+
];
|
|
354
|
+
initialRoutes = [];
|
|
355
|
+
nestedRoute = null;
|
|
356
|
+
if (entrypoint.entry) {
|
|
357
|
+
initialRoutes = getRoutes({
|
|
358
|
+
entrypoint: entrypoint,
|
|
359
|
+
srcDirectory: srcDirectory,
|
|
360
|
+
srcAlias: internalSrcAlias,
|
|
361
|
+
internalDirectory: internalDirectory,
|
|
362
|
+
internalDirAlias: internalDirAlias
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
if (!entrypoint.nestedRoutesEntry) return [
|
|
366
|
+
3,
|
|
367
|
+
3
|
|
368
|
+
];
|
|
369
|
+
if (!!isV5) return [
|
|
370
|
+
3,
|
|
371
|
+
2
|
|
372
|
+
];
|
|
373
|
+
return [
|
|
374
|
+
4,
|
|
375
|
+
walk(entrypoint.nestedRoutesEntry, entrypoint.nestedRoutesEntry, {
|
|
376
|
+
name: internalSrcAlias,
|
|
377
|
+
basename: srcDirectory
|
|
378
|
+
}, entrypoint.entryName)
|
|
379
|
+
];
|
|
380
|
+
case 1:
|
|
381
|
+
nestedRoute = _state.sent();
|
|
382
|
+
if (nestedRoute) {
|
|
383
|
+
initialRoutes.unshift(nestedRoute);
|
|
384
|
+
}
|
|
385
|
+
return [
|
|
386
|
+
3,
|
|
387
|
+
3
|
|
388
|
+
];
|
|
389
|
+
case 2:
|
|
390
|
+
logger.error("Nested routes is not supported in legacy mode.");
|
|
260
391
|
process.exit(1);
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
392
|
+
_state.label = 3;
|
|
393
|
+
case 3:
|
|
394
|
+
return [
|
|
395
|
+
4,
|
|
396
|
+
hookRunners.modifyFileSystemRoutes({
|
|
397
|
+
entrypoint: entrypoint,
|
|
398
|
+
routes: initialRoutes
|
|
399
|
+
})
|
|
400
|
+
];
|
|
401
|
+
case 4:
|
|
402
|
+
routes = _state.sent().routes;
|
|
403
|
+
config2 = useResolvedConfigContext();
|
|
404
|
+
ssr = getEntryOptions(entryName, config2.server.ssr, config2.server.ssrByEntries, packageName);
|
|
405
|
+
if (ssr) {
|
|
406
|
+
mode = typeof ssr === "object" ? ssr.mode || "string" : "string";
|
|
407
|
+
} else {
|
|
408
|
+
mode = false;
|
|
409
|
+
}
|
|
410
|
+
if (mode === "stream") {
|
|
411
|
+
hasPageRoute = routes.some(function(route) {
|
|
412
|
+
return "type" in route && route.type === "page";
|
|
413
|
+
});
|
|
414
|
+
if (hasPageRoute) {
|
|
415
|
+
logger.error("Streaming ssr is not supported when pages dir exists");
|
|
416
|
+
process.exit(1);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
_ = hookRunners.beforeGenerateRoutes;
|
|
420
|
+
_tmp = {
|
|
421
|
+
entrypoint: entrypoint
|
|
422
|
+
};
|
|
423
|
+
return [
|
|
424
|
+
4,
|
|
425
|
+
templates.fileSystemRoutes({
|
|
426
|
+
routes: routes,
|
|
427
|
+
ssrMode: mode,
|
|
428
|
+
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
429
|
+
entryName: entrypoint.entryName,
|
|
430
|
+
internalDirectory: internalDirectory,
|
|
431
|
+
internalDirAlias: internalDirAlias
|
|
432
|
+
})
|
|
433
|
+
];
|
|
434
|
+
case 5:
|
|
435
|
+
return [
|
|
436
|
+
4,
|
|
437
|
+
_.apply(hookRunners, [
|
|
438
|
+
(_tmp.code = _state.sent(), _tmp)
|
|
439
|
+
])
|
|
440
|
+
];
|
|
441
|
+
case 6:
|
|
442
|
+
ref = _state.sent(), code2 = ref.code;
|
|
443
|
+
if (!entrypoint.nestedRoutesEntry) return [
|
|
444
|
+
3,
|
|
445
|
+
14
|
|
446
|
+
];
|
|
447
|
+
routesServerFile = path.join(internalDirectory, entryName, "route-server-loaders.js");
|
|
448
|
+
outputRoutesServerFile = path.join(distDirectory, LOADER_ROUTES_DIR, entryName, "index.js");
|
|
449
|
+
code3 = templates.routesForServer({
|
|
450
|
+
routes: routes,
|
|
451
|
+
internalDirectory: internalDirectory,
|
|
452
|
+
entryName: entryName
|
|
453
|
+
});
|
|
454
|
+
return [
|
|
455
|
+
4,
|
|
456
|
+
fs.ensureFile(routesServerFile)
|
|
457
|
+
];
|
|
458
|
+
case 7:
|
|
459
|
+
_state.sent();
|
|
460
|
+
return [
|
|
461
|
+
4,
|
|
462
|
+
fs.writeFile(routesServerFile, code3)
|
|
463
|
+
];
|
|
464
|
+
case 8:
|
|
465
|
+
_state.sent();
|
|
466
|
+
loaderEntryFile = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, "entry.js");
|
|
467
|
+
loaderIndexFile = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, "index.js");
|
|
468
|
+
return [
|
|
469
|
+
4,
|
|
470
|
+
fs.pathExists(loaderEntryFile)
|
|
471
|
+
];
|
|
472
|
+
case 9:
|
|
473
|
+
if (!_state.sent()) return [
|
|
474
|
+
3,
|
|
475
|
+
11
|
|
476
|
+
];
|
|
477
|
+
return [
|
|
478
|
+
4,
|
|
479
|
+
buildLoader(loaderEntryFile, loaderIndexFile)
|
|
480
|
+
];
|
|
481
|
+
case 10:
|
|
482
|
+
_state.sent();
|
|
483
|
+
_state.label = 11;
|
|
484
|
+
case 11:
|
|
485
|
+
return [
|
|
486
|
+
4,
|
|
487
|
+
fs.pathExists(routesServerFile)
|
|
488
|
+
];
|
|
489
|
+
case 12:
|
|
490
|
+
if (!_state.sent()) return [
|
|
491
|
+
3,
|
|
492
|
+
14
|
|
493
|
+
];
|
|
494
|
+
return [
|
|
495
|
+
4,
|
|
496
|
+
buildServerLoader(routesServerFile, outputRoutesServerFile)
|
|
497
|
+
];
|
|
498
|
+
case 13:
|
|
499
|
+
_state.sent();
|
|
500
|
+
_state.label = 14;
|
|
501
|
+
case 14:
|
|
502
|
+
fs.outputFileSync(path.resolve(internalDirectory, "./".concat(entryName, "/").concat(FILE_SYSTEM_ROUTES_FILE_NAME)), code2, "utf8");
|
|
503
|
+
_state.label = 15;
|
|
504
|
+
case 15:
|
|
505
|
+
return [
|
|
506
|
+
4,
|
|
507
|
+
hookRunners.modifyEntryImports({
|
|
508
|
+
entrypoint: entrypoint,
|
|
509
|
+
imports: getDefaultImports({
|
|
510
|
+
entrypoint: entrypoint,
|
|
511
|
+
srcDirectory: srcDirectory,
|
|
512
|
+
internalSrcAlias: internalSrcAlias,
|
|
513
|
+
internalDirAlias: internalDirAlias,
|
|
514
|
+
internalDirectory: internalDirectory
|
|
515
|
+
})
|
|
516
|
+
})
|
|
517
|
+
];
|
|
518
|
+
case 16:
|
|
519
|
+
ref1 = _state.sent(), importStatements = ref1.imports;
|
|
520
|
+
return [
|
|
521
|
+
4,
|
|
522
|
+
hookRunners.modifyEntryRuntimePlugins({
|
|
523
|
+
entrypoint: entrypoint,
|
|
524
|
+
plugins: []
|
|
525
|
+
})
|
|
526
|
+
];
|
|
527
|
+
case 17:
|
|
528
|
+
plugins = _state.sent().plugins;
|
|
529
|
+
return [
|
|
530
|
+
4,
|
|
531
|
+
hookRunners.modifyEntryRenderFunction({
|
|
532
|
+
entrypoint: entrypoint,
|
|
533
|
+
code: templates.renderFunction({
|
|
534
|
+
plugins: plugins,
|
|
535
|
+
customBootstrap: customBootstrap,
|
|
536
|
+
fileSystemRoutes: fileSystemRoutes
|
|
537
|
+
})
|
|
538
|
+
})
|
|
539
|
+
];
|
|
540
|
+
case 18:
|
|
541
|
+
ref2 = _state.sent(), renderFunction = ref2.code;
|
|
542
|
+
return [
|
|
543
|
+
4,
|
|
544
|
+
hookRunners.modifyEntryExport({
|
|
545
|
+
entrypoint: entrypoint,
|
|
546
|
+
exportStatement: "export default AppWrapper;"
|
|
547
|
+
})
|
|
548
|
+
];
|
|
549
|
+
case 19:
|
|
550
|
+
exportStatement = _state.sent().exportStatement;
|
|
551
|
+
code = templates.index({
|
|
552
|
+
mountId: mountId,
|
|
553
|
+
imports: createImportStatements(importStatements),
|
|
554
|
+
renderFunction: renderFunction,
|
|
555
|
+
exportStatement: exportStatement
|
|
556
|
+
});
|
|
557
|
+
entryFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_POINT_FILE_NAME));
|
|
558
|
+
entrypoint.entry = entryFile;
|
|
559
|
+
if (!config.source.enableAsyncEntry) return [
|
|
560
|
+
3,
|
|
561
|
+
21
|
|
562
|
+
];
|
|
563
|
+
return [
|
|
564
|
+
4,
|
|
565
|
+
hookRunners.modifyAsyncEntry({
|
|
566
|
+
entrypoint: entrypoint,
|
|
567
|
+
code: "import('./".concat(ENTRY_BOOTSTRAP_FILE_NAME, "');")
|
|
568
|
+
})
|
|
569
|
+
];
|
|
570
|
+
case 20:
|
|
571
|
+
ref3 = _state.sent(), asyncEntryCode = ref3.code;
|
|
572
|
+
fs.outputFileSync(entryFile, asyncEntryCode, "utf8");
|
|
573
|
+
bootstrapFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_BOOTSTRAP_FILE_NAME));
|
|
574
|
+
fs.outputFileSync(bootstrapFile, code, "utf8");
|
|
575
|
+
return [
|
|
576
|
+
3,
|
|
577
|
+
22
|
|
578
|
+
];
|
|
579
|
+
case 21:
|
|
580
|
+
fs.outputFileSync(entryFile, code, "utf8");
|
|
581
|
+
_state.label = 22;
|
|
582
|
+
case 22:
|
|
583
|
+
return [
|
|
584
|
+
2
|
|
585
|
+
];
|
|
399
586
|
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
return _generateEntryCode.apply(this, arguments);
|
|
404
|
-
};
|
|
405
|
-
generateEntryCode = function _generateEntryCode2(_x9) {
|
|
406
|
-
return _generateEntryCode.apply(this, arguments);
|
|
407
|
-
};
|
|
408
|
-
internalDirectory = appContext.internalDirectory, distDirectory = appContext.distDirectory, srcDirectory = appContext.srcDirectory, internalDirAlias = appContext.internalDirAlias, internalSrcAlias = appContext.internalSrcAlias;
|
|
409
|
-
hookRunners = api.useHookRunners();
|
|
410
|
-
islegacy = Boolean(config === null || config === void 0 ? void 0 : (_config$runtime = config.runtime) === null || _config$runtime === void 0 ? void 0 : (_config$runtime$route = _config$runtime.router) === null || _config$runtime$route === void 0 ? void 0 : _config$runtime$route.legacy);
|
|
411
|
-
mountId = config.html.mountId;
|
|
412
|
-
getRoutes = islegacy ? getClientRoutesLegacy : getClientRoutes;
|
|
413
|
-
_context4.next = 9;
|
|
414
|
-
return Promise.all(entrypoints.map(generateEntryCode));
|
|
415
|
-
case 9:
|
|
416
|
-
case "end":
|
|
417
|
-
return _context4.stop();
|
|
587
|
+
});
|
|
588
|
+
});
|
|
589
|
+
return _generateEntryCode.apply(this, arguments);
|
|
418
590
|
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
591
|
+
return __generator(this, function(_state) {
|
|
592
|
+
switch(_state.label){
|
|
593
|
+
case 0:
|
|
594
|
+
internalDirectory = appContext.internalDirectory, distDirectory = appContext.distDirectory, srcDirectory = appContext.srcDirectory, internalDirAlias = appContext.internalDirAlias, internalSrcAlias = appContext.internalSrcAlias, packageName = appContext.packageName;
|
|
595
|
+
hookRunners = api.useHookRunners();
|
|
596
|
+
isV5 = typeof ((ref = config.runtime) === null || ref === void 0 ? void 0 : ref.router) !== "boolean" && (config === null || config === void 0 ? void 0 : (ref1 = config.runtime) === null || ref1 === void 0 ? void 0 : (ref2 = ref1.router) === null || ref2 === void 0 ? void 0 : ref2.mode) === "react-router-5";
|
|
597
|
+
mountId = config.html.mountId;
|
|
598
|
+
getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
|
|
599
|
+
return [
|
|
600
|
+
4,
|
|
601
|
+
Promise.all(entrypoints.map(generateEntryCode))
|
|
602
|
+
];
|
|
603
|
+
case 1:
|
|
604
|
+
_state.sent();
|
|
605
|
+
return [
|
|
606
|
+
2
|
|
607
|
+
];
|
|
608
|
+
}
|
|
609
|
+
});
|
|
610
|
+
});
|
|
611
|
+
return function generateCode(appContext, config, entrypoints, api) {
|
|
612
|
+
return _ref.apply(this, arguments);
|
|
613
|
+
};
|
|
614
|
+
}();
|
|
615
|
+
export { createImportStatements, generateCode };
|