Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
feat: add isPackageListed
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolassutter committed Jan 17, 2023
1 parent ca2b6c8 commit 40b3750
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"devDependencies": {
"@commitlint/cli": "^17.3.0",
"@commitlint/config-conventional": "^17.3.0",
"@types/node": "^18.11.18",
"bumpp": "^8.2.1",
"eslint": "^8.28.0",
"husky": "^8.0.2",
Expand Down
14 changes: 10 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 26 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
import { isPackageExists as packageExists } from 'local-pkg'
import { isPackageExists as packageExists, PackageInfo } from 'local-pkg'
import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'

/**
* Permet de savoir si un certain package est listé
* dans le package.json du process en cours.
*
* @param name Le nom du package
*/
export const isPackageListed = (name: string) => {
const packageJson: Partial<PackageInfo['packageJson']> = (() => {
try {
return JSON.parse(readFileSync(
resolve(process.cwd(), 'package.json')
).toString())
} catch (error) {
return {}
}
})()

const deps = packageJson?.dependencies ?? {}
const devDeps = packageJson?.devDependencies ?? {}

return name in deps || name in devDeps
}

export function removeUnusedItems (items: string[]) {
return items.filter((item) => item !== '')
Expand Down

0 comments on commit 40b3750

Please sign in to comment.