@nwutils/getter 0.2.4 → 0.2.5
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 +25 -24
- package/package.json +27 -11
- package/src/decompress.js +15 -16
- package/src/ffmpeg.js +25 -22
- package/src/main.js +94 -33
- package/src/node.js +13 -9
- package/src/nw.js +40 -45
- package/src/request.js +29 -19
- package/src/verify.js +19 -12
- package/types/main.d.ts +1 -1
package/README.md
CHANGED
|
@@ -6,7 +6,6 @@ Download NW.js and related binaries for Linux, MacOS and Windows.
|
|
|
6
6
|
|
|
7
7
|
## Getting Started
|
|
8
8
|
|
|
9
|
-
1. Install [Volta](https://volta.sh)
|
|
10
9
|
1. `npm i` to install third party dependencies
|
|
11
10
|
|
|
12
11
|
## Usage
|
|
@@ -15,17 +14,17 @@ Download NW.js and related binaries for Linux, MacOS and Windows.
|
|
|
15
14
|
import get from "@nwutils/getter";
|
|
16
15
|
|
|
17
16
|
await get({
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
version: "latest",
|
|
18
|
+
flavor: "normal",
|
|
19
|
+
platform: "linux",
|
|
20
|
+
arch: "x64",
|
|
21
|
+
downloadUrl: "https://dl.nwjs.io",
|
|
22
|
+
manifestUrl: "https://nwjs.io/versions.json",
|
|
23
|
+
cacheDir: "./cache",
|
|
24
|
+
cache: true,
|
|
25
|
+
ffmpeg: false,
|
|
26
|
+
nativeAddon: false,
|
|
27
|
+
shaSum: true,
|
|
29
28
|
});
|
|
30
29
|
```
|
|
31
30
|
|
|
@@ -33,22 +32,24 @@ await get({
|
|
|
33
32
|
|
|
34
33
|
Options
|
|
35
34
|
|
|
36
|
-
| Name
|
|
37
|
-
|
|
|
38
|
-
| version
|
|
39
|
-
| flavor
|
|
40
|
-
| platform
|
|
41
|
-
| arch
|
|
35
|
+
| Name | Type | Description |
|
|
36
|
+
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
|
|
37
|
+
| version | `string \| "latest" \| "stable"` | Runtime version |
|
|
38
|
+
| flavor | `"normal" \| "sdk"` | Runtime flavor |
|
|
39
|
+
| platform | `"linux" \| "osx" \| "win"` | Host platform |
|
|
40
|
+
| arch | `"ia32" \| "x64" \| "arm64"` | Host architecture |
|
|
42
41
|
| downloadUrl | `"https://dl.nwjs.io" \| "https://npm.taobao.org/mirrors/nwjs" \| https://npmmirror.com/mirrors/nwjs \| "https://github.com/corwin-of-amber/nw.js/releases/"` | Download server. Supports file systems too (for example `file:///home/user/nwjs_mirror`) |
|
|
43
|
-
| manifestUrl | `"https://nwjs.io/versions.json" \| "https://raw.githubusercontent.com/nwutils/nw-builder/main/src/util/osx.arm.versions.json"`
|
|
44
|
-
| cacheDir
|
|
45
|
-
| cache
|
|
46
|
-
| ffmpeg
|
|
47
|
-
| nativeAddon | `boolean`
|
|
48
|
-
| shaSum
|
|
42
|
+
| manifestUrl | `"https://nwjs.io/versions.json" \| "https://raw.githubusercontent.com/nwutils/nw-builder/main/src/util/osx.arm.versions.json"` | Versions manifest |
|
|
43
|
+
| cacheDir | `string` | Directory to cache NW binaries |
|
|
44
|
+
| cache | `boolean` | If true the existing cache is used. Otherwise it removes and redownloads it. |
|
|
45
|
+
| ffmpeg | `boolean` | If true the chromium ffmpeg is replaced by community version with proprietary codecs. |
|
|
46
|
+
| nativeAddon | `boolean` | If true download NW.js Node headers. |
|
|
47
|
+
| shaSum | `boolean` | Flag to enable/disable shasum checks. |
|
|
49
48
|
|
|
50
49
|
## Contributing
|
|
51
50
|
|
|
51
|
+
- [ ] Extract code coverage into seperate action
|
|
52
|
+
|
|
52
53
|
### External contributor
|
|
53
54
|
|
|
54
55
|
- Use Node.js standard libraries whenever possible.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nwutils/getter",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "Get NW.js and related binaries for Linux, MacOS and Windows.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"NW.js",
|
|
@@ -39,27 +39,43 @@
|
|
|
39
39
|
"url": "git+https://github.com/nwutils/getter.git"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
|
+
"format": "prettier --check .",
|
|
43
|
+
"format:fix": "prettier --write .",
|
|
42
44
|
"lint": "eslint .",
|
|
45
|
+
"lint:fix": "eslint . --fix",
|
|
43
46
|
"type": "tsc",
|
|
44
47
|
"test": "node --test --experimental-test-coverage --test-coverage-exclude=\"tests/**/*\" \"tests/specs/*.test.js\""
|
|
45
48
|
},
|
|
46
|
-
"volta": {
|
|
47
|
-
"node": "25.1.0",
|
|
48
|
-
"npm": "11.7.0"
|
|
49
|
-
},
|
|
50
49
|
"dependencies": {
|
|
51
|
-
"semver": "^7.
|
|
52
|
-
"tar": "^7.5.
|
|
50
|
+
"semver": "^7.8.5",
|
|
51
|
+
"tar": "^7.5.20",
|
|
53
52
|
"yauzl-promise": "^4.0.0"
|
|
54
53
|
},
|
|
55
54
|
"devDependencies": {
|
|
56
55
|
"@eslint/js": "^10.0.1",
|
|
57
|
-
"@types/node": "^
|
|
56
|
+
"@types/node": "^26.1.1",
|
|
58
57
|
"@types/semver": "^7.7.1",
|
|
59
58
|
"@types/yauzl-promise": "^4.0.1",
|
|
60
|
-
"eslint": "^10.0
|
|
61
|
-
"eslint-plugin-jsdoc": "^
|
|
59
|
+
"eslint": "^10.7.0",
|
|
60
|
+
"eslint-plugin-jsdoc": "^63.1.0",
|
|
61
|
+
"eslint-plugin-simple-import-sort": "^14.0.0",
|
|
62
62
|
"globals": "^17.4.0",
|
|
63
|
-
"
|
|
63
|
+
"prettier": "^3.9.5",
|
|
64
|
+
"typescript": "^7.0.2"
|
|
65
|
+
},
|
|
66
|
+
"devEngines": {
|
|
67
|
+
"runtime": {
|
|
68
|
+
"name": "node",
|
|
69
|
+
"version": "26.1.0",
|
|
70
|
+
"onFail": "warn"
|
|
71
|
+
},
|
|
72
|
+
"packageManager": {
|
|
73
|
+
"name": "npm",
|
|
74
|
+
"version": "12.0.1",
|
|
75
|
+
"onFail": "warn"
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
"prettier": {
|
|
79
|
+
"endOfLine": "lf"
|
|
64
80
|
}
|
|
65
81
|
}
|
package/src/decompress.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import stream from "node:stream";
|
|
1
4
|
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import stream from 'node:stream';
|
|
5
|
-
|
|
6
|
-
import * as tar from 'tar';
|
|
7
|
-
import yauzl from 'yauzl-promise';
|
|
5
|
+
import * as tar from "tar";
|
|
6
|
+
import yauzl from "yauzl-promise";
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* Decompresses a file at `filePath` to `cacheDir` directory.
|
|
@@ -16,12 +15,12 @@ import yauzl from 'yauzl-promise';
|
|
|
16
15
|
* @returns {Promise<void>}
|
|
17
16
|
*/
|
|
18
17
|
export default async function decompress(filePath, cacheDir) {
|
|
19
|
-
if (filePath.endsWith(
|
|
18
|
+
if (filePath.endsWith(".zip")) {
|
|
20
19
|
await unzip(filePath, cacheDir);
|
|
21
20
|
} else {
|
|
22
21
|
await tar.extract({
|
|
23
22
|
file: filePath,
|
|
24
|
-
C: cacheDir
|
|
23
|
+
C: cacheDir,
|
|
25
24
|
});
|
|
26
25
|
}
|
|
27
26
|
}
|
|
@@ -37,7 +36,7 @@ function modeFromEntry(entry) {
|
|
|
37
36
|
const attr = entry.externalFileAttributes >> 16 || 33188;
|
|
38
37
|
|
|
39
38
|
return [448 /* S_IRWXU */, 56 /* S_IRWXG */, 7 /* S_IRWXO */]
|
|
40
|
-
.map(mask => attr & mask)
|
|
39
|
+
.map((mask) => attr & mask)
|
|
41
40
|
.reduce((a, b) => a + b, attr & 61440 /* S_IFMT */);
|
|
42
41
|
}
|
|
43
42
|
|
|
@@ -59,16 +58,16 @@ async function unzip(zippedFile, cacheDir) {
|
|
|
59
58
|
while (entry !== null) {
|
|
60
59
|
let entryPathAbs = path.join(cacheDir, entry.filename);
|
|
61
60
|
/* Check if entry is a symbolic link */
|
|
62
|
-
const isSymlink = (
|
|
61
|
+
const isSymlink = (modeFromEntry(entry) & 0o170000) === 0o120000;
|
|
63
62
|
|
|
64
63
|
if (isSymlink) {
|
|
65
64
|
/* Store symlink entries to process later */
|
|
66
65
|
symlinks.push(entry);
|
|
67
66
|
} else {
|
|
68
67
|
/* Handle regular files and directories */
|
|
69
|
-
await fs.promises.mkdir(path.dirname(entryPathAbs), {recursive: true});
|
|
70
|
-
|
|
71
|
-
if (!entry.filename.endsWith(
|
|
68
|
+
await fs.promises.mkdir(path.dirname(entryPathAbs), { recursive: true });
|
|
69
|
+
/* Skip directories */
|
|
70
|
+
if (!entry.filename.endsWith("/")) {
|
|
72
71
|
const readStream = await entry.openReadStream();
|
|
73
72
|
const writeStream = fs.createWriteStream(entryPathAbs);
|
|
74
73
|
await stream.promises.pipeline(readStream, writeStream);
|
|
@@ -89,9 +88,9 @@ async function unzip(zippedFile, cacheDir) {
|
|
|
89
88
|
const readStream = await symlinkEntry.openReadStream();
|
|
90
89
|
/** @type {Buffer[]} */
|
|
91
90
|
const chunks = [];
|
|
92
|
-
readStream.on(
|
|
93
|
-
await new Promise(resolve => readStream.on(
|
|
94
|
-
const linkTarget = Buffer.concat(chunks).toString(
|
|
91
|
+
readStream.on("data", (chunk) => chunks.push(chunk));
|
|
92
|
+
await new Promise((resolve) => readStream.on("end", resolve));
|
|
93
|
+
const linkTarget = Buffer.concat(chunks).toString("utf8").trim();
|
|
95
94
|
|
|
96
95
|
/* Check if the symlink or a file/directory already exists at the destination */
|
|
97
96
|
if (fs.existsSync(entryPathAbs)) {
|
package/src/ffmpeg.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import path from
|
|
1
|
+
import path from "node:path";
|
|
2
2
|
|
|
3
|
-
import request from
|
|
3
|
+
import request from "./request.js";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Download community FFmpeg binary from `https://github.com/nwjs-ffmpeg-prebuilt/nwjs-ffmpeg-prebuilt`.
|
|
@@ -14,26 +14,29 @@ import request from './request.js';
|
|
|
14
14
|
* @throws {Error} - When download fails
|
|
15
15
|
* @returns {Promise<string>} - Path of compressed file which containscommunity FFmpeg binary.
|
|
16
16
|
*/
|
|
17
|
-
export default async function ffmpeg(
|
|
17
|
+
export default async function ffmpeg(
|
|
18
|
+
downloadUrl,
|
|
19
|
+
version,
|
|
20
|
+
platform,
|
|
21
|
+
arch,
|
|
22
|
+
cacheDir,
|
|
23
|
+
) {
|
|
24
|
+
/**
|
|
25
|
+
* URL to download specific FFmpeg binary from.
|
|
26
|
+
* @type {string}
|
|
27
|
+
*/
|
|
28
|
+
const url = [downloadUrl, version, `${version}-${platform}-${arch}.zip`].join(
|
|
29
|
+
"/",
|
|
30
|
+
);
|
|
18
31
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
`${version}-${platform}-${arch}.zip`,
|
|
27
|
-
].join('/');
|
|
32
|
+
/**
|
|
33
|
+
* Absolute path of compressed file which contains FFmpeg binary.
|
|
34
|
+
*/
|
|
35
|
+
const ffmpegFileAbs = path.resolve(
|
|
36
|
+
cacheDir,
|
|
37
|
+
`ffmpeg-${version}-${platform}-${arch}.zip`,
|
|
38
|
+
);
|
|
28
39
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
*/
|
|
32
|
-
const ffmpegFileAbs = path.resolve(
|
|
33
|
-
cacheDir,
|
|
34
|
-
`ffmpeg-${version}-${platform}-${arch}.zip`,
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
await request(url, ffmpegFileAbs);
|
|
38
|
-
return ffmpegFileAbs;
|
|
40
|
+
await request(url, ffmpegFileAbs);
|
|
41
|
+
return ffmpegFileAbs;
|
|
39
42
|
}
|
package/src/main.js
CHANGED
|
@@ -34,24 +34,26 @@ import verify from "./verify.js";
|
|
|
34
34
|
* @returns {Promise<void>}
|
|
35
35
|
*/
|
|
36
36
|
async function get(options) {
|
|
37
|
-
|
|
38
37
|
/* If `options.cacheDir` exists, then `true`. Otherwise, it is `false`. */
|
|
39
38
|
if (fs.existsSync(options.cacheDir) === false) {
|
|
40
39
|
await fs.promises.mkdir(options.cacheDir, { recursive: true });
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
const manifestFilePath = path.resolve(options.cacheDir, "manifest.json");
|
|
44
|
-
if (options.manifestUrl.startsWith(
|
|
43
|
+
if (options.manifestUrl.startsWith("file://")) {
|
|
45
44
|
const filePath = url.fileURLToPath(options.manifestUrl);
|
|
46
|
-
fs.writeFileSync(manifestFilePath, fs.readFileSync(filePath,
|
|
45
|
+
fs.writeFileSync(manifestFilePath, fs.readFileSync(filePath, "utf-8"));
|
|
47
46
|
} else {
|
|
48
47
|
await request(options.manifestUrl, manifestFilePath);
|
|
49
48
|
}
|
|
50
|
-
const manifestData = JSON.parse(
|
|
49
|
+
const manifestData = JSON.parse(
|
|
50
|
+
await fs.promises.readFile(manifestFilePath, "utf-8"),
|
|
51
|
+
);
|
|
51
52
|
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
if (
|
|
54
|
+
options.version === "latest" ||
|
|
55
|
+
options.version === "stable" ||
|
|
56
|
+
options.version === "lts"
|
|
55
57
|
) {
|
|
56
58
|
options.version = manifestData[options.version].slice(1);
|
|
57
59
|
} else {
|
|
@@ -59,63 +61,107 @@ async function get(options) {
|
|
|
59
61
|
if (coerced && semver.valid(coerced)) {
|
|
60
62
|
options.version = coerced.version;
|
|
61
63
|
} else {
|
|
62
|
-
throw new Error(
|
|
64
|
+
throw new Error(
|
|
65
|
+
'Expected "options.version" to be "latest", "stable", "lts" or a valid semver version. Received: ' +
|
|
66
|
+
options.version,
|
|
67
|
+
);
|
|
63
68
|
}
|
|
64
69
|
}
|
|
65
70
|
|
|
66
71
|
if (options.flavor !== "normal" && options.flavor !== "sdk") {
|
|
67
|
-
throw new Error(
|
|
72
|
+
throw new Error(
|
|
73
|
+
'Expected "options.flavor" to be "normal" or "sdk". Received: ' +
|
|
74
|
+
options.flavor,
|
|
75
|
+
);
|
|
68
76
|
}
|
|
69
77
|
|
|
70
|
-
if (
|
|
71
|
-
|
|
78
|
+
if (
|
|
79
|
+
options.platform !== "linux" &&
|
|
80
|
+
options.platform !== "osx" &&
|
|
81
|
+
options.platform !== "win"
|
|
82
|
+
) {
|
|
83
|
+
throw new Error(
|
|
84
|
+
'Expected "options.platform" to be "linux", "osx" or "win". Received: ' +
|
|
85
|
+
options.platform,
|
|
86
|
+
);
|
|
72
87
|
}
|
|
73
88
|
|
|
74
|
-
if (
|
|
75
|
-
|
|
89
|
+
if (
|
|
90
|
+
options.arch !== "ia32" &&
|
|
91
|
+
options.arch !== "x64" &&
|
|
92
|
+
options.arch !== "arm64"
|
|
93
|
+
) {
|
|
94
|
+
throw new Error(
|
|
95
|
+
'Expected "options.arch" to be "ia32", "x64" or "arm64". Received: ' +
|
|
96
|
+
options.arch,
|
|
97
|
+
);
|
|
76
98
|
}
|
|
77
99
|
|
|
78
100
|
if (typeof options.downloadUrl !== "string") {
|
|
79
|
-
throw new Error(
|
|
101
|
+
throw new Error(
|
|
102
|
+
'Expected "options.downloadUrl" to be a string. Received: ' +
|
|
103
|
+
options.downloadUrl,
|
|
104
|
+
);
|
|
80
105
|
}
|
|
81
106
|
|
|
82
107
|
if (typeof options.manifestUrl !== "string") {
|
|
83
|
-
throw new Error(
|
|
108
|
+
throw new Error(
|
|
109
|
+
'Expected "options.manifestUrl" to be a string. Received: ' +
|
|
110
|
+
options.manifestUrl,
|
|
111
|
+
);
|
|
84
112
|
}
|
|
85
113
|
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
114
|
+
if (
|
|
115
|
+
typeof options.manifestUrl == "string" &&
|
|
116
|
+
options.manifestUrl.startsWith("file://") === false &&
|
|
117
|
+
options.manifestUrl.startsWith("http://") === false &&
|
|
118
|
+
options.manifestUrl.startsWith("https://") === false
|
|
90
119
|
) {
|
|
91
|
-
throw new Error(
|
|
120
|
+
throw new Error(
|
|
121
|
+
'Expected "options.manifestUrl" to be a string starting with "file://", "http://", or "https://". Received: ' +
|
|
122
|
+
options.manifestUrl,
|
|
123
|
+
);
|
|
92
124
|
}
|
|
93
125
|
|
|
94
126
|
if (typeof options.cacheDir !== "string") {
|
|
95
|
-
throw new Error(
|
|
127
|
+
throw new Error(
|
|
128
|
+
'Expected "options.cacheDir" to be a string. Received: ' +
|
|
129
|
+
options.cacheDir,
|
|
130
|
+
);
|
|
96
131
|
}
|
|
97
132
|
|
|
98
133
|
if (typeof options.cache !== "boolean") {
|
|
99
|
-
throw new Error(
|
|
134
|
+
throw new Error(
|
|
135
|
+
'Expected "options.cache" to be a boolean. Received: ' + options.cache,
|
|
136
|
+
);
|
|
100
137
|
}
|
|
101
138
|
|
|
102
139
|
if (typeof options.ffmpeg !== "boolean") {
|
|
103
|
-
throw new Error(
|
|
140
|
+
throw new Error(
|
|
141
|
+
'Expected "options.ffmpeg" to be a boolean. Received: ' + options.ffmpeg,
|
|
142
|
+
);
|
|
104
143
|
}
|
|
105
144
|
|
|
106
145
|
if (typeof options.nativeAddon !== "boolean") {
|
|
107
|
-
throw new Error(
|
|
146
|
+
throw new Error(
|
|
147
|
+
'Expected "options.nativeAddon" to be a boolean. Received: ' +
|
|
148
|
+
options.nativeAddon,
|
|
149
|
+
);
|
|
108
150
|
}
|
|
109
151
|
|
|
110
152
|
if (typeof options.shaSum !== "boolean") {
|
|
111
|
-
throw new Error(
|
|
153
|
+
throw new Error(
|
|
154
|
+
'Expected "options.shaSum" to be a boolean. Received: ' + options.shaSum,
|
|
155
|
+
);
|
|
112
156
|
}
|
|
113
157
|
|
|
114
158
|
const uri = new url.URL(options.downloadUrl);
|
|
115
159
|
|
|
116
160
|
/* Download server is the cached directory. */
|
|
117
161
|
if (uri.protocol === "file:") {
|
|
118
|
-
options.cacheDir = path.resolve(
|
|
162
|
+
options.cacheDir = path.resolve(
|
|
163
|
+
decodeURIComponent(options.downloadUrl.slice("file://".length)),
|
|
164
|
+
);
|
|
119
165
|
}
|
|
120
166
|
|
|
121
167
|
/**
|
|
@@ -124,7 +170,8 @@ async function get(options) {
|
|
|
124
170
|
*/
|
|
125
171
|
let nwFilePath = path.resolve(
|
|
126
172
|
options.cacheDir,
|
|
127
|
-
`nwjs${options.flavor === "sdk" ? "-sdk" : ""}-v${options.version}-${options.platform}-${options.arch}.${
|
|
173
|
+
`nwjs${options.flavor === "sdk" ? "-sdk" : ""}-v${options.version}-${options.platform}-${options.arch}.${
|
|
174
|
+
options.platform === "linux" ? "tar.gz" : "zip"
|
|
128
175
|
}`,
|
|
129
176
|
);
|
|
130
177
|
|
|
@@ -153,7 +200,14 @@ async function get(options) {
|
|
|
153
200
|
|
|
154
201
|
/* If the compressed binary exists, then `true`. Otherwise, it is `false`. */
|
|
155
202
|
if (fs.existsSync(nwFilePath) === false) {
|
|
156
|
-
nwFilePath = await nw(
|
|
203
|
+
nwFilePath = await nw(
|
|
204
|
+
options.downloadUrl,
|
|
205
|
+
options.version,
|
|
206
|
+
options.flavor,
|
|
207
|
+
options.platform,
|
|
208
|
+
options.arch,
|
|
209
|
+
options.cacheDir,
|
|
210
|
+
);
|
|
157
211
|
}
|
|
158
212
|
|
|
159
213
|
await decompress(nwFilePath, options.cacheDir);
|
|
@@ -167,7 +221,6 @@ async function get(options) {
|
|
|
167
221
|
);
|
|
168
222
|
|
|
169
223
|
if (options.ffmpeg === true) {
|
|
170
|
-
|
|
171
224
|
/**
|
|
172
225
|
* File path to compressed binary which contains community FFmpeg binary.
|
|
173
226
|
* @type {string}
|
|
@@ -190,7 +243,13 @@ async function get(options) {
|
|
|
190
243
|
// Do not update the options.downloadUrl with the ffmpeg URL here. Doing so would lead to error when options.ffmpeg and options.nativeAddon are both enabled.
|
|
191
244
|
const downloadUrl =
|
|
192
245
|
"https://github.com/nwjs-ffmpeg-prebuilt/nwjs-ffmpeg-prebuilt/releases/download";
|
|
193
|
-
ffmpegFilePath = await ffmpeg(
|
|
246
|
+
ffmpegFilePath = await ffmpeg(
|
|
247
|
+
downloadUrl,
|
|
248
|
+
options.version,
|
|
249
|
+
options.platform,
|
|
250
|
+
options.arch,
|
|
251
|
+
options.cacheDir,
|
|
252
|
+
);
|
|
194
253
|
}
|
|
195
254
|
|
|
196
255
|
await decompress(ffmpegFilePath, options.cacheDir);
|
|
@@ -239,11 +298,9 @@ async function get(options) {
|
|
|
239
298
|
}
|
|
240
299
|
|
|
241
300
|
await fs.promises.copyFile(ffmpegBinaryPath, ffmpegBinaryDest);
|
|
242
|
-
|
|
243
301
|
}
|
|
244
302
|
|
|
245
303
|
if (options.nativeAddon === true) {
|
|
246
|
-
|
|
247
304
|
/**
|
|
248
305
|
* File path to NW.js Node headers tarball.
|
|
249
306
|
* @type {string}
|
|
@@ -263,7 +320,11 @@ async function get(options) {
|
|
|
263
320
|
|
|
264
321
|
/* If the compressed binary exists, then `true`. Otherwise, it is `false`. */
|
|
265
322
|
if (fs.existsSync(nodeFilePath) === false) {
|
|
266
|
-
nodeFilePath = await node(
|
|
323
|
+
nodeFilePath = await node(
|
|
324
|
+
options.downloadUrl,
|
|
325
|
+
options.version,
|
|
326
|
+
options.cacheDir,
|
|
327
|
+
);
|
|
267
328
|
}
|
|
268
329
|
|
|
269
330
|
await decompress(nodeFilePath, options.cacheDir);
|
package/src/node.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import path from
|
|
1
|
+
import path from "node:path";
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import semver from "semver";
|
|
4
|
+
|
|
5
|
+
import request from "./request.js";
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* Download NW.js's Node.js headers.
|
|
@@ -13,7 +15,6 @@ import request from './request.js';
|
|
|
13
15
|
* @returns {Promise<string>} - path of compressed file which contains the Node headers.
|
|
14
16
|
*/
|
|
15
17
|
export default async function nw(downloadUrl, version, cacheDir) {
|
|
16
|
-
|
|
17
18
|
/**
|
|
18
19
|
* Name of directory which contains Node headers.
|
|
19
20
|
* @type {string}
|
|
@@ -26,6 +27,12 @@ export default async function nw(downloadUrl, version, cacheDir) {
|
|
|
26
27
|
*/
|
|
27
28
|
const nwFile = `${nodeDir}.tar.gz`;
|
|
28
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Prefix of Node headers file name. For reference: [nwjs/nw.js@471e406](https://github.com/nwjs/nw.js/blob/471e406/lib/node.js)
|
|
32
|
+
* @type {string}
|
|
33
|
+
*/
|
|
34
|
+
const headersPrefix = semver.gte(version, "0.111.3") ? "node" : "nw-headers";
|
|
35
|
+
|
|
29
36
|
/**
|
|
30
37
|
* URL to download specific Node headers from.
|
|
31
38
|
* @type {string}
|
|
@@ -33,16 +40,13 @@ export default async function nw(downloadUrl, version, cacheDir) {
|
|
|
33
40
|
const url = [
|
|
34
41
|
downloadUrl,
|
|
35
42
|
`v${version}`,
|
|
36
|
-
|
|
37
|
-
].join(
|
|
43
|
+
`${headersPrefix}-v${version}.tar.gz`,
|
|
44
|
+
].join("/");
|
|
38
45
|
|
|
39
46
|
/**
|
|
40
47
|
* Absolute path of compressed file which contains Node headers.
|
|
41
48
|
*/
|
|
42
|
-
const nwFileAbs = path.resolve(
|
|
43
|
-
cacheDir,
|
|
44
|
-
nwFile
|
|
45
|
-
);
|
|
49
|
+
const nwFileAbs = path.resolve(cacheDir, nwFile);
|
|
46
50
|
|
|
47
51
|
await request(url, nwFileAbs);
|
|
48
52
|
return nwFileAbs;
|
package/src/nw.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import path from "node:path";
|
|
1
2
|
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import request from './request.js';
|
|
3
|
+
import request from "./request.js";
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Download NW.js binary.
|
|
@@ -16,46 +15,42 @@ import request from './request.js';
|
|
|
16
15
|
* @throws {Error} - When download fails
|
|
17
16
|
* @returns {Promise<string>} - Path of compressed file which contains NW.js binaries.
|
|
18
17
|
*/
|
|
19
|
-
export default async function nw(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
await request(url, nwFileAbs);
|
|
59
|
-
|
|
60
|
-
return nwFileAbs;
|
|
18
|
+
export default async function nw(
|
|
19
|
+
downloadUrl,
|
|
20
|
+
version,
|
|
21
|
+
flavor,
|
|
22
|
+
platform,
|
|
23
|
+
arch,
|
|
24
|
+
cacheDir,
|
|
25
|
+
) {
|
|
26
|
+
/**
|
|
27
|
+
* Name of directory which contains NW.js binaries.
|
|
28
|
+
* @type {string}
|
|
29
|
+
*/
|
|
30
|
+
const nwDir = [
|
|
31
|
+
"nwjs",
|
|
32
|
+
flavor === "sdk" ? "-sdk" : "",
|
|
33
|
+
`-v${version}-${platform}-${arch}`,
|
|
34
|
+
].join("");
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Name of compressed file which contains NW.js binaries.
|
|
38
|
+
* @type {string}
|
|
39
|
+
*/
|
|
40
|
+
const nwFile = [nwDir, platform === "linux" ? "tar.gz" : "zip"].join(".");
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* URL to download specific NW.js binary from.
|
|
44
|
+
* @type {string}
|
|
45
|
+
*/
|
|
46
|
+
const url = [downloadUrl, `v${version}`, nwFile].join("/");
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Absolute path of compressed file which contains NW.js binaries.
|
|
50
|
+
*/
|
|
51
|
+
const nwFileAbs = path.resolve(cacheDir, nwFile);
|
|
52
|
+
|
|
53
|
+
await request(url, nwFileAbs);
|
|
54
|
+
|
|
55
|
+
return nwFileAbs;
|
|
61
56
|
}
|
package/src/request.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import fs from
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { URL } from
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import http from "node:http";
|
|
3
|
+
import https from "node:https";
|
|
4
|
+
import process from "node:process";
|
|
5
|
+
import { URL } from "node:url";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Download from `url` and save at `filePath`.
|
|
@@ -12,13 +12,13 @@ import { URL } from 'node:url';
|
|
|
12
12
|
*/
|
|
13
13
|
export default function request(url, filePath) {
|
|
14
14
|
const parsedUrl = new URL(url);
|
|
15
|
-
const client = parsedUrl.protocol ===
|
|
15
|
+
const client = parsedUrl.protocol === "https:" ? https : http;
|
|
16
16
|
|
|
17
17
|
return new Promise((resolve, reject) => {
|
|
18
18
|
const writeStream = fs.createWriteStream(filePath);
|
|
19
19
|
|
|
20
20
|
/* Handle writeStream errors immediately */
|
|
21
|
-
writeStream.on(
|
|
21
|
+
writeStream.on("error", (err) => {
|
|
22
22
|
cleanup();
|
|
23
23
|
reject(err);
|
|
24
24
|
});
|
|
@@ -31,52 +31,62 @@ export default function request(url, filePath) {
|
|
|
31
31
|
}
|
|
32
32
|
process.exit();
|
|
33
33
|
};
|
|
34
|
-
process.once(
|
|
34
|
+
process.once("SIGINT", onSigInt);
|
|
35
35
|
|
|
36
36
|
const req = client.get(
|
|
37
37
|
{
|
|
38
38
|
hostname: parsedUrl.hostname,
|
|
39
|
-
port: parsedUrl.port || (parsedUrl.protocol ===
|
|
39
|
+
port: parsedUrl.port || (parsedUrl.protocol === "https:" ? 443 : 80),
|
|
40
40
|
path: parsedUrl.pathname + parsedUrl.search,
|
|
41
41
|
headers: {
|
|
42
|
-
|
|
43
|
-
}
|
|
42
|
+
"User-Agent": "node:http(s)",
|
|
43
|
+
},
|
|
44
44
|
},
|
|
45
45
|
(res) => {
|
|
46
46
|
/* Redirect handling */
|
|
47
|
-
if (
|
|
47
|
+
if (
|
|
48
|
+
res.statusCode &&
|
|
49
|
+
res.statusCode >= 300 &&
|
|
50
|
+
res.statusCode < 400 &&
|
|
51
|
+
res.headers.location
|
|
52
|
+
) {
|
|
48
53
|
cleanup();
|
|
49
54
|
|
|
50
|
-
const redirectedUrl = new URL(
|
|
55
|
+
const redirectedUrl = new URL(
|
|
56
|
+
res.headers.location,
|
|
57
|
+
parsedUrl,
|
|
58
|
+
).toString();
|
|
51
59
|
return resolve(request(redirectedUrl, filePath));
|
|
52
60
|
}
|
|
53
61
|
|
|
54
62
|
if (res.statusCode !== 200) {
|
|
55
63
|
cleanup();
|
|
56
|
-
return reject(
|
|
64
|
+
return reject(
|
|
65
|
+
new Error(`Request failed. Status code: ${res.statusCode}`),
|
|
66
|
+
);
|
|
57
67
|
}
|
|
58
68
|
|
|
59
69
|
res.pipe(writeStream);
|
|
60
70
|
|
|
61
|
-
writeStream.on(
|
|
71
|
+
writeStream.on("finish", () => {
|
|
62
72
|
cleanup();
|
|
63
73
|
resolve();
|
|
64
74
|
});
|
|
65
75
|
|
|
66
|
-
res.on(
|
|
76
|
+
res.on("error", (err) => {
|
|
67
77
|
cleanup();
|
|
68
78
|
reject(err);
|
|
69
79
|
});
|
|
70
|
-
}
|
|
80
|
+
},
|
|
71
81
|
);
|
|
72
82
|
|
|
73
|
-
req.on(
|
|
83
|
+
req.on("error", (err) => {
|
|
74
84
|
cleanup();
|
|
75
85
|
reject(err);
|
|
76
86
|
});
|
|
77
87
|
|
|
78
88
|
function cleanup() {
|
|
79
|
-
process.removeListener(
|
|
89
|
+
process.removeListener("SIGINT", onSigInt);
|
|
80
90
|
req.destroy();
|
|
81
91
|
writeStream.destroy();
|
|
82
92
|
}
|
package/src/verify.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import crypto from
|
|
2
|
-
import fs from
|
|
3
|
-
import path from
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
4
|
|
|
5
|
-
import request from
|
|
5
|
+
import request from "./request.js";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Verify the SHA256 checksum of downloaded artifacts.
|
|
@@ -12,7 +12,7 @@ import request from './request.js';
|
|
|
12
12
|
* @param {string} shaOut - File path to shasum text file.
|
|
13
13
|
* @param {string} cacheDir - File path to cache directory.
|
|
14
14
|
* @param {boolean} ffmpeg - Toggle between community (true) and official (false) ffmpeg binary
|
|
15
|
-
* @param {boolean} shaSum - Throws error if true, otherwise logs a warning.
|
|
15
|
+
* @param {boolean} shaSum - Throws error if true, otherwise logs a warning.
|
|
16
16
|
* @throws {Error}
|
|
17
17
|
* @returns {Promise<boolean>} - Returns true if the checksums match.
|
|
18
18
|
*/
|
|
@@ -28,20 +28,27 @@ export default async function verify(shaUrl, shaOut, cacheDir, ffmpeg, shaSum) {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
/* Read SHASUM text file */
|
|
31
|
-
const shasum = await fs.promises.readFile(shaOut, { encoding:
|
|
32
|
-
const shasums = shasum.trim().split(
|
|
31
|
+
const shasum = await fs.promises.readFile(shaOut, { encoding: "utf-8" });
|
|
32
|
+
const shasums = shasum.trim().split("\n");
|
|
33
33
|
for await (const line of shasums) {
|
|
34
34
|
const [storedSha, filePath] = line.split(/\s+/);
|
|
35
35
|
const relativeFilePath = path.resolve(cacheDir, filePath);
|
|
36
36
|
const relativefilePathExists = fs.existsSync(relativeFilePath);
|
|
37
37
|
if (relativefilePathExists) {
|
|
38
38
|
const fileBuffer = await fs.promises.readFile(relativeFilePath);
|
|
39
|
-
const hash = crypto.createHash(
|
|
39
|
+
const hash = crypto.createHash("sha256");
|
|
40
40
|
hash.update(fileBuffer);
|
|
41
|
-
const generatedSha = hash.digest(
|
|
42
|
-
if (
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
const generatedSha = hash.digest("hex");
|
|
42
|
+
if (
|
|
43
|
+
!crypto.timingSafeEqual(
|
|
44
|
+
Buffer.from(generatedSha, "hex"),
|
|
45
|
+
Buffer.from(storedSha, "hex"),
|
|
46
|
+
)
|
|
47
|
+
) {
|
|
48
|
+
if (filePath.includes("ffmpeg") && ffmpeg) {
|
|
49
|
+
console.warn(
|
|
50
|
+
`The generated shasum for the community ffmpeg at ${filePath} is ${generatedSha}. The integrity of this file should be manually verified.`,
|
|
51
|
+
);
|
|
45
52
|
} else {
|
|
46
53
|
const message = `SHA256 checksums do not match. The file ${filePath} expected shasum is ${storedSha} but the actual shasum is ${generatedSha}.`;
|
|
47
54
|
if (shaSum) {
|