Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/CommandLineOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface MultiProjectOptions {
inferTsconfig: boolean
progressBar: boolean
yarnWorkspaces: boolean
yarnBerryWorkspaces: boolean
cwd: string
output: string
indexedProjects: Set<string>
Expand All @@ -35,6 +36,11 @@ export function mainCommand(
.command('index')
.option('--cwd <path>', 'the working directory', process.cwd())
.option('--yarn-workspaces', 'whether to index all yarn workspaces', false)
.option(
'--yarn-berry-workspaces',
'whether to index all yarn v3 workspaces',
false
)
.option(
'--infer-tsconfig',
"whether to infer the tsconfig.json file, if it's missing",
Expand Down
1 change: 1 addition & 0 deletions src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ for (const snapshotDirectory of snapshotDirectories) {
inferTsconfig,
output,
yarnWorkspaces: Boolean(packageJson.workspaces),
yarnBerryWorkspaces: false,
progressBar: false,
indexedProjects: new Set(),
})
Expand Down
24 changes: 24 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export function indexCommand(
): void {
if (options.yarnWorkspaces) {
projects.push(...listYarnWorkspaces(options.cwd))
} else if (options.yarnBerryWorkspaces) {
projects.push(...listYarnBerryWorkspaces(options.cwd))
} else if (projects.length === 0) {
projects.push(options.cwd)
}
Expand Down Expand Up @@ -198,6 +200,28 @@ function defaultCompilerOptions(configFileName?: string): ts.CompilerOptions {
return options
}

function listYarnBerryWorkspaces(directory: string): string[] {
const result: string[] = []
const lines = child_process
.execSync('yarn workspaces list --json', {
cwd: directory,
encoding: 'utf-8',
})
.split('\n')
for (const line of lines) {
if (!line) {
continue
}
const location = 'location'
const json = JSON.parse(line)
if (json[location] !== undefined) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
result.push(path.join(directory, json[location]))
}
}
return result
}

function listYarnWorkspaces(directory: string): string[] {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const json = JSON.parse(
Expand Down