@jsenv/lighthouse-impact 4.0.4 → 4.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -33,26 +33,26 @@ _lighthouse.mjs_
33
33
  * - It starts a local server serving a single basic HTML file
34
34
  * - It is meant to be modified to use your own server and website files
35
35
  */
36
- import { chromium } from "playwright"
37
- import { createServer } from "node:http"
38
- import { readFileSync } from "node:fs"
39
- import { runLighthouseOnPlaywrightPage } from "@jsenv/lighthouse-impact"
36
+ import { chromium } from "playwright";
37
+ import { createServer } from "node:http";
38
+ import { readFileSync } from "node:fs";
39
+ import { runLighthouseOnPlaywrightPage } from "@jsenv/lighthouse-impact";
40
40
 
41
- const htmlFileUrl = new URL("./index.html", import.meta.url)
42
- const html = String(readFileSync(htmlFileUrl))
41
+ const htmlFileUrl = new URL("./index.html", import.meta.url);
42
+ const html = String(readFileSync(htmlFileUrl));
43
43
 
44
44
  const server = createServer((request, response) => {
45
45
  response.writeHead(200, {
46
46
  "content-type": "text/html",
47
- })
48
- response.end(html)
49
- })
50
- server.listen(8080)
51
- server.unref()
47
+ });
48
+ response.end(html);
49
+ });
50
+ server.listen(8080);
51
+ server.unref();
52
52
 
53
53
  const browser = await chromium.launch({
54
54
  args: ["--remote-debugging-port=9222"],
55
- })
55
+ });
56
56
  const browserContext = await browser.newContext({
57
57
  // userAgent: "",
58
58
  ignoreHTTPSErrors: true,
@@ -67,13 +67,13 @@ const browserContext = await browser.newContext({
67
67
  hasTouch: true,
68
68
  isMobile: true,
69
69
  deviceScaleFactor: 1,
70
- })
71
- const page = await browserContext.newPage()
72
- await page.goto(server.origin)
70
+ });
71
+ const page = await browserContext.newPage();
72
+ await page.goto(server.origin);
73
73
 
74
74
  export const lighthouseReport = await runLighthouseOnPlaywrightPage(page, {
75
75
  chromiumPort: 9222,
76
- })
76
+ });
77
77
  ```
78
78
 
79
79
  _index.html_
@@ -144,7 +144,7 @@ _report_lighthouse_impact.mjs_
144
144
  import {
145
145
  reportLighthouseImpactInGithubPullRequest,
146
146
  readGitHubWorkflowEnv,
147
- } from "@jsenv/lighthouse-impact"
147
+ } from "@jsenv/lighthouse-impact";
148
148
 
149
149
  await reportLighthouseImpactInGithubPullRequest({
150
150
  ...readGitHubWorkflowEnv(),
@@ -152,7 +152,7 @@ await reportLighthouseImpactInGithubPullRequest({
152
152
  "./lighthouse.mjs#lighthouseReport",
153
153
  import.meta.url,
154
154
  ),
155
- })
155
+ });
156
156
  ```
157
157
 
158
158
  ## Other tools
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/lighthouse-impact",
3
- "version": "4.0.4",
3
+ "version": "4.0.5",
4
4
  "description": "Package description",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -37,9 +37,9 @@
37
37
  "dependencies": {
38
38
  "@jsenv/abort": "4.2.4",
39
39
  "@jsenv/dynamic-import-worker": "1.1.0",
40
- "@jsenv/filesystem": "4.2.3",
40
+ "@jsenv/filesystem": "4.3.2",
41
41
  "@jsenv/github-pull-request-impact": "1.7.2",
42
- "@jsenv/log": "3.3.4",
42
+ "@jsenv/log": "3.4.0",
43
43
  "lighthouse": "10.2.0"
44
44
  }
45
45
  }
@@ -1,8 +1,8 @@
1
1
  // https://github.com/GoogleChrome/lighthouse/blob/5a14deb5c4e0ec4e8e58f50ff72b53851b021bcf/docs/readme.md#using-programmatically
2
2
 
3
- import { assertAndNormalizeFileUrl, writeFileSync } from "@jsenv/filesystem"
4
- import { createLogger } from "@jsenv/log"
5
- import { Abort, raceProcessTeardownEvents } from "@jsenv/abort"
3
+ import { assertAndNormalizeFileUrl, writeFileSync } from "@jsenv/filesystem";
4
+ import { createLogger } from "@jsenv/log";
5
+ import { Abort, raceProcessTeardownEvents } from "@jsenv/abort";
6
6
 
7
7
  import {
8
8
  runLighthouse,
@@ -10,7 +10,7 @@ import {
10
10
  formatReportAsSummaryText,
11
11
  formatReportAsJson,
12
12
  formatReportAsHtml,
13
- } from "./lighthouse_api.js"
13
+ } from "./lighthouse_api.js";
14
14
 
