Skip to content

Commit

Permalink
chore: drop Node.js v6 support (puppeteer#5045)
Browse files Browse the repository at this point in the history
Node.js v6 was end-of-life'd in April, 2019, with AWS Lambda prohibiting updaets to the Node.js v6 runtime since June 30, 2019.

This makes it quite safe for us to remove the Node 6 support from the repository.
  • Loading branch information
mathiasbynens authored and Roman Fojtik committed Dec 21, 2019
1 parent f6de8d2 commit c98dafe
Show file tree
Hide file tree
Showing 24 changed files with 48 additions and 494 deletions.
8 changes: 2 additions & 6 deletions .appveyor.yml
@@ -1,8 +1,6 @@
environment:
matrix:
- nodejs_version: "6.12.3"
FLAKINESS_DASHBOARD_NAME: Appveyor Chromium (Win + node6)
- nodejs_version: "8.11.3"
- nodejs_version: "8.16.0"
FLAKINESS_DASHBOARD_NAME: Appveyor Chromium (Win + node8)
FLAKINESS_DASHBOARD_PASSWORD:
secure: g66jP+j6C+hkXLutBV9fdxB5fRJgcQQzy93SgQzXUmcCl/RjkJwnzyHvX0xfCVnv
Expand All @@ -13,11 +11,9 @@ install:
- ps: $env:FLAKINESS_DASHBOARD_BUILD_URL="https://ci.appveyor.com/project/aslushnikov/puppeteer/builds/$env:APPVEYOR_BUILD_ID/job/$env:APPVEYOR_JOB_ID"
- ps: Install-Product node $env:nodejs_version
- npm install
- if "%nodejs_version%" == "8.11.3" (
- if "%nodejs_version%" == "8.16.0" (
npm run lint &&
npm run coverage &&
npm run test-doclint &&
npm run test-types
) else (
npm run unit-node6
)
17 changes: 0 additions & 17 deletions .ci/node6/Dockerfile.linux

This file was deleted.

9 changes: 0 additions & 9 deletions .cirrus.yml
Expand Up @@ -4,15 +4,6 @@ env:
FLAKINESS_DASHBOARD_NAME: Cirrus ${CIRRUS_TASK_NAME}
FLAKINESS_DASHBOARD_BUILD_URL: https://cirrus-ci.com/task/${CIRRUS_TASK_ID}

task:
matrix:
- name: Chromium (node6 + linux)
container:
dockerfile: .ci/node6/Dockerfile.linux
xvfb_start_background_script: Xvfb :99 -ac -screen 0 1024x768x24
install_script: npm install --unsafe-perm
test_script: npm run unit-node6

task:
matrix:
- name: Chromium (node8 + linux)
Expand Down
10 changes: 2 additions & 8 deletions .travis.yml
Expand Up @@ -24,24 +24,18 @@ script:
- 'if [ "$NODE8" = "true" ]; then npm run test-types; fi'
- 'if [ "$NODE8" = "true" ]; then npm run bundle; fi'
- 'if [ "$NODE8" = "true" ]; then npm run unit-bundle; fi'
- 'if [ "$NODE6" = "true" ]; then npm run unit-node6; fi'
jobs:
include:
- node_js: "8.11.3"
- node_js: "8.16.0"
env:
- NODE8=true
- FLAKINESS_DASHBOARD_NAME="Travis Chromium (node8 + linux)"
- FLAKINESS_DASHBOARD_BUILD_URL="${TRAVIS_JOB_WEB_URL}"
- node_js: "8.11.3"
- node_js: "8.16.0"
env:
- FIREFOX=true
- FLAKINESS_DASHBOARD_NAME="Travis Firefox (node8 + linux)"
- FLAKINESS_DASHBOARD_BUILD_URL="${TRAVIS_JOB_WEB_URL}"
- node_js: "6.12.3"
env:
- NODE6=true
- FLAKINESS_DASHBOARD_NAME="Travis Chromium (node6 + linux)"
- FLAKINESS_DASHBOARD_BUILD_URL="${TRAVIS_JOB_WEB_URL}"
before_deploy: "npm run apply-next-version"
deploy:
provider: npm
Expand Down
13 changes: 1 addition & 12 deletions DeviceDescriptors.js
Expand Up @@ -14,15 +14,4 @@
* limitations under the License.
*/

let asyncawait = true;
try {
new Function('async function test(){await 1}');
} catch (error) {
asyncawait = false;
}

// If node does not support async await, use the compiled version.
if (asyncawait)
module.exports = require('./lib/DeviceDescriptors');
else
module.exports = require('./node6/lib/DeviceDescriptors');
module.exports = require('./lib/DeviceDescriptors');
13 changes: 1 addition & 12 deletions Errors.js
Expand Up @@ -14,15 +14,4 @@
* limitations under the License.
*/

let asyncawait = true;
try {
new Function('async function test(){await 1}');
} catch (error) {
asyncawait = false;
}

// If node does not support async await, use the compiled version.
if (asyncawait)
module.exports = require('./lib/Errors');
else
module.exports = require('./node6/lib/Errors');
module.exports = require('./lib/Errors');
5 changes: 4 additions & 1 deletion README.md
Expand Up @@ -57,7 +57,10 @@ See [puppeteer vs puppeteer-core](https://github.com/GoogleChrome/puppeteer/blob

### Usage

Note: Puppeteer requires at least Node v6.4.0, but the examples below use async/await which is only supported in Node v7.6.0 or greater.
Puppeteer follows the latest [maintenance LTS](https://github.com/nodejs/Release#release-schedule) version of Node.

Note: Prior to v1.18.1, Puppeteer required at least Node v6.4.0. All subsequent versions rely on
Node 8.9.0+. All examples below use async/await which is only supported in Node v7.6.0 or greater.

Puppeteer will be familiar to people using other browser testing frameworks. You create an instance
of `Browser`, open pages, and then manipulate them with [Puppeteer's API](https://github.com/GoogleChrome/puppeteer/blob/v1.20.0/docs/api.md#).
Expand Down
13 changes: 1 addition & 12 deletions experimental/puppeteer-firefox/DeviceDescriptors.js
Expand Up @@ -14,15 +14,4 @@
* limitations under the License.
*/

let asyncawait = true;
try {
new Function('async function test(){await 1}');
} catch (error) {
asyncawait = false;
}

// If node does not support async await, use the compiled version.
if (asyncawait)
module.exports = require('./lib/DeviceDescriptors');
else
module.exports = require('./node6/lib/DeviceDescriptors');
module.exports = require('./lib/DeviceDescriptors');
3 changes: 1 addition & 2 deletions experimental/puppeteer-firefox/lib/Page.js
Expand Up @@ -4,7 +4,6 @@ const {Dialog} = require('./Dialog');
const {TimeoutError} = require('./Errors');
const fs = require('fs');
const mime = require('mime');
const util = require('util');
const EventEmitter = require('events');
const {createHandle} = require('./JSHandle');
const {Events} = require('./Events');
Expand All @@ -15,7 +14,7 @@ const {TimeoutSettings} = require('./TimeoutSettings');
const {NavigationWatchdog} = require('./NavigationWatchdog');
const {Accessibility} = require('./Accessibility');

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

class Page extends EventEmitter {
/**
Expand Down
4 changes: 4 additions & 0 deletions experimental/puppeteer-firefox/lib/helper.js
Expand Up @@ -65,6 +65,10 @@ class Helper {
}
}

/**
* @param {function} nodeFunction
* @return {function}
*/
static promisify(nodeFunction) {
function promisified(...args) {
return new Promise((resolve, reject) => {
Expand Down
4 changes: 2 additions & 2 deletions experimental/puppeteer-firefox/misc/install-preferences.js
@@ -1,14 +1,14 @@
const os = require('os');
const fs = require('fs');
const path = require('path');
const util = require('util');

// Install browser preferences after downloading and unpacking
// firefox instances.
// Based on: https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Enterprise_deployment_before_60#Configuration
async function installFirefoxPreferences(executablePath) {
const firefoxFolder = path.dirname(executablePath);
const {helper} = require('../lib/helper');
const mkdirAsync = helper.promisify(fs.mkdir.bind(fs));
const mkdirAsync = util.promisify(fs.mkdir.bind(fs));

let prefPath = '';
let configPath = '';
Expand Down
23 changes: 7 additions & 16 deletions index.js
Expand Up @@ -14,25 +14,16 @@
* limitations under the License.
*/

let asyncawait = true;
try {
new Function('async function test(){await 1}');
} catch (error) {
asyncawait = false;
}

if (asyncawait) {
const {helper} = require('./lib/helper');
const api = require('./lib/api');
for (const className in api) {
// Puppeteer-web excludes certain classes from bundle, e.g. BrowserFetcher.
if (typeof api[className] === 'function')
helper.installAsyncStackHooks(api[className]);
}
const {helper} = require('./lib/helper');
const api = require('./lib/api');
for (const className in api) {
// Puppeteer-web excludes certain classes from bundle, e.g. BrowserFetcher.
if (typeof api[className] === 'function')
helper.installAsyncStackHooks(api[className]);
}

// If node does not support async await, use the compiled version.
const Puppeteer = asyncawait ? require('./lib/Puppeteer') : require('./node6/lib/Puppeteer');
const Puppeteer = require('./lib/Puppeteer');
const packageJson = require('./package.json');
const preferredRevision = packageJson.puppeteer.chromium_revision;
const isPuppeteerCore = packageJson.name === 'puppeteer-core';
Expand Down
29 changes: 0 additions & 29 deletions install.js
Expand Up @@ -18,8 +18,6 @@
if (require('./package.json').name === 'puppeteer-core')
return;

buildNode6IfNecessary();

if (process.env.PUPPETEER_SKIP_CHROMIUM_DOWNLOAD) {
logPolitely('**INFO** Skipping Chromium download. "PUPPETEER_SKIP_CHROMIUM_DOWNLOAD" environment variable was found.');
return;
Expand Down Expand Up @@ -109,34 +107,7 @@ function toMegabytes(bytes) {
return `${Math.round(mb * 10) / 10} Mb`;
}

function buildNode6IfNecessary() {
const fs = require('fs');
const path = require('path');

// if this package is installed from NPM, then it already has up-to-date node6
// folder.
if (!fs.existsSync(path.join('utils', 'node6-transform')))
return;
// if async/await is supported, then node6 is not needed.
if (supportsAsyncAwait())
return;
// Re-build node6/ folder.
logPolitely('Building Puppeteer for Node 6');
require(path.join(__dirname, 'utils', 'node6-transform'));
}

function supportsAsyncAwait() {
try {
new Function('async function test(){await 1}');
} catch (error) {
return false;
}
return true;
}

function generateProtocolTypesIfNecessary(updated) {
if (!supportsAsyncAwait())
return;
const fs = require('fs');
const path = require('path');
if (!fs.existsSync(path.join(__dirname, 'utils', 'protocol-types-generator')))
Expand Down
2 changes: 1 addition & 1 deletion lib/BrowserFetcher.js
Expand Up @@ -17,8 +17,8 @@
const os = require('os');
const fs = require('fs');
const path = require('path');
const extract = require('extract-zip');
const util = require('util');
const extract = require('extract-zip');
const URL = require('url');
const {helper, assert} = require('./helper');
const removeRecursive = require('rimraf');
Expand Down
1 change: 1 addition & 0 deletions lib/Page.js
Expand Up @@ -31,6 +31,7 @@ const {Worker} = require('./Worker');
const {createJSHandle} = require('./JSHandle');
const {Accessibility} = require('./Accessibility');
const {TimeoutSettings} = require('./TimeoutSettings');

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

class Page extends EventEmitter {
Expand Down
4 changes: 4 additions & 0 deletions lib/helper.js
Expand Up @@ -156,6 +156,10 @@ class Helper {
return typeof obj === 'number' || obj instanceof Number;
}

/**
* @param {function} nodeFunction
* @return {function}
*/
static promisify(nodeFunction) {
function promisified(...args) {
return new Promise((resolve, reject) => {
Expand Down
8 changes: 2 additions & 6 deletions package.json
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"repository": "github:GoogleChrome/puppeteer",
"engines": {
"node": ">=6.4.0"
"node": ">=8.16.0"
},
"puppeteer": {
"chromium_revision": "686378"
Expand All @@ -15,14 +15,11 @@
"funit": "BROWSER=firefox node test/test.js",
"debug-unit": "node --inspect-brk test/test.js",
"test-doclint": "node utils/doclint/check_public_api/test/test.js && node utils/doclint/preprocessor/test.js",
"test": "npm run lint --silent && npm run coverage && npm run test-doclint && npm run test-node6-transformer && npm run test-types && node utils/testrunner/test/test.js",
"test": "npm run lint --silent && npm run coverage && npm run test-doclint && npm run test-types && node utils/testrunner/test/test.js",
"install": "node install.js",
"lint": "([ \"$CI\" = true ] && eslint --quiet -f codeframe . || eslint .) && npm run tsc && npm run doc",
"doc": "node utils/doclint/cli.js",
"coverage": "cross-env COVERAGE=true npm run unit",
"test-node6-transformer": "node utils/node6-transform/test/test.js",
"build": "node utils/node6-transform/index.js && node utils/doclint/generate_types",
"unit-node6": "node node6/test/test.js",
"tsc": "tsc -p .",
"prepublishOnly": "npm run build",
"apply-next-version": "node utils/apply_next_version.js",
Expand Down Expand Up @@ -63,7 +60,6 @@
},
"browser": {
"./lib/BrowserFetcher.js": false,
"./node6/lib/Puppeteer": false,
"ws": "./utils/browser/WebSocket",
"fs": false,
"child_process": false,
Expand Down
15 changes: 3 additions & 12 deletions test/evaluation.spec.js
Expand Up @@ -16,13 +16,6 @@

const utils = require('./utils');

let asyncawait = true;
try {
new Function('async function foo() {await 1}');
} catch (e) {
asyncawait = false;
}

const bigint = typeof BigInt !== 'undefined';

module.exports.addTests = function({testRunner, expect}) {
Expand Down Expand Up @@ -74,14 +67,12 @@ module.exports.addTests = function({testRunner, expect}) {
it_fails_ffox('should return undefined for objects with symbols', async({page, server}) => {
expect(await page.evaluate(() => [Symbol('foo4')])).toBe(undefined);
});
(asyncawait ? it : xit)('should work with function shorthands', async({page, server}) => {
// trick node6 transpiler to not touch our object.
// TODO(lushnikov): remove eval once Node6 is dropped.
const a = eval(`({
it('should work with function shorthands', async({page, server}) => {
const a = {
sum(a, b) { return a + b; },

async mult(a, b) { return a * b; }
})`);
};
expect(await page.evaluate(a.sum, 1, 2)).toBe(3);
expect(await page.evaluate(a.mult, 2, 4)).toBe(8);
});
Expand Down
7 changes: 4 additions & 3 deletions test/headful.spec.js
Expand Up @@ -17,11 +17,12 @@
const path = require('path');
const os = require('os');
const fs = require('fs');
const {helper} = require('../lib/helper');
const rmAsync = helper.promisify(require('rimraf'));
const util = require('util');
const utils = require('./utils');
const {waitEvent} = utils;
const mkdtempAsync = helper.promisify(fs.mkdtemp);

const rmAsync = util.promisify(require('rimraf'));
const mkdtempAsync = util.promisify(fs.mkdtemp);

const TMP_FOLDER = path.join(os.tmpdir(), 'pptr_tmp_folder-');

Expand Down
7 changes: 4 additions & 3 deletions test/launcher.spec.js
Expand Up @@ -233,9 +233,10 @@ module.exports.addTests = function({testRunner, expect, defaultBrowserOptions, p
const browser = await puppeteer.launch(options);
const pages = await browser.pages();
expect(pages.length).toBe(1);
if (pages[0].url() !== server.EMPTY_PAGE)
await pages[0].waitForNavigation();
expect(pages[0].url()).toBe(server.EMPTY_PAGE);
const page = pages[0];
if (page.url() !== server.EMPTY_PAGE)
await page.waitForNavigation();
expect(page.url()).toBe(server.EMPTY_PAGE);
await browser.close();
});
it('should set the default viewport', async() => {
Expand Down

0 comments on commit c98dafe

Please sign in to comment.