@nuxt/kit-nightly 4.3.2-29531071.e4e4ae81 → 4.3.2-29531289.6a3bd23e

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
@@ -1,6 +1,5 @@
1
1
  import { ConsolaInstance, ConsolaOptions } from "consola";
2
2
  import { UseContext } from "unctx";
3
- import "pkg-types";
4
3
  import { GlobOptions } from "tinyglobby";
5
4
  import { LoadConfigOptions } from "c12";
6
5
  import { Component, ComponentsDir, ModuleDefinition, ModuleMeta, ModuleOptions, Nuxt, NuxtAppConfig, NuxtCompatibility, NuxtCompatibilityIssues, NuxtConfig, NuxtHooks, NuxtMiddleware, NuxtModule, NuxtOptions, NuxtPlugin, NuxtPluginTemplate, NuxtServerTemplate, NuxtTemplate, NuxtTypeTemplate, ResolvedNuxtTemplate, SchemaDefinition } from "@nuxt/schema";
package/dist/index.mjs CHANGED
@@ -30,17 +30,44 @@ const logger = consola;
30
30
  function useLogger(tag, options = {}) {
31
31
  return tag ? logger.create(options).withTag(tag) : logger;
32
32
  }
33
+ /**
34
+ * Direct access to the Nuxt global context - see https://github.com/unjs/unctx.
35
+ * @deprecated Use `getNuxtCtx` instead
36
+ */
33
37
  const nuxtCtx = getContext("nuxt");
38
+ /** async local storage for the name of the current nuxt instance */
34
39
  const asyncNuxtStorage = createContext({
35
40
  asyncContext: true,
36
41
  AsyncLocalStorage
37
42
  });
43
+ /** Direct access to the Nuxt context with asyncLocalStorage - see https://github.com/unjs/unctx. */
38
44
  const getNuxtCtx = () => asyncNuxtStorage.tryUse();
45
+ /**
46
+ * Get access to Nuxt instance.
47
+ *
48
+ * Throws an error if Nuxt instance is unavailable.
49
+ * @example
50
+ * ```js
51
+ * const nuxt = useNuxt()
52
+ * ```
53
+ */
39
54
  function useNuxt() {
40
55
  const instance = asyncNuxtStorage.tryUse() || nuxtCtx.tryUse();
41
56
  if (!instance) throw new Error("Nuxt instance is unavailable!");
42
57
  return instance;
43
58
  }
59
+ /**
60
+ * Get access to Nuxt instance.
61
+ *
62
+ * Returns null if Nuxt instance is unavailable.
63
+ * @example
64
+ * ```js
65
+ * const nuxt = tryUseNuxt()
66
+ * if (nuxt) {
67
+ * // Do something
68
+ * }
69
+ * ```
70
+ */
44
71
  function tryUseNuxt() {
45
72
  return asyncNuxtStorage.tryUse() || nuxtCtx.tryUse();
46
73
  }
