From afd533f99c830c1b3203f7b3a4b6cd56ff40e6ae Mon Sep 17 00:00:00 2001 From: Jack Hsu Date: Wed, 28 Aug 2024 14:18:35 -0400 Subject: [PATCH] fix(core): fixes an issue where using "node:test" results in infinite loop --- .../build-dependencies/target-project-locator.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/nx/src/plugins/js/project-graph/build-dependencies/target-project-locator.ts b/packages/nx/src/plugins/js/project-graph/build-dependencies/target-project-locator.ts index af2890d22cdd82..f58ca021a69995 100644 --- a/packages/nx/src/plugins/js/project-graph/build-dependencies/target-project-locator.ts +++ b/packages/nx/src/plugins/js/project-graph/build-dependencies/target-project-locator.ts @@ -34,6 +34,11 @@ const defaultNpmResolutionCache: NpmResolutionCache = new Map(); const builtInModuleSet = new Set([ ...builtinModules, ...builtinModules.map((x) => `node:${x}`), + // These are missing in the builtinModules list + // See: https://github.com/nodejs/node/issues/42785 + // TODO(v20): We should be safe to use `isBuiltin` function instead of keep the set here (https://nodejs.org/api/module.html#moduleisbuiltinmodulename) + 'test', + 'node:test', ]); export function isBuiltinModuleImport(importExpr: string): boolean { @@ -364,7 +369,11 @@ export class TargetProjectLocator { packageJsonPath ?? resolveRelativeToDir(packageName, relativeToDir); let dir = dirname(pathOfFileInPackage); - while (dir !== parse(dir).root) { + while ( + // If we're at the root, then parse(dir).root is empty (''), so handle it separately. + dir !== '.' && + dir !== parse(dir).root + ) { const packageJsonPath = join(dir, 'package.json'); try { const parsedPackageJson = readJsonFile(packageJsonPath);