Skip to content

Commit

Permalink
Use system temp directory to download using npm and ignore temp direc…
Browse files Browse the repository at this point in the history
…tory remove errors (#551)
  • Loading branch information
Djaler authored Nov 20, 2020
1 parent b79bae6 commit ae16a0d
Showing 1 changed file with 6 additions and 2 deletions.
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

0 comments on commit ae16a0d

Please sign in to comment.