Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: download electron checksum failure #226

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ version: 2.1
orbs:
win: circleci/[email protected]
jobs:
test-linux-8:
test-linux-12:
docker:
- image: circleci/node:8
- image: circleci/node:12
<<: *steps-test
test-linux-10:
test-linux-14:
docker:
- image: circleci/node:10
- image: circleci/node:14
<<: *steps-test
test-mac:
macos:
Expand All @@ -52,14 +52,14 @@ workflows:
test_and_release:
# Run the test jobs first, then the release only when all the test jobs are successful
jobs:
- test-linux-8
- test-linux-10
- test-linux-12
BlackHole1 marked this conversation as resolved.
Show resolved Hide resolved
- test-linux-14
- test-mac
- test-windows
- release:
requires:
- test-linux-8
- test-linux-10
- test-linux-12
- test-linux-14
- test-mac
- test-windows
filters:
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
"README.md"
],
"engines": {
"node": ">=8.6"
"node": ">=12.0.0"
},
"dependencies": {
"debug": "^4.1.1",
"env-paths": "^2.2.0",
"fs-extra": "^8.1.0",
"got": "^9.6.0",
"got": "^11.8.3",
"progress": "^2.0.3",
"semver": "^6.2.0",
"sumchecker": "^3.0.1"
Expand All @@ -38,9 +38,8 @@
"@continuous-auth/semantic-release-npm": "^2.0.0",
"@types/debug": "^4.1.4",
"@types/fs-extra": "^8.0.0",
"@types/got": "^9.4.4",
"@types/jest": "^24.0.13",
"@types/node": "^12.0.2",
"@types/node": "^18.6.4",
"@types/progress": "^2.0.3",
"@types/semver": "^6.2.0",
"@typescript-eslint/eslint-plugin": "^2.34.0",
Expand Down
19 changes: 12 additions & 7 deletions src/GotDownloader.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import * as fs from 'fs-extra';
import * as got from 'got';
import got, { Options, Progress, HTTPError } from 'got';
import * as path from 'path';
import * as ProgressBar from 'progress';

import { Downloader } from './Downloader';

const PROGRESS_BAR_DELAY_IN_SECONDS = 30;

type GotStreamOptions = Options & {
isStream?: true;
};

/**
* See [`got#options`](https://github.com/sindresorhus/got#options) for possible keys/values.
* See [`got#options`](https://github.com/sindresorhus/got/tree/v11.8.5#options) for possible keys/values.
*/
export type GotDownloaderOptions = got.GotOptions<string | null> & {
export type GotDownloaderOptions = GotStreamOptions & {
/**
* if defined, triggers every time `got`'s `downloadProgress` event callback is triggered.
*/
getProgressCallback?: (progress: got.Progress) => Promise<void>;
getProgressCallback?: (progress: Progress) => Promise<void>;
/**
* if `true`, disables the console progress bar (setting the `ELECTRON_GET_NO_PROGRESS`
* environment variable to a non-empty value also does this).
Expand Down Expand Up @@ -56,7 +60,7 @@ export class GotDownloader implements Downloader<GotDownloaderOptions> {
}
}, PROGRESS_BAR_DELAY_IN_SECONDS * 1000);
}
await new Promise((resolve, reject) => {
await new Promise<void>((resolve, reject) => {
const downloadStream = got.stream(url, gotOptions);
downloadStream.on('downloadProgress', async progress => {
progressPercent = progress.percent;
Expand All @@ -68,9 +72,10 @@ export class GotDownloader implements Downloader<GotDownloaderOptions> {
}
});
downloadStream.on('error', error => {
if (error.name === 'HTTPError' && error.statusCode === 404) {
error.message += ` for ${error.url}`;
if (error instanceof HTTPError && error.response.statusCode === 404) {
error.message += ` for ${error.response.url}`;
}

if (writeStream.destroy) {
writeStream.destroy(error);
}
Expand Down
1 change: 0 additions & 1 deletion test/checksums.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as crypto from 'crypto';
import * as fs from 'fs-extra';
import * as os from 'os';
import * as path from 'path';
Expand Down
25 changes: 18 additions & 7 deletions test/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ describe('utils', () => {
Object.defineProperty(process, 'arch', {
value: savedArch,
});
process.config.variables = savedVariables;
Object.defineProperty(process.config, 'variables', {
value: savedVariables,
});
});

it('should return process.arch on x64', () => {
Expand All @@ -101,8 +103,9 @@ describe('utils', () => {
Object.defineProperty(process, 'arch', {
value: 'arm',
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
process.config.variables = {} as any;
Object.defineProperty(process.config, 'variables', {
value: {},
});
expect(getHostArch()).toEqual('armv7l');
});

Expand All @@ -111,8 +114,12 @@ describe('utils', () => {
Object.defineProperty(process, 'arch', {
value: 'arm',
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/camelcase
process.config.variables = { arm_version: '6' } as any;
Object.defineProperty(process.config, 'variables', {
value: {
// eslint-disable-next-line @typescript-eslint/camelcase
arm_version: '6',
},
});
expect(getHostArch()).toEqual(uname());
});
}
Expand All @@ -121,8 +128,12 @@ describe('utils', () => {
Object.defineProperty(process, 'arch', {
value: 'arm',
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/camelcase
process.config.variables = { arm_version: '7' } as any;
Object.defineProperty(process.config, 'variables', {
value: {
// eslint-disable-next-line @typescript-eslint/camelcase
arm_version: '7',
},
});
expect(getHostArch()).toEqual('armv7l');
});
});
Expand Down
Loading