Skip to content
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

feat: synthetic modules #1227

Merged
merged 1 commit into from
Feb 24, 2025
Merged

feat: synthetic modules #1227

merged 1 commit into from
Feb 24, 2025

Conversation

sgammon
Copy link
Member

@sgammon sgammon commented Feb 23, 2025

Ready for review Powered by Pull Request Badge

Summary

Third revision of a dynamic ability to create synthetic JavaScript modules; the first two approaches proved brittle (bytecode hacks and an overridden JS language implementation, respectively). Instead, this approach involves forking and PR-ing up to GraalJs upstream with an actual proposed feature for JavaScript module import hooks.

Supersedes #1220.

Patch to GraalJs:

Changes

  • GraalJs - Module import hooks
    • Add JSModuleLoaderFactory interface, which can be implemented by consumers
    • Add method to install the module-loader-factory on JSEngine
    • Add JS context option for js.module-loader-factory, which can be either "default" or "handler"
    • Honor js.module-loader-factory when active
    • Make JSRealm call into JSEngine when lazily creating a JSModuleLoader
    • Considerations for CommonJS
  • Elide - Use new hooks
    • Install a "module import router" singleton when JS plugin is configured
    • Module registration and resolution (pull from v1/v2)
    • Convert compatible modules (for now, requires ProxyObject compat)
      • node:assert
      • node:path
      • node:os
      • node:zlib

Changelog

feat(graalvm-js): add new `graalvm-js` module for graaljs integration
feat(graalvm-js): initial structure and api for elide's import router
feat(graalvm-js): implement commonjs module loading support
feat(graalvm-js): implement esm module loading support
feat(graalvm-ts): move js realm patcher to `graalvm-js` module
feat(graalvm-ts): use new delegated module facilities
feat(graalvm): initialize javascript when plugin is added
feat(graalvm): enable `node:assert` for injection
feat(graalvm): enable `node:path` for injection
feat(graalvm): enable `node:zlib` for injection
feat(graalvm): enable `node:os` for injection
chore: reintroduce graalvm/graaljs modules and pins
chore: mark js realm patcher as deprecated
test: add test scripts for node paths

@sgammon sgammon added feature Large PRs or issues with full-blown features 🚧 WIP Works-in-progress. Blocks merge lang:javascript Issues relating to JavaScript labels Feb 23, 2025
@sgammon sgammon added this to the Release R7: Beta 1 milestone Feb 23, 2025
@sgammon sgammon self-assigned this Feb 23, 2025
@sgammon sgammon changed the title [WIP] feat(graalvm): synthetic modules (v3) [WIP] synthetic modules Feb 23, 2025
@sgammon sgammon changed the title [WIP] synthetic modules [WIP] feat: synthetic modules Feb 23, 2025
Copy link

codecov bot commented Feb 23, 2025

Codecov Report

Attention: Patch coverage is 17.44792% with 317 lines in your changes missing coverage. Please review.

Project coverage is 52.17%. Comparing base (64d9c28) to head (d06cae3).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...me/lang/javascript/ElideUniversalJsModuleLoader.kt 0.00% 216 Missing and 2 partials ⚠️
...main/kotlin/elide/runtime/gvm/loader/ModuleInfo.kt 0.00% 19 Missing ⚠️
...elide/runtime/lang/javascript/SyntheticJSModule.kt 0.00% 18 Missing ⚠️
.../kotlin/elide/runtime/gvm/loader/ModuleRegistry.kt 0.00% 14 Missing ⚠️
...ide/runtime/lang/javascript/ElideJsModuleRouter.kt 0.00% 11 Missing ⚠️
...e/lang/javascript/DelegatedModuleLoaderRegistry.kt 0.00% 10 Missing ⚠️
...ain/kotlin/elide/runtime/node/fs/NodeFilesystem.kt 33.33% 6 Missing ⚠️
...in/kotlin/elide/runtime/node/asserts/NodeAssert.kt 81.48% 5 Missing ⚠️
.../elide/runtime/lang/javascript/JSRealmPatcher.java 0.00% 3 Missing ⚠️
...de/runtime/lang/javascript/JavaScriptExtensions.kt 0.00% 3 Missing ⚠️
... and 6 more
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1227      +/-   ##
==========================================
- Coverage   53.16%   52.17%   -1.00%     
==========================================
  Files         429      435       +6     
  Lines       17244    17531     +287     
  Branches     3125     3136      +11     
