File tree 2 files changed +32
-2
lines changed
2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change
1
+ import process , { type env } from 'node:process' ;
2
+ import { expectType , expectAssignable } from 'tsd' ;
3
+ import { execa , type Options , type Result } from '../../index.js' ;
4
+
5
+ type NodeEnv = 'production' | 'development' | 'test' ;
6
+
7
+ // Libraries like Next.js or Remix do the following type augmentation.
8
+ // The following type tests ensure this works with Execa.
9
+ // See https://github.com/sindresorhus/execa/pull/1141 and https://github.com/sindresorhus/execa/issues/1132
10
+ declare global {
11
+ // eslint-disable-next-line @typescript-eslint/no-namespace
12
+ namespace NodeJS {
13
+ // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
14
+ interface ProcessEnv {
15
+ readonly NODE_ENV : NodeEnv ;
16
+ }
17
+ }
18
+ }
19
+
20
+ // The global types are impacted
21
+ expectType < NodeEnv > ( process . env . NODE_ENV ) ;
22
+ expectType < NodeEnv > ( '' as ( typeof env ) [ 'NODE_ENV' ] ) ;
23
+ expectType < NodeEnv > ( '' as NodeJS . ProcessEnv [ 'NODE_ENV' ] ) ;
24
+ expectType < NodeEnv > ( '' as globalThis . NodeJS . ProcessEnv [ 'NODE_ENV' ] ) ;
25
+
26
+ // But Execa's types are not impacted
27
+ expectType < string | undefined > ( '' as Exclude < Options [ 'env' ] , undefined > [ 'NODE_ENV' ] ) ;
28
+ expectAssignable < Result > ( await execa ( { env : { test : 'example' } } ) `unicorns` ) ;
29
+ expectAssignable < Result > ( await execa ( { env : { test : 'example' } as const } ) `unicorns` ) ;
30
+ expectAssignable < Result > ( await execa ( { env : { test : undefined } } ) `unicorns` ) ;
31
+ expectAssignable < Result > ( await execa ( { env : { test : undefined } as const } ) `unicorns` ) ;
Original file line number Diff line number Diff line change 1
1
import type { SignalConstants } from 'node:os' ;
2
- import type { env } from 'node:process' ;
3
2
import type { Readable } from 'node:stream' ;
4
3
import type { Unless } from '../utils.js' ;
5
4
import type { Message } from '../ipc.js' ;
@@ -77,7 +76,7 @@ export type CommonOptions<IsSync extends boolean = boolean> = {
77
76
78
77
@default [process.env](https://nodejs.org/api/process.html#processenv)
79
78
*/
80
- readonly env ?: typeof env ;
79
+ readonly env ?: Readonly < Partial < Record < string , string > > > ;
81
80
82
81
/**
83
82
If `true`, the subprocess uses both the `env` option and the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)).
You can’t perform that action at this time.
0 commit comments