avil13-co 2.5.0 → 2.5.1

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.
@@ -3,5 +3,5 @@ export declare enum BranchesType {
3
3
  Merged = 1,
4
4
  NotMerged = 2
5
5
  }
6
- /** Remote origin refs are also offered for checkout/merge; deletion is local only. */
6
+ /** Remote refs retain their remote prefix; deletion is local only. */
7
7
  export declare function getBranches(type: BranchesType, localOnly?: boolean): Promise<string[]>;
@@ -8,7 +8,7 @@ var BranchesType;
8
8
  BranchesType[BranchesType["Merged"] = 1] = "Merged";
9
9
  BranchesType[BranchesType["NotMerged"] = 2] = "NotMerged";
10
10
  })(BranchesType = exports.BranchesType || (exports.BranchesType = {}));
11
- /** Remote origin refs are also offered for checkout/merge; deletion is local only. */
11
+ /** Remote refs retain their remote prefix; deletion is local only. */
12
12
  async function getBranches(type, localOnly = false) {
13
13
  const args = ['branch', '--format=%(refname)'];
14
14
  if (!localOnly)
@@ -22,7 +22,7 @@ async function getBranches(type, localOnly = false) {
22
22
  .map(name => name.trim())
23
23
  .filter(name => name && !/^refs\/remotes\/.+\/HEAD$/.test(name))
24
24
  .map(name => name.replace(/^refs\/heads\//, '')
25
- .replace(/^refs\/remotes\/(?:origin\/)?/, '')))];
25
+ .replace(/^refs\/remotes\//, '')))];
26
26
  if (!branches.length)
27
27
  throw new Error('No branches found.');
28
28
  return branches;
package/dist/prompt.js CHANGED
@@ -7,7 +7,16 @@ exports.prompt = void 0;
7
7
  const inquirer_1 = __importDefault(require("inquirer"));
8
8
  const terminal_1 = require("./terminal");
9
9
  function prompt(questions) {
10
- const result = inquirer_1.default.prompt(questions);
10
+ // Bright yellow uses the terminal palette and keeps Inquirer's bold styling.
11
+ const styleQuestion = (question) => {
12
+ if (!process.stdout.isTTY || typeof question.message !== 'string')
13
+ return question;
14
+ return { ...question, message: `\x1b[93m${question.message}\x1b[39m` };
15
+ };
16
+ const styledQuestions = Array.isArray(questions)
17
+ ? questions.map(styleQuestion)
18
+ : styleQuestion(questions);
19
+ const result = inquirer_1.default.prompt(styledQuestions);
11
20
  // Inquirer 8 re-sends SIGINT asynchronously and may exit before Node handles
12
21
  // it. Handle readline's raw-mode Ctrl+C synchronously instead.
13
22
  const ui = result.ui;
package/dist/terminal.js CHANGED
@@ -5,7 +5,9 @@ exports.installInterruptHandler = exports.finishTerminal = exports.print = expor
5
5
  let active = false;
6
6
  let messages = [];
7
7
  function startTerminal() {
8
- active = Boolean(process.stdout.isTTY && process.stdin.isTTY);
8
+ // Temporarily disable the alternate screen; keep ordinary terminal output.
9
+ // active = Boolean(process.stdout.isTTY && process.stdin.isTTY);
10
+ active = false;
9
11
  messages = [];
10
12
  if (active)
11
13
  process.stdout.write('\x1b[?1049h');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "avil13-co",
3
- "version": "2.5.0",
3
+ "version": "2.5.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "public": true,
@@ -49,11 +49,14 @@ describe('Git commands', () => {
49
49
  expect(git('branch', '--show-current')).toBe(branch);
50
50
  });
51
51
 
52
- it('preserves local origin-prefixed branches and deduplicates origin remote refs', async () => {
52
+ it('preserves remote prefixes and distinguishes local and remote branches', async () => {
53
53
  git('branch', 'origin/local');
54
54
  git('update-ref', 'refs/remotes/origin/main', 'HEAD');
55
+ git('update-ref', 'refs/remotes/upstream/main', 'HEAD');
55
56
  git('symbolic-ref', 'refs/remotes/origin/HEAD', 'refs/remotes/origin/main');
56
- expect(await getBranches(BranchesType.All)).toEqual(['main', 'origin/local']);
57
+ expect(await getBranches(BranchesType.All)).toEqual([
58
+ 'main', 'origin/local', 'origin/main', 'upstream/main',
59
+ ]);
57
60
  });
58
61
 
59
62
  it('excludes remote refs from deletion candidates', async () => {
@@ -0,0 +1,27 @@
1
+ import { afterEach, expect, it, vi } from 'vitest';
2
+ import inquirer from 'inquirer';
3
+ import { prompt } from '../prompt';
4
+
5
+ const descriptor = Object.getOwnPropertyDescriptor(process.stdout, 'isTTY');
6
+
7
+ afterEach(() => {
8
+ vi.restoreAllMocks();
9
+ if (descriptor) Object.defineProperty(process.stdout, 'isTTY', descriptor);
10
+ else delete (process.stdout as any).isTTY;
11
+ });
12
+
13
+ it.each([true, false])('styles prompt headings only in a terminal (TTY=%s)', async isTTY => {
14
+ Object.defineProperty(process.stdout, 'isTTY', { value: isTTY, configurable: true });
15
+ const spy = vi.spyOn(inquirer, 'prompt').mockResolvedValue({ branch: 'main' });
16
+ const question = { name: 'branch', message: 'Select branch' };
17
+ const expected = {
18
+ ...question,
19
+ message: isTTY ? '\x1b[93mSelect branch\x1b[39m' : 'Select branch',
20
+ };
21
+
22
+ await prompt(question);
23
+ expect(spy).toHaveBeenLastCalledWith(expected);
24
+ await prompt([question]);
25
+ expect(spy).toHaveBeenLastCalledWith([expected]);
26
+ expect(question.message).toBe('Select branch');
27
+ });
@@ -6,7 +6,7 @@ export enum BranchesType {
6
6
  NotMerged,
7
7
  }
8
8
 
9
- /** Remote origin refs are also offered for checkout/merge; deletion is local only. */
9
+ /** Remote refs retain their remote prefix; deletion is local only. */
10
10
  export async function getBranches(type: BranchesType, localOnly = false): Promise<string[]> {
11
11
  const args = ['branch', '--format=%(refname)'];
12
12
  if (!localOnly) args.push('--all');
@@ -18,7 +18,7 @@ export async function getBranches(type: BranchesType, localOnly = false): Promis
18
18
  .map(name => name.trim())
19
19
  .filter(name => name && !/^refs\/remotes\/.+\/HEAD$/.test(name))
20
20
  .map(name => name.replace(/^refs\/heads\//, '')
21
- .replace(/^refs\/remotes\/(?:origin\/)?/, '')))];
21
+ .replace(/^refs\/remotes\//, '')))];
22
22
  if (!branches.length) throw new Error('No branches found.');
23
23
  return branches;
24
24
  }
package/src/prompt.ts CHANGED
@@ -2,7 +2,15 @@ import inquirer, { Answers, QuestionCollection } from 'inquirer';
2
2
  import { finishTerminal } from './terminal';
3
3
 
4
4
  export function prompt<T extends Answers = Answers>(questions: QuestionCollection<T>): Promise<T> {
5
- const result = inquirer.prompt<T>(questions);
5
+ // Bright yellow uses the terminal palette and keeps Inquirer's bold styling.
6
+ const styleQuestion = (question: any) => {
7
+ if (!process.stdout.isTTY || typeof question.message !== 'string') return question;
8
+ return { ...question, message: `\x1b[93m${question.message}\x1b[39m` };
9
+ };
10
+ const styledQuestions = Array.isArray(questions)
11
+ ? questions.map(styleQuestion)
12
+ : styleQuestion(questions);
13
+ const result = inquirer.prompt<T>(styledQuestions);
6
14
  // Inquirer 8 re-sends SIGINT asynchronously and may exit before Node handles
7
15
  // it. Handle readline's raw-mode Ctrl+C synchronously instead.
8
16
  const ui = result.ui as any;
package/src/terminal.ts CHANGED
@@ -3,7 +3,9 @@ let active = false;
3
3
  let messages: string[] = [];
4
4
 
5
5
  export function startTerminal() {
6
- active = Boolean(process.stdout.isTTY && process.stdin.isTTY);
6
+ // Temporarily disable the alternate screen; keep ordinary terminal output.
7
+ // active = Boolean(process.stdout.isTTY && process.stdin.isTTY);
8
+ active = false;
7
9
  messages = [];
8
10
  if (active) process.stdout.write('\x1b[?1049h');
9
11
  }