15
15
  export const generateLighthouseReport = async (
16
16
  url,
@@ -49,11 +49,11 @@ export const generateLighthouseReport = async (
49
49
  if (chromiumDebuggingPort === undefined) {
50
50
  throw new Error(
51
51
  `"chromiumDebuggingPort" is required, got ${chromiumDebuggingPort}`,
52
- )
52
+ );
53
53
  }
54
54
 
55
- const generateReportOperation = Abort.startOperation()
56
- generateReportOperation.addAbortSignal(signal)
55
+ const generateReportOperation = Abort.startOperation();
56
+ generateReportOperation.addAbortSignal(signal);
57
57
  if (handleSIGINT) {
58
58
  generateReportOperation.addAbortSource((abort) => {
59
59
  return raceProcessTeardownEvents(
@@ -61,14 +61,14 @@ export const generateLighthouseReport = async (
61
61
  SIGINT: true,
62
62
  },
63
63
  abort,
64
- )
65
- })
64
+ );
65
+ });
66
66
  }
67
67
 
68
68
  const jsenvGenerateLighthouseReport = async () => {
69
- const logger = createLogger({ logLevel })
69
+ const logger = createLogger({ logLevel });
70
70
  if (generateReportOperation.signal.aborted) {
71
- return { aborted: true }
71
+ return { aborted: true };
72
72
  }
73
73
  const lighthouseOptions = {
74
74
  extends: "lighthouse:default",
@@ -86,56 +86,56 @@ export const generateLighthouseReport = async (
86
86
  emulatedUserAgent,
87
87
  ...lighthouseSettings,
88
88
  },
89
- }
90
- const reports = []
89
+ };
90
+ const reports = [];
91
91
  try {
92
92
  await Array(runCount)
93
93
  .fill()
94
94
  .reduce(async (previous, _, index) => {
95
- generateReportOperation.throwIfAborted()
96
- await previous
95
+ generateReportOperation.throwIfAborted();
96
+ await previous;
97
97
  if (index > 0 && delayBetweenEachRun) {
98
98
  await new Promise((resolve) =>
99
99
  setTimeout(resolve, delayBetweenEachRun),
100
- )
100
+ );
101
101
  }
102
- generateReportOperation.throwIfAborted()
103
- const report = await runLighthouse(url, lighthouseOptions)
104
- reports.push(report)
105
- }, Promise.resolve())
102
+ generateReportOperation.throwIfAborted();
103
+ const report = await runLighthouse(url, lighthouseOptions);
104
+ reports.push(report);
105
+ }, Promise.resolve());
106
106
  } catch (e) {
107
107
  if (Abort.isAbortError(e)) {
108
- return { aborted: true }
108
+ return { aborted: true };
109
109
  }
110
- throw e
110
+ throw e;
111
111
  }
112
112
 
113
- const lighthouseReport = await reduceToMedianReport(reports)
113
+ const lighthouseReport = await reduceToMedianReport(reports);
114
114
  if (log) {
115
- logger.info(formatReportAsSummaryText(lighthouseReport))
115
+ logger.info(formatReportAsSummaryText(lighthouseReport));
116
116
  }
117
117
  if (jsonFileUrl) {
118
- assertAndNormalizeFileUrl(jsonFileUrl)
119
- const json = formatReportAsJson(lighthouseReport)
120
- writeFileSync(jsonFileUrl, json)
118
+ assertAndNormalizeFileUrl(jsonFileUrl);
119
+ const json = formatReportAsJson(lighthouseReport);
120
+ writeFileSync(jsonFileUrl, json);
121
121
  if (jsonFileLog) {
122
- logger.info(`-> ${jsonFileUrl}`)
122
+ logger.info(`-> ${jsonFileUrl}`);
123
123
  }
124
124
  }
125
125
  if (htmlFileUrl) {
126
- assertAndNormalizeFileUrl(htmlFileUrl)
127
- const html = await formatReportAsHtml(lighthouseReport)
128
- writeFileSync(htmlFileUrl, html)
126
+ assertAndNormalizeFileUrl(htmlFileUrl);
127
+ const html = await formatReportAsHtml(lighthouseReport);
128
+ writeFileSync(htmlFileUrl, html);
129
129
  if (htmlFileLog) {
130
- logger.info(`-> ${htmlFileUrl}`)
130
+ logger.info(`-> ${htmlFileUrl}`);
131
131
  }
132
132
  }
133
- return lighthouseReport
134
- }
133
+ return lighthouseReport;
134
+ };
135
135
 
136
136
  try {
137
- return await jsenvGenerateLighthouseReport()
137
+ return await jsenvGenerateLighthouseReport();
138
138
  } finally {
139
- await generateReportOperation.end()
139
+ await generateReportOperation.end();
140
140
  }
141
- }
141
+ };
@@ -1,42 +1,44 @@
1
1
  export const runLighthouse = async (url, lighthouseOptions) => {
2
- const { default: lighthouse } = await import("lighthouse")
3
- const results = await lighthouse(url, undefined, lighthouseOptions)
2
+ const { default: lighthouse } = await import("lighthouse");
3
+ const results = await lighthouse(url, undefined, lighthouseOptions);
4
4
  // use results.lhr for the JS-consumeable output
5
5
  // https://github.com/GoogleChrome/lighthouse/blob/master/types/lhr.d.ts
6
6
  // use results.report for the HTML/JSON/CSV output as a string
7
7
  // use results.artifacts for the trace/screenshots/other specific case you need (rarer)
8
- const { lhr } = results
9
- const { runtimeError } = lhr
8
+ const { lhr } = results;
9
+ const { runtimeError } = lhr;
10
10
  if (runtimeError) {
11
- const error = new Error(runtimeError.message)
12
- Object.assign(error, runtimeError)
13
- throw error
11
+ const error = new Error(runtimeError.message);
12
+ Object.assign(error, runtimeError);
13
+ throw error;
14
14
  }
15
- return lhr
16
- }
15
+ return lhr;
16
+ };
17
17
 
