Manages loading of code assets and scripts as SystemJS modules. Exported as a singleton
instance to ensure 1:1 correspondence to the global SystemJS module loader.

All URLs that pass through SystemJS referring to either scripts or code assets are first
translated to a normalized form containing both the asset id and id of the containing asset pack.
This is necessary to resolve relative imports (import statements made from scripts or assets that
don't specify an asset pack). In that case, the only mechanism for determining the asset pack is to
examine the URL of the module which requested the import (the "parent", provided by SystemJS). By
first resolving to the normalized format, we guarantee that we can deterministically identify an
asset and its containing pack at any point within the module loader.

Scripts: script:///
example: script://86d4a79800fc48cb84f5e6076de60f9a.pack/079e18fbe88144edbf7d0ad10ac2d47e.script

Code assets: module:///
example: module://4c1a5a6c49594300a450cca975fd00d8.pack/e9e449f6e2e84972b27866cc5cfd3949.codeasset


new ModuleLoader()

Constructs a new ModuleLoader.





Clears all loaded code assets from the SystemJS registry.

_getModuleSource(url) → {Promise}

Returns a System.register module from the module registry for a given normalized asset URL.

Name Type Description
url string

The normalized asset URL.


Installs sumerian-specific extensions to the global SystemJS module loader, following the process
in the SystemJS documentation here:


  1. Replaces System.resolve with an implementation that bypasses URL validation for
    sumerian "module://" and "script://" URLs.
  2. Replaces System.instantiate with an implementation that resolves "module://" and "script://"
    imports to either user scripts, built-in sumerian API functionality, or code assets.

_packAndAssetFromUrl(url) → {Object}

Parses a module url and returns the pack and asset elements. The URL may either be in normalized
format or as it exists in a script or code asset.

ex: module://abcxyz.pack/defhij.codeasset -> { pack: abcxyz.pack, asset: defhij.codeasset }
ex: module:some_code_asset -> { pack: null, asset: some_code_asset }

Name Type Description
url string

The asset URL.

Name Type Description
pack string

The asset pack identifier, if one exists.

asset string

The asset identifier, if one exists.

_resolveUrl(url, parentUrl) → {Promise.<string>}

URL resolution function called by SystemJS after import() is called, but before module loading happens. This hook provides
the opportunity to modify the URL passed to import. This function is reponsible for normalizing URLs referring to code assets.

  1. If the URL refers to a script or built-in sumerian module, immediately resolve with the same URL. Script URLs are passed
    to import already in normalized form, and URLs referring to built-in sumerian functionality are not normalized.
  2. If the URL refers to a code asset, determine the containing asset pack by parsing it out of the URL, or if not present there,
    by examining the parent module's URL. Then use the module registry to convert the URL to the normalized format.
  3. If anything goes wrong, return a promise that rejects to indicate that the base SystemJS resolve should be called instead.
Name Type Description
url string

URL of the module that's loading.

parentUrl string

URL of the module that requested the load.

_toNormalizedModuleUrl(assetPackRef, assetRef) → {string}

Returns a normalized module URL for a given pack and asset reference.

Name Type Description
assetPackRef string

The pack reference.

assetRef string

The asset reference.

loadScript(scriptId, source) → {Promise}

Loads a script from source and returns the module.

Name Type Description
scriptId string

The asset identifier (i.e. "abcde.script") for the script.

source string

The source code for the script.