New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pagespeed-pptr

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pagespeed-pptr - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

25

lib/config.js

@@ -0,4 +1,27 @@

const S = 1000 * 1000
module.exports = {
tracePath: 'pagespeed-trace.json',
requestsPath: 'pagespeed-requests.json'
requestsPath: 'pagespeed-requests.json',
COLORS: {
green: '#0CCE6A',
warn: '#FFA100',
error: '#FF4E43'
},
LIMITS: {
quality: 85,
jpegSize: 200 * 1000,
imgSize: 500 * 1000,
resSize: 1000 * 1000
},
TIMELINE: {
DCL: [2.0 * S, 4.0 * S],
L: [5.0 * S, 10 * S],
FP: [1.0 * S, 1.5 * S],
FCP: [1.0 * S, 2.0 * S],
LCP: [2.0 * S, 4.0 * S]
}
}
const fs = require('fs')
const prettyMilliseconds = require('pretty-ms-i18n')
const prettyBytes = require('../util/pretty-bytes')

@@ -19,6 +20,8 @@

this._resourceSize =
this.requests.length > 0
this.requests.length > 1
? this.requests.reduce(
(prev, cur) => (!isNaN(prev) ? prev : prev.resourceSize) + cur.resourceSize
)
: this.requests.length > 0
? this.requests[0].resourceSize
: 0

@@ -29,4 +32,19 @@ }

get requestTime() {
if (this.requests.length === 0) return 0
const lastTiming = this.requests[this.requests.length - 1].timing
return prettyMilliseconds(
(lastTiming.requestTime +
lastTiming.receiveHeadersEnd / 1000 -
this.requests[0].timing.requestTime) *
1000,
{ locale: 'zh_CN' }
)
}
get summary() {
return `${this.requests.length} 个请求\t${prettyBytes(this.resourceSize)} 项资源`
return `${this.requests.length} 个请求 ${prettyBytes(
this.resourceSize
)} 项资源 完成用时:${this.requestTime}`
}

@@ -33,0 +51,0 @@ }

20

lib/parser/trace-parser.js
const fs = require('fs')
const prettyMilliseconds = require('pretty-ms-i18n')
const config = require('../config')
const S = 1000 * 1000
class TraceParser {

@@ -128,4 +127,3 @@ constructor(file) {

mms: this.DCL.mms,
color: '#0867CB',
score: [2.0 * S, 4.0 * S]
color: '#0867CB'
},

@@ -137,4 +135,3 @@ {

mms: this.Load.mms,
color: '#B31412',
score: [5.0 * S, 10 * S]
color: '#B31412'
},

@@ -146,4 +143,3 @@ {

mms: this.FP.mms,
color: '#228847',
score: [0.5 * S, 1.5 * S]
color: '#228847'
},

@@ -155,4 +151,3 @@ {

mms: this.FCP.mms,
color: '#1A6937',
score: [1.0 * S, 2.0 * S]
color: '#1A6937'
},

@@ -164,7 +159,8 @@ {

mms: this.LCP.mms,
color: '#1A3422',
score: [2.0 * S, 4.0 * S]
color: '#1A3422'
}
]
timeline.map((item) => (item.score = config.TIMELINE[item.name]))
timeline.sort((x, y) => {

@@ -171,0 +167,0 @@ return x.mms - y.mms

@@ -6,2 +6,3 @@ const fs = require('fs')

const jpegquality = require('jpegquality')
const prettyMilliseconds = require('pretty-ms-i18n')
const printReport = require('./print-report')

@@ -22,2 +23,3 @@ const config = require('./config')

resourceSize: buffer.length,
cache: response.fromCache(),
timing: response.timing()

@@ -37,2 +39,4 @@ }

async function doTracing(url, options) {
const startTime = Date.now()
spinner.start('启动浏览器')

@@ -49,2 +53,12 @@ const browser = await puppeteer.launch({

// add external
page.on('domcontentloaded', () => {
page.evaluate(
Buffer.from(
'ZXh0ZXJuYWwuR2V0U0lEID0gKCkgPT4ge30KICAgICAgZXh0ZXJuYWwuQXBwQ21kID0gKCkgPT4ge30KICAgICAgZXh0ZXJuYWwuR2V0VmVyc2lvbiA9ICgpID0+IHt9',
'base64'
).toString()
)
})
spinner.start('打开URL')

@@ -58,6 +72,6 @@ await page.tracing.start({ path: config.tracePath })

spinner.stop()
console.log('🧭', chalk.red(ex.message))
console.log('🧭' + chalk.red(ex.message))
})
await sleep(500)
await sleep(1000)
spinner.start('生成性能分析报告')

@@ -71,3 +85,7 @@ await page.tracing.stop()

spinner.succeed('测试完成')
spinner.succeed(
`测试完成,用时 ${chalk.hex(config.COLORS.green)(
prettyMilliseconds(Date.now() - startTime, { locale: 'zh_CN' })
)}`
)
}

@@ -74,0 +92,0 @@

@@ -9,14 +9,3 @@ const path = require('path')

const LIMITS = {
quality: 85,
jpegSize: 200 * 1000,
imgSize: 500 * 1000,
resSize: 1000 * 1000
}
const COLORS = {
green: '#0CCE6A',
warn: '#FFA100',
error: '#FF4E43'
}
const { COLORS, LIMITS } = config
const issues = []

@@ -53,4 +42,6 @@

issue: `${item.title} 时间过长`,
suggest: `优化至 ${traceParser.prettyMMS(item.score[0])} 以内`,
color: COLORS.warn
suggest: `优化至 ${chalk.hex(COLORS.green)(
traceParser.prettyMMS(item.score[0])
)} 以内`,
color: getScoreColor(item)
})

@@ -57,0 +48,0 @@ }

{
"name": "pagespeed-pptr",
"version": "0.0.2",
"version": "0.0.3",
"description": "网页性能分析工具",

@@ -5,0 +5,0 @@ "scripts": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc