Update the euristic for getting the NPM workspace root.

This commit is contained in:
Joseph Garrone
2024-06-03 22:37:22 +02:00
parent e873eb5123
commit 57ac5badba

View File

@ -14,6 +14,8 @@ export function getNpmWorkspaceRootDirPath(params: {
pathJoin(...[reactAppRootDirPath, ...Array(depth).fill("..")]) pathJoin(...[reactAppRootDirPath, ...Array(depth).fill("..")])
); );
assert(cwd !== pathSep, "NPM workspace not found");
try { try {
child_process.execSync("npm config get", { child_process.execSync("npm config get", {
cwd, cwd,
@ -21,17 +23,18 @@ export function getNpmWorkspaceRootDirPath(params: {
}); });
} catch (error) { } catch (error) {
if (String(error).includes("ENOWORKSPACES")) { if (String(error).includes("ENOWORKSPACES")) {
assert(cwd !== pathSep, "NPM workspace not found");
return callee(depth + 1); return callee(depth + 1);
} }
throw error; throw error;
} }
const { isExpectedDependencyFound } = (() => {
const packageJsonFilePath = pathJoin(cwd, "package.json"); const packageJsonFilePath = pathJoin(cwd, "package.json");
if (!fs.existsSync(packageJsonFilePath)) {
return callee(depth + 1);
}
assert(fs.existsSync(packageJsonFilePath)); assert(fs.existsSync(packageJsonFilePath));
const parsedPackageJson = JSON.parse( const parsedPackageJson = JSON.parse(
@ -59,10 +62,7 @@ export function getNpmWorkspaceRootDirPath(params: {
isExpectedDependencyFound = true; isExpectedDependencyFound = true;
} }
return { isExpectedDependencyFound }; if (!isExpectedDependencyFound && parsedPackageJson.name !== dependencyExpected) {
})();
if (!isExpectedDependencyFound) {
return callee(depth + 1); return callee(depth + 1);
} }