Socket
Socket
Sign inDemoInstall

eslint-module-utils

Package Overview
Dependencies
9
Maintainers
3
Versions
26
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.6.0 to 2.6.1

.nycrc

16

CHANGELOG.md

@@ -8,6 +8,16 @@ # Change Log

## v2.6.1 - 2021-05-13
### Fixed
- `no-unresolved`: check `import()` ([#2026], thanks [@aladdin-add])
- Add fix for Windows Subsystem for Linux ([#1786], thanks [@manuth])
### Changed
- [deps] update `debug`
- [Refactor] use `Array.isArray` instead of `instanceof Array`
## v2.6.0 - 2020-03-28
### Added
[New] Print more helpful info if parsing fails ([#1671], thanks [@kaiyoma])
- Print more helpful info if parsing fails ([#1671], thanks [@kaiyoma])

@@ -79,2 +89,4 @@ ## v2.5.2 - 2020-01-12

[#2026]: https://github.com/benmosher/eslint-plugin-import/pull/2026
[#1786]: https://github.com/benmosher/eslint-plugin-import/pull/1786
[#1671]: https://github.com/benmosher/eslint-plugin-import/pull/1671

@@ -106,1 +118,3 @@ [#1606]: https://github.com/benmosher/eslint-plugin-import/pull/1606

[@kaiyoma]: https://github.com/kaiyoma
[@manuth]: https://github.com/manuth
[@aladdin-add]: https://github.com/aladdin-add

19

declaredScope.js

@@ -1,14 +0,9 @@

'use strict'
exports.__esModule = true
'use strict';
exports.__esModule = true;
exports.default = function declaredScope(context, name) {
let references = context.getScope().references
, i
for (i = 0; i < references.length; i++) {
if (references[i].identifier.name === name) {
break
}
}
if (!references[i]) return undefined
return references[i].resolved.scope.type
}
const references = context.getScope().references;
const reference = references.find(x => x.identifier.name === name);
if (!reference) return undefined;
return reference.resolved.scope.type;
};

@@ -5,56 +5,56 @@ /**

*/
'use strict'
exports.__esModule = true
'use strict';
exports.__esModule = true;
const createHash = require('crypto').createHash
const createHash = require('crypto').createHash;
const stringify = JSON.stringify
const stringify = JSON.stringify;
function hashify(value, hash) {
if (!hash) hash = createHash('sha256')
if (!hash) hash = createHash('sha256');
if (value instanceof Array) {
hashArray(value, hash)
if (Array.isArray(value)) {
hashArray(value, hash);
} else if (value instanceof Object) {
hashObject(value, hash)
hashObject(value, hash);
} else {
hash.update(stringify(value) || 'undefined')
hash.update(stringify(value) || 'undefined');
}
return hash
return hash;
}
exports.default = hashify
exports.default = hashify;
function hashArray(array, hash) {
if (!hash) hash = createHash('sha256')
if (!hash) hash = createHash('sha256');
hash.update('[')
hash.update('[');
for (let i = 0; i < array.length; i++) {
hashify(array[i], hash)
hash.update(',')
hashify(array[i], hash);
hash.update(',');
}
hash.update(']')
hash.update(']');
return hash
return hash;
}
hashify.array = hashArray
exports.hashArray = hashArray
hashify.array = hashArray;
exports.hashArray = hashArray;
function hashObject(object, hash) {
if (!hash) hash = createHash('sha256')
if (!hash) hash = createHash('sha256');
hash.update('{')
hash.update('{');
Object.keys(object).sort().forEach(key => {
hash.update(stringify(key))
hash.update(':')
hashify(object[key], hash)
hash.update(',')
})
hash.update('}')
hash.update(stringify(key));
hash.update(':');
hashify(object[key], hash);
hash.update(',');
});
hash.update('}');
return hash
return hash;
}
hashify.object = hashObject
exports.hashObject = hashObject
hashify.object = hashObject;
exports.hashObject = hashObject;

@@ -1,18 +0,18 @@

'use strict'
exports.__esModule = true
'use strict';
exports.__esModule = true;
const extname = require('path').extname
const extname = require('path').extname;
const log = require('debug')('eslint-plugin-import:utils:ignore')
const log = require('debug')('eslint-plugin-import:utils:ignore');
// one-shot memoized
let cachedSet, lastSettings
let cachedSet; let lastSettings;
function validExtensions(context) {
if (cachedSet && context.settings === lastSettings) {
return cachedSet
return cachedSet;
}
lastSettings = context.settings
cachedSet = makeValidExtensionSet(context.settings)
return cachedSet
lastSettings = context.settings;
cachedSet = makeValidExtensionSet(context.settings);
return cachedSet;
}

@@ -22,40 +22,40 @@

// start with explicit JS-parsed extensions
const exts = new Set(settings['import/extensions'] || [ '.js' ])
const exts = new Set(settings['import/extensions'] || [ '.js' ]);
// all alternate parser extensions are also valid
if ('import/parsers' in settings) {
for (let parser in settings['import/parsers']) {
const parserSettings = settings['import/parsers'][parser]
for (const parser in settings['import/parsers']) {
const parserSettings = settings['import/parsers'][parser];
if (!Array.isArray(parserSettings)) {
throw new TypeError('"settings" for ' + parser + ' must be an array')
throw new TypeError('"settings" for ' + parser + ' must be an array');
}
parserSettings.forEach(ext => exts.add(ext))
parserSettings.forEach(ext => exts.add(ext));
}
}
return exts
return exts;
}
exports.getFileExtensions = makeValidExtensionSet
exports.getFileExtensions = makeValidExtensionSet;
exports.default = function ignore(path, context) {
// check extension whitelist first (cheap)
if (!hasValidExtension(path, context)) return true
if (!hasValidExtension(path, context)) return true;
if (!('import/ignore' in context.settings)) return false
const ignoreStrings = context.settings['import/ignore']
if (!('import/ignore' in context.settings)) return false;
const ignoreStrings = context.settings['import/ignore'];
for (let i = 0; i < ignoreStrings.length; i++) {
const regex = new RegExp(ignoreStrings[i])
const regex = new RegExp(ignoreStrings[i]);
if (regex.test(path)) {
log(`ignoring ${path}, matched pattern /${ignoreStrings[i]}/`)
return true
log(`ignoring ${path}, matched pattern /${ignoreStrings[i]}/`);
return true;
}
}
return false
}
return false;
};
function hasValidExtension(path, context) {
return validExtensions(context).has(extname(path))
return validExtensions(context).has(extname(path));
}
exports.hasValidExtension = hasValidExtension
exports.hasValidExtension = hasValidExtension;

@@ -1,13 +0,13 @@

'use strict'
exports.__esModule = true
'use strict';
exports.__esModule = true;
const Module = require('module')
const path = require('path')
const Module = require('module');
const path = require('path');
// borrowed from babel-eslint
function createModule(filename) {
const mod = new Module(filename)
mod.filename = filename
mod.paths = Module._nodeModulePaths(path.dirname(filename))
return mod
const mod = new Module(filename);
mod.filename = filename;
mod.paths = Module._nodeModulePaths(path.dirname(filename));
return mod;
}

@@ -18,5 +18,5 @@

// attempt to get espree relative to eslint
const eslintPath = require.resolve('eslint')
const eslintModule = createModule(eslintPath)
return require(Module._resolveFilename(p, eslintModule))
const eslintPath = require.resolve('eslint');
const eslintModule = createModule(eslintPath);
return require(Module._resolveFilename(p, eslintModule));
} catch(err) { /* ignore */ }

@@ -26,7 +26,7 @@

// try relative to entry point
return require.main.require(p)
return require.main.require(p);
} catch(err) { /* ignore */ }
// finally, try from here
return require(p)
}
return require(p);
};

@@ -1,9 +0,9 @@

'use strict'
exports.__esModule = true
'use strict';
exports.__esModule = true;
const log = require('debug')('eslint-module-utils:ModuleCache')
const log = require('debug')('eslint-module-utils:ModuleCache');
class ModuleCache {
constructor(map) {
this.map = map || new Map()
this.map = map || new Map();
}

@@ -17,5 +17,5 @@

set(cacheKey, result) {
this.map.set(cacheKey, { result, lastSeen: process.hrtime() })
log('setting entry for', cacheKey)
return result
this.map.set(cacheKey, { result, lastSeen: process.hrtime() });
log('setting entry for', cacheKey);
return result;
}

@@ -25,8 +25,8 @@

if (this.map.has(cacheKey)) {
const f = this.map.get(cacheKey)
const f = this.map.get(cacheKey);
// check freshness
if (process.hrtime(f.lastSeen)[0] < settings.lifetime) return f.result
} else log('cache miss for', cacheKey)
if (process.hrtime(f.lastSeen)[0] < settings.lifetime) return f.result;
} else log('cache miss for', cacheKey);
// cache miss
return undefined
return undefined;
}

@@ -39,12 +39,12 @@

lifetime: 30, // seconds
}, settings['import/cache'])
}, settings['import/cache']);
// parse infinity
if (cacheSettings.lifetime === '∞' || cacheSettings.lifetime === 'Infinity') {
cacheSettings.lifetime = Infinity
cacheSettings.lifetime = Infinity;
}
return cacheSettings
}
return cacheSettings;
};
exports.default = ModuleCache
exports.default = ModuleCache;

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

