Skip to content

Commit

Permalink
move config injection and lowResSourceMaps into jspm builder API exte…
Browse files Browse the repository at this point in the history
…nsion
  • Loading branch information
guybedford committed Mar 27, 2016
1 parent f6c9c87 commit 21e380c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 33 deletions.
3 changes: 3 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,9 @@ process.on('uncaughtException', function(err) {
if (options['global-name'])
options.globalName = options['global-name'];

if (options.inject)
options.injectConfig = true;

options.format = options.format;

if (options.globals)
Expand Down
74 changes: 41 additions & 33 deletions lib/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,32 @@ Builder.prototype.bundle = function(expressionOrTree, outFile, opts) {
if (!('normalize' in opts))
opts.normalize = true;

return SystemJSBuilder.prototype.bundle.call(this, expressionOrTree, opts);
if (!('lowResSourceMaps' in opts))
opts.lowResSourceMaps = true;

var self = this;

return SystemJSBuilder.prototype.bundle.call(this, expressionOrTree, opts)
.then(function(output) {

// Add the bundle to config if the inject flag was given
if (opts.injectConfig && opts.outFile) {
// NB deprecate
output.bundleName = output.bundleName || self.getCanonicalName(toFileURL(path.resolve(opts.outFile)));
var bundleName = output.bundleName;

if (!config.loader.bundles)
config.loader.bundles = {};

config.loader.bundles[bundleName] = output.modules;
return config.save()
.then(function() {
return output;
});
}

return output;
});
};

Builder.prototype.buildStatic = function(expressionOrTree, outFile, opts) {
Expand All @@ -77,6 +102,9 @@ Builder.prototype.buildStatic = function(expressionOrTree, outFile, opts) {
if (!('format' in opts))
opts.format = 'global';

if (!('lowResSourceMaps' in opts))
opts.lowResSourceMaps = true;

return SystemJSBuilder.prototype.buildStatic.call(this, expressionOrTree, opts);
};

Expand All @@ -86,15 +114,11 @@ exports.Builder = Builder;
exports.depCache = function(expression) {
var systemBuilder = new Builder();

return config.load()
.then(function() {
expression = expression || config.loader.main;
})
.then(function() {
ui.log('info', 'Injecting the traced dependency tree for `' + expression + '`...');
expression = expression || config.loader.main;

ui.log('info', 'Injecting the traced dependency tree for `' + expression + '`...');

return systemBuilder.trace(expression);
})
return systemBuilder.trace(expression)
.then(function(tree) {
logTree(tree);
var depCache = config.loader.depCache || {};
Expand All @@ -119,9 +143,10 @@ exports.bundle = function(moduleExpression, fileName, opts) {

opts.normalize = true;

return config.load()
fileName = fileName || path.resolve(config.pjson.baseURL, 'build.js');

return Promise.resolve()
.then(function() {
fileName = fileName || path.resolve(config.pjson.baseURL, 'build.js');

if (!opts.sourceMaps)
return removeExistingSourceMap(fileName);
Expand All @@ -133,26 +158,12 @@ exports.bundle = function(moduleExpression, fileName, opts) {
})
.then(function(buildTree) {
logTree(buildTree);
if (!('lowResSourceMaps' in opts))
opts.lowResSourceMaps = true;
return systemBuilder.bundle(buildTree, fileName, opts);
})
.then(function(output) {
delete config.loader.depCache;

if (opts.inject) {
// Add the bundle to config if the inject flag was given.
var bundleName = systemBuilder.getCanonicalName(toFileURL(path.resolve(fileName)));

if (!config.loader.bundles)
config.loader.bundles = {};
config.loader.bundles[bundleName] = output.modules;
if (opts.injectConfig)
ui.log('ok', '`' + output.bundleName + '` added to config bundles.');

ui.log('ok', '`' + bundleName + '` added to config bundles.');
}
})
.then(config.save)
.then(function() {
logBuild(path.relative(process.cwd(), fileName), opts);
})
.catch(function(e) {
Expand Down Expand Up @@ -187,10 +198,10 @@ exports.bundleSFX = function(expression, fileName, opts) {

opts = opts || {};

return config.load()
.then(function() {
fileName = fileName || path.resolve(config.pjson.baseURL, 'build.js');
fileName = fileName || path.resolve(config.pjson.baseURL, 'build.js');

return Promise.resolve()
.then(function() {
if (!opts.sourceMaps)
return removeExistingSourceMap(fileName);
})
Expand All @@ -199,9 +210,6 @@ exports.bundleSFX = function(expression, fileName, opts) {

opts.format = opts.format || 'global';

if (!('lowResSourceMaps' in opts))
opts.lowResSourceMaps = true;

return systemBuilder.buildStatic(expression, fileName, opts);
})
.then(function() {
Expand Down

0 comments on commit 21e380c

Please sign in to comment.