@nuxt/kit 3.12.1 → 3.12.2

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
@@ -42,7 +42,8 @@ declare function hasNuxtModuleCompatibility(module: string | NuxtModule, semverV
42
42
  */
43
43
  declare function getNuxtModuleVersion(module: string | NuxtModule, nuxt?: Nuxt | any): Promise<string | false>;
44
44
 
45
- interface LoadNuxtConfigOptions extends LoadConfigOptions<NuxtConfig> {
45
+ interface LoadNuxtConfigOptions extends Omit<LoadConfigOptions<NuxtConfig>, 'overrides'> {
46
+ overrides?: Exclude<LoadConfigOptions<NuxtConfig>['overrides'], Promise<any> | Function>;
46
47
  }
47
48
  declare function loadNuxtConfig(opts: LoadNuxtConfigOptions): Promise<NuxtOptions>;
48
49
 
@@ -243,8 +244,11 @@ declare function normalizePlugin(plugin: NuxtPlugin | string): NuxtPlugin;
243
244
  * Note: By default plugin is prepended to the plugins array. You can use second argument to append (push) instead.
244
245
  * @example
245
246
  * ```js
247
+ * import { createResolver } from '@nuxt/kit'
248
+ * const resolver = createResolver(import.meta.url)
249
+ *
246
250
  * addPlugin({
247
- * src: path.resolve(__dirname, 'templates/foo.js'),
251
+ * src: resolver.resolve('templates/foo.js'),
248
252
  * filename: 'foo.server.js' // [optional] only include in server bundle
249
253
  * })
250
254
  * ```
package/dist/index.d.ts CHANGED
@@ -42,7 +42,8 @@ declare function hasNuxtModuleCompatibility(module: string | NuxtModule, semverV
42
42
  */
43
43
  declare function getNuxtModuleVersion(module: string | NuxtModule, nuxt?: Nuxt | any): Promise<string | false>;
44
44
 
45
- interface LoadNuxtConfigOptions extends LoadConfigOptions<NuxtConfig> {
45
+ interface LoadNuxtConfigOptions extends Omit<LoadConfigOptions<NuxtConfig>, 'overrides'> {
46
+ overrides?: Exclude<LoadConfigOptions<NuxtConfig>['overrides'], Promise<any> | Function>;
46
47
  }
47
48
  declare function loadNuxtConfig(opts: LoadNuxtConfigOptions): Promise<NuxtOptions>;
48
49
 
@@ -243,8 +244,11 @@ declare function normalizePlugin(plugin: NuxtPlugin | string): NuxtPlugin;
243
244
  * Note: By default plugin is prepended to the plugins array. You can use second argument to append (push) instead.
244
245
  * @example
245
246
  * ```js
247
+ * import { createResolver } from '@nuxt/kit'
248
+ * const resolver = createResolver(import.meta.url)
249
+ *
246
250
  * addPlugin({
247
- * src: path.resolve(__dirname, 'templates/foo.js'),
251
+ * src: resolver.resolve('templates/foo.js'),
248
252
  * filename: 'foo.server.js' // [optional] only include in server bundle
249
253
  * })
250
254
  * ```
package/dist/index.mjs CHANGED
@@ -2070,10 +2070,11 @@ async function compileTemplate(template$1, ctx) {
2070
2070
  const serialize = (data) => JSON.stringify(data, null, 2).replace(/"\{(.+)\}"(?=,?$)/gm, (r) => JSON.parse(r).replace(/^\{(.*)\}$/, "$1"));
2071
2071
  const importSources = (sources, { lazy = false } = {}) => {
2072
2072
  return toArray(sources).map((src) => {
2073
+ const safeVariableName = genSafeVariableName(src);
2073
2074
  if (lazy) {
2074
- return `const ${genSafeVariableName(src)} = ${genDynamicImport(src, { comment: `webpackChunkName: ${JSON.stringify(src)}` })}`;
2075
+ return `const ${safeVariableName} = ${genDynamicImport(src, { comment: `webpackChunkName: ${JSON.stringify(src)}` })}`;
2075
2076
  }
2076
- return genImport(src, genSafeVariableName(src));
2077
+ return genImport(src, safeVariableName);
2077
2078
  }).join("\n");
2078
2079
  };
2079
2080
  const importName = genSafeVariableName;
@@ -2212,7 +2213,7 @@ function getRequireCacheItem(id) {
2212
2213
  } catch (e) {
2213
2214
  }
2214
2215
  }
2215
- function getModulePaths(paths) {
2216
+ function getNodeModulesPaths(paths) {
2216
2217
  return [].concat(
2217
2218
  global.__NUXT_PREPATHS__,
2218
2219
  paths || [],
@@ -2222,7 +2223,7 @@ function getModulePaths(paths) {
2222
2223
  }
2223
2224
  function resolveModule(id, opts = {}) {
2224
2225
  return normalize(_require.resolve(id, {
2225
- paths: getModulePaths(opts.paths)
2226
+ paths: getNodeModulesPaths(opts.paths)
2226
2227
  }));
2227
2228
  }
2228
2229
  function requireModule(id, opts = {}) {
@@ -2445,8 +2446,14 @@ function existsInVFS(path, nuxt = tryUseNuxt()) {
2445
2446
  return templates.some((template) => template.dst === path);
2446
2447
  }
2447
2448
  async function resolveFiles(path, pattern, opts = {}) {
2448
- const files = await globby(pattern, { cwd: path, followSymbolicLinks: opts.followSymbolicLinks ?? true });
2449
- return files.map((p) => resolve(path, p)).filter((p) => !isIgnored(p)).sort();
2449
+ const files = [];
2450
+ for (const file of await globby(pattern, { cwd: path, followSymbolicLinks: opts.followSymbolicLinks ?? true })) {
2451
+ const p = resolve(path, file);
2452
+ if (!isIgnored(p)) {
2453
+ files.push(p);
2454
+ }
2455
+ }
2456
+ return files.sort();
2450
2457
  }
2451
2458
 
2452
2459
  const NODE_MODULES_RE = /[/\\]node_modules[/\\]/;
@@ -2551,9 +2558,10 @@ async function getNuxtModuleVersion(module, nuxt = useNuxt()) {
2551
2558
  if (!moduleMeta.name) {
2552
2559
  return false;
2553
2560
  }
2554
- const version = nuxt.options._installedModules.filter((m) => m.meta.name === moduleMeta.name).map((m) => m.meta.version)?.[0];
2555
- if (version) {
2556
- return version;
2561
+ for (const m of nuxt.options._installedModules) {
2562
+ if (m.meta.name === moduleMeta.name && m.meta.version) {
2563
+ return m.meta.version;
2564
+ }
2557
2565
  }
2558
2566
  if (hasNuxtModule(moduleMeta.name)) {
2559
2567
  const { buildTimeModuleMeta } = await loadNuxtModuleInstance(moduleMeta.name, nuxt);
@@ -2563,7 +2571,12 @@ async function getNuxtModuleVersion(module, nuxt = useNuxt()) {
2563
2571
  }
2564
2572
 
2565
2573
  const layerSchemaKeys = ["future", "srcDir", "rootDir", "dir"];
2566
- const layerSchema = Object.fromEntries(Object.entries(NuxtConfigSchema).filter(([key]) => layerSchemaKeys.includes(key)));
2574
+ const layerSchema = /* @__PURE__ */ Object.create(null);
2575
+ for (const key of layerSchemaKeys) {
2576
+ if (key in NuxtConfigSchema) {
2577
+ layerSchema[key] = NuxtConfigSchema[key];
2578
+ }
2579
+ }
2567
2580
  async function loadNuxtConfig(opts) {
2568
2581
  opts.overrides = defu$1(opts.overrides, {
2569
2582
  _extends: await globby("layers/*", {
@@ -2588,9 +2601,14 @@ async function loadNuxtConfig(opts) {
2588
2601
  nuxtConfig._nuxtConfigFile = configFile;
2589
2602
  nuxtConfig._nuxtConfigFiles = [configFile];
2590
2603
  const _layers = [];
2604
+ const processedLayers = /* @__PURE__ */ new Set();
2591
2605
  for (const layer of layers) {
2592
2606
  layer.config = layer.config || {};
2593
2607
  layer.config.rootDir = layer.config.rootDir ?? layer.cwd;
2608
+ if (processedLayers.has(layer.config.rootDir)) {
2609
+ continue;
2610
+ }
2611
+ processedLayers.add(layer.config.rootDir);
2594
2612
  layer.config = await applyDefaults(layerSchema, layer.config);
2595
2613
  if (!layer.configFile || layer.configFile.endsWith(".nuxtrc")) {
2596
2614
  continue;
@@ -2980,12 +2998,44 @@ async function updateTemplates(options) {
2980
2998
  return await tryUseNuxt()?.hooks.callHook("builder:generateApp", options);
2981
2999
  }
2982
3000
  async function _generateTypes(nuxt) {
2983
- const nodeModulePaths = getModulePaths(nuxt.options.modulesDir);
2984
3001
  const rootDirWithSlash = withTrailingSlash(nuxt.options.rootDir);
2985
- const modulePaths = await resolveNuxtModule(
2986
- rootDirWithSlash,
2987
- nuxt.options._installedModules.filter((m) => m.entryPath).map((m) => getDirectory(m.entryPath))
2988
- );
3002
+ const relativeRootDir = relativeWithDot(nuxt.options.buildDir, nuxt.options.rootDir);
3003
+ const include = /* @__PURE__ */ new Set([
3004
+ "./nuxt.d.ts",
3005
+ join(relativeRootDir, ".config/nuxt.*"),
3006
+ join(relativeRootDir, "**/*")
3007
+ ]);
3008
+ if (nuxt.options.srcDir !== nuxt.options.rootDir) {
3009
+ include.add(join(relative(nuxt.options.buildDir, nuxt.options.srcDir), "**/*"));
3010
+ }
3011
+ if (nuxt.options.typescript.includeWorkspace && nuxt.options.workspaceDir !== nuxt.options.rootDir) {
3012
+ include.add(join(relative(nuxt.options.buildDir, nuxt.options.workspaceDir), "**/*"));
3013
+ }
3014
+ for (const layer of nuxt.options._layers) {
3015
+ const srcOrCwd = layer.config.srcDir ?? layer.cwd;
3016
+ if (!srcOrCwd.startsWith(rootDirWithSlash) || srcOrCwd.includes("node_modules")) {
3017
+ include.add(join(relative(nuxt.options.buildDir, srcOrCwd), "**/*"));
3018
+ }
3019
+ }
3020
+ const exclude = /* @__PURE__ */ new Set([
3021
+ // nitro generate output: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/core/nitro.ts#L186
3022
+ relativeWithDot(nuxt.options.buildDir, resolve(nuxt.options.rootDir, "dist"))
3023
+ ]);
3024
+ for (const dir of nuxt.options.modulesDir) {
3025
+ exclude.add(relativeWithDot(nuxt.options.buildDir, dir));
3026
+ }
3027
+ const moduleEntryPaths = [];
3028
+ for (const m of nuxt.options._installedModules) {
3029
+ if (m.entryPath) {
3030
+ moduleEntryPaths.push(getDirectory(m.entryPath));
3031
+ }
3032
+ }
3033
+ const modulePaths = await resolveNuxtModule(rootDirWithSlash, moduleEntryPaths);
3034
+ for (const path of modulePaths) {
3035
+ const relative2 = relativeWithDot(nuxt.options.buildDir, path);
3036
+ include.add(join(relative2, "runtime"));
3037
+ exclude.add(join(relative2, "runtime/server"));
3038
+ }
2989
3039
  const isV4 = nuxt.options.future?.compatibilityVersion === 4;
2990
3040
  const hasTypescriptVersionWithModulePreserve = await readPackageJSON("typescript", { url: nuxt.options.modulesDir }).then((r) => r?.version && gte(r.version, "5.4.0")).catch(() => isV4);
2991
3041
  const tsConfig = defu(nuxt.options.typescript?.tsConfig, {
@@ -3029,21 +3079,8 @@ async function _generateTypes(nuxt) {
3029
3079
  /* enabled with `strict` */
3030
3080
  allowSyntheticDefaultImports: true
3031
3081
  },
3032
- include: [
3033
- "./nuxt.d.ts",
3034
- join(relativeWithDot(nuxt.options.buildDir, nuxt.options.rootDir), ".config/nuxt.*"),
3035
- join(relativeWithDot(nuxt.options.buildDir, nuxt.options.rootDir), "**/*"),
3036
- ...nuxt.options.srcDir !== nuxt.options.rootDir ? [join(relative(nuxt.options.buildDir, nuxt.options.srcDir), "**/*")] : [],
3037
- ...nuxt.options._layers.map((layer) => layer.config.srcDir ?? layer.cwd).filter((srcOrCwd) => !srcOrCwd.startsWith(rootDirWithSlash) || srcOrCwd.includes("node_modules")).map((srcOrCwd) => join(relative(nuxt.options.buildDir, srcOrCwd), "**/*")),
3038
- ...nuxt.options.typescript.includeWorkspace && nuxt.options.workspaceDir !== nuxt.options.rootDir ? [join(relative(nuxt.options.buildDir, nuxt.options.workspaceDir), "**/*")] : [],
3039
- ...modulePaths.map((m) => join(relativeWithDot(nuxt.options.buildDir, m), "runtime"))
3040
- ],
3041
- exclude: [
3042
- ...nuxt.options.modulesDir.map((m) => relativeWithDot(nuxt.options.buildDir, m)),
3043
- ...modulePaths.map((m) => join(relativeWithDot(nuxt.options.buildDir, m), "runtime/server")),
3044
- // nitro generate output: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/core/nitro.ts#L186
3045
- relativeWithDot(nuxt.options.buildDir, resolve(nuxt.options.rootDir, "dist"))
3046
- ]
3082
+ include: [...include],
3083
+ exclude: [...exclude]
3047
3084
  });
3048
3085
  const aliases = {
3049
3086
  ...nuxt.options.alias,
@@ -3084,10 +3121,14 @@ async function _generateTypes(nuxt) {
3084
3121
  }
3085
3122
  }
3086
3123
  }
3087
- const references = await Promise.all([
3088
- ...nuxt.options.modules,
3089
- ...nuxt.options._modules
3090
- ].filter((f) => typeof f === "string").map(async (id) => ({ types: (await readPackageJSON(id, { url: nodeModulePaths }).catch(() => null))?.name || id })));
3124
+ const references = [];
3125
+ await Promise.all([...nuxt.options.modules, ...nuxt.options._modules].map(async (id) => {
3126
+ if (typeof id !== "string") {
3127
+ return;
3128
+ }
3129
+ const pkg = await readPackageJSON(id, { url: getNodeModulesPaths(nuxt.options.modulesDir) }).catch(() => null);
3130
+ references.push({ types: pkg?.name || id });
3131
+ }));
3091
3132
  const declarations = [];
3092
3133
  await nuxt.callHook("prepare:types", { references, declarations, tsConfig });
3093
3134
  for (const alias in tsConfig.compilerOptions.paths) {
@@ -3136,7 +3177,11 @@ async function writeTypes(nuxt) {
3136
3177
  await writeFile();
3137
3178
  }
3138
3179
  function renderAttrs(obj) {
3139
- return Object.entries(obj).map((e) => renderAttr(e[0], e[1])).join(" ");
3180
+ const attrs = [];
3181
+ for (const key in obj) {
3182
+ attrs.push(renderAttr(key, obj[key]));
3183
+ }
3184
+ return attrs.join(" ");
3140
3185
  }
3141
3186
  function renderAttr(key, value) {
3142
3187
  return value ? `${key}="${value}"` : "";
@@ -3200,13 +3245,14 @@ function addRouteMiddleware(input, options = {}) {
3200
3245
  for (const middleware of middlewares) {
3201
3246
  const find = app.middleware.findIndex((item) => item.name === middleware.name);
3202
3247
  if (find >= 0) {
3203
- if (app.middleware[find].path === middleware.path) {
3248
+ const foundPath = app.middleware[find].path;
3249
+ if (foundPath === middleware.path) {
3204
3250
  continue;
3205
3251
  }
3206
3252
  if (options.override === true) {
3207
3253
  app.middleware[find] = { ...middleware };
3208
3254
  } else {
3209
- logger.warn(`'${middleware.name}' middleware already exists at '${app.middleware[find].path}'. You can set \`override: true\` to replace it.`);
3255
+ logger.warn(`'${middleware.name}' middleware already exists at '${foundPath}'. You can set \`override: true\` to replace it.`);
3210
3256
  }
3211
3257
  } else {
3212
3258
  app.middleware.push({ ...middleware });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/kit",
3
- "version": "3.12.1",
3
+ "version": "3.12.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/nuxt.git",
@@ -23,7 +23,7 @@
23
23
  "dist"
24
24
  ],
25
25
  "dependencies": {
26
- "c12": "^1.10.0",
26
+ "c12": "^1.11.1",
27
27
  "consola": "^3.2.3",
28
28
  "defu": "^6.1.4",
29
29
  "destr": "^2.0.3",
@@ -42,7 +42,7 @@
42
42
  "unctx": "^2.3.1",
43
43
  "unimport": "^3.7.2",
44
44
  "untyped": "^1.4.2",
45
- "@nuxt/schema": "3.12.1"
45
+ "@nuxt/schema": "3.12.2"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@types/hash-sum": "1.0.2",
@@ -51,9 +51,9 @@
51
51
  "lodash-es": "4.17.21",
52
52
  "nitropack": "2.9.6",
53
53
  "unbuild": "latest",
54
- "vite": "5.2.13",
54
+ "vite": "5.3.1",
55
55
  "vitest": "1.6.0",
56
- "webpack": "5.91.0"
56
+ "webpack": "5.92.0"
57
57
  },
58
58
  "engines": {
59
59
  "node": "^14.18.0 || >=16.10.0"