-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds an option named `amdModule` to app.import. It causes any anonymous AMD module in the imported file to be registered under the given name. app.import('bower_components/some-dep/some-dep.js', { amdModule: 'some-dep' }); This should work correctly with a large number of libraries that: - check for `typeof define === 'function' && define.amd` - call `define` with just a factory function, or a dependency list and factory function.
- Loading branch information
Showing
6 changed files
with
77 additions
and
3 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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
var stew = require('broccoli-stew'); | ||
|
||
module.exports = function shimAmd(tree, nameMapping) { | ||
return stew.map(tree, function(content, relativePath) { | ||
var name = nameMapping[relativePath]; | ||
if (name) { | ||
return [ | ||
'(function(define){', | ||
content, | ||
'})((function(){ function newDefine(){ var args = Array.prototype.slice.call(arguments); args.unshift("', | ||
name, | ||
'"); return define.apply(null, args); }; newDefine.amd = true; return newDefine; })());' | ||
].join(''); | ||
} else { | ||
return content; | ||
} | ||
}); | ||
}; |
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
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
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
15 changes: 15 additions & 0 deletions
15
tests/fixtures/brocfile-tests/app-import-anonymous-amd/ember-cli-build.js
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* global require, module */ | ||
|
||
var EmberApp = require('ember-cli/lib/broccoli/ember-app'); | ||
|
||
module.exports = function (defaults) { | ||
var app = new EmberApp(defaults, { | ||
}); | ||
|
||
app.import('vendor/anonymous-amd-example.js', { | ||
amdModule: 'hello-world', | ||
outputFile: '/assets/output.js' | ||
}); | ||
|
||
return app.toTree(); | ||
}; |
10 changes: 10 additions & 0 deletions
10
tests/fixtures/brocfile-tests/app-import-anonymous-amd/vendor/anonymous-amd-example.js
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
(function() { | ||
function helloWorld() { | ||
return "Hello World"; | ||
} | ||
if (typeof define === "function" && define.amd) { | ||
define([], function () { return helloWorld; }); | ||
} else { | ||
throw new Error("No amd loader found"); | ||
} | ||
})(); |