Skip to content
New issue

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

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

Already on GitHub? # to your account

feat(publish): dist tag option #690

Merged
merged 1 commit into from
Jul 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion docs/src/commands/pack-and-publish.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The `publish` and `pack` commands interact with the pkg directory that's
created when you run `wasm-pack build`. The `pack` command creates a tarball
from the pkg directory and the `publish` command creates a tarball from the
pkg directory __and__ publishes it to the NPM registry.
pkg directory **and** publishes it to the NPM registry.

Underneath, these commands use `npm pack` and `npm publish`. You can read
more about these in the NPM documentation:
Expand All @@ -30,3 +30,16 @@ Unable to find the pkg directory at path 'myproject/src/', or in a child directo
```

If you don't set a path, they use the current directory as the path.

## Publishing tagged releases

You can also publish tagged releases with the optional `--tag` argument, e.g.

```
wasm-pack publish --tag next
```

By default, the `latest` tag is used to identify the current version of a package,
and npm install \<pkg\> (without any @\<version\> or @\<tag\> specifier) installs the latest tag.

You can read more about [distribution tags](https://docs.npmjs.com/cli/dist-tag) on NPM.
8 changes: 7 additions & 1 deletion src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ pub enum Command {
#[structopt(long = "access", short = "a")]
access: Option<Access>,

/// The distribution tag being used for publishing.
/// See https://docs.npmjs.com/cli/dist-tag
#[structopt(long = "tag")]
tag: Option<String>,

/// The path to the Rust crate. If not set, searches up the path from the current dirctory.
#[structopt(parse(from_os_str))]
path: Option<PathBuf>,
Expand Down Expand Up @@ -135,10 +140,11 @@ pub fn run_wasm_pack(command: Command) -> result::Result<(), Error> {
target,
path,
access,
tag,
} => {
info!("Running publish command...");
info!("Path: {:?}", &path);
publish(&target, path, access)
publish(&target, path, access, tag)
}
Command::Login {
registry,
Expand Down
3 changes: 2 additions & 1 deletion src/command/publish/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub fn publish(
_target: &str,
path: Option<PathBuf>,
access: Option<Access>,
tag: Option<String>,
) -> result::Result<(), Error> {
let crate_path = get_crate_path(path)?;

Expand Down Expand Up @@ -74,7 +75,7 @@ pub fn publish(
}
}
}?;
npm::npm_publish(&pkg_directory.to_string_lossy(), access)?;
npm::npm_publish(&pkg_directory.to_string_lossy(), access, tag)?;
info!("Published your package!");

PBAR.info("💥 published your package!");
Expand Down
9 changes: 8 additions & 1 deletion src/npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@ pub fn npm_pack(path: &str) -> Result<(), failure::Error> {
}

/// Run the `npm publish` command.
pub fn npm_publish(path: &str, access: Option<Access>) -> Result<(), failure::Error> {
pub fn npm_publish(
path: &str,
access: Option<Access>,
tag: Option<String>,
) -> Result<(), failure::Error> {
let mut cmd = child::new_command("npm");
match access {
Some(a) => cmd.current_dir(path).arg("publish").arg(&a.to_string()),
None => cmd.current_dir(path).arg("publish"),
};
if let Some(tag) = tag {
cmd.arg("--tag").arg(&tag.to_string());
};

child::run(cmd, "npm publish").context("Publishing to npm failed")?;
Ok(())
Expand Down