@modern-js/app-tools 2.57.2-alpha.0 → 2.58.1-alpha.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/dist/cjs/builder/builder-webpack/index.js +1 -1
- package/dist/cjs/builder/generator/index.js +2 -2
- package/dist/cjs/builder/index.js +2 -2
- package/dist/cjs/commands/build.js +0 -19
- package/dist/cjs/commands/dev.js +0 -9
- package/dist/cjs/commands/index.js +8 -8
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/plugins/analyze/index.js +3 -3
- package/dist/cjs/plugins/deploy/dependencies/index.js +12 -2
- package/dist/cjs/plugins/deploy/dependencies/utils.js +73 -13
- package/dist/cjs/plugins/deploy/platforms/netlify.js +5 -14
- package/dist/cjs/plugins/deploy/platforms/{netlify-handler.js → netlifyEntry.js} +4 -6
- package/dist/cjs/plugins/deploy/platforms/node.js +4 -13
- package/dist/cjs/plugins/deploy/platforms/vercel.js +5 -14
- package/dist/cjs/plugins/deploy/platforms/{vercel-handler.js → vercelEntry.js} +1 -27
- package/dist/cjs/utils/config.js +7 -23
- package/dist/cjs/utils/loadPlugins.js +1 -1
- package/dist/cjs/utils/register.js +22 -49
- package/dist/esm/builder/builder-rspack/adapterCopy.js +4 -3
- package/dist/esm/builder/generator/getBuilderEnvironments.js +2 -0
- package/dist/esm/builder/generator/index.js +1 -1
- package/dist/esm/builder/index.js +2 -2
- package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +1 -1
- package/dist/esm/commands/build.js +16 -9
- package/dist/esm/commands/dev.js +55 -37
- package/dist/esm/commands/index.js +7 -7
- package/dist/esm/index.js +1 -42
- package/dist/esm/plugins/analyze/index.js +10 -6
- package/dist/esm/plugins/deploy/dependencies/index.js +28 -8
- package/dist/esm/plugins/deploy/dependencies/utils.js +290 -10
- package/dist/esm/utils/config.js +6 -21
- package/dist/esm/utils/createServer.js +1 -1
- package/dist/esm-node/builder/builder-rspack/adapterCopy.js +2 -2
- package/dist/esm-node/builder/generator/getBuilderEnvironments.js +1 -1
- package/dist/esm-node/builder/generator/index.js +1 -1
- package/dist/esm-node/builder/index.js +2 -2
- package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +1 -1
- package/dist/esm-node/commands/build.js +3 -0
- package/dist/esm-node/commands/dev.js +24 -16
- package/dist/esm-node/commands/index.js +7 -7
- package/dist/esm-node/index.js +1 -17
- package/dist/esm-node/plugins/analyze/index.js +7 -5
- package/dist/esm-node/plugins/deploy/dependencies/index.js +26 -7
- package/dist/esm-node/plugins/deploy/dependencies/utils.js +83 -3
- package/dist/esm-node/utils/config.js +5 -20
- package/dist/esm-node/utils/createServer.js +1 -1
- package/dist/types/builder/index.d.ts +1 -1
- package/dist/types/plugins/deploy/dependencies/index.d.ts +5 -3
- package/dist/types/plugins/deploy/dependencies/utils.d.ts +7 -1
- package/dist/types/plugins/deploy/platforms/netlifyEntry.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/vercelEntry.d.ts +2 -0
- package/dist/types/utils/config.d.ts +0 -5
- package/package.json +23 -21
- package/dist/cjs/esm/esbuild-loader.mjs +0 -20
- package/dist/cjs/esm/register-esm.mjs +0 -65
- package/dist/cjs/esm/ts-node-loader.mjs +0 -21
- package/dist/cjs/esm/utils.mjs +0 -43
- package/dist/cjs/plugins/deploy/platforms/netlify-entry.js +0 -3
- package/dist/cjs/plugins/deploy/platforms/netlify-entry.mjs +0 -1
- package/dist/cjs/plugins/deploy/platforms/vercel-entry.js +0 -3
- package/dist/cjs/plugins/deploy/platforms/vercel-entry.mjs +0 -3
- package/dist/esm/custom-loader.mjs +0 -41
- package/dist/esm/register-esm.mjs +0 -22
- package/dist/esm-node/esm/esbuild-loader.js +0 -39
- package/dist/esm-node/esm/register-esm.js +0 -39
- package/dist/esm-node/esm/ts-node-loader.js +0 -42
- package/dist/types/esm/esbuild-loader.d.mts +0 -6
- package/dist/types/esm/register-esm.d.mts +0 -5
- package/dist/types/esm/ts-node-loader.d.mts +0 -6
- package/dist/types/esm/utils.d.mts +0 -6
- package/dist/types/plugins/deploy/platforms/netlify-entry.d.cts +0 -1
- package/dist/types/plugins/deploy/platforms/netlify-entry.d.mts +0 -1
- package/dist/types/plugins/deploy/platforms/netlify-handler.d.cts +0 -1
- package/dist/types/plugins/deploy/platforms/vercel-entry.d.cts +0 -2
- package/dist/types/plugins/deploy/platforms/vercel-entry.d.mts +0 -2
- package/dist/types/plugins/deploy/platforms/vercel-handler.d.cts +0 -1
- /package/dist/cjs/plugins/deploy/platforms/{node-entry.js → nodeEntry.js} +0 -0
- /package/dist/types/plugins/deploy/platforms/{node-entry.d.ts → nodeEntry.d.ts} +0 -0
|
@@ -38,7 +38,7 @@ async function createWebpackBuilderForModern(options) {
|
|
|
38
38
|
const { normalizedConfig } = options;
|
|
39
39
|
if (normalizedConfig.tools.esbuild) {
|
|
40
40
|
const { esbuild: esbuildOptions } = normalizedConfig.tools;
|
|
41
|
-
const { pluginEsbuild } = await
|
|
41
|
+
const { pluginEsbuild } = await Promise.resolve().then(() => __toESM(require("@modern-js/rsbuild-plugin-esbuild")));
|
|
42
42
|
builder.addPlugins([
|
|
43
43
|
pluginEsbuild(esbuildOptions)
|
|
44
44
|
]);
|
|
@@ -50,7 +50,7 @@ async function generateBuilder(options, bundlerType) {
|
|
|
50
50
|
return builder;
|
|
51
51
|
}
|
|
52
52
|
async function applyBuilderPlugins(builder, options) {
|
|
53
|
-
const { builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR, builderPluginAdapterWorker } = await
|
|
53
|
+
const { builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR, builderPluginAdapterWorker } = await Promise.resolve().then(() => __toESM(require("../shared/builderPlugins")));
|
|
54
54
|
builder.addPlugins([
|
|
55
55
|
builderPluginAdapterBasic(),
|
|
56
56
|
builderPluginAdapterSSR(options),
|
|
@@ -59,7 +59,7 @@ async function applyBuilderPlugins(builder, options) {
|
|
|
59
59
|
]);
|
|
60
60
|
const { normalizedConfig } = options;
|
|
61
61
|
if (!normalizedConfig.output.disableNodePolyfill) {
|
|
62
|
-
const { pluginNodePolyfill } = await
|
|
62
|
+
const { pluginNodePolyfill } = await Promise.resolve().then(() => __toESM(require("@rsbuild/plugin-node-polyfill")));
|
|
63
63
|
builder.addPlugins([
|
|
64
64
|
pluginNodePolyfill()
|
|
65
65
|
]);
|
|
@@ -33,10 +33,10 @@ __export(builder_exports, {
|
|
|
33
33
|
module.exports = __toCommonJS(builder_exports);
|
|
34
34
|
async function createBuilderGenerator(bundler) {
|
|
35
35
|
if (bundler === "rspack") {
|
|
36
|
-
const { createRspackBuilderForModern } = await
|
|
36
|
+
const { createRspackBuilderForModern } = await Promise.resolve().then(() => __toESM(require("./builder-rspack")));
|
|
37
37
|
return createRspackBuilderForModern;
|
|
38
38
|
}
|
|
39
|
-
const { createWebpackBuilderForModern } = await
|
|
39
|
+
const { createWebpackBuilderForModern } = await Promise.resolve().then(() => __toESM(require("./builder-webpack")));
|
|
40
40
|
return createWebpackBuilderForModern;
|
|
41
41
|
}
|
|
42
42
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
var build_exports = {};
|
|
30
20
|
__export(build_exports, {
|
|
@@ -46,15 +36,6 @@ const build = async (api, options) => {
|
|
|
46
36
|
const appContext = api.useAppContext();
|
|
47
37
|
const hookRunners = api.useHookRunners();
|
|
48
38
|
await (0, import_loadPlugins.loadServerPlugins)(api, appContext.appDirectory, appContext.metaName);
|
|
49
|
-
if (appContext.moduleType && appContext.moduleType === "module") {
|
|
50
|
-
var _resolvedConfig_source1;
|
|
51
|
-
const { registerEsm } = await import("../esm/register-esm.mjs");
|
|
52
|
-
await registerEsm({
|
|
53
|
-
appDir: appContext.appDirectory,
|
|
54
|
-
distDir: appContext.distDirectory,
|
|
55
|
-
alias: (_resolvedConfig_source1 = resolvedConfig.source) === null || _resolvedConfig_source1 === void 0 ? void 0 : _resolvedConfig_source1.alias
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
39
|
await (0, import_register.registerCompiler)(appContext.appDirectory, appContext.distDirectory, resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.alias);
|
|
59
40
|
const { apiOnly } = appContext;
|
|
60
41
|
if (apiOnly) {
|
package/dist/cjs/commands/dev.js
CHANGED
|
@@ -50,15 +50,6 @@ const dev = async (api, options, devServerOptions) => {
|
|
|
50
50
|
let normalizedConfig = api.useResolvedConfigContext();
|
|
51
51
|
const appContext = api.useAppContext();
|
|
52
52
|
const hookRunners = api.useHookRunners();
|
|
53
|
-
if (appContext.moduleType && appContext.moduleType === "module") {
|
|
54
|
-
var _normalizedConfig_source1;
|
|
55
|
-
const { registerEsm } = await import("../esm/register-esm.mjs");
|
|
56
|
-
await registerEsm({
|
|
57
|
-
appDir: appContext.appDirectory,
|
|
58
|
-
distDir: appContext.distDirectory,
|
|
59
|
-
alias: (_normalizedConfig_source1 = normalizedConfig.source) === null || _normalizedConfig_source1 === void 0 ? void 0 : _normalizedConfig_source1.alias
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
53
|
await (0, import_register.registerCompiler)(appContext.appDirectory, appContext.distDirectory, normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_source = normalizedConfig.source) === null || _normalizedConfig_source === void 0 ? void 0 : _normalizedConfig_source.alias);
|
|
63
54
|
normalizedConfig = {
|
|
64
55
|
...normalizedConfig,
|
|
@@ -44,7 +44,7 @@ const devCommand = async (program, api) => {
|
|
|
44
44
|
const runner = api.useHookRunners();
|
|
45
45
|
const devToolMetas = await runner.registerDev();
|
|
46
46
|
const devProgram = program.command("dev").alias("start").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.dev.describe)).option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).option("-e --entry [entry...]", import_locale.i18n.t(import_locale.localeKeys.command.dev.entry)).option("--analyze", import_locale.i18n.t(import_locale.localeKeys.command.shared.analyze)).option("--api-only", import_locale.i18n.t(import_locale.localeKeys.command.dev.apiOnly)).option("--web-only", import_locale.i18n.t(import_locale.localeKeys.command.dev.webOnly)).action(async (options) => {
|
|
47
|
-
const { dev } = await
|
|
47
|
+
const { dev } = await Promise.resolve().then(() => __toESM(require("./dev")));
|
|
48
48
|
await dev(api, options);
|
|
49
49
|
});
|
|
50
50
|
for (const meta of devToolMetas) {
|
|
@@ -54,7 +54,7 @@ const devCommand = async (program, api) => {
|
|
|
54
54
|
for (const subCmd of meta.subCommands) {
|
|
55
55
|
devProgram.command(subCmd).action(async (options = {}) => {
|
|
56
56
|
const { appDirectory } = api.useAppContext();
|
|
57
|
-
const { isTypescript } = await
|
|
57
|
+
const { isTypescript } = await Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
|
|
58
58
|
await runner.beforeDevTask(meta);
|
|
59
59
|
await meta.action(options, {
|
|
60
60
|
isTsProject: isTypescript(appDirectory)
|
|
@@ -67,7 +67,7 @@ const buildCommand = async (program, api) => {
|
|
|
67
67
|
const runner = api.useHookRunners();
|
|
68
68
|
const platformBuilders = await runner.registerBuildPlatform();
|
|
69
69
|
const buildProgram = program.command("build").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.build.describe)).option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).option("--analyze", import_locale.i18n.t(import_locale.localeKeys.command.shared.analyze)).action(async (options) => {
|
|
70
|
-
const { build } = await
|
|
70
|
+
const { build } = await Promise.resolve().then(() => __toESM(require("./build")));
|
|
71
71
|
await build(api, options);
|
|
72
72
|
});
|
|
73
73
|
for (const platformBuilder of platformBuilders) {
|
|
@@ -75,7 +75,7 @@ const buildCommand = async (program, api) => {
|
|
|
75
75
|
for (const platform of platforms) {
|
|
76
76
|
buildProgram.command(platform).action(async () => {
|
|
77
77
|
const { appDirectory } = api.useAppContext();
|
|
78
|
-
const { isTypescript } = await
|
|
78
|
+
const { isTypescript } = await Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
|
|
79
79
|
await runner.beforeBuildPlatform(platformBuilders);
|
|
80
80
|
await platformBuilder.build(platform, {
|
|
81
81
|
isTsProject: isTypescript(appDirectory)
|
|
@@ -86,17 +86,17 @@ const buildCommand = async (program, api) => {
|
|
|
86
86
|
};
|
|
87
87
|
const serverCommand = (program, api) => {
|
|
88
88
|
program.command("serve").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.serve.describe)).option("--api-only", import_locale.i18n.t(import_locale.localeKeys.command.dev.apiOnly)).option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).action(async () => {
|
|
89
|
-
const { start } = await
|
|
89
|
+
const { start } = await Promise.resolve().then(() => __toESM(require("./serve")));
|
|
90
90
|
await start(api);
|
|
91
91
|
});
|
|
92
92
|
};
|
|
93
93
|
const deployCommand = (program, api) => {
|
|
94
94
|
program.command("deploy").usage("[options]").option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).option("-s --skip-build", import_locale.i18n.t(import_locale.localeKeys.command.shared.skipBuild)).description(import_locale.i18n.t(import_locale.localeKeys.command.deploy.describe)).action(async (options) => {
|
|
95
95
|
if (!options.skipBuild) {
|
|
96
|
-
const { build } = await
|
|
96
|
+
const { build } = await Promise.resolve().then(() => __toESM(require("./build")));
|
|
97
97
|
await build(api);
|
|
98
98
|
}
|
|
99
|
-
const { deploy } = await
|
|
99
|
+
const { deploy } = await Promise.resolve().then(() => __toESM(require("./deploy")));
|
|
100
100
|
await deploy(api, options);
|
|
101
101
|
process.exit(0);
|
|
102
102
|
});
|
|
@@ -111,7 +111,7 @@ const newCommand = (program, locale) => {
|
|
|
111
111
|
};
|
|
112
112
|
const inspectCommand = (program, api) => {
|
|
113
113
|
program.command("inspect").description("inspect the internal configs").option(`--env <env>`, import_locale.i18n.t(import_locale.localeKeys.command.inspect.env), "development").option("--output <output>", import_locale.i18n.t(import_locale.localeKeys.command.inspect.output), "./").option("--verbose", import_locale.i18n.t(import_locale.localeKeys.command.inspect.verbose)).option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).action(async (options) => {
|
|
114
|
-
const { inspect } = await
|
|
114
|
+
const { inspect } = await Promise.resolve().then(() => __toESM(require("./inspect")));
|
|
115
115
|
inspect(api, options);
|
|
116
116
|
});
|
|
117
117
|
};
|
package/dist/cjs/index.js
CHANGED
|
@@ -139,7 +139,7 @@ const appTools = (options = {
|
|
|
139
139
|
async fileChange(e) {
|
|
140
140
|
const { filename, eventType, isPrivate } = e;
|
|
141
141
|
if (!isPrivate && (eventType === "change" || eventType === "unlink")) {
|
|
142
|
-
const { closeServer } = await
|
|
142
|
+
const { closeServer } = await Promise.resolve().then(() => __toESM(require("./utils/createServer")));
|
|
143
143
|
await closeServer();
|
|
144
144
|
await (0, import_restart.restart)(api.useHookRunners(), filename);
|
|
145
145
|
}
|
|
@@ -77,9 +77,9 @@ var analyze_default = ({ bundler }) => ({
|
|
|
77
77
|
return;
|
|
78
78
|
}
|
|
79
79
|
const [{ getBundleEntry }, { getServerRoutes }, { getHtmlTemplate }] = await Promise.all([
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
Promise.resolve().then(() => __toESM(require("./getBundleEntry"))),
|
|
81
|
+
Promise.resolve().then(() => __toESM(require("./getServerRoutes"))),
|
|
82
|
+
Promise.resolve().then(() => __toESM(require("./getHtmlTemplate")))
|
|
83
83
|
]);
|
|
84
84
|
const { entrypoints } = await hookRunners.modifyEntrypoints({
|
|
85
85
|
entrypoints: await getBundleEntry(hookRunners, appContext, resolvedConfig)
|
|
@@ -38,12 +38,21 @@ var import_pkg_types = require("pkg-types");
|
|
|
38
38
|
var import_mlly = require("mlly");
|
|
39
39
|
var import_utils2 = require("./utils");
|
|
40
40
|
var import_nft = require("@vercel/nft");
|
|
41
|
-
const handleDependencies = async ({ appDir, serverRootDir, includeEntries, traceFiles = import_utils2.traceFiles, entryFilter, modifyPackageJson, copyWholePackage,
|
|
41
|
+
const handleDependencies = async ({ appDir, serverRootDir, includeEntries, traceFiles = import_utils2.traceFiles, entryFilter, modifyPackageJson, copyWholePackage, cacheOptions = {
|
|
42
|
+
cacheDir: ".modern-js/deploy",
|
|
43
|
+
fileCache: true,
|
|
44
|
+
analysisCache: true
|
|
45
|
+
}, traceOptions }) => {
|
|
42
46
|
const base = "/";
|
|
47
|
+
const startTime = Date.now();
|
|
43
48
|
const entryFiles = await (0, import_utils2.findEntryFiles)(serverRootDir, entryFilter);
|
|
44
49
|
const fileTrace = await traceFiles({
|
|
45
50
|
entryFiles: entryFiles.concat(includeEntries),
|
|
46
51
|
serverRootDir,
|
|
52
|
+
cacheOptions: {
|
|
53
|
+
...cacheOptions,
|
|
54
|
+
cacheDir: import_node_path.default.resolve(appDir, cacheOptions.cacheDir)
|
|
55
|
+
},
|
|
47
56
|
base,
|
|
48
57
|
traceOptions
|
|
49
58
|
});
|
|
@@ -219,7 +228,6 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
|
|
|
219
228
|
name: `${projectPkgJson.name || "modernjs-project"}-prod`,
|
|
220
229
|
version: projectPkgJson.version || "0.0.0",
|
|
221
230
|
private: true,
|
|
222
|
-
type: projectPkgJson.type || "commonjs",
|
|
223
231
|
dependencies: Object.fromEntries([
|
|
224
232
|
...Object.values(tracedPackages).map((pkg) => [
|
|
225
233
|
pkg.name,
|
|
@@ -229,6 +237,8 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
|
|
|
229
237
|
};
|
|
230
238
|
const finalPkgJson = (modifyPackageJson === null || modifyPackageJson === void 0 ? void 0 : modifyPackageJson(newPkgJson)) || newPkgJson;
|
|
231
239
|
await import_utils.fs.writeJSON(outputPkgPath, finalPkgJson);
|
|
240
|
+
const endTime = Date.now();
|
|
241
|
+
console.log("handleDependencies cost:", endTime - startTime);
|
|
232
242
|
};
|
|
233
243
|
// Annotate the CommonJS export names for ESM import in node:
|
|
234
244
|
0 && (module.exports = {
|
|
@@ -139,23 +139,83 @@ const findPackageParents = (pkg, version, tracedFiles) => {
|
|
|
139
139
|
];
|
|
140
140
|
return parentPkgs.filter((parentPkg) => parentPkg);
|
|
141
141
|
};
|
|
142
|
-
|
|
143
|
-
|
|
142
|
+
async function serializeMap(map) {
|
|
143
|
+
const resolvedMap = /* @__PURE__ */ new Map();
|
|
144
|
+
await Promise.all(Array.from(map.entries()).map(async ([key, value]) => {
|
|
145
|
+
resolvedMap.set(key, value instanceof Promise ? await Promise.resolve(value) : value);
|
|
146
|
+
}));
|
|
147
|
+
return JSON.stringify(resolvedMap, (key, value) => {
|
|
148
|
+
if (value instanceof Map) {
|
|
149
|
+
return {
|
|
150
|
+
dataType: "Map",
|
|
151
|
+
value: Array.from(value.entries())
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
if (value instanceof Set) {
|
|
155
|
+
return {
|
|
156
|
+
dataType: "Set",
|
|
157
|
+
value: Array.from(value)
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
return value;
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
function deserializeMap(serializedData) {
|
|
164
|
+
return JSON.parse(serializedData, (key, value) => {
|
|
165
|
+
if (value && value.dataType === "Map") {
|
|
166
|
+
return new Map(value.value);
|
|
167
|
+
}
|
|
168
|
+
if (value && value.dataType === "Set") {
|
|
169
|
+
return new Set(value.value);
|
|
170
|
+
}
|
|
171
|
+
return value;
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
const traceFiles = async ({ entryFiles, serverRootDir, base = "/", cacheOptions, traceOptions }) => {
|
|
175
|
+
const { cacheDir, fileCache: enableFileCache, analysisCache: enableAnalysisCache } = cacheOptions;
|
|
176
|
+
const analysisCacheFile = import_path.default.join(cacheDir, "analysis-cache.json");
|
|
177
|
+
const fileCacheFile = import_path.default.join(cacheDir, "file-cache.json");
|
|
178
|
+
const cache = /* @__PURE__ */ Object.create(null);
|
|
179
|
+
if (enableAnalysisCache && await import_utils.fs.pathExists(analysisCacheFile)) {
|
|
180
|
+
const analysisCache2 = (await import_utils.fs.readFile(analysisCacheFile)).toString();
|
|
181
|
+
cache.analysisCache = deserializeMap(analysisCache2);
|
|
182
|
+
}
|
|
183
|
+
if (enableFileCache && await import_utils.fs.pathExists(fileCacheFile)) {
|
|
184
|
+
const fileCache2 = (await import_utils.fs.readFile(fileCacheFile)).toString();
|
|
185
|
+
cache.fileCache = deserializeMap(fileCache2);
|
|
186
|
+
}
|
|
187
|
+
const res = await (0, import_nft.nodeFileTrace)(entryFiles, {
|
|
144
188
|
base,
|
|
145
189
|
processCwd: serverRootDir,
|
|
146
|
-
|
|
147
|
-
if (id.startsWith("@modern-js/prod-server")) {
|
|
148
|
-
return require.resolve(id, {
|
|
149
|
-
paths: [
|
|
150
|
-
require.resolve("@modern-js/app-tools")
|
|
151
|
-
]
|
|
152
|
-
});
|
|
153
|
-
} else {
|
|
154
|
-
return (0, import_nft.resolve)(id, parent, job, isCjs);
|
|
155
|
-
}
|
|
156
|
-
},
|
|
190
|
+
cache,
|
|
157
191
|
...traceOptions
|
|
158
192
|
});
|
|
193
|
+
const { analysisCache, fileCache } = cache;
|
|
194
|
+
if (analysisCache || fileCache) {
|
|
195
|
+
await import_utils.fs.ensureDir(cacheDir);
|
|
196
|
+
if (analysisCache) {
|
|
197
|
+
const newAnalysisCache = new Map(analysisCache);
|
|
198
|
+
for (const key of newAnalysisCache.keys()) {
|
|
199
|
+
if (!key.includes("node_modules/")) {
|
|
200
|
+
newAnalysisCache.delete(key);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
import_utils.fs.writeFile(analysisCacheFile, await serializeMap(newAnalysisCache));
|
|
204
|
+
}
|
|
205
|
+
if (fileCache) {
|
|
206
|
+
const newFileCache = new Map(fileCache);
|
|
207
|
+
for (const key of newFileCache.keys()) {
|
|
208
|
+
if (!key.includes("node_modules/")) {
|
|
209
|
+
newFileCache.delete(key);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
console.time("111");
|
|
213
|
+
import_utils.fs.writeFile(fileCacheFile, await serializeMap(newFileCache));
|
|
214
|
+
console.timeEnd("111");
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
console.log("ffffffff", __filename);
|
|
218
|
+
return res;
|
|
159
219
|
};
|
|
160
220
|
const resolveTracedPath = async (base, p) => import_utils.fs.realpath(import_path.default.resolve(base, p));
|
|
161
221
|
const isSubPath = (parentPath, childPath) => {
|
|
@@ -50,13 +50,11 @@ async function cleanDistDirectory(dir) {
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
|
|
53
|
-
const { appDirectory, distDirectory, entrypoints, serverPlugins
|
|
54
|
-
const isEsmProject = moduleType === "module";
|
|
53
|
+
const { appDirectory, distDirectory, entrypoints, serverPlugins } = appContext;
|
|
55
54
|
const plugins = serverPlugins.map((plugin) => plugin.name);
|
|
56
55
|
const netlifyOutput = import_node_path.default.join(appDirectory, ".netlify");
|
|
57
56
|
const funcsDirectory = import_node_path.default.join(netlifyOutput, "functions");
|
|
58
57
|
const entryFilePath = import_node_path.default.join(funcsDirectory, "index.js");
|
|
59
|
-
const handlerFilePath = import_node_path.default.join(funcsDirectory, "netlify-handler.cjs");
|
|
60
58
|
return {
|
|
61
59
|
async prepare() {
|
|
62
60
|
await import_utils.fs.remove(netlifyOutput);
|
|
@@ -105,9 +103,7 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
|
|
|
105
103
|
prefix: modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_bff = modernConfig.bff) === null || _modernConfig_bff === void 0 ? void 0 : _modernConfig_bff.prefix
|
|
106
104
|
},
|
|
107
105
|
output: {
|
|
108
|
-
|
|
109
|
-
root: "."
|
|
110
|
-
}
|
|
106
|
+
path: "."
|
|
111
107
|
}
|
|
112
108
|
};
|
|
113
109
|
const pluginImportCode = (0, import_utils2.genPluginImportsCode)(plugins || []);
|
|
@@ -118,15 +114,10 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
|
|
|
118
114
|
const pluginsCode = `[${plugins.map((plugin, index) => {
|
|
119
115
|
return `plugin_${index}()`;
|
|
120
116
|
}).join(",")}]`;
|
|
121
|
-
let
|
|
117
|
+
let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./netlifyEntry.js"))).toString();
|
|
122
118
|
const serverAppContext = (0, import_utils2.serverAppContenxtTemplate)(appContext);
|
|
123
|
-
|
|
124
|
-
await import_utils.fs.writeFile(
|
|
125
|
-
if (isEsmProject) {
|
|
126
|
-
await import_utils.fs.copy(import_node_path.default.join(__dirname, "./netlify-entry.mjs"), entryFilePath);
|
|
127
|
-
} else {
|
|
128
|
-
await import_utils.fs.copy(import_node_path.default.join(__dirname, "./netlify-entry.js"), entryFilePath);
|
|
129
|
-
}
|
|
119
|
+
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_plugins", pluginsCode).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
|
|
120
|
+
await import_utils.fs.writeFile(entryFilePath, entryCode);
|
|
130
121
|
},
|
|
131
122
|
async end() {
|
|
132
123
|
if (process.env.NODE_ENV !== "development") {
|
|
@@ -53,11 +53,9 @@ async function createHandler() {
|
|
|
53
53
|
return requestHandler;
|
|
54
54
|
}
|
|
55
55
|
createHandler();
|
|
56
|
-
module.exports = {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
await createHandler();
|
|
60
|
-
}
|
|
61
|
-
return requestHandler(request, context);
|
|
56
|
+
module.exports.default = async (request, context) => {
|
|
57
|
+
if (!requestHandler) {
|
|
58
|
+
await createHandler();
|
|
62
59
|
}
|
|
60
|
+
return requestHandler(request, context);
|
|
63
61
|
};
|
|
@@ -36,8 +36,7 @@ var import_utils = require("@modern-js/utils");
|
|
|
36
36
|
var import_utils2 = require("../utils");
|
|
37
37
|
var import_dependencies = require("../dependencies");
|
|
38
38
|
const createNodePreset = (appContext, config) => {
|
|
39
|
-
const { appDirectory, distDirectory, serverPlugins
|
|
40
|
-
const isEsmProject = moduleType === "module";
|
|
39
|
+
const { appDirectory, distDirectory, serverPlugins } = appContext;
|
|
41
40
|
const plugins = serverPlugins.map((plugin) => plugin.name);
|
|
42
41
|
const outputDirectory = import_node_path.default.join(appDirectory, ".output");
|
|
43
42
|
const staticDirectory = import_node_path.default.join(outputDirectory, "static");
|
|
@@ -59,9 +58,7 @@ const createNodePreset = (appContext, config) => {
|
|
|
59
58
|
prefix: config === null || config === void 0 ? void 0 : (_config_bff = config.bff) === null || _config_bff === void 0 ? void 0 : _config_bff.prefix
|
|
60
59
|
},
|
|
61
60
|
output: {
|
|
62
|
-
|
|
63
|
-
root: "."
|
|
64
|
-
}
|
|
61
|
+
path: "."
|
|
65
62
|
}
|
|
66
63
|
};
|
|
67
64
|
const pluginImportCode = (0, import_utils2.genPluginImportsCode)(plugins || []);
|
|
@@ -72,16 +69,10 @@ const createNodePreset = (appContext, config) => {
|
|
|
72
69
|
const pluginsCode = `[${plugins.map((plugin, index) => {
|
|
73
70
|
return `plugin_${index}()`;
|
|
74
71
|
}).join(",")}]`;
|
|
75
|
-
let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./
|
|
72
|
+
let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./nodeEntry.js"))).toString();
|
|
76
73
|
const serverAppContext = (0, import_utils2.serverAppContenxtTemplate)(appContext);
|
|
77
74
|
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_plugins", pluginsCode).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
|
|
78
|
-
|
|
79
|
-
const cjsEntryFilePath = import_node_path.default.join(outputDirectory, "index.cjs");
|
|
80
|
-
await import_utils.fs.writeFile(cjsEntryFilePath, entryCode);
|
|
81
|
-
await import_utils.fs.writeFile(entryFilePath, `import('./index.cjs');`);
|
|
82
|
-
} else {
|
|
83
|
-
await import_utils.fs.writeFile(entryFilePath, entryCode);
|
|
84
|
-
}
|
|
75
|
+
await import_utils.fs.writeFile(entryFilePath, entryCode);
|
|
85
76
|
},
|
|
86
77
|
async end() {
|
|
87
78
|
console.log("Static directory:", import_utils.chalk.blue(import_node_path.default.relative(appDirectory, staticDirectory)));
|
|
@@ -37,14 +37,12 @@ var import_routes = require("../../../utils/routes");
|
|
|
37
37
|
var import_utils2 = require("../utils");
|
|
38
38
|
var import_dependencies = require("../dependencies");
|
|
39
39
|
const createVercelPreset = (appContext, modernConfig, needModernServer) => {
|
|
40
|
-
const { appDirectory, distDirectory, entrypoints, serverPlugins
|
|
41
|
-
const isEsmProject = moduleType === "module";
|
|
40
|
+
const { appDirectory, distDirectory, entrypoints, serverPlugins } = appContext;
|
|
42
41
|
const plugins = serverPlugins.map((plugin) => plugin.name);
|
|
43
42
|
const vercelOutput = import_node_path.default.join(appDirectory, ".vercel");
|
|
44
43
|
const outputDirectory = import_node_path.default.join(vercelOutput, "output");
|
|
45
44
|
const funcsDirectory = import_node_path.default.join(outputDirectory, "functions", "index.func");
|
|
46
45
|
const entryFilePath = import_node_path.default.join(funcsDirectory, "index.js");
|
|
47
|
-
const handlerFilePath = import_node_path.default.join(funcsDirectory, "vercel-handler.cjs");
|
|
48
46
|
return {
|
|
49
47
|
async prepare() {
|
|
50
48
|
await import_utils.fs.remove(vercelOutput);
|
|
@@ -120,9 +118,7 @@ const createVercelPreset = (appContext, modernConfig, needModernServer) => {
|
|
|
120
118
|
prefix: modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_bff = modernConfig.bff) === null || _modernConfig_bff === void 0 ? void 0 : _modernConfig_bff.prefix
|
|
121
119
|
},
|
|
122
120
|
output: {
|
|
123
|
-
|
|
124
|
-
root: "."
|
|
125
|
-
}
|
|
121
|
+
path: "."
|
|
126
122
|
}
|
|
127
123
|
};
|
|
128
124
|
const pluginImportCode = (0, import_utils2.genPluginImportsCode)(plugins || []);
|
|
@@ -134,14 +130,9 @@ const createVercelPreset = (appContext, modernConfig, needModernServer) => {
|
|
|
134
130
|
return `plugin_${index}()`;
|
|
135
131
|
}).join(",")}]`;
|
|
136
132
|
const serverAppContext = (0, import_utils2.serverAppContenxtTemplate)(appContext);
|
|
137
|
-
let
|
|
138
|
-
|
|
139
|
-
await import_utils.fs.writeFile(
|
|
140
|
-
if (isEsmProject) {
|
|
141
|
-
await import_utils.fs.copy(import_node_path.default.join(__dirname, "./vercel-entry.mjs"), entryFilePath);
|
|
142
|
-
} else {
|
|
143
|
-
await import_utils.fs.copy(import_node_path.default.join(__dirname, "./vercel-entry.js"), entryFilePath);
|
|
144
|
-
}
|
|
133
|
+
let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./vercelEntry.js"))).toString();
|
|
134
|
+
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_plugins", pluginsCode).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
|
|
135
|
+
await import_utils.fs.writeFile(entryFilePath, entryCode);
|
|
145
136
|
},
|
|
146
137
|
async end() {
|
|
147
138
|
if (!needModernServer) {
|
|
@@ -1,26 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var vercel_handler_exports = {};
|
|
20
|
-
__export(vercel_handler_exports, {
|
|
21
|
-
handler: () => handler
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(vercel_handler_exports);
|
|
24
2
|
const fs = require("node:fs/promises");
|
|
25
3
|
const path = require("node:path");
|
|
26
4
|
const { createProdServer } = require("@modern-js/prod-server");
|
|
@@ -75,13 +53,9 @@ async function createHandler() {
|
|
|
75
53
|
return requestHandler;
|
|
76
54
|
}
|
|
77
55
|
createHandler();
|
|
78
|
-
|
|
56
|
+
module.exports = async (req, res) => {
|
|
79
57
|
if (!requestHandler) {
|
|
80
58
|
await createHandler();
|
|
81
59
|
}
|
|
82
60
|
return requestHandler(req, res);
|
|
83
61
|
};
|
|
84
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
85
|
-
0 && (module.exports = {
|
|
86
|
-
handler
|
|
87
|
-
});
|
package/dist/cjs/utils/config.js
CHANGED
|
@@ -30,17 +30,17 @@ var config_exports = {};
|
|
|
30
30
|
__export(config_exports, {
|
|
31
31
|
buildServerConfig: () => buildServerConfig,
|
|
32
32
|
defineServerConfig: () => defineServerConfig,
|
|
33
|
-
emitResolvedConfig: () => emitResolvedConfig
|
|
34
|
-
safeReplacer: () => safeReplacer
|
|
33
|
+
emitResolvedConfig: () => emitResolvedConfig
|
|
35
34
|
});
|
|
36
35
|
module.exports = __toCommonJS(config_exports);
|
|
37
36
|
var path = __toESM(require("path"));
|
|
38
37
|
var import_node_bundle_require = require("@modern-js/node-bundle-require");
|
|
39
38
|
var import_utils = require("@modern-js/utils");
|
|
39
|
+
var import_flatted = require("flatted");
|
|
40
40
|
const defineServerConfig = (config) => config;
|
|
41
41
|
const buildServerConfig = async ({ appDirectory, distDirectory, configFile, options, watch }) => {
|
|
42
42
|
const configFilePath = await (0, import_utils.getServerConfig)(appDirectory, configFile);
|
|
43
|
-
const getOutputFile = async (filepath) => path.resolve(distDirectory, `${filepath.replace(new RegExp(import_utils.CONFIG_FILE_EXTENSIONS.join("|")), "")}.
|
|
43
|
+
const getOutputFile = async (filepath) => path.resolve(distDirectory, `${filepath.replace(new RegExp(import_utils.CONFIG_FILE_EXTENSIONS.join("|")), "")}.js`);
|
|
44
44
|
if (configFilePath) {
|
|
45
45
|
const configHelperFilePath = path.normalize(path.join(distDirectory, "./config-helper.js"));
|
|
46
46
|
const helperCode = `
|
|
@@ -69,33 +69,17 @@ const buildServerConfig = async ({ appDirectory, distDirectory, configFile, opti
|
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
71
|
};
|
|
72
|
-
const safeReplacer = () => {
|
|
73
|
-
const cache = [];
|
|
74
|
-
const keyCache = [];
|
|
75
|
-
return function(key, value) {
|
|
76
|
-
if (typeof value === "object" && value !== null) {
|
|
77
|
-
const index = cache.indexOf(value);
|
|
78
|
-
if (index !== -1) {
|
|
79
|
-
return `[Circular ${keyCache[index]}]`;
|
|
80
|
-
}
|
|
81
|
-
cache.push(value);
|
|
82
|
-
keyCache.push(key || "root");
|
|
83
|
-
}
|
|
84
|
-
return value;
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
72
|
const emitResolvedConfig = async (appDirectory, resolvedConfig) => {
|
|
88
73
|
var _resolvedConfig_output_distPath;
|
|
89
74
|
const outputPath = (0, import_utils.ensureAbsolutePath)(appDirectory, path.join(((_resolvedConfig_output_distPath = resolvedConfig.output.distPath) === null || _resolvedConfig_output_distPath === void 0 ? void 0 : _resolvedConfig_output_distPath.root) || "./dist", import_utils.OUTPUT_CONFIG_FILE));
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
75
|
+
const output = (0, import_flatted.stringify)(resolvedConfig);
|
|
76
|
+
await import_utils.fs.writeFile(outputPath, output, {
|
|
77
|
+
encoding: "utf-8"
|
|
93
78
|
});
|
|
94
79
|
};
|
|
95
80
|
// Annotate the CommonJS export names for ESM import in node:
|
|
96
81
|
0 && (module.exports = {
|
|
97
82
|
buildServerConfig,
|
|
98
83
|
defineServerConfig,
|
|
99
|
-
emitResolvedConfig
|
|
100
|
-
safeReplacer
|
|
84
|
+
emitResolvedConfig
|
|
101
85
|
});
|
|
@@ -37,7 +37,7 @@ async function getServerPlugins(api, metaName = "modern-js") {
|
|
|
37
37
|
}
|
|
38
38
|
async function loadServerPlugins(api, appDirectory, metaName) {
|
|
39
39
|
const plugins = await getServerPlugins(api, metaName);
|
|
40
|
-
const instances =
|
|
40
|
+
const instances = (0, import_prod_server.loadServerPlugins)(plugins, appDirectory);
|
|
41
41
|
return instances;
|
|
42
42
|
}
|
|
43
43
|
// Annotate the CommonJS export names for ESM import in node:
|