@abelspithost/commitlint 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/LICENSE +14 -14
  2. package/bin/cli.spec.ts +199 -199
  3. package/package.json +69 -69
package/LICENSE CHANGED
@@ -1,15 +1,15 @@
1
- ISC License
2
-
3
- Copyright (c) 2026 Abel Spithost
4
-
5
- Permission to use, copy, modify, and/or distribute this software for any
6
- purpose with or without fee is hereby granted, provided that the above
7
- copyright notice and this permission notice appear in all copies.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1
+ ISC License
2
+
3
+ Copyright (c) 2026 Abel Spithost
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
15
  PERFORMANCE OF THIS SOFTWARE.
package/bin/cli.spec.ts CHANGED
@@ -1,199 +1,199 @@
1
- import type { MockInstance } from 'vitest';
2
-
3
-
4
- const mockExecSync = vi.fn();
5
- const mockExistsSync = vi.fn<(path: string) => boolean>();
6
- const mockUnlinkSync = vi.fn();
7
- const mockWriteFileSync = vi.fn();
8
-
9
- vi.mock('node:child_process', () => ({
10
- execSync: mockExecSync,
11
- }));
12
-
13
- vi.mock('node:fs', () => ({
14
- existsSync: mockExistsSync,
15
- unlinkSync: mockUnlinkSync,
16
- writeFileSync: mockWriteFileSync,
17
- }));
18
-
19
- async function runCli(): Promise<void> {
20
- vi.resetModules();
21
- // @ts-expect-error: CLI function in JavaScript
22
- await import('./cli.mjs');
23
- }
24
-
25
- describe('cli.mjs', () => {
26
- let exitSpy: MockInstance;
27
-
28
- beforeEach(() => {
29
- mockExecSync.mockReturnValue(Buffer.from(''));
30
- mockExistsSync.mockReturnValue(false);
31
- exitSpy = vi.spyOn(process, 'exit').mockImplementation(() => undefined as never);
32
- vi.spyOn(console, 'log').mockReturnValue(undefined);
33
- vi.spyOn(console, 'error').mockReturnValue(undefined);
34
- });
35
-
36
- afterEach(() => {
37
- vi.restoreAllMocks();
38
- });
39
-
40
- describe('install command', () => {
41
- it('runs npm install --save-dev for npm', async () => {
42
- await runCli();
43
-
44
- expect(mockExecSync).toHaveBeenCalledWith(
45
- expect.stringContaining('npm install --save-dev'),
46
- expect.anything(),
47
- );
48
- });
49
-
50
- it('runs pnpm add -D for pnpm', async () => {
51
- mockExistsSync.mockImplementation((path: string) => path === 'pnpm-lock.yaml');
52
-
53
- await runCli();
54
-
55
- expect(mockExecSync).toHaveBeenCalledWith(
56
- expect.stringContaining('pnpm add -D'),
57
- expect.anything(),
58
- );
59
- });
60
-
61
- it('runs yarn add -D for yarn', async () => {
62
- mockExistsSync.mockImplementation((path: string) => path === 'yarn.lock');
63
-
64
- await runCli();
65
-
66
- expect(mockExecSync).toHaveBeenCalledWith(
67
- expect.stringContaining('yarn add -D'),
68
- expect.anything(),
69
- );
70
- });
71
-
72
- it('runs bun add -D for bun', async () => {
73
- mockExistsSync.mockImplementation((path: string) => path === 'bun.lockb');
74
-
75
- await runCli();
76
-
77
- expect(mockExecSync).toHaveBeenCalledWith(
78
- expect.stringContaining('bun add -D'),
79
- expect.anything(),
80
- );
81
- });
82
- });
83
-
84
- describe('husky initialization', () => {
85
- it('runs npx husky init for npm', async () => {
86
- await runCli();
87
-
88
- expect(mockExecSync).toHaveBeenCalledWith(
89
- 'npx husky init',
90
- expect.anything(),
91
- );
92
- });
93
-
94
- it('runs pnpm dlx husky init for pnpm', async () => {
95
- mockExistsSync.mockImplementation((path: string) => path === 'pnpm-lock.yaml');
96
-
97
- await runCli();
98
-
99
- expect(mockExecSync).toHaveBeenCalledWith(
100
- 'pnpm exec husky init',
101
- expect.anything(),
102
- );
103
- });
104
- });
105
-
106
- describe('pre-commit hook removal', () => {
107
- it('removes the default pre-commit hook when it exists', async () => {
108
- mockExistsSync.mockImplementation((path: string) => path === '.husky/pre-commit');
109
-
110
- await runCli();
111
-
112
- expect(mockUnlinkSync).toHaveBeenCalledWith('.husky/pre-commit');
113
- });
114
-
115
- it('skips removal when pre-commit hook does not exist', async () => {
116
- await runCli();
117
-
118
- expect(mockUnlinkSync).not.toHaveBeenCalled();
119
- });
120
- });
121
-
122
- describe('commit-msg hook', () => {
123
- it('writes hook with npx runner for npm', async () => {
124
- await runCli();
125
-
126
- expect(mockWriteFileSync).toHaveBeenCalledWith(
127
- '.husky/commit-msg',
128
- 'npx --no -- commitlint --edit $1\n',
129
- );
130
- });
131
-
132
- it('writes hook with pnpm exec runner for pnpm', async () => {
133
- mockExistsSync.mockImplementation((path: string) => path === 'pnpm-lock.yaml');
134
-
135
- await runCli();
136
-
137
- expect(mockWriteFileSync).toHaveBeenCalledWith(
138
- '.husky/commit-msg',
139
- 'pnpm exec commitlint --edit $1\n',
140
- );
141
- });
142
-
143
- it('writes hook with yarn run runner for yarn', async () => {
144
- mockExistsSync.mockImplementation((path: string) => path === 'yarn.lock');
145
-
146
- await runCli();
147
-
148
- expect(mockWriteFileSync).toHaveBeenCalledWith(
149
- '.husky/commit-msg',
150
- 'yarn run commitlint --edit $1\n',
151
- );
152
- });
153
-
154
- it('writes hook with bunx runner for bun', async () => {
155
- mockExistsSync.mockImplementation((path: string) => path === 'bun.lockb');
156
-
157
- await runCli();
158
-
159
- expect(mockWriteFileSync).toHaveBeenCalledWith(
160
- '.husky/commit-msg',
161
- 'bunx --bun commitlint --edit $1\n',
162
- );
163
- });
164
- });
165
-
166
- describe('commitlint config', () => {
167
- it('creates commitlint.config.ts with the expected export', async () => {
168
- await runCli();
169
-
170
- expect(mockWriteFileSync).toHaveBeenCalledWith(
171
- 'commitlint.config.ts',
172
- "export { default } from '@abelspithost/commitlint';\n",
173
- );
174
- });
175
-
176
- it('skips commitlint.config.ts if it already exists', async () => {
177
- mockExistsSync.mockImplementation((path: string) => path === 'commitlint.config.ts');
178
-
179
- await runCli();
180
-
181
- expect(mockWriteFileSync).not.toHaveBeenCalledWith(
182
- 'commitlint.config.ts',
183
- expect.anything(),
184
- );
185
- });
186
- });
187
-
188
- describe('error handling', () => {
189
- it('calls process.exit(1) when a step fails', async () => {
190
- mockExecSync.mockImplementation(() => {
191
- throw new Error('command failed');
192
- });
193
-
194
- await runCli();
195
-
196
- expect(exitSpy).toHaveBeenCalledWith(1);
197
- });
198
- });
199
- });
1
+ import type { MockInstance } from 'vitest';
2
+
3
+
4
+ const mockExecSync = vi.fn();
5
+ const mockExistsSync = vi.fn<(path: string) => boolean>();
6
+ const mockUnlinkSync = vi.fn();
7
+ const mockWriteFileSync = vi.fn();
8
+
9
+ vi.mock('node:child_process', () => ({
10
+ execSync: mockExecSync,
11
+ }));
12
+
13
+ vi.mock('node:fs', () => ({
14
+ existsSync: mockExistsSync,
15
+ unlinkSync: mockUnlinkSync,
16
+ writeFileSync: mockWriteFileSync,
17
+ }));
18
+
19
+ async function runCli(): Promise<void> {
20
+ vi.resetModules();
21
+ // @ts-expect-error: CLI function in JavaScript
22
+ await import('./cli.mjs');
23
+ }
24
+
25
+ describe('cli.mjs', () => {
26
+ let exitSpy: MockInstance;
27
+
28
+ beforeEach(() => {
29
+ mockExecSync.mockReturnValue(Buffer.from(''));
30
+ mockExistsSync.mockReturnValue(false);
31
+ exitSpy = vi.spyOn(process, 'exit').mockImplementation(() => undefined as never);
32
+ vi.spyOn(console, 'log').mockReturnValue(undefined);
33
+ vi.spyOn(console, 'error').mockReturnValue(undefined);
34
+ });
35
+
36
+ afterEach(() => {
37
+ vi.restoreAllMocks();
38
+ });
39
+
40
+ describe('install command', () => {
41
+ it('runs npm install --save-dev for npm', async () => {
42
+ await runCli();
43
+
44
+ expect(mockExecSync).toHaveBeenCalledWith(
45
+ expect.stringContaining('npm install --save-dev'),
46
+ expect.anything(),
47
+ );
48
+ });
49
+
50
+ it('runs pnpm add -D for pnpm', async () => {
51
+ mockExistsSync.mockImplementation((path: string) => path === 'pnpm-lock.yaml');
52
+
53
+ await runCli();
54
+
55
+ expect(mockExecSync).toHaveBeenCalledWith(
56
+ expect.stringContaining('pnpm add -D'),
57
+ expect.anything(),
58
+ );
59
+ });
60
+
61
+ it('runs yarn add -D for yarn', async () => {
62
+ mockExistsSync.mockImplementation((path: string) => path === 'yarn.lock');
63
+
64
+ await runCli();
65
+
66
+ expect(mockExecSync).toHaveBeenCalledWith(
67
+ expect.stringContaining('yarn add -D'),
68
+ expect.anything(),
69
+ );
70
+ });
71
+
72
+ it('runs bun add -D for bun', async () => {
73
+ mockExistsSync.mockImplementation((path: string) => path === 'bun.lockb');
74
+
75
+ await runCli();
76
+
77
+ expect(mockExecSync).toHaveBeenCalledWith(
78
+ expect.stringContaining('bun add -D'),
79
+ expect.anything(),
80
+ );
81
+ });
82
+ });
83
+
84
+ describe('husky initialization', () => {
85
+ it('runs npx husky init for npm', async () => {
86
+ await runCli();
87
+
88
+ expect(mockExecSync).toHaveBeenCalledWith(
89
+ 'npx husky init',
90
+ expect.anything(),
91
+ );
92
+ });
93
+
94
+ it('runs pnpm dlx husky init for pnpm', async () => {
95
+ mockExistsSync.mockImplementation((path: string) => path === 'pnpm-lock.yaml');
96
+
97
+ await runCli();
98
+
99
+ expect(mockExecSync).toHaveBeenCalledWith(
100
+ 'pnpm exec husky init',
101
+ expect.anything(),
102
+ );
103
+ });
104
+ });
105
+
106
+ describe('pre-commit hook removal', () => {
107
+ it('removes the default pre-commit hook when it exists', async () => {
108
+ mockExistsSync.mockImplementation((path: string) => path === '.husky/pre-commit');
109
+
110
+ await runCli();
111
+
112
+ expect(mockUnlinkSync).toHaveBeenCalledWith('.husky/pre-commit');
113
+ });
114
+
115
+ it('skips removal when pre-commit hook does not exist', async () => {
116
+ await runCli();
117
+
118
+ expect(mockUnlinkSync).not.toHaveBeenCalled();
119
+ });
120
+ });
121
+
122
+ describe('commit-msg hook', () => {
123
+ it('writes hook with npx runner for npm', async () => {
124
+ await runCli();
125
+
126
+ expect(mockWriteFileSync).toHaveBeenCalledWith(
127
+ '.husky/commit-msg',
128
+ 'npx --no -- commitlint --edit $1\n',
129
+ );
130
+ });
131
+
132
+ it('writes hook with pnpm exec runner for pnpm', async () => {
133
+ mockExistsSync.mockImplementation((path: string) => path === 'pnpm-lock.yaml');
134
+
135
+ await runCli();
136
+
137
+ expect(mockWriteFileSync).toHaveBeenCalledWith(
138
+ '.husky/commit-msg',
139
+ 'pnpm exec commitlint --edit $1\n',
140
+ );
141
+ });
142
+
143
+ it('writes hook with yarn run runner for yarn', async () => {
144
+ mockExistsSync.mockImplementation((path: string) => path === 'yarn.lock');
145
+
146
+ await runCli();
147
+
148
+ expect(mockWriteFileSync).toHaveBeenCalledWith(
149
+ '.husky/commit-msg',
150
+ 'yarn run commitlint --edit $1\n',
151
+ );
152
+ });
153
+
154
+ it('writes hook with bunx runner for bun', async () => {
155
+ mockExistsSync.mockImplementation((path: string) => path === 'bun.lockb');
156
+
157
+ await runCli();
158
+
159
+ expect(mockWriteFileSync).toHaveBeenCalledWith(
160
+ '.husky/commit-msg',
161
+ 'bunx --bun commitlint --edit $1\n',
162
+ );
163
+ });
164
+ });
165
+
166
+ describe('commitlint config', () => {
167
+ it('creates commitlint.config.ts with the expected export', async () => {
168
+ await runCli();
169
+
170
+ expect(mockWriteFileSync).toHaveBeenCalledWith(
171
+ 'commitlint.config.ts',
172
+ "export { default } from '@abelspithost/commitlint';\n",
173
+ );
174
+ });
175
+
176
+ it('skips commitlint.config.ts if it already exists', async () => {
177
+ mockExistsSync.mockImplementation((path: string) => path === 'commitlint.config.ts');
178
+
179
+ await runCli();
180
+
181
+ expect(mockWriteFileSync).not.toHaveBeenCalledWith(
182
+ 'commitlint.config.ts',
183
+ expect.anything(),
184
+ );
185
+ });
186
+ });
187
+
188
+ describe('error handling', () => {
189
+ it('calls process.exit(1) when a step fails', async () => {
190
+ mockExecSync.mockImplementation(() => {
191
+ throw new Error('command failed');
192
+ });
193
+
194
+ await runCli();
195
+
196
+ expect(exitSpy).toHaveBeenCalledWith(1);
197
+ });
198
+ });
199
+ });
package/package.json CHANGED
@@ -1,69 +1,69 @@
1
- {
2
- "name": "@abelspithost/commitlint",
3
- "version": "0.0.1",
4
- "description": "Shared commitlint preset extending @commitlint/config-conventional with stricter defaults",
5
- "keywords": [
6
- "commitlint",
7
- "commitlint-config",
8
- "conventional",
9
- "commits",
10
- "conventional-commits",
11
- "husky",
12
- "git-hooks"
13
- ],
14
- "homepage": "https://github.com/aspithost/commitlint#readme",
15
- "repository": {
16
- "type": "git",
17
- "url": "https://github.com/aspithost/commitlint.git"
18
- },
19
- "license": "ISC",
20
- "author": {
21
- "name": "Abel Spithost",
22
- "url": "https://github.com/aspithost"
23
- },
24
- "engines": {
25
- "node": ">=20"
26
- },
27
- "type": "module",
28
- "exports": {
29
- ".": {
30
- "types": "./dist/index.d.ts",
31
- "import": "./dist/index.js"
32
- }
33
- },
34
- "bin": {
35
- "init": "./bin/cli.mjs"
36
- },
37
- "files": [
38
- "bin",
39
- "dist"
40
- ],
41
- "scripts": {
42
- "build": "npm run clean && tsc -p tsconfig.build.json",
43
- "clean": "rimraf dist",
44
- "lint": "eslint .",
45
- "test:unit": "vitest",
46
- "test:cov": "vitest run --coverage --coverage.reporter=text",
47
- "typecheck": "tsc --noEmit",
48
- "prepare": "husky"
49
- },
50
- "dependencies": {
51
- "@commitlint/config-conventional": "^20.4.1",
52
- "@commitlint/format": "^20.4.0",
53
- "@commitlint/types": "^20.4.0"
54
- },
55
- "devDependencies": {
56
- "@abelspithost/eslint-config-ts": "^0.1.3",
57
- "@abelspithost/tsconfig-node": "^0.0.4",
58
- "@commitlint/cli": "^20.4.1",
59
- "@types/node": "^24.10.11",
60
- "@vitest/coverage-v8": "^4.0.18",
61
- "commitlint": "^20.4.1",
62
- "eslint": "^9.39.2",
63
- "husky": "^9.1.7",
64
- "jiti": "^2.6.1",
65
- "rimraf": "^6.1.2",
66
- "typescript": "^5.9.3",
67
- "vitest": "^4.0.18"
68
- }
69
- }
1
+ {
2
+ "name": "@abelspithost/commitlint",
3
+ "version": "0.0.2",
4
+ "description": "Shared commitlint preset extending @commitlint/config-conventional with stricter defaults",
5
+ "keywords": [
6
+ "commitlint",
7
+ "commitlint-config",
8
+ "conventional",
9
+ "commits",
10
+ "conventional-commits",
11
+ "husky",
12
+ "git-hooks"
13
+ ],
14
+ "homepage": "https://github.com/aspithost/commitlint#readme",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/aspithost/commitlint.git"
18
+ },
19
+ "license": "ISC",
20
+ "author": {
21
+ "name": "Abel Spithost",
22
+ "url": "https://github.com/aspithost"
23
+ },
24
+ "engines": {
25
+ "node": ">=20"
26
+ },
27
+ "type": "module",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "import": "./dist/index.js"
32
+ }
33
+ },
34
+ "bin": {
35
+ "init": "./bin/cli.mjs"
36
+ },
37
+ "files": [
38
+ "bin",
39
+ "dist"
40
+ ],
41
+ "scripts": {
42
+ "build": "npm run clean && tsc -p tsconfig.build.json",
43
+ "clean": "rimraf dist",
44
+ "lint": "eslint .",
45
+ "test:unit": "vitest",
46
+ "test:cov": "vitest run --coverage --coverage.reporter=text",
47
+ "typecheck": "tsc --noEmit",
48
+ "prepare": "husky || true"
49
+ },
50
+ "dependencies": {
51
+ "@commitlint/config-conventional": "^20.4.1",
52
+ "@commitlint/format": "^20.4.0",
53
+ "@commitlint/types": "^20.4.0"
54
+ },
55
+ "devDependencies": {
56
+ "@abelspithost/eslint-config-ts": "^0.1.3",
57
+ "@abelspithost/tsconfig-node": "^0.0.4",
58
+ "@commitlint/cli": "^20.4.1",
59
+ "@types/node": "^24.10.11",
60
+ "@vitest/coverage-v8": "^4.0.18",
61
+ "commitlint": "^20.4.1",
62
+ "eslint": "^9.39.2",
63
+ "husky": "^9.1.7",
64
+ "jiti": "^2.6.1",
65
+ "rimraf": "^6.1.2",
66
+ "typescript": "^5.9.3",
67
+ "vitest": "^4.0.18"
68
+ }
69
+ }