From dd1d3c3ed97173d97d30b2fb85b60ca82b6d0f0c Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Fri, 29 Oct 2021 20:12:46 +0200 Subject: [PATCH] Revert "chore: migrate away from ps1 in install-deps on Windows (#9876)" This reverts commit 59a406a586de5cbe39ce092b591c2c2271936f1c. --- .../bin/install_media_pack.ps1 | 5 +++ .../playwright-core/src/utils/dependencies.ts | 32 ++++--------------- 2 files changed, 11 insertions(+), 26 deletions(-) create mode 100644 packages/playwright-core/bin/install_media_pack.ps1 diff --git a/packages/playwright-core/bin/install_media_pack.ps1 b/packages/playwright-core/bin/install_media_pack.ps1 new file mode 100644 index 0000000000..6170754291 --- /dev/null +++ b/packages/playwright-core/bin/install_media_pack.ps1 @@ -0,0 +1,5 @@ +$osInfo = Get-WmiObject -Class Win32_OperatingSystem +# check if running on Windows Server +if ($osInfo.ProductType -eq 3) { + Install-WindowsFeature Server-Media-Foundation +} diff --git a/packages/playwright-core/src/utils/dependencies.ts b/packages/playwright-core/src/utils/dependencies.ts index 08bf296f49..d52e4b6df3 100644 --- a/packages/playwright-core/src/utils/dependencies.ts +++ b/packages/playwright-core/src/utils/dependencies.ts @@ -22,6 +22,8 @@ import { getUbuntuVersion } from './ubuntuVersion'; import * as utils from './utils'; import { buildPlaywrightCLICommand } from './registry'; +const BIN_DIRECTORY = path.join(__dirname, '..', '..', 'bin'); + const checkExecutable = (filePath: string) => fs.promises.access(filePath, fs.constants.X_OK).then(() => true).catch(e => false); function isSupportedWindowsVersion(): boolean { @@ -37,33 +39,11 @@ function isSupportedWindowsVersion(): boolean { export type DependencyGroup = 'chromium' | 'firefox' | 'webkit' | 'tools'; export async function installDependenciesWindows(targets: Set) { - if (!targets.has('chromium')) - return; - if (!await isWindowsServer()) - return; - const { code } = await utils.spawnAsync('dism.exe', ['/Online', '/Enable-Feature', '/FeatureName:ServerMediaFoundation', '/Quiet'], { stdio: 'inherit' }); - if (code !== 0) - throw new Error('Failed to install windows dependencies!'); -} - -async function isWindowsServer(): Promise { - /** - * ProductType Enum: - * 0 = Unknown - Product type is unknown - * 1 = WorkStation - System is a workstation - * 2 = DomainController - System is a domain controller - * 3 = Server - System is a server - * @see https://docs.microsoft.com/en-us/dotnet/api/microsoft.powershell.commands.producttype?view=powershellsdk-1.1.0 - */ - const { code, stdout } = await utils.spawnAsync('wmic.exe', ['path', 'Win32_OperatingSystem', 'get', 'ProductType', '/VALUE']); - if (code !== 0) - throw new Error('Failed to get product type version!'); - for (const line of stdout.trim().split('\n')) { - const [key, value] = line.split('='); - if (key === 'ProductType') - return parseInt(value, 10) === 3; + if (targets.has('chromium')) { + const { code } = await utils.spawnAsync('powershell.exe', ['-File', path.join(BIN_DIRECTORY, 'install_media_pack.ps1')], { cwd: BIN_DIRECTORY, stdio: 'inherit' }); + if (code !== 0) + throw new Error('Failed to install windows dependencies!'); } - throw new Error('Failed to parse product type version!\nstdout:' + stdout); } export async function installDependenciesLinux(targets: Set) {