@modern-js/app-tools 2.49.3-alpha.9 → 2.49.4

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.
Files changed (43) hide show
  1. package/dist/cjs/analyze/getServerRoutes.js +3 -4
  2. package/dist/cjs/index.js +1 -3
  3. package/dist/cjs/utils/routes.js +2 -7
  4. package/dist/esm/analyze/getServerRoutes.js +4 -5
  5. package/dist/esm/index.js +1 -3
  6. package/dist/esm/utils/routes.js +2 -6
  7. package/dist/esm-node/analyze/getServerRoutes.js +4 -5
  8. package/dist/esm-node/index.js +1 -3
  9. package/dist/esm-node/utils/routes.js +2 -6
  10. package/dist/types/utils/routes.d.ts +3 -3
  11. package/package.json +22 -26
  12. package/dist/cjs/plugins/deploy/dependencies.js +0 -256
  13. package/dist/cjs/plugins/deploy/index.js +0 -215
  14. package/dist/cjs/plugins/deploy/platforms/netlify.js +0 -95
  15. package/dist/cjs/plugins/deploy/platforms/node.js +0 -88
  16. package/dist/cjs/plugins/deploy/platforms/platform.js +0 -16
  17. package/dist/cjs/plugins/deploy/platforms/vercel.js +0 -57
  18. package/dist/cjs/plugins/deploy/platforms/vercelEntry.js +0 -55
  19. package/dist/cjs/plugins/deploy/utils.js +0 -150
  20. package/dist/esm/plugins/deploy/dependencies.js +0 -725
  21. package/dist/esm/plugins/deploy/index.js +0 -356
  22. package/dist/esm/plugins/deploy/platforms/netlify.js +0 -41
  23. package/dist/esm/plugins/deploy/platforms/node.js +0 -39
  24. package/dist/esm/plugins/deploy/platforms/platform.js +0 -0
  25. package/dist/esm/plugins/deploy/platforms/vercel.js +0 -47
  26. package/dist/esm/plugins/deploy/platforms/vercelEntry.js +0 -197
  27. package/dist/esm/plugins/deploy/utils.js +0 -244
  28. package/dist/esm-node/plugins/deploy/dependencies.js +0 -222
  29. package/dist/esm-node/plugins/deploy/index.js +0 -185
  30. package/dist/esm-node/plugins/deploy/platforms/netlify.js +0 -71
  31. package/dist/esm-node/plugins/deploy/platforms/node.js +0 -64
  32. package/dist/esm-node/plugins/deploy/platforms/platform.js +0 -0
  33. package/dist/esm-node/plugins/deploy/platforms/vercel.js +0 -23
  34. package/dist/esm-node/plugins/deploy/platforms/vercelEntry.js +0 -63
  35. package/dist/esm-node/plugins/deploy/utils.js +0 -109
  36. package/dist/types/plugins/deploy/dependencies.d.ts +0 -1
  37. package/dist/types/plugins/deploy/index.d.ts +0 -4
  38. package/dist/types/plugins/deploy/platforms/netlify.d.ts +0 -5
  39. package/dist/types/plugins/deploy/platforms/node.d.ts +0 -5
  40. package/dist/types/plugins/deploy/platforms/platform.d.ts +0 -1
  41. package/dist/types/plugins/deploy/platforms/vercel.d.ts +0 -5
  42. package/dist/types/plugins/deploy/platforms/vercelEntry.d.ts +0 -2
  43. package/dist/types/plugins/deploy/utils.d.ts +0 -27
