fix: make projectRoot optional in Puppeteer and launchers (#7967)
This commit is contained in:
parent
09ff56b7a8
commit
9afdc6300b
@ -34,10 +34,6 @@ export const initializePuppeteerNode = (packageName: string): PuppeteerNode => {
|
|||||||
if (!isPuppeteerCore && productName === 'firefox')
|
if (!isPuppeteerCore && productName === 'firefox')
|
||||||
preferredRevision = PUPPETEER_REVISIONS.firefox;
|
preferredRevision = PUPPETEER_REVISIONS.firefox;
|
||||||
|
|
||||||
if (!puppeteerRootDirectory) {
|
|
||||||
throw new Error('puppeteerRootDirectory is not found.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return new PuppeteerNode({
|
return new PuppeteerNode({
|
||||||
projectRoot: puppeteerRootDirectory,
|
projectRoot: puppeteerRootDirectory,
|
||||||
preferredRevision,
|
preferredRevision,
|
||||||
|
@ -52,12 +52,12 @@ export interface ProductLauncher {
|
|||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
class ChromeLauncher implements ProductLauncher {
|
class ChromeLauncher implements ProductLauncher {
|
||||||
_projectRoot: string;
|
_projectRoot: string | undefined;
|
||||||
_preferredRevision: string;
|
_preferredRevision: string;
|
||||||
_isPuppeteerCore: boolean;
|
_isPuppeteerCore: boolean;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
projectRoot: string,
|
projectRoot: string | undefined,
|
||||||
preferredRevision: string,
|
preferredRevision: string,
|
||||||
isPuppeteerCore: boolean
|
isPuppeteerCore: boolean
|
||||||
) {
|
) {
|
||||||
@ -276,12 +276,12 @@ class ChromeLauncher implements ProductLauncher {
|
|||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
class FirefoxLauncher implements ProductLauncher {
|
class FirefoxLauncher implements ProductLauncher {
|
||||||
_projectRoot: string;
|
_projectRoot: string | undefined;
|
||||||
_preferredRevision: string;
|
_preferredRevision: string;
|
||||||
_isPuppeteerCore: boolean;
|
_isPuppeteerCore: boolean;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
projectRoot: string,
|
projectRoot: string | undefined,
|
||||||
preferredRevision: string,
|
preferredRevision: string,
|
||||||
isPuppeteerCore: boolean
|
isPuppeteerCore: boolean
|
||||||
) {
|
) {
|
||||||
@ -428,6 +428,11 @@ class FirefoxLauncher implements ProductLauncher {
|
|||||||
async _updateRevision(): Promise<void> {
|
async _updateRevision(): Promise<void> {
|
||||||
// replace 'latest' placeholder with actual downloaded revision
|
// replace 'latest' placeholder with actual downloaded revision
|
||||||
if (this._preferredRevision === 'latest') {
|
if (this._preferredRevision === 'latest') {
|
||||||
|
if (!this._projectRoot) {
|
||||||
|
throw new Error(
|
||||||
|
'_projectRoot is undefined. Unable to create a BrowserFetcher.'
|
||||||
|
);
|
||||||
|
}
|
||||||
const browserFetcher = new BrowserFetcher(this._projectRoot, {
|
const browserFetcher = new BrowserFetcher(this._projectRoot, {
|
||||||
product: this.product,
|
product: this.product,
|
||||||
});
|
});
|
||||||
@ -813,6 +818,11 @@ function resolveExecutablePath(launcher: ChromeLauncher | FirefoxLauncher): {
|
|||||||
process.env.npm_config_puppeteer_download_path ||
|
process.env.npm_config_puppeteer_download_path ||
|
||||||
process.env.npm_package_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, {
|
const browserFetcher = new BrowserFetcher(launcher._projectRoot, {
|
||||||
product: launcher.product,
|
product: launcher.product,
|
||||||
path: downloadPath,
|
path: downloadPath,
|
||||||
@ -845,7 +855,7 @@ function resolveExecutablePath(launcher: ChromeLauncher | FirefoxLauncher): {
|
|||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
export default function Launcher(
|
export default function Launcher(
|
||||||
projectRoot: string,
|
projectRoot: string | undefined,
|
||||||
preferredRevision: string,
|
preferredRevision: string,
|
||||||
isPuppeteerCore: boolean,
|
isPuppeteerCore: boolean,
|
||||||
product?: string
|
product?: string
|
||||||
|
@ -67,7 +67,7 @@ import { Product } from '../common/Product.js';
|
|||||||
*/
|
*/
|
||||||
export class PuppeteerNode extends Puppeteer {
|
export class PuppeteerNode extends Puppeteer {
|
||||||
private _lazyLauncher?: ProductLauncher;
|
private _lazyLauncher?: ProductLauncher;
|
||||||
private _projectRoot: string;
|
private _projectRoot?: string;
|
||||||
private __productName?: Product;
|
private __productName?: Product;
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
@ -79,7 +79,7 @@ export class PuppeteerNode extends Puppeteer {
|
|||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
settings: {
|
settings: {
|
||||||
projectRoot: string;
|
projectRoot?: string;
|
||||||
preferredRevision: string;
|
preferredRevision: string;
|
||||||
productName?: Product;
|
productName?: Product;
|
||||||
} & CommonPuppeteerSettings
|
} & CommonPuppeteerSettings
|
||||||
@ -224,6 +224,11 @@ export class PuppeteerNode extends Puppeteer {
|
|||||||
* @returns A new BrowserFetcher instance.
|
* @returns A new BrowserFetcher instance.
|
||||||
*/
|
*/
|
||||||
createBrowserFetcher(options: BrowserFetcherOptions): BrowserFetcher {
|
createBrowserFetcher(options: BrowserFetcherOptions): BrowserFetcher {
|
||||||
|
if (!this._projectRoot) {
|
||||||
|
throw new Error(
|
||||||
|
'_projectRoot is undefined. Unable to create a BrowserFetcher.'
|
||||||
|
);
|
||||||
|
}
|
||||||
return new BrowserFetcher(this._projectRoot, options);
|
return new BrowserFetcher(this._projectRoot, options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user