fix(scripts): narrow napi targets instead of staging placeholder binaries - #1664
Conversation
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1664 +/- ##
==========================================
- Coverage 80.02% 80.01% -0.01%
==========================================
Files 464 464
Lines 80392 80392
Branches 80392 80392
==========================================
- Hits 64332 64325 -7
- Misses 13854 13860 +6
- Partials 2206 2207 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Wodann
left a comment
There was a problem hiding this comment.
Is there a fix for this problem that:
- doesn't duplicate the supported platform "triples" into this script; and
- keeps the verdaccio publish route as close as possible to the real publish script?
…ish_to_verdaccio.sh
0d0ca33 to
ee6be45
Compare
|
@Wodann I've pushed a different approach, which adds placeholders for missing binaries. This keeps the implementation closer to real publishing. |
2ddc413 to
501fd0a
Compare
501fd0a to
826cf07
Compare
…ries `@napi-rs/cli` >= 3.8 validates during pre-publish that every target in `napi.targets` has its .node binary staged, and `--skip-optional-publish` does not exempt them. There is no flag to skip that validation: `prePublish` loops over every target from `readNapiConfig` and calls `validateReleasePackageContents` unconditionally. Rather than staging empty placeholders for the platforms this host did not build, generate a config listing only this host's target and pass it via `--config-path`, so the other platforms are never considered. The target list is still derived from `napi.targets` (mapped to a platform package suffix with napi's exported `parseTriple`), so adding a platform needs no change here. Narrowing the targets also makes the `optionalDependencies` pruning loop redundant: `napi pre-publish` wires exactly the configured targets, so only this host's platform package is ever added. It leaves 2 tracked files modified rather than 8 — the full target list version-syncs all 7 `npm/*/package.json`, 6 of which are never published. The config is written by `scripts/write_napi_host_config.ts`, following the Hardhat repo's precedent of running TypeScript scripts directly with `node`. `scripts/package.json` marks that directory as ESM; the repo root cannot be `type: module` because `config/eslint/eslintrc.js` and `.syncpackrc.js` are CommonJS. `scripts/tsconfig.json` and the `tsc:scripts` / `test:scripts` entries give the directory the type-checking, formatting and test coverage Hardhat's scripts have. The tests cover the suffix-to-target lookup, the emitted config (including feeding it to napi's own `readNapiConfig`, which the approach depends on merging rather than replacing `package.json`'s `napi` field), the CLI's exit codes, and the invariant that `napi.targets` and `crates/edr_napi/npm/` stay in sync. `engines.node` moves to >=22.18.0, the first release where Node runs TypeScript without a flag. `scripts/prepublish.sh` now forwards its arguments to `napi pre-publish`; the release workflow passes none, so that path is unchanged.
826cf07 to
b9a65f4
Compare
Alternative: narrow
|
|
/bench |
|
🚀 Starting regression benchmark for |
|
✅ Regression benchmark passed for |
Fixes the
Regression benchmarkjob on main, broken since #1650 bumped@napi-rs/clito 3.8.6 (first surfaced on #1648's run, the first to actuallyexecute the job after the bump):
@napi-rs/cli>= 3.8 validates duringpre-publishthat every target innapi.targetshas its.nodebinary staged — unconditionally, regardless of--skip-optional-publish. #1650 fixed this for the release workflow by movingpnpm artifactsbeforeprepublish.sh, but the Verdaccio flow only everbuilds one binary, so validation fails on the first missing platform.
Fix: stage empty placeholder
.nodefiles for the platforms that weren'tbuilt, run
prepublish.shunmodified — sopre-publishsees the exact sameconfiguration as a real release — then delete the placeholders. They can never
be published:
prepublish.shpasses--skip-optional-publish, the script onlypublishes the host's platform package, and they're removed right after
pre-publishreturns. The existingoptionalDependenciesprune loop is keptunchanged. This avoids hardcoding the platform→triple mapping and keeps the
Verdaccio route as close as possible to the real publish flow.
Verified locally against
@napi-rs/cli3.8.6: without placeholders,pre-publishreproduces the exact CI error; with them it succeeds, and theresulting package state (versions,
optionalDependencies) is identical towhat the script produced before the CLI bump.