nw 0.87.0 → 0.88.0-1

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 CHANGED
@@ -6,6 +6,8 @@ An npm installer for [NW.js](https://nwjs.io).
6
6
 
7
7
  ## Install
8
8
 
9
+ Please go through the [CHANGELOG](https://github.com/nwjs/npm-installer/blob/main/CHANGELOG.md) carefully and choose the appropriate version. Bug fixes and feature updates are pushed to the repo periodically.
10
+
9
11
  ### Latest version globally
10
12
 
11
13
  ```shell
@@ -64,6 +66,10 @@ Set `nwjs_native_addon` in `.npmrc` or `NWJS_NATIVE_ADDON` environment variable
64
66
 
65
67
  Set `nwjs_urlbase` in `.npmrc`or `NWJS_URLBASE` environment variable. Defaults to `https://dl.nwjs.io`. The file system (`file://`) is also supported (for example, `file:///home/localghost/local_mirror`).
66
68
 
69
+ ### Specify unref flag
70
+
71
+ Set `nwjs_unref` in `.npmrc` or `NWJS_UNREF` environment variable. Default to `false`. This is useful if you're using `nw` package to call the executable and want to prevent zombie processes eating up memory.
72
+
67
73
  ## Usage
68
74
 
69
75
  Add a script in your `package.json`:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nw",
3
- "version": "0.87.0",
3
+ "version": "0.88.0-1",
4
4
  "description": "An installer for nw.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,10 +33,10 @@
33
33
  ],
34
34
  "license": "MIT",
35
35
  "dependencies": {
36
- "axios": "^1.6.8",
37
- "commander": "^12.0.0",
38
- "semver": "^7.5.4",
39
- "tar": "^7.0.1",
36
+ "axios": "^1.7.2",
37
+ "commander": "^12.1.0",
38
+ "semver": "^7.6.2",
39
+ "tar": "^7.2.0",
40
40
  "yauzl-promise": "^4.0.0"
41
41
  },
42
42
  "keywords": [
@@ -52,7 +52,7 @@
52
52
  "application"
53
53
  ],
54
54
  "devDependencies": {
55
- "selenium-webdriver": "^4.18.1",
56
- "vitest": "^1.5.0"
55
+ "selenium-webdriver": "^4.21.0",
56
+ "vitest": "^1.6.0"
57
57
  }
58
58
  }
package/src/cli.js CHANGED
@@ -12,13 +12,13 @@ await cli();
12
12
  async function cli() {
13
13
 
14
14
  program
15
- .option('--version <string>')
16
- .option('--flavor <flavor>')
17
- .option('--platform <platform>')
18
- .option('--arch <arch>')
19
- .option('--cacheDir <cacheDir>')
20
- .argument('[app]')
21
- .allowUnknownOption()
15
+ .argument('[app]', 'File path to project', '.')
16
+ .option('--version <string>', 'NW.js version')
17
+ .option('--flavor <flavor>', 'NW.js flavor')
18
+ .option('--platform <platform>', 'Host platform')
19
+ .option('--arch <arch>', 'Host architecture')
20
+ .option('--cacheDir <cacheDir>', 'File path to cache directory')
21
+ .allowUnknownOption() // this allows chromium and node options to be passed through to the nwjs binary
22
22
  .parse(process.argv);
23
23
 
24
24
  let options = program.opts();
@@ -31,6 +31,7 @@ async function cli() {
31
31
  arch: options.arch,
32
32
  cacheDir: options.cacheDir,
33
33
  srcDir: program.args[0],
34
+ args: program.args.slice(1),
34
35
  });
35
36
 
36
37
  }
package/src/decompress.js CHANGED
@@ -92,4 +92,5 @@ async function unzip(zippedFile, cacheDir) {
92
92
  await fs.promises.symlink(linkTarget, entryPathAbs);
93
93
  }
94
94
  }
95
+ await zip.close();
95
96
  }
package/src/parse.js CHANGED
@@ -1,9 +1,10 @@
1
+ import fs from 'node:fs';
1
2
  import path from 'node:path';
