#npm #web #build-dependencies

npm_rs

Provides simple Rust to npm bindings to use in your build scripts

4 releases

0.2.1 Sep 3, 2021
0.2.0 Sep 3, 2021
0.1.2 Aug 6, 2021
0.1.1 Jun 9, 2021
0.1.0 May 31, 2021

#49 in Build Utils

Download history 139/week @ 2021-08-15 112/week @ 2021-08-22 119/week @ 2021-08-29 217/week @ 2021-09-05 313/week @ 2021-09-12 385/week @ 2021-09-19 278/week @ 2021-09-26 97/week @ 2021-10-03 221/week @ 2021-10-10 143/week @ 2021-10-17 180/week @ 2021-10-24 98/week @ 2021-10-31 137/week @ 2021-11-07 131/week @ 2021-11-14 106/week @ 2021-11-21 55/week @ 2021-11-28

446 downloads per month

MIT/Apache

13KB
159 lines

npm_rs

License (MIT OR APACHE) GitHub Workflow Status Crates.io docs.rs

A library to run npm commands from your Rust build script.

Documentation

This library will aid you in executing npm commands when building your crate/bin, removing the burden on having to manually do so or by using a tool other than Cargo.

This crate provides an abstraction over [Command] to use npm in a simple and easy package with fluent API.

npm_rs exposes [NpmEnv] to configure the npm execution enviroment and [Npm] to use said enviroment to execute npm commands.

Examples

Manual NODE_ENV setup

// build.rs

use npm_rs::*;

let exit_status = NpmEnv::default()
       .with_node_env(&NodeEnv::Production)
       .with_env("FOO", "bar")
       .init_env()
       .install(None)
       .run("build")
       .exec()?;

Automatic NODE_ENV setup

// build.rs

use npm_rs::*;

let exit_status = NpmEnv::default()
       .with_node_env(&NodeEnv::from_cargo_profile().unwrap_or_default())
       .with_env("FOO", "bar")
       .init_env()
       .install(None)
       .run("build")
       .exec()?;

[NpmEnv] implements [Clone] while under a nightly toolchain when feature nightly is enabled.

Features

NpmEnv can be Clone when the feature nightly is enabled. This only works under a nightly toolchain.

# Cargo.toml

[build.dependencies]
npm_rs = { version = "*", features = ["nightly"] }

Stability

Since this is a small library, I would like it to have all the needed features and to be usable before commiting to a v1.0.0.

Contributions are welcome!

License

npm_rs is either distributed under MIT or Apache-2.0 license. Choose as you please.

Dependencies