nw-builder 4.5.2 → 4.5.4

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/src/get.js CHANGED
@@ -1,91 +1,36 @@
1
- import child_process from "node:child_process";
2
- import console from "node:console";
3
1
  import fs from "node:fs";
4
- import fsm from "node:fs/promises";
5
2
  import https from "node:https";
6
3
  import path from "node:path";
7
4
 
8
5
  import progress from "cli-progress";
9
6
  import tar from "tar";
10
- import unzipper from "unzipper";
11
7
 
12
8
  import util from "./util.js";
13
9
 
14
10
  /**
15
11
  * @typedef {object} GetOptions
16
- * @property {string | "latest" | "stable" | "lts"} [options.version = "latest"] Runtime version
17
- * @property {"normal" | "sdk"} [options.flavor = "normal"] Build flavor
18
- * @property {"linux" | "osx" | "win"} [options.platform] Target platform
19
- * @property {"ia32" | "x64" | "arm64"} [options.arch] Target arch
20
- * @property {string} [options.downloadUrl = "https://dl.nwjs.io"] Download server
21
- * @property {string} [options.cacheDir = "./cache"] Cache directory
22
- * @property {boolean} [options.cache = true] If false, remove cache and redownload.
23
- * @property {boolean} [options.ffmpeg = false] If true, ffmpeg is not downloaded.
24
- * @property {false | "gyp"} [options.nativeAddon = false] Rebuild native modules
12
+ * @property {string | "latest" | "stable" | "lts"} [version = "latest"] Runtime version
13
+ * @property {"normal" | "sdk"} [flavor = "normal"] Build flavor
14
+ * @property {"linux" | "osx" | "win"} [platform] Target platform
15
+ * @property {"ia32" | "x64" | "arm64"} [arch] Target arch
16
+ * @property {string} [downloadUrl = "https://dl.nwjs.io"] Download server
17
+ * @property {string} [cacheDir = "./cache"] Cache directory
18
+ * @property {boolean} [cache = true] If false, remove cache and redownload.
19
+ * @property {boolean} [ffmpeg = false] If true, ffmpeg is not downloaded.
20
+ * @property {false | "gyp"} [nativeAddon = false] Rebuild native modules
25
21
  */
26
22
 
27
23
  /**
28
24
  * Get binaries.
29
- *
25
+ *
30
26
  * @async
31
27
  * @function
32
28
  * @param {GetOptions} options Get mode options
33
29
  * @returns {Promise<void>}
34
- *
35
- * @example
36
- * // Minimal Usage (uses default values)
37
- * nwbuild({
38
- * mode: "get",
39
- * });
40
- *
41
- * // Use with nw module
42
- * nwbuild({
43
- * mode: "get",
44
- * cacheDir: "./node_modules/nw"
45
- * });
46
- *
47
- * @example
48
- * // Unofficial macOS builds (upto v0.75.0)
49
- * nwbuild({
50
- * mode: "get",
51
- * platform: "osx",
52
- * arch: "arm64",
53
- * downloadUrl: "https://github.com/corwin-of-amber/nw.js/releases/download",
54
- * manifestUrl: "https://raw.githubusercontent.com/nwutils/nw-builder/main/src/util/osx.arm.versions.json",
55
- * });
56
- *
57
- * @example
58
- * // China mirror
59
- * nwbuild({
60
- * mode: "get",
61
- * downloadUrl: "https://npm.taobao.org/mirrors/nwjs",
62
- * });
63
- *
64
- * @example
65
- * // Singapore mirror
66
- * nwbuild({
67
- * mode: "get",
68
- * downloadUrl: "https://cnpmjs.org/mirrors/nwjs/",
69
- * });
70
- *
71
- * @example
72
- * // FFMPEG (proprietary codecs)
73
- * // Please read the license's constraints: https://nwjs.readthedocs.io/en/latest/For%20Developers/Enable%20Proprietary%20Codecs/#get-ffmpeg-binaries-from-the-community
74
- * nwbuild({
75
- * mode: "get",
76
- * ffmpeg: true,
77
- * });
78
- *
79
- * @example
80
- * // Node headers
81
- * nwbuild({
82
- * mode: "get",
83
- * nativeAddon: "gyp",
84
- * });
85
30
  */
