Skip to content

Commit

Permalink
Revert "fix: dynamic require of 'events' is not supported"
Browse files Browse the repository at this point in the history
This reverts commit 6550189.
  • Loading branch information
RaulCatalinas committed May 4, 2024
1 parent 6550189 commit ffd0b85
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 --packages=external src/index.ts",
"build": "esbuild --minify --bundle --format=esm --platform=node --outfile=dist/index.js src/index.ts",
"prepublishOnly": "bun run build"
},
"dependencies": {
Expand Down
2 changes: 2 additions & 0 deletions src/constants/errors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
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}.`,
Expand Down
11 changes: 11 additions & 0 deletions src/controllers/handlers-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,24 @@ 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
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()

Expand Down
16 changes: 11 additions & 5 deletions src/utils/package-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ import type { PackageJson } from '@/types/package-json'
interface Props {
key: string
value: string
packageJsonPath: string
}

export async function addScript({ key, value }: Props) {
export async function addScript({ key, value, packageJsonPath }: 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
})
Expand All @@ -40,3 +37,12 @@ export async function addScript({ key, value }: Props) {
process.exit(1)
}
}

export async function existPackageJson(path: string) {
try {
return await fs.exists(path)
} catch {
console.error(ErrorMessages.Default)
process.exit(1)
}
}

0 comments on commit ffd0b85

Please sign in to comment.