'use strict'
exports.__esModule = true
'use strict';
exports.__esModule = true;

@@ -15,17 +15,17 @@ /**

// if esmodule is not explicitly disabled, it is assumed to be enabled
options = Object.assign({ esmodule: true }, options)
options = Object.assign({ esmodule: true }, options);
let ignoreRegExps = []
let ignoreRegExps = [];
if (options.ignore != null) {
ignoreRegExps = options.ignore.map(p => new RegExp(p))
ignoreRegExps = options.ignore.map(p => new RegExp(p));
}
function checkSourceValue(source, importer) {
if (source == null) return //?
if (source == null) return; //?
// handle ignore
if (ignoreRegExps.some(re => re.test(source.value))) return
if (ignoreRegExps.some(re => re.test(source.value))) return;
// fire visitor
visitor(source, importer)
visitor(source, importer);
}

@@ -35,3 +35,3 @@

function checkSource(node) {
checkSourceValue(node.source, node)
checkSourceValue(node.source, node);
}

@@ -41,10 +41,17 @@

function checkImportCall(node) {
if (node.callee.type !== 'Import') return
if (node.arguments.length !== 1) return
let modulePath;
// refs https://github.com/estree/estree/blob/master/es2020.md#importexpression
if (node.type === 'ImportExpression') {
modulePath = node.source;
} else if (node.type === 'CallExpression') {
if (node.callee.type !== 'Import') return;
if (node.arguments.length !== 1) return;
const modulePath = node.arguments[0]
if (modulePath.type !== 'Literal') return
if (typeof modulePath.value !== 'string') return
modulePath = node.arguments[0];
}
checkSourceValue(modulePath, node)
if (modulePath.type !== 'Literal') return;
if (typeof modulePath.value !== 'string') return;
checkSourceValue(modulePath, node);
}

@@ -55,34 +62,34 @@

function checkCommon(call) {
if (call.callee.type !== 'Identifier') return
if (call.callee.name !== 'require') return
if (call.arguments.length !== 1) return
if (call.callee.type !== 'Identifier') return;
if (call.callee.name !== 'require') return;
if (call.arguments.length !== 1) return;
const modulePath = call.arguments[0]
if (modulePath.type !== 'Literal') return
if (typeof modulePath.value !== 'string') return
const modulePath = call.arguments[0];
if (modulePath.type !== 'Literal') return;
if (typeof modulePath.value !== 'string') return;
checkSourceValue(modulePath, call)
checkSourceValue(modulePath, call);
}
function checkAMD(call) {
if (call.callee.type !== 'Identifier') return
if (call.callee.type !== 'Identifier') return;
if (call.callee.name !== 'require' &&
call.callee.name !== 'define') return
if (call.arguments.length !== 2) return
call.callee.name !== 'define') return;
if (call.arguments.length !== 2) return;
const modules = call.arguments[0]
if (modules.type !== 'ArrayExpression') return
const modules = call.arguments[0];
if (modules.type !== 'ArrayExpression') return;
for (let element of modules.elements) {
if (element.type !== 'Literal') continue
if (typeof element.value !== 'string') continue
for (const element of modules.elements) {
if (element.type !== 'Literal') continue;
if (typeof element.value !== 'string') continue;
if (element.value === 'require' ||
element.value === 'exports') continue // magic modules: http://git.io/vByan
element.value === 'exports') continue; // magic modules: http://git.io/vByan
checkSourceValue(element, element)
checkSourceValue(element, element);
}
}
const visitors = {}
const visitors = {};
if (options.esmodule) {

@@ -94,16 +101,17 @@ Object.assign(visitors, {

'CallExpression': checkImportCall,
})
'ImportExpression': checkImportCall,
});
}
if (options.commonjs || options.amd) {
const currentCallExpression = visitors['CallExpression']
const currentCallExpression = visitors['CallExpression'];
visitors['CallExpression'] = function (call) {
if (currentCallExpression) currentCallExpression(call)
if (options.commonjs) checkCommon(call)
if (options.amd) checkAMD(call)
}
if (currentCallExpression) currentCallExpression(call);
if (options.commonjs) checkCommon(call);
if (options.amd) checkAMD(call);
};
}
return visitors
}
return visitors;
};

@@ -129,13 +137,13 @@ /**

'additionalProperties': false,
}
};
if (additionalProperties){
for (let key in additionalProperties) {
base.properties[key] = additionalProperties[key]
for (const key in additionalProperties) {
base.properties[key] = additionalProperties[key];
}
}
return base
return base;
}
exports.makeOptionsSchema = makeOptionsSchema
exports.makeOptionsSchema = makeOptionsSchema;

@@ -147,2 +155,2 @@ /**

*/
exports.optionsSchema = makeOptionsSchema()
exports.optionsSchema = makeOptionsSchema();
{
"name": "eslint-module-utils",
"version": "2.6.0",
"version": "2.6.1",
"description": "Core utilities to support eslint-plugin-import and other module-related plugins.",

@@ -29,5 +29,5 @@ "engines": {

"dependencies": {
"debug": "^2.6.9",
"debug": "^3.2.7",
"pkg-dir": "^2.0.0"
}
}

@@ -1,35 +0,35 @@

'use strict'
exports.__esModule = true
'use strict';
exports.__esModule = true;
const moduleRequire = require('./module-require').default
const extname = require('path').extname
const moduleRequire = require('./module-require').default;
const extname = require('path').extname;
const log = require('debug')('eslint-plugin-import:parse')
const log = require('debug')('eslint-plugin-import:parse');
exports.default = function parse(path, content, context) {
if (context == null) throw new Error('need context to parse properly')
if (context == null) throw new Error('need context to parse properly');
let parserOptions = context.parserOptions
const parserPath = getParserPath(path, context)
let parserOptions = context.parserOptions;
const parserPath = getParserPath(path, context);
if (!parserPath) throw new Error('parserPath is required!')
if (!parserPath) throw new Error('parserPath is required!');
// hack: espree blows up with frozen options
parserOptions = Object.assign({}, parserOptions)
parserOptions.ecmaFeatures = Object.assign({}, parserOptions.ecmaFeatures)
parserOptions = Object.assign({}, parserOptions);
parserOptions.ecmaFeatures = Object.assign({}, parserOptions.ecmaFeatures);
// always include comments and tokens (for doc parsing)
parserOptions.comment = true
parserOptions.attachComment = true // keeping this for backward-compat with older parsers
parserOptions.tokens = true
parserOptions.comment = true;
parserOptions.attachComment = true; // keeping this for backward-compat with older parsers
parserOptions.tokens = true;
// attach node locations
parserOptions.loc = true
parserOptions.range = true
parserOptions.loc = true;
parserOptions.range = true;
// provide the `filePath` like eslint itself does, in `parserOptions`
// https://github.com/eslint/eslint/blob/3ec436ee/lib/linter.js#L637
parserOptions.filePath = path
parserOptions.filePath = path;
// @typescript-eslint/parser will parse the entire project with typechecking if you provide

@@ -39,16 +39,16 @@ // "project" or "projects" in parserOptions. Removing these options means the parser will

// https://github.com/benmosher/eslint-plugin-import/issues/1408#issuecomment-509298962
delete parserOptions.project
delete parserOptions.projects
delete parserOptions.project;
delete parserOptions.projects;
// require the parser relative to the main module (i.e., ESLint)
const parser = moduleRequire(parserPath)
const parser = moduleRequire(parserPath);
if (typeof parser.parseForESLint === 'function') {
let ast
let ast;
try {
ast = parser.parseForESLint(content, parserOptions).ast
ast = parser.parseForESLint(content, parserOptions).ast;
} catch (e) {
console.warn()
console.warn('Error while parsing ' + parserOptions.filePath)
console.warn('Line ' + e.lineNumber + ', column ' + e.column + ': ' + e.message)
console.warn();
console.warn('Error while parsing ' + parserOptions.filePath);
console.warn('Line ' + e.lineNumber + ', column ' + e.column + ': ' + e.message);
}

@@ -60,20 +60,20 @@ if (!ast || typeof ast !== 'object') {

'` is invalid and will just be ignored'
)
);
} else {
return ast
return ast;
}
}
return parser.parse(content, parserOptions)
}
return parser.parse(content, parserOptions);
};
function getParserPath(path, context) {
const parsers = context.settings['import/parsers']
const parsers = context.settings['import/parsers'];
if (parsers != null) {
const extension = extname(path)
for (let parserPath in parsers) {
const extension = extname(path);
for (const parserPath in parsers) {
if (parsers[parserPath].indexOf(extension) > -1) {
// use this alternate parser
log('using alt parser:', parserPath)
return parserPath
log('using alt parser:', parserPath);
return parserPath;
}

@@ -83,3 +83,3 @@ }

// default to use ESLint parser
return context.parserPath
return context.parserPath;
}

@@ -1,19 +0,19 @@

'use strict'
exports.__esModule = true
'use strict';
exports.__esModule = true;
const pkgDir = require('pkg-dir')
const pkgDir = require('pkg-dir');
const fs = require('fs')
const Module = require('module')
const path = require('path')
const fs = require('fs');
const Module = require('module');
const path = require('path');
const hashObject = require('./hash').hashObject
, ModuleCache = require('./ModuleCache').default
const hashObject = require('./hash').hashObject;
const ModuleCache = require('./ModuleCache').default;
const CASE_SENSITIVE_FS = !fs.existsSync(path.join(__dirname, 'reSOLVE.js'))
exports.CASE_SENSITIVE_FS = CASE_SENSITIVE_FS
const CASE_SENSITIVE_FS = !fs.existsSync(path.join(__dirname.toUpperCase(), 'reSOLVE.js'));
exports.CASE_SENSITIVE_FS = CASE_SENSITIVE_FS;
const ERROR_NAME = 'EslintPluginImportResolveError'
const ERROR_NAME = 'EslintPluginImportResolveError';
const fileExistsCache = new ModuleCache()
const fileExistsCache = new ModuleCache();

@@ -23,13 +23,13 @@ // Polyfill Node's `Module.createRequireFromPath` if not present (added in Node v10.12.0)

const createRequire = Module.createRequire || Module.createRequireFromPath || function (filename) {
const mod = new Module(filename, null)
mod.filename = filename
mod.paths = Module._nodeModulePaths(path.dirname(filename))
const mod = new Module(filename, null);
mod.filename = filename;
mod.paths = Module._nodeModulePaths(path.dirname(filename));
mod._compile(`module.exports = require;`, filename)
mod._compile(`module.exports = require;`, filename);
return mod.exports
}
return mod.exports;
};
function tryRequire(target, sourceFile) {
let resolved
let resolved;
try {

@@ -39,16 +39,16 @@ // Check if the target exists

try {
resolved = createRequire(path.resolve(sourceFile)).resolve(target)
resolved = createRequire(path.resolve(sourceFile)).resolve(target);
} catch (e) {
resolved = require.resolve(target)
resolved = require.resolve(target);
}
} else {
resolved = require.resolve(target)
resolved = require.resolve(target);
}
} catch(e) {
// If the target does not exist then just return undefined
return undefined
return undefined;
}
// If the target exists then return the loaded module
return require(resolved)
return require(resolved);
}

