From b2d53b673f81379fbd27a33ea9865d68067d90c1 Mon Sep 17 00:00:00 2001 From: codejedi365 Date: Sun, 12 Sep 2021 13:21:00 -0500 Subject: [PATCH] Bubble up file tree to find `jest` Handles the edge case of a monorepo where jest is installed inside a submodule only. cannot guarantee that the CWD is always the current project. Monorepos intend to bubble up the test/lint functionality to the root folder rather than all submodules. --- src/rules/no-deprecated-functions.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/rules/no-deprecated-functions.ts b/src/rules/no-deprecated-functions.ts index 94d56aa20..e59804e54 100644 --- a/src/rules/no-deprecated-functions.ts +++ b/src/rules/no-deprecated-functions.ts @@ -1,3 +1,4 @@ +import path from 'path'; import { JSONSchemaForNPMPackageJsonFiles } from '@schemastore/package'; import { AST_NODE_TYPES, @@ -40,9 +41,23 @@ const detectJestVersion = (): JestVersion => { return cachedJestVersion; } + const cwd = process.cwd(); + const pathsToCheck = [cwd]; + if (__dirname.includes(cwd)) { + let relPath = __dirname.replace(cwd, ""); + while (relPath !== "") { + relPath = path + .resolve(relPath) + .split(`${path.sep}node_modules`) + .slice(0,-1) + .join(`${path.sep}node_modules`); + pathsToCheck.unshift(path.join(cwd, relPath)); + } + } + try { const jestPath = require.resolve('jest/package.json', { - paths: [process.cwd()], + paths: pathsToCheck }); const jestPackageJson =