Skip to content
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
26 changes: 0 additions & 26 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,3 @@ jobs:
echo 'SAUCENAO_TOKEN=${{ secrets.SAUCENAO_TOKEN }}' > ./.env.test.local
bun run coverage

test-node:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x, 22.x]

steps:
- uses: actions/checkout@v4.2.2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- uses: pnpm/action-setup@v4
with:
version: 9

- name: Get Dependencies and Build
run: pnpm install && pnpm build

- name: Run Coverage and Lint
run: |
echo 'SAUCENAO_TOKEN=${{ secrets.SAUCENAO_TOKEN }}' > ./.env.test.local
pnpm coverage:nodejs
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [4.3.0] - 2024-09-17

### Removed

- **BREAKING** - Removed `node-fetch` fallback. Native `fetch` is now required.
- **BREAKING** - Dropped CommonJS (CJS) support. The library is now ESM-only.

## [4.1.0] - 2024-08-27

- **NEW** - Library now passes Deno tests. Any forthcoming change should always pass through the test suite.
Expand Down
Binary file modified bun.lockb
Binary file not shown.
11 changes: 0 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
"version": "4.3.0",
"description": "A simple, lightweight and actually good JS wrapper for the SauceNAO API.",
"license": "MIT",
"main": "./dist/sagiri.cjs",
"module": "./dist/sagiri.mjs",
"types": "./dist/sagiri.d.ts",
"exports": {
".": {
"require": "./dist/sagiri.cjs",
"import": "./dist/sagiri.mjs"
}
},
Expand Down Expand Up @@ -55,8 +53,6 @@
"test": "bun --env-file='./.env.test.local' test bun",
"test:deno": "deno test --unstable-sloppy-imports --allow-net --allow-read test/deno/sagiri.test.ts",
"coverage:deno": "deno test --unstable-sloppy-imports --allow-net --allow-read --coverage test/deno/sagiri.test.ts",
"test:nodejs": "mocha ./test/node/",
"coverage:nodejs": "nyc mocha ./test/node/",
"coverage": "bun --env-file='./.env.test.local' test bun --coverage",
"lint": "eslint --fix",
"build": "unbuild",
Expand All @@ -65,12 +61,8 @@
},
"devDependencies": {
"@types/bun": "latest",
"@types/mocha": "^10.0.9",
"@types/node-fetch": "^2.6.11",
"bun": "^1.1.26",
"eslint": "^9.9.1",
"mocha": "^11.0.1",
"nyc": "^17.1.0",
"typescript": "^5.6.2",
"typescript-eslint": "^8.3.0",
"unbuild": "^3.2.0"
Expand All @@ -80,8 +72,5 @@
},
"dependencies": {
"form-data": "^4.0.0"
},
"optionalDependencies": {
"node-fetch": "^2.6.7"
}
}
26 changes: 2 additions & 24 deletions src/sagiri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,8 @@ 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) {
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;
}

type File = string | Buffer | globalThis.Blob | Readable;

/**
Expand Down Expand Up @@ -108,9 +86,9 @@ const sagiri = (
throw new Error("Invalid file type");
}

const response = await fetchFn("https://saucenao.com/search.php", {
const response = await fetch("https://saucenao.com/search.php", {
method: "POST",
body: form.getBuffer(),
body: form.getBuffer() as any,
headers: form.getHeaders(),
});

Expand Down
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import { IResult } from "./response";
import type { IResult } from "./response";
import sites from "./sites";

export const generateMask = (masks: number[]): number =>
Expand Down
1 change: 1 addition & 0 deletions test/deno/sagiri.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// <reference lib="deno.ns" />
import { assertThrows, assertExists } from "jsr:@std/assert";
import sagiri from "../../src/sagiri.ts";

Expand Down
16 changes: 0 additions & 16 deletions test/node/commonjs.test.cjs

This file was deleted.

Loading