@modern-js/app-tools 2.49.3-alpha.16 → 2.49.3-alpha.18

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,8 +5,8 @@ import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse, getInternalPlugins }
5
5
  import { isMainEntry } from "../../../utils/routes";
6
6
  import { genPluginImportsCode, serverAppContenxtTemplate } from "../utils";
7
7
  import { handleDependencies } from "../dependencies";
8
- var createVercelPreset = function(appContext, config, needModernServer) {
9
- var appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverInternalPlugins = appContext.serverInternalPlugins, sharedDirectory = appContext.sharedDirectory, apiDirectory = appContext.apiDirectory, lambdaDirectory = appContext.lambdaDirectory, metaName = appContext.metaName, entrypoints = appContext.entrypoints;
8
+ var createVercelPreset = function(appContext, modernConfig, needModernServer) {
9
+ var appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverInternalPlugins = appContext.serverInternalPlugins, entrypoints = appContext.entrypoints;
10
10
  var plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
11
11
  var vercelOutput = path.join(appDirectory, ".vercel");
12
12
  var outputDirectory = path.join(vercelOutput, "output");
@@ -33,11 +33,11 @@ var createVercelPreset = function(appContext, config, needModernServer) {
33
33
  },
34
34
  writeOutput: function writeOutput() {
35
35
  return _async_to_generator(function() {
36
- var config2, mainEntryName, staticDirectory, destHtmlDirectory, outputHtmlDirectory;
36
+ var config, mainEntryName, staticDirectory, destHtmlDirectory, outputHtmlDirectory;
37
37
  return _ts_generator(this, function(_state) {
38
38
  switch (_state.label) {
39
39
  case 0:
40
- config2 = {
40
+ config = {
41
41
  version: 3,
42
42
  routes: [
43
43
  {
@@ -53,10 +53,10 @@ var createVercelPreset = function(appContext, config, needModernServer) {
53
53
  ]
54
54
  };
55
55
  if (!needModernServer) {
56
- mainEntryName = config2.source.mainEntryName;
56
+ mainEntryName = modernConfig.source.mainEntryName;
57
57
  entrypoints.forEach(function(entry) {
58
58
  var isMain = isMainEntry(entry.entryName, mainEntryName);
59
- config2.routes.push({
59
+ config.routes.push({
60
60
  src: "/".concat(isMain ? "" : entry.entryName, "(?:/.*)?"),
61
61
  headers: {
62
62
  "cache-control": "s-maxage=0"
@@ -65,7 +65,7 @@ var createVercelPreset = function(appContext, config, needModernServer) {
65
65
  });
66
66
  });
67
67
  } else {
68
- config2.routes.push({
68
+ config.routes.push({
69
69
  src: "/(.*)",
70
70
  dest: "/index"
71
71
  });
@@ -78,7 +78,7 @@ var createVercelPreset = function(appContext, config, needModernServer) {
78
78
  _state.sent();
79
79
  return [
80
80
  4,
81
- fse.writeJSON(path.join(outputDirectory, "config.json"), config2, {
81
+ fse.writeJSON(path.join(outputDirectory, "config.json"), config, {
82
82
  spaces: 2
83
83
  })
84
84
  ];
@@ -149,7 +149,7 @@ var createVercelPreset = function(appContext, config, needModernServer) {
149
149
  },
150
150
  genEntry: function genEntry() {
151
151
  return _async_to_generator(function() {
152
- var _config_bff, serverConfig, pluginImportCode, dynamicProdOptions, serverAppContext, entryCode;
152
+ var _modernConfig_bff, serverConfig, pluginImportCode, dynamicProdOptions, serverAppContext, entryCode;
153
153
  return _ts_generator(this, function(_state) {
154
154
  switch (_state.label) {
155
155
  case 0:
@@ -160,7 +160,7 @@ var createVercelPreset = function(appContext, config, needModernServer) {
160
160
  }
161
161
  serverConfig = {
162
162
  bff: {
163
- prefix: config === null || config === void 0 ? void 0 : (_config_bff = config.bff) === null || _config_bff === void 0 ? void 0 : _config_bff.prefix
163
+ prefix: modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_bff = modernConfig.bff) === null || _modernConfig_bff === void 0 ? void 0 : _modernConfig_bff.prefix
164
164
  },
165
165
  output: {
166
166
  path: "."
@@ -169,7 +169,6 @@ const handleDependencies = async (appDir, serverRootDir, include) => {
169
169
  const version = Object.keys(pkg.versions)[0];
170
170
  return writePackage(pkg, version, serverRootDir);
171
171
  }));
172
- console.log("multiVersionPkgs111111111", multiVersionPkgs);
173
172
  for (const [pkgName, pkgVersions] of Object.entries(multiVersionPkgs)) {
174
173
  const versionEntires = Object.entries(pkgVersions).sort(([v1, p1], [v2, p2]) => {
175
174
  if (p1.length === 0) {
@@ -3,6 +3,21 @@ import { getProjectUsage } from "./utils";
3
3
  import { createNodePreset } from "./platforms/node";
4
4
  import { createVercelPreset } from "./platforms/vercel";
5
5
  import { createNetlifyPreset } from "./platforms/netlify";
6
+ const deployPresets = {
7
+ node: createNodePreset,
8
+ vercel: createVercelPreset,
9
+ netlify: createNetlifyPreset
10
+ };
11
+ async function getDeployPreset(appContext, modernConfig, deployTarget) {
12
+ const { appDirectory, distDirectory } = appContext;
13
+ const { useSSR, useAPI, useWebServer } = getProjectUsage(appDirectory, distDirectory);
14
+ const needModernServer = useSSR || useAPI || useWebServer;
15
+ const createPreset = deployPresets[deployTarget];
16
+ if (!createPreset) {
17
+ throw new Error(`Unknown deploy target: '${deployTarget}'. MODERNJS_DEPLOY should be 'node', 'vercel', or 'netlify'.`);
18
+ }
19
+ return createPreset(appContext, modernConfig, needModernServer);
20
+ }
6
21
  var deploy_default = () => ({
7
22
  name: "@modern-js/plugin-deploy",
8
23
  pre: [
@@ -14,28 +29,12 @@ var deploy_default = () => ({
14
29
  return {
15
30
  async beforeDeploy() {
16
31
  const appContext = api.useAppContext();
17
- const { appDirectory, distDirectory } = appContext;
18
32
  const modernConfig = api.useResolvedConfigContext();
19
- const { useSSR, useAPI, useWebServer } = getProjectUsage(appDirectory, distDirectory);
20
- const needModernServer = useSSR || useAPI || useWebServer;
21
- let deployPreset;
22
- switch (deployTarget) {
23
- case "node":
24
- deployPreset = createNodePreset(appContext, modernConfig, needModernServer);
25
- break;
26
- case "vercel":
27
- deployPreset = createVercelPreset(appContext, modernConfig, needModernServer);
28
- break;
29
- case "netlify":
30
- deployPreset = createNetlifyPreset(appContext, modernConfig, needModernServer);
31
- break;
32
- default: {
33
- throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");
34
- }
35
- }
36
- await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare());
37
- await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput());
38
- await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry());
33
+ const deployPreset = await getDeployPreset(appContext, modernConfig, deployTarget);
34
+ (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare());
35
+ (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput());
36
+ (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry());
37
+ (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end());
39
38
  }
40
39
  };
41
40
  }
@@ -3,86 +3,59 @@ import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse, getInternalPlugins }
3
3
  import { isMainEntry } from "../../../utils/routes";
4
4
  import { genPluginImportsCode, serverAppContenxtTemplate } from "../utils";
5
5
  import { handleDependencies } from "../dependencies";
6
- const createNetlifyPreset = (appContext, config, needModernServer) => {
7
- const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints } = appContext;
6
+ const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
7
+ const { appDirectory, distDirectory, serverInternalPlugins, entrypoints } = appContext;
8
8
  const plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
9
9
  const netlifyOutput = path.join(appDirectory, ".netlify");
10
- const outputDirectory = path.join(netlifyOutput, "output");
11
- const funcsDirectory = path.join(outputDirectory, "functions", "index.func");
10
+ const funcsDirectory = path.join(netlifyOutput, "functions");
12
11
  const entryFilePath = path.join(funcsDirectory, "index.js");
13
12
  return {
14
13
  async prepare() {
15
14
  await fse.remove(netlifyOutput);
16
15
  },
17
16
  async writeOutput() {
18
- const config2 = {
19
- version: 3,
20
- routes: [
21
- {
22
- src: "/static/(.*)",
23
- headers: {
24
- "cache-control": "s-maxage=31536000, immutable"
25
- },
26
- continue: true
27
- },
28
- {
29
- handle: "filesystem"
30
- }
31
- ]
32
- };
17
+ const routes = [];
18
+ const { source: { mainEntryName } } = modernConfig;
33
19
  if (!needModernServer) {
34
- const { source: { mainEntryName } } = config2;
35
20
  entrypoints.forEach((entry) => {
36
21
  const isMain = isMainEntry(entry.entryName, mainEntryName);
37
- config2.routes.push({
38
- src: `/${isMain ? "" : entry.entryName}(?:/.*)?`,
39
- headers: {
40
- "cache-control": "s-maxage=0"
41
- },
42
- dest: `/html/${entry.entryName}/index.html`
22
+ routes.push({
23
+ src: `/${isMain ? "" : `${entry.entryName}/`}*`,
24
+ dest: `/html/${entry.entryName}/index.html`,
25
+ status: 200
43
26
  });
44
27
  });
45
28
  } else {
46
- config2.routes.push({
47
- src: "/(.*)",
48
- dest: `/index`
29
+ routes.push({
30
+ src: "/*",
31
+ dest: `/.netlify/functions/index`,
32
+ status: 200
49
33
  });
50
34
  }
51
- await fse.ensureDir(outputDirectory);
52
- await fse.writeJSON(path.join(outputDirectory, "config.json"), config2, {
53
- spaces: 2
54
- });
55
- const staticDirectory = path.join(outputDirectory, "static/static");
56
- await fse.copy(path.join(distDirectory, "static"), staticDirectory);
57
- if (!needModernServer) {
58
- const destHtmlDirectory = path.join(distDirectory, "html");
59
- const outputHtmlDirectory = path.join(path.join(outputDirectory, "static"), "html");
60
- await fse.copy(destHtmlDirectory, outputHtmlDirectory);
61
- } else {
35
+ const redirectContent = routes.map((route) => {
36
+ return `${route.src} ${route.dest} ${route.status}`;
37
+ }).join("\n");
38
+ if (needModernServer) {
62
39
  await fse.ensureDir(funcsDirectory);
40
+ await fse.copy(distDirectory, funcsDirectory);
63
41
  await fse.copy(distDirectory, funcsDirectory, {
64
42
  filter: (src) => {
65
- const distStaticDirectory = path.join(distDirectory, "static");
43
+ const distStaticDirectory = path.join(distDirectory, `static`);
66
44
  return !src.includes(distStaticDirectory);
67
45
  }
68
46
  });
69
- await fse.writeJSON(path.join(funcsDirectory, ".vc-config.json"), {
70
- runtime: "nodejs16.x",
71
- handler: "index.js",
72
- launcherType: "Nodejs",
73
- shouldAddHelpers: false,
74
- supportsResponseStreaming: true
75
- });
76
47
  }
48
+ const redirectFilePath = path.join(distDirectory, "_redirects");
49
+ await fse.writeFile(redirectFilePath, redirectContent);
77
50
  },
78
51
  async genEntry() {
79
- var _config_bff;
52
+ var _modernConfig_bff;
80
53
  if (!needModernServer) {
81
54
  return;
82
55
  }
83
56
  const serverConfig = {
84
57
  bff: {
85
- prefix: config === null || config === void 0 ? void 0 : (_config_bff = config.bff) === null || _config_bff === void 0 ? void 0 : _config_bff.prefix
58
+ prefix: modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_bff = modernConfig.bff) === null || _modernConfig_bff === void 0 ? void 0 : _modernConfig_bff.prefix
86
59
  },
87
60
  output: {
88
61
  path: "."
@@ -1,11 +1,12 @@
1
1
  import path from "node:path";
2
- import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse, getInternalPlugins } from "@modern-js/utils";
2
+ import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse, getInternalPlugins, chalk } from "@modern-js/utils";
3
3
  import { genPluginImportsCode, serverAppContenxtTemplate } from "../utils";
4
4
  import { handleDependencies } from "../dependencies";
5
5
  const createNodePreset = (appContext, config, needModernServer) => {
6
- const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints } = appContext;
6
+ const { appDirectory, distDirectory, serverInternalPlugins } = appContext;
7
7
  const plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
8
8
  const outputDirectory = path.join(appDirectory, ".output");
9
+ const staticDirectory = path.join(outputDirectory, "static");
9
10
  const entryFilePath = path.join(outputDirectory, "index.js");
10
11
  return {
11
12
  async prepare() {
@@ -43,6 +44,10 @@ const createNodePreset = (appContext, config, needModernServer) => {
43
44
  await handleDependencies(appDirectory, outputDirectory, [
44
45
  "@modern-js/prod-server"
45
46
  ]);
47
+ },
48
+ async end() {
49
+ console.log("Static directory:", chalk.blue(path.relative(appDirectory, staticDirectory)));
50
+ console.log(`You can preview this build by`, chalk.blue(`node .output/index`));
46
51
  }
47
52
  };
48
53
  };
@@ -3,8 +3,8 @@ import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse, getInternalPlugins }
3
3
  import { isMainEntry } from "../../../utils/routes";
4
4
  import { genPluginImportsCode, serverAppContenxtTemplate } from "../utils";
5
5
  import { handleDependencies } from "../dependencies";
6
- const createVercelPreset = (appContext, config, needModernServer) => {
7
- const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints } = appContext;
6
+ const createVercelPreset = (appContext, modernConfig, needModernServer) => {
7
+ const { appDirectory, distDirectory, serverInternalPlugins, entrypoints } = appContext;
8
8
  const plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
9
9
  const vercelOutput = path.join(appDirectory, ".vercel");
10
10
  const outputDirectory = path.join(vercelOutput, "output");
@@ -15,7 +15,7 @@ const createVercelPreset = (appContext, config, needModernServer) => {
15
15
  await fse.remove(vercelOutput);
16
16
  },
17
17
  async writeOutput() {
18
- const config2 = {
18
+ const config = {
19
19
  version: 3,
20
20
  routes: [
21
21
  {
@@ -31,10 +31,10 @@ const createVercelPreset = (appContext, config, needModernServer) => {
31
31
  ]
32
32
  };
33
33
  if (!needModernServer) {
34
- const { source: { mainEntryName } } = config2;
34
+ const { source: { mainEntryName } } = modernConfig;
35
35
  entrypoints.forEach((entry) => {
36
36
  const isMain = isMainEntry(entry.entryName, mainEntryName);
37
- config2.routes.push({
37
+ config.routes.push({
38
38
  src: `/${isMain ? "" : entry.entryName}(?:/.*)?`,
39
39
  headers: {
40
40
  "cache-control": "s-maxage=0"
@@ -43,13 +43,13 @@ const createVercelPreset = (appContext, config, needModernServer) => {
43
43
  });
44
44
  });
45
45
  } else {
46
- config2.routes.push({
46
+ config.routes.push({
47
47
  src: "/(.*)",
48
48
  dest: `/index`
49
49
  });
50
50
  }
51
51
  await fse.ensureDir(outputDirectory);
52
- await fse.writeJSON(path.join(outputDirectory, "config.json"), config2, {
52
+ await fse.writeJSON(path.join(outputDirectory, "config.json"), config, {
53
53
  spaces: 2
54
54
  });
55
55
  const staticDirectory = path.join(outputDirectory, "static/static");
@@ -76,13 +76,13 @@ const createVercelPreset = (appContext, config, needModernServer) => {
76
76
  }
77
77
  },
78
78
  async genEntry() {
79
- var _config_bff;
79
+ var _modernConfig_bff;
80
80
  if (!needModernServer) {
81
81
  return;
82
82
  }
83
83
  const serverConfig = {
84
84
  bff: {
85
- prefix: config === null || config === void 0 ? void 0 : (_config_bff = config.bff) === null || _config_bff === void 0 ? void 0 : _config_bff.prefix
85
+ prefix: modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_bff = modernConfig.bff) === null || _modernConfig_bff === void 0 ? void 0 : _modernConfig_bff.prefix
86
86
  },
87
87
  output: {
88
88
  path: "."
@@ -2,8 +2,9 @@ import { IAppContext, NormalizedConfig } from '@modern-js/core';
2
2
  import { AppTools } from '../../../types';
3
3
  export type CreatePreset = (appContext: IAppContext, config: NormalizedConfig<AppTools>, needModernServer?: boolean) => DeployPreset;
4
4
  type DeployPreset = {
5
- prepare: () => Promise<void>;
6
- writeOutput: () => Promise<void>;
7
- genEntry: () => Promise<void>;
5
+ prepare?: () => Promise<void>;
6
+ writeOutput?: () => Promise<void>;
7
+ genEntry?: () => Promise<void>;
8
+ end?: () => Promise<void>;
8
9
  };
9
10
  export {};
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.49.3-alpha.16",
18
+ "version": "2.49.3-alpha.18",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -80,20 +80,20 @@
80
80
  "mlly": "^1.6.1",
81
81
  "pkg-types": "^1.1.0",
82
82
  "std-env": "^3.7.0",
83
- "@modern-js/plugin-data-loader": "2.49.2",
84
- "@modern-js/core": "2.49.2",
85
83
  "@modern-js/plugin": "2.49.2",
84
+ "@modern-js/node-bundle-require": "2.49.2",
85
+ "@modern-js/core": "2.49.2",
86
+ "@modern-js/plugin-data-loader": "2.49.2",
87
+ "@modern-js/plugin-i18n": "2.49.2",
86
88
  "@modern-js/plugin-lint": "2.49.2",
87
- "@modern-js/rsbuild-plugin-esbuild": "2.49.2",
89
+ "@modern-js/server": "2.49.2",
88
90
  "@modern-js/prod-server": "2.49.2",
89
- "@modern-js/plugin-i18n": "2.49.2",
90
- "@modern-js/server-core": "2.49.2",
91
- "@modern-js/node-bundle-require": "2.49.2",
92
91
  "@modern-js/server-utils": "2.49.2",
93
- "@modern-js/types": "2.49.2",
94
92
  "@modern-js/utils": "2.49.2",
93
+ "@modern-js/types": "2.49.2",
95
94
  "@modern-js/uni-builder": "2.49.2",
96
- "@modern-js/server": "2.49.2"
95
+ "@modern-js/rsbuild-plugin-esbuild": "2.49.2",
96
+ "@modern-js/server-core": "2.49.2"
97
97
  },
98
98
  "devDependencies": {
99
99
  "@rsbuild/plugin-swc": "0.6.10",
@@ -1,216 +0,0 @@
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 index_copy_exports = {};
30
- __export(index_copy_exports, {
31
- default: () => index_copy_default
32
- });
33
- module.exports = __toCommonJS(index_copy_exports);
34
- var import_path = __toESM(require("path"));
35
- var import_utils = require("@modern-js/utils");
36
- var import_std_env = require("std-env");
37
- var import_routes = require("../../utils/routes");
38
- var import_utils2 = require("./utils");
39
- var import_dependencies = require("./dependencies");
40
- var index_copy_default = () => ({
41
- name: "@modern-js/plugin-deploy",
42
- pre: [
43
- "@modern-js/plugin-bff",
44
- "@modern-js/plugin-server"
45
- ],
46
- setup: (api) => {
47
- const deployTarget = process.env.MODERNJS_DEPLOY || import_std_env.provider || "node";
48
- return {
49
- async beforeDeploy() {
50
- const appContext = api.useAppContext();
51
- const modernConfig = api.useResolvedConfigContext();
52
- const { source: { mainEntryName } } = modernConfig;
53
- const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints } = appContext;
54
- const { useSSR, useAPI, useWebServer } = (0, import_utils2.getProjectUsage)(appDirectory, distDirectory);
55
- const needModernServer = useSSR || useAPI || useWebServer;
56
- let outputDirectory = import_path.default.join(appDirectory, ".output");
57
- let funcsDirectory = outputDirectory;
58
- let staticDirectory = import_path.default.join(outputDirectory, "static");
59
- if (deployTarget === "node") {
60
- await import_utils.fs.remove(outputDirectory);
61
- await import_utils.fs.copy(distDirectory, outputDirectory);
62
- }
63
- if (deployTarget === "netlify") {
64
- const netlifyOutput = import_path.default.join(appDirectory, ".netlify");
65
- funcsDirectory = import_path.default.join(netlifyOutput, "functions");
66
- const routes = [];
67
- if (!needModernServer) {
68
- entrypoints.forEach((entry) => {
69
- const isMain = (0, import_routes.isMainEntry)(entry.entryName, mainEntryName);
70
- routes.push({
71
- src: `/${isMain ? "" : `${entry.entryName}/`}*`,
72
- dest: `/html/${entry.entryName}/index.html`,
73
- status: 200
74
- });
75
- });
76
- } else {
77
- routes.push({
78
- src: `/*`,
79
- dest: `/.netlify/functions/index`,
80
- status: 200
81
- });
82
- throw new Error("Currently on the Netlify platform, only CSR projects are supported, Support for SSR and BFF projects will be available later");
83
- }
84
- console.log("routes", routes, needModernServer);
85
- const redirectContent = routes.map((route) => {
86
- return `${route.src} ${route.dest} ${route.status}`;
87
- }).join("\n");
88
- console.log("redirectContent", redirectContent);
89
- await import_utils.fs.remove(outputDirectory);
90
- await import_utils.fs.ensureDir(funcsDirectory);
91
- await import_utils.fs.copy(distDirectory, funcsDirectory, {
92
- filter: (src) => {
93
- const distStaticDirectory = import_path.default.join(distDirectory, "static");
94
- return !src.includes(distStaticDirectory);
95
- }
96
- });
97
- const redirectFilePath = import_path.default.join(distDirectory, "_redirects");
98
- await import_utils.fs.writeFile(redirectFilePath, redirectContent);
99
- }
100
- if (deployTarget === "vercel") {
101
- const vercelOutput = import_path.default.join(appDirectory, ".vercel");
102
- await import_utils.fs.remove(vercelOutput);
103
- outputDirectory = import_path.default.join(vercelOutput, "output");
104
- const config = {
105
- version: 3,
106
- routes: [
107
- {
108
- src: "/static/(.*)",
109
- headers: {
110
- "cache-control": "s-maxage=31536000, immutable"
111
- },
112
- continue: true
113
- },
114
- {
115
- handle: "filesystem"
116
- }
117
- ]
118
- };
119
- if (!needModernServer) {
120
- entrypoints.forEach((entry) => {
121
- const isMain = (0, import_routes.isMainEntry)(entry.entryName, mainEntryName);
122
- config.routes.push({
123
- src: `/${isMain ? "" : entry.entryName}(?:/.*)?`,
124
- headers: {
125
- "cache-control": "s-maxage=0"
126
- },
127
- dest: `/html/${entry.entryName}/index.html`
128
- });
129
- });
130
- } else {
131
- config.routes.push({
132
- src: "/(.*)",
133
- dest: `/index`
134
- });
135
- }
136
- await import_utils.fs.ensureDir(outputDirectory);
137
- await import_utils.fs.writeJSON(import_path.default.join(outputDirectory, "config.json"), config, {
138
- spaces: 2
139
- });
140
- staticDirectory = import_path.default.join(outputDirectory, "static/static");
141
- await import_utils.fs.copy(import_path.default.join(distDirectory, "static"), staticDirectory);
142
- if (!needModernServer) {
143
- const destHtmlDirectory = import_path.default.join(distDirectory, "html");
144
- const outputHtmlDirectory = import_path.default.join(import_path.default.join(outputDirectory, "static"), "html");
145
- await import_utils.fs.copy(destHtmlDirectory, outputHtmlDirectory);
146
- } else {
147
- funcsDirectory = import_path.default.join(outputDirectory, "functions", "index.func");
148
- await import_utils.fs.ensureDir(funcsDirectory);
149
- await import_utils.fs.copy(distDirectory, funcsDirectory, {
150
- filter: (src) => {
151
- const distStaticDirectory = import_path.default.join(distDirectory, "static");
152
- return !src.includes(distStaticDirectory);
153
- }
154
- });
155
- await import_utils.fs.writeJSON(import_path.default.join(funcsDirectory, ".vc-config.json"), {
156
- runtime: "nodejs16.x",
157
- handler: "index.js",
158
- launcherType: "Nodejs",
159
- shouldAddHelpers: false,
160
- supportsResponseStreaming: true
161
- });
162
- }
163
- }
164
- const plugins = (0, import_utils.getInternalPlugins)(appDirectory, serverInternalPlugins);
165
- const serverAppContext = {
166
- sharedDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, sharedDirectory)}")`,
167
- apiDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, apiDirectory)}")`,
168
- lambdaDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, lambdaDirectory)}")`,
169
- metaName
170
- };
171
- console.log("serverAppContext", serverAppContext);
172
- let code = ``;
173
- console.log("deployTarget111111111", deployTarget);
174
- switch (deployTarget) {
175
- case "node": {
176
- const { genNodeEntry } = await Promise.resolve().then(() => __toESM(require("./platforms/node")));
177
- code = await genNodeEntry({
178
- plugins,
179
- config: modernConfig,
180
- appContext: serverAppContext
181
- });
182
- break;
183
- }
184
- case "vercel": {
185
- const { genVercelEntry } = await Promise.resolve().then(() => __toESM(require("./platforms/vercel")));
186
- code = await genVercelEntry({
187
- plugins,
188
- config: modernConfig,
189
- appContext: serverAppContext
190
- });
191
- break;
192
- }
193
- case "netlify": {
194
- const { genNetlifyEntry } = await Promise.resolve().then(() => __toESM(require("./platforms/netlify")));
195
- code = await genNetlifyEntry({
196
- plugins,
197
- config: modernConfig,
198
- appContext: serverAppContext
199
- });
200
- break;
201
- }
202
- default: {
203
- code = `throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");`;
204
- }
205
- }
206
- const entryFilePath = import_path.default.join(funcsDirectory, "index.js");
207
- if (needModernServer) {
208
- await import_utils.fs.writeFile(entryFilePath, code);
209
- await (0, import_dependencies.handleDependencies)(appDirectory, funcsDirectory, [
210
- "@modern-js/prod-server"
211
- ]);
212
- }
213
- }
214
- };
215
- }
216
- });