chore: remove helper.promisify (#6100)

It was just re-exporting the built-in Node module so let's just import
from that directly.
This commit is contained in:
Jack Franklin 2020-06-25 11:54:00 +01:00 committed by Mathias Bynens
parent 5b6d2bfb0e
commit a4d12a2b21
7 changed files with 25 additions and 18 deletions

View File

@ -266,7 +266,9 @@ export class DOMWorld {
} }
// eslint-disable-next-line @typescript-eslint/no-var-requires // eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs'); 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'); let contents = await readFileAsync(path, 'utf8');
contents += '//# sourceURL=' + path.replace(/\n/g, ''); contents += '//# sourceURL=' + path.replace(/\n/g, '');
const context = await this.executionContext(); const context = await this.executionContext();
@ -351,7 +353,9 @@ export class DOMWorld {
} }
// eslint-disable-next-line @typescript-eslint/no-var-requires // eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs'); 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'); let contents = await readFileAsync(path, 'utf8');
contents += '/*# sourceURL=' + path.replace(/\n/g, '') + '*/'; contents += '/*# sourceURL=' + path.replace(/\n/g, '') + '*/';
const context = await this.executionContext(); const context = await this.executionContext();

View File

@ -15,6 +15,7 @@
*/ */
import * as fs from 'fs'; import * as fs from 'fs';
import { promisify } from 'util';
import { EventEmitter } from './EventEmitter'; import { EventEmitter } from './EventEmitter';
import * as mime from 'mime'; import * as mime from 'mime';
import { Events } from './Events'; import { Events } from './Events';
@ -42,7 +43,7 @@ import { ConsoleMessage, ConsoleMessageType } from './ConsoleMessage';
import { PuppeteerLifeCycleEvent } from './LifecycleWatcher'; import { PuppeteerLifeCycleEvent } from './LifecycleWatcher';
import Protocol from '../protocol'; import Protocol from '../protocol';
const writeFileAsync = helper.promisify(fs.writeFile); const writeFileAsync = promisify(fs.writeFile);
export interface Metrics { export interface Metrics {
Timestamp?: number; Timestamp?: number;

View File

@ -268,7 +268,6 @@ async function readProtocolStream(
} }
export const helper = { export const helper = {
promisify,
evaluationString, evaluationString,
readProtocolStream, readProtocolStream,
waitWithTimeout, waitWithTimeout,

View File

@ -24,12 +24,13 @@ import * as http from 'http';
import extractZip from 'extract-zip'; import extractZip from 'extract-zip';
import { debug } from '../common/Debug'; import { debug } from '../common/Debug';
import { promisify } from 'util';
import removeRecursive from 'rimraf'; import removeRecursive from 'rimraf';
import * as URL from 'url'; import * as URL from 'url';
import ProxyAgent from 'https-proxy-agent'; import ProxyAgent from 'https-proxy-agent';
import { getProxyForUrl } from 'proxy-from-env'; import { getProxyForUrl } from 'proxy-from-env';
import { assert } from '../common/assert'; import { assert } from '../common/assert';
import { helper } from '../common/helper';
const debugFetcher = debug(`puppeteer:fetcher`); const debugFetcher = debug(`puppeteer:fetcher`);
const downloadURLs = { const downloadURLs = {
@ -116,10 +117,10 @@ function handleArm64(): void {
} }
}); });
} }
const readdirAsync = helper.promisify(fs.readdir.bind(fs)); const readdirAsync = promisify(fs.readdir.bind(fs));
const mkdirAsync = helper.promisify(fs.mkdir.bind(fs)); const mkdirAsync = promisify(fs.mkdir.bind(fs));
const unlinkAsync = helper.promisify(fs.unlink.bind(fs)); const unlinkAsync = promisify(fs.unlink.bind(fs));
const chmodAsync = helper.promisify(fs.chmod.bind(fs)); const chmodAsync = promisify(fs.chmod.bind(fs));
function existsAsync(filePath: string): Promise<boolean> { function existsAsync(filePath: string): Promise<boolean> {
return new Promise((resolve) => { return new Promise((resolve) => {

View File

@ -26,8 +26,9 @@ import { WebSocketTransport } from '../common/WebSocketTransport';
import { PipeTransport } from './PipeTransport'; import { PipeTransport } from './PipeTransport';
import * as readline from 'readline'; import * as readline from 'readline';
import { TimeoutError } from '../common/Errors'; import { TimeoutError } from '../common/Errors';
import { promisify } from 'util';
const removeFolderAsync = helper.promisify(removeFolder); const removeFolderAsync = promisify(removeFolder);
const debugLauncher = debug('puppeteer:launcher'); const debugLauncher = debug('puppeteer:launcher');
const PROCESS_ERROR_EXPLANATION = `Puppeteer was unable to kill the process which ran the browser binary. 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. This means that, on future Puppeteer launches, Puppeteer might not be able to launch the browser.

View File

@ -24,13 +24,14 @@ import { BrowserFetcher } from './BrowserFetcher';
import { Connection } from '../common/Connection'; import { Connection } from '../common/Connection';
import { Browser } from '../common/Browser'; import { Browser } from '../common/Browser';
import { assert } from '../common/assert'; import { assert } from '../common/assert';
import { helper, debugError } from '../common/helper'; import { debugError } from '../common/helper';
import { ConnectionTransport } from '../common/ConnectionTransport'; import { ConnectionTransport } from '../common/ConnectionTransport';
import { WebSocketTransport } from '../common/WebSocketTransport'; import { WebSocketTransport } from '../common/WebSocketTransport';
import { BrowserRunner } from './BrowserRunner'; import { BrowserRunner } from './BrowserRunner';
import { promisify } from 'util';
const mkdtempAsync = helper.promisify(fs.mkdtemp); const mkdtempAsync = promisify(fs.mkdtemp);
const writeFileAsync = helper.promisify(fs.writeFile); const writeFileAsync = promisify(fs.writeFile);
import { import {
ChromeArgOptions, ChromeArgOptions,

View File

@ -17,7 +17,7 @@ import fs from 'fs';
import os from 'os'; import os from 'os';
import path from 'path'; import path from 'path';
import sinon from 'sinon'; import sinon from 'sinon';
import { helper } from '../src/common/helper'; import { promisify } from 'util';
import { import {
getTestState, getTestState,
itFailsFirefox, itFailsFirefox,
@ -29,10 +29,10 @@ import expect from 'expect';
import rimraf from 'rimraf'; import rimraf from 'rimraf';
import { Page } from '../src/common/Page'; import { Page } from '../src/common/Page';
const rmAsync = helper.promisify(rimraf); const rmAsync = promisify(rimraf);
const mkdtempAsync = helper.promisify(fs.mkdtemp); const mkdtempAsync = promisify(fs.mkdtemp);
const readFileAsync = helper.promisify(fs.readFile); const readFileAsync = promisify(fs.readFile);
const statAsync = helper.promisify(fs.stat); const statAsync = promisify(fs.stat);
const TMP_FOLDER = path.join(os.tmpdir(), 'pptr_tmp_folder-'); const TMP_FOLDER = path.join(os.tmpdir(), 'pptr_tmp_folder-');
describe('Launcher specs', function () { describe('Launcher specs', function () {