Skip to content

Commit 6af49fe

Browse files
author
Elad Ben-Israel
committed
fix: fails if java output directory does not exist
create the directory if it does not exist.
1 parent 3307218 commit 6af49fe

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

lib/srcmak.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import * as path from 'path';
33
import { exec, mkdtemp } from './util';
44
import { compile } from './compile';
55
import { Options } from './options';
6-
import { ncp } from 'ncp';
6+
import { ncp as _ncp } from 'ncp';
7+
import { promisify } from 'util';
8+
9+
const ncp = promisify(_ncp);
710

811
const pacmakModule = require.resolve('jsii-pacmak/bin/jsii-pacmak');
912

@@ -38,11 +41,8 @@ export async function srcmak(srcdir: string, options: Options = { }) {
3841
if (options.java) {
3942
const source = path.resolve(path.join(workdir, 'dist/java/src/'));
4043
const target = path.join(options.java.outdir, 'src/');
41-
ncp(source, target, { clobber: false }, (err) => {
42-
if (err) {
43-
return console.error(err);
44-
}
45-
});
44+
await fs.mkdirp(target); // make sure target directory exists
45+
await ncp(source, target, { clobber: false });
4646
}
4747
});
4848
}

test/cli.test.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ test('fails if only one java option is given', () => {
6262
});
6363

6464
test('python output', async () => {
65-
await mkdtemp(async outdir => {
65+
await mkdtemp(async tmpdir => {
66+
67+
// put under a non-existent directory to verify it is created
68+
const outdir = path.join(tmpdir, 'python');
69+
6670
srcmakcli(srcdir,
6771
'--entrypoint lib/main.ts',
6872
`--python-outdir ${outdir}`,
@@ -76,7 +80,10 @@ test('python output', async () => {
7680
});
7781

7882
test('java output', async () => {
79-
await mkdtemp(async outdir => {
83+
await mkdtemp(async tmpdir => {
84+
// put under a non-existent directory to verify it is created
85+
const outdir = path.join(tmpdir, 'java');
86+
8087
srcmakcli(srcdir,
8188
'--entrypoint lib/main.ts',
8289
`--java-outdir ${outdir}`,

0 commit comments

Comments
 (0)