Skip to content

Commit

Permalink
feat: emit warning if downloading a deprecated linux/ia32 binary (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
malept authored and MarshallOfSound committed Jun 19, 2019
1 parent 06c86ea commit a25c0fb
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ import { getArtifactFileName, getArtifactRemoteURL, FileNameUse } from './artifa
import { ElectronArtifactDetails, ElectronDownloadRequestOptions } from './types';
import { Cache } from './Cache';
import { getDownloaderForSystem } from './downloader-resolver';
import { withTempDirectory, normalizeVersion, getHostArch, ensureIsTruthyString } from './utils';
import {
withTempDirectory,
normalizeVersion,
getHostArch,
ensureIsTruthyString,
isOfficialLinuxIA32Download,
} from './utils';

export { getHostArch } from './utils';

Expand Down Expand Up @@ -60,6 +66,19 @@ export async function downloadArtifact(_artifactDetails: ElectronArtifactDetails
}
}

if (
!artifactDetails.isGeneric &&
isOfficialLinuxIA32Download(
artifactDetails.platform,
artifactDetails.arch,
artifactDetails.version,
artifactDetails.mirrorOptions,
)
) {
console.warn('Official Linux/ia32 support is deprecated.');
console.warn('For more info: https://electronjs.org/blog/linux-32bit-support');
}

return await withTempDirectory(async tempFolder => {
const tempDownloadPath = path.resolve(
tempFolder,
Expand Down
14 changes: 14 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,17 @@ export function ensureIsTruthyString<T, K extends keyof T>(obj: T, key: K) {
throw new Error(`Expected property "${key}" to be provided as a string but it was not`);
}
}

export function isOfficialLinuxIA32Download(
platform: string,
arch: string,
version: string,
mirrorOptions?: object,
) {
return (
platform === 'linux' &&
arch === 'ia32' &&
Number(version.slice(1).split('.')[0]) >= 4 &&
typeof mirrorOptions === 'undefined'
);
}
22 changes: 22 additions & 0 deletions test/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
withTempDirectory,
getHostArch,
ensureIsTruthyString,
isOfficialLinuxIA32Download,
} from '../src/utils';

describe('utils', () => {
Expand Down Expand Up @@ -127,4 +128,25 @@ describe('utils', () => {
expect(() => ensureIsTruthyString({ a: 1234 }, 'a')).toThrow();
});
});

describe('isOfficialLinuxIA32Download()', () => {
it('should be true if an official linux/ia32 download with correct version specified', () => {
expect(isOfficialLinuxIA32Download('linux', 'ia32', 'v4.0.0')).toEqual(true);
});

it('should be false if mirrorOptions specified', () => {
expect(
isOfficialLinuxIA32Download('linux', 'ia32', 'v4.0.0', { mirror: 'mymirror' }),
).toEqual(false);
});

it('should be false if too early version specified', () => {
expect(isOfficialLinuxIA32Download('linux', 'ia32', 'v3.0.0')).toEqual(false);
});

it('should be false if wrong platform/arch specified', () => {
expect(isOfficialLinuxIA32Download('win32', 'ia32', 'v4.0.0')).toEqual(false);
expect(isOfficialLinuxIA32Download('linux', 'x64', 'v4.0.0')).toEqual(false);
});
});
});

0 comments on commit a25c0fb

Please sign in to comment.