From fb7118ff1c8f0dcd61f15e51b193512283d83fa1 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Sun, 9 Jan 2022 22:16:29 +0100 Subject: build: Add eslint-plugin-unicorn MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Kristóf Marussy --- scripts/updateElectronVendors.js | 65 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 scripts/updateElectronVendors.js (limited to 'scripts/updateElectronVendors.js') 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 @@ +import { execSync } from 'node:child_process'; +import { writeFile } from 'node:fs/promises'; +import path from 'node:path'; + +import electronPath from 'electron'; + +import fileUrlToDirname from '../config/fileUrlToDirname.js'; + +const thisDir = fileUrlToDirname(import.meta.url); + +/** + * Returns versions of electron vendors + * The performance of this feature is very poor and can be improved + * @see https://github.com/electron/electron/issues/28006 + * + * @returns {NodeJS.ProcessVersions} + */ +function getVendors() { + const output = execSync( + `${electronPath.toString()} -p "JSON.stringify(process.versions)"`, + { + env: { ELECTRON_RUN_AS_NODE: '1' }, + encoding: 'utf-8', + }, + ); + + // eslint-disable-next-line @typescript-eslint/no-unsafe-return -- Read untyped output. + return JSON.parse(output); +} + +/** + * Generates the `.browserlistrc` and `.electron-vendors.cache.json` files. + * + * @returns Promise + */ +function updateVendors() { + const electronRelease = getVendors(); + + const nodeMajorVersion = electronRelease.node.split('.')[0]; + const chromeMajorVersion = + electronRelease.v8.split('.')[0] + electronRelease.v8.split('.')[1]; + + const browserslistrcPath = path.join(thisDir, '../.browserslistrc'); + + return Promise.all([ + writeFile( + path.join(thisDir, '../.electron-vendors.cache.json'), + `${JSON.stringify( + { + chrome: chromeMajorVersion, + node: nodeMajorVersion, + }, + undefined, + 2, + )}\n`, + ), + + writeFile(browserslistrcPath, `Chrome ${chromeMajorVersion}\n`, 'utf8'), + ]); +} + +updateVendors().catch((error) => { + console.error(error); + process.exit(1); +}); -- cgit v1.2.3-54-g00ecf