@nwutils/getter 0.2.6 → 0.3.1

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2025 Ayushman Chhabra
3
+ Copyright (c) 2026 NW.js Utilities and contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
package/README.md CHANGED
@@ -48,8 +48,6 @@ Options
48
48
 
49
49
  ## Contributing
50
50
 
51
- - [ ] Extract code coverage into seperate action
52
-
53
51
  ### External contributor
54
52
 
55
53
  - Use Node.js standard libraries whenever possible.
@@ -57,5 +55,5 @@ Options
57
55
 
58
56
  ### Maintainer
59
57
 
60
- - npm trusted publishing is used for releases
61
- - a package is released when a maintainer creates a release note for a specific version
58
+ - npm Trusted Publishing with OIDC is used for releases
59
+ - A package is released when a maintainer creates a release note for a specific version
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nwutils/getter",
3
- "version": "0.2.6",
3
+ "version": "0.3.1",
4
4
  "description": "Get NW.js and related binaries for Linux, MacOS and Windows.",
5
5
  "keywords": [
6
6
  "NW.js",
@@ -21,7 +21,7 @@
21
21
  "contributors": [
22
22
  {
23
23
  "name": "@nwutils/getter Contributors",
24
- "url": "https://github.com/nwutils/getter/graphs/contributors"
24
+ "url": "https://github.com/nwutils/nw-builder/graphs/contributors"
25
25
  }
26
26
  ],
27
27
  "license": "MIT",
@@ -33,51 +33,33 @@
33
33
  "src",
34
34
  "types"
35
35
  ],
36
- "homepage": "https://github.com/nwutils/getter",
36
+ "homepage": "https://github.com/nwutils/nw-builder",
37
37
  "repository": {
38
38
  "type": "git",
39
- "url": "git+https://github.com/nwutils/getter.git"
39
+ "url": "git+https://github.com/nwutils/nw-builder.git",
40
+ "directory": "./packages/getter"
40
41
  },
41
42
  "scripts": {
42
- "format": "prettier --check .",
43
- "format:fix": "prettier --write .",
44
- "lint": "eslint .",
45
- "lint:fix": "eslint . --fix",
43
+ "lint": "eslint . ../../tests/specs/getter ../../tests/fixtures/getter",
44
+ "lint:fix": "eslint . ../../tests/specs/getter ../../tests/fixtures/getter --fix",
46
45
  "type": "tsc",
47
- "test": "node --test --experimental-test-coverage --test-coverage-exclude=\"tests/**/*\" \"tests/specs/*.test.js\""
46
+ "test": "node --test --test-concurrency=1 \"../../tests/specs/getter/*.test.js\""
48
47
  },
49
48
  "dependencies": {
50
49
  "semver": "^7.8.5",
51
50
  "tar": "^7.5.22",
52
51
  "yauzl-promise": "^4.0.0"
53
52
  },
54
- "devDependencies": {
55
- "@eslint/js": "^10.0.1",
56
- "@types/node": "^26.4.0",
57
- "@types/semver": "^7.8.0",
58
- "@types/yauzl-promise": "^4.0.1",
59
- "eslint": "^10.9.1",
60
- "eslint-plugin-jsdoc": "^64.2.1",
61
- "eslint-plugin-node-security": "^5.2.3",
62
- "eslint-plugin-secure-coding": "^5.1.4",
63
- "eslint-plugin-simple-import-sort": "^14.0.0",
64
- "globals": "^17.11.0",
65
- "prettier": "^3.9.6",
66
- "typescript": "^7.0.2"
67
- },
68
53
  "devEngines": {
69
54
  "runtime": {
70
55
  "name": "node",
71
- "version": "26.1.0",
56
+ "version": "26.7.0",
72
57
  "onFail": "warn"
73
58
  },
74
59
  "packageManager": {
75
60
  "name": "npm",
76
- "version": "12.0.1",
61
+ "version": "12.0.2",
77
62
  "onFail": "warn"
78
63
  }
79
- },
80
- "prettier": {
81
- "endOfLine": "lf"
82
64
  }
83
65
  }
