diff --git a/package.json b/package.json index 1ac6c95..0e9fc83 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "lint:fix": "eslint src --fix", "format": "prettier src --check", "format:write": "prettier src --write", - "build": "esbuild --minify --bundle --format=esm --platform=node --outfile=dist/index.js src/index.ts", + "build": "esbuild --minify --bundle --format=esm --platform=node --outfile=dist/index.js --packages=external src/index.ts", "prepublishOnly": "bun run build" }, "dependencies": { diff --git a/src/constants/errors.ts b/src/constants/errors.ts index 61a889f..293f3fb 100644 --- a/src/constants/errors.ts +++ b/src/constants/errors.ts @@ -1,8 +1,6 @@ import { ISSUES } from './github' export enum ErrorMessages { - NotFound = "The package.json file wasn't found in the current directory.", - Default = `Something went wrong, try again later, please try again later, if the error persists please report it on ${ISSUES}.`, Dependencies = `An error occurred while installing dependencies, please try again later, if the error persists please report it on ${ISSUES}.`, diff --git a/src/controllers/handlers-options.ts b/src/controllers/handlers-options.ts index 2d30606..df2f863 100644 --- a/src/controllers/handlers-options.ts +++ b/src/controllers/handlers-options.ts @@ -9,7 +9,6 @@ import opener from 'opener' import { addCommitlint } from '@/utils/add-commitlint' import { generateCommitlintConfig } from '@/utils/commitlint' import { generateHuskyConfig } from '@/utils/husky-library' -import { existPackageJson } from '@/utils/package-json' import { getPackageManger } from '@/utils/package-managers' // NodeJS @@ -17,16 +16,6 @@ import process from 'node:process' export const handlerOptionBuild = async () => { try { - const packageJsonPath = `${process.cwd()}/package.json` - const existPackageJsonInTheCurrentDirectory = - await existPackageJson(packageJsonPath) - - if (!existPackageJsonInTheCurrentDirectory) { - console.error(ErrorMessages.NotFound) - - process.exit(1) - } - const packageManagerToUse = await getPackageManger() const useCommitlint = await addCommitlint() diff --git a/src/utils/package-json.ts b/src/utils/package-json.ts index b52bfb2..b6b206e 100644 --- a/src/utils/package-json.ts +++ b/src/utils/package-json.ts @@ -12,11 +12,14 @@ import type { PackageJson } from '@/types/package-json' interface Props { key: string value: string - packageJsonPath: string } -export async function addScript({ key, value, packageJsonPath }: Props) { +export async function addScript({ key, value }: Props) { try { + const isBuild = process.env.NODE_ENV === 'production' + + const packageJsonPath = isBuild ? '../package.json' : './package.json' + const packageJsonData = await fs.readFile(packageJsonPath, { encoding: UTF8_ENCODING }) @@ -37,12 +40,3 @@ export async function addScript({ key, value, packageJsonPath }: Props) { process.exit(1) } } - -export async function existPackageJson(path: string) { - try { - return await fs.exists(path) - } catch { - console.error(ErrorMessages.Default) - process.exit(1) - } -}