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 { dirname } from 'path';
|
||||||
import { Product } from './common/Product.js';
|
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 => {
|
export const initializePuppeteerNode = (packageName: string): PuppeteerNode => {
|
||||||
const puppeteerRootDirectory = sync(
|
const puppeteerRootDirectory = resolvePuppeteerRootDirectory();
|
||||||
dirname(require.resolve('./initialize-node'))
|
|
||||||
);
|
|
||||||
let preferredRevision = PUPPETEER_REVISIONS.chromium;
|
let preferredRevision = PUPPETEER_REVISIONS.chromium;
|
||||||
const isPuppeteerCore = packageName === 'puppeteer-core';
|
const isPuppeteerCore = packageName === 'puppeteer-core';
|
||||||
// puppeteer-core ignores environment variables
|
// puppeteer-core ignores environment variables
|
||||||
|
Loading…
Reference in New Issue
Block a user