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

Use system temp directory to download using npm and ignore temp directory remove errors #551

Merged
merged 2 commits into from
Nov 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function extractFileFromTarGzip(buffer: Buffer, file: string): Buffer {
}

function installUsingNPM(name: string, file: string): Buffer {
const installDir = path.join(__dirname, '.install');
const installDir = path.join(os.tmpdir(), 'esbuild', 'install', version);
fs.mkdirSync(installDir, { recursive: true });
fs.writeFileSync(path.join(installDir, 'package.json'), '{}');

Expand All @@ -168,7 +168,11 @@ function installUsingNPM(name: string, file: string): Buffer {
child_process.execSync(`npm install --loglevel=error --prefer-offline --no-audit --progress=false ${name}@${version}`,
{ cwd: installDir, stdio: 'pipe', env });
const buffer = fs.readFileSync(path.join(installDir, 'node_modules', name, file));
removeRecursive(installDir);
try {
removeRecursive(installDir);
} catch (e) {
console.warn(e);
}
return buffer;
}

Expand Down