[READ-ONLY] Mirror of https://github.com/bombshell-dev/clack. Effortlessly build beautiful command-line apps bomb.sh/docs/clack/basics/getting-started/
cli command-line command-line-app node prompt prompts
5

Configure Feed

Select the types of activity you want to include in your feed.

wip: implement JSX package

James Garbutt (Jul 8, 2025, 2:04 PM +0100) 9312c087 9a1412da

+289 -9
+2 -2
examples/basic/spinner-cancel-advanced.ts
··· 81 81 } catch (error) { 82 82 // Handle errors but continue if not cancelled 83 83 if (!processSpinner.isCancelled) { 84 - p.note(`Error processing ${language}: ${error.message}`, 'Error'); 84 + p.note(`Error processing ${language}: ${(error as Error).message}`, 'Error'); 85 85 } 86 86 } 87 87 } ··· 134 134 } 135 135 } catch (error) { 136 136 if (!finalSpinner.isCancelled) { 137 - finalSpinner.stop(`Error during ${action}: ${error.message}`); 137 + finalSpinner.stop(`Error during ${action}: ${(error as Error).message}`); 138 138 } 139 139 } 140 140 }
+2 -2
examples/basic/text-validation.ts
··· 9 9 message: 'Enter your name (letters and spaces only)', 10 10 initialValue: 'John123', // Invalid initial value with numbers 11 11 validate: (value) => { 12 - if (!/^[a-zA-Z\s]+$/.test(value)) return 'Name can only contain letters and spaces'; 12 + if (!value || !/^[a-zA-Z\s]+$/.test(value)) return 'Name can only contain letters and spaces'; 13 13 return undefined; 14 14 }, 15 15 }); ··· 25 25 message: 'Enter another name (letters and spaces only)', 26 26 initialValue: 'John Doe', // Valid initial value 27 27 validate: (value) => { 28 - if (!/^[a-zA-Z\s]+$/.test(value)) return 'Name can only contain letters and spaces'; 28 + if (!value || !/^[a-zA-Z\s]+$/.test(value)) return 'Name can only contain letters and spaces'; 29 29 return undefined; 30 30 }, 31 31 });
+1
package.json
··· 9 9 "dev": "pnpm --filter @example/changesets run start", 10 10 "format": "biome check --write", 11 11 "lint": "biome lint --write --unsafe", 12 + "typecheck": "pnpm -r exec tsc --noEmit", 12 13 "types": "biome lint --write --unsafe", 13 14 "deps": "pnpm exec knip --production", 14 15 "test": "pnpm --color -r run test",
+2 -1
packages/core/tsconfig.json
··· 1 1 { 2 - "extends": "../../tsconfig.json" 2 + "extends": "../../tsconfig.json", 3 + "include": ["./src", "./test"] 3 4 }
+2
packages/jsx/CHANGELOG.md
··· 1 + # @clack/core 2 +
+9
packages/jsx/LICENSE
··· 1 + MIT License 2 + 3 + Copyright (c) Bombshell Maintainers 4 + 5 + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 + 7 + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 + 9 + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+18
packages/jsx/README.md
··· 1 + # `@clack/jsx` 2 + 3 + This package contains JSX support for clack, allowing you to define your 4 + prompts declaratively. 5 + 6 + Each `Prompt` can be rendered as if it were a component: 7 + 8 + ```tsx 9 + import {Confirm} from '@clack/jsx'; 10 + 11 + const p = (<Confirm message="yes?"></Confirm>); 12 + 13 + const name = await p; 14 + 15 + if (isCancel(name)) { 16 + process.exit(0); 17 + } 18 + ```
+7
packages/jsx/build.config.ts
··· 1 + import { defineBuildConfig } from 'unbuild'; 2 + 3 + // @see https://github.com/unjs/unbuild 4 + export default defineBuildConfig({ 5 + preset: '../../build.preset', 6 + entries: ['src/index'], 7 + });
+1
packages/jsx/jsx-runtime.d.ts
··· 1 + export { jsx, jsxDEV } from './dist/index.mjs';
+1
packages/jsx/jsx-runtime.js
··· 1 + export { jsx, jsxDEV } from './dist/index.mjs';
+62
packages/jsx/package.json
··· 1 + { 2 + "name": "@clack/jsx", 3 + "version": "1.0.0-alpha.1", 4 + "type": "module", 5 + "main": "./dist/index.mjs", 6 + "module": "./dist/index.mjs", 7 + "exports": { 8 + ".": { 9 + "types": "./dist/index.d.mts", 10 + "default": "./dist/index.mjs" 11 + }, 12 + "./jsx-runtime": "./jsx-runtime.js", 13 + "./jsx-dev-runtime": "./jsx-runtime.js", 14 + "./package.json": "./package.json" 15 + }, 16 + "types": "./dist/index.d.mts", 17 + "repository": { 18 + "type": "git", 19 + "url": "git+https://github.com/bombshell-dev/clack.git", 20 + "directory": "packages/jsx" 21 + }, 22 + "bugs": { 23 + "url": "https://github.com/bombshell-dev/clack/issues" 24 + }, 25 + "homepage": "https://github.com/bombshell-dev/clack/tree/main/packages/jsx#readme", 26 + "files": ["dist", "CHANGELOG.md"], 27 + "keywords": [ 28 + "ask", 29 + "clack", 30 + "cli", 31 + "command-line", 32 + "command", 33 + "input", 34 + "interact", 35 + "interface", 36 + "menu", 37 + "prompt", 38 + "prompts", 39 + "stdin", 40 + "ui", 41 + "jsx", 42 + "ink" 43 + ], 44 + "author": { 45 + "name": "James Garbutt", 46 + "url": "https://github.com/43081j" 47 + }, 48 + "license": "MIT", 49 + "packageManager": "pnpm@9.14.2", 50 + "scripts": { 51 + "build": "unbuild", 52 + "prepack": "pnpm build", 53 + "test": "vitest run" 54 + }, 55 + "dependencies": { 56 + "@clack/prompts": "workspace:*" 57 + }, 58 + "devDependencies": { 59 + "vitest": "^3.1.1", 60 + "@clack/test-utils": "workspace:*" 61 + } 62 + }
+25
packages/jsx/src/index.ts
··· 1 + import type { ConfirmOptions } from '@clack/prompts'; 2 + 3 + namespace JSX { 4 + export interface IntrinsicElements { 5 + confirm: ConfirmOptions; 6 + } 7 + 8 + export type Element = unknown; 9 + } 10 + 11 + export type { JSX }; 12 + 13 + export function Confirm(_props: JSX.IntrinsicElements['confirm']): JSX.Element { 14 + return 'foo'; 15 + } 16 + 17 + export function jsx<T extends keyof JSX.IntrinsicElements>( 18 + tag: T, 19 + props: JSX.IntrinsicElements[T], 20 + _key?: string 21 + ): JSX.Element { 22 + return 'foo'; 23 + } 24 + 25 + export const jsxDEV = jsx;
+27
packages/jsx/test/jsx.test.tsx
··· 1 + import { MockReadable, MockWritable } from '@clack/test-utils'; 2 + import { beforeEach, describe, expect, test } from 'vitest'; 3 + import { Confirm, jsx } from '../src/index.js'; 4 + 5 + describe('jsx', () => { 6 + let input: MockReadable; 7 + let output: MockWritable; 8 + 9 + beforeEach(() => { 10 + input = new MockReadable(); 11 + output = new MockWritable(); 12 + }); 13 + 14 + test('can render', async () => { 15 + const result = jsx('confirm', { 16 + message: 'foo?', 17 + input, 18 + output, 19 + }); 20 + expect(result).to.equal('foo'); 21 + }); 22 + 23 + test('can render JSX', () => { 24 + const result = <Confirm message="foo?" input={input} output={output} />; 25 + expect(result).to.equal('foo'); 26 + }); 27 + });
+8
packages/jsx/tsconfig.json
··· 1 + { 2 + "extends": "../../tsconfig.json", 3 + "compilerOptions": { 4 + "jsx": "react-jsx", 5 + "jsxImportSource": "@clack/jsx" 6 + }, 7 + "include": ["./src", "./test"] 8 + }
+1 -1
packages/prompts/test/password.test.ts
··· 77 77 const result = prompts.password({ 78 78 message: 'foo', 79 79 validate: (value) => { 80 - if (value.length < 2) { 80 + if (!value || value.length < 2) { 81 81 return 'Password must be at least 2 characters'; 82 82 } 83 83
+2 -1
packages/prompts/tsconfig.json
··· 1 1 { 2 - "extends": "../../tsconfig.json" 2 + "extends": "../../tsconfig.json", 3 + "include": ["./src", "./test"] 3 4 }
+9
packages/test-utils/LICENSE
··· 1 + MIT License 2 + 3 + Copyright (c) Bombshell Maintainers 4 + 5 + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 + 7 + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 + 9 + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+3
packages/test-utils/README.md
··· 1 + # `@clack/test-utils` 2 + 3 + A bunch of useful test utiltiies for use inside clack.
+40
packages/test-utils/package.json
··· 1 + { 2 + "name": "@clack/test-utils", 3 + "private": true, 4 + "version": "1.0.0-alpha.1", 5 + "type": "module", 6 + "main": "./dist/index.js", 7 + "module": "./dist/index.js", 8 + "exports": { 9 + ".": { 10 + "types": "./dist/index.d.ts", 11 + "default": "./dist/index.js" 12 + }, 13 + "./package.json": "./package.json" 14 + }, 15 + "types": "./dist/index.d.ts", 16 + "repository": { 17 + "type": "git", 18 + "url": "git+https://github.com/bombshell-dev/clack.git", 19 + "directory": "packages/test-utils" 20 + }, 21 + "bugs": { 22 + "url": "https://github.com/bombshell-dev/clack/issues" 23 + }, 24 + "homepage": "https://github.com/bombshell-dev/clack/tree/main/packages/test-utils#readme", 25 + "files": ["dist", "CHANGELOG.md"], 26 + "author": { 27 + "name": "James Garbutt", 28 + "url": "https://github.com/43081j" 29 + }, 30 + "license": "MIT", 31 + "packageManager": "pnpm@9.14.2", 32 + "scripts": { 33 + "build": "tsc", 34 + "prepack": "pnpm build" 35 + }, 36 + "dependencies": { 37 + }, 38 + "devDependencies": { 39 + } 40 + }
+2
packages/test-utils/src/index.ts
··· 1 + export { MockReadable } from './mock-readable.js'; 2 + export { MockWritable } from './mock-writable.js';
+26
packages/test-utils/src/mock-readable.ts
··· 1 + import { Readable } from 'node:stream'; 2 + 3 + export class MockReadable extends Readable { 4 + protected _buffer: unknown[] | null = []; 5 + 6 + _read() { 7 + if (this._buffer === null) { 8 + this.push(null); 9 + return; 10 + } 11 + 12 + for (const val of this._buffer) { 13 + this.push(val); 14 + } 15 + 16 + this._buffer = []; 17 + } 18 + 19 + pushValue(val: unknown): void { 20 + this._buffer?.push(val); 21 + } 22 + 23 + close(): void { 24 + this._buffer = null; 25 + } 26 + }
+14
packages/test-utils/src/mock-writable.ts
··· 1 + import { Writable } from 'node:stream'; 2 + 3 + export class MockWritable extends Writable { 4 + public buffer: string[] = []; 5 + 6 + _write( 7 + chunk: any, 8 + _encoding: BufferEncoding, 9 + callback: (error?: Error | null | undefined) => void 10 + ): void { 11 + this.buffer.push(chunk.toString()); 12 + callback(); 13 + } 14 + }
+9
packages/test-utils/tsconfig.json
··· 1 + { 2 + "extends": "../../tsconfig.json", 3 + "compilerOptions": { 4 + "noEmit": false, 5 + "declaration": true, 6 + "outDir": "./dist" 7 + }, 8 + "include": ["./src"] 9 + }
+15
pnpm-lock.yaml
··· 74 74 specifier: ^8.1.0 75 75 version: 8.1.0 76 76 77 + packages/jsx: 78 + dependencies: 79 + '@clack/prompts': 80 + specifier: workspace:* 81 + version: link:../prompts 82 + devDependencies: 83 + '@clack/test-utils': 84 + specifier: workspace:* 85 + version: link:../test-utils 86 + vitest: 87 + specifier: ^3.1.1 88 + version: 3.1.1(@types/node@18.16.0) 89 + 77 90 packages/prompts: 78 91 dependencies: 79 92 '@clack/core': ··· 98 111 vitest-ansi-serializer: 99 112 specifier: ^0.1.2 100 113 version: 0.1.2(vitest@3.1.1(@types/node@18.16.0)) 114 + 115 + packages/test-utils: {} 101 116 102 117 packages: 103 118
+1 -2
tsconfig.json
··· 15 15 "paths": { 16 16 "@clack/core": ["./packages/core/src"] 17 17 } 18 - }, 19 - "include": ["packages"] 18 + } 20 19 }