Skip to content

Commit

Permalink
chore: remove console logs and fix type issues
Browse files Browse the repository at this point in the history
  • Loading branch information
GalacticHypernova committed Jan 24, 2024
1 parent b1317c2 commit d843320
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ export function extractJSDoc(modulePath: string, functionName: string) {
try {
const jsDocRE = new RegExp(`(\\/\\*\\*[\\s\\S]*\\*\\/)\\s*(?:\n[^\\n]*${functionName})`,'i')
modulePath = resolve(modulePath.replaceAll('../',""))
// We want to cache the files to avoid duplicate lookups
if (!files.has(modulePath)) {
// This is a top level dep directory (example: h3), which is why it has package.json
if (existsSync(modulePath + "/package.json")) {
const pkg = JSON.parse(readFileSync(modulePath + "/package.json", "utf8"))
files.set(modulePath, readFileSync(modulePath + "/" + pkg.main, "utf8"))
}
// This is a nested dep directory (example: h3/core)
else {
if(statSync(modulePath).isDirectory()) { modulePath = modulePath+"/index" }
console.log(modulePath)
for (const ext of [".ts",".js",".mjs",".cjs"]) {
console.log("hi")
if (existsSync(modulePath + ext)) {
files.set(modulePath, readFileSync(modulePath+ext, "utf8"))
break
}
}
}
}
console.log(files, modulePath, jsDocRE)
const jsDoc = files.get(modulePath)?.match(jsDocRE)
return jsDoc;
}
Expand Down
2 changes: 2 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ describe("unjsdoc",() => {
})
it("should return null for non-existent jsdoc", () => {
const jsdoc = extractJSDoc("../playground", "noJSDoc")
// eslint-disable-next-line unicorn/no-null
expect(jsdoc).toEqual(null)
})
it("should return null for non-existent function", () => {
const jsdoc = extractJSDoc("../playground", "noFunction")
// eslint-disable-next-line unicorn/no-null
expect(jsdoc).toEqual(null)
})
})

0 comments on commit d843320

Please sign in to comment.