Skip to content

Commit

Permalink
fix: check property existence before patching (#52)
Browse files Browse the repository at this point in the history
Co-authored-by: JounQin <admin@1stg.me>
  • Loading branch information
jlarmstrongiv and JounQin committed Aug 1, 2022
1 parent 5ead2a9 commit 487fee4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/dirty-jobs-live.md
@@ -0,0 +1,5 @@
---
"sh-syntax": patch
---

fix: check property existence before patching
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -71,7 +71,7 @@
"lint": "run-p lint:*",
"lint:es": "eslint . --cache -f friendly --max-warnings 10",
"lint:tsc": "tsc --noEmit",
"prepare": "simple-git-hooks",
"prepare": "simple-git-hooks || exit 0",
"prerelease": "pnpm build",
"release": "changeset publish",
"test": "vitest run --coverage",
Expand Down
20 changes: 15 additions & 5 deletions src/shim.ts
@@ -1,11 +1,21 @@
/* eslint-disable @typescript-eslint/no-unnecessary-condition */

import { randomFillSync } from 'node:crypto'
import _fs from 'node:fs'
import { performance } from 'node:perf_hooks'

globalThis.fs = _fs
globalThis.crypto = {
if (!globalThis.fs) {
globalThis.fs = _fs
}

if (!globalThis.crypto) {
globalThis.crypto = {
// @ts-expect-error
getRandomValues: randomFillSync,
}
}

if (!globalThis.performance) {
// @ts-expect-error
getRandomValues: randomFillSync,
globalThis.performance = performance
}
// @ts-expect-error
globalThis.performance = performance

0 comments on commit 487fee4

Please sign in to comment.