Skip to content

Commit d923a27

Browse files
chore(get): factor out node headers download logic (#1022)
### Description of Changes - Factor out Node headers download logic.
1 parent 060f046 commit d923a27

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ nwbuild({
294294
- chore(cli): migrate from `yargs` to `commander`
295295
- chore(get): verify sha checksum for downloads
296296
- chore(util): factor out file paths as constant variables
297-
- chore(get): factor out node headers downloader
298297
- chore(bld): factor out core build step
299298
- chore(bld): factor out linux config
300299
- chore(bld): factor out macos config

src/get/node.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import path from "node:path";
2+
3+
import request from "./request.js";
4+
5+
/**
6+
* Download NW.js's Node.js headers.
7+
*
8+
* @param {string} downloadUrl - Download server
9+
* @param {string} version - Runtime version
10+
* @param {string} cacheDir - Directory to store NW binaries
11+
* @return {Promise<string>} - path of compressed file which contains the Node headers.
12+
*/
13+
export default async function nw(downloadUrl, version, cacheDir) {
14+
15+
/**
16+
* Name of directory which contains Node headers.
17+
*
18+
* @type {string}
19+
*/
20+
const nodeDir = `node-v${version}`;
21+
22+
/**
23+
* Name of compressed file which contains Node headers.
24+
*
25+
* @type {string}
26+
*/
27+
const nwFile = `${nodeDir}.tar.gz`
28+
29+
/**
30+
* URL to download specific Node headers from.
31+
*
32+
* @type {string}
33+
*/
34+
const url = [
35+
downloadUrl,
36+
`v${version}`,
37+
`nw-headers-v${version}.tar.gz`
38+
].join('/');
39+
40+
/**
41+
* Absolute path of compressed file which contains Node headers.
42+
*/
43+
const nwFileAbs = path.resolve(
44+
cacheDir,
45+
nwFile
46+
);
47+
await request(url, nwFileAbs);
48+
49+
return nwFileAbs;
50+
}

src/get/node.test.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import fs from "node:fs";
2+
3+
import { afterEach, describe, expect, it } from "vitest";
4+
5+
import util from "../util.js";
6+
7+
import node from "./node.js";
8+
9+
describe("get/node", function () {
10+
11+
let nodeFile = '';
12+
13+
afterEach(function () {
14+
fs.promises.rm(nodeFile, { recursive: true, force: true });
15+
});
16+
17+
it("downloades Node headers", async function () {
18+
nodeFile = await node(
19+
"https://dl.nwjs.io",
20+
"0.83.0",
21+
"./test/fixture"
22+
);
23+
expect(util.fileExists(nodeFile)).resolves.toBe(true);
24+
}, Infinity);
25+
});

0 commit comments

Comments
 (0)