diff --git a/source/helper.ts b/source/helper.ts index d6c87c1..fa19998 100644 --- a/source/helper.ts +++ b/source/helper.ts @@ -17,6 +17,10 @@ export const isValidUrl = (input: string) => { } }; +export const isRunningInAwsLambda = () => + process.env.AWS_EXECUTION_ENV && + /^AWS_Lambda_nodejs/.test(process.env.AWS_EXECUTION_ENV) === true; + export const downloadAndExtract = async (url: string) => new Promise((resolve, reject) => { const getOptions = parse(url) as FollowRedirOptions; diff --git a/source/index.ts b/source/index.ts index 924b464..b2dd265 100644 --- a/source/index.ts +++ b/source/index.ts @@ -9,7 +9,7 @@ import { https } from "follow-redirects"; import LambdaFS from "./lambdafs"; import { join } from "node:path"; import { URL } from "node:url"; -import { downloadAndExtract, isValidUrl } from "./helper"; +import { downloadAndExtract, isRunningInAwsLambda, isValidUrl } from "./helper"; /** Viewport taken from https://github.com/puppeteer/puppeteer/blob/main/docs/api/puppeteer.viewport.md */ interface Viewport { @@ -44,10 +44,7 @@ interface Viewport { hasTouch?: boolean; } -if ( - process.env.AWS_EXECUTION_ENV !== undefined && - /^AWS_Lambda_nodejs/.test(process.env.AWS_EXECUTION_ENV) === true -) { +if (isRunningInAwsLambda()) { if (process.env.FONTCONFIG_PATH === undefined) { process.env.FONTCONFIG_PATH = "/tmp/aws"; } @@ -295,10 +292,7 @@ class Chromium { promises.push(LambdaFS.inflate(`${input}/swiftshader.tar.br`)); } - if ( - process.env.AWS_EXECUTION_ENV !== undefined && - /^AWS_Lambda_nodejs/.test(process.env.AWS_EXECUTION_ENV) === true - ) { + if (isRunningInAwsLambda()) { promises.push(LambdaFS.inflate(`${input}/aws.tar.br`)); }