@modern-js/app-tools 2.34.1-alpha.1 → 2.35.1
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/analyze/generateCode.js +3 -4
- package/dist/cjs/analyze/getFileSystemEntry.js +1 -2
- package/dist/cjs/analyze/getServerRoutes.js +4 -5
- package/dist/cjs/analyze/nestedRoutes.js +2 -2
- package/dist/cjs/analyze/templates.js +4 -4
- package/dist/cjs/builder/generator/createBuilderProviderConfig.js +1 -2
- package/dist/cjs/builder/index.js +1 -1
- package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +4 -20
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +12 -14
- package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +2 -2
- package/dist/cjs/commands/build.js +2 -3
- package/dist/cjs/commands/inspect.js +1 -2
- package/dist/cjs/commands/serve.js +3 -3
- package/dist/cjs/index.js +127 -130
- package/dist/cjs/utils/config.js +1 -1
- package/dist/cjs/utils/printInstructions.js +1 -1
- package/dist/esm/analyze/generateCode.js +4 -4
- package/dist/esm/analyze/getFileSystemEntry.js +1 -2
- package/dist/esm/analyze/getServerRoutes.js +4 -5
- package/dist/esm/analyze/nestedRoutes.js +2 -2
- package/dist/esm/analyze/templates.js +4 -4
- package/dist/esm/builder/generator/createBuilderProviderConfig.js +1 -2
- package/dist/esm/builder/index.js +1 -1
- package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +12 -43
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +12 -14
- package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +2 -2
- package/dist/esm/commands/build.js +3 -3
- package/dist/esm/commands/inspect.js +2 -2
- package/dist/esm/commands/serve.js +4 -4
- package/dist/esm/index.js +2 -3
- package/dist/esm/utils/config.js +2 -2
- package/dist/esm/utils/printInstructions.js +1 -1
- package/dist/esm-node/analyze/generateCode.js +3 -4
- package/dist/esm-node/analyze/getFileSystemEntry.js +1 -2
- package/dist/esm-node/analyze/getServerRoutes.js +4 -5
- package/dist/esm-node/analyze/nestedRoutes.js +2 -2
- package/dist/esm-node/analyze/templates.js +4 -4
- package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +1 -2
- package/dist/esm-node/builder/index.js +1 -1
- package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +4 -19
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +12 -14
- package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +2 -2
- package/dist/esm-node/commands/build.js +2 -3
- package/dist/esm-node/commands/inspect.js +1 -2
- package/dist/esm-node/commands/serve.js +4 -4
- package/dist/esm-node/index.js +127 -130
- package/dist/esm-node/utils/config.js +2 -2
- package/dist/esm-node/utils/printInstructions.js +1 -1
- package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +1 -0
- package/package.json +24 -25
@@ -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
|
97
|
+
var 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,
|
103
|
+
var entryName, isMainEntry, isAutoMount, fileSystemRoutes, _config_output, 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:
|
@@ -205,7 +205,7 @@ export var generateCode = function() {
|
|
205
205
|
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
206
206
|
entryName: entrypoint.entryName,
|
207
207
|
internalDirectory: internalDirectory,
|
208
|
-
splitRouteChunks:
|
208
|
+
splitRouteChunks: _$config === null || _$config === void 0 ? void 0 : (_config_output = _$config.output) === null || _config_output === void 0 ? void 0 : _config_output.splitRouteChunks
|
209
209
|
})
|
210
210
|
];
|
211
211
|
case 4:
|
@@ -294,7 +294,7 @@ export var generateCode = function() {
|
|
294
294
|
isV5 = isRouterV5(config);
|
295
295
|
getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
|
296
296
|
importsStatemets = /* @__PURE__ */ new Map();
|
297
|
-
oldVersion = typeof (
|
297
|
+
oldVersion = typeof (config === null || config === void 0 ? void 0 : config.runtime.router) === "object" ? Boolean((config === null || config === void 0 ? void 0 : config.runtime.router).oldVersion) : false;
|
298
298
|
return [
|
299
299
|
4,
|
300
300
|
Promise.all(entrypoints.map(generateEntryCode))
|
@@ -87,8 +87,7 @@ 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
|
-
|
91
|
-
disabledDirs = (_disableEntryDirs = disableEntryDirs) === null || _disableEntryDirs === void 0 ? void 0 : _disableEntryDirs.map(function(dir) {
|
90
|
+
disabledDirs = disableEntryDirs === null || disableEntryDirs === void 0 ? void 0 : disableEntryDirs.map(function(dir) {
|
92
91
|
return ensureAbsolutePath(appDirectory, dir);
|
93
92
|
});
|
94
93
|
}
|
@@ -69,19 +69,18 @@ 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;
|
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 =
|
75
|
+
var workerSSR = 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;
|
79
78
|
var isMainEntry = entryName === (mainEntryName || MAIN_ENTRY_NAME);
|
80
79
|
var entryOptions = getEntryOptions(entryName, isMainEntry, ssr, ssrByEntries, packageName);
|
81
80
|
var isSSR = Boolean(entryOptions);
|
82
81
|
var isWorker = Boolean(workerSSR);
|
83
82
|
var isStream = typeof entryOptions === "object" && (entryOptions.mode === "stream" || Boolean(entryOptions.preload));
|
84
|
-
var resHeaders = ((
|
83
|
+
var resHeaders = ((routes === null || routes === void 0 ? void 0 : routes[entryName]) || {}).resHeaders;
|
85
84
|
var route = {
|
86
85
|
urlPath: "/".concat(isMainEntry ? "" : entryName),
|
87
86
|
entryName: entryName,
|
@@ -93,7 +92,7 @@ var collectHtmlRoutes = function(entrypoints, appContext, config) {
|
|
93
92
|
worker: isWorker ? "".concat(SERVER_WORKER_BUNDLE_DIRECTORY, "/").concat(entryName, ".js") : void 0,
|
94
93
|
bundle: isSSR ? "".concat(SERVER_BUNDLE_DIRECTORY, "/").concat(entryName, ".js") : void 0
|
95
94
|
};
|
96
|
-
if (
|
95
|
+
if (routes === null || routes === void 0 ? void 0 : routes.hasOwnProperty(entryName)) {
|
97
96
|
var routeOptions = isPlainObject(routes[entryName]) ? routes[entryName] : {
|
98
97
|
route: routes[entryName]
|
99
98
|
};
|
@@ -73,7 +73,7 @@ export var optimizeRoute = function(routeTree) {
|
|
73
73
|
};
|
74
74
|
export var walk = function() {
|
75
75
|
var _ref = _async_to_generator(function(dirname, rootDir, alias, entryName, isMainEntry, oldVersion) {
|
76
|
-
var
|
76
|
+
var _finalRoute_children, isDirectory, relativeDir, pathSegments, lastSegment, isRoot, isPathlessLayout, isWithoutLayoutPath, routePath, route, pageLoaderFile, pageRoute, splatLoaderFile, splatClientData, splatData, splatRoute, pageConfigFile, splatConfigFile, items, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, itemPath, extname, itemWithoutExt, isDirectory1, childRoute, _route_children, _route_children1, _route_children2, err, finalRoute, childRoutes, childRoute1, _$path, optimizedRoutes;
|
77
77
|
return _ts_generator(this, function(_state) {
|
78
78
|
switch (_state.label) {
|
79
79
|
case 0:
|
@@ -112,7 +112,7 @@ export var walk = function() {
|
|
112
112
|
}
|
113
113
|
routePath = replaceDynamicPath(routePath);
|
114
114
|
route = {
|
115
|
-
path:
|
115
|
+
path: routePath === null || routePath === void 0 ? void 0 : routePath.replace(/\$$/, "?"),
|
116
116
|
children: [],
|
117
117
|
isRoot: isRoot
|
118
118
|
};
|
@@ -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 =
|
31
|
+
var _route_children;
|
32
|
+
children = route2 === null || route2 === void 0 ? void 0 : (_route_children = route2.children) === null || _route_children === void 0 ? void 0 : _route_children.map(traverseRouteTree);
|
33
33
|
}
|
34
34
|
var loader;
|
35
35
|
if (route2.type === "nested") {
|
@@ -112,8 +112,8 @@ export var fileSystemRoutes = function() {
|
|
112
112
|
traverseRouteTree = function(route2) {
|
113
113
|
var children;
|
114
114
|
if ("children" in route2 && route2.children) {
|
115
|
-
var _route_children
|
116
|
-
children =
|
115
|
+
var _route_children;
|
116
|
+
children = route2 === null || route2 === void 0 ? void 0 : (_route_children = route2.children) === null || _route_children === void 0 ? void 0 : _route_children.map(traverseRouteTree);
|
117
117
|
}
|
118
118
|
var loading;
|
119
119
|
var error;
|
@@ -3,10 +3,9 @@ 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;
|
7
6
|
var defaultCopyPattern = createUploadPattern(appContext, config);
|
8
7
|
var copy = config.output.copy;
|
9
|
-
var copyOptions = Array.isArray(copy) ? copy :
|
8
|
+
var copyOptions = Array.isArray(copy) ? copy : copy === null || copy === void 0 ? void 0 : copy.patterns;
|
10
9
|
var builderCopy = _to_consumable_array(copyOptions || []).concat([
|
11
10
|
defaultCopyPattern
|
12
11
|
]);
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
|
-
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
3
2
|
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
4
3
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
5
4
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
@@ -34,7 +33,6 @@ export var builderPluginAdapterHtml = function(options) {
|
|
34
33
|
return [
|
35
34
|
4,
|
36
35
|
injectAssetPrefix({
|
37
|
-
api: api,
|
38
36
|
chain: chain
|
39
37
|
})
|
40
38
|
];
|
@@ -60,48 +58,19 @@ function injectAssetPrefix(_) {
|
|
60
58
|
}
|
61
59
|
function _injectAssetPrefix() {
|
62
60
|
_injectAssetPrefix = _async_to_generator(function(param) {
|
63
|
-
var
|
61
|
+
var chain, entries, entryNames, assetPrefix, code;
|
64
62
|
return _ts_generator(this, function(_state) {
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
2
|
77
|
-
];
|
78
|
-
fileName = "rspack-asset-prefix";
|
79
|
-
return [
|
80
|
-
4,
|
81
|
-
import("rspack-plugin-virtual-module")
|
82
|
-
];
|
83
|
-
case 1:
|
84
|
-
_ref = _state.sent(), RspackVirtualModulePlugin = _ref.default;
|
85
|
-
entryNames.forEach(function(entryName) {
|
86
|
-
entries[entryName].prepend(fileName);
|
87
|
-
chain.plugin("rspack-asset-prefix").use(RspackVirtualModulePlugin, [
|
88
|
-
_define_property({}, fileName, code)
|
89
|
-
]);
|
90
|
-
});
|
91
|
-
return [
|
92
|
-
3,
|
93
|
-
3
|
94
|
-
];
|
95
|
-
case 2:
|
96
|
-
entryNames.forEach(function(entryName) {
|
97
|
-
entries[entryName].prepend(createVirtualModule(code));
|
98
|
-
});
|
99
|
-
_state.label = 3;
|
100
|
-
case 3:
|
101
|
-
return [
|
102
|
-
2
|
103
|
-
];
|
104
|
-
}
|
63
|
+
chain = param.chain;
|
64
|
+
entries = chain.entryPoints.entries() || {};
|
65
|
+
entryNames = Object.keys(entries);
|
66
|
+
assetPrefix = removeTailSlash(chain.output.get("publicPath") || "");
|
67
|
+
code = "window.__assetPrefix__ = '".concat(assetPrefix, "';");
|
68
|
+
entryNames.forEach(function(entryName) {
|
69
|
+
entries[entryName].prepend(createVirtualModule(code));
|
70
|
+
});
|
71
|
+
return [
|
72
|
+
2
|
73
|
+
];
|
105
74
|
});
|
106
75
|
});
|
107
76
|
return _injectAssetPrefix.apply(this, arguments);
|
@@ -29,7 +29,7 @@ export var builderPluginAdapterSSR = function(options) {
|
|
29
29
|
target = param.target, CHAIN_ID = param.CHAIN_ID, isProd = param.isProd, HtmlBundlerPlugin = param.HtmlPlugin, isServer = param.isServer;
|
30
30
|
builderConfig = api.getNormalizedConfig();
|
31
31
|
normalizedConfig2 = options.normalizedConfig;
|
32
|
-
applyRouterPlugin(chain, options, HtmlBundlerPlugin);
|
32
|
+
applyRouterPlugin(chain, CHAIN_ID.PLUGIN.ROUTER_MANIFEST, options, HtmlBundlerPlugin);
|
33
33
|
if (!isSSR(normalizedConfig2))
|
34
34
|
return [
|
35
35
|
3,
|
@@ -76,7 +76,6 @@ export var builderPluginAdapterSSR = function(options) {
|
|
76
76
|
};
|
77
77
|
};
|
78
78
|
var isStreamingSSR = function(userConfig) {
|
79
|
-
var _server;
|
80
79
|
var isStreaming = function(ssr) {
|
81
80
|
return ssr && typeof ssr === "object" && ssr.mode === "stream";
|
82
81
|
};
|
@@ -84,7 +83,7 @@ var isStreamingSSR = function(userConfig) {
|
|
84
83
|
if (isStreaming(server.ssr)) {
|
85
84
|
return true;
|
86
85
|
}
|
87
|
-
if ((
|
86
|
+
if ((server === null || server === void 0 ? void 0 : server.ssrByEntries) && typeof server.ssrByEntries === "object") {
|
88
87
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
89
88
|
try {
|
90
89
|
for (var _iterator = Object.keys(server.ssrByEntries)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
@@ -118,19 +117,19 @@ function applyAsyncChunkHtmlPlugin(param) {
|
|
118
117
|
]);
|
119
118
|
}
|
120
119
|
}
|
121
|
-
function applyRouterPlugin(chain, options, HtmlBundlerPlugin) {
|
122
|
-
var _normalizedConfig_runtime,
|
120
|
+
function applyRouterPlugin(chain, pluginName, options, HtmlBundlerPlugin) {
|
121
|
+
var _normalizedConfig_runtime, _normalizedConfig_deploy_worker;
|
123
122
|
var appContext = options.appContext, normalizedConfig = options.normalizedConfig;
|
124
123
|
var entrypoints = appContext.entrypoints;
|
125
124
|
var existNestedRoutes = entrypoints.some(function(entrypoint) {
|
126
125
|
return entrypoint.nestedRoutesEntry;
|
127
126
|
});
|
128
|
-
var routerConfig =
|
129
|
-
var routerManifest = Boolean(
|
127
|
+
var routerConfig = normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_runtime = normalizedConfig.runtime) === null || _normalizedConfig_runtime === void 0 ? void 0 : _normalizedConfig_runtime.router;
|
128
|
+
var routerManifest = Boolean(routerConfig === null || routerConfig === void 0 ? void 0 : routerConfig.manifest);
|
130
129
|
var workerSSR = Boolean((_normalizedConfig_deploy_worker = normalizedConfig.deploy.worker) === null || _normalizedConfig_deploy_worker === void 0 ? void 0 : _normalizedConfig_deploy_worker.ssr);
|
131
130
|
if (existNestedRoutes || routerManifest || workerSSR) {
|
132
131
|
var _normalizedConfig_output_distPath, _normalizedConfig_output, _normalizedConfig_output1, _normalizedConfig_html, _normalizedConfig_security;
|
133
|
-
chain.plugin(
|
132
|
+
chain.plugin(pluginName).use(RouterPlugin, [
|
134
133
|
{
|
135
134
|
HtmlBundlerPlugin: HtmlBundlerPlugin,
|
136
135
|
enableInlineRouteManifests: normalizedConfig.output.enableInlineRouteManifests,
|
@@ -144,21 +143,21 @@ function applyRouterPlugin(chain, options, HtmlBundlerPlugin) {
|
|
144
143
|
}
|
145
144
|
function applyFilterEntriesBySSRConfig(param) {
|
146
145
|
var isProd = param.isProd, chain = param.chain, appNormalizedConfig = param.appNormalizedConfig;
|
147
|
-
var
|
146
|
+
var _this;
|
148
147
|
var serverConfig = appNormalizedConfig.server, outputConfig = appNormalizedConfig.output;
|
149
148
|
var entries = chain.entryPoints.entries();
|
150
|
-
if (isProd && ((
|
149
|
+
if (isProd && ((outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg) === true || typeof ((_this = outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg) === null || _this === void 0 ? void 0 : _this[0]) === "function")) {
|
151
150
|
return;
|
152
151
|
}
|
153
152
|
if (typeof entries === "undefined") {
|
154
153
|
throw new Error("No entry found, one of src/routes/layout.tsx, src/App.tsx, src/index.tsx is required");
|
155
154
|
}
|
156
155
|
var entryNames = Object.keys(entries);
|
157
|
-
if (isProd && entryNames.length === 1 && (
|
156
|
+
if (isProd && entryNames.length === 1 && (outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg)) {
|
158
157
|
return;
|
159
158
|
}
|
160
159
|
var ssgEntries = [];
|
161
|
-
if (isProd && (
|
160
|
+
if (isProd && (outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg)) {
|
162
161
|
var ssg = outputConfig.ssg;
|
163
162
|
entryNames.forEach(function(name) {
|
164
163
|
if (ssg[name]) {
|
@@ -168,8 +167,7 @@ function applyFilterEntriesBySSRConfig(param) {
|
|
168
167
|
}
|
169
168
|
var _ref = serverConfig || {}, ssr = _ref.ssr, ssrByEntries = _ref.ssrByEntries;
|
170
169
|
entryNames.forEach(function(name) {
|
171
|
-
|
172
|
-
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]))) {
|
170
|
+
if (!ssgEntries.includes(name) && (ssr && (ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]) === false || !ssr && !(ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]))) {
|
173
171
|
chain.entryPoints.delete(name);
|
174
172
|
}
|
175
173
|
});
|
@@ -18,6 +18,7 @@ export var RouterPlugin = /* @__PURE__ */ function() {
|
|
18
18
|
function RouterPlugin2(param) {
|
19
19
|
var _param_staticJsDir = param.staticJsDir, staticJsDir = _param_staticJsDir === void 0 ? "static/js" : _param_staticJsDir, HtmlBundlerPlugin = param.HtmlBundlerPlugin, enableInlineRouteManifests = param.enableInlineRouteManifests, _param_disableFilenameHash = param.disableFilenameHash, disableFilenameHash = _param_disableFilenameHash === void 0 ? false : _param_disableFilenameHash, _param_scriptLoading = param.scriptLoading, scriptLoading = _param_scriptLoading === void 0 ? "defer" : _param_scriptLoading, nonce = param.nonce;
|
20
20
|
_class_call_check(this, RouterPlugin2);
|
21
|
+
_define_property(this, "name", "RouterPlugin");
|
21
22
|
_define_property(this, "HtmlBundlerPlugin", void 0);
|
22
23
|
_define_property(this, "enableInlineRouteManifests", void 0);
|
23
24
|
_define_property(this, "staticJsDir", void 0);
|
@@ -117,10 +118,9 @@ export var RouterPlugin = /* @__PURE__ */ function() {
|
|
117
118
|
var relatedAssets = {};
|
118
119
|
if (entryChunkFiles.length > 1) {
|
119
120
|
Object.keys(routeAssets).forEach(function(routeId) {
|
120
|
-
var _chunkNames;
|
121
121
|
var segments = routeId.split("_");
|
122
122
|
var chunkName = segments[0];
|
123
|
-
if (
|
123
|
+
if (chunkNames === null || chunkNames === void 0 ? void 0 : chunkNames.includes(chunkName)) {
|
124
124
|
relatedAssets[routeId] = routeAssets[routeId];
|
125
125
|
}
|
126
126
|
});
|
@@ -8,11 +8,11 @@ import { generateRoutes } from "../utils/routes";
|
|
8
8
|
import { buildServerConfig } from "../utils/config";
|
9
9
|
export var build = function() {
|
10
10
|
var _ref = _async_to_generator(function(api, options) {
|
11
|
-
var
|
11
|
+
var resolvedConfig, appContext, hookRunners, apiOnly, appDirectory, distDirectory, serverConfigFile, distDirectory1, appDirectory1, serverConfigFile1;
|
12
12
|
return _ts_generator(this, function(_state) {
|
13
13
|
switch (_state.label) {
|
14
14
|
case 0:
|
15
|
-
if (
|
15
|
+
if (options === null || options === void 0 ? void 0 : options.analyze) {
|
16
16
|
process.env.BUNDLE_ANALYZE = "true";
|
17
17
|
}
|
18
18
|
resolvedConfig = api.useResolvedConfigContext();
|
@@ -78,7 +78,7 @@ export var build = function() {
|
|
78
78
|
];
|
79
79
|
case 6:
|
80
80
|
_state.sent();
|
81
|
-
logger.info("
|
81
|
+
logger.info("Starting production build...");
|
82
82
|
if (!appContext.builder) {
|
83
83
|
throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
|
84
84
|
}
|
@@ -3,7 +3,7 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
3
|
import { join } from "path";
|
4
4
|
export var inspect = function() {
|
5
5
|
var _ref = _async_to_generator(function(api, options) {
|
6
|
-
var
|
6
|
+
var appContext;
|
7
7
|
return _ts_generator(this, function(_state) {
|
8
8
|
appContext = api.useAppContext();
|
9
9
|
if (!appContext.builder) {
|
@@ -14,7 +14,7 @@ export var inspect = function() {
|
|
14
14
|
appContext.builder.inspectConfig({
|
15
15
|
env: options.env,
|
16
16
|
verbose: options.verbose,
|
17
|
-
outputPath: join(
|
17
|
+
outputPath: join(appContext === null || appContext === void 0 ? void 0 : appContext.builder.context.distPath, options.output),
|
18
18
|
writeToDisk: true
|
19
19
|
})
|
20
20
|
];
|
@@ -2,14 +2,14 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
3
3
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
4
4
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
5
|
-
import { logger,
|
5
|
+
import { logger, isApiOnly, getTargetDir } from "@modern-js/utils";
|
6
6
|
import server from "@modern-js/prod-server";
|
7
7
|
import { printInstructions } from "../utils/printInstructions";
|
8
8
|
import { injectDataLoaderPlugin } from "../utils/createServer";
|
9
9
|
import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
|
10
10
|
export var start = function() {
|
11
11
|
var _ref = _async_to_generator(function(api) {
|
12
|
-
var _userConfig_source,
|
12
|
+
var _userConfig_source, _userConfig_output_distPath, appContext, userConfig, hookRunners, appDirectory, port, serverConfigFile, metaName, apiOnly, serverInternalPlugins, app;
|
13
13
|
return _ts_generator(this, function(_state) {
|
14
14
|
switch (_state.label) {
|
15
15
|
case 0:
|
@@ -17,10 +17,10 @@ export var start = function() {
|
|
17
17
|
userConfig = api.useResolvedConfigContext();
|
18
18
|
hookRunners = api.useHookRunners();
|
19
19
|
appDirectory = appContext.appDirectory, port = appContext.port, serverConfigFile = appContext.serverConfigFile, metaName = appContext.metaName;
|
20
|
-
logger.
|
20
|
+
logger.info("Starting production server...");
|
21
21
|
return [
|
22
22
|
4,
|
23
|
-
isApiOnly(appContext.appDirectory,
|
23
|
+
isApiOnly(appContext.appDirectory, userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_source = userConfig.source) === null || _userConfig_source === void 0 ? void 0 : _userConfig_source.entriesDir, appContext.apiDirectory)
|
24
24
|
];
|
25
25
|
case 1:
|
26
26
|
apiOnly = _state.sent();
|
package/dist/esm/index.js
CHANGED
@@ -273,7 +273,6 @@ export var appTools = function() {
|
|
273
273
|
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
|
274
274
|
bundler: "webpack"
|
275
275
|
};
|
276
|
-
var _options, _options1;
|
277
276
|
return {
|
278
277
|
name: "@modern-js/app-tools",
|
279
278
|
post: [
|
@@ -289,10 +288,10 @@ export var appTools = function() {
|
|
289
288
|
registerHook: hooks,
|
290
289
|
usePlugins: [
|
291
290
|
initializePlugin({
|
292
|
-
bundler: (
|
291
|
+
bundler: (options === null || options === void 0 ? void 0 : options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
|
293
292
|
}),
|
294
293
|
analyzePlugin({
|
295
|
-
bundler: (
|
294
|
+
bundler: (options === null || options === void 0 ? void 0 : options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
|
296
295
|
}),
|
297
296
|
lintPlugin()
|
298
297
|
],
|
package/dist/esm/utils/config.js
CHANGED
@@ -4,7 +4,7 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
4
4
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
5
5
|
import * as path from "path";
|
6
6
|
import { bundle } from "@modern-js/node-bundle-require";
|
7
|
-
import {
|
7
|
+
import { fs, getServerConfig, ensureAbsolutePath, OUTPUT_CONFIG_FILE, CONFIG_FILE_EXTENSIONS } from "@modern-js/utils";
|
8
8
|
export var defineServerConfig = function(config) {
|
9
9
|
return config;
|
10
10
|
};
|
@@ -109,7 +109,7 @@ export var emitResolvedConfig = function() {
|
|
109
109
|
return _ts_generator(this, function(_state) {
|
110
110
|
switch (_state.label) {
|
111
111
|
case 0:
|
112
|
-
outputPath =
|
112
|
+
outputPath = ensureAbsolutePath(appDirectory, path.join(((_resolvedConfig_output_distPath = resolvedConfig.output.distPath) === null || _resolvedConfig_output_distPath === void 0 ? void 0 : _resolvedConfig_output_distPath.root) || "./dist", OUTPUT_CONFIG_FILE));
|
113
113
|
return [
|
114
114
|
4,
|
115
115
|
fs.writeJSON(outputPath, resolvedConfig, {
|
@@ -50,13 +50,12 @@ ${initialize || ""}`);
|
|
50
50
|
${initialize || ""}`).join("\n");
|
51
51
|
};
|
52
52
|
export const generateCode = async (appContext, config, entrypoints, api) => {
|
53
|
-
var _config, _config1;
|
54
53
|
const { internalDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName } = appContext;
|
55
54
|
const hookRunners = api.useHookRunners();
|
56
55
|
const isV5 = isRouterV5(config);
|
57
56
|
const getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
|
58
57
|
const importsStatemets = /* @__PURE__ */ new Map();
|
59
|
-
const oldVersion = typeof (
|
58
|
+
const oldVersion = typeof (config === null || config === void 0 ? void 0 : config.runtime.router) === "object" ? Boolean((config === null || config === void 0 ? void 0 : config.runtime.router).oldVersion) : false;
|
60
59
|
await Promise.all(entrypoints.map(generateEntryCode));
|
61
60
|
return {
|
62
61
|
importsStatemets
|
@@ -65,7 +64,7 @@ export const generateCode = async (appContext, config, entrypoints, api) => {
|
|
65
64
|
const { entryName, isMainEntry, isAutoMount, fileSystemRoutes } = entrypoint;
|
66
65
|
if (isAutoMount) {
|
67
66
|
if (fileSystemRoutes) {
|
68
|
-
var _config_output
|
67
|
+
var _config_output;
|
69
68
|
let initialRoutes = [];
|
70
69
|
let nestedRoutes = null;
|
71
70
|
if (entrypoint.entry) {
|
@@ -119,7 +118,7 @@ export const generateCode = async (appContext, config, entrypoints, api) => {
|
|
119
118
|
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
120
119
|
entryName: entrypoint.entryName,
|
121
120
|
internalDirectory,
|
122
|
-
splitRouteChunks:
|
121
|
+
splitRouteChunks: config2 === null || config2 === void 0 ? void 0 : (_config_output = config2.output) === null || _config_output === void 0 ? void 0 : _config_output.splitRouteChunks
|
123
122
|
})
|
124
123
|
});
|
125
124
|
if (entrypoint.nestedRoutesEntry && isUseSSRBundle(config2)) {
|
@@ -69,8 +69,7 @@ export const getFileSystemEntry = (appContext, config) => {
|
|
69
69
|
const { source: { entriesDir, disableEntryDirs } } = config;
|
70
70
|
let disabledDirs = [];
|
71
71
|
if (disableEntryDirs && Array.isArray(disableEntryDirs)) {
|
72
|
-
|
73
|
-
disabledDirs = (_disableEntryDirs = disableEntryDirs) === null || _disableEntryDirs === void 0 ? void 0 : _disableEntryDirs.map((dir) => ensureAbsolutePath(appDirectory, dir));
|
72
|
+
disabledDirs = disableEntryDirs === null || disableEntryDirs === void 0 ? void 0 : disableEntryDirs.map((dir) => ensureAbsolutePath(appDirectory, dir));
|
74
73
|
}
|
75
74
|
const src = ensureAbsolutePath(appDirectory, entriesDir || "");
|
76
75
|
if (fs.existsSync(src)) {
|
@@ -68,18 +68,17 @@ const applyRouteOptions = (original, routeOptions) => {
|
|
68
68
|
return routes;
|
69
69
|
};
|
70
70
|
const collectHtmlRoutes = (entrypoints, appContext, config) => {
|
71
|
-
var _deploy_worker
|
71
|
+
var _deploy_worker;
|
72
72
|
const { source: { mainEntryName }, html: { disableHtmlFolder }, output: { distPath: { html: htmlPath } = {} }, server: { baseUrl, routes, ssr, ssrByEntries }, deploy } = config;
|
73
73
|
const { packageName } = appContext;
|
74
|
-
const workerSSR =
|
74
|
+
const workerSSR = deploy === null || deploy === void 0 ? void 0 : (_deploy_worker = deploy.worker) === null || _deploy_worker === void 0 ? void 0 : _deploy_worker.ssr;
|
75
75
|
let htmlRoutes = entrypoints.reduce((previous, { entryName }) => {
|
76
|
-
var _routes, _routes1;
|
77
76
|
const isMainEntry = entryName === (mainEntryName || MAIN_ENTRY_NAME);
|
78
77
|
const entryOptions = getEntryOptions(entryName, isMainEntry, ssr, ssrByEntries, packageName);
|
79
78
|
const isSSR = Boolean(entryOptions);
|
80
79
|
const isWorker = Boolean(workerSSR);
|
81
80
|
const isStream = typeof entryOptions === "object" && (entryOptions.mode === "stream" || Boolean(entryOptions.preload));
|
82
|
-
const { resHeaders } = (
|
81
|
+
const { resHeaders } = (routes === null || routes === void 0 ? void 0 : routes[entryName]) || {};
|
83
82
|
let route = {
|
84
83
|
urlPath: `/${isMainEntry ? "" : entryName}`,
|
85
84
|
entryName,
|
@@ -91,7 +90,7 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
|
|
91
90
|
worker: isWorker ? `${SERVER_WORKER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0,
|
92
91
|
bundle: isSSR ? `${SERVER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0
|
93
92
|
};
|
94
|
-
if (
|
93
|
+
if (routes === null || routes === void 0 ? void 0 : routes.hasOwnProperty(entryName)) {
|
95
94
|
const routeOptions = isPlainObject(routes[entryName]) ? routes[entryName] : {
|
96
95
|
route: routes[entryName]
|
97
96
|
};
|
@@ -70,7 +70,7 @@ export const optimizeRoute = (routeTree) => {
|
|
70
70
|
}
|
71
71
|
};
|
72
72
|
export const walk = async (dirname, rootDir, alias, entryName, isMainEntry, oldVersion) => {
|
73
|
-
var
|
73
|
+
var _finalRoute_children;
|
74
74
|
if (!await fs.pathExists(dirname)) {
|
75
75
|
return null;
|
76
76
|
}
|
@@ -90,7 +90,7 @@ export const walk = async (dirname, rootDir, alias, entryName, isMainEntry, oldV
|
|
90
90
|
}
|
91
91
|
routePath = replaceDynamicPath(routePath);
|
92
92
|
const route = {
|
93
|
-
path:
|
93
|
+
path: routePath === null || routePath === void 0 ? void 0 : routePath.replace(/\$$/, "?"),
|
94
94
|
children: [],
|
95
95
|
isRoot
|
96
96
|
};
|
@@ -76,8 +76,8 @@ export const routesForServer = ({ routes }) => {
|
|
76
76
|
const traverseRouteTree = (route) => {
|
77
77
|
let children;
|
78
78
|
if ("children" in route && route.children) {
|
79
|
-
var _route_children
|
80
|
-
children =
|
79
|
+
var _route_children;
|
80
|
+
children = route === null || route === void 0 ? void 0 : (_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.map(traverseRouteTree);
|
81
81
|
}
|
82
82
|
let loader;
|
83
83
|
if (route.type === "nested") {
|
@@ -145,8 +145,8 @@ export const fileSystemRoutes = async ({ routes, ssrMode, nestedRoutesEntry, ent
|
|
145
145
|
const traverseRouteTree = (route) => {
|
146
146
|
let children;
|
147
147
|
if ("children" in route && route.children) {
|
148
|
-
var _route_children
|
149
|
-
children =
|
148
|
+
var _route_children;
|
149
|
+
children = route === null || route === void 0 ? void 0 : (_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.map(traverseRouteTree);
|
150
150
|
}
|
151
151
|
let loading;
|
152
152
|
let error;
|
@@ -1,9 +1,8 @@
|
|
1
1
|
import { createUploadPattern } from "../builder-webpack/createCopyPattern";
|
2
2
|
function modifyOutputConfig(config, appContext) {
|
3
|
-
var _copy;
|
4
3
|
const defaultCopyPattern = createUploadPattern(appContext, config);
|
5
4
|
const { copy } = config.output;
|
6
|
-
const copyOptions = Array.isArray(copy) ? copy :
|
5
|
+
const copyOptions = Array.isArray(copy) ? copy : copy === null || copy === void 0 ? void 0 : copy.patterns;
|
7
6
|
const builderCopy = [
|
8
7
|
...copyOptions || [],
|
9
8
|
defaultCopyPattern
|
@@ -5,7 +5,7 @@ export async function createBuilderGenerator(bundler) {
|
|
5
5
|
const { createRspackBuilderForModern } = await import("./builder-rspack");
|
6
6
|
const { getRspackVersion } = await import("@modern-js/builder-rspack-provider");
|
7
7
|
const version = await getRspackVersion();
|
8
|
-
logger.info(`Using Rspack v${version}
|
8
|
+
logger.info(`Using Rspack v${version}`);
|
9
9
|
return createRspackBuilderForModern;
|
10
10
|
} catch (_) {
|
11
11
|
throw new Error("Failed to use Rspack, please check if you have `@modern-js/builder-rspack-provider` installed");
|