From 5d20fbfb0510347be23b862701c3c313c72a5e5d Mon Sep 17 00:00:00 2001 From: Andrei Dumitrescu <5057797+andreidmt@users.noreply.github.com> Date: Wed, 8 Feb 2023 10:04:48 +0100 Subject: [PATCH] refactor(utils-node): update jsdocs and var renames --- lib/utils/node.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/utils/node.js b/lib/utils/node.js index 9fbb29f..c8230d1 100644 --- a/lib/utils/node.js +++ b/lib/utils/node.js @@ -1,12 +1,11 @@ +import path from "node:path" import { readFile } from "node:fs/promises" -import { join, resolve } from "node:path" - import { cyan } from "./colors.js" /** * Format Node.js `process.hrtime()` output to a human readable string. * - * @param {[number, number]} input + * @param {[number, number]} input Node.js `process.hrtime()` output * @returns {string} * * @example @@ -40,21 +39,21 @@ export const getNodeVersion = () => { /** * Read a file and parse it as JSON. * - * @param {string} path + * @param {string} input File path * * @returns {Promise>} * @example * readFileAsJSON("/home/user/tsd-lite-cli/package.json") * // => { name: "tsd-lite-cli", version: "1.0.0", ... } */ -export const readFileAsJSON = path => - readFile(path, "utf8") +export const readFileAsJSON = input => + readFile(input, "utf8") .then(buffer => JSON.parse(buffer.toString())) .catch(error => { console.error( "readFileAsJSON", "ERROR", - `Failed to parse JSON file: ${cyan.fg(path)}` + `Failed to parse JSON file: ${cyan.fg(input)}` ) throw error @@ -78,7 +77,9 @@ export const readFileAsJSON = path => */ export const getPackageInfo = () => { const __dirname = new URL(import.meta.url).pathname - const path = join(__dirname, "..", "..", "..", "package.json") + const filePath = path.join(__dirname, "..", "..", "..", "package.json") - return /** @type {Promise} */ (readFileAsJSON(resolve(path))) + return /** @type {Promise} */ ( + readFileAsJSON(path.resolve(filePath)) + ) }