Skip to content

Commit

Permalink
fix: use junction in windows to solve Error: EPERM: operation not per… (
Browse files Browse the repository at this point in the history
  • Loading branch information
frankwang1101 authored Jan 7, 2022
1 parent 82ce942 commit f7b3869
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/chilled-icons-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"builder-util": patch
---

fix: use `junction` for symlink type when on Windows to solve Error: EPERM: operation not permitted
4 changes: 3 additions & 1 deletion packages/builder-util/src/fs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import BluebirdPromise from "bluebird-lst"
import { copyFile as _nodeCopyFile } from "fs-extra"
import { Stats } from "fs"
import { platform } from "os"
import { access, chmod, mkdir, link, lstat, readdir, readlink, stat, symlink, unlink, writeFile } from "fs/promises"
import * as path from "path"
import { Mode } from "stat-mode"
Expand Down Expand Up @@ -283,6 +284,7 @@ export function copyDir(src: string, destination: string, options: CopyDirOption

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

// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down

0 comments on commit f7b3869

Please sign in to comment.