@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 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
+ 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
- lighthouseReportPath: "./lighthouse.mjs#lighthouseReport",
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 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.10",
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
- "eslint": "npx eslint . --ext=.js,.mjs",
37
- "snapshot": "node ./test/comment/generate_comment_snapshot_file.mjs",
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.1.2",
44
- "@jsenv/dynamic-import-worker": "1.0.1",
45
- "@jsenv/filesystem": "3.1.0",
46
- "@jsenv/github-pull-request-impact": "1.6.11",
47
- "@jsenv/logger": "4.0.1",
48
- "chrome-launcher": "0.15.0",
49
- "lighthouse": "9.2.0"
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
- jsonFile = false,
37
- jsonFileRelativeUrl = "./lighthouse/lighthouse_report.json",
30
+ jsonFileUrl,
38
31
  jsonFileLog = true,
39
- htmlFile = false,
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 (jsonFile) {
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 (htmlFile) {
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) {
@@ -1,5 +1,5 @@
1
1
  import * as githubRESTAPI from "@jsenv/github-pull-request-impact/src/internal/github_rest_api.js"
2
- import { createDetailedMessage } from "@jsenv/logger"
2
+ import { createDetailedMessage } from "@jsenv/log"
3
3
 
4
4
  // https://developer.github.com/v3/gists/#create-a-gist
5
5
 
package/src/main.js ADDED
@@ -0,0 +1,4 @@
1
+ export { readGitHubWorkflowEnv } from "@jsenv/github-pull-request-impact"
2
+
3
+ export { generateLighthouseReport } from "./generateLighthouseReport.js"
4
+ export { reportLighthouseImpact } from "./reportLighthouseImpact.js"
@@ -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
 
@@ -16,7 +16,7 @@ export const reportLighthouseImpact = async ({
16
16
  repositoryName,
17
17
  pullRequestNumber,
18
18
  installCommand = "npm install",
19
- lighthouseReportPath,
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 (typeof lighthouseReportPath !== "string") {
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
- `lighthouseReportPath must be a string but received ${lighthouseReportPath}`,
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 ({ execCommandInProjectDirectory }) => {
49
- await execCommandInProjectDirectory(installCommand)
49
+ collectInfo: async ({ execCommandInRootDirectory }) => {
50
+ await execCommandInRootDirectory(installCommand)
50
51
  const lighthouseReport = await importOneExportFromFile(
51
52
  lighthouseReportUrl,
52
53
  )
package/main.js DELETED
@@ -1,4 +0,0 @@
1
- export { generateLighthouseReport } from "./src/generateLighthouseReport.js"
2
-
3
- export { readGitHubWorkflowEnv } from "@jsenv/github-pull-request-impact"
4
- export { reportLighthouseImpact } from "./src/reportLighthouseImpact.js"