Skip to content

Commit 63dd9e2

Browse files
committed
fix(19): detect (some) package managers
1 parent eab8bf1 commit 63dd9e2

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

src/builders/playwright/index.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ async function startDevServer(
6262
return server;
6363
}
6464

65+
export function getPackageManagerExecCommand() {
66+
const env = process.env.npm_config_user_agent || '';
67+
if (env.includes('yarn')) {
68+
return 'yarn';
69+
}
70+
if (env.includes('pnpm')) {
71+
return 'pnpm exec';
72+
}
73+
return 'npx';
74+
}
75+
6576
async function startPlaywrightTest(options: JsonObject, baseURL: string) {
6677
// PLAYWRIGHT_TEST_BASE_URL is actually a non-documented env variable used
6778
// by Playwright Test.
@@ -75,12 +86,16 @@ async function startPlaywrightTest(options: JsonObject, baseURL: string) {
7586
}
7687

7788
return new Promise((resolve, reject) => {
78-
const childProcess = spawn('npx playwright test', buildArgs(options), {
79-
cwd: process.cwd(),
80-
stdio: 'inherit',
81-
shell: true,
82-
env,
83-
});
89+
const childProcess = spawn(
90+
`${getPackageManagerExecCommand()} playwright test`,
91+
buildArgs(options),
92+
{
93+
cwd: process.cwd(),
94+
stdio: 'inherit',
95+
shell: true,
96+
env,
97+
},
98+
);
8499

85100
childProcess.on('exit', (exitCode) => {
86101
if (exitCode !== 0) {

src/schematics/install-browsers/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
import { spawnSync } from 'node:child_process';
22
import type { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
33

4+
export function getPackageManagerExecCommand() {
5+
const env = process.env.npm_config_user_agent || '';
6+
if (env.includes('yarn')) {
7+
return 'yarn';
8+
}
9+
if (env.includes('pnpm')) {
10+
return 'pnpm exec';
11+
}
12+
return 'npx';
13+
}
14+
415
export default function installBrowsers(): Rule {
516
return (tree: Tree, context: SchematicContext) => {
617
context.logger.info('Installing browsers...');
718

8-
spawnSync('npx playwright install', [], {
19+
spawnSync(`${getPackageManagerExecCommand()} playwright install`, [], {
920
cwd: process.cwd(),
1021
stdio: 'inherit',
1122
shell: true,

0 commit comments

Comments
 (0)