@jsenv/lighthouse-impact 2.1.9 → 2.2.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 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. For an example, see [package.json#L37](./package.json#L37) and [script/lighthouse/lighthouse.mjs#L19](./script/lighthouse/lighthouse.mjs#L19).
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
- lighthouseReportPath: "./lighthouse.mjs#lighthouseReport",
128
+ lighthouseReportPath: new URL(
129
+ "./lighthouse.mjs#lighthouseReport",
130
+ import.meta.url,
131
+ ),
129
132
  })
130
133
  ```
131
134
 
@@ -162,7 +165,7 @@ The example below assume code is executed by Travis.
162
165
 
163
166
  reportLighthouseImpact({
164
167
  - ...readGitHubWorkflowEnv(),
165
- + projectDirectoryUrl: process.env.TRAVIS_BUILD_DIR,
168
+ + rootDirectoryUrl: process.env.TRAVIS_BUILD_DIR,
166
169
  + repositoryOwner: process.env.TRAVIS_REPO_SLUG.split("/")[0],
167
170
  + repositoryName: process.env.TRAVIS_REPO_SLUG.split("/")[1],
168
171
  + pullRequestNumber: process.env.TRAVIS_PULL_REQUEST,
@@ -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 like [lighthouse-score-impact.yml#L21](./.github/workflows/lighthouse_impact.yml#L21) to use an other token that will have the rights to create gists.
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": "2.1.9",
3
+ "version": "2.2.0",
4
4
  "description": "Package description",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -34,7 +34,6 @@
34
34
  ],
35
35
  "scripts": {
36
36
  "eslint": "npx eslint . --ext=.js,.mjs",
37
- "importmap": "node ./script/importmap/importmap.mjs",
38
37
  "snapshot": "node ./test/comment/generate_comment_snapshot_file.mjs",
39
38
  "test": "node ./script/test/test.mjs",
40
39
  "test-with-coverage": "npm run test -- --coverage",
@@ -43,20 +42,10 @@
43
42
  "dependencies": {
44
43
  "@jsenv/abort": "4.1.2",
45
44
  "@jsenv/dynamic-import-worker": "1.0.1",
46
- "@jsenv/filesystem": "2.7.1",
47
- "@jsenv/github-pull-request-impact": "1.6.10",
45
+ "@jsenv/filesystem": "3.1.0",
46
+ "@jsenv/github-pull-request-impact": "1.6.11",
48
47
  "@jsenv/logger": "4.0.1",
49
48
  "chrome-launcher": "0.15.0",
50
49
  "lighthouse": "9.2.0"
51
- },
52
- "devDependencies": {
53
- "@jsenv/assert": "2.4.1",
54
- "@jsenv/core": "25.3.0",
55
- "@jsenv/eslint-config": "16.0.9",
56
- "@jsenv/importmap-eslint-resolver": "5.2.5",
57
- "@jsenv/importmap-node-module": "5.1.3",
58
- "eslint": "8.7.0",
59
- "eslint-plugin-import": "2.25.4",
60
- "prettier": "2.5.1"
61
50
  }
62
51
  }
@@ -31,7 +31,7 @@ export const generateLighthouseReport = async (
31
31
  runCount = 1,
32
32
  delayBetweenEachRunInSeconds = 1,
33
33
 
34
- projectDirectoryUrl, // required only when jsonFile or htmlFile is passed
34
+ rootDirectoryUrl, // required only when jsonFile or htmlFile is passed
35
35
  log = false,
36
36
  jsonFile = false,
37
37
  jsonFileRelativeUrl = "./lighthouse/lighthouse_report.json",
@@ -118,17 +118,14 @@ export const generateLighthouseReport = async (
118
118
  await chrome.kill()
119
119
 
120
120
  if (jsonFile || htmlFile) {
121
- projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl)
121
+ rootDirectoryUrl = assertAndNormalizeDirectoryUrl(rootDirectoryUrl)
122
122
  }
123
123
 
124
124
  const promises = []
125
125
  if (jsonFile) {
126
126
  promises.push(
127
127
  (async () => {
128
- const jsonFileUrl = resolveUrl(
129
- jsonFileRelativeUrl,
130
- projectDirectoryUrl,
131
- )
128
+ const jsonFileUrl = resolveUrl(jsonFileRelativeUrl, rootDirectoryUrl)
132
129
  const json = JSON.stringify(lighthouseReport, null, " ")
133
130
  await writeFile(jsonFileUrl, json)
134
131
  if (jsonFileLog) {
@@ -140,10 +137,7 @@ export const generateLighthouseReport = async (
140
137
  if (htmlFile) {
141
138
  promises.push(
142
139
  (async () => {
143
- const htmlFileUrl = resolveUrl(
144
- htmlFileRelativeUrl,
145
- projectDirectoryUrl,
146
- )
140
+ const htmlFileUrl = resolveUrl(htmlFileRelativeUrl, rootDirectoryUrl)
147
141
  const html = ReportGenerator.generateReportHtml(lighthouseReport)
148
142
  await writeFile(htmlFileUrl, html)
149
143
  if (htmlFileLog) {
@@ -1,4 +1,4 @@
1
- import { assertAndNormalizeDirectoryUrl, resolveUrl } from "@jsenv/filesystem"
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
 
@@ -9,7 +9,7 @@ export const reportLighthouseImpact = async ({
9
9
  logLevel,
10
10
  commandLogs = false,
11
11
  cancelOnSIGINT,
12
- projectDirectoryUrl,
12
+ rootDirectoryUrl,
13
13
 
14
14
  githubToken,
15
15
  repositoryOwner,
@@ -23,17 +23,17 @@ export const reportLighthouseImpact = async ({
23
23
  catchError,
24
24
  skipGistWarning = false,
25
25
  }) => {
26
- projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl)
27
- if (typeof lighthouseReportPath !== "string") {
26
+ rootDirectoryUrl = assertAndNormalizeDirectoryUrl(rootDirectoryUrl)
27
+ let lighthouseReportUrl
28
+ if (lighthouseReportPath === "string") {
29
+ lighthouseReportUrl = new URL(lighthouseReportPath, rootDirectoryUrl).href
30
+ } else if (lighthouseReportPath instanceof URL) {
31
+ lighthouseReportUrl = lighthouseReportPath.href
32
+ } else {
28
33
  throw new TypeError(
29
- `lighthouseReportPath must be a string but received ${lighthouseReportPath}`,
34
+ `lighthouseReportPath must be a string or an url but received ${lighthouseReportPath}`,
30
35
  )
31
36
  }
32
- projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl)
33
- const lighthouseReportUrl = resolveUrl(
34
- lighthouseReportPath,
35
- projectDirectoryUrl,
36
- )
37
37
 
38
38
  return commentGitHubPullRequestImpact({
39
39
  logLevel,
@@ -41,15 +41,15 @@ export const reportLighthouseImpact = async ({
41
41
  // lighthouse report are super verbose, do not log them
42
42
  infoLogs: false,
43
43
  cancelOnSIGINT,
44
- projectDirectoryUrl,
44
+ rootDirectoryUrl,
45
45
 
46
46
  githubToken,
47
47
  repositoryOwner,
48
48
  repositoryName,
49
49
  pullRequestNumber,
50
50
 
51
- collectInfo: async ({ execCommandInProjectDirectory }) => {
52
- await execCommandInProjectDirectory(installCommand)
51
+ collectInfo: async ({ execCommandInRootDirectory }) => {
52
+ await execCommandInRootDirectory(installCommand)
53
53
  const lighthouseReport = await importOneExportFromFile(
54
54
  lighthouseReportUrl,
55
55
  )