chore: read browsers.json with require (#6186)

This fixes the compatibility on Vercel with Next.js when it's used in
a serverless function.
Next.js uses https://github.com/vercel/nft to trace down the
dependencies which a serverless function is using which
is currently not capable of detecting the browsers.json in our current
setup. Previously we used require to load the browers.json which was
replaced by readFileSync in #5318. Since then it was broken.

Fixes #5862
This commit is contained in:
Max Schmitt 2021-04-19 22:06:04 +02:00 committed by GitHub
parent 6296d276f2
commit 7ec57c0c18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,7 +16,6 @@
*/ */
import { execSync } from 'child_process'; import { execSync } from 'child_process';
import fs from 'fs';
import * as os from 'os'; import * as os from 'os';
import path from 'path'; import path from 'path';
import * as util from 'util'; import * as util from 'util';
@ -235,7 +234,9 @@ export class Registry {
} }
constructor(packagePath: string) { constructor(packagePath: string) {
const browsersJSON = JSON.parse(fs.readFileSync(path.join(packagePath, 'browsers.json'), 'utf8')); // require() needs to be used there otherwise it breaks on Vercel serverless
// functions. See https://github.com/microsoft/playwright/pull/6186
const browsersJSON = require(path.join(packagePath, 'browsers.json'));
this._descriptors = browsersJSON['browsers'].map((obj: any) => { this._descriptors = browsersJSON['browsers'].map((obj: any) => {
const name = obj.name; const name = obj.name;
const revisionOverride = (obj.revisionOverrides || {})[hostPlatform]; const revisionOverride = (obj.revisionOverrides || {})[hostPlatform];