@nuxt/kit 3.6.5 → 3.7.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.
@@ -0,0 +1,391 @@
1
+ import { ModuleOptions, ModuleDefinition, NuxtModule, Nuxt, ModuleMeta, NuxtConfig, NuxtOptions, SchemaDefinition, ImportPresetWithDeprecation, NuxtCompatibility, NuxtCompatibilityIssues, ComponentsDir, Component, NuxtTemplate, NuxtHooks, NuxtMiddleware, NuxtPlugin, NuxtPluginTemplate, ResolvedNuxtTemplate } from '@nuxt/schema';
2
+ import { LoadConfigOptions } from 'c12';
3
+ import { Import } from 'unimport';
4
+ import { Configuration, WebpackPluginInstance } from 'webpack';
5
+ import { UserConfig, Plugin } from 'vite';
6
+ import * as unctx_index from 'unctx/index';
7
+ import { NitroRouteConfig, NitroEventHandler, NitroDevEventHandler, Nitro } from 'nitropack';
8
+ import * as consola_dist_core from 'consola/dist/core';
9
+ import { genSafeVariableName } from 'knitwork';
10
+
11
+ /**
12
+ * Define a Nuxt module, automatically merging defaults with user provided options, installing
13
+ * any hooks that are provided, and calling an optional setup function for full control.
14
+ */
15
+ declare function defineNuxtModule<OptionsT extends ModuleOptions>(definition: ModuleDefinition<OptionsT> | NuxtModule<OptionsT>): NuxtModule<OptionsT>;
16
+
17
+ /** Installs a module on a Nuxt instance. */
18
+ declare function installModule(moduleToInstall: string | NuxtModule, inlineOptions?: any, nuxt?: Nuxt): Promise<void>;
19
+ declare const normalizeModuleTranspilePath: (p: string) => string;
20
+ declare function loadNuxtModuleInstance(nuxtModule: string | NuxtModule, nuxt?: Nuxt): Promise<{
21
+ nuxtModule: NuxtModule<any>;
22
+ buildTimeModuleMeta: ModuleMeta;
23
+ }>;
24
+
25
+ /**
26
+ * Check if a Nuxt module is installed by name.
27
+ *
28
+ * This will check both the installed modules and the modules to be installed. Note
29
+ * that it cannot detect if a module is _going to be_ installed programmatically by another module.
30
+ */
31
+ declare function hasNuxtModule(moduleName: string, nuxt?: Nuxt): boolean;
32
+ /**
33
+ * Checks if a Nuxt Module is compatible with a given semver version.
34
+ */
35
+ declare function hasNuxtModuleCompatibility(module: string | NuxtModule, semverVersion: string, nuxt?: Nuxt): Promise<boolean>;
36
+ /**
37
+ * Get the version of a Nuxt module.
38
+ *
39
+ * 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.
40
+ */
41
+ declare function getNuxtModuleVersion(module: string | NuxtModule, nuxt?: Nuxt | any): Promise<string | false>;
42
+
43
+ interface LoadNuxtConfigOptions extends LoadConfigOptions<NuxtConfig> {
44
+ }
45
+ declare function loadNuxtConfig(opts: LoadNuxtConfigOptions): Promise<NuxtOptions>;
46
+
47
+ declare function extendNuxtSchema(def: SchemaDefinition | (() => SchemaDefinition)): void;
48
+
49
+ interface LoadNuxtOptions extends LoadNuxtConfigOptions {
50
+ /** Load nuxt with development mode */
51
+ dev?: boolean;
52
+ /** Use lazy initialization of nuxt if set to false */
53
+ ready?: boolean;
54
+ /** @deprecated Use cwd option */
55
+ rootDir?: LoadNuxtConfigOptions['cwd'];
56
+ /** @deprecated use overrides option */
57
+ config?: LoadNuxtConfigOptions['overrides'];
58
+ }
59
+ declare function loadNuxt(opts: LoadNuxtOptions): Promise<Nuxt>;
60
+ declare function buildNuxt(nuxt: Nuxt): Promise<any>;
61
+
62
+ declare function addImports(imports: Import | Import[]): void;
63
+ declare function addImportsDir(dirs: string | string[], opts?: {
64
+ prepend?: boolean;
65
+ }): void;
66
+ declare function addImportsSources(presets: ImportPresetWithDeprecation | ImportPresetWithDeprecation[]): void;
67
+
68
+ interface ExtendConfigOptions {
69
+ /**
70
+ * Install plugin on dev
71
+ *
72
+ * @default true
73
+ */
74
+ dev?: boolean;
75
+ /**
76
+ * Install plugin on build
77
+ *
78
+ * @default true
79
+ */
80
+ build?: boolean;
81
+ /**
82
+ * Install plugin on server side
83
+ *
84
+ * @default true
85
+ */
86
+ server?: boolean;
87
+ /**
88
+ * Install plugin on client side
89
+ *
90
+ * @default true
91
+ */
92
+ client?: boolean;
93
+ /**
94
+ * Prepends the plugin to the array with `unshit()` instead of `push()`.
95
+ */
96
+ prepend?: boolean;
97
+ }
98
+ interface ExtendWebpackConfigOptions extends ExtendConfigOptions {
99
+ }
100
+ interface ExtendViteConfigOptions extends ExtendConfigOptions {
101
+ }
102
+ /**
103
+ * Extend webpack config
104
+ *
105
+ * The fallback function might be called multiple times
106
+ * when applying to both client and server builds.
107
+ */
108
+ declare function extendWebpackConfig(fn: ((config: Configuration) => void), options?: ExtendWebpackConfigOptions): void;
109
+ /**
110
+ * Extend Vite config
111
+ */
112
+ declare function extendViteConfig(fn: ((config: UserConfig) => void), options?: ExtendViteConfigOptions): (() => void) | undefined;
113
+ /**
114
+ * Append webpack plugin to the config.
115
+ */
116
+ declare function addWebpackPlugin(pluginOrGetter: WebpackPluginInstance | WebpackPluginInstance[] | (() => WebpackPluginInstance | WebpackPluginInstance[]), options?: ExtendWebpackConfigOptions): void;
117
+ /**
118
+ * Append Vite plugin to the config.
119
+ */
120
+ declare function addVitePlugin(pluginOrGetter: Plugin | Plugin[] | (() => Plugin | Plugin[]), options?: ExtendViteConfigOptions): void;
121
+ interface AddBuildPluginFactory {
122
+ vite?: () => Plugin | Plugin[];
123
+ webpack?: () => WebpackPluginInstance | WebpackPluginInstance[];
124
+ }
125
+ declare function addBuildPlugin(pluginFactory: AddBuildPluginFactory, options?: ExtendConfigOptions): void;
126
+
127
+ declare function normalizeSemanticVersion(version: string): string;
128
+ /**
129
+ * Check version constraints and return incompatibility issues as an array
130
+ */
131
+ declare function checkNuxtCompatibility(constraints: NuxtCompatibility, nuxt?: Nuxt): Promise<NuxtCompatibilityIssues>;
132
+ /**
133
+ * Check version constraints and throw a detailed error if has any, otherwise returns true
134
+ */
135
+ declare function assertNuxtCompatibility(constraints: NuxtCompatibility, nuxt?: Nuxt): Promise<true>;
136
+ /**
137
+ * Check version constraints and return true if passed, otherwise returns false
138
+ */
139
+ declare function hasNuxtCompatibility(constraints: NuxtCompatibility, nuxt?: Nuxt): Promise<boolean>;
140
+ /**
141
+ * Check if current nuxt instance is version 2 legacy
142
+ */
143
+ declare function isNuxt2(nuxt?: Nuxt): any;
144
+ /**
145
+ * Check if current nuxt instance is version 3
146
+ */
147
+ declare function isNuxt3(nuxt?: Nuxt): any;
148
+ /**
149
+ * Get nuxt version
150
+ */
151
+ declare function getNuxtVersion(nuxt?: Nuxt | any): any;
152
+
153
+ /**
154
+ * Register a directory to be scanned for components and imported only when used.
155
+ *
156
+ * Requires Nuxt 2.13+
157
+ */
158
+ declare function addComponentsDir(dir: ComponentsDir): Promise<void>;
159
+ type AddComponentOptions = {
160
+ name: string;
161
+ filePath: string;
162
+ } & Partial<Exclude<Component, 'shortPath' | 'async' | 'level' | 'import' | 'asyncImport'>>;
163
+ /**
164
+ * Register a component by its name and filePath.
165
+ *
166
+ * Requires Nuxt 2.13+
167
+ */
168
+ declare function addComponent(opts: AddComponentOptions): Promise<void>;
169
+
170
+ /** Direct access to the Nuxt context - see https://github.com/unjs/unctx. */
171
+ declare const nuxtCtx: unctx_index.UseContext<Nuxt>;
172
+ /**
173
+ * Get access to Nuxt instance.
174
+ *
175
+ * Throws an error if Nuxt instance is unavailable.
176
+ *
177
+ * @example
178
+ * ```js
179
+ * const nuxt = useNuxt()
180
+ * ```
181
+ */
182
+ declare function useNuxt(): Nuxt;
183
+ /**
184
+ * Get access to Nuxt instance.
185
+ *
186
+ * Returns null if Nuxt instance is unavailable.
187
+ *
188
+ * @example
189
+ * ```js
190
+ * const nuxt = tryUseNuxt()
191
+ * if (nuxt) {
192
+ * // Do something
193
+ * }
194
+ * ```
195
+ */
196
+ declare function tryUseNuxt(): Nuxt | null;
197
+
198
+ /**
199
+ * Return a filter function to filter an array of paths
200
+ */
201
+ declare function isIgnored(pathname: string): boolean;
202
+ declare function resolveIgnorePatterns(relativePath?: string): string[];
203
+
204
+ declare function addLayout(this: any, template: NuxtTemplate, name?: string): void;
205
+
206
+ declare function extendPages(cb: NuxtHooks['pages:extend']): void;
207
+ interface ExtendRouteRulesOptions {
208
+ /**
209
+ * Override route rule config
210
+ *
211
+ * @default false
212
+ */
213
+ override?: boolean;
214
+ }
215
+ declare function extendRouteRules(route: string, rule: NitroRouteConfig, options?: ExtendRouteRulesOptions): void;
216
+ interface AddRouteMiddlewareOptions {
217
+ /**
218
+ * Override existing middleware with the same name, if it exists
219
+ *
220
+ * @default false
221
+ */
222
+ override?: boolean;
223
+ }
224
+ declare function addRouteMiddleware(input: NuxtMiddleware | NuxtMiddleware[], options?: AddRouteMiddlewareOptions): void;
225
+
226
+ /**
227
+ * Normalize a nuxt plugin object
228
+ */
229
+ declare function normalizePlugin(plugin: NuxtPlugin | string): NuxtPlugin;
230
+ /**
231
+ * Registers a nuxt plugin and to the plugins array.
232
+ *
233
+ * Note: You can use mode or .client and .server modifiers with fileName option
234
+ * to use plugin only in client or server side.
235
+ *
236
+ * Note: By default plugin is prepended to the plugins array. You can use second argument to append (push) instead.
237
+ *
238
+ * @example
239
+ * ```js
240
+ * addPlugin({
241
+ * src: path.resolve(__dirname, 'templates/foo.js'),
242
+ * filename: 'foo.server.js' // [optional] only include in server bundle
243
+ * })
244
+ * ```
245
+ */
246
+ interface AddPluginOptions {
247
+ append?: boolean;
248
+ }
249
+ declare function addPlugin(_plugin: NuxtPlugin | string, opts?: AddPluginOptions): NuxtPlugin;
250
+ /**
251
+ * Adds a template and registers as a nuxt plugin.
252
+ */
253
+ declare function addPluginTemplate(plugin: NuxtPluginTemplate | string, opts?: AddPluginOptions): NuxtPlugin;
254
+
255
+ interface ResolvePathOptions {
256
+ /** Base for resolving paths from. Default is Nuxt rootDir. */
257
+ cwd?: string;
258
+ /** An object of aliases. Default is Nuxt configured aliases. */
259
+ alias?: Record<string, string>;
260
+ /** The file extensions to try. Default is Nuxt configured extensions. */
261
+ extensions?: string[];
262
+ }
263
+ /**
264
+ * Resolve full path to a file or directory respecting Nuxt alias and extensions options
265
+ *
266
+ * If path could not be resolved, normalized input path will be returned
267
+ */
268
+ declare function resolvePath(path: string, opts?: ResolvePathOptions): Promise<string>;
269
+ /**
270
+ * Try to resolve first existing file in paths
271
+ */
272
+ declare function findPath(paths: string | string[], opts?: ResolvePathOptions, pathType?: 'file' | 'dir'): Promise<string | null>;
273
+ /**
274
+ * Resolve path aliases respecting Nuxt alias options
275
+ */
276
+ declare function resolveAlias(path: string, alias?: Record<string, string>): string;
277
+ interface Resolver {
278
+ resolve(...path: string[]): string;
279
+ resolvePath(path: string, opts?: ResolvePathOptions): Promise<string>;
280
+ }
281
+ /**
282
+ * Create a relative resolver
283
+ */
284
+ declare function createResolver(base: string | URL): Resolver;
285
+ declare function resolveFiles(path: string, pattern: string | string[], opts?: {
286
+ followSymbolicLinks?: boolean;
287
+ }): Promise<string[]>;
288
+
289
+ /**
290
+ * Adds a nitro server handler
291
+ *
292
+ */
293
+ declare function addServerHandler(handler: NitroEventHandler): void;
294
+ /**
295
+ * Adds a nitro server handler for development-only
296
+ *
297
+ */
298
+ declare function addDevServerHandler(handler: NitroDevEventHandler): void;
299
+ /**
300
+ * Adds a Nitro plugin
301
+ */
302
+ declare function addServerPlugin(plugin: string): void;
303
+ /**
304
+ * Adds routes to be prerendered
305
+ */
306
+ declare function addPrerenderRoutes(routes: string | string[]): void;
307
+ /**
308
+ * Access to the Nitro instance
309
+ *
310
+ * **Note:** You can call `useNitro()` only after `ready` hook.
311
+ *
312
+ * **Note:** Changes to the Nitro instance configuration are not applied.
313
+ *
314
+ * @example
315
+ *
316
+ * ```ts
317
+ * nuxt.hook('ready', () => {
318
+ * console.log(useNitro())
319
+ * })
320
+ * ```
321
+ */
322
+ declare function useNitro(): Nitro;
323
+
324
+ /**
325
+ * Renders given template using lodash template during build into the project buildDir
326
+ */
327
+ declare function addTemplate(_template: NuxtTemplate<any> | string): ResolvedNuxtTemplate<any>;
328
+ /**
329
+ * Renders given types using lodash template during build into the project buildDir
330
+ * and register them as types.
331
+ */
332
+ declare function addTypeTemplate(_template: NuxtTemplate<any>): ResolvedNuxtTemplate<any>;
333
+ /**
334
+ * Normalize a nuxt template object
335
+ */
336
+ declare function normalizeTemplate(template: NuxtTemplate<any> | string): ResolvedNuxtTemplate<any>;
337
+ /**
338
+ * Trigger rebuilding Nuxt templates
339
+ *
340
+ * You can pass a filter within the options to selectively regenerate a subset of templates.
341
+ */
342
+ declare function updateTemplates(options?: {
343
+ filter?: (template: ResolvedNuxtTemplate<any>) => boolean;
344
+ }): Promise<any>;
345
+ declare function writeTypes(nuxt: Nuxt): Promise<void>;
346
+
347
+ declare const logger: consola_dist_core.ConsolaInstance;
348
+ declare function useLogger(tag?: string): consola_dist_core.ConsolaInstance;
349
+
350
+ /** @deprecated Do not use CJS utils */
351
+ interface ResolveModuleOptions {
352
+ paths?: string | string[];
353
+ }
354
+ /** @deprecated Do not use CJS utils */
355
+ interface RequireModuleOptions extends ResolveModuleOptions {
356
+ /** Clear the require cache (force fresh require) but only if not within `node_modules` */
357
+ clearCache?: boolean;
358
+ /** Automatically de-default the result of requiring the module. */
359
+ interopDefault?: boolean;
360
+ }
361
+ /** @deprecated Do not use CJS utils */
362
+ declare function resolveModule(id: string, opts?: ResolveModuleOptions): string;
363
+ /** @deprecated Do not use CJS utils */
364
+ declare function requireModule(id: string, opts?: RequireModuleOptions): any;
365
+ /** @deprecated Do not use CJS utils */
366
+ declare function importModule(id: string, opts?: RequireModuleOptions): Promise<any>;
367
+ /** @deprecated Do not use CJS utils */
368
+ declare function tryImportModule(id: string, opts?: RequireModuleOptions): Promise<any> | undefined;
369
+ /** @deprecated Do not use CJS utils */
370
+ declare function tryRequireModule(id: string, opts?: RequireModuleOptions): any;
371
+
372
+ /**
373
+ * Resolve a module from a given root path using an algorithm patterned on
374
+ * the upcoming `import.meta.resolve`. It returns a file URL
375
+ *
376
+ * @internal
377
+ */
378
+ declare function tryResolveModule(id: string, url?: string | string[]): Promise<string | undefined>;
379
+
380
+ /** @deprecated */
381
+ declare function compileTemplate(template: NuxtTemplate, ctx: any): Promise<string>;
382
+ /** @deprecated */
383
+ declare const templateUtils: {
384
+ serialize: (data: any) => string;
385
+ importName: typeof genSafeVariableName;
386
+ importSources: (sources: string | string[], { lazy }?: {
387
+ lazy?: boolean | undefined;
388
+ }) => string;
389
+ };
390
+
391
+ 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, addServerPlugin, addTemplate, addTypeTemplate, addVitePlugin, addWebpackPlugin, assertNuxtCompatibility, buildNuxt, checkNuxtCompatibility, compileTemplate, createResolver, defineNuxtModule, extendNuxtSchema, extendPages, extendRouteRules, extendViteConfig, extendWebpackConfig, findPath, getNuxtModuleVersion, getNuxtVersion, hasNuxtCompatibility, hasNuxtModule, hasNuxtModuleCompatibility, importModule, installModule, isIgnored, isNuxt2, isNuxt3, loadNuxt, loadNuxtConfig, loadNuxtModuleInstance, logger, normalizeModuleTranspilePath, normalizePlugin, normalizeSemanticVersion, normalizeTemplate, nuxtCtx, requireModule, resolveAlias, resolveFiles, resolveIgnorePatterns, resolveModule, resolvePath, templateUtils, tryImportModule, tryRequireModule, tryResolveModule, tryUseNuxt, updateTemplates, useLogger, useNitro, useNuxt, writeTypes };
package/dist/index.d.ts CHANGED
@@ -199,6 +199,7 @@ declare function tryUseNuxt(): Nuxt | null;
199
199
  * Return a filter function to filter an array of paths
