Skip to content

NPM dependencies don't get copied to pkg/package.json #840

@bminixhofer

Description

@bminixhofer

🐛 Bug description

Dependencies declared in a package.json next to Cargo.toml do not get copied over to pkg/package.json. This should be supported according to rustwasm/rfcs#8.

Content of handwritten package.json:

{
    "dependencies": {
        "@tensorflow/tfjs": "^1.7.4"
    }
}

Content of generated pkg/package.json:

{
  "name": "npm-dep-test",
  "collaborators": [
    "Benjamin Minixhofer <[email protected]>"
  ],
  "version": "0.1.0",
  "files": [
    "npm_dep_test_bg.wasm",
    "npm_dep_test.js",
    "npm_dep_test.d.ts"
  ],
  "module": "npm_dep_test.js",
  "types": "npm_dep_test.d.ts",
  "sideEffects": false
}

🤔 Expected Behavior

I would have expected pkg/package.json to have a "dependencies" key which lists "@tensorflow/tfjs" as dependency.

👟 Steps to reproduce

To reproduce:

  1. Generate a new project: cargo generate --git https://github.com/rustwasm/wasm-pack-template
  2. Create a file package.json next to Cargo.toml at the project root, which has the content:
{
    "dependencies": {
        "@tensorflow/tfjs": "^1.7.4"
    }
}
  1. (probably optional) add some code to src/lib.rs which uses the dependency to make sure it doesn't get optimized out, e. g.
#[wasm_bindgen(module = "@tensorflow/tfjs")]
extern {
    fn sequential() -> JsValue;
}

#[wasm_bindgen]
pub fn greet() {
    alert(&format!("{:#?}", sequential()));
}
  1. Run wasm-pack build and look at the content of pkg/package.json.

Alternatively, run git clone https://github.com/bminixhofer/npm-dep-test to skip steps 1-3.

🌍 Your environment

Include the relevant details of your environment.
wasm-pack version: wasm-pack 0.9.1
rustc version: rustc 1.43.0 (4fb7144ed 2020-04-20)

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions