Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make projectRoot optional in Puppeteer and launchers #7967

Merged
merged 1 commit into from Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/initialize-node.ts
Expand Up @@ -34,10 +34,6 @@ export const initializePuppeteerNode = (packageName: string): PuppeteerNode => {
if (!isPuppeteerCore && productName === 'firefox')
preferredRevision = PUPPETEER_REVISIONS.firefox;

if (!puppeteerRootDirectory) {
throw new Error('puppeteerRootDirectory is not found.');
}

return new PuppeteerNode({
projectRoot: puppeteerRootDirectory,
preferredRevision,
Expand Down
20 changes: 15 additions & 5 deletions src/node/Launcher.ts
Expand Up @@ -52,12 +52,12 @@ export interface ProductLauncher {
* @internal
*/
class ChromeLauncher implements ProductLauncher {
_projectRoot: string;
_projectRoot: string | undefined;
_preferredRevision: string;
_isPuppeteerCore: boolean;

constructor(
projectRoot: string,
projectRoot: string | undefined,
preferredRevision: string,
isPuppeteerCore: boolean
) {
Expand Down Expand Up @@ -276,12 +276,12 @@ class ChromeLauncher implements ProductLauncher {
* @internal
*/
class FirefoxLauncher implements ProductLauncher {
_projectRoot: string;
_projectRoot: string | undefined;
_preferredRevision: string;
_isPuppeteerCore: boolean;

constructor(
projectRoot: string,
projectRoot: string | undefined,
preferredRevision: string,
isPuppeteerCore: boolean
) {
Expand Down Expand Up @@ -428,6 +428,11 @@ class FirefoxLauncher implements ProductLauncher {
async _updateRevision(): Promise<void> {
// replace 'latest' placeholder with actual downloaded revision
if (this._preferredRevision === 'latest') {
if (!this._projectRoot) {
throw new Error(
'_projectRoot is undefined. Unable to create a BrowserFetcher.'
);
}
const browserFetcher = new BrowserFetcher(this._projectRoot, {
product: this.product,
});
Expand Down Expand Up @@ -813,6 +818,11 @@ function resolveExecutablePath(launcher: ChromeLauncher | FirefoxLauncher): {
process.env.npm_config_puppeteer_download_path ||
process.env.npm_package_config_puppeteer_download_path;
}
if (!launcher._projectRoot) {
throw new Error(
'_projectRoot is undefined. Unable to create a BrowserFetcher.'
);
}
const browserFetcher = new BrowserFetcher(launcher._projectRoot, {
product: launcher.product,
path: downloadPath,
Expand Down Expand Up @@ -845,7 +855,7 @@ function resolveExecutablePath(launcher: ChromeLauncher | FirefoxLauncher): {
* @internal
*/
export default function Launcher(
projectRoot: string,
projectRoot: string | undefined,
preferredRevision: string,
isPuppeteerCore: boolean,
product?: string
Expand Down
9 changes: 7 additions & 2 deletions src/node/Puppeteer.ts
Expand Up @@ -67,7 +67,7 @@ import { Product } from '../common/Product.js';
*/
export class PuppeteerNode extends Puppeteer {
private _lazyLauncher?: ProductLauncher;
private _projectRoot: string;
private _projectRoot?: string;
private __productName?: Product;
/**
* @internal
Expand All @@ -79,7 +79,7 @@ export class PuppeteerNode extends Puppeteer {
*/
constructor(
settings: {
projectRoot: string;
projectRoot?: string;
preferredRevision: string;
productName?: Product;
} & CommonPuppeteerSettings
Expand Down Expand Up @@ -224,6 +224,11 @@ export class PuppeteerNode extends Puppeteer {
* @returns A new BrowserFetcher instance.
*/
createBrowserFetcher(options: BrowserFetcherOptions): BrowserFetcher {
if (!this._projectRoot) {
throw new Error(
'_projectRoot is undefined. Unable to create a BrowserFetcher.'
);
}
return new BrowserFetcher(this._projectRoot, options);
}
}