==========================================
- Hits         9168     9147      -21     
- Misses       7058     7354     +296     
- Partials     1018     1030      +12     
Flag Coverage Δ
jvm 52.17% <17.44%> (-1.00%) ⬇️
lib 52.17% <17.44%> (-1.00%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...in/elide/runtime/plugins/AbstractLanguageConfig.kt 0.00% <ø> (ø)
...main/kotlin/elide/runtime/plugins/python/Python.kt 78.26% <ø> (ø)
...elide/runtime/gvm/internals/vfs/AbstractBaseVFS.kt 79.59% <100.00%> (ø)
...e/runtime/gvm/internals/vfs/AbstractDelegateVFS.kt 66.91% <ø> (ø)
.../runtime/gvm/internals/vfs/EmbeddedGuestVFSImpl.kt 68.94% <100.00%> (-1.62%) ⬇️
...tlin/elide/runtime/intrinsics/js/node/AssertAPI.kt 40.74% <ø> (-2.12%) ⬇️
...lide/runtime/node/childProcess/NodeChildProcess.kt 65.40% <100.00%> (-0.08%) ⬇️
...otlin/elide/runtime/node/os/NodeOperatingSystem.kt 84.52% <100.00%> (-0.68%) ⬇️
...rc/main/kotlin/elide/runtime/node/zlib/NodeZlib.kt 74.62% <100.00%> (-0.22%) ⬇️
...main/kotlin/elide/runtime/plugins/js/JavaScript.kt 85.59% <100.00%> (-7.54%) ⬇️
... and 16 more

... and 2 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 64d9c28...d06cae3. Read the comment docs.

@sgammon sgammon force-pushed the feat/synthesized-modules-v3 branch 4 times, most recently from 264fbca to 1397945 Compare February 23, 2025 23:09
@sgammon sgammon changed the title [WIP] feat: synthetic modules feat: synthetic modules Feb 24, 2025
@sgammon sgammon added api:node Node API and stdlib and removed 🚧 WIP Works-in-progress. Blocks merge labels Feb 24, 2025
@sgammon sgammon force-pushed the feat/synthesized-modules-v3 branch from 1397945 to 97ba819 Compare February 24, 2025 02:36
@sgammon sgammon marked this pull request as ready for review February 24, 2025 02:36
feat(graalvm-js): add new `graalvm-js` module for graaljs integration
feat(graalvm-js): initial structure and api for elide's import router
feat(graalvm-js): implement commonjs module loading support
feat(graalvm-js): implement esm module loading support
feat(graalvm-ts): move js realm patcher to `graalvm-js` module
feat(graalvm-ts): use new delegated module facilities
feat(graalvm): initialize javascript when plugin is added
feat(graalvm): enable `node:assert` for injection
feat(graalvm): enable `node:path` for injection
feat(graalvm): enable `node:zlib` for injection
feat(graalvm): enable `node:os` for injection
chore: reintroduce graalvm/graaljs modules and pins
chore: mark js realm patcher as deprecated
test: add test scripts for node paths

Signed-off-by: Sam Gammon <sam@elide.dev>
@sgammon sgammon merged commit adbbb99 into main Feb 24, 2025
22 checks passed
@sgammon sgammon deleted the feat/synthesized-modules-v3 branch February 24, 2025 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api:node Node API and stdlib feature Large PRs or issues with full-blown features lang:javascript Issues relating to JavaScript
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants