nitro 3.0.260415-beta → 3.0.260522-beta

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 (91) hide show
  1. package/dist/THIRD-PARTY-LICENSES.md.gz +0 -0
  2. package/dist/_build/common.mjs +157 -45
  3. package/dist/_build/rolldown.mjs +6 -6
  4. package/dist/_build/rollup.mjs +11 -11
  5. package/dist/_build/vite.build.mjs +3 -3
  6. package/dist/_build/vite.dev.mjs +149 -0
  7. package/dist/_build/vite.env.mjs +177 -0
  8. package/dist/_chunks/nitro.mjs +241 -14
  9. package/dist/_chunks/nitro2.mjs +117 -90
  10. package/dist/_chunks/utils.mjs +4 -4
  11. package/dist/_common.mjs +2 -2
  12. package/dist/_dev.d.mts +1 -1
  13. package/dist/_dev.mjs +7 -6
  14. package/dist/_libs/c12+rc9.mjs +24 -11
  15. package/dist/_libs/c12+readdirp+chokidar.d.mts +7 -8
  16. package/dist/_libs/citty.mjs +1 -1
  17. package/dist/_libs/common.d.mts +37 -0
  18. package/dist/_libs/commondir+is-reference.mjs +3 -3
  19. package/dist/_libs/compatx.d.mts +1 -1
  20. package/dist/_libs/compatx.mjs +1 -1
  21. package/dist/_libs/estree+pluginutils.d.mts +1 -1
  22. package/dist/_libs/estree-walker.mjs +1 -1
  23. package/dist/_libs/hasown+resolve+deepmerge.mjs +62 -49
  24. package/dist/_libs/httpxy.d.mts +2 -4
  25. package/dist/_libs/httpxy.mjs +13 -9
  26. package/dist/_libs/jsonc-parser+workers-utils.d.mts +1579 -0
  27. package/dist/_libs/klona.mjs +1 -1
  28. package/dist/_libs/magic-string.d.mts +1 -1
  29. package/dist/_libs/mlly.d.mts +1 -1
  30. package/dist/_libs/nypm+tinyexec.mjs +137 -113
  31. package/dist/_libs/openapi-types.d.mts +730 -0
  32. package/dist/_libs/perfect-debounce.mjs +1 -1
  33. package/dist/_libs/pkg-types.d.mts +8 -5
  34. package/dist/_libs/plugin-alias.mjs +2 -2
  35. package/dist/_libs/plugin-inject.mjs +4 -2
  36. package/dist/_libs/plugin-json.mjs +2 -2
  37. package/dist/_libs/pluginutils.mjs +18 -5
  38. package/dist/_libs/readdirp+chokidar.mjs +4 -3
  39. package/dist/_libs/remapping.mjs +2 -2
  40. package/dist/_libs/resolve-uri+gen-mapping.mjs +2 -5
  41. package/dist/_libs/rou3.d.mts +1 -1
  42. package/dist/_libs/rou3.mjs +1 -1
  43. package/dist/_libs/std-env.d.mts +1 -1
  44. package/dist/_libs/tsconfck.mjs +1 -1
  45. package/dist/_libs/ultrahtml.mjs +1 -1
  46. package/dist/_libs/unimport+unplugin.mjs +61 -39
  47. package/dist/_libs/unplugin+unimport.d.mts +4 -4
  48. package/dist/_libs/unwasm.d.mts +1 -1
  49. package/dist/_presets.mjs +118 -91
  50. package/dist/builder.d.mts +1 -1
  51. package/dist/builder.mjs +3 -3
  52. package/dist/cli/_chunks/build.mjs +3 -3
  53. package/dist/cli/_chunks/common.mjs +1 -1
  54. package/dist/cli/_chunks/deploy.mjs +2 -2
  55. package/dist/cli/_chunks/dev.mjs +4 -4
  56. package/dist/cli/_chunks/docs.mjs +1 -1
  57. package/dist/cli/_chunks/list.mjs +2 -2
  58. package/dist/cli/_chunks/prepare.mjs +3 -3
  59. package/dist/cli/_chunks/preview.mjs +4 -4
  60. package/dist/cli/_chunks/run.mjs +2 -2
  61. package/dist/cli/_chunks/task.mjs +1 -1
  62. package/dist/cli/index.mjs +1 -1
  63. package/dist/docs/0.docs/5.cache.md +53 -9
  64. package/dist/docs/1.deploy/2.providers/2.aws-amplify.md +3 -3
  65. package/dist/docs/1.deploy/2.providers/21.vercel.md +6 -0
  66. package/dist/docs/3.examples/27.vite-ssr-tsr-react.md +1 -1
  67. package/dist/node_modules/ufo/dist/index.mjs +2 -2
  68. package/dist/node_modules/ufo/package.json +9 -9
  69. package/dist/presets/azure/runtime/azure-swa.mjs +2 -0
  70. package/dist/presets/vercel/runtime/queue.dev.mjs +41 -0
  71. package/dist/runtime/internal/app.mjs +4 -111
  72. package/dist/runtime/internal/route-rules.d.mts +1 -0
  73. package/dist/runtime/internal/route-rules.mjs +29 -1
  74. package/dist/runtime/internal/routes/scalar.mjs +1 -0
  75. package/dist/runtime/virtual/app.d.mts +4 -0
  76. package/dist/runtime/virtual/app.mjs +32 -0
  77. package/dist/types/index.d.mts +959 -1836
  78. package/dist/vite.d.mts +1 -1
  79. package/dist/vite.mjs +23 -331
  80. package/package.json +43 -44
  81. package/dist/THIRD-PARTY-LICENSES.md +0 -1646
  82. package/dist/_chunks/nitro3.mjs +0 -136
  83. package/dist/_chunks/nitro4.mjs +0 -127
  84. package/dist/_libs/_.mjs +0 -2
  85. package/dist/_libs/_2.mjs +0 -2
  86. package/dist/_libs/_3.mjs +0 -2
  87. package/dist/_libs/_4.mjs +0 -2
  88. package/dist/_libs/_5.mjs +0 -2
  89. package/dist/_libs/_6.mjs +0 -2
  90. package/dist/_libs/_7.mjs +0 -2
  91. package/dist/_libs/escape-string-regexp.mjs +0 -5
