From 2d8475291b260aa79d2654793d9f6e8db88c06eb Mon Sep 17 00:00:00 2001 From: ehmicky Date: Fri, 10 May 2024 19:26:20 +0100 Subject: [PATCH 1/5] Export `TemplateExpression` type (#1049) --- docs/typescript.md | 15 ++++++++++----- index.d.ts | 1 + test-d/methods/template.test-d.ts | 18 ++++++++++++++++++ types/methods/template.d.ts | 4 +++- 4 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 test-d/methods/template.test-d.ts diff --git a/docs/typescript.md b/docs/typescript.md index 0b8a741cca..fbbb5f5fdf 100644 --- a/docs/typescript.md +++ b/docs/typescript.md @@ -8,7 +8,7 @@ ## Available types -The following types can be imported: [`ResultPromise`](api.md#return-value), [`Subprocess`](api.md#subprocess), [`Result`](api.md#result), [`ExecaError`](api.md#execaerror), [`Options`](api.md#options), [`StdinOption`](api.md#optionsstdin) and [`StdoutStderrOption`](api.md#optionsstdout). +The following types can be imported: [`ResultPromise`](api.md#return-value), [`Subprocess`](api.md#subprocess), [`Result`](api.md#result), [`ExecaError`](api.md#execaerror), [`Options`](api.md#options), [`StdinOption`](api.md#optionsstdin), [`StdoutStderrOption`](api.md#optionsstdout) and [`TemplateExpression`](api.md#execacommand). ```ts import { @@ -19,6 +19,7 @@ import { type Options, type StdinOption, type StdoutStderrOption, + type TemplateExpression, } from 'execa'; const options: Options = { @@ -27,9 +28,10 @@ const options: Options = { stderr: 'pipe' satisfies StdoutStderrOption, timeout: 1000, }; +const task: TemplateExpression = 'build'; try { - const subprocess: ResultPromise = execa(options)`npm run build`; + const subprocess: ResultPromise = execa(options)`npm run ${task}`; const result: Result = await subprocess; console.log(result.stdout); } catch (error) { @@ -41,7 +43,7 @@ try { ## Synchronous execution -Their [synchronous](#synchronous-execution) counterparts are [`SyncResult`](api.md#result), [`ExecaSyncError`](api.md#execasyncerror), [`SyncOptions`](api.md#options), [`StdinSyncOption`](api.md#optionsstdin) and [`StdoutStderrSyncOption`](api.md#optionsstdout). +Their [synchronous](#synchronous-execution) counterparts are [`SyncResult`](api.md#result), [`ExecaSyncError`](api.md#execasyncerror), [`SyncOptions`](api.md#options), [`StdinSyncOption`](api.md#optionsstdin), [`StdoutStderrSyncOption`](api.md#optionsstdout) and [`TemplateExpression`](api.md#execacommand). ```ts import { @@ -51,6 +53,7 @@ import { type SyncOptions, type StdinSyncOption, type StdoutStderrSyncOption, + type TemplateExpression, } from 'execa'; const options: SyncOptions = { @@ -59,9 +62,10 @@ const options: SyncOptions = { stderr: 'pipe' satisfies StdoutStderrSyncOption, timeout: 1000, }; +const task: TemplateExpression = 'build'; try { - const result: SyncResult = execaSync(options)`npm run build`; + const result: SyncResult = execaSync(options)`npm run ${task}`; console.log(result.stdout); } catch (error) { if (error instanceof ExecaSyncError) { @@ -91,9 +95,10 @@ const options = { stderr: 'pipe', timeout: 1000, } as const; +const task = 'build'; try { - const subprocess = execa(options)`npm run build`; + const subprocess = execa(options)`npm run ${task}`; const result = await subprocess; printResultStdout(result); } catch (error) { diff --git a/index.d.ts b/index.d.ts index fd64d3bfd2..344c4c2f15 100644 --- a/index.d.ts +++ b/index.d.ts @@ -8,6 +8,7 @@ export type {Options, SyncOptions} from './types/arguments/options.js'; export type {Result, SyncResult} from './types/return/result.js'; export type {ResultPromise, Subprocess} from './types/subprocess/subprocess.js'; export {ExecaError, ExecaSyncError} from './types/return/final-error.js'; +export type {TemplateExpression} from './types/methods/template.js'; export {execa} from './types/methods/main-async.js'; export {execaSync} from './types/methods/main-sync.js'; export {execaCommand, execaCommandSync} from './types/methods/command.js'; diff --git a/test-d/methods/template.test-d.ts b/test-d/methods/template.test-d.ts new file mode 100644 index 0000000000..5aa836d498 --- /dev/null +++ b/test-d/methods/template.test-d.ts @@ -0,0 +1,18 @@ +import {expectAssignable, expectNotAssignable} from 'tsd'; +import {execa, type TemplateExpression} from '../../index.js'; + +const stringArray = ['foo', 'bar'] as const; +const numberArray = [1, 2] as const; + +expectAssignable('unicorns'); +expectAssignable(1); +expectAssignable(stringArray); +expectAssignable(numberArray); +expectAssignable(false.toString()); +expectNotAssignable(false); + +expectAssignable(await execa`echo foo`); +expectAssignable(await execa({reject: false})`echo foo`); +expectNotAssignable(execa`echo foo`); +expectAssignable([await execa`echo foo`, 'bar']); +expectNotAssignable([execa`echo foo`, 'bar']); diff --git a/types/methods/template.d.ts b/types/methods/template.d.ts index 189a18986f..012d31990e 100644 --- a/types/methods/template.d.ts +++ b/types/methods/template.d.ts @@ -1,12 +1,14 @@ import type {Result, SyncResult} from '../return/result.js'; -// Values allowed inside `...${...}...` template syntax type TemplateExpressionItem = | string | number | Result | SyncResult; +/** +Value allowed inside `${...}` when using the template string syntax. +*/ export type TemplateExpression = TemplateExpressionItem | readonly TemplateExpressionItem[]; // `...${...}...` template syntax From de8e7daabefbc6f4af36ef9647b37b6a0dfca7fa Mon Sep 17 00:00:00 2001 From: ehmicky Date: Fri, 10 May 2024 22:28:27 +0100 Subject: [PATCH 2/5] Document minimum TypeScript version (#1050) --- docs/typescript.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/typescript.md b/docs/typescript.md index fbbb5f5fdf..c8b5ff0644 100644 --- a/docs/typescript.md +++ b/docs/typescript.md @@ -110,6 +110,10 @@ try { ## Troubleshooting +### Supported version + +The minimum supported TypeScript version is [`5.1.6`](https://github.com/microsoft/TypeScript/releases/tag/v5.1.6). + ### ES modules This package uses pure ES modules. Therefore the TypeScript's `--module` compiler option must be set to [`nodenext`](https://www.typescriptlang.org/docs/handbook/modules/reference.html#node16-nodenext) or [`preserve`](https://www.typescriptlang.org/docs/handbook/modules/reference.html#preserve). [More info.](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) From 3b11ac87d9c6230710dc69e0bceadd45ae7e4d86 Mon Sep 17 00:00:00 2001 From: ehmicky Date: Sat, 11 May 2024 22:00:05 +0100 Subject: [PATCH 3/5] Check types on TypeScript 5.1 + latest (#1051) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 316354233c..6b28673f43 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "node": ">=18" }, "scripts": { - "test": "xo && c8 ava && tsd && tsc" + "test": "xo && c8 ava && tsd && tsc && npx --yes tsd@0.29.0 && npx --yes --package typescript@5.1 tsc" }, "files": [ "index.js", From 733d6ff6c2cae3a64ef003accf7c419a6235900f Mon Sep 17 00:00:00 2001 From: ehmicky Date: Sun, 12 May 2024 04:47:07 +0100 Subject: [PATCH 4/5] Split CI jobs (#1052) --- .github/workflows/main.yml | 4 +++- package.json | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6dbb800f45..08e9967b2c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,7 +22,9 @@ jobs: with: node-version: ${{ matrix.node-version }} - run: npm install - - run: npm test + - run: npm run lint + - run: npm run type + - run: npm run unit - uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} diff --git a/package.json b/package.json index 6b28673f43..416a188ccf 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,10 @@ "node": ">=18" }, "scripts": { - "test": "xo && c8 ava && tsd && tsc && npx --yes tsd@0.29.0 && npx --yes --package typescript@5.1 tsc" + "test": "npm run lint && npm run unit && npm run type", + "lint": "xo", + "unit": "c8 ava", + "type": "tsd && tsc && npx --yes tsd@0.29.0 && npx --yes --package typescript@5.1 tsc" }, "files": [ "index.js", From 62d02af66940551bfb50699d7d02eed942453952 Mon Sep 17 00:00:00 2001 From: ehmicky Date: Mon, 13 May 2024 15:41:27 +0100 Subject: [PATCH 5/5] 9.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 416a188ccf..508ba8a4b1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "execa", - "version": "9.0.2", + "version": "9.1.0", "description": "Process execution for humans", "license": "MIT", "repository": "sindresorhus/execa",