diff options
author | Matthew Miller <matthew@millerti.me> | 2023-08-18 13:55:40 -0700 |
---|---|---|
committer | Matthew Miller <matthew@millerti.me> | 2023-08-18 13:55:40 -0700 |
commit | e0d32bd2a3a60b4b2fd96a2874eae3ad976483df (patch) | |
tree | e55502a635c103666e4e989bf12b280d0100aff1 /packages/typescript-types | |
parent | acdc8d4b1420d65e1ec3ef4830985df766cd8b42 (diff) |
Add deno as explicit formatter for more files
Diffstat (limited to 'packages/typescript-types')
-rw-r--r-- | packages/typescript-types/extract-dom-types.ts | 67 |
1 files changed, 40 insertions, 27 deletions
diff --git a/packages/typescript-types/extract-dom-types.ts b/packages/typescript-types/extract-dom-types.ts index 8db8db7..a5362f7 100644 --- a/packages/typescript-types/extract-dom-types.ts +++ b/packages/typescript-types/extract-dom-types.ts @@ -16,38 +16,41 @@ import { Structure, SyntaxKind, TypeAliasDeclaration, -} from 'ts-morph'; -import { version } from 'typescript'; +} from "ts-morph"; +import { version } from "typescript"; // List of types we directly reference from the dom lib. Only interface and type // alias identifiers are valid, since other syntax types (class, function, var) // are implementations, which will not be available outside of the browser. const types = [ - 'AuthenticatorAssertionResponse', - 'AttestationConveyancePreference', - 'AuthenticatorAttestationResponse', - 'AuthenticatorTransport', - 'AuthenticationExtensionsClientInputs', - 'AuthenticationExtensionsClientOutputs', - 'AuthenticatorSelectionCriteria', - 'COSEAlgorithmIdentifier', - 'Crypto', - 'PublicKeyCredential', - 'PublicKeyCredentialCreationOptions', - 'PublicKeyCredentialDescriptor', - 'PublicKeyCredentialParameters', - 'PublicKeyCredentialRequestOptions', - 'PublicKeyCredentialUserEntity', - 'UserVerificationRequirement', + "AuthenticatorAssertionResponse", + "AttestationConveyancePreference", + "AuthenticatorAttestationResponse", + "AuthenticatorTransport", + "AuthenticationExtensionsClientInputs", + "AuthenticationExtensionsClientOutputs", + "AuthenticatorSelectionCriteria", + "COSEAlgorithmIdentifier", + "Crypto", + "PublicKeyCredential", + "PublicKeyCredentialCreationOptions", + "PublicKeyCredentialDescriptor", + "PublicKeyCredentialParameters", + "PublicKeyCredentialRequestOptions", + "PublicKeyCredentialUserEntity", + "UserVerificationRequirement", ]; const project = new Project({ skipAddingFilesFromTsConfig: true }); -const domSourcePath = 'typescript/lib/lib.dom.d.ts'; -const domSourceFile = project.addSourceFileAtPath(require.resolve(domSourcePath)); +const domSourcePath = "typescript/lib/lib.dom.d.ts"; +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`); } @@ -68,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); } @@ -78,13 +83,21 @@ 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(); |