Skip to content

Commit 546108a

Browse files
committed
fix: add typecheck step to the build to catch compilation errors
This fix adds typecheck script which runs `tsc --noEmit` to verify there is no compilation errors. This would catch errors if extension's code is using not existing API. Signed-off-by: Denis Golovin <dgolovin@redhat.com>
1 parent 806a35e commit 546108a

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@
3636
"scripts": {
3737
"generate:registry-authorizer": "npx openapi-typescript src/rh-api/registry-authorizer-schema.json -o src/rh-api/gen/registry-authorizer.d.ts",
3838
"generate:subscription": "npx openapi-typescript src/rh-api/subscription-schema.json -o src/rh-api/gen/subscription.d.ts",
39-
"build": "pnpm generate:subscription && pnpm generate:registry-authorizer && vite build && node ./scripts/build.cjs",
39+
"build": "pnpm generate:subscription && pnpm generate:registry-authorizer && pnpm typecheck && vite build && node ./scripts/build.cjs",
4040
"watch": "vite build -w",
4141
"format:check": "prettier --end-of-line auto --cache --check \"{src,types,scripts}/**/*.{ts,js}\"",
4242
"format:fix": "prettier --cache --write \"{src,types,scripts}/**/*.{ts,js}\"",
4343
"lint:clean": "rimraf .eslintcache",
4444
"lint:fix": "node --max-old-space-size=6144 node_modules/eslint/bin/eslint.js --cache . --cache-strategy content --fix --ext js,ts",
4545
"lint:check": "node --max-old-space-size=6144 node_modules/eslint/bin/eslint.js --cache . --cache-strategy content --ext js,ts",
46+
"typecheck": "tsc --noEmit",
4647
"test": "vitest run --coverage",
4748
"test:all": "pnpm test && pnpm test:e2e",
4849
"test:e2e:setup": "playwright install chromium && xvfb-maybe --auto-servernum --server-args='-screen 0 1280x960x24' --",

src/extension.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,13 @@ function removeRegistry(serverUrl: string = REGISTRY_REDHAT_IO): void {
9393

9494
async function createOrReuseRegistryServiceAccount(): Promise<void> {
9595
const currentSession = await signIntoRedHatDeveloperAccount();
96-
const accessTokenJson = parseJwt(currentSession!.accessToken);
96+
if (!currentSession) {
97+
throw new Error('Red Hat sign-in is required to configure the container registry.');
98+
}
99+
const accessTokenJson = parseJwt(currentSession.accessToken);
97100
const { serviceAccountsApiV1: saApiV1 } = new ContainerRegistryAuthorizerClient({
98101
BASE: 'https://access.redhat.com/hydra/rest/terms-based-registry',
99-
TOKEN: currentSession!.accessToken,
102+
TOKEN: currentSession.accessToken,
100103
});
101104
let { data: serviceAccount } = await saApiV1.serviceAccountByNameUsingGet1(
102105
'podman-desktop',
@@ -116,20 +119,22 @@ async function createOrReuseRegistryServiceAccount(): Promise<void> {
116119
throw new Error(`Can't create registry authorizer service account.`);
117120
}
118121
}
119-
120122
await createRegistry(
121-
serviceAccount!.credentials!.username!,
122-
serviceAccount!.credentials!.password!,
123+
serviceAccount.credentials!.username!,
124+
serviceAccount.credentials!.password!,
123125
currentSession.account.label,
124126
);
125127
}
126128

127129
async function createOrReuseActivationKey(connection: extensionApi.ProviderContainerConnection): Promise<void> {
128130
const currentSession = await signIntoRedHatDeveloperAccount();
129-
const accessTokenJson = parseJwt(currentSession!.accessToken);
131+
if (!currentSession) {
132+
throw new Error('Red Hat sign-in is required to configure the subscription activation key.');
133+
}
134+
const accessTokenJson = parseJwt(currentSession.accessToken);
130135
const client = new SubscriptionManagerClient({
131136
BASE: 'https://console.redhat.com/api/rhsm/v2',
132-
TOKEN: currentSession!.accessToken,
137+
TOKEN: currentSession.accessToken,
133138
});
134139

135140
const { error: showKeyErr } = await client.activationKey.showActivationKey('podman-desktop');

0 commit comments

Comments
 (0)