package/dist/_presets.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import { B as f, F as prettyPath$1, G as findNearestFile, H as v, J as readPackageJSON, L as writeFile$2, M as glob, R, W as findFile, Y as i, Z as a, at as dirname$1, ct as join$1, dt as resolve$1, et as r, nt as resolveModulePath, q as readGitConfig, ut as relative$1 } from "./_build/common.mjs";
2
- import { r as resolveCompatibilityDatesFromEnv, t as formatCompatibilityDate } from "./_libs/compatx.mjs";
3
- import { t as Router } from "./_chunks/nitro3.mjs";
4
- import { t as importDep } from "./_chunks/utils.mjs";
1
+ import { R, a, dirname as dirname$1, f, findFile, findNearestFile, glob, i, join as join$1, prettyPath as prettyPath$1, r, readGitConfig, readPackageJSON, relative as relative$1, resolve as resolve$1, resolveModulePath, v, writeFile as writeFile$2 } from "./_build/common.mjs";
2
+ import { formatCompatibilityDate, resolveCompatibilityDatesFromEnv } from "./_libs/compatx.mjs";
3
+ import { Router } from "./_chunks/nitro.mjs";
4
+ import { importDep } from "./_chunks/utils.mjs";
5
5
  import { builtinModules } from "node:module";
6
6
  import consola from "consola";
7
7
  import { presetsDir, runtimeDir, version } from "nitro/meta";
@@ -223,11 +223,10 @@ async function writeSWARoutes(nitro) {
223
223
  route: "/",
224
224
  rewrite: "/api/server"
225
225
  });
226
- const suffix = 11;
227
226
  for (const { fileName } of routeFiles) {
228
227
  if (!fileName || !fileName.endsWith("/index.html")) continue;
229
228
  config.routes.unshift({
230
- route: fileName.slice(0, -suffix) || "/",
229
+ route: fileName.slice(0, -11) || "/",
231
230
  rewrite: fileName
232
231
  });
233
232
  }
@@ -1365,6 +1364,7 @@ async function generateFunctionFiles(nitro) {
1365
1364
  launcherType: "Nodejs",
1366
1365
  shouldAddHelpers: false,
1367
1366
  supportsResponseStreaming: true,
1367
+ ...nitro.options.sourcemap ? { shouldAddSourcemapSupport: true } : {},
1368
1368
  ...nitro.options.vercel?.functions
1369
1369
  };
1370
1370
  if (Array.isArray(baseFunctionConfig.experimentalTriggers) && baseFunctionConfig.experimentalTriggers.length > 0) nitro.logger.warn("`experimentalTriggers` on the base `vercel.functions` config applies to the catch-all function and is likely not what you want. Routes with queue triggers are not accessible on the web. Use `vercel.functionRules` to attach triggers to specific routes instead.");
@@ -1485,7 +1485,7 @@ function generateBuildConfig(nitro, o11Routes) {
1485
1485
  };
