package opam-check-npm-deps
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=04f5819d3a634909f4af015bb6e62a35a57322d98309e6196512f109e8a93036
sha512=297fcd8c64294d6be47986515119bb5be74e21c054f654b3de570cc563e5de033371d150ca5b7d3e9952c0d7a4ab2c0b7096e19161326628c5d5bf7539f22e90
doc/README.html
opam-check-npm-deps
An opam plugin to allow using the depexts field to define requirements on npm packages.
This plugin aims to solve a simple limitation: how to allow libraries written for either Melange or Js_of_ocaml to define dependencies to JavaScript packages. It addresses the problem by enabling library authors to leverage the depexts field in opam files to define dependencies on npm packages.
For bindings authors: defining constraints
Constraints are defined by adding an entry to depexts with the npm package name as the "system package" and an equality formula that matches the npm-version variable to a version range. This range can be defined using the same format as the dependencies field in a package.json file ^1.
For example, the reason-react bindings can define their dependency on the react npm package like this:
depexts: [
["react"] {npm-version = "^16.0.0 || ^17.0.0"}
["react-dom"] {npm-version = "^16.0.0 || ^17.0.0"}
]Or, to simplify:
depexts: [
["react" "react-dom"] {npm-version = "^16.0.0 || ^17.0.0"}
]For library users: checking npm dependencies status
Users can check the state of the npm dependencies by running the plugin:
$ opam-check-npm-deps
Ok: opam package "test.dev" requires the npm package "react" with constraint "^16.0.0 || ^17.0.0", installed version: "17.0.2"
Ok: opam package "test.dev" requires the npm package "react-dom" with constraint "^16.0.0 || ^17.0.0", installed version: "17.0.2"The plugin will provide information when errors occur:
$ opam-check-npm-deps
Error: opam package "test.dev" requires the npm package "react" with constraint "^16.0.0 || ^17.0.0", but the installed version found in the "node_modules/react/package.json" file is "18.2.0"
Error: opam package "test.dev" requires the npm package "react-dom" with constraint "^16.0.0 || ^17.0.0", but the installed version found in the "node_modules/react-dom/package.json" file is "18.2.0"When running the plugin, it checks the current opam switch to read all depexts fields that use the npm-version variable, and then reads the node_modules folder to determine if the constraints are satisfied.
If you don't want to the command to fail when errors are found, use the --dry-run flag:
$ opam-check-npm-deps --dry-runContributing
$ make init
$ make watchCommands
You can see all available commands by running make help or just make. Here are a few of the most useful ones:
make init: set up opam local switch and download OCaml, Melange and JavaScript dependenciesmake install: install OCaml dependenciesmake watch: watch for the filesystem and have Dune rebuild on every change