From 765446362779d70789860cb0156c3a40f266bb1c Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Tue, 14 May 2024 11:59:27 +0100 Subject: [PATCH] don't error about missing optional peer deps --- src/index.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/index.ts b/src/index.ts index 93a3837..f44e48e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -567,8 +567,22 @@ export class Project { } } + // collect a list of optional peers + let optionalPeers = []; + for (let depName of Object.keys(targetPkg['peerDependenciesMeta'] ?? {})) { + if (targetPkg['peerDependenciesMeta'][depName]?.optional === true) { + optionalPeers.push(depName); + } + } + for (let depName of depsToLink) { let depTarget = resolvePackagePath(depName, target, this.resolutionCache); + + if (!depTarget && optionalPeers.includes(depName)) { + // don't link or error about missing optional peer deps + continue; + } + if (!depTarget) { throw new Error( `[FixturifyProject] package ${name} in ${target} depends on ${depName} but we could not resolve it`