@nuxt/devtools-nightly 4.0.0-beta.3-29854425.7b9e10f → 4.0.0-beta.3-29854535.ff0512e

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.
@@ -3,13 +3,13 @@ import { onDevtoolsReady, deprecate, registerHostDiagnostics, NUXT_DEVTOOLS_GROU
3
3
  import { logger, useNuxt, addPlugin, addVitePlugin, addTemplate, extendViteConfig, addImports } from '@nuxt/kit';
4
4
  import { colors } from 'consola/utils';
5
5
  import { serveStaticNodeMiddleware } from 'devframe/utils/serve-static';
6
- import { join, dirname, resolve } from 'pathe';
6
+ import { join, dirname, resolve, extname } from 'pathe';
7
7
  import { isLess, isGreaterOrEqual } from 'verkit';
8
8
  import { version as version$1, searchForWorkspaceRoot } from 'vite';
9
9
  import { d as defaultAllowedExtensions, c as createDefaultTabOptions, s as setServerTasksEnabledByDefault } from '../shared/devtools-nightly.C3s9ubDZ.mjs';
10
10
  import { runtimeDir, packageDir } from '../dirs.mjs';
11
11
  import { execFile } from 'node:child_process';
12
- import fs, { readFileSync, existsSync, promises, accessSync, constants } from 'node:fs';
12
+ import fs, { existsSync, readFileSync, promises, accessSync, constants } from 'node:fs';
13
13
  import fsp from 'node:fs/promises';
14
14
  import { promisify } from 'node:util';
15
15
  import { glob } from 'tinyglobby';
@@ -31,9 +31,9 @@ import { createRequire } from 'node:module';
31
31
  import { DEVTOOLS_TERMINALS_DOCK_ID } from '@vitejs/devtools-kit/constants';
32
32
  import { normalizeBaseKey, normalizeKey, createStorage, builtinDrivers } from 'unstorage';
33
33
 
34
- const version = "4.0.0-beta.3-29854425.7b9e10f";
34
+ const version = "4.0.0-beta.3-29854535.ff0512e";
35
35
  const peerDependencies = {
36
- "@nuxt/devtools-assets": "npm:@nuxt/devtools-assets-nightly@4.0.0-beta.3-29854425.7b9e10f",
36
+ "@nuxt/devtools-assets": "npm:@nuxt/devtools-assets-nightly@4.0.0-beta.3-29854535.ff0512e",
37
37
  "@nuxt/kit": "^4.0.0-0 || ^5.0.0-0",
38
38
  nitro: "*",
39
39
  nitropack: "^2.0.0",
@@ -212,12 +212,21 @@ function setupAnalyzeBuildRPC(ctx) {
212
212
  };
213
213
  }
214
214
 
215
+ const MAX_TEXT_PREVIEW = 1e4;
215
216
  function setupAssetsRPC({ nuxt, refresh, options }) {
216
217
  const _imageMetaCache = /* @__PURE__ */ new Map();
217
218
  let cache = null;
218
219
  const extensions = options.assets?.uploadExtensions || defaultAllowedExtensions;
219
220
  const publicDir = resolve(nuxt.options.srcDir, nuxt.options.dir.public);
220
221
  const layerDirs = [publicDir, ...nuxt.options._layers.map((layer) => resolve(layer.cwd, "public"))];
222
+ async function assertInsideAssets(path, action) {
223
+ const resolved = resolve(path);
224
+ const real = await realpathOfNearestAncestor(resolved);
225
+ const realLayerDirs = await Promise.all(layerDirs.filter((dir) => existsSync(dir)).map((dir) => fsp.realpath(dir)));
226
+ if (!realLayerDirs.some((dir) => real === dir || real.startsWith(`${dir}/`)))
227
+ throw new Error(`[Nuxt DevTools] File ${path} is not allowed to ${action}, it's outside of the public directory`);
228
+ return resolved;
229
+ }
221
230
  const refreshDebounced = debounce(() => {
222
231
  cache = null;
223
232
  refresh("getStaticAssets");
@@ -269,6 +278,7 @@ function setupAssetsRPC({ nuxt, refresh, options }) {
269
278
  return await scan();
270
279
  },
271
280
  async getImageMeta(filepath) {
281
+ filepath = await assertInsideAssets(filepath, "read");
272
282
  if (_imageMetaCache.has(filepath))
273
283
  return _imageMetaCache.get(filepath);
274
284
  try {
@@ -282,9 +292,10 @@ function setupAssetsRPC({ nuxt, refresh, options }) {
282
292
  }
283
293
  },
284
294
  async getTextAssetContent(filepath, limit = 300) {
295
+ filepath = await assertInsideAssets(filepath, "read");
285
296
  try {
286
297
  const content = await fsp.readFile(filepath, "utf-8");
287
- return content.slice(0, limit);
298
+ return content.slice(0, Math.min(limit, MAX_TEXT_PREVIEW));
288
299
  } catch (e) {
289
300
  console.error(e);
290
301
  return void 0;
@@ -312,17 +323,8 @@ You can configure it in Nuxt config at \`devtools.assets.uploadExtensions\`.`);
312
323
  const targetStat = await fsp.lstat(finalPath).catch(() => void 0);
313
324
  if (targetStat?.isSymbolicLink())
314
325
  throw new Error(`[Nuxt DevTools] File ${path} is not allowed to upload, it's a symbolic link`);
315
- if (!override) {
316
- try {
317
- await fsp.stat(finalPath);
318
- const base = finalPath.slice(0, finalPath.length - ext.length - 1);
319
- let i = 1;
320
- while (await fsp.access(`${base}-${i}.${ext}`).then(() => true).catch(() => false))
321
- i++;
322
- finalPath = `${base}-${i}.${ext}`;
323
- } catch {
324
- }
325
- }
326
+ if (!override)
327
+ finalPath = await collisionFreePath(finalPath);
326
328
  await fsp.writeFile(finalPath, content, {
327
329
  encoding: encoding ?? "utf-8"
328
330
  });
@@ -331,9 +333,11 @@ You can configure it in Nuxt config at \`devtools.assets.uploadExtensions\`.`);
331
333
  );
332
334
  },
333
335
  async deleteStaticAsset(path) {
334
- return await fsp.unlink(path);
336
+ return await fsp.unlink(await assertInsideAssets(path, "delete"));
335
337
  },
336
338
  async renameStaticAsset(oldPath, newPath) {
339
+ oldPath = await assertInsideAssets(oldPath, "rename");
340
+ newPath = await assertInsideAssets(newPath, "rename to");
337
341
  const exist = cache?.find((asset) => asset.filePath === newPath);
338
342
  if (exist)
339
343
  throw new Error(`[Nuxt DevTools] File ${newPath} already exists, failed to rename`);
@@ -341,6 +345,16 @@ You can configure it in Nuxt config at \`devtools.assets.uploadExtensions\`.`);
341
345
  }
342
346
  };
343
347
  }
