@modern-js/app-tools 2.53.1-alpha.3 → 2.54.0
Sign up to get free protection for your applications and to get access to all the features.
- package/bin/modern.js +0 -2
- package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +2 -1
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +2 -2
- package/dist/cjs/commands/build.js +2 -0
- package/dist/cjs/commands/deploy.js +2 -2
- package/dist/cjs/commands/dev.js +19 -5
- package/dist/cjs/commands/index.js +113 -7
- package/dist/cjs/commands/serve.js +19 -5
- package/dist/cjs/hooks.js +5 -0
- package/dist/cjs/index.js +14 -83
- package/dist/cjs/plugins/analyze/constants.js +56 -0
- package/dist/cjs/{analyze → plugins/analyze}/generateCode.js +11 -84
- package/dist/cjs/{analyze → plugins/analyze}/getBundleEntry.js +11 -20
- package/dist/cjs/{analyze → plugins/analyze}/getFileSystemEntry.js +33 -47
- package/dist/cjs/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
- package/dist/cjs/{analyze → plugins/analyze}/index.js +9 -24
- package/dist/cjs/plugins/analyze/templates.js +101 -0
- package/dist/cjs/{analyze → plugins/analyze}/utils.js +12 -55
- package/dist/cjs/plugins/deploy/dependencies/index.js +16 -25
- package/dist/cjs/plugins/deploy/dependencies/utils.js +1 -2
- package/dist/cjs/plugins/deploy/platforms/netlify.js +5 -9
- package/dist/cjs/plugins/deploy/platforms/node.js +5 -13
- package/dist/cjs/plugins/deploy/platforms/vercel.js +5 -9
- package/dist/cjs/{initialize → plugins/initialize}/index.js +1 -1
- package/dist/cjs/plugins/serverBuild.js +10 -4
- package/dist/cjs/utils/createServer.js +1 -1
- package/dist/cjs/utils/{getServerInternalPlugins.js → loadPlugins.js} +18 -11
- package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +4 -1
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +2 -2
- package/dist/esm/commands/build.js +16 -9
- package/dist/esm/commands/deploy.js +2 -2
- package/dist/esm/commands/dev.js +13 -9
- package/dist/esm/commands/index.js +411 -3
- package/dist/esm/commands/serve.js +12 -8
- package/dist/esm/hooks.js +5 -0
- package/dist/esm/index.js +12 -394
- package/dist/esm/plugins/analyze/constants.js +24 -0
- package/dist/esm/{analyze → plugins/analyze}/generateCode.js +27 -169
- package/dist/esm/plugins/analyze/getBundleEntry.js +101 -0
- package/dist/esm/plugins/analyze/getFileSystemEntry.js +195 -0
- package/dist/esm/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
- package/dist/esm/{analyze → plugins/analyze}/index.js +42 -70
- package/dist/esm/plugins/analyze/templates.js +22 -0
- package/dist/esm/{analyze → plugins/analyze}/utils.js +13 -135
- package/dist/esm/plugins/deploy/dependencies/index.js +69 -94
- package/dist/esm/plugins/deploy/dependencies/utils.js +3 -4
- package/dist/esm/plugins/deploy/platforms/netlify.js +8 -10
- package/dist/esm/plugins/deploy/platforms/node.js +8 -14
- package/dist/esm/plugins/deploy/platforms/vercel.js +8 -10
- package/dist/esm/{initialize → plugins/initialize}/index.js +1 -1
- package/dist/esm/plugins/serverBuild.js +13 -6
- package/dist/esm/utils/createServer.js +2 -2
- package/dist/esm/utils/loadPlugins.js +64 -0
- package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +2 -1
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +2 -2
- package/dist/esm-node/commands/build.js +2 -0
- package/dist/esm-node/commands/deploy.js +2 -2
- package/dist/esm-node/commands/dev.js +11 -7
- package/dist/esm-node/commands/index.js +92 -3
- package/dist/esm-node/commands/serve.js +10 -6
- package/dist/esm-node/hooks.js +5 -0
- package/dist/esm-node/index.js +12 -79
- package/dist/esm-node/plugins/analyze/constants.js +24 -0
- package/dist/esm-node/{analyze → plugins/analyze}/generateCode.js +14 -87
- package/dist/esm-node/{analyze → plugins/analyze}/getBundleEntry.js +11 -20
- package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +75 -0
- package/dist/esm-node/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
- package/dist/esm-node/{analyze → plugins/analyze}/index.js +10 -25
- package/dist/esm-node/plugins/analyze/templates.js +75 -0
- package/dist/esm-node/{analyze → plugins/analyze}/utils.js +13 -52
- package/dist/esm-node/plugins/deploy/dependencies/index.js +18 -27
- package/dist/esm-node/plugins/deploy/dependencies/utils.js +1 -2
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +6 -10
- package/dist/esm-node/plugins/deploy/platforms/node.js +6 -14
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +6 -10
- package/dist/esm-node/{initialize → plugins/initialize}/index.js +1 -1
- package/dist/esm-node/plugins/serverBuild.js +11 -5
- package/dist/esm-node/utils/createServer.js +2 -2
- package/dist/esm-node/utils/loadPlugins.js +21 -0
- package/dist/types/builder/builder-webpack/createCopyPattern.d.ts +2 -2
- package/dist/types/commands/index.d.ts +10 -3
- package/dist/types/config/initialize/inits.d.ts +1 -1
- package/dist/types/exports/server.d.ts +4 -0
- package/dist/types/index.d.ts +2 -5
- package/dist/types/plugins/analyze/constants.d.ts +9 -0
- package/dist/types/{analyze → plugins/analyze}/generateCode.d.ts +1 -1
- package/dist/types/plugins/analyze/getBundleEntry.d.ts +4 -0
- package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +5 -0
- package/dist/types/{analyze → plugins/analyze}/getHtmlTemplate.d.ts +1 -1
- package/dist/types/{analyze → plugins/analyze}/getServerRoutes.d.ts +1 -1
- package/dist/types/{analyze → plugins/analyze}/index.d.ts +1 -1
- package/dist/types/plugins/analyze/templates.d.ts +19 -0
- package/dist/types/{analyze → plugins/analyze}/utils.d.ts +4 -6
- package/dist/types/plugins/deploy/dependencies/index.d.ts +1 -9
- package/dist/types/plugins/deploy/dependencies/utils.d.ts +1 -7
- package/dist/types/{initialize → plugins/initialize}/index.d.ts +1 -1
- package/dist/types/types/hooks.d.ts +11 -1
- package/dist/types/utils/loadPlugins.d.ts +5 -0
- package/package.json +22 -30
- package/dist/cjs/analyze/constants.js +0 -122
- package/dist/cjs/analyze/getClientRoutes/getRoutes.js +0 -197
- package/dist/cjs/analyze/getClientRoutes/getRoutesLegacy.js +0 -195
- package/dist/cjs/analyze/getClientRoutes/index.js +0 -31
- package/dist/cjs/analyze/getClientRoutes/utils.js +0 -59
- package/dist/cjs/analyze/makeLegalIdentifier.js +0 -37
- package/dist/cjs/analyze/nestedRoutes.js +0 -295
- package/dist/cjs/analyze/templates.js +0 -444
- package/dist/cjs/plugins/deploy/exports.js +0 -28
- package/dist/esm/analyze/constants.js +0 -76
- package/dist/esm/analyze/getBundleEntry.js +0 -75
- package/dist/esm/analyze/getClientRoutes/getRoutes.js +0 -185
- package/dist/esm/analyze/getClientRoutes/getRoutesLegacy.js +0 -183
- package/dist/esm/analyze/getClientRoutes/index.js +0 -6
- package/dist/esm/analyze/getClientRoutes/utils.js +0 -28
- package/dist/esm/analyze/getFileSystemEntry.js +0 -113
- package/dist/esm/analyze/makeLegalIdentifier.js +0 -15
- package/dist/esm/analyze/nestedRoutes.js +0 -398
- package/dist/esm/analyze/templates.js +0 -435
- package/dist/esm/plugins/deploy/exports.js +0 -4
- package/dist/esm/utils/getServerInternalPlugins.js +0 -40
- package/dist/esm-node/analyze/constants.js +0 -76
- package/dist/esm-node/analyze/getClientRoutes/getRoutes.js +0 -163
- package/dist/esm-node/analyze/getClientRoutes/getRoutesLegacy.js +0 -161
- package/dist/esm-node/analyze/getClientRoutes/index.js +0 -6
- package/dist/esm-node/analyze/getClientRoutes/utils.js +0 -22
- package/dist/esm-node/analyze/getFileSystemEntry.js +0 -89
- package/dist/esm-node/analyze/makeLegalIdentifier.js +0 -13
- package/dist/esm-node/analyze/nestedRoutes.js +0 -259
- package/dist/esm-node/analyze/templates.js +0 -405
- package/dist/esm-node/plugins/deploy/exports.js +0 -4
- package/dist/esm-node/utils/getServerInternalPlugins.js +0 -15
- package/dist/js/modern/analyze/constants.js +0 -15
- package/dist/js/modern/analyze/generateCode.js +0 -179
- package/dist/js/modern/analyze/getBundleEntry.js +0 -75
- package/dist/js/modern/analyze/getClientRoutes.js +0 -219
- package/dist/js/modern/analyze/getFileSystemEntry.js +0 -74
- package/dist/js/modern/analyze/getHtmlTemplate.js +0 -82
- package/dist/js/modern/analyze/getServerRoutes.js +0 -192
- package/dist/js/modern/analyze/index.js +0 -148
- package/dist/js/modern/analyze/isDefaultExportFunction.js +0 -32
- package/dist/js/modern/analyze/makeLegalIdentifier.js +0 -16
- package/dist/js/modern/analyze/templates.js +0 -88
- package/dist/js/modern/analyze/utils.js +0 -92
- package/dist/js/modern/commands/build.js +0 -154
- package/dist/js/modern/commands/deploy.js +0 -5
- package/dist/js/modern/commands/dev.js +0 -95
- package/dist/js/modern/commands/index.js +0 -3
- package/dist/js/modern/commands/inspect.js +0 -69
- package/dist/js/modern/commands/start.js +0 -31
- package/dist/js/modern/exports/server.js +0 -1
- package/dist/js/modern/hooks.js +0 -21
- package/dist/js/modern/index.js +0 -109
- package/dist/js/modern/locale/en.js +0 -35
- package/dist/js/modern/locale/index.js +0 -9
- package/dist/js/modern/locale/zh.js +0 -35
- package/dist/js/modern/utils/config.js +0 -78
- package/dist/js/modern/utils/createCompiler.js +0 -61
- package/dist/js/modern/utils/createServer.js +0 -18
- package/dist/js/modern/utils/getSpecifiedEntries.js +0 -36
- package/dist/js/modern/utils/language.js +0 -5
- package/dist/js/modern/utils/printInstructions.js +0 -11
- package/dist/js/modern/utils/routes.js +0 -15
- package/dist/js/modern/utils/types.js +0 -0
- package/dist/js/node/analyze/constants.js +0 -36
- package/dist/js/node/analyze/generateCode.js +0 -208
- package/dist/js/node/analyze/getBundleEntry.js +0 -89
- package/dist/js/node/analyze/getClientRoutes.js +0 -241
- package/dist/js/node/analyze/getFileSystemEntry.js +0 -90
- package/dist/js/node/analyze/getHtmlTemplate.js +0 -106
- package/dist/js/node/analyze/getServerRoutes.js +0 -208
- package/dist/js/node/analyze/index.js +0 -178
- package/dist/js/node/analyze/isDefaultExportFunction.js +0 -50
- package/dist/js/node/analyze/makeLegalIdentifier.js +0 -24
- package/dist/js/node/analyze/templates.js +0 -106
- package/dist/js/node/analyze/utils.js +0 -113
- package/dist/js/node/commands/build.js +0 -174
- package/dist/js/node/commands/deploy.js +0 -14
- package/dist/js/node/commands/dev.js +0 -120
- package/dist/js/node/commands/index.js +0 -44
- package/dist/js/node/commands/inspect.js +0 -98
- package/dist/js/node/commands/start.js +0 -47
- package/dist/js/node/exports/server.js +0 -13
- package/dist/js/node/hooks.js +0 -39
- package/dist/js/node/index.js +0 -141
- package/dist/js/node/locale/en.js +0 -42
- package/dist/js/node/locale/index.js +0 -20
- package/dist/js/node/locale/zh.js +0 -42
- package/dist/js/node/utils/config.js +0 -103
- package/dist/js/node/utils/createCompiler.js +0 -81
- package/dist/js/node/utils/createServer.js +0 -35
- package/dist/js/node/utils/getSpecifiedEntries.js +0 -46
- package/dist/js/node/utils/language.js +0 -13
- package/dist/js/node/utils/printInstructions.js +0 -22
- package/dist/js/node/utils/routes.js +0 -25
- package/dist/js/node/utils/types.js +0 -0
- package/dist/types/analyze/constants.d.ts +0 -42
- package/dist/types/analyze/getBundleEntry.d.ts +0 -3
- package/dist/types/analyze/getClientRoutes/getRoutes.d.ts +0 -8
- package/dist/types/analyze/getClientRoutes/getRoutesLegacy.d.ts +0 -9
- package/dist/types/analyze/getClientRoutes/index.d.ts +0 -2
- package/dist/types/analyze/getClientRoutes/utils.d.ts +0 -5
- package/dist/types/analyze/getFileSystemEntry.d.ts +0 -4
- package/dist/types/analyze/makeLegalIdentifier.d.ts +0 -1
- package/dist/types/analyze/nestedRoutes.d.ts +0 -7
- package/dist/types/analyze/templates.d.ts +0 -30
- package/dist/types/plugins/deploy/exports.d.ts +0 -1
- package/dist/types/utils/getServerInternalPlugins.d.ts +0 -2
- /package/dist/cjs/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
- /package/dist/cjs/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
- /package/dist/esm/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
- /package/dist/esm/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
- /package/dist/esm-node/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
- /package/dist/esm-node/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
- /package/dist/types/{analyze → plugins/analyze}/isDefaultExportFunction.d.ts +0 -0
@@ -36,9 +36,19 @@ var import_utils = require("@modern-js/utils");
|
|
36
36
|
var import_pkg_types = require("pkg-types");
|
37
37
|
var import_mlly = require("mlly");
|
38
38
|
var import_utils2 = require("./utils");
|
39
|
-
const handleDependencies = async (
|
39
|
+
const handleDependencies = async (appDir, serverRootDir, include, entryFilter) => {
|
40
40
|
const base = "/";
|
41
41
|
const entryFiles = await (0, import_utils2.findEntryFiles)(serverRootDir, entryFilter);
|
42
|
+
const includeEntries = include.map((item) => {
|
43
|
+
if ((0, import_node_path.isAbsolute)(item)) {
|
44
|
+
return item;
|
45
|
+
}
|
46
|
+
try {
|
47
|
+
return require.resolve(item);
|
48
|
+
} catch (error) {
|
49
|
+
}
|
50
|
+
return item;
|
51
|
+
});
|
42
52
|
const fileTrace = await (0, import_utils2.traceFiles)(entryFiles.concat(includeEntries), serverRootDir, base);
|
43
53
|
const currentProjectModules = import_node_path.default.join(appDir, "node_modules");
|
44
54
|
const tracedFiles = Object.fromEntries(await Promise.all([
|
@@ -133,17 +143,9 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, entry
|
|
133
143
|
}
|
134
144
|
tracedPackage.versions[pkgJSON.version] = tracedPackageVersion;
|
135
145
|
}
|
146
|
+
tracedFile.path.startsWith(tracedFile.pkgPath) && tracedPackageVersion.path === tracedFile.pkgPath && tracedPackageVersion.files.push(tracedFile.path);
|
136
147
|
tracedFile.pkgName = pkgName;
|
137
148
|
tracedFile.pkgVersion = pkgJSON.version;
|
138
|
-
const shouldCopyWholePackage = copyWholePackage === null || copyWholePackage === void 0 ? void 0 : copyWholePackage(pkgName);
|
139
|
-
if (tracedFile.path.startsWith(tracedFile.pkgPath) && tracedPackageVersion.path === tracedFile.pkgPath) {
|
140
|
-
if (shouldCopyWholePackage) {
|
141
|
-
const allFiles = await (0, import_utils2.readDirRecursive)(tracedFile.pkgPath);
|
142
|
-
tracedPackageVersion.files.push(...allFiles);
|
143
|
-
} else {
|
144
|
-
tracedPackageVersion.files.push(tracedFile.path);
|
145
|
-
}
|
146
|
-
}
|
147
149
|
}
|
148
150
|
const multiVersionPkgs = {};
|
149
151
|
const singleVersionPackages = [];
|
@@ -161,11 +163,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, entry
|
|
161
163
|
await Promise.all(singleVersionPackages.map((pkgName) => {
|
162
164
|
const pkg = tracedPackages[pkgName];
|
163
165
|
const version = Object.keys(pkg.versions)[0];
|
164
|
-
return (0, import_utils2.writePackage)(
|
165
|
-
pkg,
|
166
|
-
version,
|
167
|
-
projectDir: serverRootDir
|
168
|
-
});
|
166
|
+
return (0, import_utils2.writePackage)(pkg, version, serverRootDir);
|
169
167
|
}));
|
170
168
|
const projectPkgJson = await (0, import_pkg_types.readPackageJSON)(serverRootDir).catch(() => ({}));
|
171
169
|
for (const [pkgName, pkgVersions] of Object.entries(multiVersionPkgs)) {
|
@@ -192,12 +190,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, entry
|
|
192
190
|
for (const [version, parentPkgs] of versionEntires) {
|
193
191
|
const pkg = tracedPackages[pkgName];
|
194
192
|
const pkgDestPath = `.modernjs/${pkgName}@${version}/node_modules/${pkgName}`;
|
195
|
-
await (0, import_utils2.writePackage)(
|
196
|
-
pkg,
|
197
|
-
version,
|
198
|
-
projectDir: serverRootDir,
|
199
|
-
_pkgPath: pkgDestPath
|
200
|
-
});
|
193
|
+
await (0, import_utils2.writePackage)(pkg, version, serverRootDir, pkgDestPath);
|
201
194
|
await (0, import_utils2.linkPackage)(pkgDestPath, `${pkgName}`, serverRootDir);
|
202
195
|
for (const parentPkg of parentPkgs) {
|
203
196
|
const parentPkgName = parentPkg.replace(/@[^@]+$/, "");
|
@@ -206,7 +199,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, entry
|
|
206
199
|
}
|
207
200
|
}
|
208
201
|
const outputPkgPath = import_node_path.default.join(serverRootDir, "package.json");
|
209
|
-
|
202
|
+
await import_utils.fs.writeJSON(outputPkgPath, {
|
210
203
|
name: `${projectPkgJson.name || "modernjs-project"}-prod`,
|
211
204
|
version: projectPkgJson.version || "0.0.0",
|
212
205
|
private: true,
|
@@ -216,9 +209,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, entry
|
|
216
209
|
Object.keys(pkg.versions)[0]
|
217
210
|
])
|
218
211
|
].sort(([a], [b]) => a.localeCompare(b)))
|
219
|
-
};
|
220
|
-
const finalPkgJson = (modifyPackageJson === null || modifyPackageJson === void 0 ? void 0 : modifyPackageJson(newPkgJson)) || newPkgJson;
|
221
|
-
await import_utils.fs.writeJSON(outputPkgPath, finalPkgJson);
|
212
|
+
});
|
222
213
|
};
|
223
214
|
// Annotate the CommonJS export names for ESM import in node:
|
224
215
|
0 && (module.exports = {
|
@@ -50,8 +50,7 @@ function applyPublicCondition(pkg) {
|
|
50
50
|
pkg.exports = pkg === null || pkg === void 0 ? void 0 : (_pkg_publishConfig1 = pkg.publishConfig) === null || _pkg_publishConfig1 === void 0 ? void 0 : _pkg_publishConfig1.exports;
|
51
51
|
}
|
52
52
|
}
|
53
|
-
const writePackage = async (
|
54
|
-
const { pkg, version, projectDir, _pkgPath } = options;
|
53
|
+
const writePackage = async (pkg, version, projectDir, _pkgPath) => {
|
55
54
|
const pkgPath = _pkgPath || pkg.name;
|
56
55
|
for (const src of pkg.versions[version].files) {
|
57
56
|
if (src.includes("node_modules")) {
|
@@ -50,8 +50,8 @@ async function cleanDistDirectory(dir) {
|
|
50
50
|
}
|
51
51
|
}
|
52
52
|
const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
|
53
|
-
const { appDirectory, distDirectory,
|
54
|
-
const plugins = (
|
53
|
+
const { appDirectory, distDirectory, entrypoints, serverPlugins } = appContext;
|
54
|
+
const plugins = serverPlugins.map((plugin) => plugin.name);
|
55
55
|
const netlifyOutput = import_node_path.default.join(appDirectory, ".netlify");
|
56
56
|
const funcsDirectory = import_node_path.default.join(netlifyOutput, "functions");
|
57
57
|
const entryFilePath = import_node_path.default.join(funcsDirectory, "index.js");
|
@@ -124,13 +124,9 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
|
|
124
124
|
if (!needModernServer) {
|
125
125
|
return;
|
126
126
|
}
|
127
|
-
await (0, import_dependencies.handleDependencies)(
|
128
|
-
|
129
|
-
|
130
|
-
includeEntries: [
|
131
|
-
require.resolve("@modern-js/prod-server")
|
132
|
-
]
|
133
|
-
});
|
127
|
+
await (0, import_dependencies.handleDependencies)(appDirectory, funcsDirectory, [
|
128
|
+
"@modern-js/prod-server"
|
129
|
+
]);
|
134
130
|
}
|
135
131
|
};
|
136
132
|
};
|
@@ -36,8 +36,8 @@ 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,
|
40
|
-
const plugins = (
|
39
|
+
const { appDirectory, distDirectory, serverPlugins } = appContext;
|
40
|
+
const plugins = serverPlugins.map((plugin) => plugin.name);
|
41
41
|
const outputDirectory = import_node_path.default.join(appDirectory, ".output");
|
42
42
|
const staticDirectory = import_node_path.default.join(outputDirectory, "static");
|
43
43
|
const entryFilePath = import_node_path.default.join(outputDirectory, "index.js");
|
@@ -78,17 +78,9 @@ const createNodePreset = (appContext, config) => {
|
|
78
78
|
const filter = (filePath) => {
|
79
79
|
return !filePath.startsWith(staticDirectory);
|
80
80
|
};
|
81
|
-
await (0, import_dependencies.handleDependencies)(
|
82
|
-
|
83
|
-
|
84
|
-
includeEntries: [
|
85
|
-
require.resolve("@modern-js/prod-server")
|
86
|
-
],
|
87
|
-
entryFilter: filter,
|
88
|
-
copyWholePackage: (pkgName) => {
|
89
|
-
return pkgName === "koa";
|
90
|
-
}
|
91
|
-
});
|
81
|
+
await (0, import_dependencies.handleDependencies)(appDirectory, outputDirectory, [
|
82
|
+
"@modern-js/prod-server"
|
83
|
+
], filter);
|
92
84
|
}
|
93
85
|
};
|
94
86
|
};
|
@@ -37,8 +37,8 @@ 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,
|
41
|
-
const plugins = (
|
40
|
+
const { appDirectory, distDirectory, entrypoints, serverPlugins } = appContext;
|
41
|
+
const plugins = serverPlugins.map((plugin) => plugin.name);
|
42
42
|
const vercelOutput = import_node_path.default.join(appDirectory, ".vercel");
|
43
43
|
const outputDirectory = import_node_path.default.join(vercelOutput, "output");
|
44
44
|
const funcsDirectory = import_node_path.default.join(outputDirectory, "functions", "index.func");
|
@@ -136,13 +136,9 @@ const createVercelPreset = (appContext, modernConfig, needModernServer) => {
|
|
136
136
|
if (!needModernServer) {
|
137
137
|
return;
|
138
138
|
}
|
139
|
-
await (0, import_dependencies.handleDependencies)(
|
140
|
-
|
141
|
-
|
142
|
-
includeEntries: [
|
143
|
-
require.resolve("@modern-js/prod-server")
|
144
|
-
]
|
145
|
-
});
|
139
|
+
await (0, import_dependencies.handleDependencies)(appDirectory, funcsDirectory, [
|
140
|
+
"@modern-js/prod-server"
|
141
|
+
]);
|
146
142
|
}
|
147
143
|
};
|
148
144
|
};
|
@@ -22,7 +22,7 @@ __export(initialize_exports, {
|
|
22
22
|
});
|
23
23
|
module.exports = __toCommonJS(initialize_exports);
|
24
24
|
var import_utils = require("@modern-js/utils");
|
25
|
-
var import_config = require("
|
25
|
+
var import_config = require("../../config");
|
26
26
|
var initialize_default = ({ bundler }) => ({
|
27
27
|
name: "@modern-js/plugin-initialize",
|
28
28
|
post: [
|
@@ -37,8 +37,14 @@ var import_utils = require("@modern-js/utils");
|
|
37
37
|
var import_server_utils = require("@modern-js/server-utils");
|
38
38
|
const TS_CONFIG_FILENAME = "tsconfig.json";
|
39
39
|
function checkHasCache(appDir) {
|
40
|
-
const tsFilepath = import_path.default.resolve(appDir,
|
41
|
-
const jsfilepath = import_path.default.resolve(appDir,
|
40
|
+
const tsFilepath = import_path.default.resolve(appDir, import_utils.SERVER_DIR, "cache.ts");
|
41
|
+
const jsfilepath = import_path.default.resolve(appDir, import_utils.SERVER_DIR, "cache.js");
|
42
|
+
return import_fs.default.existsSync(tsFilepath) || import_fs.default.existsSync(jsfilepath);
|
43
|
+
}
|
44
|
+
function checkHasConfig(appDir, metaName = "modern-js") {
|
45
|
+
const meta = (0, import_utils.getMeta)(metaName);
|
46
|
+
const tsFilepath = import_path.default.resolve(appDir, import_utils.SERVER_DIR, `${meta}.server.ts`);
|
47
|
+
const jsfilepath = import_path.default.resolve(appDir, import_utils.SERVER_DIR, `${meta}.server.js`);
|
42
48
|
return import_fs.default.existsSync(tsFilepath) || import_fs.default.existsSync(jsfilepath);
|
43
49
|
}
|
44
50
|
var serverBuild_default = () => ({
|
@@ -46,8 +52,8 @@ var serverBuild_default = () => ({
|
|
46
52
|
setup(api) {
|
47
53
|
return {
|
48
54
|
async afterBuild() {
|
49
|
-
const { appDirectory, distDirectory } = api.useAppContext();
|
50
|
-
if (!checkHasCache(appDirectory)) {
|
55
|
+
const { appDirectory, distDirectory, metaName } = api.useAppContext();
|
56
|
+
if (!checkHasCache(appDirectory) && !checkHasConfig(appDirectory, metaName)) {
|
51
57
|
return;
|
52
58
|
}
|
53
59
|
const modernConfig = api.useResolvedConfigContext();
|
@@ -41,7 +41,7 @@ const createServer = async (options) => {
|
|
41
41
|
if (server) {
|
42
42
|
server.close();
|
43
43
|
}
|
44
|
-
server = await (0, import_server.createDevServer)(options, import_prod_server.
|
44
|
+
server = await (0, import_server.createDevServer)(options, import_prod_server.applyPlugins);
|
45
45
|
return server;
|
46
46
|
};
|
47
47
|
// Annotate the CommonJS export names for ESM import in node:
|
@@ -16,24 +16,31 @@ var __copyProps = (to, from, except, desc) => {
|
|
16
16
|
return to;
|
17
17
|
};
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
-
var
|
20
|
-
__export(
|
21
|
-
|
19
|
+
var loadPlugins_exports = {};
|
20
|
+
__export(loadPlugins_exports, {
|
21
|
+
getServerPlugins: () => getServerPlugins,
|
22
|
+
loadServerPlugins: () => loadServerPlugins
|
22
23
|
});
|
23
|
-
module.exports = __toCommonJS(
|
24
|
-
|
25
|
-
|
26
|
-
const
|
24
|
+
module.exports = __toCommonJS(loadPlugins_exports);
|
25
|
+
var import_prod_server = require("@modern-js/prod-server");
|
26
|
+
async function getServerPlugins(api) {
|
27
|
+
const runner = api.useHookRunners();
|
28
|
+
const { plugins } = await runner._internalServerPlugins({
|
27
29
|
plugins: []
|
28
30
|
});
|
29
|
-
const serverInternalPlugins = serverPlugins.reduce((result, plugin) => Object.assign(result, plugin), {});
|
30
31
|
api.setAppContext({
|
31
32
|
...api.useAppContext(),
|
32
|
-
|
33
|
+
serverPlugins: plugins
|
33
34
|
});
|
34
|
-
return
|
35
|
+
return plugins;
|
36
|
+
}
|
37
|
+
async function loadServerPlugins(api, appDirectory) {
|
38
|
+
const plugins = await getServerPlugins(api);
|
39
|
+
const instances = (0, import_prod_server.loadServerPlugins)(plugins, appDirectory);
|
40
|
+
return instances;
|
35
41
|
}
|
36
42
|
// Annotate the CommonJS export names for ESM import in node:
|
37
43
|
0 && (module.exports = {
|
38
|
-
|
44
|
+
getServerPlugins,
|
45
|
+
loadServerPlugins
|
39
46
|
});
|
@@ -2,10 +2,13 @@ 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 _ts_generator } from "@swc/helpers/_/_ts_generator";
|
5
|
-
import { isHtmlDisabled
|
5
|
+
import { isHtmlDisabled } from "@rsbuild/shared";
|
6
6
|
import { MAIN_ENTRY_NAME, getEntryOptions, removeTailSlash } from "@modern-js/utils";
|
7
7
|
import { template as lodashTemplate } from "@modern-js/utils/lodash";
|
8
8
|
import { BottomTemplatePlugin } from "../bundlerPlugins";
|
9
|
+
var createVirtualModule = function(content) {
|
10
|
+
return "data:text/javascript,".concat(content);
|
11
|
+
};
|
9
12
|
var builderPluginAdapterHtml = function(options) {
|
10
13
|
return {
|
11
14
|
name: "builder-plugin-adapter-modern-html",
|
@@ -5,7 +5,7 @@ import { isHtmlDisabled } from "@rsbuild/shared";
|
|
5
5
|
import { mergeRsbuildConfig } from "@rsbuild/core";
|
6
6
|
import { fs, isUseSSRBundle } from "@modern-js/utils";
|
7
7
|
import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins";
|
8
|
-
import { getServerCombinedModueFile } from "../../../analyze/utils";
|
8
|
+
import { getServerCombinedModueFile } from "../../../plugins/analyze/utils";
|
9
9
|
var builderPluginAdapterSSR = function(options) {
|
10
10
|
return {
|
11
11
|
name: "builder-plugin-adapter-modern-ssr",
|
@@ -180,7 +180,7 @@ function applyFilterEntriesBySSRConfig(param) {
|
|
180
180
|
}
|
181
181
|
var _ref = serverConfig || {}, ssr = _ref.ssr, ssrByEntries = _ref.ssrByEntries;
|
182
182
|
entryNames.forEach(function(name) {
|
183
|
-
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]))) {
|
183
|
+
if (!ssgEntries.includes(name) && !name.includes("server-loaders") && (ssr && (ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]) === false || !ssr && !(ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]))) {
|
184
184
|
chain.entryPoints.delete(name);
|
185
185
|
}
|
186
186
|
});
|
@@ -4,6 +4,7 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
4
4
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
5
5
|
import { ResolvedConfigContext } from "@modern-js/core";
|
6
6
|
import { logger } from "@modern-js/utils";
|
7
|
+
import { loadServerPlugins } from "../utils/loadPlugins";
|
7
8
|
import { generateRoutes } from "../utils/routes";
|
8
9
|
import { buildServerConfig } from "../utils/config";
|
9
10
|
import { registerCompiler } from "../utils/register";
|
@@ -21,15 +22,21 @@ var build = function() {
|
|
21
22
|
hookRunners = api.useHookRunners();
|
22
23
|
return [
|
23
24
|
4,
|
24
|
-
|
25
|
+
loadServerPlugins(api, appContext.appDirectory)
|
25
26
|
];
|
26
27
|
case 1:
|
28
|
+
_state.sent();
|
29
|
+
return [
|
30
|
+
4,
|
31
|
+
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)
|
32
|
+
];
|
33
|
+
case 2:
|
27
34
|
_state.sent();
|
28
35
|
apiOnly = appContext.apiOnly;
|
29
36
|
if (!apiOnly)
|
30
37
|
return [
|
31
38
|
3,
|
32
|
-
|
39
|
+
7
|
33
40
|
];
|
34
41
|
appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverConfigFile = appContext.serverConfigFile;
|
35
42
|
return [
|
@@ -39,7 +46,7 @@ var build = function() {
|
|
39
46
|
bundlerConfigs: void 0
|
40
47
|
})
|
41
48
|
];
|
42
|
-
case
|
49
|
+
case 3:
|
43
50
|
_state.sent();
|
44
51
|
return [
|
45
52
|
4,
|
@@ -49,13 +56,13 @@ var build = function() {
|
|
49
56
|
configFile: serverConfigFile
|
50
57
|
})
|
51
58
|
];
|
52
|
-
case
|
59
|
+
case 4:
|
53
60
|
_state.sent();
|
54
61
|
return [
|
55
62
|
4,
|
56
63
|
generateRoutes(appContext)
|
57
64
|
];
|
58
|
-
case
|
65
|
+
case 5:
|
59
66
|
_state.sent();
|
60
67
|
return [
|
61
68
|
4,
|
@@ -64,12 +71,12 @@ var build = function() {
|
|
64
71
|
stats: void 0
|
65
72
|
})
|
66
73
|
];
|
67
|
-
case
|
74
|
+
case 6:
|
68
75
|
_state.sent();
|
69
76
|
return [
|
70
77
|
2
|
71
78
|
];
|
72
|
-
case
|
79
|
+
case 7:
|
73
80
|
resolvedConfig = _object_spread_props(_object_spread({}, resolvedConfig), {
|
74
81
|
cliOptions: options
|
75
82
|
});
|
@@ -83,7 +90,7 @@ var build = function() {
|
|
83
90
|
configFile: serverConfigFile1
|
84
91
|
})
|
85
92
|
];
|
86
|
-
case
|
93
|
+
case 8:
|
87
94
|
_state.sent();
|
88
95
|
logger.info("Starting production build...");
|
89
96
|
if (!appContext.builder) {
|
@@ -93,7 +100,7 @@ var build = function() {
|
|
93
100
|
4,
|
94
101
|
appContext.builder.build()
|
95
102
|
];
|
96
|
-
case
|
103
|
+
case 9:
|
97
104
|
_state.sent();
|
98
105
|
return [
|
99
106
|
2
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
3
|
-
import {
|
3
|
+
import { getServerPlugins } from "../utils/loadPlugins";
|
4
4
|
var deploy = function() {
|
5
5
|
var _ref = _async_to_generator(function(api, options) {
|
6
6
|
var hookRunners;
|
@@ -10,7 +10,7 @@ var deploy = function() {
|
|
10
10
|
hookRunners = api.useHookRunners();
|
11
11
|
return [
|
12
12
|
4,
|
13
|
-
|
13
|
+
getServerPlugins(api)
|
14
14
|
];
|
15
15
|
case 1:
|
16
16
|
_state.sent();
|
package/dist/esm/commands/dev.js
CHANGED
@@ -2,19 +2,20 @@ 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 _ts_generator } from "@swc/helpers/_/_ts_generator";
|
5
|
+
import path from "node:path";
|
5
6
|
import { ResolvedConfigContext } from "@modern-js/core";
|
6
|
-
import { DEFAULT_DEV_HOST } from "@modern-js/utils";
|
7
|
+
import { DEFAULT_DEV_HOST, SERVER_DIR, getMeta } from "@modern-js/utils";
|
7
8
|
import { createDevServer } from "@modern-js/server";
|
8
|
-
import {
|
9
|
+
import { applyPlugins } from "@modern-js/prod-server";
|
10
|
+
import { loadServerPlugins } from "../utils/loadPlugins";
|
9
11
|
import { registerCompiler } from "../utils/register";
|
10
12
|
import { printInstructions } from "../utils/printInstructions";
|
11
13
|
import { setServer } from "../utils/createServer";
|
12
14
|
import { generateRoutes } from "../utils/routes";
|
13
15
|
import { buildServerConfig } from "../utils/config";
|
14
|
-
import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
|
15
16
|
var dev = function() {
|
16
17
|
var _ref = _async_to_generator(function(api, options) {
|
17
|
-
var devServerOptions, _normalizedConfig_source, _normalizedConfig_tools, normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverRoutes,
|
18
|
+
var devServerOptions, _normalizedConfig_source, _normalizedConfig_tools, normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverRoutes, meta, serverConfigPath, pluginInstances, serverOptions, _normalizedConfig_dev, app, host, server;
|
18
19
|
var _arguments = arguments;
|
19
20
|
return _ts_generator(this, function(_state) {
|
20
21
|
switch (_state.label) {
|
@@ -48,6 +49,8 @@ var dev = function() {
|
|
48
49
|
];
|
49
50
|
case 2:
|
50
51
|
_state.sent();
|
52
|
+
meta = getMeta(metaName);
|
53
|
+
serverConfigPath = path.resolve(appDirectory, SERVER_DIR, "".concat(meta, ".server"));
|
51
54
|
return [
|
52
55
|
4,
|
53
56
|
hookRunners.beforeDev()
|
@@ -65,10 +68,10 @@ var dev = function() {
|
|
65
68
|
_state.sent();
|
66
69
|
return [
|
67
70
|
4,
|
68
|
-
|
71
|
+
loadServerPlugins(api, appDirectory)
|
69
72
|
];
|
70
73
|
case 5:
|
71
|
-
|
74
|
+
pluginInstances = _state.sent();
|
72
75
|
serverOptions = _object_spread({
|
73
76
|
metaName,
|
74
77
|
dev: _object_spread({
|
@@ -82,11 +85,12 @@ var dev = function() {
|
|
82
85
|
lambdaDirectory: appContext.lambdaDirectory,
|
83
86
|
sharedDirectory: appContext.sharedDirectory
|
84
87
|
},
|
88
|
+
serverConfigPath,
|
85
89
|
routes: serverRoutes,
|
86
90
|
pwd: appDirectory,
|
87
91
|
config: normalizedConfig,
|
88
92
|
serverConfigFile,
|
89
|
-
|
93
|
+
plugins: pluginInstances
|
90
94
|
}, devServerOptions);
|
91
95
|
if (!apiOnly)
|
92
96
|
return [
|
@@ -95,7 +99,7 @@ var dev = function() {
|
|
95
99
|
];
|
96
100
|
return [
|
97
101
|
4,
|
98
|
-
createDevServer(serverOptions,
|
102
|
+
createDevServer(serverOptions, applyPlugins)
|
99
103
|
];
|
100
104
|
case 6:
|
101
105
|
app = _state.sent();
|
@@ -115,7 +119,7 @@ var dev = function() {
|
|
115
119
|
4,
|
116
120
|
appContext.builder.startDevServer({
|
117
121
|
serverOptions,
|
118
|
-
|
122
|
+
applyPlugins
|
119
123
|
})
|
120
124
|
];
|
121
125
|
case 8:
|