| module.exports = 42; |
| module.exports = 1; |
+12
-8
| { | ||
| "extends": "@ljharb", | ||
| "root": true, | ||
| "rules": { | ||
| "indent": [2, 4], | ||
| "strict": 0, | ||
| "complexity": 0, | ||
| "consistent-return": 0, | ||
| "curly": 0, | ||
| "func-name-matching": 0, | ||
| "func-style": 0, | ||
| "global-require": 0, | ||
| "id-length": [2, { "min": 1, "max": 30 }], | ||
| "max-nested-callbacks": 0, | ||
| "max-params": 0, | ||
| "max-statements-per-line": [2, { "max": 2 }], | ||
| "max-statements": 0, | ||
| "no-magic-numbers": 0, | ||
| "global-require": 0, | ||
| "no-console": 0, | ||
| "no-shadow": 0, | ||
| "no-unused-vars": [2, { "vars": "all", "args": "none" }], | ||
| "no-use-before-define": 0, | ||
| "object-curly-newline": 0, | ||
| "operator-linebreak": [2, "before"], | ||
| "sort-keys": 0, | ||
| "max-statements-per-line": [2, { "max": 2 }], | ||
| "func-name-matching": 0, | ||
| "func-style": 0, | ||
| "object-curly-newline": 0, | ||
| "no-use-before-define": 1, | ||
| "complexity": 0, | ||
| "consistent-return": 0 | ||
| } | ||
| } |
+51
-27
@@ -5,6 +5,6 @@ language: node_js | ||
| node_js: | ||
| - "7.2" | ||
| - "6.9" | ||
| - "7.9" | ||
| - "6.10" | ||
| - "5.12" | ||
| - "4.6" | ||
| - "4.8" | ||
| - "iojs-v3.3" | ||
@@ -20,2 +20,4 @@ - "iojs-v2.5" | ||
| - 'if [ "${TRAVIS_NODE_VERSION}" != "0.6" ] && [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then npm install -g npm; fi' | ||
| install: | ||
| - 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ]; then nvm install 0.8 && npm install -g npm@1.3 && npm install -g npm@1.4.28 && npm install -g npm@2 && npm install && nvm use "${TRAVIS_NODE_VERSION}"; else npm install; fi;' | ||
| script: | ||
@@ -32,2 +34,18 @@ - 'if [ -n "${PRETEST-}" ]; then npm run pretest ; fi' | ||
| include: | ||
| - node_js: "node" | ||
| env: PRETEST=true | ||
| - node_js: "7.8" | ||
| env: TEST=true ALLOW_FAILURE=true | ||
| - node_js: "7.7" | ||
| env: TEST=true ALLOW_FAILURE=true | ||
| - node_js: "7.6" | ||
| env: TEST=true ALLOW_FAILURE=true | ||
| - node_js: "7.5" | ||
| env: TEST=true ALLOW_FAILURE=true | ||
| - node_js: "7.4" | ||
| env: TEST=true ALLOW_FAILURE=true | ||
| - node_js: "7.3" | ||
| env: TEST=true ALLOW_FAILURE=true | ||
| - node_js: "7.2" | ||
| env: TEST=true ALLOW_FAILURE=true | ||
| - node_js: "7.1" | ||
@@ -37,2 +55,4 @@ env: TEST=true ALLOW_FAILURE=true | ||
| env: TEST=true ALLOW_FAILURE=true | ||
| - node_js: "6.9" | ||
| env: TEST=true ALLOW_FAILURE=true | ||
| - node_js: "6.8" | ||
@@ -80,2 +100,6 @@ env: TEST=true ALLOW_FAILURE=true | ||
| env: TEST=true ALLOW_FAILURE=true | ||
| - node_js: "4.7" | ||
| env: TEST=true ALLOW_FAILURE=true | ||
| - node_js: "4.6" | ||
| env: TEST=true ALLOW_FAILURE=true | ||
| - node_js: "4.5" | ||
@@ -131,28 +155,28 @@ env: TEST=true ALLOW_FAILURE=true | ||
| env: TEST=true ALLOW_FAILURE=true | ||
| - node_js: "7" | ||
| env: TEST=true | ||
| os: osx | ||
| - node_js: "6" | ||
| env: TEST=true | ||
| os: osx | ||
| - node_js: "5" | ||
| env: TEST=true | ||
| os: osx | ||
| - node_js: "4" | ||
| env: TEST=true | ||
| os: osx | ||
| - node_js: "iojs" | ||
| env: TEST=true | ||
| os: osx | ||
| - node_js: "0.12" | ||
| env: TEST=true | ||
| os: osx | ||
| - node_js: "0.10" | ||
| env: TEST=true | ||
| os: osx | ||
| - node_js: "0.8" | ||
| env: TEST=true | ||
| os: osx | ||
| ##- node_js: "7" | ||
| #env: TEST=true | ||
| #os: osx | ||
| #- node_js: "6" | ||
| #env: TEST=true | ||
| #os: osx | ||
| #- node_js: "5" | ||
| #env: TEST=true | ||
| #os: osx | ||
| #- node_js: "4" | ||
| #env: TEST=true | ||
| #os: osx | ||
| #- node_js: "iojs" | ||
| #env: TEST=true | ||
| #os: osx | ||
| #- node_js: "0.12" | ||
| #env: TEST=true | ||
| #os: osx | ||
| #- node_js: "0.10" | ||
| #env: TEST=true | ||
| #os: osx | ||
| #- node_js: "0.8" | ||
| #env: TEST=true | ||
| #os: osx | ||
| allow_failures: | ||
| - os: osx | ||
| - env: TEST=true ALLOW_FAILURE=true |
+7
-4
| var core = require('./lib/core'); | ||
| exports = module.exports = require('./lib/async'); | ||
| exports.core = core; | ||
| exports.isCore = function isCore(x) { return core[x]; }; | ||
| exports.sync = require('./lib/sync'); | ||
| var async = require('./lib/async'); | ||
| async.core = core; | ||
| async.isCore = function isCore(x) { return core[x]; }; | ||
| async.sync = require('./lib/sync'); | ||
| exports = async; | ||
| module.exports = async; |
+24
-19
@@ -15,3 +15,3 @@ var core = require('./core'); | ||
| if (typeof x !== 'string') { | ||
| var err = new TypeError('path must be a string'); | ||
| var err = new TypeError('Path must be a string.'); | ||
| return process.nextTick(function () { | ||
@@ -24,5 +24,7 @@ cb(err); | ||
| fs.stat(file, function (err, stat) { | ||
| if (err && err.code === 'ENOENT') cb(null, false); | ||
| else if (err) cb(err); | ||
| else cb(null, stat.isFile() || stat.isFIFO()); | ||
| if (!err) { | ||
| return cb(null, stat.isFile() || stat.isFIFO()); | ||
| } | ||
| if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false); | ||
| return cb(err); | ||
| }); | ||
@@ -37,5 +39,5 @@ }; | ||
| if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[\\\/])/.test(x)) { | ||
| if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/.test(x)) { | ||
| var res = path.resolve(y, x); | ||
| if (x === '..') res += '/'; | ||
| if (x === '..' || x.slice(-1) === '/') res += '/'; | ||
| if (/\/$/.test(x) && res === y) { | ||
@@ -69,16 +71,18 @@ loadAsDirectory(res, opts.package, onfile); | ||
| function loadAsFile(x, pkg, callback) { | ||
| function loadAsFile(x, thePackage, callback) { | ||
| var loadAsFilePackage = thePackage; | ||
| var cb = callback; | ||
| if (typeof pkg === 'function') { | ||
| cb = pkg; | ||
| pkg = undefined; | ||
| if (typeof loadAsFilePackage === 'function') { | ||
| cb = loadAsFilePackage; | ||
| loadAsFilePackage = undefined; | ||
| } | ||
| var exts = [''].concat(extensions); | ||
| load(exts, x, pkg); | ||
| load(exts, x, loadAsFilePackage); | ||
| function load(exts, x, pkg) { | ||
| if (exts.length === 0) return cb(null, undefined, pkg); | ||
| function load(exts, x, loadPackage) { | ||
| if (exts.length === 0) return cb(null, undefined, loadPackage); | ||
| var file = x + exts[0]; | ||
| var pkg = loadPackage; | ||
| if (pkg) onpkg(null, pkg); | ||
@@ -103,5 +107,5 @@ else loadpkg(path.dirname(file), onpkg); | ||
| function onex(err, ex) { | ||
| if (err) cb(err); | ||
| else if (!ex) load(exts.slice(1), x, pkg); | ||
| else cb(null, file, pkg); | ||
| if (err) return cb(err); | ||
| if (ex) return cb(null, file, pkg); | ||
| load(exts.slice(1), x, pkg); | ||
| } | ||
@@ -113,6 +117,6 @@ } | ||
| if (dir === '' || dir === '/') return cb(null); | ||
| if (process.platform === 'win32' && (/^\w:[\\\/]*$/).test(dir)) { | ||
| if (process.platform === 'win32' && (/^\w:[/\\]*$/).test(dir)) { | ||
| return cb(null); | ||
| } | ||
| if (/[\\\/]node_modules[\\\/]*$/.test(dir)) return cb(null); | ||
| if (/[/\\]node_modules[/\\]*$/.test(dir)) return cb(null); | ||
@@ -136,4 +140,5 @@ var pkgfile = path.join(dir, 'package.json'); | ||
| function loadAsDirectory(x, fpkg, callback) { | ||
| function loadAsDirectory(x, loadAsDirectoryPackage, callback) { | ||
| var cb = callback; | ||
| var fpkg = loadAsDirectoryPackage; | ||
| if (typeof fpkg === 'function') { | ||
@@ -140,0 +145,0 @@ cb = fpkg; |
+2
-2
@@ -1,2 +0,2 @@ | ||
| var current = process.versions && process.versions.node && process.versions.node.split('.') || []; | ||
| var current = (process.versions && process.versions.node && process.versions.node.split('.')) || []; | ||
@@ -15,3 +15,3 @@ function versionIncluded(version) { | ||
| var core = {}; | ||
| for (var version in data) { | ||
| for (var version in data) { // eslint-disable-line no-restricted-syntax | ||
| if (Object.prototype.hasOwnProperty.call(data, version) && versionIncluded(version)) { | ||
@@ -18,0 +18,0 @@ for (var i = 0; i < data[version].length; ++i) { |
@@ -12,13 +12,13 @@ var path = require('path'); | ||
| // resolving against the process' current working directory | ||
| start = path.resolve(start); | ||
| var absoluteStart = path.resolve(start); | ||
| var prefix = '/'; | ||
| if (/^([A-Za-z]:)/.test(start)) { | ||
| if (/^([A-Za-z]:)/.test(absoluteStart)) { | ||
| prefix = ''; | ||
| } else if (/^\\\\/.test(start)) { | ||
| } else if (/^\\\\/.test(absoluteStart)) { | ||
| prefix = '\\\\'; | ||
| } | ||
| var paths = [start]; | ||
| var parsed = parse(start); | ||
| var paths = [absoluteStart]; | ||
| var parsed = parse(absoluteStart); | ||
| while (parsed.dir !== paths[paths.length - 1]) { | ||
@@ -25,0 +25,0 @@ paths.push(parsed.dir); |
+6
-3
@@ -8,2 +8,5 @@ var core = require('./core'); | ||
| module.exports = function (x, options) { | ||
| if (typeof x !== 'string') { | ||
| throw new TypeError('Path must be a string.'); | ||
| } | ||
| var opts = options || {}; | ||
@@ -14,3 +17,3 @@ var isFile = opts.isFile || function (file) { | ||
| } catch (e) { | ||
| if (e && e.code === 'ENOENT') return false; | ||
| if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false; | ||
| throw e; | ||
@@ -27,5 +30,5 @@ } | ||
| if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[\\\/])/.test(x)) { | ||
| if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/.test(x)) { | ||
| var res = path.resolve(y, x); | ||
| if (x === '..') res += '/'; | ||
| if (x === '..' || x.slice(-1) === '/') res += '/'; | ||
| var m = loadAsFileSync(res) || loadAsDirectorySync(res); | ||
@@ -32,0 +35,0 @@ if (m) return m; |
+5
-1
| { | ||
| "name": "resolve", | ||
| "description": "resolve like require.resolve() on behalf of files asynchronously and synchronously", | ||
| "version": "1.3.2", | ||
| "version": "1.3.3", | ||
| "repository": { | ||
@@ -18,6 +18,10 @@ "type": "git", | ||
| "prepublish": "safe-publish-latest", | ||
| "lint": "eslint .", | ||
| "tests-only": "tape test/*.js", | ||
| "pretest": "npm run lint", | ||
| "test": "npm run --silent tests-only" | ||
| }, | ||
| "devDependencies": { | ||
| "@ljharb/eslint-config": "^11.0.0", | ||
| "eslint": "^3.19.0", | ||
| "object-keys": "^1.0.11", | ||
@@ -24,0 +28,0 @@ "safe-publish-latest": "^1.1.1", |
+1
-1
@@ -20,3 +20,3 @@ var test = require('tape'); | ||
| st.doesNotThrow( | ||
| function () { require(resolve.core[i]); }, | ||
| function () { require(resolve.core[i]); }, // eslint-disable-line no-loop-func | ||
| 'requiring ' + resolve.core[i] + ' does not throw' | ||
@@ -23,0 +23,0 @@ ); |
@@ -46,5 +46,5 @@ var path = require('path'); | ||
| }, function (err, res) { | ||
| var root = require('tap/package.json').main; | ||
| var root = require('tap/package.json').main; | ||
| t.equal(res, path.resolve(__dirname, '..', 'node_modules/tap', root)); | ||
| }); | ||
| }); |
@@ -9,4 +9,3 @@ var test = require('tape'); | ||
| var verifyDirs = function verifyDirs(t, start, dirs, moduleDirectories, paths) { | ||
| moduleDirectories = [].concat(moduleDirectories || 'node_modules'); | ||
| if (!paths) { paths = []; } | ||
| var moduleDirs = [].concat(moduleDirectories || 'node_modules'); | ||
@@ -25,3 +24,3 @@ var foundModuleDirs = {}; | ||
| var foundModuleDirNames = keys(foundModuleDirs); | ||
| t.deepEqual(foundModuleDirNames, moduleDirectories.concat(paths), 'all desired module dirs were found'); | ||
| t.deepEqual(foundModuleDirNames, moduleDirs.concat(paths || []), 'all desired module dirs were found'); | ||
| t.equal(keys(uniqueDirs).length, dirs.length, 'all dirs provided were unique'); | ||
@@ -28,0 +27,0 @@ |
@@ -16,3 +16,3 @@ var path = require('path'); | ||
| test('./ should not load ${dir}.js', function (t) { | ||
| test('./ should not load ${dir}.js', function (t) { // eslint-disable-line no-template-curly-in-string | ||
| t.plan(1); | ||
@@ -19,0 +19,0 @@ var dir = path.join(__dirname, 'precedence/bbb'); |
@@ -207,1 +207,48 @@ var path = require('path'); | ||
| test('#52 - incorrectly resolves module-paths like "./someFolder/" when there is a file of the same name', function (t) { | ||
| var dir = path.join(__dirname, 'resolver'); | ||
| t.equal( | ||
| resolve.sync('./foo', { basedir: path.join(dir, 'same_names') }), | ||
| path.join(dir, 'same_names/foo.js') | ||
| ); | ||
| t.equal( | ||
| resolve.sync('./foo/', { basedir: path.join(dir, 'same_names') }), | ||
| path.join(dir, 'same_names/foo/index.js') | ||
| ); | ||
| t.end(); | ||
| }); | ||
| test('sync: #121 - treating an existing file as a dir when no basedir', function (t) { | ||
| var testFile = path.basename(__filename); | ||
| t.test('sanity check', function (st) { | ||
| st.equal( | ||
| resolve.sync('./' + testFile), | ||
| __filename, | ||
| 'sanity check' | ||
| ); | ||
| st.end(); | ||
| }); | ||
| t.test('with a fake directory', function (st) { | ||
| function run() { return resolve.sync('./' + testFile + '/blah'); } | ||
| st.throws(run, 'throws an error'); | ||
| try { | ||
| run(); | ||
| } catch (e) { | ||
| st.equal(e.code, 'MODULE_NOT_FOUND', 'error code matches require.resolve'); | ||
| st.equal( | ||
| e.message, | ||
| 'Cannot find module \'./' + testFile + '/blah\' from \'' + __dirname + '\'', | ||
| 'can not find nonexistent module' | ||
| ); | ||
| } | ||
| st.end(); | ||
| }); | ||
| t.end(); | ||
| }); |
+50
-3
@@ -12,3 +12,3 @@ var path = require('path'); | ||
| t.equal(res, path.join(dir, 'foo.js')); | ||
| t.equal(pkg.name, 'resolve'); | ||
| t.equal(pkg && pkg.name, 'resolve'); | ||
| }); | ||
@@ -19,3 +19,3 @@ | ||
| t.equal(res, path.join(dir, 'foo.js')); | ||
| t.equal(pkg.name, 'resolve'); | ||
| t.equal(pkg && pkg.name, 'resolve'); | ||
| }); | ||
@@ -26,3 +26,3 @@ | ||
| t.equal(res, path.join(dir, 'foo.js')); | ||
| t.equal(pkg.main, 'resolver'); | ||
| t.equal(pkg && pkg.main, 'resolver'); | ||
| }); | ||
@@ -284,1 +284,48 @@ | ||
| }); | ||
| test('#52 - incorrectly resolves module-paths like "./someFolder/" when there is a file of the same name', function (t) { | ||
| t.plan(2); | ||
| var dir = path.join(__dirname, 'resolver'); | ||
| resolve('./foo', { basedir: path.join(dir, 'same_names') }, function (err, res, pkg) { | ||
| if (err) t.fail(err); | ||
| t.equal(res, path.join(dir, 'same_names/foo.js')); | ||
| }); | ||
| resolve('./foo/', { basedir: path.join(dir, 'same_names') }, function (err, res, pkg) { | ||
| if (err) t.fail(err); | ||
| t.equal(res, path.join(dir, 'same_names/foo/index.js')); | ||
| }); | ||
| }); | ||
| test('async: #121 - treating an existing file as a dir when no basedir', function (t) { | ||
| var testFile = path.basename(__filename); | ||
| t.test('sanity check', function (st) { | ||
| st.plan(1); | ||
| resolve('./' + testFile, function (err, res, pkg) { | ||
| if (err) t.fail(err); | ||
| st.equal(res, __filename, 'sanity check'); | ||
| }); | ||
| }); | ||
| t.test('with a fake directory', function (st) { | ||
| st.plan(4); | ||
| resolve('./' + testFile + '/blah', function (err, res, pkg) { | ||
| st.ok(err, 'there is an error'); | ||
| st.notOk(res, 'no result'); | ||
| st.equal(err && err.code, 'MODULE_NOT_FOUND', 'error code matches require.resolve'); | ||
| st.equal( | ||
| err && err.message, | ||
| 'Cannot find module \'./' + testFile + '/blah\' from \'' + __dirname + '\'', | ||
| 'can not find nonexistent module' | ||
| ); | ||
| st.end(); | ||
| }); | ||
| }); | ||
| t.end(); | ||
| }); |
| { | ||
| "rules": { | ||
| "max-nested-callbacks": 0 | ||
| } | ||
| } |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
61046
8.39%64
1.59%1375
6.75%6
50%