@jsenv/performance-impact 2.2.8 → 2.2.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/performance-impact",
3
- "version": "2.2.8",
3
+ "version": "2.2.9",
4
4
  "description": "Report pull request impacts on performance metrics",
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_snapshot/generate_comment_snapshot_file.mjs",
39
38
  "test": "node ./script/test/test.mjs",
40
39
  "test-with-coverage": "npm run test -- --coverage",
@@ -42,20 +41,10 @@
42
41
  },
43
42
  "dependencies": {
44
43
  "@jsenv/dynamic-import-worker": "1.0.1",
45
- "@jsenv/filesystem": "2.7.1",
44
+ "@jsenv/filesystem": "3.1.0",
46
45
  "@jsenv/github-pull-request-impact": "1.6.10",
47
46
  "@jsenv/logger": "4.0.1",
48
47
  "bytes": "3.1.1",
49
48
  "humanize-duration": "3.27.1"
50
- },
51
- "devDependencies": {
52
- "@jsenv/assert": "2.4.1",
53
- "@jsenv/core": "25.3.0",
54
- "@jsenv/eslint-config": "16.0.9",
55
- "@jsenv/importmap-eslint-resolver": "5.2.5",
56
- "@jsenv/importmap-node-module": "5.1.3",
57
- "eslint": "8.7.0",
58
- "eslint-plugin-import": "2.25.4",
59
- "prettier": "2.5.1"
60
49
  }
61
50
  }
@@ -1,12 +1,6 @@
1
+ import { formatPercentage } from "./format_percentage.js"
2
+
1
3
  export const formatRatioAsPercentage = (ratio) => {
2
- const asPercentage = ratio * 100
3
- const asPercentageFormatted = `${ratio < 0 ? `-` : "+"}${Math.abs(
4
- limitDecimals(asPercentage, 2),
5
- )}%`
4
+ const asPercentageFormatted = formatPercentage(ratio * 100)
6
5
  return asPercentageFormatted
7
6
  }
8
-
9
- const limitDecimals = (number, decimalCount = 2) => {
10
- const multiplier = Math.pow(10, decimalCount)
11
- return Math.round(number * multiplier) / multiplier
12
- }
@@ -0,0 +1,30 @@
1
+ export const formatPercentage = (number) => {
2
+ const absoluteValue = Math.abs(number)
3
+ const valueRounded = roundNumber(
4
+ absoluteValue,
5
+ determineDecimals(absoluteValue),
6
+ )
7
+ return `${number < 0 ? `-` : "+"}${valueRounded}%`
8
+ }
9
+ const determineDecimals = (number) => {
10
+ if (number < 0.001) {
11
+ return 4
12
+ }
13
+ if (number < 0.01) {
14
+ return 3
15
+ }
16
+ if (number < 0.1) {
17
+ return 2
18
+ }
19
+ if (number < 1) {
20
+ return 1
21
+ }
22
+ return 0
23
+ }
24
+
25
+ const roundNumber = (value, maxDecimals) => {
26
+ const expValue = Math.pow(10, maxDecimals)
27
+ const roundedValue = Math.round(expValue * value) / expValue
28
+ const valueAsString = roundedValue.toFixed(maxDecimals)
29
+ return parseFloat(valueAsString)
30
+ }
@@ -10,7 +10,7 @@ export const reportPerformanceImpact = async ({
10
10
  logLevel,
11
11
  commandLogs,
12
12
  cancelOnSIGINT,
13
- projectDirectoryUrl,
13
+ rootDirectoryUrl,
14
14
 
15
15
  githubToken,
16
16
  repositoryOwner,
@@ -26,23 +26,23 @@ export const reportPerformanceImpact = async ({
26
26
  runLink,
27
27
  commitInGeneratedByInfo,
28
28
  }) => {
29
- projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl)
29
+ rootDirectoryUrl = assertAndNormalizeDirectoryUrl(rootDirectoryUrl)
30
30
  if (typeof performanceReportPath !== "string") {
31
31
  throw new TypeError(
32
32
  `performanceReportPath must be a string but received ${performanceReportPath}`,
33
33
  )
34
34
  }
35
- projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl)
35
+ rootDirectoryUrl = assertAndNormalizeDirectoryUrl(rootDirectoryUrl)
36
36
  const performanceReportUrl = resolveUrl(
37
37
  performanceReportPath,
38
- projectDirectoryUrl,
38
+ rootDirectoryUrl,
39
39
  )
40
40
 
41
41
  return commentGitHubPullRequestImpact({
42
42
  logLevel,
43
43
  commandLogs,
44
44
  cancelOnSIGINT,
45
- projectDirectoryUrl,
45
+ rootDirectoryUrl,
46
46
 
47
47
  githubToken,
48
48
  repositoryOwner,