Skip to content

Commit

Permalink
fix(debug): print tar output
Browse files Browse the repository at this point in the history
  • Loading branch information
djMax committed Sep 25, 2023
1 parent 09c87d6 commit df5fc10
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ async function run() {
const tmp = path.join(os.tmpdir(), `npm-pack-tarball-${Date.now()}`);
await fs.mkdir(tmp);
try {
const tarballDirectory = await getTarball(targetPackage, tmp, argv.npmrc).catch((error) => {
const tarballDirectory = await getTarball(targetPackage, tmp, {
npmrc: argv.npmrc,
verbose: argv.verbose,
}).catch((error) => {
if (error.status === 404) {
// Treat it as empty
return path.join(tmp, 'package');
Expand Down
10 changes: 8 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,20 @@ function executeCommand(command: string, args: string[], cwd?: string): Promise<
});
}

export async function getTarball(packageName: string, workingDirectory: string, npmrc?: string) {
export async function getTarball(
packageName: string,
workingDirectory: string,
{ npmrc, verbose }: { npmrc?: string; verbose?: boolean; } = {}) {
try {
const args = ['pack', packageName, '--pack-destination', workingDirectory];
if (npmrc) {
args.push('--userconfig', npmrc);
}
const tar = await executeCommand('npm', args, workingDirectory);
await executeCommand('tar', ['xzf', tar], workingDirectory);
const tarout = await executeCommand('tar', ['xvzf', tar], workingDirectory);
if (verbose) {
console.log(tarout);
}
return path.join(workingDirectory, 'package');
} catch (error) {
if ((error as ErrorWithOutput).output?.includes('404 Not Found')) {
Expand Down

0 comments on commit df5fc10

Please sign in to comment.