Skip to content

Conversation

darvld
Copy link
Member

@darvld darvld commented Apr 18, 2024

Ready for review Powered by Pull Request Badge

Summary

Fixes the import issues in the testEmbeddedCjs and testEmbeddedEsm cases in the JsPluginTest suite, caused by an undocumented quirk of the module resolution algorithm (see below for full analysis). The following changes are enough to resolve the issue, note that this is not a bug, it could be considered a user error (albeit one caused by bad ux on our part).

  • Use a custom modulesPath configuration, to allow resolving dependencies from the bundle extracted into the guest layer of the VFS.
  • Update the hello.tar.gz embedded test bundle, moving its contents into an app directory, to ensure it is extracted as /app/node_modules/hello instead of /node_modules/hello.

Diagnostic

The hello.tar.gz test bundle contains a hello module which is used in the guest code under test:

val importResult = javascript(
"""
import { greet } from "hello"
export const returnValue = greet("Elide")
""",
esm = true,
)

The bundle is extracted to the root of the in-memory vfs layer, resulting in /node_modules/hello being the path to the module. But the default path for module search is ., which causes the GraalVM module resolver to look for ./node_modules/hello during the tests (e.g. /workspaces/elide/packages/graalvm/node_modules/hello), and fail since there is no such path.

This is not technically a bug, it is actually an inconsistency resulting from the way in which user bundles are extracted into the in-memory vfs layer. The solution in this case is to adjust the modulesPath configuration for the JS plugin and point it to the correct modules root for the in-memory layer (or the host layer, if the dependencies are located in the host FS):

Additionally, in the case of loading modules provided by an embedded bundle, special care must be taken to ensure that the target dependencies are never extracted at the root of the file system, for example, by wrapping the node_modules directory in another directory, yielding the path /app/node_modules instead of /node_modules when extracted. If the modules directory is placed in the root, it will not be recognized by GraalVM's default module loader regardless of the modulesPath configuration.

Recommendations

Given the very specific semantics of module resolution revealed by this issue, we should:

  1. Document this case as a potential pitfall in a visible location, to help users who face this problem.
  2. Fix the current ambiguity caused by the dual VFS layers present in the hybrid configuration, regarding the resolution of
    dependencies and paths in general, e.g. allowing users to specify the root path for extracting embedded bundles.

Fixes #790

Summary by CodeRabbit

  • Tests
    • Enhanced JavaScript plugin tests to include configuration for NPM module resolution paths.

@darvld darvld added module:graalvm Modules, changes, and issues relating to GraalVM javascript Features and issues relating to JS labels Apr 18, 2024
@darvld darvld self-assigned this Apr 18, 2024
@darvld darvld requested a review from sgammon as a code owner April 18, 2024 18:09
@coderabbitai
Copy link

coderabbitai bot commented Apr 18, 2024

Walkthrough

Walkthrough

The recent modifications in the JsPluginTest.kt file enhance the JavaScript plugin's handling of NPM module paths. By introducing a new function to update module resolution paths and adjusting existing tests, the changes aim to resolve issues with JavaScript imports highlighted in the linked issue.

Changes

File Path Change Summary
.../plugins/js/JsPluginTest.kt Added useModulePath function and updated testEmbeddedCjs and testEmbeddedEsm with new configurations.

Assessment against linked issues

Objective Addressed Explanation
Known issues with JS imports on main (#790) The addition of useModulePath and updates to test functions directly address the configuration issues related to JavaScript imports.

Poem

🐇🌟
In the burrow of code, under the moon's light,
A little rabbit tweaks the JS with delight.
Paths now clear, where modules lay,
Tests run smooth, errors kept at bay.
Hop, skip, a code merge dance,
In the digital fields, the bits advance. 🌿🚀


Recent Review Details

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 3138d14 and dd63945.
Files ignored due to path filters (1)
  • packages/graalvm/src/test/resources/hello-world/hello.tar.gz is excluded by !**/*.gz
Files selected for processing (1)
  • packages/graalvm/src/test/kotlin/elide/runtime/plugins/js/JsPluginTest.kt (5 hunks)
Additional comments not posted (3)
packages/graalvm/src/test/kotlin/elide/runtime/plugins/js/JsPluginTest.kt (3)

46-54: The implementation of useModulePath correctly sets the NPM module resolution path as intended.


94-95: The modification to testEmbeddedCjs correctly utilizes the useModulePath function to address the module path resolution issue.


112-113: The modification to testEmbeddedEsm correctly utilizes the useModulePath function to address the module path resolution issue.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sonarqubecloud
Copy link

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link
Member

@sgammon sgammon left a comment

Choose a reason for hiding this comment

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

Fantastic work and very well explained PR; a work of art

@sgammon sgammon merged commit 5995f16 into main Apr 18, 2024
@sgammon sgammon deleted the fix/js-imports branch April 18, 2024 18:42
@sgammon sgammon mentioned this pull request Apr 18, 2024
13 tasks
@sgammon sgammon mentioned this pull request Mar 11, 2025
64 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

javascript Features and issues relating to JS module:graalvm Modules, changes, and issues relating to GraalVM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Known issues with JS imports on main

2 participants