get-eslint-cli.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. "use strict";
  2. // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
  3. // See LICENSE in the project root for license information.
  4. var __importDefault = (this && this.__importDefault) || function (mod) {
  5. return (mod && mod.__esModule) ? mod : { "default": mod };
  6. };
  7. Object.defineProperty(exports, "__esModule", { value: true });
  8. exports.getEslintPathAndVersion = getEslintPathAndVersion;
  9. const path_1 = __importDefault(require("path"));
  10. const constants_1 = require("../../constants");
  11. // When this list is updated, update the `eslint-bulk-suppressions-newest-test`
  12. // and/or the `eslint-bulk-suppressions-newest-test` projects' eslint dependencies.
  13. const TESTED_VERSIONS = new Set([
  14. '8.6.0',
  15. '8.7.0',
  16. '8.21.0',
  17. '8.22.0',
  18. '8.23.0',
  19. '8.23.1',
  20. '8.57.0',
  21. '9.25.1'
  22. ]);
  23. function getEslintPathAndVersion(packagePath) {
  24. // Try to find a local ESLint installation, the one that should be listed as a dev dependency in package.json
  25. // and installed in node_modules
  26. try {
  27. const localEslintApiPath = require.resolve(constants_1.BULK_SUPPRESSIONS_CLI_ESLINT_PACKAGE_NAME, {
  28. paths: [packagePath]
  29. });
  30. const localEslintPath = path_1.default.dirname(path_1.default.dirname(localEslintApiPath));
  31. const { version: localEslintVersion } = require(`${localEslintPath}/package.json`);
  32. if (!TESTED_VERSIONS.has(localEslintVersion)) {
  33. console.warn('@rushstack/eslint-bulk: Be careful, the installed ESLint version has not been tested with eslint-bulk.');
  34. }
  35. return [localEslintApiPath, localEslintVersion];
  36. }
  37. catch (e1) {
  38. try {
  39. const { dependencies, devDependencies } = require(`${packagePath}/package.json`);
  40. if (devDependencies === null || devDependencies === void 0 ? void 0 : devDependencies.eslint) {
  41. throw new Error('@rushstack/eslint-bulk: eslint is specified as a dev dependency in package.json, ' +
  42. 'but eslint-bulk cannot find it in node_modules.');
  43. }
  44. else if (dependencies === null || dependencies === void 0 ? void 0 : dependencies.eslint) {
  45. throw new Error('@rushstack/eslint-bulk: eslint is specified as a dependency in package.json, ' +
  46. 'but eslint-bulk cannot find it in node_modules.');
  47. }
  48. else {
  49. throw new Error('@rushstack/eslint-bulk: eslint is not specified as a dependency in package.json.');
  50. }
  51. }
  52. catch (e2) {
  53. throw new Error("@rushstack/eslint-bulk: This command must be run in the same folder as a project's package.json file.");
  54. }
  55. }
  56. }
  57. //# sourceMappingURL=get-eslint-cli.js.map