Comparing version 4.4.2 to 4.5.0
# Change Log | ||
## 4.5.0 | ||
* Updates for Node 10 compatibility ([#237][#237]) | ||
* Throw ENOENT in readlink when item is missing (thanks @deployable, see [#232][#232]) | ||
* Add path to errors when it exists (thanks @deployable, see [#230][#230]) | ||
## 4.4.2 | ||
@@ -209,1 +215,4 @@ | ||
[#222]: https://github.com/tschaub/mock-fs/pull/222 | ||
[#230]: https://github.com/tschaub/mock-fs/pull/230 | ||
[#232]: https://github.com/tschaub/mock-fs/pull/232 | ||
[#237]: https://github.com/tschaub/mock-fs/pull/237 |
@@ -12,7 +12,18 @@ 'use strict'; | ||
var getPathParts = require('./filesystem').getPathParts; | ||
var bufferFrom = require('./buffer').from; | ||
var bufferAlloc = require('./buffer').alloc; | ||
/** Workaround for optimizations in node 8 */ | ||
/** Workaround for optimizations in node 8+ */ | ||
var fsBinding = process.binding('fs'); | ||
var statValues = fsBinding.getStatValues ? fsBinding.getStatValues() : []; | ||
var statValues; | ||
if (fsBinding.statValues) { | ||
statValues = fsBinding.statValues; // node 10 | ||
} else if (fsBinding.getStatValues) { | ||
statValues = fsBinding.getStatValues(); // node 8 | ||
} else { | ||
statValues = []; | ||
} | ||
var MAX_LINKS = 50; | ||
/** | ||
@@ -96,2 +107,5 @@ * Call the provided function and either return the result or call the callback | ||
} | ||
// node 10 expects an array internally | ||
// see https://github.com/nodejs/node/pull/19714 | ||
fillStatsArray(config, this); | ||
} | ||
@@ -282,3 +296,3 @@ | ||
if (encoding === 'buffer') { | ||
realPath = new Buffer(realPath); | ||
realPath = bufferFrom(realPath); | ||
} | ||
@@ -293,3 +307,3 @@ return realPath; | ||
* https://github.com/nodejs/node/blob/4e05952a8a75af6df625415db612d3a9a1322682/src/node_file.cc#L533 | ||
* @param {object} stats An object with file stats | ||
* @param {Object} stats An object with file stats | ||
* @param {Float64Array} statValues A Float64Array where stat values should be inserted | ||
@@ -509,3 +523,3 @@ * @returns {void} | ||
if (content.length < newLength) { | ||
var tempContent = new Buffer(newLength); | ||
var tempContent = bufferAlloc(newLength); | ||
content.copy(tempContent); | ||
@@ -557,3 +571,3 @@ content = tempContent; | ||
if (content.length < newLength) { | ||
var newContent = new Buffer(newLength); | ||
var newContent = bufferAlloc(newLength); | ||
content.copy(newContent); | ||
@@ -602,3 +616,3 @@ content = newContent; | ||
) { | ||
var buffer = new Buffer(string, encoding); | ||
var buffer = bufferFrom(string, encoding); | ||
var wrapper; | ||
@@ -691,3 +705,3 @@ if (callback) { | ||
list = list.map(function(item) { | ||
return new Buffer(item); | ||
return bufferFrom(item); | ||
}); | ||
@@ -802,3 +816,3 @@ } | ||
if (encoding === 'buffer') { | ||
uniquePath = new Buffer(uniquePath); | ||
uniquePath = bufferFrom(uniquePath); | ||
} | ||
@@ -826,3 +840,3 @@ return uniquePath; | ||
var content = file.getContent(); | ||
var newContent = new Buffer(len); | ||
var newContent = bufferAlloc(len); | ||
content.copy(newContent); | ||
@@ -1048,2 +1062,5 @@ file.setContent(newContent); | ||
var link = this._system.getItem(pathname); | ||
if (!link) { | ||
throw new FSError('ENOENT', pathname); | ||
} | ||
if (!(link instanceof SymbolicLink)) { | ||
@@ -1054,3 +1071,3 @@ throw new FSError('EINVAL', pathname); | ||
if (encoding === 'buffer') { | ||
linkPath = new Buffer(linkPath); | ||
linkPath = bufferFrom(linkPath); | ||
} | ||
@@ -1097,2 +1114,11 @@ return linkPath; | ||
var item = this._system.getItem(filepath); | ||
var links = 0; | ||
while (item instanceof SymbolicLink) { | ||
if (links > MAX_LINKS) { | ||
throw new FSError('ELOOP', filepath); | ||
} | ||
filepath = path.resolve(path.dirname(filepath), item.getPath()); | ||
item = this._system.getItem(filepath); | ||
++links; | ||
} | ||
if (!item) { | ||
@@ -1099,0 +1125,0 @@ throw new FSError('ENOENT', filepath); |
@@ -265,2 +265,5 @@ 'use strict'; | ||
this.errno = details.errno; | ||
if (path !== undefined) { | ||
this.path = path; | ||
} | ||
Error.captureStackTrace(this, FSError); | ||
@@ -267,0 +270,0 @@ } |
@@ -6,4 +6,6 @@ 'use strict'; | ||
var Item = require('./item'); | ||
var bufferFrom = require('./buffer').from; | ||
var bufferAlloc = require('./buffer').alloc; | ||
var EMPTY = new Buffer(0); | ||
var EMPTY = bufferAlloc(0); | ||
var constants = require('constants'); | ||
@@ -41,3 +43,3 @@ | ||
if (typeof content === 'string') { | ||
content = new Buffer(content); | ||
content = bufferFrom(content); | ||
} else if (!Buffer.isBuffer(content)) { | ||
@@ -44,0 +46,0 @@ throw new Error('File content must be a string or buffer'); |
{ | ||
"name": "mock-fs", | ||
"description": "A configurable mock file system. You know, for testing.", | ||
"version": "4.4.2", | ||
"version": "4.5.0", | ||
"main": "lib/index.js", | ||
@@ -6,0 +6,0 @@ "homepage": "https://github.com/tschaub/mock-fs", |
@@ -17,3 +17,3 @@ # `mock-fs` | ||
}, | ||
'path/to/some.png': new Buffer([8, 6, 7, 5, 3, 0, 9]), | ||
'path/to/some.png': Buffer.from([8, 6, 7, 5, 3, 0, 9]), | ||
'some/other/path': {/** another empty directory */} | ||
@@ -110,3 +110,3 @@ }); | ||
file1: 'text content', | ||
file2: new Buffer([1, 2, 3, 4]) | ||
file2: Buffer.from([1, 2, 3, 4]) | ||
} | ||
@@ -140,3 +140,3 @@ } | ||
file1: 'file one content', | ||
file2: new Buffer([8, 6, 7, 5, 3, 0, 9]) | ||
file2: Buffer.from([8, 6, 7, 5, 3, 0, 9]) | ||
} | ||
@@ -211,4 +211,4 @@ }) | ||
Tested on Linux, OSX, and Windows using Node 0.10 through 8.x. Check the tickets for a list of [known issues](https://github.com/tschaub/mock-fs/issues). | ||
Tested on Linux, OSX, and Windows using Node 0.10 through 10.x. Check the tickets for a list of [known issues](https://github.com/tschaub/mock-fs/issues). | ||
[](https://travis-ci.org/tschaub/mock-fs) |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
275114
35
8089
10