Skip to content

fix: keep an existing package.json when --no-pack is passed - #1602

Closed
cpruijsen wants to merge 1 commit into
wasm-bindgen:masterfrom
cpruijsen:fix/issue-1521
Closed

cpruijsen wants to merge 1 commit into
wasm-bindgen:masterfrom
cpruijsen:fix/issue-1521

Conversation

@cpruijsen

Copy link
Copy Markdown

Fixes #1521.

create_pkg_dir in src/command/utils.rs opens by deleting package.json from the out dir:

let _ = fs::remove_file(out_dir.join("package.json")); // Clean up package.json from previous runs

That is right when wasm-pack is about to write a new one, and wrong under --no-pack, where it
never will. The user's own file is removed and nothing replaces it. --no-pack reads as "do not
generate one", not "delete the one I put there", which is what the issue reports.

The flag is threaded through and the removal is skipped when it is set. create_pkg_dir already
takes no_gitignore for the same reason, so no_pack sits beside it rather than introducing a new
shape:

pub fn create_pkg_dir(out_dir: &Path, no_gitignore: bool, no_pack: bool) -> Result<()>

Worth flagging since the function is pub: that is a signature change for anything outside this
repo calling it. The two callers inside it are updated, and the fourteen call sites in
tests/all/manifest.rs take false.

Only the removal is gated. The directory is still created and .gitignore still written under
--no-pack, both unchanged.

Test

it_should_not_delete_existing_pkg_json_if_passed_no_pack writes { "name": "pre-existing" } into
pkg/package.json, builds with --no-pack, and asserts the file still reads back byte for byte.

It pins the change rather than merely passing: with the guard reverted it fails on the read, and its
sibling it_should_not_make_a_pkg_json_if_passed_no_pack still passes, so the two cover the two
halves of what --no-pack means.

cargo check --all-targets and cargo fmt --check are clean.

create_pkg_dir unconditionally deleted out_dir/package.json so a stale
wasm-pack manifest could not break the dependency merge in
write_package_json. With --no-pack that merge never runs, so the
deletion only destroyed a user-provided file. Skip the cleanup when
no_pack is set.

Fixes wasm-bindgen#1521
@cpruijsen

Copy link
Copy Markdown
Author

Closing this one so it does not sit in the queue.

@cpruijsen cpruijsen closed this Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deleting existing package.json when --no-pack is passed

1 participant