Skip to content

Commit fc2acfc

Browse files
authored
feat: support esm format configs (#120)
1 parent 72edba9 commit fc2acfc

File tree

29 files changed

+171
-77
lines changed

29 files changed

+171
-77
lines changed

.changeset/selfish-owls-collect.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"simple-git-hooks": minor
3+
---
4+
5+
feat: support esm format configs

.eslintrc.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,13 @@ module.exports = {
88
"extends": "eslint:recommended",
99
"parserOptions": {
1010
"ecmaVersion": 12
11-
}
11+
},
12+
"overrides": [
13+
{
14+
"files": ["*.mjs"],
15+
"parserOptions": {
16+
"sourceType": "module"
17+
}
18+
}
19+
]
1220
};

.github/workflows/codeql-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939

4040
steps:
4141
- name: Checkout repository
42-
uses: actions/checkout@v3
42+
uses: actions/checkout@v4
4343

4444
# Initializes the CodeQL tools for scanning.
4545
- name: Initialize CodeQL

.github/workflows/lint.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
- name: Lint
1717
uses: actions/setup-node@v4
1818
with:
19-
node-version: 14.x
20-
- run: yarn --frozen-lockfile
19+
node-version: 18.x
20+
cache: yarn
21+
- run: yarn --frozen-lockfile --ignore-engines
2122
- run: yarn lint

.github/workflows/tests.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
- name: Lint
1717
uses: actions/setup-node@v4
1818
with:
19-
node-version: 14.x
20-
- run: yarn --frozen-lockfile
19+
node-version: 18.x
20+
cache: yarn
21+
- run: yarn --frozen-lockfile --ignore-engines
2122
- run: yarn test

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,13 @@ Note that you should manually run `npx simple-git-hooks` **every time you change
120120

121121
### Additional configuration options
122122

123-
You can also add a `.simple-git-hooks.cjs`, `.simple-git-hooks.js`, `simple-git-hooks.cjs`, `simple-git-hooks.js`, `.simple-git-hooks.json` or `simple-git-hooks.json` file to the project and write the configuration inside it.
123+
You can also add a `.simple-git-hooks.cjs`, `.simple-git-hooks.js`, `.simple-git-hooks.mjs`, `simple-git-hooks.cjs`, `simple-git-hooks.js`, `simple-git-hooks.mjs`, `.simple-git-hooks.json` or `simple-git-hooks.json` file to the project and write the configuration inside it.
124124

125125
This way `simple-git-hooks` configuration in `package.json` will not take effect any more.
126126

127-
`.simple-git-hooks.cjs`, `.simple-git-hooks.js` or `simple-git-hooks.cjs`, `simple-git-hooks.js` should look like the following.
127+
`.simple-git-hooks.cjs`, `.simple-git-hooks.js`, `.simple-git-hooks.mjs` or `simple-git-hooks.cjs`, `simple-git-hooks.js`, `simple-git-hooks.mjs` should look like the following.
128+
129+
#### CommonJS
128130

129131
```js
130132
module.exports = {
@@ -133,6 +135,16 @@ module.exports = {
133135
};
134136
```
135137

138+
139+
#### ES Modules
140+
141+
```js
142+
export default {
143+
"pre-commit": "npx lint-staged",
144+
"pre-push": "npm run format",
145+
};
146+
```
147+
136148
`.simple-git-hooks.json` or `simple-git-hooks.json` should look like the following.
137149

138150
```json

_tests/project_with_configuration_in_alternative_separate_cjs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "simple-git-hooks-test-package",
2+
"name": "simple-git-hooks-test-package-alternative-cjs",
33
"version": "1.0.0",
44
"devDependencies": {
55
"simple-git-hooks": "1.0.0"

_tests/project_with_configuration_in_alternative_separate_js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "simple-git-hooks-test-package",
2+
"name": "simple-git-hooks-test-package-alternative-js",
33
"version": "1.0.0",
44
"devDependencies": {
55
"simple-git-hooks": "1.0.0"

_tests/project_with_configuration_in_alternative_separate_json/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "simple-git-hooks-test-package",
2+
"name": "simple-git-hooks-test-package-alternative-json",
33
"version": "1.0.0",
44
"devDependencies": {
55
"simple-git-hooks": "1.0.0"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default {
2+
"pre-push": "exit 1",
3+
"pre-commit": "exit 1"
4+
}

0 commit comments

Comments
 (0)