Skip to content

Commit be4ec56

Browse files
authored
fix: require is not defined error (#47)
The `require()` function is not defined in ES module scope. Loading a JSON file via `import` is behind `--experimental-json-modules` on LTS versions of Node.js, so use `createRequire()` instead. Refs: #43
1 parent 6d78f4a commit be4ec56

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

branch-diff.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env node
22

33
import fs from 'fs'
4+
import { createRequire } from 'module'
45
import path from 'path'
56
import process from 'process'
67
import { pipeline as _pipeline } from 'stream'
@@ -15,6 +16,7 @@ import gitexec from 'gitexec'
1516

1617
const pipeline = promisify(_pipeline)
1718
const pkgFile = path.join(process.cwd(), 'package.json')
19+
const require = createRequire(import.meta.url)
1820
const pkgData = fs.existsSync(pkgFile) ? require(pkgFile) : {}
1921
const pkgId = pkgtoId(pkgData)
2022
const refcmd = 'git rev-list --max-count=1 {{ref}}'

0 commit comments

Comments
 (0)