@nuxt/kit 3.15.3 → 3.16.0

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
@@ -32,7 +32,6 @@ It provides a number of features that make it easy to build fast, SEO-friendly,
32
32
  - 🧩 [Modules](#modules)
33
33
  - ❤️ [Contribute](#contribute)
34
34
  - 🏠 [Local Development](#local-development)
35
- - ⛰️ [Nuxt 2](#nuxt-2)
36
35
  - 🛟 [Professional Support](#professional-support)
37
36
  - 🔗 [Follow Us](#follow-us)
38
37
  - ⚖️ [License](#license)
@@ -44,7 +43,7 @@ It provides a number of features that make it easy to build fast, SEO-friendly,
44
43
  Use the following command to create a new starter project. This will create a starter project with all the necessary files and dependencies:
45
44
 
46
45
  ```bash
47
- npx nuxi@latest init <my-project>
46
+ npm create nuxt <my-project>
48
47
  ```
49
48
 
50
49
  > [!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,27 +4,28 @@ 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 { NuxtConfigSchema } from '@nuxt/schema';
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
- import { isWindows } from 'std-env';
28
29
 
29
30
  const logger = consola;
30
31
  function useLogger(tag, options = {}) {
@@ -32,15 +33,23 @@ function useLogger(tag, options = {}) {
32
33
  }
33
34
 
34
35
  const nuxtCtx = getContext("nuxt");
36
+ const asyncNuxtStorage = createContext({
37
+ asyncContext: true,
38
+ AsyncLocalStorage
39
+ });
40
+ const getNuxtCtx = () => asyncNuxtStorage.tryUse();
35
41
  function useNuxt() {
36
- const instance = nuxtCtx.tryUse();
42
+ const instance = asyncNuxtStorage.tryUse() || nuxtCtx.tryUse();
37
43
  if (!instance) {
38
44
  throw new Error("Nuxt instance is unavailable!");
39
45
  }
40
46
  return instance;
41
47
  }
42
48
  function tryUseNuxt() {
43
- return nuxtCtx.tryUse();
49
+ return asyncNuxtStorage.tryUse() || nuxtCtx.tryUse();
50
+ }
51
+ function runWithNuxtContext(nuxt, fn) {
52
+ return asyncNuxtStorage.call(nuxt, fn);
44
53
  }
45
54
 
46
55
  const SEMANTIC_VERSION_RE = /-\d+\.[0-9a-f]+/;
@@ -92,12 +101,17 @@ async function checkNuxtCompatibility(constraints, nuxt = useNuxt()) {
92
101
  message: `Not compatible with \`${nuxt.options.builder}\`.`
93
102
  });
94
103
  } else {
95
- const builderVersion = await readPackageJSON(nuxt.options.builder, { url: nuxt.options.modulesDir }).then((r) => r.version).catch(() => undefined);
96
- if (builderVersion && !satisfies(normalizeSemanticVersion(builderVersion), constraint, { includePrerelease: true })) {
97
- issues.push({
98
- name: "builder",
99
- message: `Not compatible with \`${builderVersion}\` of \`${currentBuilder}\`. This module requires \`${constraint}\`.`
100
- });
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
+ }
101
115
  }
102
116
  }
103
117
  }
@@ -2067,6 +2081,7 @@ function filterInPlace(array, predicate) {
2067
2081
  return array;
2068
2082
  }
2069
2083
  const MODE_RE = /\.(server|client)(\.\w+)*$/;
2084
+ const distDirURL = new URL(".", import.meta.url);
2070
2085
 
2071
2086
  async function compileTemplate(template$1, ctx) {
2072
2087
  const data = { ...ctx, options: template$1.options };
@@ -2122,9 +2137,7 @@ function _defineNuxtModule(definition) {
2122
2137
  return Promise.resolve(options);
2123
2138
  }
2124
2139
  async function normalizedModule(inlineOptions, nuxt) {
2125
- if (!nuxt) {
2126
- nuxt = tryUseNuxt() || this.nuxt;
2127
- }
2140
+ nuxt ||= tryUseNuxt() || this.nuxt;
2128
2141
  const uniqueKey = module.meta.name || module.meta.configKey;
2129
2142
  if (uniqueKey) {
2130
2143
  nuxt.options._requiredModules ||= {};
@@ -2152,7 +2165,7 @@ ${issues.toString()}`);
2152
2165
  const setupTime = Math.round(perf * 100) / 100;
2153
2166
  if (setupTime > 5e3 && uniqueKey !== "@nuxt/telemetry") {
2154
2167
  logger.warn(`Slow module \`${uniqueKey || "<no name>"}\` took \`${setupTime}ms\` to setup.`);
2155
- } else if (nuxt.options.debug) {
2168
+ } else if (nuxt.options.debug && nuxt.options.debug.modules) {
2156
2169
  logger.info(`Module \`${uniqueKey || "<no name>"}\` took \`${setupTime}ms\` to setup.`);
2157
2170
  }
2158
2171
  if (res === false) {
@@ -2209,6 +2222,51 @@ function nuxt2Shims(nuxt) {
2209
2222
  });
2210
2223
  }
2211
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
+
2212
2270
  function createIsIgnored(nuxt = tryUseNuxt()) {
2213
2271
  return (pathname, stats) => isIgnored(pathname, stats, nuxt);
2214
2272
  }
@@ -2286,9 +2344,7 @@ async function findPath(paths, opts, pathType = "file") {
2286
2344
  return null;
2287
2345
  }
2288
2346
  function resolveAlias(path, alias) {
2289
- if (!alias) {
2290
- alias = tryUseNuxt()?.options.alias || {};
2291
- }
2347
+ alias ||= tryUseNuxt()?.options.alias || {};
2292
2348
  return resolveAlias$1(path, alias);
2293
2349
  }
2294
2350
  function createResolver(base) {
@@ -2355,7 +2411,7 @@ async function _resolvePathGranularly(path, opts = {}) {
2355
2411
  const cwd = opts.cwd || (nuxt ? nuxt.options.rootDir : process.cwd());
2356
2412
  const extensions = opts.extensions || (nuxt ? nuxt.options.extensions : [".ts", ".mjs", ".cjs", ".json"]);
2357
2413
  const modulesDir = nuxt ? nuxt.options.modulesDir : [];
2358
- path = resolveAlias(path);
2414
+ path = resolveAlias$1(path, opts.alias ?? nuxt?.options.alias ?? {});
2359
2415
  if (!isAbsolute(path)) {
2360
2416
  path = resolve(cwd, path);
2361
2417
  }
@@ -2378,7 +2434,11 @@ async function _resolvePathGranularly(path, opts = {}) {
2378
2434
  return indexPath;
2379
2435
  }
2380
2436
  }
2381
- 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
+ });
2382
2442
  if (resolvedModulePath) {
2383
2443
  return {
2384
2444
  path: resolvedModulePath,
@@ -2425,7 +2485,7 @@ async function installModule(moduleToInstall, inlineOptions, nuxt = useNuxt()) {
2425
2485
  localLayerModuleDirs.push(resolve(srcDir, l.config?.dir?.modules || "modules").replace(/\/?$/, "/"));
2426
2486
  }
2427
2487
  }
2428
- 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)) ?? {};
2429
2489
  if (res === false) {
2430
2490
  return;
2431
2491
  }
@@ -2440,12 +2500,13 @@ async function installModule(moduleToInstall, inlineOptions, nuxt = useNuxt()) {
2440
2500
  }
2441
2501
  }
2442
2502
  nuxt.options._installedModules ||= [];
2443
- const entryPath = typeof moduleToInstall === "string" ? resolveAlias(moduleToInstall) : undefined;
2503
+ const entryPath = typeof moduleToInstall === "string" ? resolveAlias(moduleToInstall) : void 0;
2444
2504
  if (typeof moduleToInstall === "string" && entryPath !== moduleToInstall) {
2445
2505
  buildTimeModuleMeta.rawPath = moduleToInstall;
2446
2506
  }
2447
2507
  nuxt.options._installedModules.push({
2448
2508
  meta: defu(await nuxtModule.getMeta?.(), buildTimeModuleMeta),
2509
+ module: nuxtModule,
2449
2510
  timings: res.timings,
2450
2511
  entryPath
2451
2512
  });
@@ -2460,46 +2521,52 @@ function getDirectory(p) {
2460
2521
  const normalizeModuleTranspilePath = (p) => {
2461
2522
  return getDirectory(p).split("node_modules/").pop();
2462
2523
  };
2524
+ const MissingModuleMatcher = /Cannot find module\s+['"]?([^'")\s]+)['"]?/i;
2463
2525
  async function loadNuxtModuleInstance(nuxtModule, nuxt = useNuxt()) {
2464
2526
  let buildTimeModuleMeta = {};
2465
- 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
+ }
2466
2536
  const jiti = createJiti(nuxt.options.rootDir, { alias: nuxt.options.alias });
2467
- if (typeof nuxtModule === "string") {
2468
- const paths = /* @__PURE__ */ new Set();
2469
- nuxtModule = resolveAlias(nuxtModule, nuxt.options.alias);
2470
- if (isRelative(nuxtModule)) {
2471
- nuxtModule = resolve(nuxt.options.rootDir, nuxtModule);
2472
- }
2473
- paths.add(join(nuxtModule, "nuxt"));
2474
- paths.add(join(nuxtModule, "module"));
2475
- paths.add(nuxtModule);
2476
- for (const path of paths) {
2477
- try {
2478
- 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 });
2479
- nuxtModule = await jiti.import(src, { default: true });
2480
- resolvedModulePath = fileURLToPath(new URL(src));
2481
- const moduleMetadataPath = new URL("module.json", src);
2482
- if (existsSync(moduleMetadataPath)) {
2483
- buildTimeModuleMeta = JSON.parse(await promises.readFile(moduleMetadataPath, "utf-8"));
2484
- }
2485
- break;
2486
- } catch (error) {
2487
- const code = error.code;
2488
- if (code === "MODULE_NOT_FOUND" || code === "ERR_PACKAGE_PATH_NOT_EXPORTED" || code === "ERR_MODULE_NOT_FOUND" || code === "ERR_UNSUPPORTED_DIR_IMPORT" || code === "ENOTDIR") {
2489
- continue;
2490
- }
2491
- logger.error(`Error while importing module \`${nuxtModule}\`: ${error}`);
2492
- 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}`);
2493
2566
  }
2494
2567
  }
2495
2568
  }
2496
- if (typeof nuxtModule === "string") {
2497
- throw new TypeError(`Could not load \`${nuxtModule}\`. Is it installed?`);
2498
- }
2499
- if (typeof nuxtModule !== "function") {
2500
- throw new TypeError("Nuxt module should be a function: " + nuxtModule);
2501
- }
2502
- return { nuxtModule, buildTimeModuleMeta, resolvedModulePath };
2569
+ throw new TypeError(`Could not load \`${nuxtModule}\`. Is it installed?`);
2503
2570
  }
