diff options
Diffstat (limited to 'packages/turbo-workspaces/src/getWorkspaceDetails.ts')
| -rw-r--r-- | packages/turbo-workspaces/src/getWorkspaceDetails.ts | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/packages/turbo-workspaces/src/getWorkspaceDetails.ts b/packages/turbo-workspaces/src/getWorkspaceDetails.ts new file mode 100644 index 0000000..ad86a97 --- /dev/null +++ b/packages/turbo-workspaces/src/getWorkspaceDetails.ts @@ -0,0 +1,35 @@ +import { ConvertError } from "./errors"; +import managers from "./managers"; +import { Project } from "./types"; +import { directoryInfo } from "./utils"; + +export default async function getWorkspaceDetails({ + root, +}: { + root: string; +}): Promise<Project> { + const { exists, absolute: workspaceRoot } = directoryInfo({ + directory: root, + }); + if (!exists) { + throw new ConvertError( + `Could not find directory at ${workspaceRoot}. Ensure the directory exists.`, + { + type: "invalid_directory", + } + ); + } + + for (const { detect, read } of Object.values(managers)) { + if (await detect({ workspaceRoot })) { + return read({ workspaceRoot }); + } + } + + throw new ConvertError( + "Could not determine package manager. Add `packageManager` to `package.json` or ensure a lockfile is present.", + { + type: "package_manager-unable_to_detect", + } + ); +} |
