File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -233,6 +233,7 @@ const COMMON_CONFIG: esbuild.BuildOptions = {
233233 svelte : 'svelte' ,
234234 module : './.scripts/fakeModule.js' ,
235235 'node:module' : './.scripts/fakeModule.js' ,
236+ 'node:fs' : './src/constants.ts' ,
236237 } ,
237238 format : 'iife' ,
238239 define : DEFINES ,
Original file line number Diff line number Diff line change 11import PACKAGEJSON from '../package.json'
2- import { localize as translate } from './util/lang'
2+ import { localize } from './util/lang'
33export const PACKAGE : typeof PACKAGEJSON = PACKAGEJSON
44
55let cachedFsModule : ScopedFS | null = null
66export function getFsModule ( ) {
7+ debugger
78 cachedFsModule ??= requireNativeModule ( 'fs' , {
8- message : translate ( 'require.fs' ) ,
9+ message : localize ( 'require.fs' ) ,
910 optional : false ,
1011 } ) !
1112 return cachedFsModule
1213}
14+
15+ // Super lazy-loading of properties, so that we don't load the fs or fs.promises module until it's actually used by a dependency.
16+ export default new Proxy (
17+ { } ,
18+ {
19+ get ( target , prop ) {
20+ if ( prop === 'promises' ) {
21+ return new Proxy (
22+ { } ,
23+ {
24+ get ( target , prop ) {
25+ return ( ...args : any [ ] ) => {
26+ // @ts -expect-error
27+ return getFsModule ( ) . promises [ prop as keyof ScopedFS [ 'promises' ] ] (
28+ ...args
29+ )
30+ }
31+ } ,
32+ }
33+ )
34+ }
35+
36+ return ( ...args : any [ ] ) => {
37+ // @ts -expect-error
38+ return getFsModule ( ) [ prop as keyof ScopedFS ] ( ...args )
39+ }
40+ } ,
41+ }
42+ )
You can’t perform that action at this time.
0 commit comments