Skip to content

Commit 9286b74

Browse files
committed
mock: just make the service key a global
This gets confused when plugins put the tap install in .tap/plugins/..., because we end up with different loaders that could be getting pulled in. Better to just go ahead and make it a global, since that's the intention anyway.
1 parent 6f774b1 commit 9286b74

3 files changed

Lines changed: 9 additions & 15 deletions

File tree

src/mock/.tshy/esm.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
],
99
"exclude": [
1010
"../src/package.json",
11-
"../src/hooks-url-cjs.cts",
12-
"../src/service-key-cjs.cts"
11+
"../src/hooks-url-cjs.cts"
1312
],
1413
"compilerOptions": {
1514
"outDir": "../.tshy-build/esm"

src/mock/src/service-key-cjs.cts

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/mock/src/service-key.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
import { createRequire } from "node:module"
2-
//@ts-ignore
3-
const require = createRequire(import.meta.url)
4-
const serviceKeyCJS = require('../commonjs/service-key.js')
5-
export const { serviceKey } = serviceKeyCJS as { serviceKey: string }
1+
import { randomBytes } from 'crypto'
2+
3+
const kServiceKey = Symbol.for('@tapjs/mock.ServiceKey')
4+
const g = globalThis as typeof globalThis & {
5+
[kServiceKey]: string
6+
}
7+
export const serviceKey = (g[kServiceKey] =
8+
g[kServiceKey] ?? randomBytes(8).toString('hex'))

0 commit comments

Comments
 (0)