Socket
Socket
Sign inDemoInstall

next

Package Overview
Dependencies
4
Maintainers
1
Versions
2641
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.13 to 0.2.14

lib/fs/is-ignored.js

93

lib/find-package-root.js

@@ -6,63 +6,52 @@ // For given path returns root package path.

var stat = require('fs').stat
, path = require('path')
, basename = path.basename
, dirname = path.dirname
, resolve = path.resolve
, contains = require('es5-ext/lib/Array/prototype/contains')
, dirExists = require('./fs/dir-exists')
, fileExists = require('./fs/file-exists')
var path = require('path')
, memoize = require('es5-ext/lib/Function/prototype/memoize')
, value = require('es5-ext/lib/Object/valid-value')
, promisify = require('deferred').promisify
, stat = promisify(require('fs').stat)
, dirExists = promisify(require('./fs/dir-exists'))
, fileExists = promisify(require('./fs/file-exists'))
, isPackageRoot, cache = [];
, basename = path.basename, dirname = path.dirname, resolve = path.resolve
cache.contains = contains;
, isRoot, find;
isPackageRoot = function (path, callback) {
if (cache.contains(path)) {
callback(null, path);
return;
}
fileExists(path + '/package.json', function (exists) {
if (exists) {
cache.push(path);
callback(null, path);
return;
}
dirExists(path + '/node_modules', function (exists) {
var parentpath;
if (exists) {
cache.push(path);
callback(null, path);
} else {
parentpath = dirname(path);
if (parentpath === path) {
callback(null, null);
} else if (basename(parentpath) === 'node_modules') {
cache.push(path);
callback(null, path);
isRoot = memoize.call(function (path) {
return fileExists(resolve(path, 'package.json'))(function (exists) {
return exists ? path : dirExists(resolve(path, 'node_modules'))(
function (exists) {
var parent;
if (exists) {
return path;
} else {
isPackageRoot(parentpath, callback);
parent = dirname(path);
if (parent === path) {
return null;
} else if (basename(parent) === 'node_modules') {
return path;
} else {
return isRoot(parent);
}
}
}
});
);
});
};
});
module.exports = function find(path, callback) {
path = resolve(String(path));
stat(path, function (err, stats) {
if (err) {
if (dirname(path) !== path) {
find(dirname(path), callback);
} else {
callback(null, null);
}
return;
}
if (stats.isDirectory()) {
isPackageRoot(path, callback);
} else {
isPackageRoot(dirname(path), callback);
}
find = memoize.call(function (path) {
return stat(path)(function (stats) {
return isRoot(stats.isDirectory() ? path : dirname(path));
}, function () {
return isRoot(dirname(path));
});
}, [function (path) {
return resolve(String(value(path)));
}]);
module.exports = function (path, callback) {
try {
return find(path).cb(callback);
} catch (e) {
callback(e);
}
};

@@ -10,5 +10,8 @@ 'use strict';

isExecutable: require('./is-executable'),
isIgnored: require('./is-ignored'),
readdirDirectories: require('./readdir-directories'),
readdirFiles: require('./readdir-files'),
readdirFilesDeep: require('./readdir-files-deep')
readdirFilesDeep: require('./readdir-files-deep'),
watchPath: require('./watch-path'),
writeFile: require('./write-file')
};

@@ -11,8 +11,9 @@ // Read all filenames from directory and it's subdirectories

, path = require('path')
, curry = require('es5-ext/lib/Function/prototype/curry')
, compact = require('es5-ext/lib/Array/prototype/compact')
, contains = require('es5-ext/lib/Array/prototype/contains')
, contains = curry.call(require('es5-ext/lib/Array/prototype/contains'))
, copy = require('es5-ext/lib/Array/prototype/copy')
, group = require('es5-ext/lib/Array/prototype/group')
, intersection = require('es5-ext/lib/Array/prototype/intersection')
, memoize = require('es5-ext/lib/Function/memoize')
, memoize = require('es5-ext/lib/Function/prototype/memoize')
, isCallable = require('es5-ext/lib/Object/is-callable')

@@ -63,3 +64,3 @@ , minimatch = require('minimatch')

prepIgnore = memoize(function (ignore) {
prepIgnore = memoize.call(function (ignore) {
var result = [];

@@ -66,0 +67,0 @@ ignore.forEach(function (ignore, index) {

'use strict';
var normalize = require('path').normalize
, peek = require('es5-ext/lib/Array/prototype/peek')
, last = require('es5-ext/lib/Array/prototype/last')

@@ -18,4 +18,4 @@ , from, to;

path = (path && normalize(path).replace(from, to));
return ((path.length > 1) && (peek.call(path) === to)) ?
return ((path.length > 1) && (last.call(path) === to)) ?
path.slice(0, -1) : path;
};

@@ -7,3 +7,3 @@ // Finds relative path between two absolute paths

, commonLeft = require('es5-ext/lib/Array/prototype/common-left')
, peek = require('es5-ext/lib/Array/prototype/peek')
, last = require('es5-ext/lib/Array/prototype/last')
, separator = require('./separator')

@@ -20,7 +20,7 @@

from = String(from);
if (join(peek.call(from)) === separator) {
if (join(last.call(from)) === separator) {
from = join(from, 'x');
}
to = String(to);
if (join(peek.call(to)) === separator) {
if (join(last.call(to)) === separator) {
to = join(to, 'x');

@@ -27,0 +27,0 @@ added = true;

@@ -14,3 +14,2 @@ // Require module in given context

, props = ['require', 'module', 'exports']
, modRequire = Module.prototype.require || function (path) {

@@ -17,0 +16,0 @@ return Module._load(path, this);

{
"name": "next",
"version": "0.2.13",
"description": "Node.js extensions",
"keywords": ["node", "nodejs", "node.js", "extensions", "addons", "extras"],
"author":
"Mariusz Nowak <medikoo+node-ext@medikoo.com> (http://www.medikoo.com/)",
"main": "lib/index",
"repository": {
"type": "git",
"url": "git://github.com/medikoo/node-ext.git"
},
"bugs": {
"mail": "medikoo+node-ext@medikoo.com",
"url": "https://github.com/medikoo/node-ext/issues"
},
"engines": {
"node": ">=0.3.8"
},
"dependencies": {
"es5-ext": "0.7.x",
"deferred": "0.4.x",
"minimatch": "0.1.x"
},
"scripts": {
"test": "node ./node_modules/tad/bin/tad lib",
"lint": "node ./node_modules/jslint/bin/jslint.js --color --git"
},
"devDependencies": {
"tad": "0.1.x"
}
"name": "next",
"version": "0.2.14",
"description": "Node.js extensions",
"keywords": [
"addons",
"extensions",
"extras",
"node",
"nodejs",
"node.js"
],
"author": "Mariusz Nowak <medikoo+node-ext@medikoo.com> (http://www.medikoo.com/)",
"main": "lib/index",
"repository": {
"type": "git",
"url": "git://github.com/medikoo/node-ext.git"
},
"bugs": {
"email": "medikoo+node-ext@medikoo.com",
"url": "https://github.com/medikoo/node-ext/issues"
},
"engines": {
"node": ">=0.4"
},
"dependencies": {
"deferred": "0.5.x",
"es5-ext": "0.8.x",
"event-emitter": "0.1.x",
"minimatch": "0.2.x"
},
"scripts": {
"test": "node ./node_modules/tad/bin/tad lib"
},
"devDependencies": {
"tad": "0.1.x"
},
"optionalDependencies": {}
}
# node-ext - Node.js extensions
Functions that complement Node.js API.
_It's work in progress, new methods are added when needed._
Currently in very experimental state, While 95% of API is well tested and will work as expected, whole project is scheduled for big reorganization which with full documentation will land in 0.3 release.

@@ -10,43 +10,6 @@ ## Installation

## Usage
## Test
var nfs = require('next/lib/fs')
, npath = require('next/lib/path');
Tests also gives better idea about state of the API
nfs.fileExists(filepath, callback);
dirpath = npath.trim(dirpath);
Alternatively you can import each function individually
var fileExists = require('next/lib/fs/file-exists')
, pathTrim = require('next/lib/path/trim');
fileExists(filepath, callback);
dirpath = pathTrim(dirpath);
### Extensions
_Each extension is documented at begin of its source file._
* `findPackageRoot(path)`
* `getRequire(path)`
* `isModuleNotFoundError(error, path)`
* `requireInContext(path, context)`
* `requireSilent(path)`
#### child_process
* `child_process.pipe`
#### fs
* `fs.copy`
* `fs.copySync`
* `fs.dirExists`
* `fs.fileExists`
* `fs.readdirFilesDeep`
#### path
* `path.relative`
* `path.trim`
$ npm test

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc