Comparing version 3.4.0 to 3.5.0
{ | ||
"name": "loader.js", | ||
"main": "loader.js", | ||
"version": "3.3.0", | ||
"version": "3.5.0", | ||
"homepage": "https://github.com/ember-cli/loader.js", | ||
@@ -18,4 +18,4 @@ "authors": [ | ||
"devDependencies": { | ||
"qunit": "~1.14.0" | ||
"qunit": "~1.20.0" | ||
} | ||
} |
@@ -1,2 +0,3 @@ | ||
var define, requireModule, require, requirejs; | ||
var loader, define, requireModule, require, requirejs; | ||
var global = this; | ||
@@ -6,2 +7,28 @@ (function() { | ||
// Save off the original values of these globals, so we can restore them if someone asks us to | ||
var oldGlobals = { | ||
loader: loader, | ||
define: define, | ||
requireModule: requireModule, | ||
require: require, | ||
requirejs: requirejs | ||
}; | ||
loader = { | ||
noConflict: function(aliases) { | ||
var oldName, newName; | ||
for (oldName in aliases) { | ||
if (aliases.hasOwnProperty(oldName)) { | ||
if (oldGlobals.hasOwnProperty(oldName)) { | ||
newName = aliases[oldName]; | ||
global[newName] = global[oldName]; | ||
global[oldName] = oldGlobals[oldName]; | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
var _isArray; | ||
@@ -144,3 +171,3 @@ if (!Array.isArray) { | ||
function findModule(name, referrer) { | ||
var mod = registry[name]; | ||
var mod = registry[name] || registry[name + '/index']; | ||
@@ -147,0 +174,0 @@ while (mod && mod.callback instanceof Alias) { |
{ | ||
"name": "loader.js", | ||
"version": "3.4.0", | ||
"version": "3.5.0", | ||
"description": "loader.js =========", | ||
@@ -9,7 +9,6 @@ "main": "loader.js", | ||
}, | ||
"dependencies": { | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"testem": "^0.6.16", | ||
"bower": "^1.3.5" | ||
"bower": "^1.3.5", | ||
"testem": "^0.9.11" | ||
}, | ||
@@ -16,0 +15,0 @@ "scripts": { |
@@ -6,2 +6,20 @@ loader.js [![Build Status](https://travis-ci.org/ember-cli/loader.js.png?branch=master)](https://travis-ci.org/ember-cli/loader.js) | ||
## No Conflict | ||
To prevent the loader from overriding `require`, `define`, or `requirejs` you can instruct the loader | ||
to use no conflict mode by providing it an alternative name for the various globals that are normally used. | ||
Example: | ||
```js | ||
loader.noConflict({ | ||
define: 'newDefine', | ||
require: 'newRequire' | ||
}); | ||
``` | ||
Note: To be able to take advantage of alternate `define` method name, you will also need to ensure that your | ||
build tooling generates using the alternate. An example of this is done in the [emberjs-build](https://github.com/emberjs/emberjs-build) | ||
project in the [babel-enifed-module-formatter plugin](https://github.com/emberjs/emberjs-build/blob/v0.4.2/lib/utils/babel-enifed-module-formatter.js). | ||
## Tests | ||
@@ -8,0 +26,0 @@ |
@@ -6,3 +6,3 @@ { | ||
], | ||
"test_page": "tests/index.html", | ||
"test_page": "tests/index.html?hidepassed", | ||
"launch_in_dev": [ | ||
@@ -9,0 +9,0 @@ "PhantomJS", |
112
tests/all.js
@@ -0,1 +1,4 @@ | ||
/*globals newDefine:false, newLoader:false, newRequire:false*/ | ||
/*globals define:true, loader:true, require:true*/ | ||
'use strict'; | ||
@@ -18,3 +21,13 @@ | ||
module('loader.js api', { | ||
setup: function() { | ||
this._define = define; | ||
this._loader = loader; | ||
this._require = require; | ||
}, | ||
teardown: function() { | ||
define = this._define; | ||
loader = this._loader; | ||
require = this._require; | ||
requirejs.clear(); | ||
@@ -25,5 +38,7 @@ } | ||
test('has api', function() { | ||
equal(typeof loader, 'object'); | ||
equal(typeof loader.noConflict, 'function'); | ||
equal(typeof require, 'function'); | ||
equal(typeof define, 'function'); | ||
equal(define.amd, undefined); | ||
strictEqual(define.amd, undefined); | ||
ok(define.petal); | ||
@@ -34,2 +49,18 @@ equal(typeof requirejs, 'function'); | ||
test('no conflict mode', function() { | ||
loader.noConflict({ | ||
define: 'newDefine', | ||
loader: 'newLoader', | ||
require: 'newRequire' | ||
}); | ||
equal(define, 'LOL'); | ||
strictEqual(loader, undefined); | ||
equal(require, 'ZOMG'); | ||
equal(newDefine, this._define); | ||
equal(newLoader, this._loader); | ||
equal(newRequire, this._require); | ||
}); | ||
test('simple define/require', function() { | ||
@@ -219,3 +250,3 @@ var fooCalled = 0; | ||
define('a/bar', ['require', 'exports', 'module'], function(require, exports, module) { | ||
define('a/bar', ['require', 'exports', 'module'], function(require, exports) { | ||
exports.name = 'bar'; | ||
@@ -230,3 +261,4 @@ }); | ||
test('pass default deps if arguments are expected and deps not passed', function() { | ||
define('foo', function(require, exports, module) { | ||
// this is intentionally testing the array-less form | ||
define('foo', function(require, exports, module) { // jshint ignore:line | ||
equal(arguments.length, 3); | ||
@@ -239,3 +271,3 @@ }); | ||
test('if factory returns a value it is used as export', function() { | ||
define('foo', ['require', 'exports', 'module'], function(require, exports, module) { | ||
define('foo', ['require', 'exports', 'module'], function() { | ||
return { | ||
@@ -251,3 +283,3 @@ bar: 'bar' | ||
test("if a module has no default property assume the return is the default", function() { | ||
test('if a module has no default property assume the return is the default', function() { | ||
define('foo', [], function() { | ||
@@ -265,3 +297,3 @@ return { | ||
test("if a CJS style module has no default export assume module.exports is the default", function() { | ||
test('if a CJS style module has no default export assume module.exports is the default', function() { | ||
define('Foo', ['require', 'exports', 'module'], function(require, exports, module) { | ||
@@ -280,5 +312,5 @@ module.exports = function Foo() { | ||
test("if a module has no default property assume its export is default (function)", function() { | ||
test('if a module has no default property assume its export is default (function)', function() { | ||
var theFunction = function theFunction() {}; | ||
define('foo', ['require', 'exports', 'module'], function(require, exports, module) { | ||
define('foo', ['require', 'exports', 'module'], function() { | ||
return theFunction; | ||
@@ -292,5 +324,5 @@ }); | ||
test("has good error message for missing module", function() { | ||
test('has good error message for missing module', function() { | ||
var theFunction = function theFunction() {}; | ||
define('foo', ['apple'], function(require, exports, module) { | ||
define('foo', ['apple'], function() { | ||
return theFunction; | ||
@@ -304,3 +336,3 @@ }); | ||
test("provides good error message when an un-named AMD module is provided", function() { | ||
test('provides good error message when an un-named AMD module is provided', function() { | ||
throws(function() { | ||
@@ -330,3 +362,3 @@ define(function() { | ||
test("relative CJS esq require", function() { | ||
test('relative CJS esq require', function() { | ||
define('foo/a', ['require'], function(require) { | ||
@@ -341,3 +373,3 @@ return require('./b'); | ||
define('foo/c', ['require'], function(require) { | ||
define('foo/c', ['require'], function() { | ||
return 'c-content'; | ||
@@ -350,3 +382,3 @@ }); | ||
test("relative CJS esq require (with exports and module');", function() { | ||
test('relative CJS esq require (with exports and module);', function() { | ||
define('foo/a', ['module', 'exports', 'require'], function(module, exports, require) { | ||
@@ -360,3 +392,3 @@ module.exports = require('./b'); | ||
define('foo/c', ['module', 'exports', 'require'], function(module, exports, require) { | ||
define('foo/c', ['module', 'exports', 'require'], function(module) { | ||
module.exports = 'c-content'; | ||
@@ -382,2 +414,46 @@ }); | ||
test('foo automatically falls back to foo/index', function() { | ||
define('foo/index', [] , function() { | ||
return { 'default': 'hi' }; | ||
}); | ||
define('bar', ['foo', 'foo/index'] , function(foo, fooIndex) { | ||
deepEqual(foo, fooIndex); | ||
}); | ||
deepEqual(require('foo'), require('foo/index')); | ||
}); | ||
test('automatic /index fallback no ambiguity', function() { | ||
define('foo/index', [], function() { | ||
return 'I AM foo/index'; | ||
}); | ||
define('bar', ['foo'], function(foo) { | ||
return 'I AM bar with: ' + foo; | ||
}); | ||
equal(require('foo'), 'I AM foo/index'); | ||
equal(require('foo/index'), 'I AM foo/index'); | ||
equal(require('bar'), 'I AM bar with: I AM foo/index'); | ||
}); | ||
test('automatic /index fallback is not used if module is defined', function() { | ||
define('foo', [], function() { | ||
return 'I AM foo'; | ||
}); | ||
define('foo/index', [], function() { | ||
return 'I AM foo/index'; | ||
}); | ||
define('bar', ['foo'], function(foo) { | ||
return 'I AM bar with: ' + foo; | ||
}); | ||
equal(require('foo'), 'I AM foo'); | ||
equal(require('foo/index'), 'I AM foo/index'); | ||
equal(require('bar'), 'I AM bar with: I AM foo'); | ||
}); | ||
test('unsee', function() { | ||
@@ -403,3 +479,3 @@ var counter = 0; | ||
test('/index fallback no ambiguity', function() { | ||
test('manual /index fallback no ambiguity', function() { | ||
define('foo/index', [], function() { | ||
@@ -420,3 +496,3 @@ return 'I AM foo/index'; | ||
test('/index fallback with ambiguity (alias after)', function() { | ||
test('manual /index fallback with ambiguity (alias after)', function() { | ||
define('foo', [], function() { | ||
@@ -441,3 +517,3 @@ return 'I AM foo'; | ||
test('/index fallback with ambiguity (alias after all defines but before require)', function() { | ||
test('manual /index fallback with ambiguity (alias after all defines but before require)', function() { | ||
define('foo', [], function() { | ||
@@ -444,0 +520,0 @@ return 'I AM foo'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36952
931
46
3
1