@jsenv/file-size-impact 12.1.1 → 12.1.2

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.
File without changes
File without changes
package/package.json CHANGED
@@ -1,65 +1,56 @@
1
1
  {
2
2
  "name": "@jsenv/file-size-impact",
3
- "version": "12.1.1",
3
+ "version": "12.1.2",
4
4
  "description": "Add files size impact into pull requests",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "https://github.com/jsenv/file-size-impact"
8
+ "url": "https://github.com/jsenv/workflow",
9
+ "directory": "packages/jsenv-file-size-impact"
9
10
  },
10
11
  "engines": {
11
12
  "node": ">=14.17.0"
12
13
  },
13
14
  "publishConfig": {
14
- "access": "public"
15
+ "access": "public",
16
+ "registry": "https://registry.npmjs.org"
15
17
  },
16
18
  "type": "module",
17
19
  "exports": {
18
20
  ".": {
19
- "import": "./index.js"
21
+ "import": "./main.js"
20
22
  },
21
23
  "./*": "./*"
22
24
  },
25
+ "main": "./main.js",
23
26
  "files": [
24
27
  "/src/",
25
- "/index.js"
28
+ "/main.js"
26
29
  ],
27
30
  "scripts": {
28
- "eslint-check": "node ./node_modules/eslint/bin/eslint.js . --ext=.js,.mjs",
29
- "generate-importmap": "node ./script/importmap/generate_importmap.mjs",
30
- "measure-file-sizes": "node ./script/file_size/generate_file_size_report.mjs --log",
31
- "generate-comment-snapshot-file": "node ./test/comment/generate_comment_snapshot_file.mjs",
31
+ "eslint": "npx eslint . --ext=.js,.mjs",
32
+ "importmap": "node ./script/importmap/importmap.mjs",
33
+ "snapshot": "node ./test/comment/generate_comment_snapshot_file.mjs",
32
34
  "test": "node ./script/test/test.mjs",
33
35
  "test-with-coverage": "npm run test -- --coverage",
34
- "prettier-format": "node ./script/prettier/prettier_format.mjs",
35
- "prettier-format-stage": "npm run prettier-format -- --staged",
36
- "prettier-check": "npm run prettier-format -- --dry-run",
37
- "prepublishOnly": "node ./script/publish/remove_postinstall.mjs",
38
- "postpublish": "node ./script/publish/restore_postinstall.mjs"
36
+ "file-size": "node ./script/file_size/file_size.mjs --log",
37
+ "prettier": "prettier --write ."
39
38
  },
40
39
  "dependencies": {
41
40
  "@jsenv/dynamic-import-worker": "1.0.0",
42
- "@jsenv/filesystem": "2.3.1",
43
- "@jsenv/github-pull-request-impact": "1.6.4",
41
+ "@jsenv/filesystem": "2.7.1",
42
+ "@jsenv/github-pull-request-impact": "1.6.6",
44
43
  "@jsenv/logger": "4.0.1",
45
44
  "pretty-bytes": "5.6.0"
46
45
  },
47
46
  "devDependencies": {
48
- "@babel/core": "7.15.8",
49
- "@babel/eslint-parser": "7.15.8",
50
- "@jsenv/assert": "2.3.2",
51
- "@jsenv/cancellation": "3.0.0",
52
- "@jsenv/codecov-upload": "3.5.0",
53
- "@jsenv/core": "23.0.5",
54
- "@jsenv/eslint-config": "16.0.8",
55
- "@jsenv/filesystem": "2.2.0",
56
- "@jsenv/github-release-package": "1.2.3",
57
- "@jsenv/importmap-eslint-resolver": "5.1.2",
58
- "@jsenv/importmap-node-module": "2.4.1",
59
- "@jsenv/package-publish": "1.6.2",
60
- "@jsenv/prettier-check-project": "5.6.1",
61
- "eslint": "7.32.0",
62
- "eslint-plugin-import": "2.25.2",
63
- "prettier": "2.4.1"
47
+ "@jsenv/assert": "2.4.1",
48
+ "@jsenv/core": "25.3.0",
49
+ "@jsenv/eslint-config": "16.0.9",
50
+ "@jsenv/importmap-eslint-resolver": "5.2.5",
51
+ "@jsenv/importmap-node-module": "5.1.3",
52
+ "eslint": "8.7.0",
53
+ "eslint-plugin-import": "2.25.4",
54
+ "prettier": "2.5.1"
64
55
  }
