This issue seems to be all over GitHub's NX repository, however I was not able to find any working solution there.
My workspace contains two buildable libraries: ui/avatar
and ui/icon
and one publishable library, called bar
The idea would be to use ui/avatar
and ui/icon
as internal monorepo libraries (e.g. these can be imported in the apps directly) but I also want to encapsulate these 2 buildable libs into bar
and publish bar
as a npm package so that external consumers can benefit from it.
Here's a general overview of the file structure:
📦libs
┣ 📂external
┃ ┗ 📂bar
┃ ┃ ┣ 📂src
┃ ┃ ┃ ┣ 📂lib
┃ ┃ ┃ ┃ ┗ 📜external-bar.module.ts
┃ ┃ ┣ 📜ng-package.json
┃ ┃ ┣ 📜package.json
┃ ┃ ┣ 📜project.json
┃ ┃ ┣ 📜tsconfig.json
┣ 📂ui
┃ ┣ 📂avatar
┃ ┃ ┣ 📂src
┃ ┃ ┃ ┣ 📂lib
┃ ┃ ┃ ┃ ┣ 📂avatar
┃ ┃ ┃ ┃ ┃ ┗ 📜avatar.component.ts
┃ ┃ ┃ ┃ ┗ 📜ui-avatar.module.ts
┃ ┃ ┃ ┣ 📜index.ts
┃ ┃ ┣ 📜ng-package.json
┃ ┃ ┣ 📜package.json
┃ ┃ ┣ 📜project.json
┃ ┃ ┣ 📜tsconfig.json
┃ ┗ 📂icon
┃ ┃ ┣ 📂src
┃ ┃ ┃ ┣ 📂lib
┃ ┃ ┃ ┃ ┣ 📂icon
┃ ┃ ┃ ┃ ┃ ┗ 📜icon.component.ts
┃ ┃ ┃ ┃ ┗ 📜ui-icon.module.ts
┃ ┃ ┃ ┣ 📜index.ts
┃ ┃ ┣ 📜ng-package.json
┃ ┃ ┣ 📜package.json
┃ ┃ ┣ 📜project.json
┃ ┃ ┗ 📜tsconfig.json
That initial part, works.
I'm able to import ui/avatar
into bar
and generate the @blue/bar
package. The problem is that the generated package.json
of @blue/bar
looks as follows:
{
"name": "@blue/bar",
"version": "0.0.1",
"peerDependencies": {
"@angular/common": "^14.1.0",
"@angular/core": "^14.1.0",
"@blue/ui-avatar": "0.0.1" <-- this!!
},
"dependencies": {
"tslib": "^2.3.0"
},
"module": "esm2020/blue-bar.mjs",
"es2020": "esm2020/blue-bar.mjs",
"esm2020": "esm2020/blue-bar.mjs",
"typings": "index.d.ts",
"exports": {
"./package.json": {
"default": "./package.json"
},
".": {
"types": "./index.d.ts",
"es2020": "./esm2020/blue-bar.mjs",
"esm2020": "./esm2020/blue-bar.mjs",
"default": "./esm2020/blue-bar.mjs"
}
},
"sideEffects": false
}
The generated package, expects ui/avatar
to be a an existing npm package (and thus to exist in some registry) but what I really need is to bundle the ui/avatar
as part of the @blue/bar package and not as a third party dependency.
I have tried to adjust the tsconfig.json
file of the bar
lib to somehow try to resolve the dependencies locally (using paths
) but it doesn't seems to work.
"compilerOptions": {
"declarationMap": false,
"paths": {
"@blue/ui-avatar": ["libs/ui/avatar/src/index.ts"],
"@blue/ui-icon": ["libs/ui/icon/src/index.ts"]
}
}
Any hints would be greately appreciated :)