From b5a967a6435f193849a5163210828b130473ba43 Mon Sep 17 00:00:00 2001 From: guybedford Date: Sat, 11 Jun 2016 19:17:06 +0200 Subject: [PATCH] jspm normalize polishing --- cli.js | 18 ++++++++++++++++-- lib/core.js | 22 ++++++++++++++++------ 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/cli.js b/cli.js index bc36b8105..9f0c36f00 100755 --- a/cli.js +++ b/cli.js @@ -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; @@ -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); }) diff --git a/lib/core.js b/lib/core.js index 959b5cd37..0fb162463 100644 --- a/lib/core.js +++ b/lib/core.js @@ -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; @@ -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; }); };