Commit b4957e7d authored by Georges Khaznadar's avatar Georges Khaznadar

New upstream version 0.3.3+dfsg

parent 19e96314
{
"predef": [
"console"
],
"undef": true
}
tests
*.sh
.jshintrc
bower.json
.npmignore
.travis.yml
almond 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.
Copyright jQuery Foundation and other contributors, https://jquery.org/
This software consists of voluntary contributions made by many
individuals. For exact contribution history, see the revision history
available at https://github.com/requirejs/almond
The following license applies to all parts of this software except as
documented below:
====
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.
====
Copyright and related rights for sample code are waived via CC0. Sample
code is defined as all source code displayed within the prose of the
documentation.
CC0: http://creativecommons.org/publicdomain/zero/1.0/
====
Files located in the node_modules directory, and certain utilities used
to build or test the software in the test and dist directories, are
externally maintained libraries used by this software which have their own
licenses; we recommend you read them, as their terms may differ from the
terms above.
......@@ -14,7 +14,7 @@ almond is around **1 kilobyte** when minified with Closure Compiler and gzipped.
Since it can support certain types of loader plugin-optimized resources, it is a great
fit for a library that wants to use [text templates](http://requirejs.org/docs/api.html#text)
or [CoffeeScript](https://github.com/jrburke/require-cs) as part of
or [CoffeeScript](https://github.com/requirejs/require-cs) as part of
their project, but get a tiny download in one file after using the
[RequireJS Optimizer](http://requirejs.org/docs/optimization.html).
......@@ -49,20 +49,20 @@ What is supported:
* loader plugins that can inline their resources into optimized files, and
can access those inlined resources synchronously after the optimization pass.
The [text](http://requirejs.org/docs/api.html#text) and
[CoffeeScript](https://github.com/jrburke/require-cs) plugins are two such plugins.
[CoffeeScript](https://github.com/requirejs/require-cs) plugins are two such plugins.
## Download
[Latest release](https://github.com/jrburke/almond/raw/latest/almond.js)
[Latest release](https://github.com/requirejs/almond/raw/latest/almond.js)
## Usage
[Download the RequireJS optimizer](http://requirejs.org/docs/download.html#rjs).
[Download the current release of almond.js](https://github.com/jrburke/almond/raw/latest/almond.js).
[Download the current release of almond.js](https://github.com/requirejs/almond/raw/latest/almond.js).
Run the optimizer using [Node](http://nodejs.org) (also [works in Java](https://github.com/jrburke/r.js/blob/master/README.md)):
Run the optimizer using [Node](http://nodejs.org) (also [works in Java](https://github.com/requirejs/r.js/blob/master/README.md)):
node r.js -o baseUrl=. name=path/to/almond include=main out=main-built.js wrap=true
......@@ -79,7 +79,7 @@ wrap=true will add this wrapper around the main-built.js contents (which will be
If you do not want that wrapper, leave off the wrap=true argument.
These optimizer arguments can also be used in a build config object, so it can be used
in [runtime-generated server builds](https://github.com/jrburke/r.js/blob/master/build/tests/http/httpBuild.js).
in [runtime-generated server builds](https://github.com/requirejs/r.js/blob/master/build/tests/http/httpBuild.js).
## Triggering module execution <a name="execution"></a>
......@@ -169,6 +169,14 @@ After the build, then the built file should be structured like so:
* modules for your lib, including 'main'
* end.frag
## License
MIT
## Code of Conduct
[jQuery Foundation Code of Conduct](https://jquery.org/conduct/).
## Common errors
Explanations of common errors:
......@@ -229,8 +237,7 @@ modules from the network.
## How to get help
* Contact the [requirejs list](https://groups.google.com/group/requirejs).
* Open issues in the [issue tracker](https://github.com/jrburke/almond/issues).
* Open issues in the [issue tracker](https://github.com/requirejs/almond/issues).
## Contributing
......
/**
* @license almond 0.3.1 Copyright (c) 2011-2014, The Dojo Foundation All Rights Reserved.
* Available via the MIT or new BSD license.
* see: http://github.com/jrburke/almond for details
* @license almond 0.3.3 Copyright jQuery Foundation and other contributors.
* Released under MIT license, http://github.com/requirejs/almond/LICENSE
*/
//Going sloppy to avoid 'use strict' string cost, but strict practices should
//be followed.
/*jslint sloppy: true */
/*global setTimeout: false */
var requirejs, require, define;
......@@ -33,60 +31,58 @@ var requirejs, require, define;
*/
function normalize(name, baseName) {
var nameParts, nameSegment, mapValue, foundMap, lastIndex,
foundI, foundStarMap, starI, i, j, part,
foundI, foundStarMap, starI, i, j, part, normalizedBaseParts,
baseParts = baseName && baseName.split("/"),
map = config.map,
starMap = (map && map['*']) || {};
//Adjust any relative paths.
if (name && name.charAt(0) === ".") {
//If have a base name, try to normalize against it,
//otherwise, assume it is a top-level require that will
//be relative to baseUrl in the end.
if (baseName) {
name = name.split('/');
lastIndex = name.length - 1;
// Node .js allowance:
if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
}
if (name) {
name = name.split('/');
lastIndex = name.length - 1;
// If wanting node ID compatibility, strip .js from end
// of IDs. Have to do this here, and not in nameToUrl
// because node allows either .js or non .js to map
// to same file.
if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
}
//Lop off the last part of baseParts, so that . matches the
//"directory" and not name of the baseName's module. For instance,
//baseName of "one/two/three", maps to "one/two/three.js", but we
//want the directory, "one/two" for this normalization.
name = baseParts.slice(0, baseParts.length - 1).concat(name);
//start trimDots
for (i = 0; i < name.length; i += 1) {
part = name[i];
if (part === ".") {
name.splice(i, 1);
i -= 1;
} else if (part === "..") {
if (i === 1 && (name[2] === '..' || name[0] === '..')) {
//End of the line. Keep at least one non-dot
//path segment at the front so it can be mapped
//correctly to disk. Otherwise, there is likely
//no path mapping for a path starting with '..'.
//This can still fail, but catches the most reasonable
//uses of ..
break;
} else if (i > 0) {
name.splice(i - 1, 2);
i -= 2;
}
// Starts with a '.' so need the baseName
if (name[0].charAt(0) === '.' && baseParts) {
//Convert baseName to array, and lop off the last part,
//so that . matches that 'directory' and not name of the baseName's
//module. For instance, baseName of 'one/two/three', maps to
//'one/two/three.js', but we want the directory, 'one/two' for
//this normalization.
normalizedBaseParts = baseParts.slice(0, baseParts.length - 1);
name = normalizedBaseParts.concat(name);
}
//start trimDots
for (i = 0; i < name.length; i++) {
part = name[i];
if (part === '.') {
name.splice(i, 1);
i -= 1;
} else if (part === '..') {
// If at the start, or previous value is still ..,
// keep them so that when converted to a path it may
// still work when converted to a path, even though
// as an ID it is less than ideal. In larger point
// releases, may be better to just kick out an error.
if (i === 0 || (i === 1 && name[2] === '..') || name[i - 1] === '..') {
continue;
} else if (i > 0) {
name.splice(i - 1, 2);
i -= 2;
}
}
//end trimDots
name = name.join("/");
} else if (name.indexOf('./') === 0) {
// No baseName, so this is ID is resolved relative
// to baseUrl, pull off the leading dot.
name = name.substring(2);
}
//end trimDots
name = name.join('/');
}
//Apply map config if available.
......@@ -199,32 +195,39 @@ var requirejs, require, define;
return [prefix, name];
}
//Creates a parts array for a relName where first part is plugin ID,
//second part is resource ID. Assumes relName has already been normalized.
function makeRelParts(relName) {
return relName ? splitPrefix(relName) : [];
}
/**
* Makes a name map, normalizing the name, and using a plugin
* for normalization if necessary. Grabs a ref to plugin
* too, as an optimization.
*/
makeMap = function (name, relName) {
makeMap = function (name, relParts) {
var plugin,
parts = splitPrefix(name),
prefix = parts[0];
prefix = parts[0],
relResourceName = relParts[1];
name = parts[1];
if (prefix) {
prefix = normalize(prefix, relName);
prefix = normalize(prefix, relResourceName);
plugin = callDep(prefix);
}
//Normalize according
if (prefix) {
if (plugin && plugin.normalize) {
name = plugin.normalize(name, makeNormalize(relName));
name = plugin.normalize(name, makeNormalize(relResourceName));
} else {
name = normalize(name, relName);
name = normalize(name, relResourceName);
}
} else {
name = normalize(name, relName);
name = normalize(name, relResourceName);
parts = splitPrefix(name);
prefix = parts[0];
name = parts[1];
......@@ -271,13 +274,14 @@ var requirejs, require, define;
};
main = function (name, deps, callback, relName) {
var cjsModule, depName, ret, map, i,
var cjsModule, depName, ret, map, i, relParts,
args = [],
callbackType = typeof callback,
usingExports;
//Use name if no relName
relName = relName || name;
relParts = makeRelParts(relName);
//Call the callback to define the module, if necessary.
if (callbackType === 'undefined' || callbackType === 'function') {
......@@ -286,7 +290,7 @@ var requirejs, require, define;
//Default to [require, exports, module] if no deps
deps = !deps.length && callback.length ? ['require', 'exports', 'module'] : deps;
for (i = 0; i < deps.length; i += 1) {
map = makeMap(deps[i], relName);
map = makeMap(deps[i], relParts);
depName = map.f;
//Fast path CommonJS standard dependencies.
......@@ -342,7 +346,7 @@ var requirejs, require, define;
//deps arg is the module name, and second arg (if passed)
//is just the relName.
//Normalize module name, if it contains . or ..
return callDep(makeMap(deps, callback).f);
return callDep(makeMap(deps, makeRelParts(callback)).f);
} else if (!deps.splice) {
//deps is a config object, not an array.
config = deps;
......
{
"name": "almond",
"version": "0.3.1",
"license": [
"MIT"
],
"version": "0.3.3",
"main": "almond.js",
"ignore": [
".jshintrc",
"tests",
"shrinktest.sh"
]
......
{
"name": "almond",
"description": "A minimal AMD API implementation for use in optimized browser builds.",
"version": "0.3.1",
"homepage": "http://github.com/jrburke/almond",
"version": "0.3.3",
"homepage": "http://github.com/requirejs/almond",
"author": "James Burke <jrburke@gmail.com> (http://github.com/jrburke)",
"repository": {
"type": "git",
"url": "git://github.com/jrburke/almond.git"
"url": "git://github.com/requirejs/almond.git"
},
"licenses": [
{
"type": "BSD",
"url": "https://github.com/jrburke/almond/blob/master/LICENSE"
},
{
"type": "MIT",
"url": "https://github.com/jrburke/almond/blob/master/LICENSE"
}
],
"license": "MIT",
"main": "almond.js",
"engines": {
"node": ">=0.4.0"
......
......@@ -8,6 +8,7 @@ doh.registerUrl("mapConfigStarAdapter", "../mapConfig/mapConfigStarAdapter.html"
doh.registerUrl("mapConfigSpecificity", "../mapConfig/mapConfigSpecificity.html");
doh.registerUrl("mapConfigPlugin", "../mapConfig/mapConfigPlugin.html");
doh.registerUrl("plugins", "../plugins/plugins.html");
doh.registerUrl("pluginRelative", "../plugins/relative/pluginRelative.html");
doh.registerUrl("pluginsMapSameName", "../plugins/pluginMapSameName/pluginMapSameName.html");
doh.registerUrl("orderPlugin", "../plugins/order/order.html");
doh.registerUrl("text", "../plugins/text.html");
......@@ -25,6 +26,7 @@ doh.registerUrl("errback", "../errback/errback.html");
doh.registerUrl("specialDeps", "../specialDeps/specialDeps.html");
doh.registerUrl("hasOwnPropertyTests", "../hasOwnProperty/hasOwnProperty.html");
doh.registerUrl("firstDefine", "../firstDefine/firstDefine.html");
doh.registerUrl("relativeId", "../relativeId/relativeId.html");
doh.registerUrl("topRelativeRequire", "../topRelativeRequire/topRelativeRequire.html");
doh.registerUrl("configDeps", "../configDeps/configDeps.html");
doh.registerUrl("defineNoCallback", "../defineNoCallback/defineNoCallback.html");
......
......@@ -12,7 +12,7 @@
<p>A set of modules have multiple cycles in them, but the require() that
uses the top module in that bundle should get a fully constructed
module set.<a href="https://github.com/jrburke/requirejs/issues/414">More info</a>.</p>
module set.<a href="https://github.com/requirejs/requirejs/issues/414">More info</a>.</p>
<p>Check console for messages</p>
......
......@@ -58,7 +58,7 @@
<h1>almond: circular Test</h1>
<p>Test circular dependencies with almond. More info:
<a href="https://github.com/jrburke/almond/issues/17">17</a>.</p>
<a href="https://github.com/requirejs/almond/issues/17">17</a>.</p>
<p>Check console for messages</p>
</body>
......
......@@ -11,7 +11,7 @@
<h1>almond: Circular Transpiler Plugin Test</h1>
<p>Test support for transpiled modules with cycles in them More info:
<a href="https://github.com/jrburke/requirejs/issues/356">356</a>.</p>
<a href="https://github.com/requirejs/requirejs/issues/356">356</a>.</p>
<p>Check console for messages</p>
</body>
......
......@@ -33,7 +33,7 @@
<h1>almond: configDeps Test</h1>
<p>Make sure almond allows using config.deps. More info:
<a href="https://github.com/jrburke/almond/issues/52">52</a>.</p>
<a href="https://github.com/requirejs/almond/issues/52">52</a>.</p>
<p>Check console for messages</p>
</body>
......
......@@ -44,7 +44,7 @@
<body>
<h1>almond: Define Double Test</h1>
<p>Make sure a double define only uses the first one.
<a href="https://github.com/jrburke/almond/issues/43">More info</a></p>
<a href="https://github.com/requirejs/almond/issues/43">More info</a></p>
<p>Check console for messages</p>
</body>
</html>
......@@ -28,7 +28,7 @@
</head>
<body>
<h1>almond: First Define Test</h1>
<p>First define should win. <a href="https://github.com/jrburke/almond/issues/45">More Info</a>.</p>
<p>First define should win. <a href="https://github.com/requirejs/almond/issues/45">More Info</a>.</p>
<p>Check console for messages</p>
</body>
</html>
......@@ -30,7 +30,7 @@
<p>Make sure almond can handle juse a plain require(['a']) used by
r.js's insertRequire build option. More info:
<a href="https://github.com/jrburke/almond/issues/27">27</a>.</p>
<a href="https://github.com/requirejs/almond/issues/27">27</a>.</p>
<p>Check console for messages</p>
</body>
......
......@@ -10,7 +10,7 @@
<body>
<h1>require.js: Map Config Specificity Test</h1>
<p>Test map config specificity.
<a href="https://github.com/jrburke/almond/issues/35">More info</a>.</p>
<a href="https://github.com/requirejs/almond/issues/35">More info</a>.</p>
<p>Check console for messages</p>
</body>
</html>
......@@ -11,7 +11,7 @@
<h1>require.js: Packages Node-Style Test</h1>
<p>Test package that uses ".js" node-style module ID references inside
a package. More info:
<a href="https://github.com/jrburke/r.js/pull/591">r.js 591</a></p>
<a href="https://github.com/requirejs/r.js/pull/591">r.js 591</a></p>
<p>Check console for messages</p>
</body>
</html>
......@@ -12,7 +12,7 @@
<p>Test using the map config with plugins. but include a map value that
contains the original name of the plugin, to confirm the map translation
is only done once:
<a href="https://github.com/jrburke/requirejs/issues/484">484</a></p>
<a href="https://github.com/requirejs/requirejs/issues/484">484</a></p>
<p>Check console for messages</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>almond: Plugin Relative Module ID Test</title>
<script type="text/javascript" src="../../doh/runner.js"></script>
<script type="text/javascript" src="../../doh/_browserRunner.js"></script>
<script src="../../../almond.js"></script>
<script type="text/javascript" src="pluginRelative.js"></script>
</head>
<body>
<h1>almond: Plugin Relative Module ID Test</h1>
<p>Test if dependency that is a plugin ID with a relative resource name resolves correctly:
<a href="https://github.com/requirejs/requirejs/issues/101">101</a></p>
<p>Check console for messages</p>
</body>
</html>
define('plugin', {
load: function (id, require, load, config) {
throw new Error("Dynamic load not allowed: " + id);
}
});
define('plugin!src/b', [], function () {
return {
name: 'b'
};
});
define('plugin!src/a', ['plugin!./b'], function (b) {
return {
name: 'a',
b: b
};
});
require(['plugin!src/a'], function (a) {
doh.register(
'pluginRelative',
[
function pluginRelative(t){
t.is('a', a.name);
t.is('b', a.b.name);
}
]
);
doh.run();
});
define("pluginRelative-tests", function(){});
<!DOCTYPE html>
<html>
<head>
<title>almond: Relative ID Require Test</title>
<script type="text/javascript" src="../doh/runner.js"></script>
<script type="text/javascript" src="../doh/_browserRunner.js"></script>
<script type="text/javascript" src="../../almond.js"></script>
<script type="text/javascript">
define('../../vendor/some-file', {
name: 'some-file'
});
define('../../vendor/some-lib', ['./some-file'],
function(someFile) {
return {
name: 'some-lib',
someFile: someFile
};
});
require(['../../vendor/some-lib'], function(someLib){
doh.register(
'realtiveId',
[
function realtiveId(t){
t.is('some-lib', someLib.name);
t.is('some-file', someLib.someFile.name);
}
]
);
doh.run();
});
</script>
</head>
<body>
<h1>almond: Relative ID Require Test</h1>
<p>Make sure relative ID values are normalized as much as possible.More info:
<a href="https://github.com/requirejs/almond/issues/116">116</a>.</p>
<p>Check console for messages</p>
</body>
</html>
......@@ -61,7 +61,7 @@
<h1>almond: Relative Paths Test</h1>
<p>Test relative dependency paths with almond. More info:
<a href="https://github.com/jrburke/almond/issues/28">28</a>.</p>
<a href="https://github.com/requirejs/almond/issues/28">28</a>.</p>
<p>Check console for messages</p>
</body>
......
......@@ -45,7 +45,7 @@
<h1>almond: requireInDefine Test</h1>
<p>require(['a']) inside a define. More info:
<a href="https://github.com/jrburke/almond/issues/87">87</a>.</p>
<a href="https://github.com/requirejs/almond/issues/87">87</a>.</p>
<p>Check console for messages</p>
</body>
......
......@@ -11,7 +11,7 @@
<h1>almond: Special Dependencies Test</h1>
<p>Tests for require("require"|"exports"|"module") inside a module.
<a href="https://github.com/jrburke/requirejs/issues/409">More info</a>.</p>
<a href="https://github.com/requirejs/requirejs/issues/409">More info</a>.</p>
<p>Check console for messages</p>
</body>
......
......@@ -27,7 +27,7 @@
<h1>almond: Top Relative Require Test</h1>
<p>Test top relative require . More info:
<a href="https://github.com/jrburke/almond/issues/46">46</a>.</p>
<a href="https://github.com/requirejs/almond/issues/46">46</a>.</p>
<p>Check console for messages</p>
</body>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment