@vercel/express 0.0.18 → 0.0.20

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 (2) hide show
  1. package/dist/index.js +639 -9
  2. package/package.json +9 -4
package/dist/index.js CHANGED
@@ -6,8 +6,8 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
8
  var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
9
+ for (var name2 in all)
10
+ __defProp(target, name2, { get: all[name2], enumerable: true });
11
11
  };
12
12
  var __copyProps = (to, from, except, desc) => {
13
13
  if (from && typeof from === "object" || typeof from === "function") {
@@ -32,11 +32,14 @@ var src_exports = {};
32
32
  __export(src_exports, {
33
33
  build: () => build,
34
34
  entrypointCallback: () => entrypointCallback,
35
+ experimentalBuild: () => build2,
36
+ experimentalVersion: () => version,
35
37
  findEntrypoint: () => findEntrypoint,
38
+ name: () => name,
36
39
  require_: () => require_,
37
40
  shouldServe: () => shouldServe,
38
41
  startDevServer: () => startDevServer,
39
- version: () => version
42
+ version: () => version2
40
43
  });
41
44
  module.exports = __toCommonJS(src_exports);
42
45
 
@@ -80,20 +83,20 @@ var build = async (args) => {
80
83
  return entrypointCallback(args);
81
84
  }
82
85
  });
83
- let version2 = void 0;
86
+ let version3 = void 0;
84
87
  try {
85
88
  const resolved = require_.resolve(`${frameworkName}/package.json`, {
86
89
  paths: [args.workPath]
87
90
  });
88
91
  const expressVersion = require_(resolved).version;
89
92
  if (expressVersion) {
90
- version2 = expressVersion;
93
+ version3 = expressVersion;
91
94
  }
92
95
  } catch (e) {
93
96
  }
94
97
  res.output.framework = {
95
98
  slug: frameworkName,
96
- version: version2
99
+ version: version3
97
100
  };
98
101
  return res;
99
102
  };
@@ -202,9 +205,633 @@ var findMainPackageEntrypoint = (files) => {
202
205
  return null;
203
206
  };
204
207
 
