'use strict';var _slicedToArray = function () {function sliceIterator(arr, i) {var _arr = [];var _n = true;var _d = false;var _e = undefined;try {for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {_arr.push(_s.value);if (i && _arr.length === i) break;}} catch (err) {_d = true;_e = err;} finally {try {if (!_n && _i["return"]) _i["return"]();} finally {if (_d) throw _e;}}return _arr;}return function (arr, i) {if (Array.isArray(arr)) {return arr;} else if (Symbol.iterator in Object(arr)) {return sliceIterator(arr, i);} else {throw new TypeError("Invalid attempt to destructure non-iterable instance");}};}();var _path = require('path');var _path2 = _interopRequireDefault(_path); var _fs = require('fs');var _fs2 = _interopRequireDefault(_fs); var _pkgUp = require('eslint-module-utils/pkgUp');var _pkgUp2 = _interopRequireDefault(_pkgUp); var _minimatch = require('minimatch');var _minimatch2 = _interopRequireDefault(_minimatch); var _resolve = require('eslint-module-utils/resolve');var _resolve2 = _interopRequireDefault(_resolve); var _moduleVisitor = require('eslint-module-utils/moduleVisitor');var _moduleVisitor2 = _interopRequireDefault(_moduleVisitor); var _importType = require('../core/importType');var _importType2 = _interopRequireDefault(_importType); var _packagePath = require('../core/packagePath'); var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { 'default': obj };} var depFieldCache = new Map(); function hasKeys() {var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return Object.keys(obj).length > 0; } function arrayOrKeys(arrayOrObject) { return Array.isArray(arrayOrObject) ? arrayOrObject : Object.keys(arrayOrObject); } function readJSON(jsonPath, throwException) { try { return JSON.parse(_fs2['default'].readFileSync(jsonPath, 'utf8')); } catch (err) { if (throwException) { throw err; } } } function extractDepFields(pkg) { return { dependencies: pkg.dependencies || {}, devDependencies: pkg.devDependencies || {}, optionalDependencies: pkg.optionalDependencies || {}, peerDependencies: pkg.peerDependencies || {}, // BundledDeps should be in the form of an array, but object notation is also supported by // `npm`, so we convert it to an array if it is an object bundledDependencies: arrayOrKeys(pkg.bundleDependencies || pkg.bundledDependencies || []) }; } function getPackageDepFields(packageJsonPath, throwAtRead) { if (!depFieldCache.has(packageJsonPath)) { var packageJson = readJSON(packageJsonPath, throwAtRead); if (packageJson) { var depFields = extractDepFields(packageJson); depFieldCache.set(packageJsonPath, depFields); } } return depFieldCache.get(packageJsonPath); } function getDependencies(context, packageDir) { var paths = []; try { var packageContent = { dependencies: {}, devDependencies: {}, optionalDependencies: {}, peerDependencies: {}, bundledDependencies: [] }; if (packageDir && packageDir.length > 0) { if (!Array.isArray(packageDir)) { paths = [_path2['default'].resolve(packageDir)]; } else { paths = packageDir.map(function (dir) {return _path2['default'].resolve(dir);}); } } if (paths.length > 0) { // use rule config to find package.json paths.forEach(function (dir) { var packageJsonPath = _path2['default'].join(dir, 'package.json'); var _packageContent = getPackageDepFields(packageJsonPath, paths.length === 1); if (_packageContent) { Object.keys(packageContent).forEach(function (depsKey) { Object.assign(packageContent[depsKey], _packageContent[depsKey]); }); } }); } else { var packageJsonPath = (0, _pkgUp2['default'])({ cwd: context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename(), normalize: false }); // use closest package.json Object.assign( packageContent, getPackageDepFields(packageJsonPath, false)); } if (![ packageContent.dependencies, packageContent.devDependencies, packageContent.optionalDependencies, packageContent.peerDependencies, packageContent.bundledDependencies]. some(hasKeys)) { return null; } return packageContent; } catch (e) { if (paths.length > 0 && e.code === 'ENOENT') { context.report({ message: 'The package.json file could not be found.', loc: { line: 0, column: 0 } }); } if (e.name === 'JSONError' || e instanceof SyntaxError) { context.report({ message: 'The package.json file could not be parsed: ' + String(e.message), loc: { line: 0, column: 0 } }); } return null; } } function missingErrorMessage(packageName) { return '\'' + String(packageName) + '\' should be listed in the project\'s dependencies. Run \'npm i -S ' + String(packageName) + '\' to add it'; } function devDepErrorMessage(packageName) { return '\'' + String(packageName) + '\' should be listed in the project\'s dependencies, not devDependencies.'; } function optDepErrorMessage(packageName) { return '\'' + String(packageName) + '\' should be listed in the project\'s dependencies, not optionalDependencies.'; } function getModuleOriginalName(name) {var _name$split = name.split('/'),_name$split2 = _slicedToArray(_name$split, 2),first = _name$split2[0],second = _name$split2[1]; return first.startsWith('@') ? String(first) + '/' + String(second) : first; } function getModuleRealName(resolved) { return (0, _packagePath.getFilePackageName)(resolved); } function checkDependencyDeclaration(deps, packageName, declarationStatus) { var newDeclarationStatus = declarationStatus || { isInDeps: false, isInDevDeps: false, isInOptDeps: false, isInPeerDeps: false, isInBundledDeps: false }; // in case of sub package.json inside a module // check the dependencies on all hierarchy var packageHierarchy = []; var packageNameParts = packageName ? packageName.split('/') : []; packageNameParts.forEach(function (namePart, index) { if (!namePart.startsWith('@')) { var ancestor = packageNameParts.slice(0, index + 1).join('/'); packageHierarchy.push(ancestor); } }); return packageHierarchy.reduce(function (result, ancestorName) {return { isInDeps: result.isInDeps || deps.dependencies[ancestorName] !== undefined, isInDevDeps: result.isInDevDeps || deps.devDependencies[ancestorName] !== undefined, isInOptDeps: result.isInOptDeps || deps.optionalDependencies[ancestorName] !== undefined, isInPeerDeps: result.isInPeerDeps || deps.peerDependencies[ancestorName] !== undefined, isInBundledDeps: result.isInBundledDeps || deps.bundledDependencies.indexOf(ancestorName) !== -1 };}, newDeclarationStatus); } function reportIfMissing(context, deps, depsOptions, node, name) { // Do not report when importing types unless option is enabled if ( !depsOptions.verifyTypeImports && ( node.importKind === 'type' || node.importKind === 'typeof' || node.exportKind === 'type' || Array.isArray(node.specifiers) && node.specifiers.length && node.specifiers.every(function (specifier) {return specifier.importKind === 'type' || specifier.importKind === 'typeof';}))) { return; } var typeOfImport = (0, _importType2['default'])(name, context); if ( typeOfImport !== 'external' && ( typeOfImport !== 'internal' || !depsOptions.verifyInternalDeps)) { return; } var resolved = (0, _resolve2['default'])(name, context); if (!resolved) {return;} var importPackageName = getModuleOriginalName(name); var declarationStatus = checkDependencyDeclaration(deps, importPackageName); if ( declarationStatus.isInDeps || depsOptions.allowDevDeps && declarationStatus.isInDevDeps || depsOptions.allowPeerDeps && declarationStatus.isInPeerDeps || depsOptions.allowOptDeps && declarationStatus.isInOptDeps || depsOptions.allowBundledDeps && declarationStatus.isInBundledDeps) { return; } // test the real name from the resolved package.json // if not aliased imports (alias/react for example), importPackageName can be misinterpreted var realPackageName = getModuleRealName(resolved); if (realPackageName && realPackageName !== importPackageName) { declarationStatus = checkDependencyDeclaration(deps, realPackageName, declarationStatus); if ( declarationStatus.isInDeps || depsOptions.allowDevDeps && declarationStatus.isInDevDeps || depsOptions.allowPeerDeps && declarationStatus.isInPeerDeps || depsOptions.allowOptDeps && declarationStatus.isInOptDeps || depsOptions.allowBundledDeps && declarationStatus.isInBundledDeps) { return; } } if (declarationStatus.isInDevDeps && !depsOptions.allowDevDeps) { context.report(node, devDepErrorMessage(realPackageName || importPackageName)); return; } if (declarationStatus.isInOptDeps && !depsOptions.allowOptDeps) { context.report(node, optDepErrorMessage(realPackageName || importPackageName)); return; } context.report(node, missingErrorMessage(realPackageName || importPackageName)); } function testConfig(config, filename) { // Simplest configuration first, either a boolean or nothing. if (typeof config === 'boolean' || typeof config === 'undefined') { return config; } // Array of globs. return config.some(function (c) {return (0, _minimatch2['default'])(filename, c) || (0, _minimatch2['default'])(filename, _path2['default'].join(process.cwd(), c));}); } module.exports = { meta: { type: 'problem', docs: { category: 'Helpful warnings', description: 'Forbid the use of extraneous packages.', url: (0, _docsUrl2['default'])('no-extraneous-dependencies') }, schema: [ { type: 'object', properties: { devDependencies: { type: ['boolean', 'array'] }, optionalDependencies: { type: ['boolean', 'array'] }, peerDependencies: { type: ['boolean', 'array'] }, bundledDependencies: { type: ['boolean', 'array'] }, packageDir: { type: ['string', 'array'] }, includeInternal: { type: ['boolean'] }, includeTypes: { type: ['boolean'] } }, additionalProperties: false }] }, create: function () {function create(context) { var options = context.options[0] || {}; var filename = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename(); var deps = getDependencies(context, options.packageDir) || extractDepFields({}); var depsOptions = { allowDevDeps: testConfig(options.devDependencies, filename) !== false, allowOptDeps: testConfig(options.optionalDependencies, filename) !== false, allowPeerDeps: testConfig(options.peerDependencies, filename) !== false, allowBundledDeps: testConfig(options.bundledDependencies, filename) !== false, verifyInternalDeps: !!options.includeInternal, verifyTypeImports: !!options.includeTypes }; return (0, _moduleVisitor2['default'])(function (source, node) { reportIfMissing(context, deps, depsOptions, node, source.value); }, { commonjs: true }); }return create;}(), 'Program:exit': function () {function ProgramExit() { depFieldCache.clear(); }return ProgramExit;}() }; //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1leHRyYW5lb3VzLWRlcGVuZGVuY2llcy5qcyJdLCJuYW1lcyI6WyJkZXBGaWVsZENhY2hlIiwiTWFwIiwiaGFzS2V5cyIsIm9iaiIsIk9iamVjdCIsImtleXMiLCJsZW5ndGgiLCJhcnJheU9yS2V5cyIsImFycmF5T3JPYmplY3QiLCJBcnJheSIsImlzQXJyYXkiLCJyZWFkSlNPTiIsImpzb25QYXRoIiwidGhyb3dFeGNlcHRpb24iLCJKU09OIiwicGFyc2UiLCJmcyIsInJlYWRGaWxlU3luYyIsImVyciIsImV4dHJhY3REZXBGaWVsZHMiLCJwa2ciLCJkZXBlbmRlbmNpZXMiLCJkZXZEZXBlbmRlbmNpZXMiLCJvcHRpb25hbERlcGVuZGVuY2llcyIsInBlZXJEZXBlbmRlbmNpZXMiLCJidW5kbGVkRGVwZW5kZW5jaWVzIiwiYnVuZGxlRGVwZW5kZW5jaWVzIiwiZ2V0UGFja2FnZURlcEZpZWxkcyIsInBhY2thZ2VKc29uUGF0aCIsInRocm93QXRSZWFkIiwiaGFzIiwicGFja2FnZUpzb24iLCJkZXBGaWVsZHMiLCJzZXQiLCJnZXQiLCJnZXREZXBlbmRlbmNpZXMiLCJjb250ZXh0IiwicGFja2FnZURpciIsInBhdGhzIiwicGFja2FnZUNvbnRlbnQiLC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ICAgICB9IGVsc2Uge1xuICAgICAgICBwYXRocyA9IHBhY2thZ2VEaXIubWFwKChkaXIpID0+IHBhdGgucmVzb2x2ZShkaXIpKTtcbiAgICAgIH1cbiAgICB9XG5cbiAgICBpZiAocGF0aHMubGVuZ3RoID4gMCkge1xuICAgICAgLy8gdXNlIHJ1bGUgY29uZmlnIHRvIGZpbmQgcGFja2FnZS5qc29uXG4gICAgICBwYXRocy5mb3JFYWNoKChkaXIpID0+IHtcbiAgICAgICAgY29uc3QgcGFja2FnZUpzb25QYXRoID0gcGF0aC5qb2luKGRpciwgJ3BhY2thZ2UuanNvbicpO1xuICAgICAgICBjb25zdCBfcGFja2FnZUNvbnRlbnQgPSBnZXRQYWNrYWdlRGVwRmllbGRzKHBhY2thZ2VKc29uUGF0aCwgcGF0aHMubGVuZ3RoID09PSAxKTtcbiAgICAgICAgaWYgKF9wYWNrYWdlQ29udGVudCkge1xuICAgICAgICAgIE9iamVjdC5rZXlzKHBhY2thZ2VDb250ZW50KS5mb3JFYWNoKChkZXBzS2V5KSA9PiB7XG4gICAgICAgICAgICBPYmplY3QuYXNzaWduKHBhY2thZ2VDb250ZW50W2RlcHNLZXldLCBfcGFja2FnZUNvbnRlbnRbZGVwc0tleV0pO1xuICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgICB9KTtcbiAgICB9IGVsc2Uge1xuICAgICAgY29uc3QgcGFja2FnZUpzb25QYXRoID0gcGtnVXAoe1xuICAgICAgICBjd2Q6IGNvbnRleHQuZ2V0UGh5c2ljYWxGaWxlbmFtZSA/IGNvbnRleHQuZ2V0UGh5c2ljYWxGaWxlbmFtZSgpIDogY29udGV4dC5nZXRGaWxlbmFtZSgpLFxuICAgICAgICBub3JtYWxpemU6IGZhbHNlLFxuICAgICAgfSk7XG5cbiAgICAgIC8vIHVzZSBjbG9zZXN0IHBhY2thZ2UuanNvblxuICAgICAgT2JqZWN0LmFzc2lnbihcbiAgICAgICAgcGFja2FnZUNvbnRlbnQsXG4gICA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