Skip to content

Commit

Permalink
feat: loose mode to ignore all errors (#370)
Browse files Browse the repository at this point in the history
Currently the `loose` property is being used to signal acceptable failures to `jsii-rosetta` during the transliteration process.
Apparently there are [failures](#369) which are not covered by setting `loose: true` in rosetta.

In order to be able to generate API reference even for those types of failures, we broaden the meaning of `loose` in the context of `jsii-docgen` such that any transliteration failure will be caught and silently ignored.
  • Loading branch information
iliapolo authored Jul 20, 2021
1 parent 187f67e commit 7201434
Show file tree
Hide file tree
Showing 3 changed files with 235 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/docgen/view/documentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,15 @@ async function createAssembly(name: string, tsDir: string, loose: boolean, langu
for (let dotJsii of await glob.promise(`${tsDir}/**/.jsii`)) {
if (language) {
const packageDir = path.dirname(dotJsii);
await transliterateAssembly([packageDir], [language], { loose });
dotJsii = path.join(packageDir, `.jsii.${language}`);
try {
await transliterateAssembly([packageDir], [language], { loose });
dotJsii = path.join(packageDir, `.jsii.${language}`);
} catch (e) {
if (!loose) {
throw e;
}
console.log(`Caught transliteration error: ${e}. Ignoring...`);
}
}
await ts.load(dotJsii);
}
Expand Down
211 changes: 211 additions & 0 deletions test/docgen/view/__snapshots__/documentation.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion test/docgen/view/documentation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const LIBRARIES = `${__dirname}/../../__fixtures__/libraries`;

// this is a little concerning...we should be mindful
// if need to keep increasing this.
jest.setTimeout(2 * 60 * 1000);
jest.setTimeout(3 * 60 * 1000);


describe('extractPackageName', () => {
Expand Down Expand Up @@ -111,3 +111,17 @@ describe('typescript', () => {
expect(markdown.render()).toMatchSnapshot();
});
});

test('loose mode grossly ignores assembly transliteration failures', async () => {

// for some yet unknown reason, this package crashes the typescript compiler
// in a way that isn't recoverable by rosetta at the moment.
// so we use it to check that jsii-docgen ignores even those errors when requested to.
const docs = await Documentation.forPackage('@aws-cdk/aws-route53-patterns@1.106.0', {
language: Language.PYTHON,
loose: true,
});

const markdown = docs.render();
expect(markdown.render()).toMatchSnapshot();
});

0 comments on commit 7201434

Please sign in to comment.