From ae16a0d334874745004cb381e035dfdc5bec9da0 Mon Sep 17 00:00:00 2001 From: Kirill Romanov Date: Fri, 20 Nov 2020 23:22:34 +0300 Subject: [PATCH] Use system temp directory to download using npm and ignore temp directory remove errors (#551) --- lib/install.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/install.ts b/lib/install.ts index 558d84e75d4..e7e66311c10 100644 --- a/lib/install.ts +++ b/lib/install.ts @@ -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'), '{}'); @@ -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; }