package/src/decompress.js CHANGED
@@ -46,13 +46,6 @@ export default async function decompress(filePath, cacheDir, limits = {}) {
46
46
  limits.maxTotalExtractedSize ?? MAX_TOTAL_EXTRACTED_SIZE;
47
47
 
48
48
  if (filePath.endsWith(".zip")) {
49
- /*
50
- * Every entry unzip() writes is resolved through resolveWithin() first -
51
- * file entries, symlink names and symlink targets alike. The rule reports
52
- * the call site rather than the write site, so it cannot see that guard
53
- * from here.
54
- */
55
- // eslint-disable-next-line node-security/no-zip-slip
56
49
  await unzip(filePath, cacheDir, maxEntries, maxTotalExtractedSize);
57
50
  } else {
58
51
  /*
@@ -67,7 +60,6 @@ export default async function decompress(filePath, cacheDir, limits = {}) {
67
60
  * `maxTotalExtractedSize` and skips any entry that would exceed it, so
68
61
  * this is bounded even though the linter can't see through the closure.
69
62
  */
70
- // eslint-disable-next-line node-security/no-zip-slip, secure-coding/no-unlimited-resource-allocation
71
63
  await tar.extract({
72
64
  file: filePath,
73
65
  C: cacheDir,
package/src/main.js CHANGED
@@ -250,13 +250,20 @@ async function get(options) {
250
250
  const checksumHost =
251
251
  uri.protocol === "file:" ? options.downloadUrl : "https://dl.nwjs.io";
252
252
 
253
- /* Verify the archive's checksum before extracting its contents. */
253
+ /*
254
+ * The main NW.js binary's SHASUMS256.txt from `dl.nwjs.io` is always
255
+ * plain-text, regardless of `options.ffmpeg` - that flag only switches
256
+ * the JSON format used for the community ffmpeg release below.
257
+ */
254
258
  await verify(
255
259
  `${checksumHost}/v${options.version}/SHASUMS256.txt`,
256
260
  `${options.cacheDir}/shasum/${options.version}.txt`,
257
261
  options.cacheDir,
258
- options.ffmpeg,
262
+ false,
259
263
  options.shaSum,
264
+ options.version,
265
+ options.platform,
266
+ options.arch,
260
267
  path.basename(nwFilePath),
261
268
  );
262
269
 
@@ -294,6 +301,19 @@ async function get(options) {
294
301
  );
295
302
  }
296
303
 
304
+ const ffmpegChecksumHost = `https://api.github.com/repos/nwjs-ffmpeg-prebuilt/nwjs-ffmpeg-prebuilt/releases/tags/${options.version}`;
305
+ await verify(
306
+ `${ffmpegChecksumHost}/SHASUMS256.txt`,
307
+ `${options.cacheDir}/shasum/${options.version}.txt`,
308
+ options.cacheDir,
309
+ options.ffmpeg,
310
+ options.shaSum,
311
+ options.version,
312
+ options.platform,
313
+ options.arch,
314
+ path.basename(ffmpegFilePath),
315
+ );
316
+
297
317
  await decompress(ffmpegFilePath, options.cacheDir);
298
318
 
299
319
  /**
@@ -378,8 +398,11 @@ async function get(options) {
378
398
  `${checksumHost}/v${options.version}/SHASUMS256.txt`,
379
399
  `${options.cacheDir}/shasum/${options.version}.txt`,
380
400
  options.cacheDir,
381
- options.ffmpeg,
401
+ false,
382
402
  options.shaSum,
403
+ options.version,
404
+ options.platform,
405
+ options.arch,
383
406
  headersFileName(options.version),
384
407
  );
385
408
 
package/src/verify.js CHANGED
@@ -8,12 +8,15 @@ import request from "./request.js";
8
8
  * Verify the SHA256 checksum of downloaded artifacts.
9
9
  * @async
10
10
  * @function
11
+ * @param {string} version - Version of NW.js.
12
+ * @param {string} platform - Platform of NW.js.
13
+ * @param {string} arch - Architecture of NW.js.
11
14
  * @param {string} shaUrl - URL to get the shasum text file from.
12
15
  * @param {string} shaOut - File path to shasum text file.
13
16
  * @param {string} cacheDir - File path to cache directory.
14
17
  * @param {boolean} ffmpeg - Toggle between community (true) and official (false) ffmpeg binary
15
18
  * @param {boolean} shaSum - Throws error if true, otherwise logs a warning. Applies to both a checksum mismatch and `expectedFile` never being checked at all.
16
- * @param {string} [expectedFile] - Relative path, as listed in the SHASUMS file, that this call is actually relying on being verified. Other listed files that don't exist locally (eg. other platforms) are still skipped silently - only `expectedFile` going unchecked is treated as a failure, since that means the caller's "integrity verified" belief was never actually true.
19
+ * @param {string} expectedFile - Relative path, as listed in the SHASUMS file, that this call is actually relying on being verified. Other listed files that don't exist locally (eg. other platforms) are still skipped silently - only `expectedFile` going unchecked is treated as a failure, since that means the caller's "integrity verified" belief was never actually true.
17
20
  * @throws {Error}
18
21
  * @returns {Promise<boolean>} - Returns true if the checksums match.
19
22
  */
@@ -23,6 +26,9 @@ export default async function verify(
23
26
  cacheDir,
24
27
  ffmpeg,
25
28
  shaSum,
29
+ version,
30
+ platform,
31
+ arch,
26
32
  expectedFile,
27
33
  ) {
28
34
  const shaOutExists = fs.existsSync(shaOut);
@@ -31,39 +37,74 @@ export default async function verify(
31
37
  /* Create directory if does not exist. */
32
38
  await fs.promises.mkdir(path.dirname(shaOut), { recursive: true });
33
39
 
34
- /* Download SHASUM text file. */
35
- await request(shaUrl, shaOut);
40
+ if (ffmpeg) {
41
+ /* Download SHASUM text file for community ffmpeg binary. */
42
+ await request(shaUrl, shaOut);
43
+ } else {
44
+ /* Download SHASUM text file. */
45
+ await request(shaUrl, shaOut);
46
+ }
36
47
  }
37
48
 
38
- /* Read SHASUM text file */
39
- const shasum = await fs.promises.readFile(shaOut, { encoding: "utf-8" });
40
- const shasums = shasum.trim().split("\n");
49
+ /* TODO: refactor and make it cleaner */
41
50
  let expectedFileWasChecked = false;
51
+ if (ffmpeg) {
52
+ const shasum = JSON.parse(
53
+ await fs.promises.readFile(shaOut, { encoding: "utf-8" }),
54
+ );
55
+ const assetName = `${version}-${platform}-${arch}.zip`;
56
+ for await (const asset of shasum.assets) {
57
+ if (asset.name === assetName) {
58
+ const storedSha = asset.digest.slice(7).toLowerCase();
59
+ const relativeFilePath = path.resolve(cacheDir, expectedFile);
60
+ const relativefilePathExists = fs.existsSync(relativeFilePath);
61
+ if (relativefilePathExists) {
62
+ expectedFileWasChecked = true;
42
63
 
43
- for await (const line of shasums) {
44
- const [storedSha, filePath] = line.split(/\s+/);
45
- const relativeFilePath = path.resolve(cacheDir, filePath);
46
- const relativefilePathExists = fs.existsSync(relativeFilePath);
47
- if (relativefilePathExists) {
48
- if (filePath === expectedFile) {
49
- expectedFileWasChecked = true;
64
+ const fileBuffer = await fs.promises.readFile(relativeFilePath);
65
+ const hash = crypto.createHash("sha256");
66
+ hash.update(fileBuffer);
67
+ const generatedSha = hash.digest("hex");
68
+ if (
69
+ !crypto.timingSafeEqual(
70
+ Buffer.from(generatedSha, "hex"),
71
+ Buffer.from(storedSha, "hex"),
72
+ )
73
+ ) {
74
+ const message = `SHA256 checksums do not match. The file ${expectedFile} expected shasum is ${storedSha} but the actual shasum is ${generatedSha}.`;
75
+ if (shaSum) {
76
+ throw new Error(message);
77
+ } else {
78
+ console.log(message);
79
+ }
80
+ }
81
+ }
50
82
  }
83
+ }
84
+ } else {
85
+ /* Read SHASUM text file */
86
+ const shasum = await fs.promises.readFile(shaOut, { encoding: "utf-8" });
87
+ const shasums = shasum.trim().split("\n");
88
+
89
+ for await (const line of shasums) {
90
+ const [storedSha, filePath] = line.split(/\s+/);
91
+ const relativeFilePath = path.resolve(cacheDir, filePath);
92
+ const relativefilePathExists = fs.existsSync(relativeFilePath);
93
+ if (relativefilePathExists) {
94
+ if (filePath === expectedFile) {
95
+ expectedFileWasChecked = true;
96
+ }
51
97
 
52
- const fileBuffer = await fs.promises.readFile(relativeFilePath);
53
- const hash = crypto.createHash("sha256");
54
- hash.update(fileBuffer);
55
- const generatedSha = hash.digest("hex");
56
- if (
57
- !crypto.timingSafeEqual(
58
- Buffer.from(generatedSha, "hex"),
59
- Buffer.from(storedSha, "hex"),
60
- )
61
- ) {
62
- if (filePath.includes("ffmpeg") && ffmpeg) {
63
- console.warn(
64
- `The generated shasum for the community ffmpeg at ${filePath} is ${generatedSha}. The integrity of this file should be manually verified.`,
65
- );
66
- } else {
98
+ const fileBuffer = await fs.promises.readFile(relativeFilePath);
99
+ const hash = crypto.createHash("sha256");
100
+ hash.update(fileBuffer);
101
+ const generatedSha = hash.digest("hex");
102
+ if (
103
+ !crypto.timingSafeEqual(
104
+ Buffer.from(generatedSha, "hex"),
105
+ Buffer.from(storedSha, "hex"),
106
+ )
107
+ ) {
67
108
  const message = `SHA256 checksums do not match. The file ${filePath} expected shasum is ${storedSha} but the actual shasum is ${generatedSha}.`;
68
109
  if (shaSum) {
69
110
  throw new Error(message);
package/types/verify.d.ts CHANGED
@@ -2,13 +2,16 @@
2
2
  * Verify the SHA256 checksum of downloaded artifacts.
3
3
  * @async
4
4
  * @function
5
+ * @param {string} version - Version of NW.js.
6
+ * @param {string} platform - Platform of NW.js.
7
+ * @param {string} arch - Architecture of NW.js.
5
8
  * @param {string} shaUrl - URL to get the shasum text file from.
6
9
  * @param {string} shaOut - File path to shasum text file.
7
10
  * @param {string} cacheDir - File path to cache directory.
8
11
  * @param {boolean} ffmpeg - Toggle between community (true) and official (false) ffmpeg binary
9
12
  * @param {boolean} shaSum - Throws error if true, otherwise logs a warning. Applies to both a checksum mismatch and `expectedFile` never being checked at all.
10
- * @param {string} [expectedFile] - Relative path, as listed in the SHASUMS file, that this call is actually relying on being verified. Other listed files that don't exist locally (eg. other platforms) are still skipped silently - only `expectedFile` going unchecked is treated as a failure, since that means the caller's "integrity verified" belief was never actually true.
13
+ * @param {string} expectedFile - Relative path, as listed in the SHASUMS file, that this call is actually relying on being verified. Other listed files that don't exist locally (eg. other platforms) are still skipped silently - only `expectedFile` going unchecked is treated as a failure, since that means the caller's "integrity verified" belief was never actually true.
11
14
  * @throws {Error}
12
15
  * @returns {Promise<boolean>} - Returns true if the checksums match.
13
16
  */
14
- export default function verify(shaUrl: string, shaOut: string, cacheDir: string, ffmpeg: boolean, shaSum: boolean, expectedFile?: string): Promise<boolean>;
17
+ export default function verify(shaUrl: string, shaOut: string, cacheDir: string, ffmpeg: boolean, shaSum: boolean, version: string, platform: string, arch: string, expectedFile: string): Promise<boolean>;