2
3
  import process from 'node:process';
4
+ import url from 'node:url';
3
5
 
4
6
  import semver from 'semver';
5
7
 
6
- import nodeManifest from '../package.json' assert { type: 'json' };
7
8
  import util from '../src/util.js';
8
9
 
9
10
  /**
@@ -14,9 +15,11 @@ import util from '../src/util.js';
14
15
  * @property {"ia32" | "x64" | "arm64"} arch Target arch
15
16
  * @property {string} downloadUrl Download server.
16
17
  * @property {string} cacheDir Cache directory
18
+ * @property {string} srcDir Source directory
17
19
  * @property {boolean} cache If false, remove cache and redownload.
18
20
  * @property {boolean} ffmpeg If true, ffmpeg is not downloaded.
19
- * @property {false | "gyp"} nativeAddon Rebuild native modules
21
+ * @property {false | "gyp"} nativeAddon Rebuild native modules
22
+ * @property {boolean} unref Unref the child process and unblock the caller
20
23
  */
21
24
 
22
25
  /**
@@ -26,6 +29,15 @@ import util from '../src/util.js';
26
29
  * @return {Promise<ParseOptions>}
27
30
  */
28
31
  export default async function parse(options) {
32
+ const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
33
+ /**
34
+ * @type {fs.PathLike}
35
+ */
36
+ const nodeManifestPath = path.resolve(__dirname, '..', 'package.json');
37
+ /**
38
+ * @type {object}
39
+ */
40
+ const nodeManifest = JSON.parse(await fs.promises.readFile(nodeManifestPath, { encoding: 'utf-8' }));
29
41
  options.version = options.version ?? nodeManifest.version;
30
42
  const parsedVersion = semver.parse(options.version);
31
43
  options.version = [
@@ -57,10 +69,12 @@ export default async function parse(options) {
57
69
  options.platform = options.platform || util.PLATFORM_KV[process.env.npm_config_nwjs_platform || process.env.NWJS_PLATFORM || process.platform];
58
70
  options.arch = options.arch || util.ARCH_KV[process.env.npm_config_nwjs_process_arch || process.env.NWJS_ARCH || process.arch];
59
71
  options.downloadUrl = options.downloadUrl || process.env.npm_config_nwjs_urlbase || process.env.NWJS_URLBASE || 'https://dl.nwjs.io';
60
- options.cacheDir = options.npm_config_nwjs_urlbase || process.env.npm_config_nwjs_cache_dir || process.env.NWJS_CACHE_DIR || path.resolve('.', 'node_modules', 'nw');
72
+ options.cacheDir = options.npm_config_nwjs_urlbase || process.env.npm_config_nwjs_cache_dir || process.env.NWJS_CACHE_DIR || path.resolve(__dirname, '..');
73
+ options.srcDir = options.srcDir || process.cwd();
61
74
  options.cache = options.cache || process.env.npm_config_nwjs_cache || process.env.NWJS_CACHE || true;
62
75
  options.ffmpeg = options.ffmpeg || process.env.npm_config_nwjs_ffmpeg || process.env.NWJS_FFMPEG || false;
63
76
  options.nativeAddon = options.nativeAddon || process.env.npm_config_nwjs_native_addon || process.env.NWJS_NATIVE_ADDON || false;
77
+ options.unref = options.unref || process.env.npm_config_nwjs_unref || process.env.NWJS_UNREF || false;
64
78
 
65
79
  return { ...options };
66
80
  }
@@ -1,20 +1,32 @@
1
+ import fs from 'node:fs';
1
2
  import process from 'node:process';
3
+ import path from 'node:path';
4
+ import url from 'node:url';
2
5
 
3
6
  import semver from 'semver';
4
7
 
5
8
  import get from './get.js';
6
9
  import util from './util.js';
7
10
 
8
- import nodeManifest from '../package.json' assert { type: 'json' };
9
-
10
11
  await postinstall()
11
12
  .catch((error) => {
12
13
  if (error.code === 'EPERM') {
13
14
  console.error('Unable to create symlink since user did not run as Administrator.');
15
+ } else {
16
+ console.error(error)
14
17
  }
15
18
  });
16
19
 
17
20
  async function postinstall() {
21
+ const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
22
+ /**
23
+ * @type {fs.PathLike}
24
+ */
25
+ const nodeManifestPath = path.resolve(__dirname, '..', 'package.json');
26
+ /**
27
+ * @type {object}
28
+ */
29
+ const nodeManifest = JSON.parse(await fs.promises.readFile(nodeManifestPath));
18
30
  const parsedVersion = semver.parse(nodeManifest.version);
19
31
  let version = [
20
32
  parsedVersion.major,
@@ -23,21 +35,17 @@ async function postinstall() {
23
35
  ].join('.');
24
36
 
25
37
  let flavor = process.env.npm_config_nwjs_build_type || process.env.NWJS_BUILD_TYPE || 'normal';
26
- /* Check if version is a prelease. */
27
- if (typeof parsedVersion?.prerelease?.[0] === 'string') {
28
- let prerelease = parsedVersion.prerelease[0].split('-');
29
- if (prerelease.length > 1) {
30
- prerelease = prerelease.slice(0, -1);
31
- }
32
- version = [version, ...prerelease].join('-');
33
- }
34
38
 
39
+ /**
40
+ * If `parsedVersion` is `null`, then prerelease is `"null"`.
41
+ * If `parsedVersion?.prerelease` is `[]`, then prerelease is `"undefined"`.
42
+ * If `parsedVersion?.prerelease[0]` is `"N-sdk"` where N represents a build number, then prerelease is `"N-sdk"`.
43
+ *
44
+ * @type {"null" | "undefined" | "N-sdk" | ""}
45
+ */
46
+ const prerelease = String(parsedVersion?.prerelease[0]);
35
47
  /* Check build flavor and slice that off the `version`. */
36
- if (version.endsWith('-sdk')) {
37
- version = version.slice(0, -4);
38
- flavor = 'sdk';
39
- } else if (version.endsWith('sdk')) {
40
- version = version.slice(0, -3);
48
+ if (prerelease.endsWith('sdk')) {
41
49
  flavor = 'sdk';
42
50
  }
43
51
 
package/src/run.js CHANGED
@@ -13,6 +13,8 @@ import util from "./util.js";
13
13
  * @property {"ia32" | "x64" | "arm64"} [arch] Target arch
14
14
  * @property {string} [srcDir = "./src"] Source directory
15
15
  * @property {string} [cacheDir = "./cache"] Cache directory
16
+ * @property {boolean} [unref = false] Unref the child process and unblock the caller
17
+ * @property {string[]} [args = []] Command line arguments
16
18
  */
17
19
 
18
20
  /**
@@ -31,6 +33,8 @@ async function run({
31
33
  arch = util.ARCH_KV[process.arch],
32
34
  srcDir = ".",
33
35
  cacheDir = "./cache",
36
+ unref = false,
37
+ args = [],
34
38
  }) {
35
39
 
36
40
  try {
@@ -46,17 +50,26 @@ async function run({
46
50
  return new Promise((res, rej) => {
47
51
  const nwProcess = child_process.spawn(
48
52
  path.resolve(nwDir, util.EXE_NAME[platform]),
49
- [srcDir]
53
+ [srcDir, ...args],
54
+ { detached: true, stdio: "ignore" },
50
55
  );
51
56
 
52
57
  nwProcess.on("close", () => {
53
58
  res();
54
59
  });
55
60
 
61
+ nwProcess.on("message", (message) => {
62
+ console.log(message);
63
+ });
64
+
56
65
  nwProcess.on("error", (error) => {
57
66
  console.error(error);
58
67
  rej(error);
59
68
  });
69
+
70
+ if (unref) {
71
+ nwProcess.unref();
72
+ }
60
73
  });
61
74
  } catch (error) {
62
75
  console.error(error);