Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit d08e67e

Browse files
committed
feat: Support pnpm
1 parent bf4befd commit d08e67e

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/runner/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as util from 'util';
88
import * as server from 'vscode-languageserver';
99
import { MruCache } from './mruCache';
1010

11+
export type PackageManagers = 'npm' | 'pnpm' | 'yarn';
1112
export interface RunConfiguration {
1213
readonly jsEnable: boolean;
1314
readonly rulesDirectory?: string | string[];
@@ -16,7 +17,7 @@ export interface RunConfiguration {
1617
readonly exclude: string[];
1718
readonly validateWithDefaultConfig?: boolean;
1819
readonly nodePath?: string;
19-
readonly packageManager?: 'npm' | 'yarn';
20+
readonly packageManager?: PackageManagers;
2021
readonly traceLevel?: 'verbose' | 'normal';
2122
readonly workspaceFolderPath?: string;
2223
}
@@ -82,7 +83,7 @@ export class TsLintRunner {
8283
private readonly document2LibraryCache = new MruCache<() => typeof tslint | undefined>(100);
8384

8485
// map stores undefined values to represent failed resolutions
85-
private readonly globalPackageManagerPath = new Map<string, string>();
86+
private readonly globalPackageManagerPath = new Map<PackageManagers, string>();
8687
private readonly configCache = new ConfigCache();
8788

8889
constructor(
@@ -184,7 +185,7 @@ export class TsLintRunner {
184185
});
185186
}
186187

187-
private getGlobalPackageManagerPath(packageManager: string = 'npm'): string | undefined {
188+
private getGlobalPackageManagerPath(packageManager: PackageManagers = 'npm'): string | undefined {
188189
this.traceMethod('getGlobalPackageManagerPath', `Begin - Resolve Global Package Manager Path for: ${packageManager}`);
189190

190191
if (!this.globalPackageManagerPath.has(packageManager)) {
@@ -193,6 +194,8 @@ export class TsLintRunner {
193194
path = server.Files.resolveGlobalNodePath(this.trace);
194195
} else if (packageManager === 'yarn') {
195196
path = server.Files.resolveGlobalYarnPath(this.trace);
197+
} else if (packageManager === 'pnpm') {
198+
path = cp.execSync('pnpm root -g').toString().trim();
196199
}
197200
this.globalPackageManagerPath.set(packageManager, path!);
198201
}
@@ -391,13 +394,15 @@ function testForExclusionPattern(filePath: string, pattern: string, cwd: string
391394
return minimatch(filePath, pattern, { dot: true });
392395
}
393396

394-
function getInstallFailureMessage(filePath: string, packageManager: 'npm' | 'yarn'): string {
397+
function getInstallFailureMessage(filePath: string, packageManager: PackageManagers): string {
395398
const localCommands = {
396399
npm: 'npm install tslint',
400+
pnpm: 'pnpm install tslint',
397401
yarn: 'yarn add tslint',
398402
};
399403
const globalCommands = {
400404
npm: 'npm install -g tslint',
405+
pnpm: 'pnpm install -g tslint',
401406
yarn: 'yarn global add tslint',
402407
};
403408

0 commit comments

Comments
 (0)