From 52b7f86ed5029cccd9d46923e17e7c1f0cef4686 Mon Sep 17 00:00:00 2001 From: Chris Moesel Date: Sat, 21 Dec 2024 12:34:09 -0500 Subject: [PATCH] Avoid using Dirent.path and Dirent.parentPath since they are not available in earlier Node 18.x versions Dirent.path was added in Node 18.17.0 and then deprecated in Node 18.20.0. Dirent.parentPath was added in Node 18.20.0. In order to keep compatibility with versions of Node before 18.17.0, don't use Dirent.path or Dirent.parentPath. --- src/cache/DiskBasedPackageCache.ts | 2 +- src/virtual/DiskBasedVirtualPackage.ts | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/cache/DiskBasedPackageCache.ts b/src/cache/DiskBasedPackageCache.ts index f379f5a..11f5525 100644 --- a/src/cache/DiskBasedPackageCache.ts +++ b/src/cache/DiskBasedPackageCache.ts @@ -65,7 +65,7 @@ export class DiskBasedPackageCache implements PackageCache { return fs .readdirSync(contentPath, { withFileTypes: true }) .filter(entry => entry.isFile() && /^[^.].*\.json$/i.test(entry.name)) - .map(entry => path.resolve(entry.path, entry.name)) + .map(entry => path.resolve(contentPath, entry.name)) .sort(); } diff --git a/src/virtual/DiskBasedVirtualPackage.ts b/src/virtual/DiskBasedVirtualPackage.ts index efc5aa1..96655c4 100644 --- a/src/virtual/DiskBasedVirtualPackage.ts +++ b/src/virtual/DiskBasedVirtualPackage.ts @@ -138,11 +138,9 @@ function getFilePaths(paths: string[], recursive: boolean): string[] { } else if (stat.isDirectory()) { fs.readdirSync(p, { withFileTypes: true }).forEach(entry => { if (entry.isFile()) { - filePaths.add(path.resolve(entry.parentPath, entry.name)); + filePaths.add(path.resolve(p, entry.name)); } else if (recursive && entry.isDirectory()) { - getFilePaths([path.resolve(entry.parentPath, entry.name)], recursive).forEach(fp => - filePaths.add(fp) - ); + getFilePaths([path.resolve(p, entry.name)], recursive).forEach(fp => filePaths.add(fp)); } }); }