@modern-js/app-tools 2.27.1-alpha.0 → 2.28.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 +2 -2
- 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 +2 -2
- 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 +2 -2
- package/dist/esm/analyze/getFileSystemEntry.js +2 -1
- package/dist/esm/analyze/getServerRoutes.js +5 -4
- package/dist/esm/analyze/nestedRoutes.js +2 -2
- 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 +2 -2
- 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 +2 -2
- 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/builder/shared/bundlerPlugins/RouterPlugin.d.ts +0 -8
- package/package.json +24 -24
|
@@ -100,7 +100,7 @@ export var generateCode = function() {
|
|
|
100
100
|
}
|
|
101
101
|
function _generateEntryCode() {
|
|
102
102
|
_generateEntryCode = _async_to_generator(function(entrypoint) {
|
|
103
|
-
var entryName, isMainEntry, isAutoMount, fileSystemRoutes, _config_output, initialRoutes, nestedRoute, routes, _$config, ssr, useSSG, mode, hasPageRoute, code, _, _tmp, routesServerFile, code1, serverLoaderCombined, serverLoaderFile, imports, entryFile;
|
|
103
|
+
var entryName, isMainEntry, isAutoMount, fileSystemRoutes, _config_output, _config, initialRoutes, nestedRoute, 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:
|
|
@@ -181,7 +181,7 @@ export var generateCode = function() {
|
|
|
181
181
|
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
182
182
|
entryName: entrypoint.entryName,
|
|
183
183
|
internalDirectory: internalDirectory,
|
|
184
|
-
splitRouteChunks: _$config === null ||
|
|
184
|
+
splitRouteChunks: (_config = _$config) === null || _config === void 0 ? void 0 : (_config_output = _config.output) === null || _config_output === void 0 ? void 0 : _config_output.splitRouteChunks
|
|
185
185
|
})
|
|
186
186
|
];
|
|
187
187
|
case 4:
|
|
@@ -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
|
};
|
|
@@ -40,7 +40,7 @@ var createRoute = function(routeInfo, rootDir, filename, entryName, isMainEntry)
|
|
|
40
40
|
};
|
|
41
41
|
export var walk = function() {
|
|
42
42
|
var _ref = _async_to_generator(function(dirname, rootDir, alias, entryName, isMainEntry) {
|
|
43
|
-
var _route_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_children1, _route_children2, _route_children3, err, finalRoute, childRoute1, _$path;
|
|
43
|
+
var _routePath, _route_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_children1, _route_children2, _route_children3, err, finalRoute, childRoute1, _$path;
|
|
44
44
|
return _ts_generator(this, function(_state) {
|
|
45
45
|
switch (_state.label) {
|
|
46
46
|
case 0:
|
|
@@ -79,7 +79,7 @@ export var walk = function() {
|
|
|
79
79
|
}
|
|
80
80
|
routePath = replaceDynamicPath(routePath);
|
|
81
81
|
route = {
|
|
82
|
-
path: routePath === null ||
|
|
82
|
+
path: (_routePath = routePath) === null || _routePath === void 0 ? void 0 : _routePath.replace(/\$$/, "?"),
|
|
83
83
|
children: [],
|
|
84
84
|
isRoot: isRoot
|
|
85
85
|
};
|
|
@@ -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
|
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
|
3
3
|
import { _ as _create_class } from "@swc/helpers/_/_create_class";
|
|
4
|
-
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
5
4
|
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
6
5
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
7
6
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
@@ -14,10 +13,8 @@ import { transform } from "esbuild";
|
|
|
14
13
|
var PLUGIN_NAME = "ModernjsRoutePlugin";
|
|
15
14
|
export var RouterPlugin = /* @__PURE__ */ function() {
|
|
16
15
|
"use strict";
|
|
17
|
-
function RouterPlugin2(
|
|
16
|
+
function RouterPlugin2() {
|
|
18
17
|
_class_call_check(this, RouterPlugin2);
|
|
19
|
-
_define_property(this, "minimize", false);
|
|
20
|
-
this.minimize = options.minimize;
|
|
21
18
|
}
|
|
22
19
|
_create_class(RouterPlugin2, [
|
|
23
20
|
{
|
|
@@ -32,36 +29,9 @@ export var RouterPlugin = /* @__PURE__ */ function() {
|
|
|
32
29
|
return false;
|
|
33
30
|
}
|
|
34
31
|
},
|
|
35
|
-
{
|
|
36
|
-
key: "getEntryChunks",
|
|
37
|
-
value: function getEntryChunks(compilation, chunks) {
|
|
38
|
-
var entrypointsArray = Array.from(compilation.entrypoints.entries());
|
|
39
|
-
var entryChunkIds = entrypointsArray.map(function(entrypoint) {
|
|
40
|
-
return entrypoint[0];
|
|
41
|
-
});
|
|
42
|
-
var entryChunks = _to_consumable_array(chunks).filter(function(chunk) {
|
|
43
|
-
var _chunk_names;
|
|
44
|
-
return (_chunk_names = chunk.names) === null || _chunk_names === void 0 ? void 0 : _chunk_names.some(function(name) {
|
|
45
|
-
return entryChunkIds.includes(name);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
return entryChunks;
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
key: "getEntryChunkFiles",
|
|
53
|
-
value: function getEntryChunkFiles(entryChunks) {
|
|
54
|
-
return entryChunks.map(function(chunk) {
|
|
55
|
-
return _to_consumable_array(chunk.files || []).find(function(fname) {
|
|
56
|
-
return fname.includes(".js");
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
32
|
{
|
|
62
33
|
key: "apply",
|
|
63
34
|
value: function apply(compiler) {
|
|
64
|
-
var _this = this;
|
|
65
35
|
var target = compiler.options.target;
|
|
66
36
|
if (this.isTargetNodeOrWebWorker(target)) {
|
|
67
37
|
return;
|
|
@@ -75,15 +45,13 @@ export var RouterPlugin = /* @__PURE__ */ function() {
|
|
|
75
45
|
}
|
|
76
46
|
return path2;
|
|
77
47
|
};
|
|
78
|
-
var
|
|
79
|
-
var chunkToMap = /* @__PURE__ */ new Map();
|
|
48
|
+
var chunkToSourceAndMap = /* @__PURE__ */ new Map();
|
|
80
49
|
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, function(compilation) {
|
|
81
|
-
var _this1 = _this;
|
|
82
50
|
compilation.hooks.processAssets.tapPromise({
|
|
83
51
|
name: PLUGIN_NAME,
|
|
84
52
|
stage: Compilation.PROCESS_ASSETS_STAGE_DEV_TOOLING
|
|
85
53
|
}, /* @__PURE__ */ _async_to_generator(function() {
|
|
86
|
-
var stats, _stats_chunks, chunks, namedChunkGroups, entryChunks, entryChunkFiles, entryChunkFileIds, i, file, chunkId, asset, map;
|
|
54
|
+
var stats, _stats_chunks, chunks, namedChunkGroups, entrypointsArray, entryChunkIds, entryChunks, entryChunkFiles, entryChunkFileIds, i, file, chunkId, asset, _asset_sourceAndMap, source, map;
|
|
87
55
|
return _ts_generator(this, function(_state) {
|
|
88
56
|
stats = compilation.getStats().toJson({
|
|
89
57
|
all: false,
|
|
@@ -97,50 +65,16 @@ export var RouterPlugin = /* @__PURE__ */ function() {
|
|
|
97
65
|
2
|
|
98
66
|
];
|
|
99
67
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return
|
|
103
|
-
return fname.includes(".js");
|
|
104
|
-
});
|
|
68
|
+
entrypointsArray = Array.from(compilation.entrypoints.entries());
|
|
69
|
+
entryChunkIds = entrypointsArray.map(function(entrypoint) {
|
|
70
|
+
return entrypoint[0];
|
|
105
71
|
});
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
chunkId = entryChunkFileIds[i];
|
|
112
|
-
asset = compilation.assets[file];
|
|
113
|
-
if (!asset) {
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
map = asset.sourceAndMap().map;
|
|
117
|
-
chunkToMap.set(chunkId, map);
|
|
118
|
-
}
|
|
119
|
-
return [
|
|
120
|
-
2
|
|
121
|
-
];
|
|
122
|
-
});
|
|
123
|
-
}));
|
|
124
|
-
var _this2 = _this;
|
|
125
|
-
compilation.hooks.processAssets.tapPromise({
|
|
126
|
-
name: PLUGIN_NAME,
|
|
127
|
-
stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER
|
|
128
|
-
}, /* @__PURE__ */ _async_to_generator(function() {
|
|
129
|
-
var stats, _stats_chunks, chunks, namedChunkGroups, entryChunks, entryChunkFiles, entryChunkFileIds, i, file, chunkId, asset, source;
|
|
130
|
-
return _ts_generator(this, function(_state) {
|
|
131
|
-
stats = compilation.getStats().toJson({
|
|
132
|
-
all: false,
|
|
133
|
-
chunkGroups: true,
|
|
134
|
-
chunks: true,
|
|
135
|
-
ids: true
|
|
72
|
+
entryChunks = _to_consumable_array(chunks).filter(function(chunk) {
|
|
73
|
+
var _chunk_names;
|
|
74
|
+
return (_chunk_names = chunk.names) === null || _chunk_names === void 0 ? void 0 : _chunk_names.some(function(name) {
|
|
75
|
+
return entryChunkIds.includes(name);
|
|
76
|
+
});
|
|
136
77
|
});
|
|
137
|
-
_stats_chunks = stats.chunks, chunks = _stats_chunks === void 0 ? [] : _stats_chunks, namedChunkGroups = stats.namedChunkGroups;
|
|
138
|
-
if (!namedChunkGroups) {
|
|
139
|
-
return [
|
|
140
|
-
2
|
|
141
|
-
];
|
|
142
|
-
}
|
|
143
|
-
entryChunks = _this2.getEntryChunks(compilation, chunks);
|
|
144
78
|
entryChunkFiles = entryChunks.map(function(chunk) {
|
|
145
79
|
return _to_consumable_array(chunk.files || []).find(function(fname) {
|
|
146
80
|
return fname.includes(".js");
|
|
@@ -156,30 +90,31 @@ export var RouterPlugin = /* @__PURE__ */ function() {
|
|
|
156
90
|
if (!asset) {
|
|
157
91
|
continue;
|
|
158
92
|
}
|
|
159
|
-
|
|
160
|
-
|
|
93
|
+
_asset_sourceAndMap = asset.sourceAndMap(), source = _asset_sourceAndMap.source, map = _asset_sourceAndMap.map;
|
|
94
|
+
chunkToSourceAndMap.set(chunkId, {
|
|
95
|
+
source: source,
|
|
96
|
+
map: map
|
|
97
|
+
});
|
|
161
98
|
}
|
|
162
99
|
return [
|
|
163
100
|
2
|
|
164
101
|
];
|
|
165
102
|
});
|
|
166
103
|
}));
|
|
167
|
-
var _this3 = _this;
|
|
168
104
|
compilation.hooks.processAssets.tapPromise({
|
|
169
105
|
name: PLUGIN_NAME,
|
|
170
106
|
stage: Compilation.PROCESS_ASSETS_STAGE_REPORT
|
|
171
107
|
}, /* @__PURE__ */ _async_to_generator(function() {
|
|
172
|
-
var _loop, stats, publicPath, _stats_chunks, chunks, namedChunkGroups, routeAssets, prevManifestAsset, prevManifestStr, prevManifest, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, name, chunkGroup, assets, referenceCssAssets, manifest, entryChunks, entryChunkFiles, entryChunkFileIds, i;
|
|
108
|
+
var _loop, stats, publicPath, _stats_chunks, chunks, namedChunkGroups, routeAssets, prevManifestAsset, prevManifestStr, prevManifest, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, name, chunkGroup, assets, referenceCssAssets, manifest, entrypointsArray, entryChunkIds, entryChunks, entryChunkFiles, entryChunkFileIds, i;
|
|
173
109
|
return _ts_generator(this, function(_state) {
|
|
174
110
|
switch (_state.label) {
|
|
175
111
|
case 0:
|
|
176
112
|
_loop = function(i2) {
|
|
177
|
-
var file,
|
|
113
|
+
var file, chunkId, asset, relatedAssets, manifest2, injectedContent, _chunkToSourceAndMap_get, source, map, newContent, result, newSource;
|
|
178
114
|
return _ts_generator(this, function(_state2) {
|
|
179
115
|
switch (_state2.label) {
|
|
180
116
|
case 0:
|
|
181
117
|
file = entryChunkFiles[i2];
|
|
182
|
-
chunkNames = entryChunks[i2].names;
|
|
183
118
|
chunkId = entryChunkFileIds[i2];
|
|
184
119
|
asset = compilation.assets[file];
|
|
185
120
|
if (!asset || !chunkId) {
|
|
@@ -189,17 +124,11 @@ export var RouterPlugin = /* @__PURE__ */ function() {
|
|
|
189
124
|
];
|
|
190
125
|
}
|
|
191
126
|
relatedAssets = {};
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
relatedAssets[routeId] = routeAssets[routeId];
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
} else {
|
|
201
|
-
relatedAssets = routeAssets;
|
|
202
|
-
}
|
|
127
|
+
Object.keys(routeAssets).forEach(function(routeId) {
|
|
128
|
+
if (routeId.startsWith("".concat(chunkId))) {
|
|
129
|
+
relatedAssets[routeId] = routeAssets[routeId];
|
|
130
|
+
}
|
|
131
|
+
});
|
|
203
132
|
manifest2 = {
|
|
204
133
|
routeAssets: relatedAssets
|
|
205
134
|
};
|
|
@@ -211,15 +140,14 @@ export var RouterPlugin = /* @__PURE__ */ function() {
|
|
|
211
140
|
}
|
|
212
141
|
return v;
|
|
213
142
|
}), ";\n })();\n ");
|
|
214
|
-
|
|
215
|
-
map = chunkToMap.get(chunkId);
|
|
143
|
+
_chunkToSourceAndMap_get = chunkToSourceAndMap.get(chunkId), source = _chunkToSourceAndMap_get.source, map = _chunkToSourceAndMap_get.map;
|
|
216
144
|
newContent = "".concat(injectedContent).concat(source.toString());
|
|
217
145
|
return [
|
|
218
146
|
4,
|
|
219
147
|
transform(newContent, {
|
|
220
148
|
loader: path.extname(file).slice(1),
|
|
221
149
|
sourcemap: true,
|
|
222
|
-
minify:
|
|
150
|
+
minify: process.env.NODE_ENV === "production"
|
|
223
151
|
})
|
|
224
152
|
];
|
|
225
153
|
case 1:
|
|
@@ -270,7 +198,6 @@ export var RouterPlugin = /* @__PURE__ */ function() {
|
|
|
270
198
|
});
|
|
271
199
|
routeAssets[name] = {
|
|
272
200
|
chunkIds: chunkGroup.chunks,
|
|
273
|
-
chunkName: chunkGroup.name,
|
|
274
201
|
assets: assets,
|
|
275
202
|
referenceCssAssets: referenceCssAssets
|
|
276
203
|
};
|
|
@@ -300,15 +227,28 @@ export var RouterPlugin = /* @__PURE__ */ function() {
|
|
|
300
227
|
manifest = {
|
|
301
228
|
routeAssets: routeAssets
|
|
302
229
|
};
|
|
303
|
-
|
|
304
|
-
|
|
230
|
+
entrypointsArray = Array.from(compilation.entrypoints.entries());
|
|
231
|
+
entryChunkIds = entrypointsArray.map(function(entrypoint) {
|
|
232
|
+
return entrypoint[0];
|
|
233
|
+
});
|
|
234
|
+
entryChunks = _to_consumable_array(chunks).filter(function(chunk) {
|
|
235
|
+
var _chunk_names;
|
|
236
|
+
return (_chunk_names = chunk.names) === null || _chunk_names === void 0 ? void 0 : _chunk_names.some(function(name2) {
|
|
237
|
+
return entryChunkIds.includes(name2);
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
entryChunkFiles = entryChunks.map(function(chunk) {
|
|
241
|
+
return _to_consumable_array(chunk.files || []).find(function(fname) {
|
|
242
|
+
return fname.includes(".js");
|
|
243
|
+
});
|
|
244
|
+
});
|
|
305
245
|
entryChunkFileIds = entryChunks.map(function(chunk) {
|
|
306
246
|
return chunk.id;
|
|
307
247
|
});
|
|
308
248
|
i = 0;
|
|
309
249
|
_state.label = 1;
|
|
310
250
|
case 1:
|
|
311
|
-
if (!(i
|
|
251
|
+
if (!(i <= entryChunkFiles.length - 1))
|
|
312
252
|
return [
|
|
313
253
|
3,
|
|
314
254
|
4
|
|
@@ -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 resolvedConfig, appContext, hookRunners, apiOnly, appDirectory, distDirectory, serverConfigFile, distDirectory1, appDirectory1, serverConfigFile1;
|
|
11
|
+
var _options, 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 (options === null ||
|
|
15
|
+
if ((_options = options) === null || _options === void 0 ? void 0 : _options.analyze) {
|
|
16
16
|
process.env.BUNDLE_ANALYZE = "true";
|
|
17
17
|
}
|
|
18
18
|
resolvedConfig = api.useResolvedConfigContext();
|
|
@@ -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 appContext;
|
|
6
|
+
var _appContext, 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(appContext === null ||
|
|
17
|
+
outputPath: join((_appContext = appContext) === null || _appContext === void 0 ? void 0 : _appContext.builder.context.distPath, options.output),
|
|
18
18
|
writeToDisk: true
|
|
19
19
|
})
|
|
20
20
|
];
|
|
@@ -9,7 +9,7 @@ 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, _userConfig_output_distPath, appContext, userConfig, hookRunners, appDirectory, port, serverConfigFile, metaName, apiOnly, serverInternalPlugins, app;
|
|
12
|
+
var _userConfig_source, _userConfig, _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:
|
|
@@ -20,7 +20,7 @@ export var start = function() {
|
|
|
20
20
|
logger.log(chalk.cyan("Starting the modern server..."));
|
|
21
21
|
return [
|
|
22
22
|
4,
|
|
23
|
-
isApiOnly(appContext.appDirectory, userConfig === null ||
|
|
23
|
+
isApiOnly(appContext.appDirectory, (_userConfig = 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,6 +273,7 @@ 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;
|
|
276
277
|
return {
|
|
277
278
|
name: "@modern-js/app-tools",
|
|
278
279
|
post: [
|
|
@@ -288,10 +289,10 @@ export var appTools = function() {
|
|
|
288
289
|
registerHook: hooks,
|
|
289
290
|
usePlugins: [
|
|
290
291
|
initializePlugin({
|
|
291
|
-
bundler: (options === null ||
|
|
292
|
+
bundler: ((_options = options) === null || _options === void 0 ? void 0 : _options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
|
|
292
293
|
}),
|
|
293
294
|
analyzePlugin({
|
|
294
|
-
bundler: (options === null ||
|
|
295
|
+
bundler: ((_options1 = options) === null || _options1 === void 0 ? void 0 : _options1.bundler) === "experimental-rspack" ? "rspack" : "webpack"
|
|
295
296
|
}),
|
|
296
297
|
lintPlugin()
|
|
297
298
|
],
|
|
@@ -63,7 +63,7 @@ export const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
63
63
|
const { entryName, isMainEntry, isAutoMount, fileSystemRoutes } = entrypoint;
|
|
64
64
|
if (isAutoMount) {
|
|
65
65
|
if (fileSystemRoutes) {
|
|
66
|
-
var _config_output;
|
|
66
|
+
var _config_output, _config;
|
|
67
67
|
let initialRoutes = [];
|
|
68
68
|
let nestedRoute = null;
|
|
69
69
|
if (entrypoint.entry) {
|
|
@@ -110,7 +110,7 @@ export const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
110
110
|
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
111
111
|
entryName: entrypoint.entryName,
|
|
112
112
|
internalDirectory,
|
|
113
|
-
splitRouteChunks: config2 === null ||
|
|
113
|
+
splitRouteChunks: (_config = config2) === null || _config === void 0 ? void 0 : (_config_output = _config.output) === null || _config_output === void 0 ? void 0 : _config_output.splitRouteChunks
|
|
114
114
|
})
|
|
115
115
|
});
|
|
116
116
|
if (entrypoint.nestedRoutesEntry && isUseSSRBundle(config2)) {
|
|
@@ -69,7 +69,8 @@ export const getFileSystemEntry = (appContext, config) => {
|
|
|
69
69
|
const { source: { entriesDir, disableEntryDirs } } = config;
|
|
70
70
|
let disabledDirs = [];
|
|
71
71
|
if (disableEntryDirs && Array.isArray(disableEntryDirs)) {
|
|
72
|
-
|
|
72
|
+
var _disableEntryDirs;
|
|
73
|
+
disabledDirs = (_disableEntryDirs = disableEntryDirs) === null || _disableEntryDirs === void 0 ? void 0 : _disableEntryDirs.map((dir) => ensureAbsolutePath(appDirectory, dir));
|
|
73
74
|
}
|
|
74
75
|
const src = ensureAbsolutePath(appDirectory, entriesDir || "");
|
|
75
76
|
if (fs.existsSync(src)) {
|
|
@@ -68,17 +68,18 @@ 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, _deploy;
|
|
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 = deploy === null ||
|
|
74
|
+
const workerSSR = (_deploy = 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;
|
|
76
77
|
const isMainEntry = entryName === (mainEntryName || MAIN_ENTRY_NAME);
|
|
77
78
|
const entryOptions = getEntryOptions(entryName, isMainEntry, ssr, ssrByEntries, packageName);
|
|
78
79
|
const isSSR = Boolean(entryOptions);
|
|
79
80
|
const isWorker = Boolean(workerSSR);
|
|
80
81
|
const isStream = typeof entryOptions === "object" && entryOptions.mode === "stream";
|
|
81
|
-
const { resHeaders } = (routes === null ||
|
|
82
|
+
const { resHeaders } = ((_routes = routes) === null || _routes === void 0 ? void 0 : _routes[entryName]) || {};
|
|
82
83
|
let route = {
|
|
83
84
|
urlPath: `/${isMainEntry ? "" : entryName}`,
|
|
84
85
|
entryName,
|
|
@@ -90,7 +91,7 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
|
|
|
90
91
|
worker: isWorker ? `${SERVER_WORKER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0,
|
|
91
92
|
bundle: isSSR ? `${SERVER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0
|
|
92
93
|
};
|
|
93
|
-
if (routes === null ||
|
|
94
|
+
if ((_routes1 = routes) === null || _routes1 === void 0 ? void 0 : _routes1.hasOwnProperty(entryName)) {
|
|
94
95
|
const routeOptions = isPlainObject(routes[entryName]) ? routes[entryName] : {
|
|
95
96
|
route: routes[entryName]
|
|
96
97
|
};
|