Skip to content

Commit

Permalink
fix: don't write pnpapi binary into own pkg (#2457)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaskuske committed Aug 29, 2022
1 parent 7cae769 commit 4eb1713
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/npm/node-platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import fs = require('fs');
import os = require('os');
import path = require('path');

declare const ESBUILD_VERSION: string;

// This feature was added to give external code a way to modify the binary
// path without modifying the code itself. Do not remove this because
// external code relies on this.
Expand Down Expand Up @@ -179,16 +181,22 @@ by esbuild to install the correct binary executable for your current platform.`)
// it's inside a virtual file system and the OS needs it in the real file
// system. So we need to copy the file out of the virtual file system into
// the real file system.
let isYarnPnP = false;
let pnpapi: any;
try {
require('pnpapi');
isYarnPnP = true;
pnpapi = require('pnpapi');
} catch (e) {
}
if (isYarnPnP) {
const esbuildLibDir = path.dirname(require.resolve('esbuild'));
const binTargetPath = path.join(esbuildLibDir, `pnpapi-${pkg}-${path.basename(subpath)}`);
if (pnpapi) {
const root = pnpapi.getPackageInformation(pnpapi.topLevel).packageLocation;
const binTargetPath = path.join(
root,
'node_modules',
'.cache',
'esbuild',
`pnpapi-${pkg}-${ESBUILD_VERSION}-${path.basename(subpath)}`,
);
if (!fs.existsSync(binTargetPath)) {
fs.mkdirSync(path.dirname(binTargetPath), { recursive: true });
fs.copyFileSync(binPath, binTargetPath);
fs.chmodSync(binTargetPath, 0o755);
}
Expand Down
1 change: 1 addition & 0 deletions scripts/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const buildNeutralLib = (esbuildPath) => {
'--outfile=' + path.join(binDir, 'esbuild'),
'--bundle',
'--target=' + nodeTarget,
'--define:ESBUILD_VERSION=' + JSON.stringify(version),
'--external:esbuild',
'--platform=node',
'--log-level=warning',
Expand Down

0 comments on commit 4eb1713

Please sign in to comment.