Comparing version 2.3.3 to 2.3.4
# Change Log | ||
## 2.3.4 | ||
- Removed npm `install` script. From this version, `estimo` won't be looking for or downloading Chrome after npm install. It will be happening on the first launch. | ||
## 2.3.3 | ||
@@ -4,0 +8,0 @@ |
{ | ||
"name": "estimo", | ||
"version": "2.3.3", | ||
"version": "2.3.4", | ||
"description": "Evaluates how long the browser will execute your javascript code", | ||
@@ -13,3 +13,2 @@ "main": "index.js", | ||
"scripts": { | ||
"install": "node ./scripts/find-chrome-binary.js", | ||
"unit": "ava --timeout=4m --exit", | ||
@@ -25,5 +24,5 @@ "test": "eslint . && check-dts && yarn unit", | ||
"commander": "^9.0.0", | ||
"find-chrome-bin": "~0.1.0", | ||
"nanoid": "^3.2.0", | ||
"puppeteer-core": "^13.1.3" | ||
"find-chrome-bin": "0.1.0", | ||
"nanoid": "^3.3.1", | ||
"puppeteer-core": "^13.4.0" | ||
}, | ||
@@ -34,3 +33,3 @@ "devDependencies": { | ||
"check-dts": "^0.6.6", | ||
"eslint": "^8.8.0", | ||
"eslint": "^8.10.0", | ||
"eslint-config-standard": "^16.0.3", | ||
@@ -37,0 +36,0 @@ "eslint-plugin-import": "^2.25.4", |
@@ -5,15 +5,19 @@ const { nanoid } = require('nanoid') | ||
const { resolvePathToTempDir } = require('./utils') | ||
const chromeConfig = require('../chrome.json') | ||
const defaultBrowserOptions = { | ||
headless: true, | ||
timeout: 20000, | ||
executablePath: process.env.PUPPETEER_EXECUTABLE_PATH || chromeConfig.executablePath, | ||
timeout: 20000 | ||
} | ||
const chromeLaunchArgs = ['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage'] | ||
const chromeLaunchArgs = [ | ||
'--no-sandbox', | ||
'--disable-setuid-sandbox', | ||
'--disable-dev-shm-usage' | ||
] | ||
async function createBrowserEntity(options) { | ||
if (options.executablePath.length === 0) { | ||
throw new Error(`Chromium revision is not downloaded. Run "npm install" or "yarn install"`) | ||
throw new Error( | ||
`Chromium revision is not found or downloaded. Check that access to file system is permitted or file an issue here: https://github.com/mbalabash/estimo` | ||
) | ||
} | ||
@@ -28,3 +32,3 @@ | ||
args: chromeLaunchArgs, | ||
ignoreDefaultArgs: ['--disable-extensions'], | ||
ignoreDefaultArgs: ['--disable-extensions'] | ||
} | ||
@@ -55,3 +59,3 @@ if (process.env.ESTIMO_DEBUG) { | ||
width: options.width, | ||
height: options.height, | ||
height: options.height | ||
}) | ||
@@ -67,3 +71,3 @@ } | ||
page.on('error', (msg) => { | ||
page.on('error', msg => { | ||
throw msg | ||
@@ -103,3 +107,3 @@ }) | ||
let pages = await browser.pages() | ||
await Promise.all(pages.map((item) => item.close())) | ||
await Promise.all(pages.map(item => item.close())) | ||
@@ -106,0 +110,0 @@ if (context) { |
@@ -1,5 +0,10 @@ | ||
const { splitResourcesForEstimo, checkEstimoArgs } = require('./utils') | ||
const { | ||
splitResourcesForEstimo, | ||
checkEstimoArgs, | ||
findChromeBinary | ||
} = require('./utils') | ||
const { processor } = require('./processor') | ||
async function estimo(resources = [], browserOptions = {}) { | ||
if (process.env.ESTIMO_DISABLE) process.exit() | ||
checkEstimoArgs(resources, browserOptions) | ||
@@ -9,13 +14,21 @@ let reports = [] | ||
try { | ||
let { executablePath } = await findChromeBinary() | ||
browserOptions.executablePath = executablePath | ||
let { pages, libraries } = splitResourcesForEstimo(resources) | ||
if (libraries.length > 0) { | ||
reports = reports.concat(await processor(libraries, browserOptions, 'js-mode')) | ||
reports = reports.concat( | ||
await processor(libraries, browserOptions, 'js-mode') | ||
) | ||
} | ||
if (pages.length > 0) { | ||
reports = reports.concat(await processor(pages, browserOptions, 'page-mode')) | ||
reports = reports.concat( | ||
await processor(pages, browserOptions, 'page-mode') | ||
) | ||
} | ||
} catch (error) { | ||
console.error(error) | ||
console.log("Please, file an issues related to estimo here: https://github.com/mbalabash/estimo") | ||
} | ||
@@ -22,0 +35,0 @@ |
const fs = require('fs') | ||
const path = require('path') | ||
const { promisify } = require('util') | ||
const puppeteer = require('puppeteer-core') | ||
const { findChrome } = require('find-chrome-bin') | ||
const { | ||
PUPPETEER_REVISIONS | ||
} = require('puppeteer-core/lib/cjs/puppeteer/revisions') | ||
const chromeTempPath = path.join(__dirname, '..', 'temp', 'chrome') | ||
const chromeConfigPath = path.join(__dirname, '..', 'chrome.json') | ||
const write = promisify(fs.writeFile) | ||
@@ -39,3 +47,3 @@ const read = promisify(fs.readFile) | ||
items.forEach((item) => { | ||
items.forEach(item => { | ||
if (isJsFile(item)) { | ||
@@ -67,3 +75,3 @@ libraries.push(item) | ||
} | ||
resources.forEach((item) => { | ||
resources.forEach(item => { | ||
if (typeof item !== 'string') { | ||
@@ -79,3 +87,4 @@ throw new TypeError( | ||
browserOptions === null || | ||
(typeof browserOptions === 'object' && browserOptions.constructor !== Object) | ||
(typeof browserOptions === 'object' && | ||
browserOptions.constructor !== Object) | ||
) { | ||
@@ -108,5 +117,9 @@ throw new TypeError( | ||
const defaultMedianAccessor = (element) => element | ||
const defaultMedianAccessor = element => element | ||
const defaultMedianExecutor = (a, b) => (a + b) / 2 | ||
function median(array, accessor = defaultMedianAccessor, executor = defaultMedianExecutor) { | ||
function median( | ||
array, | ||
accessor = defaultMedianAccessor, | ||
executor = defaultMedianExecutor | ||
) { | ||
let sortedArray = array.sort((a, b) => accessor(a) - accessor(b)) | ||
@@ -127,3 +140,5 @@ let { length } = sortedArray | ||
if (reportA.name !== reportB.name) { | ||
throw new Error('Both the first report name and the second report name should be the same!') | ||
throw new Error( | ||
'Both the first report name and the second report name should be the same!' | ||
) | ||
} | ||
@@ -137,9 +152,18 @@ | ||
styleLayout: calc(reportA.styleLayout, reportB.styleLayout), | ||
paintCompositeRender: calc(reportA.paintCompositeRender, reportB.paintCompositeRender), | ||
scriptParseCompile: calc(reportA.scriptParseCompile, reportB.scriptParseCompile), | ||
paintCompositeRender: calc( | ||
reportA.paintCompositeRender, | ||
reportB.paintCompositeRender | ||
), | ||
scriptParseCompile: calc( | ||
reportA.scriptParseCompile, | ||
reportB.scriptParseCompile | ||
), | ||
scriptEvaluation: calc(reportA.scriptEvaluation, reportB.scriptEvaluation), | ||
javaScript: calc(reportA.javaScript, reportB.javaScript), | ||
garbageCollection: calc(reportA.garbageCollection, reportB.garbageCollection), | ||
garbageCollection: calc( | ||
reportA.garbageCollection, | ||
reportB.garbageCollection | ||
), | ||
other: calc(reportA.other, reportB.other), | ||
total: calc(reportA.total, reportB.total), | ||
total: calc(reportA.total, reportB.total) | ||
} | ||
@@ -199,2 +223,28 @@ } | ||
async function findChromeBinary() { | ||
try { | ||
let configData = JSON.parse(await readFile(chromeConfigPath)) | ||
if (configData.executablePath.length > 0) { | ||
return configData | ||
} | ||
let chromeInfo = await findChrome({ | ||
min: 75, | ||
download: { | ||
puppeteer, | ||
revision: PUPPETEER_REVISIONS.chromium, | ||
path: chromeTempPath | ||
} | ||
}) | ||
await writeFile(chromeConfigPath, JSON.stringify(chromeInfo)) | ||
return chromeInfo | ||
} catch (error) { | ||
console.info() | ||
console.error(error) | ||
console.info() | ||
return { executablePath: '', browser: '' } | ||
} | ||
} | ||
module.exports = { | ||
@@ -205,2 +255,3 @@ splitResourcesForEstimo, | ||
getUrlToHtmlFile, | ||
findChromeBinary, | ||
checkEstimoArgs, | ||
@@ -216,3 +267,3 @@ getLibraryName, | ||
median, | ||
isUrl, | ||
isUrl | ||
} |
@@ -5,4 +5,3 @@ const test = require('ava') | ||
const estimo = require('../src/lib') | ||
const { getUrlToHtmlFile } = require('../src/utils') | ||
const { findChromeBinary } = require('../scripts/find-chrome-binary') | ||
const { getUrlToHtmlFile, findChromeBinary } = require('../src/utils') | ||
const { cleanChromeConfig } = require('../scripts/clean-chrome-config') | ||
@@ -9,0 +8,0 @@ |
@@ -8,19 +8,28 @@ const test = require('ava') | ||
getUrlToHtmlFile, | ||
findChromeBinary, | ||
checkEstimoArgs, | ||
getLibraryName, | ||
createDiff, | ||
readFile, | ||
isJsFile, | ||
isUrl, | ||
isUrl | ||
} = require('../src/utils') | ||
const { cleanChromeConfig } = require('../scripts/clean-chrome-config') | ||
test('[resolvePathToTempDir]: should properly resolve path to file in temp directory', (t) => { | ||
test('[resolvePathToTempDir]: should properly resolve path to file in temp directory', t => { | ||
let fileName = 'someFile.txt' | ||
let customTempDir = '../test/__mock__/' | ||
t.is(resolvePathToTempDir(fileName), path.join(__dirname, '../temp/', fileName)) | ||
t.is( | ||
resolvePathToTempDir(fileName), | ||
path.join(__dirname, '../temp/', fileName) | ||
) | ||
t.is(resolvePathToTempDir(fileName, customTempDir), path.join(__dirname, customTempDir, fileName)) | ||
t.is( | ||
resolvePathToTempDir(fileName, customTempDir), | ||
path.join(__dirname, customTempDir, fileName) | ||
) | ||
}) | ||
test('[getUrlToHtmlFile]: should properly generate url to local file', (t) => { | ||
test('[getUrlToHtmlFile]: should properly generate url to local file', t => { | ||
let fileName = 'index.html' | ||
@@ -33,3 +42,3 @@ t.is( | ||
test('[createDiff]: should properly create diff', async (t) => { | ||
test('[createDiff]: should properly create diff', async t => { | ||
t.is(createDiff(100894, 110894), '-9.92% 🔽') | ||
@@ -42,3 +51,3 @@ t.is(createDiff(0.2021099999999999, 0.10210999999999999), '+49.48% 🔺') | ||
test('[getLibraryName]: should properly extract library name', async (t) => { | ||
test('[getLibraryName]: should properly extract library name', async t => { | ||
t.is(getLibraryName('http://qwe.asd/myLib.js'), 'myLib.js') | ||
@@ -53,3 +62,3 @@ t.is(getLibraryName('http://qwe.asd/myLib/some/dir/lib.js'), 'lib.js') | ||
test('[isJsFile]: should properly detect js file names', async (t) => { | ||
test('[isJsFile]: should properly detect js file names', async t => { | ||
t.is(isJsFile('http://qwe.asd/myLib.js'), true) | ||
@@ -65,3 +74,3 @@ t.is(isJsFile('https://qwe.asd/myLib.js'), true) | ||
test("[isUrl]: should properly detect web url's", async (t) => { | ||
test("[isUrl]: should properly detect web url's", async t => { | ||
t.is(isUrl('http://qwe.asd/myLib.js'), true) | ||
@@ -77,17 +86,23 @@ t.is(isUrl('https://qwe.asd/myLib.js'), true) | ||
test("[splitResourcesForEstimo]: should properly split input to js files and non-js web url's", async (t) => { | ||
t.deepEqual(splitResourcesForEstimo(['https://qwe.asd/myLib.js', 'index.js']), { | ||
pages: [], | ||
libraries: ['https://qwe.asd/myLib.js', 'index.js'], | ||
}) | ||
test("[splitResourcesForEstimo]: should properly split input to js files and non-js web url's", async t => { | ||
t.deepEqual( | ||
splitResourcesForEstimo(['https://qwe.asd/myLib.js', 'index.js']), | ||
{ | ||
pages: [], | ||
libraries: ['https://qwe.asd/myLib.js', 'index.js'] | ||
} | ||
) | ||
t.deepEqual(splitResourcesForEstimo(['http://qwe.asd/myLib.js']), { | ||
pages: [], | ||
libraries: ['http://qwe.asd/myLib.js'], | ||
libraries: ['http://qwe.asd/myLib.js'] | ||
}) | ||
t.deepEqual(splitResourcesForEstimo(['http://example.com/', 'https://example.com/']), { | ||
pages: ['http://example.com/', 'https://example.com/'], | ||
libraries: [], | ||
}) | ||
t.deepEqual( | ||
splitResourcesForEstimo(['http://example.com/', 'https://example.com/']), | ||
{ | ||
pages: ['http://example.com/', 'https://example.com/'], | ||
libraries: [] | ||
} | ||
) | ||
@@ -99,7 +114,7 @@ t.deepEqual( | ||
'http://qwe.asd/myLib.js', | ||
'index.js', | ||
'index.js' | ||
]), | ||
{ | ||
pages: ['http://qwe.asd/qwe.css', 'https://qwe.asd/zxc.html'], | ||
libraries: ['http://qwe.asd/myLib.js', 'index.js'], | ||
libraries: ['http://qwe.asd/myLib.js', 'index.js'] | ||
} | ||
@@ -110,3 +125,5 @@ ) | ||
let error = t.throws(() => splitResourcesForEstimo(['ftp://domain.to/', 'qwe/asd/'])) | ||
let error = t.throws(() => | ||
splitResourcesForEstimo(['ftp://domain.to/', 'qwe/asd/']) | ||
) | ||
t.is( | ||
@@ -118,3 +135,3 @@ error.message, | ||
test('[checkEstimoArgs]: should properly handle input args', async (t) => { | ||
test('[checkEstimoArgs]: should properly handle input args', async t => { | ||
t.is( | ||
@@ -167,1 +184,18 @@ t.throws(() => checkEstimoArgs(123)).message, | ||
}) | ||
test('should set location setting for downloaded or local chrome', async t => { | ||
let chromeInfo = await findChromeBinary() | ||
let configData = JSON.parse( | ||
await readFile(path.join(__dirname, '..', 'chrome.json')) | ||
) | ||
t.is( | ||
typeof chromeInfo === 'object' && Object.keys(chromeInfo).length === 2, | ||
true | ||
) | ||
t.is(configData.browser.length > 0, true) | ||
t.is(configData.executablePath.length > 0, true) | ||
t.is(configData.executablePath === chromeInfo.executablePath, true) | ||
await cleanChromeConfig() | ||
}) |
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
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
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
439230
17101
0
5
33
Updatedfind-chrome-bin@0.1.0
Updatednanoid@^3.3.1
Updatedpuppeteer-core@^13.4.0