From a104ce9fef81fdb8a669ab74810d1addba3f2281 Mon Sep 17 00:00:00 2001 From: Evan Wallace Date: Sat, 13 Mar 2021 13:24:14 -0800 Subject: [PATCH] attempt to fix pnpm hard link issues --- CHANGELOG.md | 6 ++++++ lib/install.ts | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2d1d8cffc5..3d9f304fbba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +* Avoid mutating the binary executable file in place ([#963](https://github.com/evanw/esbuild/issues/963)) + + This release changes the install script for the `esbuild` npm package to use the "rename a temporary file" approach instead of the "write the file directly" approach to replace the `esbuild` command stub file with the real binary executable. This should hopefully work around a problem with the [pnpm](https://pnpm.js.org/) package manager and its use of hard links. + ## 0.9.2 * Fix export name annotations in CommonJS output for node ([#960](https://github.com/evanw/esbuild/issues/960)) diff --git a/lib/install.ts b/lib/install.ts index e075cf1fb3d..48bd79581fd 100644 --- a/lib/install.ts +++ b/lib/install.ts @@ -222,7 +222,13 @@ function installDirectly(name: string) { fs.copyFileSync(process.env.ESBUILD_BINARY_PATH, binPath); validateBinaryVersion(binPath); } else { - installBinaryFromPackage(name, 'bin/esbuild', binPath) + // Write to a temporary file, then move the file into place. This is an + // attempt to avoid problems with package managers like pnpm which will + // usually turn each file into a hard link. We don't want to mutate the + // hard-linked file which may be shared with other files. + const tempBinPath = binPath + '__'; + installBinaryFromPackage(name, 'bin/esbuild', tempBinPath) + .then(() => fs.renameSync(tempBinPath, binPath)) .catch(e => setImmediate(() => { throw e; })); } }