@modern-js/app-tools 2.49.1 → 2.49.3-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/shared/builderPlugins/adapterSSR.js +1 -1
- package/dist/cjs/config/default.js +11 -1
- package/dist/cjs/index.js +4 -2
- package/dist/cjs/locale/en.js +2 -1
- package/dist/cjs/locale/zh.js +2 -1
- package/dist/cjs/plugins/deploy/dependencies.js +256 -0
- package/dist/cjs/plugins/deploy/entrys/netlify.js +95 -0
- package/dist/cjs/plugins/deploy/entrys/node.js +88 -0
- package/dist/cjs/plugins/deploy/entrys/vercel.js +94 -0
- package/dist/cjs/plugins/deploy/index.js +186 -0
- package/dist/cjs/plugins/deploy/utils.js +150 -0
- package/dist/cjs/utils/register.js +1 -1
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +2 -2
- package/dist/esm/config/default.js +11 -1
- package/dist/esm/index.js +4 -2
- package/dist/esm/locale/en.js +2 -1
- package/dist/esm/locale/zh.js +2 -1
- package/dist/esm/plugins/deploy/dependencies.js +725 -0
- package/dist/esm/plugins/deploy/entrys/netlify.js +41 -0
- package/dist/esm/plugins/deploy/entrys/node.js +39 -0
- package/dist/esm/plugins/deploy/entrys/vercel.js +40 -0
- package/dist/esm/plugins/deploy/index.js +297 -0
- package/dist/esm/plugins/deploy/utils.js +244 -0
- package/dist/esm/utils/register.js +1 -1
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +2 -2
- package/dist/esm-node/config/default.js +11 -1
- package/dist/esm-node/index.js +4 -2
- package/dist/esm-node/locale/en.js +2 -1
- package/dist/esm-node/locale/zh.js +2 -1
- package/dist/esm-node/plugins/deploy/dependencies.js +222 -0
- package/dist/esm-node/plugins/deploy/entrys/netlify.js +71 -0
- package/dist/esm-node/plugins/deploy/entrys/node.js +64 -0
- package/dist/esm-node/plugins/deploy/entrys/vercel.js +70 -0
- package/dist/esm-node/plugins/deploy/index.js +156 -0
- package/dist/esm-node/plugins/deploy/utils.js +109 -0
- package/dist/esm-node/utils/register.js +1 -1
- package/dist/types/locale/en.d.ts +1 -0
- package/dist/types/locale/index.d.ts +2 -0
- package/dist/types/locale/zh.d.ts +1 -0
- package/dist/types/plugins/deploy/dependencies.d.ts +1 -0
- package/dist/types/plugins/deploy/entrys/netlify.d.ts +5 -0
- package/dist/types/plugins/deploy/entrys/node.d.ts +5 -0
- package/dist/types/plugins/deploy/entrys/vercel.d.ts +5 -0
- package/dist/types/plugins/deploy/index.d.ts +4 -0
- package/dist/types/plugins/deploy/utils.d.ts +27 -0
- package/dist/types/utils/types.d.ts +1 -0
- package/package.json +26 -22
@@ -57,7 +57,7 @@ const builderPluginAdapterSSR = (options) => ({
|
|
57
57
|
const builderConfig = api.getNormalizedConfig();
|
58
58
|
const { normalizedConfig: normalizedConfig2 } = options;
|
59
59
|
applyRouterPlugin(chain, "route-plugin", options, HtmlBundlerPlugin);
|
60
|
-
if ((0, import_utils.
|
60
|
+
if ((0, import_utils.isUseSSRBundle)(normalizedConfig2)) {
|
61
61
|
await applySSRLoaderEntry(chain, options, isServer);
|
62
62
|
applySSRDataLoader(chain, options);
|
63
63
|
}
|
@@ -94,7 +94,17 @@ function createDefaultConfig(appContext) {
|
|
94
94
|
server,
|
95
95
|
dev,
|
96
96
|
html,
|
97
|
-
tools: {
|
97
|
+
tools: {
|
98
|
+
tsChecker: {
|
99
|
+
issue: {
|
100
|
+
exclude: [
|
101
|
+
{
|
102
|
+
file: "**/api/lambda/**/*"
|
103
|
+
}
|
104
|
+
]
|
105
|
+
}
|
106
|
+
}
|
107
|
+
},
|
98
108
|
plugins: [],
|
99
109
|
builderPlugins: [],
|
100
110
|
runtime: {},
|
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();
|
@@ -152,7 +154,7 @@ const appTools = (options = {
|
|
152
154
|
const { start } = await Promise.resolve().then(() => __toESM(require("./commands/serve")));
|
153
155
|
await start(api);
|
154
156
|
});
|
155
|
-
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 (options2) => {
|
157
|
+
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)).option("-o --output <path>", import_locale.i18n.t(import_locale.localeKeys.command.deploy.output)).description(import_locale.i18n.t(import_locale.localeKeys.command.deploy.describe)).action(async (options2) => {
|
156
158
|
if (!options2.skipBuild) {
|
157
159
|
const { build } = await Promise.resolve().then(() => __toESM(require("./commands/build")));
|
158
160
|
await build(api);
|
package/dist/cjs/locale/en.js
CHANGED
@@ -44,7 +44,8 @@ const EN_LOCALE = {
|
|
44
44
|
describe: "preview the production build locally"
|
45
45
|
},
|
46
46
|
deploy: {
|
47
|
-
describe: "deploy the application"
|
47
|
+
describe: "deploy the application",
|
48
|
+
output: "output path"
|
48
49
|
},
|
49
50
|
new: {
|
50
51
|
describe: "enable optional features or add a new entry",
|
package/dist/cjs/locale/zh.js
CHANGED
@@ -0,0 +1,256 @@
|
|
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_nft = require("@vercel/nft");
|
36
|
+
var import_utils = require("@modern-js/utils");
|
37
|
+
var import_pkg_types = require("pkg-types");
|
38
|
+
var import_mlly = require("mlly");
|
39
|
+
var import_utils2 = require("./utils");
|
40
|
+
const readDirRecursive = async (dir) => {
|
41
|
+
const files = await import_utils.fs.readdir(dir, {
|
42
|
+
withFileTypes: true
|
43
|
+
});
|
44
|
+
const filesAndDirs = await Promise.all(files.map(async (file) => {
|
45
|
+
const resPath = import_node_path.default.resolve(dir, file.name);
|
46
|
+
return file.isDirectory() ? readDirRecursive(resPath) : resPath;
|
47
|
+
}));
|
48
|
+
return filesAndDirs.flat();
|
49
|
+
};
|
50
|
+
async function isFile(file) {
|
51
|
+
try {
|
52
|
+
const stat = await import_utils.fs.stat(file);
|
53
|
+
return stat.isFile();
|
54
|
+
} catch (error) {
|
55
|
+
if (error.code === "ENOENT") {
|
56
|
+
return false;
|
57
|
+
}
|
58
|
+
throw error;
|
59
|
+
}
|
60
|
+
}
|
61
|
+
const findEntryFiles = async (rootDir) => {
|
62
|
+
const files = await readDirRecursive(rootDir);
|
63
|
+
return files;
|
64
|
+
};
|
65
|
+
const handleDependencies = async (appDir, serverRootDir, include) => {
|
66
|
+
const base = "/";
|
67
|
+
const entryFiles = await findEntryFiles(serverRootDir);
|
68
|
+
const includeEntries = include.map((item) => {
|
69
|
+
if ((0, import_node_path.isAbsolute)(item)) {
|
70
|
+
return item;
|
71
|
+
}
|
72
|
+
try {
|
73
|
+
return require.resolve(item);
|
74
|
+
} catch (error) {
|
75
|
+
}
|
76
|
+
return item;
|
77
|
+
});
|
78
|
+
const _fileTrace = await (0, import_nft.nodeFileTrace)(entryFiles.concat(includeEntries), {
|
79
|
+
base,
|
80
|
+
processCwd: serverRootDir,
|
81
|
+
resolve: async (id, parent, job, isCjs) => {
|
82
|
+
if (id.startsWith("@modern-js/prod-server")) {
|
83
|
+
return require.resolve(id, {
|
84
|
+
paths: [
|
85
|
+
require.resolve("@modern-js/app-tools")
|
86
|
+
]
|
87
|
+
});
|
88
|
+
} else {
|
89
|
+
return (0, import_nft.resolve)(id, parent, job, isCjs);
|
90
|
+
}
|
91
|
+
}
|
92
|
+
});
|
93
|
+
const currentProjectModules = import_node_path.default.join(appDir, "node_modules");
|
94
|
+
const _resolveTracedPath = (p) => import_utils.fs.realpath(import_node_path.default.resolve(base, p));
|
95
|
+
const tracedFiles = Object.fromEntries(await Promise.all([
|
96
|
+
..._fileTrace.reasons.entries()
|
97
|
+
].map(async ([_path, reasons]) => {
|
98
|
+
if (reasons.ignored) {
|
99
|
+
return;
|
100
|
+
}
|
101
|
+
const filePath = await _resolveTracedPath(_path);
|
102
|
+
if (filePath.startsWith(serverRootDir) || filePath.startsWith(appDir) && !filePath.startsWith(currentProjectModules)) {
|
103
|
+
return;
|
104
|
+
}
|
105
|
+
if (!await isFile(filePath)) {
|
106
|
+
return;
|
107
|
+
}
|
108
|
+
let baseDir;
|
109
|
+
let pkgName;
|
110
|
+
let subpath;
|
111
|
+
let pkgPath;
|
112
|
+
if (filePath.includes("node_modules")) {
|
113
|
+
const parsed = (0, import_mlly.parseNodeModulePath)(filePath);
|
114
|
+
baseDir = parsed.dir;
|
115
|
+
pkgName = parsed.name;
|
116
|
+
subpath = parsed.subpath;
|
117
|
+
pkgPath = import_node_path.default.join(baseDir, pkgName);
|
118
|
+
} else {
|
119
|
+
const MODERN_UTILS_PATH = "packages/toolkit/utils";
|
120
|
+
const MODERN_UTILS_PATH_REGEX = new RegExp(`(.*${MODERN_UTILS_PATH})`);
|
121
|
+
const match = filePath.match(MODERN_UTILS_PATH_REGEX);
|
122
|
+
const packageJsonPath = match ? import_node_path.default.join(match[0], "package.json") : await (0, import_utils.pkgUp)({
|
123
|
+
cwd: import_node_path.default.dirname(filePath)
|
124
|
+
});
|
125
|
+
if (packageJsonPath) {
|
126
|
+
const packageJson = await import_utils.fs.readJSON(packageJsonPath);
|
127
|
+
pkgPath = baseDir = import_node_path.default.dirname(packageJsonPath);
|
128
|
+
subpath = import_node_path.default.relative(baseDir, filePath);
|
129
|
+
pkgName = packageJson.name;
|
130
|
+
}
|
131
|
+
}
|
132
|
+
if (!baseDir) {
|
133
|
+
return;
|
134
|
+
}
|
135
|
+
const parents = await Promise.all([
|
136
|
+
...reasons.parents
|
137
|
+
].map((p) => _resolveTracedPath(p)));
|
138
|
+
const tracedFile = {
|
139
|
+
path: filePath,
|
140
|
+
parents,
|
141
|
+
subpath,
|
142
|
+
pkgName,
|
143
|
+
pkgPath
|
144
|
+
};
|
145
|
+
return [
|
146
|
+
filePath,
|
147
|
+
tracedFile
|
148
|
+
];
|
149
|
+
})).then((r) => r.filter(Boolean)));
|
150
|
+
const tracedPackages = {};
|
151
|
+
for (const tracedFile of Object.values(tracedFiles)) {
|
152
|
+
const { pkgName } = tracedFile;
|
153
|
+
let tracedPackage = tracedPackages[pkgName];
|
154
|
+
let pkgJSON = await (0, import_pkg_types.readPackageJSON)(tracedFile.pkgPath, {
|
155
|
+
cache: true
|
156
|
+
}).catch(() => {
|
157
|
+
});
|
158
|
+
if (!pkgJSON) {
|
159
|
+
pkgJSON = {
|
160
|
+
name: pkgName,
|
161
|
+
version: "0.0.0"
|
162
|
+
};
|
163
|
+
}
|
164
|
+
if (!tracedPackage) {
|
165
|
+
tracedPackage = {
|
166
|
+
name: pkgName,
|
167
|
+
versions: {}
|
168
|
+
};
|
169
|
+
tracedPackages[pkgName] = tracedPackage;
|
170
|
+
}
|
171
|
+
let tracedPackageVersion = tracedPackage.versions[pkgJSON.version];
|
172
|
+
if (!tracedPackageVersion) {
|
173
|
+
tracedPackageVersion = {
|
174
|
+
path: tracedFile.pkgPath,
|
175
|
+
files: [],
|
176
|
+
pkgJSON
|
177
|
+
};
|
178
|
+
tracedPackage.versions[pkgJSON.version] = tracedPackageVersion;
|
179
|
+
}
|
180
|
+
tracedFile.path.startsWith(tracedFile.pkgPath) && tracedPackageVersion.path === tracedFile.pkgPath && tracedPackageVersion.files.push(tracedFile.path);
|
181
|
+
tracedFile.pkgName = pkgName;
|
182
|
+
tracedFile.pkgVersion = pkgJSON.version;
|
183
|
+
}
|
184
|
+
const findPackageParents = (pkg, version) => {
|
185
|
+
const versionFiles = pkg.versions[version].files.map((path2) => tracedFiles[path2]);
|
186
|
+
const parentPkgs = [
|
187
|
+
...new Set(versionFiles.flatMap((file) => file.parents.map((parentPath) => {
|
188
|
+
const parentFile = tracedFiles[parentPath];
|
189
|
+
if (parentFile.pkgName === pkg.name) {
|
190
|
+
return null;
|
191
|
+
}
|
192
|
+
return `${parentFile.pkgName}@${parentFile.pkgVersion}`;
|
193
|
+
}).filter(Boolean)))
|
194
|
+
];
|
195
|
+
return parentPkgs;
|
196
|
+
};
|
197
|
+
const multiVersionPkgs = {};
|
198
|
+
const singleVersionPackages = [];
|
199
|
+
for (const tracedPackage of Object.values(tracedPackages)) {
|
200
|
+
const versions = Object.keys(tracedPackage.versions);
|
201
|
+
if (versions.length === 1) {
|
202
|
+
singleVersionPackages.push(tracedPackage.name);
|
203
|
+
continue;
|
204
|
+
}
|
205
|
+
multiVersionPkgs[tracedPackage.name] = {};
|
206
|
+
for (const version of versions) {
|
207
|
+
multiVersionPkgs[tracedPackage.name][version] = findPackageParents(tracedPackage, version);
|
208
|
+
}
|
209
|
+
}
|
210
|
+
await Promise.all(singleVersionPackages.map((pkgName) => {
|
211
|
+
const pkg = tracedPackages[pkgName];
|
212
|
+
const version = Object.keys(pkg.versions)[0];
|
213
|
+
return (0, import_utils2.writePackage)(pkg, version, serverRootDir);
|
214
|
+
}));
|
215
|
+
console.log("multiVersionPkgs111111111", multiVersionPkgs);
|
216
|
+
for (const [pkgName, pkgVersions] of Object.entries(multiVersionPkgs)) {
|
217
|
+
const versionEntires = Object.entries(pkgVersions).sort(([v1, p1], [v2, p2]) => {
|
218
|
+
if (p1.length === 0) {
|
219
|
+
return -1;
|
220
|
+
}
|
221
|
+
if (p2.length === 0) {
|
222
|
+
return 1;
|
223
|
+
}
|
224
|
+
return import_utils.semver.lt(v1, v2, {
|
225
|
+
loose: true
|
226
|
+
}) ? 1 : -1;
|
227
|
+
});
|
228
|
+
for (const [version, parentPkgs] of versionEntires) {
|
229
|
+
const pkg = tracedPackages[pkgName];
|
230
|
+
const pkgDestPath = `.modernjs/${pkgName}@${version}/node_modules/${pkgName}`;
|
231
|
+
await (0, import_utils2.writePackage)(pkg, version, serverRootDir, pkgDestPath);
|
232
|
+
await (0, import_utils2.linkPackage)(pkgDestPath, `${pkgName}`, serverRootDir);
|
233
|
+
for (const parentPkg of parentPkgs) {
|
234
|
+
const parentPkgName = parentPkg.replace(/@[^@]+$/, "");
|
235
|
+
await (multiVersionPkgs[parentPkgName] ? (0, import_utils2.linkPackage)(pkgDestPath, `.modernjs/${parentPkg}/node_modules/${pkgName}`, serverRootDir) : (0, import_utils2.linkPackage)(pkgDestPath, `${parentPkgName}/node_modules/${pkgName}`, serverRootDir));
|
236
|
+
}
|
237
|
+
}
|
238
|
+
}
|
239
|
+
const projectPkg = await (0, import_pkg_types.readPackageJSON)(serverRootDir).catch(() => ({}));
|
240
|
+
const outputPkgPath = import_node_path.default.join(serverRootDir, "package.json");
|
241
|
+
await import_utils.fs.writeJSON(outputPkgPath, {
|
242
|
+
name: `${projectPkg.name || "modernjs-project"}-prod`,
|
243
|
+
version: projectPkg.version || "0.0.0",
|
244
|
+
private: true,
|
245
|
+
dependencies: Object.fromEntries([
|
246
|
+
...Object.values(tracedPackages).map((pkg) => [
|
247
|
+
pkg.name,
|
248
|
+
Object.keys(pkg.versions)[0]
|
249
|
+
])
|
250
|
+
].sort(([a], [b]) => a.localeCompare(b)))
|
251
|
+
});
|
252
|
+
};
|
253
|
+
// Annotate the CommonJS export names for ESM import in node:
|
254
|
+
0 && (module.exports = {
|
255
|
+
handleDependencies
|
256
|
+
});
|
@@ -0,0 +1,95 @@
|
|
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 netlify_exports = {};
|
20
|
+
__export(netlify_exports, {
|
21
|
+
genNetlifyEntry: () => genNetlifyEntry
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(netlify_exports);
|
24
|
+
var import_utils = require("@modern-js/utils");
|
25
|
+
var import_utils2 = require("../utils");
|
26
|
+
function genNetlifyEntry({ config, plugins, appContext } = {}) {
|
27
|
+
const defaultConfig = {
|
28
|
+
server: {
|
29
|
+
port: 8080
|
30
|
+
},
|
31
|
+
output: {
|
32
|
+
path: "."
|
33
|
+
}
|
34
|
+
};
|
35
|
+
return `
|
36
|
+
|
37
|
+
const fs = require('node:fs/promises');
|
38
|
+
const path = require('node:path');
|
39
|
+
const { createNetlifyFunction } = require('@modern-js/prod-server/netlify');
|
40
|
+
${(0, import_utils2.genPluginImportsCode)(plugins || [])}
|
41
|
+
|
42
|
+
let requestHandler = null;
|
43
|
+
|
44
|
+
if(!process.env.NODE_ENV){
|
45
|
+
process.env.NODE_ENV = 'production';
|
46
|
+
}
|
47
|
+
|
48
|
+
async function createHandler() {
|
49
|
+
try {
|
50
|
+
let routes = [];
|
51
|
+
const routeFilepath = path.join(__dirname, "${import_utils.ROUTE_SPEC_FILE}");
|
52
|
+
try {
|
53
|
+
await fs.access(routeFilepath);
|
54
|
+
const content = await fs.readFile(routeFilepath, "utf-8");
|
55
|
+
const routeSpec = JSON.parse(content);
|
56
|
+
routes = routeSpec.routes;
|
57
|
+
} catch (error) {
|
58
|
+
console.warn('route.json not found, continuing with empty routes.');
|
59
|
+
}
|
60
|
+
|
61
|
+
const prodServerOptions = {
|
62
|
+
pwd: __dirname,
|
63
|
+
routes,
|
64
|
+
config: ${JSON.stringify(config || defaultConfig)},
|
65
|
+
serverConfigFile: '${import_utils.DEFAULT_SERVER_CONFIG}',
|
66
|
+
plugins: ${(0, import_utils2.getPluginsCode)(plugins || [])},
|
67
|
+
appContext: ${appContext ? (0, import_utils2.severAppContextTemplate)(appContext) : "undefined"},
|
68
|
+
disableCustomHook: true
|
69
|
+
}
|
70
|
+
|
71
|
+
requestHandler = await createNetlifyFunction(prodServerOptions)
|
72
|
+
|
73
|
+
return requestHandler
|
74
|
+
} catch(error) {
|
75
|
+
console.error(error);
|
76
|
+
process.exit(1);
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
createHandler();
|
81
|
+
|
82
|
+
const handleRequest = async(request, context) => {
|
83
|
+
if(typeof requestHandler !== 'function'){
|
84
|
+
await createHandler();
|
85
|
+
}
|
86
|
+
return requestHandler(request, context);
|
87
|
+
}
|
88
|
+
|
89
|
+
export default handleRequest;
|
90
|
+
`;
|
91
|
+
}
|
92
|
+
// Annotate the CommonJS export names for ESM import in node:
|
93
|
+
0 && (module.exports = {
|
94
|
+
genNetlifyEntry
|
95
|
+
});
|
@@ -0,0 +1,88 @@
|
|
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 node_exports = {};
|
20
|
+
__export(node_exports, {
|
21
|
+
genNodeEntry: () => genNodeEntry
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(node_exports);
|
24
|
+
var import_utils = require("@modern-js/utils");
|
25
|
+
var import_utils2 = require("../utils");
|
26
|
+
function genNodeEntry({ config, plugins, appContext } = {}) {
|
27
|
+
const defaultConfig = {
|
28
|
+
server: {
|
29
|
+
port: 8080
|
30
|
+
},
|
31
|
+
output: {
|
32
|
+
path: "."
|
33
|
+
}
|
34
|
+
};
|
35
|
+
return `
|
36
|
+
|
37
|
+
const fs = require('node:fs/promises');
|
38
|
+
const path = require('node:path');
|
39
|
+
const { createProdServer } = require('@modern-js/prod-server');
|
40
|
+
${(0, import_utils2.genPluginImportsCode)(plugins || [])}
|
41
|
+
|
42
|
+
if(!process.env.NODE_ENV){
|
43
|
+
process.env.NODE_ENV = 'production';
|
44
|
+
}
|
45
|
+
|
46
|
+
async function main() {
|
47
|
+
try {
|
48
|
+
let routes = [];
|
49
|
+
const routeFilepath = path.join(__dirname, "${import_utils.ROUTE_SPEC_FILE}");
|
50
|
+
try {
|
51
|
+
await fs.access(routeFilepath);
|
52
|
+
const content = await fs.readFile(routeFilepath, "utf-8");
|
53
|
+
const routeSpec = JSON.parse(content);
|
54
|
+
routes = routeSpec.routes;
|
55
|
+
} catch (error) {
|
56
|
+
console.warn('route.json not found, continuing with empty routes.');
|
57
|
+
}
|
58
|
+
|
59
|
+
const prodServerOptions = {
|
60
|
+
pwd: __dirname,
|
61
|
+
routes,
|
62
|
+
config: ${JSON.stringify(config || defaultConfig)},
|
63
|
+
serverConfigFile: '${import_utils.DEFAULT_SERVER_CONFIG}',
|
64
|
+
plugins: ${(0, import_utils2.getPluginsCode)(plugins || [])},
|
65
|
+
appContext: ${appContext ? (0, import_utils2.severAppContextTemplate)(appContext) : "undefined"},
|
66
|
+
disableCustomHook: true
|
67
|
+
}
|
68
|
+
|
69
|
+
const app = await createProdServer(prodServerOptions)
|
70
|
+
|
71
|
+
const port = process.env.PORT || 3000;
|
72
|
+
|
73
|
+
app.listen(port, () => {
|
74
|
+
console.log('\\x1b[32mServer is listening on port', port, '\\x1b[0m');
|
75
|
+
});
|
76
|
+
} catch(error) {
|
77
|
+
console.error(error);
|
78
|
+
process.exit(1);
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
main();
|
83
|
+
`;
|
84
|
+
}
|
85
|
+
// Annotate the CommonJS export names for ESM import in node:
|
86
|
+
0 && (module.exports = {
|
87
|
+
genNodeEntry
|
88
|
+
});
|
@@ -0,0 +1,94 @@
|
|
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_exports = {};
|
20
|
+
__export(vercel_exports, {
|
21
|
+
genVercelEntry: () => genVercelEntry
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(vercel_exports);
|
24
|
+
var import_utils = require("@modern-js/utils");
|
25
|
+
var import_utils2 = require("../utils");
|
26
|
+
function genVercelEntry({ config, plugins, appContext } = {}) {
|
27
|
+
const defaultConfig = {
|
28
|
+
server: {
|
29
|
+
port: 8080
|
30
|
+
},
|
31
|
+
output: {
|
32
|
+
path: "."
|
33
|
+
}
|
34
|
+
};
|
35
|
+
return `
|
36
|
+
|
37
|
+
const fs = require('node:fs/promises');
|
38
|
+
const path = require('node:path');
|
39
|
+
const { createProdServer } = require('@modern-js/prod-server');
|
40
|
+
${(0, import_utils2.genPluginImportsCode)(plugins || [])}
|
41
|
+
|
42
|
+
if(!process.env.NODE_ENV){
|
43
|
+
process.env.NODE_ENV = 'production';
|
44
|
+
}
|
45
|
+
|
46
|
+
let requestHandler = null;
|
47
|
+
async function createHandler() {
|
48
|
+
try {
|
49
|
+
let routes = [];
|
50
|
+
const routeFilepath = path.join(__dirname, "${import_utils.ROUTE_SPEC_FILE}");
|
51
|
+
try {
|
52
|
+
await fs.access(routeFilepath);
|
53
|
+
const content = await fs.readFile(routeFilepath, "utf-8");
|
54
|
+
const routeSpec = JSON.parse(content);
|
55
|
+
routes = routeSpec.routes;
|
56
|
+
} catch (error) {
|
57
|
+
console.warn('route.json not found, continuing with empty routes.');
|
58
|
+
}
|
59
|
+
|
60
|
+
const prodServerOptions = {
|
61
|
+
pwd: __dirname,
|
62
|
+
routes,
|
63
|
+
config: ${JSON.stringify(config || defaultConfig)},
|
64
|
+
serverConfigFile: '${import_utils.DEFAULT_SERVER_CONFIG}',
|
65
|
+
plugins: ${(0, import_utils2.getPluginsCode)(plugins || [])},
|
66
|
+
appContext: ${appContext ? (0, import_utils2.severAppContextTemplate)(appContext) : "undefined"},
|
67
|
+
disableCustomHook: true
|
68
|
+
}
|
69
|
+
|
70
|
+
const app = await createProdServer(prodServerOptions)
|
71
|
+
|
72
|
+
requestHandler = app.getRequestListener();
|
73
|
+
|
74
|
+
return requestHandler;
|
75
|
+
} catch(error) {
|
76
|
+
console.error(error);
|
77
|
+
process.exit(1);
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
createHandler();
|
82
|
+
|
83
|
+
module.exports = async(req, res) => {
|
84
|
+
if(typeof requestHandler !== 'function'){
|
85
|
+
await createHandler();
|
86
|
+
}
|
87
|
+
return requestHandler(req, res);
|
88
|
+
}
|
89
|
+
`;
|
90
|
+
}
|
91
|
+
// Annotate the CommonJS export names for ESM import in node:
|
92
|
+
0 && (module.exports = {
|
93
|
+
genVercelEntry
|
94
|
+
});
|