Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't write pnpapi binary into own pkg #2457

Merged
merged 3 commits into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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