@checkly/chrome-aws-lambda
Advanced tools
Comparing version 99.0.484-4.16 to 99.0.484-4.16-2
@@ -5,7 +5,2 @@ /// <reference path="../typings/chrome-aws-lambda.d.ts" /> | ||
/** | ||
* 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. | ||
*/ | ||
static font(input: string): Promise<string>; | ||
/** | ||
* Returns a list of additional Chromium flags recommended for serverless environments. | ||
@@ -19,8 +14,12 @@ * The canonical list of flags can be found on https://peter.sh/experiments/chromium-command-line-switches/. | ||
static get defaultViewport(): Required<Viewport>; | ||
static prepare(folder: string): Promise<{ | ||
config: { | ||
fontConfigPath: string; | ||
awsLibrarPath: string; | ||
}; | ||
chromium: { | ||
path: string; | ||
}; | ||
}>; | ||
/** | ||
* Inflates the current version of Chromium and returns the path to the binary. | ||
* If not running on AWS Lambda nor Google Cloud Functions, `null` is returned instead. | ||
*/ | ||
static get executablePath(): Promise<string>; | ||
/** | ||
* Returns a boolean indicating if we are running on AWS Lambda or Google Cloud Functions. | ||
@@ -27,0 +26,0 @@ * False is returned if Serverless environment variables `IS_LOCAL` or `IS_OFFLINE` are set. |
"use strict"; | ||
/// <reference path="../typings/chrome-aws-lambda.d.ts" /> | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
const fs_1 = require("fs"); | ||
const lambdafs_1 = __importDefault(require("lambdafs")); | ||
const path_1 = require("path"); | ||
const url_1 = require("url"); | ||
if (/^AWS_Lambda_nodejs(?:10|12|14)[.]x$/.test(process.env.AWS_EXECUTION_ENV) === true) { | ||
if (process.env.FONTCONFIG_PATH === undefined) { | ||
process.env.FONTCONFIG_PATH = '/tmp/aws'; | ||
} | ||
if (process.env.LD_LIBRARY_PATH === undefined) { | ||
process.env.LD_LIBRARY_PATH = '/tmp/aws/lib'; | ||
} | ||
else if (process.env.LD_LIBRARY_PATH.startsWith('/tmp/aws/lib') !== true) { | ||
process.env.LD_LIBRARY_PATH = [...new Set(['/tmp/aws/lib', ...process.env.LD_LIBRARY_PATH.split(':')])].join(':'); | ||
} | ||
} | ||
const util_1 = require("./util"); | ||
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. | ||
*/ | ||
static font(input) { | ||
if (Chromium.headless !== true) { | ||
return null; | ||
} | ||
if (process.env.HOME === undefined) { | ||
process.env.HOME = '/tmp'; | ||
} | ||
if (fs_1.existsSync(`${process.env.HOME}/.fonts`) !== true) { | ||
fs_1.mkdirSync(`${process.env.HOME}/.fonts`); | ||
} | ||
return new Promise((resolve, reject) => { | ||
if (/^https?:[/][/]/i.test(input) !== true) { | ||
input = `file://${input}`; | ||
} | ||
const url = new url_1.URL(input); | ||
const output = `${process.env.HOME}/.fonts/${url.pathname.split('/').pop()}`; | ||
if (fs_1.existsSync(output) === true) { | ||
return resolve(output.split('/').pop()); | ||
} | ||
if (url.protocol === 'file:') { | ||
fs_1.access(url.pathname, (error) => { | ||
if (error != null) { | ||
return reject(error); | ||
} | ||
fs_1.symlink(url.pathname, output, (error) => { | ||
return error != null ? reject(error) : resolve(url.pathname.split('/').pop()); | ||
}); | ||
}); | ||
} | ||
else { | ||
let handler = url.protocol === 'http:' ? require('http').get : require('https').get; | ||
handler(input, (response) => { | ||
if (response.statusCode !== 200) { | ||
return reject(`Unexpected status code: ${response.statusCode}.`); | ||
} | ||
const stream = fs_1.createWriteStream(output); | ||
stream.once('error', (error) => { | ||
return reject(error); | ||
}); | ||
response.on('data', (chunk) => { | ||
stream.write(chunk); | ||
}); | ||
response.once('end', () => { | ||
stream.end(() => { | ||
return resolve(url.pathname.split('/').pop()); | ||
}); | ||
}); | ||
}); | ||
} | ||
}); | ||
} | ||
/** | ||
* Returns a list of additional Chromium flags recommended for serverless environments. | ||
@@ -127,27 +57,33 @@ * The canonical list of flags can be found on https://peter.sh/experiments/chromium-command-line-switches/. | ||
} | ||
/** | ||
* Inflates the current version of Chromium and returns the path to the binary. | ||
* If not running on AWS Lambda nor Google Cloud Functions, `null` is returned instead. | ||
*/ | ||
static get executablePath() { | ||
if (Chromium.headless !== true) { | ||
return Promise.resolve(null); | ||
} | ||
if (fs_1.existsSync('/tmp/chromium') === true) { | ||
for (const file of fs_1.readdirSync('/tmp')) { | ||
static async prepare(folder) { | ||
await fs_1.promises.mkdir(folder, { recursive: true, mode: 0o777 }); | ||
const chromiumExpectedPath = path_1.join(folder, 'chromium'); | ||
if (await util_1.fileExists(chromiumExpectedPath)) { | ||
const files = await fs_1.promises.readdir(folder); | ||
for (const file of files) { | ||
if (file.startsWith('core.chromium') === true) { | ||
fs_1.unlinkSync(`/tmp/${file}`); | ||
await fs_1.promises.unlink(path_1.join(folder, file)); | ||
} | ||
} | ||
return Promise.resolve('/tmp/chromium'); | ||
} | ||
const input = path_1.join(__dirname, '..', 'bin'); | ||
const promises = [ | ||
lambdafs_1.default.inflate(`${input}/chromium.br`), | ||
lambdafs_1.default.inflate(`${input}/swiftshader.tar.br`) | ||
]; | ||
if (/^AWS_Lambda_nodejs(?:10|12|14)[.]x$/.test(process.env.AWS_EXECUTION_ENV) === true) { | ||
promises.push(lambdafs_1.default.inflate(`${input}/aws.tar.br`)); | ||
else { | ||
const input = path_1.join(__dirname, '..', 'bin'); | ||
const promises = [ | ||
util_1.inflate(folder, `${input}/chromium.br`), | ||
util_1.inflate(folder, `${input}/swiftshader.tar.br`), | ||
util_1.inflate(folder, `${input}/aws.tar.br`), | ||
]; | ||
const awsFolder = path_1.join(folder, 'aws'); | ||
await Promise.all(promises); | ||
await fs_1.promises.writeFile(path_1.join(awsFolder, 'fonts.conf'), util_1.fontConfig(awsFolder), { encoding: 'utf8', mode: 0o700 }); | ||
} | ||
return Promise.all(promises).then((result) => result.shift()); | ||
return { | ||
config: { | ||
fontConfigPath: path_1.join(folder, 'aws'), | ||
awsLibrarPath: path_1.join(folder, 'aws', 'lib'), | ||
}, | ||
chromium: { | ||
path: chromiumExpectedPath | ||
} | ||
}; | ||
} | ||
@@ -154,0 +90,0 @@ /** |
{ | ||
"name": "@checkly/chrome-aws-lambda", | ||
"private": false, | ||
"version": "99.0.4844.16", | ||
"version": "99.0.4844.16-2", | ||
"author": { | ||
@@ -28,6 +28,7 @@ "name": "Alix Axel" | ||
"dependencies": { | ||
"lambdafs": "^2.0.3" | ||
"tar-fs": "^2.1.1" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^10.17.55", | ||
"@types/tar-fs": "^2.0.1", | ||
"playwright-core": "^1.16.2", | ||
@@ -34,0 +35,0 @@ "puppeteer-core": "^10.1.0", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 4 instances in 1 package
51162198
52
1824
7
4
6
+ Addedtar-fs@^2.1.1
+ Addedmkdirp-classic@0.5.3(transitive)
+ Addedtar-fs@2.1.1(transitive)
- Removedlambdafs@^2.0.3
- Removedlambdafs@2.1.1(transitive)