@modern-js/app-tools 2.27.1-alpha.0 → 2.28.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/CHANGELOG.md +44 -0
- package/dist/cjs/analyze/generateCode.js +16 -7
- package/dist/cjs/analyze/getFileSystemEntry.js +2 -1
- package/dist/cjs/analyze/getServerRoutes.js +5 -4
- package/dist/cjs/analyze/index.js +209 -211
- package/dist/cjs/analyze/nestedRoutes.js +58 -15
- package/dist/cjs/analyze/templates.js +4 -4
- package/dist/cjs/builder/builder-rspack/adapterCopy.js +41 -43
- package/dist/cjs/builder/builder-webpack/adapterModern.js +23 -25
- package/dist/cjs/builder/generator/createBuilderProviderConfig.js +2 -1
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +12 -15
- package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +33 -75
- package/dist/cjs/commands/build.js +2 -1
- package/dist/cjs/commands/inspect.js +2 -1
- package/dist/cjs/commands/serve.js +2 -2
- package/dist/cjs/index.js +3 -2
- package/dist/cjs/initialize/index.js +70 -72
- package/dist/esm/analyze/generateCode.js +35 -10
- package/dist/esm/analyze/getFileSystemEntry.js +2 -1
- package/dist/esm/analyze/getServerRoutes.js +5 -4
- package/dist/esm/analyze/nestedRoutes.js +59 -13
- package/dist/esm/analyze/templates.js +4 -4
- package/dist/esm/builder/builder-rspack/adapterCopy.js +1 -1
- package/dist/esm/builder/generator/createBuilderProviderConfig.js +2 -1
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +13 -16
- package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +41 -101
- package/dist/esm/commands/build.js +2 -2
- package/dist/esm/commands/inspect.js +2 -2
- package/dist/esm/commands/serve.js +2 -2
- package/dist/esm/index.js +3 -2
- package/dist/esm-node/analyze/generateCode.js +16 -7
- package/dist/esm-node/analyze/getFileSystemEntry.js +2 -1
- package/dist/esm-node/analyze/getServerRoutes.js +5 -4
- package/dist/esm-node/analyze/index.js +209 -211
- package/dist/esm-node/analyze/nestedRoutes.js +55 -15
- package/dist/esm-node/analyze/templates.js +4 -4
- package/dist/esm-node/builder/builder-rspack/adapterCopy.js +41 -43
- package/dist/esm-node/builder/builder-webpack/adapterModern.js +23 -25
- package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +2 -1
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +12 -15
- package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +33 -75
- package/dist/esm-node/commands/build.js +2 -1
- package/dist/esm-node/commands/inspect.js +2 -1
- package/dist/esm-node/commands/serve.js +2 -2
- package/dist/esm-node/index.js +3 -2
- package/dist/esm-node/initialize/index.js +70 -72
- package/dist/types/analyze/nestedRoutes.d.ts +2 -1
- package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +0 -8
- package/package.json +24 -24
|
@@ -11,81 +11,79 @@ Object.defineProperty(exports, "default", {
|
|
|
11
11
|
const _utils = require("@modern-js/utils");
|
|
12
12
|
const _schema = require("../schema");
|
|
13
13
|
const _config = require("../config");
|
|
14
|
-
const _default = ({ bundler }) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
14
|
+
const _default = ({ bundler }) => ({
|
|
15
|
+
name: "@modern-js/plugin-initialize",
|
|
16
|
+
post: [
|
|
17
|
+
"@modern-js/plugin-ssr",
|
|
18
|
+
"@modern-js/plugin-document",
|
|
19
|
+
"@modern-js/plugin-state",
|
|
20
|
+
"@modern-js/plugin-router",
|
|
21
|
+
"@modern-js/plugin-router-v5",
|
|
22
|
+
"@modern-js/plugin-polyfill"
|
|
23
|
+
],
|
|
24
|
+
setup(api) {
|
|
25
|
+
const config = () => {
|
|
26
|
+
const appContext = api.useAppContext();
|
|
27
|
+
const userConfig = api.useConfigContext();
|
|
28
|
+
api.setAppContext({
|
|
29
|
+
...appContext,
|
|
30
|
+
bundlerType: bundler
|
|
31
|
+
});
|
|
32
|
+
return (0, _config.checkIsLegacyConfig)(userConfig) ? (0, _config.createLegacyDefaultConfig)(appContext) : (0, _config.createDefaultConfig)(appContext, bundler);
|
|
33
|
+
};
|
|
34
|
+
const validateSchema = () => {
|
|
35
|
+
const userConfig = api.useConfigContext();
|
|
36
|
+
const schemas = (0, _config.checkIsLegacyConfig)(userConfig) ? _schema.legacySchema : _schema.schema;
|
|
37
|
+
return schemas.generate();
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
config,
|
|
41
|
+
validateSchema,
|
|
42
|
+
async resolvedConfig({ resolved }) {
|
|
43
|
+
var _resolved_output_distPath;
|
|
44
|
+
let appContext = api.useAppContext();
|
|
28
45
|
const userConfig = api.useConfigContext();
|
|
29
|
-
|
|
46
|
+
const port = await getServerPort(resolved);
|
|
47
|
+
appContext = {
|
|
30
48
|
...appContext,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
resolved.autoLoadPlugins = (_normalizedConfig_autoLoadPlugins = normalizedConfig.autoLoadPlugins) !== null && _normalizedConfig_autoLoadPlugins !== void 0 ? _normalizedConfig_autoLoadPlugins : false;
|
|
62
|
-
stabilizeConfig(resolved, normalizedConfig, [
|
|
63
|
-
"source",
|
|
64
|
-
"bff",
|
|
65
|
-
"dev",
|
|
66
|
-
"html",
|
|
67
|
-
"output",
|
|
68
|
-
"tools",
|
|
69
|
-
"testing",
|
|
70
|
-
"plugins",
|
|
71
|
-
"builderPlugins",
|
|
72
|
-
"runtime",
|
|
73
|
-
"runtimeByEntries",
|
|
74
|
-
"deploy",
|
|
75
|
-
"performance"
|
|
76
|
-
]);
|
|
77
|
-
if (bundler === "webpack") {
|
|
78
|
-
resolved.security = normalizedConfig.security || {};
|
|
79
|
-
resolved.experiments = normalizedConfig.experiments;
|
|
80
|
-
}
|
|
81
|
-
return {
|
|
82
|
-
resolved
|
|
83
|
-
};
|
|
49
|
+
port,
|
|
50
|
+
distDirectory: (0, _utils.ensureAbsolutePath)(appContext.distDirectory, ((_resolved_output_distPath = resolved.output.distPath) === null || _resolved_output_distPath === void 0 ? void 0 : _resolved_output_distPath.root) || "dist")
|
|
51
|
+
};
|
|
52
|
+
api.setAppContext(appContext);
|
|
53
|
+
const normalizedConfig = (0, _config.checkIsLegacyConfig)(resolved) ? (0, _config.transformNormalizedConfig)(resolved) : resolved;
|
|
54
|
+
resolved._raw = userConfig;
|
|
55
|
+
resolved.server = {
|
|
56
|
+
...normalizedConfig.server || {},
|
|
57
|
+
port
|
|
58
|
+
};
|
|
59
|
+
var _normalizedConfig_autoLoadPlugins;
|
|
60
|
+
resolved.autoLoadPlugins = (_normalizedConfig_autoLoadPlugins = normalizedConfig.autoLoadPlugins) !== null && _normalizedConfig_autoLoadPlugins !== void 0 ? _normalizedConfig_autoLoadPlugins : false;
|
|
61
|
+
stabilizeConfig(resolved, normalizedConfig, [
|
|
62
|
+
"source",
|
|
63
|
+
"bff",
|
|
64
|
+
"dev",
|
|
65
|
+
"html",
|
|
66
|
+
"output",
|
|
67
|
+
"tools",
|
|
68
|
+
"testing",
|
|
69
|
+
"plugins",
|
|
70
|
+
"builderPlugins",
|
|
71
|
+
"runtime",
|
|
72
|
+
"runtimeByEntries",
|
|
73
|
+
"deploy",
|
|
74
|
+
"performance"
|
|
75
|
+
]);
|
|
76
|
+
if (bundler === "webpack") {
|
|
77
|
+
resolved.security = normalizedConfig.security || {};
|
|
78
|
+
resolved.experiments = normalizedConfig.experiments;
|
|
84
79
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
80
|
+
return {
|
|
81
|
+
resolved
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
});
|
|
89
87
|
function stabilizeConfig(resolve, config, keys) {
|
|
90
88
|
keys.forEach((key) => {
|
|
91
89
|
resolve[key] = config[key] || {};
|
|
@@ -94,13 +94,13 @@ export var createImportStatements = function(statements) {
|
|
|
94
94
|
};
|
|
95
95
|
export var generateCode = function() {
|
|
96
96
|
var _ref = _async_to_generator(function(appContext, config, entrypoints, api) {
|
|
97
|
-
var internalDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName, hookRunners, isV5, getRoutes, importsStatemets;
|
|
97
|
+
var _config, _config_runtime_router, _config_runtime, _config1, internalDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName, hookRunners, isV5, getRoutes, importsStatemets, oldVersion;
|
|
98
98
|
function generateEntryCode(entrypoint) {
|
|
99
99
|
return _generateEntryCode.apply(this, arguments);
|
|
100
100
|
}
|
|
101
101
|
function _generateEntryCode() {
|
|
102
102
|
_generateEntryCode = _async_to_generator(function(entrypoint) {
|
|
103
|
-
var entryName, isMainEntry, isAutoMount, fileSystemRoutes, _config_output, initialRoutes,
|
|
103
|
+
var entryName, isMainEntry, isAutoMount, fileSystemRoutes, _config_output, _config2, initialRoutes, nestedRoutes, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, route, routes, _$config, ssr, useSSG, mode, hasPageRoute, code, _, _tmp, routesServerFile, code1, serverLoaderCombined, serverLoaderFile, imports, entryFile;
|
|
104
104
|
return _ts_generator(this, function(_state) {
|
|
105
105
|
switch (_state.label) {
|
|
106
106
|
case 0:
|
|
@@ -116,7 +116,7 @@ export var generateCode = function() {
|
|
|
116
116
|
11
|
|
117
117
|
];
|
|
118
118
|
initialRoutes = [];
|
|
119
|
-
|
|
119
|
+
nestedRoutes = null;
|
|
120
120
|
if (entrypoint.entry) {
|
|
121
121
|
initialRoutes = getRoutes({
|
|
122
122
|
entrypoint: entrypoint,
|
|
@@ -136,12 +136,36 @@ export var generateCode = function() {
|
|
|
136
136
|
walk(entrypoint.nestedRoutesEntry, entrypoint.nestedRoutesEntry, {
|
|
137
137
|
name: internalSrcAlias,
|
|
138
138
|
basename: srcDirectory
|
|
139
|
-
}, entrypoint.entryName, entrypoint.isMainEntry)
|
|
139
|
+
}, entrypoint.entryName, entrypoint.isMainEntry, oldVersion)
|
|
140
140
|
];
|
|
141
141
|
case 1:
|
|
142
|
-
|
|
143
|
-
if (
|
|
144
|
-
|
|
142
|
+
nestedRoutes = _state.sent();
|
|
143
|
+
if (nestedRoutes) {
|
|
144
|
+
if (!Array.isArray(nestedRoutes)) {
|
|
145
|
+
nestedRoutes = [
|
|
146
|
+
nestedRoutes
|
|
147
|
+
];
|
|
148
|
+
}
|
|
149
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
150
|
+
try {
|
|
151
|
+
for (_iterator = nestedRoutes[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
152
|
+
route = _step.value;
|
|
153
|
+
initialRoutes.unshift(route);
|
|
154
|
+
}
|
|
155
|
+
} catch (err) {
|
|
156
|
+
_didIteratorError = true;
|
|
157
|
+
_iteratorError = err;
|
|
158
|
+
} finally {
|
|
159
|
+
try {
|
|
160
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
161
|
+
_iterator.return();
|
|
162
|
+
}
|
|
163
|
+
} finally {
|
|
164
|
+
if (_didIteratorError) {
|
|
165
|
+
throw _iteratorError;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
145
169
|
}
|
|
146
170
|
_state.label = 2;
|
|
147
171
|
case 2:
|
|
@@ -161,8 +185,8 @@ export var generateCode = function() {
|
|
|
161
185
|
mode = typeof ssr === "object" ? ssr.mode || "string" : "string";
|
|
162
186
|
}
|
|
163
187
|
if (mode === "stream") {
|
|
164
|
-
hasPageRoute = routes.some(function(
|
|
165
|
-
return "type" in
|
|
188
|
+
hasPageRoute = routes.some(function(route2) {
|
|
189
|
+
return "type" in route2 && route2.type === "page";
|
|
166
190
|
});
|
|
167
191
|
if (hasPageRoute) {
|
|
168
192
|
logger.error("Streaming ssr is not supported when pages dir exists");
|
|
@@ -181,7 +205,7 @@ export var generateCode = function() {
|
|
|
181
205
|
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
182
206
|
entryName: entrypoint.entryName,
|
|
183
207
|
internalDirectory: internalDirectory,
|
|
184
|
-
splitRouteChunks: _$config === null ||
|
|
208
|
+
splitRouteChunks: (_config2 = _$config) === null || _config2 === void 0 ? void 0 : (_config_output = _config2.output) === null || _config_output === void 0 ? void 0 : _config_output.splitRouteChunks
|
|
185
209
|
})
|
|
186
210
|
];
|
|
187
211
|
case 4:
|
|
@@ -270,6 +294,7 @@ export var generateCode = function() {
|
|
|
270
294
|
isV5 = isRouterV5(config);
|
|
271
295
|
getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
|
|
272
296
|
importsStatemets = /* @__PURE__ */ new Map();
|
|
297
|
+
oldVersion = typeof ((_config = config) === null || _config === void 0 ? void 0 : _config.runtime.router) === "object" ? Boolean((_config1 = config) === null || _config1 === void 0 ? void 0 : (_config_runtime = _config1.runtime) === null || _config_runtime === void 0 ? void 0 : (_config_runtime_router = _config_runtime.router) === null || _config_runtime_router === void 0 ? void 0 : _config_runtime_router.oldVersion) : false;
|
|
273
298
|
return [
|
|
274
299
|
4,
|
|
275
300
|
Promise.all(entrypoints.map(generateEntryCode))
|
|
@@ -87,7 +87,8 @@ export var getFileSystemEntry = function(appContext, config) {
|
|
|
87
87
|
var _config_source = config.source, entriesDir = _config_source.entriesDir, disableEntryDirs = _config_source.disableEntryDirs;
|
|
88
88
|
var disabledDirs = [];
|
|
89
89
|
if (disableEntryDirs && Array.isArray(disableEntryDirs)) {
|
|
90
|
-
|
|
90
|
+
var _disableEntryDirs;
|
|
91
|
+
disabledDirs = (_disableEntryDirs = disableEntryDirs) === null || _disableEntryDirs === void 0 ? void 0 : _disableEntryDirs.map(function(dir) {
|
|
91
92
|
return ensureAbsolutePath(appDirectory, dir);
|
|
92
93
|
});
|
|
93
94
|
}
|
|
@@ -69,18 +69,19 @@ var applyRouteOptions = function(original, routeOptions) {
|
|
|
69
69
|
return routes;
|
|
70
70
|
};
|
|
71
71
|
var collectHtmlRoutes = function(entrypoints, appContext, config) {
|
|
72
|
-
var _deploy_worker;
|
|
72
|
+
var _deploy_worker, _deploy;
|
|
73
73
|
var mainEntryName = config.source.mainEntryName, disableHtmlFolder = config.html.disableHtmlFolder, _config_output = config.output, tmp = _config_output.distPath, _ref = tmp === void 0 ? {} : tmp, htmlPath = _ref.html, _config_server = config.server, baseUrl = _config_server.baseUrl, routes = _config_server.routes, ssr = _config_server.ssr, ssrByEntries = _config_server.ssrByEntries, deploy = config.deploy;
|
|
74
74
|
var packageName = appContext.packageName;
|
|
75
|
-
var workerSSR = deploy === null ||
|
|
75
|
+
var workerSSR = (_deploy = deploy) === null || _deploy === void 0 ? void 0 : (_deploy_worker = _deploy.worker) === null || _deploy_worker === void 0 ? void 0 : _deploy_worker.ssr;
|
|
76
76
|
var htmlRoutes = entrypoints.reduce(function(previous, param) {
|
|
77
77
|
var entryName = param.entryName;
|
|
78
|
+
var _routes, _routes1;
|
|
78
79
|
var isMainEntry = entryName === (mainEntryName || MAIN_ENTRY_NAME);
|
|
79
80
|
var entryOptions = getEntryOptions(entryName, isMainEntry, ssr, ssrByEntries, packageName);
|
|
80
81
|
var isSSR = Boolean(entryOptions);
|
|
81
82
|
var isWorker = Boolean(workerSSR);
|
|
82
83
|
var isStream = typeof entryOptions === "object" && entryOptions.mode === "stream";
|
|
83
|
-
var resHeaders = ((routes === null ||
|
|
84
|
+
var resHeaders = (((_routes = routes) === null || _routes === void 0 ? void 0 : _routes[entryName]) || {}).resHeaders;
|
|
84
85
|
var route = {
|
|
85
86
|
urlPath: "/".concat(isMainEntry ? "" : entryName),
|
|
86
87
|
entryName: entryName,
|
|
@@ -92,7 +93,7 @@ var collectHtmlRoutes = function(entrypoints, appContext, config) {
|
|
|
92
93
|
worker: isWorker ? "".concat(SERVER_WORKER_BUNDLE_DIRECTORY, "/").concat(entryName, ".js") : void 0,
|
|
93
94
|
bundle: isSSR ? "".concat(SERVER_BUNDLE_DIRECTORY, "/").concat(entryName, ".js") : void 0
|
|
94
95
|
};
|
|
95
|
-
if (routes === null ||
|
|
96
|
+
if ((_routes1 = routes) === null || _routes1 === void 0 ? void 0 : _routes1.hasOwnProperty(entryName)) {
|
|
96
97
|
var routeOptions = isPlainObject(routes[entryName]) ? routes[entryName] : {
|
|
97
98
|
route: routes[entryName]
|
|
98
99
|
};
|
|
@@ -38,9 +38,37 @@ var createRoute = function(routeInfo, rootDir, filename, entryName, isMainEntry)
|
|
|
38
38
|
type: "nested"
|
|
39
39
|
});
|
|
40
40
|
};
|
|
41
|
+
export var optimizeRoute = function(routeTree) {
|
|
42
|
+
if (!routeTree.children || routeTree.children.length === 0) {
|
|
43
|
+
return [
|
|
44
|
+
routeTree
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
var children = routeTree.children;
|
|
48
|
+
if (!routeTree._component) {
|
|
49
|
+
var newRoutes = children.map(function(child) {
|
|
50
|
+
var _routeTree_path;
|
|
51
|
+
var routePath = "".concat((_routeTree_path = routeTree.path) !== null && _routeTree_path !== void 0 ? _routeTree_path : "").concat(child.path ? "/".concat(child.path) : "");
|
|
52
|
+
return _object_spread_props(_object_spread({}, child), {
|
|
53
|
+
path: routePath
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
if (newRoutes.length > 1) {
|
|
57
|
+
return newRoutes.flatMap(function(newRoute) {
|
|
58
|
+
return optimizeRoute(newRoute);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return newRoutes;
|
|
62
|
+
} else {
|
|
63
|
+
routeTree.children = children.flatMap(optimizeRoute);
|
|
64
|
+
return [
|
|
65
|
+
routeTree
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
};
|
|
41
69
|
export var walk = function() {
|
|
42
|
-
var _ref = _async_to_generator(function(dirname, rootDir, alias, entryName, isMainEntry) {
|
|
43
|
-
var
|
|
70
|
+
var _ref = _async_to_generator(function(dirname, rootDir, alias, entryName, isMainEntry, oldVersion) {
|
|
71
|
+
var _routePath, _finalRoute_children, isDirectory, relativeDir, pathSegments, lastSegment, isRoot, isPathlessLayout, isWithoutLayoutPath, routePath, route, pageLoaderFile, pageRoute, splatLoaderFile, splatRoute, pageConfigFile, items, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, itemPath, extname, itemWithoutExt, isDirectory1, childRoute, _route_children, _route_children1, _route_children2, err, finalRoute, childRoutes, childRoute1, _$path, _childRoutes, slatRouteIndex, _childRoutes1, _childRoutes2, optimizedRoutes;
|
|
44
72
|
return _ts_generator(this, function(_state) {
|
|
45
73
|
switch (_state.label) {
|
|
46
74
|
case 0:
|
|
@@ -79,7 +107,7 @@ export var walk = function() {
|
|
|
79
107
|
}
|
|
80
108
|
routePath = replaceDynamicPath(routePath);
|
|
81
109
|
route = {
|
|
82
|
-
path: routePath === null ||
|
|
110
|
+
path: (_routePath = routePath) === null || _routePath === void 0 ? void 0 : _routePath.replace(/\$$/, "?"),
|
|
83
111
|
children: [],
|
|
84
112
|
isRoot: isRoot
|
|
85
113
|
};
|
|
@@ -128,13 +156,13 @@ export var walk = function() {
|
|
|
128
156
|
];
|
|
129
157
|
return [
|
|
130
158
|
4,
|
|
131
|
-
walk(itemPath, rootDir, alias, entryName, isMainEntry)
|
|
159
|
+
walk(itemPath, rootDir, alias, entryName, isMainEntry, oldVersion)
|
|
132
160
|
];
|
|
133
161
|
case 7:
|
|
134
162
|
childRoute = _state.sent();
|
|
135
|
-
if (childRoute) {
|
|
163
|
+
if (childRoute && !Array.isArray(childRoute)) {
|
|
136
164
|
;
|
|
137
|
-
(
|
|
165
|
+
(_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.push(childRoute);
|
|
138
166
|
}
|
|
139
167
|
_state.label = 8;
|
|
140
168
|
case 8:
|
|
@@ -174,7 +202,7 @@ export var walk = function() {
|
|
|
174
202
|
if (pageConfigFile) {
|
|
175
203
|
pageRoute.config = pageConfigFile;
|
|
176
204
|
}
|
|
177
|
-
(
|
|
205
|
+
(_route_children1 = route.children) === null || _route_children1 === void 0 ? void 0 : _route_children1.push(pageRoute);
|
|
178
206
|
}
|
|
179
207
|
if (itemWithoutExt === NESTED_ROUTE.SPLATE_LOADER_FILE) {
|
|
180
208
|
splatLoaderFile = itemPath;
|
|
@@ -188,7 +216,7 @@ export var walk = function() {
|
|
|
188
216
|
if (splatLoaderFile) {
|
|
189
217
|
splatRoute.loader = splatLoaderFile;
|
|
190
218
|
}
|
|
191
|
-
(
|
|
219
|
+
(_route_children2 = route.children) === null || _route_children2 === void 0 ? void 0 : _route_children2.push(splatRoute);
|
|
192
220
|
}
|
|
193
221
|
if (itemWithoutExt === NESTED_ROUTE.LOADING_FILE) {
|
|
194
222
|
route.loading = replaceWithAlias(alias.basename, itemPath, alias.name);
|
|
@@ -234,17 +262,17 @@ export var walk = function() {
|
|
|
234
262
|
if (isPathlessLayout) {
|
|
235
263
|
delete finalRoute.path;
|
|
236
264
|
}
|
|
237
|
-
|
|
265
|
+
childRoutes = finalRoute.children = (_finalRoute_children = finalRoute.children) === null || _finalRoute_children === void 0 ? void 0 : _finalRoute_children.filter(function(childRoute2) {
|
|
238
266
|
return childRoute2;
|
|
239
267
|
});
|
|
240
|
-
if (
|
|
268
|
+
if (childRoutes && childRoutes.length === 0 && !finalRoute.index) {
|
|
241
269
|
return [
|
|
242
270
|
2,
|
|
243
271
|
null
|
|
244
272
|
];
|
|
245
273
|
}
|
|
246
|
-
if (
|
|
247
|
-
childRoute1 =
|
|
274
|
+
if (childRoutes && childRoutes.length === 1 && !finalRoute._component) {
|
|
275
|
+
childRoute1 = childRoutes[0];
|
|
248
276
|
if (childRoute1.path === "*") {
|
|
249
277
|
_$path = "".concat(finalRoute.path || "", "/").concat(childRoute1.path || "");
|
|
250
278
|
finalRoute = _object_spread_props(_object_spread({}, childRoute1), {
|
|
@@ -252,6 +280,24 @@ export var walk = function() {
|
|
|
252
280
|
});
|
|
253
281
|
}
|
|
254
282
|
}
|
|
283
|
+
if (splatRoute) {
|
|
284
|
+
;
|
|
285
|
+
slatRouteIndex = (_childRoutes = childRoutes) === null || _childRoutes === void 0 ? void 0 : _childRoutes.findIndex(function(childRoute2) {
|
|
286
|
+
return childRoute2 === splatRoute;
|
|
287
|
+
});
|
|
288
|
+
if (typeof slatRouteIndex === "number" && slatRouteIndex !== -1) {
|
|
289
|
+
;
|
|
290
|
+
(_childRoutes1 = childRoutes) === null || _childRoutes1 === void 0 ? void 0 : _childRoutes1.splice(slatRouteIndex, 1);
|
|
291
|
+
(_childRoutes2 = childRoutes) === null || _childRoutes2 === void 0 ? void 0 : _childRoutes2.push(splatRoute);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
if (isRoot && !oldVersion) {
|
|
295
|
+
optimizedRoutes = optimizeRoute(finalRoute);
|
|
296
|
+
return [
|
|
297
|
+
2,
|
|
298
|
+
optimizedRoutes
|
|
299
|
+
];
|
|
300
|
+
}
|
|
255
301
|
return [
|
|
256
302
|
2,
|
|
257
303
|
finalRoute
|
|
@@ -259,7 +305,7 @@ export var walk = function() {
|
|
|
259
305
|
}
|
|
260
306
|
});
|
|
261
307
|
});
|
|
262
|
-
return function walk2(dirname, rootDir, alias, entryName, isMainEntry) {
|
|
308
|
+
return function walk2(dirname, rootDir, alias, entryName, isMainEntry, oldVersion) {
|
|
263
309
|
return _ref.apply(this, arguments);
|
|
264
310
|
};
|
|
265
311
|
}();
|
|
@@ -28,8 +28,8 @@ export var routesForServer = function(param) {
|
|
|
28
28
|
var traverseRouteTree = function(route2) {
|
|
29
29
|
var children;
|
|
30
30
|
if ("children" in route2 && route2.children) {
|
|
31
|
-
var _route_children;
|
|
32
|
-
children = route2 === null ||
|
|
31
|
+
var _route_children, _route;
|
|
32
|
+
children = (_route = route2) === null || _route === void 0 ? void 0 : (_route_children = _route.children) === null || _route_children === void 0 ? void 0 : _route_children.map(traverseRouteTree);
|
|
33
33
|
}
|
|
34
34
|
var loader;
|
|
35
35
|
if (route2.type === "nested") {
|
|
@@ -111,8 +111,8 @@ export var fileSystemRoutes = function() {
|
|
|
111
111
|
traverseRouteTree = function(route2) {
|
|
112
112
|
var children;
|
|
113
113
|
if ("children" in route2 && route2.children) {
|
|
114
|
-
var _route_children;
|
|
115
|
-
children = route2 === null ||
|
|
114
|
+
var _route_children, _route;
|
|
115
|
+
children = (_route = route2) === null || _route === void 0 ? void 0 : (_route_children = _route.children) === null || _route_children === void 0 ? void 0 : _route_children.map(traverseRouteTree);
|
|
116
116
|
}
|
|
117
117
|
var loading;
|
|
118
118
|
var error;
|
|
@@ -13,7 +13,7 @@ export var builderPluginAdpaterCopy = function(options) {
|
|
|
13
13
|
setup: function setup(api) {
|
|
14
14
|
var publicPath;
|
|
15
15
|
api.modifyRspackConfig(function(config) {
|
|
16
|
-
var
|
|
16
|
+
var _config_builtins_copy, _config_builtins, _config_output;
|
|
17
17
|
config.builtins = _object_spread_props(_object_spread({}, config.builtins || {}), {
|
|
18
18
|
copy: {
|
|
19
19
|
patterns: _to_consumable_array(((_config_builtins = config.builtins) === null || _config_builtins === void 0 ? void 0 : (_config_builtins_copy = _config_builtins.copy) === null || _config_builtins_copy === void 0 ? void 0 : _config_builtins_copy.patterns) || []).concat(_to_consumable_array(createConfigBuiltinCopy(options)))
|
|
@@ -3,9 +3,10 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
|
3
3
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
4
4
|
import { createUploadPattern } from "../builder-webpack/createCopyPattern";
|
|
5
5
|
function modifyOutputConfig(config, appContext) {
|
|
6
|
+
var _copy;
|
|
6
7
|
var defaultCopyPattern = createUploadPattern(appContext, config);
|
|
7
8
|
var copy = config.output.copy;
|
|
8
|
-
var copyOptions = Array.isArray(copy) ? copy : copy === null ||
|
|
9
|
+
var copyOptions = Array.isArray(copy) ? copy : (_copy = copy) === null || _copy === void 0 ? void 0 : _copy.patterns;
|
|
9
10
|
var builderCopy = _to_consumable_array(copyOptions || []).concat([
|
|
10
11
|
defaultCopyPattern
|
|
11
12
|
]);
|
|
@@ -76,6 +76,7 @@ export var builderPluginAdapterSSR = function(options) {
|
|
|
76
76
|
};
|
|
77
77
|
};
|
|
78
78
|
var isStreamingSSR = function(userConfig) {
|
|
79
|
+
var _server;
|
|
79
80
|
var isStreaming = function(ssr) {
|
|
80
81
|
return ssr && typeof ssr === "object" && ssr.mode === "stream";
|
|
81
82
|
};
|
|
@@ -83,7 +84,7 @@ var isStreamingSSR = function(userConfig) {
|
|
|
83
84
|
if (isStreaming(server.ssr)) {
|
|
84
85
|
return true;
|
|
85
86
|
}
|
|
86
|
-
if ((server === null ||
|
|
87
|
+
if (((_server = server) === null || _server === void 0 ? void 0 : _server.ssrByEntries) && typeof server.ssrByEntries === "object") {
|
|
87
88
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
88
89
|
try {
|
|
89
90
|
for (var _iterator = Object.keys(server.ssrByEntries)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
@@ -118,41 +119,36 @@ function applyAsyncChunkHtmlPlugin(param) {
|
|
|
118
119
|
}
|
|
119
120
|
}
|
|
120
121
|
function applyRouterPlugin(chain, options) {
|
|
121
|
-
var _normalizedConfig_runtime, _normalizedConfig_deploy_worker;
|
|
122
|
+
var _normalizedConfig_runtime, _normalizedConfig, _routerConfig, _normalizedConfig_deploy_worker;
|
|
122
123
|
var appContext = options.appContext, normalizedConfig = options.normalizedConfig;
|
|
123
124
|
var entrypoints = appContext.entrypoints;
|
|
124
125
|
var existNestedRoutes = entrypoints.some(function(entrypoint) {
|
|
125
126
|
return entrypoint.nestedRoutesEntry;
|
|
126
127
|
});
|
|
127
|
-
var routerConfig = normalizedConfig === null ||
|
|
128
|
-
var routerManifest = Boolean(routerConfig === null ||
|
|
128
|
+
var routerConfig = (_normalizedConfig = normalizedConfig) === null || _normalizedConfig === void 0 ? void 0 : (_normalizedConfig_runtime = _normalizedConfig.runtime) === null || _normalizedConfig_runtime === void 0 ? void 0 : _normalizedConfig_runtime.router;
|
|
129
|
+
var routerManifest = Boolean((_routerConfig = routerConfig) === null || _routerConfig === void 0 ? void 0 : _routerConfig.manifest);
|
|
129
130
|
var workerSSR = Boolean((_normalizedConfig_deploy_worker = normalizedConfig.deploy.worker) === null || _normalizedConfig_deploy_worker === void 0 ? void 0 : _normalizedConfig_deploy_worker.ssr);
|
|
130
|
-
var minimize = !normalizedConfig.output.disableMinimize && process.env.NODE_ENV === "production";
|
|
131
131
|
if (existNestedRoutes || routerManifest || workerSSR) {
|
|
132
|
-
chain.plugin("route-plugin").use(RouterPlugin
|
|
133
|
-
{
|
|
134
|
-
minimize: minimize
|
|
135
|
-
}
|
|
136
|
-
]);
|
|
132
|
+
chain.plugin("route-plugin").use(RouterPlugin);
|
|
137
133
|
}
|
|
138
134
|
}
|
|
139
135
|
function applyFilterEntriesBySSRConfig(param) {
|
|
140
136
|
var isProd = param.isProd, chain = param.chain, appNormalizedConfig = param.appNormalizedConfig;
|
|
141
|
-
var
|
|
137
|
+
var _outputConfig, _this, _outputConfig1, _outputConfig2, _outputConfig3;
|
|
142
138
|
var serverConfig = appNormalizedConfig.server, outputConfig = appNormalizedConfig.output;
|
|
143
139
|
var entries = chain.entryPoints.entries();
|
|
144
|
-
if (isProd && ((outputConfig === null ||
|
|
140
|
+
if (isProd && (((_outputConfig = outputConfig) === null || _outputConfig === void 0 ? void 0 : _outputConfig.ssg) === true || typeof ((_this = (_outputConfig1 = outputConfig) === null || _outputConfig1 === void 0 ? void 0 : _outputConfig1.ssg) === null || _this === void 0 ? void 0 : _this[0]) === "function")) {
|
|
145
141
|
return;
|
|
146
142
|
}
|
|
147
143
|
if (typeof entries === "undefined") {
|
|
148
144
|
throw new Error("No entry found, one of src/routes/layout.tsx, src/App.tsx, src/index.tsx is required");
|
|
149
145
|
}
|
|
150
146
|
var entryNames = Object.keys(entries);
|
|
151
|
-
if (isProd && entryNames.length === 1 && (outputConfig === null ||
|
|
147
|
+
if (isProd && entryNames.length === 1 && ((_outputConfig2 = outputConfig) === null || _outputConfig2 === void 0 ? void 0 : _outputConfig2.ssg)) {
|
|
152
148
|
return;
|
|
153
149
|
}
|
|
154
150
|
var ssgEntries = [];
|
|
155
|
-
if (isProd && (outputConfig === null ||
|
|
151
|
+
if (isProd && ((_outputConfig3 = outputConfig) === null || _outputConfig3 === void 0 ? void 0 : _outputConfig3.ssg)) {
|
|
156
152
|
var ssg = outputConfig.ssg;
|
|
157
153
|
entryNames.forEach(function(name) {
|
|
158
154
|
if (ssg[name]) {
|
|
@@ -160,9 +156,10 @@ function applyFilterEntriesBySSRConfig(param) {
|
|
|
160
156
|
}
|
|
161
157
|
});
|
|
162
158
|
}
|
|
163
|
-
var
|
|
159
|
+
var _ref = serverConfig || {}, ssr = _ref.ssr, ssrByEntries = _ref.ssrByEntries;
|
|
164
160
|
entryNames.forEach(function(name) {
|
|
165
|
-
|
|
161
|
+
var _ssrByEntries, _ssrByEntries1;
|
|
162
|
+
if (!ssgEntries.includes(name) && (ssr && ((_ssrByEntries = ssrByEntries) === null || _ssrByEntries === void 0 ? void 0 : _ssrByEntries[name]) === false || !ssr && !((_ssrByEntries1 = ssrByEntries) === null || _ssrByEntries1 === void 0 ? void 0 : _ssrByEntries1[name]))) {
|
|
166
163
|
chain.entryPoints.delete(name);
|
|
167
164
|
}
|
|
168
165
|
});
|