Require.loadPackage accepts the following configuration options for
all packages in a fresh module system.
- makeLoader: the module loader maker, which by default depends on
whether the loader is running on a browser or on Node. On the
browser, it is a stack of
Require.MemoizedLoader, then either
config.definefor the config of the particular package.
- makeCompiler: the compiler maker for each package, which by
default is a stack of the
- lint: an optional event handler that accepts a
lintis used by
- read: an optional resource reader, a function that must accept a fully qualified URL and return a promise for the content of that resource as a string. The default reader depends on whether Montage Require is running in a browser or on Node.
Mr then adds shared state for all packages to the
- registry: the location of each known package by name, for those
packages that have either designated their own name, or been named
by a dependent package in the
mappingsproperties of their package description.
- getPackage: returns the
requirefunction for a package that has already been loaded, or throws an error.
- loadPackage: returns a memoized promise for the description of a package at a given location.
- descriptions: promises for each package description that is loading or has been loaded, by location.
- descriptionLocations: an object mapping package locations to the
locations of their package descriptions if an alternate is injected
Then, for each package, Mr creates a
prototypically inherits from the master
config and expands on that
configuration with details synthesized from the content of the package
package.json. This is the config that gets passed to
- location: the package's location directory, including a trailing slash.
- name: the name of this package, if it has one.
- packageDescription: the original package description, either
parsed from a
package.jsonor injected by
- define: true if this package uses script injection to load resources.
- modules: object mapping module descriptions by identifier
- lib: the root directory location where modules can be found, by
default the same as
- paths: a prioritized array of directories in which to search for
modules for this package, by default just the
libdirectory. It is inadvisable to give this array multiple entries on the client-side, and thus inadvisable for packages that might be used both client and server side. Really, just don't use this. It is used only by
PathsLoadersmiddleware to convert module identifiers to locations.
- mappings: object mapping module identifier prefixes to
dependencies. These dependencies are suitable for passing to
- packagesDirectory: the location in which to look for unknown
packages by name, by default
node_moduleswithin this package.
- exposedConfigs: an array of
makeRequireto copy those properties from
requirefunction, by default
Require.makeRequire(config), Mr uses
makeConfig with its own
config to produce
config.compile properties. The
config.load in particular is
distinct and used internally by
require.load, which memoizes and