@nuxt/kit 3.13.2 → 3.14.159

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,15 +2,15 @@ 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 { fileURLToPath, pathToFileURL } from 'node:url';
12
+ import { createJiti } from 'jiti';
13
+ import { resolvePath as resolvePath$1, resolve as resolve$1, resolvePathSync, interopDefault } from 'mlly';
14
14
  import { globby } from 'globby';
15
15
  import { resolveAlias as resolveAlias$1 } from 'pathe/utils';
16
16
  import ignore from 'ignore';
@@ -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,33 @@ 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;
2433
+ const paths = [join(nuxtModule, "nuxt"), join(nuxtModule, "module"), nuxtModule, join(nuxt.options.rootDir, nuxtModule)];
2515
2434
  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"));
2435
+ for (const parentURL of nuxt.options.modulesDir) {
2436
+ try {
2437
+ const resolved = resolveAlias(path, nuxt.options.alias);
2438
+ const src = isAbsolute(resolved) ? pathToFileURL(await resolvePath(resolved, { cwd: parentURL, fallbackToOriginal: false, extensions: nuxt.options.extensions })).href : await resolve$1(resolved, { url: pathToFileURL(parentURL.replace(/\/node_modules\/?$/, "")), extensions: nuxt.options.extensions });
2439
+ nuxtModule = await jiti.import(src, { default: true });
2440
+ const moduleMetadataPath = new URL("module.json", src);
2441
+ if (existsSync(moduleMetadataPath)) {
2442
+ buildTimeModuleMeta = JSON.parse(await promises.readFile(moduleMetadataPath, "utf-8"));
2443
+ }
2444
+ break;
2445
+ } catch (error) {
2446
+ const code = error.code;
2447
+ if (code === "MODULE_NOT_FOUND" || code === "ERR_PACKAGE_PATH_NOT_EXPORTED" || code === "ERR_MODULE_NOT_FOUND" || code === "ERR_UNSUPPORTED_DIR_IMPORT" || code === "ENOTDIR") {
2448
+ continue;
2449
+ }
2450
+ logger.error(`Error while importing module \`${nuxtModule}\`: ${error}`);
2451
+ throw error;
2522
2452
  }
2453
+ }
2454
+ if (typeof nuxtModule !== "string") {
2523
2455
  break;
2524
- } catch (_err) {
2525
- error = _err;
2526
- continue;
2527
2456
  }
2528
2457
  }
2529
- if (typeof nuxtModule !== "function" && error) {
2530
- logger.error(`Error while requiring module \`${nuxtModule}\`: ${error}`);
2531
- throw error;
2532
- }
2533
2458
  }
2534
2459
  if (typeof nuxtModule !== "function") {
2535
2460
  throw new TypeError("Nuxt module should be a function: " + nuxtModule);
@@ -2573,8 +2498,8 @@ async function getNuxtModuleVersion(module, nuxt = useNuxt()) {
2573
2498
  }
2574
2499
  }
2575
2500
  if (hasNuxtModule(moduleMeta.name)) {
2576
- const { buildTimeModuleMeta } = await loadNuxtModuleInstance(moduleMeta.name, nuxt);
2577
- return buildTimeModuleMeta.version || false;
2501
+ const { nuxtModule, buildTimeModuleMeta } = await loadNuxtModuleInstance(moduleMeta.name, nuxt);
2502
+ return buildTimeModuleMeta.version || await nuxtModule.getMeta?.().then((r) => r.version) || false;
2578
2503
  }
2579
2504
  return false;
2580
2505
  }
@@ -2648,6 +2573,44 @@ function extendNuxtSchema(def) {
2648
2573
  });
2649
2574
  }
2650
2575
 
