From d84332097fb37dcd601098c346b9bd627600fb7d Mon Sep 17 00:00:00 2001 From: tbitw2549 Date: Wed, 24 Jan 2024 17:28:09 +0200 Subject: [PATCH] chore: remove console logs and fix type issues --- src/utils.ts | 6 +++--- test/index.test.ts | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index f0f67a3..34ec039 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -13,16 +13,17 @@ 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 @@ -30,7 +31,6 @@ export function extractJSDoc(modulePath: string, functionName: string) { } } } - console.log(files, modulePath, jsDocRE) const jsDoc = files.get(modulePath)?.match(jsDocRE) return jsDoc; } diff --git a/test/index.test.ts b/test/index.test.ts index 1f67e1a..21c7021 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -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) }) }) \ No newline at end of file