@nuxt/kit 3.15.4 → 3.16.1

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/README.md CHANGED
@@ -8,6 +8,7 @@
8
8
  <a href="https://github.com/nuxt/nuxt/tree/main/LICENSE"><img src="https://img.shields.io/github/license/nuxt/nuxt.svg?style=flat&colorA=18181B&colorB=28CF8D" alt="License"></a>
9
9
  <a href="https://nuxt.com"><img src="https://img.shields.io/badge/Nuxt%20Docs-18181B?logo=nuxt.js" alt="Website"></a>
10
10
  <a href="https://chat.nuxt.dev"><img src="https://img.shields.io/badge/Nuxt%20Discord-18181B?logo=discord" alt="Discord"></a>
11
+ <a href="https://securityscorecards.dev/"><img src="https://api.securityscorecards.dev/projects/github.com/nuxt/nuxt/badge" alt="Nuxt openssf scorecard score"></a>
11
12
  </p>
12
13
 
13
14
  Nuxt is a free and open-source framework with an intuitive and extendable way to create type-safe, performant and production-grade full-stack web applications and websites with Vue.js.
@@ -32,7 +33,6 @@ It provides a number of features that make it easy to build fast, SEO-friendly,
32
33
  - 🧩 [Modules](#modules)
33
34
  - ❤️ [Contribute](#contribute)
34
35
  - 🏠 [Local Development](#local-development)
35
- - ⛰️ [Nuxt 2](#nuxt-2)
36
36
  - 🛟 [Professional Support](#professional-support)
37
37
  - 🔗 [Follow Us](#follow-us)
38
38
  - ⚖️ [License](#license)
@@ -44,7 +44,7 @@ It provides a number of features that make it easy to build fast, SEO-friendly,
44
44
  Use the following command to create a new starter project. This will create a starter project with all the necessary files and dependencies:
45
45
 
46
46
  ```bash
47
- npx nuxi@latest init <my-project>
47
+ npm create nuxt <my-project>
48
48
  ```
49
49
 
50
50
  > [!TIP]
package/dist/index.d.mts CHANGED
@@ -1,10 +1,10 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
- import { ModuleOptions, ModuleDefinition, NuxtModule, NuxtConfig, Nuxt, ModuleMeta, NuxtOptions, SchemaDefinition, ImportPresetWithDeprecation, NuxtCompatibility, NuxtCompatibilityIssues, ComponentsDir, Component, NuxtTemplate, NuxtHooks, NuxtMiddleware, NuxtPlugin, NuxtPluginTemplate, ResolvedNuxtTemplate, NuxtServerTemplate, NuxtTypeTemplate } from '@nuxt/schema';
2
+ import { ModuleOptions, ModuleDefinition, NuxtModule, NuxtConfig, Nuxt, ModuleMeta, NuxtOptions, SchemaDefinition, ImportPresetWithDeprecation, NuxtCompatibility, NuxtCompatibilityIssues, Component, ComponentsDir, NuxtTemplate, NuxtMiddleware, NuxtHooks, NuxtPlugin, NuxtPluginTemplate, ResolvedNuxtTemplate, NuxtServerTemplate, NuxtTypeTemplate } from '@nuxt/schema';
3
3
  import { LoadConfigOptions } from 'c12';
4
4
  import { Import } from 'unimport';
5
- import { Configuration, WebpackPluginInstance } from 'webpack';
5
+ import { WebpackPluginInstance, Configuration } from 'webpack';
6
6
  import { RspackPluginInstance } from '@rspack/core';
7
- import { UserConfig, Plugin } from 'vite';
7
+ import { Plugin, UserConfig } from 'vite';
8
8
  import * as unctx from 'unctx';
9
9
  import { NitroRouteConfig, NitroEventHandler, NitroDevEventHandler, Nitro } from 'nitropack';
10
10
  import * as consola from 'consola';
@@ -201,8 +201,13 @@ type AddComponentOptions = {
201
201
  */
202
202
  declare function addComponent(opts: AddComponentOptions): void;
203
203
 
204
- /** Direct access to the Nuxt context - see https://github.com/unjs/unctx. */
204
+ /**
205
+ * Direct access to the Nuxt global context - see https://github.com/unjs/unctx.
206
+ * @deprecated Use `getNuxtCtx` instead
207
+ */
205
208
  declare const nuxtCtx: unctx.UseContext<Nuxt>;
209
+ /** Direct access to the Nuxt context with asyncLocalStorage - see https://github.com/unjs/unctx. */
210
+ declare const getNuxtCtx: () => Nuxt | null;
206
211
  /**
207
212
  * Get access to Nuxt instance.
208
213
  *
@@ -226,6 +231,7 @@ declare function useNuxt(): Nuxt;
226
231
  * ```
227
232
  */
228
233
  declare function tryUseNuxt(): Nuxt | null;
234
+ declare function runWithNuxtContext<T extends (...args: any[]) => any>(nuxt: Nuxt, fn: T): ReturnType<T>;
229
235
 
230
236
  declare function createIsIgnored(nuxt?: _nuxt_schema.Nuxt | null): (pathname: string, stats?: unknown) => boolean;
231
237
  /**
@@ -395,8 +401,15 @@ declare function addServerTemplate(template: NuxtServerTemplate): NuxtServerTemp
395
401
  /**
396
402
  * Renders given types during build to disk in the project `buildDir`
397
403
  * and register them as types.
404
+ *
405
+ * You can pass a second context object to specify in which context the type should be added.
406
+ *
407
+ * If no context object is passed, then it will only be added to the nuxt context.
398
408
  */
399
- declare function addTypeTemplate<T>(_template: NuxtTypeTemplate<T>): ResolvedNuxtTemplate<T>;
409
+ declare function addTypeTemplate<T>(_template: NuxtTypeTemplate<T>, context?: {
410
+ nitro?: boolean;
411
+ nuxt?: boolean;
412
+ }): ResolvedNuxtTemplate<T>;
400
413
  /**
401
414
  * Normalize a nuxt template object
402
415
  */
@@ -415,15 +428,20 @@ declare const logger: consola.ConsolaInstance;
415
428
  declare function useLogger(tag?: string, options?: Partial<ConsolaOptions>): consola.ConsolaInstance;
416
429
 
417
430
  interface ResolveModuleOptions {
431
+ /** @deprecated use `url` with URLs pointing at a file - never a directory */
418
432
  paths?: string | string[];
433
+ url?: URL | URL[];
419
434
  }
435
+ declare function directoryToURL(dir: string): URL;
420
436
  /**
421
437
  * Resolve a module from a given root path using an algorithm patterned on
422
438
  * the upcoming `import.meta.resolve`. It returns a file URL
423
439
  *
424
440
  * @internal
425
441
  */
426
- declare function tryResolveModule(id: string, url?: string | string[]): Promise<string | undefined>;
442
+ declare function tryResolveModule(id: string, url: URL | URL[]): Promise<string | undefined>;
443
+ /** @deprecated pass URLs pointing at files */
444
+ declare function tryResolveModule(id: string, url: string | string[]): Promise<string | undefined>;
427
445
  declare function resolveModule(id: string, options?: ResolveModuleOptions): string;
428
446
  interface ImportModuleOptions extends ResolveModuleOptions {
429
447
  /** Automatically de-default the result of requiring the module. */
@@ -451,4 +469,4 @@ declare const templateUtils: {
451
469
  }) => string;
452
470
  };
453
471
 
454
- export { type AddComponentOptions, type AddPluginOptions, type AddRouteMiddlewareOptions, type ExtendConfigOptions, type ExtendRouteRulesOptions, type ExtendViteConfigOptions, type ExtendWebpackConfigOptions, type ImportModuleOptions, type LoadNuxtConfigOptions, type LoadNuxtOptions, type ResolveModuleOptions, type ResolvePathOptions, type Resolver, addBuildPlugin, addComponent, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, addLayout, addPlugin, addPluginTemplate, addPrerenderRoutes, addRouteMiddleware, addRspackPlugin, addServerHandler, addServerImports, addServerImportsDir, addServerPlugin, addServerScanDir, addServerTemplate, addTemplate, addTypeTemplate, addVitePlugin, addWebpackPlugin, assertNuxtCompatibility, buildNuxt, checkNuxtCompatibility, compileTemplate, createIsIgnored, createResolver, defineNuxtModule, extendNuxtSchema, extendPages, extendRouteRules, extendRspackConfig, extendViteConfig, extendWebpackConfig, findPath, getDirectory, getNuxtModuleVersion, getNuxtVersion, hasNuxtCompatibility, hasNuxtModule, hasNuxtModuleCompatibility, importModule, installModule, isIgnored, isNuxt2, isNuxt3, isNuxtMajorVersion, loadNuxt, loadNuxtConfig, loadNuxtModuleInstance, logger, normalizeModuleTranspilePath, normalizePlugin, normalizeSemanticVersion, normalizeTemplate, nuxtCtx, requireModule, resolveAlias, resolveFiles, resolveIgnorePatterns, resolveModule, resolveNuxtModule, resolvePath, templateUtils, tryImportModule, tryRequireModule, tryResolveModule, tryUseNuxt, updateRuntimeConfig, updateTemplates, useLogger, useNitro, useNuxt, useRuntimeConfig, writeTypes };
472
+ export { type AddComponentOptions, type AddPluginOptions, type AddRouteMiddlewareOptions, type ExtendConfigOptions, type ExtendRouteRulesOptions, type ExtendViteConfigOptions, type ExtendWebpackConfigOptions, type ImportModuleOptions, type LoadNuxtConfigOptions, type LoadNuxtOptions, type ResolveModuleOptions, type ResolvePathOptions, type Resolver, addBuildPlugin, addComponent, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, addLayout, addPlugin, addPluginTemplate, addPrerenderRoutes, addRouteMiddleware, addRspackPlugin, addServerHandler, addServerImports, addServerImportsDir, addServerPlugin, addServerScanDir, addServerTemplate, addTemplate, addTypeTemplate, addVitePlugin, addWebpackPlugin, assertNuxtCompatibility, buildNuxt, checkNuxtCompatibility, compileTemplate, createIsIgnored, createResolver, defineNuxtModule, directoryToURL, extendNuxtSchema, extendPages, extendRouteRules, extendRspackConfig, extendViteConfig, extendWebpackConfig, findPath, getDirectory, getNuxtCtx, getNuxtModuleVersion, getNuxtVersion, hasNuxtCompatibility, hasNuxtModule, hasNuxtModuleCompatibility, importModule, installModule, isIgnored, isNuxt2, isNuxt3, isNuxtMajorVersion, loadNuxt, loadNuxtConfig, loadNuxtModuleInstance, logger, normalizeModuleTranspilePath, normalizePlugin, normalizeSemanticVersion, normalizeTemplate, nuxtCtx, requireModule, resolveAlias, resolveFiles, resolveIgnorePatterns, resolveModule, resolveNuxtModule, resolvePath, runWithNuxtContext, templateUtils, tryImportModule, tryRequireModule, tryResolveModule, tryUseNuxt, updateRuntimeConfig, updateTemplates, useLogger, useNitro, useNuxt, useRuntimeConfig, writeTypes };
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
- import { ModuleOptions, ModuleDefinition, NuxtModule, NuxtConfig, Nuxt, ModuleMeta, NuxtOptions, SchemaDefinition, ImportPresetWithDeprecation, NuxtCompatibility, NuxtCompatibilityIssues, ComponentsDir, Component, NuxtTemplate, NuxtHooks, NuxtMiddleware, NuxtPlugin, NuxtPluginTemplate, ResolvedNuxtTemplate, NuxtServerTemplate, NuxtTypeTemplate } from '@nuxt/schema';
2
+ import { ModuleOptions, ModuleDefinition, NuxtModule, NuxtConfig, Nuxt, ModuleMeta, NuxtOptions, SchemaDefinition, ImportPresetWithDeprecation, NuxtCompatibility, NuxtCompatibilityIssues, Component, ComponentsDir, NuxtTemplate, NuxtMiddleware, NuxtHooks, NuxtPlugin, NuxtPluginTemplate, ResolvedNuxtTemplate, NuxtServerTemplate, NuxtTypeTemplate } from '@nuxt/schema';
3
3
  import { LoadConfigOptions } from 'c12';
4
4
  import { Import } from 'unimport';
5
- import { Configuration, WebpackPluginInstance } from 'webpack';
5
+ import { WebpackPluginInstance, Configuration } from 'webpack';
6
6
  import { RspackPluginInstance } from '@rspack/core';
7
- import { UserConfig, Plugin } from 'vite';
7
+ import { Plugin, UserConfig } from 'vite';
8
8
  import * as unctx from 'unctx';
9
9
  import { NitroRouteConfig, NitroEventHandler, NitroDevEventHandler, Nitro } from 'nitropack';
10
10
  import * as consola from 'consola';
@@ -201,8 +201,13 @@ type AddComponentOptions = {
201
201
  */
202
202
  declare function addComponent(opts: AddComponentOptions): void;
203
203
 
204
- /** Direct access to the Nuxt context - see https://github.com/unjs/unctx. */
204
+ /**
205
+ * Direct access to the Nuxt global context - see https://github.com/unjs/unctx.
206
+ * @deprecated Use `getNuxtCtx` instead
207
+ */
205
208
  declare const nuxtCtx: unctx.UseContext<Nuxt>;
209
+ /** Direct access to the Nuxt context with asyncLocalStorage - see https://github.com/unjs/unctx. */
210
+ declare const getNuxtCtx: () => Nuxt | null;
206
211
  /**
207
212
  * Get access to Nuxt instance.
208
213
  *
@@ -226,6 +231,7 @@ declare function useNuxt(): Nuxt;
226
231
  * ```
227
232
  */
228
233
  declare function tryUseNuxt(): Nuxt | null;
234
+ declare function runWithNuxtContext<T extends (...args: any[]) => any>(nuxt: Nuxt, fn: T): ReturnType<T>;
229
235
 
230
236
  declare function createIsIgnored(nuxt?: _nuxt_schema.Nuxt | null): (pathname: string, stats?: unknown) => boolean;
231
237
  /**
@@ -395,8 +401,15 @@ declare function addServerTemplate(template: NuxtServerTemplate): NuxtServerTemp
395
401
  /**
396
402
  * Renders given types during build to disk in the project `buildDir`
397
403
  * and register them as types.
404
+ *
405
+ * You can pass a second context object to specify in which context the type should be added.
406
+ *
407
+ * If no context object is passed, then it will only be added to the nuxt context.
398
408
  */
399
- declare function addTypeTemplate<T>(_template: NuxtTypeTemplate<T>): ResolvedNuxtTemplate<T>;
409
+ declare function addTypeTemplate<T>(_template: NuxtTypeTemplate<T>, context?: {
410
+ nitro?: boolean;
411
+ nuxt?: boolean;
412
+ }): ResolvedNuxtTemplate<T>;
400
413
  /**
401
414
  * Normalize a nuxt template object
402
415
  */
@@ -415,15 +428,20 @@ declare const logger: consola.ConsolaInstance;
415
428
  declare function useLogger(tag?: string, options?: Partial<ConsolaOptions>): consola.ConsolaInstance;
416
429
 
417
430
  interface ResolveModuleOptions {
431
+ /** @deprecated use `url` with URLs pointing at a file - never a directory */
418
432
  paths?: string | string[];
433
+ url?: URL | URL[];
419
434
  }
435
+ declare function directoryToURL(dir: string): URL;
420
436
  /**
421
437
  * Resolve a module from a given root path using an algorithm patterned on
422
438
  * the upcoming `import.meta.resolve`. It returns a file URL
423
439
  *
424
440
  * @internal
425
441
  */
426
- declare function tryResolveModule(id: string, url?: string | string[]): Promise<string | undefined>;
442
+ declare function tryResolveModule(id: string, url: URL | URL[]): Promise<string | undefined>;
443
+ /** @deprecated pass URLs pointing at files */
444
+ declare function tryResolveModule(id: string, url: string | string[]): Promise<string | undefined>;
427
445
  declare function resolveModule(id: string, options?: ResolveModuleOptions): string;
428
446
  interface ImportModuleOptions extends ResolveModuleOptions {
429
447
  /** Automatically de-default the result of requiring the module. */
@@ -451,4 +469,4 @@ declare const templateUtils: {
451
469
  }) => string;
452
470
  };
453
471
 
454
- export { type AddComponentOptions, type AddPluginOptions, type AddRouteMiddlewareOptions, type ExtendConfigOptions, type ExtendRouteRulesOptions, type ExtendViteConfigOptions, type ExtendWebpackConfigOptions, type ImportModuleOptions, type LoadNuxtConfigOptions, type LoadNuxtOptions, type ResolveModuleOptions, type ResolvePathOptions, type Resolver, addBuildPlugin, addComponent, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, addLayout, addPlugin, addPluginTemplate, addPrerenderRoutes, addRouteMiddleware, addRspackPlugin, addServerHandler, addServerImports, addServerImportsDir, addServerPlugin, addServerScanDir, addServerTemplate, addTemplate, addTypeTemplate, addVitePlugin, addWebpackPlugin, assertNuxtCompatibility, buildNuxt, checkNuxtCompatibility, compileTemplate, createIsIgnored, createResolver, defineNuxtModule, extendNuxtSchema, extendPages, extendRouteRules, extendRspackConfig, extendViteConfig, extendWebpackConfig, findPath, getDirectory, getNuxtModuleVersion, getNuxtVersion, hasNuxtCompatibility, hasNuxtModule, hasNuxtModuleCompatibility, importModule, installModule, isIgnored, isNuxt2, isNuxt3, isNuxtMajorVersion, loadNuxt, loadNuxtConfig, loadNuxtModuleInstance, logger, normalizeModuleTranspilePath, normalizePlugin, normalizeSemanticVersion, normalizeTemplate, nuxtCtx, requireModule, resolveAlias, resolveFiles, resolveIgnorePatterns, resolveModule, resolveNuxtModule, resolvePath, templateUtils, tryImportModule, tryRequireModule, tryResolveModule, tryUseNuxt, updateRuntimeConfig, updateTemplates, useLogger, useNitro, useNuxt, useRuntimeConfig, writeTypes };
472
+ export { type AddComponentOptions, type AddPluginOptions, type AddRouteMiddlewareOptions, type ExtendConfigOptions, type ExtendRouteRulesOptions, type ExtendViteConfigOptions, type ExtendWebpackConfigOptions, type ImportModuleOptions, type LoadNuxtConfigOptions, type LoadNuxtOptions, type ResolveModuleOptions, type ResolvePathOptions, type Resolver, addBuildPlugin, addComponent, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, addLayout, addPlugin, addPluginTemplate, addPrerenderRoutes, addRouteMiddleware, addRspackPlugin, addServerHandler, addServerImports, addServerImportsDir, addServerPlugin, addServerScanDir, addServerTemplate, addTemplate, addTypeTemplate, addVitePlugin, addWebpackPlugin, assertNuxtCompatibility, buildNuxt, checkNuxtCompatibility, compileTemplate, createIsIgnored, createResolver, defineNuxtModule, directoryToURL, extendNuxtSchema, extendPages, extendRouteRules, extendRspackConfig, extendViteConfig, extendWebpackConfig, findPath, getDirectory, getNuxtCtx, getNuxtModuleVersion, getNuxtVersion, hasNuxtCompatibility, hasNuxtModule, hasNuxtModuleCompatibility, importModule, installModule, isIgnored, isNuxt2, isNuxt3, isNuxtMajorVersion, loadNuxt, loadNuxtConfig, loadNuxtModuleInstance, logger, normalizeModuleTranspilePath, normalizePlugin, normalizeSemanticVersion, normalizeTemplate, nuxtCtx, requireModule, resolveAlias, resolveFiles, resolveIgnorePatterns, resolveModule, resolveNuxtModule, resolvePath, runWithNuxtContext, templateUtils, tryImportModule, tryRequireModule, tryResolveModule, tryUseNuxt, updateRuntimeConfig, updateTemplates, useLogger, useNitro, useNuxt, useRuntimeConfig, writeTypes };
package/dist/index.mjs CHANGED
@@ -4,25 +4,27 @@ import defu$1, { defu } from 'defu';
4
4
  import { applyDefaults } from 'untyped';
5
5
  import { dirname, relative, join, resolve, normalize, isAbsolute, basename, parse } from 'pathe';
6
6
  import { consola } from 'consola';
7
- import { getContext } from 'unctx';
7
+ import { AsyncLocalStorage } from 'node:async_hooks';
8
+ import { getContext, createContext } from 'unctx';
8
9
  import satisfies from 'semver/functions/satisfies.js';
9
- import { readPackageJSON, resolvePackageJSON } from 'pkg-types';
10
+ import { readPackageJSON } from 'pkg-types';
10
11
  import { genSafeVariableName, genDynamicImport, genImport } from 'knitwork';
11
- import { fileURLToPath, pathToFileURL } from 'node:url';
12
+ import { pathToFileURL, fileURLToPath } from 'node:url';
12
13
  import { createJiti } from 'jiti';
13
- import { resolvePath as resolvePath$1, parseNodeModulePath, resolve as resolve$1, resolvePathSync, interopDefault } from 'mlly';
14
+ import { interopDefault, parseNodeModulePath } from 'mlly';
15
+ import { resolveModulePath, resolveModuleURL } from 'exsolve';
14
16
  import { isRelative, withTrailingSlash } from 'ufo';
15
17
  import { globby } from 'globby';
16
18
  import { resolveAlias as resolveAlias$1 } from 'pathe/utils';
17
19
  import ignore from 'ignore';
18
20
  import { loadConfig } from 'c12';
19
- import { isWindows } from 'std-env';
20
21
  import process$1 from 'node:process';
21
22
  import destr from 'destr';
22
- import { snakeCase, kebabCase, pascalCase } from 'scule';
23
+ import { snakeCase, pascalCase, kebabCase } from 'scule';
23
24
  import { klona } from 'klona';
24
25
  import { hash } from 'ohash';
25
26
  import { gte } from 'semver';
27
+ import { captureStackTrace } from 'errx';
26
28
  import { isAbsolute as isAbsolute$1 } from 'node:path';
27
29
 
28
30
  const logger = consola;
@@ -31,15 +33,23 @@ function useLogger(tag, options = {}) {
31
33
  }
32
34
 
33
35
  const nuxtCtx = getContext("nuxt");
36
+ const asyncNuxtStorage = createContext({
37
+ asyncContext: true,
38
+ AsyncLocalStorage
39
+ });
40
+ const getNuxtCtx = () => asyncNuxtStorage.tryUse();
34
41
  function useNuxt() {
35
- const instance = nuxtCtx.tryUse();
42
+ const instance = asyncNuxtStorage.tryUse() || nuxtCtx.tryUse();
36
43
  if (!instance) {
37
44
  throw new Error("Nuxt instance is unavailable!");
38
45
  }
39
46
  return instance;
40
47
  }
41
48
  function tryUseNuxt() {
42
- return nuxtCtx.tryUse();
49
+ return asyncNuxtStorage.tryUse() || nuxtCtx.tryUse();
50
+ }
51
+ function runWithNuxtContext(nuxt, fn) {
52
+ return asyncNuxtStorage.call(nuxt, fn);
43
53
  }
44
54
 
45
55
  const SEMANTIC_VERSION_RE = /-\d+\.[0-9a-f]+/;
@@ -91,12 +101,17 @@ async function checkNuxtCompatibility(constraints, nuxt = useNuxt()) {
91
101
  message: `Not compatible with \`${nuxt.options.builder}\`.`
92
102
  });
93
103
  } else {
94
- const builderVersion = await readPackageJSON(nuxt.options.builder, { url: nuxt.options.modulesDir }).then((r) => r.version).catch(() => undefined);
95
- if (builderVersion && !satisfies(normalizeSemanticVersion(builderVersion), constraint, { includePrerelease: true })) {
96
- issues.push({
97
- name: "builder",
98
- message: `Not compatible with \`${builderVersion}\` of \`${currentBuilder}\`. This module requires \`${constraint}\`.`
99
- });
104
+ for (const parent of [nuxt.options.rootDir, nuxt.options.workspaceDir, import.meta.url]) {
105
+ const builderVersion = await readPackageJSON(nuxt.options.builder, { parent }).then((r) => r.version).catch(() => void 0);
106
+ if (builderVersion) {
107
+ if (!satisfies(normalizeSemanticVersion(builderVersion), constraint, { includePrerelease: true })) {
108
+ issues.push({
109
+ name: "builder",
110
+ message: `Not compatible with \`${builderVersion}\` of \`${currentBuilder}\`. This module requires \`${constraint}\`.`
111
+ });
112
+ }
113
+ break;
114
+ }
100
115
  }
101
116
  }
102
117
  }
@@ -2066,6 +2081,7 @@ function filterInPlace(array, predicate) {
2066
2081
  return array;
2067
2082
  }
2068
2083
  const MODE_RE = /\.(server|client)(\.\w+)*$/;
2084
+ const distDirURL = new URL(".", import.meta.url);
2069
2085
 
2070
2086
  async function compileTemplate(template$1, ctx) {
2071
2087
  const data = { ...ctx, options: template$1.options };
@@ -2121,9 +2137,7 @@ function _defineNuxtModule(definition) {
2121
2137
  return Promise.resolve(options);
2122
2138
  }
2123
2139
  async function normalizedModule(inlineOptions, nuxt) {
2124
- if (!nuxt) {
2125
- nuxt = tryUseNuxt() || this.nuxt;
2126
- }
2140
+ nuxt ||= tryUseNuxt() || this.nuxt;
2127
2141
  const uniqueKey = module.meta.name || module.meta.configKey;
2128
2142
  if (uniqueKey) {
2129
2143
  nuxt.options._requiredModules ||= {};
@@ -2151,7 +2165,7 @@ ${issues.toString()}`);
2151
2165
  const setupTime = Math.round(perf * 100) / 100;
2152
2166
  if (setupTime > 5e3 && uniqueKey !== "@nuxt/telemetry") {
2153
2167
  logger.warn(`Slow module \`${uniqueKey || "<no name>"}\` took \`${setupTime}ms\` to setup.`);
2154
- } else if (nuxt.options.debug) {
2168
+ } else if (nuxt.options.debug && nuxt.options.debug.modules) {
2155
2169
  logger.info(`Module \`${uniqueKey || "<no name>"}\` took \`${setupTime}ms\` to setup.`);
2156
2170
  }
2157
2171
  if (res === false) {
@@ -2208,6 +2222,51 @@ function nuxt2Shims(nuxt) {
2208
2222
  });
2209
2223
  }
2210
2224
 
2225
+ function directoryToURL(dir) {
2226
+ return pathToFileURL(dir + "/");
2227
+ }
2228
+ function tryResolveModule(id, url = import.meta.url) {
2229
+ return Promise.resolve(resolveModulePath(id, {
2230
+ from: url,
2231
+ suffixes: ["", "index"],
2232
+ try: true
2233
+ }));
2234
+ }
2235
+ function resolveModule(id, options) {
2236
+ return resolveModulePath(id, {
2237
+ from: options?.url ?? options?.paths ?? [import.meta.url],
2238
+ extensions: [".js", ".mjs", ".cjs", ".ts", ".mts", ".cts"]
2239
+ });
2240
+ }
2241
+ async function importModule(id, opts) {
2242
+ const resolvedPath = resolveModule(id, opts);
2243
+ return await import(pathToFileURL(resolvedPath).href).then((r) => opts?.interopDefault !== false ? interopDefault(r) : r);
2244
+ }
2245
+ function tryImportModule(id, opts) {
2246
+ try {
2247
+ return importModule(id, opts).catch(() => void 0);
2248
+ } catch {
2249
+ }
2250
+ }
2251
+ const warnings = /* @__PURE__ */ new Set();
2252
+ function requireModule(id, opts) {
2253
+ if (!warnings.has(id)) {
2254
+ console.warn("[@nuxt/kit] `requireModule` is deprecated. Please use `importModule` instead.");
2255
+ warnings.add(id);
2256
+ }
2257
+ const resolvedPath = resolveModule(id, opts);
2258
+ const jiti = createJiti(import.meta.url, {
2259
+ interopDefault: opts?.interopDefault !== false
2260
+ });
2261
+ return jiti(pathToFileURL(resolvedPath).href);
2262
+ }
2263
+ function tryRequireModule(id, opts) {
2264
+ try {
2265
+ return requireModule(id, opts);
2266
+ } catch {
2267
+ }
2268
+ }
2269
+
2211
2270
  function createIsIgnored(nuxt = tryUseNuxt()) {
2212
2271
  return (pathname, stats) => isIgnored(pathname, stats, nuxt);
2213
2272
  }
@@ -2285,9 +2344,7 @@ async function findPath(paths, opts, pathType = "file") {
2285
2344
  return null;
2286
2345
  }
2287
2346
  function resolveAlias(path, alias) {
2288
- if (!alias) {
2289
- alias = tryUseNuxt()?.options.alias || {};
2290
- }
2347
+ alias ||= tryUseNuxt()?.options.alias || {};
2291
2348
  return resolveAlias$1(path, alias);
2292
2349
  }
2293
2350
  function createResolver(base) {
@@ -2354,7 +2411,7 @@ async function _resolvePathGranularly(path, opts = {}) {
2354
2411
  const cwd = opts.cwd || (nuxt ? nuxt.options.rootDir : process.cwd());
2355
2412
  const extensions = opts.extensions || (nuxt ? nuxt.options.extensions : [".ts", ".mjs", ".cjs", ".json"]);
2356
2413
  const modulesDir = nuxt ? nuxt.options.modulesDir : [];
2357
- path = resolveAlias(path);
2414
+ path = resolveAlias$1(path, opts.alias ?? nuxt?.options.alias ?? {});
2358
2415
  if (!isAbsolute(path)) {
2359
2416
  path = resolve(cwd, path);
2360
2417
  }
@@ -2377,7 +2434,11 @@ async function _resolvePathGranularly(path, opts = {}) {
2377
2434
  return indexPath;
2378
2435
  }
2379
2436
  }
2380
- const resolvedModulePath = await resolvePath$1(_path, { url: [cwd, ...modulesDir] }).catch(() => null);
2437
+ const resolvedModulePath = resolveModulePath(_path, {
2438
+ try: true,
2439
+ suffixes: ["", "index"],
2440
+ from: [cwd, ...modulesDir].map((d) => directoryToURL(d))
2441
+ });
2381
2442
  if (resolvedModulePath) {
2382
2443
  return {
2383
2444
  path: resolvedModulePath,
@@ -2424,7 +2485,7 @@ async function installModule(moduleToInstall, inlineOptions, nuxt = useNuxt()) {
2424
2485
  localLayerModuleDirs.push(resolve(srcDir, l.config?.dir?.modules || "modules").replace(/\/?$/, "/"));
2425
2486
  }
2426
2487
  }
2427
- const res = (isNuxt2() ? await nuxtModule.call(nuxt.moduleContainer, inlineOptions, nuxt) : await nuxtModule(inlineOptions, nuxt)) ?? {};
2488
+ const res = (isNuxt2() ? await nuxtModule.call(nuxt.moduleContainer, inlineOptions, nuxt) : nuxt.options.experimental?.debugModuleMutation && nuxt._asyncLocalStorageModule ? await nuxt._asyncLocalStorageModule.run(nuxtModule, () => nuxtModule(inlineOptions || {}, nuxt)) : await nuxtModule(inlineOptions || {}, nuxt)) ?? {};
2428
2489
  if (res === false) {
2429
2490
  return;
2430
2491
  }
@@ -2439,12 +2500,13 @@ async function installModule(moduleToInstall, inlineOptions, nuxt = useNuxt()) {
2439
2500
  }
2440
2501
  }
2441
2502
  nuxt.options._installedModules ||= [];
2442
- const entryPath = typeof moduleToInstall === "string" ? resolveAlias(moduleToInstall) : undefined;
2503
+ const entryPath = typeof moduleToInstall === "string" ? resolveAlias(moduleToInstall) : void 0;
2443
2504
  if (typeof moduleToInstall === "string" && entryPath !== moduleToInstall) {
2444
2505
  buildTimeModuleMeta.rawPath = moduleToInstall;
2445
2506
  }
2446
2507
  nuxt.options._installedModules.push({
2447
2508
  meta: defu(await nuxtModule.getMeta?.(), buildTimeModuleMeta),
2509
+ module: nuxtModule,
2448
2510
  timings: res.timings,
2449
2511
  entryPath
2450
2512
  });
@@ -2459,46 +2521,52 @@ function getDirectory(p) {
2459
2521
  const normalizeModuleTranspilePath = (p) => {
2460
2522
  return getDirectory(p).split("node_modules/").pop();
2461
2523
  };
2524
+ const MissingModuleMatcher = /Cannot find module\s+['"]?([^'")\s]+)['"]?/i;
2462
2525
  async function loadNuxtModuleInstance(nuxtModule, nuxt = useNuxt()) {
2463
2526
  let buildTimeModuleMeta = {};
2464
- let resolvedModulePath;
2527
+ if (typeof nuxtModule === "function") {
2528
+ return {
2529
+ nuxtModule,
2530
+ buildTimeModuleMeta
2531
+ };
2532
+ }
2533
+ if (typeof nuxtModule !== "string") {
2534
+ throw new TypeError(`Nuxt module should be a function or a string to import. Received: ${nuxtModule}.`);
2535
+ }
2465
2536
  const jiti = createJiti(nuxt.options.rootDir, { alias: nuxt.options.alias });
2466
- if (typeof nuxtModule === "string") {
2467
- const paths = /* @__PURE__ */ new Set();
2468
- nuxtModule = resolveAlias(nuxtModule, nuxt.options.alias);
2469
- if (isRelative(nuxtModule)) {
2470
- nuxtModule = resolve(nuxt.options.rootDir, nuxtModule);
2471
- }
2472
- paths.add(join(nuxtModule, "nuxt"));
2473
- paths.add(join(nuxtModule, "module"));
2474
- paths.add(nuxtModule);
2475
- for (const path of paths) {
2476
- try {
2477
- const src = isAbsolute(path) ? pathToFileURL(await resolvePath(path, { fallbackToOriginal: false, extensions: nuxt.options.extensions })).href : await resolve$1(path, { url: nuxt.options.modulesDir.map((m) => pathToFileURL(m.replace(/\/node_modules\/?$/, ""))), extensions: nuxt.options.extensions });
2478
- nuxtModule = await jiti.import(src, { default: true });
2479
- resolvedModulePath = fileURLToPath(new URL(src));
2480
- const moduleMetadataPath = new URL("module.json", src);
2481
- if (existsSync(moduleMetadataPath)) {
2482
- buildTimeModuleMeta = JSON.parse(await promises.readFile(moduleMetadataPath, "utf-8"));
2483
- }
2484
- break;
2485
- } catch (error) {
2486
- const code = error.code;
2487
- if (code === "MODULE_NOT_FOUND" || code === "ERR_PACKAGE_PATH_NOT_EXPORTED" || code === "ERR_MODULE_NOT_FOUND" || code === "ERR_UNSUPPORTED_DIR_IMPORT" || code === "ENOTDIR") {
2488
- continue;
2489
- }
2490
- logger.error(`Error while importing module \`${nuxtModule}\`: ${error}`);
2491
- throw error;
2537
+ nuxtModule = resolveAlias(nuxtModule, nuxt.options.alias);
2538
+ if (isRelative(nuxtModule)) {
2539
+ nuxtModule = resolve(nuxt.options.rootDir, nuxtModule);
2540
+ }
2541
+ try {
2542
+ const src = resolveModuleURL(nuxtModule, {
2543
+ from: nuxt.options.modulesDir.map((m) => directoryToURL(m.replace(/\/node_modules\/?$/, "/"))),
2544
+ suffixes: ["nuxt", "nuxt/index", "module", "module/index", "", "index"],
2545
+ extensions: [".js", ".mjs", ".cjs", ".ts", ".mts", ".cts"]
2546
+ });
2547
+ const resolvedModulePath = fileURLToPath(src);
2548
+ const resolvedNuxtModule = await jiti.import(src, { default: true });
2549
+ if (typeof resolvedNuxtModule !== "function") {
2550
+ throw new TypeError(`Nuxt module should be a function: ${nuxtModule}.`);
2551
+ }
2552
+ const moduleMetadataPath = new URL("module.json", src);
2553
+ if (existsSync(moduleMetadataPath)) {
2554
+ buildTimeModuleMeta = JSON.parse(await promises.readFile(moduleMetadataPath, "utf-8"));
2555
+ }
2556
+ return { nuxtModule: resolvedNuxtModule, buildTimeModuleMeta, resolvedModulePath };
2557
+ } catch (error) {
2558
+ const code = error.code;
2559
+ if (code === "ERR_PACKAGE_PATH_NOT_EXPORTED" || code === "ERR_UNSUPPORTED_DIR_IMPORT" || code === "ENOTDIR") {
2560
+ throw new TypeError(`Could not load \`${nuxtModule}\`. Is it installed?`);
2561
+ }
2562
+ if (code === "MODULE_NOT_FOUND" || code === "ERR_MODULE_NOT_FOUND") {
2563
+ const module = MissingModuleMatcher.exec(error.message)?.[1];
2564
+ if (module && !module.includes(nuxtModule)) {
2565
+ throw new TypeError(`Error while importing module \`${nuxtModule}\`: ${error}`);
2492
2566
  }
2493
2567
  }
2494
2568
  }
2495
- if (typeof nuxtModule === "string") {
2496
- throw new TypeError(`Could not load \`${nuxtModule}\`. Is it installed?`);
2497
- }
2498
- if (typeof nuxtModule !== "function") {
2499
- throw new TypeError("Nuxt module should be a function: " + nuxtModule);
2500
- }
2501
- return { nuxtModule, buildTimeModuleMeta, resolvedModulePath };
2569
+ throw new TypeError(`Could not load \`${nuxtModule}\`. Is it installed?`);
2502
2570
  }
2503
2571
 
2504
2572
  function resolveNuxtModuleEntryName(m) {
@@ -2543,53 +2611,11 @@ async function getNuxtModuleVersion(module, nuxt = useNuxt()) {
2543
2611
  return false;
2544
2612
  }
2545
2613
 
2546
- async function tryResolveModule(id, url = import.meta.url) {
2547
- try {
2548
- return await resolvePath$1(id, { url });
2549
- } catch {
2550
- }
2551
- }
2552
- function resolveModule(id, options) {
2553
- return resolvePathSync(id, { url: options?.paths ?? [import.meta.url] });
2554
- }
2555
- async function importModule(id, opts) {
2556
- const resolvedPath = await resolveModule(id, opts);
2557
- return import(pathToFileURL(resolvedPath).href).then((r) => opts?.interopDefault !== false ? interopDefault(r) : r);
2558
- }
2559
- function tryImportModule(id, opts) {
2560
- try {
2561
- return importModule(id, opts).catch(() => void 0);
2562
- } catch {
2563
- }
2564
- }
2565
- const warnings = /* @__PURE__ */ new Set();
2566
- function requireModule(id, opts) {
2567
- if (!warnings.has(id)) {
2568
- console.warn("[@nuxt/kit] `requireModule` is deprecated. Please use `importModule` instead.");
2569
- warnings.add(id);
2570
- }
2571
- const resolvedPath = resolveModule(id, opts);
2572
- const jiti = createJiti(import.meta.url, {
2573
- interopDefault: opts?.interopDefault !== false
2574
- });
2575
- return jiti(pathToFileURL(resolvedPath).href);
2576
- }
2577
- function tryRequireModule(id, opts) {
2578
- try {
2579
- return requireModule(id, opts);
2580
- } catch {
2581
- }
2582
- }
2583
-
2584
2614
  async function loadNuxtConfig(opts) {
2585
- opts.overrides = defu$1(opts.overrides, {
2586
- _extends: await globby("layers/*", {
2587
- onlyDirectories: true,
2588
- cwd: opts.cwd || process.cwd()
2589
- })
2590
- });
2615
+ const localLayers = await globby("layers/*", { onlyDirectories: true, cwd: opts.cwd || process.cwd() });
2616
+ opts.overrides = defu$1(opts.overrides, { _extends: localLayers });
2591
2617
  globalThis.defineNuxtConfig = (c) => c;
2592
- const result = await loadConfig({
2618
+ const { configFile, layers = [], cwd, config: nuxtConfig, meta } = await loadConfig({
2593
2619
  name: "nuxt",
2594
2620
  configFile: "nuxt.config",
2595
2621
  rcFile: ".nuxtrc",
@@ -2599,11 +2625,14 @@ async function loadNuxtConfig(opts) {
2599
2625
  ...opts
2600
2626
  });
2601
2627
  delete globalThis.defineNuxtConfig;
2602
- const { configFile, layers = [], cwd } = result;
2603
- const nuxtConfig = result.config;
2604
- nuxtConfig.rootDir = nuxtConfig.rootDir || cwd;
2628
+ nuxtConfig.rootDir ||= cwd;
2605
2629
  nuxtConfig._nuxtConfigFile = configFile;
2606
2630
  nuxtConfig._nuxtConfigFiles = [configFile];
2631
+ nuxtConfig.alias ||= {};
2632
+ if (meta?.name) {
2633
+ const alias = `#layers/${meta.name}`;
2634
+ nuxtConfig.alias[alias] ||= nuxtConfig.rootDir;
2635
+ }
2607
2636
  const defaultBuildDir = join(nuxtConfig.rootDir, ".nuxt");
2608
2637
  if (!opts.overrides?._prepare && !nuxtConfig.dev && !nuxtConfig.buildDir && nuxtConfig.future?.compatibilityVersion === 4 && existsSync(defaultBuildDir)) {
2609
2638
  nuxtConfig.buildDir = join(nuxtConfig.rootDir, "node_modules/.cache/nuxt/.nuxt");
@@ -2620,7 +2649,7 @@ async function loadNuxtConfig(opts) {
2620
2649
  const processedLayers = /* @__PURE__ */ new Set();
2621
2650
  for (const layer of layers) {
2622
2651
  layer.config ||= {};
2623
- layer.config.rootDir = layer.config.rootDir ?? layer.cwd;
2652
+ layer.config.rootDir ??= layer.cwd;
2624
2653
  if (processedLayers.has(layer.config.rootDir)) {
2625
2654
  continue;
2626
2655
  }
@@ -2629,6 +2658,14 @@ async function loadNuxtConfig(opts) {
2629
2658
  if (!layer.configFile || layer.configFile.endsWith(".nuxtrc")) {
2630
2659
  continue;
2631
2660
  }
2661
+ if (layer.cwd && cwd && localLayers.includes(relative(cwd, layer.cwd))) {
2662
+ layer.meta ||= {};
2663
+ layer.meta.name ||= basename(layer.cwd);
2664
+ }
2665
+ if (layer.meta?.name) {
2666
+ const alias = `#layers/${layer.meta.name}`;
2667
+ nuxtConfig.alias[alias] ||= layer.config.rootDir || layer.cwd;
2668
+ }
2632
2669
  _layers.push(layer);
2633
2670
  }
2634
2671
  nuxtConfig._layers = _layers;
@@ -2644,13 +2681,14 @@ async function loadNuxtConfig(opts) {
2644
2681
  return await applyDefaults(NuxtConfigSchema, nuxtConfig);
2645
2682
  }
2646
2683
  async function loadNuxtSchema(cwd) {
2647
- const paths = [cwd];
2648
- const nuxtPath = await tryResolveModule("nuxt", cwd) ?? await tryResolveModule("nuxt-nightly", cwd);
2684
+ const url = directoryToURL(cwd);
2685
+ const urls = [url];
2686
+ const nuxtPath = resolveModuleURL("nuxt", { try: true, from: url }) ?? resolveModuleURL("nuxt-nightly", { try: true, from: url });
2649
2687
  if (nuxtPath) {
2650
- paths.unshift(nuxtPath);
2688
+ urls.unshift(pathToFileURL(nuxtPath));
2651
2689
  }
2652
- const schemaPath = await tryResolveModule("@nuxt/schema", paths) ?? "@nuxt/schema";
2653
- return await (isWindows ? import(pathToFileURL(schemaPath).href) : import(schemaPath)).then((r) => r.NuxtConfigSchema);
2690
+ const schemaPath = resolveModuleURL("@nuxt/schema", { try: true, from: urls }) ?? "@nuxt/schema";
2691
+ return await import(schemaPath).then((r) => r.NuxtConfigSchema);
2654
2692
  }
2655
2693
 
2656
2694
  function extendNuxtSchema(def) {
@@ -2661,22 +2699,22 @@ function extendNuxtSchema(def) {
2661
2699
  }
2662
2700
 
2663
2701
  async function loadNuxt(opts) {
2664
- opts.cwd = opts.cwd || opts.rootDir;
2702
+ opts.cwd ||= opts.rootDir;
2665
2703
  opts.overrides ||= opts.config || {};
2666
2704
  opts.overrides.dev = !!opts.dev;
2667
- const nearestNuxtPkg = await Promise.all(["nuxt-nightly", "nuxt3", "nuxt", "nuxt-edge"].map((pkg2) => resolvePackageJSON(pkg2, { url: opts.cwd }).catch(() => null))).then((r) => r.filter(Boolean).sort((a, b) => b.length - a.length)[0]);
2668
- if (!nearestNuxtPkg) {
2705
+ const resolvedPath = ["nuxt-nightly", "nuxt3", "nuxt", "nuxt-edge"].map((pkg2) => resolveModulePath(pkg2, { try: true, from: [directoryToURL(opts.cwd)] })).filter((p) => !!p).sort((a, b) => b.length - a.length)[0];
2706
+ if (!resolvedPath) {
2669
2707
  throw new Error(`Cannot find any nuxt version from ${opts.cwd}`);
2670
2708
  }
2671
- const pkg = await readPackageJSON(nearestNuxtPkg);
2709
+ const pkg = await readPackageJSON(resolvedPath);
2672
2710
  const majorVersion = pkg.version ? Number.parseInt(pkg.version.split(".")[0]) : "";
2673
- const rootDir = pathToFileURL(opts.cwd || process.cwd()).href;
2674
2711
  if (majorVersion && majorVersion >= 3) {
2675
- const { loadNuxt: loadNuxt3 } = await importModule(pkg._name || pkg.name, { paths: rootDir });
2712
+ const { loadNuxt: loadNuxt3 } = await import(pathToFileURL(resolvedPath).href).then((r) => interopDefault(r));
2676
2713
  const nuxt2 = await loadNuxt3(opts);
2677
2714
  return nuxt2;
2678
2715
  }
2679
- const { loadNuxt: loadNuxt2 } = await tryImportModule("nuxt-edge", { paths: rootDir }) || await importModule("nuxt", { paths: rootDir });
2716
+ const rootURL = directoryToURL(opts.cwd);
2717
+ const { loadNuxt: loadNuxt2 } = await tryImportModule("nuxt-edge", { url: rootURL }) || await importModule("nuxt", { url: rootURL });
2680
2718
  const nuxt = await loadNuxt2({
2681
2719
  rootDir: opts.cwd,
2682
2720
  for: opts.dev ? "dev" : "build",
@@ -2698,13 +2736,13 @@ async function loadNuxt(opts) {
2698
2736
  return nuxt;
2699
2737
  }
2700
2738
  async function buildNuxt(nuxt) {
2701
- const rootDir = pathToFileURL(nuxt.options.rootDir).href;
2739
+ const rootURL = directoryToURL(nuxt.options.rootDir);
2702
2740
  if (nuxt.options._majorVersion === 3) {
2703
- const { build: build2 } = await tryImportModule("nuxt-nightly", { paths: rootDir }) || await tryImportModule("nuxt3", { paths: rootDir }) || await importModule("nuxt", { paths: rootDir });
2704
- return build2(nuxt);
2741
+ const { build: build2 } = await tryImportModule("nuxt-nightly", { url: rootURL }) || await tryImportModule("nuxt3", { url: rootURL }) || await importModule("nuxt", { url: rootURL });
2742
+ return runWithNuxtContext(nuxt, () => build2(nuxt));
2705
2743
  }
2706
- const { build } = await tryImportModule("nuxt-edge", { paths: rootDir }) || await importModule("nuxt", { paths: rootDir });
2707
- return build(nuxt);
2744
+ const { build } = await tryImportModule("nuxt-edge", { url: rootURL }) || await importModule("nuxt", { url: rootURL });
2745
+ return runWithNuxtContext(nuxt, () => build(nuxt));
2708
2746
  }
2709
2747
 
2710
2748
  function addImports(imports) {
@@ -2732,7 +2770,7 @@ function addImportsSources(presets) {
2732
2770
 
2733
2771
  const HANDLER_METHOD_RE = /\.(get|head|patch|post|put|delete|connect|options|trace)(\.\w+)*$/;
2734
2772
  function normalizeHandlerMethod(handler) {
2735
- const [, method = undefined] = handler.handler.match(HANDLER_METHOD_RE) || [];
2773
+ const [, method = void 0] = handler.handler.match(HANDLER_METHOD_RE) || [];
2736
2774
  return {
2737
2775
  method,
2738
2776
  ...handler,
@@ -2829,7 +2867,7 @@ function applyEnv(obj, opts, parentKey = "") {
2829
2867
  if (_isObject(envValue)) {
2830
2868
  obj[key] = { ...obj[key], ...envValue };
2831
2869
  applyEnv(obj[key], opts, subKey);
2832
- } else if (envValue === undefined) {
2870
+ } else if (envValue === void 0) {
2833
2871
  applyEnv(obj[key], opts, subKey);
2834
2872
  } else {
2835
2873
  obj[key] = envValue ?? obj[key];
@@ -2990,6 +3028,17 @@ function addTemplate(_template) {
2990
3028
  const nuxt = useNuxt();
2991
3029
  const template = normalizeTemplate(_template);
2992
3030
  filterInPlace(nuxt.options.build.templates, (p) => normalizeTemplate(p).dst !== template.dst);
3031
+ try {
3032
+ const distDir = distDirURL.toString();
3033
+ const { source } = captureStackTrace().find((e) => e.source && !e.source.startsWith(distDir)) ?? {};
3034
+ if (source) {
3035
+ const path = normalize(fileURLToPath(source));
3036
+ if (existsSync(path)) {
3037
+ template._path = path;
3038
+ }
3039
+ }
3040
+ } catch {
3041
+ }
2993
3042
  nuxt.options.build.templates.push(template);
2994
3043
  return template;
2995
3044
  }
@@ -2999,15 +3048,22 @@ function addServerTemplate(template) {
2999
3048
  nuxt.options.nitro.virtual[template.filename] = template.getContents;
3000
3049
  return template;
3001
3050
  }
3002
- function addTypeTemplate(_template) {
3051
+ function addTypeTemplate(_template, context) {
3003
3052
  const nuxt = useNuxt();
3004
3053
  const template = addTemplate(_template);
3005
3054
  if (!template.filename.endsWith(".d.ts")) {
3006
3055
  throw new Error(`Invalid type template. Filename must end with .d.ts : "${template.filename}"`);
3007
3056
  }
3008
- nuxt.hook("prepare:types", ({ references }) => {
3009
- references.push({ path: template.dst });
3010
- });
3057
+ if (!context || context.nuxt) {
3058
+ nuxt.hook("prepare:types", ({ references }) => {
3059
+ references.push({ path: template.dst });
3060
+ });
3061
+ }
3062
+ if (context?.nitro) {
3063
+ nuxt.hook("nitro:prepare:types", ({ references }) => {
3064
+ references.push({ path: template.dst });
3065
+ });
3066
+ }
3011
3067
  return template;
3012
3068
  }
3013
3069
  function normalizeTemplate(template, buildDir) {
@@ -3037,15 +3093,13 @@ function normalizeTemplate(template, buildDir) {
3037
3093
  if (template.filename.endsWith(".d.ts")) {
3038
3094
  template.write = true;
3039
3095
  }
3040
- if (!template.dst) {
3041
- template.dst = resolve(buildDir ?? useNuxt().options.buildDir, template.filename);
3042
- }
3096
+ template.dst ||= resolve(buildDir ?? useNuxt().options.buildDir, template.filename);
3043
3097
  return template;
3044
3098
  }
3045
3099
  async function updateTemplates(options) {
3046
3100
  return await tryUseNuxt()?.hooks.callHook("builder:generateApp", options);
3047
3101
  }
3048
- const EXTENSION_RE = /\b\.\w+$/g;
3102
+ const EXTENSION_RE = /\b(?:\.d\.[cm]?ts|\.\w+)$/g;
3049
3103
  const excludedAlias = [/^@vue\/.*$/, /^#internal\/nuxt/];
3050
3104
  async function _generateTypes(nuxt) {
3051
3105
  const rootDirWithSlash = withTrailingSlash(nuxt.options.rootDir);
@@ -3089,7 +3143,19 @@ async function _generateTypes(nuxt) {
3089
3143
  exclude.add(join(relative2, "dist/runtime/server"));
3090
3144
  }
3091
3145
  const isV4 = nuxt.options.future?.compatibilityVersion === 4;
3092
- const hasTypescriptVersionWithModulePreserve = await readPackageJSON("typescript", { url: nuxt.options.modulesDir }).then((r) => r?.version && gte(r.version, "5.4.0")).catch(() => isV4);
3146
+ const nestedModulesDirs = [];
3147
+ for (const dir of [...nuxt.options.modulesDir].sort()) {
3148
+ const withSlash = withTrailingSlash(dir);
3149
+ if (nestedModulesDirs.every((d) => !d.startsWith(withSlash))) {
3150
+ nestedModulesDirs.push(withSlash);
3151
+ }
3152
+ }
3153
+ let hasTypescriptVersionWithModulePreserve;
3154
+ for (const parent of nestedModulesDirs) {
3155
+ hasTypescriptVersionWithModulePreserve ??= await readPackageJSON("typescript", { parent }).then((r) => r?.version && gte(r.version, "5.4.0")).catch(() => void 0);
3156
+ }
3157
+ hasTypescriptVersionWithModulePreserve ??= isV4;
3158
+ const useDecorators = Boolean(nuxt.options.experimental?.decorators);
3093
3159
  const tsConfig = defu(nuxt.options.typescript?.tsConfig, {
3094
3160
  compilerOptions: {
3095
3161
  /* Base options: */
@@ -3106,12 +3172,17 @@ async function _generateTypes(nuxt) {
3106
3172
  noUncheckedIndexedAccess: isV4,
3107
3173
  forceConsistentCasingInFileNames: true,
3108
3174
  noImplicitOverride: true,
3175
+ /* Decorator support */
3176
+ ...useDecorators ? {
3177
+ experimentalDecorators: false
3178
+ } : {},
3109
3179
  /* If NOT transpiling with TypeScript: */
3110
3180
  module: hasTypescriptVersionWithModulePreserve ? "preserve" : "ESNext",
3111
3181
  noEmit: true,
3112
3182
  /* If your code runs in the DOM: */
3113
3183
  lib: [
3114
3184
  "ESNext",
3185
+ ...useDecorators ? ["esnext.decorators"] : [],
3115
3186
  "dom",
3116
3187
  "dom.iterable",
3117
3188
  "webworker"
@@ -3140,6 +3211,7 @@ async function _generateTypes(nuxt) {
3140
3211
  tsConfig.compilerOptions ||= {};
3141
3212
  tsConfig.compilerOptions.paths ||= {};
3142
3213
  tsConfig.include ||= [];
3214
+ const importPaths = nuxt.options.modulesDir.map((d) => directoryToURL(d));
3143
3215
  for (const alias in aliases) {
3144
3216
  if (excludedAlias.some((re) => re.test(alias))) {
3145
3217
  continue;
@@ -3150,7 +3222,11 @@ async function _generateTypes(nuxt) {
3150
3222
  /* file does not exist */
3151
3223
  );
3152
3224
  if (!stats) {
3153
- const resolvedModule = await tryResolveModule(aliases[alias], nuxt.options.modulesDir);
3225
+ const resolvedModule = resolveModulePath(aliases[alias], {
3226
+ try: true,
3227
+ from: importPaths,
3228
+ extensions: [...nuxt.options.extensions, ".d.ts", ".d.mts", ".d.cts"]
3229
+ });
3154
3230
  if (resolvedModule) {
3155
3231
  absolutePath = resolvedModule;
3156
3232
  stats = await promises.stat(resolvedModule).catch(() => null);
@@ -3176,8 +3252,14 @@ async function _generateTypes(nuxt) {
3176
3252
  if (typeof id !== "string") {
3177
3253
  return;
3178
3254
  }
3179
- const pkg = await readPackageJSON(id, { url: nuxt.options.modulesDir }).catch(() => null);
3180
- references.push({ types: pkg?.name || id });
3255
+ for (const parent of nestedModulesDirs) {
3256
+ const pkg = await readPackageJSON(id, { parent }).catch(() => null);
3257
+ if (pkg) {
3258
+ references.push({ types: pkg.name ?? id });
3259
+ return;
3260
+ }
3261
+ }
3262
+ references.push({ types: id });
3181
3263
  }));
3182
3264
  const declarations = [];
3183
3265
  await nuxt.callHook("prepare:types", { references, declarations, tsConfig });
@@ -3339,7 +3421,9 @@ function normalizePlugin(plugin) {
3339
3421
  plugin.src = normalize(resolveAlias(plugin.src));
3340
3422
  if (!existsSync(plugin.src) && isAbsolute$1(plugin.src)) {
3341
3423
  try {
3342
- plugin.src = resolvePathSync(isWindows ? pathToFileURL(plugin.src).href : plugin.src, { extensions: tryUseNuxt()?.options.extensions });
3424
+ plugin.src = resolveModulePath(plugin.src, {
3425
+ extensions: tryUseNuxt()?.options.extensions ?? [".js", ".mjs", ".cjs", ".ts", ".tsx", ".mts", ".cts"]
3426
+ });
3343
3427
  } catch {
3344
3428
  }
3345
3429
  }
@@ -3365,4 +3449,4 @@ function addPluginTemplate(plugin, opts = {}) {
3365
3449
  return addPlugin(normalizedPlugin, opts);
3366
3450
  }
3367
3451
 
3368
- export { addBuildPlugin, addComponent, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, addLayout, addPlugin, addPluginTemplate, addPrerenderRoutes, addRouteMiddleware, addRspackPlugin, addServerHandler, addServerImports, addServerImportsDir, addServerPlugin, addServerScanDir, addServerTemplate, addTemplate, addTypeTemplate, addVitePlugin, addWebpackPlugin, assertNuxtCompatibility, buildNuxt, checkNuxtCompatibility, compileTemplate, createIsIgnored, createResolver, defineNuxtModule, extendNuxtSchema, extendPages, extendRouteRules, extendRspackConfig, extendViteConfig, extendWebpackConfig, findPath, getDirectory, getNuxtModuleVersion, getNuxtVersion, hasNuxtCompatibility, hasNuxtModule, hasNuxtModuleCompatibility, importModule, installModule, isIgnored, isNuxt2, isNuxt3, isNuxtMajorVersion, loadNuxt, loadNuxtConfig, loadNuxtModuleInstance, logger, normalizeModuleTranspilePath, normalizePlugin, normalizeSemanticVersion, normalizeTemplate, nuxtCtx, requireModule, resolveAlias, resolveFiles, resolveIgnorePatterns, resolveModule, resolveNuxtModule, resolvePath, templateUtils, tryImportModule, tryRequireModule, tryResolveModule, tryUseNuxt, updateRuntimeConfig, updateTemplates, useLogger, useNitro, useNuxt, useRuntimeConfig, writeTypes };
3452
+ export { addBuildPlugin, addComponent, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, addLayout, addPlugin, addPluginTemplate, addPrerenderRoutes, addRouteMiddleware, addRspackPlugin, addServerHandler, addServerImports, addServerImportsDir, addServerPlugin, addServerScanDir, addServerTemplate, addTemplate, addTypeTemplate, addVitePlugin, addWebpackPlugin, assertNuxtCompatibility, buildNuxt, checkNuxtCompatibility, compileTemplate, createIsIgnored, createResolver, defineNuxtModule, directoryToURL, extendNuxtSchema, extendPages, extendRouteRules, extendRspackConfig, extendViteConfig, extendWebpackConfig, findPath, getDirectory, getNuxtCtx, getNuxtModuleVersion, getNuxtVersion, hasNuxtCompatibility, hasNuxtModule, hasNuxtModuleCompatibility, importModule, installModule, isIgnored, isNuxt2, isNuxt3, isNuxtMajorVersion, loadNuxt, loadNuxtConfig, loadNuxtModuleInstance, logger, normalizeModuleTranspilePath, normalizePlugin, normalizeSemanticVersion, normalizeTemplate, nuxtCtx, requireModule, resolveAlias, resolveFiles, resolveIgnorePatterns, resolveModule, resolveNuxtModule, resolvePath, runWithNuxtContext, templateUtils, tryImportModule, tryRequireModule, tryResolveModule, tryUseNuxt, updateRuntimeConfig, updateTemplates, useLogger, useNitro, useNuxt, useRuntimeConfig, writeTypes };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/kit",
3
- "version": "3.15.4",
3
+ "version": "3.16.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/nuxt.git",
@@ -23,38 +23,40 @@
23
23
  "dist"
24
24
  ],
25
25
  "dependencies": {
26
- "c12": "^2.0.1",
27
- "consola": "^3.4.0",
26
+ "c12": "^3.0.2",
27
+ "consola": "^3.4.2",
28
28
  "defu": "^6.1.4",
29
29
  "destr": "^2.0.3",
30
- "globby": "^14.0.2",
30
+ "errx": "^0.1.0",
31
+ "exsolve": "^1.0.4",
32
+ "globby": "^14.1.0",
31
33
  "ignore": "^7.0.3",
32
34
  "jiti": "^2.4.2",
33
35
  "klona": "^2.0.6",
34
36
  "knitwork": "^1.2.0",
35
37
  "mlly": "^1.7.4",
36
- "ohash": "^1.1.4",
37
- "pathe": "^2.0.2",
38
- "pkg-types": "^1.3.1",
38
+ "ohash": "^2.0.11",
39
+ "pathe": "^2.0.3",
40
+ "pkg-types": "^2.1.0",
39
41
  "scule": "^1.3.0",
40
- "semver": "^7.6.3",
41
- "std-env": "^3.8.0",
42
+ "semver": "^7.7.1",
43
+ "std-env": "^3.8.1",
42
44
  "ufo": "^1.5.4",
43
45
  "unctx": "^2.4.1",
44
- "unimport": "^4.0.0",
45
- "untyped": "^1.5.2"
46
+ "unimport": "^4.1.2",
47
+ "untyped": "^2.0.0"
46
48
  },
47
49
  "devDependencies": {
48
- "@rspack/core": "1.2.2",
50
+ "@rspack/core": "1.2.8",
49
51
  "@types/lodash-es": "4.17.12",
50
52
  "@types/semver": "7.5.8",
51
53
  "lodash-es": "4.17.21",
52
- "nitropack": "2.10.4",
54
+ "nitropack": "2.11.7",
53
55
  "unbuild": "latest",
54
- "vite": "6.0.11",
55
- "vitest": "3.0.4",
56
- "webpack": "5.96.1",
57
- "@nuxt/schema": "3.15.4"
56
+ "vite": "6.2.2",
57
+ "vitest": "3.0.9",
58
+ "webpack": "5.98.0",
59
+ "@nuxt/schema": "3.16.1"
58
60
  },
59
61
  "engines": {
60
62
  "node": ">=18.12.0"