From c27a467bbea0df524e2071f459f1237672f92e3f Mon Sep 17 00:00:00 2001 From: guybedford Date: Tue, 1 Mar 2016 17:20:32 +0200 Subject: [PATCH] error stack loader option, plugin loader normalization fix, alias and loader to use usual resolution --- lib/amd-helpers.js | 2 +- lib/core.js | 12 +++++++++++- lib/package.js | 12 ------------ lib/plugins.js | 12 ++++++++++++ 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/lib/amd-helpers.js b/lib/amd-helpers.js index 3288e247..f379e558 100644 --- a/lib/amd-helpers.js +++ b/lib/amd-helpers.js @@ -79,7 +79,7 @@ hookConstructor(function(constructor) { normalized = normalized.substr(0, normalized.length - 3); var module = loader.get(normalized); if (!module) - throw new Error('Module not already loaded loading "' + names + '" from "' + referer + '".'); + throw new Error('Module not already loaded loading "' + names + '" as ' + normalized + (referer ? ' from "' + referer + '".' : '.')); return module.__useDefault ? module['default'] : module; } diff --git a/lib/core.js b/lib/core.js index 8a714654..1a830c65 100644 --- a/lib/core.js +++ b/lib/core.js @@ -64,6 +64,7 @@ hookConstructor(function(constructor) { this.warnings = false; this.defaultJSExtensions = false; this.pluginFirst = false; + this.loaderErrorStack = false; // by default load ".json" files as json // leading * meta doesn't need normalization @@ -291,9 +292,18 @@ hook('instantiate', function(instantiate) { */ SystemJSLoader.prototype.env = 'development'; +var curCurScript; SystemJSLoader.prototype.config = function(cfg) { var loader = this; + if ('loaderErrorStack' in cfg) { + curCurScript = $__curScript; + if (cfg.loaderErrorStack) + $__curScript = undefined; + else + $__curScript = curCurScript; + } + if ('warnings' in cfg) loader.warnings = cfg.warnings; @@ -432,7 +442,7 @@ SystemJSLoader.prototype.config = function(cfg) { for (var c in cfg) { var v = cfg[c]; - if (c == 'baseURL' || c == 'map' || c == 'packages' || c == 'bundles' || c == 'paths' || c == 'warnings' || c == 'packageConfigPaths') + if (c == 'baseURL' || c == 'map' || c == 'packages' || c == 'bundles' || c == 'paths' || c == 'warnings' || c == 'packageConfigPaths' || c == 'loaderErrorStack') continue; if (typeof v != 'object' || v instanceof Array) { diff --git a/lib/package.js b/lib/package.js index 8937f7ed..ea08421f 100644 --- a/lib/package.js +++ b/lib/package.js @@ -58,13 +58,6 @@ * - map targets support conditional interpolation ('./x': './x.#{|env}.js') * - internal package map targets cannot use boolean conditionals * - * In addition, the following modules properties will be allowed to be package - * -relative as well in the package module config: - * - * - loader - * - alias - * - * * Package Configuration Loading * * Not all packages may already have their configuration present in the System config @@ -616,11 +609,6 @@ extendMeta(meta, matchMeta, matchDepth && bestDepth > matchDepth); }); - // allow alias and loader to be package-relative - if (meta.alias && meta.alias.substr(0, 2) == './') - meta.alias = pkgName + meta.alias.substr(1); - if (meta.loader && meta.loader.substr(0, 2) == './') - meta.loader = pkgName + meta.loader.substr(1); extendMeta(load.metadata, meta); } } diff --git a/lib/plugins.js b/lib/plugins.js index 025e9900..f1bff93c 100644 --- a/lib/plugins.js +++ b/lib/plugins.js @@ -132,6 +132,18 @@ } return locate.call(loader, load) + .then(function(address) { + if (pluginSyntaxIndex != -1 || !load.metadata.loader) + return address; + + // normalize plugin relative to parent in locate here when + // using plugin via loader metadata + return loader.normalize(load.metadata.loader, load.name) + .then(function(loaderNormalized) { + load.metadata.loader = loaderNormalized; + return address; + }); + }) .then(function(address) { var plugin = load.metadata.loader;