@pnpm/fs.hard-link-dir
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -9,2 +9,3 @@ "use strict"; | ||
const fs_1 = require("fs"); | ||
const logger_1 = require("@pnpm/logger"); | ||
async function hardLinkDir(src, destDirs) { | ||
@@ -15,3 +16,17 @@ if (destDirs.length === 0) | ||
destDirs = destDirs.filter((destDir) => path_1.default.relative(destDir, src) !== ''); | ||
const files = await fs_1.promises.readdir(src); | ||
await _hardLinkDir(src, destDirs, true); | ||
} | ||
exports.hardLinkDir = hardLinkDir; | ||
async function _hardLinkDir(src, destDirs, isRoot) { | ||
let files = []; | ||
try { | ||
files = await fs_1.promises.readdir(src); | ||
} | ||
catch (err) { // eslint-disable-line | ||
if (!isRoot || err.code !== 'ENOENT') | ||
throw err; | ||
(0, logger_1.globalWarn)(`Source directory not found when creating hardLinks for: ${src}. Creating destinations as empty: ${destDirs.join(', ')}`); | ||
await Promise.all(destDirs.map((dir) => fs_1.promises.mkdir(dir, { recursive: true }))); | ||
return; | ||
} | ||
await Promise.all(files.map(async (file) => { | ||
@@ -33,3 +48,3 @@ if (file === 'node_modules') | ||
})); | ||
await hardLinkDir(srcFile, destSubdirs); | ||
await _hardLinkDir(srcFile, destSubdirs); | ||
return; | ||
@@ -52,3 +67,2 @@ } | ||
} | ||
exports.hardLinkDir = hardLinkDir; | ||
async function linkOrCopyFile(srcFile, destFile) { | ||
@@ -55,0 +69,0 @@ try { |
{ | ||
"name": "@pnpm/fs.hard-link-dir", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Hard link (or copy if linking fails) all files from a directory to several target directories.", | ||
@@ -26,4 +26,7 @@ "main": "lib/index.js", | ||
"funding": "https://opencollective.com/pnpm", | ||
"peerDependencies": { | ||
"@pnpm/logger": "^5.0.0" | ||
}, | ||
"devDependencies": { | ||
"@pnpm/fs.hard-link-dir": "2.0.0", | ||
"@pnpm/fs.hard-link-dir": "2.0.1", | ||
"@pnpm/prepare": "0.0.65" | ||
@@ -30,0 +33,0 @@ }, |
Sorry, the diff of this file is not supported yet
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
8785
93
1