From 1ef67ceae8ff47c5be0af79e88ff89c2a1239be0 Mon Sep 17 00:00:00 2001 From: Sparticuz Date: Fri, 30 Dec 2022 11:27:52 -0500 Subject: [PATCH 1/3] Cleanup old node versions --- package.json | 4 ++-- source/index.ts | 12 ++++++------ source/lambdafs.ts | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index cddb2d5..88fd127 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "build" ], "engines": { - "node": ">= 14" + "node": ">= 14.18.0" }, "scripts": { "test": "make clean && make && make pretest && make test", @@ -23,7 +23,7 @@ "preversion": "npm run build" }, "devDependencies": { - "@types/node": "^16.11.62", + "@types/node": "^18.11.18", "@types/tar-fs": "^2.0.1", "clean-modules": "^2.0.6", "typescript": "^4.8.3" diff --git a/source/index.ts b/source/index.ts index 3f74607..0cc3d09 100644 --- a/source/index.ts +++ b/source/index.ts @@ -1,8 +1,8 @@ -import { access, createWriteStream, existsSync, mkdirSync, symlink } from 'fs'; -import { IncomingMessage } from 'http'; +import { access, createWriteStream, existsSync, mkdirSync, symlink } from 'node:fs'; +import { IncomingMessage } from 'node:http'; import LambdaFS from './lambdafs'; -import { join } from 'path'; -import { URL } from 'url'; +import { join } from 'node:path'; +import { URL } from 'node:url'; /** Viewport taken from https://github.com/puppeteer/puppeteer/blob/main/docs/api/puppeteer.viewport.md */ interface Viewport { @@ -37,7 +37,7 @@ interface Viewport { hasTouch?: boolean; } -if (/^AWS_Lambda_nodejs(?:10|12|14|16|18)[.]x$/.test(process.env.AWS_EXECUTION_ENV) === true) { +if ( process.env.AWS_EXECUTION_ENV !== undefined && /^AWS_Lambda_nodejs(?:14|16|18)[.]x$/.test(process.env.AWS_EXECUTION_ENV) === true) { if (process.env.FONTCONFIG_PATH === undefined) { process.env.FONTCONFIG_PATH = '/tmp/aws'; } @@ -208,7 +208,7 @@ class Chromium { LambdaFS.inflate(`${input}/swiftshader.tar.br`), ]; - if (/^AWS_Lambda_nodejs(?:10|12|14|16|18)[.]x$/.test(process.env.AWS_EXECUTION_ENV) === true) { + if (process.env.AWS_EXECUTION_ENV !== undefined && /^AWS_Lambda_nodejs(?:14|16|18)[.]x$/.test(process.env.AWS_EXECUTION_ENV) === true) { promises.push(LambdaFS.inflate(`${input}/aws.tar.br`)); } diff --git a/source/lambdafs.ts b/source/lambdafs.ts index f0cb1f8..de95eab 100644 --- a/source/lambdafs.ts +++ b/source/lambdafs.ts @@ -1,8 +1,8 @@ -import { createReadStream, createWriteStream, existsSync } from 'fs'; -import { tmpdir } from 'os'; -import { basename, join } from 'path'; +import { createReadStream, createWriteStream, existsSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { basename, join } from 'node:path'; import { extract } from 'tar-fs'; -import { createBrotliDecompress, createUnzip } from 'zlib'; +import { createBrotliDecompress, createUnzip } from 'node:zlib'; class LambdaFS { /** From 9578aa01544164d0eaa50f6dbe640807827090e0 Mon Sep 17 00:00:00 2001 From: Sparticuz Date: Fri, 30 Dec 2022 11:28:32 -0500 Subject: [PATCH 2/3] Cleanup typescript and lint --- package.json | 2 +- source/index.ts | 8 ++++---- tsconfig.json | 25 +------------------------ 3 files changed, 6 insertions(+), 29 deletions(-) diff --git a/package.json b/package.json index 88fd127..7a559dd 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "@types/node": "^18.11.18", "@types/tar-fs": "^2.0.1", "clean-modules": "^2.0.6", - "typescript": "^4.8.3" + "typescript": "^4.9.4" }, "bugs": { "url": "https://github.com/Sparticuz/chromium/issues" diff --git a/source/index.ts b/source/index.ts index 0cc3d09..b2e1209 100644 --- a/source/index.ts +++ b/source/index.ts @@ -76,7 +76,7 @@ class Chromium { const output = `${process.env.HOME}/.fonts/${url.pathname.split('/').pop()}`; if (existsSync(output) === true) { - return resolve(output.split('/').pop()); + return resolve(output.split('/').pop() as string); } if (url.protocol === 'file:') { @@ -86,7 +86,7 @@ class Chromium { } symlink(url.pathname, output, (error) => { - return error != null ? reject(error) : resolve(url.pathname.split('/').pop()); + return error != null ? reject(error) : resolve(url.pathname.split('/').pop() as string); }); }); } else { @@ -109,7 +109,7 @@ class Chromium { response.once('end', () => { stream.end(() => { - return resolve(url.pathname.split('/').pop()); + return resolve(url.pathname.split('/').pop() as string); }); }); }); @@ -213,7 +213,7 @@ class Chromium { } const result = await Promise.all(promises); - return result.shift(); + return result.shift() as string; } /** diff --git a/tsconfig.json b/tsconfig.json index 3f3541d..24d1ae7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,41 +1,18 @@ { - "compileOnSave": false, "compilerOptions": { - "alwaysStrict": true, "declaration": true, "declarationDir": "build", - "emitDecoratorMetadata": true, "esModuleInterop": true, - "experimentalDecorators": true, "forceConsistentCasingInFileNames": true, - "importHelpers": false, - "inlineSourceMap": false, "lib": ["dom", "es2020"], - "listEmittedFiles": false, - "listFiles": false, "module": "commonjs", "moduleResolution": "node", - "noFallthroughCasesInSwitch": true, - "noImplicitAny": true, - "noImplicitReturns": true, - "noImplicitThis": true, - "noUnusedLocals": false, - "noUnusedParameters": false, "outDir": "build", "pretty": true, - "resolveJsonModule": true, "skipLibCheck": true, - "sourceMap": true, "strict": true, - "strictFunctionTypes": true, - "strictNullChecks": false, "target": "es2020", - "traceResolution": false, - "types": ["node"] }, "exclude": ["build", "node_modules", "tmp"], - "include": ["source"], - "typeAcquisition": { - "enable": true - } + "include": ["source"] } From 03ec7424023cefdc276f273a1a92e148bbb7c698 Mon Sep 17 00:00:00 2001 From: Sparticuz Date: Fri, 30 Dec 2022 11:28:52 -0500 Subject: [PATCH 3/3] font should return a promise with null here, instead of just null --- source/index.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/source/index.ts b/source/index.ts index b2e1209..b7c7769 100644 --- a/source/index.ts +++ b/source/index.ts @@ -52,11 +52,13 @@ if ( process.env.AWS_EXECUTION_ENV !== undefined && /^AWS_Lambda_nodejs(?:14|16| class Chromium { /** * Downloads or symlinks a custom font and returns its basename, patching the environment so that Chromium can find it. - * If not running on AWS Lambda nor Google Cloud Functions, `null` is returned instead. + * If headless is not true, `null` is returned instead. */ - static font(input: string): Promise { + static font(input: string): Promise { if (Chromium.headless !== true) { - return null; + return new Promise((resolve) => { + return resolve(null); + }); } if (process.env.HOME === undefined) {