Skip to content

Commit 9c67c3b

Browse files
committed
fix(prompt-cli): reuse inquirer instance from cli
1 parent 0e28abc commit 9c67c3b

File tree

6 files changed

+15
-14
lines changed

6 files changed

+15
-14
lines changed

@commitlint/prompt-cli/cli.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#!/usr/bin/env node
22
const execa = require('execa');
3+
const inquirer = require('inquirer');
34
const {prompter} = require('@commitlint/prompt');
45

5-
const _ = undefined;
6-
const prompt = () => prompter(_, commit);
7-
86
main().catch((err) => {
97
setTimeout(() => {
108
throw err;
@@ -21,7 +19,7 @@ function main() {
2119
process.exit(1);
2220
}
2321
})
24-
.then(() => prompt());
22+
.then(() => prompter(inquirer, commit));
2523
}
2624

2725
function isStageEmpty() {

@commitlint/prompt-cli/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
},
3737
"dependencies": {
3838
"@commitlint/prompt": "^11.0.0",
39+
"inquirer": "^6.5.2",
3940
"execa": "^5.0.0"
4041
},
4142
"gitHead": "cb565dfcca3128380b9b3dc274aedbcae34ce5ca"

@commitlint/prompt/fixtures/cli.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
const inquirer = require("inquirer");
12
const {prompter} = require("../lib");
23

3-
process.stdin.isTTY = false;
4-
process.stdout.isTTY = false;
5-
prompter(null, (answers) => {
4+
prompter(inquirer, (answers) => {
65
console.log('!$#$!')
76
console.log(answers)
87
console.log('!$#$!')

@commitlint/prompt/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@
4040
"@types/inquirer": "^6.5.0",
4141
"@types/concat-stream": "^1.6.0",
4242
"commitizen": "4.2.2",
43-
"concat-stream": "^2.0.0"
43+
"concat-stream": "^2.0.0",
44+
"inquirer": "^6.5.2"
4445
},
4546
"dependencies": {
4647
"@commitlint/load": "^11.0.0",
4748
"chalk": "^4.0.0",
48-
"inquirer": "^6.5.2",
4949
"lodash": "^4.17.19"
5050
},
5151
"gitHead": "cb565dfcca3128380b9b3dc274aedbcae34ce5ca"

@commitlint/prompt/src/index.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
import inquirer from 'inquirer';
22
import input from './input';
3+
import InputCustomPrompt from './inquirer/InputCustomPrompt';
34

45
type Commit = (input: string) => void;
56

67
/**
78
* Entry point for commitizen
8-
* @param _ inquirer instance passed by commitizen, unused
9+
* @param cz inquirer instance passed by commitizen
910
* @param commit callback to execute with complete commit message
1011
* @return generated commit message
1112
*/
12-
export async function prompter(_: unknown, commit: Commit): Promise<void> {
13-
const message = await input(inquirer.createPromptModule());
13+
export async function prompter(
14+
cz: typeof inquirer,
15+
commit: Commit
16+
): Promise<void> {
17+
cz.prompt.registerPrompt('input-custom', InputCustomPrompt);
18+
const message = await input(cz.prompt);
1419
commit(message);
1520
}

@commitlint/prompt/src/input.ts

-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import getPrompt from './library/get-prompt';
66
import settings from './settings';
77
import {InputSetting, Result} from './library/types';
88

9-
import InputCustomPrompt from './inquirer/InputCustomPrompt';
109
import {getHasName, getMaxLength, getRules} from './library/utils';
1110

1211
/**
@@ -26,7 +25,6 @@ export default async function input(prompter: PromptModule): Promise<string> {
2625
const maxLength = getMaxLength(headerLengthRule);
2726

2827
try {
29-
prompter.registerPrompt('input-custom', InputCustomPrompt);
3028
const questions: DistinctQuestion<Result>[] = [];
3129

3230
for (const input of parts) {

0 commit comments

Comments
 (0)