Skip to content

Commit

Permalink
Merge pull request #612 from ClarityCafe/sr229/cjs
Browse files Browse the repository at this point in the history
Fix CJS support
  • Loading branch information
sr229 authored Oct 8, 2024
2 parents 0b35a73 + 201c4e3 commit c27caa2
Show file tree
Hide file tree
Showing 16 changed files with 92 additions and 34 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
deno install -D
deno task build
deno task coverage:deno
test-bun:
runs-on: ubuntu-latest

Expand All @@ -52,3 +53,30 @@ jobs:
run: |
echo 'SAUCENAO_TOKEN=${{ secrets.SAUCENAO_TOKEN }}' > ./.env.test.local
bun run coverage
test-node:
runs-on: ubuntu-latest

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

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

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ docsbuild/
# Lock files
package-lock.json
yarn.lock

# nyc test coverage
.nyc_output/
Binary file modified bun.lockb
Binary file not shown.
8 changes: 0 additions & 8 deletions jest.config.js

This file was deleted.

9 changes: 8 additions & 1 deletion jsr.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"name": "@clarity/sagiri",
"version": "4.1.0",
"exports": "./lib/sagiri.ts"
"exports": "./src/sagiri.ts",
"publish": {
"include": [
"LICENSE",
"README.md",
"src/**/*.ts"
]
}
}
40 changes: 25 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@
"version": "4.1.0",
"description": "A simple, lightweight and actually good JS wrapper for the SauceNAO API.",
"license": "MIT",
"main": "dist/sagiri.cjs",
"type": "module",
"main": "./dist/sagiri.cjs",
"module": "./dist/sagiri.mjs",
"types": "./dist/sagiri.d.ts",
"exports": {
".": {
"require": "./dist/sagiri.cjs",
"import": "./dist/sagiri.mjs"
}
},
"homepage": "https://github.com/ClarityCafe/Sagiri#readme",
"repository": {
"type": "git",
Expand Down Expand Up @@ -36,39 +43,42 @@
"source"
],
"engines": {
"node": ">=20"
"node": "20.x"
},
"files": [
"dist",
"README.md",
"LICENSE"
],
"exports": {
"import": "./dist/sagiri.cjs",
"require": "./dist/index.cjs"
},
"scripts": {
"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": "jest node",
"coverage:nodejs": "jest node --coverage",
"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": "tsup",
"prepublishOnly": "bun run build"
"build": "unbuild",
"prepublishOnly": "bun run build",
"postinstall": "node scripts/postinstall.js"
},
"devDependencies": {
"@types/bun": "latest",
"@types/mocha": "^10.0.9",
"@types/node-fetch": "^2.6.11",
"bun": "^1.1.26",
"eslint": "^9.9.1",
"jest": "^29.7.0",
"tsup": "^8.2.4",
"mocha": "^10.7.3",
"nyc": "^17.1.0",
"typescript": "^5.6.2",
"typescript-eslint": "^8.3.0"
"typescript-eslint": "^8.3.0",
"unbuild": "^2.0.0"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"dependencies": { "form-data": "^4.0.0", "node-fetch": "^3.3.2" }
"dependencies": {
"form-data": "^4.0.0",
"node-fetch": "2.6.6"
}
}
14 changes: 14 additions & 0 deletions scripts/postinstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
console.log(`
**************************************************
* *
* Thank you for using Sagiri <3! *
* *
* If you find this library useful, please *
* consider supporting its maintenance by *
* contributing or donating. *
* *
**************************************************
Support this project financially at: https://ko-fi.com/capuccino
Contribute to this project at: https://github.com/ClarityCafe/Sagiri
`);
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion test/bun/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from "bun:test";
import sagiri from "../../lib/sagiri";
import sagiri from "../../src/sagiri";
import { env } from "node:process";

test("Should fail on invalid characters", () => {
Expand Down
2 changes: 1 addition & 1 deletion test/deno/sagiri.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assertThrows, assertExists } from "@std/assert";
import sagiri from "../../lib/sagiri.ts";
import sagiri from "../../src/sagiri.ts";

Deno.test("should fail on invalid characters", () => {
assertThrows(() => { sagiri("!!!!!*&#@(!)") });
Expand Down
20 changes: 12 additions & 8 deletions test/node/commonjs.test.cjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
/* eslint-disable @typescript-eslint/no-require-imports */
const process = require("process");
// this is so arbitrary holy shit
const sagiriOnCjs = require("../../dist/sagiri.cjs");
/* eslint-disable no-undef */
const assert = require('assert');
const sagiri = require('../../dist/sagiri.cjs');
const describe = require('mocha').describe;
const it = require('mocha').it;

test("Resolve using Commonjs", async() => {
const result = await sagiriOnCjs(process.env.SAUCENAO_TOKEN, { results: 5 })("https://i.imgur.com/F9QSgPx.jpeg");
console.log(result);
describe('Sagiri#client', function() {
it('should be a function', function() {
assert.strictEqual(typeof sagiri, 'function');
});

expect(sagiriOnCjs).toBeDefined();
expect(result).toBeDefined();
it('should throw on invalid characters', function () {
assert.throws(() => sagiri("!!!!!*&#@(!)"));
})
})

0 comments on commit c27caa2

Please sign in to comment.