@nwutils/getter 0.1.6 → 0.2.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nwutils/getter",
3
- "version": "0.1.6",
3
+ "version": "0.2.2",
4
4
  "description": "Get NW.js and related binaries for Linux, MacOS and Windows.",
5
5
  "keywords": [
6
6
  "NW.js",
@@ -26,6 +26,7 @@
26
26
  ],
27
27
  "license": "MIT",
28
28
  "main": "./src/main.js",
29
+ "types": "types",
29
30
  "type": "module",
30
31
  "files": [
31
32
  "LICENSE",
@@ -37,15 +38,27 @@
37
38
  "url": "git+https://github.com/nwutils/getter.git"
38
39
  },
39
40
  "scripts": {
41
+ "lint": "eslint .",
42
+ "type": "tsc",
40
43
  "test": "node --test --experimental-test-coverage --test-coverage-exclude=\"tests/**/*\" \"tests/specs/*.test.js\""
41
44
  },
42
45
  "volta": {
43
- "node": "24.9.0",
44
- "npm": "11.6.2"
46
+ "node": "25.1.0",
47
+ "npm": "11.7.0"
45
48
  },
46
49
  "dependencies": {
47
50
  "semver": "^7.7.3",
48
- "tar": "^7.5.2",
51
+ "tar": "^7.5.4",
49
52
  "yauzl-promise": "^4.0.0"
53
+ },
54
+ "devDependencies": {
55
+ "@eslint/js": "^9.39.2",
56
+ "@types/node": "^25.0.10",
57
+ "@types/semver": "^7.7.1",
58
+ "@types/yauzl-promise": "^4.0.1",
59
+ "eslint": "^9.39.2",
60
+ "eslint-plugin-jsdoc": "^62.1.0",
61
+ "globals": "^17.0.0",
62
+ "typescript": "^5.9.3"
50
63
  }
51
64
  }
package/src/decompress.js CHANGED
@@ -87,6 +87,7 @@ async function unzip(zippedFile, cacheDir) {
87
87
  for (const symlinkEntry of symlinks) {
88
88
  let entryPathAbs = path.join(cacheDir, symlinkEntry.filename);
89
89
  const readStream = await symlinkEntry.openReadStream();
90
+ /** @type {Buffer[]} */
90
91
  const chunks = [];
91
92
  readStream.on('data', (chunk) => chunks.push(chunk));
92
93
  await new Promise(resolve => readStream.on('end', resolve));
package/src/ffmpeg.js CHANGED
@@ -35,4 +35,5 @@ export default async function ffmpeg(downloadUrl, version, platform, arch, cache
35
35
  );
36
36
 
37
37
  await request(url, ffmpegFileAbs);
38
+ return ffmpegFileAbs;
38
39
  }
package/src/main.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
- import process from "node:process";
4
3
  import url from "node:url";
5
4
 
6
5
  import semver from "semver";
@@ -17,9 +16,9 @@ import verify from "./verify.js";
17
16
  * @property {string | "latest" | "stable" | "lts"} version Runtime version
18
17
  * @property {"normal" | "sdk"} flavor Build flavor
19
18
  * @property {"linux" | "osx" | "win"} platform Target platform
20
- * @property {"ia32" | "x64" | "arm64"} arch Target arch
21
- * @property {"https://dl.nwjs.io"} downloadUrl Download server
22
- * @property {"https://nwjs.io/versions.json"} manifestUrl Manifest URL
19
+ * @property {"ia32" | "x64" | "arm64"} arch Target architecture
20
+ * @property {"https://dl.nwjs.io"} downloadUrl Download server, accepts http and https
21
+ * @property {"https://nwjs.io/versions.json"} manifestUrl Manifest URI, accepts file, http and https
23
22
  * @property {string} cacheDir Cache directory
24
23
  * @property {boolean} cache If false, remove cache and redownload.
25
24
  * @property {boolean} ffmpeg If true, ffmpeg is not downloaded.
@@ -42,15 +41,26 @@ async function get(options) {
42
41
  }
43
42
 
44
43
  const manifestFilePath = path.resolve(options.cacheDir, "manifest.json");
45
- await request(options.manifestUrl, manifestFilePath);
44
+ if (options.manifestUrl.startsWith('file://')) {
45
+ const filePath = url.fileURLToPath(options.manifestUrl);
46
+ fs.writeFileSync(manifestFilePath, fs.readFileSync(filePath, 'utf-8'));
47
+ } else {
48
+ await request(options.manifestUrl, manifestFilePath);
49
+ }
46
50
  const manifestData = JSON.parse(await fs.promises.readFile(manifestFilePath, "utf-8"));
47
51
 
48
- if (options.version === "latest" | options.version === "stable" | options.version === "lts") {
52
+ if (options.version === "latest"
53
+ || options.version === "stable"
54
+ || options.version === "lts"
55
+ ) {
49
56
  options.version = manifestData[options.version].slice(1);
50
- } else if (semver.valid(semver.coerce(options.version))) {
51
- options.version = semver.coerce(options.version).version;
52
57
  } else {
53
- throw new Error('Expected "options.version" to be "latest", "stable", "lts" or a valid semver version. Received: ' + options.version);
58
+ const coerced = semver.coerce(options.version);
59
+ if (coerced && semver.valid(coerced)) {
60
+ options.version = coerced.version;
61
+ } else {
62
+ throw new Error('Expected "options.version" to be "latest", "stable", "lts" or a valid semver version. Received: ' + options.version);
63
+ }
54
64
  }
55
65
 
56
66
  if (options.flavor !== "normal" && options.flavor !== "sdk") {
@@ -73,6 +83,14 @@ async function get(options) {
73
83
  throw new Error('Expected "options.manifestUrl" to be a string. Received: ' + options.manifestUrl);
74
84
  }
75
85
 
86
+ if (typeof options.manifestUrl == "string"
87
+ && options.manifestUrl.startsWith('file://') === false
88
+ && options.manifestUrl.startsWith('http://') === false
89
+ && options.manifestUrl.startsWith('https://') === false
90
+ ) {
91
+ throw new Error('Expected "options.manifestUrl" to be a string starting with "file://", "http://", or "https://". Received: ' + options.manifestUrl);
92
+ }
93
+
76
94
  if (typeof options.cacheDir !== "string") {
77
95
  throw new Error('Expected "options.cacheDir" to be a string. Received: ' + options.cacheDir);
78
96
  }
package/src/node.js CHANGED
@@ -45,4 +45,5 @@ export default async function nw(downloadUrl, version, cacheDir) {
45
45
  );
46
46
 
47
47
  await request(url, nwFileAbs);
48
+ return nwFileAbs;
48
49
  }
package/src/request.js CHANGED
@@ -44,7 +44,7 @@ export default function request(url, filePath) {
44
44
  },
45
45
  (res) => {
46
46
  /* Redirect handling */
47
- if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
47
+ if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
48
48
  cleanup();
49
49
 
50
50
  const redirectedUrl = new URL(res.headers.location, parsedUrl).toString();