@vercel/hono 0.1.1 → 0.1.3

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 +643 -10
  2. package/package.json +9 -3
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 honoVersion = require_(resolved).version;
89
92
  if (honoVersion) {
90
- version2 = honoVersion;
93
+ version3 = honoVersion;
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,635 @@ var findMainPackageEntrypoint = (files) => {
202
205
  return null;
203
206
  };
204
207
 
205
- // src/index.ts
208
+ // src/experimental/build.ts
209
+ var import_build_utils5 = 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*)?["']hono["']\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 hono. 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 hono. 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_path5 = require("path");
551
+ var import_fs_extra = require("fs-extra");
552
+ var import_fs4 = require("fs");
553
+ var import_promises = require("fs/promises");
554
+ var import_child_process = require("child_process");
555
+ var import_path_to_regexp = require("path-to-regexp");
556
+ var import_zod = require("zod");
557
+ var introspectApp = async (args, options) => {
558
+ await injectRouteCapture(options);
559
+ await invokeFunction(args, options);
560
+ const {
561
+ routes: routesFromIntrospection,
562
+ views,
563
+ staticPaths,
564
+ viewEngine
565
+ } = await processIntrospection(options);
566
+ await cleanup(options);
567
+ console.log(
568
+ `Generated introspection.json with ${routesFromIntrospection.length} routes for observability`
569
+ );
570
+ return { routes: routesFromIntrospection, views, staticPaths, viewEngine };
571
+ };
572
+ var processIntrospection = async (options) => {
573
+ const schema = import_zod.z.object({
574
+ routes: import_zod.z.record(
575
+ import_zod.z.string(),
576
+ import_zod.z.object({
577
+ methods: import_zod.z.array(import_zod.z.string())
578
+ })
579
+ ).transform(
580
+ (value) => Object.entries(value).map(([path, route]) => convertHonoRoute(path, route)).filter(Boolean)
581
+ ),
582
+ views: import_zod.z.string().optional(),
583
+ staticPaths: import_zod.z.array(import_zod.z.string()).optional(),
584
+ viewEngine: import_zod.z.string().optional()
585
+ });
586
+ try {
587
+ const introspectionPath = (0, import_path5.join)(options.outputDir, "introspection.json");
588
+ const introspection = (0, import_fs4.readFileSync)(introspectionPath, "utf8");
589
+ const parsedData = JSON.parse(introspection);
590
+ console.log("Parsed introspection data:", Object.keys(parsedData));
591
+ console.log("Routes count:", Object.keys(parsedData.routes || {}).length);
592
+ return schema.parse(parsedData);
593
+ } catch (error) {
594
+ console.log("Schema validation error:", error);
595
+ console.log(
596
+ `Unable to extract routes from hono, route level observability will not be available`
597
+ );
598
+ return {
599
+ routes: [],
600
+ views: void 0,
601
+ staticPaths: void 0,
602
+ viewEngine: void 0
603
+ };
604
+ }
605
+ };
606
+ var getIntrospectionPath = (options) => {
607
+ return (0, import_path5.join)(options.outputDir, "introspection.json");
608
+ };
609
+ var cleanup = async (options) => {
610
+ await (0, import_promises.rm)((0, import_path5.join)(options.outputDir, "node_modules"), {
611
+ recursive: true,
612
+ force: true
613
+ });
614
+ await (0, import_promises.rm)(getIntrospectionPath(options), { force: true });
615
+ };
616
+ var invokeFunction = async (args, options) => {
617
+ await new Promise((resolve) => {
618
+ try {
619
+ const child = (0, import_child_process.spawn)("node", [(0, import_path5.join)(options.outputDir, options.handler)], {
620
+ stdio: ["pipe", "pipe", "pipe"],
621
+ cwd: options.outputDir,
622
+ env: {
623
+ ...process.env,
624
+ ...args.meta?.env || {},
625
+ ...args.meta?.buildEnv || {}
626
+ }
627
+ });
628
+ setTimeout(() => {
629
+ child.kill("SIGTERM");
630
+ }, 5e3);
631
+ child.on("error", () => {
632
+ console.log(
633
+ `Unable to extract routes from hono, route level observability will not be available`
634
+ );
635
+ resolve(void 0);
636
+ });
637
+ child.on("close", () => {
638
+ resolve(void 0);
639
+ });
640
+ } catch (error) {
641
+ console.log(
642
+ `Unable to extract routes from hono, route level observability will not be available`
643
+ );
644
+ resolve(void 0);
645
+ }
646
+ });
647
+ };
648
+ var injectRouteCapture = async (options) => {
649
+ const bundlePath = (0, import_path5.join)(options.outputDir, options.handler);
650
+ const introspectionPath = getIntrospectionPath(options);
651
+ try {
652
+ let bundleContent = (0, import_fs4.readFileSync)(bundlePath, "utf8");
653
+ const routeCaptureCode = `
654
+ // Route capture for introspection using Hono's built-in methods
655
+ import fs from 'fs';
656
+ import path from 'path';
657
+ const routes = {};
658
+ let routesExtracted = false;
659
+
660
+ // Function to extract routes using Hono's built-in app.routes
661
+ function extractRoutesFromApp(app) {
662
+ if (!app || !app.routes) {
663
+ return;
664
+ }
665
+
666
+ // Use Hono's built-in routes property
667
+ for (const route of app.routes) {
668
+ const routePath = route.path;
669
+ const method = route.method.toUpperCase();
670
+
671
+ if (!routes[routePath]) {
672
+ routes[routePath] = { methods: [] };
673
+ }
674
+ if (!routes[routePath].methods.includes(method)) {
675
+ routes[routePath].methods.push(method);
676
+ }
677
+ }
678
+ }
679
+
680
+ // Handle app.all() routes - they should include all HTTP methods
681
+ const processAllRoutes = () => {
682
+ for (const [path, routeData] of Object.entries(routes)) {
683
+ if (routeData.methods.includes('ALL')) {
684
+ routeData.methods = [
685
+ 'GET',
686
+ 'POST',
687
+ 'PUT',
688
+ 'DELETE',
689
+ 'PATCH',
690
+ 'OPTIONS',
691
+ 'HEAD',
692
+ ];
693
+ }
694
+ }
695
+ };
696
+
697
+ const extractRoutes = () => {
698
+ if (routesExtracted) {
699
+ return;
700
+ }
701
+ routesExtracted = true;
702
+
703
+ // Extract routes from all Hono instances
704
+ if (typeof app !== 'undefined') {
705
+ extractRoutesFromApp(app);
706
+ }
707
+
708
+ // Also check for other common variable names
709
+ const commonNames = ['api', 'router', 'server', 'hono', 'honoApp'];
710
+ for (const name of commonNames) {
711
+ if (typeof globalThis[name] !== 'undefined') {
712
+ extractRoutesFromApp(globalThis[name]);
713
+ }
714
+ }
715
+
716
+ processAllRoutes();
717
+
718
+ // Ensure directory exists
719
+ const dir = path.dirname('${introspectionPath}');
720
+ if (!fs.existsSync(dir)) {
721
+ fs.mkdirSync(dir, { recursive: true });
722
+ }
723
+
724
+ fs.writeFileSync('${introspectionPath}', JSON.stringify({
725
+ routes,
726
+ views: undefined,
727
+ staticPaths: undefined,
728
+ viewEngine: undefined
729
+ }, null, 2));
730
+ };
731
+
732
+ process.on('exit', () => {
733
+ extractRoutes();
734
+ });
735
+
736
+ process.on('SIGINT', () => {
737
+ extractRoutes();
738
+ process.exit(0);
739
+ });
740
+
741
+ process.on('SIGTERM', () => {
742
+ extractRoutes();
743
+ process.exit(0);
744
+ });
745
+
746
+ `;
747
+ const importEndIndex = bundleContent.indexOf("//#region index.js");
748
+ if (importEndIndex !== -1) {
749
+ bundleContent = bundleContent.slice(0, importEndIndex) + routeCaptureCode + bundleContent.slice(importEndIndex);
750
+ } else {
751
+ bundleContent = routeCaptureCode + bundleContent;
752
+ }
753
+ await (0, import_fs_extra.outputFile)(bundlePath, bundleContent);
754
+ console.log("Injected route capture into bundled JavaScript");
755
+ } catch (error) {
756
+ console.log("Failed to inject route capture:", error);
757
+ throw error;
758
+ }
759
+ };
760
+ var convertHonoRoute = (route, routeData) => {
761
+ try {
762
+ const { regexp } = (0, import_path_to_regexp.pathToRegexp)(route);
763
+ const dest = route;
764
+ const src = regexp.source;
765
+ return {
766
+ src,
767
+ dest,
768
+ methods: routeData.methods
769
+ };
770
+ } catch (error) {
771
+ console.log(`Skipping route with invalid path: ${route}`);
772
+ const escapedRoute = route.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
773
+ return {
774
+ src: `^${escapedRoute}$`,
775
+ dest: route,
776
+ methods: routeData.methods
777
+ };
778
+ }
779
+ };
780
+
781
+ // src/experimental/build.ts
782
+ var version = 2;
783
+ var build2 = async (args) => {
784
+ console.log(`Using experimental hono build`);
785
+ const downloadResult = await downloadInstallAndBundle(args);
786
+ await maybeExecBuildCommand(args, downloadResult);
787
+ args.entrypoint = await entrypointCallback2(args);
788
+ const rolldownResult = await rolldown(args);
789
+ const { routes } = await introspectApp(args, rolldownResult);
790
+ const lambda = new import_build_utils5.Lambda({
791
+ runtime: downloadResult.nodeVersion.runtime,
792
+ ...rolldownResult
793
+ });
794
+ const output = { index: lambda };
795
+ const usedPaths = /* @__PURE__ */ new Set();
796
+ for (const route of routes) {
797
+ if (route.dest) {
798
+ if (route.dest === "/") {
799
+ continue;
800
+ }
801
+ const normalizedPath = route.dest.replace(/\/$/, "");
802
+ if (!usedPaths.has(normalizedPath)) {
803
+ output[normalizedPath] = lambda;
804
+ usedPaths.add(normalizedPath);
805
+ }
806
+ }
807
+ }
808
+ const normalizedRoutes = routes.map((route) => {
809
+ if (route.dest && route.dest !== "/") {
810
+ return {
811
+ ...route,
812
+ dest: route.dest.replace(/\/$/, "")
813
+ };
814
+ }
815
+ return route;
816
+ });
817
+ const mainRoutes = [
818
+ {
819
+ handle: "filesystem"
820
+ },
821
+ ...normalizedRoutes,
822
+ {
823
+ src: "/(.*)",
824
+ dest: "/"
825
+ }
826
+ ];
827
+ return {
828
+ routes: mainRoutes,
829
+ output
830
+ };
831
+ };
832
+
833
+ // src/index.ts
834
+ var import_node3 = require("@vercel/node");
835
+ var version2 = 3;
836
+ var name = "hono";
208
837
  var shouldServe = async (opts) => {
209
838
  const requestPath = opts.requestPath.replace(/\/$/, "");
210
839
  if (requestPath.startsWith("api") && opts.hasMatched) {
@@ -215,16 +844,20 @@ var shouldServe = async (opts) => {
215
844
  var startDevServer = async (opts) => {
216
845
  const entrypoint = await entrypointCallback(opts);
217
846
  process.env.EXPERIMENTAL_NODE_TYPESCRIPT_ERRORS = "1";
218
- return (0, import_node2.startDevServer)({
847
+ return (0, import_node3.startDevServer)({
219
848
  ...opts,
220
- entrypoint
849
+ entrypoint,
850
+ publicDir: "public"
221
851
  });
222
852
  };
223
853
  // Annotate the CommonJS export names for ESM import in node:
224
854
  0 && (module.exports = {
225
855
  build,
226
856
  entrypointCallback,
857
+ experimentalBuild,
858
+ experimentalVersion,
227
859
  findEntrypoint,
860
+ name,
228
861
  require_,
229
862
  shouldServe,
230
863
  startDevServer,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/hono",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index.js",
6
6
  "homepage": "https://vercel.com/docs",
@@ -17,11 +17,17 @@
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.23",
22
- "ts-morph": "12.0.0"
22
+ "@vercel/node": "5.3.24",
23
+ "fs-extra": "11.1.0",
24
+ "path-to-regexp": "8.3.0",
25
+ "rolldown": "1.0.0-beta.35",
26
+ "ts-morph": "12.0.0",
27
+ "zod": "3.22.4"
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",