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 81fc65a
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 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,14 +176,14 @@ 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 });
return path.resolve(packageDir, out.trim());
const out = await shell('npm', [ 'pack' ], { cwd: tmpdir });
return path.resolve(tmpdir, out.trim());
}

async function updateNpmIgnore(packageDir: string, excludeOutdir: string | undefined) {
Expand Down

0 comments on commit 81fc65a

Please sign in to comment.