nw 0.84.0 → 0.85.0-1-sdk

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