@jsdocs-io/extractor
Version:
Analyze and extract the API from npm packages
3 lines (2 loc) • 28 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0});var e=require("perf_hooks"),t=require("query-registry"),n=require("debug"),a=require("ts-morph"),r=require("prettier"),i=require("@microsoft/tsdoc"),o=require("hosted-git-info"),c=require("path"),s=require("got"),l=require("gunzip-maybe"),d=require("stream"),u=require("util"),g=require("concat-stream"),p=require("tar-stream");function m(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function f(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var a=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,a.get?a:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,t}var D=m(n),y=f(a),x=f(r),S=f(i),N=m(o),I=f(c),P=m(s),h=m(l),k=m(d),b=m(g),T=m(p);const K=D.default("@jsdocs-io/extractor");var C;function M(e){return e.kind===exports.DeclarationKinds.VariableDeclaration}function v(e){return e.kind===exports.DeclarationKinds.FunctionDeclaration}function F(e){return e.kind===exports.DeclarationKinds.ClassDeclaration}function O(e){return e.kind===exports.DeclarationKinds.ClassPropertyDeclaration}function $(e){return e.kind===exports.DeclarationKinds.ClassMethodDeclaration}function A(e){return e.kind===exports.DeclarationKinds.InterfaceDeclaration}function w(e){return e.kind===exports.DeclarationKinds.InterfacePropertyDeclaration}function E(e){return e.kind===exports.DeclarationKinds.InterfaceMethodDeclaration}function R(e){return e.kind===exports.DeclarationKinds.InterfaceConstructSignatureDeclaration}function j(e){return e.kind===exports.DeclarationKinds.InterfaceCallSignatureDeclaration}function L(e){return e.kind===exports.DeclarationKinds.InterfaceIndexSignatureDeclaration}function _(e){return e.kind===exports.DeclarationKinds.EnumDeclaration}function U(e){return e.kind===exports.DeclarationKinds.TypeAliasDeclaration}function q(e){return e.kind===exports.DeclarationKinds.NamespaceDeclaration}exports.DeclarationKinds=void 0,(C=exports.DeclarationKinds||(exports.DeclarationKinds={})).VariableDeclaration="VariableDeclaration",C.FunctionDeclaration="FunctionDeclaration",C.ClassDeclaration="ClassDeclaration",C.ClassConstructorDeclaration="ClassConstructorDeclaration",C.ClassPropertyDeclaration="ClassPropertyDeclaration",C.ClassMethodDeclaration="ClassMethodDeclaration",C.InterfaceDeclaration="InterfaceDeclaration",C.InterfacePropertyDeclaration="InterfacePropertyDeclaration",C.InterfaceMethodDeclaration="InterfaceMethodDeclaration",C.InterfaceConstructSignatureDeclaration="InterfaceConstructSignatureDeclaration",C.InterfaceCallSignatureDeclaration="InterfaceCallSignatureDeclaration",C.InterfaceIndexSignatureDeclaration="InterfaceIndexSignatureDeclaration",C.EnumDeclaration="EnumDeclaration",C.EnumMemberDeclaration="EnumMemberDeclaration",C.TypeAliasDeclaration="TypeAliasDeclaration",C.NamespaceDeclaration="NamespaceDeclaration";const z={semi:!0,singleQuote:!0,trailingComma:"es5",tabWidth:4,printWidth:85,endOfLine:"lf",arrowParens:"always",parser:"typescript"};function V(e){return J(e.replace("default:","_______:")).replace("_______:","default:")}function W(e){return G(`class C { ${e} }`)}function B(e){return G(`interface I { ${e} }`)}function G(e){const t=J(e).split("\n");return t.slice(1,t.length-1).map((e=>e.replace(/^\s{4}/,""))).join("\n")}function J(e){let t=e.trim().replace(/^export\s+/,"").replace(/^default\s+/,"").replace(/^declare\s+/,"");try{t=x.format(t,z)}catch(e){K("formatText: formatting error: %O",{err:e})}return t.trim()}function H({declaration:e}){return e.getType().getApparentType().getText(e,y.ts.TypeFormatFlags.NoTruncation|y.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope).replace(/^Number$/,"number").replace(/^Boolean$/,"boolean").replace(/^String$/,"string")}function Q({declaration:e}){const t=function({declaration:e}){if(y.Node.isVariableDeclaration(e))return[e.getVariableStatementOrThrow()];if(y.Node.isExpression(e))return[e.getParent()];if(y.Node.isOverloadable(e)&&!y.Node.isConstructorDeclaration(e)){const t=e.getOverloads(),n=e.getImplementation();return[...t,...n?[n]:[]]}if(y.Node.isMethodSignature(e)&&e.getParent().getKind()===y.SyntaxKind.InterfaceDeclaration){const t=e.getName();return e.getParentIfKindOrThrow(y.SyntaxKind.InterfaceDeclaration).getMethods().filter((e=>e.getName()===t))}return[e]}({declaration:e}),n=t.flatMap((e=>{const t=function({declaration:e}){var t;const n=null==(t=e.getLastChildByKind(y.SyntaxKind.JSDocComment))?void 0:t.getText();if(n&&!(new S.TSDocParser).parseString(n).docComment.modifierTagSet.isPackageDocumentation())return n}({declaration:e});return t||[]}));return Array.from(new Set(n))}function X({declaration:e}){return e.getModifiers().flatMap((e=>e.getKind()===y.SyntaxKind.PublicKeyword?[]:e.getText())).join(" ")}function Y({declaration:e}){const t=[];for(const n of e.getChildren())if(n.getKind()!==y.SyntaxKind.JSDocComment){if(n.getKind()===y.SyntaxKind.OpenBraceToken)break;t.push(n.getText())}return t.push("{}"),J(t.join(" "))}function Z({declaration:e,name:t=""}){return t.startsWith("_")||t.startsWith("#")||function({declaration:e}){return y.Node.isModifierable(e)&&e.hasModifier(y.SyntaxKind.PrivateKeyword)}({declaration:e})||function({declaration:e}){const t=Q({declaration:e})[0];return!!t&&(new S.TSDocParser).parseString(t).docComment.modifierTagSet.isInternal()}({declaration:e})}function ee(e,t){return e.id.localeCompare(t.id)}function te(...e){return e.filter(Boolean).join(".")}function ne(e){var t;if((null==(t=e.getTypeNode())?void 0:t.getKind())===y.SyntaxKind.FunctionType)return!0;const n=e.getInitializer();return!!n&&(y.Node.isArrowFunction(n)||y.Node.isFunctionExpression(n))}function ae({id:e,name:t,declaration:n,getSource:a,suggestedType:r}){const i=exports.DeclarationKinds.VariableDeclaration,o=Q({declaration:n}),c=a({declaration:n}),s=function({declaration:e}){return e.getVariableStatementOrThrow().getDeclarationKind().toString()}({declaration:n}),l=function({declaration:e,suggestedType:t="any"}){const n=H({declaration:e});return"any"!==n?n:t}({declaration:n,suggestedType:r});return{kind:i,id:e,name:t,docs:o,source:c,signature:re({variableKind:s,name:t,type:l}),variableKind:s,type:l}}function re({variableKind:e,name:t,type:n}){return V(`${e} ${t}: ${n}`)}function ie({declaration:e}){return e.getSourceFile().getFilePath().replace(/^\//,"")}function oe({name:e,type:t}){return V(`let ${e}: ${t}`).replace(/^let\s/,"")}function ce({exportName:e,declaration:t}){var n;return"default"!==e||y.Node.isExpression(t)||y.Node.isSourceFile(t)?e:null!=(n=t.getName())?n:e}function se(e){return y.Node.isModuleDeclaration(e)}function le({module:e,moduleName:t,maxDepth:n,getSource:a,getType:r,project:i}){K("getModuleDeclarations: extracting declarations: %O",{moduleName:t,maxDepth:n,module:e});const o=function({module:e,moduleName:t}){const n=new Set;return Array.from(e.getExportedDeclarations()).flatMap((([e,a])=>a.flatMap((a=>{if(Z({declaration:a,name:e}))return[];const r=te(t,e),i=ce({exportName:e,declaration:a}),o=te(t,i);return o===r&&n.add(o),{exportID:r,exportName:e,declarationID:o,declarationName:i,declaration:a}})))).filter((({exportID:e,declarationID:t})=>t===e||!n.has(t)))}({module:e,moduleName:t});K("getModuleDeclarations: got normal export declarations: %O",{moduleName:t,total:o.length,normalExportDeclarations:o});const c=function({module:e,moduleName:t}){var n;if(y.Node.isModuleDeclaration(e)&&!e.hasBody())return[];const a=null==(n=e.getExportAssignment((e=>e.isExportEquals())))?void 0:n.getLastChildByKind(y.SyntaxKind.Identifier);if(!a)return[];const r=a.getText();return a.getDefinitionNodes().flatMap((e=>{if(Z({declaration:e,name:r})||!function(e){return y.Node.isVariableDeclaration(e)||y.Node.isClassDeclaration(e)||y.Node.isInterfaceDeclaration(e)||y.Node.isEnumDeclaration(e)||y.Node.isTypeAliasDeclaration(e)||y.Node.isModuleDeclaration(e)||y.Node.isExpression(e)||y.Node.isFunctionDeclaration(e)}(e))return[];if(se(e))return[];const n=te(t,r),a=ce({exportName:r,declaration:e}),i=te(t,a);return{exportID:n,exportName:r,declarationID:i,declarationName:a,declaration:e}}))}({module:e,moduleName:t});K("getModuleDeclarations: got export equals declarations: %O",{moduleName:t,total:c.length,exportEqualsDeclarations:c});const s=function({project:e}){return e?e.getAmbientModules().flatMap((e=>e.getDeclarations().flatMap((e=>{const t=e.getSourceFile().getFilePath();if(!y.Node.isModuleDeclaration(e)||t.startsWith("/node_modules"))return[];const n=e.getName(),a=n,r=n.replace(/"|'/g,"").replace(/\s/g,"_").trim();return{exportID:r,exportName:n,declarationID:r,declarationName:a,declaration:e}})))):[]}({project:i});K("getModuleDeclarations: got ambient modules declarations: %O",{moduleName:t,total:s.length,ambientModulesDeclarations:s});const l=function({module:e,moduleName:t}){return y.Node.isSourceFile(e)?[...e.getVariableDeclarations(),...e.getFunctions(),...e.getModules()].flatMap((e=>{const n=e.getName();if(!function({declaration:e}){const t=y.Node.isVariableDeclaration(e)&&e.getVariableStatementOrThrow().isAmbient()&&!e.isExported(),n=y.Node.isFunctionDeclaration(e)&&e.isAmbient()&&void 0!==e.getName()&&!e.isExported(),a=y.Node.isModuleDeclaration(e)&&e.isAmbient()&&!e.isExported()&&!e.hasModuleKeyword();return t||n||a}({declaration:e})||Z({declaration:e,name:n}))return[];const a=te(t,n),r=ce({exportName:n,declaration:e});return{exportID:a,exportName:n,declarationID:te(t,r),declarationName:r,declaration:e}})):[]}({module:e,moduleName:t});return K("getModuleDeclarations: got global ambient declarations: %O",{moduleName:t,total:l.length,globalAmbientDeclarations:l}),function({exportedDeclarations:e,maxDepth:t,getSource:n,getType:a}){const r=new Set,i=new Set,o=e.flatMap((({exportID:e,declarationID:o,declarationName:c,declaration:s})=>{if(function(e){return y.Node.isVariableDeclaration(e)&&!ne(e)}(s))return ae({id:o,name:c,declaration:s,getSource:n});if(function(e){return y.Node.isBinaryExpression(e)&&y.Node.isIdentifier(e.getLeft())}(s))return function({id:e,name:t,declaration:n,getSource:a}){const r=function({declaration:e}){return e.getLeft().getSymbol().getDeclarations()[0]}({declaration:n});return ae({id:e,name:t,declaration:r,getSource:a,suggestedType:H({declaration:n.getRight()})})}({id:o,name:c,declaration:s,getSource:n});if(function(e){return y.Node.isExpression(e)}(s))return function({id:e,name:t,declaration:n,getSource:a}){const r=exports.DeclarationKinds.VariableDeclaration,i=Q({declaration:n}),o=a({declaration:n}),c="const",s=H({declaration:n});return{kind:r,id:e,name:t,docs:i,source:o,signature:re({variableKind:c,name:t,type:s}),variableKind:c,type:s}}({id:o,name:c,declaration:s,getSource:n});if(function(e){return y.Node.isFunctionDeclaration(e)&&(e.isAmbient()||e.isImplementation())}(s))return r.has(e)?[]:(r.add(e),function({id:e,name:t,declaration:n,getSource:a,getType:r}){const i=exports.DeclarationKinds.FunctionDeclaration,o=Q({declaration:n}),c=a({declaration:n}),s=r({declaration:n});return{kind:i,id:e,name:t,docs:o,source:c,signature:oe({name:t,type:s}),type:s}}({id:o,name:c,declaration:s,getSource:n,getType:a}));if(function(e){return y.Node.isVariableDeclaration(e)&&ne(e)}(s))return function({id:e,name:t,declaration:n,getSource:a,getType:r}){const i=exports.DeclarationKinds.FunctionDeclaration,o=Q({declaration:n}),c=a({declaration:n}),s=r({declaration:n});return{kind:i,id:e,name:t,docs:o,source:c,signature:oe({name:t,type:s}),type:s}}({id:o,name:c,declaration:s,getSource:n,getType:a});if(function(e){return y.Node.isClassDeclaration(e)}(s))return function({id:e,name:t,declaration:n,getSource:a,getType:r}){const i=exports.DeclarationKinds.ClassDeclaration,o=Q({declaration:n}),c=a({declaration:n}),s=n.isAbstract(),l=Y({declaration:n}),d=function({classID:e,classDeclaration:t,getSource:n}){const a=t.getConstructors()[0];if(!a)return[];const r=a.getOverloads(),i=a.getImplementation();return[...r,...i?[i]:[]].flatMap(((t,a)=>{if(Z({declaration:t}))return[];const r=exports.DeclarationKinds.ClassConstructorDeclaration,i="constructor",o=te(e,`${a}-${i}`),c=Q({declaration:t}),s=n({declaration:t}),l=function({declaration:e}){const t=e.getModifiers().map((e=>e.getText())).join(" "),n=e.getParameters().map((e=>{const t=e.getName(),n=H({declaration:e}),a=e.isRestParameter(),r=a?"...":"",i=e.isOptional();return`${r}${t}${!a&&i?"?":""}: ${n}`})).join(",");return W(`${t} constructor(${n});`)}({declaration:t});return{kind:r,id:o,name:i,docs:c,source:s,signature:l}}))}({classID:e,classDeclaration:n,getSource:a}),u=function({classID:e,classDeclaration:t,getSource:n,getType:a}){const r=new Set,i=[...t.getStaticMembers(),...t.getInstanceMembers()].flatMap((t=>{const i=t.getName(),o=te(e,i);return Z({declaration:t,name:i})?[]:y.Node.isPropertyDeclaration(t)||y.Node.isParameterDeclaration(t)?function({id:e,name:t,declaration:n,getSource:a}){const r=exports.DeclarationKinds.ClassPropertyDeclaration,i=Q({declaration:n}),o=a({declaration:n}),c=X({declaration:n}),s=y.Node.isPropertyDeclaration(n)&&n.isStatic(),l=n.hasQuestionToken()?"?":"",d=H({declaration:n});return{kind:r,id:e,name:t,docs:i,source:o,signature:W(`${c} ${t} ${l}: ${d}`),isStatic:s,type:d}}({id:o,name:i,declaration:t,getSource:n}):y.Node.isGetAccessorDeclaration(t)?function({id:e,name:t,declaration:n,getSource:a}){const r=exports.DeclarationKinds.ClassPropertyDeclaration,i=Q({declaration:n}),o=a({declaration:n}),c=n.isStatic(),s=void 0===n.getSetAccessor(),l=H({declaration:n});return{kind:r,id:e,name:t,docs:i,source:o,signature:W(`${c?"static":""} ${s?"readonly":""} ${t}: ${l}`),isStatic:c,type:l}}({id:o,name:i,declaration:t,getSource:n}):y.Node.isMethodDeclaration(t)?r.has(o)?[]:(r.add(o),function({id:e,name:t,declaration:n,getSource:a,getType:r}){const i=exports.DeclarationKinds.ClassMethodDeclaration,o=Q({declaration:n}),c=a({declaration:n}),s=n.isStatic(),l=X({declaration:n}),d=r({declaration:n});return{kind:i,id:e,name:t,docs:o,source:c,signature:W(`${l} ${t}: ${d}`),isStatic:s,type:d}}({id:o,name:i,declaration:t,getSource:n,getType:a})):[]})).sort(ee);return{properties:i.filter(O),methods:i.filter($)}}({classID:e,classDeclaration:n,getSource:a,getType:r});return{kind:i,id:e,name:t,docs:o,source:c,signature:l,isAbstract:s,constructors:d,members:u}}({id:o,name:c,declaration:s,getSource:n,getType:a});if(function(e){return y.Node.isInterfaceDeclaration(e)}(s))return function({id:e,name:t,declaration:n,getSource:a,getType:r}){const i=exports.DeclarationKinds.InterfaceDeclaration,o=Q({declaration:n}),c=a({declaration:n}),s=Y({declaration:n}),l=function({interfaceID:e,interfaceDeclaration:t,getSource:n,getType:a}){const r=new Set,i=t.getMembers().flatMap(((t,i)=>{const o=function({declaration:e}){return y.Node.isPropertySignature(e)||y.Node.isMethodSignature(e)?e.getName():y.Node.isConstructSignatureDeclaration(e)?"construct signature":y.Node.isCallSignatureDeclaration(e)?"call signature":"index signature"}({declaration:t}),c=te(e,function({declaration:e,index:t}){return y.Node.isPropertySignature(e)||y.Node.isMethodSignature(e)?e.getName():y.Node.isConstructSignatureDeclaration(e)?`${t}-construct-signature`:y.Node.isCallSignatureDeclaration(e)?`${t}-call-signature`:`${t}-index-signature`}({declaration:t,index:i}));return Z({declaration:t,name:o})?[]:y.Node.isPropertySignature(t)?function({id:e,name:t,declaration:n,getSource:a}){const r=exports.DeclarationKinds.InterfacePropertyDeclaration,i=Q({declaration:n}),o=a({declaration:n}),c=n.isReadonly(),s=n.hasQuestionToken(),l=H({declaration:n});return{kind:r,id:e,name:t,docs:i,source:o,signature:B(n.getText()),isReadonly:c,isOptional:s,type:l}}({id:c,name:o,declaration:t,getSource:n}):y.Node.isMethodSignature(t)?r.has(c)?[]:(r.add(c),function({id:e,name:t,declaration:n,getSource:a,getType:r}){const i=exports.DeclarationKinds.InterfaceMethodDeclaration,o=Q({declaration:n}),c=a({declaration:n}),s=r({declaration:n});return{kind:i,id:e,name:t,docs:o,source:c,signature:B(`${t}: ${s}`),type:s}}({id:c,name:o,declaration:t,getSource:n,getType:a})):y.Node.isConstructSignatureDeclaration(t)?function({id:e,name:t,declaration:n,getSource:a}){return{kind:exports.DeclarationKinds.InterfaceConstructSignatureDeclaration,id:e,name:t,docs:Q({declaration:n}),source:a({declaration:n}),signature:B(n.getText())}}({id:c,name:o,declaration:t,getSource:n}):y.Node.isCallSignatureDeclaration(t)?function({id:e,name:t,declaration:n,getSource:a}){return{kind:exports.DeclarationKinds.InterfaceCallSignatureDeclaration,id:e,name:t,docs:Q({declaration:n}),source:a({declaration:n}),signature:B(n.getText())}}({id:c,name:o,declaration:t,getSource:n}):function({id:e,name:t,declaration:n,getSource:a}){return{kind:exports.DeclarationKinds.InterfaceIndexSignatureDeclaration,id:e,name:t,docs:Q({declaration:n}),source:a({declaration:n}),signature:B(n.getText())}}({id:c,name:o,declaration:t,getSource:n})})).sort(ee);return{properties:i.filter(w),methods:i.filter(E),constructSignatures:i.filter(R),callSignatures:i.filter(j),indexSignatures:i.filter(L)}}({interfaceID:e,interfaceDeclaration:n,getSource:a,getType:r});return{kind:i,id:e,name:t,docs:o,source:c,signature:s,members:l}}({id:o,name:c,declaration:s,getSource:n,getType:a});if(function(e){return y.Node.isEnumDeclaration(e)}(s))return function({id:e,name:t,declaration:n,getSource:a}){const r=exports.DeclarationKinds.EnumDeclaration,i=Q({declaration:n}),o=a({declaration:n}),c=n.isConstEnum(),s=function({enumID:e,enumDeclaration:t,getSource:n}){return t.getMembers().flatMap((t=>{const a=t.getName();return Z({declaration:t,name:a})?[]:{kind:exports.DeclarationKinds.EnumMemberDeclaration,id:te(e,a),name:a,docs:Q({declaration:t}),source:n({declaration:t}),signature:G(`enum E { ${t.getText()} }`).replace(/,$/,""),value:t.getValue()}}))}({enumID:e,enumDeclaration:n,getSource:a}),l=function({isConst:e,name:t,members:n}){const a=e?"const enum":"enum",r=n.map((({signature:e})=>e)).join();return J(`${a} ${t} { ${r} }`)}({isConst:c,name:t,members:s});return s.sort(ee),{kind:r,id:e,name:t,docs:i,source:o,signature:l,isConst:c,members:s}}({id:o,name:c,declaration:s,getSource:n});if(function(e){return y.Node.isTypeAliasDeclaration(e)}(s))return function({id:e,name:t,declaration:n,getSource:a}){const r=exports.DeclarationKinds.TypeAliasDeclaration,i=Q({declaration:n}),o=a({declaration:n}),c=function({declaration:e}){return J(e.getText())}({declaration:n});return{kind:r,id:e,name:t,docs:i,source:o,signature:c}}({id:o,name:c,declaration:s,getSource:n});if(se(s)&&t>0){if(i.has(e))return[];const r=le({module:s,moduleName:o,maxDepth:t-1,getSource:n,getType:a});return i.add(e),function({id:e,name:t,declaration:n,declarations:a,getSource:r}){const i=exports.DeclarationKinds.NamespaceDeclaration,o=Q({declaration:n}),c=r({declaration:n}),s=function({id:e,name:t}){return J(function({name:e}){return e.startsWith("'")||e.startsWith('"')}({name:t})?`module ${t} {}`:`namespace ${e} {}`)}({id:e,name:t});return{kind:i,id:e,name:e,docs:o,source:c,signature:s,declarations:a}}({id:o,name:c,declaration:s,declarations:r,getSource:n})}return function(e){return y.Node.isSourceFile(e)}(s)&&t>0?function({id:e,name:t,declaration:n,declarations:a,getSource:r}){const i=exports.DeclarationKinds.NamespaceDeclaration,o=function({declaration:e}){var t;const n=null==(t=e.getDescendantsOfKind(y.SyntaxKind.JSDocComment)[0])?void 0:t.getText();return n?[n]:[]}({declaration:n}),c=r({declaration:n}),s=function({declaration:e}){return J(`module '${ie({declaration:e})}' {}`)}({declaration:n});return{kind:i,id:e,name:t,docs:o,source:c,signature:s,declarations:a}}({id:o,name:c,declaration:s,declarations:le({module:s,moduleName:o,maxDepth:t-1,getSource:n,getType:a}),getSource:n}):[]})).sort(ee);return{variables:o.filter(M),functions:o.filter(v),classes:o.filter(F),interfaces:o.filter(A),enums:o.filter(_),typeAliases:o.filter(U),namespaces:o.filter(q)}}({exportedDeclarations:[...o,...c,...s,...l],maxDepth:n,getSource:a,getType:r})}function de({indexFile:e,declarations:t,getRepositoryFileURL:n,getUnpkgFileURL:a}){const r=ie({declaration:e}),i=ue({declarations:t});return Array.from(new Set([r,...i])).sort().map((e=>{const t=n({filename:e}),i=a({filename:e});return e===r?{isIndexFile:!0,filename:e,url:t,unpkgURL:i}:{filename:e,url:t,unpkgURL:i}}))}function ue({declarations:e}){return Object.values(e).flat().flatMap((e=>{const{source:{filename:t}}=e;if(q(e)){const{declarations:n}=e;return[t,...ue({declarations:n})]}return t}))}function ge(e){return e.replace(/\\/g,"/")}function pe({fileSystem:t,entryPoint:n,maxDepth:a,pattern:r,repository:i,id:o}){const c=e.performance.now();K("extractPackageAPI: extracting API: %O",{id:o,entryPoint:n,maxDepth:a,pattern:r,repository:i,fileSystem:t});const s=function({fileSystem:e,pattern:t="**/*.ts"}){const n=new y.Project({fileSystem:e,compilerOptions:{lib:["lib.esnext.full.d.ts"]}});return n.addSourceFilesAtPaths(t),n}({fileSystem:t,pattern:r});K("extractPackageAPI: created project: %O",{id:o,files:s.getSourceFiles().map((e=>e.getFilePath()))});const l=s.getSourceFileOrThrow(n);K("extractPackageAPI: found index file: %O",{id:o,indexFile:l.getFilePath()});const d=function({repository:e}){if(!e)return()=>{};const{url:t,tag:n="",dir:a=""}=e,r=N.default.fromUrl(t,{noGitPlus:!0});if(!r)return()=>{};const i=function({info:e}){const{type:t}=e;return"bitbucket"===t?"#lines-":"#L"}({info:r});return({filename:e,line:t})=>{const o=ge(I.join(a,e));return`${r.browse(o,{committish:n})}${t?`${i}${t}`:""}`}}({repository:i});K("extractPackageAPI: got repository file URL provider");const u=function({id:e}){return e?({filename:t,line:n})=>{const a=`https://unpkg.com/browse/${e}/${t}`;return n?`${a}#L${n}`:a}:()=>{}}({id:o});K("extractPackageAPI: got unpkg file URL provider");const g=function({getRepositoryFileURL:e,getUnpkgFileURL:t}){return({declaration:n})=>{const a=ie({declaration:n}),r=function({declaration:e}){return y.Node.isSourceFile(e)?1:e.getStartLineNumber()}({declaration:n});return{filename:a,line:r,url:e({filename:a,line:r}),unpkgURL:t({filename:a,line:r})}}}({getRepositoryFileURL:d,getUnpkgFileURL:u});K("extractPackageAPI: got source provider");const p=function({project:e}){const t=e.getTypeChecker();return({declaration:e})=>{let n="any";try{const a=t.compilerObject,{compilerNode:r}=e,i=a.getTypeAtLocation(r);n=a.typeToString(i,r,y.ts.TypeFormatFlags.NoTruncation|y.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope)}catch(e){K("type checker: error: %O",{err:e})}return n}}({project:s});K("extractPackageAPI: got type checker");const m=function({indexFile:e}){var t,n;return null==(t=e.getDescendantsOfKind(y.SyntaxKind.JSDocTag).find((e=>"packageDocumentation"===e.getTagName())))||null==(n=t.getParentIfKind(y.SyntaxKind.JSDocComment))?void 0:n.getText()}({indexFile:l});K("extractPackageAPI: got package overview: %O",{id:o,overview:m});const f=function({project:e,indexFile:t,getSource:n,getType:a,maxDepth:r=5}){return le({module:t,moduleName:"",maxDepth:r,getSource:n,getType:a,project:e})}({project:s,indexFile:l,maxDepth:a,getSource:g,getType:p});K("extractPackageAPI: got package declarations: %O",{id:o,declarations:f});const D=de({indexFile:l,declarations:f,getRepositoryFileURL:d,getUnpkgFileURL:u});K("extractPackageAPI: got package files: %O",{id:o,files:D});const x=Math.round(e.performance.now()-c);return K("extractPackageAPI: performance (ms): %O",{id:o,elapsed:x}),K("extractPackageAPI: extracted package API: %O",{id:o,api:{overview:m,declarations:f,files:D}}),{overview:m,declarations:f,files:D}}function me({source:e}){return null!=e&&e.endsWith(".ts")?[I.normalize(e)]:[]}function fe({name:e,extension:t}){if(!e)return[];const n=e.replace(".d.ts","").replace(".ts","").replace(".js","").replace("@","").replace("/","__");return[`${e}${t}`,`${n}${t}`]}function De({types:e,typings:t}){const n=e||t;return null!=n&&n.endsWith(".d.ts")?[I.normalize(n)]:[]}const ye={typescript:"lib/typescript.d.ts"},xe=u.promisify(k.default.pipeline);exports.analyzeRegistryPackage=async function({name:n,version:a,registry:r,mirrors:i,ignoreLicense:o,ignoreFilePatternOptimizations:c,skipAPIExtraction:s=!1}){const l=e.performance.now();K("analyzeRegistryPackage: analyzing package: %O",{name:n,version:a});const d=await t.getPackageManifest({name:n,version:a,registry:r,mirrors:i}),{id:u}=d;if(K("analyzeRegistryPackage: got manifest: %O",{id:u,manifest:d}),s)return K("analyzeRegistryPackage: skipping API extraction: %O",{id:u}),{id:u,manifest:d,api:void 0,elapsed:Math.round(e.performance.now()-l),createdAt:(new Date).toISOString()};const g=await async function({manifest:e,ignoreLicense:t,ignoreFilePatternOptimizations:n}){const{id:a,name:r,version:i,license:o,gitHead:c,gitRepository:s,dist:{tarball:l},source:d,types:u,typings:g}=e;if(!function({license:e,ignoreLicense:t=!1}){return!!t||!!e&&"unlicensed"!==e.toLowerCase()&&!e.toLowerCase().startsWith("see ")}({license:o,ignoreLicense:t}))return void K("tryGetPackageAPI: invalid license: %O",{id:a,license:o});const p=await async function({tarball:e}){try{const t=new y.InMemoryFileSystemHost;return await xe(P.default.stream(e),h.default(),function({fileSystem:e}){const t=T.default.extract();return t.on("entry",((t,n,a)=>{const{type:r,name:i}=t,o=function({name:e}){return ge(e).split("/").slice(1).join("/")}({name:i});if(!function({type:e,filename:t}){return"file"===e&&t.endsWith(".ts")}({type:r,filename:o}))return n.resume(),a();n.pipe(b.default((t=>{const n=t.toString();e.writeFileSync(o,n),a()})))})),t}({fileSystem:t})),t}catch(t){return void K("tryDownloadPackage: download failed: %O",{tarball:e,err:t})}}({tarball:l});if(!p)return void K("tryGetPackageAPI: download failed: %O",{id:a,tarball:l});const m=function({fileSystem:e,name:t,source:n,types:a,typings:r}){const i=[...me({source:n}),...De({types:a,typings:r}),"public-package-api.ts",...fe({name:t,extension:".ts"}),"index.ts","main.ts","public-package-api.d.ts",...fe({name:t,extension:".d.ts"}),"index.d.ts","main.d.ts"];for(const t of i){const n=e.globSync([`**/${t}`,"!node_modules/*"]),[a]=n.sort(((e,t)=>{const n=e.split("/").length-t.split("/").length,a=e.localeCompare(t);return n||a}));if(a)return a}}({fileSystem:p,name:r,source:d,types:u,typings:g});if(!m)return void K("tryGetPackageAPI: entry point not found: %O",{id:a,name:r,source:d,types:u,typings:g,fileSystem:p});const f=function({id:e,gitRepository:t,gitHead:n,version:a}){if(!t)return;const{url:r,directory:i}=t;return function({id:e}){return e.startsWith("@types/")}({id:e})?{url:r,dir:i}:{url:r,tag:null!=n?n:`v${a}`,dir:i}}({id:a,gitRepository:s,gitHead:c,version:i}),D=function({name:e,ignoreFilePatternOptimizations:t=!1}){if(!t)return ye[e]}({name:r,ignoreFilePatternOptimizations:n});try{return pe({fileSystem:p,entryPoint:m,id:a,repository:f,pattern:D})}catch(e){return void K("tryGetPackageAPI: API extraction failed: %O",{id:a,err:e})}}({manifest:d,ignoreLicense:o,ignoreFilePatternOptimizations:c});K("analyzeRegistryPackage: extracted API: %O",{id:u,api:g});const p=Math.round(e.performance.now()-l);return K("analyzeRegistryPackage: performance (ms): %O",{id:u,elapsed:p}),{id:u,manifest:d,api:g,elapsed:p,createdAt:(new Date).toISOString()}},exports.isClassConstructorDeclaration=function(e){return e.kind===exports.DeclarationKinds.ClassConstructorDeclaration},exports.isClassDeclaration=F,exports.isClassMethodDeclaration=$,exports.isClassPropertyDeclaration=O,exports.isEnumDeclaration=_,exports.isEnumMemberDeclaration=function(e){return e.kind===exports.DeclarationKinds.EnumMemberDeclaration},exports.isFunctionDeclaration=v,exports.isInterfaceCallSignatureDeclaration=j,exports.isInterfaceConstructSignatureDeclaration=R,exports.isInterfaceDeclaration=A,exports.isInterfaceIndexSignatureDeclaration=L,exports.isInterfaceMethodDeclaration=E,exports.isInterfacePropertyDeclaration=w,exports.isNamespaceDeclaration=q,exports.isTypeAliasDeclaration=U,exports.isVariableDeclaration=M;
//# sourceMappingURL=extractor.cjs.production.min.js.map