Skip to content

Commit

Permalink
jspm normalize polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Jun 11, 2016
1 parent dfaf1c3 commit b5a967a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
18 changes: 16 additions & 2 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ var install = require('./lib/install');
var fs = require('graceful-fs');
var Promise = require('bluebird');

// load the API but revert the API resolver
require('./api');
ui.setResolver();

var readOptions = require('./lib/cli-utils').readOptions;
var readValue = require('./lib/cli-utils').readValue;
var readPropertySetters = require('./lib/cli-utils').readPropertySetters;
Expand Down Expand Up @@ -367,8 +371,18 @@ process.on('uncaughtException', function(err) {
var canonicalize = true;

case 'normalize':
options = readOptions(args, ['yes'], ['parent']);
core.normalize(options.args[1], options.parent, canonicalize)
options = readOptions(args, ['yes'], ['parent', 'browser', 'dev', 'production']);
var env = {};
if ('production' in options) {
env.production = true;
env.dev = false;
}
if ('browser' in options) {
env.browser = true;
env.node = false;
}

core.normalize(options.args[1], options.parent, canonicalize, env)
.then(function(normalized) {
console.log(normalized);
})
Expand Down
22 changes: 16 additions & 6 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ var mkdirp = require('mkdirp');
var rimraf = require('rimraf');
var asp = require('bluebird').Promise.promisify;
var System = require('systemjs');
var Builder = require('../lib/bundle').Builder;
var Loader = require('../api').Loader;
var HOME = require('./common').HOME;
var Promise = require('bluebird');

var getCanonicalName = require('systemjs-builder/lib/utils').getCanonicalName;
var extend = require('./common').extend;

var core = module.exports;

Expand Down Expand Up @@ -194,12 +195,21 @@ exports.dlLoader = function(unminified, edge, latest) {
});
};

exports.normalize = function(moduleName, parentName, canonicalize) {
var builder = new Builder();
return builder.loader.normalize(moduleName, parentName && builder.loader.normalizeSync(parentName))
exports.normalize = function(moduleName, parentName, canonicalize, env) {
var loader = new Loader();

// set a custom environment for normalization
var envModule = extend(extend({}, loader.get('@system-env')), env);
loader.set('@system-env', loader.newModule(envModule));

// ensure the parent package is loaded first
return loader.normalize(parentName)
.then(function() {
return loader.normalize(moduleName, parentName && loader.normalizeSync(parentName));
})
.then(function(normalized) {
if (canonicalize)
return builder.getCanonicalName(normalized);
return getCanonicalName(loader, normalized);
return normalized;
});
};
Expand Down

0 comments on commit b5a967a

Please sign in to comment.