Skip to content

Commit

Permalink
fix: rosetta failures causes fallback to typescript (#373)
Browse files Browse the repository at this point in the history
This PR reverts a previous misguided decision to [ignore](#370) rosetta failures and fallback to typescript assemblies. 

We decided we never want to show typescript code in the documentation of other languages, a better experience is actually to fail and either introduce more heuristics in rosetta to bypass such failures, or make the necessary adjustments to the published package. 

In addition, we used to transliterate the entire type-system (i.e all dependent assemblies) and not just the top level assembly. 
The rational being that code snippets might come from those assemblies when expanding arguments for python docs. 

Problem is that this means that a transliteration failure in a deeply nested dependency, that most likely doesn't have any affect on the documentation, prevents package transliteration. This can act as a sort of poison pill because many packages depend on the same core libraries. 

Also, we aren't currently even rendering those code snippets in the docs, so there is no good reason to do it.
  • Loading branch information
iliapolo authored Jul 22, 2021
1 parent 09e43ae commit 5b9c990
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 279 deletions.
6 changes: 3 additions & 3 deletions package.json

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

19 changes: 9 additions & 10 deletions src/docgen/view/documentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,17 +262,16 @@ async function createAssembly(name: string, tsDir: string, loose: boolean, langu
console.log(`Creating assembly in ${language ?? 'ts'} for ${name} from ${tsDir} (loose: ${loose})`);
const ts = new reflect.TypeSystem();
for (let dotJsii of await glob.promise(`${tsDir}/**/.jsii`)) {
if (language) {
// we only transliterate the top level assembly and not the entire type-system.
// note that the only reason to translate dependant assemblies is to show code examples
// for expanded python arguments - which we don't to right now anyway.
// we don't want to make any assumption of the directory structure, so this is the most
// robuse way to detect the root assembly.
const spec = JSON.parse(await fs.readFile(dotJsii, 'utf-8'));
if (language && spec.name === name) {
const packageDir = path.dirname(dotJsii);
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 transliterateAssembly([packageDir], [language], { loose });
dotJsii = path.join(packageDir, `.jsii.${language}`);
}
await ts.load(dotJsii);
}
Expand Down
Loading

0 comments on commit 5b9c990

Please sign in to comment.