chore: warn against using globally scoped install (#13196)

This commit is contained in:
Ross Wollman 2022-04-03 20:26:23 -07:00 committed by GitHub
parent b0103566c9
commit 42798b5857
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -32,7 +32,7 @@ import { BrowserType } from '../client/browserType';
import { BrowserContextOptions, LaunchOptions } from '../client/types';
import { spawn } from 'child_process';
import { registry, Executable } from '../utils/registry';
import { spawnAsync, getPlaywrightVersion } from '../utils/utils';
import { spawnAsync, getPlaywrightVersion, wrapInASCIIBox } from '../utils/utils';
import { writeDockerVersion } from '../utils/dependencies';
import { launchGridAgent } from '../grid/gridAgent';
import { GridServer, GridFactory } from '../grid/gridServer';
@ -115,6 +115,27 @@ program
.option('--with-deps', 'install system dependencies for browsers')
.option('--force', 'force reinstall of stable browser channels')
.action(async function(args: string[], options: { withDeps?: boolean, force?: boolean }) {
const isLikelyNpxGlobal = process.argv.length >= 2 && process.argv[1].includes('_npx');
if (isLikelyNpxGlobal) {
console.error(wrapInASCIIBox([
`WARNING: It looks like you are running 'npx playwright install' without first`,
`installing your project's dependencies.`,
``,
`To avoid unexpected behavior, please install your dependencies first, and`,
`then run Playwright's install command:`,
``,
` npm install`,
` npx playwright install`,
``,
`If your project does not yet depend on Playwright, first install the`,
`applicable npm package (most commonly @playwright/test), and`,
`then run Playwright's install command to download the browsers:`,
``,
` npm install @playwright/test`,
` npx playwright install`,
``,
].join('\n'), 1));
}
try {
if (!args.length) {
const executables = registry.defaultExecutables();