Skip to content

Instantly share code, notes, and snippets.

@Raynos
Created April 22, 2020 16:20
Show Gist options
  • Save Raynos/6f83a548374ba9a243f3b0b82a5102ed to your computer and use it in GitHub Desktop.
Save Raynos/6f83a548374ba9a243f3b0b82a5102ed to your computer and use it in GitHub Desktop.
1 import fs, { readFileSync } from 'fs';
2 import { syncBuiltinESMExports, createRequire } from 'module';
3
4 const require = createRequire(import.meta.url)
5 const { readFileSync: readFileSync2 } = require('fs')
6
7 var ref = readFileSync
8
9 console.log('import', readFileSync)
10 console.log('var ok ?', ref)
11 console.log('const destruct ?', readFileSync2)
12
13 fs.readFileSync = () => { console.log('lol') }
14 syncBuiltinESMExports()
15
16 console.log(fs.readFileSync === readFileSync)
17 console.log('import mutated ?', readFileSync)
18 console.log('var mutated ?', ref)
19 console.log('const destruct mutated ?', readFileSync2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment