Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const compilerModule = require.resolve('jsii/bin/jsii');
export async function compile(workdir: string, options: Options) {
const args = [ '--silence-warnings', 'reserved-word' ];
const entrypoint = options.entrypoint ?? 'index.ts';
const packageName = options.packageName?.replace(/\./g, '').replace(/\//g, '') ?? 'generated';
Comment thread
campionfellin marked this conversation as resolved.
Outdated

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


const pkg = {
name: 'generated',
name: packageName,
version: '0.0.0',
author: 'generated@generated.com',
main: `${basepath}.js`,
Expand Down
6 changes: 6 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ export interface Options {
*/
jsii?: JsiiOutputOptions;

/**
* Package name
* @default "generated"
Comment thread
eladb marked this conversation as resolved.
Outdated
*/
packageName?: string
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure that's the correct name for this because users don't really interact with this value after code generation. Maybe moduleKey or something like that.

Docstring help needs to indicate that it should be project-unique.


/**
* Produce python code.
* @default - python is not generated
Expand Down
42 changes: 33 additions & 9 deletions test/__snapshots__/srcmak.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public final class $Module extends JsiiModule {
private final Map<String, Class<?>> cache = new HashMap<>();

public $Module() {
super(\\"generated\\", \\"0.0.0\\", $Module.class, \\"generated@0.0.0.jsii.tgz\\");
super(\\"javapackage\\", \\"0.0.0\\", $Module.class, \\"javapackage@0.0.0.jsii.tgz\\");
}

@Override
Expand Down Expand Up @@ -73,7 +73,7 @@ public final class $Module extends JsiiModule {
"src/main/java/hello/world/Hello.java": "package hello.world;


@software.amazon.jsii.Jsii(module = hello.world.$Module.class, fqn = \\"generated.Hello\\")
@software.amazon.jsii.Jsii(module = hello.world.$Module.class, fqn = \\"javapackage.Hello\\")
public class Hello extends software.amazon.jsii.JsiiObject {

protected Hello(final software.amazon.jsii.JsiiObjectRef objRef) {
Expand All @@ -97,7 +97,7 @@ public class Hello extends software.amazon.jsii.JsiiObject {
"src/main/java/hello/world/Operands.java": "package hello.world;


@software.amazon.jsii.Jsii(module = hello.world.$Module.class, fqn = \\"generated.Operands\\")
@software.amazon.jsii.Jsii(module = hello.world.$Module.class, fqn = \\"javapackage.Operands\\")
@software.amazon.jsii.Jsii.Proxy(Operands.Jsii$Proxy.class)
public interface Operands extends software.amazon.jsii.JsiiSerializable {

Expand Down Expand Up @@ -194,7 +194,7 @@ public interface Operands extends software.amazon.jsii.JsiiSerializable {
data.set(\\"rhs\\", om.valueToTree(this.getRhs()));

final com.fasterxml.jackson.databind.node.ObjectNode struct = com.fasterxml.jackson.databind.node.JsonNodeFactory.instance.objectNode();
struct.set(\\"fqn\\", om.valueToTree(\\"generated.Operands\\"));
struct.set(\\"fqn\\", om.valueToTree(\\"javapackage.Operands\\"));
struct.set(\\"data\\", data);

final com.fasterxml.jackson.databind.node.ObjectNode obj = com.fasterxml.jackson.databind.node.JsonNodeFactory.instance.objectNode();
Expand Down Expand Up @@ -223,9 +223,23 @@ public interface Operands extends software.amazon.jsii.JsiiSerializable {
}
}
",
"src/main/resources/hello/world/$Module.txt": "generated.Hello=hello.world.Hello
generated.Operands=hello.world.Operands
"src/main/resources/hello/world/$Module.txt": "javapackage.Hello=hello.world.Hello
javapackage.Operands=hello.world.Operands
",
"src/main/resources/hello/world/javapackage@0.0.0.jsii.tgz": "��ko�H�����K���6��D�.£$���SU������v�S��o��UM������;�����xlE{P&���1����R*q��J�r�{�(V*� � IG��I���e�BA��������8�W\\\\gjQ���g07��� Q�A�_�(�Y�Q� t��k>���_�����F��\`���ΔG��nň�Z�� ��c�
����!�,� �+y�{����T:FGe� �$XC&[�:!S���TdԆ|�l�aǢ���g�Nd�K�V
c;�3��з �E!�
!6A[����g07�Gd&|gR��i�W��\\"�P˵�������X_yD���( �B*�8��iYOԱ��2愔��/#�Ma *�9E0�'!�����
� ��ҵm�\\\\�����'�����6�,�%(��1&(��Lj\\"�)��zy�%L��Sm��@�z2�����4�>-��'V�I�8�]O��O���Ii��8�IJ�
��Dv��س!M�P�z��5��Қ\\"ǥ&�t�-x�b��q���*��NY�q4���>B0}J��=��+��P=wb���Mx���O�wi#ޣ�Z�Ԃ5�g��2�B*˘��a�pE%Y��l��ٖ����)\\"����a�R�%�����L�E����Lt37�����k4�H�؜
�M�e|���,d��s��:.΅��S�vH�k�]2J���p��g|n�{�j�a�)d#d�^O����X�l�/IҾ���� q��0��\\\\O�!�����dv�=��u�!���X�o�oܣB\\\\$'nyp�[Ua��� �T#8H���f�\`5Y���AV9
�2� �@�,\`x�+����R
])�
��v�=�o��B�ʇ���SUa�R:D^G�u�\\\\u�3kѽ��<'0�#�,h惫�W�jq��K�U�
>����&UE͸&�׮�^����C7����ǽ��'
�m�S�U�UC_��{ �ֿ;݆X��
v#\\\\�nN�{}�m��X��޼տ���D�Fp�l��7��чk>}�۸���]O ����\\"���\`��a7����-�����&���{��fiҾ8���Oj�#���՛Cod\\\\�F7�O�����Վ\\"��E�ɗ�Tf�Ɣ�U��,���!���T|е:�^<�Ƽ cK[X�:����s7�5���氤5��~Q�����l��9SӲ�t���j�>6�O>���ьKwԺ�{��겈Gw� ��Dz�
���Z�-���Ҽs��yxe�HʩF��0��������>�?Q���N������?��l���}����g[#ۋ��]�l��7ln+>g�O�6��>}����k��Es��ԉ�L�W��\`���i��[?���fgw�%�u������IػA%�2SB��F��L-�8 �&���g1��[��v���|-��A�6�Q,����W@PksqO��:<a��H�-�x��'\\\\�!���$&��9��E��o��X�Ar�[;d{���'�/��� ",
}
`;

Expand Down Expand Up @@ -300,7 +314,7 @@ import publication
from ._jsii import *


class Hello(metaclass=jsii.JSIIMeta, jsii_type=\\"generated.Hello\\"):
class Hello(metaclass=jsii.JSIIMeta, jsii_type=\\"pythonpackage.Hello\\"):
def __init__(self) -> None:
jsii.create(Hello, self, [])

Expand All @@ -315,7 +329,7 @@ class Hello(metaclass=jsii.JSIIMeta, jsii_type=\\"generated.Hello\\"):
return jsii.invoke(self, \\"add\\", [ops])


@jsii.data_type(jsii_type=\\"generated.Operands\\", jsii_struct_bases=[], name_mapping={'lhs': 'lhs', 'rhs': 'rhs'})
@jsii.data_type(jsii_type=\\"pythonpackage.Operands\\", jsii_struct_bases=[], name_mapping={'lhs': 'lhs', 'rhs': 'rhs'})
class Operands():
def __init__(self, *, lhs: jsii.Number, rhs: jsii.Number) -> None:
\\"\\"\\"
Expand Down Expand Up @@ -362,14 +376,24 @@ import jsii
import jsii.compat
import publication

__jsii_assembly__ = jsii.JSIIAssembly.load(\\"generated\\", \\"0.0.0\\", __name__[0:-6], \\"generated@0.0.0.jsii.tgz\\")
__jsii_assembly__ = jsii.JSIIAssembly.load(\\"pythonpackage\\", \\"0.0.0\\", __name__[0:-6], \\"pythonpackage@0.0.0.jsii.tgz\\")

__all__ = [
\\"__jsii_assembly__\\",
]

publication.publish()
",
"my_python_module/submodule/_jsii/pythonpackage@0.0.0.jsii.tgz": "��ko�8p?�+�ܗ��Ixt۪�hy��B��rZUNb����NKX��o��]���VבZl�x^�'� m�F8��0B>|�$��� ��rY%/|�� �,
�I��(Y��N����8��ʷ� ���_��AD.�T<��-db��#la�8��LFi�6�㐌�f@�w0]� �_���'u�4JNl�g�x@d9a��ımbǟz̹s��$C
?:{�����.�%��C��'|�W�BJ�h�b�K2�(i)D�f�Ѐb�f���[z�{N��c�]j��1���@�4��)-K�t��l����9�nr Q�{t�xk�\\"]mںkH�{ w?�ki�6�����:�*6 {U�6U���Հd����G�bN�A�8�E��K�wkHZ����p�Y���X%_\\"1p|�:1�����|�%�˧:�V�rM �꫱-�H8���X�����b�$�]��k{EQ@q�k�nj���v6X���}G�v �,���\\"�o�eMo��K-���=z�%&��S\`��*��^Y�q<J�'^�p��2�u�#�\\"#8u��7!���ĂC\\"
��W��>޾��CmX��p)��8E�0<��t9R�M���u��ڗ=x�������w(�V�����L�g�[{&������Q��2~+��a
�-�eb�\\\\���ʴ�8�n~��]��trLj�R{r�-O��t!���]T�B��f�L���x����Y�+'��^��]�HN��y��N���:� �?�)���g�M9;��G̢Dt,|����0k ���TP� ��%
(W>B�q��7‡_��4�_��\`��<� �T$/�����y*��M\`�K5�D��۸��3�B�$�̄�ֹ�.䎱WW��9ꟺ��=o��&�� �A?/i��EV���\\\\����w�*�����g�)��f� ͫ�^�P���oa�W�a��ЗC�,��)��j�QM}��o�y�s'�Wr�ӿb��u�v�띻�]�J��:���f�����-�8�-5�N��u��fe��c�hͧ�6�Z��\\\\�kKF�3o�\\"� �/w'��U��*u��]R� l�:�m0r_ɍj����~��f�R�b�z��
�����Y��C??ռ�IL[+�A�z�*y�o� U��Z%/����M���ː�Z7��'՜�alks{�Z=�\`���<sCYS�h\\\\��ʩ����r=��A��u��z��P�9�ӛ�����l���kwPm:mRt��L�����z�w����-���ּKZ�yxy�X�s����G]v..~��F��\\\\����e����������|���|=��]�%
�[D�����.�0q�ٰE�ǥ�K�]=�}
���NR����%��:��R,i�l6ov�c6d^Ւ�K�e��c[:���#,l��ƴ��I-������x�;p�e���Bx��?�ZKH�
B���5�H�-��V;�/��u ]��՛�c�)�քg�����?�!������E��",
"my_python_module/submodule/py.typed": "
",
}
Expand Down
2 changes: 2 additions & 0 deletions test/srcmak.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ test('python + different entrypoint + submodule', async () => {
await mkdtemp(async target => {
await srcmak(source, {
entrypoint: 'different/entry.ts',
packageName: 'python.package',
python: {
outdir: target,
moduleName: 'my_python_module.submodule',
Expand Down Expand Up @@ -96,6 +97,7 @@ test('java + different entrypoint', async () => {
await mkdtemp(async target => {
await srcmak(source, {
entrypoint: 'different/entry.ts',
packageName: 'java.package',
java: {
outdir: target,
package: 'hello.world',
Expand Down