From b2c5bfb72c45446ce2825ae9dea814769919d25b Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Mon, 19 Jul 2021 13:54:42 +0300 Subject: [PATCH] chore: nicer message to install dependencies (#7715) If we know how to install all dependencies, then we should recommend a Playwright CLI one-liner to install dependencies. References #7682 --- src/utils/dependencies.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/utils/dependencies.ts b/src/utils/dependencies.ts index 088dcc72b5..14cfc57b5b 100644 --- a/src/utils/dependencies.ts +++ b/src/utils/dependencies.ts @@ -175,11 +175,26 @@ export async function validateDependenciesLinux(linuxLddDirectories: string[], d } } + const maybeSudo = (process.getuid() !== 0) && os.platform() !== 'win32' ? 'sudo ' : ''; + // Happy path: known dependencies are missing for browsers. + // Suggest installation with a Playwright CLI. + if (missingPackages.size && !missingDeps.size) { + throw new Error('\n' + utils.wrapInASCIIBox([ + `Host system is missing a few dependencies to run browsers.`, + `Please install them with the following command:`, + ``, + ` ${maybeSudo}npx playwright install-deps`, + ``, + `<3 Playwright Team`, + ].join('\n'), 1)); + } + + // Unhappy path - unusual distribution configuration. let missingPackagesMessage = ''; if (missingPackages.size) { missingPackagesMessage = [ ` Install missing packages with:`, - ` sudo apt-get install ${[...missingPackages].join('\\\n ')}`, + ` ${maybeSudo}apt-get install ${[...missingPackages].join('\\\n ')}`, ``, ``, ].join('\n');