aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/updateElectronVendors.js
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/updateElectronVendors.js')
-rw-r--r--scripts/updateElectronVendors.js65
1 files changed, 65 insertions, 0 deletions
diff --git a/scripts/updateElectronVendors.js b/scripts/updateElectronVendors.js
new file mode 100644
index 0000000..5e8ab36
--- /dev/null
+++ b/scripts/updateElectronVendors.js
@@ -0,0 +1,65 @@
1import { execSync } from 'node:child_process';
2import { writeFile } from 'node:fs/promises';
3import path from 'node:path';
4
5import electronPath from 'electron';
6
7import fileUrlToDirname from '../config/fileUrlToDirname.js';
8
9const thisDir = fileUrlToDirname(import.meta.url);
10
11/**
12 * Returns versions of electron vendors
13 * The performance of this feature is very poor and can be improved
14 * @see https://github.com/electron/electron/issues/28006
15 *
16 * @returns {NodeJS.ProcessVersions}
17 */
18function getVendors() {
19 const output = execSync(
20 `${electronPath.toString()} -p "JSON.stringify(process.versions)"`,
21 {
22 env: { ELECTRON_RUN_AS_NODE: '1' },
23 encoding: 'utf-8',
24 },
25 );
26
27 // eslint-disable-next-line @typescript-eslint/no-unsafe-return -- Read untyped output.
28 return JSON.parse(output);
29}
30
31/**
32 * Generates the `.browserlistrc` and `.electron-vendors.cache.json` files.
33 *
34 * @returns Promise<void>
35 */
36function updateVendors() {
37 const electronRelease = getVendors();
38
39 const nodeMajorVersion = electronRelease.node.split('.')[0];
40 const chromeMajorVersion =
41 electronRelease.v8.split('.')[0] + electronRelease.v8.split('.')[1];
42
43 const browserslistrcPath = path.join(thisDir, '../.browserslistrc');
44
45 return Promise.all([
46 writeFile(
47 path.join(thisDir, '../.electron-vendors.cache.json'),
48 `${JSON.stringify(
49 {
50 chrome: chromeMajorVersion,
51 node: nodeMajorVersion,
52 },
53 undefined,
54 2,
55 )}\n`,
56 ),
57
58 writeFile(browserslistrcPath, `Chrome ${chromeMajorVersion}\n`, 'utf8'),
59 ]);
60}
61
62updateVendors().catch((error) => {
63 console.error(error);
64 process.exit(1);
65});