Skip to content

Commit 1cd2059

Browse files
committed
chore(npm): fix windows and update deps
1 parent 86f6065 commit 1cd2059

File tree

14 files changed

+224
-92
lines changed

14 files changed

+224
-92
lines changed

.github/workflows/release.yml

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -274,44 +274,64 @@ jobs:
274274
275275
- name: Setup Bun (npm)
276276
uses: oven-sh/setup-bun@735343b667d3e6f658f44d0eca948eb6282f2b76
277-
env:
278-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
279277
with:
280278
bun-version: "latest"
281279
scope: "@foundry-rs"
282280
registry-url: "https://registry.npmjs.org"
283281

282+
- name: Setup Node (auth for npm publish)
283+
uses: actions/setup-node@v4
284+
with:
285+
node-version: lts
286+
registry-url: "https://registry.npmjs.org"
287+
284288
- name: Install dependencies
285289
working-directory: ./npm
286290
run: bun install --frozen-lockfile
287291

288292
- name: Publish @foundry-rs/forge-${{ matrix.platform }}-${{ matrix.arch }} (npm)
293+
if: matrix.platform != 'alpine'
289294
shell: bash
290295
working-directory: ./npm
291296
env:
292-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
297+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
293298
NPM_REGISTRY_URL: "https://registry.npmjs.org"
299+
PROVENANCE: true
294300
ARCH: ${{ matrix.arch }}
295301
TARGET: ${{ matrix.target }}
296-
PLATFORM: ${{ matrix.platform }}
297-
OUT_DIR: target/${{ matrix.target }}/${{ env.PROFILE }}
302+
PLATFORM_NAME: ${{ matrix.platform }}
303+
OUT_DIR: ${{ github.workspace }}/target/${{ matrix.target }}/${{ env.PROFILE }}
298304
VERSION_NAME: ${{ (env.IS_NIGHTLY == 'true' && 'nightly') || needs.prepare.outputs.tag_name }}
299305
run: |-
306+
set -eo pipefail
307+
# Provide explicit path to the compiled forge binary for this platform
308+
if [[ "$TARGET" == *windows* ]]; then
309+
export FORGE_BIN_PATH="$OUT_DIR/forge.exe"
310+
else
311+
export FORGE_BIN_PATH="$OUT_DIR/forge"
312+
fi
313+
echo "Using FORGE_BIN_PATH=$FORGE_BIN_PATH"
300314
bun ./scripts/prepublish.ts
301-
bun run ./scripts/publish.ts ./@foundry-rs/forge-${{ env.PLATFORM }}-${{ env.ARCH }}
315+
bun run ./scripts/publish.ts ./@foundry-rs/forge-${PLATFORM_NAME}-${ARCH}
302316
303317
publish-npm:
304318
name: Publish @foundry-rs/forge
305319
runs-on: ubuntu-latest
306320
needs: release
307321
steps:
308-
- uses: actions/checkout@v4
322+
- uses: actions/checkout@v5
309323
- uses: oven-sh/setup-bun@735343b667d3e6f658f44d0eca948eb6282f2b76
310324
with:
311325
bun-version: "latest"
312326
scope: "@foundry-rs"
313327
registry-url: "https://registry.npmjs.org"
314328

329+
- name: Setup Node (auth for npm publish)
330+
uses: actions/setup-node@v4
331+
with:
332+
node-version: lts
333+
registry-url: "https://registry.npmjs.org"
334+
315335
- name: Install dependencies
316336
working-directory: ./npm
317337
run: bun install --frozen-lockfile
@@ -320,10 +340,12 @@ jobs:
320340
shell: bash
321341
working-directory: ./npm
322342
env:
323-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
343+
PROVENANCE: true
344+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
324345
NPM_REGISTRY_URL: "https://registry.npmjs.org"
325346
run: |-
326-
bun ./scripts/prepublish.ts
347+
# Build wrappers for the meta package
348+
npm run build
327349
bun run ./scripts/publish.ts ./@foundry-rs/forge
328350
329351
cleanup:

