Skip to content

Commit 392ca31

Browse files
refactor: replace got with native fetch API (#4189)
chore: remove got dependency in favor of built-in fetch Replace the got HTTP client with native fetch in the zip maker for fetching RELEASES.json manifests. Native fetch has been stable in Node.js since v18 and the package already requires Node >= 22.12.0. Also remove the unused got dependency from @electron-forge/core. Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6cdefb6 commit 392ca31

File tree

4 files changed

+29
-38
lines changed

4 files changed

+29
-38
lines changed

packages/maker/zip/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
"@electron-forge/maker-base": "workspace:*",
1919
"@electron-forge/shared-types": "workspace:*",
2020
"cross-zip": "^4.0.0",
21-
"fs-extra": "^10.0.0",
22-
"got": "^14.0.0"
21+
"fs-extra": "^10.0.0"
2322
},
2423
"publishConfig": {
2524
"access": "public"

packages/maker/zip/spec/MakerZip.spec.ts

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import path from 'node:path';
44
import { ForgeArch } from '@electron-forge/shared-types';
55
import { zip } from 'cross-zip';
66
import fs from 'fs-extra';
7-
import { got } from 'got';
8-
import { describe, expect, it, vi } from 'vitest';
7+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
98

109
import { MakerZIP } from '../src/MakerZIP';
1110

@@ -32,19 +31,17 @@ vi.mock(import('fs-extra'), async (importOriginal) => {
3231
};
3332
});
3433

35-
// @ts-expect-error - This mock works but vi.mock isn't happy.
36-
vi.mock(import('got'), async (importOriginal) => {
37-
const mod = await importOriginal();
38-
return {
39-
...mod,
40-
got: {
41-
...mod.got,
42-
get: vi.fn(),
43-
},
44-
};
45-
});
46-
4734
describe('MakerZip', () => {
35+
const mockFetch = vi.fn();
36+
37+
beforeEach(() => {
38+
vi.stubGlobal('fetch', mockFetch);
39+
});
40+
41+
afterEach(() => {
42+
vi.unstubAllGlobals();
43+
});
44+
4845
const dir = path.resolve(import.meta.dirname, 'fixture', 'fake-app');
4946
const darwinDir = path.resolve(
5047
import.meta.dirname,
@@ -141,7 +138,7 @@ describe('MakerZip', () => {
141138
});
142139

143140
expect(output).toHaveLength(1);
144-
expect(got.get).not.toHaveBeenCalled();
141+
expect(mockFetch).not.toHaveBeenCalled();
145142
},
146143
);
147144

@@ -155,7 +152,7 @@ describe('MakerZip', () => {
155152
);
156153
maker.prepareConfig(targetArch);
157154
maker.ensureFile = vi.fn();
158-
vi.mocked(got.get).mockResolvedValue({ statusCode: 200, body: '{}' });
155+
mockFetch.mockResolvedValue(new Response('{}', { status: 200 }));
159156
await maker.make({
160157
dir: darwinDir,
161158
makeDir,
@@ -166,7 +163,7 @@ describe('MakerZip', () => {
166163
forgeConfig: null as any,
167164
});
168165

169-
expect(got.get).toHaveBeenCalledOnce();
166+
expect(mockFetch).toHaveBeenCalledOnce();
170167
expect(fs.writeJson).toHaveBeenCalledWith(expect.anything(), {
171168
currentRelease: '1.2.3',
172169
releases: [
@@ -193,10 +190,7 @@ describe('MakerZip', () => {
193190
);
194191
maker.prepareConfig(targetArch);
195192
maker.ensureFile = vi.fn();
196-
vi.mocked(got.get).mockResolvedValue({
197-
statusCode: 404,
198-
body: undefined,
199-
});
193+
mockFetch.mockResolvedValue(new Response(null, { status: 404 }));
200194
await maker.make({
201195
dir: darwinDir,
202196
makeDir,
@@ -207,7 +201,7 @@ describe('MakerZip', () => {
207201
forgeConfig: null as any,
208202
});
209203

210-
expect(got.get).toHaveBeenCalledOnce();
204+
expect(mockFetch).toHaveBeenCalledOnce();
211205
expect(fs.writeJson).toHaveBeenCalledWith(expect.anything(), {
212206
currentRelease: '1.2.3',
213207
releases: [
@@ -243,13 +237,15 @@ describe('MakerZip', () => {
243237
url: 'fake://test/bar',
244238
},
245239
};
246-
vi.mocked(got.get).mockResolvedValue({
247-
statusCode: 200,
248-
body: JSON.stringify({
249-
currentRelease: '1.1.1',
250-
releases: [oneOneOneRelease],
251-
}),
252-
});
240+
mockFetch.mockResolvedValue(
241+
new Response(
242+
JSON.stringify({
243+
currentRelease: '1.1.1',
244+
releases: [oneOneOneRelease],
245+
}),
246+
{ status: 200 },
247+
),
248+
);
253249
await maker.make({
254250
dir: darwinDir,
255251
makeDir,

packages/maker/zip/src/MakerZIP.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { MakerBase, MakerOptions } from '@electron-forge/maker-base';
55
import { ForgePlatform } from '@electron-forge/shared-types';
66
import { zip } from 'cross-zip';
77
import fs from 'fs-extra';
8-
import { got } from 'got';
98

109
import { MakerZIPConfig } from './Config.js';
1110

@@ -62,15 +61,13 @@ export default class MakerZIP extends MakerBase<MakerZIPConfig> {
6261
if (targetPlatform === 'darwin' && this.config.macUpdateManifestBaseUrl) {
6362
const parsed = new URL(this.config.macUpdateManifestBaseUrl);
6463
parsed.pathname += '/RELEASES.json';
65-
const response = await got.get(parsed.toString(), {
66-
throwHttpErrors: false,
67-
});
64+
const response = await fetch(parsed.toString());
6865
let currentValue: SquirrelMacReleases = {
6966
currentRelease: '',
7067
releases: [],
7168
};
72-
if (response.statusCode === 200) {
73-
currentValue = JSON.parse(response.body);
69+
if (response.status === 200) {
70+
currentValue = (await response.json()) as SquirrelMacReleases;
7471
}
7572
const updateUrl = new URL(this.config.macUpdateManifestBaseUrl);
7673
updateUrl.pathname += `/${zipName}`;

yarn.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,6 @@ __metadata:
10431043
"@electron-forge/shared-types": "workspace:*"
10441044
cross-zip: "npm:^4.0.0"
10451045
fs-extra: "npm:^10.0.0"
1046-
got: "npm:^14.0.0"
10471046
vitest: "npm:^4.0.14"
10481047
languageName: unknown
10491048
linkType: soft

0 commit comments

Comments
 (0)