@overwolf/ow-electron 18.3.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/index.js ADDED
@@ -0,0 +1,21 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ const pathFile = path.join(__dirname, 'path.txt');
5
+
6
+ function getElectronPath () {
7
+ let executablePath;
8
+ if (fs.existsSync(pathFile)) {
9
+ executablePath = fs.readFileSync(pathFile, 'utf-8');
10
+ }
11
+ if (process.env.ELECTRON_OVERRIDE_DIST_PATH) {
12
+ return path.join(process.env.ELECTRON_OVERRIDE_DIST_PATH, executablePath || 'electron');
13
+ }
14
+ if (executablePath) {
15
+ return path.join(__dirname, 'dist', executablePath);
16
+ } else {
17
+ throw new Error('Electron failed to install correctly, please delete node_modules/electron and try installing again');
18
+ }
19
+ }
20
+
21
+ module.exports = getElectronPath();
package/install.js ADDED
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { version } = require('./package');
4
+
5
+ const childProcess = require('child_process');
6
+ const fs = require('fs');
7
+ const os = require('os');
8
+ const path = require('path');
9
+ const extract = require('extract-zip');
10
+ const { downloadArtifact } = require('@electron/get');
11
+
12
+ if (process.env.ELECTRON_SKIP_BINARY_DOWNLOAD) {
13
+ process.exit(0);
14
+ }
15
+
16
+ const platformPath = getPlatformPath();
17
+
18
+ if (isInstalled()) {
19
+ process.exit(0);
20
+ }
21
+
22
+ const platform = process.env.npm_config_platform || process.platform;
23
+ let arch = process.env.npm_config_arch || process.arch;
24
+
25
+ if (platform === 'darwin' && process.platform === 'darwin' && arch === 'x64' &&
26
+ process.env.npm_config_arch === undefined) {
27
+ // When downloading for macOS ON macOS and we think we need x64 we should
28
+ // check if we're running under rosetta and download the arm64 version if appropriate
29
+ try {
30
+ const output = childProcess.execSync('sysctl -in sysctl.proc_translated');
31
+ if (output.toString().trim() === '1') {
32
+ arch = 'arm64';
33
+ }
34
+ } catch {
35
+ // Ignore failure
36
+ }
37
+ }
38
+
39
+ // downloads if not cached
40
+ downloadArtifact({
41
+ version,
42
+ artifactName: 'electron',
43
+ force: process.env.force_no_cache === 'true',
44
+ cacheRoot: process.env.electron_config_cache,
45
+ checksums: process.env.electron_use_remote_checksums ? undefined : require('./checksums.json'),
46
+ platform,
47
+ arch,
48
+ mirrorOptions: {
49
+ mirror: 'https://github.com/electron/electron/releases/download/'
50
+ }
51
+ }).then(extractFile).catch(err => {
52
+ console.error(err.stack);
53
+ process.exit(1);
54
+ });
55
+
56
+ function isInstalled () {
57
+ try {
58
+ if (fs.readFileSync(path.join(__dirname, 'dist', 'version'), 'utf-8').replace(/^v/, '') !== version) {
59
+ return false;
60
+ }
61
+
62
+ if (fs.readFileSync(path.join(__dirname, 'path.txt'), 'utf-8') !== platformPath) {
63
+ return false;
64
+ }
65
+ } catch (ignored) {
66
+ return false;
67
+ }
68
+
69
+ const electronPath = process.env.ELECTRON_OVERRIDE_DIST_PATH || path.join(__dirname, 'dist', platformPath);
70
+
71
+ return fs.existsSync(electronPath);
72
+ }
73
+
74
+ // unzips and makes path.txt point at the correct executable
75
+ function extractFile (zipPath) {
76
+ return new Promise((resolve, reject) => {
77
+ extract(zipPath, { dir: path.join(__dirname, 'dist') }, err => {
78
+ if (err) return reject(err);
79
+
80
+ fs.writeFile(path.join(__dirname, 'path.txt'), platformPath, err => {
81
+ if (err) return reject(err);
82
+
83
+ resolve();
84
+ });
85
+ });
86
+ });
87
+ }
88
+
89
+ function getPlatformPath () {
90
+ const platform = process.env.npm_config_platform || os.platform();
91
+
92
+ switch (platform) {
93
+ case 'mas':
94
+ case 'darwin':
95
+ return 'Electron.app/Contents/MacOS/Electron';
96
+ case 'freebsd':
97
+ case 'openbsd':
98
+ case 'linux':
99
+ return 'electron';
100
+ case 'win32':
101
+ return 'electron.exe';
102
+ default:
103
+ throw new Error('Electron builds are not available on platform: ' + platform);
104
+ }
105
+ }
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "main": "index.js",
3
+ "types": "electron.d.ts",
4
+ "bin": {
5
+ "ow-electron": "cli.js"
6
+ },
7
+ "scripts": {
8
+ "postinstall": "node install.js"
9
+ },
10
+ "dependencies": {
11
+ "@electron/get": "^1.13.0",
12
+ "@types/node": "^16.11.26",
13
+ "extract-zip": "^1.0.3"
14
+ },
15
+ "engines": {
16
+ "node": ">= 8.6"
17
+ },
18
+ "name": "@overwolf/ow-electron",
19
+ "version": "18.3.0",
20
+ "repository": "https://github.com/electron/electron",
21
+ "description": "Build cross platform desktop apps with JavaScript, HTML, and CSS",
22
+ "license": "MIT",
23
+ "author": "Overwolf",
24
+ "keywords": [
25
+ "ow-electron"
26
+ ]
27
+ }