diff --git a/packages/jsii-pacmak/lib/packaging.ts b/packages/jsii-pacmak/lib/packaging.ts index 11e60abcb2..c7d8040876 100644 --- a/packages/jsii-pacmak/lib/packaging.ts +++ b/packages/jsii-pacmak/lib/packaging.ts @@ -58,7 +58,13 @@ export class JsiiModule { // tarball name. otherwise, there can be a lot of extra noise there // from scripts that emit to STDOUT. const lines = out.trim().split(os.EOL); - return path.resolve(tmpdir, lines[lines.length - 1].trim()); + const lastLine = lines[lines.length - 1].trim(); + + if (!lastLine.endsWith('.tgz') && !lastLine.endsWith('.tar.gz')) { + throw new Error(`npm pack did not produce tarball from ${this.moduleDirectory} into ${tmpdir} (output was ${JSON.stringify(lines)})`); + } + + return path.resolve(tmpdir, lastLine); }); } diff --git a/packages/jsii-pacmak/lib/util.ts b/packages/jsii-pacmak/lib/util.ts index 81dca2fde4..0dbdafe0a9 100644 --- a/packages/jsii-pacmak/lib/util.ts +++ b/packages/jsii-pacmak/lib/util.ts @@ -52,7 +52,10 @@ export async function shell(cmd: string, args: string[], options: ShellOptions): stderr.push(Buffer.from(chunk)); }); child.once('error', ko); - child.once('exit', (code, signal) => { + + // Must use CLOSE instead of EXIT; EXIT may fire while there is still data in the + // I/O pipes, which we will miss if we return at that point. + child.once('close', (code, signal) => { const out = Buffer.concat(stdout).toString('utf-8'); if (code === 0) { return ok(out); } const err = Buffer.concat(stderr).toString('utf-8');