@@ -59,30 +59,30 @@

// don't care if the FS is case-sensitive
if (CASE_SENSITIVE_FS) return true
if (CASE_SENSITIVE_FS) return true;
// null means it resolved to a builtin
if (filepath === null) return true
if (filepath.toLowerCase() === process.cwd().toLowerCase()) return true
const parsedPath = path.parse(filepath)
, dir = parsedPath.dir
if (filepath === null) return true;
if (filepath.toLowerCase() === process.cwd().toLowerCase()) return true;
const parsedPath = path.parse(filepath);
const dir = parsedPath.dir;
let result = fileExistsCache.get(filepath, cacheSettings)
if (result != null) return result
let result = fileExistsCache.get(filepath, cacheSettings);
if (result != null) return result;
// base case
if (dir === '' || parsedPath.root === filepath) {
result = true
result = true;
} else {
const filenames = fs.readdirSync(dir)
const filenames = fs.readdirSync(dir);
if (filenames.indexOf(parsedPath.base) === -1) {
result = false
result = false;
} else {
result = fileExistsWithCaseSync(dir, cacheSettings)
result = fileExistsWithCaseSync(dir, cacheSettings);
}
}
fileExistsCache.set(filepath, result)
return result
}
fileExistsCache.set(filepath, result);
return result;
};
function relative(modulePath, sourceFile, settings) {
return fullResolve(modulePath, sourceFile, settings).path
return fullResolve(modulePath, sourceFile, settings).path;
}

