Modules

From CommonJS Spec Wiki
Jump to: navigation, search

STATUS: 1.1 RATIFIED

Modules

To date, client side JavaScript has generally been able to get away with something as simple as the <script> tag and no standard way to do namespaces. On the server, it's a bit different because you're more likely to use more libraries and you can potentially load up a lot of code. Having a basic system for loading code and encouraging the use of namespaces to avoid unintentional interference will underlie everything else.

Specifications

  • 1.0
  • 1.1 (1.0 + Module Meta-object Amendment).
  • 1.1.1 relaxes details for "main" and enumerability requirements.
    • version 1.1.1 will need spec tweaks and more work: there has been discussion/argument over the behaviour and formation of module.id, one side going for invariance based on path relative to search paths, the other going for absolute file path, since the top level id is dependent on the require.paths at the time of module load. There is also discussion about what we should and shouldn't allow as an argument to require, particularly about camelCase (which not many platforms mandate) and about file extensions.

Proposals

Several proposals were made. There was convergence toward the Securable Modules proposal, with several implementations passing the unit tests.

  1. Global File Loading
  2. Global Object Loading
  3. Pythonic Modules
  4. Securable Modules
  5. Declarative Modules proposal, introducing readable module definition format suitable for both server and browser.

There are also proposals for amendments and supplements to these proposals:

  1. Modules/Meta ratified and incorporated into Modules/1.1.
  2. Modules/Loaders for module loader specification proposals
  3. Modules/Transport for module transport format proposals (for a module format suitable for browser script injection)
  4. Modules/SetExports function for exporting something other than a plain object.
  5. Modules/Async/A proposes async loading.
  6. Modules/Metadata proposes JSON metadata.
  7. Modules/Resources proposes module-relative resource access.

We need proposals for:

  1. A module-relative "resource" object, like module.resource(path).open(…).
  2. To fix the module identifier domain. The current specification restricts module identifiers to camelCase delimited by slashes, but this is hazardous in case-insensitve stores, and not restricted in practice.
  3. A page for discussing a system for injecting free variables from the exports of a foreign module
  4. module.setExports(exports) exports Object

Prior Art

Related Discussions