Skip to content

Commit 08e08b6

Browse files
committed
fix: type assertions
1 parent ca6aeb8 commit 08e08b6

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/naming-strategy/tokens.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import { Aws } from 'aws-cdk-lib';
2-
import ci from 'env-ci';
2+
import ci, { AppveyorEnv } from 'env-ci';
33
import Haikunator, { Options as HaikunatorOptions } from 'haikunator';
44

5-
function fromCI(name: 'branch' | 'commit' | 'build' | 'job' | 'pr' | 'slug'): IStaticWebsitePreviewNamingToken {
6-
const c = ci();
5+
// The env-ci package has some funky type union setup per each CI environment, and we cannot
6+
// handle every use case, so just generalize this by taking one of the environments that has types
7+
// for all of the keys that we care about
8+
type GenericCiEnv = AppveyorEnv
79

8-
if (name in c) {
9-
const val = c[name];
10+
function fromCI(name: keyof GenericCiEnv): IStaticWebsitePreviewNamingToken {
1011

11-
if (val) {
12-
return new StaticWebsitePreviewNamingToken(val);
13-
}
12+
const c = ci() as GenericCiEnv;
13+
const val = c[name];
14+
15+
if (typeof val === 'string' && val) {
16+
return new StaticWebsitePreviewNamingToken(val);
1417
}
1518

1619
throw new Error(`The value for "${name}" is not set.`);

0 commit comments

Comments
 (0)