Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start deprecating node-fetch fallback for future versions #628

Merged
merged 4 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading