vite-plugin-utils
Advanced tools
Comparing version 0.3.7 to 0.4.0
@@ -119,11 +119,16 @@ import fs from 'node:fs'; | ||
}; | ||
export function node_modules(root, count = 0) { | ||
const p = path.join(root, 'node_modules'); | ||
if (fs.existsSync(p)) { | ||
return p; | ||
const VOLUME_RE = /^[A-Z]:/i; | ||
export function node_modules(root, paths = []) { | ||
if (!root) | ||
return paths; | ||
if (!(root.startsWith('/') || VOLUME_RE.test(root))) | ||
return paths; | ||
const p = path.posix.join(normalizePath(root), 'node_modules'); | ||
if (fs.existsSync(p) && fs.statSync(p).isDirectory()) { | ||
paths = paths.concat(p); | ||
} | ||
if (count >= 19) { | ||
throw new Error(`Can not found node_modules directory.\n with: ${root}`); | ||
} | ||
return node_modules(path.join(root, '..'), count + 1); | ||
root = path.posix.join(root, '..'); | ||
return (root === '/' || /^[A-Z]:$/i.test(root)) | ||
? paths | ||
: node_modules(root, paths); | ||
} |
@@ -142,11 +142,16 @@ import fs from 'node:fs' | ||
export function node_modules(root: string, count = 0): string { | ||
const p = path.join(root, 'node_modules') | ||
if (fs.existsSync(p)) { | ||
return p | ||
const VOLUME_RE = /^[A-Z]:/i | ||
export function node_modules(root: string, paths: string[] = []): string[] { | ||
if (!root) return paths | ||
if (!(root.startsWith('/') || VOLUME_RE.test(root))) return paths | ||
const p = path.posix.join(normalizePath(root), 'node_modules') | ||
if (fs.existsSync(p) && fs.statSync(p).isDirectory()) { | ||
paths = paths.concat(p) | ||
} | ||
if (count >= 19) { | ||
throw new Error(`Can not found node_modules directory.\n with: ${root}`) | ||
} | ||
return node_modules(path.join(root, '..'), count + 1) | ||
root = path.posix.join(root, '..') | ||
return (root === '/' || /^[A-Z]:$/i.test(root)) | ||
? paths | ||
: node_modules(root, paths) | ||
} |
{ | ||
"name": "vite-plugin-utils", | ||
"description": "A collection of opinionated Vite plugin utils", | ||
"version": "0.3.7", | ||
"version": "0.4.0", | ||
"type": "module", | ||
@@ -6,0 +6,0 @@ "main": "", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29340
11
884