nw 0.81.0-1 → 0.81.0-3

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/lib/install.mjs CHANGED
@@ -11,194 +11,213 @@ import semver from 'semver';
11
11
 
12
12
  import nodeManifest from '../package.json' assert { type: 'json' };
13
13
 
14
- /**
15
- * NW.js build flavor
16
- *
17
- * @type {'sdk' | 'normal'}
18
- */
19
- let buildType = env.npm_config_nwjs_build_type || env.NWJS_BUILD_TYPE || 'normal';
20
-
21
- /**
22
- * Parsed string version to Semver version object
23
- */
24
- let parsedVersion = semver.parse(nodeManifest.version);
25
-
26
- /**
27
- * Version string of the format `X.Y.Z-pre`.
28
- * The prerelease segment `pre` is used to specify build flavor, or other tags.
29
- *
30
- * @type {string}
31
- */
32
- let versionString = [
33
- parsedVersion.major,
34
- parsedVersion.minor,
35
- parsedVersion.patch
36
- ].join('.');
37
-
38
- // Check if version is a prelease.
39
- if (typeof parsedVersion?.prerelease?.[0] === 'string') {
40
- let prerelease = parsedVersion.prerelease[0].split('-');
41
- if (prerelease.length > 1) {
42
- prerelease = prerelease.slice(0, -1);
14
+ await install();
15
+
16
+ async function install() {
17
+
18
+ const PLATFORM_KV = {
19
+ darwin: 'osx',
20
+ linux: 'linux',
21
+ win32: 'win',
22
+ };
23
+
24
+ const ARCH_KV = {
25
+ x64: 'x64',
26
+ ia32: 'ia32',
27
+ arm64: 'arm64',
28
+ };
29
+
30
+ const __dirname = dirname(fileURLToPath(import.meta.url));
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('-');
43
119
  }
44
- versionString = [versionString, ...prerelease].join('-');
45
- }
46
-
47
- // Check build flavor and slice that off the `versionString`.
48
- if (versionString.endsWith('-sdk')) {
49
- versionString = versionString.slice(0, -4);
50
- buildType = 'sdk';
51
- } else if (versionString.endsWith('sdk')) {
52
- versionString = versionString.slice(0, -3);
53
- buildType = 'sdk';
54
- }
55
-
56
- /**
57
- * URL to download or get binaries from.
58
- *
59
- * @type {string}
60
- */
61
- let url = '';
62
-
63
- /**
64
- * Host operating system
65
- *
66
- * @type {NodeJS.Platform | 'osx' | 'win'}
67
- */
68
- let hostOs = env.npm_config_nwjs_platform || env.NWJS_PLATFORM || platform;
69
-
70
- /**
71
- * Host architecture
72
- *
73
- * @type {NodeJS.Architecture}
74
- */
75
- let hostArch = env.npm_config_nwjs_process_arch || arch;
76
-
77
- /**
78
- * URL base prepended to `url`.
79
- *
80
- * @type {string}
81
- */
82
- let urlBase = env.npm_config_nwjs_urlbase || env.NWJS_URLBASE || 'https://dl.nwjs.io/v';
83
-
84
- const PLATFORM_KV = {
85
- darwin: 'osx',
86
- linux: 'linux',
87
- win32: 'win',
88
- };
89
-
90
- const ARCH_KV = {
91
- x64: 'x64',
92
- ia32: 'ia32',
93
- arm64: 'arm64',
94
- };
95
-
96
- url = [
97
- urlBase,
98
- versionString,
99
- '/nwjs',
100
- buildType === 'normal' ? '' : `-${buildType}`,
101
- '-v',
102
- versionString,
103
- '-',
104
- PLATFORM_KV[hostOs],
105
- '-',
106
- ARCH_KV[hostArch],
107
- PLATFORM_KV[hostOs] === 'linux' ? '.tar.gz' : '.zip'
108
- ].join('');
109
-
110
- if (!PLATFORM_KV[hostOs] || !ARCH_KV[hostArch]) {
111
- console.error('[ ERROR ] Could not find a compatible version of nw.js to download for your platform.');
112
- exit(1);
113
- }
114
-
115
- const __dirname = dirname(fileURLToPath(import.meta.url));
116
-
117
- /**
118
- * The folder where NW.js binaries are placed.
119
- *
120
- * @type {string}
121
- */
122
- let nwDir = resolve(__dirname, '..', 'nwjs');
123
-
124
- if (existsSync(nwDir) === true) {
125
- exit(0);
126
- }
127
120
 
128
- let parsedUrl = new URL(url);
129
-
130
- /**
131
- * Path to the compressed binary.
132
- *
133
- * @type {string}
134
- */
135
- let filePath = '';
136
-
137
- /**
138
- * Recursively delete the passed in directory.
139
- * Rename the downloaded file.
140
- * @param {string} dir - directory to remove
141
- */
142
- const rmAndRename = async (dir) => {
143
- await rm(dir, { recursive: true, force: true });
144
- await rename(`nwjs-v${versionString}-${PLATFORM_KV[hostOs]}-${ARCH_KV[hostArch]}`, 'nwjs');
145
- };
146
-
147
- /**
148
- * @param {'zip' | 'tgz'} zipOrTgz
149
- * @param {string} filePath
150
- * @return {Promise<void>}
151
- */
152
- const decompress = function (zipOrTgz, filePath) {
153
- return compressing[zipOrTgz].uncompress(filePath, '.')
154
- .then(async () => await rmAndRename(filePath));
155
- }
156
-
157
- // If the url is linking to the file system,
158
- // then it is assumed that a compressed binary exists in that location.
159
- if (parsedUrl.protocol === 'file:') {
160
- filePath = resolve(decodeURIComponent(url.slice('file://'.length)));
161
-
162
- if (existsSync(filePath) === false) {
163
- console.error('[ ERROR ] Could not find ' + filePath);
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';
164
128
  }
165
129
 
166
- // If the compressed file is of ZIP format:
167
- if (filePath.endsWith('.zip')) {
168
- decompress('zip', filePath);
169
- // If the compressed file is of TGZ format:
170
- } else if (filePath.endsWith('.tar.gz')) {
171
- decompress('tgz', filePath);
172
- } else {
173
- console.error(`[ ERROR ] Expected .zip or .tar.gz file format. Got ${filePath}`);
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.');
174
154
  exit(1);
175
155
  }
176
156
 
177
- } else {
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
178
 
179
- const bar = new progress.SingleBar({}, progress.Presets.rect);
179
+ if (existsSync(nwCache) === false) {
180
+ const bar = new progress.SingleBar({}, progress.Presets.rect);
180
181
 
181
- const stream = createWriteStream(nwDir);
182
+ const stream = createWriteStream(nwCache);
183
+ request = new Promise((res, rej) => {
184
+ get(url, (response) => {
182
185
 
183
- get(url, (response) => {
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
+ });
184
193
 
185
- let chunks = 0;
186
- bar.start(Number(response.headers['content-length']), 0);
187
- response.on('data', async (chunk) => {
188
- chunks += chunk.length;
189
- bar.increment();
190
- bar.update(chunks);
191
- });
194
+ response.on('error', async () => {
195
+ await rm(nwCache, { force: true });
196
+ rej();
197
+ });
192
198
 
193
- response.on('error', async () => await rm(nwDir, { force: true }));
199
+ response.on('end', () => {
200
+ res();
201
+ });
194
202
 
195
- response.on('end', () => {
196
- if (PLATFORM_KV[hostOs] === 'linux') {
197
- decompress('tgz', nwDir);
198
- } else {
199
- decompress('zip', nwDir);
200
- }
203
+ response.pipe(stream);
204
+ });
201
205
  });
202
- response.pipe(stream);
206
+ }
207
+
208
+ if (request !== null) {
209
+ await request;
210
+ }
211
+ await rm(nwDir, {
212
+ recursive: true,
213
+ force: true,
203
214
  });
215
+ await compressing[platform === 'linux' ? 'tgz' : 'zip']
216
+ .uncompress(nwCache, '.');
217
+ await rename(
218
+ nwFile,
219
+ nwDir
220
+ );
221
+
222
+ return;
204
223
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nw",
3
- "version": "0.81.0-1",
3
+ "version": "0.81.0-3",
4
4
  "description": "A installer for nw.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -35,9 +35,6 @@
35
35
  "semver": "^7.5.4",
36
36
  "yargs": "^3.2.1"
37
37
  },
38
- "devDependencies": {
39
- "request": "^2.53.0"
40
- },
41
38
  "keywords": [
42
39
  "nw",
43
40
  "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
- });