Class NodeModulesProvider

  • All Implemented Interfaces:
    java.io.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:
    Serialized Form
    • Field Summary

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

        NOT_MODIFIED
    • Constructor Summary

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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected org.mozilla.javascript.commonjs.module.provider.ModuleSource loadFromUri​(java.net.URI uri, java.net.URI base, java.lang.Object validator)
      Do what Node.js's require(X) would do.
      • Methods inherited from class org.mozilla.javascript.commonjs.module.provider.UrlModuleSourceProvider

        entityNeedsRevalidation, 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 Detail

      • NodeModulesProvider

        public NodeModulesProvider​(java.lang.Iterable<java.net.URI> privilegedUris,
                                   java.lang.Iterable<java.net.URI> fallbackUris)
        Delegates to the super constructor.
    • Method Detail

      • loadFromUri

        protected org.mozilla.javascript.commonjs.module.provider.ModuleSource loadFromUri​(java.net.URI uri,
                                                                                           java.net.URI base,
                                                                                           java.lang.Object validator)
                                                                                    throws java.io.IOException,
                                                                                           java.net.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:
        java.io.IOException
        java.net.URISyntaxException