Skip to content

Commit 031d591

Browse files
authored
Merge pull request #1291 from hamza1311/no-package
--no-pack flag
2 parents 0326141 + b6a30b0 commit 031d591

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

src/command/build.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub struct Build {
3131
pub weak_refs: bool,
3232
pub reference_types: bool,
3333
pub target: Target,
34+
pub no_pack: bool,
3435
pub profile: BuildProfile,
3536
pub mode: InstallMode,
3637
pub out_dir: PathBuf,
@@ -171,6 +172,10 @@ pub struct BuildOptions {
171172
/// Sets the output file names. Defaults to package name.
172173
pub out_name: Option<String>,
173174

175+
#[structopt(long = "no-pack", alias = "no-package")]
176+
/// Option to not generate a package.json
177+
pub no_pack: bool,
178+
174179
#[structopt(allow_hyphen_values = true)]
175180
/// List of extra options to pass to `cargo build`
176181
pub extra_options: Vec<String>,
@@ -188,6 +193,7 @@ impl Default for BuildOptions {
188193
target: Target::default(),
189194
debug: false,
190195
dev: false,
196+
no_pack: false,
191197
release: false,
192198
profiling: false,
193199
out_dir: String::new(),
@@ -232,6 +238,7 @@ impl Build {
232238
weak_refs: build_opts.weak_refs,
233239
reference_types: build_opts.reference_types,
234240
target: build_opts.target,
241+
no_pack: build_opts.no_pack,
235242
profile,
236243
mode: build_opts.mode,
237244
out_dir,
@@ -249,7 +256,7 @@ impl Build {
249256

250257
/// Execute this `Build` command.
251258
pub fn run(&mut self) -> Result<()> {
252-
let process_steps = Build::get_process_steps(self.mode);
259+
let process_steps = Build::get_process_steps(self.mode, self.no_pack);
253260

254261
let started = Instant::now();
255262

@@ -274,7 +281,7 @@ impl Build {
274281
Ok(())
275282
}
276283

277-
fn get_process_steps(mode: InstallMode) -> Vec<(&'static str, BuildStep)> {
284+
fn get_process_steps(mode: InstallMode, no_pack: bool) -> Vec<(&'static str, BuildStep)> {
278285
macro_rules! steps {
279286
($($name:ident),+) => {
280287
{
@@ -296,16 +303,23 @@ impl Build {
296303
]);
297304
}
298305
}
306+
299307
steps.extend(steps![
300308
step_build_wasm,
301309
step_create_dir,
302-
step_copy_readme,
303-
step_copy_license,
304310
step_install_wasm_bindgen,
305311
step_run_wasm_bindgen,
306312
step_run_wasm_opt,
307-
step_create_json,
308313
]);
314+
315+
if !no_pack {
316+
steps.extend(steps![
317+
step_create_json,
318+
step_copy_readme,
319+
step_copy_license,
320+
]);
321+
}
322+
309323
steps
310324
}
311325

tests/all/build.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ fn it_should_build_js_hello_world_example() {
2121
fixture.wasm_pack().arg("build").assert().success();
2222
}
2323

24+
#[test]
25+
fn it_should_not_make_a_pkg_json_if_passed_no_pack() {
26+
let fixture = utils::fixture::js_hello_world();
27+
fixture
28+
.wasm_pack()
29+
.arg("build")
30+
.arg("--no-pack")
31+
.assert()
32+
.success();
33+
34+
let pkg_path = fixture.path.join("pkg");
35+
assert_eq!(pkg_path.join("package.json").exists(), false);
36+
assert_eq!(pkg_path.join("README.md").exists(), false);
37+
assert_eq!(pkg_path.join("licence").exists(), false);
38+
}
39+
2440
#[test]
2541
fn it_should_build_crates_in_a_workspace() {
2642
let fixture = utils::fixture::Fixture::new();

0 commit comments

Comments
 (0)