npm/@foundry-rs/forge-darwin-arm64/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@foundry-rs/forge-darwin-arm64",
3-
"version": "1.3.0",
3+
"version": "1.3.2",
44
"type": "module",
55
"homepage": "https://getfoundry.sh",
66
"description": "Fast and flexible Ethereum testing framework (macOS arm64)",

npm/@foundry-rs/forge-win32-amd64/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"homepage": "https://getfoundry.sh",
66
"description": "Fast and flexible Ethereum testing framework (Windows amd64)",
77
"bin": {
8-
"forge": "./bin/forge"
8+
"forge": "./bin/forge.exe"
99
},
1010
"os": [
1111
"win32"

npm/@foundry-rs/forge/package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@foundry-rs/forge",
3-
"version": "1.3.0",
3+
"version": "1.3.2",
44
"type": "module",
55
"homepage": "https://getfoundry.sh",
66
"description": "Fast and flexible Ethereum testing framework",
@@ -19,14 +19,15 @@
1919
"postinstall": "node ./dist/install.mjs"
2020
},
2121
"optionalDependencies": {
22-
"@foundry-rs/forge-darwin-arm64": "1.3.0",
23-
"@foundry-rs/forge-darwin-amd64": "1.3.0",
24-
"@foundry-rs/forge-linux-arm64": "1.3.0",
25-
"@foundry-rs/forge-linux-amd64": "1.3.0",
26-
"@foundry-rs/forge-win32-amd64": "1.3.0"
22+
"@foundry-rs/forge-darwin-arm64": "1.3.2",
23+
"@foundry-rs/forge-darwin-amd64": "1.3.2",
24+
"@foundry-rs/forge-linux-arm64": "1.3.2",
25+
"@foundry-rs/forge-linux-amd64": "1.3.2",
26+
"@foundry-rs/forge-win32-amd64": "1.3.2"
2727
},
2828
"publishConfig": {
2929
"access": "public",
30+
"provenance": true,
3031
"registry": "https://registry.npmjs.org"
3132
},
3233
"license": "MIT OR Apache-2.0",

