Repository navigation
fix: ensure emnapi version is synced - #3151
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 ignored due to path filters (1)
📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughAdds runtime checks that ensure Changes
Sequence Diagram(s)sequenceDiagram
participant Builder as "Builder\n(setWasiEnv)"
participant FS as "Project\npackage.json (cwd)"
participant Emnapi as "Installed\nemnapi/package.json"
participant CreateDirs as "create-npm-dirs\n(generated package.json)"
rect rgba(100,150,240,0.5)
Builder->>Emnapi: read installed emnapi version
Builder->>FS: read project's `@emnapi/core` & `@emnapi/runtime` versions
end
alt versions match
rect rgba(100,200,120,0.5)
Builder->>Builder: compare versions (equal)
Builder->>CreateDirs: proceed, inject pinned deps into generated package.json
Builder->>Builder: set WASI env vars and link dir
end
else mismatch
rect rgba(240,100,100,0.5)
Builder->>Builder: detect mismatch
Builder-->>FS: throw Error("emnapi version mismatch")
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 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
🧹 Nitpick comments (1)
cli/src/api/__tests__/build.spec.ts (1)
255-262: Keep the fake emnapi modules' exports empty.Right now this test still passes if production code reads
require('@emnapi/core').versionfrom the module entrypoint, because the stubbedindex.jsexportsversion. Leaving the version only inpackage.jsonturns this into a real regression test.Suggested fix
await writeFile( join(pkgDir, 'index.js'), - `module.exports = { version: "${fakeVersion}" }`, + 'module.exports = {}', )🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@cli/src/api/__tests__/build.spec.ts` around lines 255 - 262, The test currently writes an index.js that exports version, which masks regressions; update the second writeFile call that writes join(pkgDir, 'index.js') so the module exports are empty (e.g., no version export or an empty module.exports) while keeping the package.json containing the fakeVersion; modify the write to create an empty export for the fake emnapi modules referenced by pkg and pkgDir so production code must read version from package.json rather than the module entrypoint.
🤖 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/package.json`:
- Around line 69-77: Update package.json peer dependency declarations so WASM
builds resolve correctly: in package.json's "peerDependencies" bump
"@emnapi/runtime" from ^1.7.1 to ^1.9.1 and add "@emnapi/core" (same major range
you expect) to "peerDependencies", and mark "@emnapi/core" as optional via
"peerDependenciesMeta" (e.g. "peerDependenciesMeta": {"@emnapi/core":
{"optional": true}}) so build.ts can resolve both `@emnapi/runtime` and
`@emnapi/core` from the consumer without package managers allowing incompatible
installs.
In `@cli/src/api/build.ts`:
- Around line 573-575: The code currently uses
projectRequire('@emnapi/core').version and
projectRequire('@emnapi/runtime').version and creates the require with
join(this.options.cwd, 'package.json'); change this to
createRequire(resolve(this.options.cwd, 'package.json')) (use resolve from
'path') and read the real package metadata by requiring the packages'
package.json files: projectRequire('@emnapi/core/package.json').version and
projectRequire('@emnapi/runtime/package.json').version so you get the installed
versions instead of undefined.
---
Nitpick comments:
In `@cli/src/api/__tests__/build.spec.ts`:
- Around line 255-262: The test currently writes an index.js that exports
version, which masks regressions; update the second writeFile call that writes
join(pkgDir, 'index.js') so the module exports are empty (e.g., no version
export or an empty module.exports) while keeping the package.json containing the
fakeVersion; modify the write to create an empty export for the fake emnapi
modules referenced by pkg and pkgDir so production code must read version from
package.json rather than the module entrypoint.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: acf5498b-d5be-4959-b327-e65e8614c2f0
⛔ Files ignored due to path filters (1)
yarn.lockis excluded by!**/yarn.lock,!**/*.lock
📒 Files selected for processing (7)
cli/package.jsoncli/src/api/__tests__/build.spec.tscli/src/api/__tests__/create-npm-dirs.spec.tscli/src/api/build.tscli/src/api/create-npm-dirs.tsexamples/napi/package.jsonwasm-runtime/package.json
A fix suggestion for toyobayashi/emnapi#202
Summary by CodeRabbit
New Features
Dependencies
Tests