enhanced-resolve
Advanced tools
Comparing version 0.7.5 to 0.7.6
@@ -28,2 +28,6 @@ /* | ||
} catch(e) { | ||
if(callback.log) | ||
callback.log(descriptionFilePath + " (directory description file): " + e); | ||
else | ||
e.message = descriptionFilePath + " (directory description file): " + e; | ||
return callback(e); | ||
@@ -30,0 +34,0 @@ } |
@@ -32,2 +32,4 @@ /* | ||
callback.log(descriptionFilePath + " (directory description file): " + e); | ||
else | ||
e.message = descriptionFilePath + " (directory description file): " + e; | ||
return callback(e); | ||
@@ -34,0 +36,0 @@ } |
@@ -5,121 +5,2 @@ /* | ||
*/ | ||
function MemoryInputFileSystem(data) { | ||
this.data = data || {}; | ||
} | ||
module.exports = MemoryInputFileSystem; | ||
MemoryInputFileSystem.prototype.stat = function(path, callback) { | ||
try { | ||
return callback(null, this.statSync(path)); | ||
} catch(e) { | ||
return callback(e); | ||
} | ||
}; | ||
MemoryInputFileSystem.prototype.readdir = function(path, callback) { | ||
try { | ||
return callback(null, this.readdirSync(path)); | ||
} catch(e) { | ||
return callback(e); | ||
} | ||
}; | ||
MemoryInputFileSystem.prototype.readFile = function(path, callback) { | ||
try { | ||
return callback(null, this.readFileSync(path)); | ||
} catch(e) { | ||
return callback(e); | ||
} | ||
}; | ||
function isDir(item) { | ||
if(typeof item != "object") return false; | ||
return item[""] === true; | ||
} | ||
function isFile(item) { | ||
if(typeof item == "string") return true; | ||
if(typeof item != "object") return false; | ||
return !item[""]; | ||
} | ||
function pathToArray(path) { | ||
var nix = /^\//.test(path); | ||
if(!nix) { | ||
if(!/^[A-Za-z]:\\/.test(path)) throw new Error("Invalid path " + path); | ||
path = path.replace(/\\/g, "/"); | ||
} | ||
path = path.replace(/\/+/g, "/"); // multi slashs | ||
path = (nix ? path.substr(1) : path).split("/"); | ||
return path; | ||
} | ||
function trueFn() { return true } | ||
function falseFn() { return false } | ||
MemoryInputFileSystem.prototype.statSync = function(_path) { | ||
var path = pathToArray(_path); | ||
var current = this.data; | ||
for(var i = 0; i < path.length - 1; i++) { | ||
if(!isDir(current[path[i]])) | ||
throw new Error("Path doesn't exists " + _path); | ||
current = current[path[i]]; | ||
} | ||
if(_path === "/" || isDir(current[path[i]])) { | ||
return { | ||
isFile: falseFn, | ||
isDirectory: trueFn, | ||
isBlockDevice: falseFn, | ||
isCharacterDevice: falseFn, | ||
isSymbolicLink: falseFn, | ||
isFIFO: falseFn, | ||
isSocket: falseFn | ||
}; | ||
} else if(isFile(current[path[i]])) { | ||
return { | ||
isFile: trueFn, | ||
isDirectory: falseFn, | ||
isBlockDevice: falseFn, | ||
isCharacterDevice: falseFn, | ||
isSymbolicLink: falseFn, | ||
isFIFO: falseFn, | ||
isSocket: falseFn | ||
}; | ||
} else | ||
throw new Error("Path doesn't exists " + _path); | ||
}; | ||
MemoryInputFileSystem.prototype.readFileSync = function(_path) { | ||
var path = pathToArray(_path); | ||
var current = this.data; | ||
for(var i = 0; i < path.length - 1; i++) { | ||
if(!isDir(current[path[i]])) | ||
throw new Error("Path doesn't exists " + _path); | ||
current = current[path[i]]; | ||
} | ||
if(!isFile(current[path[i]])) { | ||
if(isDir(current[path[i]])) | ||
throw new Error("Cannot readFile on directory " + _path); | ||
else | ||
throw new Error("File doesn't exists " + _path); | ||
} | ||
return current[path[i]]; | ||
}; | ||
MemoryInputFileSystem.prototype.readdirSync = function(_path) { | ||
if(_path === "/") return Object.keys(this.data).filter(Boolean); | ||
var path = pathToArray(_path); | ||
var current = this.data; | ||
for(var i = 0; i < path.length - 1; i++) { | ||
if(!isDir(current[path[i]])) | ||
throw new Error("Path doesn't exists " + _path); | ||
current = current[path[i]]; | ||
} | ||
if(!isDir(current[path[i]])) { | ||
if(isFile(current[path[i]])) | ||
throw new Error("Cannot readFile on file " + _path); | ||
else | ||
throw new Error("File doesn't exists " + _path); | ||
} | ||
return Object.keys(current[path[i]]).filter(Boolean); | ||
}; | ||
module.exports = require("memory-fs"); |
@@ -80,3 +80,3 @@ /* | ||
if(types[0] === "result") return callback(null, request); | ||
var error = new Error("Cannot resolve " + types[0] + " " + request.request + " in " + request.path); | ||
var error = new Error("Cannot resolve " + types[0] + " '" + request.request + "' in " + request.path); | ||
error.details = logAsString(); | ||
@@ -89,6 +89,7 @@ return callback(error); | ||
} | ||
// For multiple type we have to ignore the error | ||
// For multiple type we list the errors in the details although some of them are not important | ||
this.forEachBail(types, function(type, callback) { | ||
this.applyPluginsParallelBailResult(type, request, createInnerCallback(function(err, result) { | ||
if(!err && result) return callback(result); | ||
if (err) log.push(" " + err.message); | ||
callback(); | ||
@@ -101,3 +102,3 @@ }, { | ||
if(callback.log) { | ||
callback.log("resolve " + types.join(" or ") + " " + currentRequestString); | ||
callback.log("resolve '" + types.join("' or '") + "' " + currentRequestString); | ||
for(var i = 0; i < log.length; i++) | ||
@@ -108,3 +109,3 @@ callback.log(" " + log[i]); | ||
if(result) return callback(null, result); | ||
var error = new Error("Cannot resolve " + types.join(" or ") + " " + currentRequestString); | ||
var error = new Error("Cannot resolve '" + types.join("' or '") + "' " + currentRequestString); | ||
error.details = logAsString(); | ||
@@ -111,0 +112,0 @@ return callback(error); |
{ | ||
"name": "enhanced-resolve", | ||
"version": "0.7.5", | ||
"version": "0.7.6", | ||
"author": "Tobias Koppers @sokra", | ||
@@ -8,2 +8,3 @@ "description": "Offers a async require.resolve function. It's highly configurable.", | ||
"tapable": "0.1.x", | ||
"memory-fs": "~0.1.0", | ||
"graceful-fs": "~2.0.3" | ||
@@ -28,3 +29,7 @@ }, | ||
"test": "mocha --reporter spec" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/webpack/enhanced-resolve.git" | ||
} | ||
} | ||
} |
@@ -7,3 +7,3 @@ var Resolver = require("../lib/Resolver"); | ||
var FileAppendPlugin = require("../lib/FileAppendPlugin"); | ||
var MemoryInputFileSystem = require("../lib/MemoryInputFileSystem"); | ||
var MemoryFileSystem = require("memory-fs"); | ||
var should = require("should"); | ||
@@ -15,10 +15,11 @@ | ||
beforeEach(function() { | ||
var fileSystem = new MemoryInputFileSystem({ | ||
var buf = new Buffer(""); | ||
var fileSystem = new MemoryFileSystem({ | ||
"": true, | ||
a: { | ||
"": true, | ||
index: "", | ||
index: buf, | ||
dir: { | ||
"": true, | ||
index: "" | ||
index: buf | ||
} | ||
@@ -28,6 +29,6 @@ }, | ||
"": true, | ||
index: "", | ||
index: buf, | ||
dir: { | ||
"": true, | ||
index: "" | ||
index: buf | ||
} | ||
@@ -37,6 +38,6 @@ }, | ||
"": true, | ||
index: "", | ||
index: buf, | ||
dir: { | ||
"": true, | ||
index: "" | ||
index: buf | ||
} | ||
@@ -46,6 +47,6 @@ }, | ||
"": true, | ||
index: "", | ||
index: buf, | ||
dir: { | ||
"": true, | ||
index: "" | ||
index: buf | ||
} | ||
@@ -52,0 +53,0 @@ } |
@@ -1,2 +0,2 @@ | ||
var MemoryInputFileSystem = require("../lib/MemoryInputFileSystem"); | ||
var MemoryFileSystem = require("memory-fs"); | ||
var should = require("should"); | ||
@@ -8,10 +8,10 @@ | ||
beforeEach(function() { | ||
fileSystem = new MemoryInputFileSystem({ | ||
fileSystem = new MemoryFileSystem({ | ||
"": true, | ||
a: { | ||
"": true, | ||
index: "1", // /a/index | ||
index: new Buffer("1"), // /a/index | ||
dir: { | ||
"": true, | ||
index: "2" // /a/dir/index | ||
index: new Buffer("2") // /a/dir/index | ||
} | ||
@@ -23,6 +23,6 @@ }, | ||
"": true, | ||
index: "3", // C:\files\index | ||
index: new Buffer("3"), // C:\files\index | ||
dir: { | ||
"": true, | ||
index: "4" // C:\files\a\index | ||
index: new Buffer("4") // C:\files\a\index | ||
} | ||
@@ -50,4 +50,4 @@ } | ||
it("should readdir directories", function() { | ||
fileSystem.readFileSync("/a/index").should.be.eql("1"); | ||
fileSystem.readFileSync("/a/dir/index").should.be.eql("2"); | ||
fileSystem.readFileSync("/a/index", "utf-8").should.be.eql("1"); | ||
fileSystem.readFileSync("/a/dir/index", "utf-8").should.be.eql("2"); | ||
}); | ||
@@ -75,4 +75,4 @@ it("should also accept multi slashs", function() { | ||
it("should readdir directories", function() { | ||
fileSystem.readFileSync("C:\\a\\index").should.be.eql("3"); | ||
fileSystem.readFileSync("C:\\a\\dir\\index").should.be.eql("4"); | ||
fileSystem.readFileSync("C:\\a\\index", "utf-8").should.be.eql("3"); | ||
fileSystem.readFileSync("C:\\a\\dir\\index", "utf-8").should.be.eql("4"); | ||
}); | ||
@@ -79,0 +79,0 @@ it("should also accept multi slashs", function() { |
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
4
58406
3
1541
+ Addedmemory-fs@~0.1.0
+ Addedmemory-fs@0.1.1(transitive)