Skip to content

Commit ad82dec

Browse files
Remove node-fetch fallback and drop CJS support (#641)
* chore: remove node-fetch fallback and drop CJS support - Removed node-fetch from optionalDependencies and @types/node-fetch from devDependencies. - Refactored src/sagiri.ts to use native fetch and removed legacy fallback logic. - Dropped CommonJS (CJS) support, making the library ESM-only. - Updated package.json exports and removed Node.js specific scripts. - Deleted CJS test file test/node/commonjs.test.cjs. - Cleaned up unused devDependencies (mocha, nyc). - Updated CHANGELOG.md for version 4.3.0. Co-authored-by: sr229 <14976516+sr229@users.noreply.github.com> * fix: resolve CI failures after node-fetch removal - Fixed Deno type check errors by using type-only import for IResult in util.ts. - Added Deno namespace reference to Deno tests. - Updated GitHub Actions test-node job to use bun for coverage instead of removed coverage:nodejs. Co-authored-by: sr229 <14976516+sr229@users.noreply.github.com> * fix: add bun setup to test-node job in CI The test-node job was failing because it tried to run `bun run coverage` without having Bun installed in that job's environment. Added `oven-sh/setup-bun@v2` to the `test-node` job. Co-authored-by: sr229 <14976516+sr229@users.noreply.github.com> * chore: trim out Node.js specific tests from CI Since we are no longer running Node.js specific tests (dropped CJS/mocha), the `test-node` job was redundant and actually incorrect as it tried to use `bun`. We now rely on `test-bun` and `test-deno` jobs. - Removed `test-node` job from `.github/workflows/test.yml`. - Removed empty `test/node` directory. Co-authored-by: sr229 <14976516+sr229@users.noreply.github.com> --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent e9b2511 commit ad82dec

8 files changed

Lines changed: 11 additions & 78 deletions

File tree

.github/workflows/test.yml

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,3 @@ jobs:
5454
echo 'SAUCENAO_TOKEN=${{ secrets.SAUCENAO_TOKEN }}' > ./.env.test.local
5555
bun run coverage
5656
57-
test-node:
58-
runs-on: ubuntu-latest
59-
60-
strategy:
61-
matrix:
62-
node-version: [20.x, 22.x]
63-
64-
steps:
65-
- uses: actions/checkout@v4.2.2
66-
67-
- name: Use Node.js ${{ matrix.node-version }}
68-
uses: actions/setup-node@v4
69-
with:
70-
node-version: ${{ matrix.node-version }}
71-
72-
- uses: pnpm/action-setup@v4
73-
with:
74-
version: 9
75-
76-
- name: Get Dependencies and Build
77-
run: pnpm install && pnpm build
78-
79-
- name: Run Coverage and Lint
80-
run: |
81-
echo 'SAUCENAO_TOKEN=${{ secrets.SAUCENAO_TOKEN }}' > ./.env.test.local
82-
pnpm coverage:nodejs

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [4.3.0] - 2024-09-17
9+
10+
### Removed
11+
12+
- **BREAKING** - Removed `node-fetch` fallback. Native `fetch` is now required.
13+
- **BREAKING** - Dropped CommonJS (CJS) support. The library is now ESM-only.
14+
815
## [4.1.0] - 2024-08-27
916

1017
- **NEW** - Library now passes Deno tests. Any forthcoming change should always pass through the test suite.

bun.lockb

-1.85 KB
Binary file not shown.

package.json

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
"version": "4.3.0",
44
"description": "A simple, lightweight and actually good JS wrapper for the SauceNAO API.",
55
"license": "MIT",
6-
"main": "./dist/sagiri.cjs",
76
"module": "./dist/sagiri.mjs",
87
"types": "./dist/sagiri.d.ts",
98
"exports": {
109
".": {
11-
"require": "./dist/sagiri.cjs",
1210
"import": "./dist/sagiri.mjs"
1311
}
1412
},
@@ -55,8 +53,6 @@
5553
"test": "bun --env-file='./.env.test.local' test bun",
5654
"test:deno": "deno test --unstable-sloppy-imports --allow-net --allow-read test/deno/sagiri.test.ts",
5755
"coverage:deno": "deno test --unstable-sloppy-imports --allow-net --allow-read --coverage test/deno/sagiri.test.ts",
58-
"test:nodejs": "mocha ./test/node/",
59-
"coverage:nodejs": "nyc mocha ./test/node/",
6056
"coverage": "bun --env-file='./.env.test.local' test bun --coverage",
6157
"lint": "eslint --fix",
6258
"build": "unbuild",
@@ -65,12 +61,8 @@
6561
},
6662
"devDependencies": {
6763
"@types/bun": "latest",
68-
"@types/mocha": "^10.0.9",
69-
"@types/node-fetch": "^2.6.11",
7064
"bun": "^1.1.26",
7165
"eslint": "^9.9.1",
72-
"mocha": "^11.0.1",
73-
"nyc": "^17.1.0",
7466
"typescript": "^5.6.2",
7567
"typescript-eslint": "^8.3.0",
7668
"unbuild": "^3.2.0"
@@ -80,8 +72,5 @@
8072
},
8173
"dependencies": {
8274
"form-data": "^4.0.0"
83-
},
84-
"optionalDependencies": {
85-
"node-fetch": "^2.6.7"
8675
}
8776
}

