@modern-js/app-tools 2.50.0 → 2.51.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/analyze/getServerRoutes.js +4 -3
- package/dist/cjs/commands/deploy.js +1 -0
- package/dist/cjs/hooks.js +1 -0
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/plugins/deploy/dependencies/index.js +217 -0
- package/dist/cjs/plugins/deploy/dependencies/utils.js +165 -0
- package/dist/cjs/plugins/deploy/index.js +64 -0
- package/dist/cjs/plugins/deploy/platforms/netlify.js +136 -0
- package/dist/cjs/plugins/deploy/platforms/netlifyEntry.js +60 -0
- package/dist/cjs/plugins/deploy/platforms/node.js +90 -0
- package/dist/cjs/plugins/deploy/platforms/nodeEntry.js +44 -0
- package/dist/cjs/plugins/deploy/platforms/platform.js +16 -0
- package/dist/cjs/plugins/deploy/platforms/vercel.js +148 -0
- package/dist/cjs/plugins/deploy/platforms/vercelEntry.js +60 -0
- package/dist/cjs/plugins/deploy/utils.js +81 -0
- package/dist/cjs/utils/routes.js +7 -2
- package/dist/esm/analyze/getServerRoutes.js +5 -4
- package/dist/esm/commands/deploy.js +7 -1
- package/dist/esm/hooks.js +1 -0
- package/dist/esm/index.js +3 -1
- package/dist/esm/plugins/deploy/dependencies/index.js +580 -0
- package/dist/esm/plugins/deploy/dependencies/utils.js +407 -0
- package/dist/esm/plugins/deploy/index.js +135 -0
- package/dist/esm/plugins/deploy/platforms/netlify.js +291 -0
- package/dist/esm/plugins/deploy/platforms/netlifyEntry.js +202 -0
- package/dist/esm/plugins/deploy/platforms/node.js +124 -0
- package/dist/esm/plugins/deploy/platforms/nodeEntry.js +107 -0
- package/dist/esm/plugins/deploy/platforms/platform.js +0 -0
- package/dist/esm/plugins/deploy/platforms/vercel.js +225 -0
- package/dist/esm/plugins/deploy/platforms/vercelEntry.js +202 -0
- package/dist/esm/plugins/deploy/utils.js +47 -0
- package/dist/esm/utils/routes.js +6 -2
- package/dist/esm-node/analyze/getServerRoutes.js +5 -4
- package/dist/esm-node/commands/deploy.js +1 -0
- package/dist/esm-node/hooks.js +1 -0
- package/dist/esm-node/index.js +3 -1
- package/dist/esm-node/plugins/deploy/dependencies/index.js +183 -0
- package/dist/esm-node/plugins/deploy/dependencies/utils.js +124 -0
- package/dist/esm-node/plugins/deploy/index.js +44 -0
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +102 -0
- package/dist/esm-node/plugins/deploy/platforms/netlifyEntry.js +68 -0
- package/dist/esm-node/plugins/deploy/platforms/node.js +56 -0
- package/dist/esm-node/plugins/deploy/platforms/nodeEntry.js +43 -0
- package/dist/esm-node/plugins/deploy/platforms/platform.js +0 -0
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +114 -0
- package/dist/esm-node/plugins/deploy/platforms/vercelEntry.js +68 -0
- package/dist/esm-node/plugins/deploy/utils.js +44 -0
- package/dist/esm-node/utils/routes.js +6 -2
- package/dist/types/defineConfig.d.ts +1 -1
- package/dist/types/plugins/deploy/dependencies/index.d.ts +1 -0
- package/dist/types/plugins/deploy/dependencies/utils.d.ts +31 -0
- package/dist/types/plugins/deploy/index.d.ts +4 -0
- package/dist/types/plugins/deploy/platforms/netlify.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/netlifyEntry.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/node.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/nodeEntry.d.ts +1 -0
- package/dist/types/plugins/deploy/platforms/platform.d.ts +10 -0
- package/dist/types/plugins/deploy/platforms/vercel.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/vercelEntry.d.ts +2 -0
- package/dist/types/plugins/deploy/utils.d.ts +20 -0
- package/dist/types/types/hooks.d.ts +1 -0
- package/dist/types/utils/routes.d.ts +3 -3
- package/package.json +26 -22
@@ -34,6 +34,7 @@ module.exports = __toCommonJS(getServerRoutes_exports);
|
|
34
34
|
var import_path = __toESM(require("path"));
|
35
35
|
var import_fs = __toESM(require("fs"));
|
36
36
|
var import_utils = require("@modern-js/utils");
|
37
|
+
var import_routes = require("../utils/routes");
|
37
38
|
var import_utils2 = require("./utils");
|
38
39
|
const applyBaseUrl = (baseUrl, routes) => {
|
39
40
|
if (baseUrl) {
|
@@ -106,14 +107,14 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
|
|
106
107
|
const { packageName } = appContext;
|
107
108
|
const workerSSR = deploy === null || deploy === void 0 ? void 0 : (_deploy_worker = deploy.worker) === null || _deploy_worker === void 0 ? void 0 : _deploy_worker.ssr;
|
108
109
|
let htmlRoutes = entrypoints.reduce((previous, { entryName }) => {
|
109
|
-
const
|
110
|
-
const entryOptions = (0, import_utils.getEntryOptions)(entryName,
|
110
|
+
const isMain = (0, import_routes.isMainEntry)(entryName, mainEntryName);
|
111
|
+
const entryOptions = (0, import_utils.getEntryOptions)(entryName, isMain, ssr, ssrByEntries, packageName);
|
111
112
|
const isSSR = Boolean(entryOptions);
|
112
113
|
const isWorker = Boolean(workerSSR);
|
113
114
|
const isStream = typeof entryOptions === "object" && (entryOptions.mode === "stream" || Boolean(entryOptions.preload));
|
114
115
|
const { resHeaders } = (routes === null || routes === void 0 ? void 0 : routes[entryName]) || {};
|
115
116
|
let route = {
|
116
|
-
urlPath: `/${
|
117
|
+
urlPath: `/${isMain ? "" : entryName}`,
|
117
118
|
entryName,
|
118
119
|
entryPath: (0, import_utils.removeLeadingSlash)(import_path.default.posix.normalize(`${htmlPath}/${entryName}${disableHtmlFolder ? ".html" : "/index.html"}`)),
|
119
120
|
isSPA: true,
|
@@ -26,6 +26,7 @@ const deploy = async (api, options) => {
|
|
26
26
|
const hookRunners = api.useHookRunners();
|
27
27
|
await (0, import_getServerInternalPlugins.getServerInternalPlugins)(api);
|
28
28
|
await hookRunners.beforeDeploy(options);
|
29
|
+
await hookRunners.deploy(options);
|
29
30
|
await hookRunners.afterDeploy(options);
|
30
31
|
};
|
31
32
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/cjs/hooks.js
CHANGED
@@ -42,6 +42,7 @@ const hooks = {
|
|
42
42
|
beforeBuild: (0, import_plugin.createAsyncWorkflow)(),
|
43
43
|
afterBuild: (0, import_plugin.createAsyncWorkflow)(),
|
44
44
|
beforeDeploy: (0, import_plugin.createAsyncWorkflow)(),
|
45
|
+
deploy: (0, import_plugin.createAsyncWorkflow)(),
|
45
46
|
afterDeploy: (0, import_plugin.createAsyncWorkflow)(),
|
46
47
|
beforeRestart: (0, import_plugin.createAsyncWorkflow)(),
|
47
48
|
registerDev: (0, import_plugin.createParallelWorkflow)(),
|
package/dist/cjs/index.js
CHANGED
@@ -47,6 +47,7 @@ var import_initialize = __toESM(require("./initialize"));
|
|
47
47
|
var import_hooks = require("./hooks");
|
48
48
|
var import_locale = require("./locale");
|
49
49
|
var import_serverBuild = __toESM(require("./plugins/serverBuild"));
|
50
|
+
var import_deploy = __toESM(require("./plugins/deploy"));
|
50
51
|
var import_restart = require("./utils/restart");
|
51
52
|
var import_generateWatchFiles = require("./utils/generateWatchFiles");
|
52
53
|
var import_core = require("@modern-js/core");
|
@@ -120,7 +121,8 @@ const appTools = (options = {
|
|
120
121
|
bundler: (options === null || options === void 0 ? void 0 : options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
|
121
122
|
}),
|
122
123
|
(0, import_serverBuild.default)(),
|
123
|
-
(0, import_plugin_lint.lintPlugin)()
|
124
|
+
(0, import_plugin_lint.lintPlugin)(),
|
125
|
+
(0, import_deploy.default)()
|
124
126
|
],
|
125
127
|
setup: (api) => {
|
126
128
|
const appContext = api.useAppContext();
|
@@ -0,0 +1,217 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
9
|
+
for (var name in all)
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
+
}
|
18
|
+
return to;
|
19
|
+
};
|
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
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
+
var dependencies_exports = {};
|
30
|
+
__export(dependencies_exports, {
|
31
|
+
handleDependencies: () => handleDependencies
|
32
|
+
});
|
33
|
+
module.exports = __toCommonJS(dependencies_exports);
|
34
|
+
var import_node_path = __toESM(require("node:path"));
|
35
|
+
var import_utils = require("@modern-js/utils");
|
36
|
+
var import_pkg_types = require("pkg-types");
|
37
|
+
var import_mlly = require("mlly");
|
38
|
+
var import_utils2 = require("./utils");
|
39
|
+
const handleDependencies = async (appDir, serverRootDir, include, entryFilter) => {
|
40
|
+
const base = "/";
|
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
|
+
});
|
52
|
+
const fileTrace = await (0, import_utils2.traceFiles)(entryFiles.concat(includeEntries), serverRootDir, base);
|
53
|
+
const currentProjectModules = import_node_path.default.join(appDir, "node_modules");
|
54
|
+
const tracedFiles = Object.fromEntries(await Promise.all([
|
55
|
+
...fileTrace.reasons.entries()
|
56
|
+
].map(async ([_path, reasons]) => {
|
57
|
+
if (reasons.ignored) {
|
58
|
+
return;
|
59
|
+
}
|
60
|
+
const filePath = await (0, import_utils2.resolveTracedPath)(base, _path);
|
61
|
+
if (filePath.startsWith(serverRootDir) || filePath.startsWith(appDir) && !filePath.startsWith(currentProjectModules)) {
|
62
|
+
return;
|
63
|
+
}
|
64
|
+
if (!await (0, import_utils2.isFile)(filePath)) {
|
65
|
+
return;
|
66
|
+
}
|
67
|
+
let baseDir;
|
68
|
+
let pkgName;
|
69
|
+
let subpath;
|
70
|
+
let pkgPath;
|
71
|
+
if (filePath.includes("node_modules")) {
|
72
|
+
const parsed = (0, import_mlly.parseNodeModulePath)(filePath);
|
73
|
+
baseDir = parsed.dir;
|
74
|
+
pkgName = parsed.name;
|
75
|
+
subpath = parsed.subpath;
|
76
|
+
pkgPath = import_node_path.default.join(baseDir, pkgName);
|
77
|
+
} else {
|
78
|
+
const MODERN_UTILS_PATH = "packages/toolkit/utils";
|
79
|
+
const MODERN_UTILS_PATH_REGEX = new RegExp(`(.*${MODERN_UTILS_PATH})`);
|
80
|
+
const match = filePath.match(MODERN_UTILS_PATH_REGEX);
|
81
|
+
const packageJsonPath = match ? import_node_path.default.join(match[0], "package.json") : await (0, import_utils.pkgUp)({
|
82
|
+
cwd: import_node_path.default.dirname(filePath)
|
83
|
+
});
|
84
|
+
if (packageJsonPath) {
|
85
|
+
const packageJson = await import_utils.fs.readJSON(packageJsonPath);
|
86
|
+
pkgPath = baseDir = import_node_path.default.dirname(packageJsonPath);
|
87
|
+
subpath = import_node_path.default.relative(baseDir, filePath);
|
88
|
+
pkgName = packageJson.name;
|
89
|
+
}
|
90
|
+
}
|
91
|
+
if (!baseDir) {
|
92
|
+
return;
|
93
|
+
}
|
94
|
+
const parents = await Promise.all([
|
95
|
+
...reasons.parents
|
96
|
+
].map((p) => (0, import_utils2.resolveTracedPath)(base, p)));
|
97
|
+
const tracedFile = {
|
98
|
+
path: filePath,
|
99
|
+
parents,
|
100
|
+
isDirectDep: parents.some((parent) => {
|
101
|
+
return parent.startsWith(appDir) && !parent.startsWith(currentProjectModules);
|
102
|
+
}),
|
103
|
+
subpath,
|
104
|
+
pkgName,
|
105
|
+
pkgPath
|
106
|
+
};
|
107
|
+
return [
|
108
|
+
filePath,
|
109
|
+
tracedFile
|
110
|
+
];
|
111
|
+
})).then((r) => r.filter(Boolean)));
|
112
|
+
const tracedPackages = {};
|
113
|
+
for (const tracedFile of Object.values(tracedFiles)) {
|
114
|
+
const { pkgName } = tracedFile;
|
115
|
+
let tracedPackage = tracedPackages[pkgName];
|
116
|
+
let pkgJSON = await (0, import_pkg_types.readPackageJSON)(tracedFile.pkgPath, {
|
117
|
+
cache: true
|
118
|
+
}).catch(() => {
|
119
|
+
});
|
120
|
+
if (!pkgJSON) {
|
121
|
+
pkgJSON = {
|
122
|
+
name: pkgName,
|
123
|
+
version: "0.0.0"
|
124
|
+
};
|
125
|
+
}
|
126
|
+
if (!tracedPackage) {
|
127
|
+
tracedPackage = {
|
128
|
+
name: pkgName,
|
129
|
+
versions: {}
|
130
|
+
};
|
131
|
+
tracedPackages[pkgName] = tracedPackage;
|
132
|
+
}
|
133
|
+
let tracedPackageVersion = tracedPackage.versions[pkgJSON.version];
|
134
|
+
if (!tracedPackageVersion) {
|
135
|
+
tracedPackageVersion = {
|
136
|
+
path: tracedFile.pkgPath,
|
137
|
+
files: [],
|
138
|
+
isDirectDep: false,
|
139
|
+
pkgJSON
|
140
|
+
};
|
141
|
+
if (tracedFile.isDirectDep) {
|
142
|
+
tracedPackageVersion.isDirectDep = tracedFile.isDirectDep;
|
143
|
+
}
|
144
|
+
tracedPackage.versions[pkgJSON.version] = tracedPackageVersion;
|
145
|
+
}
|
146
|
+
tracedFile.path.startsWith(tracedFile.pkgPath) && tracedPackageVersion.path === tracedFile.pkgPath && tracedPackageVersion.files.push(tracedFile.path);
|
147
|
+
tracedFile.pkgName = pkgName;
|
148
|
+
tracedFile.pkgVersion = pkgJSON.version;
|
149
|
+
}
|
150
|
+
const multiVersionPkgs = {};
|
151
|
+
const singleVersionPackages = [];
|
152
|
+
for (const tracedPackage of Object.values(tracedPackages)) {
|
153
|
+
const versions = Object.keys(tracedPackage.versions);
|
154
|
+
if (versions.length === 1) {
|
155
|
+
singleVersionPackages.push(tracedPackage.name);
|
156
|
+
continue;
|
157
|
+
}
|
158
|
+
multiVersionPkgs[tracedPackage.name] = {};
|
159
|
+
for (const version of versions) {
|
160
|
+
multiVersionPkgs[tracedPackage.name][version] = (0, import_utils2.findPackageParents)(tracedPackage, version, tracedFiles);
|
161
|
+
}
|
162
|
+
}
|
163
|
+
await Promise.all(singleVersionPackages.map((pkgName) => {
|
164
|
+
const pkg = tracedPackages[pkgName];
|
165
|
+
const version = Object.keys(pkg.versions)[0];
|
166
|
+
return (0, import_utils2.writePackage)(pkg, version, serverRootDir);
|
167
|
+
}));
|
168
|
+
const projectPkgJson = await (0, import_pkg_types.readPackageJSON)(serverRootDir).catch(() => ({}));
|
169
|
+
for (const [pkgName, pkgVersions] of Object.entries(multiVersionPkgs)) {
|
170
|
+
const versionEntires = Object.entries(pkgVersions).sort(([v1, p1], [v2, p2]) => {
|
171
|
+
var _tracedPackages_pkgName_versions_v1, _tracedPackages_pkgName_versions, _tracedPackages_pkgName, _tracedPackages_pkgName_versions_v2, _tracedPackages_pkgName_versions1, _tracedPackages_pkgName1;
|
172
|
+
const shouldHoist1 = (_tracedPackages_pkgName = tracedPackages[pkgName]) === null || _tracedPackages_pkgName === void 0 ? void 0 : (_tracedPackages_pkgName_versions = _tracedPackages_pkgName.versions) === null || _tracedPackages_pkgName_versions === void 0 ? void 0 : (_tracedPackages_pkgName_versions_v1 = _tracedPackages_pkgName_versions[v1]) === null || _tracedPackages_pkgName_versions_v1 === void 0 ? void 0 : _tracedPackages_pkgName_versions_v1.isDirectDep;
|
173
|
+
const shouldHoist2 = (_tracedPackages_pkgName1 = tracedPackages[pkgName]) === null || _tracedPackages_pkgName1 === void 0 ? void 0 : (_tracedPackages_pkgName_versions1 = _tracedPackages_pkgName1.versions) === null || _tracedPackages_pkgName_versions1 === void 0 ? void 0 : (_tracedPackages_pkgName_versions_v2 = _tracedPackages_pkgName_versions1[v2]) === null || _tracedPackages_pkgName_versions_v2 === void 0 ? void 0 : _tracedPackages_pkgName_versions_v2.isDirectDep;
|
174
|
+
if (shouldHoist1 && !shouldHoist2) {
|
175
|
+
return -1;
|
176
|
+
}
|
177
|
+
if (!shouldHoist1 && shouldHoist2) {
|
178
|
+
return 1;
|
179
|
+
}
|
180
|
+
if (p1.length === 0) {
|
181
|
+
return -1;
|
182
|
+
}
|
183
|
+
if (p2.length === 0) {
|
184
|
+
return 1;
|
185
|
+
}
|
186
|
+
return import_utils.semver.lt(v1, v2, {
|
187
|
+
loose: true
|
188
|
+
}) ? 1 : -1;
|
189
|
+
});
|
190
|
+
for (const [version, parentPkgs] of versionEntires) {
|
191
|
+
const pkg = tracedPackages[pkgName];
|
192
|
+
const pkgDestPath = `.modernjs/${pkgName}@${version}/node_modules/${pkgName}`;
|
193
|
+
await (0, import_utils2.writePackage)(pkg, version, serverRootDir, pkgDestPath);
|
194
|
+
await (0, import_utils2.linkPackage)(pkgDestPath, `${pkgName}`, serverRootDir);
|
195
|
+
for (const parentPkg of parentPkgs) {
|
196
|
+
const parentPkgName = parentPkg.replace(/@[^@]+$/, "");
|
197
|
+
await (multiVersionPkgs[parentPkgName] ? (0, import_utils2.linkPackage)(pkgDestPath, `.modernjs/${parentPkg}/node_modules/${pkgName}`, serverRootDir) : (0, import_utils2.linkPackage)(pkgDestPath, `${parentPkgName}/node_modules/${pkgName}`, serverRootDir));
|
198
|
+
}
|
199
|
+
}
|
200
|
+
}
|
201
|
+
const outputPkgPath = import_node_path.default.join(serverRootDir, "package.json");
|
202
|
+
await import_utils.fs.writeJSON(outputPkgPath, {
|
203
|
+
name: `${projectPkgJson.name || "modernjs-project"}-prod`,
|
204
|
+
version: projectPkgJson.version || "0.0.0",
|
205
|
+
private: true,
|
206
|
+
dependencies: Object.fromEntries([
|
207
|
+
...Object.values(tracedPackages).map((pkg) => [
|
208
|
+
pkg.name,
|
209
|
+
Object.keys(pkg.versions)[0]
|
210
|
+
])
|
211
|
+
].sort(([a], [b]) => a.localeCompare(b)))
|
212
|
+
});
|
213
|
+
};
|
214
|
+
// Annotate the CommonJS export names for ESM import in node:
|
215
|
+
0 && (module.exports = {
|
216
|
+
handleDependencies
|
217
|
+
});
|
@@ -0,0 +1,165 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
9
|
+
for (var name in all)
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
+
}
|
18
|
+
return to;
|
19
|
+
};
|
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
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
+
var utils_exports = {};
|
30
|
+
__export(utils_exports, {
|
31
|
+
findEntryFiles: () => findEntryFiles,
|
32
|
+
findPackageParents: () => findPackageParents,
|
33
|
+
isFile: () => isFile,
|
34
|
+
linkPackage: () => linkPackage,
|
35
|
+
readDirRecursive: () => readDirRecursive,
|
36
|
+
resolveTracedPath: () => resolveTracedPath,
|
37
|
+
traceFiles: () => traceFiles,
|
38
|
+
writePackage: () => writePackage
|
39
|
+
});
|
40
|
+
module.exports = __toCommonJS(utils_exports);
|
41
|
+
var import_path = __toESM(require("path"));
|
42
|
+
var import_node_os = __toESM(require("node:os"));
|
43
|
+
var import_utils = require("@modern-js/utils");
|
44
|
+
var import_mlly = require("mlly");
|
45
|
+
var import_nft = require("@vercel/nft");
|
46
|
+
function applyPublicCondition(pkg) {
|
47
|
+
var _pkg_publishConfig;
|
48
|
+
if (pkg === null || pkg === void 0 ? void 0 : (_pkg_publishConfig = pkg.publishConfig) === null || _pkg_publishConfig === void 0 ? void 0 : _pkg_publishConfig.exports) {
|
49
|
+
var _pkg_publishConfig1;
|
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
|
+
}
|
52
|
+
}
|
53
|
+
const writePackage = async (pkg, version, projectDir, _pkgPath) => {
|
54
|
+
const pkgPath = _pkgPath || pkg.name;
|
55
|
+
for (const src of pkg.versions[version].files) {
|
56
|
+
if (src.includes("node_modules")) {
|
57
|
+
const { subpath } = (0, import_mlly.parseNodeModulePath)(src);
|
58
|
+
const dest = import_path.default.join(projectDir, "node_modules", pkgPath, subpath);
|
59
|
+
const dirname = import_path.default.dirname(dest);
|
60
|
+
await import_utils.fs.ensureDir(dirname);
|
61
|
+
await import_utils.fs.copyFile(src, dest);
|
62
|
+
} else {
|
63
|
+
const subpath = import_path.default.relative(pkg.versions[version].path, src);
|
64
|
+
const dest = import_path.default.join(projectDir, "node_modules", pkgPath, subpath);
|
65
|
+
const dirname = import_path.default.dirname(dest);
|
66
|
+
await import_utils.fs.ensureDir(dirname);
|
67
|
+
await import_utils.fs.copyFile(src, dest);
|
68
|
+
}
|
69
|
+
}
|
70
|
+
const { pkgJSON } = pkg.versions[version];
|
71
|
+
applyPublicCondition(pkgJSON);
|
72
|
+
const packageJsonPath = import_path.default.join(projectDir, "node_modules", pkgPath, "package.json");
|
73
|
+
await import_utils.fs.ensureDir(import_path.default.dirname(packageJsonPath));
|
74
|
+
await import_utils.fs.writeFile(packageJsonPath, JSON.stringify(pkgJSON, null, 2));
|
75
|
+
};
|
76
|
+
const isWindows = import_node_os.default.platform() === "win32";
|
77
|
+
const linkPackage = async (from, to, projectRootDir) => {
|
78
|
+
const src = import_path.default.join(projectRootDir, "node_modules", from);
|
79
|
+
const dest = import_path.default.join(projectRootDir, "node_modules", to);
|
80
|
+
const dstStat = await import_utils.fs.lstat(dest).catch(() => null);
|
81
|
+
const exists = dstStat === null || dstStat === void 0 ? void 0 : dstStat.isSymbolicLink();
|
82
|
+
if (exists) {
|
83
|
+
return;
|
84
|
+
}
|
85
|
+
await import_utils.fs.mkdir(import_path.default.dirname(dest), {
|
86
|
+
recursive: true
|
87
|
+
});
|
88
|
+
await import_utils.fs.symlink(import_path.default.relative(import_path.default.dirname(dest), src), dest, isWindows ? "junction" : "dir").catch((error) => {
|
89
|
+
console.error("Cannot link", from, "to", to, error);
|
90
|
+
});
|
91
|
+
};
|
92
|
+
const readDirRecursive = async (dir, options = {}) => {
|
93
|
+
const { filter } = options;
|
94
|
+
const files = await import_utils.fs.readdir(dir, {
|
95
|
+
withFileTypes: true
|
96
|
+
});
|
97
|
+
const filesAndDirs = await Promise.all(files.map(async (file) => {
|
98
|
+
const resolvedPath = import_path.default.resolve(dir, file.name);
|
99
|
+
if (file.isDirectory()) {
|
100
|
+
return readDirRecursive(resolvedPath, options);
|
101
|
+
} else {
|
102
|
+
return filter && !filter(resolvedPath) ? [] : resolvedPath;
|
103
|
+
}
|
104
|
+
}));
|
105
|
+
return filesAndDirs.flat();
|
106
|
+
};
|
107
|
+
const isFile = async (file) => {
|
108
|
+
try {
|
109
|
+
const stat = await import_utils.fs.stat(file);
|
110
|
+
return stat.isFile();
|
111
|
+
} catch (error) {
|
112
|
+
if (error.code === "ENOENT") {
|
113
|
+
return false;
|
114
|
+
}
|
115
|
+
throw error;
|
116
|
+
}
|
117
|
+
};
|
118
|
+
const findEntryFiles = async (rootDir, entryFilter) => {
|
119
|
+
const files = await readDirRecursive(rootDir, {
|
120
|
+
filter: entryFilter
|
121
|
+
});
|
122
|
+
return files.filter((file) => file.endsWith(".mjs") || file.endsWith(".cjs") || file.endsWith(".js"));
|
123
|
+
};
|
124
|
+
const findPackageParents = (pkg, version, tracedFiles) => {
|
125
|
+
const versionFiles = pkg.versions[version].files.map((path2) => tracedFiles[path2]);
|
126
|
+
const parentPkgs = [
|
127
|
+
...new Set(versionFiles.flatMap((file) => file.parents.map((parentPath) => {
|
128
|
+
const parentFile = tracedFiles[parentPath];
|
129
|
+
if (!parentFile || parentFile.pkgName === pkg.name) {
|
130
|
+
return null;
|
131
|
+
}
|
132
|
+
return `${parentFile.pkgName}@${parentFile.pkgVersion}`;
|
133
|
+
}).filter(Boolean)))
|
134
|
+
];
|
135
|
+
return parentPkgs;
|
136
|
+
};
|
137
|
+
const traceFiles = async (entryFiles, serverRootDir, base = "/") => {
|
138
|
+
return await (0, import_nft.nodeFileTrace)(entryFiles, {
|
139
|
+
base,
|
140
|
+
processCwd: serverRootDir,
|
141
|
+
resolve: async (id, parent, job, isCjs) => {
|
142
|
+
if (id.startsWith("@modern-js/prod-server")) {
|
143
|
+
return require.resolve(id, {
|
144
|
+
paths: [
|
145
|
+
require.resolve("@modern-js/app-tools")
|
146
|
+
]
|
147
|
+
});
|
148
|
+
} else {
|
149
|
+
return (0, import_nft.resolve)(id, parent, job, isCjs);
|
150
|
+
}
|
151
|
+
}
|
152
|
+
});
|
153
|
+
};
|
154
|
+
const resolveTracedPath = async (base, p) => import_utils.fs.realpath(import_path.default.resolve(base, p));
|
155
|
+
// Annotate the CommonJS export names for ESM import in node:
|
156
|
+
0 && (module.exports = {
|
157
|
+
findEntryFiles,
|
158
|
+
findPackageParents,
|
159
|
+
isFile,
|
160
|
+
linkPackage,
|
161
|
+
readDirRecursive,
|
162
|
+
resolveTracedPath,
|
163
|
+
traceFiles,
|
164
|
+
writePackage
|
165
|
+
});
|
@@ -0,0 +1,64 @@
|
|
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 deploy_exports = {};
|
20
|
+
__export(deploy_exports, {
|
21
|
+
default: () => deploy_default
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(deploy_exports);
|
24
|
+
var import_std_env = require("std-env");
|
25
|
+
var import_utils = require("./utils");
|
26
|
+
var import_node = require("./platforms/node");
|
27
|
+
var import_vercel = require("./platforms/vercel");
|
28
|
+
var import_netlify = require("./platforms/netlify");
|
29
|
+
const deployPresets = {
|
30
|
+
node: import_node.createNodePreset,
|
31
|
+
vercel: import_vercel.createVercelPreset,
|
32
|
+
netlify: import_netlify.createNetlifyPreset
|
33
|
+
};
|
34
|
+
async function getDeployPreset(appContext, modernConfig, deployTarget) {
|
35
|
+
const { appDirectory, distDirectory } = appContext;
|
36
|
+
const { useSSR, useAPI, useWebServer } = (0, import_utils.getProjectUsage)(appDirectory, distDirectory);
|
37
|
+
const needModernServer = useSSR || useAPI || useWebServer;
|
38
|
+
const createPreset = deployPresets[deployTarget];
|
39
|
+
if (!createPreset) {
|
40
|
+
throw new Error(`Unknown deploy target: '${deployTarget}'. MODERNJS_DEPLOY should be 'node', 'vercel', or 'netlify'.`);
|
41
|
+
}
|
42
|
+
return createPreset(appContext, modernConfig, needModernServer);
|
43
|
+
}
|
44
|
+
var deploy_default = () => ({
|
45
|
+
name: "@modern-js/plugin-deploy",
|
46
|
+
setup: (api) => {
|
47
|
+
const deployTarget = process.env.MODERNJS_DEPLOY || import_std_env.provider || "node";
|
48
|
+
return {
|
49
|
+
async deploy() {
|
50
|
+
const appContext = api.useAppContext();
|
51
|
+
const { metaName } = appContext;
|
52
|
+
if (metaName !== "modern-js" && !process.env.MODERNJS_DEPLOY) {
|
53
|
+
return;
|
54
|
+
}
|
55
|
+
const modernConfig = api.useResolvedConfigContext();
|
56
|
+
const deployPreset = await getDeployPreset(appContext, modernConfig, deployTarget);
|
57
|
+
(deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare());
|
58
|
+
(deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput());
|
59
|
+
(deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry());
|
60
|
+
(deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end());
|
61
|
+
}
|
62
|
+
};
|
63
|
+
}
|
64
|
+
});
|
@@ -0,0 +1,136 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
9
|
+
for (var name in all)
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
+
}
|
18
|
+
return to;
|
19
|
+
};
|
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
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
+
var netlify_exports = {};
|
30
|
+
__export(netlify_exports, {
|
31
|
+
createNetlifyPreset: () => createNetlifyPreset
|
32
|
+
});
|
33
|
+
module.exports = __toCommonJS(netlify_exports);
|
34
|
+
var import_node_path = __toESM(require("node:path"));
|
35
|
+
var import_utils = require("@modern-js/utils");
|
36
|
+
var import_routes = require("../../../utils/routes");
|
37
|
+
var import_utils2 = require("../utils");
|
38
|
+
var import_dependencies = require("../dependencies");
|
39
|
+
async function cleanDistDirectory(dir) {
|
40
|
+
try {
|
41
|
+
const items = await import_utils.fs.readdir(dir);
|
42
|
+
for (const item of items) {
|
43
|
+
const fullPath = import_node_path.default.join(dir, item);
|
44
|
+
if (item !== "static" && item !== "_redirects") {
|
45
|
+
await import_utils.fs.remove(fullPath);
|
46
|
+
}
|
47
|
+
}
|
48
|
+
} catch (error) {
|
49
|
+
console.error("Error cleaning directory:", error);
|
50
|
+
}
|
51
|
+
}
|
52
|
+
const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
|
53
|
+
const { appDirectory, distDirectory, serverInternalPlugins, entrypoints } = appContext;
|
54
|
+
const plugins = (0, import_utils.getInternalPlugins)(appDirectory, serverInternalPlugins);
|
55
|
+
const netlifyOutput = import_node_path.default.join(appDirectory, ".netlify");
|
56
|
+
const funcsDirectory = import_node_path.default.join(netlifyOutput, "functions");
|
57
|
+
const entryFilePath = import_node_path.default.join(funcsDirectory, "index.js");
|
58
|
+
return {
|
59
|
+
async prepare() {
|
60
|
+
await import_utils.fs.remove(netlifyOutput);
|
61
|
+
},
|
62
|
+
async writeOutput() {
|
63
|
+
const routes = [];
|
64
|
+
const { source: { mainEntryName } } = modernConfig;
|
65
|
+
if (!needModernServer) {
|
66
|
+
entrypoints.forEach((entry) => {
|
67
|
+
const isMain = (0, import_routes.isMainEntry)(entry.entryName, mainEntryName);
|
68
|
+
routes.push({
|
69
|
+
src: `/${isMain ? "" : `${entry.entryName}/`}*`,
|
70
|
+
dest: `/html/${entry.entryName}/index.html`,
|
71
|
+
status: 200
|
72
|
+
});
|
73
|
+
});
|
74
|
+
} else {
|
75
|
+
routes.push({
|
76
|
+
src: "/*",
|
77
|
+
dest: `/.netlify/functions/index`,
|
78
|
+
status: 200
|
79
|
+
});
|
80
|
+
}
|
81
|
+
const redirectContent = routes.map((route) => {
|
82
|
+
return `${route.src} ${route.dest} ${route.status}`;
|
83
|
+
}).join("\n");
|
84
|
+
if (needModernServer) {
|
85
|
+
await import_utils.fs.ensureDir(funcsDirectory);
|
86
|
+
await import_utils.fs.copy(distDirectory, funcsDirectory, {
|
87
|
+
filter: (src) => {
|
88
|
+
const distStaticDirectory = import_node_path.default.join(distDirectory, `static`);
|
89
|
+
return !src.includes(distStaticDirectory);
|
90
|
+
}
|
91
|
+
});
|
92
|
+
}
|
93
|
+
const redirectFilePath = import_node_path.default.join(distDirectory, "_redirects");
|
94
|
+
await import_utils.fs.writeFile(redirectFilePath, redirectContent);
|
95
|
+
},
|
96
|
+
async genEntry() {
|
97
|
+
var _modernConfig_bff;
|
98
|
+
if (!needModernServer) {
|
99
|
+
return;
|
100
|
+
}
|
101
|
+
const serverConfig = {
|
102
|
+
bff: {
|
103
|
+
prefix: modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_bff = modernConfig.bff) === null || _modernConfig_bff === void 0 ? void 0 : _modernConfig_bff.prefix
|
104
|
+
},
|
105
|
+
output: {
|
106
|
+
path: "."
|
107
|
+
}
|
108
|
+
};
|
109
|
+
const pluginImportCode = (0, import_utils2.genPluginImportsCode)(plugins || []);
|
110
|
+
const dynamicProdOptions = {
|
111
|
+
config: serverConfig,
|
112
|
+
serverConfigFile: import_utils.DEFAULT_SERVER_CONFIG,
|
113
|
+
plugins
|
114
|
+
};
|
115
|
+
let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./netlifyEntry.js"))).toString();
|
116
|
+
const serverAppContext = (0, import_utils2.serverAppContenxtTemplate)(appContext);
|
117
|
+
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
|
118
|
+
await import_utils.fs.writeFile(entryFilePath, entryCode);
|
119
|
+
},
|
120
|
+
async end() {
|
121
|
+
if (process.env.NODE_ENV !== "test" && process.env.NODE_ENV !== "development") {
|
122
|
+
await cleanDistDirectory(distDirectory);
|
123
|
+
}
|
124
|
+
if (!needModernServer) {
|
125
|
+
return;
|
126
|
+
}
|
127
|
+
await (0, import_dependencies.handleDependencies)(appDirectory, funcsDirectory, [
|
128
|
+
"@modern-js/prod-server"
|
129
|
+
]);
|
130
|
+
}
|
131
|
+
};
|
132
|
+
};
|
133
|
+
// Annotate the CommonJS export names for ESM import in node:
|
134
|
+
0 && (module.exports = {
|
135
|
+
createNetlifyPreset
|
136
|
+
});
|