Skip to content
This repository was archived by the owner on Dec 28, 2024. It is now read-only.

Commit 5d20fbf

Browse files
committed
refactor(utils-node): update jsdocs and var renames
1 parent 30659e3 commit 5d20fbf

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

lib/utils/node.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1+
import path from "node:path"
12
import { readFile } from "node:fs/promises"
2-
import { join, resolve } from "node:path"
3-
43
import { cyan } from "./colors.js"
54

65
/**
76
* Format Node.js `process.hrtime()` output to a human readable string.
87
*
9-
* @param {[number, number]} input
8+
* @param {[number, number]} input Node.js `process.hrtime()` output
109
* @returns {string}
1110
*
1211
* @example
@@ -40,21 +39,21 @@ export const getNodeVersion = () => {
4039
/**
4140
* Read a file and parse it as JSON.
4241
*
43-
* @param {string} path
42+
* @param {string} input File path
4443
*
4544
* @returns {Promise<Record<string, unknown>>}
4645
* @example
4746
* readFileAsJSON("/home/user/tsd-lite-cli/package.json")
4847
* // => { name: "tsd-lite-cli", version: "1.0.0", ... }
4948
*/
50-
export const readFileAsJSON = path =>
51-
readFile(path, "utf8")
49+
export const readFileAsJSON = input =>
50+
readFile(input, "utf8")
5251
.then(buffer => JSON.parse(buffer.toString()))
5352
.catch(error => {
5453
console.error(
5554
"readFileAsJSON",
5655
"ERROR",
57-
`Failed to parse JSON file: ${cyan.fg(path)}`
56+
`Failed to parse JSON file: ${cyan.fg(input)}`
5857
)
5958

6059
throw error
@@ -78,7 +77,9 @@ export const readFileAsJSON = path =>
7877
*/
7978
export const getPackageInfo = () => {
8079
const __dirname = new URL(import.meta.url).pathname
81-
const path = join(__dirname, "..", "..", "..", "package.json")
80+
const filePath = path.join(__dirname, "..", "..", "..", "package.json")
8281

83-
return /** @type {Promise<PackageJSON>} */ (readFileAsJSON(resolve(path)))
82+
return /** @type {Promise<PackageJSON>} */ (
83+
readFileAsJSON(path.resolve(filePath))
84+
)
8485
}

0 commit comments

Comments
 (0)