@nuxt/kit-nightly 4.6.0-29776167.796cdae2 → 4.6.0-29778602.bfddf2f0

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
@@ -144,14 +144,31 @@ interface LoadNuxtConfigOptions {
144
144
  */
145
145
  onConfigResolved?: (context: ResolvedNuxtConfigContext) => void | Promise<void>;
146
146
  }
147
- /** A single difference between two resolved Nuxt configurations. */
148
- interface NuxtConfigDiffEntry {
149
- /** Dot-separated path of the changed value, such as `modules` or `runtimeConfig.public.foo`. */
150
- key: string;
151
- type: 'added' | 'changed' | 'removed';
152
- newValue?: unknown;
153
- oldValue?: unknown;
147
+ interface NuxtConfigDiffLocation {
148
+ /**
149
+ * Property path of the changed value, with array indices as numbers: `['modules']`,
150
+ * `['runtimeConfig', 'public', 'foo']`, `['modules', 0]`. Prefer this over {@link label} when
151
+ * reading the value back out of a config object.
152
+ */
153
+ path: Array<string | number>;
154
+ /**
155
+ * {@link path} written as a property accessor, for display and for matching against a known
156
+ * key: `ssr`, `runtimeConfig.public.foo`, `modules[0]`, `nitro.routeRules["/index.html"].ssr`.
157
+ */
158
+ label: string;
154
159
  }
160
+ /** A single difference between two resolved Nuxt configurations. */
161
+ type NuxtConfigDiffEntry = (NuxtConfigDiffLocation & {
162
+ type: 'added';
163
+ newValue: unknown;
164
+ }) | (NuxtConfigDiffLocation & {
165
+ type: 'removed';
166
+ oldValue: unknown;
167
+ }) | (NuxtConfigDiffLocation & {
168
+ type: 'changed';
169
+ newValue: unknown;
170
+ oldValue: unknown;
171
+ });
155
172
  /**
156
173
  * Compare two `rawConfig` snapshots (as provided to `onConfigResolved`) and return the
157
174
  * differences between them.
package/dist/index.mjs CHANGED
@@ -28,9 +28,9 @@ import * as nodeUtil from "node:util";
28
28
  import { readFile, rm, stat } from "node:fs/promises";
29
29
  import { homedir } from "node:os";
30
30
  import { klona } from "klona";
31
- import { diff } from "ohash/utils";
31
+ import microdiff from "microdiff";
32
32
  import destr from "destr";
33
- import { hash } from "ohash";
33
+ import { createHash } from "node:crypto";
34
34
  import { isAbsolute as isAbsolute$1, join as join$1, resolve as resolve$1 } from "node:path";
35
35
  //#region ../../node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/shared/untyped.Br_uXjZG.mjs
36
36
  function getType(val) {
@@ -1221,6 +1221,7 @@ async function getAddDependencyCommand(names, cwd, options = {}) {
1221
1221
  //#region src/internal/jiti.ts
1222
1222
  const LOADER_ERROR_CODES = /* @__PURE__ */ new Set([
1223
1223
  "ERR_MODULE_NOT_FOUND",
1224
+ "ERR_IMPORT_ATTRIBUTE_MISSING",
1224
1225
  "ERR_UNKNOWN_FILE_EXTENSION",
1225
1226
  "ERR_UNSUPPORTED_DIR_IMPORT",
1226
1227
  "ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING",
@@ -1231,15 +1232,14 @@ const LOADER_ERROR_CODES = /* @__PURE__ */ new Set([
1231
1232
  * Whether a failed `import()` failed because the runtime would not load the file, rather than
1232
1233
  * because the file threw once it was running.
1233
1234
  *
1235
+ * A resolution failure anywhere in the imported file's static graph counts, not just one for the
1236
+ * file itself.
1237
+ *
1234
1238
  * @param error the error the failed `import()` rejected with
1235
- * @param target the URL that was imported, used to tell an unresolved import of `target` itself
1236
- * apart from one the file made after it had started running
1237
1239
  */
1238
- function isLoaderError(error, target) {
1239
- const { code, url } = error ?? {};
1240
- if (typeof code !== "string" || !LOADER_ERROR_CODES.has(code)) return false;
1241
- if (code === "ERR_MODULE_NOT_FOUND" && target) return url === target;
1242
- return true;
1240
+ function isLoaderError(error) {
1241
+ const { code } = error ?? {};
1242
+ return typeof code === "string" && LOADER_ERROR_CODES.has(code);
1243
1243
  }
1244
1244
  let cached;
1245
1245
  /**
@@ -1560,7 +1560,7 @@ async function loadNuxtModuleInstance(nuxtModule, nuxt = useNuxt()) {
1560
1560
  try {
1561
1561
  resolvedNuxtModule = await import(src).then((r) => interopDefault(r));
1562
1562
  } catch (nativeError) {
1563
- if (!isLoaderError(nativeError, src)) throw kitDiagnostics.NUXT_B8018({
1563
+ if (!isLoaderError(nativeError)) throw kitDiagnostics.NUXT_B8018({
1564
1564
  module: nuxtModule,
1565
1565
  error: String(nativeError),
1566
1566
  cause: nativeError
@@ -2069,17 +2069,52 @@ function _isDirectory(path) {
2069
2069
  }
2070
2070
  //#endregion
2071
2071
  //#region src/loader/config.ts
2072
+ const IDENTIFIER_RE = /^[a-z_$][\w$]*$/i;
2073
+ function formatLabel(path) {
2074
+ let label = "";
2075
+ for (const segment of path) if (typeof segment === "number") label += `[${segment}]`;
2076
+ else if (IDENTIFIER_RE.test(segment)) label += label ? `.${segment}` : segment;
2077
+ else label += `[${JSON.stringify(segment)}]`;
2078
+ return label;
2079
+ }
2072
2080
  /**
2073
2081
  * Compare two `rawConfig` snapshots (as provided to `onConfigResolved`) and return the
2074
2082
  * differences between them.
2075
2083
  */
2076
2084
  function diffNuxtConfig(oldConfig, newConfig) {
2077
- return diff(oldConfig, newConfig).map((entry) => ({
2078
- key: entry.key,
2079
- type: entry.type,
2080
- newValue: entry.newValue?.value,
2081
- oldValue: entry.oldValue?.value
2082
- }));
2085
+ const entries = [];
2086
+ for (const entry of microdiff(oldConfig, newConfig)) {
2087
+ const location = {
2088
+ path: entry.path,
2089
+ label: formatLabel(entry.path)
2090
+ };
2091
+ switch (entry.type) {
2092
+ case "CREATE":
2093
+ entries.push({
2094
+ ...location,
2095
+ type: "added",
2096
+ newValue: entry.value
2097
+ });
2098
+ break;
2099
+ case "REMOVE":
2100
+ entries.push({
2101
+ ...location,
2102
+ type: "removed",
2103
+ oldValue: entry.oldValue
2104
+ });
2105
+ break;
2106
+ case "CHANGE": if (!isSameFunction(entry.oldValue, entry.value)) entries.push({
2107
+ ...location,
2108
+ type: "changed",
2109
+ newValue: entry.value,
2110
+ oldValue: entry.oldValue
2111
+ });
2112
+ }
2113
+ }
2114
+ return entries;
2115
+ }
2116
+ function isSameFunction(a, b) {
2117
+ return typeof a === "function" && typeof b === "function" && a.toString() === b.toString();
2083
2118
  }
2084
2119
  const CONFIG_EXTENSIONS = [
2085
2120
  ".js",
@@ -2139,7 +2174,7 @@ async function loadNuxtConfig(opts) {
2139
2174
  try {
2140
2175
  return await import(url.href);
2141
2176
  } catch (error) {
2142
- if (!isLoaderError(error, url.href)) throw error;
2177
+ if (!isLoaderError(error)) throw error;
2143
2178
  jitiPromise ??= loadJiti({ rootDir: rootCwd }).then((mod) => mod?.createJiti(join(rootCwd, "nuxt.config"), {
2144
2179
  interopDefault: true,
2145
2180
  moduleCache: false,
@@ -3201,6 +3236,9 @@ function addTypeTemplate(_template, context) {
3201
3236
  });
3202
3237
  return template;
3203
3238
  }
3239
+ function hashPath(path) {
3240
+ return createHash("sha256").update(path).digest("base64url").slice(0, 10).replace(/-/g, "_");
3241
+ }
3204
3242
  /**
3205
3243
  * Normalize a nuxt template object
3206
3244
  */
@@ -3212,7 +3250,7 @@ function normalizeTemplate(template, buildDir) {
3212
3250
  if (!existsSync(template.src)) throw kitDiagnostics.NUXT_B8009({ template: template.src });
3213
3251
  if (!template.filename) {
3214
3252
  const srcPath = parse(template.src);
3215
- template.filename = template.fileName || `${basename(srcPath.dir)}.${srcPath.name}.${hash(template.src).replace(/-/g, "_")}${srcPath.ext}`;
3253
+ template.filename = template.fileName || `${basename(srcPath.dir)}.${srcPath.name}.${hashPath(template.src)}${srcPath.ext}`;
3216
3254
  }
3217
3255
  }
3218
3256
  if (!template.src && !template.getContents) throw kitDiagnostics.NUXT_B8010({ template: template.filename || template.src || JSON.stringify(template) });
@@ -3467,7 +3505,8 @@ async function _generateTypes(nuxt) {
3467
3505
  exclude: [...sharedExclude]
3468
3506
  });
3469
3507
  const aliases = nuxt.options.alias;
3470
- const basePath = tsConfig.compilerOptions.baseUrl ? resolve(nuxt.options.buildDir, tsConfig.compilerOptions.baseUrl) : nuxt.options.buildDir;
3508
+ const baseUrl = isV5OrHigher ? void 0 : tsConfig.compilerOptions.baseUrl;
3509
+ const basePath = baseUrl ? resolve(nuxt.options.buildDir, baseUrl) : nuxt.options.buildDir;
3471
3510
  tsConfig.compilerOptions ||= {};
3472
3511
  tsConfig.compilerOptions.paths ||= {};
3473
3512
  tsConfig.include ||= [];
@@ -3535,6 +3574,7 @@ async function _generateTypes(nuxt) {
3535
3574
  });
3536
3575
  const nonRootLayerDirs = layerDirs.map((dirs) => dirs.root).filter((root) => !rootDirWithSlash.startsWith(root));
3537
3576
  async function resolveConfig(tsConfig) {
3577
+ if (isV5OrHigher) Reflect.deleteProperty(tsConfig.compilerOptions, "baseUrl");
3538
3578
  for (const alias in tsConfig.compilerOptions.paths) {
3539
3579
  const paths = tsConfig.compilerOptions.paths[alias];
3540
3580
  tsConfig.compilerOptions.paths[alias] = [...new Set(await Promise.all(paths.map(async (path) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/kit-nightly",
3
- "version": "4.6.0-29776167.796cdae2",
3
+ "version": "4.6.0-29778602.bfddf2f0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/nuxt.git",
@@ -27,9 +27,9 @@
27
27
  "exsolve": "^1.1.1",
28
28
  "ignore": "^7.0.6",
29
29
  "klona": "^2.0.6",
30
+ "microdiff": "^1.6.0",
30
31
  "nostics": "^1.2.0",
31
32
  "nypm": "^0.6.9",
32
- "ohash": "^2.0.11",
33
33
  "pathe": "^2.0.3",
34
34
  "pkg-types": "^2.3.1",
35
35
  "rc9": "^3.0.1",
@@ -69,7 +69,7 @@
69
69
  }
70
70
  },
71
71
  "devDependencies": {
72
- "@nuxt/schema": "npm:@nuxt/schema-nightly@4.6.0-29776167.796cdae2",
72
+ "@nuxt/schema": "npm:@nuxt/schema-nightly@4.6.0-29778602.bfddf2f0",
73
73
  "c12": "4.0.0-beta.5",
74
74
  "chokidar": "^5.0.0",
75
75
  "dotenv": "^17.4.2",