MCPcopy
hub / github.com/browserless/browserless / loadPwVersions

Method loadPwVersions

src/browserless.ts:169–206  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

167 }
168
169 protected async loadPwVersions(): Promise<void> {
170 // Consumer's package.json wins — downstream projects can declare their
171 // own playwrightVersions to override the SDK's defaults. Tolerate a
172 // missing consumer package.json (e.g. CWD detached from the project root)
173 // and fall back to the SDK's map below; surface other read/parse errors.
174 let consumerVersions: { [key: string]: string } | undefined;
175 try {
176 const consumerPkg = JSON.parse(
177 (await fs.readFile('package.json')).toString(),
178 );
179 consumerVersions = consumerPkg.playwrightVersions;
180 } catch (err) {
181 if ((err as NodeJS.ErrnoException).code !== 'ENOENT') throw err;
182 }
183
184 if (consumerVersions) {
185 this.config.setPwVersions(consumerVersions);
186 return;
187 }
188
189 // SDK consumers don't (and shouldn't have to) mirror the SDK's
190 // playwrightVersions map in their own package.json. Fall back to the
191 // SDK package's own map.
192 const sdkPkgPath = fileURLToPath(
193 new URL('../package.json', import.meta.url),
194 );
195 const { playwrightVersions: sdkVersions } = JSON.parse(
196 (await fs.readFile(sdkPkgPath)).toString(),
197 );
198
199 if (!sdkVersions) {
200 throw new Error(
201 `playwrightVersions is missing from both the consumer's package.json and the SDK's package.json at ${sdkPkgPath}. The SDK package is malformed.`,
202 );
203 }
204
205 this.config.setPwVersions(sdkVersions);
206 }
207
208 protected async loadInstalledBinaries(): Promise<void> {
209 const pwVersions = this.config.getPwVersions();

Callers 1

startMethod · 0.95

Calls 1

setPwVersionsMethod · 0.80

Tested by

no test coverage detected