Skip to content

Commit

Permalink
warn on invalid packages
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Aug 8, 2015
1 parent 28dad78 commit def97e2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 11 additions & 2 deletions lib/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,23 @@
if (!pkgConfig.env)
return Promise.resolve(pkgConfig);

// NB this derive function will run many times as we have no queue

// check environment conditions
// default environment condition is '@env' in package or '@system-env' globally
return loader['import'](pkgConfig.map['@env'] || '@system-env', pkgName)
.then(function(env) {
// derived config object
var pkg = {};
for (var p in pkgConfig)
if (p !== 'map' & p !== 'env')
for (var p in pkgConfig) {
if (p == 'main' || p == 'format' || p == 'defaultExtension' || p == 'meta') {
pkg[p] = pkgConfig[p];
}
else if (p != 'map' && p != 'env') {
if (typeof console != 'undefined' && console.warn)
console.warn('"' + p + '" is not a valid package configuration option in package ' + pkgName);
}
}

pkg.map = {};
for (var p in pkgConfig.map)
Expand All @@ -100,6 +108,7 @@
}

// store the derived environment config so we have this cached for next time
console.log('store derived');
loader.packages[pkgName] = pkg;

return pkg;
Expand Down
3 changes: 2 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,8 @@ asyncTest('Package configuration CommonJS config example', function() {
'./env-module': './env-module-browser.js'
}
}
}
},
asdf: 'asdf'
}
}
});
Expand Down

0 comments on commit def97e2

Please sign in to comment.