@@ -59,6 +86,9 @@ const builderMap = {
59
86
  function checkNuxtVersion(version, nuxt = useNuxt()) {
60
87
  return satisfies(normalizeSemanticVersion(getNuxtVersion(nuxt)), version, { includePrerelease: true });
61
88
  }
89
+ /**
90
+ * Check version constraints and return incompatibility issues as an array
91
+ */
62
92
  async function checkNuxtCompatibility(constraints, nuxt = useNuxt()) {
63
93
  const issues = [];
64
94
  if (constraints.nuxt) {
@@ -96,25 +126,43 @@ async function checkNuxtCompatibility(constraints, nuxt = useNuxt()) {
96
126
  issues.toString = () => issues.map((issue) => ` - [${issue.name}] ${issue.message}`).join("\n");
97
127
  return issues;
98
128
  }
129
+ /**
130
+ * Check version constraints and throw a detailed error if has any, otherwise returns true
131
+ */
99
132
  async function assertNuxtCompatibility(constraints, nuxt = useNuxt()) {
100
133
  const issues = await checkNuxtCompatibility(constraints, nuxt);
101
134
  if (issues.length) throw new Error("Nuxt compatibility issues found:\n" + issues.toString());
102
135
  return true;
103
136
  }
137
+ /**
138
+ * Check version constraints and return true if passed, otherwise returns false
139
+ */
104
140
  async function hasNuxtCompatibility(constraints, nuxt = useNuxt()) {
105
141
  return !(await checkNuxtCompatibility(constraints, nuxt)).length;
106
142
  }
143
+ /**
144
+ * Check if current Nuxt instance is of specified major version
145
+ */
107
146
  function isNuxtMajorVersion(majorVersion, nuxt = useNuxt()) {
108
147
  const version = getNuxtVersion(nuxt);
109
148
  return version[0] === majorVersion.toString() && version[1] === ".";
110
149
  }
150
+ /**
151
+ * @deprecated Use `isNuxtMajorVersion(2, nuxt)` instead. This may be removed in \@nuxt/kit v5 or a future major version.
152
+ */
111
153
  function isNuxt2(nuxt = useNuxt()) {
112
154
  return isNuxtMajorVersion(2, nuxt);
113
155
  }
156
+ /**
157
+ * @deprecated Use `isNuxtMajorVersion(3, nuxt)` instead. This may be removed in \@nuxt/kit v5 or a future major version.
158
+ */
114
159
  function isNuxt3(nuxt = useNuxt()) {
115
160
  return isNuxtMajorVersion(3, nuxt);
116
161
  }
117
162
  const NUXT_VERSION_RE = /^v/g;
163
+ /**
164
+ * Get nuxt version
165
+ */
118
166
  function getNuxtVersion(nuxt = useNuxt()) {
119
167
  const rawVersion = nuxt?._version || nuxt?.version || nuxt?.constructor?.version;
120
168
  if (typeof rawVersion !== "string") throw new TypeError("Cannot determine nuxt version! Is current instance passed?");
@@ -196,6 +244,17 @@ function warn(warning) {
196
244
  }
197
245
  }
198
246
  const layerMap = /* @__PURE__ */ new WeakMap();
247
+ /**
248
+ * Get the resolved directory paths for all layers in a Nuxt application.
249
+ *
250
+ * Returns an array of LayerDirectories objects, ordered by layer priority:
251
+ * - The first layer is the user/project layer (highest priority)
252
+ * - Earlier layers override later layers in the array
253
+ * - Base layers appear last in the array (lowest priority)
254
+ *
255
+ * @param nuxt - The Nuxt instance to get layers from. Defaults to the current Nuxt context.
256
+ * @returns Array of LayerDirectories objects, ordered by priority (user layer first)
257
+ */
199
258
  function getLayerDirectories(nuxt = useNuxt()) {
200
259
  return nuxt.options._layers.map((layer) => {
201
260
  if (layerMap.has(layer)) return layerMap.get(layer);
@@ -224,6 +283,9 @@ function withTrailingSlash$2(dir) {
224
283
  function createIsIgnored(nuxt = tryUseNuxt()) {
225
284
  return (pathname, stats) => isIgnored(pathname, stats, nuxt);
226
285
  }
286
+ /**
287
+ * Return a filter function to filter an array of paths
288
+ */
227
289
  function isIgnored(pathname, _stats, nuxt = tryUseNuxt()) {
228
290
  if (!nuxt) return false;
229
291
  if (!nuxt._ignore) {
@@ -251,6 +313,13 @@ function resolveIgnorePatterns(relativePath) {
251
313
  });
252
314
  return ignorePatterns;
253
315
  }
316
+ /**
317
+ * This function turns string containing groups '**\/*.{spec,test}.{js,ts}' into an array of strings.
318
+ * For example will '**\/*.{spec,test}.{js,ts}' be resolved to:
319
+ * ['**\/*.spec.js', '**\/*.spec.ts', '**\/*.test.js', '**\/*.test.ts']
320
+ * @param group string containing the group syntax
321
+ * @returns {string[]} array of strings without the group syntax
322
+ */
254
323
  function resolveGroupSyntax(group) {
255
324
  let groups = [group];
256
325
  while (groups.some((group) => group.includes("{"))) groups = groups.flatMap((group) => {
@@ -263,15 +332,28 @@ function resolveGroupSyntax(group) {
263
332
  });
264
333
  return groups;
265
334
  }
335
+ /** @since 3.9.0 */
266
336
  function toArray(value) {
267
337
  return Array.isArray(value) ? value : [value];
268
338
  }
339
+ /**
340
+ * Filter out items from an array in place. This function mutates the array.
341
+ * `predicate` get through the array from the end to the start for performance.
342
+ *
343
+ * This function should be faster than `Array.prototype.filter` on large arrays.
344
+ */
269
345
  function filterInPlace(array, predicate) {
270
346
  for (let i = array.length; i--;) if (!predicate(array[i], i, array)) array.splice(i, 1);
271
347
  return array;
272
348
  }
273
349
  const MODE_RE = /\.(server|client)(\.\w+)*$/;
274
350
  const distDirURL = new URL(".", import.meta.url);
351
+ /**
352
+ * Resolve the full path to a file or a directory (based on the provided type), respecting Nuxt alias and extensions options.
353
+ *
354
+ * If a path cannot be resolved, normalized input will be returned unless the `fallbackToOriginal` option is set to `true`,
355
+ * in which case the original input path will be returned.
356
+ */
275
357
  async function resolvePath(path, opts = {}) {
276
358
  const { type = "file" } = opts;
277
359
  const res = await _resolvePathGranularly(path, {
@@ -281,6 +363,9 @@ async function resolvePath(path, opts = {}) {
281
363
  if (res.type === type) return res.path;
282
364
  return opts.fallbackToOriginal ? path : res.path;
283
365
  }
366
+ /**
367
+ * Try to resolve first existing file in paths
368
+ */
284
369
  async function findPath(paths, opts, pathType = "file") {
285
370
  for (const path of toArray(paths)) {
286
371
  const res = await _resolvePathGranularly(path, {
@@ -292,10 +377,16 @@ async function findPath(paths, opts, pathType = "file") {
292
377
  }
293
378
  return null;
294
379
  }
380
+ /**
381
+ * Resolve path aliases respecting Nuxt alias options
382
+ */
295
383
  function resolveAlias(path, alias) {
296
384
  alias ||= tryUseNuxt()?.options.alias || {};
297
385
  return resolveAlias$1(path, alias);
298
386
  }
387
+ /**
388
+ * Create a relative resolver
389
+ */
299
390
  function createResolver(base) {
300
391
  if (!base) throw new Error("`base` argument is missing for createResolver(base)!");
301
392
  base = base.toString();
@@ -398,6 +489,15 @@ function existsInVFS(path, nuxt = tryUseNuxt()) {
398
489
  if (path in nuxt.vfs) return true;
399
490
  return (nuxt.apps.default?.templates ?? nuxt.options.build.templates).some((template) => template.dst === path);
400
491
  }
492
+ /**
493
+ * Resolve absolute file paths in the provided directory with respect to `.nuxtignore` and return them sorted.
494
+ * @param path path to the directory to resolve files in
495
+ * @param pattern glob pattern or an array of glob patterns to match files
496
+ * @param opts options for globbing
497
+ * @param opts.followSymbolicLinks whether to follow symbolic links, default is `true`
498
+ * @param opts.ignore additional glob patterns to ignore
499
+ * @returns sorted array of absolute file paths
500
+ */
401
501
  async function resolveFiles(path, pattern, opts = {}) {
402
502
  const files = [];
403
503
  for (const p of await glob(pattern, {
@@ -439,12 +539,18 @@ function tryImportModule(id, opts) {
439
539
  return importModule(id, opts).catch(() => void 0);
440
540
  } catch {}
441
541
  }
542
+ /**
543
+ * @deprecated Please use `importModule` instead.
544
+ */
442
545
  function requireModule(id, opts) {
443
546
  const caller = getUserCaller();
444
547
  warn(`[@nuxt/kit] \`requireModule\` is deprecated${caller ? ` (used at \`${resolveAlias(caller.source)}:${caller.line}:${caller.column}\`)` : ""}. Please use \`importModule\` instead.`);
445
548
  const resolvedPath = resolveModule(id, opts);
446
549
  return createJiti(import.meta.url, { interopDefault: opts?.interopDefault !== false })(pathToFileURL(resolvedPath).href);
447
550
  }
551
+ /**
552
+ * @deprecated Please use `tryImportModule` instead.
553
+ */
448
554
  function tryRequireModule(id, opts) {
449
555
  try {
450
556
  return requireModule(id, opts);
@@ -458,6 +564,10 @@ const ignoredConfigKeys = new Set([
458
564
  "devtools",
459
565
  "telemetry"
460
566
  ]);
567
+ /**
568
+ * Installs a set of modules on a Nuxt instance.
569
+ * @internal
570
+ */
461
571
  async function installModules(modulesToInstall, resolvedModulePaths, nuxt = useNuxt()) {
462
572
  const localLayerModuleDirs = [];
463
573
  for (const l of nuxt.options._layers) {
@@ -556,6 +666,10 @@ async function installModules(modulesToInstall, resolvedModulePaths, nuxt = useN
556
666
  }
557
667
  delete nuxt._moduleOptionsFunctions;
558
668
  }
669
+ /**
670
+ * Installs a module on a Nuxt instance.
671
+ * @deprecated Use module dependencies.
672
+ */
559
673
  async function installModule(moduleToInstall, inlineOptions, nuxt = useNuxt()) {
560
674
  const { nuxtModule, buildTimeModuleMeta, resolvedModulePath } = await loadNuxtModuleInstance(moduleToInstall, nuxt);
561
675
  const localLayerModuleDirs = [];
@@ -735,14 +849,28 @@ function resolveNuxtModuleEntryName(m) {
735
849
  if (Array.isArray(m)) return resolveNuxtModuleEntryName(m[0]);
736
850
  return m || false;
737
851
  }
852
+ /**
853
+ * Check if a Nuxt module is installed by name.
854
+ *
855
+ * This will check both the installed modules and the modules to be installed. Note
856
+ * that it cannot detect if a module is _going to be_ installed programmatically by another module.
857
+ */
738
858
  function hasNuxtModule(moduleName, nuxt = useNuxt()) {
739
859
  return nuxt.options._installedModules.some(({ meta }) => meta.name === moduleName) || nuxt.options.modules.some((m) => moduleName === resolveNuxtModuleEntryName(m));
740
860
  }
861
+ /**
862
+ * Checks if a Nuxt module is compatible with a given semver version.
863
+ */
741
864
  async function hasNuxtModuleCompatibility(module, semverVersion, nuxt = useNuxt()) {
742
865
  const version = await getNuxtModuleVersion(module, nuxt);
743
866
  if (!version) return false;
744
867
  return satisfies(normalizeSemanticVersion(version), semverVersion, { includePrerelease: true });
745
868
  }
869
+ /**
870
+ * Get the version of a Nuxt module.
871
+ *
872
+ * Scans installed modules for the version, if it's not found it will attempt to load the module instance and get the version from there.
873
+ */
746
874
  async function getNuxtModuleVersion(module, nuxt = useNuxt()) {
747
875
  const moduleMeta = (typeof module === "string" ? { name: module } : await module.getMeta?.()) || {};
748
876
  if (moduleMeta.version) return moduleMeta.version;
@@ -910,6 +1038,10 @@ function addImportsSources(presets) {
910
1038
  });
911
1039
  }
912
1040
  const HANDLER_METHOD_RE = /\.(get|head|patch|post|put|delete|connect|options|trace)(\.\w+)*$/;
1041
+ /**
1042
+ * normalize handler object
1043
+ *
1044
+ */
913
1045
  function normalizeHandlerMethod(handler) {
914
1046
  const [, method = void 0] = handler.handler.match(HANDLER_METHOD_RE) || [];
915
1047
  return {
@@ -918,17 +1050,31 @@ function normalizeHandlerMethod(handler) {
918
1050
  handler: normalize(handler.handler)
919
1051
  };
920
1052
  }
1053
+ /**
1054
+ * Adds a nitro server handler
1055
+ *
1056
+ */
921
1057
  function addServerHandler(handler) {
922
1058
  useNuxt().options.serverHandlers.push(normalizeHandlerMethod(handler));
923
1059
  }
1060
+ /**
1061
+ * Adds a nitro server handler for development-only
1062
+ *
1063
+ */
924
1064
  function addDevServerHandler(handler) {
925
1065
  useNuxt().options.devServerHandlers.push(handler);
926
1066
  }
1067
+ /**
1068
+ * Adds a Nitro plugin
1069
+ */
927
1070
  function addServerPlugin(plugin) {
928
1071
  const nuxt = useNuxt();
929
1072
  nuxt.options.nitro.plugins ||= [];
930
1073
  nuxt.options.nitro.plugins.push(normalize(plugin));
931
1074
  }
1075
+ /**
1076
+ * Adds routes to be prerendered
1077
+ */
932
1078
  function addPrerenderRoutes(routes) {
933
1079
  const nuxt = useNuxt();
934
1080
  routes = toArray(routes).filter(Boolean);
@@ -937,11 +1083,28 @@ function addPrerenderRoutes(routes) {
937
1083
  for (const route of routes) ctx.routes.add(route);
938
1084
  });
939
1085
  }
1086
+ /**
1087
+ * Access to the Nitro instance
1088
+ *
1089
+ * **Note:** You can call `useNitro()` only after `ready` hook.
1090
+ *
1091
+ * **Note:** Changes to the Nitro instance configuration are not applied.
1092
+ * @example
1093
+ *
1094
+ * ```ts
1095
+ * nuxt.hook('ready', () => {
1096
+ * console.log(useNitro())
1097
+ * })
1098
+ * ```
1099
+ */
940
1100
  function useNitro() {
941
1101
  const nuxt = useNuxt();
942
1102
  if (!nuxt._nitro) throw new Error("Nitro is not initialized yet. You can call `useNitro()` only after `ready` hook.");
943
1103
  return nuxt._nitro;
944
1104
  }
1105
+ /**
1106
+ * Add server imports to be auto-imported by Nitro
1107
+ */
945
1108
  function addServerImports(imports) {
946
1109
  const nuxt = useNuxt();
947
1110
  const _imports = toArray(imports);
@@ -951,6 +1114,9 @@ function addServerImports(imports) {
951
1114
  config.imports.imports.push(..._imports);
952
1115
  });
953
1116
  }
1117
+ /**
1118
+ * Add directories to be scanned for auto-imports by Nitro
1119
+ */
954
1120
  function addServerImportsDir(dirs, opts = {}) {
955
1121
  const nuxt = useNuxt();
956
1122
  const _dirs = toArray(dirs);
@@ -960,12 +1126,21 @@ function addServerImportsDir(dirs, opts = {}) {
960
1126
  config.imports.dirs[opts.prepend ? "unshift" : "push"](..._dirs);
961
1127
  });
962
1128
  }
1129
+ /**
1130
+ * Add directories to be scanned by Nitro. It will check for subdirectories,
1131
+ * which will be registered just like the `~~/server` folder is.
1132
+ */
963
1133
  function addServerScanDir(dirs, opts = {}) {
964
1134
  useNuxt().hook("nitro:config", (config) => {
965
1135
  config.scanDirs ||= [];
966
1136
  for (const dir of toArray(dirs)) config.scanDirs[opts.prepend ? "unshift" : "push"](dir);
967
1137
  });
968
1138
  }
1139
+ /**
1140
+ * Access 'resolved' Nuxt runtime configuration, with values updated from environment.
1141
+ *
1142
+ * This mirrors the runtime behavior of Nitro.
1143
+ */
969
1144
  function useRuntimeConfig() {
970
1145
  const nuxt = useNuxt();
971
1146
  return applyEnv(klona(nuxt.options.nitro.runtimeConfig), {
@@ -974,6 +1149,9 @@ function useRuntimeConfig() {
974
1149
  envExpansion: nuxt.options.nitro.experimental?.envExpansion ?? !!process.env.NITRO_ENV_EXPANSION
975
1150
  });
976
1151
  }
1152
+ /**
1153
+ * Update Nuxt runtime configuration.
1154
+ */
977
1155
  function updateRuntimeConfig(runtimeConfig) {
978
1156
  const nuxt = useNuxt();
979
1157
  Object.assign(nuxt.options.nitro.runtimeConfig, defu(runtimeConfig, nuxt.options.nitro.runtimeConfig));
@@ -1026,8 +1204,23 @@ const extendWebpackCompatibleConfig = (builder) => (fn, options = {}) => {
1026
1204
  }
1027
1205
  });
1028
1206
  };
1207
+ /**
1208
+ * Extend webpack config
1209
+ *
1210
+ * The fallback function might be called multiple times
1211
+ * when applying to both client and server builds.
1212
+ */
1029
1213
  const extendWebpackConfig = extendWebpackCompatibleConfig("webpack");
1214
+ /**
1215
+ * Extend rspack config
1216
+ *
1217
+ * The fallback function might be called multiple times
1218
+ * when applying to both client and server builds.
1219
+ */
1030
1220
  const extendRspackConfig = extendWebpackCompatibleConfig("rspack");
1221
+ /**
1222
+ * Extend Vite config
1223
+ */
1031
1224
  function extendViteConfig(fn, options = {}) {
1032
1225
  const nuxt = useNuxt();
1033
1226
  if (options.dev === false && nuxt.options.dev) return;
@@ -1038,6 +1231,9 @@ function extendViteConfig(fn, options = {}) {
1038
1231
  }
1039
1232
  return nuxt.hook("vite:extend", ({ config }) => fn(config));
1040
1233
  }
1234
+ /**
1235
+ * Append webpack plugin to the config.
1236
+ */
1041
1237
  function addWebpackPlugin(pluginOrGetter, options) {
1042
1238
  extendWebpackConfig(async (config) => {
1043
1239
  const method = options?.prepend ? "unshift" : "push";
@@ -1046,6 +1242,9 @@ function addWebpackPlugin(pluginOrGetter, options) {
1046
1242
  config.plugins[method](...toArray(plugin));
1047
1243
  }, options);
1048
1244
  }
1245
+ /**
1246
+ * Append rspack plugin to the config.
1247
+ */
1049
1248
  function addRspackPlugin(pluginOrGetter, options) {
1050
1249
  extendRspackConfig(async (config) => {
1051
1250
  const method = options?.prepend ? "unshift" : "push";
@@ -1054,6 +1253,9 @@ function addRspackPlugin(pluginOrGetter, options) {
1054
1253
  config.plugins[method](...toArray(plugin));
1055
1254
  }, options);
1056
1255
  }
1256
+ /**
1257
+ * Append Vite plugin to the config.
1258
+ */
1057
1259
  function addVitePlugin(pluginOrGetter, options = {}) {
1058
1260
  const nuxt = useNuxt();
1059
1261
  if (options.dev === false && nuxt.options.dev) return;
@@ -1094,6 +1296,9 @@ function addBuildPlugin(pluginFactory, options) {
1094
1296
  if (pluginFactory.webpack) addWebpackPlugin(pluginFactory.webpack, options);
1095
1297
  if (pluginFactory.rspack) addRspackPlugin(pluginFactory.rspack, options);
1096
1298
  }
1299
+ /**
1300
+ * Register a directory to be scanned for components and imported only when used.
1301
+ */
1097
1302
  function addComponentsDir(dir, opts = {}) {
1098
1303
  const nuxt = useNuxt();
1099
1304
  nuxt.options.components ||= [];
@@ -1102,6 +1307,9 @@ function addComponentsDir(dir, opts = {}) {
1102
1307
  dirs[opts.prepend ? "unshift" : "push"](dir);
1103
1308
  });
1104
1309
  }
1310
+ /**
1311
+ * This utility takes a file path or npm package that is scanned for named exports, which are get added automatically
1312
+ */
1105
1313
  function addComponentExports(opts) {
1106
1314
  const nuxt = useNuxt();
1107
1315
  const components = [];
@@ -1116,6 +1324,9 @@ function addComponentExports(opts) {
1116
1324
  });
1117
1325
  addComponents(components);
1118
1326
  }
1327
+ /**
1328
+ * Register a component by its name and filePath.
1329
+ */
1119
1330
  function addComponent(opts) {
1120
1331
  addComponents([normalizeComponent(opts)]);
1121
1332
  }
@@ -1159,6 +1370,9 @@ function normalizeComponent(opts) {
1159
1370
  ...opts
1160
1371
  };
1161
1372
  }
1373
+ /**
1374
+ * Renders given template during build into the virtual file system (and optionally to disk in the project `buildDir`)
1375
+ */
1162
1376
  function addTemplate(_template) {
1163
1377
  const nuxt = useNuxt();
1164
1378
  const template = normalizeTemplate(_template);
@@ -1174,12 +1388,23 @@ function addTemplate(_template) {
1174
1388
  nuxt.options.build.templates.push(template);
1175
1389
  return template;
1176
1390
  }
1391
+ /**
1392
+ * Adds a virtual file that can be used within the Nuxt Nitro server build.
1393
+ */
1177
1394
  function addServerTemplate(template) {
1178
1395
  const nuxt = useNuxt();
1179
1396
  nuxt.options.nitro.virtual ||= {};
1180
1397
  nuxt.options.nitro.virtual[template.filename] = template.getContents;
1181
1398
  return template;
1182
1399
  }
1400
+ /**
1401
+ * Renders given types during build to disk in the project `buildDir`
1402
+ * and register them as types.
1403
+ *
1404
+ * You can pass a second context object to specify in which context the type should be added.
1405
+ *
1406
+ * If no context object is passed, then it will only be added to the nuxt context.
1407
+ */
1183
1408
  function addTypeTemplate(_template, context) {
1184
1409
  const nuxt = useNuxt();
1185
1410
  const template = addTemplate(_template);
@@ -1203,6 +1428,9 @@ function addTypeTemplate(_template, context) {
1203
1428
  });
1204
1429
  return template;
1205
1430
  }
1431
+ /**
1432
+ * Normalize a nuxt template object
1433
+ */
1206
1434
  function normalizeTemplate(template, buildDir) {
1207
1435
  if (!template) throw new Error("Invalid template: " + JSON.stringify(template));
1208
1436
  if (typeof template === "string") template = { src: template };
@@ -1220,6 +1448,11 @@ function normalizeTemplate(template, buildDir) {
1220
1448
  template.dst ||= resolve(buildDir ?? useNuxt().options.buildDir, template.filename);
1221
1449
  return template;
1222
1450
  }
1451
+ /**
1452
+ * Trigger rebuilding Nuxt templates
1453
+ *
1454
+ * You can pass a filter within the options to selectively regenerate a subset of templates.
1455
+ */
1223
1456
  async function updateTemplates(options) {
1224
1457
  return await tryUseNuxt()?.hooks.callHook("builder:generateApp", options);
1225
1458
  }
@@ -1643,6 +1876,9 @@ function addRouteMiddleware(input, options = {}) {
1643
1876
  }
1644
1877
  });
1645
1878
  }
1879
+ /**
1880
+ * Normalize a nuxt plugin object
1881
+ */
1646
1882
  const pluginSymbol = Symbol.for("nuxt plugin");
1647
1883
  function normalizePlugin(plugin) {
1648
1884
  if (typeof plugin === "string") plugin = { src: plugin };
@@ -1676,6 +1912,9 @@ function addPlugin(_plugin, opts = {}) {
1676
1912
  nuxt.options.plugins[opts.append ? "push" : "unshift"](plugin);
1677
1913
  return plugin;
1678
1914
  }
1915
+ /**
1916
+ * Adds a template and registers as a nuxt plugin.
1917
+ */
1679
1918
  function addPluginTemplate(plugin, opts = {}) {
1680
1919
  return addPlugin(typeof plugin === "string" ? { src: plugin } : {
1681
1920
  ...plugin,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/kit-nightly",
3
- "version": "4.3.2-29531071.e4e4ae81",
3
+ "version": "4.3.2-29531289.6a3bd23e",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/nuxt.git",
@@ -41,13 +41,13 @@
41
41
  "untyped": "^2.0.0"
42
42
  },
43
43
  "devDependencies": {
44
- "@nuxt/schema": "npm:@nuxt/schema-nightly@4.3.2-29531071.e4e4ae81",
45
- "@rspack/core": "1.7.5",
44
+ "@nuxt/schema": "npm:@nuxt/schema-nightly@4.3.2-29531289.6a3bd23e",
45
+ "@rspack/core": "1.7.6",
46
46
  "@types/semver": "7.7.1",
47
47
  "hookable": "5.5.3",
48
48
  "nitro": "3.0.1-alpha.2",
49
49
  "nitropack": "2.13.1",
50
- "obuild": "0.4.27",
50
+ "obuild": "0.4.31",
51
51
  "unimport": "5.6.0",
52
52
  "vite": "7.3.1",
53
53
  "vitest": "4.0.18",