205
- // src/index.ts
208
+ // src/experimental/build.ts
209
+ var import_build_utils6 = require("@vercel/build-utils");
210
+
211
+ // src/experimental/utils.ts
212
+ var import_path2 = require("path");
213
+ var import_build_utils2 = require("@vercel/build-utils");
214
+ async function downloadInstallAndBundle(args) {
215
+ const { entrypoint, files, workPath, meta, config } = args;
216
+ await (0, import_build_utils2.download)(files, workPath, meta);
217
+ const entrypointFsDirname = (0, import_path2.join)(workPath, (0, import_path2.dirname)(entrypoint));
218
+ const nodeVersion = await (0, import_build_utils2.getNodeVersion)(
219
+ entrypointFsDirname,
220
+ void 0,
221
+ config,
222
+ meta
223
+ );
224
+ const spawnOpts = (0, import_build_utils2.getSpawnOptions)(meta || {}, nodeVersion);
225
+ const {
226
+ cliType,
227
+ lockfileVersion,
228
+ packageJsonPackageManager,
229
+ turboSupportsCorepackHome
230
+ } = await (0, import_build_utils2.scanParentDirs)(entrypointFsDirname, true);
231
+ spawnOpts.env = (0, import_build_utils2.getEnvForPackageManager)({
232
+ cliType,
233
+ lockfileVersion,
234
+ packageJsonPackageManager,
235
+ nodeVersion,
236
+ env: spawnOpts.env || {},
237
+ turboSupportsCorepackHome,
238
+ projectCreatedAt: config.projectSettings?.createdAt
239
+ });
240
+ const installCommand = config.projectSettings?.installCommand;
241
+ if (typeof installCommand === "string") {
242
+ if (installCommand.trim()) {
243
+ console.log(`Running "install" command: \`${installCommand}\`...`);
244
+ await (0, import_build_utils2.execCommand)(installCommand, {
245
+ ...spawnOpts,
246
+ cwd: entrypointFsDirname
247
+ });
248
+ } else {
249
+ console.log(`Skipping "install" command...`);
250
+ }
251
+ } else {
252
+ await (0, import_build_utils2.runNpmInstall)(
253
+ entrypointFsDirname,
254
+ [],
255
+ spawnOpts,
256
+ meta,
257
+ nodeVersion,
258
+ config.projectSettings?.createdAt
259
+ );
260
+ }
261
+ return { entrypointFsDirname, nodeVersion, spawnOpts };
262
+ }
263
+ async function maybeExecBuildCommand(args, options) {
264
+ const projectBuildCommand = args.config.projectSettings?.buildCommand;
265
+ if (projectBuildCommand) {
266
+ await (0, import_build_utils2.execCommand)(projectBuildCommand, {
267
+ ...options.spawnOpts,
268
+ cwd: args.workPath
269
+ });
270
+ } else {
271
+ const possibleScripts = ["build"];
272
+ await (0, import_build_utils2.runPackageJsonScript)(
273
+ options.entrypointFsDirname,
274
+ possibleScripts,
275
+ options.spawnOpts,
276
+ args.config.projectSettings?.createdAt
277
+ );
278
+ }
279
+ }
280
+
281
+ // src/experimental/rolldown.ts
282
+ var import_build_utils3 = require("@vercel/build-utils");
283
+ var import_nft = require("@vercel/nft");
284
+ var import_fs2 = require("fs");
285
+ var import_path3 = require("path");
286
+ var import_rolldown = require("rolldown");
287
+ var rolldown = async (args) => {
288
+ const baseDir = args.repoRootPath || args.workPath;
289
+ const entrypointPath = (0, import_path3.join)(args.workPath, args.entrypoint);
290
+ const files = {};
291
+ const shouldAddSourcemapSupport = false;
292
+ const extension = (0, import_path3.extname)(args.entrypoint);
293
+ const extensionMap = {
294
+ ".ts": { format: "auto", extension: "js" },
295
+ ".mts": { format: "esm", extension: "mjs" },
296
+ ".cts": { format: "cjs", extension: "cjs" },
297
+ ".cjs": { format: "cjs", extension: "cjs" },
298
+ ".js": { format: "auto", extension: "js" },
299
+ ".mjs": { format: "esm", extension: "mjs" }
300
+ };
301
+ const extensionInfo = extensionMap[extension] || extensionMap[".js"];
302
+ let format = extensionInfo.format;
303
+ const packageJsonPath = (0, import_path3.join)(args.workPath, "package.json");
304
+ const external = [];
305
+ if ((0, import_fs2.existsSync)(packageJsonPath)) {
306
+ const { mode } = (0, import_fs2.lstatSync)(packageJsonPath);
307
+ const source = (0, import_fs2.readFileSync)(packageJsonPath);
308
+ const relPath = (0, import_path3.relative)(baseDir, packageJsonPath);
309
+ let pkg;
310
+ try {
311
+ pkg = JSON.parse(source.toString());
312
+ } catch (_e) {
313
+ pkg = {};
314
+ }
315
+ if (format === "auto") {
316
+ if (pkg.type === "module") {
317
+ format = "esm";
318
+ } else {
319
+ format = "cjs";
320
+ }
321
+ }
322
+ for (const dependency of Object.keys(pkg.dependencies || {})) {
323
+ external.push(dependency);
324
+ }
325
+ for (const dependency of Object.keys(pkg.devDependencies || {})) {
326
+ external.push(dependency);
327
+ }
328
+ for (const dependency of Object.keys(pkg.peerDependencies || {})) {
329
+ external.push(dependency);
330
+ }
331
+ for (const dependency of Object.keys(pkg.optionalDependencies || {})) {
332
+ external.push(dependency);
333
+ }
334
+ files[relPath] = new import_build_utils3.FileBlob({ data: source, mode });
335
+ }
336
+ const absoluteImportPlugin = {
337
+ name: "absolute-import-resolver",
338
+ resolveId(source) {
339
+ if (external.includes(source)) {
340
+ return { id: source, external: true };
341
+ }
342
+ return null;
343
+ }
344
+ };
345
+ let tsconfigPath = (0, import_path3.join)(baseDir, "tsconfig.json");
346
+ if (!(0, import_fs2.existsSync)(tsconfigPath)) {
347
+ tsconfigPath = await (0, import_build_utils3.walkParentDirs)({
348
+ base: baseDir,
349
+ start: args.workPath,
350
+ filename: "tsconfig.json"
351
+ });
352
+ }
353
+ const relativeOutputDir = (0, import_path3.join)(
354
+ ".vercel",
355
+ "output",
356
+ "functions",
357
+ "index.func"
358
+ );
359
+ const outputDir = (0, import_path3.join)(baseDir, relativeOutputDir);
360
+ let handler = null;
361
+ await (0, import_rolldown.build)({
362
+ input: entrypointPath,
363
+ cwd: baseDir,
364
+ platform: "node",
365
+ external: /node_modules/,
366
+ plugins: [absoluteImportPlugin],
367
+ tsconfig: tsconfigPath || void 0,
368
+ output: {
369
+ dir: outputDir,
370
+ // FIXME: This is a bit messy, not sure what facadeModuleId even is and the only reason for renaming here
371
+ // is to preserve the proper extension for mjs/cjs scenario.
372
+ // There doesn't seem to be another way to do only specify the entrypoint extension.
373
+ entryFileNames: (info) => {
374
+ if (info.name === "rolldown_runtime") {
375
+ return "rolldown_runtime.js";
376
+ }
377
+ const facadeModuleId = info.facadeModuleId;
378
+ if (!facadeModuleId) {
379
+ throw new Error(`Unable to resolve module for ${info.name}`);
380
+ }
381
+ const relPath = (0, import_path3.relative)(baseDir, facadeModuleId);
382
+ const extension2 = (0, import_path3.extname)(relPath);
383
+ const extensionMap2 = {
384
+ ".ts": ".js",
385
+ ".mts": ".mjs",
386
+ ".mjs": ".mjs",
387
+ ".cts": ".cjs",
388
+ ".cjs": ".cjs",
389
+ ".js": ".js"
390
+ };
391
+ const ext = extensionMap2[extension2] || ".js";
392
+ const nameWithJS = relPath.slice(0, -extension2.length) + ext;
393
+ if (info.isEntry) {
394
+ handler = nameWithJS;
395
+ }
396
+ return nameWithJS;
397
+ },
398
+ format,
399
+ preserveModules: true,
400
+ sourcemap: false
401
+ }
402
+ });
403
+ if (typeof handler !== "string") {
404
+ throw new Error(`Unable to resolve module for ${args.entrypoint}`);
405
+ }
406
+ const nftResult = await (0, import_nft.nodeFileTrace)([(0, import_path3.join)(outputDir, handler)], {
407
+ // This didn't work as I expected it to, didn't find node_modules
408
+ // base: outputDir,
409
+ // processCwd: outputDir,
410
+ ignore: args.config.excludeFiles
411
+ });
412
+ for (const file of nftResult.fileList) {
413
+ if (file.startsWith(relativeOutputDir)) {
414
+ continue;
415
+ }
416
+ files[file] = new import_build_utils3.FileFsRef({ fsPath: file, mode: 420 });
417
+ }
418
+ return {
419
+ files,
420
+ shouldAddSourcemapSupport,
421
+ handler,
422
+ outputDir
423
+ };
424
+ };
425
+
426
+ // src/experimental/find-entrypoint.ts
427
+ var import_build_utils4 = require("@vercel/build-utils");
206
428
  var import_node2 = require("@vercel/node");
