Skip to content

Commit 696f082

Browse files
authoredAug 25, 2024··
Remove node-fetch and got from dependencies (#1133)
* Remove `node-fetch` and `got` from dependencies * Remove console * npm dedupe * Try 22.4.1 * Try 22.5.1 * Try revert CI change
1 parent 8b57290 commit 696f082

File tree

5 files changed

+281
-519
lines changed

5 files changed

+281
-519
lines changed
 

Diff for: ‎lib/plugin/github/GitHub.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import fs from 'node:fs';
22
import path from 'node:path';
33
import open from 'open';
44
import { Octokit } from '@octokit/rest';
5-
import fetch from 'node-fetch';
65
import { globby } from 'globby';
76
import mime from 'mime-types';
87
import _ from 'lodash';
@@ -177,8 +176,7 @@ class GitHub extends Release {
177176
userAgent: `release-it/${pkg.version}`,
178177
log: this.config.isDebug ? console : null,
179178
request: {
180-
timeout,
181-
fetch
179+
timeout
182180
}
183181
};
184182

Diff for: ‎lib/plugin/gitlab/GitLab.js

+24-21
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import fs from 'node:fs';
22
import path from 'node:path';
3-
import got from 'got';
43
import { globby } from 'globby';
5-
import { FormData, fileFromSync } from 'node-fetch';
64
import _ from 'lodash';
75
import Release from '../GitRelease.js';
86
import { format, e } from '../../util.js';
@@ -30,22 +28,6 @@ class GitLab extends Release {
3028
this.certificateAuthorityOption = _.isEmpty(https) ? {} : { https };
3129
}
3230

33-
get client() {
34-
if (this._client) return this._client;
35-
const { tokenHeader } = this.options;
36-
const { baseUrl } = this.getContext();
37-
this._client = got.extend({
38-
prefixUrl: baseUrl,
39-
method: 'POST',
40-
headers: {
41-
'user-agent': 'webpro/release-it',
42-
[tokenHeader]: this.token
43-
},
44-
...this.certificateAuthorityOption
45-
});
46-
return this._client;
47-
}
48-
4931
async init() {
5032
await super.init();
5133

@@ -179,8 +161,28 @@ class GitLab extends Release {
179161
const { baseUrl } = this.getContext();
180162
this.debug(Object.assign({ url: `${baseUrl}/${endpoint}` }, options));
181163
const method = (options.method || 'POST').toLowerCase();
182-
const response = await this.client[method](endpoint, options);
183-
const body = typeof response.body === 'string' ? JSON.parse(response.body) : response.body || {};
164+
const { tokenHeader } = this.options;
165+
const url = `${baseUrl}/${endpoint}${options.searchParams ? `?${new URLSearchParams(options.searchParams)}` : ''}`;
166+
const headers = {
167+
'user-agent': 'webpro/release-it',
168+
[tokenHeader]: this.token
169+
};
170+
const requestOptions = {
171+
method,
172+
headers,
173+
...this.certificateAuthorityOption
174+
};
175+
176+
const response = await fetch(
177+
url,
178+
options.json || options.body
179+
? {
180+
...requestOptions,
181+
body: options.json ? JSON.stringify(options.json) : options.body
182+
}
183+
: requestOptions
184+
);
185+
const body = await response.json();
184186
this.debug(body);
185187
return body;
186188
}
@@ -239,7 +241,8 @@ class GitLab extends Release {
239241
const endpoint = `projects/${id}/uploads`;
240242

241243
const body = new FormData();
242-
body.set('file', fileFromSync(filePath));
244+
const rawData = await fs.promises.readFile(filePath);
245+
body.set('file', new Blob([rawData]), name);
243246
const options = { body };
244247

245248
try {

Diff for: ‎package-lock.json

+254-486
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: ‎package.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,12 @@
8686
"execa": "8.0.1",
8787
"git-url-parse": "14.0.0",
8888
"globby": "14.0.2",
89-
"got": "13.0.0",
9089
"inquirer": "9.3.2",
9190
"is-ci": "3.0.1",
9291
"issue-parser": "7.0.1",
9392
"lodash": "4.17.21",
9493
"mime-types": "2.1.35",
9594
"new-github-release-url": "2.0.0",
96-
"node-fetch": "3.3.2",
9795
"open": "10.1.0",
9896
"ora": "8.0.1",
9997
"os-name": "5.1.0",
@@ -123,7 +121,7 @@
123121
"knip": "5.26.0",
124122
"memfs": "4.9.3",
125123
"mock-stdio": "1.0.3",
126-
"nock": "13.5.4",
124+
"nock": "14.0.0-beta.8",
127125
"prettier": "3.3.3",
128126
"remark-cli": "12.0.1",
129127
"remark-preset-webpro": "1.1.0",

Diff for: ‎test/gitlab.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -226,29 +226,24 @@ test('should not make requests in dry run', async t => {
226226
const options = { 'dry-run': true, git: { pushRepo }, gitlab: { releaseName: 'R', tokenRef } };
227227
const gitlab = factory(GitLab, { options });
228228
sinon.stub(gitlab, 'getLatestVersion').resolves('1.0.0');
229-
const spy = sinon.spy(gitlab, 'client', ['get']);
230229

231230
await runTasks(gitlab);
232231

233232
const { isReleased, releaseUrl } = gitlab.getContext();
234-
t.is(spy.get.callCount, 0);
233+
235234
t.is(gitlab.log.exec.args[2][0], 'gitlab releases#uploadAssets');
236235
t.is(gitlab.log.exec.args[3][0], 'gitlab releases#createRelease "R" (1.0.1)');
237236
t.true(isReleased);
238237
t.is(releaseUrl, `${pushRepo}/-/releases`);
239-
spy.get.restore();
240238
});
241239

242240
test('should skip checks', async t => {
243241
const options = { gitlab: { tokenRef, skipChecks: true, release: true, milestones: ['v1.0.0'] } };
244242
const gitlab = factory(GitLab, { options });
245-
const spy = sinon.spy(gitlab, 'client', ['get']);
246243

247244
await t.notThrowsAsync(gitlab.init());
248245
await t.notThrowsAsync(gitlab.beforeRelease());
249246

250-
t.is(spy.get.callCount, 0);
251-
252247
t.is(gitlab.log.exec.args.filter(entry => /checkReleaseMilestones/.test(entry[0])).length, 0);
253248
});
254249

0 commit comments

Comments
 (0)
Please sign in to comment.