Skip to content

Commit

Permalink
chore: remove helper.promisify (#6100)
Browse files Browse the repository at this point in the history
It was just re-exporting the built-in Node module so let's just import
from that directly.
  • Loading branch information
jackfranklin authored and mathiasbynens committed Jun 25, 2020
1 parent 5b6d2bf commit a4d12a2
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 18 deletions.
8 changes: 6 additions & 2 deletions src/common/DOMWorld.ts
Expand Up @@ -266,7 +266,9 @@ export class DOMWorld {
}
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs');
const readFileAsync = helper.promisify(fs.readFile);
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { promisify } = require('util');
const readFileAsync = promisify(fs.readFile);
let contents = await readFileAsync(path, 'utf8');
contents += '//# sourceURL=' + path.replace(/\n/g, '');
const context = await this.executionContext();
Expand Down Expand Up @@ -351,7 +353,9 @@ export class DOMWorld {
}
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs');
const readFileAsync = helper.promisify(fs.readFile);
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { promisify } = require('util');
const readFileAsync = promisify(fs.readFile);
let contents = await readFileAsync(path, 'utf8');
contents += '/*# sourceURL=' + path.replace(/\n/g, '') + '*/';
const context = await this.executionContext();
Expand Down
3 changes: 2 additions & 1 deletion src/common/Page.ts
Expand Up @@ -15,6 +15,7 @@
*/

import * as fs from 'fs';
import { promisify } from 'util';
import { EventEmitter } from './EventEmitter';
import * as mime from 'mime';
import { Events } from './Events';
Expand Down Expand Up @@ -42,7 +43,7 @@ import { ConsoleMessage, ConsoleMessageType } from './ConsoleMessage';
import { PuppeteerLifeCycleEvent } from './LifecycleWatcher';
import Protocol from '../protocol';

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

export interface Metrics {
Timestamp?: number;
Expand Down
1 change: 0 additions & 1 deletion src/common/helper.ts
Expand Up @@ -268,7 +268,6 @@ async function readProtocolStream(
}

export const helper = {
promisify,
evaluationString,
readProtocolStream,
waitWithTimeout,
Expand Down
11 changes: 6 additions & 5 deletions src/node/BrowserFetcher.ts
Expand Up @@ -24,12 +24,13 @@ import * as http from 'http';

import extractZip from 'extract-zip';
import { debug } from '../common/Debug';
import { promisify } from 'util';
import removeRecursive from 'rimraf';
import * as URL from 'url';
import ProxyAgent from 'https-proxy-agent';
import { getProxyForUrl } from 'proxy-from-env';
import { assert } from '../common/assert';
import { helper } from '../common/helper';

const debugFetcher = debug(`puppeteer:fetcher`);

const downloadURLs = {
Expand Down Expand Up @@ -116,10 +117,10 @@ function handleArm64(): void {
}
});
}
const readdirAsync = helper.promisify(fs.readdir.bind(fs));
const mkdirAsync = helper.promisify(fs.mkdir.bind(fs));
const unlinkAsync = helper.promisify(fs.unlink.bind(fs));
const chmodAsync = helper.promisify(fs.chmod.bind(fs));
const readdirAsync = promisify(fs.readdir.bind(fs));
const mkdirAsync = promisify(fs.mkdir.bind(fs));
const unlinkAsync = promisify(fs.unlink.bind(fs));
const chmodAsync = promisify(fs.chmod.bind(fs));

function existsAsync(filePath: string): Promise<boolean> {
return new Promise((resolve) => {
Expand Down
3 changes: 2 additions & 1 deletion src/node/BrowserRunner.ts
Expand Up @@ -26,8 +26,9 @@ import { WebSocketTransport } from '../common/WebSocketTransport';
import { PipeTransport } from './PipeTransport';
import * as readline from 'readline';
import { TimeoutError } from '../common/Errors';
import { promisify } from 'util';

const removeFolderAsync = helper.promisify(removeFolder);
const removeFolderAsync = promisify(removeFolder);
const debugLauncher = debug('puppeteer:launcher');
const PROCESS_ERROR_EXPLANATION = `Puppeteer was unable to kill the process which ran the browser binary.
This means that, on future Puppeteer launches, Puppeteer might not be able to launch the browser.
Expand Down
7 changes: 4 additions & 3 deletions src/node/Launcher.ts
Expand Up @@ -24,13 +24,14 @@ import { BrowserFetcher } from './BrowserFetcher';
import { Connection } from '../common/Connection';
import { Browser } from '../common/Browser';
import { assert } from '../common/assert';
import { helper, debugError } from '../common/helper';
import { debugError } from '../common/helper';
import { ConnectionTransport } from '../common/ConnectionTransport';
import { WebSocketTransport } from '../common/WebSocketTransport';
import { BrowserRunner } from './BrowserRunner';
import { promisify } from 'util';

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

import {
ChromeArgOptions,
Expand Down
10 changes: 5 additions & 5 deletions test/launcher.spec.ts
Expand Up @@ -17,7 +17,7 @@ import fs from 'fs';
import os from 'os';
import path from 'path';
import sinon from 'sinon';
import { helper } from '../src/common/helper';
import { promisify } from 'util';
import {
getTestState,
itFailsFirefox,
Expand All @@ -29,10 +29,10 @@ import expect from 'expect';
import rimraf from 'rimraf';
import { Page } from '../src/common/Page';

const rmAsync = helper.promisify(rimraf);
const mkdtempAsync = helper.promisify(fs.mkdtemp);
const readFileAsync = helper.promisify(fs.readFile);
const statAsync = helper.promisify(fs.stat);
const rmAsync = promisify(rimraf);
const mkdtempAsync = promisify(fs.mkdtemp);
const readFileAsync = promisify(fs.readFile);
const statAsync = promisify(fs.stat);
const TMP_FOLDER = path.join(os.tmpdir(), 'pptr_tmp_folder-');

describe('Launcher specs', function () {
Expand Down

0 comments on commit a4d12a2

Please sign in to comment.