-
Notifications
You must be signed in to change notification settings - Fork 412
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
Allow the user to fully customize the package name #427
Comments
While I agree that we want to allow this functionality, I don't think adding a new flag is quite the fix we want. rustwasm/rfcs#4 will likely end up allowing crates to write package.json snippets that are then merged into the package.json that wasm-pack creates. I think using this package.json merging would be the right way to customize the package name. In the meantime, one can always edit the |
Thanks for the response @fitzgen! I wanted to explain a bit more about the use case I imagine, because I don't think snippet-merging would help here and runtime renaming is actually preferable.
As a basic example of how a runtime option would let me have it both ways: the excellent
The first invocation produces a standard browser-compatible target called So, in summary, I thought a new flag could be merited because it lets us use multiple package names with the same code base without having to rewrite anything. |
FYI, this is not common practice. Instead, it is standard to publish both the ES6 and CommonJS versions within the same package (using the wasm-pack doesn't currently support this, but it will: #157 #313 As for browser vs Node, that's usually handled with the
I think it's reasonable for the If we add in ad-hoc flags to wasm-pack, that raises some questions like: why only allow for customizing the name? Why not the version? Why not other things? That leads to an explosion of various flags, which I don't think is very good. Rather than adding flags to wasm-pack, I think the It could even support a nice API like this: module.exports = {
plugins: [
new WasmPackPlugin({
crateDirectory: path.resolve(__dirname, "crate"),
packageJson: {
name: "@foo/bar"
}
}),
new WasmPackPlugin({
crateDirectory: path.resolve(__dirname, "crate"),
packageJson: {
name: "@foo/bar-node"
}
}),
],
}; That would allow you to customize all of the |
I agree #313 (with both |
For anyone else coming to this needing to change the package name more than just the SHELL = /bin/bash
.SHELLFLAGS := -eu -o pipefail -c
.DEFAULT_GOAL := build
.DELETE_ON_ERROR:
.SUFFIXES:
build: pkg
pkg: src
wasm-pack build
sed -i ".bak" -e 's/"name": "rust-package-name"/"name": "npm-package-name"/g' pkg/package.json
rm pkg/package.json.bak For those unfamiliar with make files, there is a bit of unnecessary fluff here but the important parts are:
Then, whenever you want to build, just run One thing to watch out for, if the build fails it will remove the target (ie. the |
I don't think this issue should be marked as resolved because, while the original problem of @stristr was resolved, and I'm happy for it, the functionality is still missing and I think it's needed. In my case I have multiple packages in a monorepo and I would like to prefix them with something like Every way to replace generated package.json name seems a bit hacky to me and since lots of npm packages are scoped I don't see why this is not supported yet, but I'm open to discussion. I think that a flag, like
|
💡 Feature description
Currently, the NPM package name generated by
wasm-pack
is the (optionally scoped) name of the Rust crate being packed. There is utility in being able to choose the name of the package; for example, I might want to publish multiple packages to the NPM repository using different--target
options.💻 Basic example
I propose a command line flag,
--package-name
, for this purpose, which should work in conjunction with--scope
.For example:
wasm-pack build examples/js-hello-world --scope test --package-name custom-name
should result in an NPM package named
@test/custom-name
.The text was updated successfully, but these errors were encountered: