@modern-js/app-tools 2.63.1-alpha.0 → 2.63.2
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/config/default.js +6 -1
- package/dist/cjs/config/legacy/index.js +0 -1
- package/dist/cjs/plugins/analyze/getServerRoutes.js +12 -2
- package/dist/cjs/plugins/analyze/index.js +25 -10
- package/dist/cjs/plugins/analyze/utils.js +6 -0
- package/dist/esm/config/default.js +12 -1
- package/dist/esm/config/legacy/index.js +0 -1
- package/dist/esm/plugins/analyze/getServerRoutes.js +11 -2
- package/dist/esm/plugins/analyze/index.js +76 -34
- package/dist/esm/plugins/analyze/utils.js +5 -0
- package/dist/esm-node/config/default.js +6 -1
- package/dist/esm-node/config/legacy/index.js +0 -1
- package/dist/esm-node/plugins/analyze/getServerRoutes.js +11 -2
- package/dist/esm-node/plugins/analyze/index.js +26 -11
- package/dist/esm-node/plugins/analyze/utils.js +5 -0
- package/dist/types/plugins/analyze/getServerRoutes.d.ts +1 -0
- package/dist/types/plugins/analyze/utils.d.ts +1 -0
- package/dist/types/types/config/index.d.ts +0 -1
- package/package.json +21 -20
@@ -28,7 +28,12 @@ function createDefaultConfig(appContext) {
|
|
28
28
|
const dev = {
|
29
29
|
// `dev.port` should not have a default value
|
30
30
|
// because we will use `server.port` by default
|
31
|
-
port: void 0
|
31
|
+
port: void 0,
|
32
|
+
cliShortcuts: {
|
33
|
+
help: false,
|
34
|
+
// does not support restart server and print urls yet
|
35
|
+
custom: (shortcuts = []) => shortcuts.filter(({ key }) => key !== "r" && key !== "u")
|
36
|
+
}
|
32
37
|
};
|
33
38
|
const output = {
|
34
39
|
distPath: {
|
@@ -28,10 +28,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
29
|
var getServerRoutes_exports = {};
|
30
30
|
__export(getServerRoutes_exports, {
|
31
|
+
getProdServerRoutes: () => getProdServerRoutes,
|
31
32
|
getServerRoutes: () => getServerRoutes
|
32
33
|
});
|
33
34
|
module.exports = __toCommonJS(getServerRoutes_exports);
|
34
|
-
var import_fs = __toESM(require("fs"));
|
35
35
|
var import_path = __toESM(require("path"));
|
36
36
|
var import_utils = require("@modern-js/utils");
|
37
37
|
var import_routes = require("../../utils/routes");
|
@@ -148,7 +148,7 @@ const collectStaticRoutes = (appContext, config) => {
|
|
148
148
|
const ignoreFiles = [
|
149
149
|
".gitkeep"
|
150
150
|
];
|
151
|
-
return
|
151
|
+
return import_utils.fs.existsSync(publicFolder) ? (0, import_utils2.walkDirectory)(publicFolder).filter((filePath) => !ignoreFiles.includes(import_path.default.basename(filePath))).map((filePath) => {
|
152
152
|
const urlPath = `${(0, import_utils.urlJoin)(toPosix(filePath).slice(toPosix(publicFolder).length))}`;
|
153
153
|
return {
|
154
154
|
urlPath: publicRoutes[(0, import_utils.removeLeadingSlash)(urlPath)] || urlPath,
|
@@ -163,7 +163,17 @@ const getServerRoutes = (entrypoints, { appContext, config }) => [
|
|
163
163
|
...collectStaticRoutes(appContext, config)
|
164
164
|
];
|
165
165
|
const toPosix = (pathStr) => pathStr.split(import_path.default.sep).join(import_path.default.posix.sep);
|
166
|
+
const getProdServerRoutes = (distDirectory) => {
|
167
|
+
const routeJSON = import_path.default.join(distDirectory, import_utils.ROUTE_SPEC_FILE);
|
168
|
+
try {
|
169
|
+
const { routes } = import_utils.fs.readJSONSync(routeJSON);
|
170
|
+
return routes;
|
171
|
+
} catch (e) {
|
172
|
+
throw new Error(`Failed to read routes from ${routeJSON}, please check if the file exists.`);
|
173
|
+
}
|
174
|
+
};
|
166
175
|
// Annotate the CommonJS export names for ESM import in node:
|
167
176
|
0 && (module.exports = {
|
177
|
+
getProdServerRoutes,
|
168
178
|
getServerRoutes
|
169
179
|
});
|
@@ -62,10 +62,19 @@ var analyze_default = ({ bundler }) => ({
|
|
62
62
|
}
|
63
63
|
const apiOnly = await (0, import_utils.isApiOnly)(appContext.appDirectory, (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.entriesDir, appContext.apiDirectory);
|
64
64
|
await hooks.addRuntimeExports.call();
|
65
|
+
const [{ getProdServerRoutes }] = await Promise.all([
|
66
|
+
import("./getServerRoutes.js")
|
67
|
+
]);
|
65
68
|
if (apiOnly) {
|
66
|
-
const
|
67
|
-
|
68
|
-
|
69
|
+
const routes2 = [];
|
70
|
+
if ((0, import_utils2.checkIsServeCommand)()) {
|
71
|
+
routes2.push(...getProdServerRoutes(appContext.distDirectory));
|
72
|
+
} else {
|
73
|
+
const { routes: modifiedRoutes } = await hooks.modifyServerRoutes.call({
|
74
|
+
routes: []
|
75
|
+
});
|
76
|
+
routes2.push(...modifiedRoutes);
|
77
|
+
}
|
69
78
|
debug(`server routes: %o`, routes2);
|
70
79
|
api.updateAppContext({
|
71
80
|
apiOnly,
|
@@ -82,13 +91,19 @@ var analyze_default = ({ bundler }) => ({
|
|
82
91
|
entrypoints: await getBundleEntry(hooks, appContext, resolvedConfig)
|
83
92
|
});
|
84
93
|
debug(`entrypoints: %o`, entrypoints);
|
85
|
-
const
|
86
|
-
|
87
|
-
|
88
|
-
}
|
89
|
-
|
90
|
-
|
91
|
-
|
94
|
+
const routes = [];
|
95
|
+
if ((0, import_utils2.checkIsServeCommand)()) {
|
96
|
+
routes.push(...getProdServerRoutes(appContext.distDirectory));
|
97
|
+
} else {
|
98
|
+
const initialRoutes = getServerRoutes(entrypoints, {
|
99
|
+
appContext,
|
100
|
+
config: resolvedConfig
|
101
|
+
});
|
102
|
+
const { routes: modifiedRoutes } = await hooks.modifyServerRoutes.call({
|
103
|
+
routes: initialRoutes
|
104
|
+
});
|
105
|
+
routes.push(...modifiedRoutes);
|
106
|
+
}
|
92
107
|
debug(`server routes: %o`, routes);
|
93
108
|
appContext = {
|
94
109
|
...api.getAppContext(),
|
@@ -29,6 +29,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
29
29
|
var utils_exports = {};
|
30
30
|
__export(utils_exports, {
|
31
31
|
checkIsBuildCommands: () => checkIsBuildCommands,
|
32
|
+
checkIsServeCommand: () => checkIsServeCommand,
|
32
33
|
getServerCombinedModueFile: () => getServerCombinedModueFile,
|
33
34
|
isSubDirOrEqual: () => isSubDirOrEqual,
|
34
35
|
parseModule: () => parseModule,
|
@@ -88,6 +89,10 @@ const checkIsBuildCommands = () => {
|
|
88
89
|
const command = (0, import_utils.getCommand)();
|
89
90
|
return buildCommands.includes(command);
|
90
91
|
};
|
92
|
+
const checkIsServeCommand = () => {
|
93
|
+
const command = (0, import_utils.getCommand)();
|
94
|
+
return command === "serve";
|
95
|
+
};
|
91
96
|
const isSubDirOrEqual = (parent, child) => {
|
92
97
|
if (parent === child) {
|
93
98
|
return true;
|
@@ -99,6 +104,7 @@ const isSubDirOrEqual = (parent, child) => {
|
|
99
104
|
// Annotate the CommonJS export names for ESM import in node:
|
100
105
|
0 && (module.exports = {
|
101
106
|
checkIsBuildCommands,
|
107
|
+
checkIsServeCommand,
|
102
108
|
getServerCombinedModueFile,
|
103
109
|
isSubDirOrEqual,
|
104
110
|
parseModule,
|
@@ -5,7 +5,18 @@ function createDefaultConfig(appContext) {
|
|
5
5
|
var dev = {
|
6
6
|
// `dev.port` should not have a default value
|
7
7
|
// because we will use `server.port` by default
|
8
|
-
port: void 0
|
8
|
+
port: void 0,
|
9
|
+
cliShortcuts: {
|
10
|
+
help: false,
|
11
|
+
// does not support restart server and print urls yet
|
12
|
+
custom: function() {
|
13
|
+
var shortcuts = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
|
14
|
+
return shortcuts.filter(function(param) {
|
15
|
+
var key = param.key;
|
16
|
+
return key !== "r" && key !== "u";
|
17
|
+
});
|
18
|
+
}
|
19
|
+
}
|
9
20
|
};
|
10
21
|
var output = {
|
11
22
|
distPath: {
|
@@ -3,9 +3,8 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
3
3
|
import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties";
|
4
4
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
5
5
|
import { _ as _type_of } from "@swc/helpers/_/_type_of";
|
6
|
-
import fs from "fs";
|
7
6
|
import path from "path";
|
8
|
-
import { SERVER_BUNDLE_DIRECTORY, SERVER_WORKER_BUNDLE_DIRECTORY, getEntryOptions, isPlainObject, removeLeadingSlash, removeTailSlash, urlJoin } from "@modern-js/utils";
|
7
|
+
import { fs, ROUTE_SPEC_FILE, SERVER_BUNDLE_DIRECTORY, SERVER_WORKER_BUNDLE_DIRECTORY, getEntryOptions, isPlainObject, removeLeadingSlash, removeTailSlash, urlJoin } from "@modern-js/utils";
|
9
8
|
import { isMainEntry } from "../../utils/routes";
|
10
9
|
import { walkDirectory } from "./utils";
|
11
10
|
var applyBaseUrl = function(baseUrl, routes) {
|
@@ -132,6 +131,16 @@ var getServerRoutes = function(entrypoints, param) {
|
|
132
131
|
var toPosix = function(pathStr) {
|
133
132
|
return pathStr.split(path.sep).join(path.posix.sep);
|
134
133
|
};
|
134
|
+
var getProdServerRoutes = function(distDirectory) {
|
135
|
+
var routeJSON = path.join(distDirectory, ROUTE_SPEC_FILE);
|
136
|
+
try {
|
137
|
+
var routes = fs.readJSONSync(routeJSON).routes;
|
138
|
+
return routes;
|
139
|
+
} catch (e) {
|
140
|
+
throw new Error("Failed to read routes from ".concat(routeJSON, ", please check if the file exists."));
|
141
|
+
}
|
142
|
+
};
|
135
143
|
export {
|
144
|
+
getProdServerRoutes,
|
136
145
|
getServerRoutes
|
137
146
|
};
|
@@ -2,6 +2,7 @@ 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 _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
5
|
+
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
5
6
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
6
7
|
import * as path from "path";
|
7
8
|
import { fs, createDebugger, getArgv, isApiOnly, isDevCommand, minimist } from "@modern-js/utils";
|
@@ -11,7 +12,7 @@ import { emitResolvedConfig } from "../../utils/config";
|
|
11
12
|
import { getSelectedEntries } from "../../utils/getSelectedEntries";
|
12
13
|
import { printInstructions } from "../../utils/printInstructions";
|
13
14
|
import { generateRoutes } from "../../utils/routes";
|
14
|
-
import { checkIsBuildCommands } from "./utils";
|
15
|
+
import { checkIsBuildCommands, checkIsServeCommand } from "./utils";
|
15
16
|
var debug = createDebugger("plugin-analyze");
|
16
17
|
function analyze_default(param) {
|
17
18
|
var bundler = param.bundler;
|
@@ -24,7 +25,7 @@ function analyze_default(param) {
|
|
24
25
|
var pagesDir = [];
|
25
26
|
var nestedRouteEntries = [];
|
26
27
|
api.onPrepare(/* @__PURE__ */ _async_to_generator(function() {
|
27
|
-
var _resolvedConfig_source, appContext, resolvedConfig, hooks, apiOnly, routes,
|
28
|
+
var _resolvedConfig_source, appContext, resolvedConfig, hooks, apiOnly, _ref, getProdServerRoutes, routes, _routes, _routes1, _ref1, modifiedRoutes, _ref2, getBundleEntry, getServerRoutes, getHtmlTemplate, entrypoints, _, _1, _tmp, routes1, _routes2, _routes3, initialRoutes, _ref3, modifiedRoutes1, _ref4, partialsByEntrypoint, htmlTemplates, checkedEntries, entry, normalizedConfig, createBuilderForModern, builder;
|
28
29
|
return _ts_generator(this, function(_state) {
|
29
30
|
switch (_state.label) {
|
30
31
|
case 0:
|
@@ -49,19 +50,45 @@ function analyze_default(param) {
|
|
49
50
|
];
|
50
51
|
case 2:
|
51
52
|
_state.sent();
|
53
|
+
return [
|
54
|
+
4,
|
55
|
+
Promise.all([
|
56
|
+
import("./getServerRoutes.js")
|
57
|
+
])
|
58
|
+
];
|
59
|
+
case 3:
|
60
|
+
_ref = _sliced_to_array.apply(void 0, [
|
61
|
+
_state.sent(),
|
62
|
+
1
|
63
|
+
]), getProdServerRoutes = _ref[0].getProdServerRoutes;
|
52
64
|
if (!apiOnly)
|
65
|
+
return [
|
66
|
+
3,
|
67
|
+
7
|
68
|
+
];
|
69
|
+
routes = [];
|
70
|
+
if (!checkIsServeCommand())
|
53
71
|
return [
|
54
72
|
3,
|
55
73
|
4
|
56
74
|
];
|
75
|
+
(_routes = routes).push.apply(_routes, _to_consumable_array(getProdServerRoutes(appContext.distDirectory)));
|
76
|
+
return [
|
77
|
+
3,
|
78
|
+
6
|
79
|
+
];
|
80
|
+
case 4:
|
57
81
|
return [
|
58
82
|
4,
|
59
83
|
hooks.modifyServerRoutes.call({
|
60
84
|
routes: []
|
61
85
|
})
|
62
86
|
];
|
63
|
-
case
|
64
|
-
|
87
|
+
case 5:
|
88
|
+
_ref1 = _state.sent(), modifiedRoutes = _ref1.routes;
|
89
|
+
(_routes1 = routes).push.apply(_routes1, _to_consumable_array(modifiedRoutes));
|
90
|
+
_state.label = 6;
|
91
|
+
case 6:
|
65
92
|
debug("server routes: %o", routes);
|
66
93
|
api.updateAppContext({
|
67
94
|
apiOnly,
|
@@ -70,7 +97,7 @@ function analyze_default(param) {
|
|
70
97
|
return [
|
71
98
|
2
|
72
99
|
];
|
73
|
-
case
|
100
|
+
case 7:
|
74
101
|
return [
|
75
102
|
4,
|
76
103
|
Promise.all([
|
@@ -79,27 +106,39 @@ function analyze_default(param) {
|
|
79
106
|
import("./getHtmlTemplate.js")
|
80
107
|
])
|
81
108
|
];
|
82
|
-
case
|
83
|
-
|
109
|
+
case 8:
|
110
|
+
_ref2 = _sliced_to_array.apply(void 0, [
|
84
111
|
_state.sent(),
|
85
112
|
3
|
86
|
-
]), getBundleEntry =
|
113
|
+
]), getBundleEntry = _ref2[0].getBundleEntry, getServerRoutes = _ref2[1].getServerRoutes, getHtmlTemplate = _ref2[2].getHtmlTemplate;
|
87
114
|
_1 = (_ = hooks.modifyEntrypoints).call;
|
88
115
|
_tmp = {};
|
89
116
|
return [
|
90
117
|
4,
|
91
118
|
getBundleEntry(hooks, appContext, resolvedConfig)
|
92
119
|
];
|
93
|
-
case
|
120
|
+
case 9:
|
94
121
|
return [
|
95
122
|
4,
|
96
123
|
_1.apply(_, [
|
97
124
|
(_tmp.entrypoints = _state.sent(), _tmp)
|
98
125
|
])
|
99
126
|
];
|
100
|
-
case
|
127
|
+
case 10:
|
101
128
|
entrypoints = _state.sent().entrypoints;
|
102
129
|
debug("entrypoints: %o", entrypoints);
|
130
|
+
routes1 = [];
|
131
|
+
if (!checkIsServeCommand())
|
132
|
+
return [
|
133
|
+
3,
|
134
|
+
11
|
135
|
+
];
|
136
|
+
(_routes2 = routes1).push.apply(_routes2, _to_consumable_array(getProdServerRoutes(appContext.distDirectory)));
|
137
|
+
return [
|
138
|
+
3,
|
139
|
+
13
|
140
|
+
];
|
141
|
+
case 11:
|
103
142
|
initialRoutes = getServerRoutes(entrypoints, {
|
104
143
|
appContext,
|
105
144
|
config: resolvedConfig
|
@@ -110,8 +149,11 @@ function analyze_default(param) {
|
|
110
149
|
routes: initialRoutes
|
111
150
|
})
|
112
151
|
];
|
113
|
-
case
|
114
|
-
|
152
|
+
case 12:
|
153
|
+
_ref3 = _state.sent(), modifiedRoutes1 = _ref3.routes;
|
154
|
+
(_routes3 = routes1).push.apply(_routes3, _to_consumable_array(modifiedRoutes1));
|
155
|
+
_state.label = 13;
|
156
|
+
case 13:
|
115
157
|
debug("server routes: %o", routes1);
|
116
158
|
appContext = _object_spread_props(_object_spread({}, api.getAppContext()), {
|
117
159
|
entrypoints,
|
@@ -133,8 +175,8 @@ function analyze_default(param) {
|
|
133
175
|
config: resolvedConfig
|
134
176
|
})
|
135
177
|
];
|
136
|
-
case
|
137
|
-
|
178
|
+
case 14:
|
179
|
+
_ref4 = _state.sent(), partialsByEntrypoint = _ref4.partialsByEntrypoint, htmlTemplates = _ref4.htmlTemplates;
|
138
180
|
debug("html templates: %o", htmlTemplates);
|
139
181
|
api.updateAppContext({
|
140
182
|
partialsByEntrypoint
|
@@ -145,17 +187,17 @@ function analyze_default(param) {
|
|
145
187
|
if (!isDevCommand())
|
146
188
|
return [
|
147
189
|
3,
|
148
|
-
|
190
|
+
16
|
149
191
|
];
|
150
192
|
entry = minimist(getArgv()).entry;
|
151
193
|
return [
|
152
194
|
4,
|
153
195
|
getSelectedEntries(typeof entry === "string" ? entry.split(",") : entry, entrypoints)
|
154
196
|
];
|
155
|
-
case
|
197
|
+
case 15:
|
156
198
|
checkedEntries = _state.sent();
|
157
|
-
_state.label =
|
158
|
-
case
|
199
|
+
_state.label = 16;
|
200
|
+
case 16:
|
159
201
|
appContext = _object_spread_props(_object_spread({}, api.getAppContext()), {
|
160
202
|
entrypoints,
|
161
203
|
checkedEntries,
|
@@ -167,7 +209,7 @@ function analyze_default(param) {
|
|
167
209
|
if (!checkIsBuildCommands())
|
168
210
|
return [
|
169
211
|
3,
|
170
|
-
|
212
|
+
20
|
171
213
|
];
|
172
214
|
return [
|
173
215
|
4,
|
@@ -175,14 +217,14 @@ function analyze_default(param) {
|
|
175
217
|
entrypoints
|
176
218
|
})
|
177
219
|
];
|
178
|
-
case
|
220
|
+
case 17:
|
179
221
|
_state.sent();
|
180
222
|
normalizedConfig = api.getNormalizedConfig();
|
181
223
|
return [
|
182
224
|
4,
|
183
225
|
createBuilderGenerator(bundler)
|
184
226
|
];
|
185
|
-
case
|
227
|
+
case 18:
|
186
228
|
createBuilderForModern = _state.sent();
|
187
229
|
return [
|
188
230
|
4,
|
@@ -191,10 +233,10 @@ function analyze_default(param) {
|
|
191
233
|
appContext
|
192
234
|
})
|
193
235
|
];
|
194
|
-
case
|
236
|
+
case 19:
|
195
237
|
builder = _state.sent();
|
196
238
|
builder.onBeforeBuild(function() {
|
197
|
-
var
|
239
|
+
var _ref5 = _async_to_generator(function(param2) {
|
198
240
|
var bundlerConfigs, isFirstCompile, environments, isWatch;
|
199
241
|
return _ts_generator(this, function(_state2) {
|
200
242
|
switch (_state2.label) {
|
@@ -229,11 +271,11 @@ function analyze_default(param) {
|
|
229
271
|
});
|
230
272
|
});
|
231
273
|
return function(_2) {
|
232
|
-
return
|
274
|
+
return _ref5.apply(this, arguments);
|
233
275
|
};
|
234
276
|
}());
|
235
277
|
builder.onAfterBuild(function() {
|
236
|
-
var
|
278
|
+
var _ref5 = _async_to_generator(function(param2) {
|
237
279
|
var stats, environments, isFirstCompile, isWatch;
|
238
280
|
return _ts_generator(this, function(_state2) {
|
239
281
|
switch (_state2.label) {
|
@@ -263,11 +305,11 @@ function analyze_default(param) {
|
|
263
305
|
});
|
264
306
|
});
|
265
307
|
return function(_2) {
|
266
|
-
return
|
308
|
+
return _ref5.apply(this, arguments);
|
267
309
|
};
|
268
310
|
}());
|
269
311
|
builder.onDevCompileDone(function() {
|
270
|
-
var
|
312
|
+
var _ref5 = _async_to_generator(function(param2) {
|
271
313
|
var isFirstCompile;
|
272
314
|
return _ts_generator(this, function(_state2) {
|
273
315
|
isFirstCompile = param2.isFirstCompile;
|
@@ -283,11 +325,11 @@ function analyze_default(param) {
|
|
283
325
|
});
|
284
326
|
});
|
285
327
|
return function(_2) {
|
286
|
-
return
|
328
|
+
return _ref5.apply(this, arguments);
|
287
329
|
};
|
288
330
|
}());
|
289
331
|
builder.onBeforeCreateCompiler(function() {
|
290
|
-
var
|
332
|
+
var _ref5 = _async_to_generator(function(param2) {
|
291
333
|
var bundlerConfigs, environments;
|
292
334
|
return _ts_generator(this, function(_state2) {
|
293
335
|
switch (_state2.label) {
|
@@ -309,11 +351,11 @@ function analyze_default(param) {
|
|
309
351
|
});
|
310
352
|
});
|
311
353
|
return function(_2) {
|
312
|
-
return
|
354
|
+
return _ref5.apply(this, arguments);
|
313
355
|
};
|
314
356
|
}());
|
315
357
|
builder.onAfterCreateCompiler(function() {
|
316
|
-
var
|
358
|
+
var _ref5 = _async_to_generator(function(param2) {
|
317
359
|
var compiler, environments;
|
318
360
|
return _ts_generator(this, function(_state2) {
|
319
361
|
switch (_state2.label) {
|
@@ -335,15 +377,15 @@ function analyze_default(param) {
|
|
335
377
|
});
|
336
378
|
});
|
337
379
|
return function(_2) {
|
338
|
-
return
|
380
|
+
return _ref5.apply(this, arguments);
|
339
381
|
};
|
340
382
|
}());
|
341
383
|
builder.addPlugins(resolvedConfig.builderPlugins);
|
342
384
|
api.updateAppContext({
|
343
385
|
builder
|
344
386
|
});
|
345
|
-
_state.label =
|
346
|
-
case
|
387
|
+
_state.label = 20;
|
388
|
+
case 20:
|
347
389
|
return [
|
348
390
|
2
|
349
391
|
];
|
@@ -83,6 +83,10 @@ var checkIsBuildCommands = function() {
|
|
83
83
|
var command = getCommand();
|
84
84
|
return buildCommands.includes(command);
|
85
85
|
};
|
86
|
+
var checkIsServeCommand = function() {
|
87
|
+
var command = getCommand();
|
88
|
+
return command === "serve";
|
89
|
+
};
|
86
90
|
var isSubDirOrEqual = function(parent, child) {
|
87
91
|
if (parent === child) {
|
88
92
|
return true;
|
@@ -93,6 +97,7 @@ var isSubDirOrEqual = function(parent, child) {
|
|
93
97
|
};
|
94
98
|
export {
|
95
99
|
checkIsBuildCommands,
|
100
|
+
checkIsServeCommand,
|
96
101
|
getServerCombinedModueFile,
|
97
102
|
isSubDirOrEqual,
|
98
103
|
parseModule,
|
@@ -4,7 +4,12 @@ function createDefaultConfig(appContext) {
|
|
4
4
|
const dev = {
|
5
5
|
// `dev.port` should not have a default value
|
6
6
|
// because we will use `server.port` by default
|
7
|
-
port: void 0
|
7
|
+
port: void 0,
|
8
|
+
cliShortcuts: {
|
9
|
+
help: false,
|
10
|
+
// does not support restart server and print urls yet
|
11
|
+
custom: (shortcuts = []) => shortcuts.filter(({ key }) => key !== "r" && key !== "u")
|
12
|
+
}
|
8
13
|
};
|
9
14
|
const output = {
|
10
15
|
distPath: {
|
@@ -1,6 +1,5 @@
|
|
1
|
-
import fs from "fs";
|
2
1
|
import path from "path";
|
3
|
-
import { SERVER_BUNDLE_DIRECTORY, SERVER_WORKER_BUNDLE_DIRECTORY, getEntryOptions, isPlainObject, removeLeadingSlash, removeTailSlash, urlJoin } from "@modern-js/utils";
|
2
|
+
import { fs, ROUTE_SPEC_FILE, SERVER_BUNDLE_DIRECTORY, SERVER_WORKER_BUNDLE_DIRECTORY, getEntryOptions, isPlainObject, removeLeadingSlash, removeTailSlash, urlJoin } from "@modern-js/utils";
|
4
3
|
import { isMainEntry } from "../../utils/routes";
|
5
4
|
import { walkDirectory } from "./utils";
|
6
5
|
const applyBaseUrl = (baseUrl, routes) => {
|
@@ -130,6 +129,16 @@ const getServerRoutes = (entrypoints, { appContext, config }) => [
|
|
130
129
|
...collectStaticRoutes(appContext, config)
|
131
130
|
];
|
132
131
|
const toPosix = (pathStr) => pathStr.split(path.sep).join(path.posix.sep);
|
132
|
+
const getProdServerRoutes = (distDirectory) => {
|
133
|
+
const routeJSON = path.join(distDirectory, ROUTE_SPEC_FILE);
|
134
|
+
try {
|
135
|
+
const { routes } = fs.readJSONSync(routeJSON);
|
136
|
+
return routes;
|
137
|
+
} catch (e) {
|
138
|
+
throw new Error(`Failed to read routes from ${routeJSON}, please check if the file exists.`);
|
139
|
+
}
|
140
|
+
};
|
133
141
|
export {
|
142
|
+
getProdServerRoutes,
|
134
143
|
getServerRoutes
|
135
144
|
};
|
@@ -6,7 +6,7 @@ import { emitResolvedConfig } from "../../utils/config";
|
|
6
6
|
import { getSelectedEntries } from "../../utils/getSelectedEntries";
|
7
7
|
import { printInstructions } from "../../utils/printInstructions";
|
8
8
|
import { generateRoutes } from "../../utils/routes";
|
9
|
-
import { checkIsBuildCommands } from "./utils";
|
9
|
+
import { checkIsBuildCommands, checkIsServeCommand } from "./utils";
|
10
10
|
const debug = createDebugger("plugin-analyze");
|
11
11
|
var analyze_default = ({ bundler }) => ({
|
12
12
|
name: "@modern-js/plugin-analyze",
|
@@ -29,10 +29,19 @@ var analyze_default = ({ bundler }) => ({
|
|
29
29
|
}
|
30
30
|
const apiOnly = await isApiOnly(appContext.appDirectory, (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.entriesDir, appContext.apiDirectory);
|
31
31
|
await hooks.addRuntimeExports.call();
|
32
|
+
const [{ getProdServerRoutes }] = await Promise.all([
|
33
|
+
import("./getServerRoutes.js")
|
34
|
+
]);
|
32
35
|
if (apiOnly) {
|
33
|
-
const
|
34
|
-
|
35
|
-
|
36
|
+
const routes2 = [];
|
37
|
+
if (checkIsServeCommand()) {
|
38
|
+
routes2.push(...getProdServerRoutes(appContext.distDirectory));
|
39
|
+
} else {
|
40
|
+
const { routes: modifiedRoutes } = await hooks.modifyServerRoutes.call({
|
41
|
+
routes: []
|
42
|
+
});
|
43
|
+
routes2.push(...modifiedRoutes);
|
44
|
+
}
|
36
45
|
debug(`server routes: %o`, routes2);
|
37
46
|
api.updateAppContext({
|
38
47
|
apiOnly,
|
@@ -49,13 +58,19 @@ var analyze_default = ({ bundler }) => ({
|
|
49
58
|
entrypoints: await getBundleEntry(hooks, appContext, resolvedConfig)
|
50
59
|
});
|
51
60
|
debug(`entrypoints: %o`, entrypoints);
|
52
|
-
const
|
53
|
-
|
54
|
-
|
55
|
-
}
|
56
|
-
|
57
|
-
|
58
|
-
|
61
|
+
const routes = [];
|
62
|
+
if (checkIsServeCommand()) {
|
63
|
+
routes.push(...getProdServerRoutes(appContext.distDirectory));
|
64
|
+
} else {
|
65
|
+
const initialRoutes = getServerRoutes(entrypoints, {
|
66
|
+
appContext,
|
67
|
+
config: resolvedConfig
|
68
|
+
});
|
69
|
+
const { routes: modifiedRoutes } = await hooks.modifyServerRoutes.call({
|
70
|
+
routes: initialRoutes
|
71
|
+
});
|
72
|
+
routes.push(...modifiedRoutes);
|
73
|
+
}
|
59
74
|
debug(`server routes: %o`, routes);
|
60
75
|
appContext = {
|
61
76
|
...api.getAppContext(),
|
@@ -50,6 +50,10 @@ const checkIsBuildCommands = () => {
|
|
50
50
|
const command = getCommand();
|
51
51
|
return buildCommands.includes(command);
|
52
52
|
};
|
53
|
+
const checkIsServeCommand = () => {
|
54
|
+
const command = getCommand();
|
55
|
+
return command === "serve";
|
56
|
+
};
|
53
57
|
const isSubDirOrEqual = (parent, child) => {
|
54
58
|
if (parent === child) {
|
55
59
|
return true;
|
@@ -60,6 +64,7 @@ const isSubDirOrEqual = (parent, child) => {
|
|
60
64
|
};
|
61
65
|
export {
|
62
66
|
checkIsBuildCommands,
|
67
|
+
checkIsServeCommand,
|
63
68
|
getServerCombinedModueFile,
|
64
69
|
isSubDirOrEqual,
|
65
70
|
parseModule,
|
@@ -6,4 +6,5 @@ export declare const parseModule: ({ source, filename, }: {
|
|
6
6
|
}) => Promise<readonly [imports: readonly import("es-module-lexer").ImportSpecifier[], exports: readonly import("es-module-lexer").ExportSpecifier[], facade: boolean]>;
|
7
7
|
export declare const getServerCombinedModueFile: (internalDirectory: string, entryName: string) => string;
|
8
8
|
export declare const checkIsBuildCommands: () => boolean;
|
9
|
+
export declare const checkIsServeCommand: () => boolean;
|
9
10
|
export declare const isSubDirOrEqual: (parent: string, child: string) => boolean;
|
@@ -40,7 +40,6 @@ export interface AppToolsUserConfig<B extends Bundler> {
|
|
40
40
|
testing?: TestingUserConfig;
|
41
41
|
builderPlugins?: Array<LooseRsbuildPlugin | UniBuilderPlugin>;
|
42
42
|
performance?: PerformanceUserConfig;
|
43
|
-
devtools?: any;
|
44
43
|
environments?: RsbuildConfig['environments'];
|
45
44
|
}
|
46
45
|
interface SharedNormalizedConfig<RawConfig> {
|
package/package.json
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
"modern",
|
16
16
|
"modern.js"
|
17
17
|
],
|
18
|
-
"version": "2.63.
|
18
|
+
"version": "2.63.2",
|
19
19
|
"jsnext:source": "./src/index.ts",
|
20
20
|
"types": "./dist/types/index.d.ts",
|
21
21
|
"main": "./dist/cjs/index.js",
|
@@ -85,7 +85,7 @@
|
|
85
85
|
"@babel/parser": "^7.22.15",
|
86
86
|
"@babel/traverse": "^7.23.2",
|
87
87
|
"@babel/types": "^7.26.0",
|
88
|
-
"@rsbuild/core": "1.1.
|
88
|
+
"@rsbuild/core": "1.1.9",
|
89
89
|
"@rsbuild/plugin-node-polyfill": "1.2.0",
|
90
90
|
"@swc/helpers": "0.5.13",
|
91
91
|
"@vercel/nft": "^0.26.4",
|
@@ -96,20 +96,20 @@
|
|
96
96
|
"mlly": "^1.6.1",
|
97
97
|
"pkg-types": "^1.1.0",
|
98
98
|
"std-env": "^3.7.0",
|
99
|
-
"@modern-js/core": "2.63.
|
100
|
-
"@modern-js/
|
101
|
-
"@modern-js/
|
102
|
-
"@modern-js/plugin-
|
103
|
-
"@modern-js/
|
104
|
-
"@modern-js/
|
105
|
-
"@modern-js/rsbuild-plugin-esbuild": "2.63.
|
106
|
-
"@modern-js/
|
107
|
-
"@modern-js/server-core": "2.63.
|
108
|
-
"@modern-js/server
|
109
|
-
"@modern-js/
|
110
|
-
"@modern-js/
|
111
|
-
"@modern-js/
|
112
|
-
"@modern-js/
|
99
|
+
"@modern-js/core": "2.63.2",
|
100
|
+
"@modern-js/plugin": "2.63.2",
|
101
|
+
"@modern-js/node-bundle-require": "2.63.2",
|
102
|
+
"@modern-js/plugin-data-loader": "2.63.2",
|
103
|
+
"@modern-js/prod-server": "2.63.2",
|
104
|
+
"@modern-js/plugin-i18n": "2.63.2",
|
105
|
+
"@modern-js/rsbuild-plugin-esbuild": "2.63.2",
|
106
|
+
"@modern-js/plugin-v2": "2.63.2",
|
107
|
+
"@modern-js/server-core": "2.63.2",
|
108
|
+
"@modern-js/server": "2.63.2",
|
109
|
+
"@modern-js/server-utils": "2.63.2",
|
110
|
+
"@modern-js/types": "2.63.2",
|
111
|
+
"@modern-js/uni-builder": "2.63.2",
|
112
|
+
"@modern-js/utils": "2.63.2"
|
113
113
|
},
|
114
114
|
"devDependencies": {
|
115
115
|
"@rsbuild/plugin-webpack-swc": "1.0.9",
|
@@ -120,9 +120,9 @@
|
|
120
120
|
"ts-node": "^10.9.1",
|
121
121
|
"tsconfig-paths": "^4.2.0",
|
122
122
|
"typescript": "^5",
|
123
|
-
"webpack": "^5.
|
124
|
-
"@scripts/build": "2.63.
|
125
|
-
"@scripts/jest-config": "2.63.
|
123
|
+
"webpack": "^5.97.1",
|
124
|
+
"@scripts/build": "2.63.2",
|
125
|
+
"@scripts/jest-config": "2.63.2"
|
126
126
|
},
|
127
127
|
"peerDependencies": {
|
128
128
|
"ts-node": "^10.7.0",
|
@@ -139,7 +139,8 @@
|
|
139
139
|
"sideEffects": false,
|
140
140
|
"publishConfig": {
|
141
141
|
"registry": "https://registry.npmjs.org/",
|
142
|
-
"access": "public"
|
142
|
+
"access": "public",
|
143
|
+
"provenance": true
|
143
144
|
},
|
144
145
|
"scripts": {
|
145
146
|
"new": "modern-lib new",
|