Merge branch 'master' of github.com:rustwasm/wasm-pack

master
Jesper Håkansson 3 years ago
commit e12f6f7022
  1. 44
      .appveyor.yml
  2. 15
      .github/workflows/approve.yml
  3. 51
      .github/workflows/book.yml
  4. 196
      .github/workflows/release.yml
  5. 63
      .github/workflows/test.yml
  6. 99
      .travis.yml
  7. 136
      CHANGELOG.md
  8. 1070
      Cargo.lock
  9. 19
      Cargo.toml
  10. 10
      README.md
  11. 14
      docs/_theme/header.hbs
  12. 6
      docs/index.html
  13. 1
      docs/src/SUMMARY.md
  14. 8
      docs/src/commands/build.md
  15. 12
      docs/src/commands/test.md
  16. 4
      docs/src/introduction.md
  17. 38
      docs/src/prerequisites/considerations.md
  18. 5
      docs/src/tutorials/npm-browser-packages/template-deep-dive/src-lib-rs.md
  19. 4
      docs/src/tutorials/npm-browser-packages/template-deep-dive/src-utils-rs.md
  20. 5
      docs/src/tutorials/npm-browser-packages/template-deep-dive/wee_alloc.md
  21. 14
      npm/README.md
  22. 11
      npm/binary.js
  23. 377
      npm/package-lock.json
  24. 4
      npm/package.json
  25. 18
      src/bindgen.rs
  26. 19
      src/build/mod.rs
  27. 4
      src/build/wasm_target.rs
  28. 24
      src/command/build.rs
  29. 51
      src/command/test.rs
  30. 1
      src/command/utils.rs
  31. 2
      src/emoji.rs
  32. 12
      src/install/mod.rs
  33. 2
      src/installer.rs
  34. 45
      src/manifest/mod.rs
  35. 4
      src/manifest/npm/commonjs.rs
  36. 4
      src/manifest/npm/esmodules.rs
  37. 4
      src/manifest/npm/nomodules.rs
  38. 2
      src/target.rs
  39. 7
      src/test/webdriver.rs
  40. 2
      src/test/webdriver/chromedriver.rs
  41. 2
      src/test/webdriver/geckodriver.rs
  42. 12
      src/wasm_opt.rs
  43. 5
      tests/all/build.rs
  44. 4
      tests/all/download.rs
  45. 12
      tests/all/lockfile.rs
  46. 1
      tests/all/log_level.rs
  47. 2
      tests/all/main.rs
  48. 50
      tests/all/manifest.rs
  49. 58
      tests/all/test.rs
  50. 14
      tests/all/utils/fixture.rs
  51. 8
      tests/all/utils/manifest.rs

@ -1,44 +0,0 @@
environment:
global:
RUSTFLAGS: -C target-feature=+crt-static
install:
- ps: Install-Product node 10
- appveyor-retry appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
- rustup-init.exe -y --default-host x86_64-pc-windows-msvc --default-toolchain stable
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
- set RUST_BACKTRACE=1
- rustup target add wasm32-unknown-unknown --toolchain stable
- rustc -V
- cargo -V
build: false
test_script:
- cargo test --release --tests --locked
- cargo test --release --doc
before_deploy:
- ps: |
$NAME = "wasm-pack-${env:APPVEYOR_REPO_TAG_NAME}-x86_64-pc-windows-msvc"
New-Item -Path $NAME -ItemType directory
Copy-Item target/release/wasm-pack.exe "${NAME}/"
Copy-Item target/release/wasm-pack.exe wasm-pack-init.exe
Copy-Item LICENSE-MIT "${NAME}/"
Copy-Item LICENSE-APACHE "${NAME}/"
Copy-Item README.md "${NAME}/"
7z a -ttar "${NAME}.tar" "${NAME}"
7z a "${NAME}.tar.gz" "${NAME}.tar"
Push-AppveyorArtifact "${NAME}.tar.gz"
Push-AppveyorArtifact wasm-pack-init.exe
deploy:
artifact: /.*\.tar.gz/, /.*\.exe/
description: 'Appveyor Automated Release'
provider: GitHub
draft: false
prerelease: false
auth_token:
secure: iHsRUqwGf/Zh7OuYpHOWQL8buaOL+c8/6kXLRly8V2j0LCUo7CcDs0NxQ0vl2bhZ
on:
appveyor_repo_tag: true

@ -0,0 +1,15 @@
name: Automatic Approve
on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
jobs:
automatic-approve:
name: Automatic Approve
runs-on: ubuntu-latest
steps:
- name: Automatic Approve
uses: mheap/automatic-approve-action@v1.1.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
workflows: "test.yml"

@ -0,0 +1,51 @@
name: Build and deploy documentation book
on:
push:
pull_request:
jobs:
book:
name: Build and deploy book
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: Cache dependencies
uses: actions/cache@v2
env:
cache-name: cache-mdbook
with:
path: |
~/.cargo/.crates.toml
~/.cargo/.crates2.json
~/.cargo/bin
~/.cargo/registry/index
~/.cargo/registry/cache
key: ${{ runner.os }}-build-${{ env.cache-name }}-0.3 }}
- name: Install mdbook
run: |
(test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update)
(test -x $HOME/.cargo/bin/mdbook || cargo install --vers "^0.3" mdbook)
cargo install-update -a
- name: Build book
run: |
mdbook --version
(cd docs && mv _theme theme && mdbook build)
rustc ./docs/_installer/build-installer.rs
./build-installer
- name: Deploy book
uses: JamesIves/github-pages-deploy-action@4.1.4
if: ${{ github.ref == 'refs/heads/master' }}
with:
branch: gh-pages
folder: docs
token: ${{ secrets.GITHUB_TOKEN }}
single-commit: true

@ -0,0 +1,196 @@
on:
push:
tags:
- 'v*' # Run when tag matches v*, i.e. v1.0, v20.15.10
name: Release
env:
RELEASE_BIN: wasm-pack
RELEASE_DIR: artifacts
GITHUB_REF: '${{ github.ref }}'
WINDOWS_TARGET: x86_64-pc-windows-msvc
MACOS_TARGET: x86_64-apple-darwin
LINUX_AMD64_TARGET: x86_64-unknown-linux-musl
LINUX_ARM64_TARGET: aarch64-unknown-linux-musl
# Space separated paths to include in the archive.
RELEASE_ADDS: README.md LICENSE-APACHE LICENSE-MIT
jobs:
build:
name: Build artifacts
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
rust: stable
- target: aarch64-unknown-linux-musl
os: ubuntu-latest
rust: stable
- target: x86_64-apple-darwin
os: macos-latest
rust: stable
- target: x86_64-pc-windows-msvc
os: windows-latest
rust: stable
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true
target: wasm32-unknown-unknown
- name: Query version number
id: get_version
shell: bash
run: |
echo "using version tag ${GITHUB_REF:10}"
echo ::set-output name=version::"${GITHUB_REF:10}"
- name: Install C compilation tooling (Linux)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update -y
sudo apt-get install clang gcc-aarch64-linux-gnu -y
echo "TARGET_CC=clang" >> $GITHUB_ENV
echo "CFLAGS_aarch64_unknown_linux_musl=--sysroot=/usr/aarch64-linux-gnu" >> $GITHUB_ENV
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=/usr/aarch64-linux-gnu/bin/ld" >> $GITHUB_ENV
- name: Install p7zip (MacOS)
if: matrix.os == 'macos-latest'
run: brew install p7zip
- name: Add rustup target
run: rustup target add ${{ matrix.target }}
- name: Build
run: cargo build --release --target ${{ matrix.target }}
- name: Set RUSTFLAGS (Windows)
if: matrix.os == 'windows-latest'
run: echo "RUSTFLAGS=-Ctarget-feature=+crt-static" >> $GITHUB_ENV
- name: Create artifact directory
run: |
mkdir ${{ env.RELEASE_DIR }}
mkdir -p ${{ env.RELEASE_DIR }}/${{ env.RELEASE_BIN }}-${{ steps.get_version.outputs.VERSION }}-${{ matrix.target }}
- name: Move binaries (Linux/MacOS)
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest'
run: |
mv ./target/${{ matrix.target }}/release/${{ env.RELEASE_BIN }} ${{ env.RELEASE_DIR }}/${{ env.RELEASE_BIN }}-${{ steps.get_version.outputs.VERSION }}-${{ matrix.target }}/${{ env.RELEASE_BIN }}
mv ${{ env.RELEASE_ADDS }} ./${{ env.RELEASE_DIR }}/${{ env.RELEASE_BIN }}-${{ steps.get_version.outputs.VERSION }}-${{ matrix.target }}
- name: Move binaries (Windows)
if: matrix.os == 'windows-latest'
shell: bash
run: |
cp ./target/${{ matrix.target }}/release/${{ env.RELEASE_BIN }}.exe ./${{ env.RELEASE_DIR }}/${{ env.RELEASE_BIN }}-${{ steps.get_version.outputs.VERSION }}-${{ matrix.target }}/${{ env.RELEASE_BIN }}.exe
cp ./target/${{ matrix.target }}/release/${{ env.RELEASE_BIN }}.exe wasm-pack-init.exe
mv ${{ env.RELEASE_ADDS }} ./${{ env.RELEASE_DIR }}/${{ env.RELEASE_BIN }}-${{ steps.get_version.outputs.VERSION }}-${{ matrix.target }}
mv wasm-pack-init.exe ${{ env.RELEASE_DIR }}
- name: Create tarball
run: 7z a -ttar -so -an ./${{ env.RELEASE_DIR }}/${{ env.RELEASE_BIN }}-${{ steps.get_version.outputs.VERSION }}-${{ matrix.target }} | 7z a -si ./${{ env.RELEASE_DIR }}/${{ env.RELEASE_BIN }}-${{ steps.get_version.outputs.VERSION }}-${{ matrix.target }}.tar.gz
- name: Upload Zip
uses: actions/upload-artifact@v1
with:
name: ${{ matrix.target }}
path: ./${{ env.RELEASE_DIR }}
release:
name: GitHub Release
needs: build
runs-on: ubuntu-latest
steps:
- name: Query version number
id: get_version
shell: bash
run: |
echo "using version tag ${GITHUB_REF:10}"
echo ::set-output name=version::"${GITHUB_REF:10}"
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_version.outputs.VERSION }}
release_name: ${{ steps.get_version.outputs.VERSION }}
- name: Download Linux amd64 tarball
uses: actions/download-artifact@v2
with:
name: ${{ env.LINUX_AMD64_TARGET }}
- name: Download Linux arm64 tarball
uses: actions/download-artifact@v2
with:
name: ${{ env.LINUX_ARM64_TARGET }}
- name: Download Windows tarball
uses: actions/download-artifact@v2
with:
name: ${{ env.WINDOWS_TARGET }}
- name: Download MacOS tarball
uses: actions/download-artifact@v2
with:
name: ${{ env.MACOS_TARGET }}
- name: Release Linux amd64 tarball
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./wasm-pack-${{ steps.get_version.outputs.VERSION }}-${{ env.LINUX_AMD64_TARGET }}.tar.gz
asset_content_type: application/gzip
asset_name: wasm-pack-${{ steps.get_version.outputs.VERSION }}-${{ env.LINUX_AMD64_TARGET }}.tar.gz
- name: Release Linux arm64 tarball
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./wasm-pack-${{ steps.get_version.outputs.VERSION }}-${{ env.LINUX_ARM64_TARGET }}.tar.gz
asset_content_type: application/gzip
asset_name: wasm-pack-${{ steps.get_version.outputs.VERSION }}-${{ env.LINUX_ARM64_TARGET }}.tar.gz
- name: Release Windows tarball
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./wasm-pack-${{ steps.get_version.outputs.VERSION }}-${{ env.WINDOWS_TARGET }}.tar.gz
asset_content_type: application/gzip
asset_name: wasm-pack-${{ steps.get_version.outputs.VERSION }}-${{ env.WINDOWS_TARGET }}.tar.gz
- name: Release Windows init exe
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./wasm-pack-init.exe
asset_content_type: application/vnd.microsoft.portable-executable
asset_name: wasm-pack-init.exe
- name: Release MacOS tarball
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./wasm-pack-${{ steps.get_version.outputs.VERSION }}-${{ env.MACOS_TARGET }}.tar.gz
asset_content_type: application/gzip
asset_name: wasm-pack-${{ steps.get_version.outputs.VERSION }}-${{ env.MACOS_TARGET }}.tar.gz

