Socket
Socket
Sign inDemoInstall

next

Package Overview
Dependencies
3
Maintainers
1
Versions
2641
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.11 to 0.2.12

.lint

4

lib/find-package-root.js

@@ -39,3 +39,3 @@ // For given path returns root package path.

} else if (parentpath.slice(parentpath.lastIndexOf(separator) + 1)
=== 'node_modules') {
=== 'node_modules') {
cache.push(path);

@@ -51,3 +51,3 @@ callback(null, path);

module.exports = function find (path, callback) {
module.exports = function find(path, callback) {
path = normalize(path);

@@ -54,0 +54,0 @@ stat(path, function (err, stats) {

@@ -7,5 +7,5 @@ // Copy file, synchronous

module.exports = function (source, dest){
module.exports = function (source, dest) {
fs.writeFileSync(dest, fs.readFileSync(source), 'binary');
fs.chmodSync(dest, fs.statSync(source).mode);
};
// Copy file
// Credit: Isaac Schlueter http://groups.google.com/group/nodejs/msg/ef4de0b516f7d5b8
// Credit: Isaac Schlueter
// http://groups.google.com/group/nodejs/msg/ef4de0b516f7d5b8

@@ -9,3 +10,3 @@ 'use strict';

module.exports = function (source, dest, cb){
module.exports = function (source, dest, cb) {
fs.lstat(source, function (err, stats) {

@@ -12,0 +13,0 @@ var read;

@@ -11,2 +11,2 @@ // Whether given path points existing directory

});
};
};

@@ -7,3 +7,3 @@ // Get all files at path

, normalize = require('../path/normalize')
, readdir = require('./readdir-files-deep')
, readdir = require('./readdir-files-deep');

@@ -10,0 +10,0 @@ module.exports = function (path, cb) {

@@ -9,2 +9,3 @@ 'use strict';

filesAtPath: require('./files-at-path'),
isExecutable: require('./is-executable'),
readdirDirectories: require('./readdir-directories'),

@@ -11,0 +12,0 @@ readdirFiles: require('./readdir-files'),

@@ -12,7 +12,6 @@ // Read all filenames from directory and it's subdirectories

module.exports = function self (path, callback) {
module.exports = function (path, callback) {
readdir(path = normalize(path)).map(function (file) {
var npath = path + '/' + file;
return stat(npath)
(function (stats) {
return stat(npath)(function (stats) {
return stats.isDirectory() ? file : null;

@@ -19,0 +18,0 @@ }, k(null));

@@ -5,15 +5,103 @@ // Read all filenames from directory and it's subdirectories

var fs = require('fs')
, normalize = require('../path/normalize')
, readdir = fs.readdir, lstat = fs.lstat
var push = Array.prototype.push
, call = Function.prototype.call
, keys = Object.keys
, trim = call.bind(String.prototype.trim)
, fs = require('fs')
, normalize = require('../path/normalize')
, compact = require('es5-ext/lib/Array/prototype/compact')
, contains = 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')
, isCallable = require('es5-ext/lib/Object/is-callable')
, minimatch = require('minimatch')
, read;
, readdir = fs.readdir, lstat = fs.lstat, readFile = fs.readFile
, read, read2, match, match2, prepIgnore;
read = function (path, files, cb) {
var waiting = files.length, result = [];
if (!waiting) {
cb(null, result);
read = function (path, options, ignore, files, cb) {
var ignorefiles, waiting;
if (!files.length) {
cb(null, []);
return;
}
if (options.ignorefile.some(contains, files)) {
waiting = options.ignorefile.length;
options.ignorefile.forEach(function (file, index) {
if (contains.call(files, file)) {
readFile(path + '/' + file, 'utf-8', function (err, result) {
if (err) {
cb(err);
waiting = -1;
return;
}
if (!ignore['/']) {
ignore['/'] = [];
}
if (!ignore['/'][index]) {
ignore['/'][index] = [];
}
push.apply(ignore['/'][index],
compact.call(result.split('\n').map(trim)));
if (!--waiting) {
ignore['/'] = compact.call(ignore['/']);
read2(path, options, ignore, files, cb);
}
});
} else if (!--waiting) {
read2(path, options, ignore, files, cb);
}
});
} else {
read2(path, options, ignore, files, cb);
}
};
prepIgnore = memoize(function (ignore) {
var result = [];
ignore.forEach(function (ignore, index) {
var res = result[index] = group.call(ignore, function (item) {
return (item[0] === '!') ? 'exclude' : 'include';
});
!res.exclude && (res.exclude = []);
!res.include && (res.include = []);
});
result.forEach(function (ignore, index) {
while (result[++index]) {
push.apply(ignore.exclude, result[index].exclude);
}
});
return result;
});
match = function (ignore, file) {
if (!ignore.length) {
return false;
}
return (ignore = prepIgnore(ignore)).some(function (ignore) {
return ignore.include.some(function (pattern) {
return minimatch(file, pattern, { matchBase: true });
}) && ignore.exclude.every(function (pattern) {
return minimatch(file, pattern, { matchBase: true });
});
});
};
match2 = function (ignore, file) {
return keys(ignore).some(function (key) {
return match(ignore[key], key + file);
});
};
read2 = function (path, options, ignore, files, cb) {
var waiting = files.length, result = [], nignore;
files.forEach(function (file) {
if (match2(ignore, file)) {
if (!--waiting) {
cb(null, result);
}
return;
}
lstat(path + '/' + file, function (err, stat) {

@@ -25,3 +113,5 @@ if (err) {

} else if (stat.isFile()) {
result.push(file);
if (!options.pattern || options.pattern.test(file)) {
result.push(file);
}
if (!--waiting) {

@@ -37,10 +127,20 @@ cb(null, result);

} else {
read(path + '/' + file, files, function (err, res) {
result = result.concat(res.map(function (name) {
return normalize(file + '/' + name);
}));
if (!--waiting) {
cb(null, result);
}
nignore = {};
keys(ignore).forEach(function (key) {
nignore[key + file + '/'] = ignore[key];
});
read(path + '/' + file, options, nignore, files,
function (err, res) {
if (err) {
cb(err);
waiting = -1;
return;
}
result = result.concat(res.map(function (name) {
return normalize(file + '/' + name);
}));
if (!--waiting) {
cb(null, result);
}
});
}

@@ -55,3 +155,28 @@ });

module.exports = function self (path, cb) {
module.exports = function (path, options, cb) {
var ignore = [], ignorefiles = [];
if (isCallable(options)) {
cb = options;
options = {};
}
if (options.globignore) {
ignore.push(copy.call(options.globignore));
}
if (options.ignorefile) {
if (options.ignorefile === '.gitignore') {
options.git = true;
options.ignorefile = [];
} else {
ignore.unshift([options.ignorefile]);
options.ignorefile = [options.ignorefile];
}
} else {
options.ignorefile = [];
}
if (options.git) {
options.ignorefile.unshift('.gitignore');
ignore.unshift(['.gitignore', '.git']);
}
ignore = { "/": ignore };
readdir(path = normalize(path), function (err, files) {

@@ -62,4 +187,10 @@ if (err) {

}
read(path, files, cb);
read(path, options, ignore, files, function (err, result) {
if (err) {
cb(err);
return;
}
cb(null, result.sort());
});
});
};

@@ -12,7 +12,6 @@ // Read all filenames from directory and it's subdirectories

module.exports = function self (path, callback) {
module.exports = function self(path, callback) {
readdir(path = normalize(path)).map(function (file) {
var npath = path + '/' + file;
return stat(npath)
(function (stats) {
return stat(npath)(function (stats) {
return stats.isFile() ? file : null;

@@ -19,0 +18,0 @@ }, k(null));

@@ -5,3 +5,4 @@ // Return require function for given path

var defineProperty = Object.defineProperty
var isArray = Array.isArray
, defineProperty = Object.defineProperty
, Module = require('module')

@@ -26,3 +27,3 @@ , fs = require('fs')

throw new Error('require.paths is removed. Use ' +
'node_modules folders, or the NODE_PATH '+
'node_modules folders, or the NODE_PATH ' +
'environment variable instead.');

@@ -38,3 +39,3 @@ }});

require.extensions = Module._extensions;
require.registerExtension = function() {
require.registerExtension = function () {
throw new Error('require.registerExtension() removed. Use ' +

@@ -45,5 +46,6 @@ 'require.extensions instead.');

require.cache = nodeCache;
require.resolve = function(request) {
return Module._resolveFilename(request, module)[1];
}
require.resolve = function (request) {
var res = Module._resolveFilename(request, module);
return isArray(res) ? res[1] : res;
};

@@ -60,3 +62,3 @@ return require;

if ((fmodule = nodeCache[filename])) {
return cache[filename] = getFromNodeCache(fmodule);
return (cache[filename] = getFromNodeCache(fmodule));
}

@@ -71,3 +73,3 @@

fmodule.loaded = true;
return cache[filename] = getFromNodeCache(fmodule);
return (cache[filename] = getFromNodeCache(fmodule));
};

@@ -1,3 +0,3 @@

// Whether passed error is error thrown by require in case module (at given path)
// is not found
// Whether passed error is error thrown by require in case module
// (at given path) is not found

@@ -16,3 +16,3 @@ 'use strict';

module.exports = exports = function fn (e, path) {
module.exports = exports = function (e, path) {
return e.message === pattern.replace(token, path);

@@ -19,0 +19,0 @@ };

@@ -9,5 +9,7 @@ 'use strict';

if (process.env.OS === 'Windows_NT') {
from = /\//g; to = '\\';
from = /\//g;
to = '\\';
} else {
to = '/'; from = /\\/g;
to = '/';
from = /\\/g;
}

@@ -18,3 +20,3 @@

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

@@ -13,4 +13,5 @@ // Finds relative path between two absolute paths

module.exports = function (from, to) {
var x, y, separator, sfrom, orgto;
var prefrom = from; orgto = to;
var x, y, separator, sfrom, orgto
, prefrom = from;
orgto = to;
if (contains.call(from, '/') && contains.call(from, '\\')) {

@@ -26,5 +27,7 @@ from = normalize2(from);

if (contains.call(from, '/') || contains.call(to, '/')) {
separator = '/'; sfrom = /\\/g;
separator = '/';
sfrom = /\\/g;
} else if (contains.call(from, '\\') || contains.call(to, '\\')) {
separator = '\\'; sfrom = /\//g;
separator = '\\';
sfrom = /\//g;
} else {

@@ -61,5 +64,6 @@ separator = sysSep;

while (x.length && (x[0] === y[0])) {
x.shift(); y.shift();
x.shift();
y.shift();
}
return Array(x.length).join(".." + separator) + y.join(separator);
return new Array(x.length).join(".." + separator) + y.join(separator);
};

@@ -5,3 +5,3 @@ // Trims trailing slash from given path

var re = /.[\/\\]$/;
var re = /[\u0000-\.0-\[\]-\uffff][\/\\]$/;

@@ -8,0 +8,0 @@ module.exports = function (path) {

@@ -16,4 +16,4 @@ // Require module in given context

, modRequire = Module.prototype.require || function (path) {
return Module._load(path, this);
};
return Module._load(path, this);
};

@@ -24,3 +24,3 @@ module.exports = function (path, context) {

if ((context === global)
|| (context.process && (context.process.title === 'node')
|| (context.process && (context.process.title === 'node')
&& (context.pid === global.pid))) {

@@ -39,4 +39,4 @@ return require(path);

}
vm.runInContext(wrap(content), context).call(fmodule.exports, fmodule.exports,
fmodule.require.bind(fmodule), fmodule, path, dirpath);
vm.runInContext(wrap(content), context).call(fmodule.exports,
fmodule.exports, fmodule.require.bind(fmodule), fmodule, path, dirpath);
fmodule.loaded = true;

@@ -43,0 +43,0 @@ return fmodule.exports;

{
"name": "next",
"version": "0.2.11",
"version": "0.2.12",
"description": "Node.js extensions",

@@ -22,6 +22,8 @@ "keywords": ["node", "nodejs", "node.js", "extensions", "addons", "extras"],

"es5-ext": "0.7.x",
"deferred": "0.4.x"
"deferred": "0.4.x",
"minimatch": "0.1.x"
},
"scripts": {
"test": "node ./node_modules/tad/bin/tad lib"
"test": "node ./node_modules/tad/bin/tad lib",
"lint": "node ./node_modules/jslint/bin/jslint.js --color --git"
},

@@ -28,0 +30,0 @@ "devDependencies": {

@@ -14,3 +14,4 @@ 'use strict';

t(pgPath + '/package/one/two/', function (err, path) {
a.equal(normalize(path), normalize(pgPath + '/package')); d();
a.equal(normalize(path), normalize(pgPath + '/package'));
d();
});

@@ -20,13 +21,18 @@ },

t(pgPath + '/package2/one/two/samplefile', function (err, path) {
a.equal(normalize(path), normalize(pgPath + '/package2')); d();
a.equal(normalize(path), normalize(pgPath + '/package2'));
d();
});
},
"Detect by parent node_modules": function (t, a, d) {
t(pgPath + '/package2/node_modules/package/module.js', function (err, path) {
a.equal(normalize(path), normalize(pgPath + '/package2/node_modules/package')); d();
});
t(pgPath + '/package2/node_modules/package/module.js',
function (err, path) {
a.equal(normalize(path),
normalize(pgPath + '/package2/node_modules/package'));
d();
});
},
"No package path": function (t, a, d) {
t('/', function (err, path) {
a.equal(path, null); d();
a.equal(path, null);
d();
});

@@ -36,5 +42,6 @@ },

t(pgPath + '/package/abc/cdf', function (err, path) {
a.equal(normalize(path), normalize(pgPath + '/package')); d();
a.equal(normalize(path), normalize(pgPath + '/package'));
d();
});
}
};

@@ -12,3 +12,4 @@ 'use strict';

t(pgPath + '/package/one', function (exists) {
a.equal(exists, true); d();
a.equal(exists, true);
d();
});

@@ -18,3 +19,4 @@ },

t(pgPath + '/package/package.json', function (exists) {
a.equal(exists, false); d();
a.equal(exists, false);
d();
});

@@ -24,5 +26,6 @@ },

t(pgPath + '/package/bad.path', function (exists) {
a.equal(exists, false); d();
a.equal(exists, false);
d();
});
}
};

@@ -12,3 +12,4 @@ 'use strict';

t(pgPath + '/package/package.json', function (exists) {
a.equal(exists, true); d();
a.equal(exists, true);
d();
});

@@ -18,3 +19,4 @@ },

t(pgPath + '/package/one', function (exists) {
a.equal(exists, false); d();
a.equal(exists, false);
d();
});

@@ -24,5 +26,6 @@ },

t(pgPath + '/package/bad.path', function (exists) {
a.equal(exists, false); d();
a.equal(exists, false);
d();
});
}
};

@@ -18,3 +18,4 @@ 'use strict';

}
a.deep(result, [normalize(path)]); d();
a.deep(result, [normalize(path)]);
d();
});

@@ -36,3 +37,4 @@ },

return normalize(path + '/' + file);
}).sort()); d();
}).sort());
d();
});

@@ -42,2 +44,1 @@ });

};
'use strict';
var path = require('path')
, pgPath;

@@ -15,4 +14,5 @@

}
a.deepEqual(dirs.sort(), ['one', 'two'].sort()); d();
a.deepEqual(dirs.sort(), ['one', 'two'].sort());
d();
});
};

@@ -10,10 +10,137 @@ 'use strict';

module.exports = function (t, a, d) {
t(pgPath, function (err, files) {
if (err) {
throw err;
module.exports = function (t) {
return {
"": function (a, d) {
t(pgPath, function (err, files) {
if (err) {
d(err);
return;
}
a.deepEqual(files.sort(), [
'.gitignore', '.ignore', 'eleven', 'five', 'four', 'nine', 'nine.foo',
'nine.keep', 'seven', 'six', 'ten',
'one/.gitignore', 'one/.ignore', 'one/eleven', 'one/five', 'one/nine',
'one/nine.bar', 'one/nine.keep', 'one/seven', 'one/six', 'one/ten',
'one/one/.ignore', 'one/one/eleven', 'one/one/nine',
'one/one/nine.else', 'one/one/nine.keep', 'one/one/one',
'one/one/seven', 'one/one/six', 'one/one/ten',
'two/one'].map(normalize).sort());
d();
});
},
"pattern": function (a, d) {
t(pgPath, { pattern: /^five|nine[\u0000-\uffff]*$/ },
function (err, files) {
if (err) {
d(err);
return;
}
a.deepEqual(files.sort(), [
'five', 'nine', 'nine.foo', 'nine.keep',
'one/five', 'one/nine', 'one/nine.bar',
'one/nine.keep',
'one/one/nine',
'one/one/nine.else', 'one/one/nine.keep'].map(normalize).sort());
d();
});
},
"git": function (a, d) {
t(pgPath, { git: true }, function (err, files) {
if (err) {
d(err);
return;
}
a.deepEqual(files.sort(), [
'.ignore', 'eleven', 'five', 'four', 'nine', 'nine.foo',
'seven', 'six', 'ten',
'one/.ignore', 'one/five', 'one/nine',
'one/nine.bar', 'one/seven', 'one/six', 'one/ten',
'one/one/.ignore', 'one/one/eleven', 'one/one/nine',
'one/one/nine.else', 'one/one/one',
'one/one/seven', 'one/one/six', 'one/one/ten',
'two/one'].map(normalize).sort());
d();
});
},
"ignorefile": function (a, d) {
t(pgPath, { ignorefile: '.ignore' }, function (err, files) {
if (err) {
d(err);
return;
}
a.deepEqual(files.sort(), [
'.gitignore', 'eleven', 'four', 'nine', 'nine.keep',
'seven', 'ten',
'one/.gitignore', 'one/eleven', 'one/nine',
'one/nine.keep', 'one/ten',
'one/one/nine', 'one/one/nine.keep', 'one/one/one', 'one/one/six',
'two/one'].map(normalize).sort());
d();
});
},
"git & ignorefile": function (a, d) {
t(pgPath, { ignorefile: '.ignore', git: true }, function (err, files) {
if (err) {
d(err);
return;
}
a.deepEqual(files.sort(), [
'eleven', 'four', 'nine', 'nine.keep',
'seven', 'ten',
'one/nine',
'one/nine.keep', 'one/ten',
'one/one/nine', 'one/one/nine.keep', 'one/one/one', 'one/one/six',
'two/one'].map(normalize).sort());
d();
});
},
"pattern & ignorefile": function (a, d) {
t(pgPath, { pattern: /^five|nine[\u0000-\uffff]*$/,
ignorefile: '.ignore' }, function (err, files) {
if (err) {
d(err);
return;
}
a.deepEqual(files.sort(), [
'nine', 'nine.keep',
'one/nine',
'one/nine.keep',
'one/one/nine', 'one/one/nine.keep'].map(normalize).sort());
d();
});
},
"git & pattern & ignorefile": function (a, d) {
t(pgPath, { pattern: /^five|nine[\u0000-\uffff]*$/,
ignorefile: '.ignore', git: true }, function (err, files) {
if (err) {
d(err);
return;
}
a.deepEqual(files.sort(), [
'nine', 'nine.keep',
'one/nine',
'one/nine.keep',
'one/one/nine', 'one/one/nine.keep'].map(normalize).sort());
d();
});
}
a.deepEqual(files.sort(), ['four', 'five', normalize('one/one/one'),
normalize('two/one')].sort()); d();
});
};
};

@@ -15,4 +15,6 @@ 'use strict';

}
a.deepEqual(dirs.sort(), ['five', 'four'].sort()); d();
a.deepEqual(dirs.sort(), ['.gitignore', '.ignore', 'eleven', 'five', 'four',
'nine', 'nine.foo', 'nine.keep', 'seven', 'six', 'ten'].sort());
d();
});
};

@@ -12,3 +12,6 @@ 'use strict';

a(t(pg)('./sample'), require(pg + '/sample'));
},
"Resolve": function (t, a) {
a(t(pg).resolve('./sample'), pg + '/sample.js');
}
};

@@ -16,4 +16,4 @@ 'use strict';

a.never("Syntax error");
} catch (e) {
a(t(e, path), false, "Syntax error");
} catch (e2) {
a(t(e2, path), false, "Syntax error");
}

@@ -20,0 +20,0 @@ a.ok(t.token, "Exposes token");

'use strict';
module.exports = function (t, a) {
a.ok(t.match(/^[\/\\]$/))
a.ok(t.match(/^[\/\\]$/));
};

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