-
Notifications
You must be signed in to change notification settings - Fork 7
feat: support direct ESM imports in wasm #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Directly import from an ES module following the ESM integration proposal. e.g. `(import "./add-esmi-deps.mjs" "getValue" (func $getValue (result i32)))`
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #55 +/- ##
==========================================
- Coverage 90.80% 88.69% -2.11%
==========================================
Files 6 8 +2
Lines 500 336 -164
Branches 53 68 +15
==========================================
- Hits 454 298 -156
+ Misses 45 38 -7
+ Partials 1 0 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
src/plugin/runtime/imports.ts
Outdated
imports.push(genImport(pkgImport, { name: "*", as: importName })); | ||
} else if (fs.existsSync(path.resolve(directory, moduleName))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we could use esm resolution to support node_modules and import maps and also fail if ESM import in wasm cannot be resolved?
(we can use exsolve for this)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I'll switch to that.
There's currently the path where imports don't have to be resolved (e.g. resolved = false
). If we error out I think we'll break that. Do we want a mode where imports have to be resolved or is there some other way you are thinking we should implement that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use exsolve.resolve(id, { try: true }
. Is there a case that non resolvable ids might be safe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could have a non-resolved id and then supply it in the imports. e.g.
importObj = { 'someFile.js': { foo: ....} }
. I don't know how useful this feature is though. I'd prefer unwasm to error out if there's an unresolvable ESM import, but I think that will break the current behavior where resolving is optional.
Directly import from an ES module following the ESM integration proposal.
e.g.
This adds wabt as a dependency to build the test example and test case
.wat
file.resolves #54