nw-builder 4.17.13 → 4.18.0

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/util.js CHANGED
@@ -1,11 +1,11 @@
1
- import console from 'node:console';
2
- import fs from 'node:fs';
3
- import https from 'node:https';
4
- import path from 'node:path';
5
- import process from 'node:process';
6
- import url from 'node:url';
1
+ import console from "node:console";
2
+ import fs from "node:fs";
3
+ import https from "node:https";
4
+ import path from "node:path";
5
+ import process from "node:process";
6
+ import url from "node:url";
7
7
 
8
- import * as GlobModule from 'glob';
8
+ import * as GlobModule from "glob";
9
9
 
10
10
  /**
11
11
  * Get manifest (array of NW release metadata) from URL.
@@ -13,31 +13,31 @@ import * as GlobModule from 'glob';
13
13
  * @returns {string} - Manifest object
14
14
  */
15
15
  function getManifest(manifestUrl) {
16
- let chunks = '';
16
+ let chunks = "";
17
17
 
18
- if (manifestUrl && manifestUrl.startsWith('file://')) {
18
+ if (manifestUrl && manifestUrl.startsWith("file://")) {
19
19
  const filePath = url.fileURLToPath(manifestUrl);
20
- return fs.readFileSync(filePath, 'utf-8');
20
+ return fs.readFileSync(filePath, "utf-8");
21
21
  }
22
22
 
23
23
  return new Promise((resolve) => {
24
24
  const req = https.get(manifestUrl, (response) => {
25
- response.on('data', (chunk) => {
25
+ response.on("data", (chunk) => {
26
26
  chunks += chunk;
27
27
  });
28
28
 
29
- response.on('error', (e) => {
29
+ response.on("error", (e) => {
30
30
  console.error(e);
31
- resolve('');
31
+ resolve("");
32
32
  });
33
33
 
34
- response.on('end', () => {
34
+ response.on("end", () => {
35
35
  resolve(chunks);
36
36
  });
37
37
  });
38
- req.on('error', (e) => {
38
+ req.on("error", (e) => {
39
39
  console.error(e);
40
- resolve('');
40
+ resolve("");
41
41
  });
42
42
  });
43
43
  }
@@ -51,19 +51,13 @@ function getManifest(manifestUrl) {
51
51
  * @param {string} manifestUrl Versions manifest URI, https or file path
52
52
  * @returns {Promise<object>} Version specific release info
53
53
  */
54
- async function getReleaseInfo(
55
- version,
56
- platform,
57
- arch,
58
- cacheDir,
59
- manifestUrl,
60
- ) {
54
+ async function getReleaseInfo(version, platform, arch, cacheDir, manifestUrl) {
61
55
  let releaseData = undefined;
62
56
  let manifestPath;
63
- if (platform === 'osx' && arch === 'arm64') {
64
- manifestPath = path.resolve(cacheDir, 'manifest.mac.arm.json');
57
+ if (platform === "osx" && arch === "arm64") {
58
+ manifestPath = path.resolve(cacheDir, "manifest.mac.arm.json");
65
59
  } else {
66
- manifestPath = path.resolve(cacheDir, 'manifest.json');
60
+ manifestPath = path.resolve(cacheDir, "manifest.json");
67
61
  }
68
62
 
69
63
  try {
@@ -73,7 +67,7 @@ async function getReleaseInfo(
73
67
  }
74
68
 
75
69
  const manifest = JSON.parse(await fs.promises.readFile(manifestPath));
76
- if (version === 'latest' || version === 'stable' || version === 'lts') {
70
+ if (version === "latest" || version === "stable" || version === "lts") {
77
71
  // Remove leading "v" from version string
78
72
  version = manifest[version].slice(1);
79
73
  }
@@ -83,28 +77,28 @@ async function getReleaseInfo(
83
77
  );
84
78
  } catch {
85
79
  console.error(
86
- 'The version manifest does not exist/was not downloaded. Please try again in some time.',
80
+ "The version manifest does not exist/was not downloaded. Please try again in some time.",
87
81
  );
88
82
  }
89
83
  return releaseData;
90
84
  }
91
85
 
92
86
  const PLATFORM_KV = {
93
- darwin: 'osx',
94
- linux: 'linux',
95
- win32: 'win',
87
+ darwin: "osx",
88
+ linux: "linux",
89
+ win32: "win",
96
90
  };
97
91
 
98
92
  const ARCH_KV = {
99
- x64: 'x64',
100
- ia32: 'ia32',
101
- arm64: 'arm64',
93
+ x64: "x64",
94
+ ia32: "ia32",
95
+ arm64: "arm64",
102
96
  };
103
97
 
104
98
  const EXE_NAME = {
105
- win: 'nw.exe',
106
- osx: 'nwjs.app/Contents/MacOS/nwjs',
107
- linux: 'nw',
99
+ win: "nw.exe",
100
+ osx: "nwjs.app/Contents/MacOS/nwjs",
101
+ linux: "nw",
108
102
  };
109
103
 
110
104
  /**
@@ -116,10 +110,7 @@ const EXE_NAME = {
116
110
  * @param {boolean} options.glob - glob flag
117
111
  * @returns {Promise<string[]>} - Returns array of file paths
118
112
  */
119
- async function globFiles({
120
- srcDir,
121
- glob,
122
- }) {
113
+ async function globFiles({ srcDir, glob }) {
123
114
  let files;
124
115
  let patterns;
125
116
  if (glob) {
@@ -127,13 +118,15 @@ async function globFiles({
127
118
  if (Array.isArray(srcDir)) {
128
119
  patterns = srcDir;
129
120
  } else {
130
- patterns = srcDir.split(' ');
121
+ patterns = srcDir.split(" ");
131
122
  }
132
123
 
133
- for (const pattern of patterns) {
134
- let filePath = await GlobModule.glob(pattern);
135
- files.push(...filePath);
136
- }
124
+ const include = patterns.filter((p) => !p.startsWith("!"));
125
+ const ignore = patterns
126
+ .filter((p) => p.startsWith("!"))
127
+ .map((p) => p.substring(1));
128
+ let filePath = await GlobModule.glob(include, { ignore });
129
+ files.push(...filePath);
137
130
  } else {
138
131
  files = srcDir;
139
132
  }
@@ -149,29 +142,32 @@ async function globFiles({
149
142
  * @param {boolean} options.glob - glob flag
150
143
  * @returns {Promise.<{path: string, json: object}>} - Node manifest
151
144
  */
152
- async function getNodeManifest({
153
- srcDir, glob
154
- }) {
145
+ async function getNodeManifest({ srcDir, glob }) {
155
146
  let manifest = {
156
- path: '',
147
+ path: "",
157
148
  json: undefined,
158
149
  };
159
150
  let files;
160
151
  if (glob === true) {
161
152
  files = await globFiles({ srcDir, glob });
162
153
  for (const file of files) {
163
- if (path.basename(file) === 'package.json' && manifest.json === undefined) {
154
+ if (
155
+ path.basename(file) === "package.json" &&
156
+ manifest.json === undefined
157
+ ) {
164
158
  manifest.path = file;
165
159
  manifest.json = JSON.parse(await fs.promises.readFile(file));
166
160
  }
167
161
  }
168
162
  } else {
169
- manifest.path = path.resolve(srcDir, 'package.json');
170
- manifest.json = JSON.parse(await fs.promises.readFile(path.resolve(srcDir, 'package.json')));
163
+ manifest.path = path.resolve(srcDir, "package.json");
164
+ manifest.json = JSON.parse(
165
+ await fs.promises.readFile(path.resolve(srcDir, "package.json")),
166
+ );
171
167
  }
172
168
 
173
169
  if (manifest.json === undefined) {
174
- throw new Error('package.json not found in srcDir file glob patterns.');
170
+ throw new Error("package.json not found in srcDir file glob patterns.");
175
171
  }
176
172
 
177
173
  return manifest;
@@ -184,9 +180,9 @@ async function getNodeManifest({
184
180
  * @returns {true | false | string} `true`, `false` or file path
185
181
  */
186
182
  function str2Bool(option) {
187
- if (option === 'true') {
183
+ if (option === "true") {
188
184
  return true;
189
- } else if (option === 'false') {
185
+ } else if (option === "false") {
190
186
  return false;
191
187
  } else {
192
188
  return option;
@@ -201,34 +197,34 @@ function str2Bool(option) {
201
197
  */
202
198
  export const parse = async (options, pkg) => {
203
199
  options = options ?? {};
204
- options.mode = options.mode ?? 'build';
200
+ options.mode = options.mode ?? "build";
205
201
 
206
- options.version = options.version ?? 'latest';
207
- options.flavor = options.flavor ?? 'normal';
202
+ options.version = options.version ?? "latest";
203
+ options.flavor = options.flavor ?? "normal";
208
204
  options.platform = options.platform ?? PLATFORM_KV[process.platform];
209
205
  options.arch = options.arch ?? ARCH_KV[process.arch];
210
- options.downloadUrl = options.downloadUrl ?? 'https://dl.nwjs.io';
211
- options.manifestUrl = options.manifestUrl ?? 'https://nwjs.io/versions.json';
212
- options.cacheDir = options.cacheDir ?? './cache';
206
+ options.downloadUrl = options.downloadUrl ?? "https://dl.nwjs.io";
207
+ options.manifestUrl = options.manifestUrl ?? "https://nwjs.io/versions.json";
208
+ options.cacheDir = options.cacheDir ?? "./cache";
213
209
  options.cache = str2Bool(options.cache ?? true);
214
210
  options.ffmpeg = str2Bool(options.ffmpeg ?? false);
215
- options.logLevel = options.logLevel ?? 'info';
211
+ options.logLevel = options.logLevel ?? "info";
216
212
  options.shaSum = str2Bool(options.shaSum ?? true);
217
213
  options.nativeAddon = str2Bool(options.nativeAddon) ?? false;
218
214
 
219
- if (options.mode === 'get') {
215
+ if (options.mode === "get") {
220
216
  return { ...options };
221
217
  }
222
218
 
223
219
  options.argv = options.argv ?? [];
224
220
  options.glob = str2Bool(options.glob) ?? true;
225
- options.srcDir = options.srcDir ?? (options.glob ? './*' : '.');
221
+ options.srcDir = options.srcDir ?? (options.glob ? "./*" : ".");
226
222
 
227
- if (options.mode === 'run') {
223
+ if (options.mode === "run") {
228
224
  return { ...options };
229
225
  }
230
226
 
231
- options.outDir = path.resolve(options.outDir ?? './out');
227
+ options.outDir = path.resolve(options.outDir ?? "./out");
232
228
  options.zip = str2Bool(options.zip) ?? false;
233
229
 
234
230
  options.managedManifest = str2Bool(options.managedManifest) ?? false;
@@ -238,13 +234,16 @@ export const parse = async (options, pkg) => {
238
234
  /* Since the `parse` function is called twice, the first time `pkg` is `{}` and `options.app.name` is `undefined`. */
239
235
  if (options.app.name) {
240
236
  /* Remove special and control characters from app.name to mitigate potential path traversal. */
241
- options.app.name = options.app.name.replace(/[<>:"/\\|?*\u0000-\u001F]/g, '');
237
+ options.app.name = options.app.name.replace(
238
+ /[<>:"/\\|?*\u0000-\u001F]/g,
239
+ "",
240
+ );
242
241
  }
243
242
  /* Path to where the icon currently is in the filesystem */
244
243
  options.app.icon = options.app.icon ?? pkg.window?.icon ?? undefined;
245
244
 
246
245
  // TODO(#737): move this out
247
- if (options.platform === 'linux') {
246
+ if (options.platform === "linux") {
248
247
  // linux desktop entry file configurations options
249
248
  options.app.genericName = options.app.genericName ?? undefined;
250
249
  options.app.noDisplay = options.app.noDisplay ?? undefined;
@@ -254,7 +253,9 @@ export const parse = async (options, pkg) => {
254
253
  options.app.notShowIn = options.app.notShowIn ?? undefined;
255
254
  options.app.dBusActivatable = options.app.dBusActivatable ?? undefined;
256
255
  options.app.tryExec = options.app.tryExec ?? undefined;
257
- options.app.exec = options.app.exec ? path.resolve(options.app.exec) : options.app.name ?? undefined;
256
+ options.app.exec = options.app.exec
257
+ ? path.resolve(options.app.exec)
258
+ : (options.app.name ?? undefined);
258
259
  options.app.path = options.app.path ?? options.outDir ?? undefined;
259
260
  options.app.terminal = options.app.terminal ?? undefined;
260
261
  options.app.actions = options.app.actions ?? undefined;
@@ -268,18 +269,20 @@ export const parse = async (options, pkg) => {
268
269
  options.app.prefersNonDefaultGPU ?? undefined;
269
270
  options.app.singleMainWindow = options.app.singleMainWindow ?? undefined;
270
271
  }
271
- if (options.platform === 'win') {
272
+ if (options.platform === "win") {
272
273
  // windows configuration options
273
274
  options.app.version = options.app.version ?? pkg.version;
274
275
  options.app.comments = options.app.comments ?? undefined;
275
276
  options.app.company = options.app.company ?? pkg.author;
276
277
  options.app.fileDescription =
277
278
  options.app.fileDescription ?? pkg.description;
278
- options.app.fileVersion = options.app.fileVersion ?? options.app.version ?? pkg.version;
279
+ options.app.fileVersion =
280
+ options.app.fileVersion ?? options.app.version ?? pkg.version;
279
281
  options.app.internalName = options.app.internalName ?? pkg.name;
280
282
  options.app.legalCopyright = options.app.legalCopyright ?? undefined;
281
283
  options.app.legalTrademark = options.app.legalTrademark ?? undefined;
282
- options.app.originalFilename = options.app.originalFilename ?? options.app.name;
284
+ options.app.originalFilename =
285
+ options.app.originalFilename ?? options.app.name;
283
286
  options.app.privateBuild = options.app.privateBuild ?? undefined;
284
287
  options.app.productName = options.app.productName ?? pkg.name;
285
288
  options.app.productVersion = options.app.productVersion ?? pkg.version;
@@ -287,7 +290,7 @@ export const parse = async (options, pkg) => {
287
290
  options.app.languageCode = options.app.languageCode ?? 1033;
288
291
  }
289
292
 
290
- if (options.platform === 'osx') {
293
+ if (options.platform === "osx") {
291
294
  options.app.LSApplicationCategoryType =
292
295
  options.app.LSApplicationCategoryType ?? undefined;
293
296
  options.app.CFBundleIdentifier =
@@ -318,17 +321,17 @@ export const parse = async (options, pkg) => {
318
321
  */
319
322
  export const validate = async (options, releaseInfo) => {
320
323
  if (
321
- options.mode !== 'get' &&
322
- options.mode !== 'run' &&
323
- options.mode !== 'build'
324
+ options.mode !== "get" &&
325
+ options.mode !== "run" &&
326
+ options.mode !== "build"
324
327
  ) {
325
328
  throw new Error(
326
329
  `Unknown mode ${options.mode}. Expected "get", "run" or "build".`,
327
330
  );
328
331
  }
329
- if (typeof releaseInfo === 'undefined') {
332
+ if (typeof releaseInfo === "undefined") {
330
333
  throw new Error(
331
- 'Either the specific version info does not exist or the version manifest itself does not exist. In case of the latter, please check your internet connection and try again later.',
334
+ "Either the specific version info does not exist or the version manifest itself does not exist. In case of the latter, please check your internet connection and try again later.",
332
335
  );
333
336
  }
334
337
  if (!releaseInfo.flavors.includes(options.flavor)) {
@@ -345,253 +348,477 @@ export const validate = async (options, releaseInfo) => {
345
348
  `Platform ${options.platform} and architecture ${options.arch} is not supported by this download server.`,
346
349
  );
347
350
  }
348
- if (typeof options.downloadUrl === 'string' && !options.downloadUrl.startsWith('http') && !options.downloadUrl.startsWith('file')) {
349
- throw new Error('Expected options.downloadUrl to be a string and starts with `http` or `file`.');
351
+ if (
352
+ typeof options.downloadUrl === "string" &&
353
+ !options.downloadUrl.startsWith("http") &&
354
+ !options.downloadUrl.startsWith("file")
355
+ ) {
356
+ throw new Error(
357
+ "Expected options.downloadUrl to be a string and starts with `http` or `file`.",
358
+ );
350
359
  }
351
- if (typeof options.manifestUrl === 'string' && !options.manifestUrl.startsWith('https') && !options.manifestUrl.startsWith('file')) {
352
- throw new Error('Expected options.manifestUrl to be a string and starts with `https` or `file`.');
360
+ if (
361
+ typeof options.manifestUrl === "string" &&
362
+ !options.manifestUrl.startsWith("https") &&
363
+ !options.manifestUrl.startsWith("file")
364
+ ) {
365
+ throw new Error(
366
+ "Expected options.manifestUrl to be a string and starts with `https` or `file`.",
367
+ );
353
368
  }
354
- if (typeof options.cacheDir !== 'string') {
355
- throw new Error('Expected options.cacheDir to be a string. Got ' + typeof options.cacheDir);
369
+ if (typeof options.cacheDir !== "string") {
370
+ throw new Error(
371
+ "Expected options.cacheDir to be a string. Got " +
372
+ typeof options.cacheDir,
373
+ );
356
374
  }
357
375
 
358
- if (typeof options.cache !== 'boolean') {
376
+ if (typeof options.cache !== "boolean") {
359
377
  throw new Error(
360
- 'Expected options.cache to be a boolean. Got ' + typeof options.cache,
378
+ "Expected options.cache to be a boolean. Got " + typeof options.cache,
361
379
  );
362
380
  }
363
- if (typeof options.ffmpeg !== 'boolean') {
381
+ if (typeof options.ffmpeg !== "boolean") {
364
382
  throw new Error(
365
- 'Expected options.ffmpeg to be a boolean. Got ' + typeof options.ffmpeg,
383
+ "Expected options.ffmpeg to be a boolean. Got " + typeof options.ffmpeg,
366
384
  );
367
385
  }
368
386
 
369
387
  if (
370
- options.logLevel !== 'error' &&
371
- options.logLevel !== 'warn' &&
372
- options.logLevel !== 'info' &&
373
- options.logLevel !== 'debug'
388
+ options.logLevel !== "error" &&
389
+ options.logLevel !== "warn" &&
390
+ options.logLevel !== "info" &&
391
+ options.logLevel !== "debug"
374
392
  ) {
375
393
  throw new Error(
376
- 'Expected options.logLevel to be \'error\', \'warn\', \'info\' or \'debug\'. Got ' +
377
- options.logLevel,
394
+ "Expected options.logLevel to be 'error', 'warn', 'info' or 'debug'. Got " +
395
+ options.logLevel,
378
396
  );
379
397
  }
380
398
 
381
- if (typeof options.shaSum !== 'boolean') {
399
+ if (typeof options.shaSum !== "boolean") {
382
400
  throw new Error(
383
- 'Expected options.shaSum to be a boolean. Got ' + typeof options.shaSum,
401
+ "Expected options.shaSum to be a boolean. Got " + typeof options.shaSum,
384
402
  );
385
403
  }
386
404
 
387
- if (options.mode === 'get') {
405
+ if (options.mode === "get") {
388
406
  return undefined;
389
407
  }
390
- if (typeof options.srcDir !== 'string' && !Array.isArray(options.srcDir)) {
391
- throw new Error('Expected options.srcDir to be a string or Array<string>. Got ' + typeof options.srcDir);
408
+ if (typeof options.srcDir !== "string" && !Array.isArray(options.srcDir)) {
409
+ throw new Error(
410
+ "Expected options.srcDir to be a string or Array<string>. Got " +
411
+ typeof options.srcDir,
412
+ );
392
413
  }
393
414
  if (!Array.isArray(options.argv)) {
394
415
  throw new Error(
395
- 'Expected options.argv to be an array. Got ' + typeof options.argv,
416
+ "Expected options.argv to be an array. Got " + typeof options.argv,
396
417
  );
397
418
  }
398
- if (typeof options.glob !== 'boolean') {
419
+ if (typeof options.glob !== "boolean") {
399
420
  throw new Error(
400
- 'Expected options.glob to be a boolean. Got ' + typeof options.glob,
421
+ "Expected options.glob to be a boolean. Got " + typeof options.glob,
401
422
  );
402
423
  }
403
424
 
404
- if (options.mode === 'run') {
425
+ if (options.mode === "run") {
405
426
  return undefined;
406
427
  }
407
428
 
408
- if (typeof options.outDir !== 'string') {
409
- throw new Error('Expected options.outDir to be a string. Got ' + typeof options.outDir);
429
+ if (typeof options.outDir !== "string") {
430
+ throw new Error(
431
+ "Expected options.outDir to be a string. Got " + typeof options.outDir,
432
+ );
410
433
  }
411
434
 
412
435
  if (
413
- typeof options.managedManifest !== 'boolean' &&
414
- typeof options.managedManifest !== 'object' &&
415
- typeof options.managedManifest !== 'string'
436
+ typeof options.managedManifest !== "boolean" &&
437
+ typeof options.managedManifest !== "object" &&
438
+ typeof options.managedManifest !== "string"
416
439
  ) {
417
440
  throw new Error(
418
- 'Expected options.managedManifest to be a boolean, object or string. Got ' +
419
- typeof options.managedManifest,
441
+ "Expected options.managedManifest to be a boolean, object or string. Got " +
442
+ typeof options.managedManifest,
420
443
  );
421
444
  }
422
445
 
423
- if (typeof options.managedManifest === 'object') {
446
+ if (typeof options.managedManifest === "object") {
424
447
  if (options.managedManifest.name === undefined) {
425
- throw new Error('Expected NW.js Manifest to have a `name` property.');
448
+ throw new Error("Expected NW.js Manifest to have a `name` property.");
426
449
  }
427
450
  if (options.managedManifest.main === undefined) {
428
- throw new Error('Expected NW.js Manifest to have a `main` property.');
451
+ throw new Error("Expected NW.js Manifest to have a `main` property.");
429
452
  }
430
453
  }
431
454
 
432
- if (typeof options.nativeAddon !== 'boolean') {
433
- throw new Error('Expected options.nativeAddon to be a boolean. Got ' + typeof options.nativeAddon);
455
+ if (typeof options.nativeAddon !== "boolean") {
456
+ throw new Error(
457
+ "Expected options.nativeAddon to be a boolean. Got " +
458
+ typeof options.nativeAddon,
459
+ );
434
460
  }
435
461
 
436
- if (typeof options.zip !== 'boolean' &
437
- options.zip !== 'zip' &&
438
- options.zip !== 'tar' &&
439
- options.zip !== 'tgz') {
440
- throw new Error('Expected options.zip to be a boolean, `zip`, `tar` or `tgz`. Got ' + typeof options.zip);
462
+ if (
463
+ (typeof options.zip !== "boolean") & (options.zip !== "zip") &&
464
+ options.zip !== "tar" &&
465
+ options.zip !== "tgz"
466
+ ) {
467
+ throw new Error(
468
+ "Expected options.zip to be a boolean, `zip`, `tar` or `tgz`. Got " +
469
+ typeof options.zip,
470
+ );
441
471
  }
442
472
 
443
- if (options.platform === 'linux') {
444
- if (options.app.name && typeof options.app.name !== 'string') {
445
- throw new Error('Expected options.app.name to be a string. Got ' + options.app.name);
446
- }
447
- if (options.app.genericName && typeof options.app.genericName !== 'string') {
448
- throw new Error('Expected options.app.genericName to be a string. Got ' + options.app.genericName);
449
- }
450
- if (options.app.noDisplay && typeof options.app.noDisplay !== 'boolean') {
451
- throw new Error('Expected options.app.noDisplay to be a boolean. Got ' + options.app.noDisplay);
452
- }
453
- if (options.app.comment && typeof options.app.comment !== 'string') {
454
- throw new Error('Expected options.app.comment to be a string. Got ' + options.app.comment);
455
- }
456
- if (options.app.icon && typeof options.app.icon !== 'string') {
457
- throw new Error('Expected options.app.icon to be a string. Got ' + options.app.icon);
458
- }
459
- if (options.app.hidden && typeof options.app.hidden !== 'string') {
460
- throw new Error('Expected options.app.hidden to be a string. Got ' + options.app.hidden);
473
+ if (options.platform === "linux") {
474
+ if (options.app.name && typeof options.app.name !== "string") {
475
+ throw new Error(
476
+ "Expected options.app.name to be a string. Got " + options.app.name,
477
+ );
478
+ }
479
+ if (
480
+ options.app.genericName &&
481
+ typeof options.app.genericName !== "string"
482
+ ) {
483
+ throw new Error(
484
+ "Expected options.app.genericName to be a string. Got " +
485
+ options.app.genericName,
486
+ );
487
+ }
488
+ if (options.app.noDisplay && typeof options.app.noDisplay !== "boolean") {
489
+ throw new Error(
490
+ "Expected options.app.noDisplay to be a boolean. Got " +
491
+ options.app.noDisplay,
492
+ );
493
+ }
494
+ if (options.app.comment && typeof options.app.comment !== "string") {
495
+ throw new Error(
496
+ "Expected options.app.comment to be a string. Got " +
497
+ options.app.comment,
498
+ );
499
+ }
500
+ if (options.app.icon && typeof options.app.icon !== "string") {
501
+ throw new Error(
502
+ "Expected options.app.icon to be a string. Got " + options.app.icon,
503
+ );
504
+ }
505
+ if (options.app.hidden && typeof options.app.hidden !== "string") {
506
+ throw new Error(
507
+ "Expected options.app.hidden to be a string. Got " + options.app.hidden,
508
+ );
461
509
  }
462
510
  if (options.app.onlyShowIn && !Array.isArray(options.app.onlyShowIn)) {
463
- throw new Error('Expected options.app.onlyShowIn to be an Array<string>. Got ' + options.app.onlyShowIn);
511
+ throw new Error(
512
+ "Expected options.app.onlyShowIn to be an Array<string>. Got " +
513
+ options.app.onlyShowIn,
514
+ );
464
515
  }
465
516
  if (options.app.notShowIn && !Array.isArray(options.app.notShowIn)) {
466
- throw new Error('Expected options.app.notShowIn to be an Array<string>. Got ' + options.app.notShowIn);
467
- }
468
- if (options.app.dBusActivatable && typeof options.app.dBusActivatable !== 'boolean') {
469
- throw new Error('Expected options.app.dBusActivatable to be a boolean. Got ' + options.app.dBusActivatable);
470
- }
471
- if (options.app.tryExec && typeof options.app.tryExec !== 'string') {
472
- throw new Error('Expected options.app.tryExec to be a string. Got ' + options.app.tryExec);
473
- }
474
- if (options.app.exec && typeof options.app.exec !== 'string') {
475
- throw new Error('Expected options.app.exec to be a string. Got ' + options.app.exec);
476
- }
477
- if (options.app.path && typeof options.app.path !== 'string') {
478
- throw new Error('Expected options.app.path to be a string. Got ' + options.app.path);
479
- }
480
- if (options.app.terminal && typeof options.app.terminal !== 'boolean') {
481
- throw new Error('Expected options.app.terminal to be a boolean. Got ' + options.app.terminal);
517
+ throw new Error(
518
+ "Expected options.app.notShowIn to be an Array<string>. Got " +
519
+ options.app.notShowIn,
520
+ );
521
+ }
522
+ if (
523
+ options.app.dBusActivatable &&
524
+ typeof options.app.dBusActivatable !== "boolean"
525
+ ) {
526
+ throw new Error(
527
+ "Expected options.app.dBusActivatable to be a boolean. Got " +
528
+ options.app.dBusActivatable,
529
+ );
530
+ }
531
+ if (options.app.tryExec && typeof options.app.tryExec !== "string") {
532
+ throw new Error(
533
+ "Expected options.app.tryExec to be a string. Got " +
534
+ options.app.tryExec,
535
+ );
536
+ }
537
+ if (options.app.exec && typeof options.app.exec !== "string") {
538
+ throw new Error(
539
+ "Expected options.app.exec to be a string. Got " + options.app.exec,
540
+ );
541
+ }
542
+ if (options.app.path && typeof options.app.path !== "string") {
543
+ throw new Error(
544
+ "Expected options.app.path to be a string. Got " + options.app.path,
545
+ );
546
+ }
547
+ if (options.app.terminal && typeof options.app.terminal !== "boolean") {
548
+ throw new Error(
549
+ "Expected options.app.terminal to be a boolean. Got " +
550
+ options.app.terminal,
551
+ );
482
552
  }
483
553
  if (options.app.actions && !Array.isArray(options.app.actions)) {
484
- throw new Error('Expected options.app.actions to be a Array<string>. Got ' + options.app.actions);
554
+ throw new Error(
555
+ "Expected options.app.actions to be a Array<string>. Got " +
556
+ options.app.actions,
557
+ );
485
558
  }
486
559
  if (options.app.mimeType && !Array.isArray(options.app.mimeType)) {
487
- throw new Error('Expected options.app.mimeType to be a Array<string>. Got ' + options.app.mimeType);
560
+ throw new Error(
561
+ "Expected options.app.mimeType to be a Array<string>. Got " +
562
+ options.app.mimeType,
563
+ );
488
564
  }
489
565
  if (options.app.categories && !Array.isArray(options.app.categories)) {
490
- throw new Error('Expected options.app.categories to be a Array<string>. Got ' + options.app.categories);
566
+ throw new Error(
567
+ "Expected options.app.categories to be a Array<string>. Got " +
568
+ options.app.categories,
569
+ );
491
570
  }
492
571
  if (options.app.implements && !Array.isArray(options.app.implements)) {
493
- throw new Error('Expected options.app.implements to be a Array<string>. Got ' + options.app.implements);
572
+ throw new Error(
573
+ "Expected options.app.implements to be a Array<string>. Got " +
574
+ options.app.implements,
575
+ );
494
576
  }
495
577
  if (options.app.keywords && !Array.isArray(options.app.keywords)) {
496
- throw new Error('Expected options.app.keywords to be a Array<string>. Got ' + options.app.keywords);
497
- }
498
- if (options.app.startupNotify && typeof options.app.startupNotify !== 'boolean') {
499
- throw new Error('Expected options.app.startupNotify to be a boolean. Got ' + options.app.startupNotify);
500
- }
501
- if (options.app.startupWMClass && typeof options.app.startupWMClass !== 'string') {
502
- throw new Error('Expected options.app.startupWMClass to be a string. Got ' + options.app.startupWMClass);
503
- }
504
- if (options.app.prefersNonDefaultGPU && typeof options.app.prefersNonDefaultGPU !== 'boolean') {
505
- throw new Error('Expected options.app.prefersNonDefaultGPU to be a boolean. Got ' + options.app.prefersNonDefaultGPU);
506
- }
507
- if (options.app.singleMainWindow && typeof options.app.singleMainWindow !== 'string') {
508
- throw new Error('Expected options.app.singleMainWindow to be a string. Got ' + options.app.singleMainWindow);
509
- }
510
- } else if (options.platform === 'osx') {
511
- if (typeof options.app.name !== 'string') {
512
- throw new Error('Expected options.app.name to be a string. Got ' + options.app.name);
513
- }
514
- if (typeof options.app.icon !== 'string') {
515
- throw new Error('Expected options.app.icon to be a string. Got ' + options.app.icon);
516
- }
517
- if (typeof options.app.LSApplicationCategoryType !== 'string') {
518
- throw new Error('Expected options.app.LSApplicationCategoryType to be a string. Got ' + options.app.LSApplicationCategoryType);
519
- }
520
- if (typeof options.app.CFBundleIdentifier !== 'string') {
521
- throw new Error('Expected options.app.CFBundleIdentifier to be a string. Got ' + options.app.CFBundleIdentifier);
522
- }
523
- if (typeof options.app.CFBundleName !== 'string') {
524
- throw new Error('Expected options.app.CFBundleName to be a string. Got ' + options.app.CFBundleName);
525
- }
526
- if (typeof options.app.CFBundleDisplayName !== 'string') {
527
- throw new Error('Expected options.app.CFBundleDisplayName to be a string. Got ' + options.app.CFBundleDisplayName);
528
- }
529
- if (typeof options.app.CFBundleSpokenName !== 'string') {
530
- throw new Error('Expected options.app.CFBundleSpokenName to be a string. Got ' + options.app.CFBundleSpokenName);
531
- }
532
- if (typeof options.app.CFBundleVersion !== 'string') {
533
- throw new Error('Expected options.app.CFBundleVersion to be a string. Got ' + options.app.CFBundleVersion);
534
- }
535
- if (typeof options.app.CFBundleShortVersionString !== 'string') {
536
- throw new Error('Expected options.app.CFBundleShortVersionString to be a string. Got ' + options.app.CFBundleShortVersionString);
537
- }
538
- if (typeof options.app.NSHumanReadableCopyright !== 'string') {
539
- throw new Error('Expected options.app.NSHumanReadableCopyright to be a string. Got ' + options.app.NSHumanReadableCopyright);
540
- }
541
- if (options.app.NSLocalNetworkUsageDescription && typeof options.app.NSLocalNetworkUsageDescription !== 'string') {
542
- throw new Error('Expected options.app.NSLocalNetworkUsageDescription to be a string. Got ' + options.app.NSLocalNetworkUsageDescription);
578
+ throw new Error(
579
+ "Expected options.app.keywords to be a Array<string>. Got " +
580
+ options.app.keywords,
581
+ );
582
+ }
583
+ if (
584
+ options.app.startupNotify &&
585
+ typeof options.app.startupNotify !== "boolean"
586
+ ) {
587
+ throw new Error(
588
+ "Expected options.app.startupNotify to be a boolean. Got " +
589
+ options.app.startupNotify,
590
+ );
591
+ }
592
+ if (
593
+ options.app.startupWMClass &&
594
+ typeof options.app.startupWMClass !== "string"
595
+ ) {
596
+ throw new Error(
597
+ "Expected options.app.startupWMClass to be a string. Got " +
598
+ options.app.startupWMClass,
599
+ );
600
+ }
601
+ if (
602
+ options.app.prefersNonDefaultGPU &&
603
+ typeof options.app.prefersNonDefaultGPU !== "boolean"
604
+ ) {
605
+ throw new Error(
606
+ "Expected options.app.prefersNonDefaultGPU to be a boolean. Got " +
607
+ options.app.prefersNonDefaultGPU,
608
+ );
609
+ }
610
+ if (
611
+ options.app.singleMainWindow &&
612
+ typeof options.app.singleMainWindow !== "string"
613
+ ) {
614
+ throw new Error(
615
+ "Expected options.app.singleMainWindow to be a string. Got " +
616
+ options.app.singleMainWindow,
617
+ );
618
+ }
619
+ } else if (options.platform === "osx") {
620
+ if (typeof options.app.name !== "string") {
621
+ throw new Error(
622
+ "Expected options.app.name to be a string. Got " + options.app.name,
623
+ );
624
+ }
625
+ if (typeof options.app.icon !== "string") {
626
+ throw new Error(
627
+ "Expected options.app.icon to be a string. Got " + options.app.icon,
628
+ );
629
+ }
630
+ if (typeof options.app.LSApplicationCategoryType !== "string") {
631
+ throw new Error(
632
+ "Expected options.app.LSApplicationCategoryType to be a string. Got " +
633
+ options.app.LSApplicationCategoryType,
634
+ );
635
+ }
636
+ if (typeof options.app.CFBundleIdentifier !== "string") {
637
+ throw new Error(
638
+ "Expected options.app.CFBundleIdentifier to be a string. Got " +
639
+ options.app.CFBundleIdentifier,
640
+ );
641
+ }
642
+ if (typeof options.app.CFBundleName !== "string") {
643
+ throw new Error(
644
+ "Expected options.app.CFBundleName to be a string. Got " +
645
+ options.app.CFBundleName,
646
+ );
647
+ }
648
+ if (typeof options.app.CFBundleDisplayName !== "string") {
649
+ throw new Error(
650
+ "Expected options.app.CFBundleDisplayName to be a string. Got " +
651
+ options.app.CFBundleDisplayName,
652
+ );
653
+ }
654
+ if (typeof options.app.CFBundleSpokenName !== "string") {
655
+ throw new Error(
656
+ "Expected options.app.CFBundleSpokenName to be a string. Got " +
657
+ options.app.CFBundleSpokenName,
658
+ );
659
+ }
660
+ if (typeof options.app.CFBundleVersion !== "string") {
661
+ throw new Error(
662
+ "Expected options.app.CFBundleVersion to be a string. Got " +
663
+ options.app.CFBundleVersion,
664
+ );
665
+ }
666
+ if (typeof options.app.CFBundleShortVersionString !== "string") {
667
+ throw new Error(
668
+ "Expected options.app.CFBundleShortVersionString to be a string. Got " +
669
+ options.app.CFBundleShortVersionString,
670
+ );
671
+ }
672
+ if (typeof options.app.NSHumanReadableCopyright !== "string") {
673
+ throw new Error(
674
+ "Expected options.app.NSHumanReadableCopyright to be a string. Got " +
675
+ options.app.NSHumanReadableCopyright,
676
+ );
677
+ }
678
+ if (
679
+ options.app.NSLocalNetworkUsageDescription &&
680
+ typeof options.app.NSLocalNetworkUsageDescription !== "string"
681
+ ) {
682
+ throw new Error(
683
+ "Expected options.app.NSLocalNetworkUsageDescription to be a string. Got " +
684
+ options.app.NSLocalNetworkUsageDescription,
685
+ );
543
686
  }
544
687
  } else {
545
- if (typeof options.app.name !== 'string') {
546
- throw new Error('Expected options.app.name to be a string. Got ' + options.app.name);
547
- }
548
- if (typeof options.app.icon !== 'string') {
549
- throw new Error('Expected options.app.icon to be a string. Got ' + options.app.icon);
550
- }
551
- if (typeof options.app.version !== 'string') {
552
- throw new Error('Expected options.app.version to be a string. Got ' + options.app.version);
553
- }
554
- if (options.app.comments && typeof options.app.comments !== 'string') {
555
- throw new Error('Expected options.app.comments to be a string. Got ' + options.app.comments);
556
- }
557
- if (options.app.company && typeof options.app.company !== 'string') {
558
- throw new Error('Expected options.app.company to be a string. Got ' + options.app.company);
559
- }
560
- if (options.app.fileDescription && typeof options.app.fileDescription !== 'string') {
561
- throw new Error('Expected options.app.fileDescription to be a string. Got ' + options.app.fileDescription);
562
- }
563
- if (options.app.fileVersion && typeof options.app.fileVersion !== 'string') {
564
- throw new Error('Expected options.app.fileVersion to be a string. Got ' + options.app.fileVersion);
565
- }
566
- if (options.app.internalName && typeof options.app.internalName !== 'string') {
567
- throw new Error('Expected options.app.internalName to be a string. Got ' + options.app.internalName);
568
- }
569
- if (options.app.legalCopyright && options.app.legalCopyright && typeof options.app.legalCopyright !== 'string') {
570
- throw new Error('Expected options.app.legalCopyright to be a string. Got ' + options.app.legalCopyright);
571
- }
572
- if (options.app.legalTrademark && typeof options.app.legalTrademark !== 'string') {
573
- throw new Error('Expected options.app.legalTrademark to be a string. Got ' + options.app.legalTrademark);
574
- }
575
- if (options.app.originalFilename && typeof options.app.originalFilename !== 'string') {
576
- throw new Error('Expected options.app.originalFilename to be a string. Got ' + options.app.originalFilename);
577
- }
578
- if (options.app.privateBuild && typeof options.app.privateBuild !== 'string') {
579
- throw new Error('Expected options.app.privateBuild to be a string. Got ' + options.app.privateBuild);
580
- }
581
- if (options.app.productName && typeof options.app.productName !== 'string') {
582
- throw new Error('Expected options.app.productName to be a string. Got ' + options.app.productName);
583
- }
584
- if (options.app.productVersion && typeof options.app.productVersion !== 'string') {
585
- throw new Error('Expected options.app.productVersion to be a string. Got ' + options.app.productVersion);
586
- }
587
- if (options.app.specialBuild && options.app.specialBuild && typeof options.app.specialBuild !== 'string') {
588
- throw new Error('Expected options.app.specialBuild to be a string. Got ' + options.app.specialBuild);
589
- }
590
- if (options.app.legalCopyright && typeof options.app.legalCopyright !== 'string') {
591
- throw new Error('Expected options.app.legalCopyright to be a string. Got ' + options.app.legalCopyright);
592
- }
593
- if (typeof options.app.languageCode !== 'number') {
594
- throw new Error('Expected options.app.languageCode to be a number. Got ' + options.app.languageCode);
688
+ if (typeof options.app.name !== "string") {
689
+ throw new Error(
690
+ "Expected options.app.name to be a string. Got " + options.app.name,
691
+ );
692
+ }
693
+ if (typeof options.app.icon !== "string") {
694
+ throw new Error(
695
+ "Expected options.app.icon to be a string. Got " + options.app.icon,
696
+ );
697
+ }
698
+ if (typeof options.app.version !== "string") {
699
+ throw new Error(
700
+ "Expected options.app.version to be a string. Got " +
701
+ options.app.version,
702
+ );
703
+ }
704
+ if (options.app.comments && typeof options.app.comments !== "string") {
705
+ throw new Error(
706
+ "Expected options.app.comments to be a string. Got " +
707
+ options.app.comments,
708
+ );
709
+ }
710
+ if (options.app.company && typeof options.app.company !== "string") {
711
+ throw new Error(
712
+ "Expected options.app.company to be a string. Got " +
713
+ options.app.company,
714
+ );
715
+ }
716
+ if (
717
+ options.app.fileDescription &&
718
+ typeof options.app.fileDescription !== "string"
719
+ ) {
720
+ throw new Error(
721
+ "Expected options.app.fileDescription to be a string. Got " +
722
+ options.app.fileDescription,
723
+ );
724
+ }
725
+ if (
726
+ options.app.fileVersion &&
727
+ typeof options.app.fileVersion !== "string"
728
+ ) {
729
+ throw new Error(
730
+ "Expected options.app.fileVersion to be a string. Got " +
731
+ options.app.fileVersion,
732
+ );
733
+ }
734
+ if (
735
+ options.app.internalName &&
736
+ typeof options.app.internalName !== "string"
737
+ ) {
738
+ throw new Error(
739
+ "Expected options.app.internalName to be a string. Got " +
740
+ options.app.internalName,
741
+ );
742
+ }
743
+ if (
744
+ options.app.legalCopyright &&
745
+ options.app.legalCopyright &&
746
+ typeof options.app.legalCopyright !== "string"
747
+ ) {
748
+ throw new Error(
749
+ "Expected options.app.legalCopyright to be a string. Got " +
750
+ options.app.legalCopyright,
751
+ );
752
+ }
753
+ if (
754
+ options.app.legalTrademark &&
755
+ typeof options.app.legalTrademark !== "string"
756
+ ) {
757
+ throw new Error(
758
+ "Expected options.app.legalTrademark to be a string. Got " +
759
+ options.app.legalTrademark,
760
+ );
761
+ }
762
+ if (
763
+ options.app.originalFilename &&
764
+ typeof options.app.originalFilename !== "string"
765
+ ) {
766
+ throw new Error(
767
+ "Expected options.app.originalFilename to be a string. Got " +
768
+ options.app.originalFilename,
769
+ );
770
+ }
771
+ if (
772
+ options.app.privateBuild &&
773
+ typeof options.app.privateBuild !== "string"
774
+ ) {
775
+ throw new Error(
776
+ "Expected options.app.privateBuild to be a string. Got " +
777
+ options.app.privateBuild,
778
+ );
779
+ }
780
+ if (
781
+ options.app.productName &&
782
+ typeof options.app.productName !== "string"
783
+ ) {
784
+ throw new Error(
785
+ "Expected options.app.productName to be a string. Got " +
786
+ options.app.productName,
787
+ );
788
+ }
789
+ if (
790
+ options.app.productVersion &&
791
+ typeof options.app.productVersion !== "string"
792
+ ) {
793
+ throw new Error(
794
+ "Expected options.app.productVersion to be a string. Got " +
795
+ options.app.productVersion,
796
+ );
797
+ }
798
+ if (
799
+ options.app.specialBuild &&
800
+ options.app.specialBuild &&
801
+ typeof options.app.specialBuild !== "string"
802
+ ) {
803
+ throw new Error(
804
+ "Expected options.app.specialBuild to be a string. Got " +
805
+ options.app.specialBuild,
806
+ );
807
+ }
808
+ if (
809
+ options.app.legalCopyright &&
810
+ typeof options.app.legalCopyright !== "string"
811
+ ) {
812
+ throw new Error(
813
+ "Expected options.app.legalCopyright to be a string. Got " +
814
+ options.app.legalCopyright,
815
+ );
816
+ }
817
+ if (typeof options.app.languageCode !== "number") {
818
+ throw new Error(
819
+ "Expected options.app.languageCode to be a number. Got " +
820
+ options.app.languageCode,
821
+ );
595
822
  }
596
823
  }
597
824
  return undefined;
@@ -607,15 +834,16 @@ export const validate = async (options, releaseInfo) => {
607
834
  * @throws {Error}
608
835
  */
609
836
  async function getPath(type, options) {
610
- if (type === 'chromedriver') {
837
+ if (type === "chromedriver") {
611
838
  return path.resolve(
612
839
  options.cacheDir,
613
- `nwjs${options.flavor === 'sdk' ? '-sdk' : ''}-v${options.version}-${options.platform
840
+ `nwjs${options.flavor === "sdk" ? "-sdk" : ""}-v${options.version}-${
841
+ options.platform
614
842
  }-${options.arch}`,
615
- `chromedriver${options.platform === 'win' ? '.exe' : ''}`,
843
+ `chromedriver${options.platform === "win" ? ".exe" : ""}`,
616
844
  );
617
845
  } else {
618
- throw new Error('Invalid type. Expected `chromedriver` but got ', type);
846
+ throw new Error("Invalid type. Expected `chromedriver` but got ", type);
619
847
  }
620
848
  }
621
849
 
@@ -643,20 +871,24 @@ async function fileExists(filePath) {
643
871
  * @returns {string} - stdout
644
872
  */
645
873
  function log(severity, logLevel, message) {
646
- if (!['debug', 'info', 'warn', 'error'].includes(severity)) {
647
- throw new Error(`Expected debug, info, warn or error message severity. Got ${severity}`);
874
+ if (!["debug", "info", "warn", "error"].includes(severity)) {
875
+ throw new Error(
876
+ `Expected debug, info, warn or error message severity. Got ${severity}`,
877
+ );
648
878
  }
649
- if (!['debug', 'info', 'warn', 'error'].includes(logLevel)) {
650
- throw new Error(`Expected debug, info, warn or error user defined log level. Got ${logLevel}`);
879
+ if (!["debug", "info", "warn", "error"].includes(logLevel)) {
880
+ throw new Error(
881
+ `Expected debug, info, warn or error user defined log level. Got ${logLevel}`,
882
+ );
651
883
  }
652
884
 
653
885
  const sev = {
654
- 'debug': 4,
655
- 'info': 3,
656
- 'warn': 2,
657
- 'error': 1,
886
+ debug: 4,
887
+ info: 3,
888
+ warn: 2,
889
+ error: 1,
658
890
  };
659
- let stdout = '';
891
+ let stdout = "";
660
892
  const messageSeverity = sev[severity];
661
893
  const userDefSeverity = sev[logLevel];
662
894
 
@@ -669,4 +901,17 @@ function log(severity, logLevel, message) {
669
901
  return stdout;
670
902
  }
671
903
 
672
- export default { fileExists, getReleaseInfo, getManifest, getPath, PLATFORM_KV, ARCH_KV, EXE_NAME, globFiles, getNodeManifest, parse, validate, log };
904
+ export default {
905
+ fileExists,
906
+ getReleaseInfo,
907
+ getManifest,
908
+ getPath,
909
+ PLATFORM_KV,
910
+ ARCH_KV,
911
+ EXE_NAME,
912
+ globFiles,
913
+ getNodeManifest,
914
+ parse,
915
+ validate,
916
+ log,
917
+ };