@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
@@ -16,35 +16,20 @@ export const builderPluginAdapterHtml = (options) => ({
|
|
16
16
|
HtmlBundlerPlugin
|
17
17
|
});
|
18
18
|
await injectAssetPrefix({
|
19
|
-
api,
|
20
19
|
chain
|
21
20
|
});
|
22
21
|
}
|
23
22
|
});
|
24
23
|
}
|
25
24
|
});
|
26
|
-
async function injectAssetPrefix({
|
25
|
+
async function injectAssetPrefix({ chain }) {
|
27
26
|
const entries = chain.entryPoints.entries() || {};
|
28
27
|
const entryNames = Object.keys(entries);
|
29
28
|
const assetPrefix = removeTailSlash(chain.output.get("publicPath") || "");
|
30
29
|
const code = `window.__assetPrefix__ = '${assetPrefix}';`;
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
const { default: RspackVirtualModulePlugin } = await import("rspack-plugin-virtual-module");
|
35
|
-
entryNames.forEach((entryName) => {
|
36
|
-
entries[entryName].prepend(fileName);
|
37
|
-
chain.plugin("rspack-asset-prefix").use(RspackVirtualModulePlugin, [
|
38
|
-
{
|
39
|
-
[fileName]: code
|
40
|
-
}
|
41
|
-
]);
|
42
|
-
});
|
43
|
-
} else {
|
44
|
-
entryNames.forEach((entryName) => {
|
45
|
-
entries[entryName].prepend(createVirtualModule(code));
|
46
|
-
});
|
47
|
-
}
|
30
|
+
entryNames.forEach((entryName) => {
|
31
|
+
entries[entryName].prepend(createVirtualModule(code));
|
32
|
+
});
|
48
33
|
}
|
49
34
|
function applyBottomHtmlPlugin({ api, chain, options, CHAIN_ID, HtmlBundlerPlugin }) {
|
50
35
|
const { normalizedConfig: modernConfig, appContext } = options;
|
@@ -20,7 +20,7 @@ export const builderPluginAdapterSSR = (options) => ({
|
|
20
20
|
api.modifyBundlerChain(async (chain, { target, CHAIN_ID, isProd, HtmlPlugin: HtmlBundlerPlugin, isServer }) => {
|
21
21
|
const builderConfig = api.getNormalizedConfig();
|
22
22
|
const { normalizedConfig: normalizedConfig2 } = options;
|
23
|
-
applyRouterPlugin(chain, options, HtmlBundlerPlugin);
|
23
|
+
applyRouterPlugin(chain, CHAIN_ID.PLUGIN.ROUTER_MANIFEST, options, HtmlBundlerPlugin);
|
24
24
|
if (isSSR(normalizedConfig2)) {
|
25
25
|
await applySSRLoaderEntry(chain, options, isServer);
|
26
26
|
applySSRDataLoader(chain, options);
|
@@ -47,13 +47,12 @@ export const builderPluginAdapterSSR = (options) => ({
|
|
47
47
|
}
|
48
48
|
});
|
49
49
|
const isStreamingSSR = (userConfig) => {
|
50
|
-
var _server;
|
51
50
|
const isStreaming = (ssr) => ssr && typeof ssr === "object" && ssr.mode === "stream";
|
52
51
|
const { server } = userConfig;
|
53
52
|
if (isStreaming(server.ssr)) {
|
54
53
|
return true;
|
55
54
|
}
|
56
|
-
if ((
|
55
|
+
if ((server === null || server === void 0 ? void 0 : server.ssrByEntries) && typeof server.ssrByEntries === "object") {
|
57
56
|
for (const name of Object.keys(server.ssrByEntries)) {
|
58
57
|
if (isStreaming(server.ssrByEntries[name])) {
|
59
58
|
return true;
|
@@ -69,17 +68,17 @@ function applyAsyncChunkHtmlPlugin({ chain, modernConfig, CHAIN_ID, HtmlBundlerP
|
|
69
68
|
]);
|
70
69
|
}
|
71
70
|
}
|
72
|
-
function applyRouterPlugin(chain, options, HtmlBundlerPlugin) {
|
73
|
-
var _normalizedConfig_runtime,
|
71
|
+
function applyRouterPlugin(chain, pluginName, options, HtmlBundlerPlugin) {
|
72
|
+
var _normalizedConfig_runtime, _normalizedConfig_deploy_worker;
|
74
73
|
const { appContext, normalizedConfig } = options;
|
75
74
|
const { entrypoints } = appContext;
|
76
75
|
const existNestedRoutes = entrypoints.some((entrypoint) => entrypoint.nestedRoutesEntry);
|
77
|
-
const routerConfig =
|
78
|
-
const routerManifest = Boolean(
|
76
|
+
const routerConfig = normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_runtime = normalizedConfig.runtime) === null || _normalizedConfig_runtime === void 0 ? void 0 : _normalizedConfig_runtime.router;
|
77
|
+
const routerManifest = Boolean(routerConfig === null || routerConfig === void 0 ? void 0 : routerConfig.manifest);
|
79
78
|
const workerSSR = Boolean((_normalizedConfig_deploy_worker = normalizedConfig.deploy.worker) === null || _normalizedConfig_deploy_worker === void 0 ? void 0 : _normalizedConfig_deploy_worker.ssr);
|
80
79
|
if (existNestedRoutes || routerManifest || workerSSR) {
|
81
80
|
var _normalizedConfig_output_distPath, _normalizedConfig_output, _normalizedConfig_output1, _normalizedConfig_html, _normalizedConfig_security;
|
82
|
-
chain.plugin(
|
81
|
+
chain.plugin(pluginName).use(RouterPlugin, [
|
83
82
|
{
|
84
83
|
HtmlBundlerPlugin,
|
85
84
|
enableInlineRouteManifests: normalizedConfig.output.enableInlineRouteManifests,
|
@@ -92,21 +91,21 @@ function applyRouterPlugin(chain, options, HtmlBundlerPlugin) {
|
|
92
91
|
}
|
93
92
|
}
|
94
93
|
function applyFilterEntriesBySSRConfig({ isProd, chain, appNormalizedConfig }) {
|
95
|
-
var
|
94
|
+
var _this;
|
96
95
|
const { server: serverConfig, output: outputConfig } = appNormalizedConfig;
|
97
96
|
const entries = chain.entryPoints.entries();
|
98
|
-
if (isProd && ((
|
97
|
+
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")) {
|
99
98
|
return;
|
100
99
|
}
|
101
100
|
if (typeof entries === "undefined") {
|
102
101
|
throw new Error("No entry found, one of src/routes/layout.tsx, src/App.tsx, src/index.tsx is required");
|
103
102
|
}
|
104
103
|
const entryNames = Object.keys(entries);
|
105
|
-
if (isProd && entryNames.length === 1 && (
|
104
|
+
if (isProd && entryNames.length === 1 && (outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg)) {
|
106
105
|
return;
|
107
106
|
}
|
108
107
|
const ssgEntries = [];
|
109
|
-
if (isProd && (
|
108
|
+
if (isProd && (outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg)) {
|
110
109
|
const { ssg } = outputConfig;
|
111
110
|
entryNames.forEach((name) => {
|
112
111
|
if (ssg[name]) {
|
@@ -116,8 +115,7 @@ function applyFilterEntriesBySSRConfig({ isProd, chain, appNormalizedConfig }) {
|
|
116
115
|
}
|
117
116
|
const { ssr, ssrByEntries } = serverConfig || {};
|
118
117
|
entryNames.forEach((name) => {
|
119
|
-
|
120
|
-
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]))) {
|
118
|
+
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]))) {
|
121
119
|
chain.entryPoints.delete(name);
|
122
120
|
}
|
123
121
|
});
|
@@ -119,10 +119,9 @@ export class RouterPlugin {
|
|
119
119
|
let relatedAssets = {};
|
120
120
|
if (entryChunkFiles.length > 1) {
|
121
121
|
Object.keys(routeAssets).forEach((routeId) => {
|
122
|
-
var _chunkNames;
|
123
122
|
const segments = routeId.split("_");
|
124
123
|
const chunkName = segments[0];
|
125
|
-
if (
|
124
|
+
if (chunkNames === null || chunkNames === void 0 ? void 0 : chunkNames.includes(chunkName)) {
|
126
125
|
relatedAssets[routeId] = routeAssets[routeId];
|
127
126
|
}
|
128
127
|
});
|
@@ -194,6 +193,7 @@ export class RouterPlugin {
|
|
194
193
|
});
|
195
194
|
}
|
196
195
|
constructor({ staticJsDir = "static/js", HtmlBundlerPlugin, enableInlineRouteManifests, disableFilenameHash = false, scriptLoading = "defer", nonce }) {
|
196
|
+
_define_property(this, "name", "RouterPlugin");
|
197
197
|
_define_property(this, "HtmlBundlerPlugin", void 0);
|
198
198
|
_define_property(this, "enableInlineRouteManifests", void 0);
|
199
199
|
_define_property(this, "staticJsDir", void 0);
|
@@ -3,8 +3,7 @@ import { logger } from "@modern-js/utils";
|
|
3
3
|
import { generateRoutes } from "../utils/routes";
|
4
4
|
import { buildServerConfig } from "../utils/config";
|
5
5
|
export const build = async (api, options) => {
|
6
|
-
|
7
|
-
if ((_options = options) === null || _options === void 0 ? void 0 : _options.analyze) {
|
6
|
+
if (options === null || options === void 0 ? void 0 : options.analyze) {
|
8
7
|
process.env.BUNDLE_ANALYZE = "true";
|
9
8
|
}
|
10
9
|
let resolvedConfig = api.useResolvedConfigContext();
|
@@ -40,7 +39,7 @@ export const build = async (api, options) => {
|
|
40
39
|
distDirectory,
|
41
40
|
configFile: serverConfigFile
|
42
41
|
});
|
43
|
-
logger.info("
|
42
|
+
logger.info("Starting production build...");
|
44
43
|
if (!appContext.builder) {
|
45
44
|
throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
|
46
45
|
}
|
@@ -1,6 +1,5 @@
|
|
1
1
|
import { join } from "path";
|
2
2
|
export const inspect = async (api, options) => {
|
3
|
-
var _appContext;
|
4
3
|
const appContext = api.useAppContext();
|
5
4
|
if (!appContext.builder) {
|
6
5
|
throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
|
@@ -8,7 +7,7 @@ export const inspect = async (api, options) => {
|
|
8
7
|
return appContext.builder.inspectConfig({
|
9
8
|
env: options.env,
|
10
9
|
verbose: options.verbose,
|
11
|
-
outputPath: join(
|
10
|
+
outputPath: join(appContext === null || appContext === void 0 ? void 0 : appContext.builder.context.distPath, options.output),
|
12
11
|
writeToDisk: true
|
13
12
|
});
|
14
13
|
};
|
@@ -1,16 +1,16 @@
|
|
1
|
-
import { logger,
|
1
|
+
import { logger, isApiOnly, getTargetDir } from "@modern-js/utils";
|
2
2
|
import server from "@modern-js/prod-server";
|
3
3
|
import { printInstructions } from "../utils/printInstructions";
|
4
4
|
import { injectDataLoaderPlugin } from "../utils/createServer";
|
5
5
|
import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
|
6
6
|
export const start = async (api) => {
|
7
|
-
var _userConfig_source,
|
7
|
+
var _userConfig_source, _userConfig_output_distPath;
|
8
8
|
const appContext = api.useAppContext();
|
9
9
|
const userConfig = api.useResolvedConfigContext();
|
10
10
|
const hookRunners = api.useHookRunners();
|
11
11
|
const { appDirectory, port, serverConfigFile, metaName } = appContext;
|
12
|
-
logger.
|
13
|
-
const apiOnly = await isApiOnly(appContext.appDirectory,
|
12
|
+
logger.info(`Starting production server...`);
|
13
|
+
const apiOnly = await 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);
|
14
14
|
const serverInternalPlugins = await getServerInternalPlugins(api);
|
15
15
|
const app = await server({
|
16
16
|
pwd: appDirectory,
|
package/dist/esm-node/index.js
CHANGED
@@ -59,140 +59,137 @@ export const buildCommand = async (program, api) => {
|
|
59
59
|
};
|
60
60
|
export const appTools = (options = {
|
61
61
|
bundler: "webpack"
|
62
|
-
}) => {
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
...appContext2,
|
105
|
-
internalDirectory: path.resolve(appContext2.appDirectory, userConfig.output.tempDir)
|
106
|
-
});
|
107
|
-
}
|
108
|
-
},
|
109
|
-
async commands({ program }) {
|
110
|
-
await devCommand(program, api);
|
111
|
-
await buildCommand(program, api);
|
112
|
-
program.command("serve").usage("[options]").description(i18n.t(localeKeys.command.serve.describe)).option("--api-only", i18n.t(localeKeys.command.dev.apiOnly)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).action(async () => {
|
113
|
-
const { start } = await import("./commands/serve");
|
114
|
-
await start(api);
|
115
|
-
});
|
116
|
-
program.command("deploy").usage("[options]").option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("-s --skip-build", i18n.t(localeKeys.command.shared.skipBuild)).description(i18n.t(localeKeys.command.deploy.describe)).action(async (options2) => {
|
117
|
-
if (!options2.skipBuild) {
|
118
|
-
const { build } = await import("./commands/build");
|
119
|
-
await build(api);
|
120
|
-
}
|
121
|
-
const { deploy } = await import("./commands/deploy");
|
122
|
-
await deploy(api, options2);
|
123
|
-
process.exit(0);
|
62
|
+
}) => ({
|
63
|
+
name: "@modern-js/app-tools",
|
64
|
+
post: [
|
65
|
+
"@modern-js/plugin-initialize",
|
66
|
+
"@modern-js/plugin-analyze",
|
67
|
+
"@modern-js/plugin-ssr",
|
68
|
+
"@modern-js/plugin-document",
|
69
|
+
"@modern-js/plugin-state",
|
70
|
+
"@modern-js/plugin-router",
|
71
|
+
"@modern-js/plugin-router-v5",
|
72
|
+
"@modern-js/plugin-polyfill"
|
73
|
+
],
|
74
|
+
registerHook: hooks,
|
75
|
+
usePlugins: [
|
76
|
+
initializePlugin({
|
77
|
+
bundler: (options === null || options === void 0 ? void 0 : options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
|
78
|
+
}),
|
79
|
+
analyzePlugin({
|
80
|
+
bundler: (options === null || options === void 0 ? void 0 : options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
|
81
|
+
}),
|
82
|
+
lintPlugin()
|
83
|
+
],
|
84
|
+
setup: (api) => {
|
85
|
+
const appContext = api.useAppContext();
|
86
|
+
api.setAppContext({
|
87
|
+
...appContext,
|
88
|
+
toolsType: "app-tools"
|
89
|
+
});
|
90
|
+
const nestedRoutes = {};
|
91
|
+
const locale = getLocaleLanguage();
|
92
|
+
i18n.changeLanguage({
|
93
|
+
locale
|
94
|
+
});
|
95
|
+
return {
|
96
|
+
async beforeConfig() {
|
97
|
+
var _userConfig_output;
|
98
|
+
const userConfig = api.useConfigContext();
|
99
|
+
const appContext2 = api.useAppContext();
|
100
|
+
if ((_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir) {
|
101
|
+
api.setAppContext({
|
102
|
+
...appContext2,
|
103
|
+
internalDirectory: path.resolve(appContext2.appDirectory, userConfig.output.tempDir)
|
124
104
|
});
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
105
|
+
}
|
106
|
+
},
|
107
|
+
async commands({ program }) {
|
108
|
+
await devCommand(program, api);
|
109
|
+
await buildCommand(program, api);
|
110
|
+
program.command("serve").usage("[options]").description(i18n.t(localeKeys.command.serve.describe)).option("--api-only", i18n.t(localeKeys.command.dev.apiOnly)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).action(async () => {
|
111
|
+
const { start } = await import("./commands/serve");
|
112
|
+
await start(api);
|
113
|
+
});
|
114
|
+
program.command("deploy").usage("[options]").option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("-s --skip-build", i18n.t(localeKeys.command.shared.skipBuild)).description(i18n.t(localeKeys.command.deploy.describe)).action(async (options2) => {
|
115
|
+
if (!options2.skipBuild) {
|
116
|
+
const { build } = await import("./commands/build");
|
117
|
+
await build(api);
|
118
|
+
}
|
119
|
+
const { deploy } = await import("./commands/deploy");
|
120
|
+
await deploy(api, options2);
|
121
|
+
process.exit(0);
|
122
|
+
});
|
123
|
+
program.command("new").usage("[options]").description(i18n.t(localeKeys.command.new.describe)).option("--config-file <configFile>", i18n.t(localeKeys.command.shared.config)).option("--lang <lang>", i18n.t(localeKeys.command.new.lang)).option("-c, --config <config>", i18n.t(localeKeys.command.new.config)).option("-d, --debug", i18n.t(localeKeys.command.new.debug), false).option("--dist-tag <tag>", i18n.t(localeKeys.command.new.distTag)).option("--registry", i18n.t(localeKeys.command.new.registry)).option("--no-need-install", i18n.t(localeKeys.command.shared.noNeedInstall)).action(async (options2) => {
|
124
|
+
const { MWANewAction } = await import("@modern-js/new-action");
|
125
|
+
await MWANewAction({
|
126
|
+
...options2,
|
127
|
+
locale: options2.lang || locale
|
131
128
|
});
|
132
|
-
|
133
|
-
|
134
|
-
|
129
|
+
});
|
130
|
+
program.command("inspect").description("inspect the internal configs").option(`--env <env>`, i18n.t(localeKeys.command.inspect.env), "development").option("--output <output>", i18n.t(localeKeys.command.inspect.output), "/").option("--verbose", i18n.t(localeKeys.command.inspect.verbose)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).action(async (options2) => {
|
131
|
+
const { inspect } = await import("./commands/inspect");
|
132
|
+
inspect(api, options2);
|
133
|
+
});
|
134
|
+
const { defineCommand } = await import("@modern-js/upgrade");
|
135
|
+
defineCommand(program.command("upgrade").option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("--no-need-install", i18n.t(localeKeys.command.shared.noNeedInstall)));
|
136
|
+
},
|
137
|
+
async prepare() {
|
138
|
+
const command = getCommand();
|
139
|
+
if (command === "deploy") {
|
140
|
+
const isSkipBuild = [
|
141
|
+
"-s",
|
142
|
+
"--skip-build"
|
143
|
+
].some((tag) => {
|
144
|
+
return getArgv().includes(tag);
|
135
145
|
});
|
136
|
-
|
137
|
-
|
138
|
-
},
|
139
|
-
async prepare() {
|
140
|
-
const command = getCommand();
|
141
|
-
if (command === "deploy") {
|
142
|
-
const isSkipBuild = [
|
143
|
-
"-s",
|
144
|
-
"--skip-build"
|
145
|
-
].some((tag) => {
|
146
|
-
return getArgv().includes(tag);
|
147
|
-
});
|
148
|
-
if (isSkipBuild) {
|
149
|
-
return;
|
150
|
-
}
|
146
|
+
if (isSkipBuild) {
|
147
|
+
return;
|
151
148
|
}
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
}
|
159
|
-
},
|
160
|
-
async watchFiles() {
|
161
|
-
const appContext2 = api.useAppContext();
|
162
|
-
const config = api.useResolvedConfigContext();
|
163
|
-
return await generateWatchFiles(appContext2, config.source.configDir);
|
164
|
-
},
|
165
|
-
// 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
|
166
|
-
async fileChange(e) {
|
167
|
-
const { filename, eventType, isPrivate } = e;
|
168
|
-
if (!isPrivate && (eventType === "change" || eventType === "unlink")) {
|
169
|
-
const { closeServer } = await import("./utils/createServer");
|
170
|
-
await closeServer();
|
171
|
-
await restart(api.useHookRunners(), filename);
|
149
|
+
}
|
150
|
+
if (command === "dev" || command === "start" || command === "build" || command === "deploy") {
|
151
|
+
const resolvedConfig = api.useResolvedConfigContext();
|
152
|
+
if (resolvedConfig.output.cleanDistPath) {
|
153
|
+
const appContext2 = api.useAppContext();
|
154
|
+
await emptyDir(appContext2.distDirectory);
|
172
155
|
}
|
173
|
-
},
|
174
|
-
async beforeRestart() {
|
175
|
-
cleanRequireCache([
|
176
|
-
require.resolve("./analyze")
|
177
|
-
]);
|
178
|
-
},
|
179
|
-
async modifyFileSystemRoutes({ entrypoint, routes }) {
|
180
|
-
nestedRoutes[entrypoint.entryName] = routes;
|
181
|
-
return {
|
182
|
-
entrypoint,
|
183
|
-
routes
|
184
|
-
};
|
185
|
-
},
|
186
|
-
async beforeGenerateRoutes({ entrypoint, code }) {
|
187
|
-
const { distDirectory } = api.useAppContext();
|
188
|
-
await fs.outputJSON(path.resolve(distDirectory, NESTED_ROUTE_SPEC_FILE), nestedRoutes);
|
189
|
-
return {
|
190
|
-
entrypoint,
|
191
|
-
code
|
192
|
-
};
|
193
156
|
}
|
194
|
-
}
|
195
|
-
|
196
|
-
|
197
|
-
|
157
|
+
},
|
158
|
+
async watchFiles() {
|
159
|
+
const appContext2 = api.useAppContext();
|
160
|
+
const config = api.useResolvedConfigContext();
|
161
|
+
return await generateWatchFiles(appContext2, config.source.configDir);
|
162
|
+
},
|
163
|
+
// 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
|
164
|
+
async fileChange(e) {
|
165
|
+
const { filename, eventType, isPrivate } = e;
|
166
|
+
if (!isPrivate && (eventType === "change" || eventType === "unlink")) {
|
167
|
+
const { closeServer } = await import("./utils/createServer");
|
168
|
+
await closeServer();
|
169
|
+
await restart(api.useHookRunners(), filename);
|
170
|
+
}
|
171
|
+
},
|
172
|
+
async beforeRestart() {
|
173
|
+
cleanRequireCache([
|
174
|
+
require.resolve("./analyze")
|
175
|
+
]);
|
176
|
+
},
|
177
|
+
async modifyFileSystemRoutes({ entrypoint, routes }) {
|
178
|
+
nestedRoutes[entrypoint.entryName] = routes;
|
179
|
+
return {
|
180
|
+
entrypoint,
|
181
|
+
routes
|
182
|
+
};
|
183
|
+
},
|
184
|
+
async beforeGenerateRoutes({ entrypoint, code }) {
|
185
|
+
const { distDirectory } = api.useAppContext();
|
186
|
+
await fs.outputJSON(path.resolve(distDirectory, NESTED_ROUTE_SPEC_FILE), nestedRoutes);
|
187
|
+
return {
|
188
|
+
entrypoint,
|
189
|
+
code
|
190
|
+
};
|
191
|
+
}
|
192
|
+
};
|
193
|
+
}
|
194
|
+
});
|
198
195
|
export default appTools;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import * as path from "path";
|
2
2
|
import { bundle } from "@modern-js/node-bundle-require";
|
3
|
-
import {
|
3
|
+
import { fs, getServerConfig, ensureAbsolutePath, OUTPUT_CONFIG_FILE, CONFIG_FILE_EXTENSIONS } from "@modern-js/utils";
|
4
4
|
export const defineServerConfig = (config) => config;
|
5
5
|
export const buildServerConfig = async ({ appDirectory, distDirectory, configFile, options, watch }) => {
|
6
6
|
const configFilePath = await getServerConfig(appDirectory, configFile);
|
@@ -50,7 +50,7 @@ export const safeReplacer = () => {
|
|
50
50
|
};
|
51
51
|
export const emitResolvedConfig = async (appDirectory, resolvedConfig) => {
|
52
52
|
var _resolvedConfig_output_distPath;
|
53
|
-
const outputPath =
|
53
|
+
const 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));
|
54
54
|
await fs.writeJSON(outputPath, resolvedConfig, {
|
55
55
|
spaces: 2,
|
56
56
|
replacer: safeReplacer()
|
package/package.json
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
"modern",
|
16
16
|
"modern.js"
|
17
17
|
],
|
18
|
-
"version": "2.
|
18
|
+
"version": "2.35.1",
|
19
19
|
"jsnext:source": "./src/index.ts",
|
20
20
|
"types": "./dist/types/index.d.ts",
|
21
21
|
"main": "./dist/cjs/index.js",
|
@@ -71,26 +71,25 @@
|
|
71
71
|
"@babel/types": "^7.22.15",
|
72
72
|
"es-module-lexer": "^1.1.0",
|
73
73
|
"esbuild": "0.17.19",
|
74
|
-
"rspack-plugin-virtual-module": "0.1.7",
|
75
74
|
"@swc/helpers": "0.5.1",
|
76
|
-
"@modern-js/builder
|
77
|
-
"@modern-js/builder-plugin-
|
78
|
-
"@modern-js/
|
79
|
-
"@modern-js/builder": "2.
|
80
|
-
"@modern-js/builder-
|
81
|
-
"@modern-js/
|
82
|
-
"@modern-js/
|
83
|
-
"@modern-js/
|
84
|
-
"@modern-js/plugin
|
85
|
-
"@modern-js/plugin-
|
86
|
-
"@modern-js/
|
87
|
-
"@modern-js/
|
88
|
-
"@modern-js/
|
89
|
-
"@modern-js/
|
90
|
-
"@modern-js/
|
91
|
-
"@modern-js/
|
92
|
-
"@modern-js/
|
93
|
-
"@modern-js/
|
75
|
+
"@modern-js/builder": "2.35.1",
|
76
|
+
"@modern-js/builder-plugin-esbuild": "2.35.1",
|
77
|
+
"@modern-js/builder-plugin-node-polyfill": "2.35.1",
|
78
|
+
"@modern-js/builder-shared": "2.35.1",
|
79
|
+
"@modern-js/builder-webpack-provider": "2.35.1",
|
80
|
+
"@modern-js/core": "2.35.1",
|
81
|
+
"@modern-js/new-action": "2.35.1",
|
82
|
+
"@modern-js/node-bundle-require": "2.35.1",
|
83
|
+
"@modern-js/plugin": "2.35.1",
|
84
|
+
"@modern-js/plugin-data-loader": "2.35.1",
|
85
|
+
"@modern-js/plugin-i18n": "2.35.1",
|
86
|
+
"@modern-js/plugin-lint": "2.35.1",
|
87
|
+
"@modern-js/prod-server": "2.35.1",
|
88
|
+
"@modern-js/server": "2.35.1",
|
89
|
+
"@modern-js/types": "2.35.1",
|
90
|
+
"@modern-js/upgrade": "2.35.1",
|
91
|
+
"@modern-js/utils": "2.35.1",
|
92
|
+
"@modern-js/server-core": "2.35.1"
|
94
93
|
},
|
95
94
|
"devDependencies": {
|
96
95
|
"@types/babel__traverse": "^7.14.2",
|
@@ -99,13 +98,13 @@
|
|
99
98
|
"jest": "^29",
|
100
99
|
"typescript": "^5",
|
101
100
|
"webpack": "^5.88.1",
|
102
|
-
"@modern-js/builder-plugin-swc": "2.
|
103
|
-
"@
|
104
|
-
"@
|
105
|
-
"@scripts/jest-config": "2.
|
101
|
+
"@modern-js/builder-plugin-swc": "2.35.1",
|
102
|
+
"@modern-js/builder-rspack-provider": "2.35.1",
|
103
|
+
"@scripts/build": "2.35.1",
|
104
|
+
"@scripts/jest-config": "2.35.1"
|
106
105
|
},
|
107
106
|
"peerDependencies": {
|
108
|
-
"@modern-js/builder-rspack-provider": "^2.
|
107
|
+
"@modern-js/builder-rspack-provider": "^2.35.1"
|
109
108
|
},
|
110
109
|
"peerDependenciesMeta": {
|
111
110
|
"@modern-js/builder-rspack-provider": {
|