src/sagiri.ts

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,8 @@ import FormData from "form-data";
77
import { generateMask, resolveResult } from "./util";
88
import { SagiriClientError, SagiriServerError } from "./errors";
99
import type { IResponse, IResult } from "./response";
10-
import * as process from "node:process";
1110
import sites from "./sites";
1211

13-
// compatibility with older versions of nodejs. This will be removed in the future once LTS versions of nodejs has moved above 21.x
14-
let fetchFn;
15-
const disableWarning = process.env.SAGIRI_DISABLE_NODE_FETCH_WARNING === "true" ? true : false;
16-
17-
if (globalThis.fetch === undefined) {
18-
if (!disableWarning)
19-
console.warn(`
20-
WARNING: Starting in Sagiri 4.3.x, the node-fetch fallback will be removed in favor of using Node.js's native
21-
fetch implementation. Furthermore, CJS exports will cease to work. 4.3.0 will be a transitionary period for
22-
everyone relying on the old implementation. If you wish to use older LTS versions, stick to Sagiri 4.2.x
23-
which will be supported until EOY 2025.
24-
25-
To disable this warning, add SAGIRI_DISABLE_NODE_FETCH_WARNING="true" in your environment variable.
26-
`)
27-
28-
// eslint-disable-next-line @typescript-eslint/no-require-imports
29-
fetchFn = require("node-fetch");
30-
} else {
31-
fetchFn = globalThis.fetch;
32-
}
33-
3412
type File = string | Buffer | globalThis.Blob | Readable;
3513

3614
/**
@@ -108,9 +86,9 @@ const sagiri = (
10886
throw new Error("Invalid file type");
10987
}
11088

111-
const response = await fetchFn("https://saucenao.com/search.php", {
89+
const response = await fetch("https://saucenao.com/search.php", {
11290
method: "POST",
113-
body: form.getBuffer(),
91+
body: form.getBuffer() as any,
11492
headers: form.getHeaders(),
11593
});
11694

src/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22

3-
import { IResult } from "./response";
3+
import type { IResult } from "./response";
44
import sites from "./sites";
55

66
export const generateMask = (masks: number[]): number =>

test/deno/sagiri.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/// <reference lib="deno.ns" />
12
import { assertThrows, assertExists } from "jsr:@std/assert";
23
import sagiri from "../../src/sagiri.ts";
34

test/node/commonjs.test.cjs

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)