@nuxt/kit 3.2.3 → 3.3.1

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.ts CHANGED
@@ -126,7 +126,7 @@ type AddComponentOptions = {
126
126
  filePath: string;
127
127
  } & Partial<Exclude<Component, 'shortPath' | 'async' | 'level' | 'import' | 'asyncImport'>>;
128
128
  /**
129
- * Register a directory to be scanned for components and imported only when used.
129
+ * Register a component by its name and filePath.
130
130
  *
131
131
  * Requires Nuxt 2.13+
132
132
  */
@@ -317,20 +317,8 @@ interface RequireModuleOptions extends ResolveModuleOptions {
317
317
  interopDefault?: boolean;
318
318
  }
319
319
  /** @deprecated Do not use CJS utils */
320
- declare function isNodeModules(id: string): boolean;
321
- /** @deprecated Do not use CJS utils */
322
- declare function clearRequireCache(id: string): void;
323
- /** @deprecated Do not use CJS utils */
324
- declare function scanRequireTree(id: string, files?: Set<string>): Set<string>;
325
- /** @deprecated Do not use CJS utils */
326
- declare function getRequireCacheItem(id: string): NodeModule | undefined;
327
- /** Resolve the `package.json` file for a given module. */
328
- declare function requireModulePkg(id: string, opts?: RequireModuleOptions): any;
329
- /** @deprecated Do not use CJS utils */
330
320
  declare function resolveModule(id: string, opts?: ResolveModuleOptions): string;
331
321
  /** @deprecated Do not use CJS utils */
332
- declare function tryResolveModule(path: string, opts?: ResolveModuleOptions): string | null;
333
- /** @deprecated Do not use CJS utils */
334
322
  declare function requireModule(id: string, opts?: RequireModuleOptions): any;
335
323
  /** @deprecated Do not use CJS utils */
336
324
  declare function importModule(id: string, opts?: RequireModuleOptions): Promise<any>;
@@ -339,6 +327,14 @@ declare function tryImportModule(id: string, opts?: RequireModuleOptions): Promi
339
327
  /** @deprecated Do not use CJS utils */
340
328
  declare function tryRequireModule(id: string, opts?: RequireModuleOptions): any;
341
329
 
330
+ /**
331
+ * Resolve a module from a given root path using an algorithm patterned on
332
+ * the upcoming `import.meta.resolve`. It returns a file URL
333
+ *
334
+ * @internal
335
+ */
336
+ declare function tryResolveModule(id: string, url?: string | string[]): Promise<any>;
337
+
342
338
  /** @deprecated */
343
339
  declare function compileTemplate(template: NuxtTemplate, ctx: any): Promise<string>;
344
340
  /** @deprecated */
@@ -350,4 +346,4 @@ declare const templateUtils: {
350
346
  }) => string;
351
347
  };
352
348
 
