@nuxt/kit-nightly 5.0.0-29754172.7cdbbb7a → 5.0.0-29754187.c12e0090

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
@@ -663,7 +663,7 @@ declare const buildDiagnostics: import("nostics").Diagnostics<{
663
663
  readonly NUXT_B1004: {
664
664
  readonly why: "Failed to install dependencies.";
665
665
  readonly fix: (p: {
666
- packages: string;
666
+ installCommand: string;
667
667
  }) => string;
668
668
  readonly docs: false;
669
669
  };
@@ -741,7 +741,9 @@ declare const buildDiagnostics: import("nostics").Diagnostics<{
741
741
  };
742
742
  readonly NUXT_B1015: {
743
743
  readonly why: "Falling back to `chokidar-granular` as `@parcel/watcher` cannot be resolved in your project.";
744
- readonly fix: "Install `@parcel/watcher` for better performance: `npm install -D @parcel/watcher`.";
744
+ readonly fix: (p: {
745
+ installCommand: string;
746
+ }) => string;
745
747
  readonly docs: false;
746
748
  };
747
749
  readonly NUXT_B1016: {
@@ -754,7 +756,7 @@ declare const buildDiagnostics: import("nostics").Diagnostics<{
754
756
  builder: string;
755
757
  }) => string;
756
758
  readonly fix: (p: {
757
- builder: string;
759
+ installCommand: string;
758
760
  }) => string;
759
761
  readonly docs: false;
760
762
  };
@@ -763,7 +765,7 @@ declare const buildDiagnostics: import("nostics").Diagnostics<{
763
765
  builder: string;
764
766
  }) => string;
765
767
  readonly fix: (p: {
766
- builder: string;
768
+ installCommand: string;
767
769
  }) => string;
768
770
  readonly docs: false;
769
771
  };
@@ -1154,7 +1156,9 @@ declare const configDiagnostics: import("nostics").Diagnostics<{
1154
1156
  readonly why: (p: {
1155
1157
  rootDir: string;
1156
1158
  }) => string;
1157
- readonly fix: "Install it manually with `npm install -D @nuxt/webpack-builder`, or change the `builder` option to `vite` in `nuxt.config`.";
1159
+ readonly fix: (p: {
1160
+ installCommand: string;
1161
+ }) => string;
1158
1162
  readonly docs: false;
1159
1163
  };
1160
1164
  readonly NUXT_B5003: {
@@ -1190,7 +1194,9 @@ declare const configDiagnostics: import("nostics").Diagnostics<{
1190
1194
  };
1191
1195
  readonly NUXT_B5009: {
1192
1196
  readonly why: "`@parcel/watcher` cannot be resolved in your project, so `chokidar` is being used instead.";
1193
- readonly fix: "Install `@parcel/watcher` for better file watching: `npm install -D @parcel/watcher`.";
1197
+ readonly fix: (p: {
1198
+ installCommand: string;
1199
+ }) => string;
1194
1200
  readonly docs: false;
1195
1201
  };
1196
1202
  readonly NUXT_B5010: {
@@ -1198,7 +1204,7 @@ declare const configDiagnostics: import("nostics").Diagnostics<{
1198
1204
  names: string;
1199
1205
  }) => string;
1200
1206
  readonly fix: (p: {
1201
- install: string;
1207
+ installCommand: string;
1202
1208
  }) => string;
1203
1209
  readonly docs: false;
1204
1210
  };
@@ -1273,7 +1279,9 @@ declare const headDiagnostics: import("nostics").Diagnostics<{
1273
1279
  declare const bundlerDiagnostics: import("nostics").Diagnostics<{
1274
1280
  readonly NUXT_B7001: {
1275
1281
  readonly why: "`rollup-plugin-visualizer` is not installed, so bundle analysis cannot run.";
1276
- readonly fix: "Run `npm install -D rollup-plugin-visualizer` to enable bundle analysis.";
1282
+ readonly fix: (p: {
1283
+ installCommand: string;
1284
+ }) => string;
1277
1285
  readonly docs: false;
1278
1286
  };
1279
1287
  readonly NUXT_B7002: {
@@ -1316,13 +1324,15 @@ declare const bundlerDiagnostics: import("nostics").Diagnostics<{
1316
1324
  pluginName: string;
1317
1325
  }) => string;
1318
1326
  readonly fix: (p: {
1319
- pluginName: string;
1327
+ installCommand: string;
1320
1328
  }) => string;
1321
1329
  readonly docs: false;
1322
1330
  };
1323
1331
  readonly NUXT_B7008: {
1324
1332
  readonly why: "`@vitejs/plugin-vue-jsx` is not installed, so JSX support is unavailable.";
1325
- readonly fix: "Run `npm install -D @vitejs/plugin-vue-jsx` to install it.";
1333
+ readonly fix: (p: {
1334
+ installCommand: string;
1335
+ }) => string;
1326
1336
  readonly docs: false;
1327
1337
  };
1328
1338
  readonly NUXT_B7009: {
@@ -1330,7 +1340,7 @@ declare const bundlerDiagnostics: import("nostics").Diagnostics<{
1330
1340
  deps: string;
1331
1341
  }) => string;
1332
1342
  readonly fix: (p: {
1333
- install: string;
1343
+ installCommand: string;
1334
1344
  }) => string;
1335
1345
  readonly docs: false;
1336
1346
  };
@@ -1339,7 +1349,7 @@ declare const bundlerDiagnostics: import("nostics").Diagnostics<{
1339
1349
  pluginName: string;
1340
1350
  }) => string;
1341
1351
  readonly fix: (p: {
1342
- pluginName: string;
1352
+ installCommand: string;
1343
1353
  }) => string;
1344
1354
  readonly docs: false;
1345
1355
  };
