electron-info 1.26.1 → 1.27.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,5 @@
1
1
  import fs from 'node:fs/promises';
2
2
  import { inspect } from 'node:util';
3
- import axios from 'axios';
4
3
  import logdown from 'logdown';
5
4
  export class HTTPService {
6
5
  constructor(options) {
@@ -18,8 +17,11 @@ export class HTTPService {
18
17
  this.logger.log('Downloading releases file:', { downloadUrl, targetFile });
19
18
  let releases = [];
20
19
  try {
21
- const response = await axios.get(downloadUrl, { timeout: this.options.timeout });
22
- releases = response.data;
20
+ const response = await fetch(downloadUrl, { signal: AbortSignal.timeout(this.options.timeout) });
21
+ if (!response.ok) {
22
+ throw new Error(response.statusText);
23
+ }
24
+ releases = (await response.json());
23
25
  }
24
26
  catch (error) {
25
27
  throw new Error(`Request failed: "${error.message}"`);
package/package.json CHANGED
@@ -2,7 +2,6 @@
2
2
  "author": "Florian Imdahl <git@ffflorian.de>",
3
3
  "bin": "dist/cli.js",
4
4
  "dependencies": {
5
- "axios": "1.13.2",
6
5
  "chalk": "5.6.2",
7
6
  "commander": "14.0.2",
8
7
  "date-fns": "4.1.0",
@@ -40,13 +39,13 @@
40
39
  "name": "electron-info",
41
40
  "repository": "https://github.com/ffflorian/node-packages/tree/main/packages/electron-info",
42
41
  "scripts": {
43
- "build": "tsc -p tsconfig.json",
42
+ "build": "tsc -p tsconfig.build.json",
44
43
  "clean": "rimraf dist",
45
44
  "dist": "yarn clean && yarn build",
46
45
  "start": "tsx src/cli.ts -d",
47
46
  "test": "vitest run"
48
47
  },
49
48
  "type": "module",
50
- "version": "1.26.1",
51
- "gitHead": "eedb2984fd69190a0b69a992d18fe451e714e04d"
49
+ "version": "1.27.1",
50
+ "gitHead": "624bfac36e769ed7157fe9a9ada1c3e5443745ff"
52
51
  }
@@ -1 +0,0 @@
1
- export {};
@@ -1,141 +0,0 @@
1
- import path from 'node:path';
2
- import { randomUUID } from 'node:crypto';
3
- import fs from 'node:fs/promises';
4
- import { expect, describe, test, beforeEach, beforeAll, afterAll, afterEach } from 'vitest';
5
- import { StatusCodes as HTTP_STATUS } from 'http-status-codes';
6
- import nock from 'nock';
7
- import { ElectronInfo } from './ElectronInfo.js';
8
- const __dirname = import.meta.dirname;
9
- const tempDir = path.resolve(__dirname, '.temp');
10
- const tempDirDownload = path.resolve(__dirname, '.temp/download');
11
- const mockUrl = 'http://example.com';
12
- const invalidUrl = 'http://invalid.inv';
13
- const fixturesDir = path.resolve(__dirname, '../fixtures');
14
- const fullReleasesFile = path.join(fixturesDir, 'electron-releases-full.json');
15
- const createRandomBody = () => [
16
- {
17
- name: 'electron v8.0.0-nightly.20190820',
18
- node_id: randomUUID(),
19
- npm_dist_tags: [],
20
- prerelease: !!Math.round(Math.random()),
21
- published_at: new Date().toUTCString(),
22
- tag_name: 'v8.0.0-nightly.20190820',
23
- // eslint-disable-next-line no-magic-numbers
24
- total_downloads: Math.round(Math.random() * 1000),
25
- version: '8.0.0-nightly.20190820',
26
- },
27
- ];
28
- const provideReleaseFile = async () => {
29
- await fs.cp(fullReleasesFile, path.join(tempDirDownload, 'latest.json'));
30
- };
31
- describe('ElectronInfo', () => {
32
- let releases;
33
- beforeAll(async () => {
34
- try {
35
- await fs.mkdir(tempDir);
36
- }
37
- catch (_a) { }
38
- releases = await fs.readFile(fullReleasesFile, 'utf8');
39
- });
40
- beforeEach(() => {
41
- nock(mockUrl).get('/').reply(HTTP_STATUS.OK, releases);
42
- });
43
- afterAll(() => fs.rm(tempDir, { force: true, recursive: true }));
44
- afterEach(() => nock.cleanAll());
45
- describe('getElectronReleases', () => {
46
- test('parses Electron versions', async () => {
47
- const result = await new ElectronInfo({
48
- releasesUrl: mockUrl,
49
- tempDirectory: tempDir,
50
- }).getElectronReleases('5.0.8');
51
- expect(result.length).toBe(1);
52
- expect(result[0].version).toBe('5.0.8');
53
- });
54
- test('parses Electron SemVer', async () => {
55
- const result = await new ElectronInfo({
56
- releasesUrl: mockUrl,
57
- tempDirectory: tempDir,
58
- }).getElectronReleases('^5');
59
- // eslint-disable-next-line no-magic-numbers
60
- expect(result.length).toBe(23);
61
- });
62
- test('parses dist tags', async () => {
63
- const result = await new ElectronInfo({
64
- releasesUrl: mockUrl,
65
- tempDirectory: tempDir,
66
- }).getElectronReleases('5-0-x');
67
- expect(result.length).toBe(1);
68
- });
69
- test('returns nothing for invalid versions', async () => {
70
- const result = await new ElectronInfo({
71
- releasesUrl: mockUrl,
72
- tempDirectory: tempDir,
73
- }).getElectronReleases('invalid');
74
- expect(result.length).toBe(0);
75
- });
76
- test('forces downloading the release file', async () => {
77
- const customBody = createRandomBody();
78
- const customUrl = 'http://custom.com';
79
- await provideReleaseFile();
80
- nock(customUrl).get('/').reply(HTTP_STATUS.OK, customBody);
81
- const result = await new ElectronInfo({
82
- forceUpdate: true,
83
- releasesUrl: customUrl,
84
- tempDirectory: tempDirDownload,
85
- }).getElectronReleases('all');
86
- expect(result).toEqual(customBody);
87
- });
88
- });
89
- describe('getDependencyReleases', () => {
90
- test('parses Chrome versions', async () => {
91
- const result = await new ElectronInfo({
92
- releasesUrl: mockUrl,
93
- tempDirectory: tempDir,
94
- }).getDependencyReleases('chrome', '71.0.3578.98');
95
- expect(result.length).toBe(2);
96
- expect(result[0].deps).toBeDefined();
97
- expect(result[0].deps.chrome).toBe('71.0.3578.98');
98
- });
99
- test('parses Chrome SemVer', async () => {
100
- const result = await new ElectronInfo({
101
- releasesUrl: mockUrl,
102
- tempDirectory: tempDir,
103
- }).getDependencyReleases('chrome', '~66');
104
- // eslint-disable-next-line no-magic-numbers
105
- expect(result.length).toBe(56);
106
- });
107
- test('returns nothing for invalid versions', async () => {
108
- const result = await new ElectronInfo({
109
- releasesUrl: mockUrl,
110
- tempDirectory: tempDir,
111
- }).getDependencyReleases('chrome', 'invalid');
112
- expect(result.length).toBe(0);
113
- });
114
- test('limits releases', async () => {
115
- const limit = 2;
116
- const result = await new ElectronInfo({
117
- limit,
118
- releasesUrl: mockUrl,
119
- tempDirectory: tempDir,
120
- }).getDependencyReleases('chrome', 'all');
121
- expect(result.length).toBe(limit);
122
- });
123
- test('uses a local copy of the releases', async () => {
124
- nock(invalidUrl).get('/').reply(HTTP_STATUS.NOT_FOUND);
125
- await provideReleaseFile();
126
- await new ElectronInfo({
127
- releasesUrl: invalidUrl,
128
- tempDirectory: tempDirDownload,
129
- }).getDependencyReleases('chrome', 'all');
130
- });
131
- test('uses latest as alias for limit=1', async () => {
132
- const result = await new ElectronInfo({
133
- latest: true,
134
- releasesUrl: mockUrl,
135
- tempDirectory: tempDir,
136
- }).getElectronReleases('all');
137
- expect(result.length).toBe(1);
138
- expect(result[0].version).toBe('8.0.0-nightly.20190820');
139
- });
140
- });
141
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,29 +0,0 @@
1
- import { assert, describe, test, beforeEach, afterEach } from 'vitest';
2
- import { StatusCodes as HTTP_STATUS } from 'http-status-codes';
3
- import nock from 'nock';
4
- import { HTTPService } from './HTTPService.js';
5
- const mockUrl = 'http://example.com';
6
- const FIVE_SECONDS_IN_MILLIS = 5000;
7
- const HALF_SECOND_IN_MILLIS = 500;
8
- describe('HTTPService', () => {
9
- const httpService = new HTTPService({
10
- debug: false,
11
- timeout: HALF_SECOND_IN_MILLIS,
12
- });
13
- beforeEach(() => {
14
- nock(mockUrl)
15
- .get('/')
16
- .delayConnection(FIVE_SECONDS_IN_MILLIS)
17
- .reply(HTTP_STATUS.OK, [{ data: 'invalid' }]);
18
- });
19
- afterEach(() => nock.cleanAll());
20
- describe('downloadReleasesFile', () => {
21
- test('honors a custom timeout', async () => {
22
- try {
23
- await httpService.downloadReleasesFile(mockUrl, '');
24
- assert.fail('Should throw on timeout');
25
- }
26
- catch (_a) { }
27
- });
28
- });
29
- });