systemjs-builder
Advanced tools
Comparing version 0.15.9 to 0.15.10
@@ -15,3 +15,3 @@ var System = require('systemjs'); | ||
// second pass will do rewriting based on this info | ||
// we set this.isAnon, which is true if there is one named define, or one anonymous define | ||
// we set this.anonDefine, which is true if there is one named define, or one anonymous define | ||
// if there are more than one anonymous defines, it is invalid | ||
@@ -22,4 +22,6 @@ function AMDDependenciesTransformer(map) { | ||
this.anonDefine = false; | ||
this.defineBundle = false; | ||
this.anonDefineIndex = -1; | ||
this.anonNamed = false; | ||
this.deps = []; | ||
this.bundleDefines = []; | ||
this.defineRedefined = false; | ||
@@ -31,5 +33,8 @@ return ParseTreeTransformer.call(this); | ||
var newDeps = []; | ||
var bundleDefines = this.bundleDefines; | ||
deps.forEach(function(dep) { | ||
if (['require', 'exports', 'module'].indexOf(dep) != -1) | ||
return; | ||
if (bundleDefines.indexOf(dep) != -1) | ||
return; | ||
newDeps.push(dep); | ||
@@ -39,3 +44,13 @@ }); | ||
}; | ||
// NB we should really extend this to any scope change | ||
// var define = x is the stopping point for handling a define | ||
// we still allow (function(define) {}) | ||
// these are the same rules of the r.js optimizer | ||
// var define disables until we quit the existing scope | ||
AMDDependenciesTransformer.prototype.transformVariableDeclaration = function(tree) { | ||
if (tree.lvalue.identifierToken.value == 'define') | ||
this.defineRedefined = true; | ||
return tree; | ||
}; | ||
// this catches the scope exit, although should be better handled than this (eg blocks for ES6) | ||
AMDDependenciesTransformer.prototype.transformFunctionDeclaration = function(tree) { | ||
@@ -48,5 +63,7 @@ var defineRedefined = this.defineRedefined; | ||
}; | ||
AMDDependenciesTransformer.prototype.transformVariableDeclaration = function(tree) { | ||
if (tree.lvalue.identifierToken.value == 'define') | ||
this.defineRedefined = true; | ||
AMDDependenciesTransformer.prototype.transformFunctionExpression = function(tree) { | ||
var defineRedefined = this.defineRedefined; | ||
tree = ParseTreeTransformer.prototype.transformFunctionExpression.call(this, tree); | ||
if (defineRedefined === false) | ||
this.defineRedefined = false; | ||
return tree; | ||
@@ -59,42 +76,59 @@ }; | ||
var args = tree.args.args; | ||
var name = args[0].type === 'LITERAL_EXPRESSION' && args[0].literalToken.processedValue; | ||
var name; | ||
var depArg = -1; | ||
if (args[0].type == 'LITERAL_EXPRESSION') { | ||
name = args[0].literalToken.processedValue; | ||
if (args[1] && args[1].type == 'ARRAY_LITERAL') | ||
depArg = 1; | ||
} | ||
else if (args[0].type == 'ARRAY_LITERAL') { | ||
depArg = 0; | ||
} | ||
var factoryArg = name && depArg == -1 ? 1 : depArg + 1; | ||
// ignore requires of the wrong form | ||
if (!args[factoryArg]) | ||
return ParseTreeTransformer.prototype.transformCallExpression.call(this, tree); | ||
// note the define index | ||
// so we know which one to name for the second pass | ||
if (!this.anonDefine || this.anonNamed) | ||
this.anonDefineIndex++; | ||
var parseDeps = false; | ||
// anonymous define | ||
if (!name) { | ||
if (this.anonDefine && !this.anonNamed) | ||
throw new Error('Multiple anonymous defines.'); | ||
this.anonDefine = true; | ||
this.anonNamed = false; | ||
parseDeps = true; | ||
} | ||
// named define | ||
else { | ||
// if we don't have any other defines, | ||
// then let this be an anonymous define | ||
if (!this.anonDefine && !this.defineBundle) | ||
this.bundleDefines.push(name); | ||
// remove any deps which exactly reference a name | ||
var depsIndex = this.deps.indexOf(name); | ||
if (depsIndex != -1) | ||
this.deps.splice(depsIndex, 1); | ||
if (!this.anonDefine && this.anonDefineIndex == 0) { | ||
this.anonDefine = true; | ||
// otherwise its a bundle only | ||
else { | ||
this.anonNamed = true; | ||
parseDeps = true; | ||
} | ||
else if (this.anonDefine && this.anonNamed) { | ||
this.anonDefine = false; | ||
this.anonNamed = false; | ||
this.deps = []; | ||
} | ||
// the above is just to support single modules of the form: | ||
// define('jquery') | ||
// still loading anonymously | ||
// because it is done widely enough to be useful | ||
// note this is now a bundle | ||
this.defineBundle = true; | ||
} | ||
// only continue to extracting dependencies if we're anonymous | ||
if (!this.anonDefine) | ||
return tree; | ||
// only continue to extracting dependencies if this is THE anonymous define | ||
if (!parseDeps) | ||
return ParseTreeTransformer.prototype.transformCallExpression.call(this, tree); | ||
var depArg; | ||
if (args[0].type === 'ARRAY_LITERAL') | ||
depArg = 0; | ||
else if (args[1] && args[1].type == 'ARRAY_LITERAL') | ||
depArg = 1; | ||
if (typeof depArg == 'number') { | ||
if (depArg != -1) { | ||
var deps = args[depArg].elements.map(function(dep) { | ||
@@ -119,15 +153,7 @@ return dep.literalToken.processedValue; | ||
return tree; | ||
return ParseTreeTransformer.prototype.transformCallExpression.call(this, tree); | ||
} | ||
var cjsFactory; | ||
if (args[0].type == 'FUNCTION_EXPRESSION') | ||
cjsFactory = args[0]; | ||
else if (args[0].type == 'LITERAL_EXPRESSION' && args[1] && args[1].type == 'FUNCTION_EXPRESSION') | ||
cjsFactory = args[1]; | ||
/* else if (args[0].type == 'IDENTIFIER_EXPRESSION') | ||
this.globalCJSRequires = true; */ | ||
if (cjsFactory) { | ||
if (depArg == -1 && args[factoryArg].type == 'FUNCTION_EXPRESSION') { | ||
var cjsFactory = args[factoryArg]; | ||
// now we need to do a scope transformer for the require function at this position | ||
@@ -144,5 +170,3 @@ var fnParameters = cjsFactory.parameterList.parameters; | ||
this.defineRedefined = true; | ||
return tree; | ||
return ParseTreeTransformer.prototype.transformCallExpression.call(this, tree); | ||
}; | ||
@@ -153,6 +177,8 @@ exports.AMDDependenciesTransformer = AMDDependenciesTransformer; | ||
// This is the second of the two pass transform | ||
function AMDDefineRegisterTransformer(moduleName, load, isAnon, depMap) { | ||
function AMDDefineRegisterTransformer(moduleName, load, anonDefine, anonDefineIndex, depMap) { | ||
this.name = moduleName; | ||
this.load = load; | ||
this.isAnon = isAnon; | ||
this.anonDefine = anonDefine; | ||
this.anonDefineIndex = anonDefineIndex; | ||
this.curDefineIndex = -1; | ||
this.depMap = depMap; | ||
@@ -165,2 +191,3 @@ this.defineRedefined = false; | ||
AMDDefineRegisterTransformer.prototype.transformFunctionDeclaration = AMDDependenciesTransformer.prototype.transformFunctionDeclaration; | ||
AMDDefineRegisterTransformer.prototype.transformFunctionExpression = AMDDependenciesTransformer.prototype.transformFunctionExpression; | ||
AMDDefineRegisterTransformer.prototype.transformCallExpression = function(tree) { | ||
@@ -171,51 +198,46 @@ if (this.defineRedefined || !tree.operand.identifierToken || tree.operand.identifierToken.value != 'define') | ||
var self = this; | ||
var args = tree.args.args; | ||
var name = this.name; | ||
// check for named modules | ||
if (args[0].type === 'LITERAL_EXPRESSION') { | ||
if (!this.isAnon) | ||
name = args[0].literalToken.processedValue; | ||
args = args.splice(1); | ||
var name; | ||
var depArg = -1; | ||
if (args[0].type == 'LITERAL_EXPRESSION') { | ||
name = args[0].literalToken.processedValue; | ||
if (args[1] && args[1].type == 'ARRAY_LITERAL') | ||
depArg = 1; | ||
} | ||
else if (args[0].type == 'ARRAY_LITERAL') { | ||
depArg = 0; | ||
} | ||
if (!args[0]) | ||
return; | ||
var factoryArg = name && depArg == -1 ? 1 : depArg + 1; | ||
// ignore requires of the wrong form | ||
// skip all named defines until we reach our anonymous define | ||
// then skip all further named defines | ||
if (!args[factoryArg] || ++this.curDefineIndex != this.anonDefineIndex) | ||
return ParseTreeTransformer.prototype.transformCallExpression.call(this, tree); | ||
var deps; | ||
var factoryTree; | ||
if (args[0].type === 'ARRAY_LITERAL') { | ||
deps = args[0].elements.map(function(dep) { | ||
return dep.literalToken.processedValue; | ||
var factoryTree = args[factoryArg]; | ||
// put together normalized deps array | ||
var deps = []; | ||
if (depArg != -1) { | ||
deps = args[depArg].elements.map(function(dep) { | ||
var depVal = dep.literalToken.processedValue; | ||
return self.depMap[depVal] || depVal; | ||
}); | ||
factoryTree = args[1]; | ||
// amend deps with any extra dependencies from metadata | ||
deps = deps.concat(this.load.deps.map(function(dep) { | ||
return self.depMap[dep] || dep; | ||
}).filter(function(dep) { | ||
return deps.indexOf(dep) == -1; | ||
})); | ||
} | ||
else if (args[0].type == 'OBJECT_LITERAL' || args[0].type == 'IDENTIFIER_EXPRESSION') { | ||
factoryTree = args[0]; | ||
else if (factoryTree.type == 'FUNCTION_EXPRESSION') { | ||
deps = ['require', 'exports', 'module'].splice(0, args[0].parameterList.parameters.length).concat(this.load.deps.map(function(dep) { | ||
return self.depMap[dep] || dep; | ||
})); | ||
} | ||
else if (args[0].type == 'FUNCTION_EXPRESSION') { | ||
// deps already parsed on trace | ||
deps = ['require', 'exports', 'module'].splice(0, args[0].parameterList.parameters.length).concat(this.load.deps); | ||
factoryTree = args[0]; | ||
} | ||
else if (args.length == 1) { | ||
// allow a define(some && expression || statement) for an object | ||
factoryTree = args[0]; | ||
} | ||
else { | ||
// not valid define | ||
return ParseTreeTransformer.prototype.transformCallExpression.call(this, tree); | ||
} | ||
deps = deps || []; | ||
// normalize existing dep array | ||
deps = deps.map(function(dep) { | ||
if (['require', 'exports', 'module'].indexOf(dep) != -1) | ||
return dep; | ||
return self.depMap[dep] || dep; | ||
}); | ||
// normalize CommonJS-style requires in body | ||
@@ -230,12 +252,18 @@ var requireIndex = deps.indexOf('require'); | ||
// ammend deps with extra dependencies from metadata or CJS trace | ||
deps = deps.concat(this.load.deps.map(function(dep) { | ||
return self.depMap[dep] || dep; | ||
}).filter(function(dep) { | ||
return deps.indexOf(dep) == -1; | ||
})); | ||
// support for single named modules as doubling as anonymous modules | ||
/* | ||
define('jquery', function() { | ||
... | ||
}) | ||
-> | ||
define('this:name', function() { | ||
... | ||
}), define('jquery', ['this:name'], function(m) { return m; }) | ||
*/ | ||
var nameAlias = ''; | ||
if (name && this.name && name != this.name) | ||
nameAlias = ', define("' + name + '", ["' + this.name + '"], function(m) { return m; })'; | ||
this.defineRedefined = true; | ||
return parseExpression(['define(' + (name ? '"' + name + '", ' : '') + (deps ? JSON.stringify(deps) + ', ' : ''), ');'], factoryTree); | ||
// write out the anonymous define as named and dep-normalized | ||
return parseExpression(['define(' + (this.name ? '"' + this.name + '", ' : '') + JSON.stringify(deps) + ', ', ')' + nameAlias + ';'], factoryTree); | ||
}; | ||
@@ -285,11 +313,5 @@ exports.AMDDefineRegisterTransformer = AMDDefineRegisterTransformer; | ||
// we store the results as meta | ||
load.metadata.isAnon = depTransformer.anonDefine; | ||
// load.metadata.globalCJSRequires = depTransformer.globalCJSRequires; | ||
load.metadata.anonDefine = depTransformer.anonDefine; | ||
load.metadata.anonDefineIndex = depTransformer.anonDefineIndex; | ||
/* if (depTransformer.globalCJSRequires) { | ||
var cjsRequires = new CJSRequireTransformer('require'); | ||
cjsRequires.transformAny(load.metadata.parseTree); | ||
depTransformer.deps = depTransformer.filterAMDDeps(cjsRequires.requires); | ||
} */ | ||
var entry = loader.defined[load.name]; | ||
@@ -346,7 +368,2 @@ entry.deps = dedupe(depTransformer.deps.concat(load.metadata.deps)); | ||
/* if (transformer.globalCJSRequires) { | ||
var cjsRequires = new CJSRequireTransformer('require', function(v) { return map[v] || v; }); | ||
tree = cjsRequires.transformAny(tree); | ||
} */ | ||
var output = compiler.write(tree); | ||
@@ -372,17 +389,11 @@ return Promise.resolve(output); | ||
var tree = load.metadata.parseTree || compiler.parse(load.source, load.path); | ||
var transformer = new AMDDefineRegisterTransformer(!opts.anonymous && load.name, load, load.metadata.isAnon, normalize ? load.depMap : {}); | ||
var transformer = new AMDDefineRegisterTransformer(!opts.anonymous && load.name, load, load.metadata.anonDefine, load.metadata.anonDefineIndex, normalize ? load.depMap : {}); | ||
tree = transformer.transformAny(tree); | ||
// normalize cjs requires | ||
/* if (load.metadata.globalCJSRequires) { | ||
var cjsRequires = new CJSRequireTransformer('require', normalize && function(v) { return load.depMap[v] || v; }); | ||
tree = cjsRequires.transformAny(tree); | ||
} */ | ||
var output = compiler.write(tree, load.path); | ||
// because we've blindly replaced the define statement from AMD with a System.registerDynamic call | ||
// we have to ensure we still trigger any AMD guard statements in the code by creating a dummy define which isn't called | ||
// AMD define extraction via parsing stops on var define redefinitions | ||
// so this creates a natural boundary to allow future folds of this same code through rebundling | ||
return Promise.resolve({ | ||
source: '(function() {\nvar _removeDefine = ' + opts.systemGlobal + '.get("@@amd-helpers").createDefine();\n' + output + '\n_removeDefine();\n})();', | ||
source: '(function() {\nvar define = ' + opts.systemGlobal + '.amdDefine;\n' + output + '\n})();', | ||
sourceMap: compiler.getSourceMap(), | ||
@@ -389,0 +400,0 @@ sourceMapOffset: 2 |
@@ -148,7 +148,5 @@ var path = require('path'); | ||
scriptItemList = useStrict.concat(parseStatements([ | ||
globalExpression + nl | ||
+ 'var global = this, __define = global.define;' + nl + 'global.define = undefined;' | ||
globalExpression + nl + 'var define;' + nl + 'var global = this;' + nl + 'var GLOBAL = this;' | ||
])).concat(scriptItemList).concat(parseStatements([ | ||
'global.define = __define;' + nl | ||
+ 'return module.exports;' | ||
'return module.exports;' | ||
])); | ||
@@ -155,0 +153,0 @@ |
@@ -149,3 +149,3 @@ var traceur = require('traceur'); | ||
var tree = load.metadata.parseTree || compiler.parse(load.source, load.path); | ||
var tree = load.metadata.parseTree || compiler.parse(source, load.path); | ||
@@ -152,0 +152,0 @@ if (opts.normalize) { |
@@ -94,3 +94,3 @@ var traceur = require('traceur'); | ||
for (var g in this.globals) { | ||
globalExpression += (first ? '' : ',') + nl + '"' + g + '": __require("' + this.globals[g] + '")'; | ||
globalExpression += (first ? '' : ',') + nl + '"' + g + '": $__require("' + this.globals[g] + '")'; | ||
first = false; | ||
@@ -102,4 +102,4 @@ } | ||
return new Script(tree.location, parseStatements([ | ||
this.systemGlobal + '.registerDynamic(' + (this.name ? '"' + this.name + '", ' : '') + JSON.stringify(this.deps) + ', false, function(__require, __exports, __module) {\n' | ||
+ 'var _retrieveGlobal = ' + this.systemGlobal + '.get("@@global-helpers").prepareGlobal(__module.id, ' | ||
this.systemGlobal + '.registerDynamic(' + (this.name ? '"' + this.name + '", ' : '') + JSON.stringify(this.deps) + ', false, function($__require, $__exports, $__module) {\n' | ||
+ 'var _retrieveGlobal = ' + this.systemGlobal + '.get("@@global-helpers").prepareGlobal($__module.id, ' | ||
+ (this.exportName ? '"' + this.exportName + '"' : 'null') + ', ' + (globalExpression ? globalExpression : 'null') + ');\n' | ||
@@ -106,0 +106,0 @@ + ' (', |
@@ -1,3 +0,1 @@ | ||
var getPackageConfigPath = require('../lib/utils').getPackageConfigPath; | ||
function hasProperties(obj) { | ||
@@ -17,3 +15,3 @@ for (var p in obj) | ||
if (isPackageConfig(loader, loader.decanonicalize(load.name))) | ||
if (load.isPackageConfig) | ||
json = optimizePackageConfig(json); | ||
@@ -65,23 +63,1 @@ | ||
// determine whether the given module name is a package config file | ||
var curHash; | ||
var configPathCache = {}; | ||
function isPackageConfig(loader, moduleName) { | ||
if (loader.configHash != curHash) { | ||
configPathCache = {}; | ||
curHash = loader.configHash; | ||
} | ||
if (configPathCache[moduleName]) | ||
return true; | ||
// repopulate config path cache | ||
Object.keys(loader.packages).forEach(function(pkgName) { | ||
var configPath = getPackageConfigPath(loader.packageConfigPaths, pkgName); | ||
if (configPath) | ||
configPathCache[configPath] = true; | ||
}); | ||
return !!configPathCache[moduleName]; | ||
} |
@@ -116,3 +116,4 @@ var asp = require('bluebird').promisify; | ||
else { | ||
return loader.normalize(operation.moduleName); | ||
// normalizeSync avoids package config loading which we don't want for wildcards | ||
return loader.normalizeSync(operation.moduleName); | ||
} | ||
@@ -119,0 +120,0 @@ }) |
@@ -538,3 +538,3 @@ var Promise = require('bluebird'); | ||
if (expressionOrTree instanceof Array) | ||
expressionOrTree = '[' + expressionOrTree.join('] [') + ']'; | ||
expressionOrTree = '[' + expressionOrTree.join('] + [') + ']'; | ||
@@ -575,5 +575,12 @@ if (typeof expressionOrTree != 'string') | ||
// if only one module is provided, it is an entry point | ||
var entryPoints; | ||
if (typeof expressionOrTree == 'string') | ||
entryPoints = [expressionOrTree.split(/ [\+\&\-] /)[0]]; | ||
else if (expressionOrTree instanceof Array) | ||
entryPoints = expressionOrTree[0]; | ||
var outputOpts = processOutputOpts(opts, { outFile: outFile }); | ||
var traceOpts = processTraceOpts(opts, { tracePackageConfig: false }); | ||
var compileOpts = processCompileOpts(opts, { static: true }); | ||
var compileOpts = processCompileOpts(opts, { static: true, entryPoints: entryPoints }); | ||
var inlineMap; | ||
@@ -588,3 +595,3 @@ | ||
if (expressionOrTree instanceof Array) | ||
expressionOrTree = '[' + expressionOrTree.join('] [') + ']'; | ||
expressionOrTree = '[' + expressionOrTree.join('] + [') + ']'; | ||
@@ -591,0 +598,0 @@ if (typeof expressionOrTree != 'string') |
@@ -191,4 +191,11 @@ var Promise = require('bluebird'); | ||
// compileOpts.entryPoints can be unnormalized | ||
var inputEntryPoints; | ||
if (compileOpts.entryPoints) | ||
inputEntryPoints = compileOpts.entryPoints.map(function(entryPoint) { | ||
return loader.getCanonicalName(loader.normalizeSync(entryPoint)); | ||
}); | ||
// get entrypoints from graph algorithm | ||
var entryPoints = compileOpts.entryPoints || []; | ||
var entryPoints = inputEntryPoints || []; | ||
@@ -375,4 +382,4 @@ ordered.entryPoints.forEach(function(entryPoint) { | ||
var externalDepIds = externalDeps.map(function(dep) { | ||
if (compileOpts.format == 'global' || compileOpts.format == 'umd' && (compileOpts.globalName || | ||
Object.keys(compileOpts.globalDeps).length > 0)) { | ||
if (compileOpts.format == 'global' || | ||
compileOpts.format == 'umd' && (compileOpts.globalName || Object.keys(compileOpts.globalDeps).length > 0)) { | ||
var alias = getAlias(loader, dep); | ||
@@ -398,6 +405,2 @@ var globalDep = compileOpts.globalDeps[dep] || compileOpts.globalDeps[alias]; | ||
if (compileOpts.globalName && globalDeps.length != externalDeps.length) { | ||
throw new Error('not enough globalDeps'); | ||
} | ||
// next wrap with the core code | ||
@@ -404,0 +407,0 @@ return asp(fs.readFile)(path.resolve(__dirname, (allRegister ? '../templates/sfx-core-register.min.js' : '../templates/sfx-core.min.js'))) |
@@ -88,3 +88,3 @@ var rollup = require('rollup'); | ||
optimizationPoints.push(entryPoint); | ||
}) | ||
}); | ||
@@ -281,3 +281,3 @@ /* | ||
// replace the entry point module itself with the inlined subgraph module | ||
var curInlined = inlineMap[entryPoint]; | ||
var curInlined = inlineMap[entryPoint] || []; | ||
@@ -300,3 +300,3 @@ // merge all external deps across all inlined modules | ||
if (inlinedModule.depMap[dep] != mergedDepMap[dep]) | ||
if (inlinedLoad.depMap[dep] != mergedDepMap[dep]) | ||
throw new Error('Duplicate dependency "' + dep + '" while using Rollup on "' + inlinedModule + '". Rename the dependency, or post to https://github.com/rollup/rollup/issues/424.'); | ||
@@ -331,2 +331,2 @@ } | ||
}); | ||
}; | ||
}; |
@@ -12,2 +12,3 @@ var getCanonicalName = require('./utils').getCanonicalName; | ||
var getPackageConfigPath = require('./utils').getPackageConfigPath; | ||
var isPackageConfig = require('./utils').isPackageConfig; | ||
@@ -109,2 +110,3 @@ module.exports = Trace; | ||
Trace.prototype.getLoadRecord = function(canonical, excludeURLs, parentStack) { | ||
var loader = this.loader; | ||
@@ -329,2 +331,3 @@ var loads = this.loads; | ||
packageConfig: null, | ||
isPackageConfig: isPackageConfig(loader, canonical), | ||
@@ -394,2 +397,3 @@ // these are only populated by the separate builder.getDeferredImports(tree) method | ||
if (load.metadata.format == 'esm' && !load.metadata.originalSource) { | ||
curHook = 'es module parsing'; | ||
var esmCompiler = require('../compilers/esm.js'); | ||
@@ -414,3 +418,3 @@ load.metadata.parseTree = esmCompiler.parse(source); | ||
// record package config paths | ||
if (getPackage(loader.packages, normalized)) { | ||
if (getPackage(loader.packages, normalized) && !load.isPackageConfig) { | ||
var packageConfigPath = getPackageConfigPath(loader.packageConfigPaths, normalized); | ||
@@ -465,8 +469,7 @@ if (packageConfigPath) { | ||
// rethrow loader hook errors with the hook information | ||
if (err instanceof Error) | ||
err.message = msg + '\n\t' + err.message; | ||
else | ||
err = msg + '\n\t' + err; | ||
throw err; | ||
var newMsg = msg + '\n\t' + (err.message || err); | ||
var newErr = new Error(newMsg, err.fileName, err.lineNumber); | ||
newErr.originalErr = err.originalErr || err; | ||
newErr.stack = msg + '\n\t' + (err.stack || err); | ||
throw newErr; | ||
}) | ||
@@ -473,0 +476,0 @@ .then(function() { |
@@ -75,16 +75,28 @@ var path = require('path'); | ||
var bestAliasLength = 0; | ||
var bestAliasSubpath; | ||
var bestAlias; | ||
Object.keys(loader.map).forEach(function(alias) { | ||
if (alias.split('/').length <= bestAliasLength) | ||
return; | ||
function getBestAlias(mapped) { | ||
return canonicalName.substr(0, mapped.length) == mapped && | ||
(canonicalName.length == mapped.length || canonicalName[mapped.length] == '/'); | ||
} | ||
// get mapped without defaultJSExtension | ||
var mapped = normalizePath(loader, loader.map[alias], true); | ||
Object.keys(loader.map).forEach(function(alias) { | ||
if (getBestAlias(loader.map[alias])) | ||
// do matching with defaultJSExtension checking | ||
if (loader.defaultJSExtensions && canonicalName == mapped + '.js') { | ||
bestAlias = alias; | ||
bestAliasSubpath = ''; | ||
bestAliasLength = alias.split('/').length; | ||
} | ||
else if (canonicalName.substr(0, mapped.length) == mapped && | ||
(canonicalName.length == mapped.length || canonicalName[mapped.length] == '/')) { | ||
bestAlias = alias; | ||
bestAliasSubpath = canonicalName.substr(alias.length); | ||
bestAliasLength = alias.split('/').length; | ||
} | ||
}); | ||
if (bestAlias) | ||
return bestAlias + canonicalName.substr(loader.map[bestAlias].length); | ||
return bestAlias + bestAliasSubpath; | ||
@@ -165,3 +177,3 @@ return canonicalName; | ||
var curPath = normalizePath(loader, p, isPlugin); | ||
var curPath = normalizePath(loader, loader.paths[p], isPlugin); | ||
@@ -186,3 +198,3 @@ // always stop on first exact match | ||
// normalize the output path | ||
var curPath = normalizePath(loader, p, true); | ||
var curPath = normalizePath(loader, loader.paths[p], true); | ||
@@ -256,2 +268,31 @@ // do reverse match | ||
// determine whether the given module name is a package config file | ||
exports.isPackageConfig = isPackageConfig; | ||
var curHash; | ||
var configPathCache = null; | ||
var canonicalConfigPaths = null; | ||
function isPackageConfig(loader, canonical) { | ||
if (loader.configHash != curHash) { | ||
configPathCache = null; | ||
curHash = loader.configHash; | ||
} | ||
// generate canonical packageConfigPaths for matching | ||
if (!configPathCache) { | ||
canonicalConfigPaths = loader.packageConfigPaths.map(function(configPath) { | ||
return getCanonicalName(loader, configPath); | ||
}); | ||
configPathCache = {}; | ||
} | ||
if (canonical in configPathCache) | ||
return configPathCache[canonical]; | ||
// check if the given canonical matches the canonical package config paths | ||
var cfgPathMatch = getPackageConfigPath(canonicalConfigPaths, canonical); | ||
configPathCache[canonical] = cfgPathMatch && cfgPathMatch.split('/').length == canonical.split('/').length; | ||
return configPathCache[canonical]; | ||
} | ||
exports.getPackage = getPackage; | ||
@@ -276,6 +317,6 @@ function getPackage(packages, name) { | ||
var curPath; | ||
if (loader.paths[path][0] == '.') | ||
curPath = decodeURI(url.resolve(toFileURL(process.cwd()) + '/', loader.paths[path])); | ||
if (path[0] == '.') | ||
curPath = decodeURI(url.resolve(toFileURL(process.cwd()) + '/', path)); | ||
else | ||
curPath = decodeURI(url.resolve(loader.baseURL, loader.paths[path])); | ||
curPath = decodeURI(url.resolve(loader.baseURL, path)); | ||
if (loader.defaultJSExtensions && !skipExtension && curPath.substr(curPath.length - 3, 3) != '.js') | ||
@@ -287,1 +328,3 @@ curPath += '.js'; | ||
{ | ||
"name": "systemjs-builder", | ||
"version": "0.15.9", | ||
"version": "0.15.10", | ||
"description": "SystemJS Build Tool", | ||
@@ -13,3 +13,3 @@ "main": "index.js", | ||
"source-map": "^0.5.3", | ||
"systemjs": "^0.19.22", | ||
"systemjs": "^0.19.23", | ||
"traceur": "0.0.102", | ||
@@ -16,0 +16,0 @@ "uglify-js": "^2.6.1" |
@@ -279,3 +279,3 @@ SystemJS Build Tool [![Build Status][travis-image]][travis-url] | ||
return Promise.all([ | ||
builder.bundle(commonTree, 'shared-bundle.js') | ||
builder.bundle(commonTree, 'shared-bundle.js'), | ||
builder.bundle(builder.subtractTrees(trees[0], commonTree), 'first-bundle.js'), | ||
@@ -282,0 +282,0 @@ builder.bundle(builder.subtractTrees(trees[1], commonTree), 'second-bundle.js') |
@@ -148,2 +148,4 @@ (function(__global) { | ||
}; | ||
// NB we should never output anonymomus in SFX though! | ||
@@ -153,4 +155,5 @@ // anonymous define | ||
// already defined anonymously -> throw | ||
if (lastModule.anonDefine) | ||
throw new TypeError('Multiple defines for anonymous module'); | ||
if (lastModule.anonDefine && !lastModule.anonDefine.name) | ||
throw new Error('Multiple anonymous defines in module ' + name); | ||
lastModule.anonDefine = define; | ||
@@ -166,15 +169,7 @@ } | ||
// because it is done widely enough to be useful | ||
if (!lastModule.anonDefine && !lastModule.isBundle) { | ||
if (!lastModule.anonDefine && !lastModule.isBundle) | ||
lastModule.anonDefine = define; | ||
} | ||
// otherwise its a bundle only | ||
else { | ||
// if there is an anonDefine already (we thought it could have had a single named define) | ||
// then we define it now | ||
// this is to avoid defining named defines when they are actually anonymous | ||
if (lastModule.anonDefine && lastModule.anonDefine.name) | ||
loader.registerDynamic(lastModule.anonDefine.name, lastModule.anonDefine.deps, false, lastModule.anonDefine.execute); | ||
else if (lastModule.anonDefine && lastModule.anonDefine.name) | ||
lastModule.anonDefine = null; | ||
} | ||
@@ -185,3 +180,3 @@ // note this is now a bundle | ||
// define the module through the register registry | ||
loader.registerDynamic(name, define.deps, false, define.execute); | ||
loader.registerDynamic(define.name, define.deps, false, define.execute); | ||
} | ||
@@ -191,23 +186,2 @@ } | ||
// adds define as a global (potentially just temporarily) | ||
function createDefine(loader) { | ||
lastModule.anonDefine = null; | ||
lastModule.isBundle = false; | ||
// ensure no NodeJS environment detection | ||
var oldModule = __global.module; | ||
var oldExports = __global.exports; | ||
var oldDefine = __global.define; | ||
__global.module = undefined; | ||
__global.exports = undefined; | ||
__global.define = define; | ||
return function() { | ||
__global.define = oldDefine; | ||
__global.module = oldModule; | ||
__global.exports = oldExports; | ||
}; | ||
} | ||
var lastModule = { | ||
@@ -218,10 +192,4 @@ isBundle: false, | ||
loader.set('@@amd-helpers', loader.newModule({ | ||
createDefine: createDefine, | ||
require: require, | ||
define: define, | ||
lastModule: lastModule | ||
})); | ||
loader.amdDefine = define; | ||
loader.amdRequire = require; | ||
})(typeof self != 'undefined' ? self : global); |
@@ -1,1 +0,1 @@ | ||
!function(e){function n(e,n){e=e.replace(l,"");var r=e.match(s),i=(r[1].split(",")[n]||"require").replace(p,""),t=c[i]||(c[i]=new RegExp(u+i+a,"g"));t.lastIndex=0;for(var o,f=[];o=t.exec(e);)f.push(o[2]||o[3]);return f}function r(e,n,i,t){if("object"==typeof e&&!(e instanceof Array))return r.apply(null,Array.prototype.splice.call(arguments,1,arguments.length-1));if("string"==typeof e&&"function"==typeof n&&(e=[e]),!(e instanceof Array)){if("string"==typeof e){var f=o.get(e);return f.__useDefault?f["default"]:f}throw new TypeError("Invalid require")}for(var l=[],u=0;u<e.length;u++)l.push(o["import"](e[u],t));Promise.all(l).then(function(e){n&&n.apply(null,e)},i)}function i(i,t,l){"string"!=typeof i&&(l=t,t=i,i=null),t instanceof Array||(l=t,t=["require","exports","module"].splice(0,l.length)),"function"!=typeof l&&(l=function(e){return function(){return e}}(l)),void 0===t[t.length-1]&&t.pop();var u,a,s;-1!=(u=f.call(t,"require"))&&(t.splice(u,1),i||(t=t.concat(n(l.toString(),u)))),-1!=(a=f.call(t,"exports"))&&t.splice(a,1),-1!=(s=f.call(t,"module"))&&t.splice(s,1);var p={name:i,deps:t,execute:function(n,i,f){for(var p=[],c=0;c<t.length;c++)p.push(n(t[c]));f.uri=f.id,f.config=function(){},-1!=s&&p.splice(s,0,f),-1!=a&&p.splice(a,0,i),-1!=u&&p.splice(u,0,function(e,i,t){return"string"==typeof e&&"function"!=typeof i?n(e):r.call(o,e,i,t,f.id)});var d=l.apply(-1==a?e:i,p);return"undefined"==typeof d&&f&&(d=f.exports),"undefined"!=typeof d?d:void 0}};if(i)d.anonDefine||d.isBundle?(d.anonDefine&&d.anonDefine.name&&o.registerDynamic(d.anonDefine.name,d.anonDefine.deps,!1,d.anonDefine.execute),d.anonDefine=null):d.anonDefine=p,d.isBundle=!0,o.registerDynamic(i,p.deps,!1,p.execute);else{if(d.anonDefine)throw new TypeError("Multiple defines for anonymous module");d.anonDefine=p}}function t(n){d.anonDefine=null,d.isBundle=!1;var r=e.module,t=e.exports,o=e.define;return e.module=void 0,e.exports=void 0,e.define=i,function(){e.define=o,e.module=r,e.exports=t}}var o=$__System,f=Array.prototype.indexOf||function(e){for(var n=0,r=this.length;r>n;n++)if(this[n]===e)return n;return-1},l=/(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/gm,u="(?:^|[^$_a-zA-Z\\xA0-\\uFFFF.])",a="\\s*\\(\\s*(\"([^\"]+)\"|'([^']+)')\\s*\\)",s=/\(([^\)]*)\)/,p=/^\s+|\s+$/g,c={};i.amd={};var d={isBundle:!1,anonDefine:null};o.set("@@amd-helpers",o.newModule({createDefine:t,require:r,define:i,lastModule:d})),o.amdDefine=i,o.amdRequire=r}("undefined"!=typeof self?self:global); | ||
!function(e){function n(e,n){e=e.replace(l,"");var r=e.match(u),t=(r[1].split(",")[n]||"require").replace(s,""),i=p[t]||(p[t]=new RegExp(a+t+f,"g"));i.lastIndex=0;for(var o,c=[];o=i.exec(e);)c.push(o[2]||o[3]);return c}function r(e,n,t,o){if("object"==typeof e&&!(e instanceof Array))return r.apply(null,Array.prototype.splice.call(arguments,1,arguments.length-1));if("string"==typeof e&&"function"==typeof n&&(e=[e]),!(e instanceof Array)){if("string"==typeof e){var l=i.get(e);return l.__useDefault?l["default"]:l}throw new TypeError("Invalid require")}for(var a=[],f=0;f<e.length;f++)a.push(i["import"](e[f],o));Promise.all(a).then(function(e){n&&n.apply(null,e)},t)}function t(t,l,a){"string"!=typeof t&&(a=l,l=t,t=null),l instanceof Array||(a=l,l=["require","exports","module"].splice(0,a.length)),"function"!=typeof a&&(a=function(e){return function(){return e}}(a)),void 0===l[l.length-1]&&l.pop();var f,u,s;-1!=(f=o.call(l,"require"))&&(l.splice(f,1),t||(l=l.concat(n(a.toString(),f)))),-1!=(u=o.call(l,"exports"))&&l.splice(u,1),-1!=(s=o.call(l,"module"))&&l.splice(s,1);var p={name:t,deps:l,execute:function(n,t,o){for(var p=[],c=0;c<l.length;c++)p.push(n(l[c]));o.uri=o.id,o.config=function(){},-1!=s&&p.splice(s,0,o),-1!=u&&p.splice(u,0,t),-1!=f&&p.splice(f,0,function(e,t,l){return"string"==typeof e&&"function"!=typeof t?n(e):r.call(i,e,t,l,o.id)});var d=a.apply(-1==u?e:t,p);return"undefined"==typeof d&&o&&(d=o.exports),"undefined"!=typeof d?d:void 0}};if(t)c.anonDefine||c.isBundle?c.anonDefine&&c.anonDefine.name&&(c.anonDefine=null):c.anonDefine=p,c.isBundle=!0,i.registerDynamic(p.name,p.deps,!1,p.execute);else{if(c.anonDefine&&!c.anonDefine.name)throw new Error("Multiple anonymous defines in module "+t);c.anonDefine=p}}var i=$__System,o=Array.prototype.indexOf||function(e){for(var n=0,r=this.length;r>n;n++)if(this[n]===e)return n;return-1},l=/(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/gm,a="(?:^|[^$_a-zA-Z\\xA0-\\uFFFF.])",f="\\s*\\(\\s*(\"([^\"]+)\"|'([^']+)')\\s*\\)",u=/\(([^\)]*)\)/,s=/^\s+|\s+$/g,p={};t.amd={};var c={isBundle:!1,anonDefine:null};i.amdDefine=t,i.amdRequire=r}("undefined"!=typeof self?self:global); |
@@ -52,7 +52,3 @@ (function(__global) { | ||
var curDefine = __global.define; | ||
__global.define = undefined; | ||
__global.exports = undefined; | ||
if (__global.module && __global.module.exports) | ||
__global.module = undefined; | ||
@@ -59,0 +55,0 @@ // set globals |
@@ -1,1 +0,1 @@ | ||
!function(e){function n(e,n){for(var t=e.split(".");t.length;)n=n[t.shift()];return n}function t(n){if(Object.keys)Object.keys(e).forEach(n);else for(var t in e)f.call(e,t)&&n(t)}function r(n){t(function(t){if(-1==a.call(l,t)){try{var r=e[t]}catch(o){l.push(t)}n(t,r)}})}var o,i=$__System,f=Object.prototype.hasOwnProperty,a=Array.prototype.indexOf||function(e){for(var n=0,t=this.length;t>n;n++)if(this[n]===e)return n;return-1},l=["_g","sessionStorage","localStorage","clipboardData","frames","frameElement","external","mozAnimationStartTime","webkitStorageInfo","webkitIndexedDB"];i.set("@@global-helpers",i.newModule({prepareGlobal:function(t,i,f){var a=e.define;e.define=void 0,e.exports=void 0,e.module&&e.module.exports&&(e.module=void 0);var l;if(f){l={};for(var u in f)l[u]=e[u],e[u]=f[u]}return i||(o={},r(function(e,n){o[e]=n})),function(){var t;if(i)t=n(i,e);else{var f,u,s={};r(function(e,n){o[e]!==n&&"undefined"!=typeof n&&(s[e]=n,"undefined"!=typeof f?u||f===n||(u=!0):f=n)}),t=u?s:f}if(l)for(var c in l)e[c]=l[c];return e.define=a,t}}}))}("undefined"!=typeof self?self:global); | ||
!function(e){function n(e,n){for(var t=e.split(".");t.length;)n=n[t.shift()];return n}function t(n){if(Object.keys)Object.keys(e).forEach(n);else for(var t in e)o.call(e,t)&&n(t)}function r(n){t(function(t){if(-1==a.call(l,t)){try{var r=e[t]}catch(f){l.push(t)}n(t,r)}})}var f,i=$__System,o=Object.prototype.hasOwnProperty,a=Array.prototype.indexOf||function(e){for(var n=0,t=this.length;t>n;n++)if(this[n]===e)return n;return-1},l=["_g","sessionStorage","localStorage","clipboardData","frames","frameElement","external","mozAnimationStartTime","webkitStorageInfo","webkitIndexedDB"];i.set("@@global-helpers",i.newModule({prepareGlobal:function(t,i,o){var a=e.define;e.define=void 0;var l;if(o){l={};for(var c in o)l[c]=e[c],e[c]=o[c]}return i||(f={},r(function(e,n){f[e]=n})),function(){var t;if(i)t=n(i,e);else{var o,c,u={};r(function(e,n){f[e]!==n&&"undefined"!=typeof n&&(u[e]=n,"undefined"!=typeof o?c||o===n||(c=!0):o=n)}),t=c?u:o}if(l)for(var s in l)e[s]=l[s];return e.define=a,t}}}))}("undefined"!=typeof self?self:global); |
@@ -135,2 +135,14 @@ var Builder = require('../index'); | ||
.then(function() { | ||
return builder.bundle('amd-9.js', 'test/output/amd-9.js'); | ||
}) | ||
.then(function() { | ||
return builder.bundle('amd-10.js', 'test/output/amd-10.js'); | ||
}) | ||
.then(function() { | ||
return builder.bundle('amd-11.js', 'test/output/amd-11.js'); | ||
}) | ||
.then(function() { | ||
builder.loader.config({ paths: { 'output/*': './test/output/*' } }); | ||
@@ -137,0 +149,0 @@ return builder.bundle('cjs-globals.js - output/amd-8.js', 'test/output/cjs-globals.js'); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
275685
121
5952
29
Updatedsystemjs@^0.19.23