Skip to content

Commit

Permalink
Merge pull request #1 from streamich/develop
Browse files Browse the repository at this point in the history
v2.0
  • Loading branch information
streamich authored Aug 13, 2017
2 parents 8e6f36f + bc78907 commit 769fde7
Show file tree
Hide file tree
Showing 18 changed files with 633 additions and 149 deletions.
8 changes: 8 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"presets": ["es2015"],
"comments": false,
"ignore": [
"spec.js",
"test.js"
]
}
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.idea
node_modules
/.idea
.nyc_output
coverage
package-lock.json
yarn.lock
13 changes: 13 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
example.js
hello-world.js
*.ts
/typings
example.js
tsd.json
simple.js
node_modules
/test
.idea
.idea/
.nyc_output
coverage
package-lock.json
yarn.lock
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8.2.1
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: node_js
node_js:
- "8"
cache:
yarn: true
directories:
- "node_modules"
87 changes: 70 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,80 @@
# linkfs

Rewrite file system `fs` paths.
Redirects filesystem paths.

```javascript
var linkfs = require('linkfs');
var fs = require('fs');
[![][npm-img]][npm-url]

var mylinkfs = linkfs(fs, {'/mylib.com': __dirname});
// Now you can do:
console.log(mylinkfs.readFileSync('/mylib.com/index.js').toString());
npm install --save linkfs

```js
import {link} from 'linkfs';
import {fs} from 'memfs';

fs.writeFileSync('/foo', 'bar');
const lfs = link(fs, ['/foo2', '/foo']);
console.log(lfs.readFileSync('/foo2', 'utf8')); // bar
```

Use it together with [`unionfs`](http://www.npmjs.com/package/unionfs) to overwrite the original `fs` module.
# Reference

### `link(fs, rewrites)`

This way you can create custom `require` paths:
Returns a new *fs-like* object with redirected file paths.

```javascript
var unionfs = require('unionfs');
`fs` is the source *fs-like* object.

unionfs
.use(fs)
.use(mylinkfs)
.replace(fs);
require('/mylib.com/index.js');
`rewrites` is a 2-tuple or an array of 2-tuples, where each 2-tuple
has a form of `[from, to]`. `from` is the new, *virtual* path; and `to`
is an existing path in the `fs` filesystem.

```js
const lfs = link(fs, ['/foo', '/bar']);
```

or

```js
const lfs = link(fs, [
['/foo1', '/bar1'],
['/foo2', '/bar2'],
['/foo3', '/bar3'],
]);
```

[npm-url]: https://www.npmjs.com/package/linkfs
[npm-img]: https://img.shields.io/npm/v/linkfs.svg
[memfs]: https://github.com/streamich/memfs
[unionfs]: https://github.com/streamich/unionfs
[linkfs]: https://github.com/streamich/linkfs
[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/>
7 changes: 7 additions & 0 deletions demo/example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {link} from '../src';
import {Volume} from '../../memfs/src';


const vol = Volume.fromJSON({'/foo': 'bar'});
const linkfs = link(vol, [['/foo2', '/foo']]);
console.log(linkfs.readFileSync('/foo2', 'utf8'));
24 changes: 24 additions & 0 deletions demo/multiple-rewrites.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {link} from '../src';
import {Volume} from '../../memfs/src';


const vol = Volume.fromJSON({'/foo/bar': 'hello'});
const lfs = link(vol, [
['/a', '/lol/bar'],
['/lol', '/abc'],
['/abc', '/foo'],
['/hello', '/foo/bar'],
]);


console.log(lfs.readFileSync('/abc/bar', 'utf8'));


console.log(lfs.readFileSync('/lol/bar', 'utf8'));


console.log(lfs.readFileSync('/hello', 'utf8'));


console.log(lfs.readFileSync('/a', 'utf8'));

21 changes: 0 additions & 21 deletions example.js

This file was deleted.

15 changes: 15 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var gulp = require('gulp');
var ts = require('gulp-typescript');


gulp.task('build-ts', function () {
return gulp.src('src/**/*.ts')
.pipe(ts({
"target": "es5",
"module": "commonjs",
"removeComments": false,
"noImplicitAny": false,
"sourceMap": false,
}))
.pipe(gulp.dest('lib'));
});
2 changes: 0 additions & 2 deletions hello-world.js

This file was deleted.

103 changes: 0 additions & 103 deletions index.js

This file was deleted.

Loading

0 comments on commit 769fde7

Please sign in to comment.