This commit is contained in:
tatianamac
2019-11-26 14:50:43 -08:00
parent 8a55660ed0
commit 6d5445ecc5
13894 changed files with 2233957 additions and 0 deletions

16
node_modules/find/.travis.yml generated vendored Normal file
View File

@ -0,0 +1,16 @@
language: node_js
node_js:
- '11'
- '10'
- '8'
- '6'
os:
- linux
- osx
- windows
matrix:
allow_failures:
- os: windows
sudo: false

22
node_modules/find/LICENSE generated vendored Normal file
View File

@ -0,0 +1,22 @@
(The MIT License)
Copyright (c) 2013-2018 Yuan Chuan <yuanchuan23@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
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 OR COPYRIGHT HOLDERS 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.

137
node_modules/find/README.md generated vendored Normal file
View File

@ -0,0 +1,137 @@
# find [![Status](https://travis-ci.org/yuanchuan/find.svg?branch=master)](https://travis-ci.org/yuanchuan/find "See test builds")
Find files or directories by name.
[![NPM](https://nodei.co/npm/find.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/find/)
## Installation
```bash
$ npm install --save find
```
## Examples
Find all files in current directory.
```javascript
var find = require('find');
find.file(__dirname, function(files) {
console.log(files.length);
})
```
Filter by regular expression.
```javascript
find.file(/\.js$/, __dirname, function(files) {
console.log(files.length);
})
```
## Features
* Recursively search each sub-directories
* Asynchronously or synchronously
* Filtering by regular expression or string comparing
## Changelog
#### 0.3.0
* Added `.use()` method
#### 0.2.0
* The first `pattern` option is now optional
* Will follow symbolic links
## API
#### .file([pattern,] root, callback)
```javascript
find.file(__dirname, function(files) {
//
})
```
#### .dir([pattern,] root, callback)
```javascript
find.dir(__dirname, function(dirs) {
//
})
```
#### .eachfile([pattern,] root, action)
```javascript
find.eachfile(__dirname, function(file) {
//
})
```
#### .eachdir([pattern,] root, action)
```javascript
find.eachdir(__dirname, function(dir) {
//
})
```
#### .fileSync([pattern,] root)
```javascript
var files = find.fileSync(__dirname);
```
#### .dirSync([pattern,] root)
```javascript
var dirs = find.dirSync(__dirname);
```
#### .error([callback])
Handling errors in asynchronous interfaces
```javascript
find
.file(__dirname, function(file) {
//
})
.error(function(err) {
if (err) {
//
}
})
```
#### .end([callback])
Detect `end` in `find.eachfile` and `find.eachdir`
```javascript
find
.eachfile(__dirname, function(file) {
//
})
.end(function() {
console.log('find end');
})
```
#### .use(Options)
* `fs`: The internal fs object to be used.
```javascript
const { fs, vol } = require('memfs');
const json = {
'./README.md': '1',
'./src/index.js': '2'
};
vol.fromJSON(json, '/app');
find
.use({ fs: fs })
.file('/app', console.log);
```

425
node_modules/find/index.js generated vendored Normal file
View File

@ -0,0 +1,425 @@
var fs = require('fs');
var path = require('path');
var Chain = require('traverse-chain');
/**
* Outline the APIs.
*/
var find = module.exports = {
// file: function([pat,] root, callback) {}
// dir: function([pat,] root, callback) {}
// eachfile: function([pat,] root, action) {}
// eachdir: function([pat,] root, action) {}
// fileSync: function([pat,] root) {}
// dirSync: function([pat,] root) {}
// use:: function(options) {}
};
var fss = {};
/**
* Error handler wrapper.
*/
fss.errorHandler = function(err) {
if (err) {
if (find.__errorHandler) {
find.__errorHandler(err);
} else {
throw err;
}
}
};
var error = {
notExist: function(name) {
return new Error(name + ' does not exist.');
}
};
var is = (function() {
function existed(name) {
return fs.existsSync(name);
}
function fsType(type) {
return function(name) {
try {
return fs.lstatSync(name)['is' + type]();
} catch(err) {
if (!/^(EPERM|EACCES)$/.test(err.code)) {
fss.errorHandler(err);
}
else {
console.warn('Warning: Cannot access %s', name);
}
}
}
}
function objType(type) {
return function(input) {
if (type === 'Function') {
return typeof input === 'function';
}
return ({}).toString.call(input) === '[object ' + type + ']';
}
}
return {
existed: existed,
file: fsType('File'),
directory: fsType('Directory'),
symbolicLink: fsType('SymbolicLink'),
string: objType('String'),
regexp: objType('RegExp'),
func: objType('Function')
};
}());
/**
* Method injection for handling errors.
*/
['readdir', 'lstat'].forEach(function(method) {
fss[method] = function(path, callback) {
var origin = fs[method];
return origin.apply(fs, [path, function(err) {
fss.errorHandler(err);
return callback.apply(null, arguments);
}]);
}
});
/**
* Enhancement for fs.readlink && fs.readlinkSync.
*/
fss.readlink = function(name, fn, depth) {
if (depth == undefined) depth = 5;
if (!is.existed(name) && (depth < 5)) {
return fn(path.resolve(name));
}
var isSymbolicLink = is.symbolicLink(name);
if (!isSymbolicLink) {
fn(path.resolve(name));
} else if (depth) {
fs.realpath(name, function(err, origin) {
if (err && /^(ENOENT|ELOOP|EPERM|EACCES)$/.test(err.code)) {
fn(name);
} else {
if (err) {
fss.errorHandler(err);
} else {
fss.readlink(origin, fn, --depth);
}
}
});
} else {
fn(isSymbolicLink ? '' : path.resolve(name));
}
}
fss.readlinkSync = function(name, depth) {
if (depth == undefined) depth = 5;
if (!is.existed(name) && depth < 5) {
return path.resolve(name);
}
var isSymbolicLink = is.symbolicLink(name);
if (!isSymbolicLink) {
return path.resolve(name);
} else if (depth) {
var origin;
try {
origin = fs.realpathSync(name);
} catch (err) {
if (/^(ENOENT|ELOOP|EPERM|EACCES)$/.test(err.code)) {
return name;
} else {
fss.errorHandler(err);
}
}
return fss.readlinkSync(origin, --depth);
} else {
return isSymbolicLink ? '' : path.resolve(name);
}
}
/**
* Check pattern against the path
*/
var compare = function(pat, name) {
var str = path.basename(name);
return (
is.regexp(pat) && pat.test(name)
|| is.string(pat) && pat === str
);
};
/**
* Traverse a directory recursively and asynchronously.
*
* @param {String} root
* @param {String} type
* @param {Function} action
* @param {Function} callback
* @param {Chain} c
* @api private
*/
var traverseAsync = function(root, type, action, callback, c) {
if (!is.existed(root)) {
fss.errorHandler(error.notExist(root))
}
var originRoot = root;
if (is.symbolicLink(root)) {
root = fss.readlinkSync(root);
}
if (is.directory(root)) {
fss.readdir(root, function(err, all) {
var chain = Chain();
all && all.forEach(function(dir) {
dir = path.join(originRoot, dir);
chain.add(function() {
var handleFile = function() {
if (type == 'file') action(dir);
process.nextTick(function() { chain.next() });
}
var handleDir = function(skip) {
if (type == 'dir') action(dir);
if (skip) chain.next();
else process.nextTick(function() { traverseAsync(dir, type, action, callback, chain)});
}
var isSymbolicLink = is.symbolicLink(dir);
if (is.directory(dir)) {
handleDir();
} else if (isSymbolicLink) {
fss.readlink(dir, function(origin) {
if (origin) {
if (is.existed(origin) && is.directory(origin)) {
handleDir(isSymbolicLink)
} else {
handleFile()
}
} else {
chain.next();
}
});
} else {
handleFile();
}
})
});
chain.traverse(function() {
c ? c.next() : callback();
});
});
}
}
/**
* Traverse a directory recursively.
*
* @param {String} root
* @param {String} type
* @param {Function} action
* @return {Array} the result
* @api private
*/
var traverseSync = function(root, type, action) {
if (!is.existed(root)) throw error.notExist(root);
var originRoot = root;
if (is.symbolicLink(root)) {
root = fss.readlinkSync(root);
}
if (is.directory(root)) {
fs.readdirSync(root).forEach(function(dir) {
dir = path.join(originRoot, dir);
var handleDir = function(skip) {
if (type == 'dir') action(dir);
if (skip) return;
traverseSync(dir, type, action);
}
var handleFile = function() {
if (type == 'file') action(dir);
}
var isSymbolicLink = is.symbolicLink(dir);
if (is.directory(dir)) {
handleDir();
} else if (isSymbolicLink) {
var origin = fss.readlinkSync(dir);
if (origin) {
if (is.existed(origin) && is.directory(origin)) {
handleDir(isSymbolicLink);
} else {
handleFile();
}
}
} else {
handleFile();
}
});
}
};
['file', 'dir'].forEach(function(type) {
/**
* `find.file` and `find.dir`
*
* Find files or sub-directories in a given directory and
* passes the result in an array as a whole. This follows
* the default callback style of nodejs, think about `fs.readdir`,
*
* @param {RegExp|String} pat
* @param {String} root
* @param {Function} fn
* @api public
*/
find[type] = function(pat, root, fn) {
var buffer = [];
if (arguments.length == 2) {
fn = root;
root = pat;
pat = '';
}
process.nextTick(function() {
traverseAsync(
root
, type
, function(n) { buffer.push(n);}
, function() {
if (is.func(fn) && pat) {
fn(buffer.filter(function(n) {
return compare(pat, n);
}));
} else {
fn(buffer);
}
}
);
});
return {
error: function(handler) {
if (is.func(handler)) {
find.__errorHandler = handler;
}
}
}
}
/**
* `find.eachfile` and `find.eachdir`
*
* Find files or sub-directories in a given directory and
* apply with a given action to each result immediately
* rather than pass them back as an array.
*
* @param {RegExp|String} pat
* @param {String} root
* @param {Function} action
* @return {Object} for chain methods
* @api public
*
*/
find['each' + type] = function(pat, root, action) {
var callback = function() {}
if (arguments.length == 2) {
action = root;
root = pat;
pat = '';
}
process.nextTick(function() {
traverseAsync(
root
, type
, function(n) {
if (!is.func(action)) return;
if (!pat || compare(pat, n)) {
action(n);
}
}
, callback
);
});
return {
end: function(fn) {
if (is.func(fn)) {
callback = fn;
}
return this;
},
error: function(handler) {
if (is.func(handler)) {
find.__errorHandler = handler;
}
return this;
}
};
}
/**
* `find.fileSync` and `find.dirSync`
*
* Find files or sub-directories in a given directory synchronously
* and returns the result as an array. This follows the default 'Sync'
* methods of nodejs, think about `fs.readdirSync`,
*
* @param {RegExp|String} pat
* @param {String} root
* @return {Array} the result
* @api public
*/
find[type + 'Sync'] = function(pat, root) {
var buffer = [];
if (arguments.length == 1) {
root = pat;
pat = '';
}
traverseSync(root, type, function(n) {
buffer.push(n);
});
return pat && buffer.filter(function(n) {
return compare(pat, n);
}) || buffer;
}
});
var fsMethods = [
'existsSync',
'lstatSync',
'realpath',
'realpathSync',
'readdir',
'readdirSync'
];
/**
* Configuations for internal usage
*
* @param {Object} options
* @api public
*/
find.use = function(options) {
if (options && options.fs) {
if (fsMethods.every(n => !!options.fs[n])) {
fs = options.fs;
} else {
throw new Error('The provided fs object is not compatiable with native fs.');
}
}
return find;
}

68
node_modules/find/package.json generated vendored Normal file
View File

@ -0,0 +1,68 @@
{
"_args": [
[
"find@0.3.0",
"/Users/tatiana/selfdefined"
]
],
"_from": "find@0.3.0",
"_id": "find@0.3.0",
"_inBundle": false,
"_integrity": "sha512-iSd+O4OEYV/I36Zl8MdYJO0xD82wH528SaCieTVHhclgiYNe9y+yPKSwK+A7/WsmHL1EZ+pYUJBXWTL5qofksw==",
"_location": "/find",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "find@0.3.0",
"name": "find",
"escapedName": "find",
"rawSpec": "0.3.0",
"saveSpec": null,
"fetchSpec": "0.3.0"
},
"_requiredBy": [
"/module-lookup-amd"
],
"_resolved": "https://registry.npmjs.org/find/-/find-0.3.0.tgz",
"_spec": "0.3.0",
"_where": "/Users/tatiana/selfdefined",
"author": {
"name": "yuanchuan",
"email": "yuanchuan23@gmail.com",
"url": "http://yuanchuan.name"
},
"bugs": {
"url": "https://github.com/yuanchuan/find/issues"
},
"dependencies": {
"traverse-chain": "~0.1.0"
},
"description": "Find files or directories by name",
"devDependencies": {
"mocha": "^6.0.2",
"tmp": "^0.0.33"
},
"directories": {
"test": "test"
},
"homepage": "https://github.com/yuanchuan/find#readme",
"keywords": [
"find",
"findfile",
"search",
"files"
],
"license": "MIT",
"main": "./index.js",
"name": "find",
"repository": {
"url": "git://github.com/yuanchuan/find.git",
"type": "git"
},
"scripts": {
"test": "mocha"
},
"url": "https://github.com/yuanchuan/find",
"version": "0.3.0"
}

280
node_modules/find/test/test.js generated vendored Normal file
View File

@ -0,0 +1,280 @@
var fs = require('fs');
var assert = require('assert');
var path = require('path');
var tmp = require('tmp');
var find = require('..');
tmp.setGracefulCleanup();
function createBy(type) {
return function(dir, num, ext) {
var targets = [];
num = num || 1;
if (Array.isArray(dir)) dir = dir[0];
var opts = { template: path.join(dir, '/tmp-XXXXXX' + (ext || '')) };
for (var i = 0; i < num; ++i) {
targets.push(tmp[type + 'Sync'](opts).name);
}
return targets;
}
}
function assertEqual(a, b) {
assert.deepEqual(a.sort(), b.sort());
}
var createFilesUnder = createBy('file');
var createDirUnder = createBy('dir');
function createNestedDirs(testdir) {
var level1 = createDirUnder(testdir)[0];
var level2 = createDirUnder(level1)[0];
var level22 = createDirUnder(level1)[0];
var level3 = createDirUnder(level2)[0];
return [level1, level2, level22, level3];
}
describe('API test', function() {
var testdir;
beforeEach(function(done) {
tmp.dir({unsafeCleanup: true}, function(err, dir) {
if (err) return done(err);
testdir = dir;
done();
});
});
it('`find.file()` should find all files and returns as an array in callback', function(done) {
var expect = createFilesUnder(testdir, 3);
find.file(testdir, function(found) {
assertEqual(expect, found);
done();
});
});
it('`find.file()` should find recursively', function(done) {
var expect = createFilesUnder(testdir, 3);
var level1 = createDirUnder(testdir);
expect = expect.concat(createFilesUnder(testdir, 2));
find.file(testdir, function(found) {
assertEqual(expect, found);
done();
});
});
it('`find.dir()` should find all dirs just like find.file()', function(done) {
var expect = createNestedDirs(testdir);
find.dir(testdir, function(found) {
assertEqual(expect, found);
done();
});
});
it('`find.eachfile()` should find all files and process one by one', function(done) {
var expect = createFilesUnder(testdir, 3);
count = 0;
find.eachfile(testdir, function(thisfile) {
assert(expect.indexOf(thisfile) > -1);
count++;
}).end(function() {
assert(count == expect.length);
done();
});
});
it('`find.eachdir()` should find all dirs just like find.eachfile()', function(done) {
var expect = createNestedDirs(testdir);
var count = 0;
find.eachdir(testdir, function(thisdir) {
assert(expect.indexOf(thisdir) > -1);
count++;
}).end(function() {
assert(count == expect.length);
done();
});
});
it('`find.fileSync()` should find all files synchronously', function() {
var expect = createFilesUnder(testdir, 3);
var found = find.fileSync(testdir);
assertEqual(expect, found);
});
it('`find.dirSync()` should find all dirs synchronously', function() {
var expect = createNestedDirs(testdir, 3);
var found = find.dirSync(testdir);
assertEqual(expect, found);
});
it('`find.*` should find by name', function(done) {
var expect = createFilesUnder(testdir, 3);
var first = expect[0];
find.file(path.basename(first), testdir, function(found) {
assert.equal(first, found[0]);
done();
});
});
it('`find.*` should find by regular expression', function() {
var html = createFilesUnder(testdir, 1, '.html');
var js = createFilesUnder(testdir, 2, '.js');
htmlAll = find.fileSync(/\.html$/, testdir);
assert.equal( html.join(''), htmlAll.join(''));
jsAll = find.fileSync(/\.js$/, testdir);
assertEqual(js, jsAll);
});
it('`find.*` should follow file symbolic links', function(done) {
var files = createFilesUnder(testdir, 2);
var srcfile = files[0];
var linkfile = srcfile + '-link';
files.push(linkfile);
fs.symlinkSync(srcfile, linkfile, 'file');
var allfile = find.fileSync(testdir);
assertEqual(files, allfile);
find.file(testdir, function(found) {
assertEqual(files, found);
done();
});
});
it('`find.find(Sync)` should return the symbolic links directly which does not exist', function(done) {
var files = createFilesUnder(testdir, 2);
var srcfile = files[0];
var linkfile = srcfile + '-link';
fs.symlinkSync(srcfile, linkfile, 'file');
fs.unlinkSync(srcfile);
var expected = [files[1], linkfile];
var found = find.fileSync(testdir);
assertEqual(found, expected);
find.file(testdir, function(found) {
assertEqual(expected, found);
done();
});
});
it('`find.*` should follow direcotry symbolic links', function(done) {
createFilesUnder(testdir, 2);
var dir = createDirUnder(testdir)[0];
var srcdir = createDirUnder(testdir)[0];
var linkdir = srcdir + '-link';
var dirs = [dir, srcdir, linkdir];
fs.symlinkSync(srcdir, linkdir, 'dir');
var alldir = find.dirSync(testdir);
assertEqual(dirs, alldir);
find.dir(testdir, function(found) {
assertEqual(dirs, found);
done();
});
});
it('`find.dir(Sync)` should ignore circular symbolic links', function(done) {
var dirs = createDirUnder(testdir, 2);
var src = dirs[0];
var remaining = dirs.slice(1);
var a = src + '-link-a';
var b = src + '-link-b';
var c = src + '-link-c';
fs.symlinkSync(src, a, 'dir');
fs.symlinkSync(a, b, 'dir');
fs.symlinkSync(b, c, 'dir');
fs.rmdirSync(src);
fs.symlinkSync(c, src, 'dir');
var found = find.dirSync(testdir);
assertEqual(remaining, found);
find.dir(testdir, function(found) {
assertEqual(remaining, found);
done();
})
});
it('`find.*` should find for a symbolic directory', function(done) {
var expect = createFilesUnder(testdir, 2);
var linkdir = testdir + '-link';
fs.symlinkSync(testdir, linkdir, 'dir');
var allfiles = find.fileSync(linkdir);
assertEqual(
expect.map(function(n) { return fs.realpathSync(n) }),
allfiles.map(function(n) { return fs.realpathSync(n) })
);
find.file(linkdir, function(found) {
assertEqual(
expect.map(function(n) { return fs.realpathSync(n) }),
found.map(function(n) { return fs.realpathSync(n) })
);
done();
});
});
it('`find.*` should follow relative symbolic links', function(done) {
var count = 2;
var dir = createNestedDirs(testdir)[0];
createFilesUnder(dir, count);
var linkdir = dir + '-link';
// create relative symbolic link
process.chdir(path.dirname(dir));
fs.symlinkSync(path.basename(dir), linkdir, 'dir');
// move to somewhere else
process.chdir(__dirname);
var found = find.fileSync(linkdir);
assert.equal(found.length, count);
find.file(testdir, function(found) {
assert.equal(found.length, count);
done();
});
});
it('`.error()`should catch exceptions', function(done) {
var catched;
try {
find
.file('__not_exist', function(f) { })
.error(function(err) {
catched = true;
});
} catch(e) {
catched = false;
}
setTimeout(function() {
assert(catched);
done();
});
});
it('should throw exception at root which does not exist', function(done) {
var catched = false;
try {
find.fileSync('__not_exist');
} catch(e) {
catched = true;
}
setTimeout(function() {
assert(catched);
done();
});
});
});