Skip to content

Commit 92886a2

Browse files
committed
merge main
2 parents 82041c5 + 5077381 commit 92886a2

File tree

15 files changed

+159
-138
lines changed

15 files changed

+159
-138
lines changed

.changeset/kind-yaks-clean.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@clack/prompts": patch
3+
"@clack/core": patch
4+
---
5+
6+
Add missing nullish checks around values.

.changeset/short-squids-battle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@clack/prompts": patch
3+
---
4+
5+
Handle `stop` calls on spinners which have not yet been started.

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ charset = utf-8
77
trim_trailing_whitespace = true
88
insert_final_newline = true
99

10-
[*.yml]
10+
[*.{yml,json,yaml}]
1111
indent_style = space
1212
indent_size = 2

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"dev": "pnpm --filter @example/changesets run start",
1010
"format": "biome check --write",
1111
"lint": "biome lint --write --unsafe",
12-
"types": "biome lint --write --unsafe",
12+
"types": "tsc --noEmit",
1313
"deps": "pnpm exec knip --production",
1414
"test": "pnpm --color -r run test",
1515
"pretest": "pnpm run build"

packages/core/src/prompts/multi-select.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ export default class MultiSelectPrompt<T extends { value: any }> extends Prompt<
2121
}
2222

2323
private toggleInvert() {
24-
const notSelected = this.options.filter((v) => !this.value.includes(v.value));
24+
const value = this.value;
25+
if (!value) {
26+
return;
27+
}
28+
const notSelected = this.options.filter((v) => !value.includes(v.value));
2529
this.value = notSelected.map((v) => v.value);
2630
}
2731

packages/core/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"extends": "../../tsconfig.json"
2+
"extends": "../../tsconfig.json",
3+
"include": ["src"]
34
}

packages/prompts/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ console.log(group.name, group.age, group.color);
203203
Execute multiple tasks in spinners.
204204

205205
```js
206-
await p.tasks([
206+
import { tasks } from '@clack/prompts';
207+
208+
await tasks([
207209
{
208210
title: 'Installing via npm',
209211
task: async (message) => {

packages/prompts/src/note.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import process from 'node:process';
22
import type { Writable } from 'node:stream';
33
import { stripVTControlCharacters as strip } from 'node:util';
4+
import { getColumns } from '@clack/core';
45
import { wrapAnsi, type Options as WrapAnsiOptions } from 'fast-wrap-ansi';
56
import color from 'picocolors';
67
import {
@@ -13,13 +14,14 @@ import {
1314
S_STEP_SUBMIT,
1415
} from './common.js';
1516

17+
type FormatFn = (line: string) => string;
1618
export interface NoteOptions extends CommonOptions {
17-
format?: (line: string) => string;
19+
format?: FormatFn;
1820
}
1921

2022
const defaultNoteFormatter = (line: string): string => color.dim(line);
2123

22-
const wrapWithFormat = (message: string, width: number, format: NoteOptions['format']): string => {
24+
const wrapWithFormat = (message: string, width: number, format: FormatFn): string => {
2325
const opts: WrapAnsiOptions = {
2426
hard: true,
2527
trim: false,
@@ -35,9 +37,9 @@ const wrapWithFormat = (message: string, width: number, format: NoteOptions['for
3537

3638
export const note = (message = '', title = '', opts?: NoteOptions) => {
3739
const output: Writable = opts?.output ?? process.stdout;
38-
const format = (ln) => opts?.format?.(ln) ?? defaultNoteFormatter(ln);
39-
const wrapMsg = wrapWithFormat(message, output.columns - 6, format);
40-
const lines = ['', ...wrapMsg.split('\n').map(format), ''];
40+
const format = (ln) => opts?.format?.(ln) ?? defaultNoteFormatter(ln);
41+
const wrapMsg = wrapWithFormat(message, getColumns(output) - 6, format);
42+
const lines = ['', ...wrapMsg.split('\n').map(format), ''];
4143
const titleLen = strip(title).length;
4244
const len =
4345
Math.max(

packages/prompts/src/spinner.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ export const spinner = ({
159159
};
160160

161161
const stop = (msg = '', code = 0): void => {
162+
if (!isSpinnerActive) return;
162163
isSpinnerActive = false;
163164
clearInterval(loop);
164165
clearPrevMessage();

packages/prompts/test/__snapshots__/note.test.ts.snap

Lines changed: 112 additions & 120 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)