2504
2571
 
2505
2572
  function resolveNuxtModuleEntryName(m) {
@@ -2544,22 +2611,11 @@ async function getNuxtModuleVersion(module, nuxt = useNuxt()) {
2544
2611
  return false;
2545
2612
  }
2546
2613
 
2547
- const layerSchemaKeys = ["future", "srcDir", "rootDir", "serverDir", "dir"];
2548
- const layerSchema = /* @__PURE__ */ Object.create(null);
2549
- for (const key of layerSchemaKeys) {
2550
- if (key in NuxtConfigSchema) {
2551
- layerSchema[key] = NuxtConfigSchema[key];
2552
- }
2553
- }
2554
2614
  async function loadNuxtConfig(opts) {
2555
- opts.overrides = defu$1(opts.overrides, {
2556
- _extends: await globby("layers/*", {
2557
- onlyDirectories: true,
2558
- cwd: opts.cwd || process.cwd()
2559
- })
2560
- });
2615
+ const localLayers = await globby("layers/*", { onlyDirectories: true, cwd: opts.cwd || process.cwd() });
2616
+ opts.overrides = defu$1(opts.overrides, { _extends: localLayers });
2561
2617
  globalThis.defineNuxtConfig = (c) => c;
2562
- const result = await loadConfig({
2618
+ const { configFile, layers = [], cwd, config: nuxtConfig, meta } = await loadConfig({
2563
2619
  name: "nuxt",
2564
2620
  configFile: "nuxt.config",
2565
2621
  rcFile: ".nuxtrc",
@@ -2569,20 +2625,31 @@ async function loadNuxtConfig(opts) {
2569
2625
  ...opts
2570
2626
  });
2571
2627
  delete globalThis.defineNuxtConfig;
2572
- const { configFile, layers = [], cwd } = result;
2573
- const nuxtConfig = result.config;
2574
- nuxtConfig.rootDir = nuxtConfig.rootDir || cwd;
2628
+ nuxtConfig.rootDir ||= cwd;
2575
2629
  nuxtConfig._nuxtConfigFile = configFile;
2576
2630
  nuxtConfig._nuxtConfigFiles = [configFile];
2631
+ nuxtConfig.alias ||= {};
2632
+ if (meta?.name) {
2633
+ const alias = `#layers/${meta.name}`;
2634
+ nuxtConfig.alias[alias] ||= nuxtConfig.rootDir;
2635
+ }
2577
2636
  const defaultBuildDir = join(nuxtConfig.rootDir, ".nuxt");
2578
2637
  if (!opts.overrides?._prepare && !nuxtConfig.dev && !nuxtConfig.buildDir && nuxtConfig.future?.compatibilityVersion === 4 && existsSync(defaultBuildDir)) {
2579
2638
  nuxtConfig.buildDir = join(nuxtConfig.rootDir, "node_modules/.cache/nuxt/.nuxt");
2580
2639
  }
2640
+ const NuxtConfigSchema = await loadNuxtSchema(nuxtConfig.rootDir || cwd || process.cwd());
2641
+ const layerSchemaKeys = ["future", "srcDir", "rootDir", "serverDir", "dir"];
2642
+ const layerSchema = /* @__PURE__ */ Object.create(null);
2643
+ for (const key of layerSchemaKeys) {
2644
+ if (key in NuxtConfigSchema) {
2645
+ layerSchema[key] = NuxtConfigSchema[key];
2646
+ }
2647
+ }
2581
2648
  const _layers = [];
2582
2649
  const processedLayers = /* @__PURE__ */ new Set();
2583
2650
  for (const layer of layers) {
2584
2651
  layer.config ||= {};
2585
- layer.config.rootDir = layer.config.rootDir ?? layer.cwd;
2652
+ layer.config.rootDir ??= layer.cwd;
2586
2653
  if (processedLayers.has(layer.config.rootDir)) {
2587
2654
  continue;
2588
2655
  }
@@ -2591,6 +2658,14 @@ async function loadNuxtConfig(opts) {
2591
2658
  if (!layer.configFile || layer.configFile.endsWith(".nuxtrc")) {
2592
2659
  continue;
2593
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
+ }
2594
2669
  _layers.push(layer);
2595
2670
  }
2596
2671
  nuxtConfig._layers = _layers;
@@ -2605,6 +2680,16 @@ async function loadNuxtConfig(opts) {
2605
2680
  }
2606
2681
  return await applyDefaults(NuxtConfigSchema, nuxtConfig);
2607
2682
  }
2683
+ async function loadNuxtSchema(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 });
2687
+ if (nuxtPath) {
2688
+ urls.unshift(pathToFileURL(nuxtPath));
2689
+ }
2690
+ const schemaPath = resolveModuleURL("@nuxt/schema", { try: true, from: urls }) ?? "@nuxt/schema";
2691
+ return await import(schemaPath).then((r) => r.NuxtConfigSchema);
2692
+ }
2608
2693
 
2609
2694
  function extendNuxtSchema(def) {
2610
2695
  const nuxt = useNuxt();
@@ -2613,61 +2698,23 @@ function extendNuxtSchema(def) {
2613
2698
  });
2614
2699
  }
2615
2700
 
2616
- async function tryResolveModule(id, url = import.meta.url) {
2617
- try {
2618
- return await resolvePath$1(id, { url });
2619
- } catch {
2620
- }
2621
- }
2622
- function resolveModule(id, options) {
2623
- return resolvePathSync(id, { url: options?.paths ?? [import.meta.url] });
2624
- }
2625
- async function importModule(id, opts) {
2626
- const resolvedPath = await resolveModule(id, opts);
2627
- return import(pathToFileURL(resolvedPath).href).then((r) => opts?.interopDefault !== false ? interopDefault(r) : r);
2628
- }
2629
- function tryImportModule(id, opts) {
2630
- try {
2631
- return importModule(id, opts).catch(() => void 0);
2632
- } catch {
2633
- }
2634
- }
2635
- const warnings = /* @__PURE__ */ new Set();
2636
- function requireModule(id, opts) {
2637
- if (!warnings.has(id)) {
2638
- console.warn("[@nuxt/kit] `requireModule` is deprecated. Please use `importModule` instead.");
2639
- warnings.add(id);
2640
- }
2641
- const resolvedPath = resolveModule(id, opts);
2642
- const jiti = createJiti(import.meta.url, {
2643
- interopDefault: opts?.interopDefault !== false
2644
- });
2645
- return jiti(pathToFileURL(resolvedPath).href);
2646
- }
2647
- function tryRequireModule(id, opts) {
2648
- try {
2649
- return requireModule(id, opts);
2650
- } catch {
2651
- }
2652
- }
2653
-
2654
2701
  async function loadNuxt(opts) {
2655
- opts.cwd = opts.cwd || opts.rootDir;
2702
+ opts.cwd ||= opts.rootDir;
2656
2703
  opts.overrides ||= opts.config || {};
2657
2704
  opts.overrides.dev = !!opts.dev;
2658
- 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]);
2659
- 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) {
2660
2707
  throw new Error(`Cannot find any nuxt version from ${opts.cwd}`);
2661
2708
  }
