@web-ts-toolkit/express-runtime 0.25.0 → 0.27.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/README.md +98 -41
- package/chunk-SOW7OLVN.mjs +221 -0
- package/cli-api.d.mts +237 -0
- package/cli-api.d.ts +237 -0
- package/cli-api.js +1084 -0
- package/cli-api.mjs +839 -0
- package/cli.js +269 -68
- package/index.mjs +7 -213
- package/package.json +7 -1
package/cli.js
CHANGED
|
@@ -6,6 +6,13 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
6
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __esm = (fn, res) => function __init() {
|
|
10
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
11
|
+
};
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
9
16
|
var __copyProps = (to, from, except, desc) => {
|
|
10
17
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
18
|
for (let key of __getOwnPropNames(from))
|
|
@@ -23,22 +30,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
30
|
mod
|
|
24
31
|
));
|
|
25
32
|
|
|
26
|
-
// src/cli-utils.ts
|
|
27
|
-
var import_node_url = require("url");
|
|
28
|
-
var import_node_path = require("path");
|
|
29
|
-
var import_node_fs = require("fs");
|
|
30
|
-
var import_node_module = require("module");
|
|
31
|
-
var import_node_child_process = require("child_process");
|
|
32
|
-
|
|
33
33
|
// src/index.ts
|
|
34
|
-
var import_node_http = __toESM(require("http"));
|
|
35
|
-
var import_express = __toESM(require("express"));
|
|
36
|
-
var import_serverless_http = __toESM(require("serverless-http"));
|
|
37
|
-
var defaultLogger = {
|
|
38
|
-
log: (...args) => console.log(...args),
|
|
39
|
-
error: (...args) => console.error(...args),
|
|
40
|
-
debug: (...args) => console.debug(...args)
|
|
41
|
-
};
|
|
42
34
|
function applySettings(app, options) {
|
|
43
35
|
if (options.disablePoweredBy !== false) {
|
|
44
36
|
app.disable("x-powered-by");
|
|
@@ -83,8 +75,6 @@ function createExpressApp(options = {}) {
|
|
|
83
75
|
}
|
|
84
76
|
return app;
|
|
85
77
|
}
|
|
86
|
-
var DEFAULT_SIGNALS = ["SIGINT", "SIGTERM"];
|
|
87
|
-
var DEFAULT_SHUTDOWN_TIMEOUT = 5e3;
|
|
88
78
|
function normalizePort(val) {
|
|
89
79
|
if (val === void 0 || val === "") {
|
|
90
80
|
const envPort = process.env.PORT;
|
|
@@ -194,10 +184,24 @@ function startLocalServer(app, options = {}) {
|
|
|
194
184
|
shutdown
|
|
195
185
|
};
|
|
196
186
|
}
|
|
187
|
+
var import_node_http, import_express, import_serverless_http, defaultLogger, DEFAULT_SIGNALS, DEFAULT_SHUTDOWN_TIMEOUT;
|
|
188
|
+
var init_src = __esm({
|
|
189
|
+
"src/index.ts"() {
|
|
190
|
+
"use strict";
|
|
191
|
+
import_node_http = __toESM(require("http"));
|
|
192
|
+
import_express = __toESM(require("express"));
|
|
193
|
+
import_serverless_http = __toESM(require("serverless-http"));
|
|
194
|
+
defaultLogger = {
|
|
195
|
+
log: (...args) => console.log(...args),
|
|
196
|
+
error: (...args) => console.error(...args),
|
|
197
|
+
debug: (...args) => console.debug(...args)
|
|
198
|
+
};
|
|
199
|
+
DEFAULT_SIGNALS = ["SIGINT", "SIGTERM"];
|
|
200
|
+
DEFAULT_SHUTDOWN_TIMEOUT = 5e3;
|
|
201
|
+
}
|
|
202
|
+
});
|
|
197
203
|
|
|
198
204
|
// src/cli-utils.ts
|
|
199
|
-
var import_meta = {};
|
|
200
|
-
var CLI_VERSION = "0.0.0-PLACEHOLDER";
|
|
201
205
|
function readValue(argv, index, name) {
|
|
202
206
|
const value = argv[index + 1];
|
|
203
207
|
if (value === void 0 || value.startsWith("--")) {
|
|
@@ -208,7 +212,7 @@ function readValue(argv, index, name) {
|
|
|
208
212
|
function printHelp() {
|
|
209
213
|
console.log(`wtt-express-runtime
|
|
210
214
|
|
|
211
|
-
Run an Express app locally, bundle it
|
|
215
|
+
Run an Express app locally, bundle it for local or serverless runtimes, or run the bundle.
|
|
212
216
|
|
|
213
217
|
Usage:
|
|
214
218
|
wtt-express-runtime <command> <app-module> [options]
|
|
@@ -216,8 +220,10 @@ Usage:
|
|
|
216
220
|
|
|
217
221
|
Commands:
|
|
218
222
|
dev Run the Express app as a local dev server
|
|
219
|
-
build Bundle the Express app as a
|
|
220
|
-
start Run a bundled
|
|
223
|
+
build Bundle the Express app as a local app module
|
|
224
|
+
start Run a bundled local app module
|
|
225
|
+
build-serverless Bundle the Express app as a serverless handler
|
|
226
|
+
start-serverless Run a bundled serverless handler locally
|
|
221
227
|
|
|
222
228
|
Dev options:
|
|
223
229
|
--port <number> Port or named pipe (default: process.env.PORT or 8080)
|
|
@@ -233,13 +239,30 @@ Dev options:
|
|
|
233
239
|
Build options:
|
|
234
240
|
--init <path> Init hook module (default export, async function)
|
|
235
241
|
--out-dir <path> Output directory (default: dist)
|
|
236
|
-
--out-name <name> Output filename without extension (default:
|
|
242
|
+
--out-name <name> Output filename without extension (default: app)
|
|
237
243
|
--format <cjs|esm> Output format (default: cjs)
|
|
238
244
|
--target <target> Compilation target (default: node22)
|
|
239
245
|
--external <pkg> Mark package as external (repeatable; express always external)
|
|
240
246
|
--no-clean Don't clean the output directory before building
|
|
241
247
|
|
|
242
248
|
Start options:
|
|
249
|
+
--port <number> Port or named pipe (default: process.env.PORT or 8080)
|
|
250
|
+
--host <hostname> Hostname to bind (default: process.env.HOST or 0.0.0.0)
|
|
251
|
+
--no-signals Disable SIGINT/SIGTERM handler registration
|
|
252
|
+
--shutdown-timeout <ms> Max ms to wait for in-flight requests (default: 5000)
|
|
253
|
+
--require <module> Module(s) to preload before app load (repeatable)
|
|
254
|
+
--env <path> Env file(s) to load (repeatable; existing env vars are not overridden)
|
|
255
|
+
|
|
256
|
+
Build-serverless options:
|
|
257
|
+
--init <path> Init hook module (default export, async function)
|
|
258
|
+
--out-dir <path> Output directory (default: dist)
|
|
259
|
+
--out-name <name> Output filename without extension (default: handler)
|
|
260
|
+
--format <cjs|esm> Output format (default: cjs)
|
|
261
|
+
--target <target> Compilation target (default: node22)
|
|
262
|
+
--external <pkg> Mark package as external (repeatable; express always external)
|
|
263
|
+
--no-clean Don't clean the output directory before building
|
|
264
|
+
|
|
265
|
+
Start-serverless options:
|
|
243
266
|
--port <number> Port or named pipe (default: process.env.PORT or 8080)
|
|
244
267
|
--host <hostname> Hostname to bind (default: process.env.HOST or 0.0.0.0)
|
|
245
268
|
--no-signals Disable SIGINT/SIGTERM handler registration
|
|
@@ -255,10 +278,12 @@ Examples:
|
|
|
255
278
|
wtt-express-runtime dev ./dist/app.js
|
|
256
279
|
wtt-express-runtime dev ./dist/app.js --port 3000 --host localhost
|
|
257
280
|
wtt-express-runtime dev ./src/app.ts --env .env --require tsconfig-paths/register --watch ./src,./shared
|
|
258
|
-
wtt-express-runtime build ./src/app.ts --out-dir
|
|
259
|
-
wtt-express-runtime
|
|
260
|
-
wtt-express-runtime
|
|
261
|
-
wtt-express-runtime build ./src/app.ts
|
|
281
|
+
wtt-express-runtime build ./src/app.ts --out-dir dist
|
|
282
|
+
wtt-express-runtime start ./dist/app.js --port 3000 --env .env
|
|
283
|
+
wtt-express-runtime build-serverless ./src/app.ts --out-dir netlify/functions
|
|
284
|
+
wtt-express-runtime build-serverless ./src/app.ts --init ./src/init.ts --format esm
|
|
285
|
+
wtt-express-runtime start-serverless ./netlify/functions/handler.js --port 9000 --env .env
|
|
286
|
+
wtt-express-runtime build-serverless ./src/app.ts && wtt-express-runtime start-serverless ./dist/handler.js
|
|
262
287
|
|
|
263
288
|
Notes:
|
|
264
289
|
- In dev mode, the CLI evaluates arbitrary code from <app-module> in the current process.
|
|
@@ -269,9 +294,11 @@ Notes:
|
|
|
269
294
|
For advanced dotenv features (multiline, expansion), --require dotenv/config instead.
|
|
270
295
|
- --watch forks a child process running the same CLI without --watch. On file change,
|
|
271
296
|
the child is killed (SIGTERM) and respawned after the debounce delay.
|
|
272
|
-
- In build mode, express is always external. Add more externals with --external.
|
|
273
|
-
- In start mode, the bundled
|
|
274
|
-
|
|
297
|
+
- In build/build-serverless mode, express is always external. Add more externals with --external.
|
|
298
|
+
- In start mode, the bundled app file must default-export an Express app (or export it as "app").
|
|
299
|
+
If the bundle exports "init", it runs before the server starts listening.
|
|
300
|
+
- In start-serverless mode, the bundled handler file must be a JS/CJS module whose
|
|
301
|
+
"handler" export (or default export) is a function: (event, context) => Promise<result>.
|
|
275
302
|
- Init logic for dev mode (DB connections, etc.): add at the top level of your app module.
|
|
276
303
|
`);
|
|
277
304
|
}
|
|
@@ -282,10 +309,8 @@ function isHelp(arg) {
|
|
|
282
309
|
return arg === "-h" || arg === "--help";
|
|
283
310
|
}
|
|
284
311
|
function isSubcommand(arg) {
|
|
285
|
-
return arg === "dev" || arg === "build" || arg === "start";
|
|
312
|
+
return arg === "dev" || arg === "build" || arg === "start" || arg === "build-serverless" || arg === "start-serverless";
|
|
286
313
|
}
|
|
287
|
-
var DEFAULT_WATCH_EXTENSIONS = ["ts", "js", "mjs", "cjs", "json"];
|
|
288
|
-
var DEFAULT_WATCH_DELAY = 500;
|
|
289
314
|
function parseRepeatable(argv, index, arg, list) {
|
|
290
315
|
const value = readValue(argv, index, arg);
|
|
291
316
|
for (const part of value.split(",")) {
|
|
@@ -423,13 +448,25 @@ function parseDevArgs(argv) {
|
|
|
423
448
|
watchDelay: watchDelay ?? DEFAULT_WATCH_DELAY
|
|
424
449
|
};
|
|
425
450
|
}
|
|
426
|
-
function
|
|
451
|
+
function parseStartLikeArgs(argv, subcommandName) {
|
|
427
452
|
for (const arg of argv) {
|
|
428
453
|
if (arg === "--watch" || arg.startsWith("--watch=") || arg === "--ext" || arg.startsWith("--ext=") || arg === "--delay" || arg.startsWith("--delay=")) {
|
|
429
|
-
throw new Error(`--watch/--ext/--delay are not supported with the
|
|
454
|
+
throw new Error(`--watch/--ext/--delay are not supported with the ${subcommandName} subcommand`);
|
|
430
455
|
}
|
|
431
456
|
}
|
|
432
|
-
|
|
457
|
+
return parseDevArgs(argv);
|
|
458
|
+
}
|
|
459
|
+
function parseStartArgs(argv) {
|
|
460
|
+
const result = parseStartLikeArgs(argv, "start");
|
|
461
|
+
return {
|
|
462
|
+
appPath: result.appPath,
|
|
463
|
+
options: result.options,
|
|
464
|
+
require: result.require,
|
|
465
|
+
env: result.env
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
function parseStartServerlessArgs(argv) {
|
|
469
|
+
const result = parseStartLikeArgs(argv, "start-serverless");
|
|
433
470
|
return {
|
|
434
471
|
handlerPath: result.appPath,
|
|
435
472
|
options: result.options,
|
|
@@ -437,13 +474,13 @@ function parseStartArgs(argv) {
|
|
|
437
474
|
env: result.env
|
|
438
475
|
};
|
|
439
476
|
}
|
|
440
|
-
function parseBuildArgs(argv) {
|
|
477
|
+
function parseBuildArgs(argv, outNameDefault) {
|
|
441
478
|
let appPath;
|
|
442
479
|
const external = [];
|
|
443
480
|
const result = {
|
|
444
481
|
initPath: void 0,
|
|
445
482
|
outDir: "dist",
|
|
446
|
-
outName:
|
|
483
|
+
outName: outNameDefault,
|
|
447
484
|
format: "cjs",
|
|
448
485
|
target: "node22",
|
|
449
486
|
external,
|
|
@@ -538,6 +575,12 @@ function parseBuildArgs(argv) {
|
|
|
538
575
|
}
|
|
539
576
|
return { appPath, ...result };
|
|
540
577
|
}
|
|
578
|
+
function parseLocalBuildArgs(argv) {
|
|
579
|
+
return parseBuildArgs(argv, "app");
|
|
580
|
+
}
|
|
581
|
+
function parseBuildServerlessArgs(argv) {
|
|
582
|
+
return parseBuildArgs(argv, "handler");
|
|
583
|
+
}
|
|
541
584
|
function parseArgs(argv) {
|
|
542
585
|
if (argv.length === 0) {
|
|
543
586
|
printHelp();
|
|
@@ -557,10 +600,16 @@ function parseArgs(argv) {
|
|
|
557
600
|
if (first === "dev") {
|
|
558
601
|
return { subcommand: "dev", dev: parseDevArgs(rest) };
|
|
559
602
|
}
|
|
603
|
+
if (first === "build") {
|
|
604
|
+
return { subcommand: "build", build: parseLocalBuildArgs(rest) };
|
|
605
|
+
}
|
|
560
606
|
if (first === "start") {
|
|
561
607
|
return { subcommand: "start", start: parseStartArgs(rest) };
|
|
562
608
|
}
|
|
563
|
-
|
|
609
|
+
if (first === "build-serverless") {
|
|
610
|
+
return { subcommand: "build-serverless", buildServerless: parseBuildServerlessArgs(rest) };
|
|
611
|
+
}
|
|
612
|
+
return { subcommand: "start-serverless", startServerless: parseStartServerlessArgs(rest) };
|
|
564
613
|
}
|
|
565
614
|
return { subcommand: "dev", dev: parseDevArgs(argv) };
|
|
566
615
|
}
|
|
@@ -634,9 +683,6 @@ function loadEnvFiles(paths) {
|
|
|
634
683
|
}
|
|
635
684
|
}
|
|
636
685
|
}
|
|
637
|
-
var moduleRequire = (0, import_node_module.createRequire)(
|
|
638
|
-
typeof import_meta !== "undefined" && import_meta.url || (0, import_node_path.resolve)(process.cwd(), "x").replace(/x$/, "")
|
|
639
|
-
);
|
|
640
686
|
async function preloadModules(modules) {
|
|
641
687
|
for (const mod of modules) {
|
|
642
688
|
moduleRequire(mod);
|
|
@@ -716,7 +762,6 @@ function runWithWatch(args) {
|
|
|
716
762
|
process.on("SIGTERM", shutdown);
|
|
717
763
|
spawnChild();
|
|
718
764
|
}
|
|
719
|
-
var TEMP_ENTRY_FILENAME = ".express-runtime-build-entry.ts";
|
|
720
765
|
function generateServerlessEntry(appPath, initPath) {
|
|
721
766
|
const absAppPath = (0, import_node_path.resolve)(process.cwd(), appPath);
|
|
722
767
|
const absInitPath = initPath ? (0, import_node_path.resolve)(process.cwd(), initPath) : void 0;
|
|
@@ -734,16 +779,28 @@ function generateServerlessEntry(appPath, initPath) {
|
|
|
734
779
|
lines.push(`export { handler };`);
|
|
735
780
|
return lines.join("\n") + "\n";
|
|
736
781
|
}
|
|
737
|
-
|
|
782
|
+
function generateRuntimeEntry(appPath, initPath) {
|
|
783
|
+
const absAppPath = (0, import_node_path.resolve)(process.cwd(), appPath);
|
|
784
|
+
const absInitPath = initPath ? (0, import_node_path.resolve)(process.cwd(), initPath) : void 0;
|
|
785
|
+
const lines = [
|
|
786
|
+
"// Auto-generated by @web-ts-toolkit/express-runtime CLI \u2014 do not edit.",
|
|
787
|
+
`import app from ${JSON.stringify(absAppPath)};`,
|
|
788
|
+
"export default app;",
|
|
789
|
+
"export { app };"
|
|
790
|
+
];
|
|
791
|
+
if (absInitPath) {
|
|
792
|
+
lines.push(`export { default as init } from ${JSON.stringify(absInitPath)};`);
|
|
793
|
+
}
|
|
794
|
+
return lines.join("\n") + "\n";
|
|
795
|
+
}
|
|
796
|
+
async function buildBundleFromEntryContent(args) {
|
|
738
797
|
const tsupModule = await import("tsup");
|
|
739
798
|
const { build } = tsupModule;
|
|
740
|
-
const
|
|
741
|
-
|
|
742
|
-
(0, import_node_fs.writeFileSync)(tempEntryPath, entryContent, "utf8");
|
|
799
|
+
const tempEntryPath = (0, import_node_path.resolve)(process.cwd(), args.tempEntryFilename);
|
|
800
|
+
(0, import_node_fs.writeFileSync)(tempEntryPath, args.entryContent, "utf8");
|
|
743
801
|
try {
|
|
744
802
|
await build({
|
|
745
803
|
config: false,
|
|
746
|
-
// Don't auto-load tsup.config.ts from cwd
|
|
747
804
|
entry: { [args.outName]: tempEntryPath },
|
|
748
805
|
format: [args.format],
|
|
749
806
|
target: args.target,
|
|
@@ -758,6 +815,20 @@ async function buildServerless(args) {
|
|
|
758
815
|
(0, import_node_fs.rmSync)(tempEntryPath, { force: true });
|
|
759
816
|
}
|
|
760
817
|
}
|
|
818
|
+
async function buildRuntime(args) {
|
|
819
|
+
const { runBuildEntryCommand: runBuildEntryCommand2 } = await Promise.resolve().then(() => (init_cli_api(), cli_api_exports));
|
|
820
|
+
await runBuildEntryCommand2(args, {
|
|
821
|
+
generateEntry: generateRuntimeEntry,
|
|
822
|
+
tempEntryFilename: TEMP_BUILD_ENTRY_FILENAME
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
async function buildServerless(args) {
|
|
826
|
+
const { runBuildEntryCommand: runBuildEntryCommand2 } = await Promise.resolve().then(() => (init_cli_api(), cli_api_exports));
|
|
827
|
+
await runBuildEntryCommand2(args, {
|
|
828
|
+
generateEntry: generateServerlessEntry,
|
|
829
|
+
tempEntryFilename: TEMP_SERVERLESS_ENTRY_FILENAME
|
|
830
|
+
});
|
|
831
|
+
}
|
|
761
832
|
function collectBody(req) {
|
|
762
833
|
return new Promise((resolve, reject) => {
|
|
763
834
|
const chunks = [];
|
|
@@ -816,6 +887,25 @@ function createServerlessAdapterApp(handler) {
|
|
|
816
887
|
}
|
|
817
888
|
});
|
|
818
889
|
}
|
|
890
|
+
async function loadBuiltApp(appPath) {
|
|
891
|
+
const fullPath = (0, import_node_path.resolve)(process.cwd(), appPath);
|
|
892
|
+
const moduleUrl = (0, import_node_url.pathToFileURL)(fullPath).href;
|
|
893
|
+
const mod = await import(moduleUrl);
|
|
894
|
+
const exported = extractExport(mod);
|
|
895
|
+
if (!exported) {
|
|
896
|
+
throw new Error(
|
|
897
|
+
`Module "${appPath}" must default-export an Express app or export it as "app". Exports: ${Object.keys(mod).join(", ")}`
|
|
898
|
+
);
|
|
899
|
+
}
|
|
900
|
+
const init = mod.init;
|
|
901
|
+
if (init !== void 0 && typeof init !== "function") {
|
|
902
|
+
throw new Error(`Module "${appPath}" must export "init" as a function when present.`);
|
|
903
|
+
}
|
|
904
|
+
return {
|
|
905
|
+
app: await resolveExport(exported, appPath),
|
|
906
|
+
init
|
|
907
|
+
};
|
|
908
|
+
}
|
|
819
909
|
async function loadHandler(handlerPath) {
|
|
820
910
|
const fullPath = (0, import_node_path.resolve)(process.cwd(), handlerPath);
|
|
821
911
|
const moduleUrl = (0, import_node_url.pathToFileURL)(fullPath).href;
|
|
@@ -828,37 +918,148 @@ async function loadHandler(handlerPath) {
|
|
|
828
918
|
}
|
|
829
919
|
return exported;
|
|
830
920
|
}
|
|
921
|
+
var import_node_url, import_node_path, import_node_fs, import_node_module, import_node_child_process, import_meta, CLI_VERSION, DEFAULT_WATCH_EXTENSIONS, DEFAULT_WATCH_DELAY, moduleRequire, TEMP_BUILD_ENTRY_FILENAME, TEMP_SERVERLESS_ENTRY_FILENAME;
|
|
922
|
+
var init_cli_utils = __esm({
|
|
923
|
+
"src/cli-utils.ts"() {
|
|
924
|
+
"use strict";
|
|
925
|
+
import_node_url = require("url");
|
|
926
|
+
import_node_path = require("path");
|
|
927
|
+
import_node_fs = require("fs");
|
|
928
|
+
import_node_module = require("module");
|
|
929
|
+
import_node_child_process = require("child_process");
|
|
930
|
+
init_src();
|
|
931
|
+
import_meta = {};
|
|
932
|
+
CLI_VERSION = "0.0.0-PLACEHOLDER";
|
|
933
|
+
DEFAULT_WATCH_EXTENSIONS = ["ts", "js", "mjs", "cjs", "json"];
|
|
934
|
+
DEFAULT_WATCH_DELAY = 500;
|
|
935
|
+
moduleRequire = (0, import_node_module.createRequire)(
|
|
936
|
+
typeof import_meta !== "undefined" && import_meta.url || (0, import_node_path.resolve)(process.cwd(), "x").replace(/x$/, "")
|
|
937
|
+
);
|
|
938
|
+
TEMP_BUILD_ENTRY_FILENAME = ".express-runtime-build-entry.ts";
|
|
939
|
+
TEMP_SERVERLESS_ENTRY_FILENAME = ".express-runtime-build-serverless-entry.ts";
|
|
940
|
+
}
|
|
941
|
+
});
|
|
831
942
|
|
|
832
|
-
// src/cli.ts
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
943
|
+
// src/cli-api.ts
|
|
944
|
+
var cli_api_exports = {};
|
|
945
|
+
__export(cli_api_exports, {
|
|
946
|
+
CLI_VERSION: () => CLI_VERSION,
|
|
947
|
+
applyServerlessResult: () => applyServerlessResult,
|
|
948
|
+
buildBundleFromEntryContent: () => buildBundleFromEntryContent,
|
|
949
|
+
buildChildArgs: () => buildChildArgs,
|
|
950
|
+
buildRuntime: () => buildRuntime,
|
|
951
|
+
buildServerless: () => buildServerless,
|
|
952
|
+
createServerlessAdapterApp: () => createServerlessAdapterApp,
|
|
953
|
+
extractExport: () => extractExport,
|
|
954
|
+
generateRuntimeEntry: () => generateRuntimeEntry,
|
|
955
|
+
generateServerlessEntry: () => generateServerlessEntry,
|
|
956
|
+
isExpressApp: () => isExpressApp,
|
|
957
|
+
loadApp: () => loadApp,
|
|
958
|
+
loadBuiltApp: () => loadBuiltApp,
|
|
959
|
+
loadEnvFiles: () => loadEnvFiles,
|
|
960
|
+
loadHandler: () => loadHandler,
|
|
961
|
+
parseArgs: () => parseArgs,
|
|
962
|
+
parseEnvFile: () => parseEnvFile,
|
|
963
|
+
preloadModules: () => preloadModules,
|
|
964
|
+
printHelp: () => printHelp,
|
|
965
|
+
readValue: () => readValue,
|
|
966
|
+
resolveExport: () => resolveExport,
|
|
967
|
+
runBuildEntryCommand: () => runBuildEntryCommand,
|
|
968
|
+
runCliCommand: () => runCliCommand,
|
|
969
|
+
runDevCommand: () => runDevCommand,
|
|
970
|
+
runExpressDevCommand: () => runExpressDevCommand,
|
|
971
|
+
runWithWatch: () => runWithWatch,
|
|
972
|
+
toServerlessEvent: () => toServerlessEvent
|
|
973
|
+
});
|
|
974
|
+
async function runDevCommand(args, runner) {
|
|
975
|
+
if (args.watch.length > 0) {
|
|
976
|
+
(runner.watch ?? runWithWatch)(args);
|
|
836
977
|
return;
|
|
837
978
|
}
|
|
979
|
+
if (args.env.length > 0) {
|
|
980
|
+
loadEnvFiles(args.env);
|
|
981
|
+
}
|
|
982
|
+
await preloadModules(args.require);
|
|
983
|
+
const loaded = await runner.load(args.appPath);
|
|
984
|
+
runner.start(loaded, { ...args.options, exitAfterShutdown: true });
|
|
985
|
+
}
|
|
986
|
+
async function runExpressDevCommand(args) {
|
|
987
|
+
await runDevCommand(args, {
|
|
988
|
+
load: loadApp,
|
|
989
|
+
start: (app, options) => {
|
|
990
|
+
startLocalServer(app, options);
|
|
991
|
+
}
|
|
992
|
+
});
|
|
993
|
+
}
|
|
994
|
+
async function runBuildEntryCommand(args, options) {
|
|
995
|
+
if (options.allowInit === false && args.initPath) {
|
|
996
|
+
throw new Error(options.initErrorMessage ?? "This build command manages init automatically. Remove --init.");
|
|
997
|
+
}
|
|
998
|
+
await buildBundleFromEntryContent({
|
|
999
|
+
entryContent: options.generateEntry(args.appPath, args.initPath),
|
|
1000
|
+
tempEntryFilename: options.tempEntryFilename,
|
|
1001
|
+
outDir: args.outDir,
|
|
1002
|
+
outName: args.outName,
|
|
1003
|
+
format: args.format,
|
|
1004
|
+
target: args.target,
|
|
1005
|
+
external: args.external,
|
|
1006
|
+
clean: args.clean
|
|
1007
|
+
});
|
|
1008
|
+
}
|
|
1009
|
+
async function runCliCommand(parsedArgs) {
|
|
838
1010
|
if (parsedArgs.subcommand === "dev") {
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
}
|
|
844
|
-
if (dev.env.length > 0) {
|
|
845
|
-
loadEnvFiles(dev.env);
|
|
846
|
-
}
|
|
847
|
-
await preloadModules(dev.require);
|
|
848
|
-
const app = await loadApp(dev.appPath);
|
|
849
|
-
startLocalServer(app, { ...dev.options, exitAfterShutdown: true });
|
|
850
|
-
} else if (parsedArgs.subcommand === "start") {
|
|
1011
|
+
await runExpressDevCommand(parsedArgs.dev);
|
|
1012
|
+
return;
|
|
1013
|
+
}
|
|
1014
|
+
if (parsedArgs.subcommand === "start") {
|
|
851
1015
|
const { start } = parsedArgs;
|
|
852
1016
|
if (start.env.length > 0) {
|
|
853
1017
|
loadEnvFiles(start.env);
|
|
854
1018
|
}
|
|
855
1019
|
await preloadModules(start.require);
|
|
856
|
-
const
|
|
1020
|
+
const { app, init } = await loadBuiltApp(start.appPath);
|
|
1021
|
+
startLocalServer(app, {
|
|
1022
|
+
...start.options,
|
|
1023
|
+
init: init ? async () => {
|
|
1024
|
+
await init();
|
|
1025
|
+
} : void 0,
|
|
1026
|
+
exitAfterShutdown: true
|
|
1027
|
+
});
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1030
|
+
if (parsedArgs.subcommand === "build") {
|
|
1031
|
+
await buildRuntime(parsedArgs.build);
|
|
1032
|
+
return;
|
|
1033
|
+
}
|
|
1034
|
+
if (parsedArgs.subcommand === "start-serverless") {
|
|
1035
|
+
const { startServerless } = parsedArgs;
|
|
1036
|
+
if (startServerless.env.length > 0) {
|
|
1037
|
+
loadEnvFiles(startServerless.env);
|
|
1038
|
+
}
|
|
1039
|
+
await preloadModules(startServerless.require);
|
|
1040
|
+
const handler = await loadHandler(startServerless.handlerPath);
|
|
857
1041
|
const app = createServerlessAdapterApp(handler);
|
|
858
|
-
startLocalServer(app, { ...
|
|
859
|
-
|
|
860
|
-
|
|
1042
|
+
startLocalServer(app, { ...startServerless.options, exitAfterShutdown: true });
|
|
1043
|
+
return;
|
|
1044
|
+
}
|
|
1045
|
+
await buildServerless(parsedArgs.buildServerless);
|
|
1046
|
+
}
|
|
1047
|
+
var init_cli_api = __esm({
|
|
1048
|
+
"src/cli-api.ts"() {
|
|
1049
|
+
"use strict";
|
|
1050
|
+
init_src();
|
|
1051
|
+
init_cli_utils();
|
|
1052
|
+
}
|
|
1053
|
+
});
|
|
1054
|
+
|
|
1055
|
+
// src/cli.ts
|
|
1056
|
+
init_cli_api();
|
|
1057
|
+
async function main() {
|
|
1058
|
+
const parsedArgs = parseArgs(process.argv.slice(2));
|
|
1059
|
+
if (!parsedArgs) {
|
|
1060
|
+
return;
|
|
861
1061
|
}
|
|
1062
|
+
await runCliCommand(parsedArgs);
|
|
862
1063
|
}
|
|
863
1064
|
main().catch((error) => {
|
|
864
1065
|
const message = error instanceof Error ? error.message : String(error);
|