sfdx-lwc-jest
sfdx-lwc-jest copied to clipboard
Consider using `peerDependencies` for LWC
Currently @salesforce/sfdx-lwc-jest has an explicit dependency on these core LWC packages:
@lwc/compiler@lwc/engine-dom@lwc/engine-server@lwc/module-resolver@lwc/synthetic-shadow@lwc/wire-service
And these lwc-test packages:
@lwc/jest-preset@lwc/jest-resolver@lwc/jest-serializer@lwc/jest-transformer
I've seen cases where a repo ends up with mixed LWC dependencies, due to @salesforce/sfdx-lwc-jest bringing in its own version of LWC, in addition to 1) direct dependencies on LWC, and 2) dependencies from other meta-packages (like LWR). This can lead to version mismatch errors where a component is compiled with one version of LWC and run through another version's runtime.
It's less of an issue for the lwc-test dependencies, but it could still happen.
Arguably we could use peerDependencies for the above – at least for the core LWC packages. This would be a breaking change, since consumers would now need to install their own version of LWC on top of @salesforce/sfdx-lwc-jest.
We could ease the burden by requiring only the lwc package to be installed, but this would require changing all the imports from e.g. @lwc/engine-dom to lwc/engine-dom. The same may need to be done for @lwc/jest-*, which does use peerDependencies already.