@ -0,0 +1,63 @@
name: Tests
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
test:
name: Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
build: [linux-stable, macos-stable, windows-stable]
include:
- build: linux-stable
os: ubuntu-latest
rust: stable
- build: macos-stable
os: macos-latest
rust: stable
- build: windows-stable
os: windows-latest
rust: stable
steps:
- uses: actions/checkout@v2
- uses: nanasess/setup-chromedriver@master
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true
target: wasm32-unknown-unknown
- uses: actions/setup-node@v2
- name: Cache dependencies
uses: actions/cache@v2
env:
cache-name: cache-dependencies
with:
path: |
~/.cargo/.crates.toml
~/.cargo/.crates2.json
~/.cargo/bin
~/.cargo/registry/index
~/.cargo/registry/cache
target
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('Cargo.lock') }}
- name: Run Tests
run: cargo test --features "strict" --all --locked
env:
RUST_BACKTRACE: 1
- name: Clippy
run: cargo clippy
- name: Cargo fmt
run: cargo fmt --all -- --check

@ -1,99 +0,0 @@
language: rust
sudo: false
INSTALL_NODE_VIA_NVM: &INSTALL_NODE_VIA_NVM
|
rustup target add wasm32-unknown-unknown
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
source ~/.nvm/nvm.sh
nvm install lts/carbon
# Cache `cargo install`ed tools, but don't cache the project's `target`
# directory (which ends up over-caching and filling all disk space!)
cache:
directories:
- /home/travis/.cargo
GH_TOKEN: &GH_TOKEN
secure: fx0rR5Ii1KcsydexE6QpkDbqItNdj3Lt6L5yFZaKKB/ejw9M555NkXA+0GZqV0sLZ54qfR8zTaXAf6eBFKgcG9etaCl7vTXqsvDrlssth82oki1zufP39uuoOy4WgFq8OfACOtUq7opDAgYmpaGzlFiny+c5j7asGwDtAU1Fc3JeJsvAnxHKg9+0spXFD6kBQd5CWpqDXv2rLFK0b8IM2fHAzd0PiJZQWqz//2Cj/r9rTiewtIzqigctAfOgFwYoQvfdM+0mKb4pefG+zXEGfxxQr4r5hqZ6UMO7hto3Jnm9LRjNR8dNaDQCqQ0bkdLTAMTC3nV/gZPM679yQU3KHueVjg9pleNzuKnuBgYmH9+BrlG1dW68kqA+6Xh+wIJYrLuagWhJDlCtiU6PM5QAbFg3mabPIBG3M2IHTrOVATme+iW5vpROARhgjbQEF235DyvZaT+Tml3+PY+PfcRax2DVUhvGQViv4tzppbT0PjjBlEbGct49cFLGdqZIJBiVrYW24I2QkENTnUgZsFIBuJlVCBHZwZlLo9ldVvu4XTMKw65z42zoTzobjtbC1QPEZPiaJXSxC7W569fqL/ORXwGToFk6rQjXwEqDP2okGiusR75LXrZD6qFibNpqeypRFtqOzntsOfTUGrlaN1yTt/6dz0V0j9uI7a9/CHVcblI=
DEPLOY_TO_GITHUB: &DEPLOY_TO_GITHUB
before_deploy:
- git config --local user.name "Ashley Williams"
- git config --local user.email "ashley666ashley@gmail.com"
- name="wasm-pack-$TRAVIS_TAG-$TARGET"
- mkdir $name
- cp target/$TARGET/release/wasm-pack $name/
- cp README.md LICENSE-MIT LICENSE-APACHE $name/
- tar czvf $name.tar.gz $name
deploy:
provider: releases
api_key: *GH_TOKEN
file: wasm-pack-$TRAVIS_TAG-$TARGET.tar.gz
skip_cleanup: true
on:
branch: master
tags: true
matrix:
include:
- name: Tests
env: RUST_BACKTRACE=1
rust: stable
addons:
firefox: latest
chrome: stable
install:
- *INSTALL_NODE_VIA_NVM
script:
- cargo test --all --locked
- rustup component add rustfmt-preview
- cargo fmt --version
- cargo fmt --all -- --check
- rustup component add clippy-preview
- cargo clippy --version
- cargo clippy
- name: Book
rust: stable
before_script:
- (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update)
- (test -x $HOME/.cargo/bin/mdbook || cargo install --vers "^0.2" mdbook)
- cargo install-update -a
script:
- mdbook --version
- (cd docs && mv _theme theme && mdbook build)
- rustc ./docs/_installer/build-installer.rs
- ./build-installer
deploy:
provider: pages
skip-cleanup: true
github-token: *GH_TOKEN
local-dir: docs
keep-history: false
on:
branch: master
- name: Linux Binary
env: TARGET=x86_64-unknown-linux-musl
rust: stable
before_script: rustup target add $TARGET
script: cargo build --release --target $TARGET --locked --features vendored-openssl
addons:
apt:
packages:
- musl-tools
<<: *DEPLOY_TO_GITHUB
- name: macOS Binary
env: MACOSX_DEPLOYMENT_TARGET=10.7 TARGET=x86_64-apple-darwin
os: osx
rust: stable
script: cargo build --release --target $TARGET --locked
install: true
<<: *DEPLOY_TO_GITHUB
notifications:
email:
on_success: never

@ -1,5 +1,141 @@
# Changelog
## 🤍 Unreleased
## 🌦 0.10.1
- ### 🤕 Fixes
- **Add exe to binary name if windows - [drager], [issue/1038] [pull/1055]**
[pull/1055]: https://github.com/rustwasm/wasm-pack/pull/1055
[issue/1038]: https://github.com/rustwasm/wasm-pack/issues/1038
## 🌦 0.10.0
- ### ✨ Features
- **Added keywords - [lucashorward], [issue/707] [pull/838]**
`package.json` files usually contain a keywords array so that npm can make searching easier.
This PR extracts keywords from `Cargo.toml` and puts them into `package.json`.
[lucashorward]: https://github.com/lucashorward
[pull/838]: https://github.com/rustwasm/wasm-pack/pull/838
[issue/707]: https://github.com/rustwasm/wasm-pack/issues/707
- ### 🤕 Fixes
- **Update binary-install to get fix for axios security vulnerability - [simlay], [Rizary], [issue/958] [pull/973] [pull/1012]**
Updates `binary-install` npm package to version `^0.1.0` in order to get security fix for a security vulnerability in axios.
[simlay]: https://github.com/simlay
[rizary]: https://github.com/Rizary
[pull/973]: https://github.com/rustwasm/wasm-pack/pull/973
[pull/1012]: https://github.com/rustwasm/wasm-pack/pull/1012
[issue/958]: https://github.com/rustwasm/wasm-pack/issues/958
- **Fix cargo-generate installation - [bradyjoslin], [issue/975] [issue/907] [pull/983]**
`wasm-pack new hello-wasm` didn't work due to a bad link when trying to install `cargo-generate`.
This PR points the installation to the correct place and makes `wasm-pack new` working again!
[bradyjoslin]: https://github.com/bradyjoslin
[pull/983]: https://github.com/rustwasm/wasm-pack/pull/983
[issue/975]: https://github.com/rustwasm/wasm-pack/issues/975
[issue/907]: https://github.com/rustwasm/wasm-pack/issues/907
- **Pass through extra options when building tests - [azriel91], [issue/698] [pull/851]**
`wasm-pack test` accepts extra options to pass through to `cargo` when running tests.
Under the hood, this runs `cargo build` before `cargo test`, and the additional options were only passed through to the `test` command. This meant that crates that enabled native features by default could not be built using `wasm-pack`, as it would attempt to build tests for the `wasm32-unknown-unknown` target with the native features enabled.
This PR passes through the extra options to `cargo` when building the tests as well.
[azriel91]: https://github.com/azriel91
[pull/851]: https://github.com/rustwasm/wasm-pack/pull/851
[issue/698]: https://github.com/rustwasm/wasm-pack/issues/698
- **Corrected files included in package.json for bundler / no target - [lucashorward], [issue/837] [pull/839]**
`wasm-pack build` and `wasm-pack build --target bundler` generates a \_bg.js file, but it was not added to the `package.json`.
The file that is added, \*.js will however reference the \_bg.js, so when the package was distributed (both through pack or publish) it is not usable.
This PR includes that \_bg.js file in `package.json`.
[pull/839]: https://github.com/rustwasm/wasm-pack/pull/839
[issue/837]: https://github.com/rustwasm/wasm-pack/issues/837
- **Find the main package if multiple packages have the same name - [ghost], [pull/830]**
If there were 2 packages with the same name, `wasm-pack` would sometimes use the wrong one and errored.
[ghost]: https://github.com/ghost
[pull/830]: https://github.com/rustwasm/wasm-pack/pull/830
[issue/829]: https://github.com/rustwasm/wasm-pack/issues/829
- ### 📖 Documentation
- **Remove duplicated "is" in the wee_alloc tutorial- [pione30], [issue/1003] [pull/1004]**
[pione30]: https://github.com/pione30
[pull/1004]: https://github.com/rustwasm/wasm-pack/pull/1004
[issue/1003]: https://github.com/rustwasm/wasm-pack/issues/1003
- **Fix TOC links - [Swaagie], [pull/1007]**
[swaagie]: https://github.com/Swaagie
[pull/1007]: https://github.com/rustwasm/wasm-pack/pull/1007
- **Remove outdated TOC heading- [gthb], [pull/1011]**
[gthb]: https://github.com/gthb
[pull/1011]: https://github.com/rustwasm/wasm-pack/pull/1011
- **Add link to template repo - [milahu], [pull/942]**
[milahu]: https://github.com/milahu
[pull/942]: https://github.com/rustwasm/wasm-pack/pull/942
- **Remove greenkeeper reference - [cdvv7788], [crotwell], [issue/1001] [pull/844] [pull/1002]**
[cdvv7788]: https://github.com/cdvv7788
[crotwell]: https://github.com/crotwell
[pull/844]: https://github.com/rustwasm/wasm-pack/pull/844
[pull/1002]: https://github.com/rustwasm/wasm-pack/pull/1002
[issue/1001]: https://github.com/rustwasm/wasm-pack/issues/1001
- ### 🛠 Maintenance
- **Fix CI. Remove appveyor and travis and use Github actions - [ashleygwilliams], [drager], [issue/594] [issue/979] [pull/947]**
[pull/947]: https://github.com/rustwasm/wasm-pack/pull/947
[issue/594]: https://github.com/rustwasm/wasm-pack/issues/594
[issue/979]: https://github.com/rustwasm/wasm-pack/issues/979
- **Cargo update - [ashleygwilliams], [pull/800]**
[ashleygwilliams]: https://github.com/ashleygwilliams
[pull/800]: https://github.com/rustwasm/wasm-pack/pull/800
- **Remove dirs dependency - [brightly-salty], [issue/943] [pull/944]**
[brightly-salty]: https://github.com/brightly-salty
[pull/944]: https://github.com/rustwasm/wasm-pack/pull/944
[issue/943]: https://github.com/rustwasm/wasm-pack/issues/943
- **Fix logs for uniformity - [petosorus], [issue/716] [pull/723]**
[petosorus]: https://github.com/petosorus
[pull/723]: https://github.com/rustwasm/wasm-pack/pull/723
[issue/716]: https://github.com/rustwasm/wasm-pack/issues/716
- **Fixing build error - [Pauan], [pull/841]**
[pull/841]: https://github.com/rustwasm/wasm-pack/pull/841
## ☁ 0.9.1
- ### 🤕 Fixes

