From 7cbfc2e8931d670f48b287da1e9255ccc34f6143 Mon Sep 17 00:00:00 2001 From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Tue, 17 Jul 2018 00:49:55 +0800 Subject: [PATCH 1/6] cmd(init/build): split init and build --- src/command/build.rs | 274 +++++++++++++++++++++++++++++++++++++++++++ src/command/init.rs | 97 ++++++--------- src/command/mod.rs | 69 +++-------- src/logger.rs | 3 +- 4 files changed, 333 insertions(+), 110 deletions(-) create mode 100644 src/command/build.rs diff --git a/src/command/build.rs b/src/command/build.rs new file mode 100644 index 00000000..8832cefe --- /dev/null +++ b/src/command/build.rs @@ -0,0 +1,274 @@ +//! Initializing a crate for packing `.wasm`s. + +use bindgen; +use build; +use command::utils::{set_crate_path, create_pkg_dir}; +use emoji; +use error::Error; +use indicatif::HumanDuration; +use manifest; +use progressbar::Step; +use readme; +use slog::Logger; +use std::time::Instant; +use PBAR; + +/// Everything required to configure and run the `wasm-pack init` command. +pub(crate) struct Build { + pub crate_path: String, + pub scope: Option, + pub disable_dts: bool, + pub target: String, + pub debug: bool, + // build_config: Option, + pub crate_name: String, +} + +/// The `BuildMode` determines which mode of initialization we are running, and +/// what build and install steps we perform. +pub enum BuildMode { + /// Perform all the build and install steps. + Normal, + /// Don't install tools like `wasm-bindgen`, just use the global + /// environment's existing versions to do builds. + Noinstall, +} + +/// Everything required to configure and run the `wasm-pack build` command. +#[derive(Debug,StructOpt)] +pub struct BuildOptions { + /// The path to the Rust crate. + pub path: Option, + + /// The npm scope to use in package.json, if any. + #[structopt(long = "scope", short = "s")] + pub scope: Option, + + #[structopt(long = "mode", short = "m", default_value = "normal")] + /// Sets steps to be run. [possible values: no-install, normal] + pub mode: String, + + #[structopt(long = "no-typescript")] + /// By default a *.d.ts file is generated for the generated JS file, but + /// this flag will disable generating this TypeScript file. + pub disable_dts: bool, + + #[structopt(long = "target", short = "t", default_value = "browser")] + /// Sets the target environment. [possible values: browser, nodejs] + pub target: String, + + #[structopt(long = "debug")] + /// Build without --release. + debug: bool, + + // build config from manifest + // build_config: Option, +} + +impl From for Build { + fn from(build_opts: BuildOptions) -> Self { + let crate_path = set_crate_path(build_opts.path); + let crate_name = manifest::get_crate_name(&crate_path).unwrap(); + // let build_config = manifest::xxx(&crate_path).xxx(); + Build { + crate_path, + scope:build_opts.scope, + disable_dts:build_opts.disable_dts, + target:build_opts.target, + debug:build_opts.debug, + // build_config, + crate_name, + } + } +} + +type BuildStep = fn(&mut Build, &Step, &Logger) -> Result<(), Error>; + +impl Build { + /// Execute this `Init` command. + pub fn run(&mut self, log: &Logger, mode: BuildMode) -> Result<(), Error> { + let process_steps = Build::get_process_steps(mode); + + let mut step_counter = Step::new(process_steps.len()); + + let started = Instant::now(); + + for (_, process_step) in process_steps { + process_step(self, &step_counter, log)?; + step_counter.inc(); + } + + let duration = HumanDuration(started.elapsed()); + info!(&log, "Done in {}.", &duration); + info!( + &log, + "Your WASM pkg is ready to publish at {}/pkg.", &self.crate_path + ); + + PBAR.message(&format!("{} Done in {}", emoji::SPARKLE, &duration)); + + PBAR.message(&format!( + "{} Your WASM pkg is ready to publish at {}/pkg.", + emoji::PACKAGE, + &self.crate_path + )); + Ok(()) + } + + fn get_process_steps(mode: BuildMode) -> Vec<(&'static str, BuildStep)> { + macro_rules! steps { + ($($name:ident),+) => { + { + let mut steps: Vec<(&'static str, BuildStep)> = Vec::new(); + $(steps.push((stringify!($name), Build::$name));)* + steps + } + }; + ($($name:ident,)*) => (steps![$($name),*]) + } + match mode { + BuildMode::Normal => steps![ + step_check_crate_config, + step_add_wasm_target, + step_build_wasm, + step_create_dir, + step_create_json, + step_copy_readme, + step_install_wasm_bindgen, + step_run_wasm_bindgen, + ], + BuildMode::Noinstall => steps![ + step_check_crate_config, + step_build_wasm, + step_create_dir, + step_create_json, + step_copy_readme, + step_run_wasm_bindgen + ], + } + } + + + fn step_check_crate_config(&mut self, step: &Step, log: &Logger) -> Result<(), Error> { + info!(&log, "Checking crate configuration..."); + manifest::check_crate_config(&self.crate_path, step)?; + info!(&log, "Crate is correctly configured."); + Ok(()) + } + + fn step_add_wasm_target(&mut self, step: &Step, log: &Logger) -> Result<(), Error> { + info!(&log, "Adding wasm-target..."); + build::rustup_add_wasm_target(step)?; + info!(&log, "Adding wasm-target was successful."); + Ok(()) + } + + fn step_build_wasm(&mut self, step: &Step, log: &Logger) -> Result<(), Error> { + info!(&log, "Building wasm..."); + build::cargo_build_wasm(&self.crate_path, self.debug, step)?; + + #[cfg(not(target_os = "windows"))] + info!( + &log, + "wasm built at {}/target/wasm32-unknown-unknown/release.", &self.crate_path + ); + #[cfg(target_os = "windows")] + info!( + &log, + "wasm built at {}\\target\\wasm32-unknown-unknown\\release.", &self.crate_path + ); + Ok(()) + } + + fn step_create_dir(&mut self, step: &Step, log: &Logger) -> Result<(), Error> { + info!(&log, "Creating a pkg directory..."); + create_pkg_dir(&self.crate_path, step)?; + info!(&log, "Created a pkg directory at {}.", &self.crate_path); + Ok(()) + } + + fn step_create_json(&mut self, step: &Step, log: &Logger) -> Result<(), Error> { + info!(&log, "Writing a package.json..."); + manifest::write_package_json( + &self.crate_path, + &self.scope, + self.disable_dts, + &self.target, + step, + )?; + #[cfg(not(target_os = "windows"))] + info!( + &log, + "Wrote a package.json at {}/pkg/package.json.", &self.crate_path + ); + #[cfg(target_os = "windows")] + info!( + &log, + "Wrote a package.json at {}\\pkg\\package.json.", &self.crate_path + ); + Ok(()) + } + + fn step_copy_readme(&mut self, step: &Step, log: &Logger) -> Result<(), Error> { + info!(&log, "Copying readme from crate..."); + readme::copy_from_crate(&self.crate_path, step)?; + #[cfg(not(target_os = "windows"))] + info!( + &log, + "Copied readme from crate to {}/pkg.", &self.crate_path + ); + #[cfg(target_os = "windows")] + info!( + &log, + "Copied readme from crate to {}\\pkg.", &self.crate_path + ); + Ok(()) + } + + fn step_install_wasm_bindgen(&mut self, step: &Step, log: &Logger) -> Result<(), Error> { + info!(&log, "Installing wasm-bindgen-cli..."); + bindgen::cargo_install_wasm_bindgen(step)?; + info!(&log, "Installing wasm-bindgen-cli was successful."); + + info!(&log, "Getting the crate name from the manifest..."); + self.crate_name = manifest::get_crate_name(&self.crate_path)?; + #[cfg(not(target_os = "windows"))] + info!( + &log, + "Got crate name {} from the manifest at {}/Cargo.toml.", + &self.crate_name, + &self.crate_path + ); + #[cfg(target_os = "windows")] + info!( + &log, + "Got crate name {} from the manifest at {}\\Cargo.toml.", + &self.crate_name, + &self.crate_path + ); + Ok(()) + } + + fn step_run_wasm_bindgen(&mut self, step: &Step, log: &Logger) -> Result<(), Error> { + info!(&log, "Building the wasm bindings..."); + bindgen::wasm_bindgen_build( + &self.crate_path, + &self.crate_name, + self.disable_dts, + &self.target, + self.debug, + step, + )?; + #[cfg(not(target_os = "windows"))] + info!( + &log, + "wasm bindings were built at {}/pkg.", &self.crate_path + ); + #[cfg(target_os = "windows")] + info!( + &log, + "wasm bindings were built at {}\\pkg.", &self.crate_path + ); + Ok(()) + } +} diff --git a/src/command/init.rs b/src/command/init.rs index c405a80b..09e7ff5a 100644 --- a/src/command/init.rs +++ b/src/command/init.rs @@ -1,8 +1,6 @@ //! Initializing a crate for packing `.wasm`s. -use bindgen; -use build; -use command::utils::set_crate_path; +use command::utils::{set_crate_path,create_pkg_dir}; use emoji; use error::Error; use indicatif::HumanDuration; @@ -43,71 +41,54 @@ pub struct Init { scope: Option, disable_dts: bool, target: String, + // build without --release. debug: bool, - crate_name: String, } -type InitStep = fn(&mut Init, &Step, &Logger) -> Result<(), Error>; +/// `Init` options +#[derive(Debug, StructOpt)] +pub struct InitOptions { + /// The path to the Rust crate. + pub path: Option, -impl Init { - /// Construct a new `Init` command. - pub fn new( - path: Option, - scope: Option, - disable_dts: bool, - target: String, - debug: bool, - ) -> Result { - let crate_path = set_crate_path(path); - let crate_name = manifest::get_crate_name(&crate_path)?; - Ok(Init { - crate_path, - scope, - disable_dts, - target, - debug, - crate_name, - }) - } + /// The npm scope to use in package.json, if any. + #[structopt(long = "scope", short = "s")] + pub scope: Option, - fn get_process_steps(mode: InitMode) -> Vec<(&'static str, InitStep)> { - macro_rules! steps { - ($($name:ident),+) => { - { - let mut steps: Vec<(&'static str, InitStep)> = Vec::new(); - $(steps.push((stringify!($name), Init::$name));)* - steps - } - }; - ($($name:ident,)*) => (steps![$($name),*]) - } + #[structopt(long = "no-typescript")] + /// By default a *.d.ts file is generated for the generated JS file, but + /// this flag will disable generating this TypeScript file. + pub disable_dts: bool, + + #[structopt(long = "target", short = "t", default_value = "browser")] + /// Sets the target environment. [possible values: browser, nodejs] + pub target: String, - match mode { - InitMode::Normal => steps![ - step_check_crate_config, - step_add_wasm_target, - step_build_wasm, - step_create_dir, - step_create_json, - step_copy_readme, - step_install_wasm_bindgen, - step_run_wasm_bindgen, - ], - InitMode::Nobuild => steps![step_create_dir, step_create_json, step_copy_readme,], - InitMode::Noinstall => steps![ - step_check_crate_config, - step_build_wasm, - step_create_dir, - step_create_json, - step_copy_readme, - step_run_wasm_bindgen - ], + #[structopt(long = "debug")] + /// Build without --release. + pub debug: bool, +} + +impl From for Init { + fn from(init_opts: InitOptions) -> Self { + let crate_path = set_crate_path(init_opts.path); + let crate_name = manifest::get_crate_name(&crate_path).unwrap(); + Init { + crate_path, + scope: init_opts.scope, + disable_dts:init_opts.disable_dts, + target:init_opts.target, + debug:init_opts.debug, } } +} +type InitStep = fn(&mut Init, &Step, &Logger) -> Result<(), Error>; + +impl Init { /// Execute this `Init` command. - pub fn process(&mut self, log: &Logger, mode: InitMode) -> Result<(), Error> { - let process_steps = Init::get_process_steps(mode); + pub fn run(&mut self, log: &Logger) -> Result<(), Error> { + let process_steps = Init::set_process_steps(); let mut step_counter = Step::new(process_steps.len()); diff --git a/src/command/mod.rs b/src/command/mod.rs index 2b9ed8dc..0e9a4e43 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -1,15 +1,17 @@ //! CLI command structures, parsing, and execution. +mod build; pub mod init; mod login; mod pack; mod publish; pub mod utils; -use self::init::{Init, InitMode}; use self::login::login; use self::pack::pack; use self::publish::publish; +use self::build::{Build,BuildMode}; +use self::init::Init; use error::Error; use slog::Logger; use std::path::PathBuf; @@ -21,37 +23,16 @@ use PBAR; pub enum Command { #[structopt(name = "init")] /// 🐣 initialize a package.json based on your compiled wasm! - Init { - /// The path to the Rust crate. - #[structopt(parse(from_os_str))] - path: Option, - - /// The npm scope to use in package.json, if any. - #[structopt(long = "scope", short = "s")] - scope: Option, - - #[structopt(long = "mode", short = "m", default_value = "normal")] - /// Sets steps to be run. [possible values: no-build, no-install, normal] - mode: String, - - #[structopt(long = "no-typescript")] - /// By default a *.d.ts file is generated for the generated JS file, but - /// this flag will disable generating this TypeScript file. - disable_dts: bool, - - #[structopt(long = "target", short = "t", default_value = "browser")] - /// Sets the target environment. [possible values: browser, nodejs] - target: String, + Init(init::InitOptions), - #[structopt(long = "debug")] - /// Build without --release. - debug: bool, - }, + /// build + #[structopt(name = "build")] + Build(self::build::BuildOptions), #[structopt(name = "pack")] /// 🍱 create a tar of your npm package but don't publish! Pack { - /// The path to the Rust crate. + /// The path to the Rust crate. #[structopt(parse(from_os_str))] path: Option, }, @@ -102,32 +83,18 @@ pub fn run_wasm_pack(command: Command, log: &Logger) -> result::Result<(), Error // Run the correct command based off input and store the result of it so that we can clear // the progress bar then return it let status = match command { - Command::Init { - path, - scope, - mode, - disable_dts, - target, - debug, - } => { + Command::Init(init_opts) => { info!(&log, "Running init command..."); - info!( - &log, - "Path: {:?}, Scope: {:?}, Skip build: {}, Disable Dts: {}, Target: {}, Debug: {}", - &path, - &scope, - &mode, - &disable_dts, - &target, - debug - ); - let modetype = match &*mode { - "no-build" => InitMode::Nobuild, - "no-install" => InitMode::Noinstall, - "normal" => InitMode::Normal, - _ => InitMode::Normal, + Init::from(init_opts).run(&log) + } + Command::Build(build_opts) => { + info!(&log, "Running build command..."); + let build_mode = match build_opts.mode.as_str() { + "no-install" => BuildMode::Noinstall, + "normal" => BuildMode::Normal, + _ => BuildMode::Normal, }; - Init::new(path, scope, disable_dts, target, debug)?.process(&log, modetype) + Build::from(build_opts).run(&log, build_mode) } Command::Pack { path } => { info!(&log, "Running pack command..."); diff --git a/src/logger.rs b/src/logger.rs index 3ddea3a7..1ceae491 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -33,7 +33,8 @@ pub fn new(cmd: &Command, verbosity: u8) -> Result { /// Figure out where to stick the log based off the command arguments given fn log_file_path(cmd: &Command) -> PathBuf { let path = match cmd { - Command::Init { path, .. } => path, + Command::Init(init_opts) => &init_opts.path, + Command::Build(build_opts) => &build_opts.path, Command::Pack { path } => path, Command::Publish { path } => path, Command::Login { .. } => &None, From edbd6f4118d7b15fa6af773d40d842d1094bb2e3 Mon Sep 17 00:00:00 2001 From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Tue, 17 Jul 2018 07:34:00 +0800 Subject: [PATCH 2/6] cmd(init/build): cargo fmt --- src/command/build.rs | 18 +++++++----------- src/command/init.rs | 16 ++++------------ src/command/mod.rs | 4 ++-- src/command/utils.rs | 5 +++++ 4 files changed, 18 insertions(+), 25 deletions(-) diff --git a/src/command/build.rs b/src/command/build.rs index 8832cefe..689dab40 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -1,8 +1,6 @@ -//! Initializing a crate for packing `.wasm`s. - use bindgen; use build; -use command::utils::{set_crate_path, create_pkg_dir}; +use command::utils::{create_pkg_dir, set_crate_path}; use emoji; use error::Error; use indicatif::HumanDuration; @@ -35,7 +33,7 @@ pub enum BuildMode { } /// Everything required to configure and run the `wasm-pack build` command. -#[derive(Debug,StructOpt)] +#[derive(Debug, StructOpt)] pub struct BuildOptions { /// The path to the Rust crate. pub path: Option, @@ -60,7 +58,6 @@ pub struct BuildOptions { #[structopt(long = "debug")] /// Build without --release. debug: bool, - // build config from manifest // build_config: Option, } @@ -72,10 +69,10 @@ impl From for Build { // let build_config = manifest::xxx(&crate_path).xxx(); Build { crate_path, - scope:build_opts.scope, - disable_dts:build_opts.disable_dts, - target:build_opts.target, - debug:build_opts.debug, + scope: build_opts.scope, + disable_dts: build_opts.disable_dts, + target: build_opts.target, + debug: build_opts.debug, // build_config, crate_name, } @@ -85,7 +82,7 @@ impl From for Build { type BuildStep = fn(&mut Build, &Step, &Logger) -> Result<(), Error>; impl Build { - /// Execute this `Init` command. + /// Execute this `Build` command. pub fn run(&mut self, log: &Logger, mode: BuildMode) -> Result<(), Error> { let process_steps = Build::get_process_steps(mode); @@ -148,7 +145,6 @@ impl Build { } } - fn step_check_crate_config(&mut self, step: &Step, log: &Logger) -> Result<(), Error> { info!(&log, "Checking crate configuration..."); manifest::check_crate_config(&self.crate_path, step)?; diff --git a/src/command/init.rs b/src/command/init.rs index 09e7ff5a..7f6213b1 100644 --- a/src/command/init.rs +++ b/src/command/init.rs @@ -1,6 +1,6 @@ //! Initializing a crate for packing `.wasm`s. -use command::utils::{set_crate_path,create_pkg_dir}; +use command::utils::{create_pkg_dir, set_crate_path}; use emoji; use error::Error; use indicatif::HumanDuration; @@ -41,8 +41,6 @@ pub struct Init { scope: Option, disable_dts: bool, target: String, - // build without --release. - debug: bool, } /// `Init` options @@ -63,22 +61,16 @@ pub struct InitOptions { #[structopt(long = "target", short = "t", default_value = "browser")] /// Sets the target environment. [possible values: browser, nodejs] pub target: String, - - #[structopt(long = "debug")] - /// Build without --release. - pub debug: bool, } impl From for Init { fn from(init_opts: InitOptions) -> Self { let crate_path = set_crate_path(init_opts.path); - let crate_name = manifest::get_crate_name(&crate_path).unwrap(); - Init { + Init { crate_path, scope: init_opts.scope, - disable_dts:init_opts.disable_dts, - target:init_opts.target, - debug:init_opts.debug, + disable_dts: init_opts.disable_dts, + target: init_opts.target, } } } diff --git a/src/command/mod.rs b/src/command/mod.rs index 0e9a4e43..a9e555f3 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -7,11 +7,11 @@ mod pack; mod publish; pub mod utils; +use self::build::{Build, BuildMode}; +use self::init::Init; use self::login::login; use self::pack::pack; use self::publish::publish; -use self::build::{Build,BuildMode}; -use self::init::Init; use error::Error; use slog::Logger; use std::path::PathBuf; diff --git a/src/command/utils.rs b/src/command/utils.rs index 3e0fb705..220f60c3 100644 --- a/src/command/utils.rs +++ b/src/command/utils.rs @@ -1,6 +1,11 @@ //! Utility functions for commands. use std::path::{Path, PathBuf}; +use emoji; +use error::Error; +use progressbar::Step; +use std::fs; +use PBAR; /// If an explicit path is given, then use it, otherwise assume the current /// directory is the crate path. From 0a616624aa0f5e7d816aab19d483d66c3d3725ef Mon Sep 17 00:00:00 2001 From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Tue, 17 Jul 2018 11:03:42 +0800 Subject: [PATCH 3/6] cmd(init/build): cargo clippy --- src/command/build.rs | 6 +++--- src/command/mod.rs | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/command/build.rs b/src/command/build.rs index 689dab40..e7a16a29 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -83,7 +83,7 @@ type BuildStep = fn(&mut Build, &Step, &Logger) -> Result<(), Error>; impl Build { /// Execute this `Build` command. - pub fn run(&mut self, log: &Logger, mode: BuildMode) -> Result<(), Error> { + pub fn run(&mut self, log: &Logger, mode: &BuildMode) -> Result<(), Error> { let process_steps = Build::get_process_steps(mode); let mut step_counter = Step::new(process_steps.len()); @@ -112,7 +112,7 @@ impl Build { Ok(()) } - fn get_process_steps(mode: BuildMode) -> Vec<(&'static str, BuildStep)> { + fn get_process_steps(mode: &BuildMode) -> Vec<(&'static str, BuildStep)> { macro_rules! steps { ($($name:ident),+) => { { @@ -123,7 +123,7 @@ impl Build { }; ($($name:ident,)*) => (steps![$($name),*]) } - match mode { + match &mode { BuildMode::Normal => steps![ step_check_crate_config, step_add_wasm_target, diff --git a/src/command/mod.rs b/src/command/mod.rs index a9e555f3..360c7718 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -7,8 +7,8 @@ mod pack; mod publish; pub mod utils; -use self::build::{Build, BuildMode}; -use self::init::Init; +use self::build::{Build, BuildMode, BuildOptions}; +use self::init::{Init, InitOptions}; use self::login::login; use self::pack::pack; use self::publish::publish; @@ -23,11 +23,11 @@ use PBAR; pub enum Command { #[structopt(name = "init")] /// 🐣 initialize a package.json based on your compiled wasm! - Init(init::InitOptions), + Init(InitOptions), - /// build + /// 🏗️ build your npm package! #[structopt(name = "build")] - Build(self::build::BuildOptions), + Build(BuildOptions), #[structopt(name = "pack")] /// 🍱 create a tar of your npm package but don't publish! @@ -94,7 +94,7 @@ pub fn run_wasm_pack(command: Command, log: &Logger) -> result::Result<(), Error "normal" => BuildMode::Normal, _ => BuildMode::Normal, }; - Build::from(build_opts).run(&log, build_mode) + Build::from(build_opts).run(&log, &build_mode) } Command::Pack { path } => { info!(&log, "Running pack command..."); From d0ac2fa3cd403842bb451ce7f9bf416532df7197 Mon Sep 17 00:00:00 2001 From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Tue, 17 Jul 2018 17:19:50 +0800 Subject: [PATCH 4/6] cmd(init/build): update docs --- README.md | 5 ++-- docs/build.md | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++ docs/init.md | 31 +++------------------- 3 files changed, 80 insertions(+), 29 deletions(-) create mode 100644 docs/build.md diff --git a/README.md b/README.md index 7beef6e0..e26e08ea 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,8 @@ visiting that repo! ## 🎙️ Commands -- [`init`](docs/init.md): Generate an npm wasm pkg from a rustwasm crate +- [`init`](docs/init.md): Initialize an npm wasm pkg from a rustwasm crate +- [`build`](docs/build.md): Generate an npm wasm pkg from a rustwasm crate - [`pack`](docs/pack.md): Create a tarball of your rustwasm pkg - [`publish`](docs/publish.md): Publish your rustwasm pkg to a registry @@ -90,7 +91,7 @@ check out our [contribution policy]. ``` 5. Install this tool: `cargo install wasm-pack` -6. Run `wasm-pack init`, optionally, pass a path to a dir or a scope (see above for details) +6. Run `wasm-pack build`, optionally, pass a path to a dir or a scope (see above for details) 7. This tool generates files in a `pkg` dir 8. To publish to npm, run `wasm-pack publish`. You may need to login to the registry you want to publish to. You can login using `wasm-pack login`. diff --git a/docs/build.md b/docs/build.md new file mode 100644 index 00000000..5fe9b620 --- /dev/null +++ b/docs/build.md @@ -0,0 +1,73 @@ +# wasm-pack build + +The `wasm-pack build` command creates the files neccessary for JavaScript +interoperability and for publishing a package to npm. This involves compiling +your code to wasm and generating a pkg folder. This pkg folder will contain the +wasm binary, a JS wrapper file, your `README`, and a `package.json` file. + +## Path + +The `wasm-pack build` command can be given an optional path argument, e.g.: + +``` +wasm-pack build examples/js-hello-world +``` + +This path should point to a directory that contains a `Cargo.toml` file. If no +path is given, the `build` command will run in the current directory. + +## Debug + +The init command accepts an optional `--debug` argument. This will build the +output package using cargo's +[default non-release profile][cargo-profile-sections-documentation]. Building +this way is faster but applies few optimizations to the output, and enables +debug assertions and other runtime correctness checks. + +The exact meaning of this flag may evolve as the platform matures. + +[cargo-profile-sections-documentation]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-profile-sections + +## Target + +The `build` command accepts a `--target` argument. This will customize the output files +to align with a particular type of JS module. This allows wasm-pack to generate either +ES6 modules or CommonJS modules for use in browser and in NodeJS. Defaults to `browser`. +The options are: + +``` +wasm-pack build --target nodejs +``` + +| Option | Description | +|-----------|-----------------------------------------------------------------------------------------------------------------| +| `nodejs` | Outputs JS that uses CommonJS modules, for use with a `require` statement. | +| `browser` | Outputs JS that uses ES6 modules, primarily for use with `import` statements and/or bundlers such as `webpack`. | + +## Scope + +The init command also accepts an optional `--scope` argument. This will scope +your package name, which is useful if your package name might conflict with +something in the public registry. For example: + +``` +wasm-pack build examples/js-hello-world --scope test +``` + +This command would create a `package.json` file for a package called +`@test/js-hello-world`. For more information about scoping, you can refer to +the npm documentation [here][npm-scope-documentation]. + +[npm-scope-documentation]: https://docs.npmjs.com/misc/scope + +## Mode + +The `build` command accepts an optional `--mode` argument. +``` +wasm-pack build examples/js-hello-world --mode no-install +``` + +| Option | Description | +|---------------|------------------------------------------------------------------------------------------| +| `no-install` | `wasm-pack init` implicitly and create wasm binding without installing `wasm-bindgen`. | +| `normal` | do all the stuffs of `no-install` with installed `wasm-bindgen`. | diff --git a/docs/init.md b/docs/init.md index 91355c78..62cf418a 100644 --- a/docs/init.md +++ b/docs/init.md @@ -1,9 +1,9 @@ # wasm-pack init The `wasm-pack init` command creates the files neccessary for JavaScript -interoperability and for publishing a package to npm. This involves compiling -your code to wasm and generating a pkg folder. This pkg folder will contain the -wasm binary, a JS wrapper file, your `README`, and a `package.json` file. +interoperability and for publishing a package to npm. This involves +generating a pkg folder. This pkg folder will contain the +`README` and a `package.json` file. ## Path @@ -46,27 +46,4 @@ This command would create a `package.json` file for a package called `@test/js-hello-world`. For more information about scoping, you can refer to the npm documentation [here][npm-scope-documentation]. -## Debug - -The init command accepts an optional `--debug` argument. This will build the -output package using cargo's -[default non-release profile][cargo-profile-sections-documentation]. Building -this way is faster but applies few optimizations to the output, and enables -debug assertions and other runtime correctness checks. - -The exact meaning of this flag may evolve as the platform matures. - -[npm-scope-documentation]: https://docs.npmjs.com/misc/scope -[cargo-profile-sections-documentation]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-profile-sections - -## Skipping build - -The init command accepts an optional `--skip-build` argument. - -This will deactivate those steps: -- installing wasm target (via cargo) -- compiling the code to wasm -- installing wasm-bindgen (via rustup) -- running wasm-bindgen on the built wasm - -Basically it will remains only the steps that update the metadata of `package.json`. +[npm-scope-documentation]: https://docs.npmjs.com/misc/scope \ No newline at end of file From ddab496f51758cf9e13c7bab14d9a98270f37739 Mon Sep 17 00:00:00 2001 From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Wed, 25 Jul 2018 10:52:03 +0800 Subject: [PATCH 5/6] cmd(init/build): rebase --- src/command/build.rs | 67 +++++++----------- src/command/init.rs | 159 ++++--------------------------------------- src/command/utils.rs | 11 ++- 3 files changed, 48 insertions(+), 189 deletions(-) diff --git a/src/command/build.rs b/src/command/build.rs index e7a16a29..c9ebf59f 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -8,12 +8,13 @@ use manifest; use progressbar::Step; use readme; use slog::Logger; +use std::path::PathBuf; use std::time::Instant; use PBAR; /// Everything required to configure and run the `wasm-pack init` command. pub(crate) struct Build { - pub crate_path: String, + pub crate_path: PathBuf, pub scope: Option, pub disable_dts: bool, pub target: String, @@ -36,7 +37,8 @@ pub enum BuildMode { #[derive(Debug, StructOpt)] pub struct BuildOptions { /// The path to the Rust crate. - pub path: Option, + #[structopt(parse(from_os_str))] + pub path: Option, /// The npm scope to use in package.json, if any. #[structopt(long = "scope", short = "s")] @@ -99,15 +101,16 @@ impl Build { info!(&log, "Done in {}.", &duration); info!( &log, - "Your WASM pkg is ready to publish at {}/pkg.", &self.crate_path + "Your WASM pkg is ready to publish at {:#?}.", + &self.crate_path.join("pkg") ); PBAR.message(&format!("{} Done in {}", emoji::SPARKLE, &duration)); PBAR.message(&format!( - "{} Your WASM pkg is ready to publish at {}/pkg.", + "{} Your WASM pkg is ready to publish at {:#?}.", emoji::PACKAGE, - &self.crate_path + &self.crate_path.join("pkg") )); Ok(()) } @@ -163,15 +166,14 @@ impl Build { info!(&log, "Building wasm..."); build::cargo_build_wasm(&self.crate_path, self.debug, step)?; - #[cfg(not(target_os = "windows"))] info!( &log, - "wasm built at {}/target/wasm32-unknown-unknown/release.", &self.crate_path - ); - #[cfg(target_os = "windows")] - info!( - &log, - "wasm built at {}\\target\\wasm32-unknown-unknown\\release.", &self.crate_path + "wasm built at {:#?}.", + &self + .crate_path + .join("target") + .join("wasm32-unknown-unknown") + .join("release") ); Ok(()) } @@ -179,7 +181,7 @@ impl Build { fn step_create_dir(&mut self, step: &Step, log: &Logger) -> Result<(), Error> { info!(&log, "Creating a pkg directory..."); create_pkg_dir(&self.crate_path, step)?; - info!(&log, "Created a pkg directory at {}.", &self.crate_path); + info!(&log, "Created a pkg directory at {:#?}.", &self.crate_path); Ok(()) } @@ -192,15 +194,10 @@ impl Build { &self.target, step, )?; - #[cfg(not(target_os = "windows"))] - info!( - &log, - "Wrote a package.json at {}/pkg/package.json.", &self.crate_path - ); - #[cfg(target_os = "windows")] info!( &log, - "Wrote a package.json at {}\\pkg\\package.json.", &self.crate_path + "Wrote a package.json at {:#?}.", + &self.crate_path.join("pkg").join("package.json") ); Ok(()) } @@ -208,15 +205,10 @@ impl Build { fn step_copy_readme(&mut self, step: &Step, log: &Logger) -> Result<(), Error> { info!(&log, "Copying readme from crate..."); readme::copy_from_crate(&self.crate_path, step)?; - #[cfg(not(target_os = "windows"))] - info!( - &log, - "Copied readme from crate to {}/pkg.", &self.crate_path - ); - #[cfg(target_os = "windows")] info!( &log, - "Copied readme from crate to {}\\pkg.", &self.crate_path + "Copied readme from crate to {:#?}.", + &self.crate_path.join("pkg") ); Ok(()) } @@ -228,19 +220,11 @@ impl Build { info!(&log, "Getting the crate name from the manifest..."); self.crate_name = manifest::get_crate_name(&self.crate_path)?; - #[cfg(not(target_os = "windows"))] - info!( - &log, - "Got crate name {} from the manifest at {}/Cargo.toml.", - &self.crate_name, - &self.crate_path - ); - #[cfg(target_os = "windows")] info!( &log, - "Got crate name {} from the manifest at {}\\Cargo.toml.", + "Got crate name {:#?} from the manifest at {:#?}.", &self.crate_name, - &self.crate_path + &self.crate_path.join("Cargo.toml") ); Ok(()) } @@ -255,15 +239,10 @@ impl Build { self.debug, step, )?; - #[cfg(not(target_os = "windows"))] - info!( - &log, - "wasm bindings were built at {}/pkg.", &self.crate_path - ); - #[cfg(target_os = "windows")] info!( &log, - "wasm bindings were built at {}\\pkg.", &self.crate_path + "wasm bindings were built at {:#?}.", + &self.crate_path.join("pkg") ); Ok(()) } diff --git a/src/command/init.rs b/src/command/init.rs index 7f6213b1..29ad44ec 100644 --- a/src/command/init.rs +++ b/src/command/init.rs @@ -8,33 +8,10 @@ use manifest; use progressbar::Step; use readme; use slog::Logger; -use std::fs; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use std::time::Instant; use PBAR; -/// Construct our `pkg` directory in the crate. -pub fn create_pkg_dir(path: &Path, step: &Step) -> Result<(), Error> { - let msg = format!("{}Creating a pkg directory...", emoji::FOLDER); - PBAR.step(step, &msg); - let pkg_dir_path = path.join("pkg"); - fs::create_dir_all(pkg_dir_path)?; - Ok(()) -} - -/// The `InitMode` determines which mode of initialization we are running, and -/// what build and install steps we perform. -pub enum InitMode { - /// Perform all the build and install steps. - Normal, - /// Don't build the crate as a `.wasm` but do install tools and create - /// meta-data. - Nobuild, - /// Don't install tools like `wasm-bindgen`, just use the global - /// environment's existing versions to do builds. - Noinstall, -} - /// Everything required to configure and run the `wasm-pack init` command. pub struct Init { crate_path: PathBuf, @@ -47,7 +24,8 @@ pub struct Init { #[derive(Debug, StructOpt)] pub struct InitOptions { /// The path to the Rust crate. - pub path: Option, + #[structopt(parse(from_os_str))] + pub path: Option, /// The npm scope to use in package.json, if any. #[structopt(long = "scope", short = "s")] @@ -109,34 +87,18 @@ impl Init { Ok(()) } - fn step_check_crate_config(&mut self, step: &Step, log: &Logger) -> Result<(), Error> { - info!(&log, "Checking crate configuration..."); - manifest::check_crate_config(&self.crate_path, step)?; - info!(&log, "Crate is correctly configured."); - Ok(()) - } - - fn step_add_wasm_target(&mut self, step: &Step, log: &Logger) -> Result<(), Error> { - info!(&log, "Adding wasm-target..."); - build::rustup_add_wasm_target(step)?; - info!(&log, "Adding wasm-target was successful."); - Ok(()) - } - - fn step_build_wasm(&mut self, step: &Step, log: &Logger) -> Result<(), Error> { - info!(&log, "Building wasm..."); - build::cargo_build_wasm(&self.crate_path, self.debug, step)?; - - info!( - &log, - "wasm built at {:#?}.", - &self - .crate_path - .join("target") - .join("wasm32-unknown-unknown") - .join("release") - ); - Ok(()) + fn set_process_steps() -> Vec<(&'static str, InitStep)> { + macro_rules! steps { + ($($name:ident),+) => { + { + let mut steps: Vec<(&'static str, InitStep)> = Vec::new(); + $(steps.push((stringify!($name), Init::$name));)* + steps + } + }; + ($($name:ident,)*) => (steps![$($name),*]) + } + steps![step_create_dir, step_create_json, step_copy_readme,] } fn step_create_dir(&mut self, step: &Step, log: &Logger) -> Result<(), Error> { @@ -173,95 +135,4 @@ impl Init { ); Ok(()) } - - fn step_install_wasm_bindgen(&mut self, step: &Step, log: &Logger) -> Result<(), Error> { - info!(&log, "Installing wasm-bindgen-cli..."); - bindgen::cargo_install_wasm_bindgen(step)?; - info!(&log, "Installing wasm-bindgen-cli was successful."); - - info!(&log, "Getting the crate name from the manifest..."); - self.crate_name = manifest::get_crate_name(&self.crate_path)?; - info!( - &log, - "Got crate name {:#?} from the manifest at {:#?}.", - &self.crate_name, - &self.crate_path.join("Cargo.toml") - ); - Ok(()) - } - - fn step_run_wasm_bindgen(&mut self, step: &Step, log: &Logger) -> Result<(), Error> { - info!(&log, "Building the wasm bindings..."); - bindgen::wasm_bindgen_build( - &self.crate_path, - &self.crate_name, - self.disable_dts, - &self.target, - self.debug, - step, - )?; - info!( - &log, - "wasm bindings were built at {:#?}.", - &self.crate_path.join("pkg") - ); - Ok(()) - } -} - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn init_normal_build() { - let steps: Vec<&str> = Init::get_process_steps(InitMode::Normal) - .into_iter() - .map(|(n, _)| n) - .collect(); - assert_eq!( - steps, - [ - "step_check_crate_config", - "step_add_wasm_target", - "step_build_wasm", - "step_create_dir", - "step_create_json", - "step_copy_readme", - "step_install_wasm_bindgen", - "step_run_wasm_bindgen" - ] - ); - } - - #[test] - fn init_skip_build() { - let steps: Vec<&str> = Init::get_process_steps(InitMode::Nobuild) - .into_iter() - .map(|(n, _)| n) - .collect(); - assert_eq!( - steps, - ["step_create_dir", "step_create_json", "step_copy_readme"] - ); - } - - #[test] - fn init_skip_install() { - let steps: Vec<&str> = Init::get_process_steps(InitMode::Noinstall) - .into_iter() - .map(|(n, _)| n) - .collect(); - assert_eq!( - steps, - [ - "step_check_crate_config", - "step_build_wasm", - "step_create_dir", - "step_create_json", - "step_copy_readme", - "step_run_wasm_bindgen" - ] - ); - } } diff --git a/src/command/utils.rs b/src/command/utils.rs index 220f60c3..c66b089e 100644 --- a/src/command/utils.rs +++ b/src/command/utils.rs @@ -1,10 +1,10 @@ //! Utility functions for commands. -use std::path::{Path, PathBuf}; use emoji; use error::Error; use progressbar::Step; use std::fs; +use std::path::{Path, PathBuf}; use PBAR; /// If an explicit path is given, then use it, otherwise assume the current @@ -18,6 +18,15 @@ pub fn set_crate_path(path: Option) -> PathBuf { crate_path } +/// Construct our `pkg` directory in the crate. +pub fn create_pkg_dir(path: &Path, step: &Step) -> Result<(), Error> { + let msg = format!("{}Creating a pkg directory...", emoji::FOLDER); + PBAR.step(step, &msg); + let pkg_dir_path = path.join("pkg"); + fs::create_dir_all(pkg_dir_path)?; + Ok(()) +} + /// Locates the pkg directory from a specific path /// Returns None if unable to find the 'pkg' directory pub fn find_pkg_directory(path: &Path) -> Option { From 022b787a2f94443ef5c3b18d357249bed23d8984 Mon Sep 17 00:00:00 2001 From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Fri, 27 Jul 2018 10:53:32 +0800 Subject: [PATCH 6/6] cmd(init/build): deprecate init --- README.md | 2 +- docs/init.md | 2 +- src/command/init.rs | 138 ------------------------------------------ src/command/mod.rs | 12 +--- src/logger.rs | 1 - src/main.rs | 6 ++ tests/all/manifest.rs | 10 +-- 7 files changed, 14 insertions(+), 157 deletions(-) delete mode 100644 src/command/init.rs diff --git a/README.md b/README.md index e26e08ea..d638d2b1 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ visiting that repo! ## 🎙️ Commands -- [`init`](docs/init.md): Initialize an npm wasm pkg from a rustwasm crate +- [`init`](docs/init.md): [**Deprecated**] Initialize an npm wasm pkg from a rustwasm crate - [`build`](docs/build.md): Generate an npm wasm pkg from a rustwasm crate - [`pack`](docs/pack.md): Create a tarball of your rustwasm pkg - [`publish`](docs/publish.md): Publish your rustwasm pkg to a registry diff --git a/docs/init.md b/docs/init.md index 62cf418a..02d9924a 100644 --- a/docs/init.md +++ b/docs/init.md @@ -1,4 +1,4 @@ -# wasm-pack init +# wasm-pack init(Deprecated) The `wasm-pack init` command creates the files neccessary for JavaScript interoperability and for publishing a package to npm. This involves diff --git a/src/command/init.rs b/src/command/init.rs deleted file mode 100644 index 29ad44ec..00000000 --- a/src/command/init.rs +++ /dev/null @@ -1,138 +0,0 @@ -//! Initializing a crate for packing `.wasm`s. - -use command::utils::{create_pkg_dir, set_crate_path}; -use emoji; -use error::Error; -use indicatif::HumanDuration; -use manifest; -use progressbar::Step; -use readme; -use slog::Logger; -use std::path::PathBuf; -use std::time::Instant; -use PBAR; - -/// Everything required to configure and run the `wasm-pack init` command. -pub struct Init { - crate_path: PathBuf, - scope: Option, - disable_dts: bool, - target: String, -} - -/// `Init` options -#[derive(Debug, StructOpt)] -pub struct InitOptions { - /// The path to the Rust crate. - #[structopt(parse(from_os_str))] - pub path: Option, - - /// The npm scope to use in package.json, if any. - #[structopt(long = "scope", short = "s")] - pub scope: Option, - - #[structopt(long = "no-typescript")] - /// By default a *.d.ts file is generated for the generated JS file, but - /// this flag will disable generating this TypeScript file. - pub disable_dts: bool, - - #[structopt(long = "target", short = "t", default_value = "browser")] - /// Sets the target environment. [possible values: browser, nodejs] - pub target: String, -} - -impl From for Init { - fn from(init_opts: InitOptions) -> Self { - let crate_path = set_crate_path(init_opts.path); - Init { - crate_path, - scope: init_opts.scope, - disable_dts: init_opts.disable_dts, - target: init_opts.target, - } - } -} - -type InitStep = fn(&mut Init, &Step, &Logger) -> Result<(), Error>; - -impl Init { - /// Execute this `Init` command. - pub fn run(&mut self, log: &Logger) -> Result<(), Error> { - let process_steps = Init::set_process_steps(); - - let mut step_counter = Step::new(process_steps.len()); - - let started = Instant::now(); - - for (_, process_step) in process_steps { - process_step(self, &step_counter, log)?; - step_counter.inc(); - } - - let duration = HumanDuration(started.elapsed()); - info!(&log, "Done in {}.", &duration); - info!( - &log, - "Your WASM pkg is ready to publish at {:#?}.", - &self.crate_path.join("pkg") - ); - - PBAR.message(&format!("{} Done in {}", emoji::SPARKLE, &duration)); - - PBAR.message(&format!( - "{} Your WASM pkg is ready to publish at {:#?}.", - emoji::PACKAGE, - &self.crate_path.join("pkg") - )); - Ok(()) - } - - fn set_process_steps() -> Vec<(&'static str, InitStep)> { - macro_rules! steps { - ($($name:ident),+) => { - { - let mut steps: Vec<(&'static str, InitStep)> = Vec::new(); - $(steps.push((stringify!($name), Init::$name));)* - steps - } - }; - ($($name:ident,)*) => (steps![$($name),*]) - } - steps![step_create_dir, step_create_json, step_copy_readme,] - } - - fn step_create_dir(&mut self, step: &Step, log: &Logger) -> Result<(), Error> { - info!(&log, "Creating a pkg directory..."); - create_pkg_dir(&self.crate_path, step)?; - info!(&log, "Created a pkg directory at {:#?}.", &self.crate_path); - Ok(()) - } - - fn step_create_json(&mut self, step: &Step, log: &Logger) -> Result<(), Error> { - info!(&log, "Writing a package.json..."); - manifest::write_package_json( - &self.crate_path, - &self.scope, - self.disable_dts, - &self.target, - step, - )?; - info!( - &log, - "Wrote a package.json at {:#?}.", - &self.crate_path.join("pkg").join("package.json") - ); - Ok(()) - } - - fn step_copy_readme(&mut self, step: &Step, log: &Logger) -> Result<(), Error> { - info!(&log, "Copying readme from crate..."); - readme::copy_from_crate(&self.crate_path, step)?; - info!( - &log, - "Copied readme from crate to {:#?}.", - &self.crate_path.join("pkg") - ); - Ok(()) - } -} diff --git a/src/command/mod.rs b/src/command/mod.rs index 360c7718..9b20672c 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -1,14 +1,12 @@ //! CLI command structures, parsing, and execution. mod build; -pub mod init; mod login; mod pack; mod publish; pub mod utils; use self::build::{Build, BuildMode, BuildOptions}; -use self::init::{Init, InitOptions}; use self::login::login; use self::pack::pack; use self::publish::publish; @@ -21,12 +19,8 @@ use PBAR; /// The various kinds of commands that `wasm-pack` can execute. #[derive(Debug, StructOpt)] pub enum Command { - #[structopt(name = "init")] - /// 🐣 initialize a package.json based on your compiled wasm! - Init(InitOptions), - /// 🏗️ build your npm package! - #[structopt(name = "build")] + #[structopt(name = "build", alias = "init")] Build(BuildOptions), #[structopt(name = "pack")] @@ -83,10 +77,6 @@ pub fn run_wasm_pack(command: Command, log: &Logger) -> result::Result<(), Error // Run the correct command based off input and store the result of it so that we can clear // the progress bar then return it let status = match command { - Command::Init(init_opts) => { - info!(&log, "Running init command..."); - Init::from(init_opts).run(&log) - } Command::Build(build_opts) => { info!(&log, "Running build command..."); let build_mode = match build_opts.mode.as_str() { diff --git a/src/logger.rs b/src/logger.rs index 1ceae491..d100ccf7 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -33,7 +33,6 @@ pub fn new(cmd: &Command, verbosity: u8) -> Result { /// Figure out where to stick the log based off the command arguments given fn log_file_path(cmd: &Command) -> PathBuf { let path = match cmd { - Command::Init(init_opts) => &init_opts.path, Command::Build(build_opts) => &build_opts.path, Command::Pack { path } => path, Command::Publish { path } => path, diff --git a/src/main.rs b/src/main.rs index 68e6e4b2..0617f116 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ extern crate structopt; extern crate wasm_pack; use failure::Fail; +use std::env; use structopt::StructOpt; use wasm_pack::{command::run_wasm_pack, error::Error, logger, Cli}; @@ -20,6 +21,11 @@ fn main() { } fn run() -> Result<(), Error> { + // Deprecate `init` + if let Some("init") = env::args().nth(1).as_ref().map(|arg| arg.as_str()) { + println!("wasm-pack init is deprecated, consider using wasm-pack build"); + } + let args = Cli::from_args(); let log = logger::new(&args.cmd, args.verbosity)?; run_wasm_pack(args.cmd, &log)?; diff --git a/tests/all/manifest.rs b/tests/all/manifest.rs index 45f046e0..14cbbf5d 100644 --- a/tests/all/manifest.rs +++ b/tests/all/manifest.rs @@ -55,7 +55,7 @@ fn it_recognizes_a_map_during_depcheck() { fn it_creates_a_package_json_default_path() { let fixture = utils::fixture("."); let step = wasm_pack::progressbar::Step::new(1); - wasm_pack::command::init::create_pkg_dir(&fixture.path, &step).unwrap(); + wasm_pack::command::utils::create_pkg_dir(&fixture.path, &step).unwrap(); assert!(manifest::write_package_json(&fixture.path, &None, false, "", &step).is_ok()); let package_json_path = &fixture.path.join("pkg").join("package.json"); assert!(fs::metadata(package_json_path).is_ok()); @@ -83,7 +83,7 @@ fn it_creates_a_package_json_default_path() { fn it_creates_a_package_json_provided_path() { let fixture = utils::fixture("tests/fixtures/js-hello-world"); let step = wasm_pack::progressbar::Step::new(1); - wasm_pack::command::init::create_pkg_dir(&fixture.path, &step).unwrap(); + wasm_pack::command::utils::create_pkg_dir(&fixture.path, &step).unwrap(); assert!(manifest::write_package_json(&fixture.path, &None, false, "", &step).is_ok()); let package_json_path = &fixture.path.join("pkg").join("package.json"); assert!(fs::metadata(package_json_path).is_ok()); @@ -104,7 +104,7 @@ fn it_creates_a_package_json_provided_path() { fn it_creates_a_package_json_provided_path_with_scope() { let fixture = utils::fixture("tests/fixtures/scopes"); let step = wasm_pack::progressbar::Step::new(1); - wasm_pack::command::init::create_pkg_dir(&fixture.path, &step).unwrap(); + wasm_pack::command::utils::create_pkg_dir(&fixture.path, &step).unwrap(); assert!( manifest::write_package_json(&fixture.path, &Some("test".to_string()), false, "", &step) .is_ok() @@ -128,7 +128,7 @@ fn it_creates_a_package_json_provided_path_with_scope() { fn it_creates_a_pkg_json_with_correct_files_on_node() { let fixture = utils::fixture("."); let step = wasm_pack::progressbar::Step::new(1); - wasm_pack::command::init::create_pkg_dir(&fixture.path, &step).unwrap(); + wasm_pack::command::utils::create_pkg_dir(&fixture.path, &step).unwrap(); assert!(manifest::write_package_json(&fixture.path, &None, false, "nodejs", &step).is_ok()); let package_json_path = &fixture.path.join("pkg").join("package.json"); assert!(fs::metadata(package_json_path).is_ok()); @@ -157,7 +157,7 @@ fn it_creates_a_pkg_json_with_correct_files_on_node() { fn it_creates_a_package_json_with_correct_keys_when_types_are_skipped() { let fixture = utils::fixture("."); let step = wasm_pack::progressbar::Step::new(1); - wasm_pack::command::init::create_pkg_dir(&fixture.path, &step).unwrap(); + wasm_pack::command::utils::create_pkg_dir(&fixture.path, &step).unwrap(); assert!(manifest::write_package_json(&fixture.path, &None, true, "", &step).is_ok()); let package_json_path = &fixture.path.join("pkg").join("package.json"); assert!(fs::metadata(package_json_path).is_ok());