@procore/core-scripts
Version:
A CLI to enhance your development experience
46 lines • 2.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const path = tslib_1.__importStar(require("path"));
const fs_1 = tslib_1.__importDefault(require("fs"));
// This fix works for ESLint 7.x || 8.x
// In the next major version of eslint this fix should be tested that it still works
const eslintrcFolder = path.dirname(require.resolve('@eslint/eslintrc/package.json'));
const eslintrcBundlePath = path.join(eslintrcFolder, 'dist/eslintrc.cjs');
function checkEslintConfigInPackageJson(path) {
let packageJson;
try {
packageJson = require(path);
// eslint-disable-next-line no-empty
}
catch (e) { }
if (packageJson) {
return ((packageJson.dependencies &&
'@procore/eslint-config' in packageJson.dependencies) ||
(packageJson.devDependencies &&
'@procore/eslint-config' in packageJson.devDependencies));
}
return false;
}
const cwd = fs_1.default.realpathSync(process.cwd());
const packageJsonPath = path.resolve(cwd, 'package.json');
const hasProcoreEslintConfigInPackageJson = checkEslintConfigInPackageJson(packageJsonPath);
const rootPackageJsonPath = path.resolve(cwd, '../..', 'package.json');
const hasProcoreEslintConfigInRootPackageJson = checkEslintConfigInPackageJson(rootPackageJsonPath);
const { ModuleResolver } = require(eslintrcBundlePath).Legacy;
const originalResolve = ModuleResolver.resolve;
ModuleResolver.resolve = function HackedModuleResolver(moduleName, relativeToPath) {
if (moduleName === '@procore/eslint-config' &&
// if "@procore/eslint-config" in the "package.json" - use it instead builtin "@procore/eslint-config"
!hasProcoreEslintConfigInPackageJson &&
!hasProcoreEslintConfigInRootPackageJson) {
/**
* To find "@procore/eslint-config" in "@procore/core-scripts/node_modules",
* because original ModuleResolver starts search from cwd (package folder or workspace)
*/
//
return require.resolve(moduleName);
}
return originalResolve.call(this, moduleName, relativeToPath);
};
//# sourceMappingURL=hack.js.map