2576
+ async function tryResolveModule(id, url = import.meta.url) {
2577
+ try {
2578
+ return await resolvePath$1(id, { url });
2579
+ } catch {
2580
+ }
2581
+ }
2582
+ function resolveModule(id, options) {
2583
+ return resolvePathSync(id, { url: options?.paths ?? [import.meta.url] });
2584
+ }
2585
+ async function importModule(id, opts) {
2586
+ const resolvedPath = await resolveModule(id, opts);
2587
+ return import(pathToFileURL(resolvedPath).href).then((r) => opts?.interopDefault !== false ? interopDefault(r) : r);
2588
+ }
2589
+ function tryImportModule(id, opts) {
2590
+ try {
2591
+ return importModule(id, opts).catch(() => void 0);
2592
+ } catch {
2593
+ }
2594
+ }
2595
+ const warnings = /* @__PURE__ */ new Set();
2596
+ function requireModule(id, opts) {
2597
+ if (!warnings.has(id)) {
2598
+ console.warn("[@nuxt/kit] `requireModule` is deprecated. Please use `importModule` instead.");
2599
+ warnings.add(id);
2600
+ }
2601
+ const resolvedPath = resolveModule(id, opts);
2602
+ const jiti = createJiti(import.meta.url, {
2603
+ interopDefault: opts?.interopDefault !== false
2604
+ });
2605
+ return jiti(pathToFileURL(resolvedPath).href);
2606
+ }
2607
+ function tryRequireModule(id, opts) {
2608
+ try {
2609
+ return requireModule(id, opts);
2610
+ } catch {
2611
+ }
2612
+ }
2613
+
2651
2614
  async function loadNuxt(opts) {
2652
2615
  opts.cwd = opts.cwd || opts.rootDir;
2653
2616
  opts.overrides = opts.overrides || opts.config || {};
@@ -2660,11 +2623,11 @@ async function loadNuxt(opts) {
2660
2623
  const majorVersion = pkg.version ? Number.parseInt(pkg.version.split(".")[0]) : "";
2661
2624
  const rootDir = pathToFileURL(opts.cwd || process.cwd()).href;
2662
2625
  if (majorVersion && majorVersion >= 3) {
2663
- const { loadNuxt: loadNuxt3 } = await importModule(pkg._name || pkg.name, rootDir);
2626
+ const { loadNuxt: loadNuxt3 } = await importModule(pkg._name || pkg.name, { paths: rootDir });
2664
2627
  const nuxt2 = await loadNuxt3(opts);
2665
2628
  return nuxt2;
2666
2629
  }
2667
- const { loadNuxt: loadNuxt2 } = await tryImportModule("nuxt-edge", rootDir) || await importModule("nuxt", rootDir);
2630
+ const { loadNuxt: loadNuxt2 } = await tryImportModule("nuxt-edge", { paths: rootDir }) || await importModule("nuxt", { paths: rootDir });
2668
2631
  const nuxt = await loadNuxt2({
2669
2632
  rootDir: opts.cwd,
2670
2633
  for: opts.dev ? "dev" : "build",
@@ -2688,10 +2651,10 @@ async function loadNuxt(opts) {
2688
2651
  async function buildNuxt(nuxt) {
2689
2652
  const rootDir = pathToFileURL(nuxt.options.rootDir).href;
2690
2653
  if (nuxt.options._majorVersion === 3) {
2691
- const { build: build2 } = await tryImportModule("nuxt-nightly", rootDir) || await tryImportModule("nuxt3", rootDir) || await importModule("nuxt", rootDir);
2654
+ const { build: build2 } = await tryImportModule("nuxt-nightly", { paths: rootDir }) || await tryImportModule("nuxt3", { paths: rootDir }) || await importModule("nuxt", { paths: rootDir });
2692
2655
  return build2(nuxt);
2693
2656
  }
2694
- const { build } = await tryImportModule("nuxt-edge", rootDir) || await importModule("nuxt", rootDir);
2657
+ const { build } = await tryImportModule("nuxt-edge", { paths: rootDir }) || await importModule("nuxt", { paths: rootDir });
2695
2658
  return build(nuxt);
2696
2659
  }
2697
2660
 
@@ -2718,8 +2681,9 @@ function addImportsSources(presets) {
2718
2681
  });
2719
2682
  }
2720
2683
 
2684
+ const HANDLER_METHOD_RE = /\.(get|head|patch|post|put|delete|connect|options|trace)(\.\w+)*$/;
2721
2685
  function normalizeHandlerMethod(handler) {
2722
- const [, method = void 0] = handler.handler.match(/\.(get|head|patch|post|put|delete|connect|options|trace)(\.\w+)*$/) || [];
2686
+ const [, method = void 0] = handler.handler.match(HANDLER_METHOD_RE) || [];
2723
2687
  return {
2724
2688
  method,
2725
2689
  ...handler,
@@ -2837,7 +2801,7 @@ function _expandFromEnv(value, env = process$1.env) {
2837
2801
  });
2838
2802
  }
2839
2803
 
2840
- function extendWebpackConfig(fn, options = {}) {
2804
+ const extendWebpackCompatibleConfig = (builder) => (fn, options = {}) => {
2841
2805
  const nuxt = useNuxt();
2842
2806
  if (options.dev === false && nuxt.options.dev) {
2843
2807
  return;
@@ -2845,7 +2809,7 @@ function extendWebpackConfig(fn, options = {}) {
2845
2809
  if (options.build === false && nuxt.options.build) {
2846
2810
  return;
2847
2811
  }
2848
- nuxt.hook("webpack:config", (configs) => {
2812
+ nuxt.hook(`${builder}:config`, (configs) => {
2849
2813
  if (options.server !== false) {
2850
2814
  const config = configs.find((i) => i.name === "server");
2851
2815
  if (config) {
@@ -2859,7 +2823,9 @@ function extendWebpackConfig(fn, options = {}) {
2859
2823
  }
2860
2824
  }
2861
2825
  });
2862
- }
2826
+ };
2827
+ const extendWebpackConfig = extendWebpackCompatibleConfig("webpack");
2828
+ const extendRspackConfig = extendWebpackCompatibleConfig("rspack");
2863
2829
  function extendViteConfig(fn, options = {}) {
2864
2830
  const nuxt = useNuxt();
2865
2831
  if (options.dev === false && nuxt.options.dev) {
@@ -2888,6 +2854,14 @@ function addWebpackPlugin(pluginOrGetter, options) {
2888
2854
  config.plugins[method](...toArray(plugin));
2889
2855
  }, options);
2890
2856
  }
2857
+ function addRspackPlugin(pluginOrGetter, options) {
2858
+ extendRspackConfig((config) => {
2859
+ const method = options?.prepend ? "unshift" : "push";
2860
+ const plugin = typeof pluginOrGetter === "function" ? pluginOrGetter() : pluginOrGetter;
2861
+ config.plugins = config.plugins || [];
2862
+ config.plugins[method](...toArray(plugin));
2863
+ }, options);
2864
+ }
2891
2865
  function addVitePlugin(pluginOrGetter, options) {
2892
2866
  extendViteConfig((config) => {
2893
2867
  const method = options?.prepend ? "unshift" : "push";
@@ -2903,6 +2877,9 @@ function addBuildPlugin(pluginFactory, options) {
2903
2877
  if (pluginFactory.webpack) {
2904
2878
  addWebpackPlugin(pluginFactory.webpack, options);
2905
2879
  }
2880
+ if (pluginFactory.rspack) {
2881
+ addRspackPlugin(pluginFactory.rspack, options);
2882
+ }
2906
2883
  }
2907
2884
 
2908
2885
  async function addComponentsDir(dir, opts = {}) {
@@ -2919,7 +2896,7 @@ async function addComponent(opts) {
2919
2896
  await assertNuxtCompatibility({ nuxt: ">=2.13" }, nuxt);
2920
2897
  nuxt.options.components = nuxt.options.components || [];
2921
2898
  if (!opts.mode) {
2922
- const [, mode = "all"] = opts.filePath.match(/\.(server|client)(\.\w+)*$/) || [];
2899
+ const [, mode = "all"] = opts.filePath.match(MODE_RE) || [];
2923
2900
  opts.mode = mode;
2924
2901
  }
2925
2902
  const component = {
@@ -3010,6 +2987,8 @@ function normalizeTemplate(template) {
3010
2987
  async function updateTemplates(options) {
3011
2988
  return await tryUseNuxt()?.hooks.callHook("builder:generateApp", options);
3012
2989
  }
2990
+ const EXTENSION_RE = /\b\.\w+$/g;
2991
+ const excludedAlias = [/^@vue\/.*$/, /^#internal\/nuxt/];
3013
2992
  async function _generateTypes(nuxt) {
3014
2993
  const rootDirWithSlash = withTrailingSlash(nuxt.options.rootDir);
3015
2994
  const relativeRootDir = relativeWithDot(nuxt.options.buildDir, nuxt.options.rootDir);
@@ -3098,11 +3077,7 @@ async function _generateTypes(nuxt) {
3098
3077
  include: [...include],
3099
3078
  exclude: [...exclude]
3100
3079
  });
3101
- const aliases = {
3102
- ...nuxt.options.alias,
3103
- "#build": nuxt.options.buildDir
3104
- };
3105
- const excludedAlias = [/^@vue\/.*$/];
3080
+ const aliases = nuxt.options.alias;
3106
3081
  const basePath = tsConfig.compilerOptions.baseUrl ? resolve(nuxt.options.buildDir, tsConfig.compilerOptions.baseUrl) : nuxt.options.buildDir;
3107
3082
  tsConfig.compilerOptions = tsConfig.compilerOptions || {};
3108
3083
  tsConfig.include = tsConfig.include || [];
@@ -3130,7 +3105,7 @@ async function _generateTypes(nuxt) {
3130
3105
  tsConfig.include.push(relativePath);
3131
3106
  }
3132
3107
  } else {
3133
- const path = stats?.isFile() ? relativePath.replace(/\b\.\w+$/g, "") : aliases[alias];
3108
+ const path = stats?.isFile() ? relativePath.replace(EXTENSION_RE, "") : aliases[alias];
3134
3109
  tsConfig.compilerOptions.paths[alias] = [path];
3135
3110
  if (!absolutePath.startsWith(rootDirWithSlash)) {
3136
3111
  tsConfig.include.push(path);
@@ -3142,7 +3117,7 @@ async function _generateTypes(nuxt) {
3142
3117
  if (typeof id !== "string") {
3143
3118
  return;
3144
3119
  }
3145
- const pkg = await readPackageJSON(id, { url: getNodeModulesPaths(nuxt.options.modulesDir) }).catch(() => null);
3120
+ const pkg = await readPackageJSON(id, { url: nuxt.options.modulesDir }).catch(() => null);
3146
3121
  references.push({ types: pkg?.name || id });
3147
3122
  }));
3148
3123
  const declarations = [];
@@ -3157,7 +3132,7 @@ async function _generateTypes(nuxt) {
3157
3132
  () => null
3158
3133
  /* file does not exist */
3159
3134
  );
3160
- return relativeWithDot(nuxt.options.buildDir, stats?.isFile() ? path.replace(/\b\.\w+$/g, "") : path);
3135
+ return relativeWithDot(nuxt.options.buildDir, stats?.isFile() ? path.replace(EXTENSION_RE, "") : path);
3161
3136
  }));
3162
3137
  }
3163
3138
  tsConfig.include = [...new Set(tsConfig.include.map((p) => isAbsolute(p) ? relativeWithDot(nuxt.options.buildDir, p) : p))];
@@ -3202,14 +3177,16 @@ function renderAttrs(obj) {
3202
3177
  function renderAttr(key, value) {
3203
3178
  return value ? `${key}="${value}"` : "";
3204
3179
  }
3180
+ const RELATIVE_WITH_DOT_RE = /^([^.])/;
3205
3181
  function relativeWithDot(from, to) {
3206
- return relative(from, to).replace(/^([^.])/, "./$1") || ".";
3182
+ return relative(from, to).replace(RELATIVE_WITH_DOT_RE, "./$1") || ".";
3207
3183
  }
3208
3184
 
3185
+ const LAYOUT_RE = /["']/g;
3209
3186
  function addLayout(template, name) {
3210
3187
  const nuxt = useNuxt();
3211
3188
  const { filename, src } = addTemplate(template);
3212
- const layoutName = kebabCase(name || parse(filename).name).replace(/["']/g, "");
3189
+ const layoutName = kebabCase(name || parse(filename).name).replace(LAYOUT_RE, "");
3213
3190
  if (isNuxt2(nuxt)) {
3214
3191
  const layout = nuxt.options.layouts[layoutName];
3215
3192
  if (layout) {
@@ -3293,7 +3270,7 @@ function normalizePlugin(plugin) {
3293
3270
  plugin.mode = "server";
3294
3271
  }
3295
3272
  if (!plugin.mode) {
3296
- const [, mode = "all"] = plugin.src.match(/\.(server|client)(\.\w+)*$/) || [];
3273
+ const [, mode = "all"] = plugin.src.match(MODE_RE) || [];
3297
3274
  plugin.mode = mode;
3298
3275
  }
3299
3276
  return plugin;
@@ -3310,4 +3287,4 @@ function addPluginTemplate(plugin, opts = {}) {
3310
3287
  return addPlugin(normalizedPlugin, opts);
3311
3288
  }
3312
3289
 
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 };
3290
+ 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.159",
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.159"
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.3",
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"