1070
Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -1,9 +1,9 @@
[package]
name = "wasm-pack"
description = "📦✨ your favorite rust -> wasm workflow tool!"
version = "0.9.1"
authors = ["Ashley Williams <ashley666ashley@gmail.com>"]
repository = "https://github.com/ashleygwilliams/wasm-pack.git"
version = "0.10.1"
authors = ["Ashley Williams <ashley666ashley@gmail.com>", "Jesper Håkansson <jesper@jesperh.se>"]
repository = "https://github.com/rustwasm/wasm-pack.git"
license = "MIT/Apache-2.0"
readme = "README.md"
categories = ["wasm"]
@ -30,7 +30,7 @@ serde_ignored = "0.0.4"
serde_json = "1.0.26"
strsim = "0.8.0"
siphasher = "0.2.3"
structopt = "0.2"
structopt = "0.3"
toml = "0.4"
which = "2.0.0"
binary-install = "0.0.2"
@ -41,9 +41,16 @@ chrono = "0.4.6"
assert_cmd = "0.11"
lazy_static = "1.1.0"
predicates = "1.0.0"
serial_test = "0.2"
serial_test_derive = "0.2"
serial_test = "0.3"
tempfile = "3"
[features]
# OpenSSL is vendored by default, can use system OpenSSL through feature flag.
default = ['openssl/vendored']
# Treat compiler warnings as a build error.
# This only runs in CI by default
strict = ['openssl/vendored']
sys-openssl = ['openssl']
# Keeping feature for users already using this feature flag
vendored-openssl = ['openssl/vendored']

@ -7,9 +7,8 @@
</p>
<p>
<a href="https://travis-ci.com/rustwasm/wasm-pack"><img alt="Build Status" src="https://travis-ci.com/rustwasm/wasm-pack.svg?branch=master"/></a>
<a href="https://ci.appveyor.com/project/ashleygwilliams/wasm-pack-071k0"><img alt="Build status" src="https://ci.appveyor.com/api/projects/status/iv1qtnqtv168ef8h?svg=true"/></a>
<a href="https://crates.io/crates/wasm-pack"><img alt="crates.io" src="https://meritbadge.herokuapp.com/wasm-pack"/></a>
<a href="https://github.com/rustwasm/wasm-pack/actions/workflows/test.yml"><img alt="Build Status" src="https://github.com/rustwasm/wasm-pack/actions/workflows/test.yml/badge.svg?branch=master"/></a>
<a href="https://crates.io/crates/wasm-pack"><img alt="crates.io" src="https://img.shields.io/crates/v/wasm-pack"/></a>
</p>
<h3>
@ -20,7 +19,8 @@
<a href="https://discordapp.com/channels/442252698964721669/443151097398296587">Chat</a>
</h3>
<sub>Built with 🦀🕸 by <a href="https://rustwasm.github.io/">The Rust and WebAssembly Working Group</a></sub>
<sub>Built with 🦀🕸 by <a href="https://rustwasm.github.io/">The Rust and WebAssembly Working Group</a></sub>
</div>
## About
@ -89,4 +89,4 @@ This project was started by [ashleygwilliams] and is co-maintained by [ashleygwi
[ashleygwilliams]: https://github.com/ashleygwilliams
[drager]: https://github.com/drager
[rustwasm Working Group]: https://github.com/rustwasm/team
[rustwasm working group]: https://github.com/rustwasm/team

@ -35,10 +35,12 @@
}
</style>
<header class='warning'>
This is the <strong>unpublished</strong> documentation of
<code>wasm-pack</code>, the published documentation is available
<a href="https://rustwasm.github.io/docs/wasm-pack/">
on the main Rust and WebAssembly documentation site
</a>. Features documented here may not be available in released versions of
<code>wasm-pack</code>.
<p>
This is the <strong>unpublished</strong> documentation of
<code>wasm-pack</code>, the published documentation is available
<a href="https://rustwasm.github.io/docs/wasm-pack/">
on the main Rust and WebAssembly documentation site
</a>. Features documented here may not be available in released versions of
<code>wasm-pack</code>.
</p>
</header>

@ -42,9 +42,9 @@
<h2>📦✨ your favorite rust -> wasm workflow tool!</h2>
</div>
<div class="five columns" id="installer">
<a class="button button-primary" href="/wasm-pack/installer">✨ Install wasm-pack 0.9.1 ✨</a>
<p>7 Feb 2020 |
<a href="https://github.com/rustwasm/wasm-pack/releases/tag/v0.9.1">
<a class="button button-primary" href="/wasm-pack/installer">✨ Install wasm-pack 0.10.1 ✨</a>
<p>5 Sep 2021 |
<a href="https://github.com/rustwasm/wasm-pack/releases/tag/v0.10.1">
Release Notes
</a>
</p>

@ -4,6 +4,7 @@
- [Quickstart](./quickstart.md)
- [Prerequisites](./prerequisites/index.md)
- [npm (optional)](./prerequisites/npm.md)
- [considerations](./prerequisites/considerations.md)
- [Non-`rustup` setups](./prerequisites/non-rustup-setups.md)
- [Commands](./commands/index.md)
- [`new`](./commands/new.md)

