UNPKG

1.13 kBJavaScriptView Raw
1import path from "node:path";
2
3import 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 */
13export 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}