1486
1486
  return {
1487
1487
  src,
1488
- dest: withLeadingSlash(normalizeRouteDest(key) + ISR_SUFFIX + `?${ISR_URL_PARAM}=$${ISR_URL_PARAM}`)
1488
+ dest: withLeadingSlash(normalizeRouteDest(key) + `-isr?${ISR_URL_PARAM}=$${ISR_URL_PARAM}`)
1489
1489
  };
1490
1490
  }), ...nitro.options.vercel?.functionRules ? Object.keys(nitro.options.vercel.functionRules).map((pattern) => ({
1491
1491
  src: joinURL(nitro.options.baseURL, normalizeRouteSrc(pattern)),
@@ -1616,96 +1616,123 @@ async function writePrerenderConfig(filename, isrConfig, bypassToken) {
1616
1616
  if (prerenderConfig.allowQuery && !prerenderConfig.allowQuery.includes("__isr_route")) prerenderConfig.allowQuery.push(ISR_URL_PARAM);
1617
1617
  await writeFile$1(filename, JSON.stringify(prerenderConfig, null, 2));
1618
1618
  }
1619
- var preset_default$4 = [defineNitroPreset({
1620
- entry: "./vercel/runtime/vercel.{format}",
1621
- manifest: { deploymentId: process.env.VERCEL_DEPLOYMENT_ID },
1622
- vercel: {
1623
- skewProtection: !!process.env.VERCEL_SKEW_PROTECTION_ENABLED,
1624
- cronHandlerRoute: "/_vercel/cron"
1625
- },
1626
- output: {
1627
- dir: "{{ rootDir }}/.vercel/output",
1628
- serverDir: "{{ output.dir }}/functions/__server.func",
1629
- publicDir: "{{ output.dir }}/static/{{ baseURL }}"
1630
- },
1631
- commands: {
1632
- preview: "npx srvx --static ../../static ./functions/__server.func/index.mjs",
1633
- deploy: "npx vercel deploy --prebuilt"
1634
- },
1635
- hooks: {
1636
- "build:before": async (nitro) => {
1637
- const logger = nitro.logger.withTag("vercel");
1638
- const runtime = await resolveVercelRuntime(nitro);
1639
- if (runtime.startsWith("bun") && !nitro.options.exportConditions.includes("bun")) nitro.options.exportConditions.push("bun");
1640
- logger.info(`Using \`${runtime}\` runtime.`);
1641
- let serverFormat = nitro.options.vercel?.entryFormat;
1642
- if (!serverFormat) serverFormat = nitro.routing.routes.routes.flatMap((r) => r.data).some((h) => h.format === "node") ? "node" : "web";
1643
- logger.info(`Using \`${serverFormat}\` entry format.`);
1644
- nitro.options.entry = nitro.options.entry.replace("{format}", serverFormat);
1645
- if (nitro.options.experimental.tasks && Object.keys(nitro.options.scheduledTasks || {}).length > 0) nitro.options.handlers.push({
1646
- route: nitro.options.vercel.cronHandlerRoute || "/_vercel/cron",
1647
- lazy: true,
1648
- handler: join$1(presetsDir, "vercel/runtime/cron-handler")
1649
- });
1650
- const queues = nitro.options.vercel?.queues;
1651
- if (queues?.triggers?.length) {
1652
- await importDep({
1653
- id: "@vercel/queue",
1654
- dir: nitro.options.rootDir,
1655
- reason: "Vercel Queues"
1656
- });
1657
- const handlerRoute = queues.handlerRoute || "/_vercel/queues/consumer";
1658
- nitro.options.handlers.push({
1659
- route: handlerRoute,
1619
+ async function vercelDevModule(nitro) {
1620
+ if (!nitro.options.dev) return;
1621
+ const triggers = nitro.options.vercel?.queues?.triggers;
1622
+ if (!triggers?.length) return;
1623
+ if (nitro.options.devServer.runner !== "vercel") throw new Error(`[vercel:queue] Local queue delivery requires the \`vercel\` dev runner, but \`devServer.runner\` is set to "${nitro.options.devServer.runner}". Remove the \`devServer.runner\` override in your \`nitro.config.ts\` or set it explicitly to \`"vercel"\`.`);
1624
+ nitro.options.runtimeConfig.vercel = {
1625
+ ...nitro.options.runtimeConfig.vercel,
1626
+ queues: { triggers: triggers.map((t) => ({ ...t })) }
1627
+ };
1628
+ nitro.options.plugins = nitro.options.plugins || [];
1629
+ nitro.options.plugins.unshift(resolveModulePath("./vercel/runtime/queue.dev", {
1630
+ from: presetsDir,
1631
+ extensions: [".mjs", ".ts"]
1632
+ }));
1633
+ }
1634
+ var preset_default$4 = [
1635
+ defineNitroPreset({
1636
+ entry: "./vercel/runtime/vercel.{format}",
1637
+ manifest: { deploymentId: process.env.VERCEL_DEPLOYMENT_ID },
1638
+ vercel: {
1639
+ skewProtection: !!process.env.VERCEL_SKEW_PROTECTION_ENABLED,
1640
+ cronHandlerRoute: "/_vercel/cron"
1641
+ },
1642
+ output: {
1643
+ dir: "{{ rootDir }}/.vercel/output",
1644
+ serverDir: "{{ output.dir }}/functions/__server.func",
1645
+ publicDir: "{{ output.dir }}/static/{{ baseURL }}"
1646
+ },
1647
+ commands: {
1648
+ preview: "npx srvx --static ../../static ./functions/__server.func/index.mjs",
1649
+ deploy: "npx vercel deploy --prebuilt"
1650
+ },
1651
+ hooks: {
1652
+ "build:before": async (nitro) => {
1653
+ const logger = nitro.logger.withTag("vercel");
1654
+ const runtime = await resolveVercelRuntime(nitro);
1655
+ if (runtime.startsWith("bun") && !nitro.options.exportConditions.includes("bun")) nitro.options.exportConditions.push("bun");
1656
+ logger.info(`Using \`${runtime}\` runtime.`);
1657
+ let serverFormat = nitro.options.vercel?.entryFormat;
1658
+ if (!serverFormat) serverFormat = nitro.routing.routes.routes.flatMap((r) => r.data).some((h) => h.format === "node") ? "node" : "web";
1659
+ logger.info(`Using \`${serverFormat}\` entry format.`);
1660
+ nitro.options.entry = nitro.options.entry.replace("{format}", serverFormat);
1661
+ if (nitro.options.experimental.tasks && Object.keys(nitro.options.scheduledTasks || {}).length > 0) nitro.options.handlers.push({
1662
+ route: nitro.options.vercel.cronHandlerRoute || "/_vercel/cron",
1660
1663
  lazy: true,
1661
- handler: join$1(presetsDir, "vercel/runtime/queue-handler")
1664
+ handler: join$1(presetsDir, "vercel/runtime/cron-handler")
1662
1665
  });
1663
- const queueTriggers = queues.triggers.map(({ topic, ...opts }) => ({
1664
- type: "queue/v2beta",
1665
- topic,
1666
- ...opts
1667
- }));
1668
- nitro.options.vercel ??= {};
1669
- nitro.options.vercel.functionRules ??= {};
1670
- const existingRule = nitro.options.vercel.functionRules[handlerRoute];
1671
- nitro.options.vercel.functionRules[handlerRoute] = {
1672
- ...existingRule,
1673
- experimentalTriggers: [...existingRule?.experimentalTriggers || [], ...queueTriggers]
1674
- };
1666
+ const queues = nitro.options.vercel?.queues;
1667
+ if (queues?.triggers?.length) {
1668
+ await importDep({
1669
+ id: "@vercel/queue",
1670
+ dir: nitro.options.rootDir,
1671
+ reason: "Vercel Queues"
1672
+ });
1673
+ const handlerRoute = queues.handlerRoute || "/_vercel/queues/consumer";
1674
+ nitro.options.handlers.push({
1675
+ route: handlerRoute,
1676
+ lazy: true,
1677
+ handler: join$1(presetsDir, "vercel/runtime/queue-handler")
1678
+ });
1679
+ const queueTriggers = queues.triggers.map(({ topic, ...opts }) => ({
1680
+ type: "queue/v2beta",
1681
+ topic,
1682
+ ...opts
1683
+ }));
1684
+ nitro.options.vercel ??= {};
1685
+ nitro.options.vercel.functionRules ??= {};
1686
+ const existingRule = nitro.options.vercel.functionRules[handlerRoute];
1687
+ nitro.options.vercel.functionRules[handlerRoute] = {
1688
+ ...existingRule,
1689
+ experimentalTriggers: [...existingRule?.experimentalTriggers || [], ...queueTriggers]
1690
+ };
1691
+ }
1692
+ },
1693
+ "rollup:before": (nitro) => {
1694
+ deprecateSWR(nitro);
1695
+ },
1696
+ async compiled(nitro) {
1697
+ await generateFunctionFiles(nitro);
1675
1698
  }
1676
- },
1677
- "rollup:before": (nitro) => {
1678
- deprecateSWR(nitro);
1679
- },
1680
- async compiled(nitro) {
1681
- await generateFunctionFiles(nitro);
1682
1699
  }
1683
- }
1684
- }, {
1685
- name: "vercel",
1686
- stdName: "vercel"
1687
- }), defineNitroPreset({
1688
- extends: "static",
1689
- manifest: { deploymentId: process.env.VERCEL_DEPLOYMENT_ID },
1690
- vercel: { skewProtection: !!process.env.VERCEL_SKEW_PROTECTION_ENABLED },
1691
- output: {
1692
- dir: "{{ rootDir }}/.vercel/output",
1693
- publicDir: "{{ output.dir }}/static/{{ baseURL }}"
1694
- },
1695
- commands: { preview: "npx serve ./static" },
1696
- hooks: {
1697
- "rollup:before": (nitro) => {
1698
- deprecateSWR(nitro);
1700
+ }, {
1701
+ name: "vercel",
1702
+ stdName: "vercel"
1703
+ }),
1704
+ defineNitroPreset({
1705
+ extends: "static",
1706
+ manifest: { deploymentId: process.env.VERCEL_DEPLOYMENT_ID },
1707
+ vercel: { skewProtection: !!process.env.VERCEL_SKEW_PROTECTION_ENABLED },
1708
+ output: {
1709
+ dir: "{{ rootDir }}/.vercel/output",
1710
+ publicDir: "{{ output.dir }}/static/{{ baseURL }}"
1699
1711
  },
1700
- async compiled(nitro) {
1701
- await generateStaticFiles(nitro);
1712
+ commands: { preview: "npx serve ./static" },
1713
+ hooks: {
1714
+ "rollup:before": (nitro) => {
1715
+ deprecateSWR(nitro);
1716
+ },
1717
+ async compiled(nitro) {
1718
+ await generateStaticFiles(nitro);
1719
+ }
1702
1720
  }
1703
- }
1704
- }, {
1705
- name: "vercel-static",
1706
- stdName: "vercel",
1707
- static: true
1708
- })];
1721
+ }, {
1722
+ name: "vercel-static",
1723
+ stdName: "vercel",
1724
+ static: true
1725
+ }),
1726
+ defineNitroPreset({
1727
+ extends: "nitro-dev",
1728
+ devServer: { runner: "vercel" },
1729
+ modules: [vercelDevModule]
1730
+ }, {
1731
+ name: "vercel-dev",
1732
+ aliases: ["vercel"],
1733
+ dev: true
1734
+ })
1735
+ ];
1709
1736
  var preset_default$3 = [defineNitroPreset({
1710
1737
  extends: "base-worker",
1711
1738
  entry: "./winterjs/runtime/winterjs",
@@ -1,4 +1,4 @@
1
- import { t as NitroDevApp } from "./_dev.mjs";
1
+ import { NitroDevApp } from "./_dev.mjs";
2
2
  import { RunnerMessageListener, RunnerRPCHooks } from "env-runner";
3
3
  import { IncomingMessage } from "node:http";
4
4
  import { Socket } from "node:net";
package/dist/builder.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { D as copyPublicAssets, E as prepare, _ as writeTypes, j as build, m as getBuildInfo } from "./_build/common.mjs";
2
- import { a as loadOptions, i as createNitro, n as runTask, r as prerender, t as listTasks } from "./_chunks/nitro.mjs";
3
- import { n as createDevServer } from "./_dev.mjs";
1
+ import { build, copyPublicAssets, getBuildInfo, prepare, writeTypes } from "./_build/common.mjs";
2
+ import { createNitro, listTasks, loadOptions, prerender, runTask } from "./_chunks/nitro.mjs";
3
+ import { createDevServer } from "./_dev.mjs";
4
4
  export { build, copyPublicAssets, createDevServer, createNitro, getBuildInfo, listTasks, loadOptions, prepare, prerender, runTask, writeTypes };
@@ -1,6 +1,6 @@
1
- import { dt as resolve } from "../../_build/common.mjs";
2
- import { t as defineCommand } from "../../_libs/citty.mjs";
3
- import { t as commonArgs } from "./common.mjs";
1
+ import { resolve } from "../../_build/common.mjs";
2
+ import { defineCommand } from "../../_libs/citty.mjs";
3
+ import { commonArgs } from "./common.mjs";
4
4
  import { build, copyPublicAssets, createNitro, prepare, prerender } from "nitro/builder";
5
5
  const buildArgs = {
6
6
  ...commonArgs,
@@ -9,4 +9,4 @@ const commonArgs = {
9
9
  description: "project root directory (prefer using `--dir`)"
10
10
  }
11
11
  };
12
- export { commonArgs as t };
12
+ export { commonArgs };
@@ -1,5 +1,5 @@
1
- import { dt as resolve, m as getBuildInfo, ut as relative } from "../../_build/common.mjs";
2
- import { t as defineCommand } from "../../_libs/citty.mjs";
1
+ import { getBuildInfo, relative, resolve } from "../../_build/common.mjs";
2
+ import { defineCommand } from "../../_libs/citty.mjs";
3
3
  import build_default, { buildArgs } from "./build.mjs";
4
4
  import consola from "consola";
5
5
  import { execSync } from "node:child_process";
@@ -1,7 +1,7 @@
1
- import { dt as resolve } from "../../_build/common.mjs";
2
- import { t as NitroDevServer } from "../../_dev.mjs";
3
- import { t as defineCommand } from "../../_libs/citty.mjs";
4
- import { t as commonArgs } from "./common.mjs";
1
+ import { resolve } from "../../_build/common.mjs";
2
+ import { NitroDevServer } from "../../_dev.mjs";
3
+ import { defineCommand } from "../../_libs/citty.mjs";
4
+ import { commonArgs } from "./common.mjs";
5
5
  import { consola as consola$1 } from "consola";
6
6
  import { build, createNitro, prepare } from "nitro/builder";
7
7
  const hmrKeyRe = /^runtimeConfig\.|routeRules\./;
@@ -1,4 +1,4 @@
1
- import { t as defineCommand } from "../../_libs/citty.mjs";
1
+ import { defineCommand } from "../../_libs/citty.mjs";
2
2
  import { docsDir } from "nitro/meta";
3
3
  import { execSync } from "node:child_process";
4
4
  var docs_default = defineCommand({
@@ -1,5 +1,5 @@
1
- import { dt as resolve } from "../../_build/common.mjs";
2
- import { t as defineCommand } from "../../_libs/citty.mjs";
1
+ import { resolve } from "../../_build/common.mjs";
2
+ import { defineCommand } from "../../_libs/citty.mjs";
3
3
  import { consola as consola$1 } from "consola";
4
4
  import { listTasks, loadOptions } from "nitro/builder";
5
5
  var list_default = defineCommand({
@@ -1,6 +1,6 @@
1
- import { dt as resolve } from "../../_build/common.mjs";
2
- import { t as defineCommand } from "../../_libs/citty.mjs";
3
- import { t as commonArgs } from "./common.mjs";
1
+ import { resolve } from "../../_build/common.mjs";
2
+ import { defineCommand } from "../../_libs/citty.mjs";
3
+ import { commonArgs } from "./common.mjs";
4
4
  import { createNitro, writeTypes } from "nitro/builder";
5
5
  var prepare_default = defineCommand({
6
6
  meta: {
@@ -1,7 +1,7 @@
1
- import { dt as resolve } from "../../_build/common.mjs";
2
- import { t as defineCommand } from "../../_libs/citty.mjs";
3
- import { t as startPreview } from "../../_chunks/nitro4.mjs";
4
- import { t as commonArgs } from "./common.mjs";
1
+ import { resolve } from "../../_build/common.mjs";
2
+ import { defineCommand } from "../../_libs/citty.mjs";
3
+ import { startPreview } from "../../_chunks/nitro2.mjs";
4
+ import { commonArgs } from "./common.mjs";
5
5
  import { serve } from "srvx";
6
6
  import { log } from "srvx/log";
7
7
  var preview_default = defineCommand({
@@ -1,5 +1,5 @@
1
- import { dt as resolve } from "../../_build/common.mjs";
2
- import { t as defineCommand } from "../../_libs/citty.mjs";
1
+ import { resolve } from "../../_build/common.mjs";
2
+ import { defineCommand } from "../../_libs/citty.mjs";
3
3
  import { consola as consola$1 } from "consola";
4
4
  import destr from "destr";
5
5
  import { loadOptions, runTask } from "nitro/builder";
@@ -1,4 +1,4 @@
1
- import { t as defineCommand } from "../../_libs/citty.mjs";
1
+ import { defineCommand } from "../../_libs/citty.mjs";
2
2
  var task_default = defineCommand({
3
3
  meta: {
4
4
  name: "task",
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { n as runMain, t as defineCommand } from "../_libs/citty.mjs";
2
+ import { defineCommand, runMain } from "../_libs/citty.mjs";
3
3
  import { version } from "nitro/meta";
4
4
  runMain(defineCommand({
5
5
  meta: {
@@ -357,7 +357,59 @@ When `swr` is disabled and a cached value has expired:
357
357
  1. The stale entry is cleared.
358
358
  2. The client waits for the function/handler to resolve with a fresh value.
359
359
 
360
- ## Cache keys and invalidation
360
+ ## Cache invalidation
361
+ Cached entries can be invalidated programmatically at runtime (for example from a webhook when the underlying data changes) without waiting for `maxAge` to expire.
362
+
363
+ ### `.invalidate()` method
364
+
365
+ Every function created with `defineCachedFunction` exposes an `.invalidate()` method. Arguments are passed through `getKey` to generate the cache key.
366
+
367
+ ```ts
368
+ import { defineCachedFunction } from "nitro/cache";
369
+
370
+ const cachedGHStars = defineCachedFunction(async (repo: string) => {
371
+ const data = await fetch(`https://api.github.com/repos/${repo}`).then(res => res.json());
372
+ return data.stargazers_count;
373
+ }, {
374
+ maxAge: 60 * 60,
375
+ name: "ghStars",
376
+ getKey: (repo: string) => repo,
377
+ });
378
+
379
+ await cachedGHStars("unjs/nitro"); // populates the cache
380
+ await cachedGHStars.invalidate("unjs/nitro"); // removes the entry
381
+ await cachedGHStars("unjs/nitro"); // re-invokes the function
382
+ ```
383
+
384
+ If no cached entry matches the given arguments, `.invalidate()` resolves without error and leaves storage unchanged.
385
+
386
+ ### `invalidateCache()` helper
387
+
388
+ `invalidateCache` is a helper from `ocache`. It invalidates a cached entry from the cache options used to define it, so invalidation can live anywhere in your app, independent of where the cached function is defined.
389
+
390
+ Pass the same `name`, `group`, `base`, and `getKey` used when defining the function, along with the `args` identifying the entry to remove:
391
+
392
+ ```ts
393
+ import { invalidateCache } from "ocache";
394
+
395
+ await invalidateCache({
396
+ options: {
397
+ name: "ghStars",
398
+ group: "nitro/functions",
399
+ getKey: (repo: string) => repo,
400
+ },
401
+ args: ["unjs/nitro"],
402
+ });
403
+ ```
404
+
405
+ <important>
406
+
407
+ The `name`, `group`, `base`, and `getKey` passed to `invalidateCache` must match the ones used when the cached function was defined. Mismatched options resolve to a different storage key and will not invalidate the intended entry. :br :br
408
+ Nitro defaults to `group: 'nitro/functions'` for cached functions and `group: 'nitro/handlers'` for cached handlers (or `'nitro/route-rules'` when using [route rules](#using-route-rules)).
409
+ </important>
410
+
411
+ ## Cache keys
412
+
361
413
  When using the `defineCachedFunction` or `defineCachedHandler` functions, the cache key is generated using the following pattern:
362
414
 
363
415
  ```ts
@@ -384,14 +436,6 @@ Will generate the following cache key:
384
436
  cache:nitro/functions:getAccessToken:default.json
385
437
  ```
386
438
 
387
- You can invalidate the cached function entry with:
388
-
389
- ```ts
390
- import { useStorage } from "nitro/storage";
391
-
392
- await useStorage('cache').removeItem('nitro/functions:getAccessToken:default.json')
393
- ```
394
-
395
439
  <note>
396
440
 
397
441
  For cached handlers, the cache key includes a hash of the URL path and, when using the [`varies`](#handler-only-options) option, hashes of the specified header values appended to the key.
@@ -31,7 +31,7 @@ export default defineConfig({
31
31
  // catchAllStaticFallback: true,
32
32
  // imageOptimization: { path: "/_image", cacheControl: "public, max-age=3600, immutable" },
33
33
  // imageSettings: { ... },
34
- // runtime: "nodejs18.x", // default: "nodejs18.x" | "nodejs16.x" | "nodejs20.x"
34
+ // runtime: "nodejs24.x", // default: "nodejs20.x" | "nodejs22.x" | "nodejs24.x"
35
35
  }
36
36
  })
37
37
  ```
@@ -48,7 +48,7 @@ frontend:
48
48
  phases:
49
49
  preBuild:
50
50
  commands:
51
- - nvm use 18 && node --version
51
+ - nvm use 24 && node --version
52
52
  - corepack enable && npx --yes nypm install
53
53
  build:
54
54
  commands:
@@ -66,7 +66,7 @@ applications:
66
66
  phases:
67
67
  preBuild:
68
68
  commands:
69
- - nvm use 18 && node --version
69
+ - nvm use 24 && node --version
70
70
  - corepack enable && npx --yes nypm install
71
71
  build:
72
72
  commands:
@@ -210,6 +210,12 @@ export default defineEventHandler(async (event) => {
210
210
  });
211
211
  ```
212
212
 
213
+ ### Local development
214
+
215
+ Queues work in `nitro dev` — `send()` delivers messages straight to your `vercel:queue` hook, so you can iterate without deploying. Pull your Vercel environment first with `vercel link` and `vercel env pull` so the SDK can authenticate.
216
+
217
+ If your hook throws, the message is retried locally. Retries honour `retryAfterSeconds` from each trigger when set.
218
+
213
219
  ## Custom build output configuration
214
220
 
215
221
  You can provide additional [build output configuration](https://vercel.com/docs/build-output-api/v3) using `vercel.config` key inside `nitro.config`. It will be merged with built-in auto-generated config.
@@ -50,7 +50,7 @@
50
50
  "baseUrl": ".",
51
51
  "jsx": "react-jsx",
52
52
  "paths": {
53
- "@/*": ["sec/*"]
53
+ "@/*": ["./src/*"]
54
54
  }
55
55
  }
56
56
  }
@@ -286,8 +286,8 @@ function withoutBase(input, base) {
286
286
  if (nextChar && nextChar !== "/" && nextChar !== "?") {
287
287
  return input;
288
288
  }
289
- const trimmed = input.slice(_base.length);
290
- return trimmed[0] === "/" ? trimmed : "/" + trimmed;
289
+ const trimmed = input.slice(_base.length).replace(/^\/+/, "");
290
+ return "/" + trimmed;
291
291
  }
292
292
  function withQuery(input, query) {
293
293
  const parsed = parseURL(input);
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ufo",
3
- "version": "1.6.3",
3
+ "version": "1.6.4",
4
4
  "description": "URL utils for humans",
5
5
  "repository": "unjs/ufo",
6
6
  "license": "MIT",
@@ -31,18 +31,18 @@
31
31
  "test": "pnpm lint && vitest run --typecheck"
32
32
  },
33
33
  "devDependencies": {
34
- "@types/node": "^25.0.8",
35
- "@vitest/coverage-v8": "^4.0.17",
36
- "automd": "^0.4.2",
34
+ "@types/node": "^25.6.0",
35
+ "@vitest/coverage-v8": "^4.1.5",
36
+ "automd": "^0.4.3",
37
37
  "changelogen": "^0.6.2",
38
- "eslint": "^9.39.2",
38
+ "eslint": "^10.2.1",
39
39
  "eslint-config-unjs": "^0.6.2",
40
40
  "jiti": "^2.6.1",
41
- "prettier": "^3.7.4",
42
- "typescript": "^5.9.3",
41
+ "prettier": "^3.8.3",
42
+ "typescript": "^6.0.3",
43
43
  "unbuild": "^3.6.1",
44
44
  "untyped": "^2.0.0",
45
- "vitest": "^4.0.17"
45
+ "vitest": "^4.1.5"
46
46
  },
47
- "packageManager": "pnpm@10.28.0"
47
+ "packageManager": "pnpm@10.33.2"
48
48
  }
@@ -16,6 +16,8 @@ export async function handle(context, req) {
16
16
  }
17
17
  const request = new Request(url, {
18
18
  method: req.method || undefined,
19
+
20
+
19
21
  body: req.bufferBody ?? req.rawBody
20
22
  });
21
23
  const response = await nitroApp.fetch(request);
@@ -0,0 +1,41 @@
1
+ import { send } from "@vercel/queue";
2
+ import { useRuntimeConfig } from "nitro/runtime-config";
3
+ import { registerVercelQueueConsumer } from "env-runner/runners/vercel/queue-dev";
4
+ const queueDevPlugin = (nitroApp) => {
5
+ const triggers = useRuntimeConfig().vercel?.queues?.triggers || [];
6
+ if (triggers.length === 0) {
7
+ return;
8
+ }
9
+ const unregisters = [];
10
+ const ready = Promise.all(triggers.map((trigger) => registerVercelQueueConsumer({
11
+ topic: trigger.topic,
12
+ retryAfterSeconds: trigger.retryAfterSeconds,
13
+ handler: async (message, metadata) => {
14
+ try {
15
+ await nitroApp.hooks.callHook("vercel:queue", {
16
+ message,
17
+ metadata,
18
+ send
19
+ });
20
+ } catch (error) {
21
+ console.error("[vercel:queue]", error);
22
+ nitroApp.captureError?.(error, { tags: ["vercel:queue"] });
23
+
24
+ throw error;
25
+ }
26
+ }
27
+ }).then((unregister) => {
28
+ unregisters.push(unregister);
29
+ }))).catch((error) => {
30
+ console.error("[vercel:queue] failed to register dev consumer:", error);
31
+ });
32
+ nitroApp.hooks.hook("close", async () => {
33
+ await ready;
34
+ for (const unregister of unregisters) {
35
+ try {
36
+ unregister();
37
+ } catch {}
38
+ }
39
+ });
40
+ };
41
+ export default queueDevPlugin;