1

I am creating an Angular library - let's call it libA - that can use another Angular library - let's call it libB - for an optional feature, i.e., if the Angular application doesn't have the libB, the feature in the libA will be disabled. But, if the Angular app has the libB installed, the feature in libA will be available.

So, to implement this behavior, I'd have to make verifications in libA to check if libB is available. However, I'm having trouble verifying whether or not the libB is installed in the application.

Does anyone know how can I check if the libB is installed in the application inside libA?

Wesley Gonçalves
  • 1,985
  • 2
  • 19
  • 22

1 Answers1

0

projects/libA/package.json

{
    "name": "libA",
    "version": "0.0.0",
    "peerDependencies": {
        "libB": "0.0.0",
    },
    "dependencies": {
        "tslib": "^2.0.0"
    },
    "publishConfig": {
        "registry": "http://192.168.10.20:4873"
    }

}

And main package configuration see it (example): How to setup angular project as a dependency in package.json of another angular project

My solution is (IP is a example)

I run a own registry (example: https://verdaccio.org/) on one Linux VM (exist docker too) and I upload my package into this. Every package set:

{
    "name": "@my-name/package-name",
    "version": "0.0.0",
    "peerDependencies": {
       ...
    },
    "dependencies": {
        "tslib": "^2.0.0"
    },
    "publishConfig": {
        "registry": "http://192.168.10.20:4873"
    }
}
$ ng build <package-name>
$ cd /path/to/dist/package-name
$ npm publish

In Angular project

$ npm login --scope=@my-name --registry=http://192.168.10.20:4873/
$ npm install @my-name/package-name

(I used many configuration to set registry, so maybe login not enough. I not tracked it. :D)

Numichi
  • 926
  • 6
  • 14