1
0
Fork 0

Merge branch 'devel' of https://github.com/triAGENS/ArangoDB into devel

This commit is contained in:
Heiko Kernbach 2013-02-26 18:30:54 +01:00
commit a96f99af36
113 changed files with 3239 additions and 194 deletions

View File

@ -80,6 +80,7 @@ SERVER_OPT := \
--javascript.action-directory @top_srcdir@/js/actions/system \
--javascript.gc-interval 1 \
--javascript.modules-path @top_srcdir@/js/server/modules:@top_srcdir@/js/common/modules \
--javascript.package-path @top_srcdir@/js/common/test-data/modules \
--javascript.startup-directory @top_srcdir@/js \
--ruby.action-directory @top_srcdir@/mr/actions/system \
--ruby.modules-path @top_srcdir@/mr/server/modules:@top_srcdir@/mr/common/modules \
@ -91,6 +92,7 @@ CLIENT_OPT := \
--configuration none \
--javascript.startup-directory @top_srcdir@/js \
--javascript.modules-path @top_srcdir@/js/client/modules:@top_srcdir@/js/common/modules \
--javascript.package-path @top_srcdir@/js/common/test-data/modules \
--no-colors \
--quiet
@ -206,7 +208,8 @@ endif
### @brief SHELL SERVER TESTS (BASICS)
################################################################################
SHELL_COMMON = @top_srcdir@/js/common/tests/shell-document.js \
SHELL_COMMON = @top_srcdir@/js/common/tests/shell-require.js \
@top_srcdir@/js/common/tests/shell-document.js \
@top_srcdir@/js/common/tests/shell-edge.js \
@top_srcdir@/js/common/tests/shell-database.js \
@top_srcdir@/js/common/tests/shell-collection.js \

View File

