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