Skip to content
This repository was archived by the owner on Sep 17, 2023. It is now read-only.

Commit 3a2acaf

Browse files
committed
fix(npm): use symlink in node_modules/.bin
- removes npm dependency on `tmp` - simplifies logic originally sourced from the esbuild install flow - favor a symlink over a hardlink to avoid the npm error referenced in the issue Closes #115
1 parent cca8ab0 commit 3a2acaf

File tree

4 files changed

+5
-35
lines changed

4 files changed

+5
-35
lines changed

npm/binary-install.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Binary {
4242
}
4343
this.url = url;
4444
this.name = name;
45-
this.installDirectory = join(__dirname, "../@typescript-tools/rust-implementation/bin");
45+
this.installDirectory = join(__dirname, "../bin");
4646

4747
if (!existsSync(this.installDirectory)) {
4848
mkdirSync(this.installDirectory, { recursive: true });

npm/install.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const fs = require('fs')
22
const path = require('path')
3-
const tmp = require('tmp')
43
const getBinary = require('./get-binary')
54

65
const binaryName = 'monorepo'
@@ -13,25 +12,17 @@ const nodeModulesBinDir = path.resolve(nodeModulesDir, '.bin')
1312
// Link the downloaded binary into the node_modules/.bin directory.
1413
// Inspiration from https://github.com/evanw/esbuild/releases/tag/v0.13.4
1514
const linkBinaryIntoBin = () => {
16-
const tempPath = tmp.tmpNameSync({ tmpdir: nodeModulesBinDir })
1715
const existingPath = path.resolve(downloadDir, binaryName)
1816
const desiredPath = path.resolve(nodeModulesBinDir, binaryName)
1917

20-
// First, link the binary with a temporary file. If this fails and throw an error,
21-
// then we'll end up doing nothing. This uses a hard link to avoid taking up
22-
// additional space on the file system.
23-
fs.linkSync(existingPath, tempPath)
24-
25-
// Then use rename to atomically replace the target file with the temporary file.
26-
// If this fails and throws an error, we'll end up leaving the temporary file there,
27-
// which is harmless.
28-
fs.renameSync(tempPath, desiredPath)
18+
fs.symlinkSync(existingPath, desiredPath)
2919

3020
// By default, the downloaded file preserves the mtime of the binary created by GitHub
3121
// Actions. For a seamless GNU Make experience on local machines, we want to update the
3222
// mtime of this binary to the time of download.
3323
const now = new Date()
3424
fs.utimesSync(desiredPath, now, now)
25+
fs.utimesSync(existingPath, now, now)
3526
}
3627

3728
// Downloaded binary to /bin/{ name }

package-lock.json

Lines changed: 1 addition & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
"dependencies": {
2323
"axios": "0.26.1",
2424
"rimraf": "3.0.2",
25-
"tar": "6.1.11",
26-
"tmp": "0.2.1"
25+
"tar": "6.1.11"
2726
},
2827
"devDependencies": {
2928
"@codedependant/semantic-release-docker": "4.0.0",

0 commit comments

Comments
 (0)