Comparing version 2.0.1 to 2.0.2
@@ -11,41 +11,27 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var constants_1 = require("./constants"); | ||
var node_1 = require("./node"); | ||
var volume_1 = require("./volume"); | ||
exports.constants = constants_1.constants; | ||
exports.F_OK = constants_1.constants.F_OK; | ||
exports.R_OK = constants_1.constants.R_OK; | ||
exports.W_OK = constants_1.constants.W_OK; | ||
exports.X_OK = constants_1.constants.X_OK; | ||
var volume = require("./volume"); | ||
var _a = require('fs-money/lib/util/lists'), fsSyncMethods = _a.fsSyncMethods, fsAsyncMethods = _a.fsAsyncMethods; | ||
var constants_1 = require("./constants"); | ||
var F_OK = constants_1.constants.F_OK, R_OK = constants_1.constants.R_OK, W_OK = constants_1.constants.W_OK, X_OK = constants_1.constants.X_OK; | ||
exports.Volume = volume_1.Volume; | ||
// Default volume. | ||
exports.vol = new volume_1.Volume; | ||
// List of `fs.js` methods, used to export bound (`.bind`) method list, just like `require('fs')` would do. | ||
var FS_METHODS = [ | ||
'open', 'openSync', | ||
'close', 'closeSync', | ||
'readFile', 'readFileSync', | ||
'write', 'writeSync', | ||
'writeFile', 'writeFileSync', | ||
'link', 'linkSync', | ||
'unlink', 'unlinkSync', | ||
'symlink', 'symlinkSync', | ||
'realpath', 'realpathSync', | ||
'stat', 'statSync', | ||
'lstat', 'lstatSync', | ||
'fstat', 'fstatSync', | ||
'rename', 'renameSync', | ||
'exists', 'existsSync', | ||
'access', 'accessSync', | ||
'readdir', 'readdirSync', | ||
'watchFile', 'unwatchFile', | ||
'createReadStream', | ||
]; | ||
function createFsFromVolume(volume) { | ||
var fs = {}; | ||
function createFsFromVolume(vol) { | ||
var fs = { F_OK: F_OK, R_OK: R_OK, W_OK: W_OK, X_OK: X_OK, constants: constants_1.constants, Stats: node_1.Stats }; | ||
// Bind FS methods. | ||
for (var _i = 0, FS_METHODS_1 = FS_METHODS; _i < FS_METHODS_1.length; _i++) { | ||
var method = FS_METHODS_1[_i]; | ||
fs[method] = volume[method].bind(volume); | ||
for (var _i = 0, fsSyncMethods_1 = fsSyncMethods; _i < fsSyncMethods_1.length; _i++) { | ||
var method = fsSyncMethods_1[_i]; | ||
fs[method] = vol[method].bind(vol); | ||
} | ||
fs.Stats = node_1.Stats; | ||
for (var _a = 0, fsAsyncMethods_1 = fsAsyncMethods; _a < fsAsyncMethods_1.length; _a++) { | ||
var method = fsAsyncMethods_1[_a]; | ||
fs[method] = vol[method].bind(vol); | ||
} | ||
fs.StatWatcher = volume_1.StatWatcher.bind(null, vol); | ||
fs.FSWatcher = volume_1.FSWatcher.bind(null, vol); | ||
fs.WriteStream = volume.WriteStream.bind(null, vol); | ||
fs.ReadStream = volume.ReadStream.bind(null, vol); | ||
fs._toUnixTimestamp = volume_1.toUnixTimestamp; | ||
return fs; | ||
@@ -52,0 +38,0 @@ } |
@@ -91,2 +91,39 @@ "use strict"; | ||
}); | ||
it('Specify export path', function () { | ||
var vol = volume_1.Volume.fromJSON({ | ||
'/foo': 'bar', | ||
'/dir/a': 'b', | ||
}); | ||
chai_1.expect(vol.toJSON('/dir')).to.eql({ | ||
'/dir/a': 'b', | ||
}); | ||
}); | ||
it('Specify multiple export paths', function () { | ||
var vol = volume_1.Volume.fromJSON({ | ||
'/foo': 'bar', | ||
'/dir/a': 'b', | ||
'/dir2/a': 'b', | ||
'/dir2/c': 'd', | ||
}); | ||
chai_1.expect(vol.toJSON(['/dir2', '/dir'])).to.eql({ | ||
'/dir/a': 'b', | ||
'/dir2/a': 'b', | ||
'/dir2/c': 'd', | ||
}); | ||
}); | ||
it('Accumulate exports on supplied object', function () { | ||
var vol = volume_1.Volume.fromJSON({ | ||
'/foo': 'bar', | ||
}); | ||
var obj = {}; | ||
chai_1.expect(vol.toJSON('/', obj)).to.equal(obj); | ||
}); | ||
it('Export empty volume', function () { | ||
var vol = volume_1.Volume.fromJSON({}); | ||
chai_1.expect(vol.toJSON()).to.eql({}); | ||
}); | ||
it('Exporting non-existing path', function () { | ||
var vol = volume_1.Volume.fromJSON({}); | ||
chai_1.expect(vol.toJSON('/lol')).to.eql({}); | ||
}); | ||
}); | ||
@@ -109,3 +146,3 @@ describe('.fromJSON(json[, cwd])', function () { | ||
}; | ||
vol.fromJSON(json); | ||
vol.fromJSON(json, '/'); | ||
chai_1.expect(vol.toJSON()).to.eql({ | ||
@@ -508,2 +545,28 @@ '/hello': 'world', | ||
}); | ||
describe('Complex, deep, multi-step symlinks get resolved', function () { | ||
it('Symlink to a folder', function () { | ||
var vol = volume_1.Volume.fromJSON({ '/a1/a2/a3/a4/a5/hello.txt': 'world!' }); | ||
vol.symlinkSync('/a1', '/b1'); | ||
chai_1.expect(vol.readFileSync('/b1/a2/a3/a4/a5/hello.txt', 'utf8')).to.equal('world!'); | ||
}); | ||
it('Symlink to a folder to a folder', function () { | ||
var vol = volume_1.Volume.fromJSON({ '/a1/a2/a3/a4/a5/hello.txt': 'world!' }); | ||
vol.symlinkSync('/a1', '/b1'); | ||
vol.symlinkSync('/b1', '/c1'); | ||
vol.openSync('/c1/a2/a3/a4/a5/hello.txt', 'r'); | ||
}); | ||
it('Multiple hops to folders', function () { | ||
var vol = volume_1.Volume.fromJSON({ | ||
'/a1/a2/a3/a4/a5/hello.txt': 'world a', | ||
'/b1/b2/b3/b4/b5/hello.txt': 'world b', | ||
'/c1/c2/c3/c4/c5/hello.txt': 'world c', | ||
}); | ||
vol.symlinkSync('/a1/a2', '/b1/l'); | ||
vol.symlinkSync('/b1/l', '/b1/b2/b3/ok'); | ||
vol.symlinkSync('/b1/b2/b3/ok', '/c1/a'); | ||
vol.symlinkSync('/c1/a', '/c1/c2/c3/c4/c5/final'); | ||
vol.openSync('/c1/c2/c3/c4/c5/final/a3/a4/a5/hello.txt', 'r'); | ||
chai_1.expect(vol.readFileSync('/c1/c2/c3/c4/c5/final/a3/a4/a5/hello.txt', 'utf8')).to.equal('world a'); | ||
}); | ||
}); | ||
}); | ||
@@ -510,0 +573,0 @@ describe('.symlink(target, path[, type], callback)', function () { |
{ | ||
"name": "memfs", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "In-memory file-system with Node's fs API.", | ||
"main": "lib/index.js", | ||
"keywords": [ | ||
"fs", "fs.js", "memory-fs", "memfs", | ||
"file", "file system", "mount", "memory", | ||
"in-memory", "virtual", "test", "testing", "mock"], | ||
"fs", | ||
"fs.js", | ||
"memory-fs", | ||
"memfs", | ||
"file", | ||
"file system", | ||
"mount", | ||
"memory", | ||
"in-memory", | ||
"virtual", | ||
"test", | ||
"testing", | ||
"mock" | ||
], | ||
"repository": { | ||
"type" : "git", | ||
"url" : "https://github.com/streamich/memfs.git" | ||
"type": "git", | ||
"url": "https://github.com/streamich/memfs.git" | ||
}, | ||
"scripts": { | ||
"build": "npm run build-ts && npm run build-js", | ||
"build-ts": "./node_modules/.bin/gulp build-ts", | ||
"build-js": "./node_modules/.bin/babel src --out-dir lib", | ||
"test": "npm run test-coverage", | ||
"test-basic": "./node_modules/.bin/mocha --require ts-node/register src/**/*.test.ts src/**/*.test.tsx", | ||
"test-watch": "./node_modules/.bin/mocha --require ts-node/register src/**/*.test.ts src/**/*.test.tsx --watch", | ||
"test-coverage": "nyc --per-file mocha --require ts-node/register --require source-map-support/register --full-trace --bail src/**/*.test.ts" | ||
"build": "npm run build-ts && npm run build-js", | ||
"build-ts": "./node_modules/.bin/gulp build-ts", | ||
"build-js": "./node_modules/.bin/babel src --out-dir lib", | ||
"test": "npm run test-coverage", | ||
"test-basic": "./node_modules/.bin/mocha --require ts-node/register src/**/*.test.ts src/**/*.test.tsx", | ||
"test-watch": "./node_modules/.bin/mocha --require ts-node/register src/**/*.test.ts src/**/*.test.tsx --watch", | ||
"test-coverage": "nyc --per-file mocha --require ts-node/register --require source-map-support/register --full-trace --bail src/**/*.test.ts" | ||
}, | ||
"dependencies": { | ||
"fast-extend": "0.0.2" | ||
"fast-extend": "0.0.2", | ||
"fs-monkey": "0.1.1" | ||
}, | ||
@@ -37,3 +49,2 @@ "devDependencies": { | ||
"nyc": "11.1.0", | ||
"@types/mocha": "2.2.41", | ||
@@ -40,0 +51,0 @@ "@types/chai": "4.0.1", |
@@ -116,7 +116,14 @@ # memfs 2.0 | ||
`vol` is an instance of `Volume` constructor, it is a default volume created | ||
for your convenience. `fs` in and *fs-like* object created from `vol` using | ||
for your convenience. `fs` in an *fs-like* object created from `vol` using | ||
`createFsFromVolume(vol)`, see reference below. | ||
#### `Volume` | ||
All contents of the `fs` object are also exported individually, so you can use | ||
`memfs` just like you would `fs` module: | ||
```js | ||
import {readFileSync, F_OK, ReadStream} from 'memfs'; | ||
``` | ||
#### `Volume` Constructor | ||
`Volume` is a constructor function for creating new volumes: | ||
@@ -194,4 +201,27 @@ | ||
#### FS API Status | ||
#### `createFsFromVolume(vol)` | ||
Returns an *fs-like* object created from a `Volume` instance `vol. | ||
```js | ||
import {createFsFromVolume, Volume} from 'memfs'; | ||
const vol = new Volume; | ||
const fs = createFsFromVolume(vol); | ||
``` | ||
The idea behind the *fs-like* object is to make it identical to the one | ||
you get from `require('fs')`. Here are some things this function does: | ||
- Binds all methods, so you can do: | ||
```js | ||
const {createFileSync, readFileSync} = fs; | ||
``` | ||
- Adds constructor functions `fs.Stats`, `fs.ReadStream`, `fs.WriteStream`, `fs.FileWatcher`, `fs.FSWatcher`. | ||
- Adds constants `fs.constants`, `fs.F_OK`, etc. | ||
# API Status | ||
- [x] Constants | ||
@@ -288,1 +318,32 @@ - [x] `FSWatcher` | ||
[fs-monkey]: https://github.com/streamich/fs-monkey | ||
# License | ||
This is free and unencumbered software released into the public domain. | ||
Anyone is free to copy, modify, publish, use, compile, sell, or | ||
distribute this software, either in source code form or as a compiled | ||
binary, for any purpose, commercial or non-commercial, and by any | ||
means. | ||
In jurisdictions that recognize copyright laws, the author or authors | ||
of this software dedicate any and all copyright interest in the | ||
software to the public domain. We make this dedication for the benefit | ||
of the public at large and to the detriment of our heirs and | ||
successors. We intend this dedication to be an overt act of | ||
relinquishment in perpetuity of all present and future rights to this | ||
software under copyright law. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. | ||
For more information, please refer to <http://unlicense.org/> |
Sorry, the diff of this file is too big to display
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
297243
4025
347
0
2
1
+ Addedfs-monkey@0.1.1
+ Addedfs-monkey@0.1.1(transitive)