Skip to content

Allow modules to be loaded from local directory #916

@tvanhens

Description

@tvanhens

🚀 Feature Request

Affected Languages

  • TypeScript or Javascript
  • Python
  • Java
  • .NET (C#, F#, ...)

General Information

  • JSII Version: n/a

  • Platform: n/a

  • I may be able to implement this feature request

  • This feature might incur a breaking change

Description

While building a JSii wrapper for a Clojure CDK API, I've come to realize that it is beneficial to rely on npm & node_modules for JSii libraries. The bundling of the Java JSii runtime with the maven CDK modules opens the door to dependency conflicts that can be avoided by relying directly on node_modules. Additionally, maven modules are hard to load dynamically into a JVM which makes it hard to dynamically work with CDK constructs.

Right now the JSii protocol only allows for archived modules to be loaded (from the classpath in the Java case). If the JSii protocol was expanded to allow modules to be loaded locally from a node_modules folder it would make it easier to enable more dynamic workflows in REPL-friendly languages.

Proposed Solution

I can see two plausible solutions - both non-breaking:

  1. Amend the load request to allow an optional boolean local argument. When this argument is supplied as true then modules are loaded from the local directory's node_modules folder. This would keep the surface area of the protocol largely unchanged and allows for a non-breaking change by falling back to the current behavior when the argument is not present.

  2. Add a new require request that would allow a local module to be loaded. This increases the surface area of the API but prevents decreasing the complexity of the load API request. The commonality that would be shared between require and load could be factored into shared private functions to prevent drift between the two APIs.

I'm happy to put together a PR for either of these solutions (or an alternative solution) if this change is desirable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions