@modern-js/app-tools 2.49.1-alpha.7 → 2.49.1-alpha.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -214,18 +214,17 @@ const handleDependencies = async (appDir, serverRootDir, include) => {
214
214
  }));
215
215
  console.log("multiVersionPkgs111111111", multiVersionPkgs);
216
216
  for (const [pkgName, pkgVersions] of Object.entries(multiVersionPkgs)) {
217
- const versionEntires = Object.entries(pkgVersions).sort(
218
- // TODO: remove ts-ignore
219
- // @ts-expect-error
220
- ([v1, p1], [v2, p2]) => {
221
- if (p1.length === 0) {
222
- return -1;
223
- }
224
- if (p2.length === 0) {
225
- return 1;
226
- }
217
+ const versionEntires = Object.entries(pkgVersions).sort(([v1, p1], [v2, p2]) => {
218
+ if (p1.length === 0) {
219
+ return -1;
227
220
  }
228
- );
221
+ if (p2.length === 0) {
222
+ return 1;
223
+ }
224
+ return import_utils.semver.lt(v1, v2, {
225
+ loose: true
226
+ }) ? 1 : -1;
227
+ });
229
228
  for (const [version, parentPkgs] of versionEntires) {
230
229
  const pkg = tracedPackages[pkgName];
231
230
  const pkgDestPath = `.modernjs/${pkgName}@${version}/node_modules/${pkgName}`;
@@ -47,38 +47,44 @@ var deploy_default = () => ({
47
47
  async beforeDeploy() {
48
48
  const appContext = api.useAppContext();
49
49
  const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName } = appContext;
50
+ const { useSSR, useAPI, useWebServer } = (0, import_utils2.getProjectUsage)(appDirectory, distDirectory);
51
+ const needModernServer = useSSR || useAPI || useWebServer;
50
52
  const configContext = api.useResolvedConfigContext();
51
53
  let outputDirectory = import_path.default.join(appDirectory, ".output");
52
54
  let funcsDirectory = outputDirectory;
53
55
  let staticDirectory = import_path.default.join(outputDirectory, "static");
54
- await import_utils.fs.remove(outputDirectory);
55
56
  if (deployTarget === "node") {
57
+ await import_utils.fs.remove(outputDirectory);
56
58
  await import_utils.fs.copy(distDirectory, outputDirectory);
57
59
  }
58
60
  if (deployTarget === "vercel") {
59
- outputDirectory = import_path.default.join(appDirectory, ".vercel/output");
61
+ const vercelOutput = import_path.default.join(appDirectory, ".vercel");
62
+ await import_utils.fs.remove(vercelOutput);
63
+ outputDirectory = import_path.default.join(vercelOutput, "output");
60
64
  const config2 = {
61
65
  version: 3
62
66
  };
63
67
  await import_utils.fs.ensureDir(outputDirectory);
64
68
  await import_utils.fs.writeJSON(import_path.default.join(outputDirectory, "config.json"), config2);
65
- funcsDirectory = import_path.default.join(outputDirectory, "functions", "index.func");
66
69
  staticDirectory = import_path.default.join(outputDirectory, "static/static");
67
- await import_utils.fs.ensureDir(funcsDirectory);
68
- await import_utils.fs.copy(distDirectory, funcsDirectory, {
69
- filter: (src) => {
70
- const distStaticDirectory = import_path.default.join(distDirectory, "static");
71
- return !src.includes(distStaticDirectory);
72
- }
73
- });
74
70
  await import_utils.fs.copy(import_path.default.join(distDirectory, "static"), staticDirectory);
75
- await import_utils.fs.writeJSON(import_path.default.join(funcsDirectory, ".vc-config.json"), {
76
- runtime: "nodejs16.x",
77
- handler: "index.js",
78
- launcherType: "Nodejs",
79
- shouldAddHelpers: false,
80
- supportsResponseStreaming: true
81
- });
71
+ if (needModernServer) {
72
+ funcsDirectory = import_path.default.join(outputDirectory, "functions", "index.func");
73
+ await import_utils.fs.ensureDir(funcsDirectory);
74
+ await import_utils.fs.copy(distDirectory, funcsDirectory, {
75
+ filter: (src) => {
76
+ const distStaticDirectory = import_path.default.join(distDirectory, "static");
77
+ return !src.includes(distStaticDirectory);
78
+ }
79
+ });
80
+ await import_utils.fs.writeJSON(import_path.default.join(funcsDirectory, ".vc-config.json"), {
81
+ runtime: "nodejs16.x",
82
+ handler: "index.js",
83
+ launcherType: "Nodejs",
84
+ shouldAddHelpers: false,
85
+ supportsResponseStreaming: true
86
+ });
87
+ }
82
88
  }
83
89
  const { bff } = configContext;
84
90
  const config = {
@@ -128,14 +134,13 @@ var deploy_default = () => ({
128
134
  code = `throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");`;
129
135
  }
130
136
  }
131
- const { useSSR, useAPI, useWebServer } = (0, import_utils2.getProjectUsage)(appDirectory, distDirectory);
132
137
  const entryFilePath = import_path.default.join(funcsDirectory, "index.js");
133
- if (useSSR || useAPI || useWebServer) {
138
+ if (needModernServer) {
134
139
  await import_utils.fs.writeFile(entryFilePath, code);
140
+ await (0, import_dependencies.handleDependencies)(appDirectory, funcsDirectory, [
141
+ "@modern-js/prod-server"
142
+ ]);
135
143
  }
136
- await (0, import_dependencies.handleDependencies)(appDirectory, funcsDirectory, [
137
- "@modern-js/prod-server"
138
- ]);
139
144
  }
140
145
  };
141
146
  }
@@ -5,7 +5,7 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
5
  import { _ as _ts_values } from "@swc/helpers/_/_ts_values";
6
6
  import path, { isAbsolute } from "node:path";
7
7
  import { nodeFileTrace, resolve } from "@vercel/nft";
8
- import { fs as fse, pkgUp } from "@modern-js/utils";
8
+ import { fs as fse, pkgUp, semver } from "@modern-js/utils";
9
9
  import { readPackageJSON } from "pkg-types";
10
10
  import { parseNodeModulePath } from "mlly";
11
11
  import { linkPackage, writePackage } from "./utils";
@@ -493,19 +493,18 @@ var handleDependencies = function() {
493
493
  switch (_state2.label) {
494
494
  case 0:
495
495
  _step_value = _sliced_to_array(_step3.value, 2), pkgName2 = _step_value[0], pkgVersions = _step_value[1];
496
- versionEntires = Object.entries(pkgVersions).sort(
497
- // TODO: remove ts-ignore
498
- // @ts-expect-error
499
- function(param, param1) {
500
- var _param = _sliced_to_array(param, 2), v1 = _param[0], p1 = _param[1], _param1 = _sliced_to_array(param1, 2), v2 = _param1[0], p2 = _param1[1];
501
- if (p1.length === 0) {
502
- return -1;
503
- }
504
- if (p2.length === 0) {
505
- return 1;
506
- }
496
+ versionEntires = Object.entries(pkgVersions).sort(function(param, param1) {
497
+ var _param = _sliced_to_array(param, 2), v1 = _param[0], p1 = _param[1], _param1 = _sliced_to_array(param1, 2), v2 = _param1[0], p2 = _param1[1];
498
+ if (p1.length === 0) {
499
+ return -1;
507
500
  }
508
- );
501
+ if (p2.length === 0) {
502
+ return 1;
503
+ }
504
+ return semver.lt(v1, v2, {
505
+ loose: true
506
+ }) ? 1 : -1;
507
+ });
509
508
  _iteratorNormalCompletion4 = true, _didIteratorError4 = false, _iteratorError4 = void 0;
510
509
  _state2.label = 1;
511
510
  case 1:
@@ -16,27 +16,29 @@ function deploy_default() {
16
16
  return {
17
17
  beforeDeploy: function beforeDeploy() {
18
18
  return _async_to_generator(function() {
19
- var appContext, appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, configContext, outputDirectory, funcsDirectory, staticDirectory, config, bff, config1, plugins, serverAppContext, code, genNodeEntry, genVercelEntry, genNetlifyEntry, _getProjectUsage, useSSR, useAPI, useWebServer, entryFilePath;
19
+ var appContext, appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, _getProjectUsage, useSSR, useAPI, useWebServer, needModernServer, configContext, outputDirectory, funcsDirectory, staticDirectory, vercelOutput, config, bff, config1, plugins, serverAppContext, code, genNodeEntry, genVercelEntry, genNetlifyEntry, entryFilePath;
20
20
  return _ts_generator(this, function(_state) {
21
21
  switch (_state.label) {
22
22
  case 0:
23
23
  appContext = api.useAppContext();
24
24
  appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverInternalPlugins = appContext.serverInternalPlugins, sharedDirectory = appContext.sharedDirectory, apiDirectory = appContext.apiDirectory, lambdaDirectory = appContext.lambdaDirectory, metaName = appContext.metaName;
25
+ _getProjectUsage = getProjectUsage(appDirectory, distDirectory), useSSR = _getProjectUsage.useSSR, useAPI = _getProjectUsage.useAPI, useWebServer = _getProjectUsage.useWebServer;
26
+ needModernServer = useSSR || useAPI || useWebServer;
25
27
  configContext = api.useResolvedConfigContext();
26
28
  outputDirectory = path.join(appDirectory, ".output");
27
29
  funcsDirectory = outputDirectory;
28
30
  staticDirectory = path.join(outputDirectory, "static");
31
+ if (!(deployTarget === "node"))
32
+ return [
33
+ 3,
34
+ 3
35
+ ];
29
36
  return [
30
37
  4,
31
38
  fse.remove(outputDirectory)
32
39
  ];
33
40
  case 1:
34
41
  _state.sent();
35
- if (!(deployTarget === "node"))
36
- return [
37
- 3,
38
- 3
39
- ];
40
42
  return [
41
43
  4,
42
44
  fse.copy(distDirectory, outputDirectory)
@@ -48,9 +50,16 @@ function deploy_default() {
48
50
  if (!(deployTarget === "vercel"))
49
51
  return [
50
52
  3,
51
- 10
53
+ 11
52
54
  ];
53
- outputDirectory = path.join(appDirectory, ".vercel/output");
55
+ vercelOutput = path.join(appDirectory, ".vercel");
56
+ return [
57
+ 4,
58
+ fse.remove(vercelOutput)
59
+ ];
60
+ case 4:
61
+ _state.sent();
62
+ outputDirectory = path.join(vercelOutput, "output");
54
63
  config = {
55
64
  version: 3
56
65
  };
@@ -58,21 +67,32 @@ function deploy_default() {
58
67
  4,
59
68
  fse.ensureDir(outputDirectory)
60
69
  ];
61
- case 4:
70
+ case 5:
62
71
  _state.sent();
63
72
  return [
64
73
  4,
65
74
  fse.writeJSON(path.join(outputDirectory, "config.json"), config)
66
75
  ];
67
- case 5:
76
+ case 6:
68
77
  _state.sent();
69
- funcsDirectory = path.join(outputDirectory, "functions", "index.func");
70
78
  staticDirectory = path.join(outputDirectory, "static/static");
79
+ return [
80
+ 4,
81
+ fse.copy(path.join(distDirectory, "static"), staticDirectory)
82
+ ];
83
+ case 7:
84
+ _state.sent();
85
+ if (!needModernServer)
86
+ return [
87
+ 3,
88
+ 11
89
+ ];
90
+ funcsDirectory = path.join(outputDirectory, "functions", "index.func");
71
91
  return [
72
92
  4,
73
93
  fse.ensureDir(funcsDirectory)
74
94
  ];
75
- case 6:
95
+ case 8:
76
96
  _state.sent();
77
97
  return [
78
98
  4,
@@ -83,13 +103,7 @@ function deploy_default() {
83
103
  }
84
104
  })
85
105
  ];
86
- case 7:
87
- _state.sent();
88
- return [
89
- 4,
90
- fse.copy(path.join(distDirectory, "static"), staticDirectory)
91
- ];
92
- case 8:
106
+ case 9:
93
107
  _state.sent();
94
108
  return [
95
109
  4,
@@ -101,10 +115,10 @@ function deploy_default() {
101
115
  supportsResponseStreaming: true
102
116
  })
103
117
  ];
104
- case 9:
105
- _state.sent();
106
- _state.label = 10;
107
118
  case 10:
119
+ _state.sent();
120
+ _state.label = 11;
121
+ case 11:
108
122
  bff = configContext.bff;
109
123
  config1 = {
110
124
  output: {
@@ -125,29 +139,29 @@ function deploy_default() {
125
139
  case "node":
126
140
  return [
127
141
  3,
128
- 11
142
+ 12
129
143
  ];
130
144
  case "vercel":
131
145
  return [
132
146
  3,
133
- 13
147
+ 14
134
148
  ];
135
149
  case "netlify":
136
150
  return [
137
151
  3,
138
- 15
152
+ 16
139
153
  ];
140
154
  }
141
155
  return [
142
156
  3,
143
- 17
157
+ 18
144
158
  ];
145
- case 11:
159
+ case 12:
146
160
  return [
147
161
  4,
148
162
  import("./entrys/node")
149
163
  ];
150
- case 12:
164
+ case 13:
151
165
  genNodeEntry = _state.sent().genNodeEntry;
152
166
  code = genNodeEntry({
153
167
  plugins,
@@ -156,14 +170,14 @@ function deploy_default() {
156
170
  });
157
171
  return [
158
172
  3,
159
- 18
173
+ 19
160
174
  ];
161
- case 13:
175
+ case 14:
162
176
  return [
163
177
  4,
164
178
  import("./entrys/vercel")
165
179
  ];
166
- case 14:
180
+ case 15:
167
181
  genVercelEntry = _state.sent().genVercelEntry;
168
182
  code = genVercelEntry({
169
183
  plugins,
@@ -172,14 +186,14 @@ function deploy_default() {
172
186
  });
173
187
  return [
174
188
  3,
175
- 18
189
+ 19
176
190
  ];
177
- case 15:
191
+ case 16:
178
192
  return [
179
193
  4,
180
194
  import("./entrys/netlify")
181
195
  ];
182
- case 16:
196
+ case 17:
183
197
  genNetlifyEntry = _state.sent().genNetlifyEntry;
184
198
  code = genNetlifyEntry({
185
199
  plugins,
@@ -188,29 +202,26 @@ function deploy_default() {
188
202
  });
189
203
  return [
190
204
  3,
191
- 18
205
+ 19
192
206
  ];
193
- case 17:
207
+ case 18:
194
208
  {
195
209
  code = 'throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");';
196
210
  }
197
- _state.label = 18;
198
- case 18:
199
- _getProjectUsage = getProjectUsage(appDirectory, distDirectory), useSSR = _getProjectUsage.useSSR, useAPI = _getProjectUsage.useAPI, useWebServer = _getProjectUsage.useWebServer;
211
+ _state.label = 19;
212
+ case 19:
200
213
  entryFilePath = path.join(funcsDirectory, "index.js");
201
- if (!(useSSR || useAPI || useWebServer))
214
+ if (!needModernServer)
202
215
  return [
203
216
  3,
204
- 20
217
+ 22
205
218
  ];
206
219
  return [
207
220
  4,
208
221
  fse.writeFile(entryFilePath, code)
209
222
  ];
210
- case 19:
211
- _state.sent();
212
- _state.label = 20;
213
223
  case 20:
224
+ _state.sent();
214
225
  return [
215
226
  4,
216
227
  handleDependencies(appDirectory, funcsDirectory, [
@@ -219,6 +230,8 @@ function deploy_default() {
219
230
  ];
220
231
  case 21:
221
232
  _state.sent();
233
+ _state.label = 22;
234
+ case 22:
222
235
  return [
223
236
  2
224
237
  ];
@@ -1,6 +1,6 @@
1
1
  import path, { isAbsolute } from "node:path";
2
2
  import { nodeFileTrace, resolve } from "@vercel/nft";
3
- import { fs as fse, pkgUp } from "@modern-js/utils";
3
+ import { fs as fse, pkgUp, semver } from "@modern-js/utils";
4
4
  import { readPackageJSON } from "pkg-types";
5
5
  import { parseNodeModulePath } from "mlly";
6
6
  import { linkPackage, writePackage } from "./utils";
@@ -181,18 +181,17 @@ const handleDependencies = async (appDir, serverRootDir, include) => {
181
181
  }));
182
182
  console.log("multiVersionPkgs111111111", multiVersionPkgs);
183
183
  for (const [pkgName, pkgVersions] of Object.entries(multiVersionPkgs)) {
184
- const versionEntires = Object.entries(pkgVersions).sort(
185
- // TODO: remove ts-ignore
186
- // @ts-expect-error
187
- ([v1, p1], [v2, p2]) => {
188
- if (p1.length === 0) {
189
- return -1;
190
- }
191
- if (p2.length === 0) {
192
- return 1;
193
- }
184
+ const versionEntires = Object.entries(pkgVersions).sort(([v1, p1], [v2, p2]) => {
185
+ if (p1.length === 0) {
186
+ return -1;
194
187
  }
195
- );
188
+ if (p2.length === 0) {
189
+ return 1;
190
+ }
191
+ return semver.lt(v1, v2, {
192
+ loose: true
193
+ }) ? 1 : -1;
194
+ });
196
195
  for (const [version, parentPkgs] of versionEntires) {
197
196
  const pkg = tracedPackages[pkgName];
198
197
  const pkgDestPath = `.modernjs/${pkgName}@${version}/node_modules/${pkgName}`;
@@ -14,38 +14,44 @@ var deploy_default = () => ({
14
14
  async beforeDeploy() {
15
15
  const appContext = api.useAppContext();
16
16
  const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName } = appContext;
17
+ const { useSSR, useAPI, useWebServer } = getProjectUsage(appDirectory, distDirectory);
18
+ const needModernServer = useSSR || useAPI || useWebServer;
17
19
  const configContext = api.useResolvedConfigContext();
18
20
  let outputDirectory = path.join(appDirectory, ".output");
19
21
  let funcsDirectory = outputDirectory;
20
22
  let staticDirectory = path.join(outputDirectory, "static");
21
- await fse.remove(outputDirectory);
22
23
  if (deployTarget === "node") {
24
+ await fse.remove(outputDirectory);
23
25
  await fse.copy(distDirectory, outputDirectory);
24
26
  }
25
27
  if (deployTarget === "vercel") {
26
- outputDirectory = path.join(appDirectory, ".vercel/output");
28
+ const vercelOutput = path.join(appDirectory, ".vercel");
29
+ await fse.remove(vercelOutput);
30
+ outputDirectory = path.join(vercelOutput, "output");
27
31
  const config2 = {
28
32
  version: 3
29
33
  };
30
34
  await fse.ensureDir(outputDirectory);
31
35
  await fse.writeJSON(path.join(outputDirectory, "config.json"), config2);
32
- funcsDirectory = path.join(outputDirectory, "functions", "index.func");
33
36
  staticDirectory = path.join(outputDirectory, "static/static");
34
- await fse.ensureDir(funcsDirectory);
35
- await fse.copy(distDirectory, funcsDirectory, {
36
- filter: (src) => {
37
- const distStaticDirectory = path.join(distDirectory, "static");
38
- return !src.includes(distStaticDirectory);
39
- }
40
- });
41
37
  await fse.copy(path.join(distDirectory, "static"), staticDirectory);
42
- await fse.writeJSON(path.join(funcsDirectory, ".vc-config.json"), {
43
- runtime: "nodejs16.x",
44
- handler: "index.js",
45
- launcherType: "Nodejs",
46
- shouldAddHelpers: false,
47
- supportsResponseStreaming: true
48
- });
38
+ if (needModernServer) {
39
+ funcsDirectory = path.join(outputDirectory, "functions", "index.func");
40
+ await fse.ensureDir(funcsDirectory);
41
+ await fse.copy(distDirectory, funcsDirectory, {
42
+ filter: (src) => {
43
+ const distStaticDirectory = path.join(distDirectory, "static");
44
+ return !src.includes(distStaticDirectory);
45
+ }
46
+ });
47
+ await fse.writeJSON(path.join(funcsDirectory, ".vc-config.json"), {
48
+ runtime: "nodejs16.x",
49
+ handler: "index.js",
50
+ launcherType: "Nodejs",
51
+ shouldAddHelpers: false,
52
+ supportsResponseStreaming: true
53
+ });
54
+ }
49
55
  }
50
56
  const { bff } = configContext;
51
57
  const config = {
@@ -95,14 +101,13 @@ var deploy_default = () => ({
95
101
  code = `throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");`;
96
102
  }
97
103
  }
98
- const { useSSR, useAPI, useWebServer } = getProjectUsage(appDirectory, distDirectory);
99
104
  const entryFilePath = path.join(funcsDirectory, "index.js");
100
- if (useSSR || useAPI || useWebServer) {
105
+ if (needModernServer) {
101
106
  await fse.writeFile(entryFilePath, code);
107
+ await handleDependencies(appDirectory, funcsDirectory, [
108
+ "@modern-js/prod-server"
109
+ ]);
102
110
  }
103
- await handleDependencies(appDirectory, funcsDirectory, [
104
- "@modern-js/prod-server"
105
- ]);
106
111
  }
107
112
  };
108
113
  }
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.49.1-alpha.7",
18
+ "version": "2.49.1-alpha.8",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -79,20 +79,20 @@
79
79
  "esbuild-register": "^3.5.0",
80
80
  "mlly": "^1.6.1",
81
81
  "pkg-types": "^1.1.0",
82
- "@modern-js/core": "2.49.0",
83
82
  "@modern-js/plugin": "2.49.0",
84
- "@modern-js/node-bundle-require": "2.49.0",
83
+ "@modern-js/core": "2.49.0",
85
84
  "@modern-js/plugin-i18n": "2.49.0",
86
- "@modern-js/plugin-lint": "2.49.0",
87
85
  "@modern-js/prod-server": "2.49.0",
88
86
  "@modern-js/server-core": "2.49.0",
89
- "@modern-js/server-utils": "2.49.0",
90
- "@modern-js/types": "2.49.0",
91
- "@modern-js/utils": "2.49.0",
87
+ "@modern-js/plugin-data-loader": "2.49.0",
88
+ "@modern-js/node-bundle-require": "2.49.0",
89
+ "@modern-js/rsbuild-plugin-esbuild": "2.49.1",
92
90
  "@modern-js/server": "2.49.0",
91
+ "@modern-js/plugin-lint": "2.49.0",
92
+ "@modern-js/types": "2.49.0",
93
93
  "@modern-js/uni-builder": "2.49.0",
94
- "@modern-js/plugin-data-loader": "2.49.0",
95
- "@modern-js/rsbuild-plugin-esbuild": "2.49.1"
94
+ "@modern-js/server-utils": "2.49.0",
95
+ "@modern-js/utils": "2.49.0"
96
96
  },
97
97
  "devDependencies": {
98
98
  "@rsbuild/plugin-swc": "0.6.4",