Skip to content

Commit

Permalink
various polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Nov 19, 2015
1 parent d41e1e4 commit 9566a80
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 26 deletions.
18 changes: 6 additions & 12 deletions lib/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,10 @@ var toFileURL = require('./common').toFileURL;
// just allows cfg object
function Builder(_config) {
config.loadSync();
SystemJSBuilder.call(this, toFileURL(config.pjson.baseURL));

var cfg = config.loader.getConfig();

if (_config)
extend(cfg, _config);

SystemJSBuilder.call(this, toFileURL(config.pjson.baseURL), cfg);
// NB do really need a proper config merging function here to handle edge cases properly
SystemJSBuilder.call(this, config.getLoaderConfig());
this.config(_config);
}
Builder.prototype = Object.create(SystemJSBuilder.prototype);
exports.Builder = Builder;
Expand Down Expand Up @@ -103,9 +99,7 @@ exports.bundle = function(moduleExpression, fileName, opts) {
// 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.entryPoints;
config.loaderBrowser.file.setValue(['bundles', bundleName], output.modules);

ui.log('ok', '`' + bundleName + '` added to config bundles.');
}
Expand All @@ -123,8 +117,8 @@ exports.bundle = function(moduleExpression, fileName, opts) {
exports.unbundle = function() {
return config.load()
.then(function() {
config.loader.bundles = {};
config.loader.depCache = {};
config.loaderBrowser.file.remove(['bundles']);
config.loaderBrowser.file.remove(['depCache']);
return config.save();
})
.then(function() {
Expand Down
9 changes: 7 additions & 2 deletions lib/config/config-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,16 @@ ConfigFile.prototype.setValue = function(memberArray, value) {
// default behaviour is to not write empty objects, but to also not clear objects made empty
// also avoids unnecessary changes
ConfigFile.prototype.setProperties = function(memberArray, properties, clearIfEmpty, keepOrder) {
var targetProperties;

if (!properties.length && clearIfEmpty) {
this.remove(memberArray);
targetProperties = this.getProperties(memberArray)
if (targetProperties && targetProperties.length)
this.remove(memberArray);
return;
}

var targetProperties = this.getProperties(memberArray, true);
targetProperties = this.getProperties(memberArray, true);

var ordering;
if (!keepOrder)
Expand Down Expand Up @@ -395,6 +399,7 @@ ConfigFile.prototype.serialize = function(obj) {
jsonString += this.style.newline;

return jsonString
.replace(/([^\\])""/g, '$1' + this.style.quote + this.style.quote) // empty strings
.replace(/([^\\])"/g, '$1' + this.style.quote)
.replace(/\n/g, this.style.newline);
};
Expand Down
18 changes: 18 additions & 0 deletions lib/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var PackageName = require('../package-name');
var stringify = require('../common').stringify;
var absURLRegEx = require('../common').absURLRegEx;
var inDir = require('../common').inDir;
var toFileURL = require('../common').toFileURL;

var config = module.exports;

Expand All @@ -35,6 +36,23 @@ exports.version = require('../../package.json').version;
exports.pjson = null;
exports.loader = null;

exports.getLoaderConfig = function() {
var cfg = config.loader.getConfig();

cfg.paths = cfg.paths || {};
(cfg.packageConfigPaths || []).forEach(function(pkgConfigPath) {
var registryName = pkgConfigPath.substr(0, pkgConfigPath.indexOf(':'));
if (registryName && !cfg.paths[registryName + ':*'])
cfg.paths[registryName + ':*'] = toFileURL(config.pjson.packages) + '/' + registryName + '/*';
});

// no depCache or bundles
delete cfg.depCache;
delete cfg.bundles;

return cfg;
};

var loadPromise;
exports.loaded = false;
exports.load = function(prompts) {
Expand Down
7 changes: 4 additions & 3 deletions lib/config/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function JspmSystemConfig(fileName) {

// the base install map is the global map config
this.baseMap = {};
var map = this.file.getObject(['map']);
var map = this.file.getObject(['map']) || {};
Object.keys(map).forEach(function(key) {
self.baseMap[key] = new PackageName(map[key]);
});
Expand Down Expand Up @@ -82,7 +82,7 @@ function JspmSystemConfig(fileName) {
JspmSystemConfig.prototype = Object.create(SystemConfig.prototype);
JspmSystemConfig.prototype.ensureRegistry = function(registryName) {
// ensure packageNameFormats are present as packageConfigPaths in the right order
var packageConfigPaths = this.file.getValue(['packageConfigPaths'], 'array');
var packageConfigPaths = this.file.getValue(['packageConfigPaths'], 'array') || [];

var lastIndex;
(registry.load(registryName).constructor.packageNameFormats || ['*'])
Expand Down Expand Up @@ -129,7 +129,8 @@ JspmSystemConfig.prototype.syncFile = function() {

if (this.packageName != config.pjson.name)
this.file.remove(['packages', this.packageName = config.pjson.name]);
this.file.setObject(['packages', this.packageName], this.package);

this.file.setObject(['packages', this.packageName], this.package, true);
// ensure the local package is the first in the package list
this.file.orderFirst(['packages', this.packageName]);
};
Expand Down
2 changes: 1 addition & 1 deletion lib/config/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function PackageConfig(fileName) {

this.dir = path.dirname(path.resolve(fileName));

this.name = prefixedGetValue.call(this, ['name'], 'string') || '';
this.name = prefixedGetValue.call(this, ['name'], 'string') || 'app';

this.jspmPrefix = this.file.has(['jspm']);
this.jspmAware = this.jspmPrefix || this.file.has(['registry']);
Expand Down
11 changes: 5 additions & 6 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,20 @@ var asp = require('rsvp').denodeify;
var System = require('systemjs');
var toFileURL = require('./common').toFileURL;
var HOME = require('./common').HOME;
var dextend = require('./common').dextend;


var core = module.exports;

// we always download the latest semver compatible version
var systemVersion = require('../package.json').dependencies.systemjs;

exports.run = function(moduleName) {
exports.run = function(moduleName, _config) {
return config.load()
.then(function() {
var cfg = config.loader.getConfig();
delete cfg.bundles;
cfg.baseURL = toFileURL(config.pjson.baseURL);
System.config(cfg);

System.config(config.getLoaderConfig());
if (_config)
System.config(_config);
return System.import(moduleName);
})
.catch(function(e) {
Expand Down
4 changes: 2 additions & 2 deletions lib/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ function wordWrap(text, leftIndent, rightIndent) {
}
if (text[i] == ' ')
lastSpace = i;
if ((i - skipLength) != lastBreak && (i - lastBreak - skipLength) % columns == 0 && text[i + 1] != '\n') {
if ((i - skipLength) != lastBreak && (i - lastBreak - skipLength) % columns == 0 && text[i] != '\n') {
if (lastSpace <= lastBreak)
lastSpace = lastBreak + columns + skipLength;
lastSpace = lastBreak + columns + skipLength - 1;
var line = text.substring(lastBreak, lastSpace + 1);
lines.push(line);
lastBreak = lastSpace + 1;
Expand Down

0 comments on commit 9566a80

Please sign in to comment.