353
- export { AddComponentOptions, AddPluginOptions, AddRouteMiddlewareOptions, ExtendConfigOptions, ExtendRouteRulesOptions, ExtendViteConfigOptions, ExtendWebpackConfigOptions, LoadNuxtConfigOptions, LoadNuxtOptions, RequireModuleOptions, ResolveModuleOptions, ResolvePathOptions, Resolver, addComponent, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, addLayout, addPlugin, addPluginTemplate, addPrerenderRoutes, addRouteMiddleware, addServerHandler, addServerPlugin, addTemplate, addVitePlugin, addWebpackPlugin, assertNuxtCompatibility, buildNuxt, checkNuxtCompatibility, clearRequireCache, compileTemplate, createResolver, defineNuxtModule, extendNuxtSchema, extendPages, extendRouteRules, extendViteConfig, extendWebpackConfig, findPath, getNuxtVersion, getRequireCacheItem, hasNuxtCompatibility, importModule, installModule, isIgnored, isNodeModules, isNuxt2, isNuxt3, loadNuxt, loadNuxtConfig, logger, normalizePlugin, normalizeTemplate, nuxtCtx, requireModule, requireModulePkg, resolveAlias, resolveFiles, resolveModule, resolvePath, scanRequireTree, templateUtils, tryImportModule, tryRequireModule, tryResolveModule, tryUseNuxt, updateTemplates, useLogger, useNitro, useNuxt };
349
+ export { AddComponentOptions, AddPluginOptions, AddRouteMiddlewareOptions, ExtendConfigOptions, ExtendRouteRulesOptions, ExtendViteConfigOptions, ExtendWebpackConfigOptions, LoadNuxtConfigOptions, LoadNuxtOptions, RequireModuleOptions, ResolveModuleOptions, ResolvePathOptions, Resolver, addComponent, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, addLayout, addPlugin, addPluginTemplate, addPrerenderRoutes, addRouteMiddleware, addServerHandler, addServerPlugin, addTemplate, addVitePlugin, addWebpackPlugin, assertNuxtCompatibility, buildNuxt, checkNuxtCompatibility, compileTemplate, createResolver, defineNuxtModule, extendNuxtSchema, extendPages, extendRouteRules, extendViteConfig, extendWebpackConfig, findPath, getNuxtVersion, hasNuxtCompatibility, importModule, installModule, isIgnored, isNuxt2, isNuxt3, loadNuxt, loadNuxtConfig, logger, normalizePlugin, normalizeTemplate, nuxtCtx, requireModule, resolveAlias, resolveFiles, resolveModule, resolvePath, templateUtils, tryImportModule, tryRequireModule, tryResolveModule, tryUseNuxt, updateTemplates, useLogger, useNitro, useNuxt };
package/dist/index.mjs CHANGED
@@ -1,14 +1,15 @@
1
1
  import { promises, existsSync, readFileSync } from 'node:fs';
2
+ import { performance } from 'node:perf_hooks';
2
3
  import { defu } from 'defu';
3
4
  import { applyDefaults } from 'untyped';
4
- import { dirname, join, normalize, relative, isAbsolute, resolve, basename, parse } from 'pathe';
5
+ import { dirname, normalize, join, relative, isAbsolute, resolve, basename, parse } from 'pathe';
5
6
  import consola from 'consola';
6
7
  import { getContext } from 'unctx';
7
8
  import satisfies from 'semver/functions/satisfies.js';
8
9
  import lodashTemplate from 'lodash.template';
9
10
  import { genSafeVariableName, genDynamicImport, genImport } from 'knitwork';
10
11
  import { pathToFileURL, fileURLToPath } from 'node:url';
11
- import { interopDefault } from 'mlly';
12
+ import { interopDefault, resolvePath as resolvePath$1 } from 'mlly';
12
13
  import jiti from 'jiti';
13
14
  import { globby } from 'globby';
14
15
  import { resolveAlias as resolveAlias$1 } from 'pathe/utils';
