nx/packages/cli/lib/find-workspace-root.ts
Stuart Taylor 9180e9094c
fix(core): allow building of workspaces when hosted at / (#5252)
Building a project in the node:14-alpine docker image requires the workspace to be copied in
to directory other than /.
The proposed change allows workspaces to be hosted at / and not force the developer to create a directory inside a docker image just to build the project.

Co-authored-by: Stuart Taylor <stuart@chargifi.com>
2021-04-13 15:34:45 -04:00

26 lines
619 B
TypeScript

import { existsSync } from 'fs';
import * as path from 'path';
import { Workspace } from './workspace';
/**
* Recursive function that walks back up the directory
* tree to try and find a workspace file.
*
* @param dir Directory to start searching with
*/
export function findWorkspaceRoot(dir: string): Workspace | null {
if (existsSync(path.join(dir, 'angular.json'))) {
return { type: 'angular', dir };
}
if (existsSync(path.join(dir, 'workspace.json'))) {
return { type: 'nx', dir };
}
if (path.dirname(dir) === dir) {
return null;
}
return findWorkspaceRoot(path.dirname(dir));
}