The official documentation for peerDependency‘s says (emphasis mine):
A plugin package is meant to be used with another “host” package, even though it does not always directly use the host package.
I’ve got a situation where my plugin does use the host package directly (in a test), even though this peerDependency
is meant to be optional for the app. This is the relationship I want between these packages:
App --may depend on, but may not--> canvas
My package --optional peer dependency--> canvas
My package tests --depends on--> canvas
How should my package.json
be written for this? Here’s what I’ve currently got, and I think it works?
{
// ...
"devDependencies": {
"canvas": "^2.11.2"
},
"peerDependencies": {
"canvas": "^2.11.2",
"jsdom": "^24.0.0"
},
"peerDependenciesMeta": {
"canvas": {
"optional": true
}
}
}
Is this the correct way to write a package.json
with an optional peerDependency
that it uses in test code?