@nuxt/kit 3.13.2 → 3.14.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/dist/index.d.mts CHANGED
@@ -2,6 +2,7 @@ import { ModuleOptions, ModuleDefinition, NuxtModule, NuxtConfig, Nuxt, ModuleMe
2
2
  import { LoadConfigOptions } from 'c12';
3
3
  import { Import } from 'unimport';
4
4
  import { Configuration, WebpackPluginInstance } from 'webpack';
5
+ import { RspackPluginInstance } from '@rspack/core';
5
6
  import { UserConfig, Plugin } from 'vite';
6
7
  import * as unctx from 'unctx';
7
8
  import { NitroRouteConfig, NitroEventHandler, NitroDevEventHandler, Nitro } from 'nitropack';
@@ -118,7 +119,14 @@ interface ExtendViteConfigOptions extends ExtendConfigOptions {
118
119
  * The fallback function might be called multiple times
119
120
  * when applying to both client and server builds.
120
121
  */
121
- declare function extendWebpackConfig(fn: ((config: Configuration) => void), options?: ExtendWebpackConfigOptions): void;
122
+ declare const extendWebpackConfig: (fn: ((config: Configuration) => void), options?: ExtendWebpackConfigOptions) => void;
123
+ /**
124
+ * Extend rspack config
125
+ *
126
+ * The fallback function might be called multiple times
127
+ * when applying to both client and server builds.
128
+ */
129
+ declare const extendRspackConfig: (fn: ((config: Configuration) => void), options?: ExtendWebpackConfigOptions) => void;
122
130
  /**
123
131
  * Extend Vite config
124
132
  */
@@ -127,6 +135,10 @@ declare function extendViteConfig(fn: ((config: UserConfig) => void), options?:
127
135
  * Append webpack plugin to the config.
128
136
  */
129
137
  declare function addWebpackPlugin(pluginOrGetter: WebpackPluginInstance | WebpackPluginInstance[] | (() => WebpackPluginInstance | WebpackPluginInstance[]), options?: ExtendWebpackConfigOptions): void;
138
+ /**
139
+ * Append rspack plugin to the config.
140
+ */
141
+ declare function addRspackPlugin(pluginOrGetter: RspackPluginInstance | RspackPluginInstance[] | (() => RspackPluginInstance | RspackPluginInstance[]), options?: ExtendWebpackConfigOptions): void;
130
142
  /**
131
143
  * Append Vite plugin to the config.
132
144
  */
@@ -134,6 +146,7 @@ declare function addVitePlugin(pluginOrGetter: Plugin | Plugin[] | (() => Plugin
134
146
  interface AddBuildPluginFactory {
135
147
  vite?: () => Plugin | Plugin[];
136
148
  webpack?: () => WebpackPluginInstance | WebpackPluginInstance[];
149
+ rspack?: () => RspackPluginInstance | RspackPluginInstance[];
137
150
  }
138
151
  declare function addBuildPlugin(pluginFactory: AddBuildPluginFactory, options?: ExtendConfigOptions): void;
139
152
 
@@ -397,28 +410,9 @@ declare function writeTypes(nuxt: Nuxt): Promise<void>;
397
410
  declare const logger: consola.ConsolaInstance;
398
411
  declare function useLogger(tag?: string, options?: Partial<ConsolaOptions>): consola.ConsolaInstance;
399
412
 
400
- /** @deprecated Do not use CJS utils */
401
413
  interface ResolveModuleOptions {
402
414
  paths?: string | string[];
403
415
  }
404
- /** @deprecated Do not use CJS utils */
405
- interface RequireModuleOptions extends ResolveModuleOptions {
406
- /** Clear the require cache (force fresh require) but only if not within `node_modules` */
407
- clearCache?: boolean;
408
- /** Automatically de-default the result of requiring the module. */
409
- interopDefault?: boolean;
410
- }
411
- /** @deprecated Do not use CJS utils */
412
- declare function resolveModule(id: string, opts?: ResolveModuleOptions): string;
413
- /** @deprecated Do not use CJS utils */
414
- declare function requireModule(id: string, opts?: RequireModuleOptions): any;
415
- /** @deprecated Do not use CJS utils */
416
- declare function importModule(id: string, opts?: RequireModuleOptions): Promise<any>;
417
- /** @deprecated Do not use CJS utils */
418
- declare function tryImportModule(id: string, opts?: RequireModuleOptions): Promise<any> | undefined;
419
- /** @deprecated Do not use CJS utils */
420
- declare function tryRequireModule(id: string, opts?: RequireModuleOptions): any;
421
-
422
416
  /**
423
417
  * Resolve a module from a given root path using an algorithm patterned on
424
418
  * the upcoming `import.meta.resolve`. It returns a file URL
@@ -426,6 +420,21 @@ declare function tryRequireModule(id: string, opts?: RequireModuleOptions): any;
426
420
  * @internal
427
421
  */
428
422
  declare function tryResolveModule(id: string, url?: string | string[]): Promise<string | undefined>;
423
+ declare function resolveModule(id: string, options?: ResolveModuleOptions): string;
424
+ interface ImportModuleOptions extends ResolveModuleOptions {
425
+ /** Automatically de-default the result of requiring the module. */
426
+ interopDefault?: boolean;
427
+ }
428
+ declare function importModule<T = unknown>(id: string, opts?: ImportModuleOptions): Promise<T>;
429
+ declare function tryImportModule<T = unknown>(id: string, opts?: ImportModuleOptions): Promise<T | undefined> | undefined;
430
+ /**
431
+ * @deprecated Please use `importModule` instead.
432
+ */
433
+ declare function requireModule<T = unknown>(id: string, opts?: ImportModuleOptions): T;
434
+ /**
435
+ * @deprecated Please use `tryImportModule` instead.
436
+ */
437
+ declare function tryRequireModule<T = unknown>(id: string, opts?: ImportModuleOptions): T | undefined;
429
438
 
430
439
  /** @deprecated */
431
440
  declare function compileTemplate<T>(template: NuxtTemplate<T>, ctx: any): Promise<string>;
@@ -438,4 +447,4 @@ declare const templateUtils: {
438
447
  }) => string;
439
448
  };
440
449
 
441
- export { type AddComponentOptions, type AddPluginOptions, type AddRouteMiddlewareOptions, type ExtendConfigOptions, type ExtendRouteRulesOptions, type ExtendViteConfigOptions, type ExtendWebpackConfigOptions, type LoadNuxtConfigOptions, type LoadNuxtOptions, type RequireModuleOptions, type ResolveModuleOptions, type ResolvePathOptions, type Resolver, addBuildPlugin, addComponent, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, addLayout, addPlugin, addPluginTemplate, addPrerenderRoutes, addRouteMiddleware, addServerHandler, addServerImports, addServerImportsDir, addServerPlugin, addServerScanDir, addTemplate, addTypeTemplate, addVitePlugin, addWebpackPlugin, assertNuxtCompatibility, buildNuxt, checkNuxtCompatibility, compileTemplate, createResolver, defineNuxtModule, extendNuxtSchema, extendPages, extendRouteRules, 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 };
450
+ 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, addTemplate, addTypeTemplate, addVitePlugin, addWebpackPlugin, assertNuxtCompatibility, buildNuxt, checkNuxtCompatibility, compileTemplate, 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 };
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import { ModuleOptions, ModuleDefinition, NuxtModule, NuxtConfig, Nuxt, ModuleMe
2
2
  import { LoadConfigOptions } from 'c12';
3
3
  import { Import } from 'unimport';
4
4
  import { Configuration, WebpackPluginInstance } from 'webpack';
5
+ import { RspackPluginInstance } from '@rspack/core';
5
6
  import { UserConfig, Plugin } from 'vite';
6
7
  import * as unctx from 'unctx';
7
8
  import { NitroRouteConfig, NitroEventHandler, NitroDevEventHandler, Nitro } from 'nitropack';
@@ -118,7 +119,14 @@ interface ExtendViteConfigOptions extends ExtendConfigOptions {
118
119
  * The fallback function might be called multiple times
119
120
  * when applying to both client and server builds.
120
121
  */
121
- declare function extendWebpackConfig(fn: ((config: Configuration) => void), options?: ExtendWebpackConfigOptions): void;
122
+ declare const extendWebpackConfig: (fn: ((config: Configuration) => void), options?: ExtendWebpackConfigOptions) => void;
123
+ /**
124
+ * Extend rspack config
125
+ *
126
+ * The fallback function might be called multiple times
127
+ * when applying to both client and server builds.
128
+ */
129
+ declare const extendRspackConfig: (fn: ((config: Configuration) => void), options?: ExtendWebpackConfigOptions) => void;
122
130
  /**
123
131
  * Extend Vite config
124
132
  */
@@ -127,6 +135,10 @@ declare function extendViteConfig(fn: ((config: UserConfig) => void), options?:
127
135
  * Append webpack plugin to the config.
128
136
  */
129
137
  declare function addWebpackPlugin(pluginOrGetter: WebpackPluginInstance | WebpackPluginInstance[] | (() => WebpackPluginInstance | WebpackPluginInstance[]), options?: ExtendWebpackConfigOptions): void;
138
+ /**
139
+ * Append rspack plugin to the config.
140
+ */
141
+ declare function addRspackPlugin(pluginOrGetter: RspackPluginInstance | RspackPluginInstance[] | (() => RspackPluginInstance | RspackPluginInstance[]), options?: ExtendWebpackConfigOptions): void;
130
142
  /**
131
143
  * Append Vite plugin to the config.
132
144
  */
@@ -134,6 +146,7 @@ declare function addVitePlugin(pluginOrGetter: Plugin | Plugin[] | (() => Plugin
134
146
  interface AddBuildPluginFactory {
135
147
  vite?: () => Plugin | Plugin[];
136
148
  webpack?: () => WebpackPluginInstance | WebpackPluginInstance[];
149
+ rspack?: () => RspackPluginInstance | RspackPluginInstance[];
137
150
  }
138
151
  declare function addBuildPlugin(pluginFactory: AddBuildPluginFactory, options?: ExtendConfigOptions): void;
139
152
 
@@ -397,28 +410,9 @@ declare function writeTypes(nuxt: Nuxt): Promise<void>;
397
410
  declare const logger: consola.ConsolaInstance;
398
411
  declare function useLogger(tag?: string, options?: Partial<ConsolaOptions>): consola.ConsolaInstance;
399
412
 
400
- /** @deprecated Do not use CJS utils */
401
413
  interface ResolveModuleOptions {
402
414
  paths?: string | string[];
403
415
  }
404
- /** @deprecated Do not use CJS utils */
405
- interface RequireModuleOptions extends ResolveModuleOptions {
406
- /** Clear the require cache (force fresh require) but only if not within `node_modules` */
407
- clearCache?: boolean;
408
- /** Automatically de-default the result of requiring the module. */
409
- interopDefault?: boolean;
410
- }
411
- /** @deprecated Do not use CJS utils */
412
- declare function resolveModule(id: string, opts?: ResolveModuleOptions): string;
413
- /** @deprecated Do not use CJS utils */
414
- declare function requireModule(id: string, opts?: RequireModuleOptions): any;
415
- /** @deprecated Do not use CJS utils */
416
- declare function importModule(id: string, opts?: RequireModuleOptions): Promise<any>;
417
- /** @deprecated Do not use CJS utils */
418
- declare function tryImportModule(id: string, opts?: RequireModuleOptions): Promise<any> | undefined;
419
- /** @deprecated Do not use CJS utils */
420
- declare function tryRequireModule(id: string, opts?: RequireModuleOptions): any;
421
-
422
416
  /**
423
417
  * Resolve a module from a given root path using an algorithm patterned on
424
418
  * the upcoming `import.meta.resolve`. It returns a file URL
@@ -426,6 +420,21 @@ declare function tryRequireModule(id: string, opts?: RequireModuleOptions): any;
426
420
  * @internal
427
421
  */
428
422
  declare function tryResolveModule(id: string, url?: string | string[]): Promise<string | undefined>;
423
+ declare function resolveModule(id: string, options?: ResolveModuleOptions): string;
424
+ interface ImportModuleOptions extends ResolveModuleOptions {
425
+ /** Automatically de-default the result of requiring the module. */
426
+ interopDefault?: boolean;
427
+ }
428
+ declare function importModule<T = unknown>(id: string, opts?: ImportModuleOptions): Promise<T>;
429
+ declare function tryImportModule<T = unknown>(id: string, opts?: ImportModuleOptions): Promise<T | undefined> | undefined;
430
+ /**
431
+ * @deprecated Please use `importModule` instead.
432
+ */
433
+ declare function requireModule<T = unknown>(id: string, opts?: ImportModuleOptions): T;
434
+ /**
435
+ * @deprecated Please use `tryImportModule` instead.
436
+ */
437
+ declare function tryRequireModule<T = unknown>(id: string, opts?: ImportModuleOptions): T | undefined;
429
438
 
430
439
  /** @deprecated */
431
440
  declare function compileTemplate<T>(template: NuxtTemplate<T>, ctx: any): Promise<string>;
@@ -438,4 +447,4 @@ declare const templateUtils: {
438
447
  }) => string;
439
448
  };
440
449
 
441
- export { type AddComponentOptions, type AddPluginOptions, type AddRouteMiddlewareOptions, type ExtendConfigOptions, type ExtendRouteRulesOptions, type ExtendViteConfigOptions, type ExtendWebpackConfigOptions, type LoadNuxtConfigOptions, type LoadNuxtOptions, type RequireModuleOptions, type ResolveModuleOptions, type ResolvePathOptions, type Resolver, addBuildPlugin, addComponent, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, addLayout, addPlugin, addPluginTemplate, addPrerenderRoutes, addRouteMiddleware, addServerHandler, addServerImports, addServerImportsDir, addServerPlugin, addServerScanDir, addTemplate, addTypeTemplate, addVitePlugin, addWebpackPlugin, assertNuxtCompatibility, buildNuxt, checkNuxtCompatibility, compileTemplate, createResolver, defineNuxtModule, extendNuxtSchema, extendPages, extendRouteRules, 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 };
450
+ 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, addTemplate, addTypeTemplate, addVitePlugin, addWebpackPlugin, assertNuxtCompatibility, buildNuxt, checkNuxtCompatibility, compileTemplate, 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 };
package/dist/index.mjs CHANGED
@@ -2,16 +2,16 @@ import { promises, existsSync, readFileSync, lstatSync } from 'node:fs';
2
2
  import { performance } from 'node:perf_hooks';
3
3
  import defu$1, { defu } from 'defu';
4
4
  import { applyDefaults } from 'untyped';
5
- import { dirname, normalize, relative, join, resolve, isAbsolute, basename, parse } from 'pathe';
5
+ import { dirname, relative, join, resolve, normalize, isAbsolute, basename, parse } from 'pathe';
6
6
  import { consola } from 'consola';
7
7
  import { getContext } from 'unctx';
8
8
  import satisfies from 'semver/functions/satisfies.js';
9
9
  import { readPackageJSON, resolvePackageJSON } from 'pkg-types';
10
10
  import { genSafeVariableName, genDynamicImport, genImport } from 'knitwork';
11
- import { pathToFileURL, fileURLToPath } from 'node:url';
12
- import { interopDefault, resolvePath as resolvePath$1 } from 'mlly';
13
- import jiti from 'jiti';
11
+ import { createJiti } from 'jiti';
12
+ import { fileURLToPath, pathToFileURL } from 'node:url';
14
13
  import { globby } from 'globby';
14
+ import { resolvePath as resolvePath$1, resolvePathSync, interopDefault } from 'mlly';
15
15
  import { resolveAlias as resolveAlias$1 } from 'pathe/utils';
16
16
  import ignore from 'ignore';
17
17
  import { loadConfig } from 'c12';
@@ -41,10 +41,12 @@ function tryUseNuxt() {
41
41
  return nuxtCtx.tryUse();
42
42
  }
43
43
 
44
+ const SEMANTIC_VERSION_RE = /-\d+\.[0-9a-f]+/;
44
45
  function normalizeSemanticVersion(version) {
45
- return version.replace(/-\d+\.[0-9a-f]+/, "");
46
+ return version.replace(SEMANTIC_VERSION_RE, "");
46
47
  }
47
48
  const builderMap = {
49
+ "@nuxt/rspack-builder": "rspack",
48
50
  "@nuxt/vite-builder": "vite",
49
51
  "@nuxt/webpack-builder": "webpack"
50
52
  };
@@ -119,12 +121,13 @@ function isNuxt2(nuxt = useNuxt()) {
119
121
  function isNuxt3(nuxt = useNuxt()) {
120
122
  return isNuxtMajorVersion(3, nuxt);
121
123
  }
124
+ const NUXT_VERSION_RE = /^v/g;
122
125
  function getNuxtVersion(nuxt = useNuxt()) {
123
126
  const rawVersion = nuxt?._version || nuxt?.version || nuxt?.constructor?.version;
124
127
  if (typeof rawVersion !== "string") {
125
128
  throw new TypeError("Cannot determine nuxt version! Is current instance passed?");
126
129
  }
127
- return rawVersion.replace(/^v/g, "");
130
+ return rawVersion.replace(NUXT_VERSION_RE, "");
128
131
  }
129
132
 
130
133
  /** Detect free variable `global` from Node.js. */
@@ -2052,6 +2055,7 @@ function template(string, options, guard) {
2052
2055
  function toArray(value) {
2053
2056
  return Array.isArray(value) ? value : [value];
2054
2057
  }
2058
+ const MODE_RE = /\.(server|client)(\.\w+)*$/;
2055
2059
 
2056
2060
  async function compileTemplate(template$1, ctx) {
2057
2061
  const data = { ...ctx, options: template$1.options };
@@ -2195,91 +2199,6 @@ function nuxt2Shims(nuxt) {
2195
2199
  });
2196
2200
  }
2197
2201
 
2198
- const _require = jiti(process.cwd(), { interopDefault: true, esmResolve: true });
2199
- function isNodeModules(id) {
2200
- return /[/\\]node_modules[/\\]/.test(id);
2201
- }
2202
- function clearRequireCache(id) {
2203
- if (isNodeModules(id)) {
2204
- return;
2205
- }
2206
- const entry = getRequireCacheItem(id);
2207
- if (!entry) {
2208
- delete _require.cache[id];
2209
- return;
2210
- }
2211
- if (entry.parent) {
2212
- entry.parent.children = entry.parent.children.filter((e) => e.id !== id);
2213
- }
2214
- for (const child of entry.children) {
2215
- clearRequireCache(child.id);
2216
- }
2217
- delete _require.cache[id];
2218
- }
2219
- function getRequireCacheItem(id) {
2220
- try {
2221
- return _require.cache[id];
2222
- } catch {
2223
- }
2224
- }
2225
- function getNodeModulesPaths(paths) {
2226
- return [].concat(
2227
- global.__NUXT_PREPATHS__,
2228
- paths || [],
2229
- process.cwd(),
2230
- global.__NUXT_PATHS__
2231
- ).filter(Boolean);
2232
- }
2233
- function resolveModule(id, opts = {}) {
2234
- return normalize(_require.resolve(id, {
2235
- paths: getNodeModulesPaths(opts.paths)
2236
- }));
2237
- }
2238
- function requireModule(id, opts = {}) {
2239
- const resolvedPath = resolveModule(id, opts);
2240
- if (opts.clearCache && !isNodeModules(id)) {
2241
- clearRequireCache(resolvedPath);
2242
- }
2243
- const requiredModule = _require(resolvedPath);
2244
- return requiredModule;
2245
- }
2246
- function importModule$1(id, opts = {}) {
2247
- const resolvedPath = resolveModule(id, opts);
2248
- if (opts.interopDefault !== false) {
2249
- return import(pathToFileURL(resolvedPath).href).then(interopDefault);
2250
- }
2251
- return import(pathToFileURL(resolvedPath).href);
2252
- }
2253
- function tryImportModule$1(id, opts = {}) {
2254
- try {
2255
- return importModule$1(id, opts).catch(() => void 0);
2256
- } catch {
2257
- }
2258
- }
2259
- function tryRequireModule(id, opts = {}) {
2260
- try {
2261
- return requireModule(id, opts);
2262
- } catch {
2263
- }
2264
- }
2265
-
2266
- async function tryResolveModule(id, url = import.meta.url) {
2267
- try {
2268
- return await resolvePath$1(id, { url });
2269
- } catch {
2270
- }
2271
- }
2272
- async function importModule(id, url = import.meta.url) {
2273
- const resolvedPath = await resolvePath$1(id, { url });
2274
- return import(pathToFileURL(resolvedPath).href).then(interopDefault);
2275
- }
2276
- function tryImportModule(id, url = import.meta.url) {
2277
- try {
2278
- return importModule(id, url).catch(() => void 0);
2279
- } catch {
2280
- }
2281
- }
2282
-
2283
2202
  function isIgnored(pathname) {
2284
2203
  const nuxt = tryUseNuxt();
2285
2204
  if (!nuxt) {
@@ -2509,27 +2428,32 @@ const normalizeModuleTranspilePath = (p) => {
2509
2428
  };
2510
2429
  async function loadNuxtModuleInstance(nuxtModule, nuxt = useNuxt()) {
2511
2430
  let buildTimeModuleMeta = {};
2431
+ const jiti = createJiti(nuxt.options.rootDir, { alias: nuxt.options.alias });
2512
2432
  if (typeof nuxtModule === "string") {
2513
- const paths = [join(nuxtModule, "nuxt"), join(nuxtModule, "module"), nuxtModule];
2514
- let error;
2515
- for (const path of paths) {
2516
- try {
2517
- const src = await resolvePath(path, { fallbackToOriginal: true });
2518
- nuxtModule = await importModule(src, nuxt.options.modulesDir).catch(() => null) ?? requireModule(src, { paths: nuxt.options.modulesDir });
2519
- const moduleMetadataPath = join(dirname(src), "module.json");
2520
- if (existsSync(moduleMetadataPath)) {
2521
- buildTimeModuleMeta = JSON.parse(await promises.readFile(moduleMetadataPath, "utf-8"));
2433
+ const paths = [join(nuxtModule, "nuxt"), join(nuxtModule, "module"), nuxtModule, join(nuxt.options.rootDir, nuxtModule)];
2434
+ for (const parentURL of nuxt.options.modulesDir) {
2435
+ for (const path of paths) {
2436
+ try {
2437
+ const src = jiti.esmResolve(path, { parentURL: parentURL.replace(/\/node_modules\/?$/, "") });
2438
+ nuxtModule = await jiti.import(src, { default: true });
2439
+ const moduleMetadataPath = join(dirname(src), "module.json");
2440
+ if (existsSync(moduleMetadataPath)) {
2441
+ buildTimeModuleMeta = JSON.parse(await promises.readFile(moduleMetadataPath, "utf-8"));
2442
+ }
2443
+ break;
2444
+ } catch (error) {
2445
+ const code = error.code;
2446
+ if (code === "MODULE_NOT_FOUND" || code === "ERR_PACKAGE_PATH_NOT_EXPORTED" || code === "ERR_MODULE_NOT_FOUND" || code === "ERR_UNSUPPORTED_DIR_IMPORT") {
2447
+ continue;
2448
+ }
2449
+ logger.error(`Error while importing module \`${nuxtModule}\`: ${error}`);
2450
+ throw error;
2522
2451
  }
2452
+ }
2453
+ if (typeof nuxtModule !== "string") {
2523
2454
  break;
2524
- } catch (_err) {
2525
- error = _err;
2526
- continue;
2527
2455
  }
2528
2456
  }
2529
- if (typeof nuxtModule !== "function" && error) {
2530
- logger.error(`Error while requiring module \`${nuxtModule}\`: ${error}`);
2531
- throw error;
2532
- }
2533
2457
  }
2534
2458
  if (typeof nuxtModule !== "function") {
2535
2459
  throw new TypeError("Nuxt module should be a function: " + nuxtModule);
@@ -2648,6 +2572,44 @@ function extendNuxtSchema(def) {
2648
2572
  });
2649
2573
  }
2650
2574
 
2575
+ async function tryResolveModule(id, url = import.meta.url) {
2576
+ try {
2577
+ return await resolvePath$1(id, { url });
2578
+ } catch {
2579
+ }
2580
+ }
2581
+ function resolveModule(id, options) {
2582
+ return resolvePathSync(id, { url: options?.paths ?? [import.meta.url] });
2583
+ }
2584
+ async function importModule(id, opts) {
2585
+ const resolvedPath = await resolveModule(id, opts);
2586
+ return import(pathToFileURL(resolvedPath).href).then((r) => opts?.interopDefault !== false ? interopDefault(r) : r);
2587
+ }
2588
+ function tryImportModule(id, opts) {
2589
+ try {
2590
+ return importModule(id, opts).catch(() => void 0);
2591
+ } catch {
2592
+ }
2593
+ }
2594
+ const warnings = /* @__PURE__ */ new Set();
2595
+ function requireModule(id, opts) {
2596
+ if (!warnings.has(id)) {
2597
+ console.warn("[@nuxt/kit] `requireModule` is deprecated. Please use `importModule` instead.");
2598
+ warnings.add(id);
2599
+ }
2600
+ const resolvedPath = resolveModule(id, opts);
2601
+ const jiti = createJiti(import.meta.url, {
2602
+ interopDefault: opts?.interopDefault !== false
2603
+ });
2604
+ return jiti(pathToFileURL(resolvedPath).href);
2605
+ }
2606
+ function tryRequireModule(id, opts) {
2607
+ try {
2608
+ return requireModule(id, opts);
2609
+ } catch {
2610
+ }
2611
+ }
2612
+
2651
2613
  async function loadNuxt(opts) {
2652
2614
  opts.cwd = opts.cwd || opts.rootDir;
2653
2615
  opts.overrides = opts.overrides || opts.config || {};
@@ -2660,11 +2622,11 @@ async function loadNuxt(opts) {
2660
2622
  const majorVersion = pkg.version ? Number.parseInt(pkg.version.split(".")[0]) : "";
2661
2623
  const rootDir = pathToFileURL(opts.cwd || process.cwd()).href;
2662
2624
  if (majorVersion && majorVersion >= 3) {
2663
- const { loadNuxt: loadNuxt3 } = await importModule(pkg._name || pkg.name, rootDir);
2625
+ const { loadNuxt: loadNuxt3 } = await importModule(pkg._name || pkg.name, { paths: rootDir });
2664
2626
  const nuxt2 = await loadNuxt3(opts);
2665
2627
  return nuxt2;
2666
2628
  }
2667
- const { loadNuxt: loadNuxt2 } = await tryImportModule("nuxt-edge", rootDir) || await importModule("nuxt", rootDir);
2629
+ const { loadNuxt: loadNuxt2 } = await tryImportModule("nuxt-edge", { paths: rootDir }) || await importModule("nuxt", { paths: rootDir });
2668
2630
  const nuxt = await loadNuxt2({
2669
2631
  rootDir: opts.cwd,
2670
2632
  for: opts.dev ? "dev" : "build",
@@ -2688,10 +2650,10 @@ async function loadNuxt(opts) {
2688
2650
  async function buildNuxt(nuxt) {
2689
2651
  const rootDir = pathToFileURL(nuxt.options.rootDir).href;
2690
2652
  if (nuxt.options._majorVersion === 3) {
2691
- const { build: build2 } = await tryImportModule("nuxt-nightly", rootDir) || await tryImportModule("nuxt3", rootDir) || await importModule("nuxt", rootDir);
2653
+ const { build: build2 } = await tryImportModule("nuxt-nightly", { paths: rootDir }) || await tryImportModule("nuxt3", { paths: rootDir }) || await importModule("nuxt", { paths: rootDir });
2692
2654
  return build2(nuxt);
2693
2655
  }
2694
- const { build } = await tryImportModule("nuxt-edge", rootDir) || await importModule("nuxt", rootDir);
2656
+ const { build } = await tryImportModule("nuxt-edge", { paths: rootDir }) || await importModule("nuxt", { paths: rootDir });
2695
2657
  return build(nuxt);
2696
2658
  }
2697
2659
 
@@ -2718,8 +2680,9 @@ function addImportsSources(presets) {
2718
2680
  });
2719
2681
  }
2720
2682
 
2683
+ const HANDLER_METHOD_RE = /\.(get|head|patch|post|put|delete|connect|options|trace)(\.\w+)*$/;
2721
2684
  function normalizeHandlerMethod(handler) {
2722
- const [, method = void 0] = handler.handler.match(/\.(get|head|patch|post|put|delete|connect|options|trace)(\.\w+)*$/) || [];
2685
+ const [, method = void 0] = handler.handler.match(HANDLER_METHOD_RE) || [];
2723
2686
  return {
2724
2687
  method,
2725
2688
  ...handler,
@@ -2837,7 +2800,7 @@ function _expandFromEnv(value, env = process$1.env) {
2837
2800
  });
2838
2801
  }
2839
2802
 
2840
- function extendWebpackConfig(fn, options = {}) {
2803
+ const extendWebpackCompatibleConfig = (builder) => (fn, options = {}) => {
2841
2804
  const nuxt = useNuxt();
2842
2805
  if (options.dev === false && nuxt.options.dev) {
2843
2806
  return;
@@ -2845,7 +2808,7 @@ function extendWebpackConfig(fn, options = {}) {
2845
2808
  if (options.build === false && nuxt.options.build) {
2846
2809
  return;
2847
2810
  }
2848
- nuxt.hook("webpack:config", (configs) => {
2811
+ nuxt.hook(`${builder}:config`, (configs) => {
2849
2812
  if (options.server !== false) {
2850
2813
  const config = configs.find((i) => i.name === "server");
2851
2814
  if (config) {
@@ -2859,7 +2822,9 @@ function extendWebpackConfig(fn, options = {}) {
2859
2822
  }
2860
2823
  }
2861
2824
  });
2862
- }
2825
+ };
2826
+ const extendWebpackConfig = extendWebpackCompatibleConfig("webpack");
2827
+ const extendRspackConfig = extendWebpackCompatibleConfig("rspack");
2863
2828
  function extendViteConfig(fn, options = {}) {
2864
2829
  const nuxt = useNuxt();
2865
2830
  if (options.dev === false && nuxt.options.dev) {
@@ -2888,6 +2853,14 @@ function addWebpackPlugin(pluginOrGetter, options) {
2888
2853
  config.plugins[method](...toArray(plugin));
2889
2854
  }, options);
2890
2855
  }
2856
+ function addRspackPlugin(pluginOrGetter, options) {
2857
+ extendRspackConfig((config) => {
2858
+ const method = options?.prepend ? "unshift" : "push";
2859
+ const plugin = typeof pluginOrGetter === "function" ? pluginOrGetter() : pluginOrGetter;
2860
+ config.plugins = config.plugins || [];
2861
+ config.plugins[method](...toArray(plugin));
2862
+ }, options);
2863
+ }
2891
2864
  function addVitePlugin(pluginOrGetter, options) {
2892
2865
  extendViteConfig((config) => {
2893
2866
  const method = options?.prepend ? "unshift" : "push";
@@ -2903,6 +2876,9 @@ function addBuildPlugin(pluginFactory, options) {
2903
2876
  if (pluginFactory.webpack) {
2904
2877
  addWebpackPlugin(pluginFactory.webpack, options);
2905
2878
  }
2879
+ if (pluginFactory.rspack) {
2880
+ addRspackPlugin(pluginFactory.rspack, options);
2881
+ }
2906
2882
  }
2907
2883
 
2908
2884
  async function addComponentsDir(dir, opts = {}) {
@@ -2919,7 +2895,7 @@ async function addComponent(opts) {
2919
2895
  await assertNuxtCompatibility({ nuxt: ">=2.13" }, nuxt);
2920
2896
  nuxt.options.components = nuxt.options.components || [];
2921
2897
  if (!opts.mode) {
2922
- const [, mode = "all"] = opts.filePath.match(/\.(server|client)(\.\w+)*$/) || [];
2898
+ const [, mode = "all"] = opts.filePath.match(MODE_RE) || [];
2923
2899
  opts.mode = mode;
2924
2900
  }
2925
2901
  const component = {
@@ -3010,6 +2986,8 @@ function normalizeTemplate(template) {
3010
2986
  async function updateTemplates(options) {
3011
2987
  return await tryUseNuxt()?.hooks.callHook("builder:generateApp", options);
3012
2988
  }
2989
+ const EXTENSION_RE = /\b\.\w+$/g;
2990
+ const excludedAlias = [/^@vue\/.*$/, /^#internal\/nuxt/];
3013
2991
  async function _generateTypes(nuxt) {
3014
2992
  const rootDirWithSlash = withTrailingSlash(nuxt.options.rootDir);
3015
2993
  const relativeRootDir = relativeWithDot(nuxt.options.buildDir, nuxt.options.rootDir);
@@ -3098,11 +3076,7 @@ async function _generateTypes(nuxt) {
3098
3076
  include: [...include],
3099
3077
  exclude: [...exclude]
3100
3078
  });
3101
- const aliases = {
3102
- ...nuxt.options.alias,
3103
- "#build": nuxt.options.buildDir
3104
- };
3105
- const excludedAlias = [/^@vue\/.*$/];
3079
+ const aliases = nuxt.options.alias;
3106
3080
  const basePath = tsConfig.compilerOptions.baseUrl ? resolve(nuxt.options.buildDir, tsConfig.compilerOptions.baseUrl) : nuxt.options.buildDir;
3107
3081
  tsConfig.compilerOptions = tsConfig.compilerOptions || {};
3108
3082
  tsConfig.include = tsConfig.include || [];
@@ -3130,7 +3104,7 @@ async function _generateTypes(nuxt) {
3130
3104
  tsConfig.include.push(relativePath);
3131
3105
  }
3132
3106
  } else {
3133
- const path = stats?.isFile() ? relativePath.replace(/\b\.\w+$/g, "") : aliases[alias];
3107
+ const path = stats?.isFile() ? relativePath.replace(EXTENSION_RE, "") : aliases[alias];
3134
3108
  tsConfig.compilerOptions.paths[alias] = [path];
3135
3109
  if (!absolutePath.startsWith(rootDirWithSlash)) {
3136
3110
  tsConfig.include.push(path);
@@ -3142,7 +3116,7 @@ async function _generateTypes(nuxt) {
3142
3116
  if (typeof id !== "string") {
3143
3117
  return;
3144
3118
  }
3145
- const pkg = await readPackageJSON(id, { url: getNodeModulesPaths(nuxt.options.modulesDir) }).catch(() => null);
3119
+ const pkg = await readPackageJSON(id, { url: nuxt.options.modulesDir }).catch(() => null);
3146
3120
  references.push({ types: pkg?.name || id });
3147
3121
  }));
3148
3122
  const declarations = [];
@@ -3157,7 +3131,7 @@ async function _generateTypes(nuxt) {
3157
3131
  () => null
3158
3132
  /* file does not exist */
3159
3133
  );
3160
- return relativeWithDot(nuxt.options.buildDir, stats?.isFile() ? path.replace(/\b\.\w+$/g, "") : path);
3134
+ return relativeWithDot(nuxt.options.buildDir, stats?.isFile() ? path.replace(EXTENSION_RE, "") : path);
3161
3135
  }));
3162
3136
  }
3163
3137
  tsConfig.include = [...new Set(tsConfig.include.map((p) => isAbsolute(p) ? relativeWithDot(nuxt.options.buildDir, p) : p))];
@@ -3202,14 +3176,16 @@ function renderAttrs(obj) {
3202
3176
  function renderAttr(key, value) {
3203
3177
  return value ? `${key}="${value}"` : "";
3204
3178
  }
3179
+ const RELATIVE_WITH_DOT_RE = /^([^.])/;
3205
3180
  function relativeWithDot(from, to) {
3206
- return relative(from, to).replace(/^([^.])/, "./$1") || ".";
3181
+ return relative(from, to).replace(RELATIVE_WITH_DOT_RE, "./$1") || ".";
3207
3182
  }
3208
3183
 
3184
+ const LAYOUT_RE = /["']/g;
3209
3185
  function addLayout(template, name) {
3210
3186
  const nuxt = useNuxt();
3211
3187
  const { filename, src } = addTemplate(template);
3212
- const layoutName = kebabCase(name || parse(filename).name).replace(/["']/g, "");
3188
+ const layoutName = kebabCase(name || parse(filename).name).replace(LAYOUT_RE, "");
3213
3189
  if (isNuxt2(nuxt)) {
3214
3190
  const layout = nuxt.options.layouts[layoutName];
3215
3191
  if (layout) {
@@ -3293,7 +3269,7 @@ function normalizePlugin(plugin) {
3293
3269
  plugin.mode = "server";
3294
3270
  }
3295
3271
  if (!plugin.mode) {
3296
- const [, mode = "all"] = plugin.src.match(/\.(server|client)(\.\w+)*$/) || [];
3272
+ const [, mode = "all"] = plugin.src.match(MODE_RE) || [];
3297
3273
  plugin.mode = mode;
3298
3274
  }
3299
3275
  return plugin;
@@ -3310,4 +3286,4 @@ function addPluginTemplate(plugin, opts = {}) {
3310
3286
  return addPlugin(normalizedPlugin, opts);
3311
3287
  }
3312
3288
 
3313
- export { addBuildPlugin, addComponent, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, addLayout, addPlugin, addPluginTemplate, addPrerenderRoutes, addRouteMiddleware, addServerHandler, addServerImports, addServerImportsDir, addServerPlugin, addServerScanDir, addTemplate, addTypeTemplate, addVitePlugin, addWebpackPlugin, assertNuxtCompatibility, buildNuxt, checkNuxtCompatibility, compileTemplate, createResolver, defineNuxtModule, extendNuxtSchema, extendPages, extendRouteRules, extendViteConfig, extendWebpackConfig, findPath, getDirectory, getNuxtModuleVersion, getNuxtVersion, hasNuxtCompatibility, hasNuxtModule, hasNuxtModuleCompatibility, importModule$1 as importModule, installModule, isIgnored, isNuxt2, isNuxt3, isNuxtMajorVersion, loadNuxt, loadNuxtConfig, loadNuxtModuleInstance, logger, normalizeModuleTranspilePath, normalizePlugin, normalizeSemanticVersion, normalizeTemplate, nuxtCtx, requireModule, resolveAlias, resolveFiles, resolveIgnorePatterns, resolveModule, resolveNuxtModule, resolvePath, templateUtils, tryImportModule$1 as tryImportModule, tryRequireModule, tryResolveModule, tryUseNuxt, updateRuntimeConfig, updateTemplates, useLogger, useNitro, useNuxt, useRuntimeConfig, writeTypes };
3289
+ export { addBuildPlugin, addComponent, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, addLayout, addPlugin, addPluginTemplate, addPrerenderRoutes, addRouteMiddleware, addRspackPlugin, addServerHandler, addServerImports, addServerImportsDir, addServerPlugin, addServerScanDir, addTemplate, addTypeTemplate, addVitePlugin, addWebpackPlugin, assertNuxtCompatibility, buildNuxt, checkNuxtCompatibility, compileTemplate, 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/kit",
3
- "version": "3.13.2",
3
+ "version": "3.14.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/nuxt.git",
@@ -23,37 +23,38 @@
23
23
  "dist"
24
24
  ],
25
25
  "dependencies": {
26
- "c12": "^1.11.2",
26
+ "c12": "^2.0.1",
27
27
  "consola": "^3.2.3",
28
28
  "defu": "^6.1.4",
29
29
  "destr": "^2.0.3",
30
30
  "globby": "^14.0.2",
31
31
  "hash-sum": "^2.0.0",
32
- "ignore": "^5.3.2",
33
- "jiti": "^1.21.6",
32
+ "ignore": "^6.0.2",
33
+ "jiti": "^2.4.0",
34
34
  "klona": "^2.0.6",
35
35
  "knitwork": "^1.1.0",
36
- "mlly": "^1.7.1",
36
+ "mlly": "^1.7.2",
37
37
  "pathe": "^1.1.2",
38
- "pkg-types": "^1.2.0",
38
+ "pkg-types": "^1.2.1",
39
39
  "scule": "^1.3.0",
40
40
  "semver": "^7.6.3",
41
41
  "ufo": "^1.5.4",
42
42
  "unctx": "^2.3.1",
43
- "unimport": "^3.12.0",
44
- "untyped": "^1.4.2",
45
- "@nuxt/schema": "3.13.2"
43
+ "unimport": "^3.13.1",
44
+ "untyped": "^1.5.1",
45
+ "@nuxt/schema": "3.14.0"
46
46
  },
47
47
  "devDependencies": {
48
+ "@rspack/core": "1.0.14",
48
49
  "@types/hash-sum": "1.0.2",
49
50
  "@types/lodash-es": "4.17.12",
50
51
  "@types/semver": "7.5.8",
51
52
  "lodash-es": "4.17.21",
52
- "nitropack": "2.9.7",
53
+ "nitropack": "2.10.2",
53
54
  "unbuild": "latest",
54
- "vite": "5.4.5",
55
- "vitest": "2.1.1",
56
- "webpack": "5.94.0"
55
+ "vite": "5.4.10",
56
+ "vitest": "2.1.4",
57
+ "webpack": "5.96.1"
57
58
  },
58
59
  "engines": {
59
60
  "node": "^14.18.0 || >=16.10.0"