@pnpm/fs.hard-link-dir
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -20,6 +20,6 @@ "use strict"; | ||
if ((await fs_1.promises.lstat(srcFile)).isDirectory()) { | ||
await Promise.all(destDirs.map(async (destDir) => { | ||
const destFile = path_1.default.join(destDir, file); | ||
const destSubdirs = await Promise.all(destDirs.map(async (destDir) => { | ||
const destSubdir = path_1.default.join(destDir, file); | ||
try { | ||
await fs_1.promises.mkdir(destFile, { recursive: true }); | ||
await fs_1.promises.mkdir(destSubdir, { recursive: true }); | ||
} | ||
@@ -30,4 +30,5 @@ catch (err) { // eslint-disable-line | ||
} | ||
return hardLinkDir(srcFile, [destFile]); | ||
return destSubdir; | ||
})); | ||
await hardLinkDir(srcFile, destSubdirs); | ||
return; | ||
@@ -38,13 +39,10 @@ } | ||
try { | ||
await linkOrCopy(srcFile, destFile); | ||
await linkOrCopyFile(srcFile, destFile); | ||
} | ||
catch (err) { // eslint-disable-line | ||
if (err.code === 'ENOENT') { | ||
await fs_1.promises.mkdir(destDir, { recursive: true }); | ||
await linkOrCopy(srcFile, destFile); | ||
// Ignore broken symlinks | ||
return; | ||
} | ||
if (err.code !== 'EEXIST') { | ||
throw err; | ||
} | ||
throw err; | ||
} | ||
@@ -55,2 +53,17 @@ })); | ||
exports.hardLinkDir = hardLinkDir; | ||
async function linkOrCopyFile(srcFile, destFile) { | ||
try { | ||
await linkOrCopy(srcFile, destFile); | ||
} | ||
catch (err) { // eslint-disable-line | ||
if (err.code === 'ENOENT') { | ||
await fs_1.promises.mkdir(path_1.default.dirname(destFile), { recursive: true }); | ||
await linkOrCopy(srcFile, destFile); | ||
return; | ||
} | ||
if (err.code !== 'EEXIST') { | ||
throw err; | ||
} | ||
} | ||
} | ||
/* | ||
@@ -57,0 +70,0 @@ * This function could be optimized because we don't really need to try linking again |
{ | ||
"name": "@pnpm/fs.hard-link-dir", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Hard link (or copy if linking fails) all files from a directory to several target directories.", | ||
@@ -28,3 +28,3 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@pnpm/fs.hard-link-dir": "1.0.2", | ||
"@pnpm/fs.hard-link-dir": "1.0.3", | ||
"@pnpm/prepare": "0.0.62" | ||
@@ -31,0 +31,0 @@ }, |
Sorry, the diff of this file is not supported yet
7651
79