Class NodeModulesProvider

java.lang.Object
org.mozilla.javascript.commonjs.module.provider.ModuleSourceProviderBase
org.mozilla.javascript.commonjs.module.provider.UrlModuleSourceProvider
helma.scripting.rhino.NodeModulesProvider
All Implemented Interfaces:
Serializable, org.mozilla.javascript.commonjs.module.provider.ModuleSourceProvider

public class NodeModulesProvider extends org.mozilla.javascript.commonjs.module.provider.UrlModuleSourceProvider
Bridges the gap between CommonJS-style module loading and Node.js-style module loading.
See Also:
  • Field Summary

    Fields inherited from interface org.mozilla.javascript.commonjs.module.provider.ModuleSourceProvider

    NOT_MODIFIED
  • Constructor Summary

    Constructors
    Constructor
    Description
    NodeModulesProvider(Iterable<URI> privilegedUris, Iterable<URI> fallbackUris)
    Delegates to the super constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected org.mozilla.javascript.commonjs.module.provider.ModuleSource
    loadFromUri(URI uri, URI base, Object validator)
    Do what Node.js's require(X) would do.

    Methods inherited from class org.mozilla.javascript.commonjs.module.provider.UrlModuleSourceProvider

    entityNeedsRevalidation, getCharacterEncoding, loadFromActualUri, loadFromFallbackLocations, loadFromPrivilegedLocations, onFailedClosingUrlConnection, openUrlConnection

    Methods inherited from class org.mozilla.javascript.commonjs.module.provider.ModuleSourceProviderBase

    loadSource, loadSource

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • NodeModulesProvider

      public NodeModulesProvider(Iterable<URI> privilegedUris, Iterable<URI> fallbackUris)
      Delegates to the super constructor.
  • Method Details

    • loadFromUri

      protected org.mozilla.javascript.commonjs.module.provider.ModuleSource loadFromUri(URI uri, URI base, Object validator) throws IOException, URISyntaxException
      Do what Node.js's require(X) would do. Case 1 is not supported, you will have to use modules from npmjs.org, re-implementing the core core module's functionality. We might want to use Nodeschnaps in the future. Case 2 is not supported, paths are always treated as relative paths within the application's "commonjs" directory. Case 5 additionally tries ModuleSourceProviderBase.loadSource(URI, URI, Object), even if it is very unlikely that something, which hasn't been tried yet, will be done. One could say we are just delegating throwing the error.
      Overrides:
      loadFromUri in class org.mozilla.javascript.commonjs.module.provider.UrlModuleSourceProvider
      Throws:
      IOException
      URISyntaxException