-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfs.ts
More file actions
22 lines (19 loc) · 749 Bytes
/
fs.ts
File metadata and controls
22 lines (19 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/**
* @fileoverview Lazy-loader for `node:fs`.
*
* Bundlers (Webpack/Rollup/esbuild) targeting browsers can't statically
* resolve `require('node:fs')` — but they CAN drop the call entirely
* if it's wrapped in a `/*@__NO_SIDE_EFFECTS__*\/`-marked function and
* never called. So we always go through `getFs()` instead of importing
* top-level.
*
* Cache slot is module-local: first call resolves the require, every
* subsequent call returns the cached reference.
*/
// eslint-disable-next-line n/prefer-node-protocol
import type * as NodeFs from 'node:fs'
let _fs: typeof NodeFs | undefined
/*@__NO_SIDE_EFFECTS__*/
export function getNodeFs(): typeof NodeFs {
return (_fs ??= /*@__PURE__*/ require('node:fs') as typeof NodeFs)
}