npm/README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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`.

npm/env.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ interface ImportMetaEnv {
55

66
readonly NODE_ENV: 'development' | 'production'
77

8+
readonly PROVENANCE: 'true' | 'false'
9+
810
// release.yml#jobs:release:strategy:matrix:include:-|target
911
readonly TARGET:
1012
| 'x86_64-unknown-linux-gnu'

npm/scripts/publish.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ async function packPackage(packagePath: string) {
8888
}
8989

9090
async function publishPackage(packagePath: string, packedFile: string) {
91-
const result = await Bun.$`npm publish ./${packedFile} --access=public --registry=${REGISTRY_URL}`
91+
const result = await Bun.$`npm publish ./${packedFile} --access=public --registry=${REGISTRY_URL} --provenance=${
92+
Bun.env.PROVENANCE || 'false'
93+
}`
9294
.cwd(packagePath)
9395
.nothrow()
9496

npm/scripts/setup-local.sh

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,39 @@
11
#!/usr/bin/env bash
22

3-
set -eou pipefail
3+
set -euo pipefail
44

5-
# build
6-
npm run build
5+
REGISTRY_URL="${NPM_REGISTRY_URL:-http://localhost:4873}"
6+
export NPM_REGISTRY_URL="$REGISTRY_URL"
7+
export NPM_TOKEN="${NPM_TOKEN:-localtesttoken}"
78

8-
# unpublish
9-
npm unpublish @foundry-rs/forge --registry http://localhost:4873 --force || true
10-
npm unpublish @foundry-rs/forge-darwin-arm64 --registry http://localhost:4873 --force || true
9+
bun run build
1110

12-
# publish
11+
# create user if not exists
12+
me=$(npm whoami --registry "$REGISTRY_URL")
13+
if [ -z "$me" ]; then
14+
echo "Not logged in or no user. Please run 'npm adduser --registry $REGISTRY_URL --scope=@foundry-rs' to create a user."
15+
exit 1
16+
fi
17+
18+
# determine arch and platform
19+
ARCH=$(uname -m | awk '{print tolower($0)}')
20+
if [ "$ARCH" = "aarch64" ]; then
21+
ARCH="arm64"
22+
fi
23+
if [ "$ARCH" = "x86_64" ]; then
24+
ARCH="amd64"
25+
fi
26+
PLATFORM=$(uname -s | awk '{print tolower($0)}')
27+
FORGE_PACKAGE_NAME="@foundry-rs/forge-${PLATFORM}-${ARCH}"
28+
echo "FORGE_PACKAGE_NAME: $FORGE_PACKAGE_NAME"
29+
30+
31+
echo "Unpublishing from $REGISTRY_URL (if present)" >&2
32+
npm unpublish @foundry-rs/forge --registry "$REGISTRY_URL" --force || true
33+
npm unpublish "$FORGE_PACKAGE_NAME" --registry "$REGISTRY_URL" --force || true
34+
35+
echo "Publishing to $REGISTRY_URL" >&2
36+
# Publish platform packages first
37+
bun scripts/publish.ts "$FORGE_PACKAGE_NAME"
38+
# Publish meta package last so optionalDependencies point to the same version
1339
bun scripts/publish.ts @foundry-rs/forge
14-
bun scripts/publish.ts @foundry-rs/forge-darwin-arm64

npm/src/const.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import type * as Process from 'node:process'
22

33
export function getRegistryUrl() {
4-
if (process.env.NODE_ENV !== 'production') return process.env.REGISTRY_URL ?? 'https://registry.npmjs.org'
5-
6-
return 'https://registry.npmjs.org'
4+
// Prefer npm's configured registry (works with Verdaccio and custom registries)
5+
// Fallback to REGISTRY_URL for tests/dev, then npmjs
6+
return (
7+
process.env.npm_config_registry
8+
|| process.env.REGISTRY_URL
9+
|| 'https://registry.npmjs.org'
10+
)
711
}
812

913
export type Architecture = Extract<(typeof Process)['arch'], 'arm64' | 'x64'>
@@ -30,8 +34,7 @@ export const BINARY_DISTRIBUTION_PACKAGES = {
3034
arm64: '@foundry-rs/forge-linux-arm64'
3135
},
3236
win32: {
33-
x64: '@foundry-rs/forge-win32-amd64',
34-
arm64: '@foundry-rs/forge-win32-arm64'
37+
x64: '@foundry-rs/forge-win32-amd64'
3538
}
3639
} as const
3740

npm/src/forge.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import * as NodeChildProcess from 'node:child_process'
22
import * as NodeFS from 'node:fs'
33
import * as NodeModule from 'node:module'
44
import * as NodePath from 'node:path'
5+
import { fileURLToPath } from 'node:url'
56
import { BINARY_NAME } from './const.js'
67

78
const require = NodeModule.createRequire(import.meta.url)
9+
const __dirname = NodePath.dirname(fileURLToPath(import.meta.url))
810

911
function getBinaryPath() {
1012
const { platform, arch } = process
@@ -39,14 +41,8 @@ function getBinaryPath() {
3941
const binaryPath = require.resolve(`${packageName}/bin/${binaryName}`)
4042
if (NodeFS.existsSync(binaryPath)) return binaryPath
4143
} catch (error) {
42-
return NodePath.join(
43-
import.meta.dirname,
44-
'..',
45-
'..',
46-
BINARY_NAME + '-' + process.platform + '-' + process.arch,
47-
'bin',
48-
BINARY_NAME
49-
)
44+
// Fall back to the binary written by postinstall into dist/
45+
return NodePath.join(__dirname, '..', 'dist', BINARY_NAME)
5046
}
5147

5248
console.error(`Platform-specific package ${packageName} not found.`)

0 commit comments

Comments
 (0)