nw 0.81.0 → 0.82.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/README.md CHANGED
@@ -103,6 +103,16 @@ var nwpath = findpath();
103
103
  // nwpath will equal the path to the binary depending on your environment
104
104
  ```
105
105
 
106
+ ## finding the path to the chromedriver binary
107
+
108
+ If you would like to programmatically retrieve the path to the chromedriver use:
109
+
110
+ ``` js
111
+ var findpath = require('nw').findpath;
112
+ var chromedriver_path = findpath('chromedriver');
113
+ // chromedriver_path will equal the path to the binary depending on your environment
114
+ ```
115
+
106
116
  Then you can use that path to run NW.js programmatically. For example, to run in the current script's directory:
107
117
 
108
118
  ```js
@@ -1,9 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- var fs = require('fs');
4
- var path = require('path');
5
- var spawn = require('child_process').spawn;
6
- var bin = require('../lib/findpath.js')();
3
+ const { spawn } = require('node:child_process');
4
+ const fs = require('node:fs');
5
+ const path = require('node:path');
6
+ const process = require('node:process');
7
+
8
+ const { copyAssets } = require('../lib/app_assets.js');
9
+ const findpath = require('../lib/findpath.js').findpath;
7
10
 
8
11
  function run() {
9
12
  // Rename nw.js's own package.json as workaround for https://github.com/nwjs/nw.js/issues/1503
@@ -16,7 +19,7 @@ function run() {
16
19
  }
17
20
 
18
21
  // copy over any asset files (icons, etc) specified via CLI args:
19
- require('../lib/app_assets').copyAssets(process.platform, bin);
22
+ copyAssets(process.platform, findpath());
20
23
 
21
24
  // Normalize cli args
22
25
  var args = process.argv.slice(2);
@@ -28,7 +31,7 @@ function run() {
28
31
  }
29
32
 
30
33
  // Spawn node-webkit
31
- var nw = spawn(bin, args, { stdio: 'inherit' });
34
+ var nw = spawn(findpath(), args, { stdio: 'inherit' });
32
35
  nw.on('close', function() {
33
36
  process.nextTick(function() {
34
37
  process.exit(0);
@@ -45,7 +48,7 @@ function run() {
45
48
  }, 1000);
46
49
  }
47
50
 
48
- if (!fs.existsSync(bin)) {
51
+ if (!fs.existsSync(findpath())) {
49
52
  console.log('nw.js appears to have failed to download and extract. Attempting to download and extract again...');
50
53
  var child = spawn(process.execPath, [path.resolve(__dirname, '..', 'scripts', 'install.js')], { stdio: 'inherit' });
51
54
  child.on('close', run);
package/lib/findpath.js CHANGED
@@ -1,20 +1,57 @@
1
- var fs = require('fs');
2
- var path = require('path');
3
- var bindir = path.resolve(__dirname, '..', 'nwjs');
1
+ const { env, platform } = require('node:process');
2
+ const { join, resolve } = require('node:path');
4
3
 
5
- module.exports = function() {
6
- var bin = bindir;
7
- var platform = process.env.npm_config_nwjs_platform || process.env.NWJS_PLATFORM || process.platform;
8
- if (platform === 'darwin') {
9
- if (fs.existsSync(path.join(bin, 'Contents'))) {
10
- bin = path.join(bin, 'Contents', 'MacOS', 'nwjs');
4
+ /**
5
+ * Get the platform dependant path of the NW.js or ChromeDriver binary.
6
+ *
7
+ * @param {'nwjs' | 'chromedriver'} executable Path to NW.js or Chromedriver executable.
8
+ * @return {string}
9
+ */
10
+ function findpath(executable = 'nwjs') {
11
+ const nwDir = resolve(__dirname, '..', 'nwjs');
12
+ /**
13
+ * File path to executable.
14
+ *
15
+ * @type {string}
16
+ */
17
+ let binPath = '';
18
+
19
+ /**
20
+ * Host operating system
21
+ *
22
+ * @type {NodeJS.Platform}
23
+ */
24
+ let hostOs = env.npm_config_nwjs_platform || env.NWJS_PLATFORM || platform;
25
+
26
+ /**
27
+ * Get the platform dependant path of the NW.js binary.
28
+ */
29
+ function findNwjs() {
30
+ if (hostOs === 'darwin') {
31
+ binPath = join(nwDir, 'nwjs.app', 'Contents', 'MacOS', 'nwjs');
32
+ } else if (hostOs === 'win32') {
33
+ binPath = join(nwDir, 'nw.exe');
11
34
  } else {
12
- bin = path.join(bin, 'nwjs.app', 'Contents', 'MacOS', 'nwjs');
35
+ binPath = join(nwDir, 'nw');
13
36
  }
14
- } else if (platform === 'win32') {
15
- bin = path.join(bin, 'nw.exe');
37
+ }
38
+
39
+ /**
40
+ * Get the platform dependant path of the ChromeDriver binary.
41
+ */
42
+ function findChromeDriver() {
43
+ binPath = resolve(nwDir, `chromedriver${platform === "win32" ? ".exe" : ""}`);
44
+ }
45
+
46
+ if (executable === 'nwjs') {
47
+ findNwjs();
48
+ } else if (executable === 'chromedriver') {
49
+ findChromeDriver();
16
50
  } else {
17
- bin = path.join(bin, 'nw');
51
+ console.error(`[ ERROR ] Expected nwjs or chromedriver, got ${executable}.`);
18
52
  }
19
- return bin;
53
+
54
+ return binPath;
20
55
  }
56
+
57
+ module.exports = { findpath };
package/lib/install.js ADDED
@@ -0,0 +1,223 @@
1
+ const { createWriteStream, existsSync } = require('node:fs');
2
+ const { rename, rm } = require('node:fs/promises');
3
+ const { get } = require('node:https');
4
+ const { resolve } = require('node:path');
5
+ const { arch, env, platform, exit } = require('node:process');
6
+ const { URL } = require('node:url');
7
+
8
+ const compressing = require('compressing');
9
+ const progress = require('cli-progress');
10
+ const semver = require('semver');
11
+
12
+ const nodeManifest = require('../package.json');
13
+
14
+ install()
15
+ .then(() => {})
16
+ .catch((error) => console.error(error));
17
+
18
+ async function install() {
19
+
20
+ const PLATFORM_KV = {
21
+ darwin: 'osx',
22
+ linux: 'linux',
23
+ win32: 'win',
24
+ };
25
+
26
+ const ARCH_KV = {
27
+ x64: 'x64',
28
+ ia32: 'ia32',
29
+ arm64: 'arm64',
30
+ };
31
+
32
+ /**
33
+ * URL to download or get binaries from.
34
+ *
35
+ * @type {string}
36
+ */
37
+ let url = '';
38
+
39
+ /**
40
+ * URL base prepended to `url`.
41
+ *
42
+ * @type {string}
43
+ */
44
+ let urlBase = env.npm_config_nwjs_urlbase || env.NWJS_URLBASE || 'https://dl.nwjs.io/v';
45
+
46
+ /**
47
+ * NW.js build flavor
48
+ *
49
+ * @type {'sdk' | 'normal'}
50
+ */
51
+ let buildType = env.npm_config_nwjs_build_type || env.NWJS_BUILD_TYPE || 'normal';
52
+
53
+ /**
54
+ * Parsed string version to Semver version object
55
+ */
56
+ let parsedVersion = semver.parse(nodeManifest.version);
57
+
58
+ /**
59
+ * Version string of the format `X.Y.Z-pre`.
60
+ * The prerelease segment `pre` is used to specify build flavor, or other tags.
61
+ *
62
+ * @type {string}
63
+ */
64
+ let versionString = [
65
+ parsedVersion.major,
66
+ parsedVersion.minor,
67
+ parsedVersion.patch
68
+ ].join('.');
69
+
70
+ /**
71
+ * Host operating system
72
+ *
73
+ * @type {NodeJS.Platform | 'osx' | 'win'}
74
+ */
75
+ let hostOs = env.npm_config_nwjs_platform || env.NWJS_PLATFORM || platform;
76
+
77
+ /**
78
+ * Host architecture
79
+ *
80
+ * @type {NodeJS.Architecture}
81
+ */
82
+ let hostArch = env.npm_config_nwjs_process_arch || arch;
83
+
84
+ /**
85
+ * Path to the decompressed folder.
86
+ *
87
+ * @type {string}
88
+ */
89
+ let nwFile = '';
90
+
91
+ /**
92
+ * Extension of the downloaded file.
93
+ *
94
+ * @type {'.tar.gz' | '.zip'}
95
+ */
96
+ let nwExt = '';
97
+
98
+ /**
99
+ * Path to the compressed file.
100
+ *
101
+ * @type {string}
102
+ */
103
+ let nwCache = '';
104
+
105
+ /**
106
+ * Path to the renamed folder containing NW.js binaries.
107
+ *
108
+ * @type {string}
109
+ */
110
+ let nwDir = resolve(__dirname, '..', 'nwjs');
111
+
112
+ // Check if version is a prelease.
113
+ if (typeof parsedVersion?.prerelease?.[0] === 'string') {
114
+ let prerelease = parsedVersion.prerelease[0].split('-');
115
+ if (prerelease.length > 1) {
116
+ prerelease = prerelease.slice(0, -1);
117
+ }
118
+ versionString = [versionString, ...prerelease].join('-');
119
+ }
120
+
121
+ // Check build flavor and slice that off the `versionString`.
122
+ if (versionString.endsWith('-sdk')) {
123
+ versionString = versionString.slice(0, -4);
124
+ buildType = 'sdk';
125
+ } else if (versionString.endsWith('sdk')) {
126
+ versionString = versionString.slice(0, -3);
127
+ buildType = 'sdk';
128
+ }
129
+
130
+ nwFile = [
131
+ 'nwjs',
132
+ buildType === 'normal' ? '' : `-${buildType}`,
133
+ '-v',
134
+ versionString,
135
+ '-',
136
+ PLATFORM_KV[hostOs],
137
+ '-',
138
+ ARCH_KV[hostArch],
139
+ ].join('');
140
+
141
+ nwExt = PLATFORM_KV[hostOs] === 'linux' ? '.tar.gz' : '.zip'
142
+
143
+ nwCache = [nwFile, nwExt].join('');
144
+
145
+ url = [
146
+ urlBase,
147
+ versionString,
148
+ '/',
149
+ nwCache,
150
+ ].join('');
151
+
152
+ if (!PLATFORM_KV[hostOs] || !ARCH_KV[hostArch]) {
153
+ console.error('[ ERROR ] Could not find a compatible version of nw.js to download for your platform.');
154
+ exit(1);
155
+ }
156
+
157
+ /**
158
+ * Parsed URL.
159
+ *
160
+ * @type {URL}
161
+ */
162
+ let parsedUrl = new URL(url);
163
+
164
+ /**
165
+ * Request download from server.
166
+ *
167
+ * @type {Promise<void> | null}
168
+ */
169
+ let request = null;
170
+
171
+ if (parsedUrl.protocol === 'file:') {
172
+ nwCache = resolve(decodeURIComponent(url.slice('file://'.length)));
173
+ if (existsSync(nwCache) === false) {
174
+ console.error('[ ERROR ] Could not find ' + nwCache);
175
+ exit(1);
176
+ }
177
+ }
178
+
179
+ if (existsSync(nwCache) === false) {
180
+ const bar = new progress.SingleBar({}, progress.Presets.rect);
181
+
182
+ const stream = createWriteStream(nwCache);
183
+ request = new Promise((res, rej) => {
184
+ get(url, (response) => {
185
+
186
+ let chunks = 0;
187
+ bar.start(Number(response.headers['content-length']), 0);
188
+ response.on('data', async (chunk) => {
189
+ chunks += chunk.length;
190
+ bar.increment();
191
+ bar.update(chunks);
192
+ });
193
+
194
+ response.on('error', async () => {
195
+ await rm(nwCache, { force: true });
196
+ rej();
197
+ });
198
+
199
+ response.on('end', () => {
200
+ res();
201
+ });
202
+
203
+ response.pipe(stream);
204
+ });
205
+ });
206
+ }
207
+
208
+ if (request !== null) {
209
+ await request;
210
+ }
211
+ await rm(nwDir, {
212
+ recursive: true,
213
+ force: true,
214
+ });
215
+ await compressing[platform === 'linux' ? 'tgz' : 'zip']
216
+ .uncompress(nwCache, '.');
217
+ await rename(
218
+ nwFile,
219
+ nwDir
220
+ );
221
+
222
+ return;
223
+ }
package/package.json CHANGED
@@ -1,45 +1,41 @@
1
1
  {
2
2
  "name": "nw",
3
- "version": "0.81.0",
3
+ "version": "0.82.0",
4
4
  "description": "A installer for nw.js",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git://github.com/nwjs/npm-installer.git"
8
8
  },
9
- "main": "index.js",
9
+ "main": "lib/findpath.js",
10
10
  "bin": {
11
- "nw": "bin/nw"
11
+ "nw": "bin/nw.js"
12
12
  },
13
13
  "scripts": {
14
- "postinstall": "node scripts/install.js",
15
- "test": "node --test-reporter=spec --test test/index.mjs"
14
+ "postinstall": "node lib/install.js",
15
+ "test": "node --test-reporter=spec --test test/index.js",
16
+ "dry-run": "nw ./test/app"
16
17
  },
17
18
  "files": [
18
19
  "lib",
19
- "bin",
20
- "scripts",
21
- "index.js"
20
+ "bin"
21
+ ],
22
+ "author": {
23
+ "name": "Kyle Robinson Young",
24
+ "url": "https://github.com/shama"
25
+ },
26
+ "contributors": [
27
+ {
28
+ "name": "nwjs/npm-installer Contributors",
29
+ "url": "https://github.com/nwjs/npm-installer/graphs/contributors"
30
+ }
22
31
  ],
23
- "author": "Kyle Robinson Young",
24
32
  "license": "MIT",
25
33
  "dependencies": {
26
- "chalk": "~1.1.3",
27
- "decompress": "^4.2.0",
28
- "download": "^5.0.3",
29
- "file-exists": "^2.0.0",
30
- "merge": "^2.1.1",
31
- "progress": "^2.0.3",
32
- "rimraf": "^2.2.8",
33
- "semver": "^5.1.0",
34
+ "cli-progress": "^3.12.0",
35
+ "compressing": "^1.10.0",
36
+ "semver": "^7.5.4",
34
37
  "yargs": "^3.2.1"
35
38
  },
36
- "devDependencies": {
37
- "request": "^2.53.0"
38
- },
39
- "engines": {
40
- "node": "v20.5.0"
41
- },
42
- "packageManager": "npm@9.8.1",
43
39
  "keywords": [
44
40
  "nw",
45
41
  "nw.js",
package/bin/autobump DELETED
@@ -1,51 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- var fs = require('fs');
4
- var path = require('path');
5
- var semver = require('semver');
6
- var request = require('request');
7
- var exec = require('child_process').exec;
8
-
9
- var url = 'https://raw.github.com/rogerwang/node-webkit/master/README.md';
10
- var pkgpath = path.join(__dirname, '..', 'package.json');
11
-
12
- // Download README file
13
- var readme = request(url);
14
- var data = '';
15
- readme.on('data', function(buf) { data += buf; });
16
- readme.on('end', function() {
17
- var version = semver.clean(/\[v([^\s]+)\s+release notes\]/i.exec(data)[1]);
18
- // Version invalid so quit
19
- if (!semver.valid(version)) {
20
- console.error('INVALID VERSION: ' + version);
21
- process.exit();
22
- }
23
- var pkg = require(pkgpath);
24
- var currentversion = pkg.version;
25
- if (semver.gt(version, pkg.version)) {
26
- // Write new version to package.json
27
- pkg.version = version;
28
- fs.writeFileSync(pkgpath, JSON.stringify(pkg, null, 2));
29
-
30
- console.log('PUBLISHING NEW VERSION ' + version);
31
-
32
- var cmd = [
33
- 'git add package.json',
34
- 'git commit -m "v' + version + '"',
35
- 'git push origin master',
36
- 'npm publish',
37
- ].join(' && ');
38
- exec(cmd, { cwd: path.resolve(__dirname, '..') }, function(err, stdout, stderr) {
39
- if (err || stderr) {
40
- // Revert package.json change and try again next time
41
- console.error('FAILED');
42
- console.error(err || stderr);
43
- pkg.version = currentversion;
44
- fs.writeFileSync(pkgpath, JSON.stringify(pkg, null, 2));
45
- // TODO: Should revert commit here as well
46
- } else {
47
- console.log('SUCCESS');
48
- }
49
- });
50
- }
51
- });
package/index.js DELETED
@@ -1,4 +0,0 @@
1
- /**
2
- * Export `findpath` function to get the platform dependant path of the `nodewebkit` binary
3
- */
4
- module.exports.findpath = require('./lib/findpath.js');
@@ -1,137 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- var download = require('download');
4
- var rimraf = require('rimraf');
5
- var semver = require('semver');
6
- var ProgressBar = require('progress')
7
- var path = require('path');
8
- var fs = require('fs');
9
- var merge = require('merge');
10
- var urlModule = require('url');
11
- var Decompress = require('decompress');
12
- var fileExists = require('file-exists');
13
- var chalk = require('chalk');
14
-
15
- var buildType = process.env.npm_config_nwjs_build_type || process.env.NWJS_BUILD_TYPE || 'normal';
16
-
17
- var v = semver.parse(require('../package.json').version);
18
- var version = [v.major, v.minor, v.patch].join('.');
19
- if (v.prerelease && typeof v.prerelease[0] === 'string') {
20
- var prerelease = v.prerelease[0].split('-');
21
- if (prerelease.length > 1) {
22
- prerelease = prerelease.slice(0, -1);
23
- }
24
- version += '-' + prerelease.join('-');
25
- }
26
-
27
- if ( version.slice(-4) === '-sdk' ){
28
- version = version.slice(0, -4);
29
- buildType = 'sdk';
30
- } else if ( version.slice(-3) === 'sdk' ){
31
- version = version.slice(0, -3);
32
- buildType = 'sdk';
33
- }
34
-
35
- var url = false;
36
- var arch = process.env.npm_config_nwjs_process_arch || process.arch;
37
- var urlBase = process.env.npm_config_nwjs_urlbase || process.env.NWJS_URLBASE || 'https://dl.nwjs.io/v';
38
- var buildTypeSuffix = buildType === 'normal' ? '' : ('-' + buildType);
39
- var platform = process.env.npm_config_nwjs_platform || process.env.NWJS_PLATFORM || process.platform;
40
-
41
- // Determine download url
42
- switch (platform) {
43
- case 'win32':
44
- url = urlBase + version + '/nwjs' + buildTypeSuffix + '-v' + version + '-win-' + arch +'.zip';
45
- break;
46
- case 'darwin':
47
- url = urlBase + version + '/nwjs' + buildTypeSuffix + '-v' + version + '-osx-' + arch + '.zip';
48
- break;
49
- case 'linux':
50
- url = urlBase + version + '/nwjs' + buildTypeSuffix + '-v' + version + '-linux-' + arch + '.tar.gz';
51
- break;
52
- }
53
-
54
- function logError(e) {
55
- console.error(chalk.bold.red((typeof e === 'string') ? e : e.message));
56
- process.exit(1);
57
- }
58
-
59
- function cb(error) {
60
- if( error != null ) {
61
- return logError( error )
62
- }
63
-
64
- process.nextTick(function() {
65
- process.exit();
66
- });
67
- }
68
-
69
- function fileExistsAndAvailable(filepath) {
70
- try {
71
- return fileExists(filepath);
72
- } catch(err) {
73
- return false;
74
- }
75
- }
76
-
77
- if (!url) logError('Could not find a compatible version of nw.js to download for your platform.');
78
-
79
- var dest = path.resolve(__dirname, '..', 'nwjs');
80
- rimraf.sync(dest);
81
-
82
- var bar = new ProgressBar(url + ' [:bar] :current/:totalM', {total: 100, clear: true});
83
-
84
- var total = 0;
85
- var progress = 0;
86
-
87
- var parsedUrl = urlModule.parse(url);
88
- var decompressOptions = { strip: 1, mode: '755' };
89
- var filePath;
90
- if( parsedUrl.protocol == 'file:' ) {
91
- filePath = path.resolve(
92
- decodeURIComponent(
93
- url.slice( 'file://'.length )
94
- )
95
- );
96
- if ( !fileExistsAndAvailable(filePath) ) logError(
97
- 'Could not find ' + filePath
98
- );
99
- new Decompress()
100
- .src( filePath )
101
- .dest( dest )
102
- .use( Decompress.zip(decompressOptions) )
103
- .use( Decompress.targz(decompressOptions) )
104
- .run( cb );
105
- } else {
106
- var progress = {
107
- total: null,
108
- downloaded: 0,
109
- start: function (response) {
110
- this.total = parseInt(response.headers['content-length']);
111
- bar.total = (this.total / 1000000).toFixed(2);
112
- },
113
- recieved: function (chunk) {
114
- this.downloaded += chunk.length;
115
- if (this.total) {
116
- bar.update(this.downloaded / this.total);
117
- }
118
- }
119
- };
120
-
121
- download(url, dest, merge({ extract: true }, decompressOptions))
122
- .on('response', function (response) {
123
- progress.start(response);
124
- })
125
- .on('data', function (chunk) {
126
- progress.recieved(chunk);
127
- })
128
- .on('end', function () {
129
- bar.terminate();
130
- })
131
- .then(function () {
132
- cb();
133
- })
134
- .catch(function (err) {
135
- cb(err);
136
- });
137
- }