18
18
  export const reduceToMedianReport = async (lighthouseReports) => {
19
- const { computeMedianRun } = await import("lighthouse/core/lib/median-run.js")
20
- return computeMedianRun(lighthouseReports)
21
- }
19
+ const { computeMedianRun } = await import(
20
+ "lighthouse/core/lib/median-run.js"
21
+ );
22
+ return computeMedianRun(lighthouseReports);
23
+ };
22
24
 
23
25
  export const formatReportAsSummaryText = (lighthouseReport) => {
24
- const scores = {}
26
+ const scores = {};
25
27
  Object.keys(lighthouseReport.categories).forEach((name) => {
26
- scores[name] = lighthouseReport.categories[name].score
27
- })
28
- return JSON.stringify(scores, null, " ")
29
- }
28
+ scores[name] = lighthouseReport.categories[name].score;
29
+ });
30
+ return JSON.stringify(scores, null, " ");
31
+ };
30
32
 
31
33
  export const formatReportAsJson = (lighthouseReport) => {
32
- const json = JSON.stringify(lighthouseReport, null, " ")
33
- return json
34
- }
34
+ const json = JSON.stringify(lighthouseReport, null, " ");
35
+ return json;
36
+ };
35
37
 
36
38
  export const formatReportAsHtml = async (lighthouseReport) => {
37
39
  const { ReportGenerator } = await import(
38
40
  "lighthouse/report/generator/report-generator.js"
39
- )
40
- const html = ReportGenerator.generateReportHtml(lighthouseReport)
41
- return html
42
- }
41
+ );
42
+ const html = ReportGenerator.generateReportHtml(lighthouseReport);
43
+ return html;
44
+ };
package/src/main.js CHANGED
@@ -1,4 +1,4 @@
1
- export { readGitHubWorkflowEnv } from "@jsenv/github-pull-request-impact"
1
+ export { readGitHubWorkflowEnv } from "@jsenv/github-pull-request-impact";
2
2
 
3
- export { runLighthouseOnPlaywrightPage } from "./run_lighthouse_on_playwright_page.js"
4
- export { reportLighthouseImpactInGithubPullRequest } from "./report_lighthouse_impact_in_github_pr.js"
3
+ export { runLighthouseOnPlaywrightPage } from "./run_lighthouse_on_playwright_page.js";
4
+ export { reportLighthouseImpactInGithubPullRequest } from "./report_lighthouse_impact_in_github_pr.js";
@@ -1,4 +1,4 @@
1
- import { formatNumericDiff } from "./formatNumericDiff.js"
1
+ import { formatNumericDiff } from "./formatNumericDiff.js";
2
2
 
3
3
  export const createLighthouseImpactComment = ({
4
4
  pullRequestBase,
@@ -8,33 +8,33 @@ export const createLighthouseImpactComment = ({
8
8
  beforeMergeGist,
9
9
  afterMergeGist,
10
10
  }) => {
11
- const warnings = []
11
+ const warnings = [];
12
12
 
13
- const beforeMergeVersion = beforeMergeLighthouseReport.lighthouseVersion
14
- const afterMergeVersion = afterMergeLighthouseReport.lighthouseVersion
15
- let impactAnalysisEnabled = true
13
+ const beforeMergeVersion = beforeMergeLighthouseReport.lighthouseVersion;
14
+ const afterMergeVersion = afterMergeLighthouseReport.lighthouseVersion;
15
+ let impactAnalysisEnabled = true;
16
16
  if (beforeMergeVersion !== afterMergeVersion) {
17
- impactAnalysisEnabled = false
17
+ impactAnalysisEnabled = false;
18
18
  warnings.push(
19
19
  `**Warning:** Impact analysis skipped because lighthouse version are different on \`${pullRequestBase}\` (${beforeMergeVersion}) and \`${pullRequestHead}\` (${afterMergeVersion}).`,
20
- )
20
+ );
21
21
  }
22
22
 
23
- const beforeMergeWarnings = beforeMergeLighthouseReport.runWarnings
23
+ const beforeMergeWarnings = beforeMergeLighthouseReport.runWarnings;
24
24
  if (beforeMergeWarnings && beforeMergeWarnings.length) {
25
25
  warnings.push(
26
26
  `**Warning**: warnings produced while generating lighthouse report on \`${pullRequestBase}\`:
27
27
  - ${beforeMergeWarnings.join(`
28
28
  - `)}`,
29
- )
29
+ );
30
30
  }
31
- const afterMergeWarnings = afterMergeLighthouseReport.runWarnings
31
+ const afterMergeWarnings = afterMergeLighthouseReport.runWarnings;
32
32
  if (afterMergeWarnings && afterMergeWarnings.length) {
33
33
  warnings.push(
34
34
  `**Warning**: warnings produced while generating lighthouse report after merge:
35
35
  - ${afterMergeWarnings.join(`
36
36
  - `)}`,
37
- )
37
+ );
38
38
  }
39
39
 
40
40
  const bodyLines = [
@@ -66,13 +66,13 @@ ${renderBody({
66
66
  }),
67
67
  ]
68
68
  : []),
