Skip to content

Commit

Permalink
feat: export public types only
Browse files Browse the repository at this point in the history
  • Loading branch information
jrandolf committed Jun 27, 2022
1 parent f2e9cbb commit a56eec9
Show file tree
Hide file tree
Showing 46 changed files with 534 additions and 524 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Expand Up @@ -5,4 +5,4 @@ doclint/
lib/
test-ts-types/
tsconfig.tsbuildinfo
vendor/
vendor/
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -13,6 +13,7 @@ docs/api.html
lib/
node_modules/
package-lock.json
puppeteer.api.json
puppeteer*.tgz
test-ts-types/**/dist/
test-ts-types/**/node_modules
Expand Down
7 changes: 4 additions & 3 deletions api-extractor.json
@@ -1,6 +1,6 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"mainEntryPointFilePath": "<projectFolder>/lib/cjs/puppeteer/api-docs-entry.d.ts",
"mainEntryPointFilePath": "<projectFolder>/lib/esm/puppeteer/types.d.ts",
"bundledPackages": [],

"apiReport": {
Expand All @@ -9,12 +9,13 @@

"docModel": {
"enabled": true,
"apiJsonFilePath": "<projectFolder>/docs-api-json/<unscopedPackageName>.api.json"
"apiJsonFilePath": "<projectFolder>/docs/<unscopedPackageName>.api.json"
},

"dtsRollup": {
"enabled": true,
"untrimmedFilePath": "lib/types.d.ts"
"untrimmedFilePath": "",
"publicTrimmedFilePath": "lib/types.d.ts"
},

"tsdocMetadata": {
Expand Down
3 changes: 3 additions & 0 deletions compat/cjs/compat.ts
@@ -1,5 +1,8 @@
import {dirname} from 'path';

/**
* @internal
*/
let puppeteerDirname: string;

try {
Expand Down
3 changes: 3 additions & 0 deletions compat/esm/compat.ts
Expand Up @@ -4,6 +4,9 @@ import {fileURLToPath} from 'url';

const require = createRequire(import.meta.url);

/**
* @internal
*/
let puppeteerDirname: string;

try {
Expand Down
152 changes: 0 additions & 152 deletions src/api-docs-entry.ts

This file was deleted.

3 changes: 3 additions & 0 deletions src/common/BrowserWebSocketTransport.ts
Expand Up @@ -15,6 +15,9 @@
*/
import {ConnectionTransport} from './ConnectionTransport.js';

/**
* @internal
*/
export class BrowserWebSocketTransport implements ConnectionTransport {
static create(url: string): Promise<BrowserWebSocketTransport> {
return new Promise((resolve, reject) => {
Expand Down
4 changes: 2 additions & 2 deletions src/common/DOMWorld.ts
Expand Up @@ -24,7 +24,7 @@ import {Frame, FrameManager} from './FrameManager.js';
import {MouseButton} from './Input.js';
import {JSHandle} from './JSHandle.js';
import {LifecycleWatcher, PuppeteerLifeCycleEvent} from './LifecycleWatcher.js';
import {_getQueryHandlerAndSelector} from './QueryHandler.js';
import {getQueryHandlerAndSelector} from './QueryHandler.js';
import {TimeoutSettings} from './TimeoutSettings.js';
import {EvaluateFunc, HandleFor} from './types.js';
import {
Expand Down Expand Up @@ -653,7 +653,7 @@ export class DOMWorld {
options: WaitForSelectorOptions
): Promise<ElementHandle | null> {
const {updatedSelector, queryHandler} =
_getQueryHandlerAndSelector(selector);
getQueryHandlerAndSelector(selector);
assert(queryHandler.waitFor, 'Query handler does not support waiting');
return queryHandler.waitFor(this, updatedSelector, options);
}
Expand Down
9 changes: 5 additions & 4 deletions src/common/Debug.ts
Expand Up @@ -25,14 +25,10 @@ declare global {
* A debug function that can be used in any environment.
*
* @remarks
*
* If used in Node, it falls back to the
* {@link https://www.npmjs.com/package/debug | debug module}. In the browser it
* uses `console.log`.
*
* @param prefix - this will be prefixed to each log.
* @returns a function that can be called to log to that debug channel.
*
* In Node, use the `DEBUG` environment variable to control logging:
*
* ```
Expand All @@ -56,6 +52,11 @@ declare global {
* log('new page created')
* // logs "Page: new page created"
* ```
*
* @param prefix - this will be prefixed to each log.
* @returns a function that can be called to log to that debug channel.
*
* @internal
*/
export const debug = (prefix: string): ((...args: unknown[]) => void) => {
if (isNode) {
Expand Down
30 changes: 25 additions & 5 deletions src/common/DeviceDescriptors.ts
Expand Up @@ -30,7 +30,7 @@ export interface Device {
};
}

const devices: Device[] = [
const deviceArray: Device[] = [
{
name: 'Blackberry PlayBook',
userAgent:
Expand Down Expand Up @@ -1536,10 +1536,30 @@ export type DevicesMap = {
};

/**
* @internal
* A list of devices to be used with `page.emulate(options)`. Actual list of devices can be found in {@link https://github.com/puppeteer/puppeteer/blob/main/src/common/DeviceDescriptors.ts | src/common/DeviceDescriptors.ts}.
*
* @example
*
* ```js
* const puppeteer = require('puppeteer');
* const iPhone = puppeteer.devices['iPhone 6'];
*
* (async () => {
* const browser = await puppeteer.launch();
* const page = await browser.newPage();
* await page.emulate(iPhone);
* await page.goto('https://www.google.com');
* // other actions...
* await browser.close();
* })();
* ```
*
* @public
*/
export const _devicesMap: DevicesMap = {};
const devices: DevicesMap = {};

for (const device of devices) {
_devicesMap[device.name] = device;
for (const device of deviceArray) {
devices[device.name] = device;
}

export {devices};
22 changes: 17 additions & 5 deletions src/common/ElementHandle.ts
Expand Up @@ -8,14 +8,13 @@ import {
BoundingBox,
BoxModel,
ClickOptions,
computeQuadArea,
JSHandle,
Offset,
Point,
PressOptions,
} from './JSHandle.js';
import {Page, ScreenshotOptions} from './Page.js';
import {_getQueryHandlerAndSelector} from './QueryHandler.js';
import {getQueryHandlerAndSelector} from './QueryHandler.js';
import {EvaluateFunc} from './types.js';
import {KeyInput} from './USKeyboardLayout.js';
import {debugError, isString} from './util.js';
Expand Down Expand Up @@ -841,7 +840,7 @@ export class ElementHandle<
async $(selector: string): Promise<ElementHandle | null>;
async $(selector: string): Promise<ElementHandle | null> {
const {updatedSelector, queryHandler} =
_getQueryHandlerAndSelector(selector);
getQueryHandlerAndSelector(selector);
assert(
queryHandler.queryOne,
'Cannot handle queries for a single element with the given selector'
Expand All @@ -866,7 +865,7 @@ export class ElementHandle<
async $$(selector: string): Promise<ElementHandle[]>;
async $$(selector: string): Promise<ElementHandle[]> {
const {updatedSelector, queryHandler} =
_getQueryHandlerAndSelector(selector);
getQueryHandlerAndSelector(selector);
assert(
queryHandler.queryAll,
'Cannot handle queries for a multiple element with the given selector'
Expand Down Expand Up @@ -986,7 +985,7 @@ export class ElementHandle<
...args: Params
): Promise<Awaited<ReturnType<Func>>> {
const {updatedSelector, queryHandler} =
_getQueryHandlerAndSelector(selector);
getQueryHandlerAndSelector(selector);
assert(queryHandler.queryAllArray);
const arrayHandle = await queryHandler.queryAllArray(this, updatedSelector);
const result = await arrayHandle.evaluate(pageFunction, ...args);
Expand Down Expand Up @@ -1046,3 +1045,16 @@ export class ElementHandle<
}, threshold);
}
}

function computeQuadArea(quad: Point[]): number {
/* Compute sum of all directed areas of adjacent triangles
https://en.wikipedia.org/wiki/Polygon#Simple_polygons
*/
let area = 0;
for (let i = 0; i < quad.length; ++i) {
const p1 = quad[i]!;
const p2 = quad[(i + 1) % quad.length]!;
area += (p1.x * p2.y - p2.x * p1.y) / 2;
}
return Math.abs(area);
}
3 changes: 3 additions & 0 deletions src/common/EmulationManager.ts
Expand Up @@ -17,6 +17,9 @@ import {CDPSession} from './Connection.js';
import {Viewport} from './PuppeteerViewport.js';
import {Protocol} from 'devtools-protocol';

/**
* @internal
*/
export class EmulationManager {
#client: CDPSession;
#emulatingMobile = false;
Expand Down

0 comments on commit a56eec9

Please sign in to comment.