Skip to content

Commit

Permalink
chore: create node directory for Node-only files
Browse files Browse the repository at this point in the history
This is another step towards making Puppeteer agnostic of environment
and being able to run in Node or a browser.

The files in the `node` directory are ones that would only be needed in
the Node build - e.g. the code that downloads and launches a local
browser instance.

The long term vision here is to have three folders:

* node - Node only code
* web - Web only code
* common - code that is shared

But rather than do that in one PR I'm going to split it up to make it
easier to review and deal with.
  • Loading branch information
jackfranklin committed Jun 18, 2020
1 parent 44402b7 commit 7bb2bf1
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 22 deletions.
1 change: 0 additions & 1 deletion src/Browser.ts
Expand Up @@ -54,7 +54,6 @@ export class Browser extends EventEmitter {
_closeCallback: BrowserCloseCallback;
_defaultContext: BrowserContext;
_contexts: Map<string, BrowserContext>;
// TODO: once Target is in TypeScript we can type this properly.
_targets: Map<string, Target>;

constructor(
Expand Down
8 changes: 4 additions & 4 deletions src/Puppeteer.ts
Expand Up @@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import Launcher from './Launcher';
import Launcher from './node/Launcher';
import {
LaunchOptions,
ChromeArgOptions,
BrowserOptions,
} from './launcher/LaunchOptions';
import { ProductLauncher } from './Launcher';
import { BrowserFetcher, BrowserFetcherOptions } from './BrowserFetcher';
} from './node/LaunchOptions';
import { ProductLauncher } from './node/Launcher';
import { BrowserFetcher, BrowserFetcherOptions } from './node/BrowserFetcher';
import { puppeteerErrors, PuppeteerErrors } from './Errors';
import { ConnectionTransport } from './ConnectionTransport';

Expand Down
2 changes: 1 addition & 1 deletion src/api-docs-entry.ts
Expand Up @@ -25,7 +25,7 @@
*/
export * from './Accessibility';
export * from './Browser';
export * from './BrowserFetcher';
export * from './node/BrowserFetcher';
export * from './Connection';
export * from './ConsoleMessage';
export * from './Coverage';
Expand Down
2 changes: 1 addition & 1 deletion src/api.ts
Expand Up @@ -22,7 +22,7 @@ module.exports = {
Accessibility: require('./Accessibility').Accessibility,
Browser: require('./Browser').Browser,
BrowserContext: require('./Browser').BrowserContext,
BrowserFetcher: require('./BrowserFetcher').BrowserFetcher,
BrowserFetcher: require('./node/BrowserFetcher').BrowserFetcher,
CDPSession: require('./Connection').CDPSession,
ConsoleMessage: require('./ConsoleMessage').ConsoleMessage,
Coverage: require('./Coverage').Coverage,
Expand Down
6 changes: 3 additions & 3 deletions src/BrowserFetcher.ts → src/node/BrowserFetcher.ts
Expand Up @@ -23,13 +23,13 @@ import * as https from 'https';
import * as http from 'http';

import extractZip from 'extract-zip';
import { debug } from './Debug';
import { debug } from '../Debug';
import removeRecursive from 'rimraf';
import * as URL from 'url';
import ProxyAgent from 'https-proxy-agent';
import { getProxyForUrl } from 'proxy-from-env';
import { assert } from './assert';
import { helper } from './helper';
import { assert } from '../assert';
import { helper } from '../helper';
const debugFetcher = debug(`puppeteer:fetcher`);

const downloadURLs = {
Expand Down
Expand Up @@ -23,7 +23,7 @@ import { helper, debugError } from '../helper';
import { LaunchOptions } from './LaunchOptions';
import { Connection } from '../Connection';
import { WebSocketTransport } from '../WebSocketTransport';
import { PipeTransport } from '../PipeTransport';
import { PipeTransport } from './PipeTransport';
import * as readline from 'readline';
import { TimeoutError } from '../Errors';

Expand Down
File renamed without changes.
16 changes: 8 additions & 8 deletions src/Launcher.ts → src/node/Launcher.ts
Expand Up @@ -21,13 +21,13 @@ import * as URL from 'url';
import * as fs from 'fs';

import { BrowserFetcher } from './BrowserFetcher';
import { Connection } from './Connection';
import { Browser } from './Browser';
import { assert } from './assert';
import { helper, debugError } from './helper';
import { ConnectionTransport } from './ConnectionTransport';
import { WebSocketTransport } from './WebSocketTransport';
import { BrowserRunner } from './launcher/BrowserRunner';
import { Connection } from '../Connection';
import { Browser } from '../Browser';
import { assert } from '../assert';
import { helper, debugError } from '../helper';
import { ConnectionTransport } from '../ConnectionTransport';
import { WebSocketTransport } from '../WebSocketTransport';
import { BrowserRunner } from './BrowserRunner';

const mkdtempAsync = helper.promisify(fs.mkdtemp);
const writeFileAsync = helper.promisify(fs.writeFile);
Expand All @@ -36,7 +36,7 @@ import {
ChromeArgOptions,
LaunchOptions,
BrowserOptions,
} from './launcher/LaunchOptions';
} from './LaunchOptions';

export interface ProductLauncher {
launch(object);
Expand Down
4 changes: 2 additions & 2 deletions src/PipeTransport.ts → src/node/PipeTransport.ts
Expand Up @@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { helper, debugError, PuppeteerEventListener } from './helper';
import { ConnectionTransport } from './ConnectionTransport';
import { helper, debugError, PuppeteerEventListener } from '../helper';
import { ConnectionTransport } from '../ConnectionTransport';

export class PipeTransport implements ConnectionTransport {
_pipeWrite: NodeJS.WritableStream;
Expand Down
2 changes: 1 addition & 1 deletion utils/doclint/cli.js
Expand Up @@ -61,7 +61,7 @@ async function run() {
* we'll just list the directories manually.
*/
...(await Source.readdir(path.join(PROJECT_DIR, 'src'), 'ts')),
...(await Source.readdir(path.join(PROJECT_DIR, 'src', 'launcher'), 'ts')),
...(await Source.readdir(path.join(PROJECT_DIR, 'src', 'node'), 'ts')),
];

const tsSourcesNoDefinitions = tsSources.filter(
Expand Down

0 comments on commit 7bb2bf1

Please sign in to comment.