From 0a3f01fa73e94aea4c86adb64450f45340360b92 Mon Sep 17 00:00:00 2001 From: Eli Polonsky Date: Tue, 30 Mar 2021 19:20:50 +0300 Subject: [PATCH] fix(rosetta): 'extract' does not translate samples in submodule READMEs (#2744) Now that the CDK release branch contains the ubergen [fix](https://github.com/aws/aws-cdk/commit/e047bda2e8597e4d9fe148855e561a1206e05cf0) that aligns rosseta fixtures, we can try and re-introduce this fix. --- By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license]. [Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0 --- packages/jsii-rosetta/lib/jsii/assemblies.ts | 12 +++++++++ .../jsii-rosetta/test/jsii/assemblies.test.ts | 27 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/packages/jsii-rosetta/lib/jsii/assemblies.ts b/packages/jsii-rosetta/lib/jsii/assemblies.ts index 7221a8772e..0f3ab7545a 100644 --- a/packages/jsii-rosetta/lib/jsii/assemblies.ts +++ b/packages/jsii-rosetta/lib/jsii/assemblies.ts @@ -68,6 +68,18 @@ export function allSnippetSources( }); } + for (const [submoduleFqn, submodule] of Object.entries( + assembly.submodules ?? {}, + )) { + if (submodule.readme) { + ret.push({ + type: 'markdown', + markdown: submodule.readme.markdown, + where: removeSlashes(`${submoduleFqn}-README`), + }); + } + } + if (assembly.types) { Object.values(assembly.types).forEach((type) => { emitDocs(type.docs, `${assembly.name}.${type.name}`); diff --git a/packages/jsii-rosetta/test/jsii/assemblies.test.ts b/packages/jsii-rosetta/test/jsii/assemblies.test.ts index 4cfd0d2983..0e5d67d1e3 100644 --- a/packages/jsii-rosetta/test/jsii/assemblies.test.ts +++ b/packages/jsii-rosetta/test/jsii/assemblies.test.ts @@ -29,6 +29,33 @@ test('Extract snippet from README', () => { expect(snippets[0].visibleSource).toEqual('someExample();'); }); +test('Extract snippet from submodule READMEs', () => { + const snippets = Array.from( + allTypeScriptSnippets([ + { + assembly: fakeAssembly({ + submodules: { + 'my.submodule': { + readme: { + markdown: [ + 'Before the example.', + '```ts', + 'someExample();', + '```', + 'After the example.', + ].join('\n'), + }, + }, + }, + }), + directory: path.join(__dirname, 'fixtures'), + }, + ]), + ); + + expect(snippets[0].visibleSource).toEqual('someExample();'); +}); + test('Extract snippet from type docstring', () => { const snippets = Array.from( allTypeScriptSnippets([