Comparing version 3.5.0 to 3.6.0
@@ -81,2 +81,5 @@ var loader, define, requireModule, require, requirejs; | ||
} else { | ||
if (loader.wrapModules) { | ||
this.callback = loader.wrapModules(this.name, this.callback); | ||
} | ||
var result = this.callback.apply(this, reifiedDeps); | ||
@@ -83,0 +86,0 @@ if (!(this.hasExportsAsDep && result === undefined)) { |
{ | ||
"name": "loader.js", | ||
"version": "3.5.0", | ||
"version": "3.6.0", | ||
"description": "loader.js =========", | ||
@@ -5,0 +5,0 @@ "main": "loader.js", |
@@ -24,2 +24,18 @@ loader.js [![Build Status](https://travis-ci.org/ember-cli/loader.js.png?branch=master)](https://travis-ci.org/ember-cli/loader.js) | ||
## wrapModules | ||
It is possible to hook loader to augment or transform the loaded code. `wrapModules` is an optional method on the loader that is called as each module is originally loaded. `wrapModules` must be a function of the form `wrapModules(name, callback)`. The `callback` is the original AMD callback. The return value of `wrapModules` is then used in subsequent requests for `name` | ||
This functionality is useful for instrumenting code, for instance in code coverage libraries. | ||
``` | ||
loader.wrapModules = function(name, callback) { | ||
if (shouldTransform(name) { | ||
return myTransformer(name, callback); | ||
} | ||
} | ||
return callback; | ||
}; | ||
``` | ||
## Tests | ||
@@ -26,0 +42,0 @@ |
@@ -660,1 +660,17 @@ /*globals newDefine:false, newLoader:false, newRequire:false*/ | ||
}); | ||
test('wrapModules is called when present', function() { | ||
var fooCalled = 0; | ||
var annotatorCalled = 0; | ||
loader.wrapModules = function(name, callback) { | ||
annotatorCalled++; | ||
return callback; | ||
}; | ||
define('foo', [], function() { | ||
fooCalled++; | ||
}); | ||
equal(annotatorCalled, 0); | ||
require('foo'); | ||
equal(annotatorCalled, 1); | ||
}); |
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
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
38118
948
62
0