| function (err, result) { | ||
| if (err instanceof Error) { | ||
| self.errorCallback(err); | ||
| return; | ||
| } | ||
| else { //not an error | ||
| result = err; | ||
| } | ||
| self.results.push(result); | ||
| self.pending -= 1; | ||
| if (self.pending === 0) { | ||
| endCallback(self.results); | ||
| } | ||
| } |
| function (err, result) { | ||
| if (err instanceof Error) { | ||
| self.errorCallback(err); | ||
| return; | ||
| } | ||
| else { //not an error | ||
| result = err; | ||
| } | ||
| self.results.push(result); | ||
| self.pending -= 1; | ||
| if (self.pending === 0) { | ||
| endCallback(self.results); | ||
| } | ||
| } |
+6
-0
@@ -0,3 +1,9 @@ | ||
| 0.1.0 / 2013-01-26 | ||
| ------------------ | ||
| * Refactored tests. | ||
| * Changed API. | ||
| * Updated deps. | ||
| 0.0.1 / 2012-08-16 | ||
| ------------------ | ||
| * Initial release. |
+44
-39
@@ -6,53 +6,58 @@ var fs = require('fs') | ||
| function ParentPath(){ | ||
| this.searchPath = null; | ||
| this.searchTokens = [];// --\ | ||
| this.currentToken = 0;// --/ not really utilized like they could be | ||
| this.searchPath = null; | ||
| this.searchTokens = [];// --\ | ||
| this.currentToken = 0;// --/ not really utilized like they could be | ||
| } | ||
| ParentPath.prototype.find = function(str) { | ||
| this.searchPath = str; | ||
| this.searchTokens = str.split(path.sep); | ||
| return this; | ||
| this.searchPath = str; | ||
| this.searchTokens = str.split(path.sep); | ||
| return this; | ||
| }; | ||
| ParentPath.prototype.end = function(callback) { | ||
| var self = this; | ||
| var self = this; | ||
| function again(dir) { | ||
| fs.readdir(dir, function(err, paths) { | ||
| //console.log(paths) | ||
| if (paths.indexOf(self.searchTokens[self.currentToken]) >= 0) { | ||
| var p = path.join(path.resolve(dir), self.searchPath); | ||
| fs.exists(p, function(itDoes) { | ||
| if (itDoes) { | ||
| callback(path.resolve(dir)); //remove ending PATH SEP if there is one | ||
| } else { | ||
| var newdir = path.join(dir, '../') | ||
| if (newdir != dir) { | ||
| dir = newdir; | ||
| again(dir); | ||
| } else | ||
| callback(null); | ||
| } | ||
| }); | ||
| } else { | ||
| var newdir = path.join(dir, '../') | ||
| if (newdir != dir) { | ||
| dir = newdir; | ||
| again(dir); | ||
| } else | ||
| callback(null) | ||
| } | ||
| function again(dir) { | ||
| fs.readdir(dir, function(err, paths) { | ||
| //console.log(paths) | ||
| if (paths.indexOf(self.searchTokens[self.currentToken]) >= 0) { | ||
| var p = path.join(path.resolve(dir), self.searchPath); | ||
| fs.exists(p, function(itDoes) { | ||
| if (itDoes) { | ||
| callback(path.resolve(dir)); //remove ending PATH SEP if there is one | ||
| } else { | ||
| var newdir = path.join(dir, '../') | ||
| if (newdir != dir) { | ||
| dir = newdir; | ||
| again(dir); | ||
| } else | ||
| callback(null); | ||
| } | ||
| }); | ||
| } | ||
| again(path.join(process.cwd(), '../')); | ||
| } else { | ||
| var newdir = path.join(dir, '../') | ||
| if (newdir != dir) { | ||
| dir = newdir; | ||
| again(dir); | ||
| } else | ||
| callback(null) | ||
| } | ||
| }); | ||
| } | ||
| again(path.join(process.cwd(), '../')); | ||
| return this; | ||
| return this; | ||
| }; | ||
| module.exports.find = function(search){ | ||
| var pp = new ParentPath(); | ||
| return pp.find(search); | ||
| module.exports = function (search, callback) { | ||
| module.exports.find(search).end(callback) | ||
| } | ||
| module.exports.find = function (search){ | ||
| var pp = new ParentPath(); | ||
| return pp.find(search); | ||
| } | ||
+9
-10
| { | ||
| "name": "parentpath", | ||
| "version": "0.0.1", | ||
| "description": "Find a path in a parent directory.", | ||
| "version": "0.1.0", | ||
| "description": "Find parent directory of a path.", | ||
| "homepage": [ | ||
@@ -20,5 +20,3 @@ "" | ||
| ], | ||
| "dependencies": { | ||
| "string": "~0.2.1-2" | ||
| }, | ||
| "dependencies": {}, | ||
| "main": "./lib/parentpath.js", | ||
@@ -29,8 +27,9 @@ "scripts": { | ||
| "devDependencies": { | ||
| "testutil": "~0.2.2", | ||
| "fs-extra": "~0.1.3", | ||
| "path-extra": "0.0.x", | ||
| "batchflow": "0.0.3", | ||
| "nextflow": "~0.2.3" | ||
| "string": "~1.2.0", | ||
| "autoresolve": "0.0.3", | ||
| "walker": "~1.0.3", | ||
| "testutil": "~0.4.0", | ||
| "fs-extra": "~0.3.2", | ||
| "mocha": "*" | ||
| } | ||
| } |
+10
-12
| Node.js - parentpath | ||
| ================ | ||
| Find a path in a parent directory. | ||
| Find parent directory of a path. | ||
@@ -26,4 +26,2 @@ | ||
| **Note: I'm not quite happy with the API, so it should be considered unstable.** | ||
| Let's say we have the following directory: | ||
@@ -33,3 +31,3 @@ | ||
| └── mynewblog | ||
| ├── potter | ||
| ├── sky | ||
| │ ├── pages | ||
@@ -43,3 +41,3 @@ │ │ └── animals | ||
| │ │ └── reptiles.md | ||
| │ └── potter.json | ||
| │ └── sky.json | ||
| └── articles | ||
@@ -50,6 +48,6 @@ └── cool_article.md | ||
| ```javascript | ||
| var parent = require('parentpath') | ||
| process.chdir('/users/jp/mynewblog/potter/pages/animals/repites'); | ||
| parent.find('potter').end(function(dir) { | ||
| console.log(dir); // = /users/jp/mynewblog | ||
| var pp = require('parentpath') | ||
| process.chdir('/users/jp/mynewblog/sky/pages/animals/repites'); | ||
| pp('sky', function(dir) { | ||
| console.log(dir); // = /users/jp/mynewblog | ||
| }); | ||
@@ -62,5 +60,5 @@ ``` | ||
| var parent = require('parentpath') | ||
| process.chdir('/users/jp/mynewblog/potter/pages/animals/repites'); | ||
| parent.find('potter/potter.json').end(function(dir) { | ||
| console.log(dir); // = /users/jp/mynewblog | ||
| process.chdir('/users/jp/mynewblog/sky/pages/animals/repites'); | ||
| parent('sky/sky.json', function(dir) { | ||
| console.log(dir); // = /users/jp/mynewblog | ||
| }); | ||
@@ -67,0 +65,0 @@ ``` |
+85
-85
@@ -1,112 +0,112 @@ | ||
| var assert = require('assert') | ||
| , fs = require('fs-extra') | ||
| , parent = require('../lib/parentpath') | ||
| , path = require('path-extra') | ||
| var fs = require('fs-extra') | ||
| , pp = require('../lib/parentpath') | ||
| , testutil = require('testutil') | ||
| , batch = require('batchflow') | ||
| , next = require('nextflow') | ||
| , S = require('string') | ||
| , exec = require('child_process').exec; | ||
| , exec = require('child_process').exec | ||
| , P = require('autoresolve') | ||
| , walker = require('walker') | ||
| , path = require('path') | ||
| TEST_DIR = '', DIRS = []; | ||
| var TEST_DIR = '' | ||
| , DIRS = [] | ||
| , RESOURCE_DIR = P('test/resources') | ||
| var pj = path.join; | ||
| function removePrivate(dir) { | ||
| if (dir === null) return null | ||
| function ridx() { | ||
| return DIRS[Math.floor(Math.random() * DIRS.length)]; | ||
| if (dir.indexOf('/private/tmp') === 0) //MAC OS X symlinks /tmp to /private/tmp | ||
| dir = dir.replace('/private', ''); | ||
| return dir | ||
| } | ||
| describe('parentpath', function(){ | ||
| beforeEach(function(done) { | ||
| TEST_DIR = testutil.generateTestPath('test-parentpath'); | ||
| if (S(TEST_DIR).startsWith('/private/tmp')) { //MAC OS X symlinks /tmp to /private/tmp | ||
| TEST_DIR = TEST_DIR.replace('/private', ''); | ||
| console.log('HI: ' + TEST_DIR) | ||
| } | ||
| beforeEach(function(done) { | ||
| TEST_DIR = testutil.createTestDir('parentpath'); | ||
| process.chdir(TEST_DIR) | ||
| TEST_DIR = '/tmp/mynewblog' //path.resolve(TEST_DIR) | ||
| TEST_DIR = path.join(TEST_DIR, 'test') | ||
| TEST_DIR = removePrivate(TEST_DIR) | ||
| var dirs = []; | ||
| dirs[0] = pj(TEST_DIR, 'potter') | ||
| dirs[1] = pj(dirs[0], 'pages') | ||
| dirs[2] = pj(dirs[1], 'animals') | ||
| dirs[3] = pj(dirs[2], 'reptiles') | ||
| dirs[4] = pj(dirs[2], 'mammals') | ||
| dirs[5] = pj(dirs[3], 'snakes') | ||
| dirs[6] = pj(dirs[4], 'humans') | ||
| fs.copy(RESOURCE_DIR, TEST_DIR, function(err) { | ||
| walker(TEST_DIR) | ||
| .on('dir', function(dir) { | ||
| DIRS.push(dir) | ||
| }) | ||
| .on('end', function() { | ||
| done() | ||
| }) | ||
| }) | ||
| }) | ||
| it('should find the path of a parent dir', function(done){ | ||
| var snakeDir = '' | ||
| DIRS.forEach(function(d) { | ||
| if (S(d).endsWith(d)) | ||
| snakeDir = d | ||
| }) | ||
| if (!snakeDir) done(new Error('Cant find snake dir.')) | ||
| process.chdir(snakeDir) | ||
| pp('skyblog/', function(dir) { | ||
| dir = removePrivate(dir) | ||
| var files = []; | ||
| files[0] = path.join(dirs[0], 'potter.json') | ||
| files[1] = path.join(dirs[2], 'animals.md') | ||
| files[2] = path.join(dirs[5], 'reptiles.md') | ||
| EQ (dir, TEST_DIR); | ||
| done() | ||
| }) | ||
| }) | ||
| DIRS = dirs; | ||
| next({ | ||
| ERROR: function(err) { | ||
| done(err); | ||
| }, | ||
| createTD: function() { | ||
| var self = this; | ||
| fs.mkdir(TEST_DIR, this.next); | ||
| }, | ||
| createDirs: function(){ | ||
| var self = this; | ||
| batch(dirs).seq().each(function(i, dir, done){ fs.mkdir(dir, done); }).end(function(){ self.next(); }); | ||
| }, | ||
| createFiles: function() { | ||
| var self = this; | ||
| batch(files).par().each(function(i, file, done){ fs.writeFile(file, done); }).end(function(){ self.next(); }); | ||
| }, | ||
| done: function() { | ||
| process.chdir('/tmp') | ||
| exec('tree ' + '/tmp', function(err, stdout, stderr) { | ||
| console.log(stdout); | ||
| process.exit(); | ||
| }); | ||
| } | ||
| }); | ||
| it('should find the path of a parent path', function(done) { | ||
| var snakeDir = '' | ||
| DIRS.forEach(function(d) { | ||
| if (S(d).endsWith(d)) | ||
| snakeDir = d | ||
| }) | ||
| if (!snakeDir) done(new Error('Cant find snake dir.')) | ||
| process.chdir(snakeDir) | ||
| it('should find the path of a parent dir', function(done){ | ||
| process.chdir(ridx()); | ||
| parent.find('potter/').end(function(dir) { | ||
| if (dir) { | ||
| if (S(dir).startsWith('/private/tmp')) { //MAC OS X symlinks /tmp to /private/tmp | ||
| dir = dir.replace('/private', ''); | ||
| } | ||
| } | ||
| pp('skyblog/sky.json', function(dir) { | ||
| dir = removePrivate(dir) | ||
| assert(dir === TEST_DIR); | ||
| done(); | ||
| }) | ||
| EQ (dir, TEST_DIR); | ||
| done(); | ||
| }) | ||
| }) | ||
| it('should find the animals file', function(done) { | ||
| var snakeDir = '' | ||
| DIRS.forEach(function(d) { | ||
| if (S(d).endsWith(d)) | ||
| snakeDir = d | ||
| }) | ||
| if (!snakeDir) done(new Error('Cant find snake dir.')) | ||
| it('should find the path of a parent path', function(done) { | ||
| process.chdir(ridx()); | ||
| parent.find('potter/potter.json').end(function(dir) { | ||
| if (dir) { | ||
| if (S(dir).startsWith('/private/tmp')) { //MAC OS X symlinks /tmp to /private/tmp | ||
| dir = dir.replace('/private', ''); | ||
| } | ||
| } | ||
| process.chdir(snakeDir) | ||
| pp('animals.md', function(dir) { | ||
| dir = removePrivate(dir) | ||
| EQ (dir, path.join(TEST_DIR, 'skyblog/pages/animals')) | ||
| done(); | ||
| }) | ||
| }) | ||
| assert(dir === TEST_DIR); | ||
| done(); | ||
| }) | ||
| it('should return null if the parent path cant be found', function(done) { | ||
| var snakeDir = '' | ||
| DIRS.forEach(function(d) { | ||
| if (S(d).endsWith(d)) | ||
| snakeDir = d | ||
| }) | ||
| if (!snakeDir) done(new Error('Cant find snake dir.')) | ||
| it('should return null if the parent path cant be found', function(done) { | ||
| process.chdir(ridx()); | ||
| parent.find('potter/per.json').end(function(dir) { | ||
| assert(dir === null); | ||
| done(); | ||
| }) | ||
| process.chdir(snakeDir) | ||
| pp('skyblog/per.json', function(dir) { | ||
| EQ (dir, null); | ||
| done(); | ||
| }) | ||
| }) | ||
| }) | ||
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 2 instances in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 2 instances in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
0
-100%12
33.33%0
-100%8381
-2.27%6
20%71
-2.74%2
100%- Removed
- Removed