xref: /expo/tools/src/Workspace.ts (revision eeffdb10)
1import path from 'path';
2
3import { Package } from './Packages';
4import { spawnAsync, spawnJSONCommandAsync } from './Utils';
5import { EXPO_DIR } from './Constants';
6
7const NATIVE_APPS_PATHS = [EXPO_DIR, path.join(EXPO_DIR, 'apps/bare-expo')];
8
9/**
10 * Workspace info for the single project.
11 */
12export type WorkspaceProjectInfo = {
13  location: string;
14  workspaceDependencies: string[];
15  mismatchedWorkspaceDependencies: string[];
16};
17
18/**
19 * An object with workspace's projects info.
20 */
21export type WorkspacesInfo = Record<string, WorkspaceProjectInfo>;
22
23/**
24 * Returns an object containing info for all projects in the workspace.
25 */
26export async function getInfoAsync(): Promise<WorkspacesInfo> {
27  const info = await spawnJSONCommandAsync<{ data: string }>('yarn', [
28    '--json',
29    'workspaces',
30    'info',
31  ]);
32  return JSON.parse(info.data);
33}
34
35/**
36 * Runs yarn in the root workspace directory.
37 */
38export async function installAsync(): Promise<void> {
39  await spawnAsync('yarn');
40}
41
42/**
43 * Returns an array of workspace's native apps, like Expo Client or BareExpo.
44 */
45export function getNativeApps(): Package[] {
46  return NATIVE_APPS_PATHS.map((appPath) => new Package(appPath));
47}
48