Repository navigation
fix(cli): preserve stricter node engine ranges in WASI package generation - #3201
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughcreate-npm-dirs now enforces a WASI minimum Node engine range using precise range-restriction logic instead of coarse major-version checks; helpers compute or inject a restricted Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@cli/src/api/create-npm-dirs.ts`:
- Around line 116-119: The current else branch on scopedPackageJson.engines
overwrites any existing engines object and drops sibling constraints; update the
logic that sets scopedPackageJson.engines (in create-npm-dirs) to preserve
existing engine keys and only set/override the node property to
minimumWasiNodeVersion, merging with any existing scopedPackageJson.engines
(e.g., if engines.npm exists keep it) instead of replacing the whole object.
- Around line 185-187: The exact-match branch returns exactMatch.value without
checking the injected floor; update the logic in the function handling
comparators (the code that finds exactMatch from comparators) to validate that
exactMatch.value satisfies the injected floor (>=14.0.0) and is compatible with
all other comparators before returning it — use the same semver utilities used
elsewhere (e.g., semver.satisfies or Range/intersects) to test exactMatch.value
against the floor and each comparator in comparators, and only return
exactMatch.value when all validations pass; otherwise continue processing or
reject the exact match.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b333771e-3cff-47f9-aa8a-6eb4eab207e0
📒 Files selected for processing (2)
cli/src/api/__tests__/create-npm-dirs.spec.tscli/src/api/create-npm-dirs.ts
037199e to
31f3512
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
cli/src/api/create-npm-dirs.ts (1)
199-227: Consider logging suppressed errors for debuggability.The range restriction logic is solid and correctly handles the various scenarios (preserving stricter ranges, applying the floor for broader ranges, intersecting mixed ranges). However, the silent catch block at lines 222-224 could mask unexpected errors during debugging.
💡 Optional: Add debug logging for suppressed errors
} catch { - // ignore + // Malformed range or unexpected error – fall back to minimum }Or if the
debugutility is appropriate here:- } catch { - // ignore + } catch (err) { + debug('Failed to restrict node engine range %s: %O', nodeRange, err) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@cli/src/api/create-npm-dirs.ts` around lines 199 - 227, The catch block in restrictWasiNodeEngine currently swallows exceptions silently; update the catch to log the caught error (including the error object and context string like "restrictWasiNodeEngine failed for nodeRange") using the project's logging utility (e.g., debug(...) or console.error(...)) so you still return minimumWasiNodeVersion on failure but preserve error details for debugging; modify the try/catch inside function restrictWasiNodeEngine to log the error before falling through to the final return.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@cli/src/api/create-npm-dirs.ts`:
- Around line 199-227: The catch block in restrictWasiNodeEngine currently
swallows exceptions silently; update the catch to log the caught error
(including the error object and context string like "restrictWasiNodeEngine
failed for nodeRange") using the project's logging utility (e.g., debug(...) or
console.error(...)) so you still return minimumWasiNodeVersion on failure but
preserve error details for debugging; modify the try/catch inside function
restrictWasiNodeEngine to log the error before falling through to the final
return.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 3cfb6157-712b-4a22-b4be-7ca7bb327e2d
📒 Files selected for processing (2)
cli/src/api/__tests__/create-npm-dirs.spec.tscli/src/api/create-npm-dirs.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- cli/src/api/tests/create-npm-dirs.spec.ts
31f3512 to
fdf153e
Compare
Fixes: #3200
Summary
This fixes a bug in
napi create-npm-dirsfor WASI targets where an existingpackage.json#engines.noderange could be silently weakened to>=14.0.0.The previous implementation used
semver.parse()to inspect the engine value. That works for exact versions, but returnsnullfor common valid ranges like>=18and^20.0.0. In those cases, the generatednpm/wasm32-wasi/package.jsonfell back to>=14.0.0, even when the source package had a stricter requirement.Changes
semver.parse().>=18.Summary by CodeRabbit
Tests
Refactor