69
- ]
69
+ ];
70
70
 
71
71
  const body = bodyLines.join(`
72
- `)
72
+ `);
73
73
 
74
- return { warnings, body }
75
- }
74
+ return { warnings, body };
75
+ };
76
76
 
77
77
  const renderBody = ({
78
78
  beforeMergeLighthouseReport,
@@ -87,12 +87,12 @@ const renderBody = ({
87
87
  afterMergeLighthouseReport,
88
88
  pullRequestBase,
89
89
  pullRequestHead,
90
- })
90
+ });
91
91
  },
92
92
  ).join(`
93
93
 
94
- `)
95
- }
94
+ `);
95
+ };
96
96
 
97
97
  const renderCategory = (
98
98
  category,
@@ -100,14 +100,14 @@ const renderCategory = (
100
100
  ) => {
101
101
  const beforeMergeDisplayedScore = scoreToDisplayedScore(
102
102
  beforeMergeLighthouseReport.categories[category].score,
103
- )
103
+ );
104
104
  const afterMergeDisplayedScore = scoreToDisplayedScore(
105
105
  afterMergeLighthouseReport.categories[category].score,
106
- )
107
- const diff = afterMergeDisplayedScore - beforeMergeDisplayedScore
108
- const diffDisplayValue = diff === 0 ? "no impact" : formatNumericDiff(diff)
106
+ );
107
+ const diff = afterMergeDisplayedScore - beforeMergeDisplayedScore;
108
+ const diffDisplayValue = diff === 0 ? "no impact" : formatNumericDiff(diff);
109
109
 
110
- const summaryText = `${category} score: ${afterMergeDisplayedScore} (${diffDisplayValue})`
110
+ const summaryText = `${category} score: ${afterMergeDisplayedScore} (${diffDisplayValue})`;
111
111
 
112
112
  return `<details>
113
113
  <summary>${summaryText}</summary>
@@ -120,28 +120,28 @@ const renderCategory = (
120
120
  beforeMergeLighthouseReport,
121
121
  afterMergeLighthouseReport,
122
122
  })}
123
- </details>`
124
- }
123
+ </details>`;
124
+ };
125
125
 
126
126
  const scoreToDisplayedScore = (floatingNumber) =>
127
- Math.round(floatingNumber * 100)
127
+ Math.round(floatingNumber * 100);
128
128
 
129
129
  const renderCategoryAudits = (
130
130
  category,
131
131
  { beforeMergeLighthouseReport, afterMergeLighthouseReport },
132
132
  ) => {
133
- const { auditRefs } = afterMergeLighthouseReport.categories[category]
134
- const audits = []
133
+ const { auditRefs } = afterMergeLighthouseReport.categories[category];
134
+ const audits = [];
135
135
  auditRefs.forEach((auditRef) => {
136
- const auditId = auditRef.id
137
- const beforeMergeAudit = beforeMergeLighthouseReport.audits[auditId]
138
- const afterMergeAudit = afterMergeLighthouseReport.audits[auditId]
139
- const beforeMergeAuditOutput = renderAudit(beforeMergeAudit)
140
- const afterMergeAuditOutput = renderAudit(afterMergeAudit)
136
+ const auditId = auditRef.id;
137
+ const beforeMergeAudit = beforeMergeLighthouseReport.audits[auditId];
138
+ const afterMergeAudit = afterMergeLighthouseReport.audits[auditId];
139
+ const beforeMergeAuditOutput = renderAudit(beforeMergeAudit);
140
+ const afterMergeAuditOutput = renderAudit(afterMergeAudit);
141
141
 
142
142
  // both are not applicable
143
143
  if (beforeMergeAuditOutput === null && afterMergeAuditOutput === null) {
144
- return
144
+ return;
145
145
  }
146
146
 
147
147
  // becomes applicable
@@ -151,8 +151,8 @@ const renderCategoryAudits = (
151
151
  `<td nowrap>---</td>`,
152
152
  `<td nowrap>---</td>`,
153
153
  `<td nowrap>${afterMergeAuditOutput}</td>`,
154
- ])
155
- return
154
+ ]);
155
+ return;
156
156
  }
157
157
 
158
158
  // becomes unapplicable
@@ -162,23 +162,23 @@ const renderCategoryAudits = (
162
162
  `<td nowrap>---</td>`,
163
163
  `<td nowrap>${beforeMergeAuditOutput}</td>`,
164
164
  `<td nowrap>---</td>`,
165
- ])
166
- return
165
+ ]);
166
+ return;
167
167
  }
168
168
 
169
169
  if (
170
170
  typeof beforeMergeAuditOutput === "number" &&
171
171
  typeof afterMergeAuditOutput === "number"
172
172
  ) {
173
- const diff = afterMergeAuditOutput - beforeMergeAuditOutput
173
+ const diff = afterMergeAuditOutput - beforeMergeAuditOutput;
174
174
 
175
175
  audits.push([
176
176
  `<td nowrap>${auditId}</td>`,
177
177
  `<td nowrap>${diff === 0 ? "none" : formatNumericDiff(diff)}</td>`,
178
178
  `<td nowrap>${beforeMergeAuditOutput}</td>`,
179
179
  `<td nowrap>${afterMergeAuditOutput}</td>`,
180
- ])
181
- return
180
+ ]);
181
+ return;
182
182
  }
183
183
 
184
184
  audits.push([
@@ -188,8 +188,8 @@ const renderCategoryAudits = (
188
188
  }</td>`,