2662
- const pkg = await readPackageJSON(nearestNuxtPkg);
2709
+ const pkg = await readPackageJSON(resolvedPath);
2663
2710
  const majorVersion = pkg.version ? Number.parseInt(pkg.version.split(".")[0]) : "";
2664
- const rootDir = pathToFileURL(opts.cwd || process.cwd()).href;
2665
2711
  if (majorVersion && majorVersion >= 3) {
2666
- const { loadNuxt: loadNuxt3 } = await importModule(pkg._name || pkg.name, { paths: rootDir });
2712
+ const { loadNuxt: loadNuxt3 } = await import(pathToFileURL(resolvedPath).href).then((r) => interopDefault(r));
2667
2713
  const nuxt2 = await loadNuxt3(opts);
2668
2714
  return nuxt2;
2669
2715
  }
2670
- 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 });
2671
2718
  const nuxt = await loadNuxt2({
2672
2719
  rootDir: opts.cwd,
2673
2720
  for: opts.dev ? "dev" : "build",
@@ -2689,13 +2736,13 @@ async function loadNuxt(opts) {
2689
2736
  return nuxt;
2690
2737
  }
2691
2738
  async function buildNuxt(nuxt) {
2692
- const rootDir = pathToFileURL(nuxt.options.rootDir).href;
2739
+ const rootURL = directoryToURL(nuxt.options.rootDir);
2693
2740
  if (nuxt.options._majorVersion === 3) {
2694
- const { build: build2 } = await tryImportModule("nuxt-nightly", { paths: rootDir }) || await tryImportModule("nuxt3", { paths: rootDir }) || await importModule("nuxt", { paths: rootDir });
2695
- 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));
2696
2743
  }
2697
- const { build } = await tryImportModule("nuxt-edge", { paths: rootDir }) || await importModule("nuxt", { paths: rootDir });
2698
- return build(nuxt);
2744
+ const { build } = await tryImportModule("nuxt-edge", { url: rootURL }) || await importModule("nuxt", { url: rootURL });
2745
+ return runWithNuxtContext(nuxt, () => build(nuxt));
2699
2746
  }
