Skip to content

Commit 52eaeed

Browse files
committed
chore: hanle .json with require instead
1 parent a2a1387 commit 52eaeed

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "simple-git-hooks",
3+
"type": "commonjs",
34
"version": "2.11.1",
45
"description": "A simple, zero dependency tool for setting up git hooks for small projects",
56
"author": "Mikhail Gorbunov <toplenboren@gmail.com>",

simple-git-hooks.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,11 @@ async function _getConfigFromFile(projectRootPath, fileName) {
351351
if (filePath === __filename) {
352352
return undefined
353353
}
354-
const result = await import(url.pathToFileURL(filePath)) // handle `.cjs`, `.js`, `.mjs` and `.json`
354+
// handle `.json` with `require`, `import()` requires `with:{type:'json'}` which does not work for all engines
355+
if (filePath.endsWith('.json')) {
356+
return require(filePath)
357+
}
358+
const result = await import(url.pathToFileURL(filePath)) // handle `.cjs`, `.js`, `.mjs`
355359
return result.default || result
356360
} catch (err) {
357361
return undefined

0 commit comments

Comments
 (0)