189
189
  `<td nowrap>${beforeMergeAuditOutput}</td>`,
190
190
  `<td nowrap>${afterMergeAuditOutput}</td>`,
191
- ])
192
- })
191
+ ]);
192
+ });
193
193
 
194
194
  return `
195
195
  <table>
@@ -211,46 +211,46 @@ const renderCategoryAudits = (
211
211
  <tr>`)}
212
212
  </tr>
213
213
  </tbody>
214
- </table>`
215
- }
214
+ </table>`;
215
+ };
216
216
 
217
217
  const renderAudit = (audit) => {
218
- const { scoreDisplayMode } = audit
218
+ const { scoreDisplayMode } = audit;
219
219
 
220
220
  if (scoreDisplayMode === "manual") {
221
- return null
221
+ return null;
222
222
  }
223
223
 
224
224
  if (scoreDisplayMode === "notApplicable") {
225
- return null
225
+ return null;
226
226
  }
227
227
 
228
228
  if (scoreDisplayMode === "informative") {
229
- const { displayValue } = audit
230
- if (typeof displayValue !== "undefined") return displayValue
229
+ const { displayValue } = audit;
230
+ if (typeof displayValue !== "undefined") return displayValue;
231
231
 
232
- const { numericValue } = audit
233
- if (typeof numericValue !== "undefined") return numericValue
232
+ const { numericValue } = audit;
233
+ if (typeof numericValue !== "undefined") return numericValue;
234
234
 
235
- return null
235
+ return null;
236
236
  }
237
237
 
238
238
  if (scoreDisplayMode === "binary") {
239
- const { score } = audit
240
- return score ? "✔" : "☓"
239
+ const { score } = audit;
240
+ return score ? "✔" : "☓";
241
241
  }
242
242
 
243
243
  if (scoreDisplayMode === "numeric") {
244
- const { score } = audit
245
- return scoreToDisplayedScore(score)
244
+ const { score } = audit;
245
+ return scoreToDisplayedScore(score);
246
246
  }
247
247
 
248
248
  if (scoreDisplayMode === "error") {
249
- return "error"
249
+ return "error";
250
250
  }
251
251
 
252
- return null
253
- }
252
+ return null;
253
+ };
254
254
 
255
255
  const renderGistLinks = ({
256
256
  beforeMergeGist,
@@ -263,9 +263,9 @@ const renderGistLinks = ({
263
263
  )}">${pullRequestBase} report</a> and <a href="${gistIdToReportUrl(
264
264
  afterMergeGist.id,
265
265
  )}">report after merge</a>
266
- </sub><br />`
267
- }
266
+ </sub><br />`;
267
+ };
268
268
 
269
269
  const gistIdToReportUrl = (gistId) => {
270
- return `https://googlechrome.github.io/lighthouse/viewer/?gist=${gistId}`
271
- }
270
+ return `https://googlechrome.github.io/lighthouse/viewer/?gist=${gistId}`;
271
+ };
@@ -1,14 +1,14 @@
1
- const enDecimalFormatter = new Intl.NumberFormat("en", { style: "decimal" })
1
+ const enDecimalFormatter = new Intl.NumberFormat("en", { style: "decimal" });
2
2
 
3
3
  export const formatNumericDiff = (valueAsNumber) => {
4
- const valueAsAbsoluteNumber = Math.abs(valueAsNumber)
5
- const valueAsString = enDecimalFormatter.format(valueAsAbsoluteNumber)
4
+ const valueAsAbsoluteNumber = Math.abs(valueAsNumber);
5
+ const valueAsString = enDecimalFormatter.format(valueAsAbsoluteNumber);
6
6
 
7
7
  if (valueAsNumber < 0) {
8
- return `-${valueAsString}`
8
+ return `-${valueAsString}`;
9
9
  }
10
10
  if (valueAsNumber > 0) {
11
- return `+${valueAsString}`
11
+ return `+${valueAsString}`;
12
12
  }
13
- return valueAsString
14
- }
13
+ return valueAsString;
14
+ };
@@ -1 +1 @@
1
- export const jsenvCommentParameters = {}
1
+ export const jsenvCommentParameters = {};
@@ -1,5 +1,5 @@
1
- import * as githubRESTAPI from "@jsenv/github-pull-request-impact/src/internal/github_rest_api.js"
2
- import { createDetailedMessage } from "@jsenv/log"
1
+ import * as githubRESTAPI from "@jsenv/github-pull-request-impact/src/internal/github_rest_api.js";
2
+ import { createDetailedMessage } from "@jsenv/log";
3
3
 
4
4
  // https://developer.github.com/v3/gists/#create-a-gist
5
5
 
