diff --git a/index.ts b/index.ts index 4eeb7d3..a4ffd45 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"