@@ -92,15 +92,15 @@

// check if this is a bonus core module
const coreSet = new Set(settings['import/core-modules'])
if (coreSet.has(modulePath)) return { found: true, path: null }
const coreSet = new Set(settings['import/core-modules']);
if (coreSet.has(modulePath)) return { found: true, path: null };
const sourceDir = path.dirname(sourceFile)
, cacheKey = sourceDir + hashObject(settings).digest('hex') + modulePath
const sourceDir = path.dirname(sourceFile);
const cacheKey = sourceDir + hashObject(settings).digest('hex') + modulePath;
const cacheSettings = ModuleCache.getSettings(settings)
const cacheSettings = ModuleCache.getSettings(settings);
const cachedPath = fileExistsCache.get(cacheKey, cacheSettings)
if (cachedPath !== undefined) return { found: true, path: cachedPath }
const cachedPath = fileExistsCache.get(cacheKey, cacheSettings);
if (cachedPath !== undefined) return { found: true, path: cachedPath };
function cache(resolvedPath) {
fileExistsCache.set(cacheKey, resolvedPath)
fileExistsCache.set(cacheKey, resolvedPath);
}

@@ -112,7 +112,7 @@

try {
const resolved = resolver.resolveImport(modulePath, sourceFile, config)
if (resolved === undefined) return { found: false }
return { found: true, path: resolved }
const resolved = resolver.resolveImport(modulePath, sourceFile, config);
if (resolved === undefined) return { found: false };
return { found: true, path: resolved };
} catch (err) {
return { found: false }
return { found: false };
}

