Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 294fcef

Browse files
committed
Add script/redownload-electron-bins.js
This makes sure we download the correct version of the electron-vendored "mksnapshot" binary. This will also automatically download the version in sync with Atom, if this module is being installed as a dependency in the main Atom repository.
1 parent 18adb33 commit 294fcef

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"report:coverage": "nyc report --reporter=cobertura --reporter=html --reporter=lcovonly",
1616
"lint": "eslint --max-warnings 0 test lib",
1717
"fetch-schema": "node script/fetch-schema",
18-
"relay": "relay-compiler --src ./lib --schema graphql/schema.graphql"
18+
"relay": "relay-compiler --src ./lib --schema graphql/schema.graphql",
19+
"postinstall": "node script/redownload-electron-bins.js"
1920
},
2021
"engines": {
2122
"atom": ">=1.37.0"

script/redownload-electron-bins.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Based on: https://github.com/atom/atom/blob/v1.51.0/script/redownload-electron-bins.js
2+
3+
let downloadMksnapshotPath
4+
5+
try {
6+
downloadMksnapshotPath = require.resolve('electron-mksnapshot/download-mksnapshot.js');
7+
} catch { }
8+
9+
if (typeof(downloadMksnapshotPath) !== 'undefined') {
10+
11+
const { spawn } = require('child_process');
12+
const path = require('path');
13+
const fs = require('fs');
14+
15+
const atomRepoPath = path.join('..', '..', '..', '..', 'atom', 'package.json');
16+
const electronVersion = fs.existsSync(atomRepoPath) ? require(atomrepoPath).electronVersion : '6.1.12'
17+
// TODO: Keep the above "electronVersion" in sync with "electronVersion" from Atom's package.json
18+
19+
if (process.env.ELECTRON_CUSTOM_VERSION !== electronVersion) {
20+
const electronEnv = process.env.ELECTRON_CUSTOM_VERSION;
21+
console.info(
22+
`env var ELECTRON_CUSTOM_VERSION is not set,\n` +
23+
`or doesn't match electronVersion in atom/package.json.\n` +
24+
`(is: "${electronEnv}", wanted: "${electronVersion}").\n` +
25+
`Setting, and re-downloading mksnapshot.\n`
26+
);
27+
28+
process.env.ELECTRON_CUSTOM_VERSION = electronVersion;
29+
const downloadMksnapshot = spawn('node', [downloadMksnapshotPath]);
30+
var exitStatus;
31+
32+
downloadMksnapshot.on('close', code => {
33+
if (code === 0) {
34+
exitStatus = 'success';
35+
} else {
36+
exitStatus = 'error';
37+
}
38+
39+
console.info(`info: Done re-downloading mksnapshot. Status: ${exitStatus}`);
40+
});
41+
} else {
42+
console.info(
43+
'info: env var "ELECTRON_CUSTOM_VERSION" is already set correctly.\n(No need to re-download mksnapshot). Skipping.\n'
44+
);
45+
}
46+
} else {
47+
console.log('devDependency "electron-mksnapshot/download-mksnapshot.js" not found.\nSkipping "redownload electron bins" script.\n')
48+
}

0 commit comments

Comments
 (0)