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

Update Biome Version, extended .vscode/settings.json and Eliminate Dependency Caching #47

Merged
merged 4 commits into from
Sep 30, 2024
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
34 changes: 2 additions & 32 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,8 @@ jobs:
with:
bun-version: 1.1.6

# Cache the local `node_modules` directory.
- name: Restore npm cache
id: cache-node-modules
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('patches/**') }}-${{ hashFiles('bun.lockb') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('patches/**') }}-
${{ runner.os }}-build-${{ hashFiles('patches/**') }}-
${{ runner.os }}-${{ hashFiles('patches/**') }}-

- name: Install Dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: bun install --frozen-lockfile
run: bun install

- name: Code Linting
run: bun run lint
Expand All @@ -51,23 +36,8 @@ jobs:
with:
bun-version: 1.1.6

# Cache the local `node_modules` directory.
- name: Restore npm cache
id: cache-node-modules
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('patches/**') }}-${{ hashFiles('bun.lockb') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('patches/**') }}-
${{ runner.os }}-build-${{ hashFiles('patches/**') }}-
${{ runner.os }}-${{ hashFiles('patches/**') }}-

- name: Install Dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: bun install --frozen-lockfile
run: bun install

- name: Testing
run: bun run test
30 changes: 24 additions & 6 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
{
"editor.rulers": [80, 120],

"editor.defaultFormatter": "biomejs.biome",
"editor.formatOnSave": true,

"editor.defaultFormatter": "biomejs.biome",
"editor.rulers": [90, 120],
"editor.insertSpaces": true,
"editor.detectIndentation": true,
"editor.codeActionsOnSave": {
"source.organizeImports.biome": "explicit"
},

"javascript.updateImportsOnFileMove.enabled": "always",
"typescript.updateImportsOnFileMove.enabled": "always",
"javascript.preferences.importModuleSpecifier": "non-relative",
"typescript.preferences.importModuleSpecifier": "non-relative",
"typescript.suggest.autoImports": true,
"typescript.preferences.quoteStyle": "single",
"javascript.preferences.quoteStyle": "single",
"[json][javascript][javascriptreact][typescript][typescriptreact]": {
"editor.defaultFormatter": "biomejs.biome"
},

"typescript.updateImportsOnFileMove.enabled": "always",
"typescript.preferences.importModuleSpecifier": "non-relative"
"typescript.format.enable": false,
"javascript.format.enable": false,

"yaml.schemas": {
"https://json.schemastore.org/github-workflow.json": ".github/workflows/*.yml"
},

"tailwindCSS.colorDecorators": false
}
65 changes: 61 additions & 4 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,78 @@
{
"$schema": "https://biomejs.dev/schemas/1.7.1/schema.json",
"organizeImports": {
"enabled": true
"$schema": "https://biomejs.dev/schemas/1.9.2/schema.json",
"files": {
"include": ["./**/*.ts", "./**/*.json"],
"ignore": ["node_modules/", "bun.lockb"]
},
"formatter": {
"enabled": true,
"attributePosition": "multiline",
"indentStyle": "space",
"indentWidth": 2
"indentWidth": 2,
"lineEnding": "lf",
"lineWidth": 90
},
"javascript": {
"formatter": {
"enabled": true,
"arrowParentheses": "always",
"attributePosition": "multiline",
"bracketSameLine": true,
"bracketSpacing": true,
"jsxQuoteStyle": "double",
"quoteStyle": "single",
"semicolons": "always",
"trailingCommas": "all"
}
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,

"a11y": { "all": true },
"complexity": { "all": true },
"correctness": {
"noUnusedImports": "warn",
"noUnusedVariables": "warn"
},
"nursery": {
"all": true,
"useSortedClasses": "warn"
},
"performance": {
"all": true,

"noBarrelFile": "off"
},
"security": { "all": true },
"style": {
"all": true,
"noDefaultExport": "off",
"useBlockStatements": "off",
"noNonNullAssertion": "off",
"useConsistentArrayType": {
"level": "warn",
"options": {
"syntax": "generic"
}
},
"useFilenamingConvention": "off",
"useNamingConvention": "off",
"useShorthandArrayType": "off"
},
"suspicious": {
"all": true,
"noConsoleLog": "off"
}
}
},
"organizeImports": {
"enabled": true
},
"vcs": {
"clientKind": "git",
"defaultBranch": "main",
"enabled": true
}
}
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"ronin": "4.3.1"
},
"devDependencies": {
"@biomejs/biome": "1.8.3",
"@biomejs/biome": "1.9.2",
"@types/bun": "1.1.8",
"bunchee": "5.4.0",
"hono": "4.5.11",
Expand Down
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createMiddleware } from "hono/factory";
import createFactory from "ronin";
import { createMiddleware } from 'hono/factory';
import createFactory from 'ronin';

type Factory = ReturnType<typeof createFactory>;

