@modern-js/app-tools 2.49.3-alpha.0 → 2.49.3-alpha.1

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/index.js CHANGED
@@ -154,7 +154,7 @@ const appTools = (options = {
154
154
  const { start } = await Promise.resolve().then(() => __toESM(require("./commands/serve")));
155
155
  await start(api);
156
156
  });
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) => {
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)).description(import_locale.i18n.t(import_locale.localeKeys.command.deploy.describe)).action(async (options2) => {
158
158
  if (!options2.skipBuild) {
159
159
  const { build } = await Promise.resolve().then(() => __toESM(require("./commands/build")));
160
160
  await build(api);
@@ -44,8 +44,7 @@ const EN_LOCALE = {
44
44
  describe: "preview the production build locally"
45
45
  },
46
46
  deploy: {
47
- describe: "deploy the application",
48
- output: "output path"
47
+ describe: "deploy the application"
49
48
  },
50
49
  new: {
51
50
  describe: "enable optional features or add a new entry",
@@ -44,8 +44,7 @@ const ZH_LOCALE = {
44
44
  describe: "启动生产环境服务"
45
45
  },
46
46
  deploy: {
47
- describe: "部署应用",
48
- output: "输出路径"
47
+ describe: "部署应用"
49
48
  },
50
49
  new: {
51
50
  describe: "Web App 项目中执行生成器",
@@ -32,6 +32,9 @@ function genVercelEntry({ config, plugins, appContext } = {}) {
32
32
  path: "."
33
33
  }
34
34
  };
35
+ if (appContext === null || appContext === void 0 ? void 0 : appContext.apiDirectory) {
36
+ appContext.apiDirectory = appContext === null || appContext === void 0 ? void 0 : appContext.apiDirectory.replace(/\/api$/, "/_api");
37
+ }
35
38
  return `
36
39
 
37
40
  const fs = require('node:fs/promises');
@@ -45,17 +45,13 @@ var deploy_default = () => ({
45
45
  setup: (api) => {
46
46
  const deployTarget = process.env.MODERNJS_DEPLOY || import_std_env.provider || "node";
47
47
  return {
48
- async beforeDeploy(options) {
49
- const { output: outputPath } = options;
48
+ async beforeDeploy() {
50
49
  const appContext = api.useAppContext();
51
50
  const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints } = appContext;
52
51
  const { useSSR, useAPI, useWebServer } = (0, import_utils2.getProjectUsage)(appDirectory, distDirectory);
53
52
  const needModernServer = useSSR || useAPI || useWebServer;
54
53
  const configContext = api.useResolvedConfigContext();
55
- let outputDirectory = import_path.default.resolve(appDirectory, ".output");
56
- if (outputPath) {
57
- outputDirectory = import_path.default.isAbsolute(outputPath) ? outputPath : import_path.default.resolve(outputPath);
58
- }
54
+ let outputDirectory = import_path.default.join(appDirectory, ".output");
59
55
  let funcsDirectory = outputDirectory;
60
56
  let staticDirectory = import_path.default.join(outputDirectory, "static");
61
57
  if (deployTarget === "node") {
@@ -116,6 +112,10 @@ var deploy_default = () => ({
116
112
  return !src.includes(distStaticDirectory);
117
113
  }
118
114
  });
115
+ const apiDirectory2 = import_path.default.join(funcsDirectory, "api");
116
+ if (await import_utils.fs.pathExists(apiDirectory2)) {
117
+ await import_utils.fs.rename(apiDirectory2, import_path.default.join(funcsDirectory, "_api"));
118
+ }
119
119
  await import_utils.fs.writeJSON(import_path.default.join(funcsDirectory, ".vc-config.json"), {
120
120
  runtime: "nodejs16.x",
121
121
  handler: "index.js",
package/dist/esm/index.js CHANGED
@@ -368,7 +368,7 @@ var appTools = function() {
368
368
  }
369
369
  });
370
370
  }));
371
- program.command("deploy").usage("[options]").option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("-s --skip-build", i18n.t(localeKeys.command.shared.skipBuild)).option("-o --output <path>", i18n.t(localeKeys.command.deploy.output)).description(i18n.t(localeKeys.command.deploy.describe)).action(function() {
371
+ program.command("deploy").usage("[options]").option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("-s --skip-build", i18n.t(localeKeys.command.shared.skipBuild)).description(i18n.t(localeKeys.command.deploy.describe)).action(function() {
372
372
  var _ref = _async_to_generator(function(options2) {
373
373
  var build, deploy;
374
374
  return _ts_generator(this, function(_state2) {
@@ -21,8 +21,7 @@ var EN_LOCALE = {
21
21
  describe: "preview the production build locally"
22
22
  },
23
23
  deploy: {
24
- describe: "deploy the application",
25
- output: "output path"
24
+ describe: "deploy the application"
26
25
  },
27
26
  new: {
28
27
  describe: "enable optional features or add a new entry",
@@ -21,8 +21,7 @@ var ZH_LOCALE = {
21
21
  describe: "启动生产环境服务"
22
22
  },
23
23
  deploy: {
24
- describe: "部署应用",
25
- output: "输出路径"
24
+ describe: "部署应用"
26
25
  },
27
26
  new: {
28
27
  describe: "Web App 项目中执行生成器",
@@ -10,6 +10,9 @@ function genVercelEntry() {
10
10
  path: "."
11
11
  }
12
12
  };
13
+ if (appContext === null || appContext === void 0 ? void 0 : appContext.apiDirectory) {
14
+ appContext.apiDirectory = appContext === null || appContext === void 0 ? void 0 : appContext.apiDirectory.replace(/\/api$/, "/_api");
15
+ }
13
16
  return "\n\n const fs = require('node:fs/promises');\n const path = require('node:path');\n const { createProdServer } = require('@modern-js/prod-server');\n ".concat(genPluginImportsCode(plugins || []), `
14
17
 
15
18
  if(!process.env.NODE_ENV){
@@ -15,22 +15,18 @@ function deploy_default() {
15
15
  setup: function(api) {
16
16
  var deployTarget = process.env.MODERNJS_DEPLOY || provider || "node";
17
17
  return {
18
- beforeDeploy: function beforeDeploy(options) {
18
+ beforeDeploy: function beforeDeploy() {
19
19
  return _async_to_generator(function() {
20
- var outputPath, appContext, appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints, _getProjectUsage, useSSR, useAPI, useWebServer, needModernServer, configContext, outputDirectory, funcsDirectory, staticDirectory, vercelOutput, config, destHtmlDirectory, outputHtmlDirectory, bff, config1, plugins, serverAppContext, code, genNodeEntry, genVercelEntry, genNetlifyEntry, entryFilePath;
20
+ var appContext, appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints, _getProjectUsage, useSSR, useAPI, useWebServer, needModernServer, configContext, outputDirectory, funcsDirectory, staticDirectory, vercelOutput, config, destHtmlDirectory, outputHtmlDirectory, apiDirectory1, bff, config1, plugins, serverAppContext, code, genNodeEntry, genVercelEntry, genNetlifyEntry, entryFilePath;
21
21
  return _ts_generator(this, function(_state) {
22
22
  switch (_state.label) {
23
23
  case 0:
24
- outputPath = options.output;
25
24
  appContext = api.useAppContext();
26
25
  appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverInternalPlugins = appContext.serverInternalPlugins, sharedDirectory = appContext.sharedDirectory, apiDirectory = appContext.apiDirectory, lambdaDirectory = appContext.lambdaDirectory, metaName = appContext.metaName, entrypoints = appContext.entrypoints;
27
26
  _getProjectUsage = getProjectUsage(appDirectory, distDirectory), useSSR = _getProjectUsage.useSSR, useAPI = _getProjectUsage.useAPI, useWebServer = _getProjectUsage.useWebServer;
28
27
  needModernServer = useSSR || useAPI || useWebServer;
29
28
  configContext = api.useResolvedConfigContext();
30
- outputDirectory = path.resolve(appDirectory, ".output");
31
- if (outputPath) {
32
- outputDirectory = path.isAbsolute(outputPath) ? outputPath : path.resolve(outputPath);
33
- }
29
+ outputDirectory = path.join(appDirectory, ".output");
34
30
  funcsDirectory = outputDirectory;
35
31
  staticDirectory = path.join(outputDirectory, "static");
36
32
  if (!(deployTarget === "node"))
@@ -55,7 +51,7 @@ function deploy_default() {
55
51
  if (!(deployTarget === "vercel"))
56
52
  return [
57
53
  3,
58
- 13
54
+ 16
59
55
  ];
60
56
  vercelOutput = path.join(appDirectory, ".vercel");
61
57
  return [
@@ -132,7 +128,7 @@ function deploy_default() {
132
128
  _state.sent();
133
129
  return [
134
130
  3,
135
- 13
131
+ 16
136
132
  ];
137
133
  case 9:
138
134
  funcsDirectory = path.join(outputDirectory, "functions", "index.func");
@@ -153,6 +149,25 @@ function deploy_default() {
153
149
  ];
154
150
  case 11:
155
151
  _state.sent();
152
+ apiDirectory1 = path.join(funcsDirectory, "api");
153
+ return [
154
+ 4,
155
+ fse.pathExists(apiDirectory1)
156
+ ];
157
+ case 12:
158
+ if (!_state.sent())
159
+ return [
160
+ 3,
161
+ 14
162
+ ];
163
+ return [
164
+ 4,
165
+ fse.rename(apiDirectory1, path.join(funcsDirectory, "_api"))
166
+ ];
167
+ case 13:
168
+ _state.sent();
169
+ _state.label = 14;
170
+ case 14:
156
171
  return [
157
172
  4,
158
173
  fse.writeJSON(path.join(funcsDirectory, ".vc-config.json"), {
@@ -163,10 +178,10 @@ function deploy_default() {
163
178
  supportsResponseStreaming: true
164
179
  })
165
180
  ];
166
- case 12:
181
+ case 15:
167
182
  _state.sent();
168
- _state.label = 13;
169
- case 13:
183
+ _state.label = 16;
184
+ case 16:
170
185
  bff = configContext.bff;
171
186
  config1 = {
172
187
  output: {
@@ -187,29 +202,29 @@ function deploy_default() {
187
202
  case "node":
188
203
  return [
189
204
  3,
190
- 14
205
+ 17
191
206
  ];
192
207
  case "vercel":
193
208
  return [
194
209
  3,
195
- 16
210
+ 19
196
211
  ];
197
212
  case "netlify":
198
213
  return [
199
214
  3,
200
- 18
215
+ 21
201
216
  ];
202
217
  }
203
218
  return [
204
219
  3,
205
- 20
220
+ 23
206
221
  ];
207
- case 14:
222
+ case 17:
208
223
  return [
209
224
  4,
210
225
  import("./entrys/node")
211
226
  ];
212
- case 15:
227
+ case 18:
213
228
  genNodeEntry = _state.sent().genNodeEntry;
214
229
  code = genNodeEntry({
215
230
  plugins,
@@ -218,14 +233,14 @@ function deploy_default() {
218
233
  });
219
234
  return [
220
235
  3,
221
- 21
236
+ 24
222
237
  ];
223
- case 16:
238
+ case 19:
224
239
  return [
225
240
  4,
226
241
  import("./entrys/vercel")
227
242
  ];
228
- case 17:
243
+ case 20:
229
244
  genVercelEntry = _state.sent().genVercelEntry;
230
245
  code = genVercelEntry({
231
246
  plugins,
@@ -234,14 +249,14 @@ function deploy_default() {
234
249
  });
235
250
  return [
236
251
  3,
237
- 21
252
+ 24
238
253
  ];
239
- case 18:
254
+ case 21:
240
255
  return [
241
256
  4,
242
257
  import("./entrys/netlify")
243
258
  ];
244
- case 19:
259
+ case 22:
245
260
  genNetlifyEntry = _state.sent().genNetlifyEntry;
246
261
  code = genNetlifyEntry({
247
262
  plugins,
@@ -250,25 +265,25 @@ function deploy_default() {
250
265
  });
251
266
  return [
252
267
  3,
253
- 21
268
+ 24
254
269
  ];
255
- case 20:
270
+ case 23:
256
271
  {
257
272
  code = 'throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");';
258
273
  }
259
- _state.label = 21;
260
- case 21:
274
+ _state.label = 24;
275
+ case 24:
261
276
  entryFilePath = path.join(funcsDirectory, "index.js");
262
277
  if (!needModernServer)
263
278
  return [
264
279
  3,
265
- 24
280
+ 27
266
281
  ];
267
282
  return [
268
283
  4,
269
284
  fse.writeFile(entryFilePath, code)
270
285
  ];
271
- case 22:
286
+ case 25:
272
287
  _state.sent();
273
288
  return [
274
289
  4,
@@ -276,10 +291,10 @@ function deploy_default() {
276
291
  "@modern-js/prod-server"
277
292
  ])
278
293
  ];
279
- case 23:
294
+ case 26:
280
295
  _state.sent();
281
- _state.label = 24;
282
- case 24:
296
+ _state.label = 27;
297
+ case 27:
283
298
  return [
284
299
  2
285
300
  ];
@@ -115,7 +115,7 @@ const appTools = (options = {
115
115
  const { start } = await import("./commands/serve");
116
116
  await start(api);
117
117
  });
118
- program.command("deploy").usage("[options]").option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("-s --skip-build", i18n.t(localeKeys.command.shared.skipBuild)).option("-o --output <path>", i18n.t(localeKeys.command.deploy.output)).description(i18n.t(localeKeys.command.deploy.describe)).action(async (options2) => {
118
+ program.command("deploy").usage("[options]").option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("-s --skip-build", i18n.t(localeKeys.command.shared.skipBuild)).description(i18n.t(localeKeys.command.deploy.describe)).action(async (options2) => {
119
119
  if (!options2.skipBuild) {
120
120
  const { build } = await import("./commands/build");
121
121
  await build(api);
@@ -21,8 +21,7 @@ const EN_LOCALE = {
21
21
  describe: "preview the production build locally"
22
22
  },
23
23
  deploy: {
24
- describe: "deploy the application",
25
- output: "output path"
24
+ describe: "deploy the application"
26
25
  },
27
26
  new: {
28
27
  describe: "enable optional features or add a new entry",
@@ -21,8 +21,7 @@ const ZH_LOCALE = {
21
21
  describe: "启动生产环境服务"
22
22
  },
23
23
  deploy: {
24
- describe: "部署应用",
25
- output: "输出路径"
24
+ describe: "部署应用"
26
25
  },
27
26
  new: {
28
27
  describe: "Web App 项目中执行生成器",
@@ -9,6 +9,9 @@ function genVercelEntry({ config, plugins, appContext } = {}) {
9
9
  path: "."
10
10
  }
11
11
  };
12
+ if (appContext === null || appContext === void 0 ? void 0 : appContext.apiDirectory) {
13
+ appContext.apiDirectory = appContext === null || appContext === void 0 ? void 0 : appContext.apiDirectory.replace(/\/api$/, "/_api");
14
+ }
12
15
  return `
13
16
 
14
17
  const fs = require('node:fs/promises');
@@ -12,17 +12,13 @@ var deploy_default = () => ({
12
12
  setup: (api) => {
13
13
  const deployTarget = process.env.MODERNJS_DEPLOY || provider || "node";
14
14
  return {
15
- async beforeDeploy(options) {
16
- const { output: outputPath } = options;
15
+ async beforeDeploy() {
17
16
  const appContext = api.useAppContext();
18
17
  const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints } = appContext;
19
18
  const { useSSR, useAPI, useWebServer } = getProjectUsage(appDirectory, distDirectory);
20
19
  const needModernServer = useSSR || useAPI || useWebServer;
21
20
  const configContext = api.useResolvedConfigContext();
22
- let outputDirectory = path.resolve(appDirectory, ".output");
23
- if (outputPath) {
24
- outputDirectory = path.isAbsolute(outputPath) ? outputPath : path.resolve(outputPath);
25
- }
21
+ let outputDirectory = path.join(appDirectory, ".output");
26
22
  let funcsDirectory = outputDirectory;
27
23
  let staticDirectory = path.join(outputDirectory, "static");
28
24
  if (deployTarget === "node") {
@@ -83,6 +79,10 @@ var deploy_default = () => ({
83
79
  return !src.includes(distStaticDirectory);
84
80
  }
85
81
  });
82
+ const apiDirectory2 = path.join(funcsDirectory, "api");
83
+ if (await fse.pathExists(apiDirectory2)) {
84
+ await fse.rename(apiDirectory2, path.join(funcsDirectory, "_api"));
85
+ }
86
86
  await fse.writeJSON(path.join(funcsDirectory, ".vc-config.json"), {
87
87
  runtime: "nodejs16.x",
88
88
  handler: "index.js",
@@ -22,7 +22,6 @@ export declare const EN_LOCALE: {
22
22
  };
23
23
  deploy: {
24
24
  describe: string;
25
- output: string;
26
25
  };
27
26
  new: {
28
27
  describe: string;
@@ -24,7 +24,6 @@ declare const localeKeys: {
24
24
  };
25
25
  deploy: {
26
26
  describe: string;
27
- output: string;
28
27
  };
29
28
  new: {
30
29
  describe: string;
@@ -64,7 +63,6 @@ declare const localeKeys: {
64
63
  };
65
64
  deploy: {
66
65
  describe: string;
67
- output: string;
68
66
  };
69
67
  new: {
70
68
  describe: string;
@@ -22,7 +22,6 @@ export declare const ZH_LOCALE: {
22
22
  };
23
23
  deploy: {
24
24
  describe: string;
25
- output: string;
26
25
  };
27
26
  new: {
28
27
  describe: string;
@@ -1,5 +1,6 @@
1
+ import { ServerAppContext } from '../utils';
1
2
  export declare function genVercelEntry({ config, plugins, appContext, }?: {
2
3
  config?: Record<string, any>;
3
4
  plugins?: string[];
4
- appContext?: Record<string, any>;
5
+ appContext?: ServerAppContext;
5
6
  }): string;
@@ -10,7 +10,6 @@ export type BuildOptions = {
10
10
  };
11
11
  export type DeployOptions = {
12
12
  config?: string;
13
- output?: string;
14
13
  skipBuild?: boolean;
15
14
  };
16
15
  export type StartOptions = {
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.49.3-alpha.0",
18
+ "version": "2.49.3-alpha.1",
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/node-bundle-require": "2.49.2",
84
- "@modern-js/plugin": "2.49.2",
85
83
  "@modern-js/plugin-data-loader": "2.49.2",
86
- "@modern-js/plugin-i18n": "2.49.2",
87
- "@modern-js/rsbuild-plugin-esbuild": "2.49.2",
84
+ "@modern-js/prod-server": "2.49.2",
88
85
  "@modern-js/plugin-lint": "2.49.2",
89
- "@modern-js/server-utils": "2.49.2",
90
- "@modern-js/server": "2.49.2",
91
- "@modern-js/types": "2.49.2",
92
- "@modern-js/core": "2.49.2",
86
+ "@modern-js/plugin": "2.49.2",
87
+ "@modern-js/rsbuild-plugin-esbuild": "2.49.2",
93
88
  "@modern-js/server-core": "2.49.2",
94
- "@modern-js/utils": "2.49.2",
89
+ "@modern-js/plugin-i18n": "2.49.2",
90
+ "@modern-js/core": "2.49.2",
91
+ "@modern-js/types": "2.49.2",
95
92
  "@modern-js/uni-builder": "2.49.2",
96
- "@modern-js/prod-server": "2.49.2"
93
+ "@modern-js/utils": "2.49.2",
94
+ "@modern-js/server": "2.49.2",
95
+ "@modern-js/node-bundle-require": "2.49.2",
96
+ "@modern-js/server-utils": "2.49.2"
97
97
  },
98
98
  "devDependencies": {
99
99
  "@rsbuild/plugin-swc": "0.6.10",