mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix: use both __dirname and require.resolve to support different bundlers (#8046)
Issues: #8044
This commit is contained in:
parent
5ad343453a
commit
e6a6295d9a
@ -20,10 +20,21 @@ import { sync } from 'pkg-dir';
|
||||
import { dirname } from 'path';
|
||||
import { Product } from './common/Product.js';
|
||||
|
||||
function resolvePuppeteerRootDirectory(): string | undefined {
|
||||
try {
|
||||
// In some environments, like esbuild, this will throw an error.
|
||||
// We suppress the error since the bundled binary is not expected
|
||||
// to be used or installed in this case and, therefore, the
|
||||
// root directory does not have to be known.
|
||||
return sync(dirname(require.resolve('./initialize-node')));
|
||||
} catch (error) {
|
||||
// Fallback to __dirname.
|
||||
return sync(__dirname);
|
||||
}
|
||||
}
|
||||
|
||||
export const initializePuppeteerNode = (packageName: string): PuppeteerNode => {
|
||||
const puppeteerRootDirectory = sync(
|
||||
dirname(require.resolve('./initialize-node'))
|
||||
);
|
||||
const puppeteerRootDirectory = resolvePuppeteerRootDirectory();
|
||||
let preferredRevision = PUPPETEER_REVISIONS.chromium;
|
||||
const isPuppeteerCore = packageName === 'puppeteer-core';
|
||||
// puppeteer-core ignores environment variables
|
||||
|
Loading…
Reference in New Issue
Block a user