Skip to content

Commit 4eb1713

Browse files
authored
fix: don't write pnpapi binary into own pkg (#2457)
1 parent 7cae769 commit 4eb1713

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

lib/npm/node-platform.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import fs = require('fs');
22
import os = require('os');
33
import path = require('path');
44

5+
declare const ESBUILD_VERSION: string;
6+
57
// This feature was added to give external code a way to modify the binary
68
// path without modifying the code itself. Do not remove this because
79
// external code relies on this.
@@ -179,16 +181,22 @@ by esbuild to install the correct binary executable for your current platform.`)
179181
// it's inside a virtual file system and the OS needs it in the real file
180182
// system. So we need to copy the file out of the virtual file system into
181183
// the real file system.
182-
let isYarnPnP = false;
184+
let pnpapi: any;
183185
try {
184-
require('pnpapi');
185-
isYarnPnP = true;
186+
pnpapi = require('pnpapi');
186187
} catch (e) {
187188
}
188-
if (isYarnPnP) {
189-
const esbuildLibDir = path.dirname(require.resolve('esbuild'));
190-
const binTargetPath = path.join(esbuildLibDir, `pnpapi-${pkg}-${path.basename(subpath)}`);
189+
if (pnpapi) {
190+
const root = pnpapi.getPackageInformation(pnpapi.topLevel).packageLocation;
191+
const binTargetPath = path.join(
192+
root,
193+
'node_modules',
194+
'.cache',
195+
'esbuild',
196+
`pnpapi-${pkg}-${ESBUILD_VERSION}-${path.basename(subpath)}`,
197+
);
191198
if (!fs.existsSync(binTargetPath)) {
199+
fs.mkdirSync(path.dirname(binTargetPath), { recursive: true });
192200
fs.copyFileSync(binPath, binTargetPath);
193201
fs.chmodSync(binTargetPath, 0o755);
194202
}

scripts/esbuild.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const buildNeutralLib = (esbuildPath) => {
4949
'--outfile=' + path.join(binDir, 'esbuild'),
5050
'--bundle',
5151
'--target=' + nodeTarget,
52+
'--define:ESBUILD_VERSION=' + JSON.stringify(version),
5253
'--external:esbuild',
5354
'--platform=node',
5455
'--log-level=warning',

0 commit comments

Comments
 (0)