Skip to content

Commit

Permalink
fix: use both __dirname and require.resolve to support different bund…
Browse files Browse the repository at this point in the history
…lers (#8046)

Issues: #8044
  • Loading branch information
OrKoN committed Feb 22, 2022
1 parent 5ad3434 commit e6a6295
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/initialize-node.ts
Expand Up @@ -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
Expand Down

0 comments on commit e6a6295

Please sign in to comment.