#build-script #npm #web #build-dependencies #npm-package

build npm_rs

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

5 releases (1 stable)

1.0.0 Nov 16, 2022
0.2.1 Sep 3, 2021
0.1.2 Aug 6, 2021
0.1.1 Jun 9, 2021
0.1.0 May 31, 2021

#135 in Build Utils

Download history 467/week @ 2024-01-03 401/week @ 2024-01-10 285/week @ 2024-01-17 344/week @ 2024-01-24 549/week @ 2024-01-31 577/week @ 2024-02-07 552/week @ 2024-02-14 379/week @ 2024-02-21 383/week @ 2024-02-28 286/week @ 2024-03-06 3030/week @ 2024-03-13 4045/week @ 2024-03-20 4525/week @ 2024-03-27 3884/week @ 2024-04-03 3883/week @ 2024-04-10 3248/week @ 2024-04-17

16,493 downloads per month
Used in 16 crates (5 directly)

MIT/Apache

13KB
157 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 of 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()?;

License

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

Dependencies