I maintain a JavaScript library that is published on the npm registry and it has lots of dependencies. It gets difficult to keep track of what part of the code depends on what external packages.
Unfortunately neither lerna
, yarn
's workspaces, npm link
, or npm
's local path dependency declaration help. (I explain why after the example.)
I want to be able to break down the dependencies
list declared in package.json
by extracting some of the dependencies into new "sub-packages".
So, instead of having the following dependency list
// ~/code/example-lib/package.json
{
"name": "example-lib",
"dependencies": {
"lodash": "*",
"request": "*",
"chalk": "*",
"bluebird": "*",
"mz": "*",
"moment": "*",
"socket.io": "*",
"socket.io-client": "*",
"react": "*",
"react-dom": "*"
}
}
I want to extract some of the dependencies into a new local package example-lib-subpackage
. With local I mean that example-lib-subpackage
is only meant to be consumed by example-lib
.
example-lib-subpackage
's dependency list would be;
// ~/code/example-lib/packages/example-lib-subpackage/package.json
{
"name": "example-lib-subpackage",
"dependencies": {
"lodash": "*",
"request": "*",
"bluebird": "*",
"moment": "*",
"socket.io-client": "*",
"react": "*",
"react-dom": "*"
}
}
and example-lib
's dependency list would then be considerably reduced to;
// ~/code/example-lib/package.json
{
"name": "example-lib",
"dependencies": {
"chalk": "*",
"example-lib-subpackage": "./packages/example-lib-subpackage",
"mz": "*",
"socket.io": "*"
}
}
Note how example-lib
now depends on the local package example-lib-subpackage
;
...
"name": "example-lib",
"dependencies": {
...
"example-lib-subpackage": "./packages/example-lib-subpackage",
...
Has anyone achieved this? It would be super convenient.
Note that lerna
and yarn
's workspaces feature only help if you are ok with publishing the local packages to the npm registry. But in my case publishing the local package example-lib-subpackage
to the npm registry doesn't make sense.
Also, npm link
and npm
's local path dependency feature only work for packages that aren't published but example-lib
needs to be on the npm registry.
Local paths [...] should not be used when publishing packages to the public registry.
Quote from https://docs.npmjs.com/files/package.json#local-paths
Pub/Sub allows services to communicate asynchronously, with latencies on the order of 100 milliseconds. Pub/Sub is used for streaming analytics and data integration pipelines to ingest and distribute data.
Google Cloud Pub/Sub provides messaging between applications. Cloud Pub/Sub is designed to provide reliable, many-to-many, asynchronous messaging between applications. Publisher applications can send messages to a "topic" and other applications can subscribe to that topic to receive the messages.
Cloud Pub/Sub supports three ways of receiving messages: streaming pull, pull, and push.
Since package.json
is just a JS object, you might extend it before publishing to NPM.
On prepublish
:
example-lib-subpackage
dependencyexample-lib
dependencies with the one declared in
example-lib-subpackage
package.json
PouchDb follows a vaguely similar approach described more in detail here and here.
I was thinking you could use a build tool to maintain multiple package.json
s and have them compile down to the real one - but you'd be fighting the platform the whole way. You'd have to have your own CLI for installing, and it would be a mess.
You say:
Note that
lerna
andyarn
's workspaces feature only help if you are ok with publishing the local packages to the npm registry. But in my case publishing the local packageexample-lib-subpackage
to the npm registry doesn't make sense.
I don't think you are going to find a solution that makes perfect sense (if you're going down the route of trying to do completely nonstandard things with npm), and I am curious why you are ruling out breaking out example-lib-subpackage
into its own repo - that seems like the obvious solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With