207
- var version = 3;
429
+ var import_module2 = require("module");
430
+ var import_path4 = require("path");
431
+ var import_fs3 = __toESM(require("fs"));
432
+ var REGEX2 = /(?:from|require|import)\s*(?:\(\s*)?["']express["']\s*(?:\))?/g;
433
+ var validFilenames2 = [
434
+ "app",
435
+ "index",
436
+ "server",
437
+ "src/app",
438
+ "src/index",
439
+ "src/server"
440
+ ];
441
+ var require_2 = (0, import_module2.createRequire)(__filename);
442
+ var validExtensions2 = ["js", "cjs", "mjs", "ts", "cts", "mts"];
443
+ var entrypointsForMessage2 = validFilenames2.map((filename) => `- ${filename}.{${validExtensions2.join(",")}}`).join("\n");
444
+ var entrypointCallback2 = async (args) => {
445
+ const mainPackageEntrypoint = findMainPackageEntrypoint2(args.files);
446
+ const entrypointGlob = `{${validFilenames2.map((entrypoint) => `${entrypoint}`).join(",")}}.{${validExtensions2.join(",")}}`;
447
+ const dir = args.config.projectSettings?.outputDirectory?.replace(
448
+ /^\/+|\/+$/g,
449
+ ""
450
+ );
451
+ if (dir) {
452
+ const { entrypoint: entrypointFromOutputDir, entrypointsNotMatchingRegex: entrypointsNotMatchingRegex2 } = findEntrypoint2(await (0, import_build_utils4.glob)(entrypointGlob, (0, import_path4.join)(args.workPath, dir)));
453
+ if (entrypointFromOutputDir) {
454
+ return (0, import_path4.join)(dir, entrypointFromOutputDir);
455
+ }
456
+ if (entrypointsNotMatchingRegex2.length > 0) {
457
+ throw new Error(
458
+ `No entrypoint found which imports express. Found possible ${pluralize2("entrypoint", entrypointsNotMatchingRegex2.length)}: ${entrypointsNotMatchingRegex2.join(", ")}`
459
+ );
460
+ }
461
+ throw new Error(
462
+ `No entrypoint found in output directory: "${dir}". Searched for:
463
+ ${entrypointsForMessage2}`
464
+ );
465
+ }
466
+ const files = await (0, import_build_utils4.glob)(entrypointGlob, args.workPath);
467
+ const { entrypoint: entrypointFromRoot, entrypointsNotMatchingRegex } = findEntrypoint2(files);
468
+ if (entrypointFromRoot) {
469
+ return entrypointFromRoot;
470
+ }
471
+ if (mainPackageEntrypoint) {
472
+ const entrypointFromPackageJson = await (0, import_build_utils4.glob)(
473
+ mainPackageEntrypoint,
474
+ args.workPath
475
+ );
476
+ if (entrypointFromPackageJson[mainPackageEntrypoint]) {
477
+ if (checkMatchesRegex2(entrypointFromPackageJson[mainPackageEntrypoint])) {
478
+ return mainPackageEntrypoint;
479
+ }
480
+ }
481
+ }
482
+ if (entrypointsNotMatchingRegex.length > 0) {
483
+ throw new Error(
484
+ `No entrypoint found which imports express. Found possible ${pluralize2("entrypoint", entrypointsNotMatchingRegex.length)}: ${entrypointsNotMatchingRegex.join(", ")}`
485
+ );
486
+ }
487
+ throw new Error(
488
+ `No entrypoint found. Searched for:
489
+ ${entrypointsForMessage2}`
490
+ );
491
+ };
492
+ function pluralize2(word, count) {
493
+ return count === 1 ? word : `${word}s`;
494
+ }
495
+ var findEntrypoint2 = (files) => {
496
+ const allEntrypoints = validFilenames2.flatMap(
497
+ (filename) => validExtensions2.map((extension) => `${filename}.${extension}`)
498
+ );
499
+ const possibleEntrypointsInFiles = allEntrypoints.filter((entrypoint2) => {
500
+ return files[entrypoint2] !== void 0;
501
+ });
502
+ const entrypointsMatchingRegex = possibleEntrypointsInFiles.filter(
503
+ (entrypoint2) => {
504
+ const file = files[entrypoint2];
505
+ return checkMatchesRegex2(file);
506
+ }
507
+ );
508
+ const entrypointsNotMatchingRegex = possibleEntrypointsInFiles.filter(
509
+ (entrypoint2) => {
510
+ const file = files[entrypoint2];
511
+ return !checkMatchesRegex2(file);
512
+ }
513
+ );
514
+ const entrypoint = entrypointsMatchingRegex[0];
515
+ if (entrypointsMatchingRegex.length > 1) {
516
+ console.warn(
517
+ `Multiple entrypoints found: ${entrypointsMatchingRegex.join(", ")}. Using ${entrypoint}.`
518
+ );
519
+ }
520
+ return {
521
+ entrypoint,
522
+ entrypointsNotMatchingRegex
523
+ };
524
+ };
525
+ var checkMatchesRegex2 = (file) => {
526
+ const content = import_fs3.default.readFileSync(file.fsPath, "utf-8");
527
+ const matchesContent = content.match(REGEX2);
528
+ return matchesContent !== null;
529
+ };
530
+ var findMainPackageEntrypoint2 = (files) => {
531
+ const packageJson = files["package.json"];
532
+ if (packageJson) {
533
+ if (packageJson.type === "FileFsRef") {
534
+ const packageJsonContent = import_fs3.default.readFileSync(packageJson.fsPath, "utf-8");
535
+ let packageJsonJson;
536
+ try {
537
+ packageJsonJson = JSON.parse(packageJsonContent);
538
+ } catch (_e) {
539
+ packageJsonJson = {};
540
+ }
541
+ if ("main" in packageJsonJson && typeof packageJsonJson.main === "string") {
542
+ return packageJsonJson.main;
543
+ }
544
+ }
545
+ }
546
+ return null;
547
+ };
548
+
549
+ // src/experimental/introspection.ts
550
+ var import_build_utils5 = require("@vercel/build-utils");
551
+ var import_path5 = require("path");
552
+ var import_fs_extra = require("fs-extra");
553
+ var import_child_process = require("child_process");
554
+ var import_fs4 = require("fs");
555
+ var import_promises = require("fs/promises");
556
+ var import_module3 = require("module");
557
+ var import_path_to_regexp = require("path-to-regexp");
558
+ var import_zod = require("zod");
559
+ var require_3 = (0, import_module3.createRequire)(__filename);
560
+ var introspectApp = async (args, options) => {
561
+ const source = expressShimSource(options);
562
+ await (0, import_fs_extra.outputFile)(
563
+ (0, import_path5.join)(options.outputDir, "node_modules", "express", "index.js"),
564
+ source
565
+ );
566
+ await invokeFunction(args, options);
567
+ const {
568
+ routes: routesFromIntrospection,
569
+ views,
570
+ staticPaths
571
+ } = await processIntrospection(options);
572
+ await cleanup(options);
573
+ if (views) {
574
+ try {
575
+ const validatedViews = validatePath(views, args.workPath);
576
+ const viewFiles = await (0, import_build_utils5.glob)((0, import_path5.join)(validatedViews, "**/*"), args.workPath);
577
+ for (const [p, f] of Object.entries(viewFiles)) {
578
+ options.files[p] = f;
579
+ }
580
+ } catch (error) {
581
+ console.log(`Skipping invalid views path: ${views}`);
582
+ }
583
+ }
584
+ if (staticPaths) {
585
+ try {
586
+ const validatedStaticPaths = staticPaths.map(
587
+ (path) => validatePath(path, args.workPath)
588
+ );
589
+ for (const staticPath of validatedStaticPaths) {
590
+ const staticFiles = await (0, import_build_utils5.glob)((0, import_path5.join)(staticPath, "**/*"), args.workPath);
591
+ for (const [p, f] of Object.entries(staticFiles)) {
592
+ options.files[p] = f;
593
+ }
594
+ }
595
+ } catch (error) {
596
+ console.log(`Skipping invalid static paths: ${staticPaths}`);
597
+ }
598
+ }
599
+ const routes = [
600
+ {
601
+ handle: "filesystem"
602
+ },
603
+ ...routesFromIntrospection,
604
+ {
605
+ src: "/(.*)",
606
+ dest: "/"
607
+ }
608
+ ];
609
+ return { routes };
610
+ };
611
+ var cleanup = async (options) => {
612
+ await (0, import_promises.rm)((0, import_path5.join)(options.outputDir, "node_modules"), {
613
+ recursive: true,
614
+ force: true
615
+ });
616
+ await (0, import_promises.rm)(getIntrospectionPath(options), { force: true });
617
+ };
618
+ var processIntrospection = async (options) => {
619
+ const schema = import_zod.z.object({
620
+ routes: import_zod.z.record(
621
+ import_zod.z.string(),
622
+ import_zod.z.object({
623
+ methods: import_zod.z.array(import_zod.z.string())
624
+ })
625
+ ).transform(
626
+ (value) => Object.entries(value).map(([path, route]) => convertExpressRoute(path, route)).filter(Boolean)
627
+ ),
628
+ views: import_zod.z.string().optional(),
629
+ staticPaths: import_zod.z.array(import_zod.z.string()).optional(),
630
+ viewEngine: import_zod.z.string().optional()
631
+ });
632
+ try {
633
+ const introspectionPath = (0, import_path5.join)(options.outputDir, "introspection.json");
634
+ const introspection = (0, import_fs4.readFileSync)(introspectionPath, "utf8");
635
+ return schema.parse(JSON.parse(introspection));
636
+ } catch (error) {
637
+ console.log(
638
+ `Unable to extract routes from express, route level observability will not be available`
639
+ );
640
+ return {
641
+ routes: [],
642
+ views: void 0,
643
+ staticPaths: void 0,
644
+ viewEngine: void 0
645
+ };
646
+ }
647
+ };
648
+ var getIntrospectionPath = (options) => {
649
+ return (0, import_path5.join)(options.outputDir, "introspection.json");
650
+ };
651
+ var invokeFunction = async (args, options) => {
652
+ await new Promise((resolve2) => {
653
+ try {
654
+ const child = (0, import_child_process.spawn)("node", [(0, import_path5.join)(options.outputDir, options.handler)], {
655
+ stdio: ["pipe", "pipe", "pipe"],
656
+ cwd: options.outputDir,
657
+ env: {
658
+ ...process.env,
659
+ ...args.meta?.env || {},
660
+ ...args.meta?.buildEnv || {}
661
+ }
662
+ });
663
+ setTimeout(() => {
664
+ child.kill("SIGTERM");
665
+ }, 5e3);
666
+ child.on("error", () => {
667
+ console.log(
668
+ `Unable to extract routes from express, route level observability will not be available`
669
+ );
670
+ resolve2(void 0);
671
+ });
672
+ child.on("close", () => {
673
+ resolve2(void 0);
674
+ });
675
+ } catch (error) {
676
+ console.log(
677
+ `Unable to extract routes from express, route level observability will not be available`
678
+ );
679
+ resolve2(void 0);
680
+ }
681
+ });
682
+ };
683
+ var expressShimSource = (args) => {
684
+ const pathToExpress = require_3.resolve("express", {
685
+ paths: [args.outputDir]
686
+ });
687
+ const introspectionPath = getIntrospectionPath(args);
688
+ return `
689
+ const fs = require('fs');
690
+ const path = require('path');
691
+ const originalExpress = require(${JSON.stringify(pathToExpress)});
692
+
693
+ let app = null
694
+ let staticPaths = [];
695
+ let views = ''
696
+ let viewEngine = ''
697
+ const routes = {};
698
+ const originalStatic = originalExpress.static
699
+ originalExpress.static = (...args) => {
700
+ staticPaths.push(args[0]);
701
+ return originalStatic(...args);
702
+ }
703
+ function expressWrapper() {
704
+ app = originalExpress.apply(this, arguments);
705
+ return app;
706
+ }
707
+
708
+ // Copy all properties from the original express to the wrapper
709
+ Object.setPrototypeOf(expressWrapper, originalExpress);
710
+ Object.assign(expressWrapper, originalExpress);
711
+
712
+ // Preserve the original prototype
713
+ expressWrapper.prototype = originalExpress.prototype;
714
+
715
+ module.exports = expressWrapper;
716
+
717
+ let routesExtracted = false;
718
+
719
+ const extractRoutes = () => {
720
+ if (routesExtracted) {
721
+ return;
722
+ }
723
+ routesExtracted = true;
724
+
725
+ const methods = ["all", "get", "post", "put", "delete", "patch", "options", "head"]
726
+ if (!app) {
727
+ return;
728
+ }
729
+ const router = app._router || app.router
730
+ for (const route of router.stack) {
731
+ if(route.route) {
732
+ const m = [];
733
+ for (const method of methods) {
734
+ if(route.route.methods[method]) {
735
+ m.push(method.toUpperCase());
736
+ }
737
+ }
738
+ routes[route.route.path] = { methods: m };
739
+ }
740
+ }
741
+
742
+ views = app.settings.views
743
+ viewEngine = app.settings['view engine']
744
+
745
+ // Ensure directory exists
746
+ const dir = path.dirname(${JSON.stringify(introspectionPath)});
747
+ if (!fs.existsSync(dir)) {
748
+ fs.mkdirSync(dir, { recursive: true });
749
+ }
750
+
751
+ fs.writeFileSync(${JSON.stringify(introspectionPath)}, JSON.stringify({routes, views, staticPaths, viewEngine}, null, 2));
752
+ }
753
+
754
+ process.on('exit', () => {
755
+ extractRoutes()
756
+ });
757
+
758
+ process.on('SIGINT', () => {
759
+ extractRoutes()
760
+ process.exit(0);
761
+ });
762
+ // Write routes to file on SIGTERM
763
+ process.on('SIGTERM', () => {
764
+ extractRoutes()
765
+ process.exit(0);
766
+ });
767
+ `;
768
+ };
769
+ var convertExpressRoute = (route, routeData) => {
770
+ const { regexp } = (0, import_path_to_regexp.pathToRegexp)(route);
771
+ const dest = route;
772
+ if (dest === "/") {
773
+ return;
774
+ }
775
+ const src = regexp.source;
776
+ return {
777
+ src,
778
+ dest,
779
+ methods: routeData.methods
780
+ };
781
+ };
782
+ var validatePath = (inputPath, workPath) => {
783
+ if (inputPath.indexOf("\0") !== -1) {
784
+ throw new Error(`Path contains null bytes: ${inputPath}`);
785
+ }
786
+ const normalizedPath = (0, import_path5.normalize)(inputPath);
787
+ if (normalizedPath.includes("..")) {
788
+ throw new Error(
789
+ `Path contains directory traversal sequences: ${inputPath}`
790
+ );
791
+ }
792
+ if ((0, import_path5.isAbsolute)(normalizedPath)) {
793
+ throw new Error(`Absolute paths are not allowed: ${inputPath}`);
794
+ }
795
+ const resolvedPath = (0, import_path5.resolve)(workPath, normalizedPath);
796
+ const resolvedWorkPath = (0, import_path5.resolve)(workPath);
797
+ if (!resolvedPath.startsWith(resolvedWorkPath + import_path5.sep) && resolvedPath !== resolvedWorkPath) {
798
+ throw new Error(`Path escapes the intended directory: ${inputPath}`);
799
+ }
800
+ return normalizedPath;
801
+ };
802
+
803
+ // src/experimental/build.ts
804
+ var version = 2;
805
+ var build2 = async (args) => {
806
+ console.log(`Using experimental express build`);
807
+ const downloadResult = await downloadInstallAndBundle(args);
808
+ await maybeExecBuildCommand(args, downloadResult);
809
+ args.entrypoint = await entrypointCallback2(args);
810
+ const rolldownResult = await rolldown(args);
811
+ const { routes } = await introspectApp(args, rolldownResult);
812
+ const lambda = new import_build_utils6.Lambda({
813
+ runtime: downloadResult.nodeVersion.runtime,
814
+ ...rolldownResult
815
+ });
816
+ const output = { index: lambda };
817
+ for (const route of routes) {
818
+ if (route.dest) {
819
+ if (route.dest === "/") {
820
+ continue;
821
+ }
822
+ output[route.dest] = lambda;
823
+ }
824
+ }
825
+ return {
826
+ routes,
827
+ output
828
+ };
829
+ };
830
+
831
+ // src/index.ts
832
+ var import_node3 = require("@vercel/node");
833
+ var version2 = 3;
834
+ var name = "express";
208
835
  var shouldServe = async (opts) => {
209
836
  const requestPath = opts.requestPath.replace(/\/$/, "");
210
837
  if (requestPath.startsWith("api") && opts.hasMatched) {
@@ -215,7 +842,7 @@ var shouldServe = async (opts) => {
215
842
  var startDevServer = async (opts) => {
216
843
  const entrypoint = await entrypointCallback(opts);
217
844
  process.env.EXPERIMENTAL_NODE_TYPESCRIPT_ERRORS = "1";
218
- return (0, import_node2.startDevServer)({
845
+ return (0, import_node3.startDevServer)({
219
846
  ...opts,
220
847
  entrypoint,
221
848
  publicDir: "public"
@@ -225,7 +852,10 @@ var startDevServer = async (opts) => {
225
852
  0 && (module.exports = {
226
853
  build,
227
854
  entrypointCallback,
855
+ experimentalBuild,
856
+ experimentalVersion,
228
857
  findEntrypoint,
858
+ name,
229
859
  require_,
230
860
  shouldServe,
231
861
  startDevServer,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/express",
3
- "version": "0.0.18",
3
+ "version": "0.0.20",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index.js",
6
6
  "homepage": "https://vercel.com/docs",
@@ -17,16 +17,21 @@
17
17
  "edge-entry.js"
18
18
  ],
19
19
  "dependencies": {
20
+ "@vercel/nft": "0.30.1",
20
21
  "@vercel/static-config": "3.1.2",
21
- "@vercel/node": "5.3.24",
22
- "ts-morph": "12.0.0"
22
+ "fs-extra": "11.1.0",
23
+ "path-to-regexp": "8.3.0",
24
+ "rolldown": "1.0.0-beta.35",
25
+ "ts-morph": "12.0.0",
26
+ "zod": "3.22.4",
27
+ "@vercel/node": "5.3.24"
23
28
  },
24
29
  "devDependencies": {
30
+ "@types/fs-extra": "11",
25
31
  "@types/jest": "27.5.1",
26
32
  "@types/node": "14.18.33",
27
33
  "@vercel/build-utils": "12.1.0",
28
34
  "execa": "3.2.0",
29
- "fs-extra": "11.1.0",
30
35
  "jest-junit": "16.0.0",
31
36
  "vite": "^5.1.6",
32
37
  "vitest": "^2.0.1"