@@ -15,14 +15,14 @@ export const patchOrPostGists = async ({
15
15
  afterMergeLighthouseReport,
16
16
  existingComment,
17
17
  }) => {
18
- let beforeMergeGistId
19
- let afterMergeGistId
18
+ let beforeMergeGistId;
19
+ let afterMergeGistId;
20
20
 
21
21
  if (existingComment) {
22
- const gistIds = gistIdsFromComment(existingComment)
22
+ const gistIds = gistIdsFromComment(existingComment);
23
23
  if (gistIds) {
24
- beforeMergeGistId = gistIds.beforeMergeGistId
25
- afterMergeGistId = gistIds.afterMergeGistId
24
+ beforeMergeGistId = gistIds.beforeMergeGistId;
25
+ afterMergeGistId = gistIds.afterMergeGistId;
26
26
  logger.debug(
27
27
  createDetailedMessage(`gists found in comment body`, {
28
28
  "before merging gist with lighthouse report":
@@ -30,13 +30,13 @@ export const patchOrPostGists = async ({
30
30
  "after merging gist with lighthouse report":
31
31
  gistIdToUrl(afterMergeGistId),
32
32
  }),
33
- )
33
+ );
34
34
  } else {
35
- logger.debug(`cannot find gist id in comment body`)
35
+ logger.debug(`cannot find gist id in comment body`);
36
36
  }
37
37
  }
38
38
 
39
- logger.debug(`update or create both gists.`)
39
+ logger.debug(`update or create both gists.`);
40
40
  let [beforeMergeGist, afterMergeGist] = await Promise.all([
41
41
  beforeMergeGistId
42
42
  ? githubRESTAPI.GET({
@@ -50,30 +50,30 @@ export const patchOrPostGists = async ({
50
50
  githubToken,
51
51
  })
52
52
  : null,
53
- ])
53
+ ]);
54
54
 
55
55
  const beforeMergeGistBody = createGistBody(beforeMergeLighthouseReport, {
56
56
  repositoryOwner,
57
57
  repositoryName,
58
58
  pullRequestNumber,
59
59
  beforeMerge: true,
60
- })
60
+ });
61
61
  if (beforeMergeGist) {
62
- logger.info(`updating base gist at ${gistIdToUrl(beforeMergeGist.id)}`)
62
+ logger.info(`updating base gist at ${gistIdToUrl(beforeMergeGist.id)}`);
63
63
  beforeMergeGist = await githubRESTAPI.PATCH({
64
64
  url: `https://api.github.com/gists/${beforeMergeGist.id}`,
65
65
  githubToken,
66
66
  body: beforeMergeGistBody,
67
- })
68
- logger.info(`base gist updated`)
67
+ });
68
+ logger.info(`base gist updated`);
69
69
  } else {
70
- logger.info(`creating base gist`)
70
+ logger.info(`creating base gist`);
71
71
  beforeMergeGist = await githubRESTAPI.POST({
72
72
  url: `https://api.github.com/gists`,
73
73
  githubToken,
74
74
  body: beforeMergeGistBody,
75
- })
76
- logger.info(`base gist created at ${gistIdToUrl(beforeMergeGist.id)}`)
75
+ });
76
+ logger.info(`base gist created at ${gistIdToUrl(beforeMergeGist.id)}`);
77
77
  }
78
78
 
79
79
  const afterMergeGistBody = createGistBody(afterMergeLighthouseReport, {
@@ -81,32 +81,34 @@ export const patchOrPostGists = async ({
81
81
  repositoryName,
82
82
  pullRequestNumber,
83
83
  beforeMerge: false,
84
- })
84
+ });
85
85
  if (afterMergeGist) {
86
86
  logger.info(
87
87
  `updating after merge gist at ${gistIdToUrl(afterMergeGist.id)}`,
88
- )
88
+ );
89
89
  afterMergeGist = await githubRESTAPI.PATCH({
90
90
  url: `https://api.github.com/gists/${afterMergeGist.id}`,
91
91
  githubToken,
92
92
  body: afterMergeGistBody,
93
- })
94
- logger.info(`after merge gist updated`)
93
+ });
94
+ logger.info(`after merge gist updated`);
95
95
  } else {
96
- logger.info(`creating after merge gist`)
96
+ logger.info(`creating after merge gist`);
97
97
  afterMergeGist = await githubRESTAPI.POST({
98
98
  url: `https://api.github.com/gists`,
99
99
  githubToken,
100
100
  body: afterMergeGistBody,
101
- })
102
- logger.info(`after merge gist created at ${gistIdToUrl(afterMergeGist.id)}`)
101
+ });
102
+ logger.info(
103
+ `after merge gist created at ${gistIdToUrl(afterMergeGist.id)}`,
104
+ );
103
105
  }
104
106
 
105
107
  return {
106
108
  beforeMergeGist,
107
109
  afterMergeGist,
108
- }
109
- }
110
+ };
111
+ };
110
112
 
111
113
  const createGistBody = (
112
114
  lighthouseReport,
@@ -121,35 +123,35 @@ const createGistBody = (
121
123
  },
122
124
  },
123
125
  public: false,
124
- }
125
- }
126
+ };
127
+ };
126
128
 
127
129
  const beforeMergeGistIdRegex = new RegExp(
128
130
  "<!-- before_merge_gist_id=([a-zA-Z0-9_]+) -->",
129
- )
131
+ );
130
132
  const afterMergeGistIdRegex = new RegExp(
131
133
  "<!-- after_merge_gist_id=([a-zA-Z0-9_]+) -->",
132
- )
134
+ );
133
135
 
