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