nitro-nightly 3.0.260522-beta → 3.0.260610-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.
Binary file
@@ -6510,6 +6510,7 @@ var require_picomatch = /* @__PURE__ */ __commonJSMin(((exports, module) => {
6510
6510
  var import_picomatch = /* @__PURE__ */ __toESM$1(require_picomatch(), 1);
6511
6511
  const isReadonlyArray = Array.isArray;
6512
6512
  const BACKSLASHES = /\\/g;
6513
+ const DRIVE_RELATIVE_PATH = /^[A-Za-z]:$/;
6513
6514
  const isWin = process.platform === "win32";
6514
6515
  const ONLY_PARENT_DIRECTORIES = /^(\/?\.\.)+$/;
6515
6516
  function getPartialMatcher(patterns, options = {}) {
@@ -6575,6 +6576,9 @@ function buildRelative(cwd, root) {
6575
6576
  return p[p.length - 1] === "/" && result !== "" ? `${result}/` : result || ".";
6576
6577
  };
6577
6578
  }
6579
+ function ensureNonDriveRelativePath(path) {
6580
+ return path.replace(DRIVE_RELATIVE_PATH, (match) => `${match}/`);
6581
+ }
6578
6582
  const splitPatternOptions = { parts: true };
6579
6583
  function splitPattern(path) {
6580
6584
  var _result$parts;
@@ -6619,7 +6623,7 @@ function normalizePattern(pattern, opts, props, isIgnore) {
6619
6623
  }
6620
6624
  const potentialRoot = posix.join(cwd, parentDir.slice(i * 3));
6621
6625
  if (potentialRoot[0] !== "." && props.root.length > potentialRoot.length) {
6622
- props.root = potentialRoot;
6626
+ props.root = ensureNonDriveRelativePath(potentialRoot);
6623
6627
  props.depthOffset = -n + i;
6624
6628
  }
6625
6629
  }
@@ -6639,7 +6643,7 @@ function normalizePattern(pattern, opts, props, isIgnore) {
6639
6643
  }
6640
6644
  props.depthOffset = newCommonPath.length;
6641
6645
  props.commonPath = newCommonPath;
6642
- props.root = newCommonPath.length > 0 ? posix.join(cwd, ...newCommonPath) : cwd;
6646
+ props.root = ensureNonDriveRelativePath(newCommonPath.length > 0 ? posix.join(cwd, ...newCommonPath) : cwd);
6643
6647
  }
6644
6648
  return result;
6645
6649
  }
@@ -6728,18 +6732,15 @@ function formatPaths(paths, mapper) {
6728
6732
  }
6729
6733
  const defaultOptions$1 = {
6730
6734
  caseSensitiveMatch: true,
6731
- cwd: process.cwd(),
6732
6735
  debug: !!process.env.TINYGLOBBY_DEBUG,
6733
6736
  expandDirectories: true,
6734
6737
  followSymbolicLinks: true,
6735
6738
  onlyFiles: true
6736
6739
  };
6737
6740
  function getOptions$1(options) {
6738
- const opts = {
6739
- ...defaultOptions$1,
6740
- ...options
6741
- };
6742
- opts.cwd = (opts.cwd instanceof URL ? fileURLToPath$1(opts.cwd) : resolve$1(opts.cwd)).replace(BACKSLASHES, "/");
6741
+ const opts = Object.assign({}, options);
6742
+ for (const key in defaultOptions$1) if (opts[key] === void 0) Object.assign(opts, { [key]: defaultOptions$1[key] });
6743
+ opts.cwd = (opts.cwd instanceof URL ? fileURLToPath$1(opts.cwd) : resolve$1(opts.cwd || process.cwd())).replace(BACKSLASHES, "/");
6743
6744
  opts.ignore = ensureStringArray(opts.ignore);
6744
6745
  opts.fs && (opts.fs = {
6745
6746
  readdir: opts.fs.readdir || readdir$1,
@@ -17499,7 +17500,7 @@ function getBtoa() {
17499
17500
  throw new Error("Unsupported environment: `window.btoa` or `Buffer` should be supported.");
17500
17501
  };
17501
17502
  }
17502
- const btoa = /* @__PURE__ */ getBtoa();
17503
+ const btoa = /*#__PURE__*/ getBtoa();
17503
17504
  var SourceMap = class {
17504
17505
  constructor(properties) {
17505
17506
  this.version = 3;
@@ -20810,7 +20811,10 @@ async function writeTypes(nitro) {
20810
20811
  if (resolvedPath) {
20811
20812
  const { dir, name } = parseNodeModulePath(resolvedPath);
20812
20813
  if (!dir || !name) path = resolvedPath;
20813
- else path = join$2(dir, name, await lookupNodeModuleSubpath(resolvedPath) || "");
20814
+ else {
20815
+ const subpath = await lookupNodeModuleSubpath(resolvedPath);
20816
+ path = subpath && subpath !== "./" ? join$2(dir, name, subpath) : resolvedPath;
20817
+ }
20814
20818
  }
20815
20819
  }
20816
20820
  if (existsSync(path) && !await isDirectory(path)) path = path.replace(/\.[a-z]+$/, "");
@@ -20913,7 +20917,7 @@ async function writeTypes(nitro) {
20913
20917
  for (const alias in tsConfig.compilerOptions.paths) {
20914
20918
  const paths = await Promise.all(tsConfig.compilerOptions.paths[alias].map(async (path) => {
20915
20919
  if (!isAbsolute$2(path)) return path;
20916
- return relativeWithDot(tsconfigDir, (await promises.stat(path).catch(() => null))?.isFile() ? path.replace(/(?<=\w)\.\w+$/g, "") : path);
20920
+ return relativeWithDot(tsconfigDir, (await promises.stat(path).catch(() => null))?.isFile() ? stripPathsExt(path) : path);
20917
20921
  }));
20918
20922
  tsConfig.compilerOptions.paths[alias] = [...new Set(paths)];
20919
20923
  }
@@ -20935,6 +20939,10 @@ function relativeWithDot(from, to) {
20935
20939
  const rel = relative$2(from, to);
20936
20940
  return RELATIVE_RE.test(rel) ? rel : "./" + rel;
20937
20941
  }
20942
+ const PATHS_STRIPPABLE_EXT_RE = /\.(?:tsx?|jsx?|[cm]js)$/;
20943
+ function stripPathsExt(path) {
20944
+ return path.replace(PATHS_STRIPPABLE_EXT_RE, "");
20945
+ }
20938
20946
  const presetsWithConfig = [
20939
20947
  "awsAmplify",
20940
20948
  "awsLambda",
@@ -21071,7 +21079,7 @@ function getNoExternals(nitro) {
21071
21079
  /\.[mc]?tsx?$/,
21072
21080
  /^(?:[\0#~.]|virtual:)/,
21073
21081
  new RegExp("^" + pathRegExp(pkgDir) + "(?!.*node_modules)"),
21074
- ...[nitro.options.rootDir, ...nitro.options.scanDirs.filter((dir) => dir.includes("node_modules") || !dir.startsWith(nitro.options.rootDir))].map((dir) => new RegExp("^" + pathRegExp(dir) + "(?!.*node_modules)"))
21082
+ ...[nitro.options.rootDir, ...[nitro.options.buildDir, ...nitro.options.scanDirs].filter((dir) => dir.includes("node_modules") || !dir.startsWith(nitro.options.rootDir))].map((dir) => new RegExp("^" + pathRegExp(dir) + "(?!.*node_modules)"))
21075
21083
  ];
21076
21084
  if (nitro.options.wasm !== false) noExternal.push(/\.wasm$/);
21077
21085
  if (Array.isArray(nitro.options.noExternals)) noExternal.push(...nitro.options.noExternals.filter(Boolean).map((item) => toPathRegExp(item)));
@@ -21464,12 +21472,17 @@ function rendererTemplate(nitro) {
21464
21472
  import { HTTPResponse } from "h3";
21465
21473
  export const rendererTemplate = () => new HTTPResponse(${JSON.stringify(html)}, { headers: { "content-type": "text/html; charset=utf-8" } });
21466
21474
  `;
21467
- else return `
21475
+ else {
21476
+ const template = compileTemplateToString(html, { contextKeys: [...RENDER_CONTEXT_KEYS] });
21477
+ return `
21468
21478
  import { renderToResponse } from 'rendu'
21469
- import { serverFetch } from 'nitro/app'
21470
- const template = ${compileTemplateToString(html, { contextKeys: [...RENDER_CONTEXT_KEYS] })};
21471
- export const rendererTemplate = (request) => renderToResponse(template, { request, context: { serverFetch } })
21479
+ import { fetch, serverFetch } from 'nitro/app'
21480
+ ${nitro.options.builder === "vite" ? `import { fetchViteEnv } from "nitro/vite/runtime"` : ""}
21481
+ const context = { fetch, serverFetch${nitro.options.builder === "vite" ? ", fetchViteEnv" : ""} }
21482
+ const template = ${template};
21483
+ export const rendererTemplate = (request) => renderToResponse(template, { request, context })
21472
21484
  `;
21485
+ }
21473
21486
  }
21474
21487
  }
21475
21488
  };
@@ -22035,6 +22048,7 @@ function isWellFormedString(input) {
22035
22048
  if (hasStringIsWellFormed) return input.isWellFormed();
22036
22049
  return !/\p{Surrogate}/u.test(input);
22037
22050
  }
22051
+ const identifierNameRE = /^[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*$/u;
22038
22052
  const dataToEsm = function dataToEsm(data, options = {}) {
22039
22053
  var _a, _b;
22040
22054
  const t = options.compact ? "" : "indent" in options ? options.indent : " ";
@@ -22060,10 +22074,13 @@ const dataToEsm = function dataToEsm(data, options = {}) {
22060
22074
  namedExportCode += `export ${declarationType} ${key}${_}=${_}${serialize(value, options.compact ? null : t, "")};${n}`;
22061
22075
  } else {
22062
22076
  defaultExportRows.push(`${stringify(key)}:${_}${serialize(value, options.compact ? null : t, "")}`);
22063
- if (options.includeArbitraryNames && isWellFormedString(key)) {
22064
- const variableName = `${arbitraryNamePrefix}${arbitraryNameExportRows.length}`;
22065
- namedExportCode += `${declarationType} ${variableName}${_}=${_}${serialize(value, options.compact ? null : t, "")};${n}`;
22066
- arbitraryNameExportRows.push(`${variableName} as ${JSON.stringify(key)}`);
22077
+ if (key !== "default") {
22078
+ const isIdentifierName = identifierNameRE.test(key);
22079
+ if (isIdentifierName || options.includeArbitraryNames && isWellFormedString(key)) {
22080
+ const variableName = `${arbitraryNamePrefix}${arbitraryNameExportRows.length}`;
22081
+ namedExportCode += `${declarationType} ${variableName}${_}=${_}${serialize(value, options.compact ? null : t, "")};${n}`;
22082
+ arbitraryNameExportRows.push(`${variableName} as ${isIdentifierName ? key : JSON.stringify(key)}`);
22083
+ }
22067
22084
  }
22068
22085
  }
22069
22086
  const arbitraryExportCode = arbitraryNameExportRows.length > 0 ? `export${_}{${n}${t}${arbitraryNameExportRows.join(`,${n}${t}`)}${n}};${n}` : "";
@@ -28155,7 +28172,7 @@ function virtual(input) {
28155
28172
  filter: { id: include },
28156
28173
  handler: async (id) => {
28157
28174
  const mod = modules.get(id);
28158
- if (!mod) throw new Error(`Virtual module ${id} not found.`);
28175
+ if (!mod) return null;
28159
28176
  return {
28160
28177
  code: await mod.render(),
28161
28178
  map: null
@@ -150,8 +150,12 @@ async function buildProduction(nitro, config) {
150
150
  const rewriteRelativePaths = (input) => {
151
151
  return input.replace(/([\s:])\.\/(\S*)/g, `$1${rOutput}/$2`);
152
152
  };
153
- nitro.logger.success("You can preview this build using `npx nitro preview`");
154
- if (buildInfo.commands.deploy) nitro.logger.success(rewriteRelativePaths("You can deploy this build using `npx nitro deploy --prebuilt`"));
153
+ const previewCommand = nitro.options.framework.previewCommand || "npx nitro preview";
154
+ nitro.logger.success(`You can preview this build using \`${previewCommand}\``);
155
+ if (buildInfo.commands.deploy) {
156
+ const deployCommand = nitro.options.framework.deployCommand || "npx nitro deploy --prebuilt";
157
+ nitro.logger.success(rewriteRelativePaths(`You can deploy this build using \`${deployCommand}\``));
158
+ }
155
159
  }
156
160
  async function rolldownBuild(nitro) {
157
161
  await nitro.hooks.callHook("build:before", nitro);
@@ -17,7 +17,7 @@ function createNitroEnvironment(ctx) {
17
17
  },
18
18
  resolve: {
19
19
  noExternal: ctx.nitro.options.dev ? isWorkerdRunner ? true : [
20
- /^nitro$/,
20
+ /^nitro(\/|$)/,
21
21
  new RegExp(`^(${runtimeDependencies.join("|")})$`),
22
22
  ...ctx.bundlerConfig.base.noExternal
23
23
  ] : true,
@@ -40,13 +40,14 @@ function createNitroEnvironment(ctx) {
40
40
  };
41
41
  }
42
42
  function createServiceEnvironment(ctx, name, serviceConfig) {
43
+ const isDev = ctx.nitro.options.dev;
43
44
  const isWorkerdRunner = _isWorkerdRunner(ctx);
44
45
  return {
45
46
  consumer: "server",
46
47
  build: {
47
48
  rollupOptions: {
48
49
  input: { index: serviceConfig.entry },
49
- external: [/^nitro(\/|$)/]
50
+ ...isDev ? {} : { external: [/^nitro(\/|$)/] }
50
51
  },
51
52
  minify: ctx.nitro.options.minify,
52
53
  sourcemap: ctx.nitro.options.sourcemap,
@@ -55,7 +56,7 @@ function createServiceEnvironment(ctx, name, serviceConfig) {
55
56
  copyPublicDir: false
56
57
  },
57
58
  resolve: {
58
- ...isWorkerdRunner ? { noExternal: true } : {},
59
+ ...isDev ? { noExternal: isWorkerdRunner ? true : [/^nitro(\/|$)/] } : {},
59
60
  conditions: isWorkerdRunner ? [
60
61
  "workerd",
61
62
  "worker",
@@ -122,39 +123,6 @@ async function _loadRunner(ctx, manager) {
122
123
  });
123
124
  await manager.reload(runner);
124
125
  }
125
- const NITRO_PROXY_PREFIX = "\0nitro-env-proxy:";
126
- function nitroServiceProxy() {
127
- return {
128
- name: "nitro:service-proxy",
129
- enforce: "pre",
130
- applyToEnvironment: (env) => env.name !== "nitro" && env.config.consumer === "server",
131
- apply: (_config, configEnv) => configEnv.command === "serve",
132
- resolveId: {
133
- filter: { id: /^nitro(\/|$)/ },
134
- handler(id) {
135
- if (id === "nitro" || id.startsWith("nitro/")) return {
136
- id: NITRO_PROXY_PREFIX + id,
137
- moduleSideEffects: false
138
- };
139
- }
140
- },
141
- load: {
142
- filter: { id: /^\0nitro-env-proxy:/ },
143
- handler(id) {
144
- if (!id.startsWith(NITRO_PROXY_PREFIX)) return;
145
- const originalId = id.slice(17);
146
- return {
147
- code: [
148
- `const _mod = await globalThis.__VITE_ENVIRONMENT_RUNNER_IMPORT__("nitro", ${JSON.stringify(originalId)});`,
149
- `__vite_ssr_exportAll__(_mod);`,
150
- `export default _mod.default;`
151
- ].join("\n"),
152
- map: null
153
- };
154
- }
155
- }
156
- };
157
- }
158
126
  function _isWorkerdRunner(ctx) {
159
127
  return (ctx.nitro.options.devServer.runner || process.env.NITRO_DEV_RUNNER || "node-worker") === "miniflare";
160
128
  }
@@ -174,4 +142,4 @@ function tryResolve(id) {
174
142
  try: true
175
143
  }) || id;
176
144
  }
177
- export { createNitroEnvironment, createServiceEnvironment, createServiceEnvironments, getEnvRunner, initEnvRunner, nitroServiceProxy };
145
+ export { createNitroEnvironment, createServiceEnvironment, createServiceEnvironments, getEnvRunner, initEnvRunner };
@@ -12,11 +12,12 @@ import { Hookable, createDebugger } from "hookable";
12
12
  import { runtimeDir, version } from "nitro/meta";
13
13
  import { existsSync, readFileSync } from "node:fs";
14
14
  import { readFile } from "node:fs/promises";
15
- import { pathToFileURL } from "node:url";
15
+ import "node:url";
16
16
  import { defu } from "defu";
17
17
  import { joinURL, parseURL, withBase, withLeadingSlash, withQuery, withTrailingSlash, withoutBase, withoutTrailingSlash } from "ufo";
18
18
  import { colors } from "consola/utils";
19
19
  import { hash } from "ohash";
20
+ import { EnvServer } from "env-runner";
20
21
  import { toRequest } from "h3";
21
22
  import http from "node:http";
22
23
  const NitroDefaults = {
@@ -267,7 +268,7 @@ async function resolvePathOptions(options) {
267
268
  else {
268
269
  const detected = resolveModulePath("./server", {
269
270
  try: true,
270
- from: options.rootDir,
271
+ from: options.serverDir && options.serverDir !== options.rootDir ? [options.serverDir, options.rootDir] : options.rootDir,
271
272
  extensions: RESOLVE_EXTENSIONS.flatMap((ext) => [ext, `.node${ext}`])
272
273
  });
273
274
  if (detected) {
@@ -530,6 +531,7 @@ async function _loadUserConfig(configOverrides = {}, opts = {}) {
530
531
  let compatibilityDate = configOverrides.compatibilityDate || opts.compatibilityDate || process.env.NITRO_COMPATIBILITY_DATE || process.env.SERVER_COMPATIBILITY_DATE || process.env.COMPATIBILITY_DATE;
531
532
  const { resolvePreset } = await import("../_presets.mjs");
532
533
  let preset = configOverrides.preset || process.env.NITRO_PRESET || process.env.SERVER_PRESET;
534
+ let inlineDefaultPreset;
533
535
  const _dotenv = opts.dotenv ?? (configOverrides.dev && { fileName: [".env", ".env.local"] });
534
536
  const envName = opts.c12?.envName ?? (configOverrides.dev ? "development" : "production");
535
537
  const loadedConfig = await (opts.watch ? watchConfig : loadConfig)({
@@ -550,11 +552,17 @@ async function _loadUserConfig(configOverrides = {}, opts = {}) {
550
552
  dev: true,
551
553
  compatibilityDate: compatibilityDate || "latest"
552
554
  }).then((p) => p?._meta?.name || "nitro-dev").catch(() => "nitro-dev") : "nitro-dev";
553
- else if (!preset) preset = await resolvePreset("", {
554
- static: getConf("static"),
555
- dev: false,
556
- compatibilityDate: compatibilityDate || "latest"
557
- }).then((p) => p?._meta?.name);
555
+ else if (!preset) {
556
+ const defaultPreset = getConf("defaultPreset");
557
+ const resolved = await resolvePreset("", {
558
+ static: getConf("static"),
559
+ dev: false,
560
+ compatibilityDate: compatibilityDate || "latest",
561
+ defaultPreset
562
+ });
563
+ preset = resolved?._meta?.name;
564
+ if (resolved && defaultPreset && typeof defaultPreset !== "string") inlineDefaultPreset = resolved;
565
+ }
558
566
  return {
559
567
  ...configOverrides,
560
568
  preset,
@@ -566,6 +574,7 @@ async function _loadUserConfig(configOverrides = {}, opts = {}) {
566
574
  };
567
575
  },
568
576
  async resolve(id) {
577
+ if (inlineDefaultPreset && id === inlineDefaultPreset._meta?.name) return { config: klona(inlineDefaultPreset) };
569
578
  const preset = await resolvePreset(id, {
570
579
  static: configOverrides.static,
571
580
  compatibilityDate: compatibilityDate || "latest",
@@ -991,6 +1000,8 @@ async function prerender(nitro) {
991
1000
  ...nitro.options._config,
992
1001
  static: false,
993
1002
  rootDir: nitro.options.rootDir,
1003
+ renderer: nitro.options.renderer,
1004
+ virtual: { ...nitro.options.virtual },
994
1005
  logLevel: 0,
995
1006
  preset: "nitro-prerender",
996
1007
  builder: nitro.options.builder === "vite" ? "rolldown" : nitro.options.builder
@@ -999,13 +1010,17 @@ async function prerender(nitro) {
999
1010
  const nitroRenderer = await createNitro(prerendererConfig);
1000
1011
  const prerenderStartTime = Date.now();
1001
1012
  await nitro.hooks.callHook("prerender:init", nitroRenderer);
1013
+ await nitroRenderer.routing.sync();
1002
1014
  let path = relative(nitro.options.output.dir, nitro.options.output.publicDir);
1003
1015
  if (!path.startsWith(".")) path = `./${path}`;
1004
1016
  nitroRenderer.options.commands.preview = `npx serve ${path}`;
1005
1017
  nitroRenderer.options.output.dir = nitro.options.output.dir;
1006
1018
  await build(nitroRenderer);
1007
1019
  const serverFilename = typeof nitroRenderer.options.rollupConfig?.output?.entryFileNames === "string" ? nitroRenderer.options.rollupConfig.output.entryFileNames : "index.mjs";
1008
- const prerenderer = await import(pathToFileURL(resolve(nitroRenderer.options.output.serverDir, serverFilename)).href).then((m) => m.default);
1020
+ const prerenderer = await new EnvServer({
1021
+ runner: "node-worker",
1022
+ entry: resolve(nitroRenderer.options.output.serverDir, serverFilename)
1023
+ }).start();
1009
1024
  const routeRules = createRouter();
1010
1025
  for (const [route, rules] of Object.entries(nitro.options.routeRules)) addRoute(routeRules, void 0, route, rules);
1011
1026
  const _getRouteRules = (path) => defu({}, ...findAllRoutes(routeRules, void 0, path).map((r) => r.data).reverse());
@@ -37,7 +37,7 @@ function isReference(node, parent) {
37
37
  }
38
38
  return false;
39
39
  }
40
- var version = "29.0.1";
40
+ var version = "29.0.2";
41
41
  var peerDependencies = { rollup: "^2.68.0||^3.0.0||^4.0.0" };
42
42
  function tryParse(parse, code, id) {
43
43
  try {
@@ -307,7 +307,7 @@ export function getAugmentedNamespace(n) {
307
307
  var isInstance = false;
308
308
  try {
309
309
  isInstance = this instanceof a;
310
- } catch {}
310
+ } catch (e) {}
311
311
  if (isInstance) {
312
312
  return Reflect.construct(f, arguments, this.constructor);
313
313
  }
@@ -1,5 +1,6 @@
1
1
  import { EventEmitter } from "node:events";
2
2
  import * as stream from "node:stream";
3
+ import { Duplex } from "node:stream";
3
4
  import http, { IncomingMessage } from "node:http";
4
5
  import http2 from "node:http2";
5
6
  import { Socket } from "node:net";