Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for pnpm #219

Merged
merged 4 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ yarn install
scip-typescript index --yarn-workspaces
```

### Index a TypeScript project using pnpm workspaces

Navigate to the project root, containing `package.json`.

```sh
pnpm install

scip-typescript index --pnpm-workspaces
```

### Indexing in CI

Add the following run steps to your CI pipeline:
Expand Down
1 change: 1 addition & 0 deletions src/CommandLineOptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ checkIndexParser([], {

checkIndexParser(['--cwd', 'qux'], { cwd: 'qux' })
checkIndexParser(['--yarn-workspaces'], { yarnWorkspaces: true })
checkIndexParser(['--pnpm-workspaces'], { pnpmWorkspaces: true })
checkIndexParser(['--infer-tsconfig'], { inferTsconfig: true })
checkIndexParser(['--no-progress-bar'], { progressBar: false })
checkIndexParser(['--progress-bar'], { progressBar: true })
Expand Down
2 changes: 2 additions & 0 deletions src/CommandLineOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface MultiProjectOptions {
progressBar: boolean
yarnWorkspaces: boolean
yarnBerryWorkspaces: boolean
pnpmWorkspaces: boolean
globalCaches: boolean
cwd: string
output: string
Expand Down Expand Up @@ -47,6 +48,7 @@ export function mainCommand(
command
.command('index')
.option('--cwd <path>', 'the working directory', process.cwd())
.option('--pnpm-workspaces', 'whether to index all pnpm workspaces', false)
.option('--yarn-workspaces', 'whether to index all yarn workspaces', false)
.option(
'--yarn-berry-workspaces',
Expand Down
1 change: 1 addition & 0 deletions src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ for (const snapshotDirectory of snapshotDirectories) {
output,
yarnWorkspaces: Boolean(packageJson.workspaces),
yarnBerryWorkspaces: false,
pnpmWorkspaces: false,
progressBar: false,
indexedProjects: new Set(),
globalCaches: true,
Expand Down
25 changes: 25 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env node
import * as child_process from 'child_process'
import * as fs from 'fs'
import { EOL } from 'os'
import * as path from 'path'
import * as url from 'url'

Expand Down Expand Up @@ -33,6 +34,8 @@ export function indexCommand(
projects.push(...listYarnWorkspaces(options.cwd, 'tryYarn1'))
} else if (options.yarnBerryWorkspaces) {
projects.push(...listYarnWorkspaces(options.cwd, 'yarn2Plus'))
} else if (options.pnpmWorkspaces) {
projects.push(...listPnpmWorkspaces(options.cwd))
} else if (projects.length === 0) {
projects.push(options.cwd)
}
Expand Down Expand Up @@ -211,6 +214,28 @@ function defaultCompilerOptions(configFileName?: string): ts.CompilerOptions {
return options
}

function listPnpmWorkspaces(directory: string): string[] {
/**
* Returns the list of projects formatted as:
* '/Users/user/sourcegraph/client/web:@sourcegraph/[email protected]:PRIVATE',
*
* See https://pnpm.io/id/cli/list#--depth-number
*/
const output = child_process.execSync(
'pnpm ls -r --depth -1 --long --parseable',
{
cwd: directory,
encoding: 'utf-8',
maxBuffer: 1024 * 1024 * 5, // 5MB
}
)

return output
.split(EOL)
.filter(project => project.includes(':'))
.map(project => project.split(':')[0])
}

function listYarnWorkspaces(
directory: string,
yarnVersion: 'tryYarn1' | 'yarn2Plus'
Expand Down