Expand Down Expand Up @@ -46,12 +46,12 @@ type QueryHandlerOptions = Parameters<typeof createFactory>[0];
export const ronin = (options: QueryHandlerOptions = {}) =>
createMiddleware<Env>(async (c, next) => {
if (!c.env.RONIN_TOKEN)
throw new Error("Missing `RONIN_TOKEN` in environment variables");
throw new Error('Missing `RONIN_TOKEN` in environment variables');

const userOptions = typeof options === "function" ? options() : options;
const userOptions = typeof options === 'function' ? options() : options;
if (userOptions.token) {
console.warn(
"The `token` option is ignored in favor of `c.env.RONIN_TOKEN` when using the `ronin` middleware.",
'The `token` option is ignored in favor of `c.env.RONIN_TOKEN` when using the `ronin` middleware.',
);

// biome-ignore lint/performance/noDelete: We're only deleting the property if it exists
Expand All @@ -63,7 +63,7 @@ export const ronin = (options: QueryHandlerOptions = {}) =>
...userOptions,
});

c.set("ronin", client);
c.set('ronin', client);

await next();
});
6 changes: 3 additions & 3 deletions tests/env.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RONIN } from "ronin";
import type { RONIN } from 'ronin';

interface ImportMetaEnv {
RONIN_TOKEN: string;
Expand All @@ -8,9 +8,9 @@ interface ImportMeta {
readonly env: ImportMetaEnv;
}

declare module "ronin" {
declare module 'ronin' {
interface UsersGetter
extends RONIN.IGetterPlural<unknown, Array<unknown>, "users", never> {}
extends RONIN.IGetterPlural<unknown, Array<unknown>, 'users', never> {}

export namespace RONIN {
export interface Getter {
Expand Down
44 changes: 22 additions & 22 deletions tests/integration/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { describe, expect, it } from "bun:test";
import { AsyncLocalStorage } from "node:async_hooks";
import { createFactory } from "hono/factory";
import { testClient } from "hono/testing";
import { describe, expect, it } from 'bun:test';
import { AsyncLocalStorage } from 'node:async_hooks';
import { createFactory } from 'hono/factory';
import { testClient } from 'hono/testing';

import { ronin } from "@/index";
import { ronin } from '@/index';

import type { Bindings, Variables } from "@/index";
import type { Bindings, Variables } from '@/index';

describe("use `ronin` middleware", () => {
describe('use `ronin` middleware', () => {
const factory = createFactory<{ Bindings: Bindings; Variables: Variables }>();

it("with a missing `RONIN_TOKEN`", async () => {
it('with a missing `RONIN_TOKEN`', async () => {
const app = factory
.createApp()
.use("*", ronin())
.get("/", async (c) => {
.use('*', ronin())
.get('/', async (c) => {
expect(c.var.ronin).toBeDefined();

const posts = (await c.var.ronin.get.blogPosts()) as Array<unknown>;
Expand All @@ -30,11 +30,11 @@ describe("use `ronin` middleware", () => {
expect(response.status).toBe(500);
});

it("with default options", async () => {
it('with default options', async () => {
const app = factory
.createApp()
.use("*", ronin())
.get("/", async (c) => {
.use('*', ronin())
.get('/', async (c) => {
expect(c.var.ronin).toBeDefined();

const users = await c.var.ronin.get.users();
Expand All @@ -59,11 +59,11 @@ describe("use `ronin` middleware", () => {
expect(json).toHaveLength(0);
});

it("with a custom options (object)", async () => {
it('with a custom options (object)', async () => {
const app = factory
.createApp()
.use(
"*",
'*',
ronin({
hooks: {
user: {
Expand All @@ -76,7 +76,7 @@ describe("use `ronin` middleware", () => {
asyncContext: new AsyncLocalStorage(),
}),
)
.get("/", async (c) => {
.get('/', async (c) => {
expect(c.var.ronin).toBeDefined();

const users = await c.var.ronin.get.users();
Expand All @@ -101,11 +101,11 @@ describe("use `ronin` middleware", () => {
expect(json).toHaveLength(1);
});

it("with a custom options (function)", async () => {
it('with a custom options (function)', async () => {
const app = factory
.createApp()
.use(
"*",
'*',
ronin(() => ({
hooks: {
user: {
Expand All @@ -118,7 +118,7 @@ describe("use `ronin` middleware", () => {
asyncContext: new AsyncLocalStorage(),
})),
)
.get("/", async (c) => {
.get('/', async (c) => {
expect(c.var.ronin).toBeDefined();

const users = await c.var.ronin.get.users();
Expand All @@ -143,11 +143,11 @@ describe("use `ronin` middleware", () => {
expect(json).toHaveLength(1);
});

it("with a ignored `token` property", async () => {
it('with a ignored `token` property', async () => {
const app = factory
.createApp()
.use("*", ronin({ token: crypto.randomUUID() }))
.get("/", async (c) => {
.use('*', ronin({ token: crypto.randomUUID() }))
.get('/', async (c) => {
expect(c.var.ronin).toBeDefined();

const users = await c.var.ronin.get.users();
Expand Down
10 changes: 5 additions & 5 deletions tests/preload.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { afterAll, afterEach, beforeAll } from "bun:test";
import { setupServer } from "msw/node";
import { http, HttpResponse } from "msw";
import { afterAll, afterEach, beforeAll } from 'bun:test';
import { http, HttpResponse } from 'msw';
import { setupServer } from 'msw/node';

import.meta.env.RONIN_TOKEN = "secret-token";
import.meta.env.RONIN_TOKEN = 'secret-token';

const mockHttpServer = setupServer(
http.post("https://data.ronin.co/", async ({ request }) => {
http.post('https://data.ronin.co/', async ({ request }) => {
const queries = (await request.json()) as {
queries: Array<{
get: {
Expand Down
Loading