Skip to content

Commit

Permalink
feat: use 'process.cwd()' to retrieve full path to package.json
Browse files Browse the repository at this point in the history
- Updated to use 'process.cwd()' to obtain the full path to the package.json file.
  • Loading branch information
RaulCatalinas committed May 1, 2024
1 parent f7e620f commit 7c94607
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/utils/package-json.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// NodeJS
import fs from 'node:fs/promises'
import process from 'node:process'

// Constants
import { UTF8_ENCODING } from '@/constants/encoding'
Expand All @@ -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
})

Expand All @@ -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
Expand Down

0 comments on commit 7c94607

Please sign in to comment.