I disovered the hard way today that I need to split a library into two packages; lets call them CoreLib
and TestCoreLib
. The CoreLib
package is a library, the TestCoreLib
library is the bundle of utilities and actors needs to setup the test environment required to test the CoreLib
library. The added benefit of splitting this into two packages is that apps built with CoreLib
can also beneift from use of TestCoreLib
as it also suffices as a mocking library.
As TestCoreLib
uses some actors from CoreLib
, I defined CoreLib
as a peerDependency of TestCoreLib
.
{
"name": "TestCoreLib",
"version": "1.0.0-rc.1",
"type": "module",
"peerDependencies": {
"CoreLib": "^1.0.0-rc.0"
}
}
Conversely, I defined TestCoreLib
as a devDependency of CoreLib
as CoreLib
of course has the need of passing its tests before publish.
{
"name": "CoreLib",
"version": "1.0.0-rc.1",
"type": "module",
"devDependencies": {
"TestCoreLib": "^1.0.0-rc.0"
}
}
Both release candidate packages have been published to NPM successfully and I have setup a third project DemoApp
that uses both CoreLib
and TestCoreLib
successfully.
{
"name": "DemoApp",
"version": "1.0.0-rc.1",
"type": "module",
"devDependencies": {
"CoreLib": "^1.0.0-rc.0",
"TestCoreLib": "^1.0.0-rc.0"
}
}
The problem is now in the development branch of the CoreLib
project. Tests don't complete complete as the following error is thrown:
Uncaught Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'CoreLib' imported from /path/to/CoreLib/node_modules/CoreTestLib/lib/index.js
That tells me that CoreLib
is not being picked up by TestCoreLib
, even though TestCoreLib
is in the node_modules
directory of the CoreLib
project. The first statement in TestCoreLib
is an import from CoreLib
, so I assume the error is being thrown as that import is not being resolved even though it should... right?
I always want the development version of CoreLib
to be used by TestCoreLib
, so I am concerned about adding CoreLib
as a devDependency
(instead of a peerDependency
) of TestCoreLib
as I worry that doing such will lock CoreLib
into version conflict with its own prior release, but I am honestly confused about what would happen in that context.
The lazy boy moon shot of linking TestCoreLib
to CoreLib
does not solve the problem either, so I am obviously missing something fundamental that I would really appreciate your help with.
Do you know of any projects that successfully split their packages off into peerDependencies in such a way that you could refer me to?
Is there an elephant in the room sitting top of me and if so could you tell it to get off so that I can resolve this maddening issue and move on? LMAO
Be safe, well, calm, clear, happy fellow humans. Thanks for considerations.