@@ -1,244 +0,0 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
- import path from "path";
4
- import os from "node:os";
5
- import { ROUTE_SPEC_FILE, fs as fse, isDepExists } from "@modern-js/utils";
6
- import { parseNodeModulePath } from "mlly";
7
- var severAppContextTemplate = function(serverAppContext) {
8
- return "{\n sharedDirectory: ".concat(serverAppContext.sharedDirectory, ",\n apiDirectory: ").concat(serverAppContext.apiDirectory, ",\n lambdaDirectory: ").concat(serverAppContext.lambdaDirectory, ",\n }");
9
- };
10
- var getPluginsCode = function(plugins) {
11
- return "[".concat(plugins.map(function(_, index) {
12
- return "plugin_".concat(index, "()");
13
- }).join(","), "]");
14
- };
15
- var genPluginImportsCode = function(plugins) {
16
- return plugins.map(function(plugin, index) {
17
- return "\n let plugin_".concat(index, " = require('").concat(plugin, "')\n plugin_").concat(index, " = plugin_").concat(index, ".default || plugin_").concat(index, "\n ");
18
- }).join(";\n");
19
- };
20
- var getProjectUsage = function(appDirectory, distDirectory) {
21
- var routeJSON = path.join(distDirectory, ROUTE_SPEC_FILE);
22
- var routes = fse.readJSONSync(routeJSON).routes;
23
- var useSSR = false;
24
- var useAPI = false;
25
- routes.forEach(function(route) {
26
- if (route.isSSR) {
27
- useSSR = true;
28
- }
29
- if (route.isApi) {
30
- useAPI = true;
31
- }
32
- });
33
- var useWebServer = isDepExists(appDirectory, "@modern-js/plugin-server");
34
- return {
35
- useSSR,
36
- useAPI,
37
- useWebServer
38
- };
39
- };
40
- function applyProductionCondition(exports) {
41
- if (!exports || typeof exports === "string") {
42
- return;
43
- }
44
- if (exports.production) {
45
- if (typeof exports.production === "string") {
46
- exports.default = exports.production;
47
- } else {
48
- Object.assign(exports, exports.production);
49
- }
50
- }
51
- for (var key in exports) {
52
- applyProductionCondition(exports[key]);
53
- }
54
- }
55
- function applyPublicCondition(pkg) {
56
- var _pkg_publishConfig;
57
- if (pkg === null || pkg === void 0 ? void 0 : (_pkg_publishConfig = pkg.publishConfig) === null || _pkg_publishConfig === void 0 ? void 0 : _pkg_publishConfig.exports) {
58
- var _pkg_publishConfig1;
59
- pkg.exports = pkg === null || pkg === void 0 ? void 0 : (_pkg_publishConfig1 = pkg.publishConfig) === null || _pkg_publishConfig1 === void 0 ? void 0 : _pkg_publishConfig1.exports;
60
- }
61
- }
62
- var writePackage = function() {
63
- var _ref = _async_to_generator(function(pkg, version, projectDir, _pkgPath) {
64
- var pkgPath, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, src, subpath, dest, dirname, subpath1, dest1, dirname1, err, pkgJSON, packageJsonPath;
65
- return _ts_generator(this, function(_state) {
66
- switch (_state.label) {
67
- case 0:
68
- pkgPath = _pkgPath || pkg.name;
69
- _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
70
- _state.label = 1;
71
- case 1:
72
- _state.trys.push([
73
- 1,
74
- 10,
75
- 11,
76
- 12
77
- ]);
78
- _iterator = pkg.versions[version].files[Symbol.iterator]();
79
- _state.label = 2;
80
- case 2:
81
- if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done))
82
- return [
83
- 3,
84
- 9
85
- ];
86
- src = _step.value;
87
- if (!src.includes("node_modules"))
88
- return [
89
- 3,
90
- 5
91
- ];
92
- subpath = parseNodeModulePath(src).subpath;
93
- dest = path.join(projectDir, "node_modules", pkgPath, subpath);
94
- dirname = path.dirname(dest);
95
- return [
96
- 4,
97
- fse.ensureDir(dirname)
98
- ];
99
- case 3:
100
- _state.sent();
101
- return [
102
- 4,
103
- fse.copyFile(src, dest)
104
- ];
105
- case 4:
106
- _state.sent();
107
- return [
108
- 3,
109
- 8
110
- ];
111
- case 5:
112
- subpath1 = path.relative(pkg.versions[version].path, src);
113
- dest1 = path.join(projectDir, "node_modules", pkgPath, subpath1);
114
- dirname1 = path.dirname(dest1);
115
- return [
116
- 4,
117
- fse.ensureDir(dirname1)
118
- ];
119
- case 6:
120
- _state.sent();
121
- return [
122
- 4,
123
- fse.copyFile(src, dest1)
124
- ];
125
- case 7:
126
- _state.sent();
127
- _state.label = 8;
128
- case 8:
129
- _iteratorNormalCompletion = true;
130
- return [
131
- 3,
132
- 2
133
- ];
134
- case 9:
135
- return [
136
- 3,
137
- 12
138
- ];
139
- case 10:
140
- err = _state.sent();
141
- _didIteratorError = true;
142
- _iteratorError = err;
143
- return [
144
- 3,
145
- 12
146
- ];
147
- case 11:
148
- try {
149
- if (!_iteratorNormalCompletion && _iterator.return != null) {
150
- _iterator.return();
151
- }
152
- } finally {
153
- if (_didIteratorError) {
154
- throw _iteratorError;
155
- }
156
- }
157
- return [
158
- 7
159
- ];
160
- case 12:
161
- pkgJSON = pkg.versions[version].pkgJSON;
162
- applyPublicCondition(pkgJSON);
163
- packageJsonPath = path.join(projectDir, "node_modules", pkgPath, "package.json");
164
- return [
165
- 4,
166
- fse.ensureDir(path.dirname(packageJsonPath))
167
- ];
168
- case 13:
169
- _state.sent();
170
- return [
171
- 4,
172
- fse.writeFile(packageJsonPath, JSON.stringify(pkgJSON, null, 2))
173
- ];
174
- case 14:
175
- _state.sent();
176
- return [
177
- 2
178
- ];
179
- }
180
- });
181
- });
182
- return function writePackage2(pkg, version, projectDir, _pkgPath) {
183
- return _ref.apply(this, arguments);
184
- };
185
- }();
186
- var isWindows = os.platform() === "win32";
187
- var linkPackage = function() {
188
- var _ref = _async_to_generator(function(from, to, projectRootDir) {
189
- var src, dest, dstStat, exists;
190
- return _ts_generator(this, function(_state) {
191
- switch (_state.label) {
192
- case 0:
193
- src = path.join(projectRootDir, "node_modules", from);
194
- dest = path.join(projectRootDir, "node_modules", to);
195
- return [
196
- 4,
197
- fse.lstat(dest).catch(function() {
198
- return null;
199
- })
200
- ];
201
- case 1:
202
- dstStat = _state.sent();
203
- exists = dstStat === null || dstStat === void 0 ? void 0 : dstStat.isSymbolicLink();
204
- if (exists) {
205
- return [
206
- 2
207
- ];
208
- }
209
- return [
210
- 4,
211
- fse.mkdir(path.dirname(dest), {
212
- recursive: true
213
- })
214
- ];
215
- case 2:
216
- _state.sent();
217
- return [
218
- 4,
219
- fse.symlink(path.relative(path.dirname(dest), src), dest, isWindows ? "junction" : "dir").catch(function(error) {
220
- console.error("Cannot link", from, "to", to, error);
221
- })
222
- ];
223
- case 3:
224
- _state.sent();
225
- return [
226
- 2
227
- ];
228
- }
229
- });
230
- });
231
- return function linkPackage2(from, to, projectRootDir) {
232
- return _ref.apply(this, arguments);
233
- };
234
- }();
235
- export {
236
- applyProductionCondition,
237
- applyPublicCondition,
238
- genPluginImportsCode,
239
- getPluginsCode,
240
- getProjectUsage,
241
- linkPackage,
242
- severAppContextTemplate,
243
- writePackage
244
- };
@@ -1,222 +0,0 @@
1
- import path, { isAbsolute } from "node:path";
2
- import { nodeFileTrace, resolve } from "@vercel/nft";
3
- import { fs as fse, pkgUp, semver } from "@modern-js/utils";
4
- import { readPackageJSON } from "pkg-types";
5
- import { parseNodeModulePath } from "mlly";
6
- import { linkPackage, writePackage } from "./utils";
7
- const readDirRecursive = async (dir) => {
8
- const files = await fse.readdir(dir, {
9
- withFileTypes: true
10
- });
11
- const filesAndDirs = await Promise.all(files.map(async (file) => {
12
- const resPath = path.resolve(dir, file.name);
13
- return file.isDirectory() ? readDirRecursive(resPath) : resPath;
14
- }));
15
- return filesAndDirs.flat();
16
- };
17
- async function isFile(file) {
18
- try {
19
- const stat = await fse.stat(file);
20
- return stat.isFile();
21
- } catch (error) {
22
- if (error.code === "ENOENT") {
23
- return false;
24
- }
25
- throw error;
26
- }
27
- }
28
- const findEntryFiles = async (rootDir) => {
29
- const files = await readDirRecursive(rootDir);
30
- return files;
31
- };
32
- const handleDependencies = async (appDir, serverRootDir, include) => {
33
- const base = "/";
34
- const entryFiles = await findEntryFiles(serverRootDir);
35
- const includeEntries = include.map((item) => {
36
- if (isAbsolute(item)) {
37
- return item;
38
- }
39
- try {
40
- return require.resolve(item);
41
- } catch (error) {
42
- }
43
- return item;
44
- });
45
- const _fileTrace = await nodeFileTrace(entryFiles.concat(includeEntries), {
46
- base,
47
- processCwd: serverRootDir,
48
- resolve: async (id, parent, job, isCjs) => {
49
- if (id.startsWith("@modern-js/prod-server")) {
50
- return require.resolve(id, {
51
- paths: [
52
- require.resolve("@modern-js/app-tools")
53
- ]
54
- });
55
- } else {
56
- return resolve(id, parent, job, isCjs);
57
- }
58
- }
59
- });
60
- const currentProjectModules = path.join(appDir, "node_modules");
61
- const _resolveTracedPath = (p) => fse.realpath(path.resolve(base, p));
62
- const tracedFiles = Object.fromEntries(await Promise.all([
63
- ..._fileTrace.reasons.entries()
64
- ].map(async ([_path, reasons]) => {
65
- if (reasons.ignored) {
66
- return;
67
- }
68
- const filePath = await _resolveTracedPath(_path);
69
- if (filePath.startsWith(serverRootDir) || filePath.startsWith(appDir) && !filePath.startsWith(currentProjectModules)) {
70
- return;
71
- }
72
- if (!await isFile(filePath)) {
73
- return;
74
- }
75
- let baseDir;
76
- let pkgName;
77
- let subpath;
78
- let pkgPath;
79
- if (filePath.includes("node_modules")) {
80
- const parsed = parseNodeModulePath(filePath);
81
- baseDir = parsed.dir;
82
- pkgName = parsed.name;
83
- subpath = parsed.subpath;
84
- pkgPath = path.join(baseDir, pkgName);
85
- } else {
86
- const MODERN_UTILS_PATH = "packages/toolkit/utils";
87
- const MODERN_UTILS_PATH_REGEX = new RegExp(`(.*${MODERN_UTILS_PATH})`);
88
- const match = filePath.match(MODERN_UTILS_PATH_REGEX);
89
- const packageJsonPath = match ? path.join(match[0], "package.json") : await pkgUp({
90
- cwd: path.dirname(filePath)
91
- });
92
- if (packageJsonPath) {
93
- const packageJson = await fse.readJSON(packageJsonPath);
94
- pkgPath = baseDir = path.dirname(packageJsonPath);
95
- subpath = path.relative(baseDir, filePath);
96
- pkgName = packageJson.name;
97
- }
98
- }
99
- if (!baseDir) {
100
- return;
101
- }
102
- const parents = await Promise.all([
103
- ...reasons.parents
104
- ].map((p) => _resolveTracedPath(p)));
105
- const tracedFile = {
106
- path: filePath,
107
- parents,
108
- subpath,
109
- pkgName,
110
- pkgPath
111
- };
112
- return [
113
- filePath,
114
- tracedFile
115
- ];
116
- })).then((r) => r.filter(Boolean)));
117
- const tracedPackages = {};
118
- for (const tracedFile of Object.values(tracedFiles)) {
119
- const { pkgName } = tracedFile;
120
- let tracedPackage = tracedPackages[pkgName];
121
- let pkgJSON = await readPackageJSON(tracedFile.pkgPath, {
122
- cache: true
123
- }).catch(() => {
124
- });
125
- if (!pkgJSON) {
126
- pkgJSON = {
127
- name: pkgName,
128
- version: "0.0.0"
129
- };
130
- }
131
- if (!tracedPackage) {
132
- tracedPackage = {
133
- name: pkgName,
134
- versions: {}
135
- };
136
- tracedPackages[pkgName] = tracedPackage;
137
- }
138
- let tracedPackageVersion = tracedPackage.versions[pkgJSON.version];
139
- if (!tracedPackageVersion) {
140
- tracedPackageVersion = {
141
- path: tracedFile.pkgPath,
142
- files: [],
143
- pkgJSON
144
- };
145
- tracedPackage.versions[pkgJSON.version] = tracedPackageVersion;
146
- }
147
- tracedFile.path.startsWith(tracedFile.pkgPath) && tracedPackageVersion.path === tracedFile.pkgPath && tracedPackageVersion.files.push(tracedFile.path);
148
- tracedFile.pkgName = pkgName;
149
- tracedFile.pkgVersion = pkgJSON.version;
150
- }
151
- const findPackageParents = (pkg, version) => {
152
- const versionFiles = pkg.versions[version].files.map((path2) => tracedFiles[path2]);
153
- const parentPkgs = [
154
- ...new Set(versionFiles.flatMap((file) => file.parents.map((parentPath) => {
155
- const parentFile = tracedFiles[parentPath];
156
- if (parentFile.pkgName === pkg.name) {
157
- return null;
158
- }
159
- return `${parentFile.pkgName}@${parentFile.pkgVersion}`;
160
- }).filter(Boolean)))
161
- ];
162
- return parentPkgs;
163
- };
164
- const multiVersionPkgs = {};
165
- const singleVersionPackages = [];
166
- for (const tracedPackage of Object.values(tracedPackages)) {
167
- const versions = Object.keys(tracedPackage.versions);
168
- if (versions.length === 1) {
169
- singleVersionPackages.push(tracedPackage.name);
170
- continue;
171
- }
172
- multiVersionPkgs[tracedPackage.name] = {};
173
- for (const version of versions) {
174
- multiVersionPkgs[tracedPackage.name][version] = findPackageParents(tracedPackage, version);
175
- }
176
- }
177
- await Promise.all(singleVersionPackages.map((pkgName) => {
178
- const pkg = tracedPackages[pkgName];
179
- const version = Object.keys(pkg.versions)[0];
180
- return writePackage(pkg, version, serverRootDir);
181
- }));
182
- console.log("multiVersionPkgs111111111", multiVersionPkgs);
183
- for (const [pkgName, pkgVersions] of Object.entries(multiVersionPkgs)) {
184
- const versionEntires = Object.entries(pkgVersions).sort(([v1, p1], [v2, p2]) => {
185
- if (p1.length === 0) {
186
- return -1;
187
- }
188
- if (p2.length === 0) {
189
- return 1;
190
- }
191
- return semver.lt(v1, v2, {
192
- loose: true
193
- }) ? 1 : -1;
194
- });
195
- for (const [version, parentPkgs] of versionEntires) {
196
- const pkg = tracedPackages[pkgName];
197
- const pkgDestPath = `.modernjs/${pkgName}@${version}/node_modules/${pkgName}`;
198
- await writePackage(pkg, version, serverRootDir, pkgDestPath);
199
- await linkPackage(pkgDestPath, `${pkgName}`, serverRootDir);
200
- for (const parentPkg of parentPkgs) {
201
- const parentPkgName = parentPkg.replace(/@[^@]+$/, "");
202
- await (multiVersionPkgs[parentPkgName] ? linkPackage(pkgDestPath, `.modernjs/${parentPkg}/node_modules/${pkgName}`, serverRootDir) : linkPackage(pkgDestPath, `${parentPkgName}/node_modules/${pkgName}`, serverRootDir));
203
- }
204
- }
205
- }
206
- const projectPkg = await readPackageJSON(serverRootDir).catch(() => ({}));
207
- const outputPkgPath = path.join(serverRootDir, "package.json");
208
- await fse.writeJSON(outputPkgPath, {
209
- name: `${projectPkg.name || "modernjs-project"}-prod`,
210
- version: projectPkg.version || "0.0.0",
211
- private: true,
212
- dependencies: Object.fromEntries([
213
- ...Object.values(tracedPackages).map((pkg) => [
214
- pkg.name,
215
- Object.keys(pkg.versions)[0]
216
- ])
217
- ].sort(([a], [b]) => a.localeCompare(b)))
218
- });
219
- };
220
- export {
221
- handleDependencies
222
- };
@@ -1,185 +0,0 @@
1
- import path from "path";
2
- import { fs as fse, getInternalPlugins } from "@modern-js/utils";
3
- import { provider } from "std-env";
4
- import { isMainEntry } from "../../utils/routes";
5
- import { getProjectUsage } from "./utils";
6
- import { handleDependencies } from "./dependencies";
7
- var deploy_default = () => ({
8
- name: "@modern-js/plugin-deploy",
9
- pre: [
10
- "@modern-js/plugin-bff",
11
- "@modern-js/plugin-server"
12
- ],
13
- setup: (api) => {
14
- const deployTarget = process.env.MODERNJS_DEPLOY || provider || "node";
15
- return {
16
- async beforeDeploy() {
17
- const appContext = api.useAppContext();
18
- const modernConfig = api.useResolvedConfigContext();
19
- const { source: { mainEntryName } } = modernConfig;
20
- const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints } = appContext;
21
- const { useSSR, useAPI, useWebServer } = getProjectUsage(appDirectory, distDirectory);
22
- const needModernServer = useSSR || useAPI || useWebServer;
23
- let outputDirectory = path.join(appDirectory, ".output");
24
- let funcsDirectory = outputDirectory;
25
- let staticDirectory = path.join(outputDirectory, "static");
26
- if (deployTarget === "node") {
27
- await fse.remove(outputDirectory);
28
- await fse.copy(distDirectory, outputDirectory);
29
- }
30
- if (deployTarget === "netlify") {
31
- const netlifyOutput = path.join(appDirectory, ".netlify");
32
- funcsDirectory = path.join(netlifyOutput, "functions");
33
- const routes = [];
34
- if (!needModernServer) {
35
- entrypoints.forEach((entry) => {
36
- const isMain = isMainEntry(entry.entryName, mainEntryName);
37
- routes.push({
38
- src: `/${isMain ? "" : `${entry.entryName}/`}*`,
39
- dest: `/html/${entry.entryName}/index.html`,
40
- status: 200
41
- });
42
- });
43
- } else {
44
- routes.push({
45
- src: `/*`,
46
- dest: `/.netlify/functions/index`,
47
- status: 200
48
- });
49
- throw new Error("Currently on the Netlify platform, only CSR projects are supporte, Support for SSR and BFF projects will be available later");
50
- }
51
- console.log("routes", routes, needModernServer);
52
- const redirectContent = routes.map((route) => {
53
- return `${route.src} ${route.dest} ${route.status}`;
54
- }).join("\n");
55
- console.log("redirectContent", redirectContent);
56
- await fse.remove(outputDirectory);
57
- await fse.ensureDir(funcsDirectory);
58
- await fse.copy(distDirectory, funcsDirectory, {
59
- filter: (src) => {
60
- const distStaticDirectory = path.join(distDirectory, "static");
61
- return !src.includes(distStaticDirectory);
62
- }
63
- });
64
- const redirectFilePath = path.join(distDirectory, "_redirects");
65
- await fse.writeFile(redirectFilePath, redirectContent);
66
- }
67
- if (deployTarget === "vercel") {
68
- const vercelOutput = path.join(appDirectory, ".vercel");
69
- await fse.remove(vercelOutput);
70
- outputDirectory = path.join(vercelOutput, "output");
71
- const config = {
72
- version: 3,
73
- routes: [
74
- {
75
- src: "/static/(.*)",
76
- headers: {
77
- "cache-control": "s-maxage=31536000, immutable"
78
- },
79
- continue: true
80
- },
81
- {
82
- handle: "filesystem"
83
- }
84
- ]
85
- };
86
- if (!needModernServer) {
87
- entrypoints.forEach((entry) => {
88
- const isMain = isMainEntry(entry.entryName, mainEntryName);
89
- config.routes.push({
90
- src: `/${isMain ? "" : entry.entryName}(?:/.*)?`,
91
- headers: {
92
- "cache-control": "s-maxage=0"
93
- },
94
- dest: `/html/${entry.entryName}/index.html`
95
- });
96
- });
97
- } else {
98
- config.routes.push({
99
- src: "/(.*)",
100
- dest: `/index`
101
- });
102
- }
103
- await fse.ensureDir(outputDirectory);
104
- await fse.writeJSON(path.join(outputDirectory, "config.json"), config, {
105
- spaces: 2
106
- });
107
- staticDirectory = path.join(outputDirectory, "static/static");
108
- await fse.copy(path.join(distDirectory, "static"), staticDirectory);
109
- if (!needModernServer) {
110
- const destHtmlDirectory = path.join(distDirectory, "html");
111
- const outputHtmlDirectory = path.join(path.join(outputDirectory, "static"), "html");
112
- await fse.copy(destHtmlDirectory, outputHtmlDirectory);
113
- } else {
114
- funcsDirectory = path.join(outputDirectory, "functions", "index.func");
115
- await fse.ensureDir(funcsDirectory);
116
- await fse.copy(distDirectory, funcsDirectory, {
117
- filter: (src) => {
118
- const distStaticDirectory = path.join(distDirectory, "static");
119
- return !src.includes(distStaticDirectory);
120
- }
121
- });
122
- await fse.writeJSON(path.join(funcsDirectory, ".vc-config.json"), {
123
- runtime: "nodejs16.x",
124
- handler: "index.js",
125
- launcherType: "Nodejs",
126
- shouldAddHelpers: false,
127
- supportsResponseStreaming: true
128
- });
129
- }
130
- }
131
- const plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
132
- const serverAppContext = {
133
- sharedDirectory: `path.join(__dirname, "${path.relative(appDirectory, sharedDirectory)}")`,
134
- apiDirectory: `path.join(__dirname, "${path.relative(appDirectory, apiDirectory)}")`,
135
- lambdaDirectory: `path.join(__dirname, "${path.relative(appDirectory, lambdaDirectory)}")`,
136
- metaName
137
- };
138
- let code = ``;
139
- console.log("deployTarget111111111", deployTarget);
140
- switch (deployTarget) {
141
- case "node": {
142
- const { genNodeEntry } = await import("./platforms/node");
143
- code = genNodeEntry({
144
- plugins,
145
- config: modernConfig,
146
- appContext: serverAppContext
147
- });
148
- break;
149
- }
150
- case "vercel": {
151
- const { genVercelEntry } = await import("./platforms/vercel");
152
- code = await genVercelEntry({
153
- plugins,
154
- config: modernConfig,
155
- appContext: serverAppContext
156
- });
157
- break;
158
- }
159
- case "netlify": {
160
- const { genNetlifyEntry } = await import("./platforms/netlify");
161
- code = genNetlifyEntry({
162
- plugins,
163
- config: modernConfig,
164
- appContext: serverAppContext
165
- });
166
- break;
167
- }
168
- default: {
169
- code = `throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");`;
170
- }
171
- }
172
- const entryFilePath = path.join(funcsDirectory, "index.js");
173
- if (needModernServer) {
174
- await fse.writeFile(entryFilePath, code);
175
- await handleDependencies(appDirectory, funcsDirectory, [
176
- "@modern-js/prod-server"
177
- ]);
178
- }
179
- }
180
- };
181
- }
182
- });
183
- export {
184
- deploy_default as default
185
- };