nw 0.85.0-sdk → 0.86.0-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/src/util.js ADDED
@@ -0,0 +1,89 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import process from 'node:process';
4
+ import url from 'node:url';
5
+
6
+ const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
7
+
8
+ /**
9
+ * Check if file exists at specified path.
10
+ *
11
+ * @param {fs.PathLike} filePath - File path to check existence of
12
+ * @return {Promise<boolean>} `true` if exists, otherwise `false`
13
+ */
14
+ async function fileExists(filePath) {
15
+ let exists = true;
16
+ try {
17
+ await fs.promises.stat(filePath);
18
+ } catch {
19
+ exists = false;
20
+ }
21
+ return exists;
22
+ }
23
+
24
+ const PLATFORM_KV = {
25
+ darwin: "osx",
26
+ linux: "linux",
27
+ win32: "win",
28
+ };
29
+
30
+ const ARCH_KV = {
31
+ x64: "x64",
32
+ ia32: "ia32",
33
+ arm64: "arm64",
34
+ };
35
+
36
+ const EXE_NAME = {
37
+ win: "nw.exe",
38
+ osx: "nwjs.app/Contents/MacOS/nwjs",
39
+ linux: "nw",
40
+ };
41
+
42
+ /**
43
+ * Get the platform dependant path of the NW.js or ChromeDriver binary.
44
+ *
45
+ * @param {'nwjs' | 'chromedriver'} executable Path to NW.js or Chromedriver executable.
46
+ * @return {string}
47
+ */
48
+ function findpath(executable = 'nwjs') {
49
+ const nwDir = path.resolve(__dirname, '..', 'nwjs');
50
+ /**
51
+ * File path to executable.
52
+ *
53
+ * @type {string}
54
+ */
55
+ let binPath = '';
56
+
57
+ /**
58
+ * Host operating system
59
+ *
60
+ * @type {NodeJS.Platform}
61
+ */
62
+ let hostOs = PLATFORM_KV[process.env.npm_config_nwjs_platform || process.env.NWJS_PLATFORM || process.platform];
63
+
64
+ /**
65
+ * Get the platform dependant path of the NW.js binary.
66
+ */
67
+ function findNwjs() {
68
+ binPath = path.resolve(nwDir, EXE_NAME[hostOs]);
69
+ }
70
+
71
+ /**
72
+ * Get the platform dependant path of the ChromeDriver binary.
73
+ */
74
+ function findChromeDriver() {
75
+ binPath = path.resolve(nwDir, `chromedriver${process.platform === "win32" ? ".exe" : ""}`);
76
+ }
77
+
78
+ if (executable === 'nwjs') {
79
+ findNwjs();
80
+ } else if (executable === 'chromedriver') {
81
+ findChromeDriver();
82
+ } else {
83
+ console.error(`[ ERROR ] Expected nwjs or chromedriver, got ${executable}.`);
84
+ }
85
+
86
+ return binPath;
87
+ }
88
+
89
+ export default { ARCH_KV, EXE_NAME, PLATFORM_KV, fileExists, findpath }
package/bin/nw.js DELETED
@@ -1,57 +0,0 @@
1
- #!/usr/bin/env node
2
-
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;
10
-
11
- function run() {
12
- // Rename nw.js's own package.json as workaround for https://github.com/nwjs/nw.js/issues/1503
13
- var packagejson = path.resolve(__dirname, '..', 'package.json');
14
- var packagejsonBackup = path.resolve(__dirname, '..', 'package_backup.json');
15
- if (!fs.existsSync(packagejsonBackup)) {
16
- try {
17
- fs.renameSync(packagejson, packagejsonBackup);
18
- } catch (err) {}
19
- }
20
-
21
- // copy over any asset files (icons, etc) specified via CLI args:
22
- copyAssets(process.platform, findpath());
23
-
24
- // Normalize cli args
25
- var args = process.argv.slice(2);
26
- var cwd = (args.length < 1) ? '.' : args[0];
27
- if (!fs.existsSync(path.resolve(cwd))) {
28
- args = ['.'].concat(args);
29
- } else {
30
- args = [cwd].concat(args.slice(1));
31
- }
32
-
33
- // Spawn node-webkit
34
- var nw = spawn(findpath(), args, { stdio: 'inherit' });
35
- nw.on('close', function() {
36
- process.nextTick(function() {
37
- process.exit(0);
38
- });
39
- });
40
-
41
- // Restore package.json shortly after nw is spawned
42
- setTimeout(function() {
43
- try {
44
- if (fs.existsSync(packagejsonBackup)) {
45
- fs.renameSync(packagejsonBackup, packagejson);
46
- }
47
- } catch (err) {}
48
- }, 1000);
49
- }
50
-
51
- if (!fs.existsSync(findpath())) {
52
- console.log('nw.js appears to have failed to download and extract. Attempting to download and extract again...');
53
- var child = spawn(process.execPath, [path.resolve(__dirname, '..', 'scripts', 'install.js')], { stdio: 'inherit' });
54
- child.on('close', run);
55
- } else {
56
- run();
57
- }
package/lib/app_assets.js DELETED
@@ -1,29 +0,0 @@
1
- var fs = require('fs');
2
- var path = require('path');
3
- var argv = require('yargs').argv;
4
-
5
- // Helper to simulate the shell's "cp" command
6
- function copyFileSync(srcFile, destFile) {
7
- var content = fs.readFileSync(srcFile);
8
- fs.writeFileSync(destFile, content);
9
- }
10
-
11
- // Copy asset files (specified via process.argv) over to the app binary's folder
12
- exports.copyAssets = function copyAssets(platform, binPath) {
13
- // OS X: Save a custom plist file to Contents/Info.plist in the
14
- // app bundle. This lets you customize things like the app's menubar
15
- // name and icon (see argv.mac_icon below)
16
- if (argv.mac_plist && platform === 'darwin') {
17
- var plistPath = path.join(binPath, '..', '..', 'Info.plist');
18
- copyFileSync(argv.mac_plist, plistPath);
19
- }
20
-
21
- // OS X: Save icon files to the Resources dir in the app bundle.
22
- // Note that for the icon to work properly you need to point to
23
- // it with a custom plist file.
24
- if (argv.mac_icon && platform === 'darwin') {
25
- var iconName = path.basename(argv.mac_icon); // Preserve the file's name
26
- var iconPath = path.join(binPath, '..', '..', 'Resources', iconName);
27
- copyFileSync(argv.mac_icon, iconPath);
28
- }
29
- };
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
- }