|
| 1 | +# @foundry-rs npm Packages |
| 2 | + |
| 3 | +This folder contains the npm packages for the Foundry CLI. |
| 4 | + |
| 5 | +- `@foundry-rs/forge`, |
| 6 | +- `@foundry-rs/anvil` (soon), |
| 7 | + |
| 8 | +## Local publish & Test |
| 9 | + |
| 10 | +The npm folder contains the meta package `@foundry-rs/forge` and per-arch packages (e.g. `@foundry-rs/forge-darwin-arm64`). This guide shows how to publish them to a local registry and test via npx/bunx. |
| 11 | + |
| 12 | +### Prerequisites |
| 13 | + |
| 14 | +- Node.js LTS, npm, and Bun installed (`bun -v`). |
| 15 | +- Docker (recommended) or a local [Verdaccio](https://verdaccio.org) install. |
| 16 | +- Optional: Rust toolchain if you want to build a fresh `forge` binary (`cargo build --release -p forge`). |
| 17 | + |
| 18 | +Start a local npm registry (Verdaccio) with Docker: |
| 19 | + |
| 20 | +- Docker: `docker run -it --rm --name verdaccio -p 4873:4873 verdaccio/verdaccio` |
| 21 | +- Verify: open `http://localhost:4873` in a browser |
| 22 | +- Note: you might need to bump `max_body_size` in [Verdaccio `config.yaml`](https://verdaccio.org/docs/configuration#max-body-size): |
| 23 | + |
| 24 | + ```yaml |
| 25 | + max_body_size: 300mb # default is 10mb |
| 26 | + ``` |
| 27 | +
|
| 28 | + I enter the docker image then `echo 'max_body_size: 300mb' >> /verdaccio/conf/config.yaml` |
| 29 | + |
| 30 | +Authenticate npm to Verdaccio |
| 31 | + |
| 32 | +- Create a user/token: `npm adduser --registry http://localhost:4873 --scope=@foundry-rs` |
| 33 | +- Ensure your auth token is present (either in `~/.npmrc` or a project `.npmrc`): |
| 34 | + - `registry=http://localhost:4873` |
| 35 | + - `//localhost:4873/:_authToken=YOUR_TOKEN` |
| 36 | + |
| 37 | +#### Quick publish (macOS arm64) |
| 38 | + |
| 39 | +- From `npm/` in this repo: |
| 40 | + - `export NPM_REGISTRY_URL=http://localhost:4873` |
| 41 | + - `export NPM_TOKEN=localtesttoken` # required by scripts; any non-empty value works |
| 42 | + - `bun install` |
| 43 | + - `./scripts/setup-local.sh` |
| 44 | +- This publishes `@foundry-rs/forge-darwin-arm64` and then `@foundry-rs/forge` to your local registry. |
| 45 | + |
| 46 | +### Manual publish (any platform) |
| 47 | + |
| 48 | +- Build wrappers: `cd npm && bun install && npm run build` |
| 49 | +- If you have a local `forge` binary, stage it for your platform: |
| 50 | + - Example (macOS arm64): |
| 51 | + - `cargo build --release -p forge` |
| 52 | + - `cd npm` |
| 53 | + - `ARCH=arm64 PLATFORM_NAME=darwin FORGE_BIN_PATH=../target/release/forge bun ./scripts/prepublish.ts` |
| 54 | +- Publish the platform package, then the meta package (versions auto-synced from Cargo.toml unless overridden by `VERSION_NAME`): |
| 55 | + - `export NPM_REGISTRY_URL=http://localhost:4873` |
| 56 | + - `export NPM_TOKEN=localtesttoken` |
| 57 | + - `bun run ./scripts/publish.ts ./@foundry-rs/forge-<platform>-<arch>` |
| 58 | + - `bun run ./scripts/publish.ts ./@foundry-rs/forge` |
| 59 | + |
| 60 | +#### Run from a test workspace |
| 61 | + |
| 62 | +- Use the provided workspace: `cd npm/test/workspace` |
| 63 | +- Registry config is already set (`.npmrc` and `bunfig.toml` point to `http://localhost:4873`). |
| 64 | +- With npm: `npx @foundry-rs/forge --version` |
| 65 | +- With Bun: `bunx @foundry-rs/forge --version` |
| 66 | +- Alternatively from anywhere, force the local registry: |
| 67 | + - `npm_config_registry=http://localhost:4873 npx @foundry-rs/forge --version` |
| 68 | + - `REGISTRY_URL=http://localhost:4873 bunx @foundry-rs/forge --version` |
| 69 | + |
| 70 | +#### Notes |
| 71 | + |
| 72 | +- The meta package’s `postinstall` either installs the platform-specific optionalDependency or downloads its tarball from the configured registry. |
| 73 | +- Publish arch packages first, then the meta package; the publish script auto-updates `optionalDependencies` to the same version. |
| 74 | +- If `npm publish` returns 401, ensure you ran `npm adduser` against `http://localhost:4873` and that your token is present in `.npmrc` or provided via `NODE_AUTH_TOKEN`. |
0 commit comments