Skip to content

Commit

Permalink
Start deprecating node-fetch fallback for future versions (#628)
Browse files Browse the repository at this point in the history
* Move node-fetch to optionalDependencies and add warning on fallback

Signed-off-by: GitHub <[email protected]>

* 4.3.0

Signed-off-by: GitHub <[email protected]>

* import node:process for deno

Signed-off-by: GitHub <[email protected]>

* hold-off deno testing in rc for now until we finish the transition

---------

Signed-off-by: GitHub <[email protected]>
  • Loading branch information
sr229 authored Jan 3, 2025
1 parent 1b041fc commit 907b544
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ jobs:

strategy:
matrix:
deno-version: [latest, rc]
# deno-version: [latest, rc]
deno-version: [latest]

steps:
- uses: actions/[email protected]
Expand Down
Binary file modified bun.lockb
Binary file not shown.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sagiri",
"version": "4.2.3",
"version": "4.3.0",
"description": "A simple, lightweight and actually good JS wrapper for the SauceNAO API.",
"license": "MIT",
"main": "./dist/sagiri.cjs",
Expand Down Expand Up @@ -79,7 +79,9 @@
"typescript": "^5.0.0"
},
"dependencies": {
"form-data": "^4.0.0",
"form-data": "^4.0.0"
},
"optionalDependencies": {
"node-fetch": "^2.6.7"
}
}
16 changes: 14 additions & 2 deletions src/sagiri.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as nodeFetch from "node-fetch";
import type { IOptions } from "./interfaces";
import { env } from "node:process";
import { Buffer } from "node:buffer";
Expand All @@ -8,13 +7,26 @@ import FormData from "form-data";
import { generateMask, resolveResult } from "./util";
import { SagiriClientError, SagiriServerError } from "./errors";
import type { IResponse, IResult } from "./response";
import * as process from "node:process";
import sites from "./sites";

// compatibility with older versions of nodejs. This will be removed in the future once LTS versions of nodejs has moved above 21.x
let fetchFn;
const disableWarning = process.env.SAGIRI_DISABLE_NODE_FETCH_WARNING === "true" ? true : false;

if (globalThis.fetch === undefined) {
fetchFn = nodeFetch.default;
if (!disableWarning)
console.warn(`
WARNING: Starting in Sagiri 4.3.x, the node-fetch fallback will be removed in favor of using Node.js's native
fetch implementation. Furthermore, CJS exports will cease to work. 4.3.0 will be a transitionary period for
everyone relying on the old implementation. If you wish to use older LTS versions, stick to Sagiri 4.2.x
which will be supported until EOY 2025.
To disable this warning, add SAGIRI_DISABLE_NODE_FETCH_WARNING="true" in your environment variable.
`)

// eslint-disable-next-line @typescript-eslint/no-require-imports
fetchFn = require("node-fetch");
} else {
fetchFn = globalThis.fetch;
}
Expand Down

0 comments on commit 907b544

Please sign in to comment.