Skip to content

Commit

Permalink
chore(deps): remove node-fetch and formdata-node
Browse files Browse the repository at this point in the history
  • Loading branch information
kanadgupta committed May 6, 2024
1 parent 1be0390 commit b9cc12b
Show file tree
Hide file tree
Showing 18 changed files with 7 additions and 128 deletions.
5 changes: 0 additions & 5 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@
"error",
{
"paths": [
{
"name": "node-fetch",
"importNames": ["default"],
"message": "Avoid using `node-fetch` directly and instead use the fetch wrapper located in `lib/readmeAPIFetch.ts`. See CONTRIBUTING.md for more information."
},
{
"name": "ci-info",
"message": "The `ci-info` package is difficult to test because misleading results will appear when running tests in the GitHub Actions runner. Instead of importing this package directly, create a wrapper function in `lib/isCI.ts` and import that instead."
Expand Down
1 change: 0 additions & 1 deletion __tests__/lib/fetch.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable no-console */
import { Headers } from 'node-fetch';
import { describe, beforeEach, afterEach, it, expect, vi } from 'vitest';

import pkg from '../../package.json' with { type: 'json' };
Expand Down
2 changes: 0 additions & 2 deletions __tests__/lib/prompts.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { Response } from 'node-fetch';

import prompts from 'prompts';
import { describe, it, expect } from 'vitest';

Expand Down
2 changes: 0 additions & 2 deletions bin/json-schema-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import fs from 'node:fs/promises';
import path from 'node:path';

// eslint-disable-next-line no-restricted-imports
import fetch from 'node-fetch';
import prettier from 'prettier';

const files = [
Expand Down
94 changes: 0 additions & 94 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@
"command-line-usage": "^7.0.1",
"configstore": "^6.0.0",
"debug": "^4.3.3",
"formdata-node": "^6.0.3",
"gray-matter": "^4.0.1",
"ignore": "^5.2.0",
"mime-types": "^2.1.35",
"node-fetch": "^3.3.2",
"oas": "^24.0.0",
"oas-normalize": "^11.0.1",
"open": "^10.0.2",
Expand Down
1 change: 0 additions & 1 deletion src/cmds/categories/create.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { AuthenticatedCommandOptions } from '../../lib/baseCommand.js';

import chalk from 'chalk';
import { Headers } from 'node-fetch';

import Command, { CommandCategories } from '../../lib/baseCommand.js';
import config from '../../lib/config.js';
Expand Down
2 changes: 0 additions & 2 deletions src/cmds/openapi/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import type { AuthenticatedCommandOptions } from '../../lib/baseCommand.js';
import type { OpenAPIPromptOptions } from '../../lib/prompts.js';
import type { RequestInit, Response } from 'node-fetch';

import chalk from 'chalk';
import { Headers } from 'node-fetch';
import ora from 'ora';
import parse from 'parse-link-header';

Expand Down
1 change: 0 additions & 1 deletion src/cmds/versions/create.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { Version } from './index.js';
import type { AuthenticatedCommandOptions } from '../../lib/baseCommand.js';

import { Headers } from 'node-fetch';
import prompts from 'prompts';
import semver from 'semver';

Expand Down
1 change: 0 additions & 1 deletion src/cmds/versions/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { CommonOptions } from './create.js';
import type { Version } from './index.js';
import type { AuthenticatedCommandOptions } from '../../lib/baseCommand.js';

import { Headers } from 'node-fetch';
import prompts from 'prompts';

import Command, { CommandCategories } from '../../lib/baseCommand.js';
Expand Down
2 changes: 0 additions & 2 deletions src/lib/deleteDoc.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { CommandCategories } from './baseCommand.js';

import { Headers } from 'node-fetch';

import readmeAPIFetch, { cleanHeaders, handleRes } from './readmeAPIFetch.js';

/**
Expand Down
2 changes: 0 additions & 2 deletions src/lib/getCategories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Headers } from 'node-fetch';

import readmeAPIFetch, { cleanHeaders, handleRes } from './readmeAPIFetch.js';

/**
Expand Down
2 changes: 0 additions & 2 deletions src/lib/getDocs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Headers } from 'node-fetch';

import getCategories from './getCategories.js';
import readmeAPIFetch, { cleanHeaders, handleRes } from './readmeAPIFetch.js';

Expand Down
2 changes: 0 additions & 2 deletions src/lib/getPkgVersion.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// eslint-disable-next-line no-restricted-imports
import fetch from 'node-fetch';
import semver from 'semver';

import pkg from '../../package.json' with { type: 'json' };
Expand Down
1 change: 0 additions & 1 deletion src/lib/prompts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Version } from '../cmds/versions/index.js';
import type { Response } from 'node-fetch';
import type { Choice, PromptObject } from 'prompts';

import parse from 'parse-link-header';
Expand Down
13 changes: 7 additions & 6 deletions src/lib/readmeAPIFetch.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import type { SpecFileType } from './prepareOas.js';
import type { RequestInit, Response } from 'node-fetch';

import path from 'node:path';

import mime from 'mime-types';
import nodeFetch, { Headers } from 'node-fetch'; // eslint-disable-line no-restricted-imports

import pkg from '../../package.json' with { type: 'json' };

Expand Down Expand Up @@ -119,8 +117,11 @@ async function normalizeFilePath(opts: FilePathDetails) {
* Sanitizes and stringifies the `Headers` object for logging purposes
*/
function sanitizeHeaders(headers: Headers) {
const raw = new Headers(headers).raw();
if (raw.Authorization) raw.Authorization = ['redacted'];
const raw = Array.from(headers.entries()).reduce<Record<string, string>>((prev, current) => {
// eslint-disable-next-line no-param-reassign
prev[current[0]] = current[0].toLowerCase() === 'authorization' ? 'redacted' : current[1];
return prev;
}, {});
return JSON.stringify(raw);
}

Expand Down Expand Up @@ -188,7 +189,7 @@ export default async function readmeAPIFetch(
`making ${(options.method || 'get').toUpperCase()} request to ${fullUrl} with headers: ${sanitizeHeaders(headers)}`,
);

return nodeFetch(fullUrl, {
return fetch(fullUrl, {
...options,
headers,
}).then(res => {
Expand Down Expand Up @@ -241,7 +242,7 @@ async function handleRes(res: Response, rejectOnJsonError = true) {
}

/**
* Returns the basic auth header and any other defined headers for use in `node-fetch` API calls.
* Returns the basic auth header and any other defined headers for use in `fetch` API calls.
*
*/
function cleanHeaders(
Expand Down
1 change: 0 additions & 1 deletion src/lib/streamSpecToRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import fs from 'node:fs';

import { FormData } from 'formdata-node';
import ora from 'ora';
import { file as tmpFile } from 'tmp-promise';

Expand Down
1 change: 0 additions & 1 deletion src/lib/syncDocsPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import fs from 'node:fs/promises';
import path from 'node:path';

import chalk from 'chalk';
import { Headers } from 'node-fetch';
import toposort from 'toposort';

import APIError from './apiError.js';
Expand Down

0 comments on commit b9cc12b

Please sign in to comment.