348
+ async function collisionFreePath(path, exists = (p) => fsp.access(p).then(() => true, () => false)) {
349
+ if (!await exists(path))
350
+ return path;
351
+ const ext = extname(path);
352
+ const stem = path.slice(0, path.length - ext.length);
353
+ let i = 1;
354
+ while (await exists(`${stem}-${i}${ext}`))
355
+ i++;
356
+ return `${stem}-${i}${ext}`;
357
+ }
344
358
  async function realpathOfNearestAncestor(dir) {
345
359
  try {
346
360
  return await fsp.realpath(dir);
@@ -1889,7 +1903,8 @@ const AGENTS = [
1889
1903
  "bun",
1890
1904
  "deno",
1891
1905
  "nub",
1892
- "aube"
1906
+ "aube",
1907
+ "upm"
1893
1908
  ];
1894
1909
  const LOCKS = {
1895
1910
  "aube-lock.yaml": "aube",
@@ -1898,6 +1913,7 @@ const LOCKS = {
1898
1913
  "bun.lockb": "bun",
1899
1914
  "deno.lock": "deno",
1900
1915
  "nub.lock": "nub",
1916
+ "upm.lock": "upm",
1901
1917
  "pnpm-lock.yaml": "pnpm",
1902
1918
  "pnpm-workspace.yaml": "pnpm",
1903
1919
  "yarn.lock": "yarn",
@@ -1908,6 +1924,7 @@ const INSTALL_METADATA = {
1908
1924
  "node_modules/.aube/": "aube",
1909
1925
  "node_modules/.deno/": "deno",
1910
1926
  "node_modules/.pnpm/": "pnpm",
1927
+ "node_modules/.upm/": "upm",
1911
1928
  "node_modules/.yarn-state.yml": "yarn",
1912
1929
  // yarn v2+ (node-modules)
1913
1930
  "node_modules/.yarn_integrity": "yarn",
@@ -1998,16 +2015,18 @@ async function detect(options = {}) {
1998
2015
  }
1999
2016
  return null;
2000
2017
  }
2018
+ function normalizeAgentVersion(version) {
2019
+ return version?.match(/\d+(\.\d+){0,2}/)?.[0] ?? version;
2020
+ }
2001
2021
  function getNameAndVer(pkg) {
2002
- const handelVer = (version) => version?.match(/\d+(\.\d+){0,2}/)?.[0] ?? version;
2003
2022
  if (typeof pkg.packageManager === "string") {
2004
2023
  const [name, ver] = pkg.packageManager.replace(/^\^/, "").split("@");
2005
- return { name, ver: handelVer(ver) };
2024
+ return { name, ver: normalizeAgentVersion(ver) };
2006
2025
  }
2007
2026
  if (typeof pkg.devEngines?.packageManager?.name === "string") {
2008
2027
  return {
2009
2028
  name: pkg.devEngines.packageManager.name,
2010
- ver: handelVer(pkg.devEngines.packageManager.version)
2029
+ ver: normalizeAgentVersion(pkg.devEngines.packageManager.version)
2011
2030
  };
2012
2031
  }
2013
2032
  return void 0;
@@ -2016,30 +2035,29 @@ async function handlePackageManager(filepath, options) {
2016
2035
  try {
2017
2036
  const content = await fsp.readFile(filepath, "utf8");
2018
2037
  const pkg = options.packageJsonParser ? await options.packageJsonParser(content, filepath) : JSON.parse(content);
2019
- let agent;
2020
2038
  const nameAndVer = getNameAndVer(pkg);
2021
2039
  if (nameAndVer) {
2022
- const name = nameAndVer.name;
2023
- const ver = nameAndVer.ver;
2024
- let version = ver;
2025
- if (name === "yarn" && ver && Number.parseInt(ver) > 1) {
2026
- agent = "yarn@berry";
2027
- version = "berry";
2028
- return { name, agent, version };
2029
- } else if (name === "pnpm" && ver && Number.parseInt(ver) < 7) {
2030
- agent = "pnpm@6";
2031
- return { name, agent, version };
2032
- } else if (AGENTS.includes(name)) {
2033
- agent = name;
2034
- return { name, agent, version };
2035
- } else {
2036
- return options.onUnknown?.(pkg.packageManager) ?? null;
2037
- }
2040
+ return resolveAgent(nameAndVer.name, nameAndVer.ver) ?? options.onUnknown?.(pkg.packageManager) ?? null;
2038
2041
  }
2039
2042
  } catch {
2040
2043
  }
2041
2044
  return null;
2042
2045
  }
2046
+ function resolveAgent(name, ver) {
2047
+ let agent;
2048
+ let version = ver;
2049
+ if (name === "yarn" && ver && Number.parseInt(ver) > 1) {
2050
+ agent = "yarn@berry";
2051
+ version = "berry";
2052
+ return { name, agent, version };
2053
+ } else if (name === "pnpm" && ver && Number.parseInt(ver) < 7) {
2054
+ agent = "pnpm@6";
2055
+ return { name, agent, version };
2056
+ } else if (AGENTS.includes(name)) {
2057
+ agent = name;
2058
+ return { name, agent, version };
2059
+ }
2060
+ }
2043
2061
  function isMetadataYarnClassic(metadataPath) {
2044
2062
  return metadataPath.endsWith(".yarn_integrity");
2045
2063
  }
@@ -3114,7 +3132,7 @@ async function watchStorageMount(storage, mountName, onChange) {
3114
3132
 
3115
3133
  const IGNORE_STORAGE_MOUNTS = ["root", "build", "src", "cache"];
3116
3134
  function shouldIgnoreStorageKey(key) {
3117
- return IGNORE_STORAGE_MOUNTS.includes(key.split(":")[0]);
3135
+ return IGNORE_STORAGE_MOUNTS.includes(normalizeKey(key).split(":")[0]);
3118
3136
  }
3119
3137
  function setupStorageRPC(ctx) {
3120
3138
  const { nuxt } = ctx;
@@ -3178,17 +3196,17 @@ function setupStorageRPC(ctx) {
3178
3196
  }
3179
3197
  },
3180
3198
  async getStorageItem(key) {
3181
- if (!storage)
3199
+ if (!storage || shouldIgnoreStorageKey(key))
3182
3200
  return null;
3183
3201
  return await storage.getItem(key);
3184
3202
  },
3185
3203
  async setStorageItem(key, value) {
3186
- if (!storage)
3204
+ if (!storage || shouldIgnoreStorageKey(key))
3187
3205
  return;
3188
3206
  return await storage.setItem(key, value);
3189
3207
  },
3190
3208
  async removeStorageItem(key) {
3191
- if (!storage)
3209
+ if (!storage || shouldIgnoreStorageKey(key))
3192
3210
  return;
3193
3211
  return await storage.removeItem(key);
3194
3212
  }
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nuxt/devtools",
3
3
  "configKey": "devtools",
4
- "version": "4.0.0-beta.3-29854425.7b9e10f",
4
+ "version": "4.0.0-beta.3-29854535.ff0512e",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.3",
7
7
  "unbuild": "3.6.1"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nuxt/devtools-nightly",
3
3
  "type": "module",
4
- "version": "4.0.0-beta.3-29854425.7b9e10f",
4
+ "version": "4.0.0-beta.3-29854535.ff0512e",
5
5
  "description": "The Nuxt DevTools gives you insights and transparency about your Nuxt App.",
6
6
  "license": "MIT",
7
7
  "homepage": "https://devtools.nuxt.com",
@@ -21,7 +21,7 @@
21
21
  "dist"
22
22
  ],
23
23
  "peerDependencies": {
24
- "@nuxt/devtools-assets": "npm:@nuxt/devtools-assets-nightly@4.0.0-beta.3-29854425.7b9e10f",
24
+ "@nuxt/devtools-assets": "npm:@nuxt/devtools-assets-nightly@4.0.0-beta.3-29854535.ff0512e",
25
25
  "@nuxt/kit": "^4.0.0-0 || ^5.0.0-0",
26
26
  "nitro": "*",
27
27
  "nitropack": "^2.0.0",
@@ -46,7 +46,7 @@
46
46
  "@devframes/hub": "^1.2.0",
47
47
  "@devframes/plugin-code-server": "^1.2.0",
48
48
  "@devframes/plugin-data-inspector": "^1.2.0",
49
- "@nuxt/devtools-kit": "npm:@nuxt/devtools-kit-nightly@4.0.0-beta.3-29854425.7b9e10f",
49
+ "@nuxt/devtools-kit": "npm:@nuxt/devtools-kit-nightly@4.0.0-beta.3-29854535.ff0512e",
50
50
  "@vitejs/devtools": "^0.7.6",
51
51
  "@vitejs/devtools-kit": "^0.7.6",
52
52
  "consola": "^3.4.2",
@@ -80,7 +80,7 @@
80
80
  "@iconify-json/ri": "^1.2.10",
81
81
  "@iconify-json/simple-icons": "^1.2.98",
82
82
  "@iconify-json/tabler": "^1.2.41",
83
- "@nuxt/devtools-assets": "npm:@nuxt/devtools-assets-nightly@4.0.0-beta.3-29854425.7b9e10f",
83
+ "@nuxt/devtools-assets": "npm:@nuxt/devtools-assets-nightly@4.0.0-beta.3-29854535.ff0512e",
84
84
  "@nuxt/kit": "npm:@nuxt/kit-nightly@5.0.0-2610052343-36eafab",
85
85
  "@nuxt/schema": "npm:@nuxt/schema-nightly@5.0.0-2610052343-36eafab",
86
86
  "@parcel/watcher": "^2.6.0",