Skip to content

Commit 60e8790

Browse files
committed
Add a signal option
1 parent ce9fbd5 commit 60e8790

File tree

5 files changed

+31
-2
lines changed

5 files changed

+31
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 4.1.0
2+
3+
## Features
4+
5+
- Add a [`signal` option](README.md#signal) to cancel
6+
17
# 4.0.0
28

39
## Breaking changes

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ The list of available Node.js versions is cached for one hour by default. If the
141141
- `true`: the cache will not be used
142142
- `false`: the cache will be used even if it's older than one hour
143143

144+
#### signal
145+
146+
_Type_:
147+
[`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)
148+
149+
Cancels when the signal is aborted.
150+
144151
# See also
145152

146153
- [`nve`](https://github.com/ehmicky/nve): Run a specific Node.js version (CLI)

src/main.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ export interface Options {
3333
*/
3434
mirror?: NodeVersionAliasOptions['mirror']
3535

36+
/**
37+
* Cancels when the signal is aborted.
38+
*/
39+
signal?: NodeVersionAliasOptions['signal']
40+
3641
/**
3742
* The list of available Node.js versions is cached for one hour by default.
3843
* If the `fetch` option is:

src/main.test-d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ expectAssignable<Options>({ mirror: 'https://example.com' })
3131
// @ts-expect-error
3232
await preferredNodeVersion({ mirror: true })
3333

34+
await preferredNodeVersion({ signal: AbortSignal.abort() })
35+
expectAssignable<Options>({ signal: AbortSignal.abort() })
36+
// @ts-expect-error
37+
await preferredNodeVersion({ signal: 'signal' })
38+
3439
await preferredNodeVersion({ fetch: true })
3540
await preferredNodeVersion({ fetch: undefined })
3641
expectAssignable<Options>({ fetch: true })

src/options.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@ export const getOpts = (opts = {}) => {
99
throw new TypeError(`Options must be a plain object: ${opts}`)
1010
}
1111

12-
const { cwd = '.', global: globalOpt = false, fetch: fetchOpt, mirror } = opts
12+
const {
13+
cwd = '.',
14+
global: globalOpt = false,
15+
fetch: fetchOpt,
16+
mirror,
17+
signal,
18+
} = opts
1319
const cwdA = normalizeCwd(cwd)
14-
const nodeVersionAliasOpts = { fetch: fetchOpt, mirror }
20+
const nodeVersionAliasOpts = { fetch: fetchOpt, mirror, signal }
1521
return { cwd: cwdA, globalOpt, nodeVersionAliasOpts }
1622
}
1723

0 commit comments

Comments
 (0)