@@ -40,7 +41,7 @@ async function checkNuxtCompatibility(constraints, nuxt = useNuxt()) {
40
41
  const issues = [];
41
42
  if (constraints.nuxt) {
42
43
  const nuxtVersion = getNuxtVersion(nuxt);
43
- const nuxtSemanticVersion = nuxtVersion.replace(/-[0-9]+\.[0-9a-f]{7,8}/, "");
44
+ const nuxtSemanticVersion = nuxtVersion.replace(/-[0-9]+\.[0-9a-f]+/, "");
44
45
  if (!satisfies(nuxtSemanticVersion, constraints.nuxt, { includePrerelease: true })) {
45
46
  issues.push({
46
47
  name: "nuxt",
@@ -164,7 +165,23 @@ ${issues.toString()}`);
164
165
  if (definition.hooks) {
165
166
  nuxt.hooks.addHooks(definition.hooks);
166
167
  }
167
- await definition.setup?.call(null, _options, nuxt);
168
+ const mark = performance.mark();
169
+ const res = await definition.setup?.call(null, _options, nuxt) ?? {};
170
+ const perf = performance.measure(`nuxt:module:${uniqueKey || Math.round(Math.random() * 1e4)}`, mark.name);
171
+ const setupTime = Math.round(perf.duration * 100) / 100;
172
+ if (setupTime > 5e3) {
173
+ logger.warn(`Slow module \`${uniqueKey || "<no name>"}\` took \`${setupTime}ms\` to setup.`);
174
+ } else if (nuxt.options.debug) {
175
+ logger.info(`Module \`${uniqueKey || "<no name>"}\` took \`${setupTime}ms\` to setup.`);
176
+ }
177
+ if (res === false) {
178
+ return false;
179
+ }
180
+ return defu(res, {
181
+ timings: {
182
+ setup: setupTime
183
+ }
184
+ });
168
185
  }
169
186
  normalizedModule.getMeta = () => Promise.resolve(definition.meta);
170
187
  normalizedModule.getOptions = getOptions;
@@ -232,30 +249,12 @@ function clearRequireCache(id) {
232
249
  }
233
250
  delete _require.cache[id];
234
251
  }
235
- function scanRequireTree(id, files = /* @__PURE__ */ new Set()) {
236
- if (isNodeModules(id) || files.has(id)) {
237
- return files;
238
- }
239
- const entry = getRequireCacheItem(id);
240
- if (!entry) {
241
- files.add(id);
242
- return files;
243
- }
244
- files.add(entry.id);
245
- for (const child of entry.children) {
246
- scanRequireTree(child.id, files);
247
- }
248
- return files;
249
- }
250
252
  function getRequireCacheItem(id) {
251
253
  try {
252
254
  return _require.cache[id];
253
255
  } catch (e) {
254
256
  }
255
257
  }
256
- function requireModulePkg(id, opts = {}) {
257
- return requireModule(join(id, "package.json"), opts);
258
- }
259
258
  function resolveModule(id, opts = {}) {
260
259
  return normalize(_require.resolve(id, {
261
260
  paths: [].concat(
@@ -268,7 +267,7 @@ function resolveModule(id, opts = {}) {
268
267
  ).filter(Boolean)
269
268
  }));
270
269
  }
271
- function tryResolveModule(path, opts = {}) {
270
+ function tryResolveModule$1(path, opts = {}) {
272
271
  try {
273
272
  return resolveModule(path, opts);
274
273
  } catch (error) {
@@ -286,16 +285,16 @@ function requireModule(id, opts = {}) {
286
285
  const requiredModule = _require(resolvedPath);
287
286
  return requiredModule;
288
287
  }
289
- function importModule(id, opts = {}) {
288
+ function importModule$1(id, opts = {}) {
290
289
  const resolvedPath = resolveModule(id, opts);
291
290
  if (opts.interopDefault !== false) {
292
291
  return import(pathToFileURL(resolvedPath).href).then(interopDefault);
293
292
  }
294
293
  return import(pathToFileURL(resolvedPath).href);
295
294
  }
296
- function tryImportModule(id, opts = {}) {
295
+ function tryImportModule$1(id, opts = {}) {
297
296
  try {
298
- return importModule(id, opts).catch(() => void 0);
297
+ return importModule$1(id, opts).catch(() => void 0);
299
298
  } catch {
300
299
  }
301
300
  }
@@ -306,6 +305,23 @@ function tryRequireModule(id, opts = {}) {
306
305
  }
307
306
  }
308
307
 
308
+ async function tryResolveModule(id, url = import.meta.url) {
309
+ try {
310
+ return await resolvePath$1(id, { url });
311
+ } catch {
312
+ }
313
+ }
314
+ async function importModule(id, url = import.meta.url) {
315
+ const resolvedPath = await resolvePath$1(id, { url });
316
+ return import(pathToFileURL(resolvedPath).href).then(interopDefault);
317
+ }
318
+ function tryImportModule(id, url = import.meta.url) {
319
+ try {
320
+ return importModule(id, url).catch(() => void 0);
321
+ } catch {
322
+ }
323
+ }
324
+
309
325
  function isIgnored(pathname) {
310
326
  const nuxt = tryUseNuxt();
311
327
  if (!nuxt) {
@@ -374,7 +390,7 @@ async function resolvePath(path, opts = {}) {
374
390
  return pathWithIndex;
375
391
  }
376
392
  }
377
- const resolveModulePath = tryResolveModule(_path, { paths: [cwd, ...modulesDir] });
393
+ const resolveModulePath = tryResolveModule$1(_path, { paths: [cwd, ...modulesDir] });
378
394
  if (resolveModulePath) {
379
395
  return resolveModulePath;
380
396
  }
@@ -432,7 +448,7 @@ async function resolveFiles(path, pattern, opts = {}) {
432
448
  async function installModule(moduleToInstall, _inlineOptions, _nuxt) {
433
449
  const nuxt = useNuxt();
434
450
  const { nuxtModule, inlineOptions } = await normalizeModule(moduleToInstall, _inlineOptions);
435
- const res = await nuxtModule(inlineOptions, nuxt);
451
+ const res = await nuxtModule(inlineOptions, nuxt) ?? {};
436
452
  if (res === false) {
437
453
  return;
438
454
  }
@@ -442,6 +458,7 @@ async function installModule(moduleToInstall, _inlineOptions, _nuxt) {
442
458
  nuxt.options._installedModules = nuxt.options._installedModules || [];
443
459
  nuxt.options._installedModules.push({
444
460
  meta: await nuxtModule.getMeta?.(),
461
+ timings: res.timings,
445
462
  entryPath: typeof moduleToInstall === "string" ? resolveAlias(moduleToInstall) : void 0
446
463
  });
447
464
  }
@@ -451,7 +468,7 @@ async function normalizeModule(nuxtModule, inlineOptions) {
451
468
  const _src = resolveModule(resolveAlias(nuxtModule), { paths: nuxt.options.modulesDir });
452
469
  const isESM = _src.endsWith(".mjs");
453
470
  try {
454
- nuxtModule = isESM ? await importModule(_src) : requireModule(_src);
471
+ nuxtModule = isESM ? await importModule(_src, nuxt.options.rootDir) : requireModule(_src);
455
472
  } catch (error) {
456
473
  console.error(`Error while requiring module \`${nuxtModule}\`: ${error}`);
457
474
  throw error;
@@ -509,7 +526,6 @@ function extendNuxtSchema(def) {
509
526
  async function loadNuxt(opts) {
510
527
  opts.cwd = opts.cwd || opts.rootDir;
511
528
  opts.overrides = opts.overrides || opts.config || {};
512
- const resolveOpts = { paths: opts.cwd };
513
529
  opts.overrides.dev = !!opts.dev;
514
530
  const nearestNuxtPkg = await Promise.all(["nuxt3", "nuxt", "nuxt-edge"].map((pkg2) => resolvePackageJSON(pkg2, { url: opts.cwd }).catch(() => null))).then((r) => r.filter(Boolean).sort((a, b) => b.length - a.length)[0]);
515
531
  if (!nearestNuxtPkg) {
@@ -517,12 +533,13 @@ async function loadNuxt(opts) {
517
533
  }
518
534
  const pkg = await readPackageJSON(nearestNuxtPkg);
519
535
  const majorVersion = parseInt((pkg.version || "").split(".")[0]);
536
+ const rootDir = pathToFileURL(opts.cwd || process.cwd()).href;
520
537
  if (majorVersion === 3) {
521
- const { loadNuxt: loadNuxt3 } = await importModule(pkg._name || pkg.name, resolveOpts);
538
+ const { loadNuxt: loadNuxt3 } = await importModule(pkg._name || pkg.name, rootDir);
522
539
  const nuxt2 = await loadNuxt3(opts);
523
540
  return nuxt2;
524
541
  }
525
- const { loadNuxt: loadNuxt2 } = await tryImportModule("nuxt-edge", resolveOpts) || await importModule("nuxt", resolveOpts);
542
+ const { loadNuxt: loadNuxt2 } = await tryImportModule("nuxt-edge", rootDir) || await importModule("nuxt", rootDir);
526
543
  const nuxt = await loadNuxt2({
527
544
  rootDir: opts.cwd,
528
545
  for: opts.dev ? "dev" : "build",
@@ -534,12 +551,12 @@ async function loadNuxt(opts) {
534
551
  return nuxt;
535
552
  }
536
553
  async function buildNuxt(nuxt) {
537
- const resolveOpts = { paths: nuxt.options.rootDir };
554
+ const rootDir = pathToFileURL(nuxt.options.rootDir).href;
538
555
  if (nuxt.options._majorVersion === 3) {
539
- const { build: build2 } = await tryImportModule("nuxt3", resolveOpts) || await importModule("nuxt", resolveOpts);
556
+ const { build: build2 } = await tryImportModule("nuxt3", rootDir) || await importModule("nuxt", rootDir);
540
557
  return build2(nuxt);
541
558
  }
542
- const { build } = await tryImportModule("nuxt-edge", resolveOpts) || await importModule("nuxt", resolveOpts);
559
+ const { build } = await tryImportModule("nuxt-edge", rootDir) || await importModule("nuxt", rootDir);
543
560
  return build(nuxt);
544
561
  }
545
562
 
@@ -652,13 +669,21 @@ async function addComponent(opts) {
652
669
  preload: false,
653
670
  mode: "all",
654
671
  shortPath: opts.filePath,
672
+ priority: 0,
655
673
  ...opts
656
674
  };
657
675
  nuxt.hook("components:extend", (components) => {
658
676
  const existingComponent = components.find((c) => (c.pascalName === component.pascalName || c.kebabName === component.kebabName) && c.mode === component.mode);
659
677
  if (existingComponent) {
660
- const name = existingComponent.pascalName || existingComponent.kebabName;
661
- console.warn(`Overriding ${name} component.`);
678
+ const existingPriority = existingComponent.priority ?? 0;
679
+ const newPriority = component.priority ?? 0;
680
+ if (newPriority < existingPriority) {
681
+ return;
682
+ }
683
+ if (newPriority === existingPriority) {
684
+ const name = existingComponent.pascalName || existingComponent.kebabName;
685
+ console.warn(`Overriding ${name} component. You can specify a \`priority\` option when calling \`addComponent\` to avoid this warning.`);
686
+ }
662
687
  Object.assign(existingComponent, component);
663
688
  } else {
664
689
  components.push(component);
@@ -786,6 +811,10 @@ function normalizePlugin(plugin) {
786
811
  if (!plugin.src) {
787
812
  throw new Error("Invalid plugin. src option is required: " + JSON.stringify(plugin));
788
813
  }
814
+ const nonTopLevelPlugin = plugin.src.match(/\/plugins\/[^/]+\/index\.[^/]+$/i);
815
+ if (nonTopLevelPlugin && nonTopLevelPlugin.length > 0 && !useNuxt().options.plugins.find((i) => (typeof i === "string" ? i : i.src).endsWith(nonTopLevelPlugin[0]))) {
816
+ console.warn(`[warn] [nuxt] [deprecation] You are using a plugin that is within a subfolder of your plugins directory without adding it to your config explicitly. You can move it to the top-level plugins directory, or include the file '~${nonTopLevelPlugin[0]}' in your plugins config (https://nuxt.com/docs/api/configuration/nuxt-config#plugins-1) to remove this warning.`);
817
+ }
789
818
  plugin.src = normalize(resolveAlias(plugin.src));
790
819
  if (plugin.ssr) {
791
820
  plugin.mode = "server";
@@ -850,4 +879,4 @@ function useNitro() {
850
879
  return nuxt._nitro;
851
880
  }
852
881
 
853
- export { addComponent, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, addLayout, addPlugin, addPluginTemplate, addPrerenderRoutes, addRouteMiddleware, addServerHandler, addServerPlugin, addTemplate, addVitePlugin, addWebpackPlugin, assertNuxtCompatibility, buildNuxt, checkNuxtCompatibility, clearRequireCache, compileTemplate, createResolver, defineNuxtModule, extendNuxtSchema, extendPages, extendRouteRules, extendViteConfig, extendWebpackConfig, findPath, getNuxtVersion, getRequireCacheItem, hasNuxtCompatibility, importModule, installModule, isIgnored, isNodeModules, isNuxt2, isNuxt3, loadNuxt, loadNuxtConfig, logger, normalizePlugin, normalizeTemplate, nuxtCtx, requireModule, requireModulePkg, resolveAlias, resolveFiles, resolveModule, resolvePath, scanRequireTree, templateUtils, tryImportModule, tryRequireModule, tryResolveModule, tryUseNuxt, updateTemplates, useLogger, useNitro, useNuxt };
882
+ export { addComponent, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, addLayout, addPlugin, addPluginTemplate, addPrerenderRoutes, addRouteMiddleware, addServerHandler, addServerPlugin, addTemplate, addVitePlugin, addWebpackPlugin, assertNuxtCompatibility, buildNuxt, checkNuxtCompatibility, compileTemplate, createResolver, defineNuxtModule, extendNuxtSchema, extendPages, extendRouteRules, extendViteConfig, extendWebpackConfig, findPath, getNuxtVersion, hasNuxtCompatibility, importModule$1 as importModule, installModule, isIgnored, isNuxt2, isNuxt3, loadNuxt, loadNuxtConfig, logger, normalizePlugin, normalizeTemplate, nuxtCtx, requireModule, resolveAlias, resolveFiles, resolveModule, resolvePath, templateUtils, tryImportModule$1 as tryImportModule, tryRequireModule, tryResolveModule, tryUseNuxt, updateTemplates, useLogger, useNitro, useNuxt };
package/package.json CHANGED
@@ -1,32 +1,38 @@
1
1
  {
2
2
  "name": "@nuxt/kit",
3
- "version": "3.2.3",
3
+ "version": "3.3.1",
4
4
  "repository": "nuxt/nuxt",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
- "main": "./dist/index.mjs",
8
7
  "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
9
15
  "files": [
10
16
  "dist"
11
17
  ],
12
18
  "dependencies": {
13
- "@nuxt/schema": "3.2.3",
14
- "c12": "^1.1.2",
19
+ "@nuxt/schema": "3.3.1",
20
+ "c12": "^1.2.0",
15
21
  "consola": "^2.15.3",
16
22
  "defu": "^6.1.2",
17
23
  "globby": "^13.1.3",
18
24
  "hash-sum": "^2.0.0",
19
25
  "ignore": "^5.2.4",
20
- "jiti": "^1.17.1",
26
+ "jiti": "^1.17.2",
21
27
  "knitwork": "^1.0.0",
22
28
  "lodash.template": "^4.5.0",
23
- "mlly": "^1.1.1",
29
+ "mlly": "^1.2.0",
24
30
  "pathe": "^1.1.0",
25
31
  "pkg-types": "^1.0.2",
26
32
  "scule": "^1.0.0",
27
33
  "semver": "^7.3.8",
28
34
  "unctx": "^2.1.2",
29
- "unimport": "^2.2.4",
35
+ "unimport": "^3.0.2",
30
36
  "untyped": "^1.2.2"
31
37
  },
32
38
  "devDependencies": {