200
200
  */
201
201
  declare function isIgnored(pathname: string): boolean;
202
+ declare function resolveIgnorePatterns(relativePath?: string): string[];
202
203
 
203
204
  declare function addLayout(this: any, template: NuxtTemplate, name?: string): void;
204
205
 
@@ -341,6 +342,7 @@ declare function normalizeTemplate(template: NuxtTemplate<any> | string): Resolv
341
342
  declare function updateTemplates(options?: {
342
343
  filter?: (template: ResolvedNuxtTemplate<any>) => boolean;
343
344
  }): Promise<any>;
345
+ declare function writeTypes(nuxt: Nuxt): Promise<void>;
344
346
 
345
347
  declare const logger: consola_dist_core.ConsolaInstance;
346
348
  declare function useLogger(tag?: string): consola_dist_core.ConsolaInstance;
@@ -386,4 +388,4 @@ declare const templateUtils: {
386
388
  }) => string;
387
389
  };
388
390
 
389
- export { AddComponentOptions, AddPluginOptions, AddRouteMiddlewareOptions, ExtendConfigOptions, ExtendRouteRulesOptions, ExtendViteConfigOptions, ExtendWebpackConfigOptions, LoadNuxtConfigOptions, LoadNuxtOptions, RequireModuleOptions, ResolveModuleOptions, ResolvePathOptions, Resolver, addBuildPlugin, addComponent, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, addLayout, addPlugin, addPluginTemplate, addPrerenderRoutes, addRouteMiddleware, addServerHandler, addServerPlugin, addTemplate, addTypeTemplate, addVitePlugin, addWebpackPlugin, assertNuxtCompatibility, buildNuxt, checkNuxtCompatibility, compileTemplate, createResolver, defineNuxtModule, extendNuxtSchema, extendPages, extendRouteRules, extendViteConfig, extendWebpackConfig, findPath, getNuxtModuleVersion, getNuxtVersion, hasNuxtCompatibility, hasNuxtModule, hasNuxtModuleCompatibility, importModule, installModule, isIgnored, isNuxt2, isNuxt3, loadNuxt, loadNuxtConfig, loadNuxtModuleInstance, logger, normalizeModuleTranspilePath, normalizePlugin, normalizeSemanticVersion, normalizeTemplate, nuxtCtx, requireModule, resolveAlias, resolveFiles, resolveModule, resolvePath, templateUtils, tryImportModule, tryRequireModule, tryResolveModule, tryUseNuxt, updateTemplates, useLogger, useNitro, useNuxt };
391
+ 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, addServerPlugin, addTemplate, addTypeTemplate, addVitePlugin, addWebpackPlugin, assertNuxtCompatibility, buildNuxt, checkNuxtCompatibility, compileTemplate, createResolver, defineNuxtModule, extendNuxtSchema, extendPages, extendRouteRules, extendViteConfig, extendWebpackConfig, findPath, getNuxtModuleVersion, getNuxtVersion, hasNuxtCompatibility, hasNuxtModule, hasNuxtModuleCompatibility, importModule, installModule, isIgnored, isNuxt2, isNuxt3, loadNuxt, loadNuxtConfig, loadNuxtModuleInstance, logger, normalizeModuleTranspilePath, normalizePlugin, normalizeSemanticVersion, normalizeTemplate, nuxtCtx, requireModule, resolveAlias, resolveFiles, resolveIgnorePatterns, resolveModule, resolvePath, templateUtils, tryImportModule, tryRequireModule, tryResolveModule, tryUseNuxt, updateTemplates, useLogger, useNitro, useNuxt, writeTypes };
package/dist/index.mjs CHANGED
@@ -2,7 +2,7 @@ import { promises, existsSync, readFileSync, lstatSync } from 'node:fs';
2
2
  import { performance } from 'node:perf_hooks';
