Skip to content

feat(p2-shim): migrate to typescript#1650

Merged
vados-cosmonic merged 5 commits into
bytecodealliance:mainfrom
eduardomourar:feat/preview2-shim-migrate-typescript
Jun 19, 2026
Merged

feat(p2-shim): migrate to typescript#1650
vados-cosmonic merged 5 commits into
bytecodealliance:mainfrom
eduardomourar:feat/preview2-shim-migrate-typescript

Conversation

@eduardomourar

@eduardomourar eduardomourar commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Related to #717.


Migrate preview2-shim to TypeScript

This PR completes the TypeScript migration for the @bytecodealliance/preview2-shim package.

Changes

Source Migration:

  • Migrated all source files from lib/ to src/ directory structure
  • Set up proper TypeScript compilation: src/ → dist/
  • Organized code into src/browser/, src/nodejs/, src/common/, src/io/, and src/synckit/

Test Migration:

  • Converted all test files to TypeScript (test/.js → test/.ts)
  • Added proper type annotations for test utilities and fixtures
  • Fixed type errors related to socket addresses, HTTP requests, bigint conversions, etc.

Type System Improvements:

  • Fixed AppendVersion type in instantiation.d.ts to correctly handle empty version strings
    • Before: wasi:random/random@ (incorrect)
    • After: wasi:random/random (correct)
  • Added type safety for WASI import objects
  • Proper typing for sandboxing configuration

Build Configuration:

  • Updated tsconfig.json to compile TypeScript sources
  • Separated source compilation from test type-checking
  • Vitest handles test file type-checking independently

Migration Strategy

Complex low-level files (IO workers, sockets, HTTP, filesystem) are still using any for now, allowing gradual type refinement in future PRs while ensuring the codebase compiles successfully.


Fixes #1596.

@eduardomourar eduardomourar force-pushed the feat/preview2-shim-migrate-typescript branch from 15de6b4 to 32b815f Compare June 17, 2026 03:03
@vados-cosmonic

Copy link
Copy Markdown
Collaborator

Hey @eduardomourar this is huge, thanks for taking on this work! Will dig in and review soon

@eduardomourar

Copy link
Copy Markdown
Contributor Author

I believe having this in TypeScript will help with any confusion between types and values being exported/exposed in the public API.

vados-cosmonic
vados-cosmonic previously approved these changes Jun 17, 2026

@vados-cosmonic vados-cosmonic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

This looks overall good to me -- just a few things to address/discuss (mostly nits) and we can get it in.

Comment thread packages/preview2-shim/.gitignore Outdated
Comment thread packages/preview2-shim/package.json Outdated
Comment thread packages/preview2-shim/src/browser/filesystem.ts
Comment thread packages/preview2-shim/src/browser/filesystem.ts Outdated
Comment thread packages/preview2-shim/src/browser/filesystem.ts
Comment thread packages/preview2-shim/src/io/worker-http.ts Outdated
Comment thread packages/preview2-shim/src/nodejs/http.ts Outdated
Comment thread packages/preview2-shim/test/test.ts
Comment thread packages/preview2-shim/package.json Outdated
@eduardomourar

Copy link
Copy Markdown
Contributor Author

@vados-cosmonic, all comments have been addressed. I was having some issues in the test/browser.ts file. The tests are all passing. There is a mismatch for options type while transpiling. I have removed some explicit options and the default behavior is in place for instantiation and wasi shim injection.

@vados-cosmonic

Copy link
Copy Markdown
Collaborator

Hey @eduardomourar thanks for the heads up -- I'll take a quick look!

Please feel free to mark all the conversations that you've addressed as resolved!

@eduardomourar eduardomourar force-pushed the feat/preview2-shim-migrate-typescript branch 7 times, most recently from 26e484e to 8ae7653 Compare June 18, 2026 11:50
@vados-cosmonic

Copy link
Copy Markdown
Collaborator

hey @eduardomourar sorry for the delay here -- I really will get to the bottom of the browser tests -- they're unfortunately really unergonomic to debug, trying to make get a jco release out and then will get to this and release p2-shim as well.

@eduardomourar

eduardomourar commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

I was able to get the other tests working, except the one for deno.

@vados-cosmonic

vados-cosmonic commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Oh that's fantastic!

Looking a the issues, it looks like something simple:

error: Module not found "file:///home/runner/work/jco/jco/node_modules/@bytecodealliance/preview2-shim/dist/nodejs/cli.js".
    at file:///home/runner/work/jco/jco/crates/jco/tests/virtualenvs/scratch.mjs:1:35

If I had to guess preview2-shim doesn't have the files array populated with dist ?

Nope it's there... wonder if it's getting a stale version somehow or because it's not installed

@eduardomourar

Copy link
Copy Markdown
Contributor Author

I think is because I changed to the new dist/ folder, but that does not exist on previously published version:

jco/package.json

Lines 17 to 19 in 3c64835

"devDependencies": {
"@actions/github": "^6.0.1",
"@bytecodealliance/preview2-shim": "0.17.9",

Let me know what you want me to do. Either I revert back that folder change for deno importmap or you merge it and include the new published version.

@vados-cosmonic

vados-cosmonic commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Yeah so it's weird because it's looking for the new code (so must be using the newer package.json), but somehow doesn't have the new package. If it was completely using the old package then it wouldn't be looking for dist in the first place, right?

I think the fix might be that we need to perform a build of preview2-shim during the test itself:

test-wasi-deno:

Do the deno tests fail locally?

Maybe I'm missing something here -- why would Deno take the newer package.json but be referring to an older release/the published version only? This is why I'm leaning towards it actually using the in-workspace version, but the built code jsut not being available @ dist in a fresh checkout in CI

@eduardomourar

eduardomourar commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

I already included the preview2-shim build to the test-wasi-deno, but it still fails. On my local machine, deno tests fail in the same way. Locally I see that the node_modules/@bytecodealliance/preview2-shim does have v0.17.9 (as pinned in the package.json file) which does not have a dist/ folder. I have reverted the path change for deno importmap. That can be put back after a new version is released and pinned in the root package.json file.

@eduardomourar eduardomourar force-pushed the feat/preview2-shim-migrate-typescript branch from 3b7d492 to 69cf55a Compare June 18, 2026 14:28
vados-cosmonic
vados-cosmonic previously approved these changes Jun 18, 2026
Comment thread .github/workflows/main.yml Outdated
@vados-cosmonic vados-cosmonic enabled auto-merge June 19, 2026 03:56
@vados-cosmonic vados-cosmonic added this pull request to the merge queue Jun 19, 2026
Merged via the queue into bytecodealliance:main with commit 3d15c81 Jun 19, 2026
46 checks passed
@eduardomourar eduardomourar deleted the feat/preview2-shim-migrate-typescript branch June 19, 2026 10:11
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.

[preview2-shim] Runtime values are exported only as types

2 participants