diff options
author | Matthew Miller <matthew@millerti.me> | 2023-08-22 10:13:03 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-22 10:13:03 -0700 |
commit | fefc95e4535e6ecf903f647124a492fba3fd11d6 (patch) | |
tree | 4c924d43d32fb12a780533302eaf5dee08875d75 /packages/typescript-types/extract-dom-types.ts | |
parent | 443c341bc2163f07b93a3ef84a43294d10b826f8 (diff) | |
parent | 2935857c76d458c26701842e500f8d97d17499c5 (diff) |
Merge pull request #425 from MasterKale/feat/server-esm-take-2-dnt
feat/server-esm-take-2-dnt
Diffstat (limited to 'packages/typescript-types/extract-dom-types.ts')
-rw-r--r-- | packages/typescript-types/extract-dom-types.ts | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/packages/typescript-types/extract-dom-types.ts b/packages/typescript-types/extract-dom-types.ts index 36072e6..436ac5b 100644 --- a/packages/typescript-types/extract-dom-types.ts +++ b/packages/typescript-types/extract-dom-types.ts @@ -1,3 +1,9 @@ +/** + * The VS Code Deno extension will yell about the imports of 'ts-morph' and 'typescript', but + * we're still using npm to run this file so that it uses Lerna's Typescript as defined in the + * package.json in the root of the monorepo. This is why `npm run build` here will run this file + * before finally building the package using dnt. + */ // n.b. ts-morph is a sibling devDependency of typescript, so that the module // loader will resolve our project's typescript package, not the transient // dependency of ts-morph. We only want to reference our typescript dependency @@ -37,11 +43,14 @@ const types = [ const project = new Project({ skipAddingFilesFromTsConfig: true }); const domSourcePath = 'typescript/lib/lib.dom.d.ts'; -const domSourceFile = project.addSourceFileAtPath(require.resolve(domSourcePath)); +const domSourceFile = project.addSourceFileAtPath( + require.resolve(domSourcePath), +); const resolvedNodes = new Set<InterfaceDeclaration | TypeAliasDeclaration>(); const unresolvedNodes = new Set<InterfaceDeclaration | TypeAliasDeclaration>( - types.map(type => { - const node = domSourceFile.getInterface(type) ?? domSourceFile.getTypeAlias(type); + types.map((type) => { + const node = domSourceFile.getInterface(type) ?? + domSourceFile.getTypeAlias(type); if (!node) { throw new Error(`${type} does not refer to an interface or type alias`); } @@ -62,7 +71,9 @@ while (unresolvedNodes.size > 0) { // alias, and add them to the unresolved list. for (const id of node.getDescendantsOfKind(SyntaxKind.Identifier)) { for (const dn of id.getDefinitionNodes()) { - if (Node.isInterfaceDeclaration(dn) || Node.isTypeAliasDeclaration(dn)) { + if ( + Node.isInterfaceDeclaration(dn) || Node.isTypeAliasDeclaration(dn) + ) { if (!resolvedNodes.has(dn)) { unresolvedNodes.add(dn); } @@ -72,13 +83,19 @@ while (unresolvedNodes.size > 0) { } } -const outputSourceFile = project.createSourceFile(`src/dom.ts`, undefined, { overwrite: true }); +const outputSourceFile = project.createSourceFile(`src/dom.ts`, undefined, { + overwrite: true, +}); outputSourceFile.addStatements([ `// Generated from typescript@${version} ${domSourcePath}`, `// To regenerate, run the following command from the project root:`, `// npx lerna --scope=@simplewebauthn/typescript-types exec -- npm run extract-dom-types`, ]); -const resolvedStructures = Array.from(resolvedNodes).map(node => node.getStructure()); -outputSourceFile.addInterfaces(resolvedStructures.filter(Structure.isInterface)); -outputSourceFile.addTypeAliases(resolvedStructures.filter(Structure.isTypeAlias)); +const resolvedStructures = Array.from(resolvedNodes).map((node) => node.getStructure()); +outputSourceFile.addInterfaces( + resolvedStructures.filter(Structure.isInterface), +); +outputSourceFile.addTypeAliases( + resolvedStructures.filter(Structure.isTypeAlias), +); outputSourceFile.saveSync(); |