castlabs / electron-releases

castLabs Electron for Content Security
https://castlabs.com/resources/downstream/
MIT License
222 stars 42 forks source link

`Error: EEXIST: file already exists, symlink 'Versions/Current/Electron Framework'` with yarn classic #188

Open eXhumer opened 1 day ago

eXhumer commented 1 day ago

I use yarn classic (v1.22.22) as my package manager and I keep receiving Error: EEXIST: file already exists, symlink 'Versions/Current/Electron Framework' -> '/Users/exhumer/Projects/exviewer/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Electron Framework' when I try yarn upgrade or yarn sometimes. If I re-run the same command twice, the problem doesn't appear and finishes the process without any error. It seems like if an existing symlink exist on macOS with the yarn package manager specifically, it fails the install script. The issue doesn't seem to appear if I use the npm package manager instead.

[4/4] 🔨  Rebuilding all packages...
error /Users/exhumer/Projects/exviewer/node_modules/electron: Command failed.
Exit code: 1
Command: node install.js
Arguments: 
Directory: /Users/exhumer/Projects/exviewer/node_modules/electron
Output:
Error: EEXIST: file already exists, symlink 'Versions/Current/Electron Framework' -> '/Users/exhumer/Projects/exviewer/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Electron Framework'
    at async Object.symlink (node:internal/fs/promises:1001:10)
    at async Extractor.extractEntry (/Users/exhumer/Projects/exviewer/node_modules/extract-zip/index.js:130:7)
    at async ZipFile.<anonymous> (/Users/exhumer/Projects/exviewer/node_modules/extract-zip/index.js:65:11)
info Visit https://yarnpkg.com/en/docs/cli/upgrade for documentation about this command.

Is there any consideration to maybe delete all contents in the distPath before trying to extract files into it? This would prevent this issue from appearing.

https://github.com/castlabs/electron-releases/blob/da9eb56bdcb9093db0c0b0c1a66e8bdb4f0f267e/install.js#L73-L90

eXhumer commented 1 day ago

Adding fs.rmSync(distPath, { recursive: true, force: true }); before the calling extract method seems to fix the issue.