134
136
  const gistIdsFromComment = (comment) => {
135
- const beforeMergeGistIdMatch = comment.body.match(beforeMergeGistIdRegex)
137
+ const beforeMergeGistIdMatch = comment.body.match(beforeMergeGistIdRegex);
136
138
  if (!beforeMergeGistIdMatch) {
137
- return null
139
+ return null;
138
140
  }
139
141
 
140
- const afterMergeGistIdMatch = comment.body.match(afterMergeGistIdRegex)
142
+ const afterMergeGistIdMatch = comment.body.match(afterMergeGistIdRegex);
141
143
  if (!afterMergeGistIdMatch) {
142
- return null
144
+ return null;
143
145
  }
144
146
 
145
- const beforeMergeGistId = beforeMergeGistIdMatch[1]
146
- const afterMergeGistId = afterMergeGistIdMatch[1]
147
+ const beforeMergeGistId = beforeMergeGistIdMatch[1];
148
+ const afterMergeGistId = afterMergeGistIdMatch[1];
147
149
  return {
148
150
  beforeMergeGistId,
149
151
  afterMergeGistId,
150
- }
151
- }
152
+ };
153
+ };
152
154
 
153
155
  const gistIdToUrl = (gistId) => {
154
- return `https://gist.github.com/${gistId}`
155
- }
156
+ return `https://gist.github.com/${gistId}`;
157
+ };
@@ -1,9 +1,9 @@
1
- import { assertAndNormalizeDirectoryUrl } from "@jsenv/filesystem"
2
- import { commentGitHubPullRequestImpact } from "@jsenv/github-pull-request-impact"
3
- import { importOneExportFromFile } from "@jsenv/dynamic-import-worker"
1
+ import { assertAndNormalizeDirectoryUrl } from "@jsenv/filesystem";
2
+ import { commentGitHubPullRequestImpact } from "@jsenv/github-pull-request-impact";
3
+ import { importOneExportFromFile } from "@jsenv/dynamic-import-worker";
4
4
 
5
- import { patchOrPostGists } from "./pr_impact/patchOrPostGists.js"
6
- import { createLighthouseImpactComment } from "./pr_impact/createLighthouseImpactComment.js"
5
+ import { patchOrPostGists } from "./pr_impact/patchOrPostGists.js";
6
+ import { createLighthouseImpactComment } from "./pr_impact/createLighthouseImpactComment.js";
7
7
 
8
8
  export const reportLighthouseImpactInGithubPullRequest = async ({
9
9
  logLevel,
@@ -23,14 +23,14 @@ export const reportLighthouseImpactInGithubPullRequest = async ({
23
23
  catchError,
24
24
  skipGistWarning = false,
25
25
  }) => {
26
- rootDirectoryUrl = assertAndNormalizeDirectoryUrl(rootDirectoryUrl)
26
+ rootDirectoryUrl = assertAndNormalizeDirectoryUrl(rootDirectoryUrl);
27
27
  if (typeof lighthouseReportUrl === "string") {
28
- lighthouseReportUrl = new URL(lighthouseReportUrl, rootDirectoryUrl).href
28
+ lighthouseReportUrl = new URL(lighthouseReportUrl, rootDirectoryUrl).href;
29
29
  } else if (lighthouseReportUrl instanceof URL) {
30
30
  } else {
31
31
  throw new TypeError(
32
32
  `lighthouseReportUrl must be a string or an url but received ${lighthouseReportUrl}`,
33
- )
33
+ );
34
34
  }
35
35
 
36
36
  return commentGitHubPullRequestImpact({
@@ -47,11 +47,11 @@ export const reportLighthouseImpactInGithubPullRequest = async ({
47
47
  pullRequestNumber,
48
48
 
49
49
  collectInfo: async ({ execCommandInRootDirectory }) => {
50
- await execCommandInRootDirectory(installCommand)
50
+ await execCommandInRootDirectory(installCommand);
51
51
  const lighthouseReport = await importOneExportFromFile(
52
52
  lighthouseReportUrl,
53
- )
54
- return { version: 1, data: lighthouseReport }
53
+ );
54
+ return { version: 1, data: lighthouseReport };
55
55
  },
56
56
  commentIdentifier: `<!-- Generated by @jsenv/lighthouse-impact -->`,
57
57
  createCommentForComparison: async ({
@@ -63,10 +63,10 @@ export const reportLighthouseImpactInGithubPullRequest = async ({
63
63
  afterMergeData,
64
64
  existingComment,
65
65
  }) => {
66
- const gistWarnings = []
66
+ const gistWarnings = [];
67
67
 
68
- let beforeMergeGist
69
- let afterMergeGist
68
+ let beforeMergeGist;
69
+ let afterMergeGist;
70
70
  try {
71
71
  const gistResult = await patchOrPostGists({
72
72
  logger,
@@ -79,18 +79,18 @@ export const reportLighthouseImpactInGithubPullRequest = async ({
79
79
  beforeMergeLighthouseReport: beforeMergeData,
80
80
  afterMergeLighthouseReport: afterMergeData,
81
81
  existingComment,
82
- })
83
- beforeMergeGist = gistResult.beforeMergeGist
84
- afterMergeGist = gistResult.afterMergeGist
82
+ });
83
+ beforeMergeGist = gistResult.beforeMergeGist;
84
+ afterMergeGist = gistResult.afterMergeGist;
85
85
  } catch (e) {
86
86
  if (e.responseStatus === 403) {
87
87
  if (!skipGistWarning) {
88
88
  gistWarnings.push(
89
89
  `**Warning:** Link to lighthouse reports cannot be generated because github token is not allowed to create gists.`,
90
- )
90
+ );
91
91
  }
92
92
  } else {
93
- throw e
93
+ throw e;
94
94
  }
95
95
  }
96
96
 
@@ -101,12 +101,12 @@ export const reportLighthouseImpactInGithubPullRequest = async ({
101
101
  afterMergeLighthouseReport: afterMergeData,
102
102
  beforeMergeGist,
103
103
  afterMergeGist,
104
- })
104
+ });
105
105
 
106
106
  return {
107
107
  warnings: [...gistWarnings, ...comment.warnings],
108
108
  body: comment.body,
109
- }
109
+ };
110
110
  },
111
111
  generatedByLink: {
112
112
  url: "https://github.com/jsenv/workflow/tree/main/packages/lighthouse-impact",
@@ -115,5 +115,5 @@ export const reportLighthouseImpactInGithubPullRequest = async ({
115
115
  runLink,
116
116
  commitInGeneratedByInfo,
117
117
  catchError,
118
- })
119
- }
118
+ });
119
+ };
@@ -1,60 +1,61 @@
1
- import { generateLighthouseReport } from "./generate/generate_lighthouse_report.js"
1
+ import { generateLighthouseReport } from "./generate/generate_lighthouse_report.js";
2
2
 
