diff --git a/cjs-entry-core.js b/cjs-entry-core.js index 446726fafa3..ad2e49c5f51 100644 --- a/cjs-entry-core.js +++ b/cjs-entry-core.js @@ -25,5 +25,5 @@ * This means that we can publish to CJS and ESM whilst maintaining the expected * import behaviour for CJS and ESM users. */ -const puppeteerExport = require('./lib/cjs/puppeteer/node-puppeteer-core'); +const puppeteerExport = require('./lib/cjs/puppeteer/node-puppeteer-core.js'); module.exports = puppeteerExport.default; diff --git a/cjs-entry.js b/cjs-entry.js index d1840a9bea1..70c262a9b78 100644 --- a/cjs-entry.js +++ b/cjs-entry.js @@ -25,5 +25,5 @@ * This means that we can publish to CJS and ESM whilst maintaining the expected * import behaviour for CJS and ESM users. */ -const puppeteerExport = require('./lib/cjs/puppeteer/node'); +const puppeteerExport = require('./lib/cjs/puppeteer/node.js'); module.exports = puppeteerExport.default; diff --git a/compat/cjs/compat.ts b/compat/cjs/compat.ts index 50dd7695be6..8bd871b20b8 100644 --- a/compat/cjs/compat.ts +++ b/compat/cjs/compat.ts @@ -1,3 +1,19 @@ +/** + * Copyright 2022 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. + */ + import { dirname } from 'path'; export const puppeteerDirname = dirname(dirname(dirname(__dirname))); diff --git a/compat/esm/compat.ts b/compat/esm/compat.ts index 5d761f74184..1decaefb280 100644 --- a/compat/esm/compat.ts +++ b/compat/esm/compat.ts @@ -1,3 +1,19 @@ +/** + * Copyright 2022 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. + */ + import { dirname } from 'path'; import { fileURLToPath } from 'url'; diff --git a/install.js b/install.js index 11518a595f5..87fa7a32dbb 100644 --- a/install.js +++ b/install.js @@ -24,7 +24,7 @@ * necessary. */ -const compileTypeScriptIfRequired = require('./typescript-if-required'); +const compileTypeScriptIfRequired = require('./typescript-if-required.js'); async function download() { await compileTypeScriptIfRequired(); @@ -32,7 +32,7 @@ async function download() { const { downloadBrowser, logPolitely, - } = require('./lib/cjs/puppeteer/node/install'); + } = require('./lib/cjs/puppeteer/node/install.js'); if (process.env.PUPPETEER_SKIP_DOWNLOAD) { logPolitely( diff --git a/mocha-config/coverage-tests.js b/mocha-config/coverage-tests.js index 6814f404cf0..0525532caf5 100644 --- a/mocha-config/coverage-tests.js +++ b/mocha-config/coverage-tests.js @@ -1,4 +1,4 @@ -const base = require('./base'); +const base = require('./base.js'); module.exports = { ...base, diff --git a/mocha-config/doclint-tests.js b/mocha-config/doclint-tests.js index 279e28eb177..e6e817a3a6a 100644 --- a/mocha-config/doclint-tests.js +++ b/mocha-config/doclint-tests.js @@ -1,4 +1,4 @@ -const base = require('./base'); +const base = require('./base.js'); module.exports = { ...base, diff --git a/mocha-config/puppeteer-unit-tests.js b/mocha-config/puppeteer-unit-tests.js index be39c5b9ae6..2f03705190e 100644 --- a/mocha-config/puppeteer-unit-tests.js +++ b/mocha-config/puppeteer-unit-tests.js @@ -14,7 +14,7 @@ * limitations under the License. */ -const base = require('./base'); +const base = require('./base.js'); module.exports = { ...base, diff --git a/package.json b/package.json index 0ea5da3ed75..c9573a727da 100644 --- a/package.json +++ b/package.json @@ -67,61 +67,61 @@ "author": "The Chromium Authors", "license": "Apache-2.0", "dependencies": { + "cross-fetch": "3.1.5", "debug": "4.3.3", "devtools-protocol": "0.0.960912", "extract-zip": "2.0.1", "https-proxy-agent": "5.0.0", - "node-fetch": "2.6.7", "pkg-dir": "4.2.0", "progress": "2.0.3", "proxy-from-env": "1.1.0", "rimraf": "3.0.2", "tar-fs": "2.1.1", "unbzip2-stream": "1.4.3", - "ws": "8.2.3" + "ws": "8.5.0" }, "devDependencies": { - "@commitlint/cli": "13.2.0", + "@commitlint/cli": "16.1.0", "@commitlint/config-conventional": "16.0.0", - "@microsoft/api-documenter": "7.13.65", - "@microsoft/api-extractor": "7.18.15", + "@microsoft/api-documenter": "7.15.1", + "@microsoft/api-extractor": "7.19.4", "@types/debug": "4.1.7", "@types/mime": "2.0.3", - "@types/mocha": "9.0.0", - "@types/node": "17.0.15", + "@types/mocha": "9.1.0", + "@types/node": "17.0.16", "@types/progress": "2.0.5", "@types/proxy-from-env": "1.0.1", "@types/rimraf": "3.0.2", - "@types/sinon": "10.0.4", + "@types/sinon": "10.0.11", "@types/tar-fs": "2.0.1", - "@types/ws": "8.2.0", - "@typescript-eslint/eslint-plugin": "4.23.0", - "@typescript-eslint/parser": "4.33.0", - "@web/test-runner": "0.13.18", - "commonmark": "0.29.3", + "@types/ws": "8.2.2", + "@typescript-eslint/eslint-plugin": "5.11.0", + "@typescript-eslint/parser": "5.11.0", + "@web/test-runner": "0.13.27", + "commonmark": "0.30.0", "cross-env": "7.0.3", - "eslint": "7.32.0", + "eslint": "8.8.0", "eslint-config-prettier": "8.3.0", - "eslint-plugin-import": "2.22.1", - "eslint-plugin-mocha": "9.0.0", + "eslint-plugin-import": "2.25.4", + "eslint-plugin-mocha": "10.0.3", "eslint-plugin-prettier": "4.0.0", - "eslint-plugin-unicorn": "37.0.1", + "eslint-plugin-unicorn": "40.1.0", "esprima": "4.0.1", "expect": "25.2.7", - "husky": "7.0.2", + "husky": "7.0.4", "jpeg-js": "0.4.3", - "mime": "2.5.2", + "mime": "3.0.0", "minimist": "1.2.5", - "mocha": "9.1.3", + "mocha": "9.2.0", "ncp": "2.0.0", "pixelmatch": "5.2.1", "pngjs": "6.0.0", - "prettier": "2.3.0", - "sinon": "9.2.4", - "source-map-support": "0.5.19", + "prettier": "2.5.1", + "sinon": "13.0.1", + "source-map-support": "0.5.21", "standard-version": "9.3.2", "text-diff": "1.0.1", - "ts-node": "10.4.0", + "ts-node": "10.5.0", "typescript": "4.4.4" } } diff --git a/src/common/BrowserConnector.ts b/src/common/BrowserConnector.ts index 3a707b5f300..4693defd59d 100644 --- a/src/common/BrowserConnector.ts +++ b/src/common/BrowserConnector.ts @@ -19,9 +19,9 @@ import { Browser, TargetFilterCallback } from './Browser.js'; import { assert } from './assert.js'; import { debugError } from '../common/helper.js'; import { Connection } from './Connection.js'; -import { getFetch } from './fetch.js'; import { Viewport } from './PuppeteerViewport.js'; import { isNode } from '../environment.js'; +import { getFetch } from './fetch.js'; /** * Generic browser options that can be passed when launching any browser or when diff --git a/src/common/Coverage.ts b/src/common/Coverage.ts index 70061be94ea..4f94f6916c6 100644 --- a/src/common/Coverage.ts +++ b/src/common/Coverage.ts @@ -273,12 +273,7 @@ export class JSCoverage { assert(this._enabled, 'JSCoverage is not enabled'); this._enabled = false; - const result = await Promise.all< - Protocol.Profiler.TakePreciseCoverageResponse, - void, - void, - void - >([ + const result = await Promise.all([ this._client.send('Profiler.takePreciseCoverage'), this._client.send('Profiler.stopPreciseCoverage'), this._client.send('Profiler.disable'), diff --git a/src/common/ExecutionContext.ts b/src/common/ExecutionContext.ts index f51b8a42ed5..631b236a173 100644 --- a/src/common/ExecutionContext.ts +++ b/src/common/ExecutionContext.ts @@ -133,7 +133,7 @@ export class ExecutionContext { * * @returns A promise that resolves to the return value of the given function. */ - async evaluate( + async evaluate( pageFunction: Function | string, ...args: unknown[] ): Promise { diff --git a/src/common/Page.ts b/src/common/Page.ts index 1b2695b4a51..43974162237 100644 --- a/src/common/Page.ts +++ b/src/common/Page.ts @@ -1795,7 +1795,7 @@ export class Page extends EventEmitter { * more than 2 network connections for at least `500` ms. */ async reload(options?: WaitForOptions): Promise { - const result = await Promise.all([ + const result = await Promise.all([ this.waitForNavigation(options), this._client.send('Page.reload'), ]); diff --git a/src/common/WebWorker.ts b/src/common/WebWorker.ts index 8131e8a9efd..ce090db6ecd 100644 --- a/src/common/WebWorker.ts +++ b/src/common/WebWorker.ts @@ -138,7 +138,7 @@ export class WebWorker extends EventEmitter { * @param args - Arguments to pass to `pageFunction`. * @returns Promise which resolves to the return value of `pageFunction`. */ - async evaluate( + async evaluate( pageFunction: Function | string, ...args: any[] ): Promise { diff --git a/src/common/fetch.ts b/src/common/fetch.ts index ae4b65c45f0..8f41553b04a 100644 --- a/src/common/fetch.ts +++ b/src/common/fetch.ts @@ -18,5 +18,5 @@ import { isNode } from '../environment.js'; /* Use the global version if we're in the browser, else load the node-fetch module. */ export const getFetch = async (): Promise => { - return isNode ? await import('node-fetch') : globalThis.fetch; + return isNode ? (await import('cross-fetch')).fetch : globalThis.fetch; }; diff --git a/src/common/helper.ts b/src/common/helper.ts index aa0dea6854a..40c9ecd8c6d 100644 --- a/src/common/helper.ts +++ b/src/common/helper.ts @@ -127,7 +127,7 @@ function isNumber(obj: unknown): obj is number { return typeof obj === 'number' || obj instanceof Number; } -async function waitForEvent( +async function waitForEvent( emitter: CommonEventEmitter, eventName: string | symbol, predicate: (event: T) => Promise | boolean, @@ -295,7 +295,7 @@ function makePredicateString( })() `; } -async function waitWithTimeout( +async function waitWithTimeout( promise: Promise, taskName: string, timeout: number diff --git a/src/compat.ts b/src/compat.ts index 873dcea7966..cc48163eb67 100644 --- a/src/compat.ts +++ b/src/compat.ts @@ -1,3 +1,19 @@ +/** + * Copyright 2022 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. + */ + declare const puppeteerDirname: string; export { puppeteerDirname }; diff --git a/src/initialize-node.ts b/src/initialize-node.ts index 17f41027513..1e8bd755430 100644 --- a/src/initialize-node.ts +++ b/src/initialize-node.ts @@ -16,12 +16,12 @@ import { PuppeteerNode } from './node/Puppeteer.js'; import { PUPPETEER_REVISIONS } from './revisions.js'; -import pkgDir from 'pkg-dir'; +import { sync } from 'pkg-dir'; import { Product } from './common/Product.js'; import { puppeteerDirname } from './compat.js'; export const initializePuppeteerNode = (packageName: string): PuppeteerNode => { - const puppeteerRootDirectory = pkgDir.sync(puppeteerDirname); + const puppeteerRootDirectory = sync(puppeteerDirname); let preferredRevision = PUPPETEER_REVISIONS.chromium; const isPuppeteerCore = packageName === 'puppeteer-core'; diff --git a/test/assert-coverage-test.js b/test/assert-coverage-test.js index 6e26a1121ad..28b25dab948 100644 --- a/test/assert-coverage-test.js +++ b/test/assert-coverage-test.js @@ -1,5 +1,5 @@ const { describe, it } = require('mocha'); -const { getCoverageResults } = require('./coverage-utils'); +const { getCoverageResults } = require('./coverage-utils.js'); const expect = require('expect'); describe('API coverage test', () => { diff --git a/test/run_static_server.js b/test/run_static_server.js index 6779e8816a4..0cd10f26466 100755 --- a/test/run_static_server.js +++ b/test/run_static_server.js @@ -15,7 +15,7 @@ * limitations under the License. */ const path = require('path'); -const { TestServer } = require('../utils/testserver/'); +const { TestServer } = require('../utils/testserver/index.js'); const port = 8907; const httpsPort = 8908; diff --git a/test/utils.js b/test/utils.js index 935b44d98ef..f70cb47e714 100644 --- a/test/utils.js +++ b/test/utils.js @@ -20,7 +20,7 @@ const fs = require('fs'); const path = require('path'); const expect = require('expect'); -const GoldenUtils = require('./golden-utils'); +const GoldenUtils = require('./golden-utils.js'); const PROJECT_ROOT = fs.existsSync(path.join(__dirname, '..', 'package.json')) ? path.join(__dirname, '..') : path.join(__dirname, '..', '..'); diff --git a/utils/check_availability.js b/utils/check_availability.js index ba8129554d4..3241dd543c7 100755 --- a/utils/check_availability.js +++ b/utils/check_availability.js @@ -172,7 +172,7 @@ async function checkRollCandidate(channel) { 10 ); const currentRevision = parseInt( - require('../lib/cjs/puppeteer/revisions').PUPPETEER_REVISIONS.chromium, + require('../lib/cjs/puppeteer/revisions.js').PUPPETEER_REVISIONS.chromium, 10 ); diff --git a/utils/doclint/check_public_api/JSBuilder.js b/utils/doclint/check_public_api/JSBuilder.js index 0994dffcff5..ebb00209f72 100644 --- a/utils/doclint/check_public_api/JSBuilder.js +++ b/utils/doclint/check_public_api/JSBuilder.js @@ -1,6 +1,6 @@ const ts = require('typescript'); const path = require('path'); -const Documentation = require('./Documentation'); +const Documentation = require('./Documentation.js'); module.exports = checkSources; /** diff --git a/utils/doclint/check_public_api/MDBuilder.js b/utils/doclint/check_public_api/MDBuilder.js index 46a4e6cfce5..3776489f8c7 100644 --- a/utils/doclint/check_public_api/MDBuilder.js +++ b/utils/doclint/check_public_api/MDBuilder.js @@ -14,8 +14,8 @@ * limitations under the License. */ -const Documentation = require('./Documentation'); -const commonmark = require('commonmark'); +const Documentation = require('./Documentation.js'); +const { Parser, HtmlRenderer } = require('commonmark'); class MDOutline { /** @@ -25,9 +25,9 @@ class MDOutline { */ static async create(page, text) { // Render markdown as HTML. - const reader = new commonmark.Parser(); + const reader = new Parser(); const parsed = reader.parse(text); - const writer = new commonmark.HtmlRenderer(); + const writer = new HtmlRenderer(); const html = writer.render(parsed); page.on('console', (msg) => { diff --git a/utils/doclint/check_public_api/index.js b/utils/doclint/check_public_api/index.js index 4e49e53223b..4c408f9a5ab 100644 --- a/utils/doclint/check_public_api/index.js +++ b/utils/doclint/check_public_api/index.js @@ -14,13 +14,13 @@ * limitations under the License. */ -const jsBuilder = require('./JSBuilder'); -const mdBuilder = require('./MDBuilder'); -const Documentation = require('./Documentation'); -const Message = require('../Message'); +const jsBuilder = require('./JSBuilder.js'); +const mdBuilder = require('./MDBuilder.js'); +const Documentation = require('./Documentation.js'); +const Message = require('../Message.js'); const { MODULES_TO_CHECK_FOR_COVERAGE, -} = require('../../../test/coverage-utils'); +} = require('../../../test/coverage-utils.js'); const EXCLUDE_PROPERTIES = new Set([ 'Browser.create', diff --git a/utils/doclint/cli.js b/utils/doclint/cli.js index e2de3a818ff..9872a808604 100755 --- a/utils/doclint/cli.js +++ b/utils/doclint/cli.js @@ -15,9 +15,10 @@ * limitations under the License. */ +// eslint-disable-next-line import/extensions const puppeteer = require('../..'); const path = require('path'); -const Source = require('./Source'); +const Source = require('./Source.js'); const PROJECT_DIR = path.join(__dirname, '..', '..'); const VERSION = require(path.join(PROJECT_DIR, 'package.json')).version; @@ -58,7 +59,7 @@ async function run() { ); const mdSources = [readme, api, troubleshooting, contributing]; - const preprocessor = require('./preprocessor'); + const preprocessor = require('./preprocessor/index.js'); messages.push(...(await preprocessor.runCommands(mdSources, VERSION))); messages.push( ...(await preprocessor.ensureReleasedAPILinks([readme], VERSION)) @@ -66,7 +67,7 @@ async function run() { const browser = await puppeteer.launch(); const page = await browser.newPage(); - const checkPublicAPI = require('./check_public_api'); + const checkPublicAPI = require('./check_public_api/index.js'); const tsSources = [ /* Source.readdir doesn't deal with nested directories well. * Rather than invest time here when we're going to remove this Doc tooling soon diff --git a/utils/doclint/preprocessor/index.js b/utils/doclint/preprocessor/index.js index d026873d25e..9c5b951bb03 100644 --- a/utils/doclint/preprocessor/index.js +++ b/utils/doclint/preprocessor/index.js @@ -14,7 +14,7 @@ * limitations under the License. */ -const Message = require('../Message'); +const Message = require('../Message.js'); const IS_RELEASE = Boolean(process.env.IS_RELEASE); diff --git a/utils/doclint/preprocessor/preprocessor.spec.js b/utils/doclint/preprocessor/preprocessor.spec.js index 713785db8ff..86625e7d1c9 100644 --- a/utils/doclint/preprocessor/preprocessor.spec.js +++ b/utils/doclint/preprocessor/preprocessor.spec.js @@ -15,7 +15,7 @@ */ const { runCommands, ensureReleasedAPILinks } = require('.'); -const Source = require('../Source'); +const Source = require('../Source.js'); const expect = require('expect'); describe('doclint preprocessor specs', function () {