Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Going back to requirejs 0.24 build tool for internal builds.
- Loading branch information
Jens Arps
committed
Sep 19, 2011
1 parent
7350d11
commit 13d1e19
Showing
446 changed files
with
48,068 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,58 @@ | |||
RequireJS is released under two licenses: new BSD, and MIT. You may pick the | |||
license that best suits your development needs. The text of both licenses are | |||
provided below. | |||
|
|||
|
|||
The "New" BSD License: | |||
---------------------- | |||
|
|||
Copyright (c) 2010-2011, The Dojo Foundation | |||
All rights reserved. | |||
|
|||
Redistribution and use in source and binary forms, with or without | |||
modification, are permitted provided that the following conditions are met: | |||
|
|||
* Redistributions of source code must retain the above copyright notice, this | |||
list of conditions and the following disclaimer. | |||
* Redistributions in binary form must reproduce the above copyright notice, | |||
this list of conditions and the following disclaimer in the documentation | |||
and/or other materials provided with the distribution. | |||
* Neither the name of the Dojo Foundation nor the names of its contributors | |||
may be used to endorse or promote products derived from this software | |||
without specific prior written permission. | |||
|
|||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE | |||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
|
|||
|
|||
|
|||
MIT License | |||
----------- | |||
|
|||
Copyright (c) 2010-2011, The Dojo Foundation | |||
|
|||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,17 @@ | |||
# RequireJS | |||
|
|||
RequireJS loads plain JavaScript files as well as more defined modules. It is optimized for in-browser use, including in [a Web Worker](requirejs/tree/master/docs/api.md#webworker), but it can be used in other JavaScript environments, like Rhino and [Node](requirejs/tree/master/docs/node.md). It implements the [Asynchronous Module](http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition) API. | |||
|
|||
RequireJS uses plain script tags to load modules/files, so it should allow for easy debugging. It can be used [simply to load existing JavaScript files](requirejs/tree/master/docs/api.md#jsfiles), so you can add it to your existing project without having to re-write your JavaScript files. | |||
|
|||
RequireJS includes [an optimization tool](requirejs/tree/master/docs/optimization.md) you can run as part of your packaging steps for deploying your code. The optimization tool can combine and minify your JavaScript files to allow for better performance. | |||
|
|||
If the JavaScript file defines a JavaScript module via [define()](requirejs/tree/master/docs/api.md#define), then there are other benefits RequireJS can offer: [better CommonJS support](requirejs/tree/master/docs/commonjs.md) and [loading multiple versions](requirejs/tree/master/docs/api.md#multiversion) of a module in a page. RequireJS also has a plugin system that supports features like [i18n string bundles](requirejs/tree/master/docs/api.md#i18n), and [text file dependencies](requirejs/tree/master/docs/api.md#text). | |||
|
|||
RequireJS does not have any dependencies on a JavaScript framework. It is dual-licensed -- new BSD or MIT. | |||
|
|||
The standard require.js file is around 5KB when minified via Closure Compiler and gzipped. | |||
|
|||
RequireJS works in IE 6+, Firefox 2+, Safari 3.2+, Chrome 3+, and Opera 10+. | |||
|
|||
Latest Release: [0.24.0](http://requirejs.org/docs/download.html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,45 @@ | |||
/** | |||
* @license Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved. | |||
* Available via the MIT or new BSD license. | |||
* see: http://github.com/jrburke/requirejs for details | |||
*/ | |||
|
|||
/* | |||
* This script will create the final r.js file used in node projects to use | |||
* RequireJS. | |||
* | |||
* This file uses Node to run: | |||
* node dist.js | |||
*/ | |||
|
|||
/*jslint strict: false */ | |||
/*global require: false */ | |||
|
|||
/** | |||
* Escapes a string so it is safe as a JS string | |||
* Taken from Dojo's buildUtil.jsEscape | |||
* @param {String} str | |||
* @returns {String} | |||
*/ | |||
function jsEscape(str) { | |||
return ('"' + str.replace(/(["\\])/g, '\\$1') + '"' | |||
).replace(/[\f]/g, '\\f' | |||
).replace(/[\b]/g, '\\b' | |||
).replace(/[\n]/g, '\\n' | |||
).replace(/[\t]/g, '\\t' | |||
).replace(/[\r]/g, '\\r'); // string | |||
} | |||
|
|||
var fs = require('fs'), | |||
contents = fs.readFileSync('../bin/x.js', 'utf8'), | |||
loadRegExp = /readFile\(requireBuildPath \+ '([\w\/\.]+)'\)/g; | |||
|
|||
//Inline file contents | |||
contents = contents.replace(loadRegExp, function (match, fileName) { | |||
return jsEscape(fs.readFileSync('../' + fileName, 'utf8')); | |||
}); | |||
|
|||
//Switch the behavior to "inlined mode" | |||
contents = contents.replace(/useRequireBuildPath \= true/, 'useRequireBuildPath = false'); | |||
|
|||
fs.writeFileSync('r.js', contents, 'utf8'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,77 @@ | |||
/** | |||
* @license RequireJS node Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved. | |||
* Available via the MIT or new BSD license. | |||
* see: http://github.com/jrburke/requirejs for details | |||
*/ | |||
|
|||
/*jslint regexp: false, strict: false */ | |||
/*global require: false, define: false, nodeRequire: true, process: false */ | |||
|
|||
/** | |||
* This adapter assumes that x.js has loaded it and set up | |||
* some variables. This adapter just allows limited RequireJS | |||
* usage from within the requirejs directory. The general | |||
* node adapater is r.js. | |||
*/ | |||
(function () { | |||
var req = nodeRequire, | |||
fs = req('fs'), | |||
path = req('path'), | |||
vm = req('vm'); | |||
|
|||
//Clear out the global set by x.js | |||
nodeRequire = null; | |||
|
|||
//Make nodeRequire available off of require, to allow a script to | |||
//add things to its require.paths for example. | |||
require.nodeRequire = req; | |||
|
|||
//Supply an implementation that allows synchronous get of a module. | |||
require.get = function (context, moduleName, relModuleMap) { | |||
if (moduleName === "require" || moduleName === "exports" || moduleName === "module") { | |||
require.onError(new Error("Explicit require of " + moduleName + " is not allowed.")); | |||
} | |||
|
|||
var ret, | |||
moduleMap = context.makeModuleMap(moduleName, relModuleMap); | |||
|
|||
//Normalize module name, if it contains . or .. | |||
moduleName = moduleMap.fullName; | |||
|
|||
if (moduleName in context.defined) { | |||
ret = context.defined[moduleName]; | |||
} else { | |||
if (ret === undefined) { | |||
//Try to dynamically fetch it. | |||
require.load(context, moduleName, moduleMap.url); | |||
//The above call is sync, so can do the next thing safely. | |||
ret = context.defined[moduleName]; | |||
} | |||
} | |||
|
|||
return ret; | |||
}; | |||
|
|||
require.load = function (context, moduleName, url) { | |||
var contents; | |||
|
|||
//isDone is used by require.ready() | |||
require.s.isDone = false; | |||
|
|||
//Indicate a the module is in process of loading. | |||
context.loaded[moduleName] = false; | |||
context.scriptCount += 1; | |||
|
|||
if (path.existsSync(url)) { | |||
contents = fs.readFileSync(url, 'utf8'); | |||
vm.runInThisContext(contents, url); | |||
} else { | |||
define(function () { | |||
return req(moduleName); | |||
}); | |||
} | |||
|
|||
//Support anonymous modules. | |||
context.completeLoad(moduleName); | |||
}; | |||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,26 @@ | |||
/** | |||
* @license RequireJS rhino Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved. | |||
* Available via the MIT or new BSD license. | |||
* see: http://github.com/jrburke/requirejs for details | |||
*/ | |||
|
|||
/*jslint strict: false */ | |||
/*global require: false, java: false, load: false */ | |||
|
|||
(function () { | |||
|
|||
require.load = function (context, moduleName, url) { | |||
//isDone is used by require.ready() | |||
require.s.isDone = false; | |||
|
|||
//Indicate a the module is in process of loading. | |||
context.loaded[moduleName] = false; | |||
context.scriptCount += 1; | |||
|
|||
load(url); | |||
|
|||
//Support anonymous modules. | |||
context.completeLoad(moduleName); | |||
}; | |||
|
|||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,49 @@ | |||
/** | |||
* @license RequireJS Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved. | |||
* Available via the MIT or new BSD license. | |||
* see: http://github.com/jrburke/requirejs for details | |||
*/ | |||
|
|||
/** | |||
* BUILD r.js IN THIS DIRECTORY FIRST BEFORE RUNNING THIS FILE | |||
* | |||
* To run in Node: | |||
* node ../r.js all.js | |||
* | |||
* To run in Rhino: | |||
* java -jar ../../build/lib/rhino/js.jar ../r.js all.js | |||
* Debug: | |||
* java -classpath ../../build/lib/rhino/js.jar org.mozilla.javascript.tools.debugger.Main ../r.js all.js | |||
*/ | |||
|
|||
/*jslint strict: false */ | |||
/*global require: false, doh: false */ | |||
|
|||
//Special global flag used by DOH. | |||
skipDohSetup = true; | |||
|
|||
require({ | |||
paths: { | |||
env: '../../build/jslib/env' | |||
} | |||
}, [ | |||
'alpha', | |||
'beta', | |||
'../../tests/doh/runner.js', | |||
'env!../../tests/doh/_{env}Runner.js' | |||
], function (alpha, beta) { | |||
|
|||
doh.register('rjsTests', | |||
[ | |||
function rjsTests(t) { | |||
t.is('alpha', alpha.name); | |||
t.is('beta', beta.name); | |||
t.is('betaSubName', beta.subName); | |||
} | |||
] | |||
); | |||
doh.run(); | |||
|
|||
//Print out the test summary. | |||
doh.run(); | |||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
define(function(require, exports) { | |||
exports.name = 'alpha'; | |||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,6 @@ | |||
define(['./sub/betaSub'], function (betaSub) { | |||
return { | |||
name: 'beta', | |||
subName: betaSub.name | |||
}; | |||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,37 @@ | |||
//Tested with nave, node 0.2.5, | |||
//npm install canvas | |||
//npm install express | |||
|
|||
/*jslint strict: false */ | |||
/*global require: false, console: false */ | |||
|
|||
var Canvas = require('canvas'), | |||
express = require('express'), | |||
canvas = new Canvas(200, 200), | |||
ctx = canvas.getContext('2d'), | |||
app = express.createServer(); | |||
|
|||
|
|||
app.configure(function () { | |||
|
|||
app.get('/', function (req, res) { | |||
res.send('hello world'); | |||
}); | |||
|
|||
app.use(express.gzip()); | |||
app.listen(3000); | |||
}); | |||
|
|||
|
|||
ctx.font = '30px Impact'; | |||
ctx.rotate(0.1); | |||
ctx.fillText("Awesome!", 50, 100); | |||
|
|||
var te = ctx.measureText('Awesome!'); | |||
ctx.strokeStyle = 'rgba(0,0,0,0.5)'; | |||
ctx.beginPath(); | |||
ctx.lineTo(50, 102); | |||
ctx.lineTo(50 + te.width, 102); | |||
ctx.stroke(); | |||
|
|||
console.log('<img src="' + canvas.toDataURL() + '" />'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
//The traditional nodejs http example | |||
|
|||
require(['sys', 'http'], function (sys, http) { | |||
http.createServer(function (req, res) { | |||
setTimeout(function () { | |||
res.writeHead(200, {'Content-Type': 'text/plain'}); | |||
res.end('Hello World\n'); | |||
}, 2000); | |||
}).listen(8000); | |||
sys.puts('Server running at http://127.0.0.1:8000/'); | |||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,6 @@ | |||
define(function (require) { | |||
var foo = require('../foo'); | |||
return { | |||
name: 'ALPHA' + foo.name | |||
}; | |||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,9 @@ | |||
<!DOCTYPE html> | |||
<html> | |||
<head> | |||
<title>Hello World</title> | |||
</head> | |||
<body> | |||
<h1>Hello World</h1> | |||
</body> | |||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
define({ | |||
name: 'foo' | |||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
//The traditional nodejs http example | |||
|
|||
require(['sys', 'foo', 'http', 'alpha/foo', 'text!alpha/hello.html'], function (sys, foo, http, alphaFoo, helloHtml) { | |||
http.createServer(function (req, res) { | |||
res.writeHead(200, {'Content-Type': 'text/plain'}); | |||
res.write('Hello ' + foo.name + '\nHello ' + alphaFoo.name + '\n'); | |||
res.write(helloHtml) | |||
res.end('\n'); | |||
}).listen(8000); | |||
sys.puts('Server running at http://127.0.0.1:8000/'); | |||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,10 @@ | |||
/* | |||
Run this file from a directory that is not the directory containing this file | |||
to see if the baseUrl of this file is used instead of the current directory. | |||
*/ | |||
|
|||
require(['alpha', 'beta'], function (alpha, beta) { | |||
console.log('alpha === ' + alpha.name); | |||
console.log('beta === ' + beta.name); | |||
console.log('betaSubName === ' + beta.subName); | |||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
define({ | |||
name: 'betaSubName' | |||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,6 @@ | |||
#!/bin/sh | |||
|
|||
# A command line tool to run some RequireJS scripts via Node | |||
|
|||
MYDIR=`cd \`dirname "$0"\`; pwd` | |||
node $MYDIR/x.js $MYDIR "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
set MYDIR=%~dp0 | |||
node %MYDIR%x.js %MYDIR% %* |
Oops, something went wrong.