File size: 688 Bytes
d3cbe09
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Monkey-patch require/import to no-op the `server-only` package, which
// throws when imported outside a Next.js Server Component context. This lets
// the audit script + adapter tests import lib/hf-data.ts and lib/model-data.ts
// directly. Same trick as tests/server-only-stub.ts but at the require/import
// resolution level instead of via vitest's alias config.

import { createRequire } from "node:module"
import Module from "node:module"

const require = createRequire(import.meta.url)
const original = Module.prototype.require
Module.prototype.require = function patchedRequire(specifier) {
  if (specifier === "server-only") return {}
  return original.apply(this, arguments)
}