65
56
  }
@@ -1,10 +1,14 @@
1
- import { brotliCompress, constants } from "zlib"
1
+ import { brotliCompress, constants } from "node:zlib"
2
2
 
3
3
  export const name = "brotli"
4
4
 
5
5
  export const transform = (
6
6
  value,
7
- { quality = constants.BROTLI_MAX_QUALITY, size = Buffer.from(value).length, ...rest } = {},
7
+ {
8
+ quality = constants.BROTLI_MAX_QUALITY,
9
+ size = Buffer.from(value).length,
10
+ ...rest
11
+ } = {},
8
12
  ) => {
9
13
  return new Promise((resolve, reject) => {
10
14
  brotliCompress(
@@ -12,7 +16,8 @@ export const transform = (
12
16
  {
13
17
  params: {
14
18
  [constants.BROTLI_PARAM_QUALITY]: quality,
15
- [constants.BROTLI_PARAM_SIZE_HINT]: typeof size === "number" ? size : 0,
19
+ [constants.BROTLI_PARAM_SIZE_HINT]:
20
+ typeof size === "number" ? size : 0,
16
21
  ...rest,
17
22
  },
18
23
  },
@@ -1,4 +1,3 @@
1
- import { createDetailedMessage, createLogger } from "@jsenv/logger"
2
1
  import {
3
2
  assertAndNormalizeDirectoryUrl,
4
3
  bufferToEtag,
@@ -6,6 +5,7 @@ import {
6
5
  readFile,
7
6
  urlToFileSystemPath,
8
7
  } from "@jsenv/filesystem"
8
+ import { createDetailedMessage, createLogger } from "@jsenv/logger"
9
9
 
10
10
  import { transform as rawTransform } from "./rawTransformation.js"
11
11
  import { jsenvTrackingConfig } from "./jsenvTrackingConfig.js"
@@ -47,12 +47,15 @@ export const generateFileSizeReport = async ({
47
47
  await Promise.all(
48
48
  groupNames.map(async (groupName) => {
49
49
  const groupTrackingResult = groupTrackingResults[groupName]
50
- const groupReport = await groupTrackingResultToGroupReport(groupTrackingResult, {
51
- logger,
52
- projectDirectoryUrl,
53
- tracking: trackingConfig[groupName],
54
- transformations,
55
- })
50
+ const groupReport = await groupTrackingResultToGroupReport(
51
+ groupTrackingResult,
52
+ {
53
+ logger,
54
+ projectDirectoryUrl,
55
+ tracking: trackingConfig[groupName],
56
+ transformations,
57
+ },
58
+ )
56
59
  groups[groupName] = groupReport
57
60
  }),
58
61
  )
@@ -78,18 +81,26 @@ const groupTrackingResultToGroupReport = async (
78
81
  const manifestRelativeUrls = Object.keys(manifestMetaMap)
79
82
  await Promise.all(
80
83
  manifestRelativeUrls.map(async (manifestRelativeUrl) => {
81
- const manifestFileUrl = resolveUrl(manifestRelativeUrl, projectDirectoryUrl)
82
- const manifestFileContent = await readFile(manifestFileUrl, { as: "string" })
84
+ const manifestFileUrl = resolveUrl(
85
+ manifestRelativeUrl,
86
+ projectDirectoryUrl,
87
+ )
88
+ const manifestFileContent = await readFile(manifestFileUrl, {
89
+ as: "string",
90
+ })
83
91
  let manifest
84
92
  try {
85
93
  manifest = JSON.parse(manifestFileContent)
86
94
  } catch (e) {
87
95
  if (e.name === "SyntaxError") {
88
96
  logger.error(
89
- createDetailedMessage(`JSON.parse error while trying to parse a manifest file`, {
90
- "error stack": e.stack,
91
- "manifest file": urlToFileSystemPath(manifestFileUrl),
92
- }),
97
+ createDetailedMessage(
98
+ `JSON.parse error while trying to parse a manifest file`,
99
+ {
100
+ "error stack": e.stack,
101
+ "manifest file": urlToFileSystemPath(manifestFileUrl),
102
+ },
103
+ ),
93
104
  )
94
105
  return
95
106
  }
@@ -109,7 +120,11 @@ const groupTrackingResultToGroupReport = async (
109
120
  const fileUrl = resolveUrl(fileRelativeUrl, projectDirectoryUrl)
110
121
  const fileContent = await readFile(fileUrl)
111
122
  const fileBuffer = Buffer.from(fileContent)
112
- const sizeMap = await getFileSizeMap(fileBuffer, { transformations, logger, fileUrl })
123
+ const sizeMap = await getFileSizeMap(fileBuffer, {
124
+ transformations,
125
+ logger,
126
+ fileUrl,
127
+ })
113
128
  const hash = bufferToEtag(fileBuffer)
114
129
  fileMap[fileRelativeUrl] = {
115
130
  sizeMap,
@@ -125,7 +140,10 @@ const groupTrackingResultToGroupReport = async (
125
140
  }
126
141
  }
127
142
 
128
- const getFileSizeMap = async (fileBuffer, { transformations, logger, fileUrl }) => {
143
+ const getFileSizeMap = async (
144
+ fileBuffer,
145
+ { transformations, logger, fileUrl },
146
+ ) => {
129
147
  const sizeMap = {}
130
148
  await Object.keys(transformations).reduce(async (previous, sizeName) => {
131
149
  await previous
@@ -135,9 +153,12 @@ const getFileSizeMap = async (fileBuffer, { transformations, logger, fileUrl })
135
153
  sizeMap[sizeName] = Buffer.from(transformResult).length
136
154
  } catch (e) {
137
155
  logger.error(
138
- createDetailedMessage(`error while transforming ${fileUrl} with ${sizeName}`, {
139
- "error stack": e.stack,
140
- }),
156
+ createDetailedMessage(
157
+ `error while transforming ${fileUrl} with ${sizeName}`,
158
+ {
159
+ "error stack": e.stack,
160
+ },
161
+ ),
141
162
  )
142
163
  sizeMap[sizeName] = "error"
143
164
  }
@@ -1,8 +1,11 @@
1
- import { gzip, constants } from "zlib"
1
+ import { gzip, constants } from "node:zlib"
2
2
 
3
3
  export const name = "gzip"
4
4
 
5
- export const transform = (value, { level = constants.Z_MAX_LEVEL, ...rest } = {}) => {
5
+ export const transform = (
6
+ value,
7
+ { level = constants.Z_MAX_LEVEL, ...rest } = {},
8
+ ) => {
6
9
  return new Promise((resolve, reject) => {
7
10
  gzip(value, { level, ...rest }, (error, buffer) => {
8
11
  if (error) {
@@ -1,9 +1,11 @@
1
- import { urlToFileSystemPath, collectDirectoryMatchReport } from "@jsenv/filesystem"
2
- import { createCancellationToken } from "@jsenv/cancellation"
1
+ import {
2
+ urlToFileSystemPath,
3
+ collectDirectoryMatchReport,
4
+ } from "@jsenv/filesystem"
3
5
 
4
6
  export const applyTrackingConfig = async (
5
7
  trackingConfig,
6
- { cancellationToken = createCancellationToken(), projectDirectoryUrl, manifestConfig },
8
+ { projectDirectoryUrl, manifestConfig },
7
9
  ) => {
8
10
  const result = {}
9
11
  const trackingNames = Object.keys(trackingConfig)
@@ -19,13 +21,15 @@ export const applyTrackingConfig = async (
19
21
  manifestConfig,
20
22
  })
21
23
  result[trackingName] = groupTrackingResult
22
- cancellationToken.throwIfRequested()
23
24
  }),
24
25
  )
25
26
  return result
26
27
  }
27
28
 
28
- const applyTracking = async (tracking, { projectDirectoryUrl, manifestConfig }) => {
29
+ const applyTracking = async (
30
+ tracking,
31
+ { projectDirectoryUrl, manifestConfig },
32
+ ) => {
29
33
  const structuredMetaMap = {
30
34
  track: tracking,
31
35
  ...(manifestConfig ? { manifest: manifestConfig } : {}),
@@ -1,4 +1,4 @@
1
- import { createRequire } from "module"
1
+ import { createRequire } from "node:module"
2
2
 
3
3
  const require = createRequire(import.meta.url)
4
4
 
@@ -1,5 +1,5 @@
1
- import { assertAndNormalizeDirectoryUrl, resolveUrl } from "@jsenv/filesystem"
2
1
  import { commentGitHubPullRequestImpact } from "@jsenv/github-pull-request-impact"
2
+ import { assertAndNormalizeDirectoryUrl, resolveUrl } from "@jsenv/filesystem"
3
3
  import { importOneExportFromFile } from "@jsenv/dynamic-import-worker"
4
4
 
5
5
  import { formatComment } from "./internal/formatComment.js"
@@ -39,13 +39,17 @@ export const reportFileSizeImpact = async ({
39
39
  if (installCommand === null) {
40
40
  // a null installCommand means there is no need to install anything
41
41
  } else if (typeof installCommand !== "string") {
42
- throw new TypeError(`installCommand must be a string but received ${installCommand}`)
42
+ throw new TypeError(
43
+ `installCommand must be a string but received ${installCommand}`,
44
+ )
43
45
  }
44
46
 
45
47
  if (buildCommand === null) {
46
48
  // a null buildCommand means there is no need to build anything
47
49
  } else if (typeof buildCommand !== "string") {
48
- throw new TypeError(`buildCommand must be a string but received ${buildCommand}`)
50
+ throw new TypeError(
51
+ `buildCommand must be a string but received ${buildCommand}`,
52
+ )
49
53
  }
50
54
 
51
55
  if (typeof fileSizeReportModulePath !== "string") {
@@ -54,7 +58,10 @@ export const reportFileSizeImpact = async ({
54
58
  )
55
59
  }
56
60
  projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl)
57
- const fileSizeReportModuleUrl = resolveUrl(fileSizeReportModulePath, projectDirectoryUrl)
61
+ const fileSizeReportModuleUrl = resolveUrl(
62
+ fileSizeReportModulePath,
63
+ projectDirectoryUrl,
64
+ )
58
65
 
59
66
  return commentGitHubPullRequestImpact({
60
67
  logLevel,
@@ -71,7 +78,9 @@ export const reportFileSizeImpact = async ({
71
78
  collectInfo: async ({ execCommandInProjectDirectory }) => {
72
79
  if (installCommand) await execCommandInProjectDirectory(installCommand)
73
80
  if (buildCommand) await execCommandInProjectDirectory(buildCommand)
74
- const fileSizeReport = await importOneExportFromFile(fileSizeReportModuleUrl)
81
+ const fileSizeReport = await importOneExportFromFile(
82
+ fileSizeReportModuleUrl,
83
+ )
75
84
  return { version: 1, data: fileSizeReport }
76
85
  },
77
86
  commentIdentifier: `<!-- Generated by @jsenv/file-size-impact -->`,