Skip to content

Commit

Permalink
feat(upgrade): adding exports of private eslint api on first rule run
Browse files Browse the repository at this point in the history
  • Loading branch information
sviat9440 committed Jul 10, 2022
1 parent 582543e commit c8186e3
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions lib/rules/decorator-position.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
const { join } = require('path');
const { existsSync: isExists, writeFileSync: write, readFileSync: read } = require('fs');

let CLIEngine;
try {
({ CLIEngine } = require('eslint/eslint-plugin-decorator-position'));
} catch {
const eslintEntrypointFileName = 'eslint-plugin-decorator-position';

if (!isExists(join(findNearestEslintPackage(), `${eslintEntrypointFileName}.js`))) {
setupEslintExports();
({ CLIEngine } = require('eslint/eslint-plugin-decorator-position'));
}

const { CLIEngine } = require('eslint/eslint-plugin-decorator-position');

const cli = CLIEngine ? new CLIEngine() : undefined;

module.exports = {
Expand Down Expand Up @@ -521,19 +521,12 @@ function arityOfDecorator(decorator) {
}

function findNearestEslintPackage() {
let dir = __dirname;
while (!isExists(join(dir, 'node_modules', 'eslint'))) {
if (dir === join(dir, '..')) {
throw new Error('Cannot found Eslint package');
}
dir = join(dir, '..');
}
return join(dir, 'node_modules', 'eslint');
return join(require.resolve('eslint/package.json'), '..');
}

function setupEslintExports() {
const eslintPath = findNearestEslintPackage();
const fileName = 'eslint-plugin-decorator-position';
const fileName = eslintEntrypointFileName;
const filePath = join(eslintPath, `${fileName}.js`);
if (!isExists(filePath)) {
const eslintPackageJson = join(eslintPath, 'package.json');
Expand Down

0 comments on commit c8186e3

Please sign in to comment.