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

Commit

Permalink
feat: Support pnpm
Browse files Browse the repository at this point in the history
  • Loading branch information
ExE-Boss committed Jun 8, 2019
1 parent bf4befd commit d08e67e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/runner/index.ts
Expand Up @@ -8,6 +8,7 @@ import * as util from 'util';
import * as server from 'vscode-languageserver';
import { MruCache } from './mruCache';

export type PackageManagers = 'npm' | 'pnpm' | 'yarn';
export interface RunConfiguration {
readonly jsEnable: boolean;
readonly rulesDirectory?: string | string[];
Expand All @@ -16,7 +17,7 @@ export interface RunConfiguration {
readonly exclude: string[];
readonly validateWithDefaultConfig?: boolean;
readonly nodePath?: string;
readonly packageManager?: 'npm' | 'yarn';
readonly packageManager?: PackageManagers;
readonly traceLevel?: 'verbose' | 'normal';
readonly workspaceFolderPath?: string;
}
Expand Down Expand Up @@ -82,7 +83,7 @@ export class TsLintRunner {
private readonly document2LibraryCache = new MruCache<() => typeof tslint | undefined>(100);

// map stores undefined values to represent failed resolutions
private readonly globalPackageManagerPath = new Map<string, string>();
private readonly globalPackageManagerPath = new Map<PackageManagers, string>();
private readonly configCache = new ConfigCache();

constructor(
Expand Down Expand Up @@ -184,7 +185,7 @@ export class TsLintRunner {
});
}

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

if (!this.globalPackageManagerPath.has(packageManager)) {
Expand All @@ -193,6 +194,8 @@ export class TsLintRunner {
path = server.Files.resolveGlobalNodePath(this.trace);
} else if (packageManager === 'yarn') {
path = server.Files.resolveGlobalYarnPath(this.trace);
} else if (packageManager === 'pnpm') {
path = cp.execSync('pnpm root -g').toString().trim();
}
this.globalPackageManagerPath.set(packageManager, path!);
}
Expand Down Expand Up @@ -391,13 +394,15 @@ function testForExclusionPattern(filePath: string, pattern: string, cwd: string
return minimatch(filePath, pattern, { dot: true });
}

function getInstallFailureMessage(filePath: string, packageManager: 'npm' | 'yarn'): string {
function getInstallFailureMessage(filePath: string, packageManager: PackageManagers): string {
const localCommands = {
npm: 'npm install tslint',
pnpm: 'pnpm install tslint',
yarn: 'yarn add tslint',
};
const globalCommands = {
npm: 'npm install -g tslint',
pnpm: 'pnpm install -g tslint',
yarn: 'yarn global add tslint',
};

Expand Down

0 comments on commit d08e67e

Please sign in to comment.