@modern-js/app-tools 2.10.0 → 2.10.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/builder/index.js +3 -1
- package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +11 -3
- package/dist/cjs/commands/serve.js +9 -2
- package/dist/esm/builder/index.js +15 -8
- package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +12 -4
- package/dist/esm/commands/serve.js +59 -2
- package/dist/esm-node/builder/index.js +3 -1
- package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +12 -9
- package/dist/esm-node/commands/serve.js +9 -2
- package/dist/js/modern/analyze/constants.js +54 -0
- package/dist/js/modern/analyze/generateCode.js +247 -0
- package/dist/js/modern/analyze/getBundleEntry.js +71 -0
- package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +220 -0
- package/dist/js/modern/analyze/getClientRoutes/getRoutesLegacy.js +216 -0
- package/dist/js/modern/analyze/getClientRoutes/index.js +6 -0
- package/dist/js/modern/analyze/getClientRoutes/utils.js +31 -0
- package/dist/js/modern/analyze/getFileSystemEntry.js +109 -0
- package/dist/js/modern/analyze/getHtmlTemplate.js +115 -0
- package/dist/js/modern/analyze/getServerRoutes.js +175 -0
- package/dist/js/modern/analyze/index.js +332 -0
- package/dist/js/modern/analyze/isDefaultExportFunction.js +42 -0
- package/dist/js/modern/analyze/makeLegalIdentifier.js +13 -0
- package/dist/js/modern/analyze/nestedRoutes.js +157 -0
- package/dist/js/modern/analyze/templates.js +334 -0
- package/dist/js/modern/analyze/utils.js +141 -0
- package/dist/js/modern/builder/builderPlugins/compatModern.js +233 -0
- package/dist/js/modern/builder/index.js +159 -0
- 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 +46 -0
- package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +30 -0
- package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +37 -0
- package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +113 -0
- package/dist/js/modern/commands/build.js +91 -0
- package/dist/js/modern/commands/deploy.js +28 -0
- package/dist/js/modern/commands/dev.js +109 -0
- package/dist/js/modern/commands/index.js +3 -0
- package/dist/js/modern/commands/inspect.js +38 -0
- package/dist/js/modern/commands/serve.js +54 -0
- package/dist/js/modern/config/default.js +175 -0
- package/dist/js/modern/config/index.js +8 -0
- package/dist/js/modern/config/initial/createHtmlConfig.js +35 -0
- package/dist/js/modern/config/initial/createOutputConfig.js +68 -0
- package/dist/js/modern/config/initial/createSourceConfig.js +39 -0
- package/dist/js/modern/config/initial/createToolsConfig.js +42 -0
- package/dist/js/modern/config/initial/index.js +16 -0
- package/dist/js/modern/config/initial/inits.js +152 -0
- package/dist/js/modern/config/initial/transformNormalizedConfig.js +47 -0
- package/dist/js/modern/defineConfig.js +27 -0
- package/dist/js/modern/exports/server.js +4 -0
- package/dist/js/modern/hooks.js +35 -0
- package/dist/js/modern/index.js +211 -0
- package/dist/js/modern/initialize/index.js +124 -0
- package/dist/js/modern/locale/en.js +36 -0
- package/dist/js/modern/locale/index.js +9 -0
- package/dist/js/modern/locale/zh.js +36 -0
- package/dist/js/modern/schema/Schema.js +40 -0
- package/dist/js/modern/schema/index.js +88 -0
- package/dist/js/modern/schema/legacy.js +148 -0
- package/dist/js/modern/types/config/deploy.js +0 -0
- package/dist/js/modern/types/config/dev.js +0 -0
- package/dist/js/modern/types/config/experiments.js +0 -0
- package/dist/js/modern/types/config/html.js +0 -0
- package/dist/js/modern/types/config/index.js +1 -0
- package/dist/js/modern/types/config/output.js +0 -0
- package/dist/js/modern/types/config/performance.js +0 -0
- package/dist/js/modern/types/config/security.js +0 -0
- package/dist/js/modern/types/config/source.js +0 -0
- package/dist/js/modern/types/config/tools.js +0 -0
- package/dist/js/modern/types/hooks.js +0 -0
- package/dist/js/modern/types/index.js +3 -0
- package/dist/js/modern/types/legacyConfig/deploy.js +0 -0
- package/dist/js/modern/types/legacyConfig/dev.js +0 -0
- package/dist/js/modern/types/legacyConfig/index.js +0 -0
- package/dist/js/modern/types/legacyConfig/output.js +0 -0
- package/dist/js/modern/types/legacyConfig/source.js +0 -0
- package/dist/js/modern/types/legacyConfig/tools.js +0 -0
- package/dist/js/modern/utils/config.js +128 -0
- package/dist/js/modern/utils/createServer.js +75 -0
- package/dist/js/modern/utils/env.js +15 -0
- package/dist/js/modern/utils/generateWatchFiles.js +55 -0
- package/dist/js/modern/utils/getSelectedEntries.js +58 -0
- package/dist/js/modern/utils/getServerInternalPlugins.js +58 -0
- package/dist/js/modern/utils/language.js +8 -0
- package/dist/js/modern/utils/printInstructions.js +31 -0
- package/dist/js/modern/utils/restart.js +44 -0
- package/dist/js/modern/utils/routes.js +30 -0
- package/dist/js/modern/utils/types.js +0 -0
- package/dist/js/node/analyze/constants.js +98 -0
- package/dist/js/node/analyze/generateCode.js +271 -0
- package/dist/js/node/analyze/getBundleEntry.js +95 -0
- package/dist/js/node/analyze/getClientRoutes/getRoutes.js +242 -0
- package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +238 -0
- package/dist/js/node/analyze/getClientRoutes/index.js +30 -0
- package/dist/js/node/analyze/getClientRoutes/utils.js +58 -0
- package/dist/js/node/analyze/getFileSystemEntry.js +131 -0
- package/dist/js/node/analyze/getHtmlTemplate.js +144 -0
- package/dist/js/node/analyze/getServerRoutes.js +194 -0
- package/dist/js/node/analyze/index.js +339 -0
- package/dist/js/node/analyze/isDefaultExportFunction.js +71 -0
- package/dist/js/node/analyze/makeLegalIdentifier.js +36 -0
- package/dist/js/node/analyze/nestedRoutes.js +184 -0
- package/dist/js/node/analyze/templates.js +365 -0
- package/dist/js/node/analyze/utils.js +172 -0
- package/dist/js/node/builder/builderPlugins/compatModern.js +258 -0
- package/dist/js/node/builder/index.js +177 -0
- package/dist/js/node/builder/loaders/routerLoader.js +38 -0
- package/dist/js/node/builder/loaders/serverModuleLoader.js +28 -0
- package/dist/js/node/builder/share.js +75 -0
- package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +53 -0
- package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +60 -0
- package/dist/js/node/builder/webpackPlugins/routerPlugin.js +135 -0
- package/dist/js/node/commands/build.js +112 -0
- package/dist/js/node/commands/deploy.js +51 -0
- package/dist/js/node/commands/dev.js +126 -0
- package/dist/js/node/commands/index.js +19 -0
- package/dist/js/node/commands/inspect.js +61 -0
- package/dist/js/node/commands/serve.js +83 -0
- package/dist/js/node/config/default.js +197 -0
- package/dist/js/node/config/index.js +34 -0
- package/dist/js/node/config/initial/createHtmlConfig.js +58 -0
- package/dist/js/node/config/initial/createOutputConfig.js +91 -0
- package/dist/js/node/config/initial/createSourceConfig.js +62 -0
- package/dist/js/node/config/initial/createToolsConfig.js +65 -0
- package/dist/js/node/config/initial/index.js +41 -0
- package/dist/js/node/config/initial/inits.js +175 -0
- package/dist/js/node/config/initial/transformNormalizedConfig.js +70 -0
- package/dist/js/node/defineConfig.js +49 -0
- package/dist/js/node/exports/server.js +27 -0
- package/dist/js/node/hooks.js +54 -0
- package/dist/js/node/index.js +235 -0
- package/dist/js/node/initialize/index.js +134 -0
- package/dist/js/node/locale/en.js +59 -0
- package/dist/js/node/locale/index.js +33 -0
- package/dist/js/node/locale/zh.js +59 -0
- package/dist/js/node/schema/Schema.js +63 -0
- package/dist/js/node/schema/index.js +118 -0
- package/dist/js/node/schema/legacy.js +169 -0
- 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 -0
- 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 -0
- 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 -0
- 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/config.js +153 -0
- package/dist/js/node/utils/createServer.js +106 -0
- package/dist/js/node/utils/env.js +38 -0
- package/dist/js/node/utils/generateWatchFiles.js +85 -0
- package/dist/js/node/utils/getSelectedEntries.js +81 -0
- package/dist/js/node/utils/getServerInternalPlugins.js +79 -0
- package/dist/js/node/utils/language.js +31 -0
- package/dist/js/node/utils/printInstructions.js +54 -0
- package/dist/js/node/utils/restart.js +67 -0
- package/dist/js/node/utils/routes.js +59 -0
- package/dist/js/node/utils/types.js +15 -0
- package/dist/js/treeshaking/analyze/constants.js +40 -0
- package/dist/js/treeshaking/analyze/generateCode.js +485 -0
- package/dist/js/treeshaking/analyze/getBundleEntry.js +62 -0
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +233 -0
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +231 -0
- package/dist/js/treeshaking/analyze/getClientRoutes/index.js +3 -0
- package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +23 -0
- package/dist/js/treeshaking/analyze/getFileSystemEntry.js +107 -0
- package/dist/js/treeshaking/analyze/getHtmlTemplate.js +302 -0
- package/dist/js/treeshaking/analyze/getServerRoutes.js +222 -0
- package/dist/js/treeshaking/analyze/index.js +697 -0
- package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +47 -0
- package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +13 -0
- package/dist/js/treeshaking/analyze/nestedRoutes.js +384 -0
- package/dist/js/treeshaking/analyze/templates.js +468 -0
- package/dist/js/treeshaking/analyze/utils.js +374 -0
- package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +304 -0
- package/dist/js/treeshaking/builder/index.js +374 -0
- 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 +40 -0
- package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +110 -0
- package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +72 -0
- package/dist/js/treeshaking/builder/webpackPlugins/routerPlugin.js +343 -0
- package/dist/js/treeshaking/commands/build.js +291 -0
- package/dist/js/treeshaking/commands/deploy.js +154 -0
- package/dist/js/treeshaking/commands/dev.js +301 -0
- package/dist/js/treeshaking/commands/index.js +3 -0
- package/dist/js/treeshaking/commands/inspect.js +149 -0
- package/dist/js/treeshaking/commands/serve.js +199 -0
- package/dist/js/treeshaking/config/default.js +210 -0
- package/dist/js/treeshaking/config/index.js +3 -0
- package/dist/js/treeshaking/config/initial/createHtmlConfig.js +19 -0
- package/dist/js/treeshaking/config/initial/createOutputConfig.js +41 -0
- package/dist/js/treeshaking/config/initial/createSourceConfig.js +42 -0
- package/dist/js/treeshaking/config/initial/createToolsConfig.js +23 -0
- package/dist/js/treeshaking/config/initial/index.js +12 -0
- package/dist/js/treeshaking/config/initial/inits.js +209 -0
- package/dist/js/treeshaking/config/initial/transformNormalizedConfig.js +35 -0
- package/dist/js/treeshaking/defineConfig.js +61 -0
- package/dist/js/treeshaking/exports/server.js +2 -0
- package/dist/js/treeshaking/hooks.js +29 -0
- package/dist/js/treeshaking/index.js +706 -0
- package/dist/js/treeshaking/initialize/index.js +276 -0
- package/dist/js/treeshaking/locale/en.js +38 -0
- package/dist/js/treeshaking/locale/index.js +9 -0
- package/dist/js/treeshaking/locale/zh.js +38 -0
- package/dist/js/treeshaking/schema/Schema.js +273 -0
- package/dist/js/treeshaking/schema/index.js +181 -0
- package/dist/js/treeshaking/schema/legacy.js +337 -0
- 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 +1 -0
- 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 +3 -0
- 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 -0
- 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/config.js +302 -0
- package/dist/js/treeshaking/utils/createServer.js +258 -0
- package/dist/js/treeshaking/utils/env.js +13 -0
- package/dist/js/treeshaking/utils/generateWatchFiles.js +214 -0
- package/dist/js/treeshaking/utils/getSelectedEntries.js +186 -0
- package/dist/js/treeshaking/utils/getServerInternalPlugins.js +210 -0
- package/dist/js/treeshaking/utils/language.js +6 -0
- package/dist/js/treeshaking/utils/printInstructions.js +152 -0
- package/dist/js/treeshaking/utils/restart.js +187 -0
- package/dist/js/treeshaking/utils/routes.js +153 -0
- package/dist/js/treeshaking/utils/types.js +1 -0
- package/package.json +9 -9
|
@@ -31,11 +31,13 @@ __export(builder_exports, {
|
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(builder_exports);
|
|
33
33
|
var import_utils = require("@modern-js/utils");
|
|
34
|
+
var import_builder_rspack_provider = require("@modern-js/builder-rspack-provider");
|
|
34
35
|
async function createBuilderGenerator(bundler) {
|
|
35
36
|
if (bundler === "rspack") {
|
|
36
37
|
try {
|
|
37
38
|
const { createRspackBuilderForModern } = await Promise.resolve().then(() => __toESM(require("./builder-rspack")));
|
|
38
|
-
|
|
39
|
+
const version = await (0, import_builder_rspack_provider.getRspackVersion)();
|
|
40
|
+
import_utils.logger.info(`Using Rspack v${version} 🦀`);
|
|
39
41
|
return createRspackBuilderForModern;
|
|
40
42
|
} catch (_) {
|
|
41
43
|
throw new Error(
|
|
@@ -32,6 +32,8 @@ __export(RouterPlugin_exports, {
|
|
|
32
32
|
module.exports = __toCommonJS(RouterPlugin_exports);
|
|
33
33
|
var import_path = __toESM(require("path"));
|
|
34
34
|
var import_utils = require("@modern-js/utils");
|
|
35
|
+
var import_constants = require("@modern-js/utils/constants");
|
|
36
|
+
var import_constants2 = require("@modern-js/utils/universal/constants");
|
|
35
37
|
const PLUGIN_NAME = "ModernjsRoutePlugin";
|
|
36
38
|
class RouterPlugin {
|
|
37
39
|
apply(compiler) {
|
|
@@ -66,7 +68,8 @@ class RouterPlugin {
|
|
|
66
68
|
publicPath: true,
|
|
67
69
|
assets: true,
|
|
68
70
|
chunkGroups: true,
|
|
69
|
-
chunks: true
|
|
71
|
+
chunks: true,
|
|
72
|
+
ids: true
|
|
70
73
|
});
|
|
71
74
|
const { publicPath, chunks = [] } = stats;
|
|
72
75
|
const routeAssets = {};
|
|
@@ -92,7 +95,12 @@ class RouterPlugin {
|
|
|
92
95
|
};
|
|
93
96
|
const injectedContent = `
|
|
94
97
|
;(function(){
|
|
95
|
-
window.${
|
|
98
|
+
window.${import_constants2.ROUTE_MANIFEST} = ${JSON.stringify(manifest, (k, v) => {
|
|
99
|
+
if (k === "assets") {
|
|
100
|
+
return void 0;
|
|
101
|
+
}
|
|
102
|
+
return v;
|
|
103
|
+
})};
|
|
96
104
|
})();
|
|
97
105
|
`;
|
|
98
106
|
const entrypointsArray = Array.from(
|
|
@@ -122,7 +130,7 @@ class RouterPlugin {
|
|
|
122
130
|
void 0
|
|
123
131
|
);
|
|
124
132
|
}
|
|
125
|
-
const filename = import_path.default.join(outputPath,
|
|
133
|
+
const filename = import_path.default.join(outputPath, import_constants.ROUTE_MANIFEST_FILE);
|
|
126
134
|
await import_utils.fs.ensureFile(filename);
|
|
127
135
|
await import_utils.fs.writeFile(filename, JSON.stringify(manifest, null, 2));
|
|
128
136
|
}
|
|
@@ -36,7 +36,7 @@ var import_printInstructions = require("../utils/printInstructions");
|
|
|
36
36
|
var import_createServer = require("../utils/createServer");
|
|
37
37
|
var import_getServerInternalPlugins = require("../utils/getServerInternalPlugins");
|
|
38
38
|
const start = async (api) => {
|
|
39
|
-
var _a;
|
|
39
|
+
var _a, _b;
|
|
40
40
|
const appContext = api.useAppContext();
|
|
41
41
|
const userConfig = api.useResolvedConfigContext();
|
|
42
42
|
const hookRunners = api.useHookRunners();
|
|
@@ -49,7 +49,14 @@ const start = async (api) => {
|
|
|
49
49
|
const serverInternalPlugins = await (0, import_getServerInternalPlugins.getServerInternalPlugins)(api);
|
|
50
50
|
const app = await (0, import_prod_server.default)({
|
|
51
51
|
pwd: appDirectory,
|
|
52
|
-
config:
|
|
52
|
+
config: {
|
|
53
|
+
...userConfig,
|
|
54
|
+
dev: userConfig.dev,
|
|
55
|
+
output: {
|
|
56
|
+
path: (_b = userConfig.output.distPath) == null ? void 0 : _b.root,
|
|
57
|
+
...userConfig.output || {}
|
|
58
|
+
}
|
|
59
|
+
},
|
|
53
60
|
appContext: {
|
|
54
61
|
sharedDirectory: (0, import_utils.getTargetDir)(
|
|
55
62
|
appContext.sharedDirectory,
|
|
@@ -123,26 +123,27 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
123
123
|
}
|
|
124
124
|
};
|
|
125
125
|
import { logger } from "@modern-js/utils";
|
|
126
|
+
import { getRspackVersion } from "@modern-js/builder-rspack-provider";
|
|
126
127
|
function createBuilderGenerator(bundler) {
|
|
127
128
|
return _createBuilderGenerator.apply(this, arguments);
|
|
128
129
|
}
|
|
129
130
|
function _createBuilderGenerator() {
|
|
130
131
|
_createBuilderGenerator = _asyncToGenerator(function(bundler) {
|
|
131
|
-
var createRspackBuilderForModern, _, createWebpackBuilderForModern;
|
|
132
|
+
var createRspackBuilderForModern, version, _, createWebpackBuilderForModern;
|
|
132
133
|
return __generator(this, function(_state) {
|
|
133
134
|
switch(_state.label){
|
|
134
135
|
case 0:
|
|
135
136
|
if (!(bundler === "rspack")) return [
|
|
136
137
|
3,
|
|
137
|
-
|
|
138
|
+
5
|
|
138
139
|
];
|
|
139
140
|
_state.label = 1;
|
|
140
141
|
case 1:
|
|
141
142
|
_state.trys.push([
|
|
142
143
|
1,
|
|
143
|
-
|
|
144
|
+
4,
|
|
144
145
|
,
|
|
145
|
-
|
|
146
|
+
5
|
|
146
147
|
]);
|
|
147
148
|
return [
|
|
148
149
|
4,
|
|
@@ -150,20 +151,26 @@ function _createBuilderGenerator() {
|
|
|
150
151
|
];
|
|
151
152
|
case 2:
|
|
152
153
|
createRspackBuilderForModern = _state.sent().createRspackBuilderForModern;
|
|
153
|
-
|
|
154
|
+
return [
|
|
155
|
+
4,
|
|
156
|
+
getRspackVersion()
|
|
157
|
+
];
|
|
158
|
+
case 3:
|
|
159
|
+
version = _state.sent();
|
|
160
|
+
logger.info("Using Rspack v".concat(version, " \uD83E\uDD80"));
|
|
154
161
|
return [
|
|
155
162
|
2,
|
|
156
163
|
createRspackBuilderForModern
|
|
157
164
|
];
|
|
158
|
-
case
|
|
165
|
+
case 4:
|
|
159
166
|
_ = _state.sent();
|
|
160
167
|
throw new Error("Failed to use Rspack, please check if you have `@modern-js/builder-rspack-provider` installed");
|
|
161
|
-
case
|
|
168
|
+
case 5:
|
|
162
169
|
return [
|
|
163
170
|
4,
|
|
164
171
|
import("./builder-webpack")
|
|
165
172
|
];
|
|
166
|
-
case
|
|
173
|
+
case 6:
|
|
167
174
|
createWebpackBuilderForModern = _state.sent().createWebpackBuilderForModern;
|
|
168
175
|
return [
|
|
169
176
|
2,
|
|
@@ -200,7 +200,9 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
200
200
|
}
|
|
201
201
|
};
|
|
202
202
|
import path from "path";
|
|
203
|
-
import { fs,
|
|
203
|
+
import { fs, logger } from "@modern-js/utils";
|
|
204
|
+
import { ROUTE_MANIFEST_FILE } from "@modern-js/utils/constants";
|
|
205
|
+
import { ROUTE_MANIFEST } from "@modern-js/utils/universal/constants";
|
|
204
206
|
var PLUGIN_NAME = "ModernjsRoutePlugin";
|
|
205
207
|
var RouterPlugin = /*#__PURE__*/ function() {
|
|
206
208
|
"use strict";
|
|
@@ -244,7 +246,8 @@ var RouterPlugin = /*#__PURE__*/ function() {
|
|
|
244
246
|
publicPath: true,
|
|
245
247
|
assets: true,
|
|
246
248
|
chunkGroups: true,
|
|
247
|
-
chunks: true
|
|
249
|
+
chunks: true,
|
|
250
|
+
ids: true
|
|
248
251
|
});
|
|
249
252
|
publicPath = stats.publicPath, _stats_chunks = stats.chunks, chunks = _stats_chunks === void 0 ? [] : _stats_chunks;
|
|
250
253
|
routeAssets = {};
|
|
@@ -285,7 +288,12 @@ var RouterPlugin = /*#__PURE__*/ function() {
|
|
|
285
288
|
manifest = {
|
|
286
289
|
routeAssets: routeAssets
|
|
287
290
|
};
|
|
288
|
-
injectedContent = "\n ;(function(){\n window.".concat(ROUTE_MANIFEST, " = ").concat(JSON.stringify(manifest
|
|
291
|
+
injectedContent = "\n ;(function(){\n window.".concat(ROUTE_MANIFEST, " = ").concat(JSON.stringify(manifest, function(k, v) {
|
|
292
|
+
if (k === "assets") {
|
|
293
|
+
return void 0;
|
|
294
|
+
}
|
|
295
|
+
return v;
|
|
296
|
+
}), ";\n })();\n ");
|
|
289
297
|
entrypointsArray = Array.from(compilation.entrypoints.entries());
|
|
290
298
|
entryChunkIds = entrypointsArray.map(function(entrypoint) {
|
|
291
299
|
return entrypoint[0];
|
|
@@ -328,7 +336,7 @@ var RouterPlugin = /*#__PURE__*/ function() {
|
|
|
328
336
|
}
|
|
329
337
|
}
|
|
330
338
|
}
|
|
331
|
-
filename = path.join(outputPath,
|
|
339
|
+
filename = path.join(outputPath, ROUTE_MANIFEST_FILE);
|
|
332
340
|
return [
|
|
333
341
|
4,
|
|
334
342
|
fs.ensureFile(filename)
|
|
@@ -27,6 +27,58 @@ function _asyncToGenerator(fn) {
|
|
|
27
27
|
});
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
+
function _defineProperty(obj, key, value) {
|
|
31
|
+
if (key in obj) {
|
|
32
|
+
Object.defineProperty(obj, key, {
|
|
33
|
+
value: value,
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true
|
|
37
|
+
});
|
|
38
|
+
} else {
|
|
39
|
+
obj[key] = value;
|
|
40
|
+
}
|
|
41
|
+
return obj;
|
|
42
|
+
}
|
|
43
|
+
function _objectSpread(target) {
|
|
44
|
+
for(var i = 1; i < arguments.length; i++){
|
|
45
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
46
|
+
var ownKeys = Object.keys(source);
|
|
47
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
48
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
49
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
ownKeys.forEach(function(key) {
|
|
53
|
+
_defineProperty(target, key, source[key]);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return target;
|
|
57
|
+
}
|
|
58
|
+
function ownKeys(object, enumerableOnly) {
|
|
59
|
+
var keys = Object.keys(object);
|
|
60
|
+
if (Object.getOwnPropertySymbols) {
|
|
61
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
62
|
+
if (enumerableOnly) {
|
|
63
|
+
symbols = symbols.filter(function(sym) {
|
|
64
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
keys.push.apply(keys, symbols);
|
|
68
|
+
}
|
|
69
|
+
return keys;
|
|
70
|
+
}
|
|
71
|
+
function _objectSpreadProps(target, source) {
|
|
72
|
+
source = source != null ? source : {};
|
|
73
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
74
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
75
|
+
} else {
|
|
76
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
77
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return target;
|
|
81
|
+
}
|
|
30
82
|
var __generator = this && this.__generator || function(thisArg, body) {
|
|
31
83
|
var f, y, t, g, _ = {
|
|
32
84
|
label: 0,
|
|
@@ -129,7 +181,7 @@ import { injectDataLoaderPlugin } from "../utils/createServer";
|
|
|
129
181
|
import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
|
|
130
182
|
var start = function() {
|
|
131
183
|
var _ref = _asyncToGenerator(function(api) {
|
|
132
|
-
var _userConfig_source, appContext, userConfig, hookRunners, appDirectory, port, serverConfigFile, apiOnly, serverInternalPlugins, app;
|
|
184
|
+
var _userConfig_source, _userConfig_output_distPath, appContext, userConfig, hookRunners, appDirectory, port, serverConfigFile, apiOnly, serverInternalPlugins, app;
|
|
133
185
|
return __generator(this, function(_state) {
|
|
134
186
|
switch(_state.label){
|
|
135
187
|
case 0:
|
|
@@ -154,7 +206,12 @@ var start = function() {
|
|
|
154
206
|
4,
|
|
155
207
|
server({
|
|
156
208
|
pwd: appDirectory,
|
|
157
|
-
config: userConfig,
|
|
209
|
+
config: _objectSpreadProps(_objectSpread({}, userConfig), {
|
|
210
|
+
dev: userConfig.dev,
|
|
211
|
+
output: _objectSpread({
|
|
212
|
+
path: (_userConfig_output_distPath = userConfig.output.distPath) === null || _userConfig_output_distPath === void 0 ? void 0 : _userConfig_output_distPath.root
|
|
213
|
+
}, userConfig.output || {})
|
|
214
|
+
}),
|
|
158
215
|
appContext: {
|
|
159
216
|
sharedDirectory: getTargetDir(appContext.sharedDirectory, appContext.appDirectory, appContext.distDirectory),
|
|
160
217
|
apiDirectory: getTargetDir(appContext.apiDirectory, appContext.appDirectory, appContext.distDirectory),
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { logger } from "@modern-js/utils";
|
|
2
|
+
import { getRspackVersion } from "@modern-js/builder-rspack-provider";
|
|
2
3
|
async function createBuilderGenerator(bundler) {
|
|
3
4
|
if (bundler === "rspack") {
|
|
4
5
|
try {
|
|
5
6
|
const { createRspackBuilderForModern } = await import("./builder-rspack");
|
|
6
|
-
|
|
7
|
+
const version = await getRspackVersion();
|
|
8
|
+
logger.info(`Using Rspack v${version} 🦀`);
|
|
7
9
|
return createRspackBuilderForModern;
|
|
8
10
|
} catch (_) {
|
|
9
11
|
throw new Error(
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
logger,
|
|
6
|
-
ROUTE_MINIFEST_FILE
|
|
7
|
-
} from "@modern-js/utils";
|
|
2
|
+
import { fs, logger } from "@modern-js/utils";
|
|
3
|
+
import { ROUTE_MANIFEST_FILE } from "@modern-js/utils/constants";
|
|
4
|
+
import { ROUTE_MANIFEST } from "@modern-js/utils/universal/constants";
|
|
8
5
|
const PLUGIN_NAME = "ModernjsRoutePlugin";
|
|
9
6
|
class RouterPlugin {
|
|
10
7
|
apply(compiler) {
|
|
@@ -39,7 +36,8 @@ class RouterPlugin {
|
|
|
39
36
|
publicPath: true,
|
|
40
37
|
assets: true,
|
|
41
38
|
chunkGroups: true,
|
|
42
|
-
chunks: true
|
|
39
|
+
chunks: true,
|
|
40
|
+
ids: true
|
|
43
41
|
});
|
|
44
42
|
const { publicPath, chunks = [] } = stats;
|
|
45
43
|
const routeAssets = {};
|
|
@@ -65,7 +63,12 @@ class RouterPlugin {
|
|
|
65
63
|
};
|
|
66
64
|
const injectedContent = `
|
|
67
65
|
;(function(){
|
|
68
|
-
window.${ROUTE_MANIFEST} = ${JSON.stringify(manifest)
|
|
66
|
+
window.${ROUTE_MANIFEST} = ${JSON.stringify(manifest, (k, v) => {
|
|
67
|
+
if (k === "assets") {
|
|
68
|
+
return void 0;
|
|
69
|
+
}
|
|
70
|
+
return v;
|
|
71
|
+
})};
|
|
69
72
|
})();
|
|
70
73
|
`;
|
|
71
74
|
const entrypointsArray = Array.from(
|
|
@@ -95,7 +98,7 @@ class RouterPlugin {
|
|
|
95
98
|
void 0
|
|
96
99
|
);
|
|
97
100
|
}
|
|
98
|
-
const filename = path.join(outputPath,
|
|
101
|
+
const filename = path.join(outputPath, ROUTE_MANIFEST_FILE);
|
|
99
102
|
await fs.ensureFile(filename);
|
|
100
103
|
await fs.writeFile(filename, JSON.stringify(manifest, null, 2));
|
|
101
104
|
}
|
|
@@ -4,7 +4,7 @@ import { printInstructions } from "../utils/printInstructions";
|
|
|
4
4
|
import { injectDataLoaderPlugin } from "../utils/createServer";
|
|
5
5
|
import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
|
|
6
6
|
const start = async (api) => {
|
|
7
|
-
var _a;
|
|
7
|
+
var _a, _b;
|
|
8
8
|
const appContext = api.useAppContext();
|
|
9
9
|
const userConfig = api.useResolvedConfigContext();
|
|
10
10
|
const hookRunners = api.useHookRunners();
|
|
@@ -17,7 +17,14 @@ const start = async (api) => {
|
|
|
17
17
|
const serverInternalPlugins = await getServerInternalPlugins(api);
|
|
18
18
|
const app = await server({
|
|
19
19
|
pwd: appDirectory,
|
|
20
|
-
config:
|
|
20
|
+
config: {
|
|
21
|
+
...userConfig,
|
|
22
|
+
dev: userConfig.dev,
|
|
23
|
+
output: {
|
|
24
|
+
path: (_b = userConfig.output.distPath) == null ? void 0 : _b.root,
|
|
25
|
+
...userConfig.output || {}
|
|
26
|
+
}
|
|
27
|
+
},
|
|
21
28
|
appContext: {
|
|
22
29
|
sharedDirectory: getTargetDir(
|
|
23
30
|
appContext.sharedDirectory,
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const JS_EXTENSIONS = [".js", ".ts", ".jsx", ".tsx"];
|
|
2
|
+
const INDEX_FILE_NAME = "index";
|
|
3
|
+
const APP_FILE_NAME = "App";
|
|
4
|
+
const PAGES_DIR_NAME = "pages";
|
|
5
|
+
const NESTED_ROUTES_DIR = "routes";
|
|
6
|
+
const FILE_SYSTEM_ROUTES_FILE_NAME = "routes.js";
|
|
7
|
+
const LOADER_EXPORT_NAME = "loader";
|
|
8
|
+
const TEMP_LOADERS_DIR = "__loaders__";
|
|
9
|
+
const ENTRY_POINT_FILE_NAME = "index.js";
|
|
10
|
+
const ENTRY_BOOTSTRAP_FILE_NAME = "bootstrap.js";
|
|
11
|
+
const FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP = /^\[(\S+)\]([*+?]?)$/;
|
|
12
|
+
const FILE_SYSTEM_ROUTES_LAYOUT = "_layout";
|
|
13
|
+
const FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT = "_app";
|
|
14
|
+
const FILE_SYSTEM_ROUTES_INDEX = "index";
|
|
15
|
+
const FILE_SYSTEM_ROUTES_IGNORED_REGEX = /\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/;
|
|
16
|
+
const HTML_PARTIALS_FOLDER = "html";
|
|
17
|
+
const HTML_PARTIALS_EXTENSIONS = [".htm", ".html", ".ejs"];
|
|
18
|
+
const FILE_SYSTEM_ROUTES_COMPONENTS_DIR = "internal_components";
|
|
19
|
+
const NESTED_ROUTE = {
|
|
20
|
+
LAYOUT_FILE: "layout",
|
|
21
|
+
LAYOUT_LOADER_FILE: "layout.loader",
|
|
22
|
+
PAGE_FILE: "page",
|
|
23
|
+
PAGE_LOADER_FILE: "page.loader",
|
|
24
|
+
LOADING_FILE: "loading",
|
|
25
|
+
ERROR_FILE: "error",
|
|
26
|
+
LOADER_FILE: "loader"
|
|
27
|
+
};
|
|
28
|
+
const APP_CONFIG_NAME = "config";
|
|
29
|
+
const APP_INIT_EXPORTED = "init";
|
|
30
|
+
const APP_INIT_IMPORTED = "appInit";
|
|
31
|
+
export {
|
|
32
|
+
APP_CONFIG_NAME,
|
|
33
|
+
APP_FILE_NAME,
|
|
34
|
+
APP_INIT_EXPORTED,
|
|
35
|
+
APP_INIT_IMPORTED,
|
|
36
|
+
ENTRY_BOOTSTRAP_FILE_NAME,
|
|
37
|
+
ENTRY_POINT_FILE_NAME,
|
|
38
|
+
FILE_SYSTEM_ROUTES_COMPONENTS_DIR,
|
|
39
|
+
FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP,
|
|
40
|
+
FILE_SYSTEM_ROUTES_FILE_NAME,
|
|
41
|
+
FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT,
|
|
42
|
+
FILE_SYSTEM_ROUTES_IGNORED_REGEX,
|
|
43
|
+
FILE_SYSTEM_ROUTES_INDEX,
|
|
44
|
+
FILE_SYSTEM_ROUTES_LAYOUT,
|
|
45
|
+
HTML_PARTIALS_EXTENSIONS,
|
|
46
|
+
HTML_PARTIALS_FOLDER,
|
|
47
|
+
INDEX_FILE_NAME,
|
|
48
|
+
JS_EXTENSIONS,
|
|
49
|
+
LOADER_EXPORT_NAME,
|
|
50
|
+
NESTED_ROUTE,
|
|
51
|
+
NESTED_ROUTES_DIR,
|
|
52
|
+
PAGES_DIR_NAME,
|
|
53
|
+
TEMP_LOADERS_DIR
|
|
54
|
+
};
|
|
@@ -0,0 +1,247 @@
|
|
|
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 { fs, getEntryOptions, logger } from "@modern-js/utils";
|
|
23
|
+
import {
|
|
24
|
+
useResolvedConfigContext
|
|
25
|
+
} from "@modern-js/core";
|
|
26
|
+
import * as templates from "./templates";
|
|
27
|
+
import { getClientRoutes, getClientRoutesLegacy } from "./getClientRoutes";
|
|
28
|
+
import {
|
|
29
|
+
FILE_SYSTEM_ROUTES_FILE_NAME,
|
|
30
|
+
ENTRY_POINT_FILE_NAME,
|
|
31
|
+
ENTRY_BOOTSTRAP_FILE_NAME
|
|
32
|
+
} from "./constants";
|
|
33
|
+
import { getDefaultImports, getServerLoadersFile } from "./utils";
|
|
34
|
+
import { walk } from "./nestedRoutes";
|
|
35
|
+
const createImportSpecifier = (specifiers) => {
|
|
36
|
+
let defaults = "";
|
|
37
|
+
const named = [];
|
|
38
|
+
for (const { local, imported } of specifiers) {
|
|
39
|
+
if (local && imported) {
|
|
40
|
+
named.push(`${imported} as ${local}`);
|
|
41
|
+
} else if (local) {
|
|
42
|
+
defaults = local;
|
|
43
|
+
} else {
|
|
44
|
+
named.push(imported);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (defaults && named.length) {
|
|
48
|
+
return `${defaults}, { ${named.join(", ")} }`;
|
|
49
|
+
} else if (defaults) {
|
|
50
|
+
return defaults;
|
|
51
|
+
} else {
|
|
52
|
+
return `{ ${named.join(", ")} }`;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const createImportStatements = (statements) => {
|
|
56
|
+
var _a, _b;
|
|
57
|
+
const deDuplicated = [];
|
|
58
|
+
const seen = /* @__PURE__ */ new Map();
|
|
59
|
+
for (const { value, specifiers, initialize } of statements) {
|
|
60
|
+
if (!seen.has(value)) {
|
|
61
|
+
deDuplicated.push({
|
|
62
|
+
value,
|
|
63
|
+
specifiers,
|
|
64
|
+
initialize
|
|
65
|
+
});
|
|
66
|
+
seen.set(value, specifiers);
|
|
67
|
+
} else {
|
|
68
|
+
seen.get(value).push(...specifiers);
|
|
69
|
+
const modifyIndex = deDuplicated.findIndex((v) => v.value === value);
|
|
70
|
+
const originInitialize = (_b = (_a = deDuplicated[modifyIndex]) == null ? void 0 : _a.initialize) != null ? _b : "";
|
|
71
|
+
deDuplicated[modifyIndex].initialize = originInitialize.concat(
|
|
72
|
+
`
|
|
73
|
+
${initialize || ""}`
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return deDuplicated.map(
|
|
78
|
+
({ value, specifiers, initialize }) => `import ${createImportSpecifier(specifiers)} from '${value}';
|
|
79
|
+
${initialize || ""}`
|
|
80
|
+
).join("\n");
|
|
81
|
+
};
|
|
82
|
+
const generateCode = (appContext, config, entrypoints, api) => __async(void 0, null, function* () {
|
|
83
|
+
var _a, _b, _c;
|
|
84
|
+
const {
|
|
85
|
+
internalDirectory,
|
|
86
|
+
srcDirectory,
|
|
87
|
+
internalDirAlias,
|
|
88
|
+
internalSrcAlias,
|
|
89
|
+
packageName
|
|
90
|
+
} = appContext;
|
|
91
|
+
const hookRunners = api.useHookRunners();
|
|
92
|
+
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";
|
|
93
|
+
const { mountId } = config.html;
|
|
94
|
+
const getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
|
|
95
|
+
yield Promise.all(entrypoints.map(generateEntryCode));
|
|
96
|
+
function generateEntryCode(entrypoint) {
|
|
97
|
+
return __async(this, null, function* () {
|
|
98
|
+
const { entryName, isAutoMount, customBootstrap, fileSystemRoutes } = entrypoint;
|
|
99
|
+
if (isAutoMount) {
|
|
100
|
+
if (fileSystemRoutes) {
|
|
101
|
+
let initialRoutes = [];
|
|
102
|
+
let nestedRoute = null;
|
|
103
|
+
if (entrypoint.entry) {
|
|
104
|
+
initialRoutes = getRoutes({
|
|
105
|
+
entrypoint,
|
|
106
|
+
srcDirectory,
|
|
107
|
+
srcAlias: internalSrcAlias,
|
|
108
|
+
internalDirectory,
|
|
109
|
+
internalDirAlias
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
if (entrypoint.nestedRoutesEntry) {
|
|
113
|
+
if (!isV5) {
|
|
114
|
+
nestedRoute = yield walk(
|
|
115
|
+
entrypoint.nestedRoutesEntry,
|
|
116
|
+
entrypoint.nestedRoutesEntry,
|
|
117
|
+
{
|
|
118
|
+
name: internalSrcAlias,
|
|
119
|
+
basename: srcDirectory
|
|
120
|
+
},
|
|
121
|
+
entrypoint.entryName
|
|
122
|
+
);
|
|
123
|
+
if (nestedRoute) {
|
|
124
|
+
initialRoutes.unshift(nestedRoute);
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
logger.error("Nested routes is not supported in legacy mode.");
|
|
128
|
+
process.exit(1);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const { routes } = yield hookRunners.modifyFileSystemRoutes({
|
|
132
|
+
entrypoint,
|
|
133
|
+
routes: initialRoutes
|
|
134
|
+
});
|
|
135
|
+
const config2 = useResolvedConfigContext();
|
|
136
|
+
const ssr = getEntryOptions(
|
|
137
|
+
entryName,
|
|
138
|
+
config2.server.ssr,
|
|
139
|
+
config2.server.ssrByEntries,
|
|
140
|
+
packageName
|
|
141
|
+
);
|
|
142
|
+
let mode;
|
|
143
|
+
if (ssr) {
|
|
144
|
+
mode = typeof ssr === "object" ? ssr.mode || "string" : "string";
|
|
145
|
+
} else {
|
|
146
|
+
mode = false;
|
|
147
|
+
}
|
|
148
|
+
if (mode === "stream") {
|
|
149
|
+
const hasPageRoute = routes.some(
|
|
150
|
+
(route) => "type" in route && route.type === "page"
|
|
151
|
+
);
|
|
152
|
+
if (hasPageRoute) {
|
|
153
|
+
logger.error(
|
|
154
|
+
"Streaming ssr is not supported when pages dir exists"
|
|
155
|
+
);
|
|
156
|
+
process.exit(1);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
const { code: code2 } = yield hookRunners.beforeGenerateRoutes({
|
|
160
|
+
entrypoint,
|
|
161
|
+
code: yield templates.fileSystemRoutes({
|
|
162
|
+
routes,
|
|
163
|
+
ssrMode: mode,
|
|
164
|
+
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
165
|
+
entryName: entrypoint.entryName,
|
|
166
|
+
internalDirectory
|
|
167
|
+
})
|
|
168
|
+
});
|
|
169
|
+
if (entrypoint.nestedRoutesEntry && mode) {
|
|
170
|
+
const routesServerFile = getServerLoadersFile(
|
|
171
|
+
internalDirectory,
|
|
172
|
+
entryName
|
|
173
|
+
);
|
|
174
|
+
const code3 = templates.routesForServer({
|
|
175
|
+
routes
|
|
176
|
+
});
|
|
177
|
+
yield fs.ensureFile(routesServerFile);
|
|
178
|
+
yield fs.writeFile(routesServerFile, code3);
|
|
179
|
+
}
|
|
180
|
+
fs.outputFileSync(
|
|
181
|
+
path.resolve(
|
|
182
|
+
internalDirectory,
|
|
183
|
+
`./${entryName}/${FILE_SYSTEM_ROUTES_FILE_NAME}`
|
|
184
|
+
),
|
|
185
|
+
code2,
|
|
186
|
+
"utf8"
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
const { imports: importStatements } = yield hookRunners.modifyEntryImports({
|
|
190
|
+
entrypoint,
|
|
191
|
+
imports: getDefaultImports({
|
|
192
|
+
entrypoint,
|
|
193
|
+
srcDirectory,
|
|
194
|
+
internalSrcAlias,
|
|
195
|
+
internalDirAlias,
|
|
196
|
+
internalDirectory
|
|
197
|
+
})
|
|
198
|
+
});
|
|
199
|
+
const { plugins } = yield hookRunners.modifyEntryRuntimePlugins({
|
|
200
|
+
entrypoint,
|
|
201
|
+
plugins: []
|
|
202
|
+
});
|
|
203
|
+
const { code: renderFunction } = yield hookRunners.modifyEntryRenderFunction({
|
|
204
|
+
entrypoint,
|
|
205
|
+
code: templates.renderFunction({
|
|
206
|
+
plugins,
|
|
207
|
+
customBootstrap,
|
|
208
|
+
fileSystemRoutes
|
|
209
|
+
})
|
|
210
|
+
});
|
|
211
|
+
const { exportStatement } = yield hookRunners.modifyEntryExport({
|
|
212
|
+
entrypoint,
|
|
213
|
+
exportStatement: "export default AppWrapper;"
|
|
214
|
+
});
|
|
215
|
+
const code = templates.index({
|
|
216
|
+
mountId,
|
|
217
|
+
imports: createImportStatements(importStatements),
|
|
218
|
+
renderFunction,
|
|
219
|
+
exportStatement
|
|
220
|
+
});
|
|
221
|
+
const entryFile = path.resolve(
|
|
222
|
+
internalDirectory,
|
|
223
|
+
`./${entryName}/${ENTRY_POINT_FILE_NAME}`
|
|
224
|
+
);
|
|
225
|
+
entrypoint.entry = entryFile;
|
|
226
|
+
if (config.source.enableAsyncEntry) {
|
|
227
|
+
const { code: asyncEntryCode } = yield hookRunners.modifyAsyncEntry({
|
|
228
|
+
entrypoint,
|
|
229
|
+
code: `import('./${ENTRY_BOOTSTRAP_FILE_NAME}');`
|
|
230
|
+
});
|
|
231
|
+
fs.outputFileSync(entryFile, asyncEntryCode, "utf8");
|
|
232
|
+
const bootstrapFile = path.resolve(
|
|
233
|
+
internalDirectory,
|
|
234
|
+
`./${entryName}/${ENTRY_BOOTSTRAP_FILE_NAME}`
|
|
235
|
+
);
|
|
236
|
+
fs.outputFileSync(bootstrapFile, code, "utf8");
|
|
237
|
+
} else {
|
|
238
|
+
fs.outputFileSync(entryFile, code, "utf8");
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
export {
|
|
245
|
+
createImportStatements,
|
|
246
|
+
generateCode
|
|
247
|
+
};
|