2700
2747
 
2701
2748
  function addImports(imports) {
@@ -2723,7 +2770,7 @@ function addImportsSources(presets) {
2723
2770
 
2724
2771
  const HANDLER_METHOD_RE = /\.(get|head|patch|post|put|delete|connect|options|trace)(\.\w+)*$/;
2725
2772
  function normalizeHandlerMethod(handler) {
2726
- const [, method = undefined] = handler.handler.match(HANDLER_METHOD_RE) || [];
2773
+ const [, method = void 0] = handler.handler.match(HANDLER_METHOD_RE) || [];
2727
2774
  return {
2728
2775
  method,
2729
2776
  ...handler,
@@ -2820,7 +2867,7 @@ function applyEnv(obj, opts, parentKey = "") {
2820
2867
  if (_isObject(envValue)) {
2821
2868
  obj[key] = { ...obj[key], ...envValue };
2822
2869
  applyEnv(obj[key], opts, subKey);
2823
- } else if (envValue === undefined) {
2870
+ } else if (envValue === void 0) {
2824
2871
  applyEnv(obj[key], opts, subKey);
2825
2872
  } else {
2826
2873
  obj[key] = envValue ?? obj[key];
@@ -2981,6 +3028,17 @@ function addTemplate(_template) {
2981
3028
  const nuxt = useNuxt();
2982
3029
  const template = normalizeTemplate(_template);
2983
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
+ }
2984
3042
  nuxt.options.build.templates.push(template);
2985
3043
  return template;
2986
3044
  }
@@ -2990,15 +3048,22 @@ function addServerTemplate(template) {
2990
3048
  nuxt.options.nitro.virtual[template.filename] = template.getContents;
2991
3049
  return template;
2992
3050
  }
2993
- function addTypeTemplate(_template) {
3051
+ function addTypeTemplate(_template, context) {
2994
3052
  const nuxt = useNuxt();
2995
3053
  const template = addTemplate(_template);
2996
3054
  if (!template.filename.endsWith(".d.ts")) {
2997
3055
  throw new Error(`Invalid type template. Filename must end with .d.ts : "${template.filename}"`);
2998
3056
  }
2999
- nuxt.hook("prepare:types", ({ references }) => {
3000
- references.push({ path: template.dst });
3001
- });
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
+ }
3002
3067
  return template;
3003
3068
  }
3004
3069
  function normalizeTemplate(template, buildDir) {
@@ -3028,15 +3093,13 @@ function normalizeTemplate(template, buildDir) {
3028
3093
  if (template.filename.endsWith(".d.ts")) {
3029
3094
  template.write = true;
3030
3095
  }
3031
- if (!template.dst) {
3032
- template.dst = resolve(buildDir ?? useNuxt().options.buildDir, template.filename);
3033
- }
3096
+ template.dst ||= resolve(buildDir ?? useNuxt().options.buildDir, template.filename);
3034
3097
  return template;
3035
3098
  }
3036
3099
  async function updateTemplates(options) {
3037
3100
  return await tryUseNuxt()?.hooks.callHook("builder:generateApp", options);
3038
3101
  }
3039
- const EXTENSION_RE = /\b\.\w+$/g;
3102
+ const EXTENSION_RE = /\b(?:\.d\.[cm]?ts|\.\w+)$/g;
3040
3103
  const excludedAlias = [/^@vue\/.*$/, /^#internal\/nuxt/];
3041
3104
  async function _generateTypes(nuxt) {
3042
3105
  const rootDirWithSlash = withTrailingSlash(nuxt.options.rootDir);
@@ -3080,7 +3143,19 @@ async function _generateTypes(nuxt) {
3080
3143
  exclude.add(join(relative2, "dist/runtime/server"));
3081
3144
  }
3082
3145
  const isV4 = nuxt.options.future?.compatibilityVersion === 4;
3083
- 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);
3084
3159
  const tsConfig = defu(nuxt.options.typescript?.tsConfig, {
3085
3160
  compilerOptions: {
3086
3161
  /* Base options: */
@@ -3097,12 +3172,17 @@ async function _generateTypes(nuxt) {
3097
3172
  noUncheckedIndexedAccess: isV4,
3098
3173
  forceConsistentCasingInFileNames: true,
3099
3174
  noImplicitOverride: true,
3175
+ /* Decorator support */
3176
+ ...useDecorators ? {
3177
+ experimentalDecorators: false
3178
+ } : {},
3100
3179
  /* If NOT transpiling with TypeScript: */
3101
3180
  module: hasTypescriptVersionWithModulePreserve ? "preserve" : "ESNext",
3102
3181
  noEmit: true,
3103
3182
  /* If your code runs in the DOM: */
3104
3183
  lib: [
3105
3184
  "ESNext",
3185
+ ...useDecorators ? ["esnext.decorators"] : [],
3106
3186
  "dom",
3107
3187
  "dom.iterable",
3108
3188
  "webworker"
@@ -3131,6 +3211,7 @@ async function _generateTypes(nuxt) {
3131
3211
  tsConfig.compilerOptions ||= {};
3132
3212
  tsConfig.compilerOptions.paths ||= {};
3133
3213
  tsConfig.include ||= [];
3214
+ const importPaths = nuxt.options.modulesDir.map((d) => directoryToURL(d));
3134
3215
  for (const alias in aliases) {
3135
3216
  if (excludedAlias.some((re) => re.test(alias))) {
3136
3217
  continue;
@@ -3141,7 +3222,11 @@ async function _generateTypes(nuxt) {
3141
3222
  /* file does not exist */
3142
3223
  );
3143
3224
  if (!stats) {
3144
- 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
+ });
3145
3230
  if (resolvedModule) {
3146
3231
  absolutePath = resolvedModule;
3147
3232
  stats = await promises.stat(resolvedModule).catch(() => null);
@@ -3167,8 +3252,14 @@ async function _generateTypes(nuxt) {
3167
3252
  if (typeof id !== "string") {
3168
3253
  return;
3169
3254
  }
3170
- const pkg = await readPackageJSON(id, { url: nuxt.options.modulesDir }).catch(() => null);
3171
- 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 });
3172
3263
  }));
3173
3264
  const declarations = [];
3174
3265
  await nuxt.callHook("prepare:types", { references, declarations, tsConfig });
@@ -3330,7 +3421,9 @@ function normalizePlugin(plugin) {
3330
3421
  plugin.src = normalize(resolveAlias(plugin.src));
3331
3422
  if (!existsSync(plugin.src) && isAbsolute$1(plugin.src)) {
3332
3423
  try {
3333
- 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
+ });
3334
3427
  } catch {
3335
3428
  }
3336
3429
  }
@@ -3356,4 +3449,4 @@ function addPluginTemplate(plugin, opts = {}) {
3356
3449
  return addPlugin(normalizedPlugin, opts);
3357
3450
  }
3358
3451
 
3359
- 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.3",
3
+ "version": "3.16.0",
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",
26
+ "c12": "^3.0.2",
27
27
  "consola": "^3.4.0",
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.2",
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
- "@nuxt/schema": "3.15.3"
46
+ "unimport": "^4.1.2",
47
+ "untyped": "^2.0.0"
47
48
  },
48
49
  "devDependencies": {
49
- "@rspack/core": "1.2.2",
50
+ "@rspack/core": "1.2.7",
50
51
  "@types/lodash-es": "4.17.12",
51
52
  "@types/semver": "7.5.8",
52
53
  "lodash-es": "4.17.21",
53
- "nitropack": "2.10.4",
54
+ "nitropack": "2.11.5",
54
55
  "unbuild": "latest",
55
- "vite": "6.0.11",
56
- "vitest": "3.0.4",
57
- "webpack": "5.96.1"
56
+ "vite": "6.2.1",
57
+ "vitest": "3.0.8",
58
+ "webpack": "5.98.0",
59
+ "@nuxt/schema": "3.16.0"
58
60
  },
59
61
  "engines": {
60
62
  "node": ">=18.12.0"