Skip to content

Commit 88fdbc5

Browse files
committed
Add documentation for pack and publish
1 parent 28d5bb5 commit 88fdbc5

File tree

5 files changed

+36
-14
lines changed

5 files changed

+36
-14
lines changed

docs/pack-and-publish.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# pack and publish
2+
3+
The `publish` and `pack` commands interact with the pkg directory that's
4+
created when you run `wasm-pack init`. The `pack` command creates a tarball
5+
from the pkg directory and the `publish` command creates a tarball from the
6+
pkg directory __and__ publishes it to the NPM registry.
7+
8+
Underneath, these commands use `npm pack` and `npm publish`. You can read
9+
more about these in the NPM documentation:
10+
11+
- [`npm pack`](https://docs.npmjs.com/cli/pack)
12+
- [`npm publish`](https://docs.npmjs.com/cli/publish)
13+
14+
Both these commands take the path to the pkg directory as the first argument.
15+
You can either set the argument directly to the pkg directory or to the parent
16+
of the pkg directory:
17+
18+
```
19+
$ wasm-pack pack myproject/pkg
20+
| 🎒 packed up your package!
21+
$ wasm-pack pack myproject
22+
| 🎒 packed up your package!
23+
```
24+
25+
If you try to call `pack` or `publish` on another directory, you get an error:
26+
27+
```
28+
$ wasm-pack pack myproject/src/
29+
Unable to find the pkg directory at path 'myproject/src/', or in a child directory of 'myproject/src/'
30+
```
31+
32+
If you don't set a path, they use the current directory as the path.

docs/pack.md

Lines changed: 0 additions & 10 deletions
This file was deleted.

docs/publish.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/command/pack.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use slog::Logger;
55
use std::result;
66
use PBAR;
77

8+
/// Executes the 'npm pack' command on the 'pkg' directory
9+
/// which creates a tarball that can be published to the NPM registry
810
pub fn pack(path: Option<String>, log: &Logger) -> result::Result<(), Error> {
911
let crate_path = set_crate_path(path);
1012

src/command/publish.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use slog::Logger;
55
use std::result;
66
use PBAR;
77

8+
/// Creates a tarball from a 'pkg' directory
9+
/// and publishes it to the NPM registry
810
pub fn publish(path: Option<String>, log: &Logger) -> result::Result<(), Error> {
911
let crate_path = set_crate_path(path);
1012

0 commit comments

Comments
 (0)