3
3
  import { defu } from 'defu';
4
4
  import { applyDefaults } from 'untyped';
5
- import { dirname, normalize, join, relative, isAbsolute, resolve, basename, parse } from 'pathe';
5
+ import { dirname, normalize, relative, join, resolve, 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';
@@ -18,6 +18,7 @@ import { NuxtConfigSchema } from '@nuxt/schema';
18
18
  import { resolvePackageJSON, readPackageJSON } from 'pkg-types';
19
19
  import { kebabCase, pascalCase } from 'scule';
20
20
  import hash from 'hash-sum';
21
+ import { withTrailingSlash } from 'ufo';
21
22
 
22
23
  const logger = consola;
23
24
  function useLogger(tag) {
@@ -2226,14 +2227,17 @@ function getRequireCacheItem(id) {
2226
2227
  } catch (e) {
2227
2228
  }
2228
2229
  }
2230
+ function getModulePaths(paths) {
2231
+ return [].concat(
2232
+ global.__NUXT_PREPATHS__,
2233
+ paths || [],
2234
+ process.cwd(),
2235
+ global.__NUXT_PATHS__
2236
+ ).filter(Boolean);
2237
+ }
2229
2238
  function resolveModule(id, opts = {}) {
2230
2239
  return normalize(_require.resolve(id, {
2231
- paths: [].concat(
2232
- global.__NUXT_PREPATHS__,
2233
- opts.paths || [],
2234
- process.cwd(),
2235
- global.__NUXT_PATHS__
2236
- ).filter(Boolean)
2240
+ paths: getModulePaths(opts.paths)
2237
2241
  }));
2238
2242
  }
2239
2243
  function requireModule(id, opts = {}) {
@@ -2288,12 +2292,7 @@ function isIgnored(pathname) {
2288
2292
  }
2289
2293
  if (!nuxt._ignore) {
2290
2294
  nuxt._ignore = ignore(nuxt.options.ignoreOptions);
2291
- const resolvedIgnore = nuxt.options.ignore.flatMap((s) => resolveGroupSyntax(s));
2292
- nuxt._ignore.add(resolvedIgnore);
2293
- const nuxtignoreFile = join(nuxt.options.rootDir, ".nuxtignore");
2294
- if (existsSync(nuxtignoreFile)) {
2295
- nuxt._ignore.add(readFileSync(nuxtignoreFile, "utf-8"));
2296
- }
2295
+ nuxt._ignore.add(resolveIgnorePatterns());
2297
2296
  }
2298
2297
  const cwds = nuxt.options._layers?.map((layer2) => layer2.cwd).sort((a, b) => b.length - a.length);
2299
2298
  const layer = cwds?.find((cwd) => pathname.startsWith(cwd));
@@ -2303,6 +2302,24 @@ function isIgnored(pathname) {
2303
2302
  }
2304
2303
  return !!(relativePath && nuxt._ignore.ignores(relativePath));
2305
2304
  }
2305
+ function resolveIgnorePatterns(relativePath) {
2306
+ const nuxt = tryUseNuxt();
2307
+ if (!nuxt) {
2308
+ return [];
2309
+ }
2310
+ if (!nuxt._ignorePatterns) {
2311
+ nuxt._ignorePatterns = nuxt.options.ignore.flatMap((s) => resolveGroupSyntax(s));
2312
+ const nuxtignoreFile = join(nuxt.options.rootDir, ".nuxtignore");
2313
+ if (existsSync(nuxtignoreFile)) {
2314
+ const contents = readFileSync(nuxtignoreFile, "utf-8");
2315
+ nuxt._ignorePatterns.push(...contents.trim().split(/\r?\n/));
2316
+ }
2317
+ }
2318
+ if (relativePath) {
2319
+ return nuxt._ignorePatterns.map((p) => p.startsWith("*") || p.startsWith("!*") ? p : relative(relativePath, resolve(nuxt.options.rootDir, p)));
2320
+ }
2321
+ return nuxt._ignorePatterns;
2322
+ }
2306
2323
  function resolveGroupSyntax(group) {
2307
2324
  let groups = [group];
2308
2325
  while (groups.some((group2) => group2.includes("{"))) {
@@ -2412,6 +2429,10 @@ async function installModule(moduleToInstall, inlineOptions, nuxt = useNuxt()) {
2412
2429
  }
2413
2430
  if (typeof moduleToInstall === "string") {
2414
2431
  nuxt.options.build.transpile.push(normalizeModuleTranspilePath(moduleToInstall));
2432
+ const directory = getDirectory(moduleToInstall);
2433
+ if (directory !== moduleToInstall) {
2434
+ nuxt.options.modulesDir.push(getDirectory(moduleToInstall));
2435
+ }
2415
2436
  }
2416
2437
  nuxt.options._installedModules = nuxt.options._installedModules || [];
2417
2438
  nuxt.options._installedModules.push({
@@ -2420,12 +2441,15 @@ async function installModule(moduleToInstall, inlineOptions, nuxt = useNuxt()) {
2420
2441
  entryPath: typeof moduleToInstall === "string" ? resolveAlias(moduleToInstall) : void 0
2421
2442
  });
2422
2443
  }
2423
- const normalizeModuleTranspilePath = (p) => {
2444
+ function getDirectory(p) {
2424
2445
  try {
2425
- p = isAbsolute(p) && lstatSync(p).isFile() ? dirname(p) : p;
2446
+ return isAbsolute(p) && lstatSync(p).isFile() ? dirname(p) : p;
2426
2447
  } catch (e) {
2427
2448
  }
2428
- return p.split("node_modules/").pop();
2449
+ return p;
2450
+ }
2451
+ const normalizeModuleTranspilePath = (p) => {
2452
+ return getDirectory(p).split("node_modules/").pop();
2429
2453
  };
2430
2454
  async function loadNuxtModuleInstance(nuxtModule, nuxt = useNuxt()) {
2431
2455
  let buildTimeModuleMeta = {};
@@ -2447,8 +2471,18 @@ async function loadNuxtModuleInstance(nuxtModule, nuxt = useNuxt()) {
2447
2471
  return { nuxtModule, buildTimeModuleMeta };
2448
2472
  }
2449
2473
 
2474
+ function resolveNuxtModuleEntryName(m) {
2475
+ if (typeof m === "object" && !Array.isArray(m)) {
2476
+ return m.name;
2477
+ }
2478
+ if (Array.isArray(m)) {
2479
+ return resolveNuxtModuleEntryName(m[0]);
2480
+ }
2481
+ return m || false;
2482
+ }
2450
2483
  function hasNuxtModule(moduleName, nuxt = useNuxt()) {
2451
- return nuxt.options._installedModules.some(({ meta }) => meta.name === moduleName) || nuxt.options.modules.includes(moduleName);
2484
+ return nuxt.options._installedModules.some(({ meta }) => meta.name === moduleName) || // check modules to be installed
2485
+ nuxt.options.modules.some((m) => moduleName === resolveNuxtModuleEntryName(m));
2452
2486
  }
2453
2487
  async function hasNuxtModuleCompatibility(module, semverVersion, nuxt = useNuxt()) {
2454
2488
  const version = await getNuxtModuleVersion(module, nuxt);
@@ -2471,7 +2505,7 @@ async function getNuxtModuleVersion(module, nuxt = useNuxt()) {
2471
2505
  if (version) {
2472
2506
  return version;
2473
2507
  }
2474
- if (nuxt.options.modules.includes(moduleMeta.name)) {
2508
+ if (hasNuxtModule(moduleMeta.name)) {
2475
2509
  const { buildTimeModuleMeta } = await loadNuxtModuleInstance(moduleMeta.name, nuxt);
2476
2510
  return buildTimeModuleMeta.version || false;
2477
2511
  }
@@ -2755,6 +2789,134 @@ function normalizeTemplate(template) {
2755
2789
  async function updateTemplates(options) {
2756
2790
  return await tryUseNuxt()?.hooks.callHook("builder:generateApp", options);
2757
2791
  }
2792
+ async function writeTypes(nuxt) {
2793
+ const modulePaths = getModulePaths(nuxt.options.modulesDir);
2794
+ const rootDirWithSlash = withTrailingSlash(nuxt.options.rootDir);
2795
+ const tsConfig = defu(nuxt.options.typescript?.tsConfig, {
2796
+ compilerOptions: {
2797
+ forceConsistentCasingInFileNames: true,
2798
+ jsx: "preserve",
2799
+ target: "ESNext",
2800
+ module: "ESNext",
2801
+ moduleResolution: nuxt.options.experimental?.typescriptBundlerResolution ? "Bundler" : "Node",
2802
+ skipLibCheck: true,
2803
+ isolatedModules: true,
2804
+ useDefineForClassFields: true,
2805
+ strict: nuxt.options.typescript?.strict ?? true,
2806
+ allowJs: true,
2807
+ noEmit: true,
2808
+ resolveJsonModule: true,
2809
+ allowSyntheticDefaultImports: true,
2810
+ paths: {}
2811
+ },
2812
+ include: [
2813
+ "./nuxt.d.ts",
2814
+ join(relativeWithDot(nuxt.options.buildDir, nuxt.options.rootDir), "**/*"),
2815
+ ...nuxt.options.srcDir !== nuxt.options.rootDir ? [join(relative(nuxt.options.buildDir, nuxt.options.srcDir), "**/*")] : [],
2816
+ ...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), "**/*")),
2817
+ ...nuxt.options.typescript.includeWorkspace && nuxt.options.workspaceDir !== nuxt.options.rootDir ? [join(relative(nuxt.options.buildDir, nuxt.options.workspaceDir), "**/*")] : []
2818
+ ],
2819
+ exclude: [
2820
+ ...nuxt.options.modulesDir.map((m) => relativeWithDot(nuxt.options.buildDir, m)),
2821
+ // nitro generate output: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/core/nitro.ts#L186
2822
+ relativeWithDot(nuxt.options.buildDir, resolve(nuxt.options.rootDir, "dist"))
2823
+ ]
2824
+ });
2825
+ const aliases = {
2826
+ ...nuxt.options.alias,
2827
+ "#build": nuxt.options.buildDir
2828
+ };
2829
+ const excludedAlias = [/^@vue\/.*$/];
2830
+ const basePath = tsConfig.compilerOptions.baseUrl ? resolve(nuxt.options.buildDir, tsConfig.compilerOptions.baseUrl) : nuxt.options.buildDir;
2831
+ tsConfig.compilerOptions = tsConfig.compilerOptions || {};
2832
+ tsConfig.include = tsConfig.include || [];
2833
+ for (const alias in aliases) {
2834
+ if (excludedAlias.some((re) => re.test(alias))) {
2835
+ continue;
2836
+ }
2837
+ let absolutePath = resolve(basePath, aliases[alias]);
2838
+ let stats = await promises.stat(absolutePath).catch(
2839
+ () => null
2840
+ /* file does not exist */
2841
+ );
2842
+ if (!stats) {
2843
+ const resolvedModule = await tryResolveModule(aliases[alias], nuxt.options.modulesDir);
2844
+ if (resolvedModule) {
2845
+ absolutePath = resolvedModule;
2846
+ stats = await promises.stat(resolvedModule).catch(() => null);
2847
+ }
2848
+ }
2849
+ const relativePath = relativeWithDot(nuxt.options.buildDir, absolutePath);
2850
+ if (stats?.isDirectory()) {
2851
+ tsConfig.compilerOptions.paths[alias] = [relativePath];
2852
+ tsConfig.compilerOptions.paths[`${alias}/*`] = [`${relativePath}/*`];
2853
+ if (!absolutePath.startsWith(rootDirWithSlash)) {
2854
+ tsConfig.include.push(relativePath);
2855
+ }
2856
+ } else {
2857
+ const path = stats?.isFile() ? relativePath.replace(/(?<=\w)\.\w+$/g, "") : aliases[alias];
2858
+ tsConfig.compilerOptions.paths[alias] = [path];
2859
+ if (!absolutePath.startsWith(rootDirWithSlash)) {
2860
+ tsConfig.include.push(path);
2861
+ }
2862
+ }
2863
+ }
2864
+ const references = await Promise.all([
2865
+ ...nuxt.options.modules,
2866
+ ...nuxt.options._modules
2867
+ ].filter((f) => typeof f === "string").map(async (id) => ({ types: (await readPackageJSON(id, { url: modulePaths }).catch(() => null))?.name || id })));
2868
+ if (nuxt.options.experimental?.reactivityTransform) {
2869
+ references.push({ types: "vue/macros-global" });
2870
+ }
2871
+ const declarations = [];
2872
+ await nuxt.callHook("prepare:types", { references, declarations, tsConfig });
2873
+ for (const alias in tsConfig.compilerOptions.paths) {
2874
+ const paths = tsConfig.compilerOptions.paths[alias];
2875
+ tsConfig.compilerOptions.paths[alias] = await Promise.all(paths.map(async (path) => {
2876
+ if (!isAbsolute(path)) {
2877
+ return path;
2878
+ }
2879
+ const stats = await promises.stat(path).catch(
2880
+ () => null
2881
+ /* file does not exist */
2882
+ );
2883
+ return relativeWithDot(nuxt.options.buildDir, stats?.isFile() ? path.replace(/(?<=\w)\.\w+$/g, "") : path);
2884
+ }));
2885
+ }
2886
+ tsConfig.include = [...new Set(tsConfig.include.map((p) => isAbsolute(p) ? relativeWithDot(nuxt.options.buildDir, p) : p))];
2887
+ tsConfig.exclude = [...new Set(tsConfig.exclude.map((p) => isAbsolute(p) ? relativeWithDot(nuxt.options.buildDir, p) : p))];
2888
+ const declaration = [
2889
+ ...references.map((ref) => {
2890
+ if ("path" in ref && isAbsolute(ref.path)) {
2891
+ ref.path = relative(nuxt.options.buildDir, ref.path);
2892
+ }
2893
+ return `/// <reference ${renderAttrs(ref)} />`;
2894
+ }),
2895
+ ...declarations,
2896
+ "",
2897
+ "export {}",
2898
+ ""
2899
+ ].join("\n");
2900
+ async function writeFile() {
2901
+ const GeneratedBy = "// Generated by nuxi";
2902
+ const tsConfigPath = resolve(nuxt.options.buildDir, "tsconfig.json");
2903
+ await promises.mkdir(nuxt.options.buildDir, { recursive: true });
2904
+ await promises.writeFile(tsConfigPath, GeneratedBy + "\n" + JSON.stringify(tsConfig, null, 2));
2905
+ const declarationPath = resolve(nuxt.options.buildDir, "nuxt.d.ts");
2906
+ await promises.writeFile(declarationPath, GeneratedBy + "\n" + declaration);
2907
+ }
2908
+ nuxt.hook("builder:prepared", writeFile);
2909
+ await writeFile();
2910
+ }
2911
+ function renderAttrs(obj) {
2912
+ return Object.entries(obj).map((e) => renderAttr(e[0], e[1])).join(" ");
2913
+ }
2914
+ function renderAttr(key, value) {
2915
+ return value ? `${key}="${value}"` : "";
2916
+ }
2917
+ function relativeWithDot(from, to) {
2918
+ return relative(from, to).replace(/^([^.])/, "./$1") || ".";
2919
+ }
2758
2920
 
2759
2921
  function addLayout(template, name) {
2760
2922
  const nuxt = useNuxt();
@@ -2900,4 +3062,4 @@ function useNitro() {
2900
3062
  return nuxt._nitro;
2901
3063
  }
2902
3064
 
2903
- export { addBuildPlugin, addComponent, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, addLayout, addPlugin, addPluginTemplate, addPrerenderRoutes, addRouteMiddleware, addServerHandler, addServerPlugin, addTemplate, addTypeTemplate, addVitePlugin, addWebpackPlugin, assertNuxtCompatibility, buildNuxt, checkNuxtCompatibility, compileTemplate, createResolver, defineNuxtModule, extendNuxtSchema, extendPages, extendRouteRules, extendViteConfig, extendWebpackConfig, findPath, getNuxtModuleVersion, getNuxtVersion, hasNuxtCompatibility, hasNuxtModule, hasNuxtModuleCompatibility, importModule$1 as importModule, installModule, isIgnored, isNuxt2, isNuxt3, loadNuxt, loadNuxtConfig, loadNuxtModuleInstance, logger, normalizeModuleTranspilePath, normalizePlugin, normalizeSemanticVersion, normalizeTemplate, nuxtCtx, requireModule, resolveAlias, resolveFiles, resolveModule, resolvePath, templateUtils, tryImportModule$1 as tryImportModule, tryRequireModule, tryResolveModule, tryUseNuxt, updateTemplates, useLogger, useNitro, useNuxt };
3065
+ export { addBuildPlugin, addComponent, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, addLayout, addPlugin, addPluginTemplate, addPrerenderRoutes, addRouteMiddleware, addServerHandler, addServerPlugin, addTemplate, addTypeTemplate, addVitePlugin, addWebpackPlugin, assertNuxtCompatibility, buildNuxt, checkNuxtCompatibility, compileTemplate, createResolver, defineNuxtModule, extendNuxtSchema, extendPages, extendRouteRules, extendViteConfig, extendWebpackConfig, findPath, getNuxtModuleVersion, getNuxtVersion, hasNuxtCompatibility, hasNuxtModule, hasNuxtModuleCompatibility, importModule$1 as importModule, installModule, isIgnored, isNuxt2, isNuxt3, loadNuxt, loadNuxtConfig, loadNuxtModuleInstance, logger, normalizeModuleTranspilePath, normalizePlugin, normalizeSemanticVersion, normalizeTemplate, nuxtCtx, requireModule, resolveAlias, resolveFiles, resolveIgnorePatterns, resolveModule, resolvePath, templateUtils, tryImportModule$1 as tryImportModule, tryRequireModule, tryResolveModule, tryUseNuxt, updateTemplates, useLogger, useNitro, useNuxt, writeTypes };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/kit",
3
- "version": "3.6.5",
3
+ "version": "3.7.0",
4
4
  "repository": "nuxt/nuxt",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -23,28 +23,29 @@
23
23
  "globby": "^13.2.2",
24
24
  "hash-sum": "^2.0.0",
25
25
  "ignore": "^5.2.4",
26
- "jiti": "^1.19.1",
26
+ "jiti": "^1.19.3",
27
27
  "knitwork": "^1.0.0",
28
- "mlly": "^1.4.0",
28
+ "mlly": "^1.4.1",
29
29
  "pathe": "^1.1.1",
30
30
  "pkg-types": "^1.0.3",
31
31
  "scule": "^1.0.0",
32
- "semver": "^7.5.3",
32
+ "semver": "^7.5.4",
33
+ "ufo": "^1.3.0",
33
34
  "unctx": "^2.3.1",
34
- "unimport": "^3.0.14",
35
- "untyped": "^1.3.2",
36
- "@nuxt/schema": "3.6.5"
35
+ "unimport": "^3.2.0",
36
+ "untyped": "^1.4.0",
37
+ "@nuxt/schema": "3.7.0"
37
38
  },
38
39
  "devDependencies": {
39
40
  "@types/hash-sum": "1.0.0",
40
- "@types/lodash-es": "4.17.7",
41
+ "@types/lodash-es": "4.17.8",
41
42
  "@types/semver": "7.5.0",
42
43
  "lodash-es": "4.17.21",
43
- "nitropack": "2.5.2",
44
+ "nitropack": "2.6.1",
44
45
  "unbuild": "latest",
45
- "vite": "4.3.9",
46
+ "vite": "4.4.9",
46
47
  "vitest": "0.33.0",
47
- "webpack": "5.88.1"
48
+ "webpack": "5.88.2"
48
49
  },
49
50
  "engines": {
50
51
  "node": "^14.18.0 || >=16.10.0"