Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lockfiles): Use Cargo.lock to identify wasm-bindgen versions #324

Closed
wants to merge 3 commits into from

Conversation

fitzgen
Copy link
Member

@fitzgen fitzgen commented Sep 20, 2018

fixes #270, #344

This lets us leverage cargo for semver finding and then ensure that we get the exact same version of the CLI that cargo selected. It also lets us support fuzzy dependencies like "0.2" instead of exact dependencies like "0.2.21" again.

Additionally, this lets us remove the _ vs - normalization, since cargo also handles that for us.

This is a updated version of #302. In addition to a rebase, this also removes the old Cargo.toml checking code, migrates callers to this new version, and ensures that we never check the wasm-bindgen version until after a Cargo.lock exists.


Make sure these boxes are checked! 📦✅

  • You have the latest version of rustfmt installed and have your
    cloned directory set to nightly
$ rustup override set nightly
$ rustup component add rustfmt-preview --toolchain nightly
  • You ran rustfmt on the code base before submitting
  • You reference which issue is being closed in the PR text

✨✨ 😄 Thanks so much for contributing to wasm-pack! 😄 ✨✨

@fitzgen
Copy link
Member Author

fitzgen commented Sep 20, 2018

Crap, I forgot to add these test cases:

More cases we can handle now and should have tests for:

  • running wasm-pack build in each crate within an umbrella workspace:
umbrella/
- Cargo.toml                        # just have `[workspace] members = [..]`
- foo/
- Cargo.toml
- src/
- lib.rs
- bar/
- Cargo.toml
- src/
- lib.rs
  • a dependency uses wasm-bindgen, but the root crate does not:
// child/src/lib.rs
extern crate wasm_bindgen;
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub fn hello() -> u32 { 42 }

// parent/src/lib.rs
extern crate child;
pub use child::*;

@fitzgen
Copy link
Member Author

fitzgen commented Sep 20, 2018

Added the missing test cases.

step_add_wasm_target,
step_build_tests,
step_check_crate_config,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about it some more, we might want to still check the crate config as the first thing we do, but have checking crate config not check wasm-bindgen versions. Then when we go to install wasm-bindgen, we look at the lockfile at tjhat time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes i think that's a good call. crate config should def be one of the first things we do because it's a quick fix for folks who it fails for.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done.

src/lockfile.rs Outdated
}

/// Get the version of `wasm-bindgen` dependency used in the `Cargo.lock`.
pub fn get_wasm_bindgen_version(path: &Path) -> Result<String, Error> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might recommend returning Option here to leave Error for things like I/O errors and such, and then callers can determine if they care about the presence or not

src/lockfile.rs Outdated
fn read_cargo_lock(crate_path: &Path) -> Result<Lockfile, Error> {
let lock_path = get_lockfile_path(crate_path)?;
let mut lockfile = String::new();
File::open(lock_path)?.read_to_string(&mut lockfile)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend fs::read_to_string(...) nowadays

Ideally this would also use failure's with_context method to add the filename to the error message too

src/lockfile.rs Show resolved Hide resolved
data-pup and others added 2 commits September 24, 2018 11:40
This lets us leverage `cargo` for semver finding and then ensure that we get the
exact same version of the CLI that cargo selected. It also lets us support fuzzy
dependencies like "0.2" instead of exact dependencies like "0.2.21" again.
This way when future wasm-bindgen version are published the tests will
continue working!
This can be somewhat expensive, so make sure we don't have to chew
through too much!
@ashleygwilliams
Copy link
Member

closing in favor of #365. hopefully for the last time <3<3

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.

Handle versions of wasm-bindgen in lockfiles
4 participants