'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 _readPkgUp = require('read-pkg-up');var _readPkgUp2 = _interopRequireDefault(_readPkgUp); 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 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 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'); if (!depFieldCache.has(packageJsonPath)) { var depFields = extractDepFields( JSON.parse(_fs2['default'].readFileSync(packageJsonPath, 'utf8'))); depFieldCache.set(packageJsonPath, depFields); } var _packageContent = depFieldCache.get(packageJsonPath); Object.keys(packageContent).forEach(function (depsKey) {return ( Object.assign(packageContent[depsKey], _packageContent[depsKey]));}); }); } else { // use closest package.json Object.assign( packageContent, extractDepFields( _readPkgUp2['default'].sync({ cwd: context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename(), normalize: false }).pkg)); } 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: ' + 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 if ( node.importKind === 'type' || node.parent && node.parent.importKind === 'type' || node.importKind === 'typeof') { return; } if ((0, _importType2['default'])(name, context) !== 'external') { 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: { 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'] } }, '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 }; return (0, _moduleVisitor2['default'])(function (source, node) { reportIfMissing(context, deps, depsOptions, node, source.value); }, { commonjs: true }); }return create;}() }; //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1leHRyYW5lb3VzLWRlcGVuZGVuY2llcy5qcyJdLCJuYW1lcyI6WyJkZXB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wdGlvbmFsRGVwZW5kZW5jaWVzOiB7fSxcbiAgICAgIHBlZXJEZXBlbmRlbmNpZXM6IHt9LFxuICAgICAgYnVuZGxlZERlcGVuZGVuY2llczogW10sXG4gICAgfTtcblxuICAgIGlmIChwYWNrYWdlRGlyICYmIHBhY2thZ2VEaXIubGVuZ3RoID4gMCkge1xuICAgICAgaWYgKCFBcnJheS5pc0FycmF5KHBhY2thZ2VEaXIpKSB7XG4gICAgICAgIHBhdGhzID0gW3BhdGgucmVzb2x2ZShwYWNrYWdlRGlyKV07XG4gICAgICB9IGVsc2Uge1xuICAgICAgICBwYXRocyA9IHBhY2thZ2VEaXIubWFwKGRpciA9PiBwYXRoLnJlc29sdmUoZGlyKSk7XG4gICAgICB9XG4gICAgfVxuXG4gICAgaWYgKHBhdGhzLmxlbmd0aCA+IDApIHtcbiAgICAgIC8vIHVzZSBydWxlIGNvbmZpZyB0byBmaW5kIHBhY2thZ2UuanNvblxuICAgICAgcGF0aHMuZm9yRWFjaChkaXIgPT4ge1xuICAgICAgICBjb25zdCBwYWNrYWdlSnNvblBhdGggPSBwYXRoLmpvaW4oZGlyLCAncGFja2FnZS5qc29uJyk7XG4gICAgICAgIGlmICghZGVwRmllbGRDYWNoZS5oYXMocGFja2FnZUpzb25QYXRoKSkge1xuICAgICAgICAgIGNvbnN0IGRlcEZpZWxkcyA9IGV4dHJhY3REZXBGaWVsZHMoXG4gICAgICAgICAgICBKU09OLnBhcnNlKGZzLnJlYWRGaWxlU3luYyhwYWNrYWdlSnNvblBhdGgsICd1dGY4JykpXG4gICAgICAgICAgKTtcbiAgICAgICAgICBkZXBGaWVsZENhY2hlLnNldChwYWNrYWdlSnNvblBhdGgsIGRlcEZpZWxkcyk7XG4gICAgICAgIH1cbiAgICAgICAgY29uc3QgX3BhY2thZ2VDb250ZW50ID0gZGVwRmllbGRDYWNoZS5nZXQocGFja2FnZUpzb25QYXRoKTtcbiAgICAgICAgT2JqZWN0LmtleXMocGFja2FnZUNvbnRlbn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