Skip to content

Commit

Permalink
Make jsii-pacmak usable in parallel
Browse files Browse the repository at this point in the history
Stops outputting the .tgz for 'npm pack' in the package directory, instead
put it in a specially created temporary directory. This avoids concurrent
executions depending on the same path & deleting each other's files.
  • Loading branch information
RomainMuller committed Aug 8, 2018
1 parent 9448860 commit b0d7e22
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/jsii-pacmak/bin/jsii-pacmak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,18 @@ import { SPEC_FILE_NAME } from '../node_modules/jsii-spec';
await updateNpmIgnore(packageDir, npmIgnoreExclude);
}

const tarball = await npmPack(packageDir);
const tmpdir = await fs.mkdtemp(path.join(os.tmpdir(), 'npm-pack'));
try {
const tarball = await npmPack(packageDir, tmpdir);
for (const targetName of targets) {
// if we are targeting a single language, output to outdir, otherwise outdir/<target>
const targetOutputDir = targets.length > 1 ? path.join(outDir, targetName) : outDir;
logging.debug(`Building ${pkg.name}/${targetName}: ${targetOutputDir}`);
await generateTarget(packageDir, targetName, targetOutputDir, tarball);
}
} finally {
logging.debug(`Removing ${tarball}`);
await fs.remove(tarball);
logging.debug(`Removing ${tmpdir}`);
await fs.remove(tmpdir);
}

}
Expand Down Expand Up @@ -175,13 +176,13 @@ import { SPEC_FILE_NAME } from '../node_modules/jsii-spec';
process.exit(1);
});

async function npmPack(packageDir: string): Promise<string> {
logging.debug(`Running "npm pack" in ${packageDir}`);
const args = [ 'pack' ];
async function npmPack(packageDir: string, tmpdir: string): Promise<string> {
logging.debug(`Running "npm pack ${packageDir}" in ${tmpdir}`);
const args = [ 'pack', packageDir ];
if (logging.level >= logging.LEVEL_VERBOSE) {
args.push('--loglevel=verbose');
}
const out = await shell('npm', [ 'pack' ], { cwd: packageDir });
const out = await shell('npm', [ 'pack' ], { cwd: tmpdir });
return path.resolve(packageDir, out.trim());
}

Expand Down

0 comments on commit b0d7e22

Please sign in to comment.