86
31
  async function get(options) {
87
32
  if (fs.existsSync(options.cacheDir) === false) {
88
- await fsm.mkdir(options.cacheDir, { recursive: true });
33
+ await fs.promises.mkdir(options.cacheDir, { recursive: true });
89
34
  }
90
35
  await getNwjs(options);
91
36
  if (options.ffmpeg === true) {
@@ -105,14 +50,14 @@ const getNwjs = async (options) => {
105
50
  );
106
51
  // If options.cache is false, remove cache.
107
52
  if (options.cache === false) {
108
- await fsm.rm(out, {
53
+ await fs.promises.rm(out, {
109
54
  recursive: true,
110
55
  force: true,
111
56
  });
112
57
  }
113
58
 
114
59
  if (fs.existsSync(out) === true) {
115
- await fsm.rm(
60
+ await fs.promises.rm(
116
61
  path.resolve(
117
62
  options.cacheDir,
118
63
  `nwjs${options.flavor === "sdk" ? "-sdk" : ""}-v${options.version}-${options.platform}-${options.arch}`,
@@ -125,13 +70,10 @@ const getNwjs = async (options) => {
125
70
  C: options.cacheDir
126
71
  });
127
72
  } else {
128
- fs.createReadStream(out)
129
- .pipe(unzipper.Extract({ path: options.cacheDir }))
130
- .on("finish", async () => {
131
- if (options.platform === "osx") {
132
- await createSymlinks(options);
133
- }
134
- });
73
+ await util.unzip(out, options.cacheDir);
74
+ if (options.platform === "osx") {
75
+ await createSymlinks(options);
76
+ }
135
77
  }
136
78
  return;
137
79
  }
@@ -147,8 +89,8 @@ const getNwjs = async (options) => {
147
89
  options.downloadUrl === "https://npmmirror.com/mirrors/nwjs"
148
90
  ) {
149
91
  url = `${options.downloadUrl}/v${options.version}/nwjs${options.flavor === "sdk" ? "-sdk" : ""
150
- }-v${options.version}-${options.platform}-${options.arch}.${options.platform === "linux" ? "tar.gz" : "zip"
151
- }`;
92
+ }-v${options.version}-${options.platform}-${options.arch}.${options.platform === "linux" ? "tar.gz" : "zip"
93
+ }`;
152
94
  }
153
95
 
154
96
  https.get(url, (response) => {
@@ -188,7 +130,7 @@ const getNwjs = async (options) => {
188
130
  });
189
131
 
190
132
  await request;
191
- await fsm.rm(
133
+ await fs.promises.rm(
192
134
  path.resolve(
193
135
  options.cacheDir,
194
136
  `nwjs${options.flavor === "sdk" ? "-sdk" : ""}-v${options.version}-${options.platform}-${options.arch}`,
@@ -201,13 +143,11 @@ const getNwjs = async (options) => {
201
143
  C: options.cacheDir
202
144
  });
203
145
  } else {
204
- fs.createReadStream(out)
205
- .pipe(unzipper.Extract({ path: options.cacheDir }))
206
- .on("finish", async () => {
207
- if (options.platform === "osx") {
208
- await createSymlinks(options);
209
- }
210
- });
146
+ await util.unzip(out, options.cacheDir);
147
+ if (options.platform === "osx") {
148
+ await createSymlinks(options);
149
+ }
150
+
211
151
  }
212
152
  }
213
153
 
@@ -226,7 +166,7 @@ const getFfmpeg = async (options) => {
226
166
 
227
167
  // If options.cache is false, remove cache.
228
168
  if (options.cache === false) {
229
- await fsm.rm(out, {
169
+ await fs.promises.rm(out, {
230
170
  recursive: true,
231
171
  force: true,
232
172
  });
@@ -234,8 +174,7 @@ const getFfmpeg = async (options) => {
234
174
 
235
175
  // Check if cache exists.
236
176
  if (fs.existsSync(out) === true) {
237
- fs.createReadStream(out)
238
- .pipe(unzipper.Extract({ path: nwDir }));
177
+ await util.unzip(out, nwDir);
239
178
  return;
240
179
  }
241
180
 
@@ -274,8 +213,7 @@ const getFfmpeg = async (options) => {
274
213
 
275
214
  // Remove compressed file after download and decompress.
276
215
  await request;
277
- fs.createReadStream(out)
278
- .pipe(unzipper.Extract({ path: nwDir }));
216
+ await util.unzip(out, nwDir);
279
217
  await util.replaceFfmpeg(options.platform, nwDir);
280
218
  }
281
219
 
@@ -288,7 +226,7 @@ const getNodeHeaders = async (options) => {
288
226
 
289
227
  // If options.cache is false, remove cache.
290
228
  if (options.cache === false) {
291
- await fsm.rm(out, {
229
+ await fs.promises.rm(out, {
292
230
  recursive: true,
293
231
  force: true,
294
232
  });
@@ -299,28 +237,15 @@ const getNodeHeaders = async (options) => {
299
237
  file: out,
300
238
  C: options.cacheDir
301
239
  });
302
- await fsm.rm(path.resolve(options.cacheDir, `node-v${options.version}-${options.platform}-${options.arch}`), {
240
+ await fs.promises.rm(path.resolve(options.cacheDir, `node-v${options.version}-${options.platform}-${options.arch}`), {
303
241
  recursive: true,
304
242
  force: true,
305
243
  });
306
- await fsm.rename(
244
+ await fs.promises.rename(
307
245
  path.resolve(options.cacheDir, "node"),
308
246
  path.resolve(options.cacheDir, `node-v${options.version}-${options.platform}-${options.arch}`),
309
247
  );
310
-
311
- child_process.exec(
312
- "patch " +
313
- path.resolve(
314
- options.cacheDir,
315
- `node-v${options.version}-${options.platform}-${options.arch}`,
316
- "common.gypi",
317
- ) +
318
- " " +
319
- path.resolve("..", "..", "patches", "node_header.patch"),
320
- (error) => {
321
- console.error(error);
322
- },
323
- );
248
+ return;
324
249
  }
325
250
 
326
251
  const stream = fs.createWriteStream(out);
@@ -353,7 +278,7 @@ const getNodeHeaders = async (options) => {
353
278
  file: out,
354
279
  C: options.cacheDir
355
280
  });
356
- await fsm.rename(
281
+ await fs.promises.rename(
357
282
  path.resolve(options.cacheDir, "node"),
358
283
  path.resolve(options.cacheDir, `node-v${options.version}-${options.platform}-${options.arch}`),
359
284
  );
@@ -369,9 +294,10 @@ const createSymlinks = async (options) => {
369
294
  path.join(frameworksPath, "Versions", "Current"),
370
295
  ];
371
296
  for await (const symlink of symlinks) {
372
- const link = String(await fsm.readFile(symlink));
373
- await fsm.rm(symlink);
374
- await fsm.symlink(link, symlink);
297
+ const buffer = await fs.promises.readFile(symlink);
298
+ const link = buffer.toString();
299
+ await fs.promises.rm(symlink);
300
+ await fs.promises.symlink(link, symlink);
375
301
  }
376
302
  };
377
303
 
package/src/index.js CHANGED
@@ -2,9 +2,6 @@ import console from "node:console";
2
2
  import fs from "node:fs";
3
3
  import fsm from "node:fs/promises";
4
4
 
5
- import { parse } from "./util/parse.js";
6
- import { validate } from "./util/validate.js";
7
-
8
5
  import bld from "./bld.js";
9
6
  import get from "./get.js";
10
7
  import run from "./run.js";
@@ -32,63 +29,29 @@ import util from "./util.js";
32
29
  */
33
30
 
34
31
  /**
35
- * Installation Guide
36
- *
37
- * Every NW.js release includes a modified Node.js binary at a specific version. It is recommended to [install](https://nodejs.org/en/download/package-manager) exactly that version on the host system. Not doing so may download ABI incompatible Node modules. Consult the NW.js [versions manifest](https://nwjs.io/versions) for what Node.js version to install. It is recommended to use a Node version manager (such as [volta](https://volta.sh), n, nvm, or nvm-windows) to be able to easily install and switch between Node versions.
38
- *
39
- * Please refer to the examples below for basic usage.
40
- *
41
- * @example
42
- * // ESM usage:
43
- *
44
- * import nwbuild from "nw-builder";
45
- *
46
- * @example
47
- * // CJS usage
48
- *
49
- * let nwbuild = undefined;
50
- *
51
- * (() => {
52
- * try {
53
- * nwbuild = await import("nw-builder");
54
- * } catch(error) {
55
- * console.error(error);
56
- * }
57
- * })();
58
- *
59
- * @example
60
- * // Module usage
61
- *
62
- * nwbuild();
63
- *
64
- * @example
65
- * // CLI usage
66
- *
67
- * npx nwbuild
68
- *
69
- * @example
70
- * // Node manifest usage
71
- *
72
- * "nwbuild": {}
73
- *
32
+ * Main module exported
33
+ *
34
+ * @async
35
+ * @function
36
+ *
74
37
  * @param {Options} options Options
75
- * @return {Promise<undefined>}
38
+ * @returns {Promise<void>}
76
39
  */
77
- const nwbuild = async (options) => {
40
+ async function nwbuild (options) {
78
41
  let built;
79
42
  let releaseInfo = {};
80
43
  let manifest = {};
81
44
 
82
45
  try {
83
46
  // Parse options
84
- options = await parse(options, manifest);
47
+ options = await util.parse(options, manifest);
85
48
 
86
49
  manifest = await util.getNodeManifest({ srcDir: options.srcDir, glob: options.glob });
87
50
  if (typeof manifest?.nwbuild === "object") {
88
51
  options = manifest.nwbuild;
89
52
  }
90
53
 
91
- options = await parse(options, manifest);
54
+ options = await util.parse(options, manifest);
92
55
 
93
56
  //TODO: impl logging
94
57
 
@@ -113,7 +76,7 @@ const nwbuild = async (options) => {
113
76
  options.manifestUrl,
114
77
  );
115
78
 
116
- await validate(options, releaseInfo);
79
+ await util.validate(options, releaseInfo);
117
80
 
118
81
  // Remove leading "v" from version string
119
82
  options.version = releaseInfo.version.slice(1);
@@ -168,6 +131,6 @@ const nwbuild = async (options) => {
168
131
  console.error(error);
169
132
  throw error;
170
133
  }
171
- };
134
+ }
172
135
 
173
136
  export default nwbuild;
package/src/run.js CHANGED
@@ -22,14 +22,9 @@ import util from "./util.js";
22
22
  *
23
23
  * @async
24
24
  * @function
25
- * @param {RunOptions} options Run mode options
26
- * @return {Promise<void>}
27
25
  *
28
- * @example
29
- * // Minimal Usage (uses default values)
30
- * nwbuild({
31
- * mode: "run",
32
- * });
26
+ * @param {RunOptions} options Run mode options
27
+ * @returns {Promise<void>}
33
28
  */
34
29
  async function run({
35
30
  version = "latest",