@modern-js/app-tools 2.27.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/analyze/utils.js +2 -1
- 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 +11 -9
- package/dist/cjs/commands/build.js +2 -1
- package/dist/cjs/commands/dev.js +3 -2
- package/dist/cjs/commands/inspect.js +2 -1
- package/dist/cjs/commands/serve.js +2 -2
- package/dist/cjs/index.js +7 -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/analyze/utils.js +2 -1
- 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 +12 -10
- package/dist/esm/commands/build.js +2 -2
- package/dist/esm/commands/dev.js +5 -3
- package/dist/esm/commands/inspect.js +2 -2
- package/dist/esm/commands/serve.js +2 -2
- package/dist/esm/index.js +7 -5
- 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/analyze/utils.js +2 -1
- 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 +11 -9
- package/dist/esm-node/commands/build.js +2 -1
- package/dist/esm-node/commands/dev.js +3 -2
- package/dist/esm-node/commands/inspect.js +2 -1
- package/dist/esm-node/commands/serve.js +2 -2
- package/dist/esm-node/index.js +6 -4
- package/dist/esm-node/initialize/index.js +70 -72
- package/dist/types/analyze/getClientRoutes/getRoutes.d.ts +2 -2
- package/dist/types/analyze/nestedRoutes.d.ts +2 -2
- package/dist/types/analyze/templates.d.ts +3 -3
- package/dist/types/commands/dev.d.ts +4 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/types/hooks.d.ts +2 -2
- package/package.json +24 -24
|
@@ -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,14 +119,14 @@ 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
131
|
if (existNestedRoutes || routerManifest || workerSSR) {
|
|
131
132
|
chain.plugin("route-plugin").use(RouterPlugin);
|
|
@@ -133,21 +134,21 @@ function applyRouterPlugin(chain, options) {
|
|
|
133
134
|
}
|
|
134
135
|
function applyFilterEntriesBySSRConfig(param) {
|
|
135
136
|
var isProd = param.isProd, chain = param.chain, appNormalizedConfig = param.appNormalizedConfig;
|
|
136
|
-
var
|
|
137
|
+
var _outputConfig, _this, _outputConfig1, _outputConfig2, _outputConfig3;
|
|
137
138
|
var serverConfig = appNormalizedConfig.server, outputConfig = appNormalizedConfig.output;
|
|
138
139
|
var entries = chain.entryPoints.entries();
|
|
139
|
-
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")) {
|
|
140
141
|
return;
|
|
141
142
|
}
|
|
142
143
|
if (typeof entries === "undefined") {
|
|
143
144
|
throw new Error("No entry found, one of src/routes/layout.tsx, src/App.tsx, src/index.tsx is required");
|
|
144
145
|
}
|
|
145
146
|
var entryNames = Object.keys(entries);
|
|
146
|
-
if (isProd && entryNames.length === 1 && (outputConfig === null ||
|
|
147
|
+
if (isProd && entryNames.length === 1 && ((_outputConfig2 = outputConfig) === null || _outputConfig2 === void 0 ? void 0 : _outputConfig2.ssg)) {
|
|
147
148
|
return;
|
|
148
149
|
}
|
|
149
150
|
var ssgEntries = [];
|
|
150
|
-
if (isProd && (outputConfig === null ||
|
|
151
|
+
if (isProd && ((_outputConfig3 = outputConfig) === null || _outputConfig3 === void 0 ? void 0 : _outputConfig3.ssg)) {
|
|
151
152
|
var ssg = outputConfig.ssg;
|
|
152
153
|
entryNames.forEach(function(name) {
|
|
153
154
|
if (ssg[name]) {
|
|
@@ -155,9 +156,10 @@ function applyFilterEntriesBySSRConfig(param) {
|
|
|
155
156
|
}
|
|
156
157
|
});
|
|
157
158
|
}
|
|
158
|
-
var
|
|
159
|
+
var _ref = serverConfig || {}, ssr = _ref.ssr, ssrByEntries = _ref.ssrByEntries;
|
|
159
160
|
entryNames.forEach(function(name) {
|
|
160
|
-
|
|
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]))) {
|
|
161
163
|
chain.entryPoints.delete(name);
|
|
162
164
|
}
|
|
163
165
|
});
|
|
@@ -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();
|
package/dist/esm/commands/dev.js
CHANGED
|
@@ -11,10 +11,12 @@ import { buildServerConfig } from "../utils/config";
|
|
|
11
11
|
import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
|
|
12
12
|
export var dev = function() {
|
|
13
13
|
var _ref = _async_to_generator(function(api, options) {
|
|
14
|
-
var _normalizedConfig_tools, normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverInternalPlugins, serverOptions, _normalizedConfig_dev, app, host, server;
|
|
14
|
+
var devServerOptions, _normalizedConfig_tools, normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverInternalPlugins, serverOptions, _normalizedConfig_dev, app, host, server;
|
|
15
|
+
var _arguments = arguments;
|
|
15
16
|
return _ts_generator(this, function(_state) {
|
|
16
17
|
switch (_state.label) {
|
|
17
18
|
case 0:
|
|
19
|
+
devServerOptions = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
|
|
18
20
|
if (options.analyze) {
|
|
19
21
|
process.env.BUNDLE_ANALYZE = "true";
|
|
20
22
|
}
|
|
@@ -58,7 +60,7 @@ export var dev = function() {
|
|
|
58
60
|
];
|
|
59
61
|
case 4:
|
|
60
62
|
serverInternalPlugins = _state.sent();
|
|
61
|
-
serverOptions = {
|
|
63
|
+
serverOptions = _object_spread({
|
|
62
64
|
dev: _object_spread({
|
|
63
65
|
port: port,
|
|
64
66
|
https: normalizedConfig.dev.https,
|
|
@@ -75,7 +77,7 @@ export var dev = function() {
|
|
|
75
77
|
config: normalizedConfig,
|
|
76
78
|
serverConfigFile: serverConfigFile,
|
|
77
79
|
internalPlugins: injectDataLoaderPlugin(serverInternalPlugins)
|
|
78
|
-
};
|
|
80
|
+
}, devServerOptions);
|
|
79
81
|
if (!apiOnly)
|
|
80
82
|
return [
|
|
81
83
|
3,
|
|
@@ -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
|
@@ -14,6 +14,7 @@ import { i18n, localeKeys } from "./locale";
|
|
|
14
14
|
import { restart } from "./utils/restart";
|
|
15
15
|
import { generateWatchFiles } from "./utils/generateWatchFiles";
|
|
16
16
|
export { mergeConfig } from "@modern-js/core";
|
|
17
|
+
export { dev } from "./commands";
|
|
17
18
|
export * from "./defineConfig";
|
|
18
19
|
export * from "./types";
|
|
19
20
|
export var devCommand = function() {
|
|
@@ -31,7 +32,7 @@ export var devCommand = function() {
|
|
|
31
32
|
devToolMetas = _state.sent();
|
|
32
33
|
devProgram = program.command("dev").alias("start").usage("[options]").description(i18n.t(localeKeys.command.dev.describe)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("-e --entry [entry...]", i18n.t(localeKeys.command.dev.entry)).option("--analyze", i18n.t(localeKeys.command.shared.analyze)).option("--api-only", i18n.t(localeKeys.command.dev.apiOnly)).option("--web-only", i18n.t(localeKeys.command.dev.webOnly)).action(function() {
|
|
33
34
|
var _ref2 = _async_to_generator(function(options) {
|
|
34
|
-
var
|
|
35
|
+
var dev2;
|
|
35
36
|
return _ts_generator(this, function(_state2) {
|
|
36
37
|
switch (_state2.label) {
|
|
37
38
|
case 0:
|
|
@@ -40,10 +41,10 @@ export var devCommand = function() {
|
|
|
40
41
|
import("./commands/dev")
|
|
41
42
|
];
|
|
42
43
|
case 1:
|
|
43
|
-
|
|
44
|
+
dev2 = _state2.sent().dev;
|
|
44
45
|
return [
|
|
45
46
|
4,
|
|
46
|
-
|
|
47
|
+
dev2(api, options)
|
|
47
48
|
];
|
|
48
49
|
case 2:
|
|
49
50
|
_state2.sent();
|
|
@@ -272,6 +273,7 @@ export var appTools = function() {
|
|
|
272
273
|
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
|
|
273
274
|
bundler: "webpack"
|
|
274
275
|
};
|
|
276
|
+
var _options, _options1;
|
|
275
277
|
return {
|
|
276
278
|
name: "@modern-js/app-tools",
|
|
277
279
|
post: [
|
|
@@ -287,10 +289,10 @@ export var appTools = function() {
|
|
|
287
289
|
registerHook: hooks,
|
|
288
290
|
usePlugins: [
|
|
289
291
|
initializePlugin({
|
|
290
|
-
bundler: (options === null ||
|
|
292
|
+
bundler: ((_options = options) === null || _options === void 0 ? void 0 : _options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
|
|
291
293
|
}),
|
|
292
294
|
analyzePlugin({
|
|
293
|
-
bundler: (options === null ||
|
|
295
|
+
bundler: ((_options1 = options) === null || _options1 === void 0 ? void 0 : _options1.bundler) === "experimental-rspack" ? "rspack" : "webpack"
|
|
294
296
|
}),
|
|
295
297
|
lintPlugin()
|
|
296
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
|
};
|