Skip to content

Commit

Permalink
chore: Introduce API Extractor and start generating documentation (#5967
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jackfranklin committed Jun 4, 2020
1 parent ef63c64 commit 0032420
Show file tree
Hide file tree
Showing 16 changed files with 128 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ yarn.lock
/utils/browser/puppeteer-web.js
/lib
test/coverage.json
temp/
42 changes: 42 additions & 0 deletions api-extractor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"mainEntryPointFilePath": "<projectFolder>/lib/api-docs-entry.d.ts",
"bundledPackages": [ ],

"apiReport": {
"enabled": false
},

"docModel": {
"enabled": true
},

"dtsRollup": {
"enabled": false
},

"tsdocMetadata": {
"enabled": false
},

"messages": {
"compilerMessageReporting": {
"default": {
"logLevel": "warning"
}
},

"extractorMessageReporting": {
"default": {
"logLevel": "warning"
}
},

"tsdocMessageReporting": {
"default": {
"logLevel": "warning"
}
}
}

}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"apply-next-version": "node utils/apply_next_version.js",
"update-protocol-d-ts": "node utils/protocol-types-generator update",
"compare-protocol-d-ts": "node utils/protocol-types-generator compare",
"test-install": "scripts/test-install.sh"
"test-install": "scripts/test-install.sh",
"generate-docs": "npm run tsc && api-extractor run --local --verbose && api-documenter markdown -i temp -o new-docs"
},
"files": [
"lib/",
Expand All @@ -56,6 +57,8 @@
"ws": "^7.2.3"
},
"devDependencies": {
"@microsoft/api-documenter": "^7.8.8",
"@microsoft/api-extractor": "^7.8.8",
"@types/debug": "0.0.31",
"@types/mime": "^2.0.0",
"@types/node": "^10.17.14",
Expand Down
2 changes: 1 addition & 1 deletion src/Browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Protocol from './protocol';
import { Connection } from './Connection';
import { Page } from './Page';
import { ChildProcess } from 'child_process';
import type { Viewport } from './PuppeteerViewport';
import { Viewport } from './PuppeteerViewport';

type BrowserCloseCallback = () => Promise<void> | void;

Expand Down
2 changes: 1 addition & 1 deletion src/Connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import * as debug from 'debug';
const debugProtocol = debug('puppeteer:protocol');

import Protocol from './protocol';
import type { ConnectionTransport } from './ConnectionTransport';
import { ConnectionTransport } from './ConnectionTransport';
import * as EventEmitter from 'events';

interface ConnectionCallback {
Expand Down
2 changes: 1 addition & 1 deletion src/EmulationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/
import { CDPSession } from './Connection';
import type { Viewport } from './PuppeteerViewport';
import { Viewport } from './PuppeteerViewport';
import Protocol from './protocol';

export class EmulationManager {
Expand Down
4 changes: 2 additions & 2 deletions src/Launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ import { BrowserFetcher } from './BrowserFetcher';
import { Connection } from './Connection';
import { Browser } from './Browser';
import { helper, assert, debugError } from './helper';
import type { ConnectionTransport } from './ConnectionTransport';
import { ConnectionTransport } from './ConnectionTransport';
import { WebSocketTransport } from './WebSocketTransport';
import { BrowserRunner } from './launcher/BrowserRunner';

const mkdtempAsync = helper.promisify(fs.mkdtemp);
const writeFileAsync = helper.promisify(fs.writeFile);

import type {
import {
ChromeArgOptions,
LaunchOptions,
BrowserOptions,
Expand Down
2 changes: 1 addition & 1 deletion src/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { WebWorker } from './WebWorker';
import { Browser, BrowserContext } from './Browser';
import { Target } from './Target';
import { createJSHandle, JSHandle, ElementHandle } from './JSHandle';
import type { Viewport } from './PuppeteerViewport';
import { Viewport } from './PuppeteerViewport';
import { Credentials } from './NetworkManager';
import { HTTPRequest } from './HTTPRequest';
import { HTTPResponse } from './HTTPResponse';
Expand Down
2 changes: 1 addition & 1 deletion src/PipeTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/
import { helper, debugError, PuppeteerEventListener } from './helper';
import type { ConnectionTransport } from './ConnectionTransport';
import { ConnectionTransport } from './ConnectionTransport';

export class PipeTransport implements ConnectionTransport {
_pipeWrite: NodeJS.WritableStream;
Expand Down
32 changes: 21 additions & 11 deletions src/Puppeteer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,31 @@
* limitations under the License.
*/
import Launcher from './Launcher';
import type {
import {
LaunchOptions,
ChromeArgOptions,
BrowserOptions,
} from './launcher/LaunchOptions';
import type { ProductLauncher } from './Launcher';
import { ProductLauncher } from './Launcher';
import { BrowserFetcher, BrowserFetcherOptions } from './BrowserFetcher';
import { puppeteerErrors, PuppeteerErrors } from './Errors';
import type { ConnectionTransport } from './ConnectionTransport';
import { ConnectionTransport } from './ConnectionTransport';

import { devicesMap } from './DeviceDescriptors';
import type { DevicesMap } from './/DeviceDescriptors';
import { DevicesMap } from './/DeviceDescriptors';
import { Browser } from './Browser';
import * as QueryHandler from './QueryHandler';
import {
registerCustomQueryHandler,
unregisterCustomQueryHandler,
customQueryHandlers,
clearQueryHandlers,
QueryHandler,
} from './QueryHandler';

/**
* The main Puppeteer class
* @public
*/
export class Puppeteer {
_projectRoot: string;
_preferredRevision: string;
Expand Down Expand Up @@ -135,23 +145,23 @@ export class Puppeteer {
// eslint-disable-next-line @typescript-eslint/camelcase
__experimental_registerCustomQueryHandler(
name: string,
queryHandler: QueryHandler.QueryHandler
queryHandler: QueryHandler
): void {
QueryHandler.registerCustomQueryHandler(name, queryHandler);
registerCustomQueryHandler(name, queryHandler);
}

// eslint-disable-next-line @typescript-eslint/camelcase
__experimental_unregisterCustomQueryHandler(name: string): void {
QueryHandler.unregisterCustomQueryHandler(name);
unregisterCustomQueryHandler(name);
}

// eslint-disable-next-line @typescript-eslint/camelcase
__experimental_customQueryHandlers(): Map<string, QueryHandler.QueryHandler> {
return QueryHandler.customQueryHandlers();
__experimental_customQueryHandlers(): Map<string, QueryHandler> {
return customQueryHandlers();
}

// eslint-disable-next-line @typescript-eslint/camelcase
__experimental_clearQueryHandlers(): void {
QueryHandler.clearQueryHandlers();
clearQueryHandlers();
}
}
8 changes: 0 additions & 8 deletions src/QueryHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,3 @@ export function getQueryHandlerAndSelector(
queryHandler,
};
}

module.exports = {
registerCustomQueryHandler,
unregisterCustomQueryHandler,
customQueryHandlers,
getQueryHandlerAndSelector,
clearQueryHandlers,
};
2 changes: 1 addition & 1 deletion src/Target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { Page } from './Page';
import { WebWorker } from './WebWorker';
import { CDPSession } from './Connection';
import { Browser, BrowserContext } from './Browser';
import type { Viewport } from './PuppeteerViewport';
import { Viewport } from './PuppeteerViewport';
import Protocol from './protocol';

export class Target {
Expand Down
2 changes: 1 addition & 1 deletion src/WebSocketTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/
import * as NodeWebSocket from 'ws';
import type { ConnectionTransport } from './ConnectionTransport';
import { ConnectionTransport } from './ConnectionTransport';

export class WebSocketTransport implements ConnectionTransport {
static create(url: string): Promise<WebSocketTransport> {
Expand Down
47 changes: 47 additions & 0 deletions src/api-docs-entry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Copyright 2020 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.
*/

/*
* This file re-exports any APIs that we want to have documentation generated for.
* It is used by API Extractor to determine what parts of the system to document.
*
* We also have src/api.ts. This is used in `index.js` and by the legacy DocLint system.
* src/api-docs-entry.ts is ONLY used by API Extractor.
*
* Once we have migrated to API Extractor and removed DocLint we can remove the duplication and use this file.
*/
export * from './Accessibility';
export * from './Browser';
export * from './BrowserFetcher';
export * from './Connection';
export * from './ConsoleMessage';
export * from './Coverage';
export * from './Dialog';
export * from './JSHandle';
export * from './ExecutionContext';
export * from './FileChooser';
export * from './FrameManager';
export * from './JSHandle';
export * from './Input';
export * from './Page';
export * from './Puppeteer';
export * from './HTTPRequest';
export * from './HTTPResponse';
export * from './SecurityDetails';
export * from './Target';
export * from './Errors';
export * from './Tracing';
export * from './WebWorker';
2 changes: 1 addition & 1 deletion src/launcher/BrowserRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import * as debug from 'debug';
import * as removeFolder from 'rimraf';
import * as childProcess from 'child_process';
import { helper, assert, debugError } from '../helper';
import type { LaunchOptions } from './LaunchOptions';
import { LaunchOptions } from './LaunchOptions';
import { Connection } from '../Connection';
import { WebSocketTransport } from '../WebSocketTransport';
import { PipeTransport } from '../PipeTransport';
Expand Down
4 changes: 3 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"outDir": "./lib",
"target": "ESNext",
"moduleResolution": "node",
"module": "CommonJS"
"module": "CommonJS",
"declaration": true,
"declarationMap": true
},
"include": [
"src"
Expand Down

0 comments on commit 0032420

Please sign in to comment.