From 7c94607c8afbd12a0d152e2a818ca099e672006c Mon Sep 17 00:00:00 2001 From: Raul Catalinas <105791463+RaulCatalinas@users.noreply.github.com> Date: Wed, 1 May 2024 18:31:04 +0200 Subject: [PATCH] feat: use 'process.cwd()' to retrieve full path to package.json - Updated to use 'process.cwd()' to obtain the full path to the package.json file. --- src/utils/package-json.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/utils/package-json.ts b/src/utils/package-json.ts index c3a8042..33362c2 100644 --- a/src/utils/package-json.ts +++ b/src/utils/package-json.ts @@ -1,5 +1,6 @@ // NodeJS import fs from 'node:fs/promises' +import process from 'node:process' // Constants import { UTF8_ENCODING } from '@/constants/encoding' @@ -14,7 +15,9 @@ interface Props { export async function addScript({ key, value }: Props) { try { - const packageJsonData = await fs.readFile('./package.json', { + const packageJsonPath = `${process.cwd()}/package.json` + + const packageJsonData = await fs.readFile(packageJsonPath, { encoding: UTF8_ENCODING }) @@ -23,7 +26,7 @@ export async function addScript({ key, value }: Props) { packageJsonObj.scripts[key] = value await fs.writeFile( - './package.json', + packageJsonPath, JSON.stringify(packageJsonObj, null, 2), { encoding: UTF8_ENCODING