@jsenv/lighthouse-impact 2.1.10 → 3.0.0
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 +7 -4
- package/package.json +13 -17
- package/src/generateLighthouseReport.js +8 -20
- package/src/internal/patchOrPostGists.js +1 -1
- package/src/main.js +4 -0
- package/src/reportLighthouseImpact.js +9 -8
- package/main.js +0 -4
package/README.md
CHANGED
|
@@ -69,7 +69,7 @@ _index.html_
|
|
|
69
69
|
</html>
|
|
70
70
|
```
|
|
71
71
|
|
|
72
|
-
At this stage, you could generate a lighthouse report on your machine.
|
|
72
|
+
At this stage, you could generate a lighthouse report on your machine.
|
|
73
73
|
|
|
74
74
|
Now it's time to configure a workflow to compare lighthouse reports before and after merging a pull request.
|
|
75
75
|
|
|
@@ -125,7 +125,10 @@ import {
|
|
|
125
125
|
|
|
126
126
|
await reportLighthouseImpact({
|
|
127
127
|
...readGitHubWorkflowEnv(),
|
|
128
|
-
|
|
128
|
+
lighthouseReportUrl: new URL(
|
|
129
|
+
"./lighthouse.mjs#lighthouseReport",
|
|
130
|
+
import.meta.url,
|
|
131
|
+
),
|
|
129
132
|
})
|
|
130
133
|
```
|
|
131
134
|
|
|
@@ -167,7 +170,7 @@ reportLighthouseImpact({
|
|
|
167
170
|
+ repositoryName: process.env.TRAVIS_REPO_SLUG.split("/")[1],
|
|
168
171
|
+ pullRequestNumber: process.env.TRAVIS_PULL_REQUEST,
|
|
169
172
|
+ githubToken: process.env.GITHUB_TOKEN, // see next step
|
|
170
|
-
|
|
173
|
+
lighthouseReportUrl: "./lighthouse.mjs#lighthouseReport",
|
|
171
174
|
})
|
|
172
175
|
```
|
|
173
176
|
|
|
@@ -186,7 +189,7 @@ The pull request comment can contain links to see lighthouse reports in [Lightho
|
|
|
186
189
|
To unlock this you need a GitHub token with the right to create gists.
|
|
187
190
|
Every github workflow has access to a magic token `secrets.GITHUB_TOKEN`.
|
|
188
191
|
But this token is not allowed to create gists.
|
|
189
|
-
We need to update the worflow file
|
|
192
|
+
We need to update the worflow file to use an other token that will have the rights to create gists.
|
|
190
193
|
|
|
191
194
|
```diff
|
|
192
195
|
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/lighthouse-impact",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Package description",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -23,29 +23,25 @@
|
|
|
23
23
|
"type": "module",
|
|
24
24
|
"exports": {
|
|
25
25
|
".": {
|
|
26
|
-
"import": "./main.js"
|
|
26
|
+
"import": "./src/main.js"
|
|
27
27
|
},
|
|
28
28
|
"./*": "./*"
|
|
29
29
|
},
|
|
30
|
-
"main": "./main.js",
|
|
30
|
+
"main": "./src/main.js",
|
|
31
31
|
"files": [
|
|
32
|
-
"/src/"
|
|
33
|
-
"/main.js"
|
|
32
|
+
"/src/"
|
|
34
33
|
],
|
|
35
34
|
"scripts": {
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"test": "node ./script/test/test.mjs",
|
|
39
|
-
"test-with-coverage": "npm run test -- --coverage",
|
|
40
|
-
"prettier": "prettier --write ."
|
|
35
|
+
"snapshot": "node ./tests/comment/generate_comment_snapshot_file.mjs",
|
|
36
|
+
"test": "node ./scripts/test.mjs"
|
|
41
37
|
},
|
|
42
38
|
"dependencies": {
|
|
43
|
-
"@jsenv/abort": "4.
|
|
44
|
-
"@jsenv/dynamic-import-worker": "1.0
|
|
45
|
-
"@jsenv/filesystem": "
|
|
46
|
-
"@jsenv/github-pull-request-impact": "1.
|
|
47
|
-
"@jsenv/
|
|
48
|
-
"chrome-launcher": "0.15.
|
|
49
|
-
"lighthouse": "9.2
|
|
39
|
+
"@jsenv/abort": "4.2.3",
|
|
40
|
+
"@jsenv/dynamic-import-worker": "1.1.0",
|
|
41
|
+
"@jsenv/filesystem": "4.1.0",
|
|
42
|
+
"@jsenv/github-pull-request-impact": "1.7.0",
|
|
43
|
+
"@jsenv/log": "2.1.0",
|
|
44
|
+
"chrome-launcher": "0.15.1",
|
|
45
|
+
"lighthouse": "9.6.2"
|
|
50
46
|
}
|
|
51
47
|
}
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
// https://github.com/GoogleChrome/lighthouse/blob/5a14deb5c4e0ec4e8e58f50ff72b53851b021bcf/docs/readme.md#using-programmatically
|
|
2
2
|
|
|
3
3
|
import { createRequire } from "node:module"
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
writeFile,
|
|
7
|
-
resolveUrl,
|
|
8
|
-
assertAndNormalizeDirectoryUrl,
|
|
9
|
-
} from "@jsenv/filesystem"
|
|
10
|
-
import { createLogger } from "@jsenv/logger"
|
|
4
|
+
import { writeFile, assertAndNormalizeFileUrl } from "@jsenv/filesystem"
|
|
5
|
+
import { createLogger } from "@jsenv/log"
|
|
11
6
|
import { Abort, raceProcessTeardownEvents } from "@jsenv/abort"
|
|
12
7
|
|
|
13
8
|
import { formatLighthouseReportForLog } from "./internal/formatLighthouseReportForLog.js"
|
|
@@ -31,13 +26,10 @@ export const generateLighthouseReport = async (
|
|
|
31
26
|
runCount = 1,
|
|
32
27
|
delayBetweenEachRunInSeconds = 1,
|
|
33
28
|
|
|
34
|
-
rootDirectoryUrl, // required only when jsonFile or htmlFile is passed
|
|
35
29
|
log = false,
|
|
36
|
-
|
|
37
|
-
jsonFileRelativeUrl = "./lighthouse/lighthouse_report.json",
|
|
30
|
+
jsonFileUrl,
|
|
38
31
|
jsonFileLog = true,
|
|
39
|
-
|
|
40
|
-
htmlFileRelativeUrl = "./lighthouse/lighthouse_report.html",
|
|
32
|
+
htmlFileUrl,
|
|
41
33
|
htmlFileLog = true,
|
|
42
34
|
} = {},
|
|
43
35
|
) => {
|
|
@@ -117,15 +109,11 @@ export const generateLighthouseReport = async (
|
|
|
117
109
|
|
|
118
110
|
await chrome.kill()
|
|
119
111
|
|
|
120
|
-
if (jsonFile || htmlFile) {
|
|
121
|
-
rootDirectoryUrl = assertAndNormalizeDirectoryUrl(rootDirectoryUrl)
|
|
122
|
-
}
|
|
123
|
-
|
|
124
112
|
const promises = []
|
|
125
|
-
if (
|
|
113
|
+
if (jsonFileUrl) {
|
|
114
|
+
assertAndNormalizeFileUrl(jsonFileUrl)
|
|
126
115
|
promises.push(
|
|
127
116
|
(async () => {
|
|
128
|
-
const jsonFileUrl = resolveUrl(jsonFileRelativeUrl, rootDirectoryUrl)
|
|
129
117
|
const json = JSON.stringify(lighthouseReport, null, " ")
|
|
130
118
|
await writeFile(jsonFileUrl, json)
|
|
131
119
|
if (jsonFileLog) {
|
|
@@ -134,10 +122,10 @@ export const generateLighthouseReport = async (
|
|
|
134
122
|
})(),
|
|
135
123
|
)
|
|
136
124
|
}
|
|
137
|
-
if (
|
|
125
|
+
if (htmlFileUrl) {
|
|
126
|
+
assertAndNormalizeFileUrl(htmlFileUrl)
|
|
138
127
|
promises.push(
|
|
139
128
|
(async () => {
|
|
140
|
-
const htmlFileUrl = resolveUrl(htmlFileRelativeUrl, rootDirectoryUrl)
|
|
141
129
|
const html = ReportGenerator.generateReportHtml(lighthouseReport)
|
|
142
130
|
await writeFile(htmlFileUrl, html)
|
|
143
131
|
if (htmlFileLog) {
|
package/src/main.js
ADDED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assertAndNormalizeDirectoryUrl
|
|
1
|
+
import { assertAndNormalizeDirectoryUrl } from "@jsenv/filesystem"
|
|
2
2
|
import { commentGitHubPullRequestImpact } from "@jsenv/github-pull-request-impact"
|
|
3
3
|
import { importOneExportFromFile } from "@jsenv/dynamic-import-worker"
|
|
4
4
|
|
|
@@ -16,7 +16,7 @@ export const reportLighthouseImpact = async ({
|
|
|
16
16
|
repositoryName,
|
|
17
17
|
pullRequestNumber,
|
|
18
18
|
installCommand = "npm install",
|
|
19
|
-
|
|
19
|
+
lighthouseReportUrl,
|
|
20
20
|
|
|
21
21
|
runLink,
|
|
22
22
|
commitInGeneratedByInfo,
|
|
@@ -24,13 +24,14 @@ export const reportLighthouseImpact = async ({
|
|
|
24
24
|
skipGistWarning = false,
|
|
25
25
|
}) => {
|
|
26
26
|
rootDirectoryUrl = assertAndNormalizeDirectoryUrl(rootDirectoryUrl)
|
|
27
|
-
if (
|
|
27
|
+
if (lighthouseReportUrl === "string") {
|
|
28
|
+
lighthouseReportUrl = new URL(lighthouseReportUrl, rootDirectoryUrl).href
|
|
29
|
+
} else if (lighthouseReportUrl instanceof URL) {
|
|
30
|
+
} else {
|
|
28
31
|
throw new TypeError(
|
|
29
|
-
`
|
|
32
|
+
`lighthouseReportUrl must be a string or an url but received ${lighthouseReportUrl}`,
|
|
30
33
|
)
|
|
31
34
|
}
|
|
32
|
-
rootDirectoryUrl = assertAndNormalizeDirectoryUrl(rootDirectoryUrl)
|
|
33
|
-
const lighthouseReportUrl = resolveUrl(lighthouseReportPath, rootDirectoryUrl)
|
|
34
35
|
|
|
35
36
|
return commentGitHubPullRequestImpact({
|
|
36
37
|
logLevel,
|
|
@@ -45,8 +46,8 @@ export const reportLighthouseImpact = async ({
|
|
|
45
46
|
repositoryName,
|
|
46
47
|
pullRequestNumber,
|
|
47
48
|
|
|
48
|
-
collectInfo: async ({
|
|
49
|
-
await
|
|
49
|
+
collectInfo: async ({ execCommandInRootDirectory }) => {
|
|
50
|
+
await execCommandInRootDirectory(installCommand)
|
|
50
51
|
const lighthouseReport = await importOneExportFromFile(
|
|
51
52
|
lighthouseReportUrl,
|
|
52
53
|
)
|
package/main.js
DELETED