From 30c6b13eec4cebf4fe4e5ec069169b562750558e Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Thu, 10 Nov 2022 17:11:18 +0100 Subject: [PATCH] chore: re-export all exports (#9241) Adds index files to subfolders and removes generation of types.ts in puppeteer-core. --- docs/api/index.md | 1 + docs/api/puppeteer.connect.md | 4 +- docs/api/puppeteer.createbrowserfetcher.md | 4 +- docs/api/puppeteer.defaultargs.md | 2 +- docs/api/puppeteer.executablepath.md | 2 +- docs/api/puppeteer.launch.md | 4 +- docs/api/puppeteer.puppeteer.md | 24 +----- ...teer.puppeteernode.createbrowserfetcher.md | 8 +- packages/puppeteer-core/api-extractor.json | 2 +- packages/puppeteer-core/package.json | 3 +- packages/puppeteer-core/src/api/api.ts | 19 +++++ .../src/common/AriaQueryHandler.ts | 18 +++-- packages/puppeteer-core/src/common/Frame.ts | 3 +- .../puppeteer-core/src/common/FrameManager.ts | 3 +- .../src/common/IsolatedWorld.ts | 20 +---- .../src/common/IsolatedWorlds.ts | 30 ++++++++ packages/puppeteer-core/src/common/Page.ts | 3 +- .../puppeteer-core/src/common/QueryHandler.ts | 7 +- .../puppeteer-core/src/common/bidi/bidi.ts | 20 +++++ packages/puppeteer-core/src/common/common.ts | 69 +++++++++++++++++ .../puppeteer-core/src/node/PuppeteerNode.ts | 7 +- packages/puppeteer-core/src/node/node.ts | 24 ++++++ packages/puppeteer-core/src/puppeteer-core.ts | 17 ++--- packages/puppeteer-core/src/types.ts | 75 ------------------ packages/puppeteer-core/src/util/util.ts | 20 +++++ .../puppeteer-core/tools/generate_sources.ts | 19 ----- packages/puppeteer/api-extractor.json | 2 +- packages/puppeteer/package.json | 15 +--- packages/puppeteer/src/puppeteer.ts | 12 +-- packages/puppeteer/src/types.ts | 76 ------------------- packages/puppeteer/tools/generate_sources.ts | 52 ------------- test/src/injected.spec.ts | 2 +- 32 files changed, 238 insertions(+), 329 deletions(-) create mode 100644 packages/puppeteer-core/src/api/api.ts create mode 100644 packages/puppeteer-core/src/common/IsolatedWorlds.ts create mode 100644 packages/puppeteer-core/src/common/bidi/bidi.ts create mode 100644 packages/puppeteer-core/src/common/common.ts create mode 100644 packages/puppeteer-core/src/node/node.ts delete mode 100644 packages/puppeteer-core/src/types.ts create mode 100644 packages/puppeteer-core/src/util/util.ts delete mode 100644 packages/puppeteer/src/types.ts delete mode 100644 packages/puppeteer/tools/generate_sources.ts diff --git a/docs/api/index.md b/docs/api/index.md index 4db66c57..1831c8af 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -136,6 +136,7 @@ sidebar_label: API | [launch](./puppeteer.launch.md) | | | [networkConditions](./puppeteer.networkconditions.md) | | | [PredefinedNetworkConditions](./puppeteer.predefinednetworkconditions.md) | A list of network conditions to be used with [Page.emulateNetworkConditions()](./puppeteer.page.emulatenetworkconditions.md). | +| [puppeteer](./puppeteer.puppeteer.md) | | ## Type Aliases diff --git a/docs/api/puppeteer.connect.md b/docs/api/puppeteer.connect.md index e9528d8d..4e6a9907 100644 --- a/docs/api/puppeteer.connect.md +++ b/docs/api/puppeteer.connect.md @@ -8,6 +8,6 @@ sidebar_label: connect ```typescript connect: ( - options: import('puppeteer-core/internal/common/Puppeteer.js').ConnectOptions -) => Promise; + options: import('puppeteer-core/internal/puppeteer-core.js').ConnectOptions +) => Promise; ``` diff --git a/docs/api/puppeteer.createbrowserfetcher.md b/docs/api/puppeteer.createbrowserfetcher.md index 79de3472..29251c6f 100644 --- a/docs/api/puppeteer.createbrowserfetcher.md +++ b/docs/api/puppeteer.createbrowserfetcher.md @@ -9,7 +9,7 @@ sidebar_label: createBrowserFetcher ```typescript createBrowserFetcher: ( options: Partial< - import('puppeteer-core/internal/node/BrowserFetcher.js').BrowserFetcherOptions + import('puppeteer-core/internal/puppeteer-core.js').BrowserFetcherOptions > -) => import('puppeteer-core/internal/node/BrowserFetcher.js').BrowserFetcher; +) => import('puppeteer-core/internal/puppeteer-core.js').BrowserFetcher; ``` diff --git a/docs/api/puppeteer.defaultargs.md b/docs/api/puppeteer.defaultargs.md index e8ede108..1ae36107 100644 --- a/docs/api/puppeteer.defaultargs.md +++ b/docs/api/puppeteer.defaultargs.md @@ -7,5 +7,5 @@ sidebar_label: defaultArgs #### Signature: ```typescript -defaultArgs: (options?: import("puppeteer-core/internal/node/LaunchOptions.js").BrowserLaunchArgumentOptions | undefined) => string[] +defaultArgs: (options?: import("puppeteer-core/internal/puppeteer-core.js").BrowserLaunchArgumentOptions | undefined) => string[] ``` diff --git a/docs/api/puppeteer.executablepath.md b/docs/api/puppeteer.executablepath.md index 22ffddc5..3ad87f3d 100644 --- a/docs/api/puppeteer.executablepath.md +++ b/docs/api/puppeteer.executablepath.md @@ -9,7 +9,7 @@ sidebar_label: executablePath ```typescript executablePath: ( channel?: - | import('puppeteer-core/internal/node/LaunchOptions.js').ChromeReleaseChannel + | import('puppeteer-core/internal/puppeteer-core.js').ChromeReleaseChannel | undefined ) => string; ``` diff --git a/docs/api/puppeteer.launch.md b/docs/api/puppeteer.launch.md index 8cc9e89e..5c9954c9 100644 --- a/docs/api/puppeteer.launch.md +++ b/docs/api/puppeteer.launch.md @@ -9,7 +9,7 @@ sidebar_label: launch ```typescript launch: ( options?: - | import('puppeteer-core/internal/node/PuppeteerNode.js').PuppeteerLaunchOptions + | import('puppeteer-core/internal/puppeteer-core.js').PuppeteerLaunchOptions | undefined -) => Promise; +) => Promise; ``` diff --git a/docs/api/puppeteer.puppeteer.md b/docs/api/puppeteer.puppeteer.md index 2cf22d42..ff8f3561 100644 --- a/docs/api/puppeteer.puppeteer.md +++ b/docs/api/puppeteer.puppeteer.md @@ -1,29 +1,11 @@ --- -sidebar_label: Puppeteer +sidebar_label: puppeteer --- -# Puppeteer class - -The main Puppeteer class. - -IMPORTANT: if you are using Puppeteer in a Node environment, you will get an instance of [PuppeteerNode](./puppeteer.puppeteernode.md) when you import or require `puppeteer`. That class extends `Puppeteer`, so has all the methods documented below as well as all that are defined on [PuppeteerNode](./puppeteer.puppeteernode.md). +# puppeteer variable #### Signature: ```typescript -export declare class Puppeteer +puppeteer: PuppeteerNode; ``` - -## Remarks - -The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `Puppeteer` class. - -## Methods - -| Method | Modifiers | Description | -| ----------------------------------------------------------------------------------------------------- | ------------------- | ---------------------------------------------------------------------- | -| [clearCustomQueryHandlers()](./puppeteer.puppeteer.clearcustomqueryhandlers.md) | static | Unregisters all custom query handlers. | -| [connect(options)](./puppeteer.puppeteer.connect.md) | | This method attaches Puppeteer to an existing browser instance. | -| [customQueryHandlerNames()](./puppeteer.puppeteer.customqueryhandlernames.md) | static | Gets the names of all custom query handlers. | -| [registerCustomQueryHandler(name, queryHandler)](./puppeteer.puppeteer.registercustomqueryhandler.md) | static | Registers a [custom query handler](./puppeteer.customqueryhandler.md). | -| [unregisterCustomQueryHandler(name)](./puppeteer.puppeteer.unregistercustomqueryhandler.md) | static | Unregisters a custom query handler for a given name. | diff --git a/docs/api/puppeteer.puppeteernode.createbrowserfetcher.md b/docs/api/puppeteer.puppeteernode.createbrowserfetcher.md index ff25dcbe..ba9c70ec 100644 --- a/docs/api/puppeteer.puppeteernode.createbrowserfetcher.md +++ b/docs/api/puppeteer.puppeteernode.createbrowserfetcher.md @@ -4,10 +4,6 @@ sidebar_label: PuppeteerNode.createBrowserFetcher # PuppeteerNode.createBrowserFetcher() method -> Warning: This API is now obsolete. -> -> If you are using `puppeteer-core`, do not use this method. Just construct [BrowserFetcher](./puppeteer.browserfetcher.md) manually. - #### Signature: ```typescript @@ -27,3 +23,7 @@ class PuppeteerNode { [BrowserFetcher](./puppeteer.browserfetcher.md) A new BrowserFetcher instance. + +## Remarks + +If you are using `puppeteer-core`, do not use this method. Just construct [BrowserFetcher](./puppeteer.browserfetcher.md) manually. diff --git a/packages/puppeteer-core/api-extractor.json b/packages/puppeteer-core/api-extractor.json index feba8dec..df82b3dc 100644 --- a/packages/puppeteer-core/api-extractor.json +++ b/packages/puppeteer-core/api-extractor.json @@ -1,6 +1,6 @@ { "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", - "mainEntryPointFilePath": "/lib/esm/puppeteer/types.d.ts", + "mainEntryPointFilePath": "/lib/esm/puppeteer/puppeteer-core.d.ts", "bundledPackages": [], "apiReport": { diff --git a/packages/puppeteer-core/package.json b/packages/puppeteer-core/package.json index 10275308..c7c8954b 100644 --- a/packages/puppeteer-core/package.json +++ b/packages/puppeteer-core/package.json @@ -69,8 +69,7 @@ "src/templates/**" ], "output": [ - "src/generated/**", - "src/types.ts" + "src/generated/**" ] }, "build:third_party": { diff --git a/packages/puppeteer-core/src/api/api.ts b/packages/puppeteer-core/src/api/api.ts new file mode 100644 index 00000000..02e10e2a --- /dev/null +++ b/packages/puppeteer-core/src/api/api.ts @@ -0,0 +1,19 @@ +/** + * Copyright 2022 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export * from './Browser.js'; +export * from './BrowserContext.js'; +export * from './Page.js'; diff --git a/packages/puppeteer-core/src/common/AriaQueryHandler.ts b/packages/puppeteer-core/src/common/AriaQueryHandler.ts index 1db69a42..ff1b0821 100644 --- a/packages/puppeteer-core/src/common/AriaQueryHandler.ts +++ b/packages/puppeteer-core/src/common/AriaQueryHandler.ts @@ -15,12 +15,14 @@ */ import {Protocol} from 'devtools-protocol'; + import {assert} from '../util/assert.js'; import {CDPSession} from './Connection.js'; -import {ElementHandle} from './ElementHandle.js'; -import {Frame} from './Frame.js'; -import {MAIN_WORLD, PUPPETEER_WORLD} from './IsolatedWorld.js'; -import {PuppeteerQueryHandler} from './QueryHandler.js'; +import {MAIN_WORLD, PUPPETEER_WORLD} from './IsolatedWorlds.js'; + +import type {ElementHandle} from './ElementHandle.js'; +import type {PuppeteerQueryHandler} from './QueryHandler.js'; +import type {Frame} from './Frame.js'; async function queryAXTree( client: CDPSession, @@ -115,7 +117,7 @@ const waitFor: PuppeteerQueryHandler['waitFor'] = async ( ) => { let frame: Frame; let element: ElementHandle | undefined; - if (elementOrFrame instanceof Frame) { + if ('isOOPFrame' in elementOrFrame) { frame = elementOrFrame; } else { frame = elementOrFrame.frame; @@ -151,11 +153,13 @@ const waitFor: PuppeteerQueryHandler['waitFor'] = async ( if (element) { await element.dispose(); } - if (!(result instanceof ElementHandle)) { + + const handle = result?.asElement(); + if (!handle) { await result?.dispose(); return null; } - return result.frame.worlds[MAIN_WORLD].transferHandle(result); + return handle.frame.worlds[MAIN_WORLD].transferHandle(handle); }; const queryAll: PuppeteerQueryHandler['queryAll'] = async ( diff --git a/packages/puppeteer-core/src/common/Frame.ts b/packages/puppeteer-core/src/common/Frame.ts index 9840fca3..89a31d5b 100644 --- a/packages/puppeteer-core/src/common/Frame.ts +++ b/packages/puppeteer-core/src/common/Frame.ts @@ -26,10 +26,9 @@ import {MouseButton} from './Input.js'; import { IsolatedWorld, IsolatedWorldChart, - MAIN_WORLD, - PUPPETEER_WORLD, WaitForSelectorOptions, } from './IsolatedWorld.js'; +import {MAIN_WORLD, PUPPETEER_WORLD} from './IsolatedWorlds.js'; import {LifecycleWatcher, PuppeteerLifeCycleEvent} from './LifecycleWatcher.js'; import {Page} from '../api/Page.js'; import {getQueryHandlerAndSelector} from './QueryHandler.js'; diff --git a/packages/puppeteer-core/src/common/FrameManager.ts b/packages/puppeteer-core/src/common/FrameManager.ts index 3bf0b2e3..b0c22402 100644 --- a/packages/puppeteer-core/src/common/FrameManager.ts +++ b/packages/puppeteer-core/src/common/FrameManager.ts @@ -22,7 +22,8 @@ import {EventEmitter} from './EventEmitter.js'; import {EVALUATION_SCRIPT_URL, ExecutionContext} from './ExecutionContext.js'; import {Frame} from './Frame.js'; import {FrameTree} from './FrameTree.js'; -import {IsolatedWorld, MAIN_WORLD, PUPPETEER_WORLD} from './IsolatedWorld.js'; +import {IsolatedWorld} from './IsolatedWorld.js'; +import {MAIN_WORLD, PUPPETEER_WORLD} from './IsolatedWorlds.js'; import {NetworkManager} from './NetworkManager.js'; import {Page} from '../api/Page.js'; import {Target} from './Target.js'; diff --git a/packages/puppeteer-core/src/common/IsolatedWorld.ts b/packages/puppeteer-core/src/common/IsolatedWorld.ts index d2aea9af..24806e5c 100644 --- a/packages/puppeteer-core/src/common/IsolatedWorld.ts +++ b/packages/puppeteer-core/src/common/IsolatedWorld.ts @@ -16,12 +16,10 @@ import {Protocol} from 'devtools-protocol'; import {source as injectedSource} from '../generated/injected.js'; -import type PuppeteerUtil from '../injected/injected.js'; import {assert} from '../util/assert.js'; import {createDeferredPromise} from '../util/DeferredPromise.js'; import {isErrorLike} from '../util/ErrorLike.js'; import {CDPSession} from './Connection.js'; -import {ElementHandle} from './ElementHandle.js'; import {ExecutionContext} from './ExecutionContext.js'; import {Frame} from './Frame.js'; import {FrameManager} from './FrameManager.js'; @@ -33,6 +31,10 @@ import {TimeoutSettings} from './TimeoutSettings.js'; import {EvaluateFunc, HandleFor, InnerLazyParams, NodeFor} from './types.js'; import {createJSHandle, debugError, pageBindingInitString} from './util.js'; import {TaskManager, WaitTask} from './WaitTask.js'; +import {MAIN_WORLD, PUPPETEER_WORLD} from './IsolatedWorlds.js'; + +import type PuppeteerUtil from '../injected/injected.js'; +import type {ElementHandle} from './ElementHandle.js'; /** * @public @@ -70,20 +72,6 @@ export interface PageBinding { pptrFunction: Function; } -/** - * A unique key for {@link IsolatedWorldChart} to denote the default world. - * Execution contexts are automatically created in the default world. - * - * @internal - */ -export const MAIN_WORLD = Symbol('mainWorld'); -/** - * A unique key for {@link IsolatedWorldChart} to denote the puppeteer world. - * This world contains all puppeteer-internal bindings/code. - * - * @internal - */ -export const PUPPETEER_WORLD = Symbol('puppeteerWorld'); /** * @internal */ diff --git a/packages/puppeteer-core/src/common/IsolatedWorlds.ts b/packages/puppeteer-core/src/common/IsolatedWorlds.ts new file mode 100644 index 00000000..bf6ee30b --- /dev/null +++ b/packages/puppeteer-core/src/common/IsolatedWorlds.ts @@ -0,0 +1,30 @@ +/** + * Copyright 2022 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * A unique key for {@link IsolatedWorldChart} to denote the default world. + * Execution contexts are automatically created in the default world. + * + * @internal + */ +export const MAIN_WORLD = Symbol('mainWorld'); +/** + * A unique key for {@link IsolatedWorldChart} to denote the puppeteer world. + * This world contains all puppeteer-internal bindings/code. + * + * @internal + */ +export const PUPPETEER_WORLD = Symbol('puppeteerWorld'); diff --git a/packages/puppeteer-core/src/common/Page.ts b/packages/puppeteer-core/src/common/Page.ts index e1fbedcb..34d72fb5 100644 --- a/packages/puppeteer-core/src/common/Page.ts +++ b/packages/puppeteer-core/src/common/Page.ts @@ -57,7 +57,8 @@ import {FrameManager, FrameManagerEmittedEvents} from './FrameManager.js'; import {HTTPRequest} from './HTTPRequest.js'; import {HTTPResponse} from './HTTPResponse.js'; import {Keyboard, Mouse, MouseButton, Touchscreen} from './Input.js'; -import {MAIN_WORLD, WaitForSelectorOptions} from './IsolatedWorld.js'; +import {WaitForSelectorOptions} from './IsolatedWorld.js'; +import {MAIN_WORLD} from './IsolatedWorlds.js'; import {JSHandle} from './JSHandle.js'; import { Credentials, diff --git a/packages/puppeteer-core/src/common/QueryHandler.ts b/packages/puppeteer-core/src/common/QueryHandler.ts index f856afe1..da9a4530 100644 --- a/packages/puppeteer-core/src/common/QueryHandler.ts +++ b/packages/puppeteer-core/src/common/QueryHandler.ts @@ -18,11 +18,8 @@ import PuppeteerUtil from '../injected/injected.js'; import {ariaHandler} from './AriaQueryHandler.js'; import {ElementHandle} from './ElementHandle.js'; import {Frame} from './Frame.js'; -import { - MAIN_WORLD, - PUPPETEER_WORLD, - WaitForSelectorOptions, -} from './IsolatedWorld.js'; +import {WaitForSelectorOptions} from './IsolatedWorld.js'; +import {MAIN_WORLD, PUPPETEER_WORLD} from './IsolatedWorlds.js'; /** * @public diff --git a/packages/puppeteer-core/src/common/bidi/bidi.ts b/packages/puppeteer-core/src/common/bidi/bidi.ts new file mode 100644 index 00000000..3561cf38 --- /dev/null +++ b/packages/puppeteer-core/src/common/bidi/bidi.ts @@ -0,0 +1,20 @@ +/** + * Copyright 2022 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export * from './Browser.js'; +export * from './BrowserContext.js'; +export * from './Page.js'; +export * from './Connection.js'; diff --git a/packages/puppeteer-core/src/common/common.ts b/packages/puppeteer-core/src/common/common.ts new file mode 100644 index 00000000..a8afa1cc --- /dev/null +++ b/packages/puppeteer-core/src/common/common.ts @@ -0,0 +1,69 @@ +/** + * Copyright 2022 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export * from './Accessibility.js'; +export * from './AriaQueryHandler.js'; +export * from './Browser.js'; +export * from './BrowserConnector.js'; +export * from './BrowserWebSocketTransport.js'; +export * from './ChromeTargetManager.js'; +export * from './Configuration.js'; +export * from './Connection.js'; +export * from './ConnectionTransport.js'; +export * from './ConsoleMessage.js'; +export * from './Coverage.js'; +export * from './Debug.js'; +export * from './Device.js'; +export * from './Dialog.js'; +export * from './ElementHandle.js'; +export * from './EmulationManager.js'; +export * from './Errors.js'; +export * from './EventEmitter.js'; +export * from './ExecutionContext.js'; +export * from './fetch.js'; +export * from './FileChooser.js'; +export * from './FirefoxTargetManager.js'; +export * from './Frame.js'; +export * from './FrameManager.js'; +export * from './FrameTree.js'; +export * from './HTTPRequest.js'; +export * from './HTTPResponse.js'; +export * from './Input.js'; +export * from './IsolatedWorld.js'; +export * from './IsolatedWorlds.js'; +export * from './JSHandle.js'; +export * from './LazyArg.js'; +export * from './LifecycleWatcher.js'; +export * from './NetworkEventManager.js'; +export * from './NetworkManager.js'; +export * from './NodeWebSocketTransport.js'; +export * from './Page.js'; +export * from './PDFOptions.js'; +export * from './PredefinedNetworkConditions.js'; +export * from './Product.js'; +export * from './Puppeteer.js'; +export * from './PuppeteerViewport.js'; +export * from './SecurityDetails.js'; +export * from './Target.js'; +export * from './TargetManager.js'; +export * from './TaskQueue.js'; +export * from './TimeoutSettings.js'; +export * from './Tracing.js'; +export * from './types.js'; +export * from './USKeyboardLayout.js'; +export * from './util.js'; +export * from './WaitTask.js'; +export * from './WebWorker.js'; diff --git a/packages/puppeteer-core/src/node/PuppeteerNode.ts b/packages/puppeteer-core/src/node/PuppeteerNode.ts index 8f5512ed..4ab74aca 100644 --- a/packages/puppeteer-core/src/node/PuppeteerNode.ts +++ b/packages/puppeteer-core/src/node/PuppeteerNode.ts @@ -279,12 +279,13 @@ export class PuppeteerNode extends Puppeteer { } /** - * @deprecated If you are using `puppeteer-core`, do not use this method. Just - * construct {@link BrowserFetcher} manually. - * * @param options - Set of configurable options to specify the settings of the * BrowserFetcher. * + * @remarks + * If you are using `puppeteer-core`, do not use this method. Just + * construct {@link BrowserFetcher} manually. + * * @returns A new BrowserFetcher instance. */ createBrowserFetcher( diff --git a/packages/puppeteer-core/src/node/node.ts b/packages/puppeteer-core/src/node/node.ts new file mode 100644 index 00000000..ba20a800 --- /dev/null +++ b/packages/puppeteer-core/src/node/node.ts @@ -0,0 +1,24 @@ +/** + * Copyright 2022 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export * from './BrowserFetcher.js'; +export * from './BrowserRunner.js'; +export * from './ChromeLauncher.js'; +export * from './FirefoxLauncher.js'; +export * from './LaunchOptions.js'; +export * from './PipeTransport.js'; +export * from './ProductLauncher.js'; +export * from './PuppeteerNode.js'; diff --git a/packages/puppeteer-core/src/puppeteer-core.ts b/packages/puppeteer-core/src/puppeteer-core.ts index e73b0e51..c6cc6d34 100644 --- a/packages/puppeteer-core/src/puppeteer-core.ts +++ b/packages/puppeteer-core/src/puppeteer-core.ts @@ -15,15 +15,17 @@ */ export {Protocol} from 'devtools-protocol'; -export * from './common/Device.js'; -export * from './common/Errors.js'; -export * from './common/PredefinedNetworkConditions.js'; -export * from './common/Puppeteer.js'; + +export * from './api/api.js'; +export * from './common/common.js'; +export * from './node/node.js'; +export * from './revisions.js'; +export * from './util/util.js'; + /** * @deprecated Use the query handler API defined on {@link Puppeteer} */ export * from './common/QueryHandler.js'; -export * from './node/BrowserFetcher.js'; import {PuppeteerNode} from './node/PuppeteerNode.js'; @@ -36,11 +38,6 @@ const puppeteer = new PuppeteerNode({ export const { connect, - /** - * @deprecated Construct {@link BrowserFetcher} manually. - * - * @public - */ createBrowserFetcher, defaultArgs, executablePath, diff --git a/packages/puppeteer-core/src/types.ts b/packages/puppeteer-core/src/types.ts deleted file mode 100644 index 089cc0ec..00000000 --- a/packages/puppeteer-core/src/types.ts +++ /dev/null @@ -1,75 +0,0 @@ -// AUTOGENERATED - Use `npm run generate:sources` to regenerate. - -export * from './api/Browser.js'; -export * from './api/BrowserContext.js'; -export * from './api/Page.js'; -export * from './common/Accessibility.js'; -export * from './common/AriaQueryHandler.js'; -export * from './common/Browser.js'; -export * from './common/BrowserConnector.js'; -export * from './common/BrowserWebSocketTransport.js'; -export * from './common/ChromeTargetManager.js'; -export * from './common/Configuration.js'; -export * from './common/Connection.js'; -export * from './common/ConnectionTransport.js'; -export * from './common/ConsoleMessage.js'; -export * from './common/Coverage.js'; -export * from './common/Debug.js'; -export * from './common/Device.js'; -export * from './common/Dialog.js'; -export * from './common/ElementHandle.js'; -export * from './common/EmulationManager.js'; -export * from './common/Errors.js'; -export * from './common/EventEmitter.js'; -export * from './common/ExecutionContext.js'; -export * from './common/fetch.js'; -export * from './common/FileChooser.js'; -export * from './common/FirefoxTargetManager.js'; -export * from './common/Frame.js'; -export * from './common/FrameManager.js'; -export * from './common/FrameTree.js'; -export * from './common/HTTPRequest.js'; -export * from './common/HTTPResponse.js'; -export * from './common/Input.js'; -export * from './common/IsolatedWorld.js'; -export * from './common/JSHandle.js'; -export * from './common/LazyArg.js'; -export * from './common/LifecycleWatcher.js'; -export * from './common/NetworkEventManager.js'; -export * from './common/NetworkManager.js'; -export * from './common/NodeWebSocketTransport.js'; -export * from './common/Page.js'; -export * from './common/PDFOptions.js'; -export * from './common/PredefinedNetworkConditions.js'; -export * from './common/Product.js'; -export * from './common/Puppeteer.js'; -export * from './common/PuppeteerViewport.js'; -export * from './common/QueryHandler.js'; -export * from './common/SecurityDetails.js'; -export * from './common/Target.js'; -export * from './common/TargetManager.js'; -export * from './common/TaskQueue.js'; -export * from './common/TimeoutSettings.js'; -export * from './common/Tracing.js'; -export * from './common/types.js'; -export * from './common/USKeyboardLayout.js'; -export * from './common/util.js'; -export * from './common/WaitTask.js'; -export * from './common/WebWorker.js'; -export * from './environment.js'; -export * from './generated/injected.js'; -export * from './generated/version.js'; -export * from './node/BrowserFetcher.js'; -export * from './node/BrowserRunner.js'; -export * from './node/ChromeLauncher.js'; -export * from './node/FirefoxLauncher.js'; -export * from './node/LaunchOptions.js'; -export * from './node/PipeTransport.js'; -export * from './node/ProductLauncher.js'; -export * from './node/PuppeteerNode.js'; -export * from './puppeteer-core.js'; -export * from './revisions.js'; -export * from './util/assert.js'; -export * from './util/DebuggableDeferredPromise.js'; -export * from './util/DeferredPromise.js'; -export * from './util/ErrorLike.js'; diff --git a/packages/puppeteer-core/src/util/util.ts b/packages/puppeteer-core/src/util/util.ts new file mode 100644 index 00000000..be9cc7fe --- /dev/null +++ b/packages/puppeteer-core/src/util/util.ts @@ -0,0 +1,20 @@ +/** + * Copyright 2022 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export * from './assert.js'; +export * from './DebuggableDeferredPromise.js'; +export * from './DeferredPromise.js'; +export * from './ErrorLike.js'; diff --git a/packages/puppeteer-core/tools/generate_sources.ts b/packages/puppeteer-core/tools/generate_sources.ts index 3cacf026..46975d4f 100644 --- a/packages/puppeteer-core/tools/generate_sources.ts +++ b/packages/puppeteer-core/tools/generate_sources.ts @@ -1,7 +1,6 @@ #!/usr/bin/env node import esbuild from 'esbuild'; import {mkdir, mkdtemp, readFile, rm, writeFile} from 'fs/promises'; -import {sync as glob} from 'glob'; import path, {join, resolve} from 'path'; import {chdir} from 'process'; import {job} from '../../../tools/internal/job.js'; @@ -9,8 +8,6 @@ import {job} from '../../../tools/internal/job.js'; const packageRoot = resolve(join(__dirname, '..')); chdir(packageRoot); -const INCLUDED_FOLDERS = ['common', 'generated', 'node', 'util', 'api']; - (async () => { await job('', async ({outputs}) => { await Promise.all( @@ -70,22 +67,6 @@ const INCLUDED_FOLDERS = ['common', 'generated', 'node', 'util', 'api']; await Promise.all([versionJob, injectedJob]); - const sources = glob( - `src/{@(${INCLUDED_FOLDERS.join('|')})/*.ts,!(types).ts}` - ); - await job('', async ({outputs}) => { - let types = - '// AUTOGENERATED - Use `npm run generate:sources` to regenerate.\n\n'; - for (const input of sources.map(source => { - return `.${source.slice(3)}`; - })) { - types += `export * from '${input.replace('.ts', '.js')}';\n`; - } - await writeFile(outputs[0]!, types); - }) - .outputs(['src/types.ts']) - .build(); - if (process.env['PUBLISH']) { job('', async ({inputs}) => { const version = JSON.parse(await readFile(inputs[0]!, 'utf8')).version; diff --git a/packages/puppeteer/api-extractor.json b/packages/puppeteer/api-extractor.json index 0e8fa60d..2a104692 100644 --- a/packages/puppeteer/api-extractor.json +++ b/packages/puppeteer/api-extractor.json @@ -1,6 +1,6 @@ { "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", - "mainEntryPointFilePath": "/lib/esm/puppeteer/types.d.ts", + "mainEntryPointFilePath": "/lib/esm/puppeteer/puppeteer.d.ts", "bundledPackages": ["puppeteer-core"], "apiReport": { diff --git a/packages/puppeteer/package.json b/packages/puppeteer/package.json index 87a48b9d..3d8071f2 100644 --- a/packages/puppeteer/package.json +++ b/packages/puppeteer/package.json @@ -60,18 +60,6 @@ "generate:package-json" ] }, - "generate:sources": { - "command": "tsx tools/generate_sources.ts", - "dependencies": [ - "../puppeteer-core:build" - ], - "files": [ - "tools/generate_sources.ts" - ], - "output": [ - "src/types.ts" - ] - }, "generate:package-json": { "command": "echo '{\"type\": \"module\"}' > lib/esm/package.json", "clean": "if-file-deleted", @@ -114,8 +102,7 @@ "command": "tsc -b", "clean": "if-file-deleted", "dependencies": [ - "../puppeteer-core:build", - "generate:sources" + "../puppeteer-core:build" ], "files": [ "src/**", diff --git a/packages/puppeteer/src/puppeteer.ts b/packages/puppeteer/src/puppeteer.ts index 3c377abc..32136d5a 100644 --- a/packages/puppeteer/src/puppeteer.ts +++ b/packages/puppeteer/src/puppeteer.ts @@ -15,16 +15,8 @@ */ export {Protocol} from 'devtools-protocol'; -export * from 'puppeteer-core/internal/common/Device.js'; -export * from 'puppeteer-core/internal/common/Errors.js'; -export * from 'puppeteer-core/internal/common/PredefinedNetworkConditions.js'; -export * from 'puppeteer-core/internal/common/Puppeteer.js'; -/** - * @deprecated Use the query handler API defined on {@link Puppeteer} - */ -export * from 'puppeteer-core/internal/common/QueryHandler.js'; -export * from 'puppeteer-core/internal/node/BrowserFetcher.js'; -export {LaunchOptions} from 'puppeteer-core/internal/node/LaunchOptions.js'; + +export * from 'puppeteer-core/internal/puppeteer-core.js'; import {PuppeteerNode} from 'puppeteer-core/internal/node/PuppeteerNode.js'; import {getConfiguration} from './getConfiguration.js'; diff --git a/packages/puppeteer/src/types.ts b/packages/puppeteer/src/types.ts deleted file mode 100644 index 3bb1ff15..00000000 --- a/packages/puppeteer/src/types.ts +++ /dev/null @@ -1,76 +0,0 @@ -// AUTOGENERATED - Use `npm run generate:sources` to regenerate. - -export * from 'puppeteer-core/internal/api/Browser.js'; -export * from 'puppeteer-core/internal/api/BrowserContext.js'; -export * from 'puppeteer-core/internal/api/Page.js'; -export * from 'puppeteer-core/internal/common/Accessibility.js'; -export * from 'puppeteer-core/internal/common/AriaQueryHandler.js'; -export * from 'puppeteer-core/internal/common/Browser.js'; -export * from 'puppeteer-core/internal/common/BrowserConnector.js'; -export * from 'puppeteer-core/internal/common/BrowserWebSocketTransport.js'; -export * from 'puppeteer-core/internal/common/ChromeTargetManager.js'; -export * from 'puppeteer-core/internal/common/Configuration.js'; -export * from 'puppeteer-core/internal/common/Connection.js'; -export * from 'puppeteer-core/internal/common/ConnectionTransport.js'; -export * from 'puppeteer-core/internal/common/ConsoleMessage.js'; -export * from 'puppeteer-core/internal/common/Coverage.js'; -export * from 'puppeteer-core/internal/common/Debug.js'; -export * from 'puppeteer-core/internal/common/Device.js'; -export * from 'puppeteer-core/internal/common/Dialog.js'; -export * from 'puppeteer-core/internal/common/ElementHandle.js'; -export * from 'puppeteer-core/internal/common/EmulationManager.js'; -export * from 'puppeteer-core/internal/common/Errors.js'; -export * from 'puppeteer-core/internal/common/EventEmitter.js'; -export * from 'puppeteer-core/internal/common/ExecutionContext.js'; -export * from 'puppeteer-core/internal/common/fetch.js'; -export * from 'puppeteer-core/internal/common/FileChooser.js'; -export * from 'puppeteer-core/internal/common/FirefoxTargetManager.js'; -export * from 'puppeteer-core/internal/common/Frame.js'; -export * from 'puppeteer-core/internal/common/FrameManager.js'; -export * from 'puppeteer-core/internal/common/FrameTree.js'; -export * from 'puppeteer-core/internal/common/HTTPRequest.js'; -export * from 'puppeteer-core/internal/common/HTTPResponse.js'; -export * from 'puppeteer-core/internal/common/Input.js'; -export * from 'puppeteer-core/internal/common/IsolatedWorld.js'; -export * from 'puppeteer-core/internal/common/JSHandle.js'; -export * from 'puppeteer-core/internal/common/LazyArg.js'; -export * from 'puppeteer-core/internal/common/LifecycleWatcher.js'; -export * from 'puppeteer-core/internal/common/NetworkEventManager.js'; -export * from 'puppeteer-core/internal/common/NetworkManager.js'; -export * from 'puppeteer-core/internal/common/NodeWebSocketTransport.js'; -export * from 'puppeteer-core/internal/common/Page.js'; -export * from 'puppeteer-core/internal/common/PDFOptions.js'; -export * from 'puppeteer-core/internal/common/PredefinedNetworkConditions.js'; -export * from 'puppeteer-core/internal/common/Product.js'; -export * from 'puppeteer-core/internal/common/Puppeteer.js'; -export * from 'puppeteer-core/internal/common/PuppeteerViewport.js'; -export * from 'puppeteer-core/internal/common/QueryHandler.js'; -export * from 'puppeteer-core/internal/common/SecurityDetails.js'; -export * from 'puppeteer-core/internal/common/Target.js'; -export * from 'puppeteer-core/internal/common/TargetManager.js'; -export * from 'puppeteer-core/internal/common/TaskQueue.js'; -export * from 'puppeteer-core/internal/common/TimeoutSettings.js'; -export * from 'puppeteer-core/internal/common/Tracing.js'; -export * from 'puppeteer-core/internal/common/types.js'; -export * from 'puppeteer-core/internal/common/USKeyboardLayout.js'; -export * from 'puppeteer-core/internal/common/util.js'; -export * from 'puppeteer-core/internal/common/WaitTask.js'; -export * from 'puppeteer-core/internal/common/WebWorker.js'; -export * from 'puppeteer-core/internal/environment.js'; -export * from 'puppeteer-core/internal/generated/injected.js'; -export * from 'puppeteer-core/internal/generated/version.js'; -export * from 'puppeteer-core/internal/node/BrowserFetcher.js'; -export * from 'puppeteer-core/internal/node/BrowserRunner.js'; -export * from 'puppeteer-core/internal/node/ChromeLauncher.js'; -export * from 'puppeteer-core/internal/node/FirefoxLauncher.js'; -export * from 'puppeteer-core/internal/node/LaunchOptions.js'; -export * from 'puppeteer-core/internal/node/PipeTransport.js'; -export * from 'puppeteer-core/internal/node/ProductLauncher.js'; -export * from 'puppeteer-core/internal/node/PuppeteerNode.js'; -export * from 'puppeteer-core/internal/revisions.js'; -export * from 'puppeteer-core/internal/util/assert.js'; -export * from 'puppeteer-core/internal/util/DebuggableDeferredPromise.js'; -export * from 'puppeteer-core/internal/util/DeferredPromise.js'; -export * from 'puppeteer-core/internal/util/ErrorLike.js'; -export * from './getConfiguration.js'; -export * from './puppeteer.js'; diff --git a/packages/puppeteer/tools/generate_sources.ts b/packages/puppeteer/tools/generate_sources.ts deleted file mode 100644 index e2b2dad2..00000000 --- a/packages/puppeteer/tools/generate_sources.ts +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Copyright 2022 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {readFile, writeFile} from 'fs/promises'; -import {sync as glob} from 'glob'; -import {join} from 'path'; - -const INCLUDED_FOLDERS = []; - -const puppeteerTypes = join(__dirname, '..', 'src', 'types.ts'); -const puppeteerCoreTypes = join( - __dirname, - '..', - '..', - 'puppeteer-core', - 'src', - 'types.ts' -); - -(async () => { - let content = await readFile(puppeteerCoreTypes, 'utf-8'); - content = content.replace(/\.\//g, 'puppeteer-core/internal/'); - content = content.replace( - "export * from 'puppeteer-core/internal/puppeteer-core.js';\n", - '' - ); - - const sources = glob( - `src/{@(${INCLUDED_FOLDERS.join('|')})/*.ts,!(types).ts}`, - {cwd: join(__dirname, '..')} - ); - for (const input of sources.map(source => { - return `.${source.slice(3)}`; - })) { - content += `export * from '${input.replace('.ts', '.js')}';\n`; - } - - await writeFile(puppeteerTypes, content); -})(); diff --git a/test/src/injected.spec.ts b/test/src/injected.spec.ts index 16503880..cde47fcc 100644 --- a/test/src/injected.spec.ts +++ b/test/src/injected.spec.ts @@ -15,7 +15,7 @@ */ import expect from 'expect'; -import {PUPPETEER_WORLD} from 'puppeteer-core/internal/common/IsolatedWorld.js'; +import {PUPPETEER_WORLD} from 'puppeteer-core/internal/common/IsolatedWorlds.js'; import { getTestState, setupTestBrowserHooks,