From CommonJS Spec Wiki
Jump to: navigation, search



This proposal adds the following on top of what is already specified by Modules/SecurableModules.

Module Context

  1. In a module, there must be a free variable "module", that is an Object.
    1. The "module" object must have a read-only, don't delete "id" property that is the top-level "id" of the module. The "id" property must be such that require( will return the exports object from which the originated. (That is to say can be passed to another module, and requiring that must return the original module).
    2. The "module" object may have a "uri" String that is the fully-qualified URI to the resource from which the module was created. The "uri" property must not exist in a sandbox.
  1. In a module, there is a free variable "require", that is a function.
    1. The "require" function may have a "main" property that is read-only, don't delete and represents the top-level "module" object of the program. If this property is provided, its must be referentially identical to the "module" object of the main program.
    2. The "require" function may have a "paths" attribute, that is a prioritized Array of path Strings, from high to low, of paths to top-level module directories.
      1. The "paths" property must not exist in "sandbox" (a secured module system).
      2. The "paths" attribute must be referentially identical in all modules.
      3. Replacing the "paths" object with an alternate object may have no affect.
      4. If the "paths" attribute exists, in-place modification of the contents of "paths" must be reflected by corresponding module search behavior.
      5. If the "paths" attribute exists, it may not be an exhaustive list of search paths, as the loader may internally look in other locations before or after the mentioned paths.
      6. If the "paths" attribute exists, it is the loader's prorogative to resolve, normalize, or canonicalize the paths provided.