Skip to content

Commit

Permalink
chore(export): upgrade puppeteer and chromium for Node 18 support
Browse files Browse the repository at this point in the history
Vercel disables Node 14 support on 15 Aug 2023, and Node 16 support on 6
Feb 2024. Let's future-proof and not worry about this for a while by
supporting Node 18.

References for migration to @sparticuz/chromium:
* alixaxel/chrome-aws-lambda#275
* https://github.com/Sparticuz/chrome-aws-lambda
* https://github.com/Sparticuz/chromium#migration-from-chrome-aws-lambda

References for upgrading puppeteer:
* https://pptr.dev/chromium-support

References for prior Node upgrades:
* #3417
* #3414
  • Loading branch information
zwliew committed Aug 5, 2023
1 parent 1dc79ba commit 0fca671
Show file tree
Hide file tree
Showing 6 changed files with 551 additions and 164 deletions.
7 changes: 3 additions & 4 deletions export/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
},
"dependencies": {
"@sentry/node": "5.30.0",
"@sparticuz/chromium": "115.0.0",
"axios": "0.21.2",
"bunyan": "1.8.15",
"chrome-aws-lambda": "~6.0.0",
"fs-extra": "9.1.0",
"http-graceful-shutdown": "2.3.2",
"koa": "2.13.1",
Expand All @@ -29,7 +29,7 @@
"lodash": "4.17.21",
"nodemon": "2.0.9",
"pug": "3.0.2",
"puppeteer-core": "5.5.0"
"puppeteer-core": "21.0.1"
},
"devDependencies": {
"@types/fs-extra": "9.0.13",
Expand All @@ -39,13 +39,12 @@
"@types/lodash": "4.14.196",
"@types/node": "18.17.2",
"@types/pug": "2.0.6",
"@types/puppeteer": "^5.4.7",
"@vercel/node": "1.9.0",
"cross-env": "7.0.3",
"dotenv": "8.2.0",
"npm-run-all": "4.1.5",
"prettier": "2.8.8",
"puppeteer": "~6.0.0",
"puppeteer": "21.0.1",
"typescript": "5.1.6"
}
}
2 changes: 1 addition & 1 deletion export/src/handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Sentry from '@sentry/node';
import type { NowApiHandler, NowRequest, NowResponse } from '@vercel/node';
import type { Page } from 'puppeteer';
import type { Page } from 'puppeteer-core';

import * as render from './render-serverless';
import config from './config';
Expand Down
8 changes: 4 additions & 4 deletions export/src/render-serverless.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import chromium from 'chrome-aws-lambda';
import type { Page } from 'puppeteer';
import chromium from '@sparticuz/chromium';
import puppeteer, { Page } from 'puppeteer-core';

import { getModules } from './data';
import config from './config';
Expand All @@ -23,11 +23,11 @@ async function setViewport(page: Page, options: ViewportOptions = {}) {
}

export async function open(url: string) {
const browser = await chromium.puppeteer.launch({
const browser = await puppeteer.launch({
// devtools: !!process.env.DEVTOOLS, // TODO: Query string && NODE_ENV === 'development'?
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath,
executablePath: await chromium.executablePath(),
headless: chromium.headless,
});

Expand Down
2 changes: 1 addition & 1 deletion export/src/render.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs-extra';
import puppeteer, { Page } from 'puppeteer';
import puppeteer, { Page } from 'puppeteer-core';
import type { Middleware } from 'koa';

import { getModules } from './data';
Expand Down
2 changes: 1 addition & 1 deletion export/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Page } from 'puppeteer';
import type { Page } from 'puppeteer-core';

export type TimetableOrientation = 'HORIZONTAL' | 'VERTICAL';

Expand Down
Loading

0 comments on commit 0fca671

Please sign in to comment.