nitropack-nightly 2.13.0-20250716-094945.42a23de2 → 2.13.0-20251211-001347-056ec854

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 (40) hide show
  1. package/dist/cli/build.mjs +1 -1
  2. package/dist/cli/dev.mjs +1 -1
  3. package/dist/core/index.mjs +42 -15
  4. package/dist/meta/index.mjs +1 -1
  5. package/dist/presets/_nitro/runtime/nitro-dev.mjs +1 -1
  6. package/dist/presets/_types.gen.d.ts +7 -7
  7. package/dist/presets/_unenv/node-compat/cloudflare.mjs +8 -11
  8. package/dist/presets/aws-lambda/preset.mjs +1 -1
  9. package/dist/presets/bun/runtime/bun.mjs +2 -1
  10. package/dist/presets/cloudflare/dev.mjs +1 -1
  11. package/dist/presets/cloudflare/preset.mjs +20 -7
  12. package/dist/presets/cloudflare/runtime/plugin.dev.mjs +6 -9
  13. package/dist/presets/cloudflare/runtime/shims/workers.dev.d.mts +21 -0
  14. package/dist/presets/cloudflare/runtime/shims/workers.dev.mjs +27 -0
  15. package/dist/presets/cloudflare/utils.d.ts +1 -1
  16. package/dist/presets/cloudflare/utils.mjs +6 -3
  17. package/dist/presets/firebase/runtime/firebase-gen-1.mjs +1 -1
  18. package/dist/presets/firebase/runtime/firebase-gen-2.d.ts +1 -1
  19. package/dist/presets/firebase/types.d.ts +1 -1
  20. package/dist/presets/netlify/legacy/runtime/netlify-builder.d.ts +1 -1
  21. package/dist/presets/netlify/legacy/runtime/netlify-builder.mjs +39 -2
  22. package/dist/presets/netlify/legacy/runtime/netlify.mjs +1 -1
  23. package/dist/presets/vercel/preset.mjs +8 -2
  24. package/dist/presets/vercel/runtime/consts.d.ts +1 -0
  25. package/dist/presets/vercel/runtime/consts.mjs +1 -0
  26. package/dist/presets/vercel/runtime/vercel.mjs +25 -6
  27. package/dist/presets/vercel/types.d.ts +32 -1
  28. package/dist/presets/vercel/utils.d.ts +4 -0
  29. package/dist/presets/vercel/utils.mjs +102 -56
  30. package/dist/rollup/index.mjs +12 -11
  31. package/dist/runtime/internal/app.mjs +4 -1
  32. package/package.json +65 -66
  33. package/dist/presets/_unenv/workerd/crypto.d.mts +0 -146
  34. package/dist/presets/_unenv/workerd/crypto.mjs +0 -173
  35. package/dist/presets/_unenv/workerd/module.d.mts +0 -34
  36. package/dist/presets/_unenv/workerd/module.mjs +0 -109
  37. package/dist/presets/_unenv/workerd/tls.d.mts +0 -36
  38. package/dist/presets/_unenv/workerd/tls.mjs +0 -48
  39. package/dist/presets/_unenv/workerd/util.d.mts +0 -73
  40. package/dist/presets/_unenv/workerd/util.mjs +0 -126
@@ -5,7 +5,7 @@ import { resolve } from 'pathe';
5
5
  import { c as commonArgs } from './common.mjs';
6
6
 
7
7
  if (!globalThis.crypto) {
8
- globalThis.crypto = nodeCrypto;
8
+ globalThis.crypto = nodeCrypto.webcrypto;
9
9
  }