@ -169,6 +169,7 @@ ApplicationV8::ApplicationV8 (string const& binaryPath)
: ApplicationFeature("V8"),
_startupPath(),
_startupModules(),
_startupNodeModules(),
_actionPath(),
_useActions(true),
_performUpgrade(false),
@ -511,6 +512,7 @@ void ApplicationV8::setupOptions (map<string, basics::ProgramOptionsDescription>
("javascript.gc-frequency", &_gcFrequency, "JavaScript time-based garbage collection frequency (each x seconds)")
("javascript.action-directory", &_actionPath, "path to the JavaScript action directory")
("javascript.modules-path", &_startupModules, "one or more directories separated by (semi-) colons")
("javascript.package-path", &_startupNodeModules, "one or more directories separated by (semi-) colons")
("javascript.startup-directory", &_startupPath, "path to the directory containing alternate JavaScript startup scripts")
("javascript.v8-options", &_v8Options, "options to pass to v8")
;
@ -536,6 +538,10 @@ bool ApplicationV8::prepare () {
LOGGER_INFO("using JavaScript modules path '" << _startupModules << "'");
}
if (! _startupNodeModules.empty()) {
LOGGER_INFO("using Node modules path '" << _startupNodeModules << "'");
}
// set up the startup loader
if (_startupPath.empty()) {
LOGGER_FATAL_AND_EXIT("no 'javascript.startup-directory' has been supplied, giving up");
@ -678,7 +684,7 @@ bool ApplicationV8::prepareV8Instance (const size_t i) {
}
TRI_InitV8Conversions(context->_context);
TRI_InitV8Utils(context->_context, _startupModules);
TRI_InitV8Utils(context->_context, _startupModules, _startupNodeModules);
TRI_InitV8Shell(context->_context);
// set global flag before loading system files

View File

@ -357,6 +357,17 @@ namespace triagens {
string _startupModules;
////////////////////////////////////////////////////////////////////////////////
/// @brief semicolon separated list of module directories
///
/// @CMDOPT{\--javascript.package-path @CA{directory}}
///
/// Specifies the @CA{directory} path with user defined Node modules.
/// Multiple paths can be specified separated with commas.
////////////////////////////////////////////////////////////////////////////////
string _startupNodeModules;
////////////////////////////////////////////////////////////////////////////////
/// @brief path to the system action directory
///

View File

@ -109,6 +109,12 @@ static JSLoader StartupLoader;
static string StartupModules = "";
////////////////////////////////////////////////////////////////////////////////
/// @brief path for Node modules files
////////////////////////////////////////////////////////////////////////////////
static string StartupNodeModules = "";
////////////////////////////////////////////////////////////////////////////////
/// @brief path for JavaScript bootstrap files
////////////////////////////////////////////////////////////////////////////////
@ -427,6 +433,7 @@ static void ParseProgramOptions (int argc, char* argv[]) {
("javascript.execute", &ExecuteScripts, "execute Javascript code from file")
("javascript.check", &CheckScripts, "syntax check code Javascript code from file")
("javascript.modules-path", &StartupModules, "one or more directories separated by cola")
("javascript.package-path", &StartupNodeModules, "one or more directories separated by cola")
("javascript.startup-directory", &StartupPath, "startup paths containing the JavaScript files; multiple directories can be separated by cola")
("javascript.unit-tests", &UnitTests, "do not start as shell, run unit tests instead")
("jslint", &JsLint, "do not start as shell, run jslint instead")
@ -1395,7 +1402,7 @@ int main (int argc, char* argv[]) {
v8::FunctionTemplate::New(JS_PagerOutput)->GetFunction(),
v8::ReadOnly);
TRI_InitV8Utils(context, StartupModules);
TRI_InitV8Utils(context, StartupModules, StartupNodeModules);
TRI_InitV8Shell(context);
// reset the prompt error flag (will determine prompt colors)

View File

@ -2,7 +2,7 @@
/*global require, module, Module, FS_MOVE, FS_REMOVE, FS_EXISTS, FS_IS_DIRECTORY, FS_LIST_TREE,
SYS_EXECUTE, SYS_LOAD, SYS_LOG, SYS_LOG_LEVEL, SYS_MD5, SYS_OUTPUT, SYS_PROCESS_STAT, SYS_RAND,
SYS_READ, SYS_SPRINTF, SYS_TIME, SYS_START_PAGER, SYS_STOP_PAGER, SYS_SHA256, SYS_WAIT,
SYS_GETLINE, SYS_PARSE, SYS_SAVE, SYS_IMPORT_CSV_FILE, SYS_IMPORT_JSON_FILE,
SYS_GETLINE, SYS_PARSE, SYS_SAVE, SYS_IMPORT_CSV_FILE, SYS_IMPORT_JSON_FILE, PACKAGE_PATH,
SYS_PROCESS_CSV_FILE, SYS_PROCESS_JSON_FILE, ARANGO_QUIET, MODULES_PATH, COLORS, COLOR_OUTPUT,
COLOR_OUTPUT_RESET, COLOR_BRIGHT, COLOR_BLACK, COLOR_BOLD_BLACK, COLOR_BLINK, COLOR_BLUE,
COLOR_BOLD_BLUE, COLOR_BOLD_GREEN, COLOR_RED, COLOR_BOLD_RED, COLOR_GREEN, COLOR_WHITE,
@ -203,6 +203,17 @@
delete MODULES_PATH;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief node modules path
////////////////////////////////////////////////////////////////////////////////
internal.PACKAGE_PATH = "";
if (typeof PACKAGE_PATH !== "undefined") {
internal.PACKAGE_PATH = PACKAGE_PATH;
delete PACKAGE_PATH;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief quiet flag
////////////////////////////////////////////////////////////////////////////////
@ -823,63 +834,6 @@
return target;
};
////////////////////////////////////////////////////////////////////////////////
/// @brief reads a file from the module path or the database
////////////////////////////////////////////////////////////////////////////////
internal.loadDatabaseFile = function (path) {
var i;
var mc;
var n;
// try to load the file
var paths = internal.MODULES_PATH;
for (i = 0; i < paths.length; ++i) {
var p = paths[i];
if (p === "") {
n = "." + path + ".js";
}
else {
n = p + "/" + path + ".js";
}
if (internal.exists(n)) {
module.ModuleExistsCache[path] = true;
return { path : n, content : internal.read(n) };
}
}
// try to load the module from the database
if (internal.db !== undefined) {
mc = internal.db._collection("_modules");
if (mc !== null && typeof mc.firstExample === "function") {
n = mc.firstExample({ path: path });
if (n !== null) {
if (n.hasOwnProperty('content')) {
module.ModuleExistsCache[path] = true;
return { path : "_collection/" + path, content : n.content };
}
if (module.ModuleExistsCache.hasOwnProperty("/console")) {
var console = module.ModuleExistsCache["/console"];
console.error("found empty content in '%s'", JSON.stringify(n));
}
}
}
}
module.ModuleExistsCache[path] = false;
throw "cannot find a file named '"
+ path
+ "' using the module path(s) '"
+ internal.MODULES_PATH + "'";
};
////////////////////////////////////////////////////////////////////////////////
/// @brief loads a file from the file-system
////////////////////////////////////////////////////////////////////////////////
@ -929,7 +883,7 @@
mc = internal.db._create("_modules", { isSystem: true });
}
path = module.normalise(path);
path = module.normalize(path);
m = mc.firstExample({ path: path });
if (m === null) {

View File

@ -1,5 +1,5 @@
/*jslint indent: 2, nomen: true, maxlen: 100, sloppy: true, vars: true, white: true, plusplus: true */
/*global require, module: true */
/*global require, module: true, PACKAGE_PATH */
////////////////////////////////////////////////////////////////////////////////
/// @brief JavaScript server functions
@ -179,13 +179,71 @@ function stop_color_print () {
/// @brief module constructor
////////////////////////////////////////////////////////////////////////////////
function Module (id) {
this.id = id; // commonjs Module/1.1.1
this.exports = {}; // commonjs Module/1.1.1
function Module (id, type, pkg) {
this.id = id; // commonjs Module/1.1.1
this.exports = {}; // commonjs Module/1.1.1
this._normalized = {};
this._type = type; // module type: 'system', 'user'
this._origin = 'unknown'; // 'file:///{path}'
// 'database:///_document/{collection}/{key}'
this._package = pkg; // package to which this module belongs
}
////////////////////////////////////////////////////////////////////////////////
/// @brief package constructor
////////////////////////////////////////////////////////////////////////////////
function Package (id, description, parent, paths) {
var i;
this.id = id; // same of the corresponding module
this._description = description; // the package.json file
this._parent = parent; // parent package
this._moduleCache = {}; // module cache for package modules
this._paths = paths; // path to the package
}
var GlobalPackage = new Package("/", {name: "ArangoDB"}, undefined, PACKAGE_PATH);
Package.prototype.defineSystemModule = function (path) {
var result = this._moduleCache[path] = new Module(path, 'system', GlobalPackage);
return result;
};
Package.prototype.defineModule = function (path, module) {
this._moduleCache[path] = module;
return module;
};
Package.prototype.clearModule = function (path) {
delete this._moduleCache[path];
};
Package.prototype.module = function (path) {
if (this._moduleCache.hasOwnProperty(path)) {
return this._moduleCache[path];
}
return null;
};
Package.prototype.moduleNames = function () {
var name;
var names = [];
for (name in this._moduleCache) {
if (this._moduleCache.hasOwnProperty(name)) {
names.push(name);
}
}
return names;
};
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
@ -200,28 +258,21 @@ function stop_color_print () {
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief module cache
/// @brief global module cache
////////////////////////////////////////////////////////////////////////////////
var ModuleCache = {};
var ModuleExistsCache = {};
ModuleCache["/"] = new Module("/");
ModuleCache["/internal"] = new Module("/internal");
ModuleCache["/fs"] = new Module("/fs");
ModuleCache["/console"] = new Module("/console");
////////////////////////////////////////////////////////////////////////////////
/// @brief file exists cache
////////////////////////////////////////////////////////////////////////////////
Module.prototype.ModuleExistsCache = {};
GlobalPackage.defineSystemModule("/");
GlobalPackage.defineSystemModule("/internal");
GlobalPackage.defineSystemModule("/fs");
GlobalPackage.defineSystemModule("/console");
////////////////////////////////////////////////////////////////////////////////
/// @brief top-level-module
////////////////////////////////////////////////////////////////////////////////
Module.prototype.root = ModuleCache["/"];
module = Module.prototype.root;
module = Module.prototype.root = GlobalPackage.module("/");
////////////////////////////////////////////////////////////////////////////////
/// @}
@ -236,86 +287,24 @@ function stop_color_print () {
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief loads a file and creates a new module descriptor
////////////////////////////////////////////////////////////////////////////////
var internal = GlobalPackage.module("/internal").exports;
var console = GlobalPackage.module("/console").exports;
Module.prototype.require = function (unormalizedPath) {
var content;
var f;
var internal;
var module;
var path;
var paths;
var raw;
var sandbox;
internal = ModuleCache["/internal"].exports;
// check if you already know the module
if (this._normalized.hasOwnProperty(unormalizedPath)) {
return this._normalized[unormalizedPath];
}
// first get rid of any ".." and "."
path = this.normalise(unormalizedPath);
// check if you already know the module, return the exports
if (ModuleCache.hasOwnProperty(path)) {
module = ModuleCache[path];
this._normalized[unormalizedPath] = module.exports;
return module.exports;
}
// locate file and read content
raw = internal.loadDatabaseFile(path);
// test for parse errors first and fail early if a parse error detected
if (! internal.parse(raw.content, path)) {
throw "Javascript parse error in file '" + path + "'";
}
// create a new sandbox and execute
module = ModuleCache[path] = new Module(path);
content = "(function (module, exports, require, print) {"
+ raw.content
+ "\n});";
f = internal.execute(content, undefined, path);
if (f === undefined) {
throw "cannot create context function";
}
try {
f(module,
module.exports,
function(path) { return module.require(path); },
ModuleCache["/internal"].exports.print);
}
catch (err) {
delete ModuleCache[path];
throw "Javascript exception in file '" + path + "': " + err + " - " + err.stack;
}
this._normalized[unormalizedPath] = module.exports;
return module.exports;
};
internal.GlobalPackage = GlobalPackage;
////////////////////////////////////////////////////////////////////////////////
/// @brief returns true if require found a file
/// @brief normalizes a module name
///
/// If @FA{path} starts with "." or "..", then it is a relative path.
/// Otherwise it is an absolute path.
///
/// @FA{prefix} must not end in `/` unless it is equal to `"/"`.
///
/// The normalized name will start with a `/`, but not end in `/' unless it
/// is equal to `"/"`.
////////////////////////////////////////////////////////////////////////////////
Module.prototype.exists = function (path) {
return this.ModuleExistsCache[path];
};
////////////////////////////////////////////////////////////////////////////////
/// @brief normalises a path
////////////////////////////////////////////////////////////////////////////////
Module.prototype.normalise = function (path) {
internal.normalizeModuleName = function (prefix, path) {
var i;
var n;
var p;
@ -323,14 +312,14 @@ function stop_color_print () {
var x;
if (path === "") {
return this.id;
return prefix;
}
p = path.split('/');
// relative path
if (p[0] === "." || p[0] === "..") {
q = this.id.split('/');
q = prefix.split('/');
q.pop();
q = q.concat(p);
}
@ -348,7 +337,7 @@ function stop_color_print () {
if (x === "..") {
if (n.length === 0) {
throw "cannot cross module top";
throw "cannot use '..' to escape top-level-directory";
}
n.pop();
@ -361,6 +350,376 @@ function stop_color_print () {
return "/" + n.join('/');
};
////////////////////////////////////////////////////////////////////////////////
/// @brief reads a module package description file
////////////////////////////////////////////////////////////////////////////////
internal.loadPackageDescription = function (main, pkg) {
var paths;
var i;
paths = pkg._paths;
for (i = 0; i < paths.length; ++i) {
var p = paths[i];
var n;
var m;
if (p === "") {
m = "./node_modules" + main;
}
else if (p[p.length - 1] === '/') {
m = p + "node_modules" + main;
}
else {
m = p + "/node_modules" + main;
}
n = m + "/package.json";
if (internal.exists(n)) {
try {
var desc = JSON.parse(internal.read(n));
var mainfile = m + internal.normalizeModuleName("", desc.main) + ".js";
if (internal.exists(mainfile)) {
var content = internal.read(mainfile);
return { name: main,
description: desc,
packagePath: m,
path: 'file://' + mainfile,
content: content };
}
}
catch (err) {
if ('error' in console) {
console.error("cannot load package '%s': %s - %s", main, String(err), String(err.stack));
}
}
}
}
return null;
};
////////////////////////////////////////////////////////////////////////////////
/// @brief reads a file from the package path
////////////////////////////////////////////////////////////////////////////////
internal.loadPackageFile = function (main, pkg) {
var n;
var i;
var mc;
var paths;
paths = pkg._paths;
// -----------------------------------------------------------------------------
// normal modules, file based
// -----------------------------------------------------------------------------
// try to load the file
for (i = 0; i < paths.length; ++i) {
var p = paths[i];
if (p === "") {
n = "." + main + ".js";
}
else if (p[p.length - 1] === '/') {
n = p + main.substr(1) + ".js";
}
else {
n = p + main + ".js";
}
if (internal.exists(n)) {
return { name: main,
path: 'file://' + n,
content: internal.read(n) };
}
}
return null;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief reads a file from the module path or the database
////////////////////////////////////////////////////////////////////////////////
internal.loadModuleFile = function (main) {
var n;
var i;
var mc;
var paths;
paths = internal.MODULES_PATH;
// -----------------------------------------------------------------------------
// normal modules, file based
// -----------------------------------------------------------------------------
// try to load the file
for (i = 0; i < paths.length; ++i) {
var p = paths[i];
if (p === "") {
n = "." + main + ".js";
}
else if (p[p.length - 1] === '/') {
n = p + main.substr(1) + ".js";
}
else {
n = p + main + ".js";
}
if (internal.exists(n)) {
return { name: main,
path: 'file://' + n,
content: internal.read(n) };
}
}
// -----------------------------------------------------------------------------
// normal modules, database based
// -----------------------------------------------------------------------------
if (internal.db !== undefined) {
mc = internal.db._collection("_modules");
if (mc !== null && typeof mc.firstExample === "function") {
n = mc.firstExample({ path: main });
if (n !== null) {
if (n.hasOwnProperty('content')) {
return { name: main,
path: "database:///_document/" + n._id,
content: n.content };
}
if ('error' in console) {
console.error("found empty content in '%s'", JSON.stringify(n));
}
}
}
}
return null;
};
////////////////////////////////////////////////////////////////////////////////
/// @brief loads a module
////////////////////////////////////////////////////////////////////////////////
Module.prototype.createModule = function (description, type, pkg) {
var content;
var fun;
var module;
// mark that we have seen the definition, used for debugging only
ModuleExistsCache[description.name] = true;
// test for parse errors first and fail early if a parse error detected
if (! internal.parse(description.content)) {
throw "Javascript parse error in file '" + description.path + "'";
}
// create a new sandbox and execute
module = new Module(description.name, type, pkg);
module._origin = description.path;
pkg.defineModule(description.name, module);
// try to execute the module source code
content = "(function (module, exports, require, print) {"
+ description.content
+ "\n});";
fun = internal.execute(content, undefined, description.name);
if (fun === undefined) {
pkg.clearModule(description.name);
throw "cannot create context function";
}
try {
fun(module,
module.exports,
function(path) { return module.require(path); },
internal.print);
}
catch (err) {
pkg.clearModule(description.name);
throw "Javascript exception in file '" + description.name + "': " + err + " - " + err.stack;
}
return module;
};
////////////////////////////////////////////////////////////////////////////////
/// @brief loads a package
////////////////////////////////////////////////////////////////////////////////
Module.prototype.createPackage = function (parent, description) {
var path;
var module;
var pkg;
path = description.name;
pkg = new Package(path,
description.description,
parent,
[description.packagePath]);
module = this.createModule(description, 'package', pkg);
if (module !== null) {
parent.defineModule(path, module);
}
return module;
};
////////////////////////////////////////////////////////////////////////////////
/// @brief requires a package
////////////////////////////////////////////////////////////////////////////////
Module.prototype.requirePackage = function (unormalizedPath) {
var current;
var module;
var path;
// first get rid of any ".." and "."
path = this.normalize(unormalizedPath);
if (this._package.id === "/" && path === "/internal") {
return null;
}
// try to locate the package file starting with the current package
current = this._package;
while (current !== undefined) {
// check if already know a package with that name
module = current.module(path);
if (module !== null && module._type === 'package') {
return module;
}
var description = internal.loadPackageDescription(path, current);
if (description !== null) {
module = this.createPackage(current, description);
if (module !== null) {
return module;
}
}
current = current._parent;
}
return null;
};
////////////////////////////////////////////////////////////////////////////////
/// @brief requires a module
////////////////////////////////////////////////////////////////////////////////
Module.prototype.requireModule = function (unormalizedPath) {
var description;
var module;
var path;
// first get rid of any ".." and "."
path = this.normalize(unormalizedPath);
// check if already know a module with that name
module = this._package.module(path);
if (module) {
if (module.type !== 'package') {
return module;
}
else {
return null;
}
}
// first check: we are talking about module within a package
description = internal.loadPackageFile(path, this._package);
if (description !== null) {
module = this.createModule(description, 'module', this._package);
if (module !== null) {
this._package.defineModule(path, module);
return module;
}
}
// second check: we are talking about a global module
description = internal.loadModuleFile(path);
if (description !== null) {
module = this.createModule(description, 'module', GlobalPackage);
if (module !== null) {
this._package.defineModule(path, module);
return module;
}
}
return null;
};
////////////////////////////////////////////////////////////////////////////////
/// @brief loads a file and creates a new module descriptor
////////////////////////////////////////////////////////////////////////////////
Module.prototype.require = function (unormalizedPath) {
var module;
var path;
// check if path points to a package or a module in a package
module = this.requirePackage(unormalizedPath);
if (module !== null) {
return module.exports;
}
// try to load a global module into the current package
module = this.requireModule(unormalizedPath);
if (module !== null) {
return module.exports;
}
throw "cannot locate module '" + unormalizedPath + "'"
+ " for package '" + this._package.id + "'"
+ " using module path '" + internal.MODULES_PATH + "'"
+ " and package path '" + this._package._paths + "'";
};
////////////////////////////////////////////////////////////////////////////////
/// @brief returns true if require found a file
////////////////////////////////////////////////////////////////////////////////
Module.prototype.exists = function (path) {
return ModuleExistsCache[path];
};
////////////////////////////////////////////////////////////////////////////////
/// @brief normalizes a path
////////////////////////////////////////////////////////////////////////////////
Module.prototype.normalize = function (path) {
return internal.normalizeModuleName(this.id, path);
};
////////////////////////////////////////////////////////////////////////////////
/// @brief unloads module
////////////////////////////////////////////////////////////////////////////////
@ -370,13 +729,18 @@ function stop_color_print () {
return;
}
var norm = module.normalise(path);
var norm = module.normalize(path);
var m = GlobalPackage.module(norm);
if ( norm === "/"
|| norm === "/console"
|| norm === "/fs"
|| norm === "/internal"
|| norm === "/org/arangodb"
if (m === null) {
return;
}
if (m._type === 'system') {
return;
}
if ( norm === "/org/arangodb"
|| norm === "/org/arangodb/actions"
|| norm === "/org/arangodb/arango-collection"
|| norm === "/org/arangodb/arango-database"
@ -386,7 +750,7 @@ function stop_color_print () {
return;
}
delete ModuleCache[norm];
GlobalPackage.clearModule(norm);
};
////////////////////////////////////////////////////////////////////////////////
@ -395,18 +759,12 @@ function stop_color_print () {
Module.prototype.unloadAll = function () {
var i;
var path;
var unload = [];
var names;
for (path in ModuleCache) {
if (ModuleCache.hasOwnProperty(path)) {
unload.push(path);
ModuleCache[path]._normalized = {};
}
}
names = GlobalPackage.moduleNames();
for (i = 0; i < unload.length; ++i) {
this.unload(unload[i]);
for (i = 0; i < names.length; ++i) {
this.unload(names[i]);
}
};
@ -415,8 +773,35 @@ function stop_color_print () {
////////////////////////////////////////////////////////////////////////////////
Module.prototype._PRINT = function () {
var internal = require("internal");
internal.output('[module "' + this.id + '"]');
var parent = "";
if (this._package._parent !== undefined) {
parent = ', parent package "' + this._package._parent.id + '"';
}
internal.output('[module "' + this.id + '"'
+ ', type "' + this._type + '"'
+ ', package "' + this._package.id + '"'
+ parent
+ ', origin "' + this._origin + '"'
+ ']');
};
////////////////////////////////////////////////////////////////////////////////
/// @brief prints a package
////////////////////////////////////////////////////////////////////////////////
Package.prototype._PRINT = function () {
var parent = "";
if (this._parent !== undefined) {
parent = ', parent "' + this._package._parent.id + '"';
}
internal.output('[module "' + this.id + '"'
+ ', path "' + this._path + '"'
+ parent
+ ']');
};
////////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,7 @@
lib
_site
include
bin
src
.Python

View File

@ -0,0 +1 @@
The Official Specs for CommonJS

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,12 @@
import markdown
MARKDOWN_EXTENSIONS = ["def_list", "fenced_code", "codehilite", "tables"]
def extended_markdown(text):
if isinstance(text, str):
text = text.decode("utf8")
return markdown.markdown(text, extensions=MARKDOWN_EXTENSIONS,
output_format="html")
Config.transformers['markdown'] = extended_markdown

View File

@ -0,0 +1 @@
Config.transformers['noop'] = lambda source: source

View File

@ -0,0 +1,104 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>CommonJS: JavaScript Standard Library</title>
<link href="{{page.root}}css/styles.css" rel="stylesheet" type="text/css">
<link href="{{page.root}}css/colorful.css" rel="stylesheet" type="text/css">
<style type="text/css">
.content {
background-image: url({{page.root}}images/banner_home.jpg);
}
.news_wrapper {
margin-top: 152px;
}
.content-left {
margin-left: 42px;
margin-top: 180px;
}
{% if page.urlparts|first == "impl" %}
.nav2 {
background-image: url({{page.root}}images/nav_commonjs_on.png); /*turn on the corresponding nav item*/
}
.content-left h1 {
color: #4e5d2e; /*change the color of page headers*/
}
.content {
background-image: url({{page.root}}images/banner_green.jpg); /*change the color of the bg image*/
}
{% endif %}
{% if page.urlparts|first == "specs" %}
.nav1 {
background-image: url({{page.root}}images/nav_js_on.png); /*turn the corresponding nav item on*/
}
.content-left h1 {
color: #266790; /*change the color of the page headers*/
}
.content {
background-image: url({{page.root}}images/banner_blue.jpg); /*change the color of the bg image*/
}
{% endif %}
</style>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-125377-8']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script');
ga.src = ('https:' == document.location.protocol ?
'https://ssl' : 'http://www') +
'.google-analytics.com/ga.js';
ga.setAttribute('async', 'true');
document.documentElement.firstChild.appendChild(ga);
})();
</script>
</head>
<body>
<div class="header_wrapper">
<div class="header_bg">
<div class="nav_wrapper">
<div class="nav_div"></div>
<div class="nav_item nav2"><a href="{{page.root}}impl/index.html">get it</a></div>
<div class="nav_div"></div>
<div class="nav_item nav1"><a href="{{page.root}}specs/0.1.html">spec</a></div>
<div class="nav_div"></div>
</div>
<a href="{{page.root}}index.html"><img border="0" class="logo" src="{{page.root}}images/logo.png" width="200" height="53"></a>
<div class="tagline">javascript: not just for browsers any more!</div>
</div>
</div>
<div class="content_wrapper">
<div class="content_bg">
<div class="content">
<div class="content-left">
{{content}}
</div>
<div class="news_wrapper">
<div class="news-top">
<h1>Site Updates</h1>
</div>
<div class="news_items">
<ul>
<li>// Work is ongoing in fleshing out the content and bringing in new CommonJS 0.5 specs.</li>
<li>// Formatting has been cleaned up around the site and on the <a href="{{page.root}}specs/modules/1.0.html">Modules 1.0</a> page.</a>
</li>
</ul>
<br>
<br>
<h1>CommonJS Links</h1>
<ul>
<li>// <a href="http://wiki.commonjs.org/">Wiki</a> (standards-in-training!)</li>
<li>// <a href="http://groups.google.com/group/commonjs/">Mailing list</a></li>
<li>// <a href="http://twitter.com/commonjs">Twitter</a></li>
<li>// <a href="irc://irc.freenode.net/commonjs">#commonjs on irc.freenode.net</a></li>
</ul>
</div>
</div>
<div class="col_level">&nbsp;</div>
</div>
</div>
</div>
<div class="footer_wrapper">© Copyright 2009 Kevin Dangoor and many <a href="{{page.root}}contributors.html">CommonJS contributors</a>. <a href="{{page.root}}license.html">MIT license</a>.</div>
</body>
</html>

View File

@ -0,0 +1,35 @@
---
layout: default
title: CommonJS Contributors
---
The CommonJS Contributors
=========================
Creating the CommonJS APIs has been a volunteer effort, and the people below have contributed their time and energy to creating a consensus around these APIs. Without working through the details and making compromises, we would never have standardized anything or seen any implementations come into existence.
The following people have contributed substantially to the work of creating the CommonJS APIs:
* Ihab Awad
* Ash Berlin
* Aristid Breitkreuz
* Kevin Dangoor
* Daniel Friesen
* Wes Garland
* Kris Kowal
* Dean Landolt
* Peter Michaux
* George Moschovitis
* Michael O'Brien
* Tom Robinson
* Hannes Wallnoefer
* Mike Wilson
* Ondrej Zara
* Chris Zumbrunn
* Kris Zyp
My apologies to any contributor whose name was omitted. With thousands of messages of discussion during 2009, there are many people who have come and pitched in to the project with their ideas.
Additionally, thanks are due to all of the people who have been involved in building the implementations of the CommonJS APIs. Many of the people on the list above are implementers, but there are many other people involved in their projects and many other projects that are not represented here.
Thanks to you all for making this project a success!

View File

@ -0,0 +1,61 @@
.codehilite .hll { background-color: #ffffcc }
.codehilite .c { color: #808080 } /* Comment */
.codehilite .err { color: #F00000; background-color: #F0A0A0 } /* Error */
.codehilite .k { color: #008000; font-weight: bold } /* Keyword */
.codehilite .o { color: #303030 } /* Operator */
.codehilite .cm { color: #808080 } /* Comment.Multiline */
.codehilite .cp { color: #507090 } /* Comment.Preproc */
.codehilite .c1 { color: #808080 } /* Comment.Single */
.codehilite .cs { color: #cc0000; font-weight: bold } /* Comment.Special */
.codehilite .gd { color: #A00000 } /* Generic.Deleted */
.codehilite .ge { font-style: italic } /* Generic.Emph */
.codehilite .gr { color: #FF0000 } /* Generic.Error */
.codehilite .gh { color: #000080; font-weight: bold } /* Generic.Heading */
.codehilite .gi { color: #00A000 } /* Generic.Inserted */
.codehilite .go { color: #808080 } /* Generic.Output */
.codehilite .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */
.codehilite .gs { font-weight: bold } /* Generic.Strong */
.codehilite .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
.codehilite .gt { color: #0040D0 } /* Generic.Traceback */
.codehilite .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
.codehilite .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
.codehilite .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
.codehilite .kp { color: #003080; font-weight: bold } /* Keyword.Pseudo */
.codehilite .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
.codehilite .kt { color: #303090; font-weight: bold } /* Keyword.Type */
.codehilite .m { color: #6000E0; font-weight: bold } /* Literal.Number */
.codehilite .s { background-color: #fff0f0 } /* Literal.String */
.codehilite .na { color: #0000C0 } /* Name.Attribute */
.codehilite .nb { color: #007020 } /* Name.Builtin */
.codehilite .nc { color: #B00060; font-weight: bold } /* Name.Class */
.codehilite .no { color: #003060; font-weight: bold } /* Name.Constant */
.codehilite .nd { color: #505050; font-weight: bold } /* Name.Decorator */
.codehilite .ni { color: #800000; font-weight: bold } /* Name.Entity */
.codehilite .ne { color: #F00000; font-weight: bold } /* Name.Exception */
.codehilite .nf { color: #0060B0; font-weight: bold } /* Name.Function */
.codehilite .nl { color: #907000; font-weight: bold } /* Name.Label */
.codehilite .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */
.codehilite .nt { color: #007000 } /* Name.Tag */
.codehilite .nv { color: #906030 } /* Name.Variable */
.codehilite .ow { color: #000000; font-weight: bold } /* Operator.Word */
.codehilite .w { color: #bbbbbb } /* Text.Whitespace */
.codehilite .mf { color: #6000E0; font-weight: bold } /* Literal.Number.Float */
.codehilite .mh { color: #005080; font-weight: bold } /* Literal.Number.Hex */
.codehilite .mi { color: #0000D0; font-weight: bold } /* Literal.Number.Integer */
.codehilite .mo { color: #4000E0; font-weight: bold } /* Literal.Number.Oct */
.codehilite .sb { background-color: #fff0f0 } /* Literal.String.Backtick */
.codehilite .sc { color: #0040D0 } /* Literal.String.Char */
.codehilite .sd { color: #D04020 } /* Literal.String.Doc */
.codehilite .s2 { background-color: #fff0f0 } /* Literal.String.Double */
.codehilite .se { color: #606060; font-weight: bold; background-color: #fff0f0 } /* Literal.String.Escape */
.codehilite .sh { background-color: #fff0f0 } /* Literal.String.Heredoc */
.codehilite .si { background-color: #e0e0e0 } /* Literal.String.Interpol */
.codehilite .sx { color: #D02000; background-color: #fff0f0 } /* Literal.String.Other */
.codehilite .sr { color: #000000; background-color: #fff0ff } /* Literal.String.Regex */
.codehilite .s1 { background-color: #fff0f0 } /* Literal.String.Single */
.codehilite .ss { color: #A06000 } /* Literal.String.Symbol */
.codehilite .bp { color: #007020 } /* Name.Builtin.Pseudo */
.codehilite .vc { color: #306090 } /* Name.Variable.Class */
.codehilite .vg { color: #d07000; font-weight: bold } /* Name.Variable.Global */
.codehilite .vi { color: #3030B0 } /* Name.Variable.Instance */
.codehilite .il { color: #0000D0; font-weight: bold } /* Literal.Number.Integer.Long */

View File

@ -0,0 +1,62 @@
.codehilite .hll { background-color: #ffffcc }
.codehilite { background: #f8f8f8; }
.codehilite .c { color: #408080; font-style: italic } /* Comment */
.codehilite .err { border: 1px solid #FF0000 } /* Error */
.codehilite .k { color: #008000; font-weight: bold } /* Keyword */
.codehilite .o { color: #666666 } /* Operator */
.codehilite .cm { color: #408080; font-style: italic } /* Comment.Multiline */
.codehilite .cp { color: #BC7A00 } /* Comment.Preproc */
.codehilite .c1 { color: #408080; font-style: italic } /* Comment.Single */
.codehilite .cs { color: #408080; font-style: italic } /* Comment.Special */
.codehilite .gd { color: #A00000 } /* Generic.Deleted */
.codehilite .ge { font-style: italic } /* Generic.Emph */
.codehilite .gr { color: #FF0000 } /* Generic.Error */
.codehilite .gh { color: #000080; font-weight: bold } /* Generic.Heading */
.codehilite .gi { color: #00A000 } /* Generic.Inserted */
.codehilite .go { color: #808080 } /* Generic.Output */
.codehilite .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
.codehilite .gs { font-weight: bold } /* Generic.Strong */
.codehilite .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
.codehilite .gt { color: #0040D0 } /* Generic.Traceback */
.codehilite .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
.codehilite .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
.codehilite .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
.codehilite .kp { color: #008000 } /* Keyword.Pseudo */
.codehilite .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
.codehilite .kt { color: #B00040 } /* Keyword.Type */
.codehilite .m { color: #666666 } /* Literal.Number */
.codehilite .s { color: #BA2121 } /* Literal.String */
.codehilite .na { color: #7D9029 } /* Name.Attribute */
.codehilite .nb { color: #008000 } /* Name.Builtin */
.codehilite .nc { color: #0000FF; font-weight: bold } /* Name.Class */
.codehilite .no { color: #880000 } /* Name.Constant */
.codehilite .nd { color: #AA22FF } /* Name.Decorator */
.codehilite .ni { color: #999999; font-weight: bold } /* Name.Entity */
.codehilite .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
.codehilite .nf { color: #0000FF } /* Name.Function */
.codehilite .nl { color: #A0A000 } /* Name.Label */
.codehilite .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
.codehilite .nt { color: #008000; font-weight: bold } /* Name.Tag */
.codehilite .nv { color: #19177C } /* Name.Variable */
.codehilite .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
.codehilite .w { color: #bbbbbb } /* Text.Whitespace */
.codehilite .mf { color: #666666 } /* Literal.Number.Float */
.codehilite .mh { color: #666666 } /* Literal.Number.Hex */
.codehilite .mi { color: #666666 } /* Literal.Number.Integer */
.codehilite .mo { color: #666666 } /* Literal.Number.Oct */
.codehilite .sb { color: #BA2121 } /* Literal.String.Backtick */
.codehilite .sc { color: #BA2121 } /* Literal.String.Char */
.codehilite .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
.codehilite .s2 { color: #BA2121 } /* Literal.String.Double */
.codehilite .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
.codehilite .sh { color: #BA2121 } /* Literal.String.Heredoc */
.codehilite .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
.codehilite .sx { color: #008000 } /* Literal.String.Other */
.codehilite .sr { color: #BB6688 } /* Literal.String.Regex */
.codehilite .s1 { color: #BA2121 } /* Literal.String.Single */
.codehilite .ss { color: #19177C } /* Literal.String.Symbol */
.codehilite .bp { color: #008000 } /* Name.Builtin.Pseudo */
.codehilite .vc { color: #19177C } /* Name.Variable.Class */
.codehilite .vg { color: #19177C } /* Name.Variable.Global */
.codehilite .vi { color: #19177C } /* Name.Variable.Instance */
.codehilite .il { color: #666666 } /* Literal.Number.Integer.Long */

View File

@ -0,0 +1,209 @@
@charset "UTF-8";
body {
background-color: #3c3c3c;
font-family: Helvetica, Arial, sans-serif;
margin: 0px;
padding: 0px;
font-size: 14px;
line-height: 18px;
}
.col_level {
font-size: 0px;
clear: both;
height: 1px;
}
/* PAGE HEADER */
.header_wrapper {
height: 107px;
background-image: url(../images/header_wrapper_bg.png);
background-repeat: repeat-x;
}
.header_bg {
width: 970px;
margin-right: auto;
margin-left: auto;
height: 107px;
background-image: url(../images/header_gradient.jpg);
background-repeat: no-repeat;
background-position: center;
}
.tagline {
float: left;
margin-left: 15px;
line-height: 107px;
font-size: 18px;
color: #9f9f9f;
}
img.logo {
float: left;
margin-top: 24px;
margin-left: 0px;
}
.nav_wrapper {
float: right;
height: 107px;
}
.nav_item {
float: right;
width: 125px;
color: #FFFFFF;
text-align: center;
padding-top: 60px;
height: 47px;
font-size: 22px;
font-weight: normal;
}
.nav_item a:link, .nav_item a:visited {
color: #FFFFFF;
text-decoration: none;
}
.nav_item a:hover {
color: #CCCCCC;
}
.nav1 {
background-image: url(../images/nav_js.png);
background-repeat: repeat-x;
background-position: bottom;
}
.nav2 {
background-image: url(../images/nav_commonjs.png);
background-repeat: repeat-x;
background-position: bottom;
}
.nav3 {
background-image: url(../images/nav_browsers.png);
background-repeat: repeat-x;
background-position: bottom;
}
.nav_div {
float: right;
background-image: url(../images/nav_div.png);
width: 1px;
background-position: bottom;
height: 107px;
background-repeat: no-repeat;
}
/* PAGE BODY */
.content_wrapper {
background-image: url(../images/content-wrapper_bg.png);
background-repeat: repeat-x;
background-color: #efefef;
}
.content_bg {
width: 1000px;
margin-right: auto;
margin-left: auto;
background-image: url(../images/content_bg.png);
background-repeat: repeat-y;
}
.content {
position: relative;
background-image: url(../images/banner_gray.jpg);
background-repeat: no-repeat;
background-position: center 11px;
}
.content-left {
width: 680px;
margin-left: 60px;
float: left;
margin-top: 60px;
padding-bottom: 20px;
}
.content-left h1 {
font-size: 28px;
color: #863e3e;
font-weight: normal;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 6px;
margin-left: 0px;
}
/* NEWS */
.news_wrapper {
width: 219px;
right: 14px;
float: right;
margin-right: 27px;
margin-top: 70px;
font-size: 12px;
line-height: 13px;
}
.news-top {
background-image: url(../images/news_bg-top.png);
background-repeat: no-repeat;
height: 25px;
background-position: left top;
padding-left: 24px;
vertical-align: bottom;
padding-top: 20px;
}
.news_items {
background-image: url(../images/news_bg-btm.png);
background-repeat: no-repeat;
background-position: left bottom;
padding-left: 24px;
color: #9d9d9d;
padding-right: 12px;
}
.news_items ul {
list-style: none;
margin-left: 0;
padding-left: 1em;
text-indent: -.9em;
margin-top: 0px;
}
.news_items li {
margin-bottom: 8px;
margin-left: 8px;
}
.news_items a:link, .news_items a:visited {
color: #90d5ff;
text-decoration: none;
}
.news_items a:hover {
text-decoration: underline;
}
.news_wrapper h1 {
font-weight: normal;
font-size: 16px;
margin-bottom: 8px;
color: #636363;
margin-top: 0px;
}
/* PAGE FOOT */
.footer_wrapper {
font-size: 10px;
border-top-width: 10px;
border-top-style: solid;
border-top-color: #636363;
text-align: center;
padding-top: 10px;
padding-bottom: 10px;
color: #999999;
}
.footer_bg {
width: 970px;
margin-right: auto;
margin-left: auto;
}

View File

@ -0,0 +1,12 @@
---
layout: default
title: CommonJS Project History
---
CommonJS Project History
========================
* January 2009: the group was formed as "ServerJS" following a blog post on Kevin Dangoor's Blue Sky on Mars
* March 2009: the dust had settled around "securable modules" as the module style for the group. This is CommonJS API 0.1
* April 2009: CommonJS modules were shown off with several implementations at the first JSConf in Washington, DC.
* August 2009: The group name was formally changed to CommonJS to reflect the broader applicability of the APIs.

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 985 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 775 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 270 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 266 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 399 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 264 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 352 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 172 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 321 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 434 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 970 B

View File

@ -0,0 +1,10 @@
---
layout: default
Title: Get CommonJS
---
Getting CommonJS
================
There are several implementations of the CommonJS standard, and you can choose the one that fits what you're trying to do.

View File

@ -0,0 +1,45 @@
---
layout: default
title: CommonJS API
---
CommonJS
========
JavaScript is a powerful object oriented language with some of the fastest dynamic language interpreters around. The official JavaScript specification defines APIs for some objects that are useful for building browser-based applications. However, the spec does not define a standard library that is useful for building a broader range of applications.
The CommonJS API will fill that gap by defining APIs that handle many common application needs, ultimately providing a standard library as rich as those of Python, Ruby and Java. The intention is that an application developer will be able to write an application using the CommonJS APIs and then run that application across different JavaScript interpreters and host environments. With CommonJS-compliant systems, you can use JavaScript to write:
* Server-side JavaScript applications
* Command line tools
* Desktop GUI-based applications
* Hybrid applications (Titanium, Adobe AIR)
Read an [additional introduction by Kris Kowal at Ars Technica](http://arstechnica.com/web/news/2009/12/commonjs-effort-sets-javascript-on-path-for-world-domination.ars).
Current version: [0.1](specs/0.1.html)
In development: [0.5](specs/0.5.html)
Implementations
---------------
<table id="implementations" class="tablesorter">
<thead>
<tr><th>Project</th><th>API Version</th><th>Interpreter</tr>
</thead>
<tbody>
<tr><td><a href="impl/narwhal.html">Narwhal</a></td><td>0.1+</td><td><a href="interp/rhino.html">Rhino</a>, <a href="interp/mozilla.html">Mozilla</a></td></tr>
<tr><td><a href="impl/v8cgi.html">v8cgi</a></td><td>0.1+</td><td><a href="interp/v8.html">v8</a></td></tr>
<tr><td><a href="impl/helma.html">Helma</a></td><td>0.1+</td><td><a href="interp/rhino.html">Rhino</a></td></tr>
<tr><td><a href="impl/persevere.html">Persevere</a></td><td>0.1+</td><td><a href="interp/rhino.html">Rhino</a></td></tr>
<tr><td><a href="impl/gpsee.html">GPSEE</a></td><td>0.1+</td><td><a href="interp/spidermonkey.html">SpiderMonkey</a></td></tr>
<tr><td><a href="impl/flusspferd.html">Flusspferd</a></td><td>0.1+</td><td><a href="interp/spidermonkey.html">SpiderMonkey</a></td></tr>
<tr><td><a href="impl/monkeyscript.html">MonkeyScript</a></td><td>0.0</td><td><a href="interp/rhino.html">Rhino</a></td></tr>
</tbody>
</table>
More information about CommonJS
-------------------------------
* [Group Process](process.html)
* [Project History](history.html)

View File

@ -0,0 +1,32 @@
---
layout: default
title: License
---
CommonJS Documentation and Code License
=======================================
The output of the CommonJS group is protected under copyright laws, but is intended for the good of the JavaScript development community. CommonJS related projects are licensed under whatever terms the author(s) wish to apply, but the CommonJS specifications and test suites are all licensed under the MIT-style license presented below.
Copyright 2009 Kevin Dangoor and many <a href="{{page.root}}commonjs/contributors.html">CommonJS contributors</a>
License
-------
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -0,0 +1,34 @@
---
layout: default
title: CommonJS Process
---
CommonJS Process
================
The CommonJS group has, to date, operated in an informal manner. Our goal is to make meaningful progress toward these goals:
1. Design reasonable APIs for common application needs
2. Document those designs
3. Implement those designs in different interpreters and environments
The process followed through the development of CommonJS 0.5 has been:
1. Discussion of an API area is started on the mailing list
2. A page is created [on the wiki][wiki] to collect proposals and prior art
3. Further discussion and iteration on the proposals
4. A rough consensus is reached
5. The proposal graduates from the wiki to this website
So far, achieving rough consensus among the group has been a successful route to meeting these goals. Everyone involved has interoperability on their mind and interop necessarily involves compromise and minimal [bikeshedding][].
As applications built upon the CommonJS APIs start appearing, we will likely need more process to handle changes to the API.
Further reading
---------------
For an interesting take on API design from a highly regarded master, take a look at [this tech talk by Josh Bloch][bloch].
[wiki]: http://wiki.commonjs.org/ "CommonJS Wiki"
[bikeshedding]: http://en.wikipedia.org/wiki/Parkinson%27s_Law_of_Triviality "Parkinson's Law of Triviality"
[bloch]: http://www.youtube.com/watch?v=aAb7hSCtvGw "Josh Bloch on API design"

View File

@ -0,0 +1,13 @@
---
layout: default
title: CommonJS API 0.1
---
CommonJS API 0.1
================
As an initial step to allowing code re-use between JavaScript interpreters and libraries, we have defined a common module format:
* [Modules 1.0](modules/1.0.html)
This format has gained broad acceptance in the community and had several implementations which were demonstrated at JSConf 2009 in Washington DC.

View File

@ -0,0 +1,21 @@
---
layout: default
title: CommonJS API 0.5
---
CommonJS API 0.5
================
CommonJS 0.5 is currently being developed. It will enable a much broader range of applications to be developed an run seamlessly in different environments.
Here are the current specifications and discussions for 0.5:
* [Modules 1.0](modules/1.0.html)
* [Binary Data Type](http://wiki.commonjs.org/wiki/Binary)
* [Encodings](http://wiki.commonjs.org/wiki/Encodings)
* [I/O Streams](http://wiki.commonjs.org/wiki/IO)
* [Filesystem](http://wiki.commonjs.org/wiki/Filesystem)
* [System interface](http://wiki.commonjs.org/wiki/System)
* [Unit Testing](http://wiki.commonjs.org/wiki/Unit_Testing)
* [Sockets](http://wiki.commonjs.org/wiki/Sockets)

View File

@ -0,0 +1,74 @@
---
layout: default
title: CommonJS Modules 1.0
---
CommonJS Modules
================
This specification addresses how modules should be written in order to be interoperable among a class of module systems that can be both client and server side, secure or insecure, implemented today or supported by future systems with syntax extensions. These modules are offered privacy of their top scope, facility for importing singleton objects from other modules, and exporting their own API. By implication, this specification defines the minimum features that a module system must provide in order to support interoperable modules.
Contract
--------
### Module Context ###
1. In a module, there is a free variable "require", that is a function.
1. The "require" function accepts a module identifier.
2. "require" returns the exported API of the foreign module.
3. If there is a dependency cycle, the foreign module may not have finished executing at the time it is required by one of its transitive dependencies; in this case, the object returned by "require" must contain at least the exports that the foreign module has prepared before the call to require that led to the current module's execution.
4. If the requested module cannot be returned, "require" must throw an error.
2. In a module, there is a free variable called "exports", that is an object that the module may add its API to as it executes.
3. modules must use the "exports" object as the only means of exporting.
### Module Identifiers ###
1. A module identifier is a String of "terms" delimited by forward slashes.
2. A term must be a camelCase identifier, ".", or "..".
3. Module identifiers may not have file-name extensions like ".js".
4. Module identifiers may be "relative" or "top-level". A module identifier is "relative" if the first term is "." or "..".
5. Top-level identifiers are resolved off the conceptual module name space root.
6. Relative identifiers are resolved relative to the identifier of the module in which "require" is written and called.
### Unspecified ###
This specification leaves the following important points of interoperability unspecified:
1. Whether modules are stored with a database, file system, or factory functions, or are interchangeable with link libraries.
2. Whether a PATH is supported by the module loader for resolving module identifiers.
Sample Code
-----------
*math.js:*
:::js
exports.add = function() {
var sum = arguments[0];
for (var i=1; i < arguments.length; i++) {
sum += arguments[i];
}
return sum;
};
*increment.js:*
:::js
var add = require('math').add;
exports.increment = function(val) {
return add(val, 1);
};
*program.js:*
:::js
var inc = require('increment').increment;
var a = 1;
inc(a); // 2
Related Documents
-----------------
* Proposal to ECMA TC39: [Module System for ES-Harmony](http://docs.google.com/Doc?id=dfgxb7gk_34gpk37z9v&hl=en)
* Presentation to ECMA TC39: [Modules](http://docs.google.com/Presentation?docid=dcd8d5dk_0cs639jg8&hl=en)

View File

@ -0,0 +1,34 @@
import sys
from paver.easy import *
import paver.virtual
options(
virtualenv=Bunch(
packages_to_install=['pip'],
paver_command_line="initial"
)
)
@task
def initial():
"""Initial setup help."""
venv_command = "Scripts/activate.bat" if sys.platform == 'win32' \
else "source bin/activate"
print """This is the source for the CommonJS website.
You can build the website, by running these two commands (the
result will be in _site):
%s
paver build
""" % (venv_command)
@task
def build(options):
"""Builds the documentation."""
if not path("src/growl").exists():
sh("pip install -r requirements.txt")
sh("growl.py . ../_site", cwd="docs")

View File

@ -0,0 +1,4 @@
-e git://github.com/dangoor/growl.git#egg=growl
PyYAML
Jinja2
Markdown

View File

@ -0,0 +1 @@
exports.foo = function() {};

View File

@ -0,0 +1,5 @@
var test = require('test');
var a = require('submodule/a');
var b = require('b');
test.assert(a.foo().foo === b.foo, 'require works with absolute identifiers');
test.print('DONE', 'info');

View File

@ -0,0 +1,3 @@
exports.foo = function () {
return require('b');
};

View File

@ -0,0 +1,15 @@
exports.print = typeof print !== "undefined" ? print : function () {
var system = require("system");
var stdio = system.stdio;
stdio.print.apply(stdio, arguments);
};
exports.assert = function (guard, message) {
if (guard) {
exports.print('PASS ' + message, 'pass');
} else {
exports.print('FAIL ' + message, 'fail');
}
};

View File

@ -0,0 +1,4 @@
exports.a = function () {
return b;
};
var b = require('b');

View File

@ -0,0 +1,4 @@
var a = require('a');
exports.b = function () {
return a;
};

View File

@ -0,0 +1,10 @@
var test = require('test');
var a = require('a');
var b = require('b');
test.assert(a.a, 'a exists');
test.assert(b.b, 'b exists')
test.assert(a.a().b === b.b, 'a gets b');
test.assert(b.b().a === a.a, 'b gets a');
test.print('DONE', 'info');

View File

@ -0,0 +1,15 @@
exports.print = typeof print !== "undefined" ? print : function () {
var system = require("system");
var stdio = system.stdio;
stdio.print.apply(stdio, arguments);
};
exports.assert = function (guard, message) {
if (guard) {
exports.print('PASS ' + message, 'pass');
} else {
exports.print('FAIL ' + message, 'fail');
}
};

View File

@ -0,0 +1,3 @@
var test = require('test');
require('submodule/a');
test.print('DONE', 'info');

View File

@ -0,0 +1,9 @@
var test = require('test');
var pass = false;
var test = require('test');
try {
require('a');
} catch (exception) {
pass = true;
}
test.assert(pass, 'require does not fall back to relative modules when absolutes are not available.')

View File

@ -0,0 +1,15 @@
exports.print = typeof print !== "undefined" ? print : function () {
var system = require("system");
var stdio = system.stdio;
stdio.print.apply(stdio, arguments);
};
exports.assert = function (guard, message) {
if (guard) {
exports.print('PASS ' + message, 'pass');
} else {
exports.print('FAIL ' + message, 'fail');
}
};

View File

@ -0,0 +1,3 @@
exports.program = function () {
return require('program');
};

View File

@ -0,0 +1,4 @@
var test = require('test');
var a = require('a');
test.assert(a.program() === exports, 'exact exports');
test.print('DONE', 'info');

View File

@ -0,0 +1,15 @@
exports.print = typeof print !== "undefined" ? print : function () {
var system = require("system");
var stdio = system.stdio;
stdio.print.apply(stdio, arguments);
};
exports.assert = function (guard, message) {
if (guard) {
exports.print('PASS ' + message, 'pass');
} else {
exports.print('FAIL ' + message, 'fail');
}
};

View File

@ -0,0 +1,4 @@
var hasOwnProperty = require('hasOwnProperty');
var toString = require('toString');
var test = require('test');
test.print('DONE', 'info');

View File

@ -0,0 +1,15 @@
exports.print = typeof print !== "undefined" ? print : function () {
var system = require("system");
var stdio = system.stdio;
stdio.print.apply(stdio, arguments);
};
exports.assert = function (guard, message) {
if (guard) {
exports.print('PASS ' + message, 'pass');
} else {
exports.print('FAIL ' + message, 'fail');
}
};

View File

@ -0,0 +1,12 @@
exports.foo = function () {
return this;
};
exports.set = function (x) {
this.x = x;
};
exports.get = function () {
return this.x;
};
exports.getClosed = function () {
return exports.x;
};

View File

@ -0,0 +1,8 @@
var test = require('test');
var a = require('a');
var foo = a.foo;
test.assert(a.foo() == a, 'calling a module member');
test.assert(foo() == (function (){return this})(), 'members not implicitly bound');
a.set(10);
test.assert(a.get() == 10, 'get and set')
test.print('DONE', 'info');

View File

@ -0,0 +1,15 @@
exports.print = typeof print !== "undefined" ? print : function () {
var system = require("system");
var stdio = system.stdio;
stdio.print.apply(stdio, arguments);
};
exports.assert = function (guard, message) {
if (guard) {
exports.print('PASS ' + message, 'pass');
} else {
exports.print('FAIL ' + message, 'fail');
}
};

View File

@ -0,0 +1,8 @@
var test = require('test');
try {
require('bogus');
test.print('FAIL require throws error when module missing', 'fail');
} catch (exception) {
test.print('PASS require throws error when module missing', 'pass');
}
test.print('DONE', 'info');

View File

@ -0,0 +1,15 @@
exports.print = typeof print !== "undefined" ? print : function () {
var system = require("system");
var stdio = system.stdio;
stdio.print.apply(stdio, arguments);
};
exports.assert = function (guard, message) {
if (guard) {
exports.print('PASS ' + message, 'pass');
} else {
exports.print('FAIL ' + message, 'fail');
}
};

View File

@ -0,0 +1 @@
require('program').monkey = 10;

View File

@ -0,0 +1,4 @@
var a = require('a');
var test = require('test');
test.assert(exports.monkey == 10, 'monkeys permitted');
test.print('DONE', 'info');

View File

@ -0,0 +1,15 @@
exports.print = typeof print !== "undefined" ? print : function () {
var system = require("system");
var stdio = system.stdio;
stdio.print.apply(stdio, arguments);
};
exports.assert = function (guard, message) {
if (guard) {
exports.print('PASS ' + message, 'pass');
} else {
exports.print('FAIL ' + message, 'fail');
}
};

View File

@ -0,0 +1,3 @@
exports.foo = function () {
return 1;
};

View File

@ -0,0 +1,3 @@
var test = require('test');
test.assert(require('a/b/c/d').foo() == 1, 'nested module identifier');
test.print('DONE', 'info');

View File

@ -0,0 +1,15 @@
exports.print = typeof print !== "undefined" ? print : function () {
var system = require("system");
var stdio = system.stdio;
stdio.print.apply(stdio, arguments);
};
exports.assert = function (guard, message) {
if (guard) {
exports.print('PASS ' + message, 'pass');
} else {
exports.print('FAIL ' + message, 'fail');
}
};

View File

@ -0,0 +1,5 @@
var test = require('test');
var a = require('submodule/a');
var b = require('submodule/b');
test.assert(a.foo == b.foo, 'a and b share foo through a relative require');
test.print('DONE', 'info');

View File

@ -0,0 +1 @@
exports.foo = require('./b').foo;

View File

@ -0,0 +1,2 @@
exports.foo = function () {
};

View File

@ -0,0 +1,15 @@
exports.print = typeof print !== "undefined" ? print : function () {
var system = require("system");
var stdio = system.stdio;
stdio.print.apply(stdio, arguments);
};
exports.assert = function (guard, message) {
if (guard) {
exports.print('PASS ' + message, 'pass');
} else {
exports.print('FAIL ' + message, 'fail');
}
};

View File

@ -0,0 +1 @@
exports.foo = require('b').foo;

View File

@ -0,0 +1 @@
exports.foo = require('c').foo;

View File

@ -0,0 +1,3 @@
exports.foo = function () {
return 1;
};

View File

@ -0,0 +1,3 @@
var test = require('test');
test.assert(require('a').foo() == 1, 'transitive');
test.print('DONE', 'info');

View File

@ -0,0 +1,15 @@
exports.print = typeof print !== "undefined" ? print : function () {
var system = require("system");
var stdio = system.stdio;
stdio.print.apply(stdio, arguments);
};
exports.assert = function (guard, message) {
if (guard) {
exports.print('PASS ' + message, 'pass');
} else {
exports.print('FAIL ' + message, 'fail');
}
};

View File

@ -0,0 +1,162 @@
// From Node.js test/mjsunit/test-assert.js
// Felix Geisendörfer (felixge), backported from NodeJS
// Karl Guertin (greyrest), backported from NodeJS
// Kris Kowal (kriskowal), conversion to CommonJS
// strangely meta, no?
var assert = require('assert');
function makeBlock(f) {
var args = Array.prototype.slice.call(arguments,1);
return function(){
return f.apply(this, args);
}
}
exports['test AssertionError instanceof Error'] = function () {
assert.ok(new assert.AssertionError({}) instanceof Error);
};
exports['test ok false'] = function () {
assert['throws'](makeBlock(assert.ok, false), assert.AssertionError);
};
exports['test ok(true)'] = makeBlock(assert.ok, true);
exports['test ok("test")'] = makeBlock(assert.ok, "test");
exports['test equal true false'] = function () {
assert['throws'](makeBlock(assert.equal, true, false), assert.AssertionError, 'equal');
};
exports['test equal null null'] = makeBlock(assert.equal, null, null);
exports['test equal undefined undefined'] = makeBlock(assert.equal, undefined, undefined);
exports['test equal null undefined'] = makeBlock(assert.equal, null, undefined);
exports['test equal 2 "2"'] = makeBlock(assert.equal, 2, "2");
exports['test equal "2" 2'] = makeBlock(assert.equal, "2", 2);
exports['test equal true true'] = makeBlock(assert.equal, true, true);
exports['test notEqual true false'] = makeBlock(assert.notEqual, true, false);
exports['test notEqual true true'] = function () {
assert['throws'](makeBlock(assert.notEqual, true, true), assert.AssertionError, 'notEqual');
};
exports['test strictEqual 2 "2"'] = function () {
assert['throws'](makeBlock(assert.strictEqual, 2, "2"), assert.AssertionError, 'strictEqual');
};
exports['test strictEqual null undefined'] = function () {
assert['throws'](makeBlock(assert.strictEqual, null, undefined), assert.AssertionError, 'strictEqual');
};
exports['test notStrictEqual 2 "2"'] = makeBlock(assert.notStrictEqual, 2, "2");
//deepEquals
//7.2
exports['test 7.2 deepEqual date'] = makeBlock(assert.deepEqual, new Date(2000,3,14), new Date(2000,3,14));
exports['test 7.2 deepEqual date negative'] = function () {
assert['throws'](makeBlock(assert.deepEqual, new Date(), new Date(2000,3,14)), assert.AssertionError, 'deepEqual date');
};
//7.3
exports['test 7.3 deepEqual 4 "4"'] = makeBlock(assert.deepEqual, 4, "4");
exports['test 7.3 deepEqual "4" 4'] = makeBlock(assert.deepEqual, "4", 4);
exports['test 7.3 deepEqual true 1'] = makeBlock(assert.deepEqual, true, 1);
exports['test 7.3 deepEqual 4 "5"'] = function () {
assert['throws'](makeBlock(assert.deepEqual, 4, "5"));
};
//7.4
// having the same number of owned properties && the same set of keys
exports['test 7.4 deepEqual {a:4} {a:4}'] = makeBlock(assert.deepEqual, {a:4}, {a:4});
exports['test 7.4 deepEqual {a:4,b:"2"} {a:4,b:"2"}'] = makeBlock(assert.deepEqual, {a:4,b:"2"}, {a:4,b:"2"});
exports['test 7.4 deepEqual [4] ["4"]'] = makeBlock(assert.deepEqual, [4], ["4"]);
exports['test 7.4 deepEqual {a:4} {a:4,b:true}'] = function () {
assert['throws'](makeBlock(assert.deepEqual, {a:4}, {a:4,b:true}), assert.AssertionError);
};
exports['test deepEqual ["a"], {0:"a"}'] = makeBlock(assert.deepEqual, ["a"], {0:"a"});
//(although not necessarily the same order),
exports['test deepEqual {a:4,b:"1"} {b:"1",a:4}'] = makeBlock(assert.deepEqual, {a:4,b:"1"}, {b:"1",a:4});
exports['test deepEqual arrays with non-numeric properties'] = function () {
var a1 = [1,2,3];
var a2 = [1,2,3];
a1.a = "test";
a1.b = true;
a2.b = true;
a2.a = "test"
assert['throws'](makeBlock(assert.deepEqual, Object.keys(a1), Object.keys(a2)), assert.AssertionError);
makeBlock(assert.deepEqual, a1, a2);
};
exports['test deepEqual identical prototype'] = function () {
// having an identical prototype property
var nbRoot = {
toString: function(){return this.first+' '+this.last;}
}
var nameBuilder = function(first,last){
this.first = first;
this.last = last;
return this;
}
nameBuilder.prototype = nbRoot;
var nameBuilder2 = function(first,last){
this.first = first;
this.last = last;
return this;
}
nameBuilder2.prototype = nbRoot;
var nb1 = new nameBuilder('Ryan', 'Dahl');
var nb2 = new nameBuilder2('Ryan','Dahl');
assert.deepEqual(nb1, nb2);
nameBuilder2.prototype = Object;
nb2 = new nameBuilder2('Ryan','Dahl');
assert['throws'](makeBlock(assert.deepEqual, nb1, nb2), assert.AssertionError);
};
exports['test deepEqual "a" {}'] = function () {
assert['throws'](makeBlock(assert.deepEqual, 'a', {}), assert.AssertionError);
};
exports['test deepEqual "" ""'] = function () {
assert.deepEqual("", "");
};
exports['test deepEqual "" [""]'] = function () {
assert['throws'](makeBlock(assert.deepEqual, '', ['']), assert.AssertionError);
};
exports['test deepEqual [""] [""]'] = function () {
assert.deepEqual([""], [""]);
};
exports['test throw AssertionError'] = function () {
//Testing the throwing
function thrower(errorConstructor){
throw new errorConstructor('test');
}
var aethrow = makeBlock(thrower, assert.AssertionError);
var aethrow = makeBlock(thrower, assert.AssertionError);
//the basic calls work
assert['throws'](makeBlock(thrower, assert.AssertionError), assert.AssertionError, 'message');
assert['throws'](makeBlock(thrower, assert.AssertionError), assert.AssertionError);
assert['throws'](makeBlock(thrower, assert.AssertionError));
//if not passing an error, catch all.
assert['throws'](makeBlock(thrower, TypeError));
//when passing a type, only catch errors of the appropriate type
var threw = false;
try {
assert['throws'](makeBlock(thrower, TypeError), assert.AssertionError);
} catch (e) {
threw = true;
assert.ok(e instanceof TypeError, 'type');
}
assert.ok(threw, 'assert.throws with an explicit error is eating extra errors', assert.AssertionError);
threw = false;
};
if (module == require.main)
require("test").run(exports);

View File

@ -0,0 +1,5 @@
exports.version = "A 1.0.0";
exports.x = require("./x");
exports.B = require("TestB");
exports.C = require("TestC");
exports.D = require("TestD");

View File

@ -0,0 +1 @@
exports.version = "B 2.0.0";

Some files were not shown because too many files have changed in this diff Show More