Skip to content

Commit

Permalink
patch: 🩹 (@elysiajs/cors, @elysiajs/server-timing) Add patches th…
Browse files Browse the repository at this point in the history
…at resolve TS errors. (#118)

- So that `next build` does not fail
  • Loading branch information
ReoHakase committed Mar 30, 2024
1 parent 2c01637 commit 8aae34e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
33 changes: 33 additions & 0 deletions patches/@elysiajs+cors+1.0.2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
diff --git a/node_modules/@elysiajs/cors/src/index.ts b/node_modules/@elysiajs/cors/src/index.ts
index e3ef50e..8cbd008 100644
--- a/node_modules/@elysiajs/cors/src/index.ts
+++ b/node_modules/@elysiajs/cors/src/index.ts
@@ -257,18 +257,20 @@ export const cors = (
}

const handleMethod = (set: Context['set'], method: string) => {
- if (methods === true)
- return (set.headers['Access-Control-Allow-Methods'] = method ?? '*')
+ if (methods === true)
+ return (set.headers['Access-Control-Allow-Methods'] = method ?? '*')

- if (methods === false || !methods?.length) return
+ if (methods === false || !methods?.length) return

- if (methods === '*')
- return (set.headers['Access-Control-Allow-Methods'] = '*')
+ if (methods === '*')
+ return (set.headers['Access-Control-Allow-Methods'] = '*')

- if (!Array.isArray(methods))
- return (set.headers['Access-Control-Allow-Methods'] = methods)
+ if (!Array.isArray(methods))
+ return (set.headers['Access-Control-Allow-Methods'] = methods)

- set.headers['Access-Control-Allow-Methods'] = methods.join(', ')
+ set.headers['Access-Control-Allow-Methods'] = methods.join(', ')
+
+ return // Added to prevent "Type error: Not all code paths return a value."
}

if (preflight)
12 changes: 12 additions & 0 deletions patches/@elysiajs+server-timing+1.0.2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/node_modules/@elysiajs/server-timing/src/index.ts b/node_modules/@elysiajs/server-timing/src/index.ts
index 12bca07..fbf86c2 100644
--- a/node_modules/@elysiajs/server-timing/src/index.ts
+++ b/node_modules/@elysiajs/server-timing/src/index.ts
@@ -109,6 +109,7 @@ export const serverTiming = (options: ServerTimingOptions = {}) => {
parse: traceParse = true,
transform: traceTransform = true,
beforeHandle: traceBeforeHandle = true,
+ // @ts-expect-error Added to prevent `next build` to fail with "traceHandler is defined but never used."
handle: traceHandle = true,
afterHandle: traceAfterHandle = true,
total: traceTotal = true

0 comments on commit 8aae34e

Please sign in to comment.