'use strict'; 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 _importType = require('../core/importType'); var _importType2 = _interopRequireDefault(_importType); var _staticRequire = require('../core/staticRequire'); var _staticRequire2 = _interopRequireDefault(_staticRequire); var _docsUrl = require('../docsUrl'); var _docsUrl2 = _interopRequireDefault(_docsUrl); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function hasKeys() { let obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return Object.keys(obj).length > 0; } function extractDepFields(pkg) { return { dependencies: pkg.dependencies || {}, devDependencies: pkg.devDependencies || {}, optionalDependencies: pkg.optionalDependencies || {}, peerDependencies: pkg.peerDependencies || {} }; } function getDependencies(context, packageDir) { let paths = []; try { const packageContent = { dependencies: {}, devDependencies: {}, optionalDependencies: {}, peerDependencies: {} }; if (packageDir && packageDir.length > 0) { if (!Array.isArray(packageDir)) { paths = [_path2.default.resolve(packageDir)]; } else { paths = packageDir.map(dir => _path2.default.resolve(dir)); } } if (paths.length > 0) { // use rule config to find package.json paths.forEach(dir => { const _packageContent = extractDepFields(JSON.parse(_fs2.default.readFileSync(_path2.default.join(dir, 'package.json'), 'utf8'))); Object.keys(packageContent).forEach(depsKey => Object.assign(packageContent[depsKey], _packageContent[depsKey])); }); } else { // use closest package.json Object.assign(packageContent, extractDepFields(_readPkgUp2.default.sync({ cwd: context.getFilename(), normalize: false }).pkg)); } if (![packageContent.dependencies, packageContent.devDependencies, packageContent.optionalDependencies, packageContent.peerDependencies].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 `'${packageName}' should be listed in the project's dependencies. ` + `Run 'npm i -S ${packageName}' to add it`; } function devDepErrorMessage(packageName) { return `'${packageName}' should be listed in the project's dependencies, not devDependencies.`; } function optDepErrorMessage(packageName) { return `'${packageName}' should be listed in the project's dependencies, ` + `not optionalDependencies.`; } function reportIfMissing(context, deps, depsOptions, node, name) { // Do not report when importing types if (node.importKind === 'type') { return; } if ((0, _importType2.default)(name, context) !== 'external') { return; } const resolved = (0, _resolve2.default)(name, context); if (!resolved) { return; } const splitName = name.split('/'); const packageName = splitName[0][0] === '@' ? splitName.slice(0, 2).join('/') : splitName[0]; const isInDeps = deps.dependencies[packageName] !== undefined; const isInDevDeps = deps.devDependencies[packageName] !== undefined; const isInOptDeps = deps.optionalDependencies[packageName] !== undefined; const isInPeerDeps = deps.peerDependencies[packageName] !== undefined; if (isInDeps || depsOptions.allowDevDeps && isInDevDeps || depsOptions.allowPeerDeps && isInPeerDeps || depsOptions.allowOptDeps && isInOptDeps) { return; } if (isInDevDeps && !depsOptions.allowDevDeps) { context.report(node, devDepErrorMessage(packageName)); return; } if (isInOptDeps && !depsOptions.allowOptDeps) { context.report(node, optDepErrorMessage(packageName)); return; } context.report(node, missingErrorMessage(packageName)); } 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(c => (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'] }, 'packageDir': { 'type': ['string', 'array'] } }, 'additionalProperties': false }] }, create: function (context) { const options = context.options[0] || {}; const filename = context.getFilename(); const deps = getDependencies(context, options.packageDir) || extractDepFields({}); const depsOptions = { allowDevDeps: testConfig(options.devDependencies, filename) !== false, allowOptDeps: testConfig(options.optionalDependencies, filename) !== false, allowPeerDeps: testConfig(options.peerDependencies, filename) !== false // todo: use module visitor from module-utils core };return { ImportDeclaration: function (node) { reportIfMissing(context, deps, depsOptions, node, node.source.value); }, CallExpression: function handleRequires(node) { if ((0, _staticRequire2.default)(node)) { reportIfMissing(context, deps, depsOptions, node, node.arguments[0].value); } } }; } }; //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1leHRyYW5lb3VzLWRlcGVuZGVuY2llcy5qcyJdLCJuYW1lcyI6WyJoYXNLZXlzIiwib2JqIiwiT2JqZWN0Iiwia2V5cyIsImxlbmd0aCIsImV4dHJhY3REZXBGaWVsZHMiLCJwa2ciLCJkZXBlbmRlbmNpZXMiLCJkZXZEZXBlbmRlbmNpZXMiLCJvcHRpb25hbERlcGVuZGVuY2llcyIsInBlZXJEZXBlbmRlbmNpZXMiLCJnZXREZXBlbmRlbmNpZXMiLCJjb250ZXh0IiwicGFja2FnZURpciIsInBhdGhzIiwicGFja2FnZUNvbnRlbnQiLCJBcnJheSIsImlzQXJyYXkiLCJwYXRoIiwicmVzb2x2ZSIsIm1hcCIsImRpciIsImZvckVhY2giLCJfcGFja2FnZUNvbnRlbnQiLCJKU09OIiwicGFyc2UiLCJmcyIsInJlYWRGaWxlU3luYyIsImpvaW4iLCJkZXBzS2V5IiwiYXNzaWduIiwicmVhZFBrZ1VwIiwic3luYyIsImN3ZCIsImdldEZpbGVuYW1lIiwibm9ybWFsaXplIiwic29tZSIsImUiLCJjb2RlIiwicmVwb3J0IiwibWVzc2FnZSIsImxvYyIsImxpbmUiLCJjb2x1bW4iLCJuYW1lIiwiU3ludG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