Skip to content

Commit f7b3869

Browse files
fix: use junction in windows to solve Error: EPERM: operation not per… (#6529)
1 parent 82ce942 commit f7b3869

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

.changeset/chilled-icons-vanish.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"builder-util": patch
3+
---
4+
5+
fix: use `junction` for symlink type when on Windows to solve Error: EPERM: operation not permitted

packages/builder-util/src/fs.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import BluebirdPromise from "bluebird-lst"
22
import { copyFile as _nodeCopyFile } from "fs-extra"
33
import { Stats } from "fs"
4+
import { platform } from "os"
45
import { access, chmod, mkdir, link, lstat, readdir, readlink, stat, symlink, unlink, writeFile } from "fs/promises"
56
import * as path from "path"
67
import { Mode } from "stat-mode"
@@ -283,6 +284,7 @@ export function copyDir(src: string, destination: string, options: CopyDirOption
283284

284285
const createdSourceDirs = new Set<string>()
285286
const links: Array<Link> = []
287+
const symlinkType = platform() === "win32" ? "junction" : "file"
286288
return walk(src, options.filter, {
287289
consume: async (file, stat, parent) => {
288290
if (!stat.isFile() && !stat.isSymbolicLink()) {
@@ -301,7 +303,7 @@ export function copyDir(src: string, destination: string, options: CopyDirOption
301303
links.push({ file: destFile, link: await readlink(file) })
302304
}
303305
},
304-
}).then(() => BluebirdPromise.map(links, it => symlink(it.link, it.file), CONCURRENCY))
306+
}).then(() => BluebirdPromise.map(links, it => symlink(it.link, it.file, symlinkType), CONCURRENCY))
305307
}
306308

307309
// eslint-disable-next-line @typescript-eslint/no-unused-vars

0 commit comments

Comments
 (0)