@ -127,10 +127,10 @@ wasm-pack build examples/js-hello-world --mode no-install
## Extra options
The `build` command can pass extra options straight to `cargo build` even if they are not
supported in wasm-pack. To use them you should add standalone `--` argument at the very
end of your command, and all the arguments you want to pass to cargo should go after.
For example, to build the previous example using cargo's offline feature:
The `build` command can pass extra options straight to `cargo build` even if
they are not supported in wasm-pack. To use them simply add the extra arguments
at the very end of your command, just as you would for `cargo build`. For
example, to build the previous example using cargo's offline feature:
```
wasm-pack build examples/js-hello-world --mode no-install -- --offline

@ -44,8 +44,8 @@ wasm-pack test --node --firefox --chrome --safari --headless
The `test` command can pass extra options straight to `cargo test` even if they are not
supported in wasm-pack.
To use them you should add standalone `--` argument at the very
end of your command, and all the arguments you want to pass to cargo should go after.
To use them simply add the extra arguments at the very end of your command, just
as you would for `cargo test`.
`cargo test -h` for a list of all options that you can pass through.
@ -72,16 +72,16 @@ $ tree crates/foo
```
# Run all tests in tests/diff_patch.rs in Firefox
wasm-pack test crates/foo --firefox --headless -- --test diff_patch
wasm-pack test crates/foo --firefox --headless --test diff_patch
# Run all tests in tests/diff_patch.rs that contain the word "replace"
wasm-pack test crates/foo --firefox --headless -- --test diff_patch replace
wasm-pack test crates/foo --firefox --headless --test diff_patch replace
# Run all tests inside of a `tests` module inside of src/lib/diff.rs
wasm-pack test crates/foo --firefox --headless -- --lib diff::tests
wasm-pack test crates/foo --firefox --headless --lib diff::tests
# Same as the above, but only if they contain the word replace
wasm-pack test crates/foo --firefox --headless -- --lib diff::tests::replace
wasm-pack test crates/foo --firefox --headless --lib diff::tests::replace
```
Note that you can also filter tests by location in which they're supposed to

@ -6,12 +6,10 @@ This tool seeks to be a one-stop shop for building and working with rust-
generated WebAssembly that you would like to interop with JavaScript, in the
browser or with Node.js. `wasm-pack` helps you build rust-generated
WebAssembly packages that you could publish to the npm registry, or otherwise use
alongside any javascript packages in workflows that you already use, such as [webpack]
or [greenkeeper].
alongside any javascript packages in workflows that you already use, such as [webpack].
[bundler-support]: https://github.com/rustwasm/team/blob/master/goals/bundler-integration.md#details
[webpack]: https://webpack.js.org/
[greenkeeper]: https://greenkeeper.io/
This project is a part of the [rust-wasm] group. You can find more info by
visiting that repo!

@ -0,0 +1,38 @@
# nodejs
Currently, `wasm-pack` generated npm modules require us to you have [fetch] polyfill in your node project.
If there is a module from `wasm-pack build --target nodejs` you may encounter some errors regarding global `Headers`, `Request`, `Response` and `fetch` Web APIs.
## Common errors:
```js
ReqwestError(reqwest::Error { kind: Builder, source: "JsValue(ReferenceError: Headers is not defined
ReqwestError(reqwest::Error { kind: Builder, source: "JsValue(ReferenceError: Request is not defined
var ret = getObject(arg0) instanceof Response;
ReferenceError: Response is not defined
```
## Workarround
Import or declare fetch and objects: Headers, Request, Response
```ts
// CommonJS
const fetch = require('node-fetch');
// ES Module
import fetch from 'node-fetch';
// @ts-ignore
global.fetch = fetch;
// @ts-ignore
global.Headers = fetch.Headers;
// @ts-ignore
global.Request = fetch.Request;
// @ts-ignore
global.Response = fetch.Response;
```
[fetch]: https://github.com/node-fetch/node-fetch

@ -83,9 +83,8 @@ Either way, the contents of `utils.rs` define a single public function `set_pani
```rust
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global // allocator.
// allocator. #[cfg(feature = "wee_alloc")]
if #[cfg(feature = "wee_alloc")] { #[global_allocator]
// allocator.
if #[cfg(feature = "wee_alloc")] {
#[global_allocator] static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
```

@ -5,8 +5,8 @@ The purpose of `utils.rs` is to define the `utils` module, which contains a sing
If the `console_error_panic_hook` feature is not enabled, then `set_panic_hook` is defined to be an inlined empty function. So, there is no run-time performance or code-size penalty incurred by its use.
We will discuss:
1. [Defining `set_panic_hook`](#a1-defining-set_panic_hook)
2. [What is `console_error_panic_hook`?](#a2-what-is-console_error_panic_hook)
1. [Defining `set_panic_hook`](#1-defining-set_panic_hook)
2. [What is `console_error_panic_hook`?](#2-what-is-console_error_panic_hook)
---

@ -2,7 +2,6 @@
1. [What is `wee_alloc`?](#what-is-wee_alloc)
2. [Enabling `wee_alloc`](#enabling-wee_alloc)
3. [Rust nightly](#rust-nightly)
## What is `wee_alloc`?
@ -15,7 +14,7 @@ responsive.
[An analysis](http://fitzgeraldnick.com/2018/02/09/wee-alloc.html) suggests that over half of the bare minimum WebAssembly memory footprint is required by Rust's default memory allocator. Yet, WebAssembly code often does not require a sophisticated allocator, since it often just requests a couple of large initial allocations.
`wee_alloc` trades off size for speed. It has a tiny code-size
footprint, but it is is not competitive in terms of performance with the
footprint, but it is not competitive in terms of performance with the
default global allocator, for example.
For even more details, see the [`wee_alloc`
@ -41,7 +40,7 @@ allocator, but only if the `wee_alloc` feature is enabled at compile time. The
feature can be enabled by passing extra options while building:
```
$ wasm-pack build -- --features wee_alloc
$ wasm-pack build --features wee_alloc
```
or alternatively you could turn it on by default in `Cargo.toml`:

@ -7,9 +7,8 @@
</p>
<p>
<a href="https://travis-ci.com/rustwasm/wasm-pack"><img alt="Build Status" src="https://travis-ci.com/rustwasm/wasm-pack.svg?branch=master"/></a>
<a href="https://ci.appveyor.com/project/ashleygwilliams/wasm-pack-071k0"><img alt="Build status" src="https://ci.appveyor.com/api/projects/status/iv1qtnqtv168ef8h?svg=true"/></a>
<a href="https://crates.io/crates/wasm-pack"><img alt="crates.io" src="https://meritbadge.herokuapp.com/wasm-pack"/></a>
<a href="https://github.com/rustwasm/wasm-pack/actions/workflows/test.yml"><img alt="Build Status" src="https://github.com/rustwasm/wasm-pack/actions/workflows/test.yml/badge.svg?branch=master"/></a>
<a href="https://crates.io/crates/wasm-pack"><img alt="crates.io" src="https://img.shields.io/crates/v/wasm-pack"/></a>
</p>
<h3>
@ -20,7 +19,8 @@
<a href="https://discordapp.com/channels/442252698964721669/443151097398296587">Chat</a>
</h3>
<sub>Built with 🦀🕸 by <a href="https://rustwasm.github.io/">The Rust and WebAssembly Working Group</a></sub>
<sub>Built with 🦀🕸 by <a href="https://rustwasm.github.io/">The Rust and WebAssembly Working Group</a></sub>
</div>
## About
@ -29,12 +29,10 @@ This tool seeks to be a one-stop shop for building and working with rust-
generated WebAssembly that you would like to interop with JavaScript, in the
browser or with Node.js. `wasm-pack` helps you build rust-generated
WebAssembly packages that you could publish to the npm registry, or otherwise use
alongside any javascript packages in workflows that you already use, such as [webpack]
or [greenkeeper].
alongside any javascript packages in workflows that you already use, such as [webpack].
[bundler-support]: https://github.com/rustwasm/team/blob/master/goals/bundler-integration.md#details
[webpack]: https://webpack.js.org/
[greenkeeper]: https://greenkeeper.io/
This project is a part of the [rust-wasm] group. You can find more info by
visiting that repo!
@ -91,4 +89,4 @@ This project was started by [ashleygwilliams] and is co-maintained by [ashleygwi
[ashleygwilliams]: https://github.com/ashleygwilliams
[drager]: https://github.com/drager
[rustwasm Working Group]: https://github.com/rustwasm/team
[rustwasm working group]: https://github.com/rustwasm/team

@ -1,18 +1,19 @@
const { Binary } = require("binary-install");
const os = require("os");
const { join } = require("path");
const windows = "x86_64-pc-windows-msvc";
const getPlatform = () => {
const type = os.type();
const arch = os.arch();
if (type === "Windows_NT" && arch === "x64") {
return "x86_64-pc-windows-msvc";
return windows;
}
if (type === "Linux" && arch === "x64") {
return "x86_64-unknown-linux-musl";
}
if (type === "Darwin" && arch === "x64") {
if (type === "Darwin" && (arch === "x64" || arch === "arm64")) {
return "x86_64-apple-darwin";
}
@ -25,7 +26,7 @@ const getBinary = () => {
const author = "rustwasm";
const name = "wasm-pack";
const url = `https://github.com/${author}/${name}/releases/download/v${version}/${name}-v${version}-${platform}.tar.gz`;
return new Binary(url, { name });
return new Binary(platform === windows ? "wasm-pack.exe" : "wasm-pack", url);
};
const run = () => {
@ -46,5 +47,5 @@ const uninstall = () => {
module.exports = {
install,
run,
uninstall
uninstall,
};

377
npm/package-lock.json generated

@ -1,16 +1,229 @@
{
"name": "wasm-pack",
"version": "0.9.1",
"lockfileVersion": 1,
"version": "0.10.1",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "wasm-pack",
"version": "0.10.1",
"hasInstallScript": true,
"license": "MIT OR Apache-2.0",
"dependencies": {
"binary-install": "^0.1.0"
},
"bin": {
"wasm-pack": "run.js"
}
},
"node_modules/axios": {
"version": "0.21.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz",
"integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==",
"dependencies": {
"follow-redirects": "^1.10.0"
}
},
"node_modules/balanced-match": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
},
"node_modules/binary-install": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/binary-install/-/binary-install-0.1.1.tgz",
"integrity": "sha512-DqED0D/6LrS+BHDkKn34vhRqOGjy5gTMgvYZsGK2TpNbdPuz4h+MRlNgGv5QBRd7pWq/jylM4eKNCizgAq3kNQ==",
"dependencies": {
"axios": "^0.21.1",
"rimraf": "^3.0.2",
"tar": "^6.1.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/brace-expansion": {
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"dependencies": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
}
},
"node_modules/chownr": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz",
"integrity": "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==",
"engines": {
"node": ">=10"
}
},
"node_modules/concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
},
"node_modules/follow-redirects": {
"version": "1.13.2",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.2.tgz",
"integrity": "sha512-6mPTgLxYm3r6Bkkg0vNM0HTjfGrOEtsfbhagQvbxDEsEkpNhw582upBaoRZylzen6krEmxXJgt9Ju6HiI4O7BA==",
"engines": {
"node": ">=4.0"
}
},
"node_modules/fs-minipass": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz",
"integrity": "sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==",
"dependencies": {
"minipass": "^3.0.0"
},
"engines": {
"node": ">= 8"
}
},
"node_modules/fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
},
"node_modules/glob": {
"version": "7.1.6",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz",
"integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==",
"dependencies": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.0.4",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
},
"engines": {
"node": "*"
}
},
"node_modules/inflight": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
"dependencies": {
"once": "^1.3.0",
"wrappy": "1"
}
},
"node_modules/inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
},
"node_modules/minimatch": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
"dependencies": {
"brace-expansion": "^1.1.7"
},
"engines": {
"node": "*"
}
},
"node_modules/minipass": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/minipass/-/minipass-3.1.3.tgz",
"integrity": "sha512-Mgd2GdMVzY+x3IJ+oHnVM+KG3lA5c8tnabyJKmHSaG2kAGpudxuOf8ToDkhumF7UzME7DecbQE9uOZhNm7PuJg==",
"dependencies": {
"yallist": "^4.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/minizlib": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/minizlib/-/minizlib-2.1.2.tgz",
"integrity": "sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg==",
"dependencies": {
"minipass": "^3.0.0",
"yallist": "^4.0.0"
},
"engines": {
"node": ">= 8"
}
},
"node_modules/mkdirp": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz",
"integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==",
"bin": {
"mkdirp": "bin/cmd.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
"dependencies": {
"wrappy": "1"
}
},
"node_modules/path-is-absolute": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/rimraf": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
"integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==",
"dependencies": {
"glob": "^7.1.3"
},
"bin": {
"rimraf": "bin.js"
}
},
"node_modules/tar": {
"version": "6.1.11",
"resolved": "https://registry.npmjs.org/tar/-/tar-6.1.11.tgz",
"integrity": "sha512-an/KZQzQUkZCkuoAA64hM92X0Urb6VpRhAFllDzz44U2mcD5scmT3zBc4VgVpkugF580+DQn8eAFSyoQt0tznA==",
"dependencies": {
"chownr": "^2.0.0",
"fs-minipass": "^2.0.0",
"minipass": "^3.0.0",
"minizlib": "^2.1.1",
"mkdirp": "^1.0.3",
"yallist": "^4.0.0"
},
"engines": {
"node": ">= 10"
}
},
"node_modules/wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
},
"node_modules/yallist": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="
}
},
"dependencies": {
"axios": {
"version": "0.19.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.19.0.tgz",
"integrity": "sha512-1uvKqKQta3KBxIz14F2v06AEHZ/dIoeKfbTRkK1E5oqjDnuEerLmYTgJB5AiQZHJcljpg1TuRzdjDR06qNk0DQ==",
"version": "0.21.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz",
"integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==",
"requires": {
"follow-redirects": "1.5.10",
"is-buffer": "^2.0.2"
"follow-redirects": "^1.10.0"
}
},
"balanced-match": {
@ -19,16 +232,13 @@
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
},
"binary-install": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/binary-install/-/binary-install-0.0.1.tgz",
"integrity": "sha512-axr6lqB4ec/pkEOb/JMnZpfcroWv1zT48pVz1oQHG7XmGkS77vmdxmP1btuH79lWQdy9e2MVw/uW0D8siopkRg==",
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/binary-install/-/binary-install-0.1.1.tgz",
"integrity": "sha512-DqED0D/6LrS+BHDkKn34vhRqOGjy5gTMgvYZsGK2TpNbdPuz4h+MRlNgGv5QBRd7pWq/jylM4eKNCizgAq3kNQ==",
"requires": {
"axios": "^0.19.0",
"env-paths": "^2.2.0",
"mkdirp": "^0.5.1",
"rimraf": "^3.0.0",
"tar": "^5.0.5",
"universal-url": "^2.0.0"
"axios": "^0.21.1",
"rimraf": "^3.0.2",
"tar": "^6.1.0"
}
},
"brace-expansion": {
@ -41,40 +251,24 @@
}
},
"chownr": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.3.tgz",
"integrity": "sha512-i70fVHhmV3DtTl6nqvZOnIjbY0Pe4kAUjwHj8z0zAdgBtYrJyYwLKCCuRBQ5ppkyL0AkN7HKRnETdmdp1zqNXw=="
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz",
"integrity": "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ=="
},
"concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
},
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"requires": {
"ms": "2.0.0"
}
},
"env-paths": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/env-paths/-/env-paths-2.2.0.tgz",
"integrity": "sha512-6u0VYSCo/OW6IoD5WCLLy9JUGARbamfSavcNXry/eu8aHVFei6CD3Sw+VGX5alea1i9pgPHW0mbu6Xj0uBh7gA=="
},
"follow-redirects": {
"version": "1.5.10",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz",
"integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==",
"requires": {
"debug": "=3.1.0"
}
"version": "1.13.2",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.2.tgz",
"integrity": "sha512-6mPTgLxYm3r6Bkkg0vNM0HTjfGrOEtsfbhagQvbxDEsEkpNhw582upBaoRZylzen6krEmxXJgt9Ju6HiI4O7BA=="
},
"fs-minipass": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.0.0.tgz",
"integrity": "sha512-40Qz+LFXmd9tzYVnnBmZvFfvAADfUA14TXPK1s7IfElJTIZ97rA8w4Kin7Wt5JBrC3ShnnFJO/5vPjPEeJIq9A==",
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz",
"integrity": "sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==",
"requires": {
"minipass": "^3.0.0"
}
@ -97,11 +291,6 @@
"path-is-absolute": "^1.0.0"
}
},
"hasurl": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/hasurl/-/hasurl-1.0.0.tgz",
"integrity": "sha512-43ypUd3DbwyCT01UYpA99AEZxZ4aKtRxWGBHEIbjcOsUghd9YUON0C+JF6isNjaiwC/UF5neaUudy6JS9jZPZQ=="
},
"inflight": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
@ -116,16 +305,6 @@
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
},
"is-buffer": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.4.tgz",
"integrity": "sha512-Kq1rokWXOPXWuaMAqZiJW4XxsmD9zGx9q4aePabbn3qCRGedtH7Cm+zV8WETitMfu1wdh+Rvd6w5egwSngUX2A=="
},
"lodash.sortby": {
"version": "4.7.0",
"resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz",
"integrity": "sha1-7dFMgk4sycHgsKG0K7UhBRakJDg="
},
"minimatch": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
@ -134,40 +313,27 @@
"brace-expansion": "^1.1.7"
}
},
"minimist": {
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0="
},
"minipass": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/minipass/-/minipass-3.1.1.tgz",
"integrity": "sha512-UFqVihv6PQgwj8/yTGvl9kPz7xIAY+R5z6XYjRInD3Gk3qx6QGSD6zEcpeG4Dy/lQnv1J6zv8ejV90hyYIKf3w==",
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/minipass/-/minipass-3.1.3.tgz",
"integrity": "sha512-Mgd2GdMVzY+x3IJ+oHnVM+KG3lA5c8tnabyJKmHSaG2kAGpudxuOf8ToDkhumF7UzME7DecbQE9uOZhNm7PuJg==",
"requires": {
"yallist": "^4.0.0"
}
},
"minizlib": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/minizlib/-/minizlib-2.1.0.tgz",
"integrity": "sha512-EzTZN/fjSvifSX0SlqUERCN39o6T40AMarPbv0MrarSFtIITCBh7bi+dU8nxGFHuqs9jdIAeoYoKuQAAASsPPA==",
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/minizlib/-/minizlib-2.1.2.tgz",
"integrity": "sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg==",
"requires": {
"minipass": "^3.0.0",
"yallist": "^4.0.0"
}
},
"mkdirp": {
"version": "0.5.1",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
"requires": {
"minimist": "0.0.8"
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz",
"integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw=="
},
"once": {
"version": "1.4.0",
@ -182,64 +348,27 @@
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18="
},
"punycode": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz",
"integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A=="
},
"rimraf": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.0.tgz",
"integrity": "sha512-NDGVxTsjqfunkds7CqsOiEnxln4Bo7Nddl3XhS4pXg5OzwkLqJ971ZVAAnB+DDLnF76N+VnDEiBHaVV8I06SUg==",
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
"integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==",
"requires": {
"glob": "^7.1.3"
}
},
"tar": {
"version": "5.0.5",
"resolved": "https://registry.npmjs.org/tar/-/tar-5.0.5.tgz",
"integrity": "sha512-MNIgJddrV2TkuwChwcSNds/5E9VijOiw7kAc1y5hTNJoLDSuIyid2QtLYiCYNnICebpuvjhPQZsXwUL0O3l7OQ==",
"version": "6.1.11",
"resolved": "https://registry.npmjs.org/tar/-/tar-6.1.11.tgz",
"integrity": "sha512-an/KZQzQUkZCkuoAA64hM92X0Urb6VpRhAFllDzz44U2mcD5scmT3zBc4VgVpkugF580+DQn8eAFSyoQt0tznA==",
"requires": {
"chownr": "^1.1.3",
"chownr": "^2.0.0",
"fs-minipass": "^2.0.0",
"minipass": "^3.0.0",
"minizlib": "^2.1.0",
"mkdirp": "^0.5.0",
"minizlib": "^2.1.1",
"mkdirp": "^1.0.3",
"yallist": "^4.0.0"
}
},
"tr46": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/tr46/-/tr46-1.0.1.tgz",
"integrity": "sha1-qLE/1r/SSJUZZ0zN5VujaTtwbQk=",
"requires": {
"punycode": "^2.1.0"
}
},
"universal-url": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/universal-url/-/universal-url-2.0.0.tgz",
"integrity": "sha512-3DLtXdm/G1LQMCnPj+Aw7uDoleQttNHp2g5FnNQKR6cP6taNWS1b/Ehjjx4PVyvejKi3TJyu8iBraKM4q3JQPg==",
"requires": {
"hasurl": "^1.0.0",
"whatwg-url": "^7.0.0"
}
},
"webidl-conversions": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-4.0.2.tgz",
"integrity": "sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg=="
},
"whatwg-url": {
"version": "7.1.0",
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-7.1.0.tgz",
"integrity": "sha512-WUu7Rg1DroM7oQvGWfOiAK21n74Gg+T4elXEQYkOhtyLeWiJFoOGLXPKI/9gzIie9CtwVLm8wtw6YJdKyxSjeg==",
"requires": {
"lodash.sortby": "^4.7.0",
"tr46": "^1.0.1",
"webidl-conversions": "^4.0.2"
}
},
"wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",