@@ -1425,6 +1435,18 @@ interface EnsureDependencyInstalledOptions {
1425
1435
  */
1426
1436
  declare function ensureDependencyInstalled(names: string, options?: EnsureDependencyInstalledOptions): Promise<boolean>;
1427
1437
  declare function ensureDependencyInstalled(names: string[], options?: EnsureDependencyInstalledOptions): Promise<true | string[]>;
1438
+ /**
1439
+ * Get the command a user should run to add dependencies to their project, using the
1440
+ * package manager detected from `cwd` (falling back to `npm`).
1441
+ *
1442
+ * @param names - One or more package names to install
1443
+ * @param cwd - Directory to detect the package manager from
1444
+ * @param options - Options for the install command
1445
+ * @param options.dev - Whether the command should install as a dev dependency
1446
+ */
1447
+ declare function getAddDependencyCommand(names: string | string[], cwd: string, options?: {
1448
+ dev?: boolean;
1449
+ }): Promise<string>;
1428
1450
  //#endregion
1429
1451
  //#region src/internal/esm.d.ts
1430
1452
  interface ResolveModuleOptions {
@@ -1460,4 +1482,4 @@ declare function requireModule<T = unknown>(id: string, opts?: ImportModuleOptio
1460
1482
  */
1461
1483
  declare function tryRequireModule<T = unknown>(id: string, opts?: ImportModuleOptions): T | undefined;
1462
1484
  //#endregion
1463
- export { type AddComponentOptions, type AddPluginOptions, type AddRouteMiddlewareOptions, DEFAULT_JSX_FILE_EXTENSIONS, DEFAULT_JS_FILE_EXTENSIONS, type EnsureDependencyInstalledOptions, type ExtendConfigOptions, type ExtendRouteRulesOptions, type ExtendViteConfigOptions, type ExtendWebpackConfigOptions, type ImportModuleOptions, type LayerDirectories, type LoadNuxtConfigOptions, type LoadNuxtOptions, type NuxtConfigDiffEntry, type NuxtMajorVersion, type ResolveModuleOptions, type ResolvePathOptions, type ResolvedNuxtConfigContext, type Resolver, addBuildPlugin, addComponent, addComponentExports, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, addLayout, addPlugin, addPluginTemplate, addPrerenderRoutes, addRouteMiddleware, addRspackPlugin, addServerHandler, addServerImports, addServerImportsDir, addServerPlugin, addServerScanDir, addServerTemplate, addTemplate, addTypeTemplate, addVitePlugin, addWebpackPlugin, assertNuxtCompatibility, buildDiagnostics, buildNuxt, bundlerDiagnostics, checkNuxtCompatibility, componentDiagnostics, configDiagnostics, createIsIgnored, createResolver, defineNuxtModule, diffNuxtConfig, directoryToURL, ensureDependencyInstalled, extendNuxtSchema, extendPages, extendRouteRules, extendRspackConfig, extendViteConfig, extendWebpackConfig, findPath, getDirectory, getLayerDirectories, getNuxtCtx, getNuxtModuleVersion, getNuxtVersion, hasNuxtCompatibility, hasNuxtModule, hasNuxtModuleCompatibility, headDiagnostics, importModule, installModule, installModules, isIgnored, isNuxt2, isNuxt3, isNuxtMajorVersion, loadNuxt, loadNuxtConfig, loadNuxtModuleInstance, logger, normalizeModuleTranspilePath, normalizePlugin, normalizeSemanticVersion, normalizeTemplate, nuxtCtx, packageName, pageDiagnostics, pluginDiagnostics, requireModule, resolveAlias, resolveDeclarationPath, resolveFiles, resolveIgnorePatterns, resolveModule, resolveModuleWithOptions, resolveNuxtModule, resolvePath, resolveTypePaths, runWithNuxtContext, setBuildOutput, setGlobalHead, tryImportModule, tryRequireModule, tryResolveModule, tryUseNuxt, updateAppConfig, updateRuntimeConfig, updateTemplates, useLogger, useNitro, useNuxt, useRuntimeConfig, writeTypes };
1485
+ export { type AddComponentOptions, type AddPluginOptions, type AddRouteMiddlewareOptions, DEFAULT_JSX_FILE_EXTENSIONS, DEFAULT_JS_FILE_EXTENSIONS, type EnsureDependencyInstalledOptions, type ExtendConfigOptions, type ExtendRouteRulesOptions, type ExtendViteConfigOptions, type ExtendWebpackConfigOptions, type ImportModuleOptions, type LayerDirectories, type LoadNuxtConfigOptions, type LoadNuxtOptions, type NuxtConfigDiffEntry, type NuxtMajorVersion, type ResolveModuleOptions, type ResolvePathOptions, type ResolvedNuxtConfigContext, type Resolver, addBuildPlugin, addComponent, addComponentExports, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, addLayout, addPlugin, addPluginTemplate, addPrerenderRoutes, addRouteMiddleware, addRspackPlugin, addServerHandler, addServerImports, addServerImportsDir, addServerPlugin, addServerScanDir, addServerTemplate, addTemplate, addTypeTemplate, addVitePlugin, addWebpackPlugin, assertNuxtCompatibility, buildDiagnostics, buildNuxt, bundlerDiagnostics, checkNuxtCompatibility, componentDiagnostics, configDiagnostics, createIsIgnored, createResolver, defineNuxtModule, diffNuxtConfig, directoryToURL, ensureDependencyInstalled, extendNuxtSchema, extendPages, extendRouteRules, extendRspackConfig, extendViteConfig, extendWebpackConfig, findPath, getAddDependencyCommand, getDirectory, getLayerDirectories, getNuxtCtx, getNuxtModuleVersion, getNuxtVersion, hasNuxtCompatibility, hasNuxtModule, hasNuxtModuleCompatibility, headDiagnostics, importModule, installModule, installModules, isIgnored, isNuxt2, isNuxt3, isNuxtMajorVersion, loadNuxt, loadNuxtConfig, loadNuxtModuleInstance, logger, normalizeModuleTranspilePath, normalizePlugin, normalizeSemanticVersion, normalizeTemplate, nuxtCtx, packageName, pageDiagnostics, pluginDiagnostics, requireModule, resolveAlias, resolveDeclarationPath, resolveFiles, resolveIgnorePatterns, resolveModule, resolveModuleWithOptions, resolveNuxtModule, resolvePath, resolveTypePaths, runWithNuxtContext, setBuildOutput, setGlobalHead, tryImportModule, tryRequireModule, tryResolveModule, tryUseNuxt, updateAppConfig, updateRuntimeConfig, updateTemplates, useLogger, useNitro, useNuxt, useRuntimeConfig, writeTypes };
package/dist/index.mjs CHANGED
@@ -22,6 +22,8 @@ import { captureStackTrace } from "errx";
22
22
  import { glob } from "tinyglobby";
23
23
  import { resolveAlias as resolveAlias$1, reverseResolveAlias } from "pathe/utils";
24
24
  import ignore from "ignore";
25
+ import { addDependency, addDependencyCommand, detectPackageManager } from "nypm";
26
+ import { hasTTY, isCI, provider } from "std-env";
25
27
  import { loadConfig, setupDotenv } from "c12";
26
28
  import { klona } from "klona/full";
27
29
  import { diff } from "ohash/utils";
@@ -30,8 +32,6 @@ import { kebabCase, pascalCase, snakeCase } from "scule";
30
32
  import { klona as klona$1 } from "klona";
31
33
  import { hash } from "ohash";
32
34
  import { isAbsolute as isAbsolute$1 } from "node:path";
33
- import { addDependency } from "nypm";
34
- import { hasTTY, isCI, provider } from "std-env";
35
35
  //#region src/logger.ts
36
36
  const logger = consola;
37
37
  function useLogger(tag, options = {}) {
@@ -84,7 +84,7 @@ const kitDiagnostics = /* #__PURE__ */ defineDiagnostics({
84
84
  },
85
85
  NUXT_B8006: {
86
86
  why: (p) => `No Nuxt version could be found from \`${p.cwd}\`.`,
87
- fix: "Run `npm install nuxt` in your project directory to install Nuxt.",
87
+ fix: (p) => `Run \`${p.installCommand}\` in your project directory to install Nuxt.`,
88
88
  docs: false
89
89
  },
90
90
  NUXT_B8007: {
@@ -139,7 +139,7 @@ const kitDiagnostics = /* #__PURE__ */ defineDiagnostics({
139
139
  },
140
140
  NUXT_B8017: {
141
141
  why: (p) => `The module \`${p.module}\` could not be loaded. It may not be installed.`,
142
- fix: (p) => `Run \`npm install ${p.module}\` to install it.`,
142
+ fix: (p) => p.installCommand ? `Run \`${p.installCommand}\` to install it.` : "Check that the module path exists and points to a valid Nuxt module.",
143
143
  docs: false
144
144
  },
145
145
  NUXT_B8018: {
@@ -720,6 +720,255 @@ function tryRequireModule(id, opts) {
720
720
  } catch {}
721
721
  }
722
722
  //#endregion
723
+ //#region src/diagnostics/build.ts
724
+ /**
725
+ * B1xxx
726
+ * Build / compilation diagnostics.
727
+ *
728
+ * @internal
729
+ */
730
+ const buildDiagnostics = /* #__PURE__ */ defineDiagnostics({
731
+ docsBase,
732
+ reporters,
733
+ codes: {
734
+ NUXT_B1001: {
735
+ why: (p) => `Could not compile template \`${p.filename}\`.`,
736
+ fix: (p) => p.src ? `Check the template source file at \`${p.src}\` for syntax errors.` : "Check the `getContents` function of this template for errors.",
737
+ docs: false
738
+ },
739
+ NUXT_B1002: {
740
+ why: (p) => `Error reading template from \`${p.src}\`.`,
741
+ fix: "Check that the template `src` path exists and is readable.",
742
+ docs: false
743
+ },
744
+ NUXT_B1003: {
745
+ why: "Invalid template. Templates must have either `src` or `getContents`.",
746
+ fix: "Add a `getContents` function or a `src` path to the `addTemplate()` call.",
747
+ docs: false
748
+ },
749
+ NUXT_B1004: {
750
+ why: "Failed to install dependencies.",
751
+ fix: (p) => `Try installing manually with \`${p.installCommand}\`.`,
752
+ docs: false
753
+ },
754
+ NUXT_B1005: {
755
+ why: (p) => `Plugin \`${p.plugin}\` failed to scan file \`${p.file}\`.`,
756
+ fix: "Check the file for syntax errors, or report this issue to the plugin author.",
757
+ docs: false
758
+ },
759
+ NUXT_B1006: {
760
+ why: (p) => `Cannot read file \`${p.file}\`.`,
761
+ fix: "Check that the file exists and has correct permissions.",
762
+ docs: false
763
+ },
764
+ NUXT_B1007: {
765
+ why: (p) => `Error in \`afterScan\` hook of plugin \`${p.plugin}\`.`,
766
+ fix: "Check the plugin implementation or report this issue to the plugin author.",
767
+ docs: false
768
+ },
769
+ NUXT_B1008: {
770
+ why: (p) => `No factory function found for \`${p.function}\` in file \`${p.file}\`. This is a Nuxt bug.`,
771
+ fix: "Please report this issue at https://github.com/nuxt/nuxt/issues with the file contents.",
772
+ docs: false
773
+ },
774
+ NUXT_B1009: {
775
+ why: (p) => `Duplicate keyed function name \`${p.functionName}\`${p.name && p.functionName !== p.name ? ` defined as \`${p.name}\`` : ""} with ${p.source ? `the same source \`${p.source}\`` : "no source"} found. Overwriting the existing entry.`,
776
+ fix: "Ensure each keyed function has a unique name, or use a different source to distinguish them.",
777
+ docs: false
778
+ },
779
+ NUXT_B1010: {
780
+ why: (p) => `Failed to read file \`${p.file}\` as it changed during read.`,
781
+ fix: "The file was modified while being read, usually by a concurrent process writing to it. Try restarting the build.",
782
+ docs: false
783
+ },
784
+ NUXT_B1011: {
785
+ why: (p) => `Failed to read file \`${p.file}\`.`,
786
+ fix: "Check that the file exists and is readable, or try clearing the build cache with `nuxt clean`.",
787
+ docs: false
788
+ },
789
+ NUXT_B1012: {
790
+ why: (p) => `Skipping unsafe cache path: ${p.path}. This cache file has a path that escapes the project directory (possible path traversal).`,
791
+ fix: "Delete the cache with `nuxt clean` and rebuild.",
792
+ docs: false
793
+ },
794
+ NUXT_B1013: {
795
+ why: (p) => `Failed to restore cached file \`${p.file}\`.`,
796
+ fix: "Try clearing the build cache with `nuxt clean` and rebuilding from scratch.",
797
+ docs: false
798
+ },
799
+ NUXT_B1014: {
800
+ why: "Problem checking for external configuration files.",
801
+ fix: "This is likely a transient file system error. If it persists, check file permissions in your project root.",
802
+ docs: false
803
+ },
804
+ NUXT_B1015: {
805
+ why: "Falling back to `chokidar-granular` as `@parcel/watcher` cannot be resolved in your project.",
806
+ fix: (p) => `Install \`@parcel/watcher\` for better performance: \`${p.installCommand}\`.`,
807
+ docs: false
808
+ },
809
+ NUXT_B1016: {
810
+ why: "Failed to set up the `@parcel/watcher` file watcher.",
811
+ fix: "This is likely an environment or file system issue. Watching for file changes may not work; restart the dev server and, if the problem persists, report it.",
812
+ docs: false
813
+ },
814
+ NUXT_B1017: {
815
+ why: (p) => `Loading \`${p.builder}\` builder failed.`,
816
+ fix: (p) => `Run \`${p.installCommand}\` to install it.`,
817
+ docs: false
818
+ },
819
+ NUXT_B1018: {
820
+ why: (p) => `Loading \`${p.builder}\` server builder failed.`,
821
+ fix: (p) => `Run \`${p.installCommand}\` to install it.`,
822
+ docs: false
823
+ },
824
+ NUXT_B1019: {
825
+ why: (p) => `Unknown component mode \`${p.mode}\`. This might be an internal Nuxt bug.`,
826
+ fix: "If you are a module author, ensure the component `mode` is set to `client`, `server`, or `all`. Otherwise, please report this issue.",
827
+ docs: false
828
+ },
829
+ NUXT_B1020: {
830
+ why: "`experimental.watcher: \"builder\"` is set but the active builder does not implement `setupWatcher`. Falling back to the default file watcher.",
831
+ fix: "Remove `experimental.watcher` from your `nuxt.config`, or use a builder that supports its own watcher.",
832
+ docs: false
833
+ }
834
+ }
835
+ });
836
+ //#endregion
837
+ //#region src/diagnostics/config.ts
838
+ /**
839
+ * B5xxx
840
+ * Configuration diagnostics.
841
+ *
842
+ * @internal
843
+ */
844
+ const configDiagnostics = /* #__PURE__ */ defineDiagnostics({
845
+ docsBase,
846
+ reporters,
847
+ codes: {
848
+ NUXT_B5001: {
849
+ why: (p) => `No \`compatibilityDate\` is set in \`nuxt.config\`, so the \`${p.fallback}\` fallback is being used.`,
850
+ fix: (p) => `Add \`compatibilityDate: '${p.latest}'\` to your \`nuxt.config.ts\`.`
851
+ },
852
+ NUXT_B5002: {
853
+ why: (p) => `\`@nuxt/webpack-builder\` could not be installed in \`${p.rootDir}\`.`,
854
+ fix: (p) => `Install it manually with \`${p.installCommand}\`, or change the \`builder\` option to \`vite\` in \`nuxt.config\`.`,
855
+ docs: false
856
+ },
857
+ NUXT_B5003: {
858
+ why: (p) => `The \`app\` namespace is reserved for Nuxt and exposed to the browser, but \`runtimeConfig.app.${p.key}\` is set.`,
859
+ fix: "Move the key to `runtimeConfig.public` or a custom namespace."
860
+ },
861
+ NUXT_B5004: {
862
+ why: (p) => `External configuration files are not supported: ${p.files}.`,
863
+ fix: "Move these configurations into `nuxt.config.ts` and delete the external config files."
864
+ },
865
+ NUXT_B5005: {
866
+ why: (p) => `Nuxt schema could not be loaded from \`${p.filePath}\`.`,
867
+ fix: "Ensure the file exports a valid object with `defineNuxtSchema()` or as a plain object.",
868
+ docs: false
869
+ },
870
+ NUXT_B5006: {
871
+ why: (p) => `\`${p.option}\` is used in dev mode, which causes a memory leak.`,
872
+ fix: "Remove the hash option from your webpack config.",
873
+ docs: false
874
+ },
875
+ NUXT_B5007: {
876
+ why: "The webpack server config `target` is not set to \"node\".",
877
+ fix: "Set `target: \"node\"` in your webpack server configuration.",
878
+ docs: false
879
+ },
880
+ NUXT_B5009: {
881
+ why: "`@parcel/watcher` cannot be resolved in your project, so `chokidar` is being used instead.",
882
+ fix: (p) => `Install \`@parcel/watcher\` for better file watching: \`${p.installCommand}\`.`,
883
+ docs: false
884
+ },
885
+ NUXT_B5010: {
886
+ why: (p) => `Required packages are not installed: ${p.names}.`,
887
+ fix: (p) => `Run \`${p.installCommand}\` to install them.`,
888
+ docs: false
889
+ },
890
+ NUXT_B5011: {
891
+ why: (p) => `Package \`${p.name}\` is missing.`,
892
+ fix: (p) => `Run \`npx nuxt add ${p.name}\` to install it.`,
893
+ docs: false
894
+ }
895
+ }
896
+ });
897
+ //#endregion
898
+ //#region src/dependency.ts
899
+ const isStackblitz = provider === "stackblitz";
900
+ async function ensureDependencyInstalled(names, options = {}) {
901
+ const packages = Array.isArray(names) ? names : [names];
902
+ const nuxt = tryUseNuxt();
903
+ const rootDir = options.rootDir || nuxt?.options.rootDir || process.cwd();
904
+ const searchPaths = options.searchPaths || nuxt?.options.modulesDir || [];
905
+ const missing = findMissing(packages, [
906
+ rootDir,
907
+ ...options.from ? [options.from] : [],
908
+ ...searchPaths
909
+ ]);
910
+ if (missing.length === 0) return true;
911
+ const formattedNames = missing.map((n) => `\`${n}\``).join(", ");
912
+ configDiagnostics.NUXT_B5010({
913
+ names: formattedNames,
914
+ installCommand: await getAddDependencyCommand(missing, rootDir, { dev: true })
915
+ });
916
+ if (isCI) return Array.isArray(names) ? missing : false;
917
+ if (options.prompt === true || options.prompt !== false && !isStackblitz) {
918
+ if (!hasTTY) return Array.isArray(names) ? missing : false;
919
+ if (await logger.prompt(`Do you want to install ${formattedNames}?`, {
920
+ type: "confirm",
921
+ initial: true
922
+ }) !== true) return Array.isArray(names) ? missing : false;
923
+ } else if (!isStackblitz) return Array.isArray(names) ? missing : false;
924
+ logger.start(`Installing ${formattedNames}...`);
925
+ try {
926
+ await addDependency(missing, {
927
+ dev: true,
928
+ cwd: rootDir,
929
+ silent: true
930
+ });
931
+ logger.success(`Installed ${formattedNames}`);
932
+ return true;
933
+ } catch (err) {
934
+ buildDiagnostics.NUXT_B1004({
935
+ installCommand: await getAddDependencyCommand(missing, rootDir, { dev: true }),
936
+ cause: err
937
+ });
938
+ return Array.isArray(names) ? missing : false;
939
+ }
940
+ }
941
+ function findMissing(packages, searchPaths) {
942
+ const missing = [];
943
+ for (const name of packages) {
944
+ if (isResolvable(name, searchPaths)) continue;
945
+ missing.push(name);
946
+ }
947
+ return missing;
948
+ }
949
+ function isResolvable(name, searchPaths) {
950
+ for (const from of searchPaths) if (resolveModulePath(name, {
951
+ from,
952
+ try: true
953
+ })) return true;
954
+ return false;
955
+ }
956
+ /**
957
+ * Get the command a user should run to add dependencies to their project, using the
958
+ * package manager detected from `cwd` (falling back to `npm`).
959
+ *
960
+ * @param names - One or more package names to install
961
+ * @param cwd - Directory to detect the package manager from
962
+ * @param options - Options for the install command
963
+ * @param options.dev - Whether the command should install as a dev dependency
964
+ */
965
+ async function getAddDependencyCommand(names, cwd, options = {}) {
966
+ return addDependencyCommand((await detectPackageManager(cwd, { includeParentDirs: true }).catch(() => void 0))?.name || "npm", names, {
967
+ ...options,
968
+ short: true
969
+ });
970
+ }
971
+ //#endregion
723
972
  //#region src/module/install.ts
724
973
  const NODE_MODULES_RE = /[/\\]node_modules[/\\]/;
725
974
  const ignoredConfigKeys = /* @__PURE__ */ new Set([
@@ -931,6 +1180,7 @@ async function loadNuxtModuleInstance(nuxtModule, nuxt = useNuxt()) {
931
1180
  } catch (error) {
932
1181
  throw kitDiagnostics.NUXT_B8017({
933
1182
  module: nuxtModule,
1183
+ installCommand: isAbsolute(nuxtModule) ? void 0 : await getAddDependencyCommand(nuxtModule, nuxt.options.rootDir),
934
1184
  cause: error
935
1185
  });
936
1186
  }
@@ -1319,7 +1569,10 @@ async function loadNuxt(opts) {
1319
1569
  });
1320
1570
  return path && path.length > resolvedPath.length ? path : resolvedPath;
1321
1571
  }, "");
1322
- if (!resolvedPath) throw kitDiagnostics.NUXT_B8006({ cwd: opts.cwd });
1572
+ if (!resolvedPath) throw kitDiagnostics.NUXT_B8006({
1573
+ cwd: opts.cwd,
1574
+ installCommand: await getAddDependencyCommand("nuxt", opts.cwd)
1575
+ });
1323
1576
  const { loadNuxt } = await import(pathToFileURL(resolvedPath).href).then((r) => interopDefault(r));
1324
1577
  return await loadNuxt(opts);
1325
1578
  }
@@ -2629,181 +2882,6 @@ function addPluginTemplate(plugin, opts = {}) {
2629
2882
  }, opts);
2630
2883
  }
2631
2884
  //#endregion
2632
- //#region src/diagnostics/build.ts
2633
- /**
2634
- * B1xxx
2635
- * Build / compilation diagnostics.
2636
- *
2637
- * @internal
2638
- */
2639
- const buildDiagnostics = /* #__PURE__ */ defineDiagnostics({
2640
- docsBase,
2641
- reporters,
2642
- codes: {
2643
- NUXT_B1001: {
2644
- why: (p) => `Could not compile template \`${p.filename}\`.`,
2645
- fix: (p) => p.src ? `Check the template source file at \`${p.src}\` for syntax errors.` : "Check the `getContents` function of this template for errors.",
2646
- docs: false
2647
- },
2648
- NUXT_B1002: {
2649
- why: (p) => `Error reading template from \`${p.src}\`.`,
2650
- fix: "Check that the template `src` path exists and is readable.",
2651
- docs: false
2652
- },
2653
- NUXT_B1003: {
2654
- why: "Invalid template. Templates must have either `src` or `getContents`.",
2655
- fix: "Add a `getContents` function or a `src` path to the `addTemplate()` call.",
2656
- docs: false
2657
- },
2658
- NUXT_B1004: {
2659
- why: "Failed to install dependencies.",
2660
- fix: (p) => `Try installing manually with \`npm install ${p.packages}\`.`,
2661
- docs: false
2662
- },
2663
- NUXT_B1005: {
2664
- why: (p) => `Plugin \`${p.plugin}\` failed to scan file \`${p.file}\`.`,
2665
- fix: "Check the file for syntax errors, or report this issue to the plugin author.",
2666
- docs: false
2667
- },
2668
- NUXT_B1006: {
2669
- why: (p) => `Cannot read file \`${p.file}\`.`,
2670
- fix: "Check that the file exists and has correct permissions.",
2671
- docs: false
2672
- },
2673
- NUXT_B1007: {
2674
- why: (p) => `Error in \`afterScan\` hook of plugin \`${p.plugin}\`.`,
2675
- fix: "Check the plugin implementation or report this issue to the plugin author.",
2676
- docs: false
2677
- },
2678
- NUXT_B1008: {
2679
- why: (p) => `No factory function found for \`${p.function}\` in file \`${p.file}\`. This is a Nuxt bug.`,
2680
- fix: "Please report this issue at https://github.com/nuxt/nuxt/issues with the file contents.",
2681
- docs: false
2682
- },
2683
- NUXT_B1009: {
2684
- why: (p) => `Duplicate keyed function name \`${p.functionName}\`${p.name && p.functionName !== p.name ? ` defined as \`${p.name}\`` : ""} with ${p.source ? `the same source \`${p.source}\`` : "no source"} found. Overwriting the existing entry.`,
2685
- fix: "Ensure each keyed function has a unique name, or use a different source to distinguish them.",
2686
- docs: false
2687
- },
2688
- NUXT_B1010: {
2689
- why: (p) => `Failed to read file \`${p.file}\` as it changed during read.`,
2690
- fix: "The file was modified while being read, usually by a concurrent process writing to it. Try restarting the build.",
2691
- docs: false
2692
- },
2693
- NUXT_B1011: {
2694
- why: (p) => `Failed to read file \`${p.file}\`.`,
2695
- fix: "Check that the file exists and is readable, or try clearing the build cache with `nuxt clean`.",
2696
- docs: false
2697
- },
2698
- NUXT_B1012: {
2699
- why: (p) => `Skipping unsafe cache path: ${p.path}. This cache file has a path that escapes the project directory (possible path traversal).`,
2700
- fix: "Delete the cache with `nuxt clean` and rebuild.",
2701
- docs: false
2702
- },
2703
- NUXT_B1013: {
2704
- why: (p) => `Failed to restore cached file \`${p.file}\`.`,
2705
- fix: "Try clearing the build cache with `nuxt clean` and rebuilding from scratch.",
2706
- docs: false
2707
- },
2708
- NUXT_B1014: {
2709
- why: "Problem checking for external configuration files.",
2710
- fix: "This is likely a transient file system error. If it persists, check file permissions in your project root.",
2711
- docs: false
2712
- },
2713
- NUXT_B1015: {
2714
- why: "Falling back to `chokidar-granular` as `@parcel/watcher` cannot be resolved in your project.",
2715
- fix: "Install `@parcel/watcher` for better performance: `npm install -D @parcel/watcher`.",
2716
- docs: false
2717
- },
2718
- NUXT_B1016: {
2719
- why: "Failed to set up the `@parcel/watcher` file watcher.",
2720
- fix: "This is likely an environment or file system issue. Watching for file changes may not work; restart the dev server and, if the problem persists, report it.",
2721
- docs: false
2722
- },
2723
- NUXT_B1017: {
2724
- why: (p) => `Loading \`${p.builder}\` builder failed.`,
2725
- fix: (p) => `Run \`npm install ${p.builder}\` to install it.`,
2726
- docs: false
2727
- },
2728
- NUXT_B1018: {
2729
- why: (p) => `Loading \`${p.builder}\` server builder failed.`,
2730
- fix: (p) => `Run \`npm install ${p.builder}\` to install it.`,
2731
- docs: false
2732
- },
2733
- NUXT_B1019: {
2734
- why: (p) => `Unknown component mode \`${p.mode}\`. This might be an internal Nuxt bug.`,
2735
- fix: "If you are a module author, ensure the component `mode` is set to `client`, `server`, or `all`. Otherwise, please report this issue.",
2736
- docs: false
2737
- },
2738
- NUXT_B1020: {
2739
- why: "`experimental.watcher: \"builder\"` is set but the active builder does not implement `setupWatcher`. Falling back to the default file watcher.",
2740
- fix: "Remove `experimental.watcher` from your `nuxt.config`, or use a builder that supports its own watcher.",
2741
- docs: false
2742
- }
2743
- }
2744
- });
2745
- //#endregion
2746
- //#region src/diagnostics/config.ts
2747
- /**
2748
- * B5xxx
2749
- * Configuration diagnostics.
2750
- *
2751
- * @internal
2752
- */
2753
- const configDiagnostics = /* #__PURE__ */ defineDiagnostics({
2754
- docsBase,
2755
- reporters,
2756
- codes: {
2757
- NUXT_B5001: {
2758
- why: (p) => `No \`compatibilityDate\` is set in \`nuxt.config\`, so the \`${p.fallback}\` fallback is being used.`,
2759
- fix: (p) => `Add \`compatibilityDate: '${p.latest}'\` to your \`nuxt.config.ts\`.`
2760
- },
2761
- NUXT_B5002: {
2762
- why: (p) => `\`@nuxt/webpack-builder\` could not be installed in \`${p.rootDir}\`.`,
2763
- fix: "Install it manually with `npm install -D @nuxt/webpack-builder`, or change the `builder` option to `vite` in `nuxt.config`.",
2764
- docs: false
2765
- },
2766
- NUXT_B5003: {
2767
- why: (p) => `The \`app\` namespace is reserved for Nuxt and exposed to the browser, but \`runtimeConfig.app.${p.key}\` is set.`,
2768
- fix: "Move the key to `runtimeConfig.public` or a custom namespace."
2769
- },
2770
- NUXT_B5004: {
2771
- why: (p) => `External configuration files are not supported: ${p.files}.`,
2772
- fix: "Move these configurations into `nuxt.config.ts` and delete the external config files."
2773
- },
2774
- NUXT_B5005: {
2775
- why: (p) => `Nuxt schema could not be loaded from \`${p.filePath}\`.`,
2776
- fix: "Ensure the file exports a valid object with `defineNuxtSchema()` or as a plain object.",
2777
- docs: false
2778
- },
2779
- NUXT_B5006: {
2780
- why: (p) => `\`${p.option}\` is used in dev mode, which causes a memory leak.`,
2781
- fix: "Remove the hash option from your webpack config.",
2782
- docs: false
2783
- },
2784
- NUXT_B5007: {
2785
- why: "The webpack server config `target` is not set to \"node\".",
2786
- fix: "Set `target: \"node\"` in your webpack server configuration.",
2787
- docs: false
2788
- },
2789
- NUXT_B5009: {
2790
- why: "`@parcel/watcher` cannot be resolved in your project, so `chokidar` is being used instead.",
2791
- fix: "Install `@parcel/watcher` for better file watching: `npm install -D @parcel/watcher`.",
2792
- docs: false
2793
- },
2794
- NUXT_B5010: {
2795
- why: (p) => `Required packages are not installed: ${p.names}.`,
2796
- fix: (p) => `Run \`npm install ${p.install}\` to install them.`,
2797
- docs: false
2798
- },
2799
- NUXT_B5011: {
2800
- why: (p) => `Package \`${p.name}\` is missing.`,
2801
- fix: (p) => `Run \`npx nuxt add ${p.name}\` to install it.`,
2802
- docs: false
2803
- }
2804
- }
2805
- });
2806
- //#endregion
2807
2885
  //#region src/diagnostics/head.ts
2808
2886
  /**
2809
2887
  * B6xxx
@@ -2856,7 +2934,7 @@ const bundlerDiagnostics = /* #__PURE__ */ defineDiagnostics({
2856
2934
  codes: {
2857
2935
  NUXT_B7001: {
2858
2936
  why: "`rollup-plugin-visualizer` is not installed, so bundle analysis cannot run.",
2859
- fix: "Run `npm install -D rollup-plugin-visualizer` to enable bundle analysis.",
2937
+ fix: (p) => `Run \`${p.installCommand}\` to enable bundle analysis.`,
2860
2938
  docs: false
2861
2939
  },
2862
2940
  NUXT_B7002: {
@@ -2886,22 +2964,22 @@ const bundlerDiagnostics = /* #__PURE__ */ defineDiagnostics({
2886
2964
  },
2887
2965
  NUXT_B7007: {
2888
2966
  why: (p) => `The PostCSS plugin \`${p.pluginName}\` could not be loaded.`,
2889
- fix: (p) => `Run \`npm install -D ${p.pluginName}\` to install the PostCSS plugin.`,
2967
+ fix: (p) => `Run \`${p.installCommand}\` to install the PostCSS plugin.`,
2890
2968
  docs: false
2891
2969
  },
2892
2970
  NUXT_B7008: {
2893
2971
  why: "`@vitejs/plugin-vue-jsx` is not installed, so JSX support is unavailable.",
2894
- fix: "Run `npm install -D @vitejs/plugin-vue-jsx` to install it.",
2972
+ fix: (p) => `Run \`${p.installCommand}\` to install it.`,
2895
2973
  docs: false
2896
2974
  },
2897
2975
  NUXT_B7009: {
2898
2976
  why: (p) => `The Babel dependencies required for decorator support are missing: ${p.deps}.`,
2899
- fix: (p) => `Run \`npm install -D ${p.install}\` to install the required Babel decorator dependencies.`,
2977
+ fix: (p) => `Run \`${p.installCommand}\` to install the required Babel decorator dependencies.`,
2900
2978
  docs: false
2901
2979
  },
2902
2980
  NUXT_B7011: {
2903
2981
  why: (p) => `The PostCSS plugin \`${p.pluginName}\` could not be imported, which is unexpected.`,
2904
- fix: (p) => `Run \`npm install -D ${p.pluginName}\` to install it, or report this issue at https://github.com/nuxt/nuxt/issues.`,
2982
+ fix: (p) => `Run \`${p.installCommand}\` to install it, or report this issue at https://github.com/nuxt/nuxt/issues.`,
2905
2983
  docs: false
2906
2984
  },
2907
2985
  NUXT_B7012: {
@@ -2947,63 +3025,4 @@ const bundlerDiagnostics = /* #__PURE__ */ defineDiagnostics({
2947
3025
  }
2948
3026
  });
2949
3027
  //#endregion
2950
- //#region src/dependency.ts
2951
- const isStackblitz = provider === "stackblitz";
2952
- async function ensureDependencyInstalled(names, options = {}) {
2953
- const packages = Array.isArray(names) ? names : [names];
2954
- const nuxt = tryUseNuxt();
2955
- const rootDir = options.rootDir || nuxt?.options.rootDir || process.cwd();
2956
- const searchPaths = options.searchPaths || nuxt?.options.modulesDir || [];
2957
- const missing = findMissing(packages, [
2958
- rootDir,
2959
- ...options.from ? [options.from] : [],
2960
- ...searchPaths
2961
- ]);
2962
- if (missing.length === 0) return true;
2963
- const formattedNames = missing.map((n) => `\`${n}\``).join(", ");
2964
- configDiagnostics.NUXT_B5010({
2965
- names: formattedNames,
2966
- install: missing.join(" ")
2967
- });
2968
- if (isCI) return Array.isArray(names) ? missing : false;
2969
- if (options.prompt === true || options.prompt !== false && !isStackblitz) {
2970
- if (!hasTTY) return Array.isArray(names) ? missing : false;
2971
- if (await logger.prompt(`Do you want to install ${formattedNames}?`, {
2972
- type: "confirm",
2973
- initial: true
2974
- }) !== true) return Array.isArray(names) ? missing : false;
2975
- } else if (!isStackblitz) return Array.isArray(names) ? missing : false;
2976
- logger.start(`Installing ${formattedNames}...`);
2977
- try {
2978
- await addDependency(missing, {
2979
- dev: true,
2980
- cwd: rootDir,
2981
- silent: true
2982
- });
2983
- logger.success(`Installed ${formattedNames}`);
2984
- return true;
2985
- } catch (err) {
2986
- buildDiagnostics.NUXT_B1004({
2987
- packages: missing.join(" "),
2988
- cause: err
2989
- });
2990
- return Array.isArray(names) ? missing : false;
2991
- }
2992
- }
2993
- function findMissing(packages, searchPaths) {
2994
- const missing = [];
2995
- for (const name of packages) {
2996
- if (isResolvable(name, searchPaths)) continue;
2997
- missing.push(name);
2998
- }
2999
- return missing;
3000
- }
3001
- function isResolvable(name, searchPaths) {
3002
- for (const from of searchPaths) if (resolveModulePath(name, {
3003
- from,
3004
- try: true
3005
- })) return true;
3006
- return false;
3007
- }
3008
- //#endregion
3009
- export { DEFAULT_JSX_FILE_EXTENSIONS, DEFAULT_JS_FILE_EXTENSIONS, addBuildPlugin, addComponent, addComponentExports, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, addLayout, addPlugin, addPluginTemplate, addPrerenderRoutes, addRouteMiddleware, addRspackPlugin, addServerHandler, addServerImports, addServerImportsDir, addServerPlugin, addServerScanDir, addServerTemplate, addTemplate, addTypeTemplate, addVitePlugin, addWebpackPlugin, assertNuxtCompatibility, buildDiagnostics, buildNuxt, bundlerDiagnostics, checkNuxtCompatibility, componentDiagnostics, configDiagnostics, createIsIgnored, createResolver, defineNuxtModule, diffNuxtConfig, directoryToURL, ensureDependencyInstalled, extendNuxtSchema, extendPages, extendRouteRules, extendRspackConfig, extendViteConfig, extendWebpackConfig, findPath, getDirectory, getLayerDirectories, getNuxtCtx, getNuxtModuleVersion, getNuxtVersion, hasNuxtCompatibility, hasNuxtModule, hasNuxtModuleCompatibility, headDiagnostics, importModule, installModule, installModules, isIgnored, isNuxt2, isNuxt3, isNuxtMajorVersion, loadNuxt, loadNuxtConfig, loadNuxtModuleInstance, logger, normalizeModuleTranspilePath, normalizePlugin, normalizeSemanticVersion, normalizeTemplate, nuxtCtx, packageName, pageDiagnostics, pluginDiagnostics, requireModule, resolveAlias, resolveDeclarationPath, resolveFiles, resolveIgnorePatterns, resolveModule, resolveModuleWithOptions, resolveNuxtModule, resolvePath, resolveTypePaths, runWithNuxtContext, setBuildOutput, setGlobalHead, tryImportModule, tryRequireModule, tryResolveModule, tryUseNuxt, updateAppConfig, updateRuntimeConfig, updateTemplates, useLogger, useNitro, useNuxt, useRuntimeConfig, writeTypes };
3028
+ export { DEFAULT_JSX_FILE_EXTENSIONS, DEFAULT_JS_FILE_EXTENSIONS, addBuildPlugin, addComponent, addComponentExports, addComponentsDir, addDevServerHandler, addImports, addImportsDir, addImportsSources, addLayout, addPlugin, addPluginTemplate, addPrerenderRoutes, addRouteMiddleware, addRspackPlugin, addServerHandler, addServerImports, addServerImportsDir, addServerPlugin, addServerScanDir, addServerTemplate, addTemplate, addTypeTemplate, addVitePlugin, addWebpackPlugin, assertNuxtCompatibility, buildDiagnostics, buildNuxt, bundlerDiagnostics, checkNuxtCompatibility, componentDiagnostics, configDiagnostics, createIsIgnored, createResolver, defineNuxtModule, diffNuxtConfig, directoryToURL, ensureDependencyInstalled, extendNuxtSchema, extendPages, extendRouteRules, extendRspackConfig, extendViteConfig, extendWebpackConfig, findPath, getAddDependencyCommand, getDirectory, getLayerDirectories, getNuxtCtx, getNuxtModuleVersion, getNuxtVersion, hasNuxtCompatibility, hasNuxtModule, hasNuxtModuleCompatibility, headDiagnostics, importModule, installModule, installModules, isIgnored, isNuxt2, isNuxt3, isNuxtMajorVersion, loadNuxt, loadNuxtConfig, loadNuxtModuleInstance, logger, normalizeModuleTranspilePath, normalizePlugin, normalizeSemanticVersion, normalizeTemplate, nuxtCtx, packageName, pageDiagnostics, pluginDiagnostics, requireModule, resolveAlias, resolveDeclarationPath, resolveFiles, resolveIgnorePatterns, resolveModule, resolveModuleWithOptions, resolveNuxtModule, resolvePath, resolveTypePaths, runWithNuxtContext, setBuildOutput, setGlobalHead, tryImportModule, tryRequireModule, tryResolveModule, tryUseNuxt, updateAppConfig, updateRuntimeConfig, updateTemplates, useLogger, useNitro, useNuxt, useRuntimeConfig, writeTypes };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/kit-nightly",
3
- "version": "5.0.0-29754172.7cdbbb7a",
3
+ "version": "5.0.0-29754187.c12e0090",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/nuxt.git",
@@ -44,7 +44,7 @@
44
44
  "verkit": "^0.3.0"
45
45
  },
46
46
  "devDependencies": {
47
- "@nuxt/schema": "npm:@nuxt/schema-nightly@5.0.0-29754172.7cdbbb7a",
47
+ "@nuxt/schema": "npm:@nuxt/schema-nightly@5.0.0-29754187.c12e0090",
48
48
  "hookable": "^6.1.1",
49
49
  "nitro": "^3.0.260610-beta",
50
50
  "nitropack": "2.13.4",