Skip to content

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

brendandahl
Copy link

Directly import from an ES module following the ESM integration proposal.

e.g.

(import "./add-esmi-deps.mjs" "getValue" (func $getValue (result i32)))

This adds wabt as a dependency to build the test example and test case .wat file.

resolves #54

Directly import from an ES module following the ESM integration proposal.

e.g.
`(import "./add-esmi-deps.mjs" "getValue" (func $getValue (result i32)))`
Copy link

codecov bot commented Apr 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.69%. Comparing base (67a94a9) to head (69036f5).
Report is 23 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

imports.push(genImport(pkgImport, { name: "*", as: importName }));
} else if (fs.existsSync(path.resolve(directory, moduleName))) {
Copy link
Member

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)

Copy link
Author

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?

Copy link
Member

@pi0 pi0 Apr 11, 2025

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?

Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support ESM imports in Wasm
2 participants