Comparing version 0.3.6 to 0.3.7
@@ -231,3 +231,49 @@ /* | ||
} | ||
var cjsRequireRegEx = /require\s*\(\s*("([^"]+)"|'([^']+)')\s*\)/g; | ||
jspmUtil.mapCJSDependencies = function(source, replaceMap) { | ||
return source.replace(cjsRequireRegEx, function(reqName, str, singleString, doubleString) { | ||
var name = singleString || doubleString; | ||
if (replaceMap[name]) | ||
return reqName.replace(name, replaceMap[name].replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&")); | ||
else | ||
return reqName; | ||
}); | ||
} | ||
var amdDefineRegEx = /(?:^\s*|[}{\(\);,\n\?\&]\s*)define\s*\(\s*("[^"]+"\s*,|'[^']+'\s*,\s*)?(\[.+\])/; | ||
jspmUtil.mapAMDDependencies = function(source, replaceMap) { | ||
var match = amdDefineRegEx.exec(source); | ||
if (match) { | ||
var innerDefine = match[2]; | ||
var newInnerDefine = innerDefine; | ||
for (var name in replaceMap) { | ||
var mapped = replaceMap[name]; | ||
if (mapped != name) { | ||
changed = true; | ||
name = name.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); | ||
newInnerDefine = newInnerDefine.replace(new RegExp('"' + name + '"|\'' + name + '\'', 'g'), '\'' + mapped + '\''); | ||
} | ||
} | ||
return source.replace(innerDefine, newInnerDefine); | ||
} | ||
else | ||
return source; | ||
} | ||
var es6DepRegEx = /(^|\}|\s)(from|import)\s*("([^"]+)"|'([^']+)')/g; | ||
jspmUtil.mapES6Dependencies = function(source, replaceMap) { | ||
return source.replace(es6DepRegEx, function(match, start, type, str, singleString, doubleString) { | ||
var name = singleString || doubleString; | ||
if (replaceMap[name]) | ||
return match.replace(name, replaceMap[name].replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&")); | ||
else | ||
return match; | ||
}); | ||
} | ||
jspmUtil.processDependencies = function(repoPath, packageOptions, callback, errback) { | ||
// glob. replace map dependency strings (basic string replacement). at the same time, extract external dependencies. | ||
@@ -272,4 +318,7 @@ glob(repoPath + path.sep + '**' + path.sep + '*.js', function(err, files) { | ||
var depStrs = ''; | ||
for (var i = 0; i < shimDeps.imports.length; i++) | ||
depStrs += '"import ' + shimDeps.imports[i] + '";\n'; | ||
if (typeof shimDeps.imports == 'string') | ||
shimDeps.imports = [shimDeps.imports]; | ||
if (shimDeps.imports) | ||
for (var i = 0; i < shimDeps.imports.length; i++) | ||
depStrs += '"import ' + shimDeps.imports[i] + '";\n'; | ||
@@ -284,11 +333,28 @@ if (shimDeps.exports) | ||
// apply dependency map | ||
for (var name in packageOptions.dependencyMap) { | ||
var mapped = packageOptions.dependencyMap[name]; | ||
if (mapped != name) { | ||
changed = true; | ||
name = name.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); | ||
source = source.replace(new RegExp('"' + name + '"|\'' + name + '\'', 'g'), '\'' + mapped + '\''); | ||
} | ||
// CJS | ||
// require('name') -> require('new-name'); | ||
var newSource = jspmUtil.mapCJSDependencies(source, packageOptions.dependencyMap); | ||
if (newSource) { | ||
source = newSource; | ||
changed = true; | ||
} | ||
// ES6 | ||
// from 'name' -> from 'new-name' | ||
// import 'name' -> import 'new-name' | ||
newSource = jspmUtil.mapES6Dependencies(source, packageOptions.dependencyMap); | ||
if (newSource) { | ||
source = newSource; | ||
changed = true; | ||
} | ||
// AMD | ||
// require(['names', 'are', 'here']) -> require(['new', 'names', 'here']) | ||
newSource = jspmUtil.mapAMDDependencies(source, packageOptions.dependencyMap); | ||
if (newSource) { | ||
source = newSource; | ||
changed = true; | ||
} | ||
// parse out external dependencies | ||
@@ -434,3 +500,3 @@ var imports = (jspmLoader.link(source, {}) || jspmLoader._link(source, {})).imports; | ||
errors += file + ':\n'; | ||
errors += err + '\n'; | ||
errors += JSON.stringify(err) + '\n'; | ||
// revert to original | ||
@@ -510,4 +576,5 @@ return fs.rename(originalFile, file, function() { | ||
})('uglify', source, null, buildOptions.uglify || {}, fileName, originalFileName, function(err, source, sourceMap) { | ||
if (err) | ||
if (err) { | ||
return fileComplete(err, file, originalFile); | ||
} | ||
@@ -514,0 +581,0 @@ // if the first line is not a comment |
{ | ||
"name": "jspm", | ||
"description": "", | ||
"version": "0.3.6", | ||
"version": "0.3.7", | ||
"main": "./jspm-util.js", | ||
@@ -6,0 +6,0 @@ "author": "", |
@@ -16,5 +16,11 @@ { | ||
"webfont@1.3.0": "cdnjs:webfont@1.3.0", | ||
"backbone": "github:jashkenas/backbone@1.1.0", | ||
"backbone": "npm:backbone@1.1.0", | ||
"underscore": "npm:underscore@1.5.2", | ||
"npm:underscore@1.5": "npm:underscore@1.5.2" | ||
"npm:underscore@1.5": "npm:underscore@1.5.2", | ||
"d3": "npm:d3@3.3.10", | ||
"npm:backbone": "npm:backbone@1.1.0", | ||
"npm:underscore": "npm:underscore@1.5.2", | ||
"jquery@2.0": "github:components/jquery@2.0.3", | ||
"underscore@1.5": "npm:underscore@1.5.2", | ||
"bootstrap": "github:twbs/bootstrap@3.0.2" | ||
}, | ||
@@ -26,2 +32,2 @@ "buildConfig": { | ||
} | ||
} | ||
} |
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
81438
1680