@vercel/express 0.0.18 → 0.0.19

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 +636 -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,630 @@ 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
+ const introspectionPath = getIntrospectionPath(args);
686
+ return `
687
+ const fs = require('fs');
688
+ const path = require('path');
689
+ const originalExpress = require(${JSON.stringify(pathToExpress)});
690
+
691
+ let app = null
692
+ let staticPaths = [];
693
+ let views = ''
694
+ let viewEngine = ''
695
+ const routes = {};
696
+ const originalStatic = originalExpress.static
697
+ originalExpress.static = (...args) => {
698
+ staticPaths.push(args[0]);
699
+ return originalStatic(...args);
700
+ }
701
+ function expressWrapper() {
702
+ app = originalExpress.apply(this, arguments);
703
+ return app;
704
+ }
705
+
706
+ // Copy all properties from the original express to the wrapper
707
+ Object.setPrototypeOf(expressWrapper, originalExpress);
708
+ Object.assign(expressWrapper, originalExpress);
709
+
710
+ // Preserve the original prototype
711
+ expressWrapper.prototype = originalExpress.prototype;
712
+
713
+ module.exports = expressWrapper;
714
+
715
+ let routesExtracted = false;
716
+
717
+ const extractRoutes = () => {
718
+ if (routesExtracted) {
719
+ return;
720
+ }
721
+ routesExtracted = true;
722
+
723
+ const methods = ["all", "get", "post", "put", "delete", "patch", "options", "head"]
724
+ if (!app || !app._router) {
725
+ return;
726
+ }
727
+ for (const route of app._router.stack) {
728
+ if(route.route) {
729
+ const m = [];
730
+ for (const method of methods) {
731
+ if(route.route.methods[method]) {
732
+ m.push(method.toUpperCase());
733
+ }
734
+ }
735
+ routes[route.route.path] = { methods: m };
736
+ }
737
+ }
738
+
739
+ views = app.settings.views
740
+ viewEngine = app.settings['view engine']
741
+
742
+ // Ensure directory exists
743
+ const dir = path.dirname(${JSON.stringify(introspectionPath)});
744
+ if (!fs.existsSync(dir)) {
745
+ fs.mkdirSync(dir, { recursive: true });
746
+ }
747
+
748
+ fs.writeFileSync(${JSON.stringify(introspectionPath)}, JSON.stringify({routes, views, staticPaths, viewEngine}, null, 2));
749
+ }
750
+
751
+ process.on('exit', () => {
752
+ extractRoutes()
753
+ });
754
+
755
+ process.on('SIGINT', () => {
756
+ extractRoutes()
757
+ process.exit(0);
758
+ });
759
+ // Write routes to file on SIGTERM
760
+ process.on('SIGTERM', () => {
761
+ extractRoutes()
762
+ process.exit(0);
763
+ });
764
+ `;
765
+ };
766
+ var convertExpressRoute = (route, routeData) => {
767
+ const { regexp } = (0, import_path_to_regexp.pathToRegexp)(route);
768
+ const dest = route;
769
+ if (dest === "/") {
770
+ return;
771
+ }
772
+ const src = regexp.source;
773
+ return {
774
+ src,
775
+ dest,
776
+ methods: routeData.methods
777
+ };
778
+ };
779
+ var validatePath = (inputPath, workPath) => {
780
+ if (inputPath.indexOf("\0") !== -1) {
781
+ throw new Error(`Path contains null bytes: ${inputPath}`);
782
+ }
783
+ const normalizedPath = (0, import_path5.normalize)(inputPath);
784
+ if (normalizedPath.includes("..")) {
785
+ throw new Error(
786
+ `Path contains directory traversal sequences: ${inputPath}`
787
+ );
788
+ }
789
+ if ((0, import_path5.isAbsolute)(normalizedPath)) {
790
+ throw new Error(`Absolute paths are not allowed: ${inputPath}`);
791
+ }
792
+ const resolvedPath = (0, import_path5.resolve)(workPath, normalizedPath);
793
+ const resolvedWorkPath = (0, import_path5.resolve)(workPath);
794
+ if (!resolvedPath.startsWith(resolvedWorkPath + import_path5.sep) && resolvedPath !== resolvedWorkPath) {
795
+ throw new Error(`Path escapes the intended directory: ${inputPath}`);
796
+ }
797
+ return normalizedPath;
798
+ };
799
+
800
+ // src/experimental/build.ts
801
+ var version = 2;
802
+ var build2 = async (args) => {
803
+ console.log(`Using experimental express build`);
804
+ const downloadResult = await downloadInstallAndBundle(args);
805
+ await maybeExecBuildCommand(args, downloadResult);
806
+ args.entrypoint = await entrypointCallback2(args);
807
+ const rolldownResult = await rolldown(args);
808
+ const { routes } = await introspectApp(args, rolldownResult);
809
+ const lambda = new import_build_utils6.Lambda({
810
+ runtime: downloadResult.nodeVersion.runtime,
811
+ ...rolldownResult
812
+ });
813
+ const output = { index: lambda };
814
+ for (const route of routes) {
815
+ if (route.dest) {
816
+ if (route.dest === "/") {
817
+ continue;
818
+ }
819
+ output[route.dest] = lambda;
820
+ }
821
+ }
822
+ return {
823
+ routes,
824
+ output
825
+ };
826
+ };
827
+
828
+ // src/index.ts
829
+ var import_node3 = require("@vercel/node");
830
+ var version2 = 3;
831
+ var name = "express";
208
832
  var shouldServe = async (opts) => {
209
833
  const requestPath = opts.requestPath.replace(/\/$/, "");
210
834
  if (requestPath.startsWith("api") && opts.hasMatched) {
@@ -215,7 +839,7 @@ var shouldServe = async (opts) => {
215
839
  var startDevServer = async (opts) => {
216
840
  const entrypoint = await entrypointCallback(opts);
217
841
  process.env.EXPERIMENTAL_NODE_TYPESCRIPT_ERRORS = "1";
218
- return (0, import_node2.startDevServer)({
842
+ return (0, import_node3.startDevServer)({
219
843
  ...opts,
220
844
  entrypoint,
221
845
  publicDir: "public"
@@ -225,7 +849,10 @@ var startDevServer = async (opts) => {
225
849
  0 && (module.exports = {
226
850
  build,
227
851
  entrypointCallback,
852
+ experimentalBuild,
853
+ experimentalVersion,
228
854
  findEntrypoint,
855
+ name,
229
856
  require_,
230
857
  shouldServe,
231
858
  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.19",
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"