Skip to content

Commit 584bc50

Browse files
committed
fix: Package name collisions
Fixes: cdk8s-team/cdk8s#273 Signed-off-by: campionfellin <campionfellin@gmail.com>
1 parent a3a5b9c commit 584bc50

5 files changed

Lines changed: 14 additions & 11 deletions

File tree

src/compile.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const compilerModule = require.resolve('jsii/bin/jsii');
1111
export async function compile(workdir: string, options: Options) {
1212
const args = [ '--silence-warnings', 'reserved-word' ];
1313
const entrypoint = options.entrypoint ?? 'index.ts';
14+
const packageName = options.packageName?.replace(/\./g, '').replace(/\//g, '') ?? 'generated';
1415

1516
if (path.extname(entrypoint) !== '.ts') {
1617
throw new Error(`jsii entrypoint must be a .ts file: ${entrypoint}`);
@@ -46,9 +47,8 @@ export async function compile(workdir: string, options: Options) {
4647
}
4748
}
4849

49-
5050
const pkg = {
51-
name: 'generated',
51+
name: packageName,
5252
version: '0.0.0',
5353
author: 'generated@generated.com',
5454
main: `${basepath}.js`,

src/options.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ export interface Options {
1818
*/
1919
jsii?: JsiiOutputOptions;
2020

21+
/**
22+
* Package name
23+
* @default "generated"
24+
*/
25+
packageName?: string
26+
2127
/**
2228
* Produce python code.
2329
* @default - python is not generated

test/__snapshots__/cli.test.ts.snap

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,7 @@ public final class $Module extends JsiiModule {
5353
if (!MODULE_TYPES.containsKey(fqn)) {
5454
throw new ClassNotFoundException(\\"Unknown JSII type: \\" + fqn);
5555
}
56-
String className = MODULE_TYPES.get(fqn);
57-
if (!this.cache.containsKey(className)) {
58-
this.cache.put(className, this.findClass(className));
59-
}
60-
return this.cache.get(className);
56+
return this.cache.computeIfAbsent(MODULE_TYPES.get(fqn), this::findClass);
6157
}
6258
6359
private Class<?> findClass(final String binaryName) {
@@ -149,7 +145,7 @@ public interface Operands extends software.amazon.jsii.JsiiSerializable {
149145
/**
150146
* A builder for {@link Operands}
151147
*/
152-
public static final class Builder implements software.amazon.jsii.Builder<Operands> {
148+
public static final class Builder {
153149
private java.lang.Number lhs;
154150
private java.lang.Number rhs;
155151
@@ -178,7 +174,6 @@ public interface Operands extends software.amazon.jsii.JsiiSerializable {
178174
* @return a new instance of {@link Operands}
179175
* @throws NullPointerException if any required attribute was not provided
180176
*/
181-
@Override
182177
public Operands build() {
183178
return new Jsii$Proxy(lhs, rhs);
184179
}
@@ -273,9 +268,9 @@ Object {
273268
],
274269
},
275270
"description": "generated",
276-
"fingerprint": "+fSgo9PQwFAKmX2JcaRILwTXE/p1H1bq+QKuOREAfuE=",
271+
"fingerprint": "YzbxW50rbVtKyO3xyXOGChedDt8pdGdCRYTETM1PW7k=",
277272
"homepage": "http://generated",
278-
"jsiiVersion": "1.6.0 (build 248e75b)",
273+
"jsiiVersion": "1.5.0 (build 46538f8)",
279274
"license": "Apache-2.0",
280275
"name": "generated",
281276
"repository": Object {
5.45 KB
Binary file not shown.

test/srcmak.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ test('python + different entrypoint + submodule', async () => {
6161
await mkdtemp(async target => {
6262
await srcmak(source, {
6363
entrypoint: 'different/entry.ts',
64+
packageName: 'python.package',
6465
python: {
6566
outdir: target,
6667
moduleName: 'my_python_module.submodule',
@@ -96,6 +97,7 @@ test('java + different entrypoint', async () => {
9697
await mkdtemp(async target => {
9798
await srcmak(source, {
9899
entrypoint: 'different/entry.ts',
100+
packageName: 'java.package',
99101
java: {
100102
outdir: target,
101103
package: 'hello.world',

0 commit comments

Comments
 (0)