@ -1,6 +1,6 @@
{
"name": "wasm-pack",
"version": "0.9.1",
"version": "0.10.1",
"description": "📦✨ your favorite rust -> wasm workflow tool!",
"main": "binary.js",
"scripts": {
@ -30,6 +30,6 @@
},
"homepage": "https://github.com/rustwasm/wasm-pack#readme",
"dependencies": {
"binary-install": "0.0.1"
"binary-install": "^0.1.0"
}
}

@ -6,7 +6,7 @@ use failure::{self, ResultExt};
use install::{self, Tool};
use manifest::CrateData;
use semver;
use std::path::{Path, PathBuf};
use std::path::Path;
use std::process::Command;
/// Run the `wasm-bindgen` CLI to generate bindings for the current crate's
@ -49,7 +49,7 @@ pub fn wasm_bindgen_build(
.arg(dts_arg);
let target_arg = build_target_arg(target, &bindgen_path)?;
if supports_dash_dash_target(bindgen_path.to_path_buf())? {
if supports_dash_dash_target(&bindgen_path)? {
cmd.arg("--target").arg(target_arg);
} else {
cmd.arg(target_arg);
@ -75,7 +75,7 @@ pub fn wasm_bindgen_build(
}
/// Check if the `wasm-bindgen` dependency is locally satisfied for the web target
fn supports_web_target(cli_path: &PathBuf) -> Result<bool, failure::Error> {
fn supports_web_target(cli_path: &Path) -> Result<bool, failure::Error> {
let cli_version = semver::Version::parse(&install::get_cli_version(
&install::Tool::WasmBindgen,
cli_path,
@ -85,30 +85,30 @@ fn supports_web_target(cli_path: &PathBuf) -> Result<bool, failure::Error> {
}
/// Check if the `wasm-bindgen` dependency is locally satisfied for the --target flag
fn supports_dash_dash_target(cli_path: PathBuf) -> Result<bool, failure::Error> {
fn supports_dash_dash_target(cli_path: &Path) -> Result<bool, failure::Error> {
let cli_version = semver::Version::parse(&install::get_cli_version(
&install::Tool::WasmBindgen,
&cli_path,
cli_path,
)?)?;
let expected_version = semver::Version::parse("0.2.40")?;
Ok(cli_version >= expected_version)
}
fn build_target_arg(target: Target, cli_path: &PathBuf) -> Result<String, failure::Error> {
if !supports_dash_dash_target(cli_path.to_path_buf())? {
fn build_target_arg(target: Target, cli_path: &Path) -> Result<String, failure::Error> {
if !supports_dash_dash_target(cli_path)? {
Ok(build_target_arg_legacy(target, cli_path)?)
} else {
Ok(target.to_string())
}
}
fn build_target_arg_legacy(target: Target, cli_path: &PathBuf) -> Result<String, failure::Error> {
fn build_target_arg_legacy(target: Target, cli_path: &Path) -> Result<String, failure::Error> {
log::info!("Your version of wasm-bindgen is out of date. You should consider updating your Cargo.toml to a version >= 0.2.40.");
let target_arg = match target {
Target::Nodejs => "--nodejs",
Target::NoModules => "--no-modules",
Target::Web => {
if supports_web_target(&cli_path)? {
if supports_web_target(cli_path)? {
"--web"
} else {
bail!("Your current version of wasm-bindgen does not support the 'web' target. Please update your project to wasm-bindgen version >= 0.2.39.")

@ -112,11 +112,24 @@ pub fn cargo_build_wasm(
Ok(())
}
/// Run `cargo build --tests` targetting `wasm32-unknown-unknown`.
/// Runs `cargo build --tests` targeting `wasm32-unknown-unknown`.
///
/// This generates the `Cargo.lock` file that we use in order to know which version of
/// wasm-bindgen-cli to use when running tests.
pub fn cargo_build_wasm_tests(path: &Path, debug: bool) -> Result<(), Error> {
///
/// Note that the command to build tests and the command to run tests must use the same parameters, i.e. features to be
/// disabled / enabled must be consistent for both `cargo build` and `cargo test`.
///
/// # Parameters
///
/// * `path`: Path to the crate directory to build tests.
/// * `debug`: Whether to build tests in `debug` mode.
/// * `extra_options`: Additional parameters to pass to `cargo` when building tests.
pub fn cargo_build_wasm_tests(
path: &Path,
debug: bool,
extra_options: &[String],
) -> Result<(), Error> {
let mut cmd = Command::new("cargo");
cmd.current_dir(path).arg("build").arg("--tests");
@ -131,6 +144,8 @@ pub fn cargo_build_wasm_tests(path: &Path, debug: bool) -> Result<(), Error> {
cmd.arg("--target").arg("wasm32-unknown-unknown");
cmd.args(extra_options);
child::run(cmd, "cargo build").context("Compilation of your program failed")?;
Ok(())
}

@ -5,7 +5,7 @@ use emoji;
use failure::{Error, ResultExt};
use log::info;
use std::fmt;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::process::Command;
use PBAR;
@ -81,7 +81,7 @@ fn get_rustc_sysroot() -> Result<PathBuf, Error> {
}
/// Checks if the wasm32-unknown-unknown is present in rustc's sysroot.
fn is_wasm32_target_in_sysroot(sysroot: &PathBuf) -> bool {
fn is_wasm32_target_in_sysroot(sysroot: &Path) -> bool {
let wasm32_target = "wasm32-unknown-unknown";
let rustlib_path = sysroot.join("lib/rustlib");

@ -18,6 +18,7 @@ use std::fmt;
use std::path::PathBuf;
use std::str::FromStr;
use std::time::Instant;
use structopt::clap::AppSettings;
use PBAR;
/// Everything required to configure and run the `wasm-pack build` command.
@ -101,6 +102,13 @@ pub enum BuildProfile {
/// Everything required to configure and run the `wasm-pack build` command.
#[derive(Debug, StructOpt)]
#[structopt(
// Allows unknown `--option`s to be parsed as positional arguments, so we can forward it to `cargo`.
setting = AppSettings::AllowLeadingHyphen,
// Allows `--` to be parsed as an argument, so we can forward it to `cargo`.
setting = AppSettings::TrailingVarArg,
)]
pub struct BuildOptions {
/// The path to the Rust crate. If not set, searches up the path from the current directory.
#[structopt(parse(from_os_str))]
@ -148,7 +156,7 @@ pub struct BuildOptions {
/// Sets the output file names. Defaults to package name.
pub out_name: Option<String>,
#[structopt(last = true)]
#[structopt(allow_hyphen_values = true)]
/// List of extra options to pass to `cargo build`
pub extra_options: Vec<String>,
}
@ -176,7 +184,15 @@ type BuildStep = fn(&mut Build) -> Result<(), Error>;
impl Build {
/// Construct a build command from the given options.
pub fn try_from_opts(build_opts: BuildOptions) -> Result<Self, Error> {
pub fn try_from_opts(mut build_opts: BuildOptions) -> Result<Self, Error> {
if let Some(path) = &build_opts.path {
if path.to_string_lossy().starts_with("--") {
let path = build_opts.path.take().unwrap();
build_opts
.extra_options
.insert(0, path.to_string_lossy().into_owned());
}
}
let crate_path = get_crate_path(build_opts.path)?;
let crate_data = manifest::CrateData::new(&crate_path, build_opts.out_name.clone())?;
let out_dir = crate_path.join(PathBuf::from(build_opts.out_dir));
@ -354,7 +370,7 @@ impl Build {
let bindgen = install::download_prebuilt_or_cargo_install(
Tool::WasmBindgen,
&self.cache,
&bindgen_version,
bindgen_version,
self.mode.install_permitted(),
)?;
self.bindgen = Some(bindgen);
@ -366,7 +382,7 @@ impl Build {
info!("Building the wasm bindings...");
bindgen::wasm_bindgen_build(
&self.crate_data,
&self.bindgen.as_ref().unwrap(),
self.bindgen.as_ref().unwrap(),
&self.out_dir,
&self.out_name,
self.disable_dts,

@ -11,16 +11,21 @@ use lockfile::Lockfile;
use log::info;
use manifest;
use std::path::PathBuf;
use std::str::FromStr;
use std::time::Instant;
use structopt::clap::AppSettings;
use test::{self, webdriver};
#[derive(Debug, Default, StructOpt)]
#[structopt(
// Allows unknown `--option`s to be parsed as positional arguments, so we can forward it to `cargo`.
setting = AppSettings::AllowLeadingHyphen,
// Allows `--` to be parsed as an argument, so we can forward it to `cargo`.
setting = AppSettings::TrailingVarArg,
)]
/// Everything required to configure the `wasm-pack test` command.
pub struct TestOptions {
#[structopt(parse(from_os_str))]
/// The path to the Rust crate. If not set, searches up the path from the current dirctory.
pub path: Option<PathBuf>,
#[structopt(long = "node")]
/// Run the tests in Node.js.
pub node: bool,
@ -74,9 +79,14 @@ pub struct TestOptions {
/// Build with the release profile.
pub release: bool,
#[structopt(last = true)]
/// List of extra options to pass to `cargo test`
pub extra_options: Vec<String>,
/// Path to the Rust crate, and extra options to pass to `cargo test`.
///
/// If the path is not provided, this command searches up the path from the current dirctory
///
/// This is a workaround to allow wasm pack to provide the same command line interface as `cargo`.
/// See <https://github.com/rustwasm/wasm-pack/pull/851> for more information.
#[structopt(allow_hyphen_values = true)]
pub path_and_extra_options: Vec<String>,
}
/// A configured `wasm-pack test` command.
@ -104,7 +114,6 @@ impl Test {
/// Construct a test command from the given options.
pub fn try_from_opts(test_opts: TestOptions) -> Result<Self, Error> {
let TestOptions {
path,
node,
mode,
headless,
@ -115,9 +124,23 @@ impl Test {
geckodriver,
safari,
safaridriver,
extra_options,
mut path_and_extra_options,
} = test_opts;
let first_arg_is_path = path_and_extra_options
.get(0)
.map(|first_arg| !first_arg.starts_with("-"))
.unwrap_or(false);
let (path, extra_options) = if first_arg_is_path {
let path = PathBuf::from_str(&path_and_extra_options.remove(0))?;
let extra_options = path_and_extra_options;
(Some(path), extra_options)
} else {
(None, path_and_extra_options)
};
let crate_path = get_crate_path(path)?;
let crate_data = manifest::CrateData::new(&crate_path, None)?;
let any_browser = chrome || firefox || safari;
@ -243,7 +266,15 @@ impl Test {
fn step_build_tests(&mut self) -> Result<(), Error> {
info!("Compiling tests to wasm...");
build::cargo_build_wasm_tests(&self.crate_path, !self.release)?;
// If the user has run `wasm-pack test -- --features "f1" -- test_name`, then we want to only pass through
// `--features "f1"` to `cargo build`
let extra_options =
if let Some(index) = self.extra_options.iter().position(|arg| arg == "--") {
&self.extra_options[..index]
} else {
&self.extra_options
};
build::cargo_build_wasm_tests(&self.crate_path, !self.release, extra_options)?;
info!("Finished compiling tests to wasm.");
Ok(())

@ -37,6 +37,7 @@ fn find_manifest_from_cwd() -> Result<PathBuf, failure::Error> {
/// Construct our `pkg` directory in the crate.
pub fn create_pkg_dir(out_dir: &Path) -> Result<(), failure::Error> {
let _ = fs::remove_dir_all(&out_dir); // Clean up any existing directory and ignore errors
fs::create_dir_all(&out_dir)?;
fs::write(out_dir.join(".gitignore"), "*")?;
Ok(())

@ -1,4 +1,4 @@
//! Emoji contants used by `wasm-pack`.
//! Emoji constants used by `wasm-pack`.
//!
//! For the woefully unfamiliar:
//!

@ -10,7 +10,7 @@ use log::debug;
use log::{info, warn};
use std::env;
use std::fs;
use std::path::PathBuf;
use std::path::Path;
use std::process::Command;
use target;
use which::which;
@ -71,7 +71,7 @@ pub fn download_prebuilt_or_cargo_install(
let msg = format!("{}Installing {}...", emoji::DOWN_ARROW, tool);
PBAR.info(&msg);
let dl = download_prebuilt(&tool, &cache, version, install_permitted);
let dl = download_prebuilt(&tool, cache, version, install_permitted);
match dl {
Ok(dl) => return Ok(dl),
Err(e) => {
@ -82,13 +82,13 @@ pub fn download_prebuilt_or_cargo_install(
}
}
cargo_install(tool, &cache, version, install_permitted)
cargo_install(tool, cache, version, install_permitted)
}
/// Check if the tool dependency is locally satisfied.
pub fn check_version(
tool: &Tool,
path: &PathBuf,
path: &Path,
expected_version: &str,
) -> Result<bool, failure::Error> {
let expected_version = if expected_version == "latest" {
@ -107,7 +107,7 @@ pub fn check_version(
}
/// Fetches the version of a CLI tool
pub fn get_cli_version(tool: &Tool, path: &PathBuf) -> Result<String, failure::Error> {
pub fn get_cli_version(tool: &Tool, path: &Path) -> Result<String, failure::Error> {
let mut cmd = Command::new(path);
cmd.arg("--version");
let stdout = child::run_capture_stdout(cmd, tool)?;
@ -172,7 +172,7 @@ fn prebuilt_url(tool: &Tool, version: &str) -> Result<String, failure::Error> {
Tool::WasmOpt => "x86-linux",
_ => bail!("Unrecognized target!"),
}
} else if target::MACOS && target::x86_64 {
} else if target::MACOS && (target::x86_64 || target::aarch64) {
"x86_64-apple-darwin"
} else if target::WINDOWS && target::x86_64 {
match tool {

@ -12,7 +12,7 @@
//! downloaded via curl/sh, and then the shell script downloads this executable
//! and runs it.
//!
//! This may get more complicated over time (self upates anyone?) but for now
//! This may get more complicated over time (self updates anyone?) but for now
//! it's pretty simple! We're largely just moving over our currently running
//! executable to a different path.

@ -8,8 +8,8 @@
mod npm;
use std::fs;
use std::path::Path;
use std::{collections::HashMap, fs};
use self::npm::{
repository::Repository, CommonJSPackage, ESModulesPackage, NoModulesPackage, NpmPackage,
@ -575,14 +575,25 @@ impl CrateData {
target: Target,
) -> Result<(), Error> {
let pkg_file_path = out_dir.join("package.json");
// Check if a `package.json` was already generated by wasm-bindgen, if so
// we merge the NPM dependencies already specified in it.
let existing_deps = if pkg_file_path.exists() {
// It's just a map of dependency names to versions
Some(serde_json::from_str::<HashMap<String, String>>(
&fs::read_to_string(&pkg_file_path)?,
)?)
} else {
None
};
let npm_data = match target {
Target::Nodejs => self.to_commonjs(scope, disable_dts, out_dir),
Target::NoModules => self.to_nomodules(scope, disable_dts, out_dir),
Target::Bundler => self.to_esmodules(scope, disable_dts, out_dir),
Target::Web => self.to_web(scope, disable_dts, out_dir),
Target::Nodejs => self.to_commonjs(scope, disable_dts, existing_deps, out_dir),
Target::NoModules => self.to_nomodules(scope, disable_dts, existing_deps, out_dir),
Target::Bundler => self.to_esmodules(scope, disable_dts, existing_deps, out_dir),
Target::Web => self.to_web(scope, disable_dts, existing_deps, out_dir),
};
let npm_json = serde_json::to_string_pretty(&npm_data)?;
fs::write(&pkg_file_path, npm_json)
.with_context(|_| format!("failed to write: {}", pkg_file_path.display()))?;
Ok(())
@ -644,7 +655,7 @@ impl CrateData {
files,
main: js_file,
homepage: self.manifest.package.homepage.clone(),
keywords: keywords,
keywords,
}
}
@ -657,7 +668,13 @@ impl CrateData {
})
}
fn to_commonjs(&self, scope: &Option<String>, disable_dts: bool, out_dir: &Path) -> NpmPackage {
fn to_commonjs(
&self,
scope: &Option<String>,
disable_dts: bool,
dependencies: Option<HashMap<String, String>>,
out_dir: &Path,
) -> NpmPackage {
let data = self.npm_data(scope, false, disable_dts, out_dir);
let pkg = &self.data.packages[self.current_idx];
@ -683,6 +700,7 @@ impl CrateData {
homepage: data.homepage,
types: data.dts_file,
keywords: data.keywords,
dependencies,
})
}
@ -690,6 +708,7 @@ impl CrateData {
&self,
scope: &Option<String>,
disable_dts: bool,
dependencies: Option<HashMap<String, String>>,
out_dir: &Path,
) -> NpmPackage {
let data = self.npm_data(scope, true, disable_dts, out_dir);
@ -718,10 +737,17 @@ impl CrateData {
types: data.dts_file,
side_effects: false,
keywords: data.keywords,
dependencies,
})
}
fn to_web(&self, scope: &Option<String>, disable_dts: bool, out_dir: &Path) -> NpmPackage {
fn to_web(
&self,
scope: &Option<String>,
disable_dts: bool,
dependencies: Option<HashMap<String, String>>,
out_dir: &Path,
) -> NpmPackage {
let data = self.npm_data(scope, false, disable_dts, out_dir);
let pkg = &self.data.packages[self.current_idx];
@ -748,6 +774,7 @@ impl CrateData {
types: data.dts_file,
side_effects: false,
keywords: data.keywords,
dependencies,
})
}
@ -755,6 +782,7 @@ impl CrateData {
&self,
scope: &Option<String>,
disable_dts: bool,
dependencies: Option<HashMap<String, String>>,
out_dir: &Path,
) -> NpmPackage {
let data = self.npm_data(scope, false, disable_dts, out_dir);
@ -782,6 +810,7 @@ impl CrateData {
homepage: data.homepage,
types: data.dts_file,
keywords: data.keywords,
dependencies,
})
}

@ -1,3 +1,5 @@
use std::collections::HashMap;
use manifest::npm::repository::Repository;
#[derive(Serialize)]
@ -21,4 +23,6 @@ pub struct CommonJSPackage {
pub types: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub keywords: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub dependencies: Option<HashMap<String, String>>,
}

@ -1,3 +1,5 @@
use std::collections::HashMap;
use manifest::npm::repository::Repository;
#[derive(Serialize)]
@ -23,4 +25,6 @@ pub struct ESModulesPackage {
pub side_effects: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub keywords: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub dependencies: Option<HashMap<String, String>>,
}

@ -1,3 +1,5 @@
use std::collections::HashMap;
use manifest::npm::repository::Repository;
#[derive(Serialize)]
@ -21,4 +23,6 @@ pub struct NoModulesPackage {
pub types: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub keywords: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub dependencies: Option<HashMap<String, String>>,
}

@ -13,3 +13,5 @@ pub const WINDOWS: bool = cfg!(target_os = "windows");
pub const x86_64: bool = cfg!(target_arch = "x86_64");
#[allow(non_upper_case_globals)]
pub const x86: bool = cfg!(target_arch = "x86");
#[allow(non_upper_case_globals)]
pub const aarch64: bool = cfg!(target_arch = "aarch64");

@ -23,13 +23,13 @@ fn get_and_notify(
name: &str,
url: &str,
) -> Result<Option<PathBuf>, failure::Error> {
if let Some(dl) = cache.download(false, name, &[name], &url)? {
if let Some(dl) = cache.download(false, name, &[name], url)? {
return Ok(Some(dl.binary(name)?));
}
if installation_allowed {
PBAR.info(&format!("Getting {}...", name));
}
match cache.download(installation_allowed, name, &[name], &url)? {
match cache.download(installation_allowed, name, &[name], url)? {
Some(dl) => Ok(Some(dl.binary(name)?)),
None => Ok(None),
}
@ -39,8 +39,7 @@ struct Collector(Vec<u8>);
impl Collector {
pub fn take_content(&mut self) -> Vec<u8> {
// TODO: replace with `std::mem::take` once stable
std::mem::replace(&mut self.0, Vec::default())
std::mem::take(&mut self.0)
}
}

@ -9,7 +9,7 @@ use target;
// Keep it up to date with each `wasm-pack` release.
// https://chromedriver.storage.googleapis.com/LATEST_RELEASE
const DEFAULT_CHROMEDRIVER_VERSION: &str = "79.0.3945.36";
const DEFAULT_CHROMEDRIVER_VERSION: &str = "91.0.4472.101";
const CHROMEDRIVER_LAST_UPDATED_STAMP: &str = "chromedriver_last_updated";
const CHROMEDRIVER_VERSION_STAMP: &str = "chromedriver_version";

@ -9,7 +9,7 @@ use target;
// Keep it up to date with each `wasm-pack` release.
// https://github.com/mozilla/geckodriver/releases/latest
const DEFAULT_GECKODRIVER_VERSION: &str = "v0.26.0";
const DEFAULT_GECKODRIVER_VERSION: &str = "v0.29.1";
const DEFAULT_WINDOWS_GECKODRIVER_VERSION: &str = "v0.24.0";
const GECKODRIVER_LAST_UPDATED_STAMP: &str = "geckodriver_last_updated";

@ -3,7 +3,7 @@
use crate::child;
use crate::install::{self, Tool};
use crate::PBAR;
use binary_install::Cache;
use binary_install::{Cache, Download};
use std::path::Path;
use std::process::Command;
@ -58,6 +58,16 @@ pub fn find_wasm_opt(
cache: &Cache,
install_permitted: bool,
) -> Result<install::Status, failure::Error> {
// First attempt to look up in PATH. If found assume it works.
if let Ok(path) = which::which("wasm-opt") {
PBAR.info(&format!("found wasm-opt at {:?}", path));
match path.as_path().parent() {
Some(path) => return Ok(install::Status::Found(Download::at(path))),
None => {}
}
}
let version = "version_78";
Ok(install::download_prebuilt(
&install::Tool::WasmOpt,

@ -146,8 +146,8 @@ fn dash_dash_web_target_has_error_on_old_bindgen() {
let output = String::from_utf8(cmd.get_output().stderr.clone()).unwrap();
assert!(
output.contains("0.2.39"),
"Output did not contain '0.2.39', output was {}",
output.contains("Please update your project to wasm-bindgen version >= 0.2.39"),
"Output did not contain 'Please update your project to wasm-bindgen version >= 0.2.39', output was {}",
output
);
}
@ -264,7 +264,6 @@ fn build_with_arbitrary_cargo_options() {
fixture
.wasm_pack()
.arg("build")
.arg("--")
.arg("--no-default-features")
.assert()
.success();

@ -12,7 +12,7 @@ fn can_download_prebuilt_wasm_bindgen() {
let dir = tempfile::TempDir::new().unwrap();
let cache = Cache::at(dir.path());
if let install::Status::Found(dl) =
install::download_prebuilt(&Tool::WasmBindgen, &cache, "0.2.37", true).unwrap()
install::download_prebuilt(&Tool::WasmBindgen, &cache, "0.2.74", true).unwrap()
{
assert!(dl.binary("wasm-bindgen").unwrap().is_file());
assert!(dl.binary("wasm-bindgen-test-runner").unwrap().is_file())
@ -29,7 +29,7 @@ fn can_download_prebuilt_wasm_bindgen() {
))]
fn downloading_prebuilt_wasm_bindgen_handles_http_errors() {
let dir = tempfile::TempDir::new().unwrap();
let bad_version = "0.2.37-some-trailing-version-stuff-that-does-not-exist";
let bad_version = "0.2.74-some-trailing-version-stuff-that-does-not-exist";
let cache = Cache::at(dir.path());
let result = install::download_prebuilt(&Tool::WasmBindgen, &cache, bad_version, true);
assert!(result.is_err());

@ -8,7 +8,7 @@ fn it_gets_wasm_bindgen_version() {
fixture.cargo_check();
let data = CrateData::new(&fixture.path, None).unwrap();
let lock = Lockfile::new(&data).unwrap();
assert_eq!(lock.wasm_bindgen_version(), Some("0.2.37"),);
assert_eq!(lock.wasm_bindgen_version(), Some("0.2.74"),);
}
#[test]
@ -17,7 +17,7 @@ fn it_gets_wasm_bindgen_test_version() {
fixture.cargo_check();
let data = CrateData::new(&fixture.path, None).unwrap();
let lock = Lockfile::new(&data).unwrap();
assert_eq!(lock.wasm_bindgen_test_version(), Some("0.2.37"),);
assert_eq!(lock.wasm_bindgen_test_version(), Some("0.3.24"),);
}
#[test]
@ -46,7 +46,7 @@ fn it_gets_wasm_bindgen_version_in_crate_inside_workspace() {
crate-type = ["cdylib"]
[dependencies]
wasm-bindgen = "=0.2.37"
wasm-bindgen = "=0.2.74"
"#,
)
.file(
@ -62,7 +62,7 @@ fn it_gets_wasm_bindgen_version_in_crate_inside_workspace() {
fixture.cargo_check();
let data = CrateData::new(&fixture.path.join("blah"), None).unwrap();
let lock = Lockfile::new(&data).unwrap();
assert_eq!(lock.wasm_bindgen_version(), Some("0.2.37"),);
assert_eq!(lock.wasm_bindgen_version(), Some("0.2.74"),);
}
#[test]
@ -91,7 +91,7 @@ fn it_gets_wasm_bindgen_version_from_dependencies() {
crate-type = ["cdylib"]
[dependencies]
wasm-bindgen = "=0.2.37"
wasm-bindgen = "=0.2.74"
"#,
)
.file(
@ -130,5 +130,5 @@ fn it_gets_wasm_bindgen_version_from_dependencies() {
fixture.cargo_check();
let data = CrateData::new(&fixture.path.join("parent"), None).unwrap();
let lock = Lockfile::new(&data).unwrap();
assert_eq!(lock.wasm_bindgen_version(), Some("0.2.37"),);
assert_eq!(lock.wasm_bindgen_version(), Some("0.2.74"),);
}

@ -9,7 +9,6 @@ fn matches_info() -> impl Predicate<str> + PredicateReflection {
contains("[INFO]: Checking for the Wasm target...")
.and(contains("[INFO]: Compiling to Wasm..."))
.and(contains("[INFO]: License key is set in Cargo.toml but no LICENSE file(s) were found; Please add the LICENSE file(s) to your project directory"))
.and(contains("[INFO]: Installing wasm-bindgen..."))
.and(contains("[INFO]: Optimizing wasm binaries with `wasm-opt`..."))
.and(contains("[INFO]: :-) Done in "))
.and(contains("[INFO]: :-) Your wasm pkg is ready to publish at "))

@ -8,7 +8,7 @@ extern crate serde_derive;
extern crate binary_install;
extern crate serde_json;
#[macro_use]
extern crate serial_test_derive;
extern crate serial_test;
extern crate structopt;
extern crate tempfile;
extern crate wasm_pack;

@ -1,5 +1,5 @@
use assert_cmd::prelude::*;
use std::collections::HashSet;
use std::collections::{HashMap, HashSet};
use std::fs;
use std::path::PathBuf;
use utils::{self, fixture};
@ -314,6 +314,54 @@ fn it_creates_a_package_json_with_correct_keys_when_types_are_skipped() {
assert_eq!(actual_files, expected_files);
}
#[test]
fn it_creates_a_package_json_with_npm_dependencies_provided_by_wasm_bindgen() {
let fixture = fixture::js_hello_world();
let out_dir = fixture.path.join("pkg");
let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap();
// Write a `package.json` in the out_dir, as wasm-bindgen does:
utils::manifest::create_wbg_package_json(
&out_dir,
r#"
{ "foo": "^1.2.3" }
"#,
)
.unwrap();
assert!(crate_data
.write_package_json(&out_dir, &None, true, Target::Bundler)
.is_ok());
let package_json_path = &out_dir.join("package.json");
fs::metadata(package_json_path).unwrap();
utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap();
let pkg = utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap();
assert_eq!(pkg.name, "js-hello-world");
assert_eq!(pkg.repository.ty, "git");
assert_eq!(
pkg.repository.url,
"https://github.com/rustwasm/wasm-pack.git"
);
assert_eq!(pkg.module, "js_hello_world.js");
let actual_files: HashSet<String> = pkg.files.into_iter().collect();
let expected_files: HashSet<String> = [
"js_hello_world_bg.wasm",
"js_hello_world_bg.js",
"js_hello_world.js",
]
.iter()
.map(|&s| String::from(s))
.collect();
assert_eq!(actual_files, expected_files);
let dependencies: Option<HashMap<String, String>> = pkg.dependencies;
assert!(dependencies.is_some());
let mut expected_dependencies: HashMap<String, String> = HashMap::new();
expected_dependencies.insert("foo".to_owned(), "^1.2.3".to_owned());
assert_eq!(dependencies.unwrap(), expected_dependencies);
}
#[test]
fn it_errors_when_wasm_bindgen_is_not_declared() {
let fixture = fixture::bad_cargo_toml();

@ -337,3 +337,61 @@ fn test_output_is_printed_once_in_both_stdout_and_failures() {
out.matches("YABBA DABBA DOO").count() == log_cnt * 2
}));
}
#[test]
fn extra_options_is_passed_to_cargo_when_building_tests() {
let fixture = fixture::Fixture::new();
fixture
.readme()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
authors = []
[dev-dependencies]
wasm-bindgen-test = "0.2"
[features]
default = ["native"]
native = []
"#,
)
.file(
"src/lib.rs",
r#"
pub fn foo() -> u32 {
#[cfg(feature = "native")]
compile_error!("Test should pass through `--no-default-features` for this to pass.");
1
}
"#,
)
.file(
"tests/foo.rs",
r#"
extern crate wasm_bindgen_test;
use wasm_bindgen_test::*;
#[wasm_bindgen_test]
fn smoke() {
foo::foo();
}
#[wasm_bindgen_test]
fn fire() {
panic!("This should be filtered from test execution.");
}
"#,
)
.install_local_wasm_bindgen();
let _lock = fixture.lock();
fixture
.wasm_pack()
.args(&["test", "--node", "--no-default-features", "--", "smoke"])
.assert()
.success();
}

@ -143,10 +143,10 @@ impl Fixture {
# bindgen downloaded is what we expect, and if `=` is
# removed then it will download whatever the newest version
# of wasm-bindgen is which may not be what's listed here.
wasm-bindgen = "=0.2.37"
wasm-bindgen = "=0.2.74"
[dev-dependencies]
wasm-bindgen-test = "0.2"
wasm-bindgen-test = "0.3"
"#,
name
),
@ -221,7 +221,7 @@ impl Fixture {
static INSTALL_WASM_BINDGEN: Once = Once::new();
let cache = self.cache();
let version = "0.2.37";
let version = "0.2.74";
let download = || {
if let Ok(download) =
@ -417,7 +417,7 @@ pub fn no_cdylib() -> Fixture {
wasm-bindgen = "0.2"
[dev-dependencies]
wasm-bindgen-test = "0.2"
wasm-bindgen-test = "0.3"
"#,
);
fixture
@ -590,7 +590,7 @@ pub fn transitive_dependencies() -> Fixture {
project_b = { path = "../project_b" }
[dev-dependencies]
wasm-bindgen-test = "0.2"
wasm-bindgen-test = "0.3"
"#,
);
fixture.file(
@ -639,7 +639,7 @@ pub fn transitive_dependencies() -> Fixture {
project_b = { path = "../project_b" }
[dev-dependencies]
wasm-bindgen-test = "0.2"
wasm-bindgen-test = "0.3"
"#,
);
fixture.file(
@ -688,7 +688,7 @@ pub fn transitive_dependencies() -> Fixture {
wasm-bindgen = "0.2"
[dev-dependencies]
wasm-bindgen-test = "0.2"
wasm-bindgen-test = "0.3"
"#,
);
fixture.file(

@ -1,6 +1,6 @@
use std::fs::File;
use std::io::prelude::*;
use std::path::Path;
use std::{collections::HashMap, fs::File};
use failure::Error;
use serde_json;
@ -25,6 +25,7 @@ pub struct NpmPackage {
pub side_effects: bool,
pub homepage: Option<String>,
pub keywords: Option<Vec<String>>,
pub dependencies: Option<HashMap<String, String>>,
}
fn default_none() -> String {
@ -50,3 +51,8 @@ pub fn read_package_json(path: &Path, out_dir: &Path) -> Result<NpmPackage, Erro
Ok(serde_json::from_str(&pkg_contents)?)
}
pub fn create_wbg_package_json(out_dir: &Path, contents: &str) -> Result<(), Error> {
let manifest_path = out_dir.join("package.json");
Ok(std::fs::write(manifest_path, contents)?)
}

Loading…
Cancel
Save