3
3
  export const runLighthouseOnPlaywrightPage = async (
4
4
  page,
5
5
  { chromiumDebuggingPort, ...options },
6
6
  ) => {
7
- const url = page.url()
7
+ const url = page.url();
8
8
  const userAgent = await page.evaluate(() => {
9
9
  /* eslint-disable no-undef */
10
- return navigator.userAgent
10
+ return navigator.userAgent;
11
11
  /* eslint-enable no-undef */
12
- })
12
+ });
13
13
  const deviceScaleFactor = await page.evaluate(() => {
14
14
  /* eslint-disable no-undef */
15
- return window.devicePixelRatio
15
+ return window.devicePixelRatio;
16
16
  /* eslint-enable no-undef */
17
- })
17
+ });
18
18
  const { screenWidth, screenHeight } = await page.evaluate(() => {
19
19
  /* eslint-disable no-undef */
20
20
  return {
21
21
  screenWidth: window.screen.width,
22
22
  screenHeight: window.screen.height,
23
- }
23
+ };
24
24
  /* eslint-enable no-undef */
25
- })
25
+ });
26
26
  // see "isMobile" into https://playwright.dev/docs/api/class-browser#browser-new-context
27
27
  const viewportMetaTakenIntoAccount = await page.evaluate(() => {
28
28
  /* eslint-disable no-undef */
29
- let mutate
30
- const viewportWidthNow = window.innerWidth
31
- const viewportMeta = document.head.querySelector("meta[name=viewport]")
29
+ let mutate;
30
+ const viewportWidthNow = window.innerWidth;
31
+ const viewportMeta = document.head.querySelector("meta[name=viewport]");
32
32
  if (viewportMeta) {
33
33
  mutate = () => {
34
- const content = viewportMeta.content
35
- viewportMeta.setAttribute("content", `width=${viewportWidthNow + 1}`)
34
+ const content = viewportMeta.content;
35
+ viewportMeta.setAttribute("content", `width=${viewportWidthNow + 1}`);
36
36
  return () => {
37
- viewportMeta.setAttribute("content", content)
38
- }
39
- }
37
+ viewportMeta.setAttribute("content", content);
38
+ };
39
+ };
40
40
  } else {
41
41
  mutate = () => {
42
- const viewportMeta = document.createElement("meta")
43
- viewportMeta.name = "viewport"
44
- viewportMeta.setAttribute("content", `width=${viewportWidthNow + 1}`)
45
- document.head.appendChild(viewportMeta)
42
+ const viewportMeta = document.createElement("meta");
43
+ viewportMeta.name = "viewport";
44
+ viewportMeta.setAttribute("content", `width=${viewportWidthNow + 1}`);
45
+ document.head.appendChild(viewportMeta);
46
46
  return () => {
47
- document.head.removeChild(viewportMeta)
48
- }
49
- }
47
+ document.head.removeChild(viewportMeta);
48
+ };
49
+ };
50
50
  }
51
- const cleanup = mutate()
52
- const viewportWidthAfter = window.innerWidth
53
- cleanup()
54
- const viewportMetaTakenIntoAccount = viewportWidthAfter !== viewportWidthNow
55
- return viewportMetaTakenIntoAccount
51
+ const cleanup = mutate();
52
+ const viewportWidthAfter = window.innerWidth;
53
+ cleanup();
54
+ const viewportMetaTakenIntoAccount =
55
+ viewportWidthAfter !== viewportWidthNow;
56
+ return viewportMetaTakenIntoAccount;
56
57
  /* eslint-enable no-undef */
57
- })
58
+ });
58
59
 
59
60
  const report = await generateLighthouseReport(url, {
60
61
  chromiumDebuggingPort,
@@ -64,6 +65,6 @@ export const runLighthouseOnPlaywrightPage = async (
64
65
  emulatedMobile: viewportMetaTakenIntoAccount,
65
66
  emulatedUserAgent: userAgent,
66
67
  ...options,
67
- })
68
- return report
69
- }
68
+ });
69
+ return report;
70
+ };