Skip to content

Commit

Permalink
Merge pull request #11 from JesseFarebro/clear-requires
Browse files Browse the repository at this point in the history
Allow for clearing of require values through streams as per #10
  • Loading branch information
wbyoung committed Mar 27, 2015
2 parents 1ecd02d + e8cc0ad commit 788f71e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function makeAMD(moduleContents, opts) {
var includes = [];
var defines = [];
_.each(opts.require, function(include, define) {
if(include === null) { return; }
includes.push(JSON.stringify(include));
defines.push(define);
});
Expand All @@ -20,6 +21,7 @@ function makeAMD(moduleContents, opts) {
function makeCommonJS(moduleContents, opts) {
// var Dependency = require('dependency');module.exports = moduleObject;
var requires = _.map(opts.require, function(key, value) {
if(value === null) { return; }
return 'var ' + value + ' = require(' + JSON.stringify(key) + ');';
});
return requires + 'module.exports = ' + moduleContents + ';';
Expand Down
5 changes: 3 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,19 @@ describe('gulp-define-module', function() {
// - context from `file.defineModuleOptions` should be processed first, then context
// from `defineModule`.
// - wrapper from `defineModule` should override that of `file.defineModuleOptions`.
// - any require from `defineModule` with the value of null should ignore the require
var stream = defineModule('amd', {
wrapper: 'Application.Library.TEMPLATES[\'<%= name %>\'] = <%= contents %>',
context: function(context) {
return { name: context.prefix + '.' + context.name };
},
require: { Application: 'application', Shared: 'shared-application-library' }
require: { Application: 'application', Shared: 'shared-application-library', Vendor: null }
});
var file = fixtureFile('basic.js');
file.defineModuleOptions = {
wrapper: 'Library.TEMPLATES[\'<%= name %>\'] = <%= contents %>',
context: { prefix: 'prefix' },
require: { Library: 'library', Shared: 'shared-library' }
require: { Library: 'library', Shared: 'shared-library', Vendor: 'shared-vendor-library' }
};
stream.on('data', function(file) {
fileShouldMatchExpected(file, 'basic_amd_advanced_options.js', function(match) {
Expand Down

0 comments on commit 788f71e

Please sign in to comment.