no-extraneous-dependencies.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. '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);
  2. var _fs = require('fs');var _fs2 = _interopRequireDefault(_fs);
  3. var _readPkgUp = require('eslint-module-utils/readPkgUp');var _readPkgUp2 = _interopRequireDefault(_readPkgUp);
  4. var _minimatch = require('minimatch');var _minimatch2 = _interopRequireDefault(_minimatch);
  5. var _resolve = require('eslint-module-utils/resolve');var _resolve2 = _interopRequireDefault(_resolve);
  6. var _moduleVisitor = require('eslint-module-utils/moduleVisitor');var _moduleVisitor2 = _interopRequireDefault(_moduleVisitor);
  7. var _importType = require('../core/importType');var _importType2 = _interopRequireDefault(_importType);
  8. var _packagePath = require('../core/packagePath');
  9. var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { 'default': obj };}
  10. var depFieldCache = new Map();
  11. function hasKeys() {var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  12. return Object.keys(obj).length > 0;
  13. }
  14. function arrayOrKeys(arrayOrObject) {
  15. return Array.isArray(arrayOrObject) ? arrayOrObject : Object.keys(arrayOrObject);
  16. }
  17. function extractDepFields(pkg) {
  18. return {
  19. dependencies: pkg.dependencies || {},
  20. devDependencies: pkg.devDependencies || {},
  21. optionalDependencies: pkg.optionalDependencies || {},
  22. peerDependencies: pkg.peerDependencies || {},
  23. // BundledDeps should be in the form of an array, but object notation is also supported by
  24. // `npm`, so we convert it to an array if it is an object
  25. bundledDependencies: arrayOrKeys(pkg.bundleDependencies || pkg.bundledDependencies || []) };
  26. }
  27. function getDependencies(context, packageDir) {
  28. var paths = [];
  29. try {
  30. var packageContent = {
  31. dependencies: {},
  32. devDependencies: {},
  33. optionalDependencies: {},
  34. peerDependencies: {},
  35. bundledDependencies: [] };
  36. if (packageDir && packageDir.length > 0) {
  37. if (!Array.isArray(packageDir)) {
  38. paths = [_path2['default'].resolve(packageDir)];
  39. } else {
  40. paths = packageDir.map(function (dir) {return _path2['default'].resolve(dir);});
  41. }
  42. }
  43. if (paths.length > 0) {
  44. // use rule config to find package.json
  45. paths.forEach(function (dir) {
  46. var packageJsonPath = _path2['default'].join(dir, 'package.json');
  47. if (!depFieldCache.has(packageJsonPath)) {
  48. var depFields = extractDepFields(
  49. JSON.parse(_fs2['default'].readFileSync(packageJsonPath, 'utf8')));
  50. depFieldCache.set(packageJsonPath, depFields);
  51. }
  52. var _packageContent = depFieldCache.get(packageJsonPath);
  53. Object.keys(packageContent).forEach(function (depsKey) {return (
  54. Object.assign(packageContent[depsKey], _packageContent[depsKey]));});
  55. });
  56. } else {
  57. // use closest package.json
  58. Object.assign(
  59. packageContent,
  60. extractDepFields(
  61. (0, _readPkgUp2['default'])({ cwd: context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename(), normalize: false }).pkg));
  62. }
  63. if (![
  64. packageContent.dependencies,
  65. packageContent.devDependencies,
  66. packageContent.optionalDependencies,
  67. packageContent.peerDependencies,
  68. packageContent.bundledDependencies].
  69. some(hasKeys)) {
  70. return null;
  71. }
  72. return packageContent;
  73. } catch (e) {
  74. if (paths.length > 0 && e.code === 'ENOENT') {
  75. context.report({
  76. message: 'The package.json file could not be found.',
  77. loc: { line: 0, column: 0 } });
  78. }
  79. if (e.name === 'JSONError' || e instanceof SyntaxError) {
  80. context.report({
  81. message: 'The package.json file could not be parsed: ' + e.message,
  82. loc: { line: 0, column: 0 } });
  83. }
  84. return null;
  85. }
  86. }
  87. function missingErrorMessage(packageName) {
  88. return '\'' + String(packageName) + '\' should be listed in the project\'s dependencies. ' + ('Run \'npm i -S ' + String(
  89. packageName) + '\' to add it');
  90. }
  91. function devDepErrorMessage(packageName) {
  92. return '\'' + String(packageName) + '\' should be listed in the project\'s dependencies, not devDependencies.';
  93. }
  94. function optDepErrorMessage(packageName) {
  95. return '\'' + String(packageName) + '\' should be listed in the project\'s dependencies, ' + 'not optionalDependencies.';
  96. }
  97. function getModuleOriginalName(name) {var _name$split =
  98. name.split('/'),_name$split2 = _slicedToArray(_name$split, 2),first = _name$split2[0],second = _name$split2[1];
  99. return first.startsWith('@') ? String(first) + '/' + String(second) : first;
  100. }
  101. function getModuleRealName(resolved) {
  102. return (0, _packagePath.getFilePackageName)(resolved);
  103. }
  104. function checkDependencyDeclaration(deps, packageName, declarationStatus) {
  105. var newDeclarationStatus = declarationStatus || {
  106. isInDeps: false,
  107. isInDevDeps: false,
  108. isInOptDeps: false,
  109. isInPeerDeps: false,
  110. isInBundledDeps: false };
  111. // in case of sub package.json inside a module
  112. // check the dependencies on all hierarchy
  113. var packageHierarchy = [];
  114. var packageNameParts = packageName ? packageName.split('/') : [];
  115. packageNameParts.forEach(function (namePart, index) {
  116. if (!namePart.startsWith('@')) {
  117. var ancestor = packageNameParts.slice(0, index + 1).join('/');
  118. packageHierarchy.push(ancestor);
  119. }
  120. });
  121. return packageHierarchy.reduce(function (result, ancestorName) {
  122. return {
  123. isInDeps: result.isInDeps || deps.dependencies[ancestorName] !== undefined,
  124. isInDevDeps: result.isInDevDeps || deps.devDependencies[ancestorName] !== undefined,
  125. isInOptDeps: result.isInOptDeps || deps.optionalDependencies[ancestorName] !== undefined,
  126. isInPeerDeps: result.isInPeerDeps || deps.peerDependencies[ancestorName] !== undefined,
  127. isInBundledDeps:
  128. result.isInBundledDeps || deps.bundledDependencies.indexOf(ancestorName) !== -1 };
  129. }, newDeclarationStatus);
  130. }
  131. function reportIfMissing(context, deps, depsOptions, node, name) {
  132. // Do not report when importing types
  133. if (
  134. node.importKind === 'type' ||
  135. node.importKind === 'typeof')
  136. {
  137. return;
  138. }
  139. if ((0, _importType2['default'])(name, context) !== 'external') {
  140. return;
  141. }
  142. var resolved = (0, _resolve2['default'])(name, context);
  143. if (!resolved) {return;}
  144. var importPackageName = getModuleOriginalName(name);
  145. var declarationStatus = checkDependencyDeclaration(deps, importPackageName);
  146. if (
  147. declarationStatus.isInDeps ||
  148. depsOptions.allowDevDeps && declarationStatus.isInDevDeps ||
  149. depsOptions.allowPeerDeps && declarationStatus.isInPeerDeps ||
  150. depsOptions.allowOptDeps && declarationStatus.isInOptDeps ||
  151. depsOptions.allowBundledDeps && declarationStatus.isInBundledDeps)
  152. {
  153. return;
  154. }
  155. // test the real name from the resolved package.json
  156. // if not aliased imports (alias/react for example), importPackageName can be misinterpreted
  157. var realPackageName = getModuleRealName(resolved);
  158. if (realPackageName && realPackageName !== importPackageName) {
  159. declarationStatus = checkDependencyDeclaration(deps, realPackageName, declarationStatus);
  160. if (
  161. declarationStatus.isInDeps ||
  162. depsOptions.allowDevDeps && declarationStatus.isInDevDeps ||
  163. depsOptions.allowPeerDeps && declarationStatus.isInPeerDeps ||
  164. depsOptions.allowOptDeps && declarationStatus.isInOptDeps ||
  165. depsOptions.allowBundledDeps && declarationStatus.isInBundledDeps)
  166. {
  167. return;
  168. }
  169. }
  170. if (declarationStatus.isInDevDeps && !depsOptions.allowDevDeps) {
  171. context.report(node, devDepErrorMessage(realPackageName || importPackageName));
  172. return;
  173. }
  174. if (declarationStatus.isInOptDeps && !depsOptions.allowOptDeps) {
  175. context.report(node, optDepErrorMessage(realPackageName || importPackageName));
  176. return;
  177. }
  178. context.report(node, missingErrorMessage(realPackageName || importPackageName));
  179. }
  180. function testConfig(config, filename) {
  181. // Simplest configuration first, either a boolean or nothing.
  182. if (typeof config === 'boolean' || typeof config === 'undefined') {
  183. return config;
  184. }
  185. // Array of globs.
  186. return config.some(function (c) {return (
  187. (0, _minimatch2['default'])(filename, c) ||
  188. (0, _minimatch2['default'])(filename, _path2['default'].join(process.cwd(), c)));});
  189. }
  190. module.exports = {
  191. meta: {
  192. type: 'problem',
  193. docs: {
  194. url: (0, _docsUrl2['default'])('no-extraneous-dependencies') },
  195. schema: [
  196. {
  197. 'type': 'object',
  198. 'properties': {
  199. 'devDependencies': { 'type': ['boolean', 'array'] },
  200. 'optionalDependencies': { 'type': ['boolean', 'array'] },
  201. 'peerDependencies': { 'type': ['boolean', 'array'] },
  202. 'bundledDependencies': { 'type': ['boolean', 'array'] },
  203. 'packageDir': { 'type': ['string', 'array'] } },
  204. 'additionalProperties': false }] },
  205. create: function () {function create(context) {
  206. var options = context.options[0] || {};
  207. var filename = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename();
  208. var deps = getDependencies(context, options.packageDir) || extractDepFields({});
  209. var depsOptions = {
  210. allowDevDeps: testConfig(options.devDependencies, filename) !== false,
  211. allowOptDeps: testConfig(options.optionalDependencies, filename) !== false,
  212. allowPeerDeps: testConfig(options.peerDependencies, filename) !== false,
  213. allowBundledDeps: testConfig(options.bundledDependencies, filename) !== false };
  214. return (0, _moduleVisitor2['default'])(function (source, node) {
  215. reportIfMissing(context, deps, depsOptions, node, source.value);
  216. }, { commonjs: true });
  217. }return create;}() };
  218. //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1leHRyYW5lb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BvcHRpb25hbERlcGVuZGVuY2llczoge30sXG4gICAgICBwZWVyRGVwZW5kZW5jaWVzOiB7fSxcbiAgICAgIGJ1bmRsZWREZXBlbmRlbmNpZXM6IFtdLFxuICAgIH07XG5cbiAgICBpZiAocGFja2FnZURpciAmJiBwYWNrYWdlRGlyLmxlbmd0aCA+IDApIHtcbiAgICAgIGlmICghQXJyYXkuaXNBcnJheShwYWNrYWdlRGlyKSkge1xuICAgICAgICBwYXRocyA9IFtwYXRoLnJlc29sdmUocGFja2FnZURpcildO1xuICAgICAgfSBlbHNlIHtcbiAgICAgICAgcGF0aHMgPSBwYWNrYWdlRGlyLm1hcChkaXIgPT4gcGF0aC5yZXNvbHZlKGRpcikpO1xuICAgICAgfVxuICAgIH1cblxuICAgIGlmIChwYXRocy5sZW5ndGggPiAwKSB7XG4gICAgICAvLyB1c2UgcnVsZSBjb25maWcgdG8gZmluZCBwYWNrYWdlLmpzb25cbiAgICAgIHBhdGhzLmZvckVhY2goZGlyID0+IHtcbiAgICAgICAgY29uc3QgcGFja2FnZUpzb25QYXRoID0gcGF0aC5qb2luKGRpciwgJ3BhY2thZ2UuanNvbicpO1xuICAgICAgICBpZiAoIWRlcEZpZWxkQ2FjaGUuaGFzKHBhY2thZ2VKc29uUGF0aCkpIHtcbiAgICAgICAgICBjb25zdCBkZXBGaWVsZHMgPSBleHRyYWN0RGVwRmllbGRzKFxuICAgICAgICAgICAgSlNPTi5wYXJzZShmcy5yZWFkRmlsZVN5bmMocGFja2FnZUpzb25QYXRoLCAndXRmOCcpKSxcbiAgICAgICAgICApO1xuICAgICAgICAgIGRlcEZpZWxkQ2FjaGUuc2V0KHBhY2thZ2VKc29uUGF0aCwgZGVwRmllbGRzKTtcbiAgICAgICAgfVxuICAgICAgICBjb25zdCBfcGFja2FnZUNvbnRlbnQgPSBkZXBGaWVsZENhY2hlLmdldChwYWNrYWdlSnNvblBhdGgpO1xuICAgICAgICBPYmplY3Qua2V5cyhwYWNrYWdlQ29udGVudCk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