Skip to content
Closed
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
17 changes: 15 additions & 2 deletions src/packageManager.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import fs from 'node:fs'
import path from 'node:path'

interface PackageManager {
cli: string;
name: string
Expand Down Expand Up @@ -61,7 +64,7 @@ class Yarn implements PackageManager {
runPlaywrightTest(args: string): string {
return this.npx('playwright', `test${args ? (' ' + args) : ''}`);
}

run(script: string): string {
return `yarn ${script}`;
}
Expand Down Expand Up @@ -96,12 +99,22 @@ class PNPM implements PackageManager {
}
}

class PNPMWITHWORKSPACE extends PNPM {
override installDevDependency(name: string): string {
return `pnpm add --save-dev -w ${name}`
}
}

function determinePackageManager(): PackageManager {
if (process.env.npm_config_user_agent) {
if (process.env.npm_config_user_agent.includes('yarn'))
return new Yarn()
if (process.env.npm_config_user_agent.includes('pnpm'))
return new PNPM()
if (fs.existsSync(path.join(process.cwd(), 'pnpm-workspace.yaml'))) {
return new PNPMWITHWORKSPACE()
} else {
return new PNPM()
}
return new NPM()
}
return new NPM()
Expand Down