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

Commit

Permalink
refactor: consolidate getPackageJson and remove pkg-dir dependency (#…
Browse files Browse the repository at this point in the history
…1039)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
Skn0tt and kodiakhq[bot] committed Jun 3, 2022
1 parent 5aaf915 commit 132485e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
3 changes: 2 additions & 1 deletion package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
"normalize-path": "^3.0.0",
"p-map": "^4.0.0",
"path-exists": "^4.0.0",
"pkg-dir": "^5.0.0",
"precinct": "^9.0.1",
"read-package-json-fast": "^2.0.2",
"require-package-name": "^2.0.1",
Expand Down
10 changes: 2 additions & 8 deletions src/runtimes/node/utils/package_json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { promises as fs } from 'fs'
import { basename, join } from 'path'

import findUp from 'find-up'
import pkgDir from 'pkg-dir'

export interface PackageJson {
name?: string
Expand Down Expand Up @@ -54,13 +53,8 @@ export const getClosestPackageJson = async (resolveDir: string): Promise<Package

// Retrieve the `package.json` of a specific project or module
export const getPackageJson = async function (srcDir: string): Promise<PackageJson> {
const packageRoot = await pkgDir(srcDir)

if (packageRoot === undefined) {
return {}
}

return readPackageJson(`${packageRoot}/package.json`)
const result = await getClosestPackageJson(srcDir)
return result?.contents ?? {}
}

export const getPackageJsonIfAvailable = async (srcDir: string): Promise<PackageJson> => {
Expand Down

1 comment on commit 132485e

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱ Benchmark results

largeDepsEsbuild: 7.8s

largeDepsZisi: 55.2s

Please sign in to comment.