10
10
  const build = defineCommand({
11
11
  meta: {
package/dist/cli/dev.mjs CHANGED
@@ -8,7 +8,7 @@ import { c as commonArgs } from './common.mjs';
8
8
 
9
9
  const hmrKeyRe = /^runtimeConfig\.|routeRules\./;
10
10
  if (!globalThis.crypto) {
11
- globalThis.crypto = nodeCrypto;
11
+ globalThis.crypto = nodeCrypto.webcrypto;
12
12
  }
13
13
  const dev = defineCommand({
14
14
  meta: {
@@ -749,7 +749,7 @@ async function _loadUserConfig(configOverrides = {}, opts = {}) {
749
749
  static: getConf("static"),
750
750
  dev: true,
751
751
  compatibilityDate: compatibilityDate || fallbackCompatibilityDate
752
- }).then((p) => p?._meta?.name).catch(() => "nitro-dev") : "nitro-dev";
752
+ }).then((p) => p?._meta?.name || "nitro-dev").catch(() => "nitro-dev") : "nitro-dev";
753
753
  } else if (!preset) {
754
754
  preset = await resolvePreset("", {
755
755
  static: getConf("static"),
@@ -1196,12 +1196,13 @@ async function writeTypes(nitro) {
1196
1196
  );
1197
1197
  const resolvedImportPathMap = /* @__PURE__ */ new Map();
1198
1198
  for (const i of allImports) {
1199
- if (resolvedImportPathMap.has(i.from)) {
1199
+ const from = i.typeFrom || i.from;
1200
+ if (resolvedImportPathMap.has(from)) {
1200
1201
  continue;
1201
1202
  }
1202
- let path = resolveAlias(i.from, nitro.options.alias);
1203
+ let path = resolveAlias(from, nitro.options.alias);
1203
1204
  if (!isAbsolute(path)) {
1204
- const resolvedPath = resolveModulePath(i.from, {
1205
+ const resolvedPath = resolveModulePath(from, {
1205
1206
  try: true,
1206
1207
  from: nitro.options.nodeModulesDirs,
1207
1208
  conditions: ["type", "node", "import"],
@@ -1224,12 +1225,15 @@ async function writeTypes(nitro) {
1224
1225
  if (isAbsolute(path)) {
1225
1226
  path = relative(typesDir, path);
1226
1227
  }
1227
- resolvedImportPathMap.set(i.from, path);
1228
+ resolvedImportPathMap.set(from, path);
1228
1229
  }
1229
1230
  autoImportedTypes = [
1230
1231
  nitro.options.imports && nitro.options.imports.autoImport !== false ? (await nitro.unimport.generateTypeDeclarations({
1231
1232
  exportHelper: false,
1232
- resolvePath: (i) => resolvedImportPathMap.get(i.from) ?? i.from
1233
+ resolvePath: (i) => {
1234
+ const from = i.typeFrom || i.from;
1235
+ return resolvedImportPathMap.get(from) ?? from;
1236
+ }
1233
1237
  })).trim() : ""
1234
1238
  ];
1235
1239
  }
@@ -1619,8 +1623,16 @@ async function buildProduction(nitro, rollupConfig) {
1619
1623
  nitro: version
1620
1624
  },
1621
1625
  commands: {
1622
- preview: resolveTmplPath(nitro.options.commands.preview, nitro),
1623
- deploy: resolveTmplPath(nitro.options.commands.deploy, nitro)
1626
+ preview: resolveTmplPath(
1627
+ nitro.options.commands.preview,
1628
+ nitro,
1629
+ nitro.options.output.dir
1630
+ ),
1631
+ deploy: resolveTmplPath(
1632
+ nitro.options.commands.deploy,
1633
+ nitro,
1634
+ nitro.options.output.dir
1635
+ )
1624
1636
  },
1625
1637
  config: {
1626
1638
  ...Object.fromEntries(
@@ -1642,14 +1654,22 @@ async function buildProduction(nitro, rollupConfig) {
1642
1654
  }
1643
1655
  }
1644
1656
  await nitro.hooks.callHook("compiled", nitro);
1645
- if (buildInfo.commands?.preview) {
1657
+ if (nitro.options.commands?.preview) {
1646
1658
  nitro.logger.success(
1647
- `You can preview this build using \`${buildInfo.commands?.preview}\``
1659
+ `You can preview this build using \`${resolveTmplPath(
1660
+ nitro.options.commands.preview,
1661
+ nitro,
1662
+ process.cwd()
1663
+ )}\``
1648
1664
  );
1649
1665
  }
1650
- if (buildInfo.commands?.deploy) {
1666
+ if (nitro.options.commands?.deploy) {
1651
1667
  nitro.logger.success(
1652
- `You can deploy this build using \`${buildInfo.commands?.deploy}\``
1668
+ `You can deploy this build using \`${resolveTmplPath(
1669
+ nitro.options.commands.deploy,
1670
+ nitro,
1671
+ process.cwd()
1672
+ )}\``
1653
1673
  );
1654
1674
  }
1655
1675
  }
@@ -1674,7 +1694,7 @@ async function _snapshot(nitro) {
1674
1694
  })
1675
1695
  );
1676
1696
  }
1677
- function resolveTmplPath(input, nitro) {
1697
+ function resolveTmplPath(input, nitro, relativeTo) {
1678
1698
  if (!input || !input.includes("{{")) {
1679
1699
  return input;
1680
1700
  }
@@ -1684,7 +1704,7 @@ function resolveTmplPath(input, nitro) {
1684
1704
  match
1685
1705
  );
1686
1706
  if (val) {
1687
- val = relative(nitro.options.rootDir, val);
1707
+ val = relative(relativeTo, val) || ".";
1688
1708
  } else {
1689
1709
  nitro.logger.warn(
1690
1710
  `cannot resolve template param '${match}' in ${input.slice(0, 20)}`
@@ -2490,7 +2510,14 @@ function fmtFrame(frame) {
2490
2510
 
2491
2511
  function createVFSHandler(nitro) {
2492
2512
  return eventHandler(async (event) => {
2493
- const ip = getRequestIP(event, { xForwardedFor: false });
2513
+ const { socket } = event.node.req;
2514
+ const isUnixSocket = (
2515
+ // No network addresses
2516
+ !socket?.remoteAddress && !socket?.localAddress && // Empty address object
2517
+ Object.keys(socket?.address?.() || {}).length === 0 && // Socket is readable/writable but has no port info
2518
+ socket?.readable && socket?.writable && !socket?.remotePort
2519
+ );
2520
+ const ip = getRequestIP(event, { xForwardedFor: isUnixSocket });
2494
2521
  const isLocalRequest = ip && /^::1$|^127\.\d+\.\d+\.\d+$/.test(ip);
2495
2522
  if (!isLocalRequest) {
2496
2523
  throw createError({
@@ -1,4 +1,4 @@
1
- const version = "2.13.0-20250716-094945.42a23de2";
1
+ const version = "2.13.0-20251211-001347-056ec854";
2
2
 
3
3
  const compatibilityChanges = [
4
4
  {
@@ -18,7 +18,7 @@ import {
18
18
  toNodeListener
19
19
  } from "h3";
20
20
  if (!globalThis.crypto) {
21
- globalThis.crypto = nodeCrypto;
21
+ globalThis.crypto = nodeCrypto.webcrypto;
22
22
  }
23
23
  const { NITRO_NO_UNIX_SOCKET, NITRO_DEV_WORKER_ID } = process.env;
24
24
  trapUnhandledNodeErrors();
@@ -6,13 +6,13 @@ import type { PresetOptions as FirebaseOptions } from "./firebase/preset";
6
6
  import type { PresetOptions as NetlifyOptions } from "./netlify/preset";
7
7
  import type { PresetOptions as VercelOptions } from "./vercel/preset";
8
8
  export interface PresetOptions {
9
- awsAmplify: AwsAmplifyOptions;
10
- awsLambda: AwsLambdaOptions;
11
- azure: AzureOptions;
12
- cloudflare: CloudflareOptions;
13
- firebase: FirebaseOptions;
14
- netlify: NetlifyOptions;
15
- vercel: VercelOptions;
9
+ awsAmplify?: AwsAmplifyOptions;
10
+ awsLambda?: AwsLambdaOptions;
11
+ azure?: AzureOptions;
12
+ cloudflare?: CloudflareOptions;
13
+ firebase?: FirebaseOptions;
14
+ netlify?: NetlifyOptions;
15
+ vercel?: VercelOptions;
16
16
  }
17
17
  export declare const presetsWithConfig: readonly ["awsAmplify", "awsLambda", "azure", "cloudflare", "firebase", "netlify", "vercel"];
18
18
  export type PresetName = "alwaysdata" | "aws-amplify" | "aws-lambda" | "azure" | "azure-functions" | "azure-swa" | "base-worker" | "bun" | "cleavr" | "cli" | "cloudflare" | "cloudflare-dev" | "cloudflare-durable" | "cloudflare-module" | "cloudflare-module-legacy" | "cloudflare-pages" | "cloudflare-pages-static" | "cloudflare-worker" | "deno" | "deno-deploy" | "deno-server" | "deno-server-legacy" | "digital-ocean" | "edgio" | "firebase" | "firebase-app-hosting" | "flight-control" | "genezio" | "github-pages" | "gitlab-pages" | "heroku" | "iis" | "iis-handler" | "iis-node" | "koyeb" | "layer0" | "netlify" | "netlify-builder" | "netlify-edge" | "netlify-legacy" | "netlify-static" | "nitro-dev" | "nitro-prerender" | "node" | "node-cluster" | "node-listener" | "node-server" | "platform-sh" | "render-com" | "service-worker" | "static" | "stormkit" | "vercel" | "vercel-edge" | "vercel-static" | "winterjs" | "zeabur" | "zeabur-static" | "zerops" | "zerops-static";
@@ -13,11 +13,16 @@ export const builtnNodeModules = [
13
13
  // Missing exports: CallTracker, partialDeepStrictEqual
14
14
  "async_hooks",
15
15
  "buffer",
16
+ "constants",
17
+ // Missing exports: EXTENSIONLESS_FORMAT_JAVASCRIPT, EXTENSIONLESS_FORMAT_WASM, O_DIRECT, O_NOATIME, RTLD_DEEPBIND, SIGPOLL, SIGPWR, SIGSTKFLT, defaultCipherList
18
+ "crypto",
16
19
  "diagnostics_channel",
17
20
  "dns",
18
21
  "dns/promises",
19
22
  "events",
20
23
  // Missing exports: captureRejections, init
24
+ "fs/promises",
25
+ "module",
21
26
  "net",
22
27
  "path",
23
28
  "path/posix",
@@ -30,22 +35,16 @@ export const builtnNodeModules = [
30
35
  "string_decoder",
31
36
  "timers",
32
37
  "timers/promises",
38
+ "tls",
33
39
  "url",
40
+ "util",
34
41
  "util/types",
35
42
  "zlib"
36
43
  ];
37
44
  export const hybridNodeModules = [
38
45
  "console",
39
- "crypto",
40
- // Missing exports: Cipher, Decipher
41
- "module",
42
- // Missing exports: Module, SourceMap, constants, enableCompileCache, findPackageJSON, findSourceMap, flushCompileCache, getCompileCacheDir, getSourceMapsSupport, globalPaths, register, runMain, setSourceMapsSupport, stripTypeScriptTypes, syncBuiltinESMExports
43
- "process",
46
+ "process"
44
47
  // Missing exports: abort, allowedNodeEnvironmentFlags, arch, argv, argv0, assert, availableMemory, binding, chdir, config, constrainedMemory, cpuUsage, cwd, debugPort, dlopen, domain, emitWarning, execArgv, execPath, exitCode, finalization, getActiveResourcesInfo, getegid, geteuid, getgid, getgroups, getuid, hasUncaughtExceptionCaptureCallback, hrtime, initgroups, kill, loadEnvFile, memoryUsage, moduleLoadList, openStdin, pid, ppid, reallyExit, ref, release, report, resourceUsage, setSourceMapsEnabled, setUncaughtExceptionCaptureCallback, setegid, seteuid, setgid, setgroups, setuid, sourceMapsEnabled, stderr, stdin, stdout, title, umask, unref, uptime, version, versions
45
- "tls",
46
- // Missing exports: createSecurePair
47
- "util"
48
- // Missing exports: isBoolean, isBuffer, isDate, isError, isFunction, isNull, isNullOrUndefined, isNumber, isObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined
49
48
  ];
50
49
  export const unsupportedNodeModules = [
51
50
  "_http_agent",
@@ -57,11 +56,9 @@ export const unsupportedNodeModules = [
57
56
  "_stream_wrap",
58
57
  "child_process",
59
58
  "cluster",
60
- "constants",
61
59
  "dgram",
62
60
  "domain",
63
61
  "fs",
64
- "fs/promises",
65
62
  "http",
66
63
  "http2",
67
64
  "https",
@@ -7,7 +7,7 @@ const awsLambda = defineNitroPreset(
7
7
  },
8
8
  hooks: {
9
9
  "rollup:before": (nitro, rollupConfig) => {
10
- if (nitro.options.awsLambda.streaming) {
10
+ if (nitro.options.awsLambda?.streaming) {
11
11
  rollupConfig.input += "-streaming";
12
12
  }
13
13
  }
@@ -6,6 +6,7 @@ const nitroApp = useNitroApp();
6
6
  const ws = import.meta._websocket ? wsAdapter(nitroApp.h3App.websocket) : void 0;
7
7
  const server = Bun.serve({
8
8
  port: process.env.NITRO_PORT || process.env.PORT || 3e3,
9
+ host: process.env.NITRO_HOST || process.env.HOST,
9
10
  websocket: import.meta._websocket ? ws.websocket : void 0,
10
11
  async fetch(req, server2) {
11
12
  if (import.meta._websocket && req.headers.get("upgrade") === "websocket") {
@@ -26,7 +27,7 @@ const server = Bun.serve({
26
27
  });
27
28
  }
28
29
  });
29
- console.log(`Listening on http://localhost:${server.port}...`);
30
+ console.log(`Listening on ${server.url}...`);
30
31
  if (import.meta._tasks) {
31
32
  startScheduleRunner();
32
33
  }
@@ -58,7 +58,7 @@ export async function cloudflareDev(nitro) {
58
58
  fileURLToPath(new URL("runtime/", import.meta.url))
59
59
  );
60
60
  nitro.options.plugins = nitro.options.plugins || [];
61
- nitro.options.plugins.push(
61
+ nitro.options.plugins.unshift(
62
62
  fileURLToPath(new URL("runtime/plugin.dev", import.meta.url))
63
63
  );
64
64
  }
@@ -44,7 +44,7 @@ const cloudflarePages = defineNitroPreset(
44
44
  hooks: {
45
45
  "build:before": async (nitro) => {
46
46
  await enableNodeCompat(nitro);
47
- if (!nitro.options.cloudflare.deployConfig) {
47
+ if (!nitro.options.cloudflare?.deployConfig) {
48
48
  nitro.options.commands.preview = "npx wrangler pages dev {{ output.dir }}";
49
49
  nitro.options.commands.deploy = "npx wrangler pages deploy {{ output.dir }}";
50
50
  }
@@ -52,7 +52,7 @@ const cloudflarePages = defineNitroPreset(
52
52
  async compiled(nitro) {
53
53
  await writeWranglerConfig(nitro, "pages");
54
54
  await writeCFRoutes(nitro);
55
- await writeCFHeaders(nitro);
55
+ await writeCFHeaders(nitro, "output");
56
56
  await writeCFPagesRedirects(nitro);
57
57
  }
58
58
  }
@@ -76,13 +76,13 @@ const cloudflarePagesStatic = defineNitroPreset(
76
76
  },
77
77
  hooks: {
78
78
  "build:before": async (nitro) => {
79
- if (!nitro.options.cloudflare.deployConfig) {
79
+ if (!nitro.options.cloudflare?.deployConfig) {
80
80
  nitro.options.commands.preview = "npx wrangler pages dev {{ output.dir }}";
81
81
  nitro.options.commands.deploy = "npx wrangler pages deploy {{ output.dir }}";
82
82
  }
83
83
  },
84
84
  async compiled(nitro) {
85
- await writeCFHeaders(nitro);
85
+ await writeCFHeaders(nitro, "output");
86
86
  await writeCFPagesRedirects(nitro);
87
87
  }
88
88
  }
@@ -99,7 +99,20 @@ export const cloudflareDev = defineNitroPreset(
99
99
  extends: "nitro-dev",
100
100
  modules: [
101
101
  async (nitro) => await import("./dev.mjs").then((m) => m.cloudflareDev(nitro))
102
- ]
102
+ ],
103
+ esbuild: {
104
+ options: {
105
+ target: "es2022"
106
+ }
107
+ },
108
+ unenv: {
109
+ meta: {
110
+ name: "cloudflare-dev"
111
+ },
112
+ alias: {
113
+ "cloudflare:workers": "nitropack/presets/cloudflare/runtime/shims/workers.dev"
114
+ }
115
+ }
103
116
  },
104
117
  {
105
118
  name: "cloudflare-dev",
@@ -136,14 +149,14 @@ const cloudflareModule = defineNitroPreset(
136
149
  hooks: {
137
150
  "build:before": async (nitro) => {
138
151
  await enableNodeCompat(nitro);
139
- if (!nitro.options.cloudflare.deployConfig) {
152
+ if (!nitro.options.cloudflare?.deployConfig) {
140
153
  nitro.options.commands.preview = "npx wrangler dev {{ output.serverDir }}/index.mjs --assets {{ output.publicDir }}";
141
154
  nitro.options.commands.deploy = "npx wrangler deploy {{ output.serverDir }}/index.mjs --assets {{ output.publicDir }}";
142
155
  }
143
156
  },
144
157
  async compiled(nitro) {
145
158
  await writeWranglerConfig(nitro, "module");
146
- await writeCFHeaders(nitro);
159
+ await writeCFHeaders(nitro, "public");
147
160
  await writeFile(
148
161
  resolve(nitro.options.output.dir, "package.json"),
149
162
  JSON.stringify({ private: true, main: "./server/index.mjs" }, null, 2)
@@ -1,15 +1,12 @@
1
1
  import { useRuntimeConfig, getRequestURL } from "#imports";
2
- const _proxy = _getPlatformProxy().catch((error) => {
2
+ const proxy = await _getPlatformProxy().catch((error) => {
3
3
  console.error("Failed to initialize wrangler bindings proxy", error);
4
4
  return _createStubProxy();
5
- }).then((proxy) => {
6
- globalThis.__env__ = proxy.env;
7
- return proxy;
8
5
  });
9
- globalThis.__env__ = _proxy.then((proxy) => proxy.env);
6
+ globalThis.__env__ = proxy.env;
7
+ globalThis.__wait_until__ = proxy.ctx.waitUntil.bind(proxy.ctx);
10
8
  export default (function(nitroApp) {
11
9
  nitroApp.hooks.hook("request", async (event) => {
12
- const proxy = await _proxy;
13
10
  event.context.cf = proxy.cf;
14
11
  event.context.waitUntil = proxy.ctx.waitUntil.bind(proxy.ctx);
15
12
  const request = new Request(getRequestURL(event));
@@ -27,7 +24,7 @@ export default (function(nitroApp) {
27
24
  });
28
25
  nitroApp.hooks._hooks.request.unshift(nitroApp.hooks._hooks.request.pop());
29
26
  nitroApp.hooks.hook("close", () => {
30
- return _proxy?.then((proxy) => proxy.dispose);
27
+ return proxy?.dispose();
31
28
  });
32
29
  });
33
30
  async function _getPlatformProxy() {
@@ -45,8 +42,8 @@ async function _getPlatformProxy() {
45
42
  if (runtimeConfig.wrangler.environment) {
46
43
  proxyOptions.environment = runtimeConfig.wrangler.environment;
47
44
  }
48
- const proxy = await getPlatformProxy(proxyOptions);
49
- return proxy;
45
+ const proxy2 = await getPlatformProxy(proxyOptions);
46
+ return proxy2;
50
47
  }
51
48
  function _createStubProxy() {
52
49
  return {
@@ -0,0 +1,21 @@
1
+ export function waitUntil(promise: any): Promise<void>;
2
+ export function withEnv(newEnv: any, fn: any): void;
3
+ export class DurableObject extends NotImplemented {
4
+ }
5
+ export class RpcPromise extends NotImplemented {
6
+ }
7
+ export class RpcProperty extends NotImplemented {
8
+ }
9
+ export class RpcStub extends NotImplemented {
10
+ }
11
+ export class RpcTarget extends NotImplemented {
12
+ }
13
+ export class ServiceStub extends NotImplemented {
14
+ }
15
+ export class WorkerEntrypoint extends NotImplemented {
16
+ }
17
+ export class WorkflowEntrypoint extends NotImplemented {
18
+ }
19
+ declare class NotImplemented {
20
+ }
21
+ export {};
@@ -0,0 +1,27 @@
1
+ // Shim for "cloudflare:workers" import in dev environment
2
+
3
+ // unenv shim respects __env__
4
+ export { env } from "unenv/node/internal/process/env";
5
+
6
+ export async function waitUntil(promise) {
7
+ await globalThis.__wait_until__?.(promise);
8
+ }
9
+
10
+ export function withEnv(newEnv, fn) {
11
+ throw new Error("cf.withEnv is not implemented in dev env currently.");
12
+ }
13
+
14
+ class NotImplemented {
15
+ constructor() {
16
+ throw new Error("Not implemented in dev env currently.");
17
+ }
18
+ }
19
+
20
+ export class DurableObject extends NotImplemented {}
21
+ export class RpcPromise extends NotImplemented {}
22
+ export class RpcProperty extends NotImplemented {}
23
+ export class RpcStub extends NotImplemented {}
24
+ export class RpcTarget extends NotImplemented {}
25
+ export class ServiceStub extends NotImplemented {}
26
+ export class WorkerEntrypoint extends NotImplemented {}
27
+ export class WorkflowEntrypoint extends NotImplemented {}
@@ -1,6 +1,6 @@
1
1
  import type { Nitro } from "nitropack/types";
2
2
  export declare function writeCFRoutes(nitro: Nitro): Promise<void>;
3
- export declare function writeCFHeaders(nitro: Nitro): Promise<void>;
3
+ export declare function writeCFHeaders(nitro: Nitro, outdir: "public" | "output"): Promise<void>;
4
4
  export declare function writeCFPagesRedirects(nitro: Nitro): Promise<void>;
5
5
  export declare function enableNodeCompat(nitro: Nitro): Promise<void>;
6
6
  export declare function writeWranglerConfig(nitro: Nitro, cfTarget: "pages" | "module"): Promise<void>;
@@ -75,8 +75,11 @@ export async function writeCFRoutes(nitro) {
75
75
  function comparePaths(a, b) {
76
76
  return a.split("/").length - b.split("/").length || a.localeCompare(b);
77
77
  }
78
- export async function writeCFHeaders(nitro) {
79
- const headersPath = join(nitro.options.output.dir, "_headers");
78
+ export async function writeCFHeaders(nitro, outdir) {
79
+ const headersPath = join(
80
+ outdir === "public" ? nitro.options.output.publicDir : nitro.options.output.dir,
81
+ "_headers"
82
+ );
80
83
  const contents = [];
81
84
  const rules = Object.entries(nitro.options.routeRules).sort(
82
85
  (a, b) => b[0].split(/\/(?!\*)/).length - a[0].split(/\/(?!\*)/).length
@@ -282,5 +285,5 @@ async function generateWorkerName(nitro) {
282
285
  );
283
286
  const pkgName = pkgJSON?.name;
284
287
  const subpath = relative(nitro.options.workspaceDir, nitro.options.rootDir);
285
- return `${gitRepo || pkgName}/${subpath}`.replace(/[^a-zA-Z0-9-]/g, "-").replace(/-$/, "");
288
+ return `${gitRepo || pkgName}/${subpath}`.toLowerCase().replace(/[^a-zA-Z0-9-]/g, "-").replace(/-$/, "");
286
289
  }
@@ -1,7 +1,7 @@
1
1
  import "#nitro-internal-pollyfills";
2
2
  import { useNitroApp } from "nitropack/runtime";
3
3
  import { useAppConfig } from "nitropack/runtime";
4
- import functions from "firebase-functions";
4
+ import functions from "firebase-functions/v1";
5
5
  import { toNodeListener } from "h3";
6
6
  const nitroApp = useNitroApp();
7
7
  const firebaseConfig = useAppConfig().nitro.firebase;
@@ -1,2 +1,2 @@
1
1
  import "#nitro-internal-pollyfills";
2
- export declare const __firebaseServerFunctionName__: import("firebase-functions/v2/https").HttpsFunction;
2
+ export declare const __firebaseServerFunctionName__: import("firebase-functions/https").HttpsFunction;
@@ -1,4 +1,4 @@
1
- import type { RuntimeOptions, region } from "firebase-functions";
1
+ import type { RuntimeOptions, region } from "firebase-functions/v1";
2
2
  import type { HttpsOptions } from "firebase-functions/v2/https";
3
3
  export type FirebaseOptions = FirebaseFunctionsOptions | AppHostingOptions;
4
4
  export type FirebaseFunctionsOptions = FirebaseOptionsGen1 | FirebaseOptionsGen2;
@@ -1,2 +1,2 @@
1
1
  import "#nitro-internal-pollyfills";
2
- export declare const handler: import("@netlify/functions").Handler;
2
+ export declare const handler: (event: any, context: any, callback?: any) => any;
@@ -1,4 +1,41 @@
1
1
  import "#nitro-internal-pollyfills";
2
- import { builder } from "@netlify/functions";
3
2
  import { lambda } from "./netlify-lambda.mjs";
4
- export const handler = builder(lambda);
3
+ export const handler = wrapHandler(lambda);
4
+ const BUILDER_FUNCTIONS_FLAG = true;
5
+ const HTTP_STATUS_METHOD_NOT_ALLOWED = 405;
6
+ const METADATA_VERSION = 1;
7
+ const augmentResponse = (response) => {
8
+ if (!response) {
9
+ return response;
10
+ }
11
+ const metadata = {
12
+ version: METADATA_VERSION,
13
+ builder_function: BUILDER_FUNCTIONS_FLAG,
14
+ ttl: response.ttl || 0
15
+ };
16
+ return {
17
+ ...response,
18
+ metadata
19
+ };
20
+ };
21
+ function wrapHandler(handler2) {
22
+ return (event, context, callback) => {
23
+ if (event.httpMethod !== "GET" && event.httpMethod !== "HEAD") {
24
+ return Promise.resolve({
25
+ body: "Method Not Allowed",
26
+ statusCode: HTTP_STATUS_METHOD_NOT_ALLOWED
27
+ });
28
+ }
29
+ const modifiedEvent = {
30
+ ...event,
31
+ multiValueQueryStringParameters: {},
32
+ queryStringParameters: {}
33
+ };
34
+ const wrappedCallback = (error, response) => callback ? callback(error, augmentResponse(response)) : null;
35
+ const execution = handler2(modifiedEvent, context, wrappedCallback);
36
+ if (typeof execution === "object" && typeof execution.then === "function") {
37
+ return execution.then(augmentResponse);
38
+ }
39
+ return execution;
40
+ };
41
+ }
@@ -14,7 +14,7 @@ export const handler = async function handler2(event, context) {
14
14
  (r) => r.builder || r.default.builder
15
15
  );
16
16
  const ttl = typeof routeRules.isr === "number" ? routeRules.isr : false;
17
- const builderHandler = ttl ? (event2, context2) => lambda(event2, context2).then((r) => ({ ...r, ttl })) : lambda;
17
+ const builderHandler = ttl ? ((event2, context2) => lambda(event2, context2).then((r) => ({ ...r, ttl }))) : lambda;
18
18
  return builder(builderHandler)(event, context);
19
19
  }
20
20
  return lambda(event, context);
@@ -10,9 +10,12 @@ const vercel = defineNitroPreset(
10
10
  {
11
11
  extends: "node",
12
12
  entry: "./runtime/vercel",
13
+ vercel: {
14
+ skewProtection: !!process.env.VERCEL_SKEW_PROTECTION_ENABLED
15
+ },
13
16
  output: {
14
17
  dir: "{{ rootDir }}/.vercel/output",
15
- serverDir: "{{ output.dir }}/functions/__nitro.func",
18
+ serverDir: "{{ output.dir }}/functions/__fallback.func",
16
19
  publicDir: "{{ output.dir }}/static/{{ baseURL }}"
17
20
  },
18
21
  commands: {
@@ -41,7 +44,7 @@ const vercelEdge = defineNitroPreset(
41
44
  exportConditions: ["edge-light"],
42
45
  output: {
43
46
  dir: "{{ rootDir }}/.vercel/output",
44
- serverDir: "{{ output.dir }}/functions/__nitro.func",
47
+ serverDir: "{{ output.dir }}/functions/__fallback.func",
45
48
  publicDir: "{{ output.dir }}/static/{{ baseURL }}"
46
49
  },
47
50
  commands: {
@@ -85,6 +88,9 @@ const vercelEdge = defineNitroPreset(
85
88
  const vercelStatic = defineNitroPreset(
86
89
  {
87
90
  extends: "static",
91
+ vercel: {
92
+ skewProtection: !!process.env.VERCEL_SKEW_PROTECTION_ENABLED
93
+ },
88
94
  output: {
89
95
  dir: "{{ rootDir }}/.vercel/output",
90
96
  publicDir: "{{ output.dir }}/static/{{ baseURL }}"
@@ -0,0 +1 @@
1
+ export declare const ISR_URL_PARAM = "__isr_route";
@@ -0,0 +1 @@
1
+ export const ISR_URL_PARAM = "__isr_route";
@@ -1,15 +1,34 @@
1
1
  import "#nitro-internal-pollyfills";
2
2
  import { useNitroApp } from "nitropack/runtime";
3
+ import { getRouteRulesForPath } from "nitropack/runtime/internal/index";
3
4
  import { toNodeListener } from "h3";
4
- import { parseQuery } from "ufo";
5
+ import { parseQuery, withQuery } from "ufo";
6
+ import { ISR_URL_PARAM } from "./consts.mjs";
5
7
  const nitroApp = useNitroApp();
6
8
  const handler = toNodeListener(nitroApp.h3App);
7
9
  const listener = function(req, res) {
8
- const query = req.headers["x-now-route-matches"];
9
- if (query) {
10
- const { url } = parseQuery(query);
11
- if (url) {
12
- req.url = url;
10
+ const isrRoute = req.headers["x-now-route-matches"];
11
+ if (isrRoute) {
12
+ const { [ISR_URL_PARAM]: url } = parseQuery(isrRoute);
13
+ if (url && typeof url === "string") {
14
+ const routeRules = getRouteRulesForPath(url);
15
+ if (routeRules.isr) {
16
+ req.url = url;
17
+ }
18
+ }
19
+ } else {
20
+ const queryIndex = req.url.indexOf("?");
21
+ const urlQueryIndex = queryIndex === -1 ? -1 : req.url.indexOf(`${ISR_URL_PARAM}=`, queryIndex);
22
+ if (urlQueryIndex !== -1) {
23
+ const { [ISR_URL_PARAM]: url, ...params } = parseQuery(
24
+ req.url.slice(queryIndex)
25
+ );
26
+ if (url && typeof url === "string") {
27
+ const routeRules = getRouteRulesForPath(url);
28
+ if (routeRules.isr) {
29
+ req.url = withQuery(url, params);
30
+ }
31
+ }
13
32
  }
14
33
  }
15
34
  return handler(req, res);