webpack-core
Advanced tools
Comparing version 0.4.8 to 0.5.0
@@ -5,20 +5,35 @@ /* | ||
*/ | ||
var SourceMapNodeSource = require("./SourceMapNodeSource"); | ||
var SourceMapNodeFastSource = require("./SourceMapNodeFastSource"); | ||
var SourceNode = require("source-map").SourceNode; | ||
function ConcatSource() { | ||
var node = new SourceNode(null, null, null, []); | ||
SourceMapNodeSource.call(this, node); | ||
Array.prototype.slice.call(arguments).forEach(function(item) { | ||
this.add(item); | ||
}, this); | ||
this.children = Array.prototype.slice.call(arguments); | ||
SourceMapNodeFastSource.call(this); | ||
} | ||
module.exports = ConcatSource; | ||
ConcatSource.prototype = Object.create(SourceMapNodeSource.prototype); | ||
ConcatSource.prototype = Object.create(SourceMapNodeFastSource.prototype); | ||
ConcatSource.prototype.constructor = ConcatSource; | ||
ConcatSource.prototype._bakeSource = function() { | ||
return this.children.map(function(item) { | ||
return typeof item === "string" ? item : item.source(); | ||
}).join(""); | ||
}; | ||
ConcatSource.prototype._bake = function() { | ||
var node = new SourceNode(null, null, null, this.children.map(function(item) { | ||
return typeof item === "string" ? item : item.node(); | ||
})); | ||
return node; | ||
}; | ||
ConcatSource.prototype.add = function(item) { | ||
if(typeof item === "string") | ||
this._node.add(item); | ||
else | ||
this._node.add(item.node()); | ||
this.children.push(item); | ||
if(this._node) { | ||
if(typeof item === "string") | ||
this._node.add(item); | ||
else | ||
this._node.add(item.node()); | ||
} | ||
}; |
@@ -9,3 +9,3 @@ /* | ||
if(element === null || typeof element !== "object") | ||
throw new Error("Each element of the loaders list must be an object"); | ||
throw new Error("Each element of the loaders list must be an object or array"); | ||
}); | ||
@@ -15,25 +15,49 @@ } | ||
/* | ||
function regExpAsMatcher(regExp) { | ||
return function(str) { | ||
return regExp.test(str); | ||
} | ||
} | ||
# matchRegExpObject(obj, str) | ||
tests if "str" matches "obj" with the following format: | ||
{ | ||
test: PART, | ||
include: PART, | ||
exclude: PART | ||
function asMatcher(test) { | ||
if(typeof test === "string") { | ||
return regExpAsMatcher(new RegExp("^"+test.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"))); | ||
} else if(typeof test === "function") { | ||
return test; | ||
} else if(test instanceof RegExp) { | ||
return regExpAsMatcher(test); | ||
} else if(Array.isArray(test)) { | ||
var matchers = test.map(function(item) { | ||
if(Array.isArray(item)) { | ||
var matchers = item.map(asMatcher); | ||
return function(str) { | ||
return matchers.every(function(matcher) { | ||
return matcher(str); | ||
}); | ||
}; | ||
} else { | ||
return asMatcher(item); | ||
} | ||
}); | ||
return function(str) { | ||
for(var i = 0; i < test.length; i++) { | ||
if(matchers[i](str)) | ||
return true; | ||
} | ||
return false; | ||
}; | ||
} else { | ||
throw new Error(test + " is not a valid test"); | ||
} | ||
} | ||
PART can be | ||
* string -> new RegExp(string) | ||
* RegExp | ||
* array of string of RegExp | ||
array is OR | ||
*/ | ||
function asRegExp(test) { | ||
if(typeof test == "string") test = new RegExp("^"+test.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&")); | ||
return test; | ||
function getLoadersFromObject(element) { | ||
if(element.query) { | ||
if(!element.loader || element.loader.indexOf("!") >= 0) throw new Error("Cannot define 'query' and multiple loaders in loaders list"); | ||
if(typeof element.query === "string") return [element.loader + "?" + element.query]; | ||
return [element.loader + "?" + JSON.stringify(element.query)]; | ||
} | ||
if(element.loader) return element.loader.split("!"); | ||
if(element.loaders) return element.loaders; | ||
throw new Error("Element from loaders list should have one of the fields 'loader' or 'loaders'"); | ||
} | ||
@@ -43,23 +67,18 @@ | ||
if(!test) return true; | ||
test = asRegExp(test); | ||
if(Array.isArray(test)) { | ||
return test.map(asRegExp).filter(function(regExp) { | ||
return regExp.test(str); | ||
}).length > 0; | ||
} else { | ||
return test.test(str); | ||
} | ||
var matcher = asMatcher(test); | ||
return matcher(str); | ||
}; | ||
LoadersList.prototype.match = function match(str) { | ||
return this.list.filter(this.matchObject.bind(this, str)).map(function(element) { | ||
if(element.query) { | ||
if(!element.loader || element.loader.indexOf("!") >= 0) throw new Error("Cannot define 'query' and multiple loaders in loaders list"); | ||
if(typeof element.query === "string") return [element.loader + "?" + element.query]; | ||
return [element.loader + "?" + JSON.stringify(element.query)]; | ||
return this.list.map(function(element) { | ||
if(Array.isArray(element)) { | ||
for(var i = 0; i < element.length; i++) { | ||
if(this.matchObject(str, element[i])) | ||
return getLoadersFromObject(element[i]); | ||
} | ||
} else { | ||
if(this.matchObject(str, element)) | ||
return getLoadersFromObject(element); | ||
} | ||
if(element.loader) return element.loader.split("!"); | ||
if(element.loaders) return element.loaders; | ||
throw new Error("Element from loaders list should have one of the fields 'loader' or 'loaders'"); | ||
}).reduce(function(array, r) { | ||
}, this).filter(Boolean).reduce(function(array, r) { | ||
r.forEach(function(r) { | ||
@@ -66,0 +85,0 @@ array.push(r); |
@@ -190,3 +190,18 @@ /* | ||
} else { | ||
l.module = require(l.path); | ||
try { | ||
l.module = require(l.path); | ||
} catch (e) { | ||
// it is possible for node to choke on a require if the FD descriptor | ||
// limit has been reached. give it a chance to recover. | ||
if (e instanceof Error && e.code === 'EMFILE') { | ||
if (typeof setImmediate === 'function') { | ||
// node >= 0.9.0 | ||
return setImmediate(loadPitch.bind(this)); | ||
} else { | ||
// node < 0.9.0 | ||
return process.nextTick(loadPitch.bind(this)); | ||
} | ||
} | ||
throw e; | ||
} | ||
} | ||
@@ -193,0 +208,0 @@ } else if(typeof __webpack_require_loader__ === "function") { |
@@ -64,2 +64,3 @@ /* | ||
OriginalSource.prototype = Object.create(SourceMapNodeSource.prototype); | ||
OriginalSource.prototype.constructor = OriginalSource; | ||
OriginalSource.prototype.source = function() { | ||
@@ -66,0 +67,0 @@ return this._value; |
@@ -5,16 +5,29 @@ /* | ||
*/ | ||
var SourceMapNodeSource = require("./SourceMapNodeSource"); | ||
var SourceMapNodeFastSource = require("./SourceMapNodeFastSource"); | ||
var SourceNode = require("source-map").SourceNode; | ||
function PrefixSource(prefix, source) { | ||
var node = source.node(); | ||
var append = [prefix]; | ||
node = new SourceNode(null, null, null, [ | ||
this._cloneAndPrefix(node, prefix, append) | ||
]); | ||
SourceMapNodeSource.call(this, node); | ||
this._source = source; | ||
this._prefix = prefix; | ||
SourceMapNodeFastSource.call(this); | ||
} | ||
module.exports = PrefixSource; | ||
PrefixSource.prototype = Object.create(SourceMapNodeSource.prototype); | ||
PrefixSource.prototype = Object.create(SourceMapNodeFastSource.prototype); | ||
PrefixSource.prototype.constructor = PrefixSource; | ||
PrefixSource.prototype._bakeSource = function() { | ||
var node = typeof this._source === "string" ? this._source : this._source.source(); | ||
var prefix = this._prefix; | ||
return prefix + node.replace(/\n(.)/g, "\n" + prefix + "$1"); | ||
}; | ||
PrefixSource.prototype._bake = function() { | ||
var node = this._source.node(); | ||
var append = [this._prefix]; | ||
return new SourceNode(null, null, null, [ | ||
this._cloneAndPrefix(node, this._prefix, append) | ||
]); | ||
}; | ||
PrefixSource.prototype._cloneAndPrefix = function cloneAndPrefix(node, prefix, append) { | ||
@@ -21,0 +34,0 @@ if(typeof node === "string") { |
@@ -14,2 +14,3 @@ /* | ||
RawSource.prototype = Object.create(Source.prototype); | ||
RawSource.prototype.constructor = RawSource; | ||
RawSource.prototype._bake = function() { | ||
@@ -19,2 +20,2 @@ return { | ||
}; | ||
}; | ||
}; |
@@ -17,2 +17,3 @@ /* | ||
ReplaceSource.prototype = Object.create(SourceMapNodeSource.prototype); | ||
ReplaceSource.prototype.constructor = ReplaceSource; | ||
@@ -93,2 +94,2 @@ ReplaceSource.prototype.replace = function(start, end, newValue) { | ||
} | ||
}; | ||
}; |
@@ -15,2 +15,3 @@ /* | ||
SourceMapNodeSource.prototype = Object.create(Source.prototype); | ||
SourceMapNodeSource.prototype.constructor = SourceMapNodeSource; | ||
SourceMapNodeSource.prototype._bake = function() { | ||
@@ -51,3 +52,7 @@ throw new Error("Overwrite or pass valid SourceNode to constructor"); | ||
function updateHashForNode(node, hash) { | ||
hash.update(node.source + ""); | ||
// We don't include the source in the hash, | ||
// because it may contain an absolute path and | ||
// the hash shouldn't be bound on absolute paths | ||
// That way we may miss some information, but how cares ;) | ||
// not <hash.update(node.source + "");> | ||
hash.update(node.line + ""); | ||
@@ -54,0 +59,0 @@ hash.update(node.column + ""); |
@@ -26,2 +26,3 @@ /* | ||
SourceMapSource.prototype = Object.create(SourceMapNodeSource.prototype); | ||
SourceMapSource.prototype.constructor = SourceMapSource; | ||
SourceMapSource.prototype.source = function() { | ||
@@ -28,0 +29,0 @@ return this._value; |
{ | ||
"name": "webpack-core", | ||
"version": "0.4.8", | ||
"version": "0.5.0", | ||
"author": "Tobias Koppers @sokra", | ||
"description": "The core of webpack and enhanced-require.", | ||
"dependencies": { | ||
"source-map": "~0.1.38" | ||
"source-map": "~0.4.1" | ||
}, | ||
@@ -23,3 +23,3 @@ "licenses": [ | ||
"homepage": "http://github.com/webpack/core", | ||
"repository": { | ||
"repository": { | ||
"type": "git", | ||
@@ -26,0 +26,0 @@ "url" : "https://github.com/webpack/core.git" |
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
32864
21
961
+ Addedsource-map@0.4.4(transitive)
- Removedsource-map@0.1.43(transitive)
Updatedsource-map@~0.4.1