Skip to content

Commit

Permalink
fix: safely fail if pnpapi cannot be found
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Oct 19, 2023
1 parent d5dc324 commit c2fc8d2
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/util/find-root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ let pnp: {
*/
function maybeRequirePnpApi(root: string): unknown {
if (pnp) return pnp
// eslint-disable-next-line node/no-missing-require
pnp = require(require.resolve('pnpapi', {paths: [root]}))
return pnp
try {
// eslint-disable-next-line node/no-missing-require
pnp = require(require.resolve('pnpapi', {paths: [root]}))
return pnp
} catch {}
}

const getKey = (locator: PackageLocator | string | [string, string] | undefined) => JSON.stringify(locator)
Expand All @@ -104,6 +106,9 @@ const isPeerDependency = (
*/
function findPnpRoot(name: string, root: string): string | undefined {
maybeRequirePnpApi(root)

if (!pnp) return

const seen = new Set()

const traverseDependencyTree = (locator: PackageLocator, parentPkg?: PackageInformation): string | undefined => {
Expand Down

0 comments on commit c2fc8d2

Please sign in to comment.