Skip to content

Commit

Permalink
refactor: remove lzma-native dependency (#1079)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshallOfSound authored Apr 12, 2023
1 parent 29365ad commit 509c8eb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 41 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"detect-libc": "^2.0.1",
"fs-extra": "^10.0.0",
"got": "^11.7.0",
"lzma-native": "^8.0.5",
"node-abi": "^3.0.0",
"node-api-version": "^0.1.4",
"node-gyp": "^9.0.0",
Expand All @@ -60,7 +59,6 @@
"@types/chai-as-promised": "^7.1.3",
"@types/debug": "^4.1.5",
"@types/fs-extra": "^9.0.1",
"@types/lzma-native": "^4.0.0",
"@types/mocha": "^9.0.0",
"@types/node": "^17.0.8",
"@types/node-abi": "^3.0.0",
Expand Down
15 changes: 5 additions & 10 deletions src/sysroot-fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { spawn } from '@malept/cross-spawn-promise';
import * as crypto from 'crypto';
import debug from 'debug';
import * as fs from 'fs-extra';
import * as path from 'path';
import * as tar from 'tar';

import { ELECTRON_GYP_DIR } from './constants';
import { fetch } from './fetcher';
Expand All @@ -27,25 +27,20 @@ export async function downloadLinuxSysroot(electronVersion: string, targetArch:

const { Sha1Sum: sha, Tarball: fileName } = electronSysroots[`sid_${linuxArch}`] || electronSysroots[`bullseye_${linuxArch}`];
const sysrootURL = `${SYSROOT_BASE_URL}/${sha}/${fileName}`;
let sysrootBuffer = await fetch(sysrootURL, 'buffer');
const sysrootBuffer = await fetch(sysrootURL, 'buffer');

const actualSha = crypto.createHash('SHA1').update(sysrootBuffer).digest('hex');
d('expected sha:', sha);
d('actual sha:', actualSha);
if (sha !== actualSha) throw new Error(`Attempted to download the linux sysroot for ${electronVersion} but the SHA checksum did not match`);

d('decompressing sysroot');
sysrootBuffer = await new Promise<Buffer>(resolve => require('lzma-native').decompress(sysrootBuffer, undefined, (result: Buffer) => resolve(result))); // eslint-disable-line

d('writing sysroot to disk');
const tmpTarFile = path.resolve(ELECTRON_GYP_DIR, `${electronVersion}-${fileName}`);
if (await fs.pathExists(tmpTarFile)) await fs.remove(tmpTarFile);
await fs.writeFile(tmpTarFile, sysrootBuffer);

d('extracting sysroot');
await tar.x({
file: tmpTarFile,
cwd: sysrootDir,
});
d('decompressing sysroot');
await spawn('tar', ['-xf', tmpTarFile, '-C', sysrootDir], { stdio: 'ignore' });

return sysrootDir;
}
32 changes: 3 additions & 29 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -666,13 +666,6 @@
dependencies:
"@types/node" "*"

"@types/lzma-native@^4.0.0":
version "4.0.1"
resolved "https://registry.yarnpkg.com/@types/lzma-native/-/lzma-native-4.0.1.tgz#29732d9a2cfcfa0f409eafa57059d47820993af0"
integrity sha512-JtD+glazM3mYYjTvCa72AblFg3VuGn8neRy3lviEkTDZUQJheqZZIaIxEGNq4Faln1aSeeL1H+7X3WH1xOUHKQ==
dependencies:
"@types/node" "*"

"@types/minipass@*":
version "3.1.1"
resolved "https://registry.yarnpkg.com/@types/minipass/-/minipass-3.1.1.tgz#7a31aedd3e05f5c5a726d3aa362243306594a043"
Expand Down Expand Up @@ -1209,9 +1202,9 @@ camelcase@^6.0.0:
integrity sha512-c7wVvbw3f37nuobQNtgsgG9POC9qMbNuMQmTCqZv23b6MIz0fcYpBiOlv9gEN/hdLdnZTDQhg6e9Dq5M1vKvfg==

caniuse-lite@^1.0.30001248:
version "1.0.30001312"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001312.tgz"
integrity sha512-Wiz1Psk2MEK0pX3rUzWaunLTZzqS2JYZFzNKqAiJGiuxIjRPLgV6+VDPOg6lQOUxmDwhTlh198JsTTi8Hzw6aQ==
version "1.0.30001478"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001478.tgz"
integrity sha512-gMhDyXGItTHipJj2ApIvR+iVB5hd0KP3svMWWXDvZOmjzJJassGLMfxRkQCSYgGd2gtdL/ReeiyvMSFD1Ss6Mw==

chai-as-promised@^7.1.1:
version "7.1.1"
Expand Down Expand Up @@ -2924,15 +2917,6 @@ lru-cache@^7.4.4, lru-cache@^7.5.1, lru-cache@^7.7.1:
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-7.14.1.tgz#8da8d2f5f59827edb388e63e459ac23d6d408fea"
integrity sha512-ysxwsnTKdAx96aTRdhDOCQfDgbHnt8SK0KY8SEjO0wHinhWOFTESbjVCMPbU1uGXg/ch4lifqx0wfjOawU2+WA==

lzma-native@^8.0.5:
version "8.0.6"
resolved "https://registry.yarnpkg.com/lzma-native/-/lzma-native-8.0.6.tgz#3ea456209d643bafd9b5d911781bdf0b396b2665"
integrity sha512-09xfg67mkL2Lz20PrrDeNYZxzeW7ADtpYFbwSQh9U8+76RIzx5QsJBMy8qikv3hbUPfpy6hqwxt6FcGK81g9AA==
dependencies:
node-addon-api "^3.1.0"
node-gyp-build "^4.2.1"
readable-stream "^3.6.0"

make-dir@^3.0.0, make-dir@^3.0.2:
version "3.1.0"
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-3.1.0.tgz#415e967046b3a7f1d185277d84aa58203726a13f"
Expand Down Expand Up @@ -3233,11 +3217,6 @@ node-abi@^3.0.0:
dependencies:
semver "^7.3.5"

node-addon-api@^3.1.0:
version "3.2.1"
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-3.2.1.tgz#81325e0a2117789c0128dab65e7e38f07ceba161"
integrity sha512-mmcei9JghVNDYydghQmeDX8KoAm0FAiYyIcUt/N4nhyAipB17pllZQDOJD2fotxABnt4Mdz+dKTO7eftLg4d0A==

node-api-version@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/node-api-version/-/node-api-version-0.1.4.tgz#1ed46a485e462d55d66b5aa1fe2821720dedf080"
Expand All @@ -3252,11 +3231,6 @@ node-fetch@^2.6.1:
dependencies:
whatwg-url "^5.0.0"

node-gyp-build@^4.2.1:
version "4.2.3"
resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.2.3.tgz#ce6277f853835f718829efb47db20f3e4d9c4739"
integrity sha512-MN6ZpzmfNCRM+3t57PTJHgHyw/h4OWnZ6mR8P5j/uZtqQr46RRuDE/P+g3n0YR/AiYXeWixZZzaip77gdICfRg==

node-gyp@^9.0.0, node-gyp@^9.1.0:
version "9.3.0"
resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-9.3.0.tgz#f8eefe77f0ad8edb3b3b898409b53e697642b319"
Expand Down

0 comments on commit 509c8eb

Please sign in to comment.