@@ -122,12 +122,12 @@ }

function v2() {
return resolver.resolve(modulePath, sourceFile, config)
return resolver.resolve(modulePath, sourceFile, config);
}
switch (resolver.interfaceVersion) {
case 2:
return v2()
case 2:
return v2();
default:
case 1:
return v1()
default:
case 1:
return v1();
}

@@ -137,17 +137,17 @@ }

const configResolvers = (settings['import/resolver']
|| { 'node': settings['import/resolve'] }) // backward compatibility
|| { 'node': settings['import/resolve'] }); // backward compatibility
const resolvers = resolverReducer(configResolvers, new Map())
const resolvers = resolverReducer(configResolvers, new Map());
for (let pair of resolvers) {
let name = pair[0]
, config = pair[1]
const resolver = requireResolver(name, sourceFile)
, resolved = withResolver(resolver, config)
for (const pair of resolvers) {
const name = pair[0];
const config = pair[1];
const resolver = requireResolver(name, sourceFile);
const resolved = withResolver(resolver, config);
if (!resolved.found) continue
if (!resolved.found) continue;
// else, counts
cache(resolved.path)
return resolved
cache(resolved.path);
return resolved;
}

@@ -157,50 +157,50 @@

// cache(undefined)
return { found: false }
return { found: false };
}
exports.relative = relative
exports.relative = relative;
function resolverReducer(resolvers, map) {
if (resolvers instanceof Array) {
resolvers.forEach(r => resolverReducer(r, map))
return map
if (Array.isArray(resolvers)) {
resolvers.forEach(r => resolverReducer(r, map));
return map;
}
if (typeof resolvers === 'string') {
map.set(resolvers, null)
return map
map.set(resolvers, null);
return map;
}
if (typeof resolvers === 'object') {
for (let key in resolvers) {
map.set(key, resolvers[key])
for (const key in resolvers) {
map.set(key, resolvers[key]);
}
return map
return map;
}
const err = new Error('invalid resolver config')
err.name = ERROR_NAME
throw err
const err = new Error('invalid resolver config');
err.name = ERROR_NAME;
throw err;
}
function getBaseDir(sourceFile) {
return pkgDir.sync(sourceFile) || process.cwd()
return pkgDir.sync(sourceFile) || process.cwd();
}
function requireResolver(name, sourceFile) {
// Try to resolve package with conventional name
let resolver = tryRequire(`eslint-import-resolver-${name}`, sourceFile) ||
const resolver = tryRequire(`eslint-import-resolver-${name}`, sourceFile) ||
tryRequire(name, sourceFile) ||
tryRequire(path.resolve(getBaseDir(sourceFile), name))
tryRequire(path.resolve(getBaseDir(sourceFile), name));
if (!resolver) {
const err = new Error(`unable to load resolver "${name}".`)
err.name = ERROR_NAME
throw err
const err = new Error(`unable to load resolver "${name}".`);
err.name = ERROR_NAME;
throw err;
}
if (!isResolverValid(resolver)) {
const err = new Error(`${name} with invalid interface loaded as resolver`)
err.name = ERROR_NAME
throw err
const err = new Error(`${name} with invalid interface loaded as resolver`);
err.name = ERROR_NAME;
throw err;
}
return resolver
return resolver;
}

@@ -210,9 +210,9 @@

if (resolver.interfaceVersion === 2) {
return resolver.resolve && typeof resolver.resolve === 'function'
return resolver.resolve && typeof resolver.resolve === 'function';
} else {
return resolver.resolveImport && typeof resolver.resolveImport === 'function'
return resolver.resolveImport && typeof resolver.resolveImport === 'function';
}
}
const erroredContexts = new Set()
const erroredContexts = new Set();

@@ -230,5 +230,5 @@ /**

return relative( p
, context.getFilename()
, context.settings
)
, context.getFilename()
, context.settings
);
} catch (err) {

@@ -238,5 +238,5 @@ if (!erroredContexts.has(context)) {

// We're filtering out the default `err.name` because it adds little value to the message.
let errMessage = err.message
let errMessage = err.message;
if (err.name !== ERROR_NAME && err.stack) {
errMessage = err.stack.replace(/^Error: /, '')
errMessage = err.stack.replace(/^Error: /, '');
}

@@ -246,8 +246,8 @@ context.report({

loc: { line: 1, column: 0 },
})
erroredContexts.add(context)
});
erroredContexts.add(context);
}
}
}
resolve.relative = relative
exports.default = resolve
resolve.relative = relative;
exports.default = resolve;

@@ -1,6 +0,6 @@

'use strict'
exports.__esModule = true
'use strict';
exports.__esModule = true;
const pattern = /(^|;)\s*(export|import)((\s+\w)|(\s*[{*=]))/m
const pattern = /(^|;)\s*(export|import)((\s+\w)|(\s*[{*=]))/m;
/**

@@ -17,7 +17,7 @@ * detect possible imports/exports without a full parse.

exports.test = function isMaybeUnambiguousModule(content) {
return pattern.test(content)
}
return pattern.test(content);
};
// future-/Babel-proof at the expense of being a little loose
const unambiguousNodeType = /^(?:(?:Exp|Imp)ort.*Declaration|TSExportAssignment)$/
const unambiguousNodeType = /^(?:(?:Exp|Imp)ort.*Declaration|TSExportAssignment)$/;

@@ -30,3 +30,3 @@ /**

exports.isModule = function isUnambiguousModule(ast) {
return ast.body.some(node => unambiguousNodeType.test(node.type))
}
return ast.body.some(node => unambiguousNodeType.test(node.type));
};
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc