Permalink
Browse files

testing and bug fixing

  • Loading branch information...
1 parent 6eae833 commit 51ade6877d06b2806af481e7bffea7edce8af3e9 @guybedford committed Mar 15, 2013
Showing with 79 additions and 18 deletions.
  1. +1 −0 test/app-built.js
  2. +3 −0 test/app.js
  3. +2 −0 test/build.sh
  4. +3 −0 test/jquery-1.8.1.js
  5. +3 −0 test/jquery-2.0.0.js
  6. +3 −0 test/jquery-2.0.js
  7. +6 −0 test/jquery.js
  8. +17 −0 test/test-built.html
  9. +9 −1 test/test.html
  10. +32 −17 v.js
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -0,0 +1,3 @@
+define(['v!jquery#>=1.9'], function($) {
+ console.log($.version);
+});
View
@@ -0,0 +1,2 @@
+r.js -o baseUrl=. name=app out=app-built.js map.*.v='../v'
+
View
@@ -0,0 +1,3 @@
+define({
+ version: '1.8.1'
+});
View
@@ -0,0 +1,3 @@
+define({
+ version: '2.0.0'
+});
View
@@ -0,0 +1,3 @@
+define({
+ version: '1.8.1'
+});
View
@@ -0,0 +1,6 @@
+define(function() {
+ return [
+ '1.8.1',
+ '2.0.0'
+ ];
+});
View
@@ -0,0 +1,17 @@
+<!doctype html>
+ <script>
+ var require = {
+ baseUrl: '.',
+ map: {
+ '*': {
+ 'v': '../v'
+ }
+ }
+ };
+ </script>
+ <script src="require.js"></script>
+ <script src="app-built.js"></script>
+ <script>
+ require(['app']);
+ </script>
+
View
@@ -1,8 +1,16 @@
<!doctype html>
<script>
var require = {
- baseUrl: '../'
+ baseUrl: '.',
+ map: {
+ '*': {
+ 'v': '../v'
+ }
+ }
};
</script>
<script src="require.js"></script>
+ <script>
+ require(['app']);
+ </script>
View
49 v.js
@@ -1,46 +1,61 @@
-define(['./semver'], function(semver) {
+define(['./semver', 'require'], function(semver, req) {
return {
loadedVersions: {},
- getVersionNum: function(name, callback) {
+ getVersionNum: function(name, build, callback) {
var hashIndex = name.lastIndexOf('#');
var moduleName = name.substr(0, hashIndex);
var versionRange = name.substr(hashIndex + 1);
- var loadedCache = this.loadedVersions;
+ var loadedVersions = this.loadedVersions;
if (!semver.validRange(versionRange))
throw moduleName + '#' + versionRange + ' has an invalid version range.';
- // load the version ranges for the given moduleName
- req([moduleName], function(supportedVersions) {
+ var checkVersions = function(supportedVersions) {
// first check if we have any loaded versions for this module
- if (loadedVersions[moduleName]) {
+ if (loadedVersions[moduleName])
for (var v in loadedVersions[moduleName])
- if (semver.satisfies(v, version))
- return callback(v);
- }
+ if (semver.satisfies(v, versionRange))
+ return callback(moduleName, v);
// no supported loaded version - need to load a version
- callback(semver.maxSatisfying(supportedVersions, version));
+ callback(moduleName, semver.maxSatisfying(supportedVersions, versionRange));
+ }
- }, function(err) {
- throw 'You need to provide a "' + moduleName + '" module providing the version array.';
- });
+ if (build) {
+ var fs = require.nodeRequire('fs');
+ checkVersions(eval(''
+ + '(function(){ \n'
+ + ' var defined; \n'
+ + ' var define = function(factory){ \n'
+ + ' defined = factory(); \n'
+ + ' } \n'
+ + fs.readFileSync(req.toUrl(moduleName) + '.js') + '\n'
+ + ' return defined; \n'
+ + '})()'
+ ));
+ }
+ else {
+ // load the version ranges for the given moduleName
+ req([moduleName], checkVersions, function(err) {
+ throw 'You need to provide a "' + moduleName + '" module providing the version array.';
+ });
+ }
},
load: function(name, req, load, config) {
var loadedVersions = this.loadedVersions;
- this.getVersionNum(name, function(version) {
+ this.getVersionNum(name, config.isBuild, function(moduleName, version) {
// load from the expected filename convention
req([moduleName + '-' + version], function(m) {
loadedVersions[moduleName] = loadedVersions[moduleName] || {};
- loadedVersions[moduleName][loadVersion] = true;
+ loadedVersions[moduleName][version] = true;
load(m);
});
});
},
write: function(pluginName, name, write) {
- this.getVersionNum(name, function(version) {
- write.asModule(pluginName + '!' + moduleName, "define(['" + name + '-' + version + "'], function(m){ return m; });")
+ this.getVersionNum(name, true, function(moduleName, version) {
+ write.asModule(pluginName + '!' + name, "define(['" + moduleName + '-' + version + "'], function(m){ return m; });")
});
}
};

0 comments on commit 51ade68

Please sign in to comment.