Skip to content

Enhanced Node.js Modules Support

David Nolen edited this page Feb 10, 2017 · 2 revisions

The Problem

Node.js CommonJS module support still lacks deeper integration to make the experience truly seamless. Currently users must define a JS entry point first in order to include a CommonJS module into the build, direct requires of CommonJS modules is not supported. Even when this becomes possible this doesn't solve the problem of creating and packaging ClojureScript libraries that can express their dependencies on NPM modules.

Proposed Solution

Requiring CommonJS modules directly from a ClojureScript namespace

We should just index the top level of node_modules. When a users requires a Node.js CommonJS module we can then easily check that it exists. We should also track all such requires.

All these requires will themselves become the entry points that we pass to module-deps (we can just create a fake JS file with the necessary requires just so we can compute the dependency graph). The only questionable bit is that we might have to hook a bit into a Closure implementation detail in computing the module name so we generate the correct goog.require in the ClojureScript namespace.

Expressing NPM dependencies in deps.cljs

We can allow users to express their Node.js dependencies in deps.cljs. We can then provide a way to shell out to Node.js to ensure that these dependencies get installed. For example something like the following:

{
 ;;..
 :npm-deps {"react" "15.4.2"
            "object-assign" "4.1.1"}
 ;; ...
}

Known Issues

We need to handle dependency conflicts. We probably need to warn about conflicts. To remove conflicts users can provide :npm-deps directly to the compiler which overrides any versions defined via deps.cljs.

Clone this wiki locally