From 06547c0f26a06aeb9f954d30842f909c69002dc7 Mon Sep 17 00:00:00 2001 From: Noah Allen Date: Thu, 11 Nov 2021 16:20:05 -0800 Subject: [PATCH 1/2] Work around npm pack issue with scoped packages --- index.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/index.ts b/index.ts index 4eeb7d3..dc220d9 100644 --- a/index.ts +++ b/index.ts @@ -317,7 +317,13 @@ function downloadNpmPackage(name: string, version: string, outDir: string): stri const fullName = `${npmName}@${version}`; const cpOpts = { encoding: "utf8", maxBuffer: 100 * 1024 * 1024 } as const; const npmPack = cp.execFileSync("npm", ["pack", fullName, "--json", "--silent"], cpOpts).trim(); - const tarballName = npmPack.endsWith(".tgz") ? npmPack : JSON.parse(npmPack)[0].filename as string; + let tarballName = npmPack.endsWith(".tgz") ? npmPack : JSON.parse(npmPack)[0].filename as string; + + // Npm does not report the correct filename for scoped packages. See https://github.com/npm/cli/issues/3405. + if ( ! fs.existsSync( tarballName ) ) { + tarballName = tarballName.replace(/^@/, '').replace(/\//, '-'); + } + const outPath = path.join(outDir, name); initDir(outPath); const args = os.platform() === "darwin" From f2bb2fccc7088335ea2f979018e4ad7f9576fbf1 Mon Sep 17 00:00:00 2001 From: Noah Allen Date: Thu, 11 Nov 2021 16:25:11 -0800 Subject: [PATCH 2/2] Update code style --- index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.ts b/index.ts index dc220d9..a4ffd45 100644 --- a/index.ts +++ b/index.ts @@ -320,7 +320,7 @@ function downloadNpmPackage(name: string, version: string, outDir: string): stri let tarballName = npmPack.endsWith(".tgz") ? npmPack : JSON.parse(npmPack)[0].filename as string; // Npm does not report the correct filename for scoped packages. See https://github.com/npm/cli/issues/3405. - if ( ! fs.existsSync( tarballName ) ) { + if (!fs.existsSync(tarballName)) { tarballName = tarballName.replace(/^@/, '').replace(/\//, '-'); }