Skip to content

Commit

Permalink
refactor: Enable TS option verbatimModuleSyntax (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
meyfa authored Dec 15, 2024
1 parent e272a9c commit 02a1741
Show file tree
Hide file tree
Showing 34 changed files with 80 additions and 74 deletions.
4 changes: 2 additions & 2 deletions backend/src/api/auth/local-login.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FastifyPluginAsync } from 'fastify'
import { authenticateLocal, LocalStrategyRequestBody } from '../../auth/local-strategy.js'
import type { FastifyPluginAsync } from 'fastify'
import { authenticateLocal, type LocalStrategyRequestBody } from '../../auth/local-strategy.js'

export interface LocalLoginRoute {
Body: LocalStrategyRequestBody
Expand Down
2 changes: 1 addition & 1 deletion backend/src/api/auth/logout.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FastifyPluginAsync } from 'fastify'
import type { FastifyPluginAsync } from 'fastify'
import { authenticateSession } from '../../auth/common.js'

export interface LogoutRoute {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/api/auth/me.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FastifyPluginAsync } from 'fastify'
import type { FastifyPluginAsync } from 'fastify'
import { forbidden } from '../errors.js'
import { authenticateSession } from '../../auth/common.js'

Expand Down
2 changes: 1 addition & 1 deletion backend/src/api/auth/oidc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FastifyPluginAsync } from 'fastify'
import type { FastifyPluginAsync } from 'fastify'
import { authenticateOidc } from '../../auth/oidc-strategy.js'
import { AuthStrategy } from '../../auth/common.js'

Expand Down
2 changes: 1 addition & 1 deletion backend/src/api/auth/strategies.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FastifyPluginAsync } from 'fastify'
import type { FastifyPluginAsync } from 'fastify'
import { AuthStrategy } from '../../auth/common.js'

export interface StrategiesRoute {
Expand Down
4 changes: 2 additions & 2 deletions backend/src/api/cronjob.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FastifyPluginAsync } from 'fastify'
import { Controllers } from '../controllers.js'
import type { FastifyPluginAsync } from 'fastify'
import type { Controllers } from '../controllers.js'
import cronParser from 'cron-parser'
import { forbidden, notFound } from './errors.js'
import { authenticateSession } from '../auth/common.js'
Expand Down
2 changes: 1 addition & 1 deletion backend/src/api/errors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FastifyReply } from 'fastify'
import type { FastifyReply } from 'fastify'

export async function badRequest (reply: FastifyReply): Promise<FastifyReply> {
return await reply.code(400).send({ error: 'Bad Request' })
Expand Down
6 changes: 3 additions & 3 deletions backend/src/api/job-pods.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { FastifyPluginAsync } from 'fastify'
import { Controllers } from '../controllers.js'
import type { FastifyPluginAsync } from 'fastify'
import type { Controllers } from '../controllers.js'
import { forbidden, notFound } from './errors.js'
import { authenticateSession } from '../auth/common.js'
import { V1Pod } from '@kubernetes/client-node'
import type { V1Pod } from '@kubernetes/client-node'
import assert from 'node:assert'
import { DEFAULT_NAMESPACE } from '../kubernetes/api.js'

Expand Down
6 changes: 3 additions & 3 deletions backend/src/api/jobs.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { FastifyPluginAsync } from 'fastify'
import { Controllers } from '../controllers.js'
import type { FastifyPluginAsync } from 'fastify'
import type { Controllers } from '../controllers.js'
import { forbidden, notFound } from './errors.js'
import { authenticateSession } from '../auth/common.js'
import { V1Job } from '@kubernetes/client-node'
import type { V1Job } from '@kubernetes/client-node'
import assert from 'node:assert'
import { DEFAULT_NAMESPACE } from '../kubernetes/api.js'
import { ForemanAnnotations } from '../metadata.js'
Expand Down
4 changes: 2 additions & 2 deletions backend/src/api/pod-logs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FastifyPluginAsync } from 'fastify'
import { Controllers } from '../controllers.js'
import type { FastifyPluginAsync } from 'fastify'
import type { Controllers } from '../controllers.js'
import { badRequest, forbidden, notFound } from './errors.js'
import { authenticateSession } from '../auth/common.js'
import { prettifyLogs } from '../renovate/prettify-logs.js'
Expand Down
8 changes: 4 additions & 4 deletions backend/src/api/pod-progress.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { FastifyPluginAsync } from 'fastify'
import { Controllers } from '../controllers.js'
import type { FastifyPluginAsync } from 'fastify'
import type { Controllers } from '../controllers.js'
import { forbidden, notFound } from './errors.js'
import { authenticateSession } from '../auth/common.js'
import { extractProgress, ProgressItem } from '../renovate/progress.js'
import { BackendConfig } from '../backend-config.js'
import { extractProgress, type ProgressItem } from '../renovate/progress.js'
import type { BackendConfig } from '../backend-config.js'

export interface PodProgressRoute {
Reply: ProgressItem[]
Expand Down
6 changes: 3 additions & 3 deletions backend/src/api/trigger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FastifyPluginAsync } from 'fastify'
import { Controllers } from '../controllers.js'
import { boolean, Infer, object, optional, pattern, string } from 'superstruct'
import type { FastifyPluginAsync } from 'fastify'
import type { Controllers } from '../controllers.js'
import { boolean, type Infer, object, optional, pattern, string } from 'superstruct'
import { badRequest, forbidden } from './errors.js'
import { authenticateSession } from '../auth/common.js'
import assert from 'node:assert'
Expand Down
4 changes: 2 additions & 2 deletions backend/src/auth/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RouteHandlerMethod } from 'fastify'
import fastifyPassport from '@fastify/passport'
import type { RouteHandlerMethod } from 'fastify'
import { fastifyPassport } from '../fastifyPassport.js'

export enum AuthStrategy {
LOCAL = 'local',
Expand Down
8 changes: 4 additions & 4 deletions backend/src/auth/local-strategy.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Strategy as LocalStrategy } from 'passport-local'
import crypto, { BinaryLike, timingSafeEqual } from 'node:crypto'
import crypto, { type BinaryLike, timingSafeEqual } from 'node:crypto'
import { Mutex } from '../util/mutex.js'
import { AuthStrategy, User } from './common.js'
import { RouteHandlerMethod } from 'fastify'
import fastifyPassport from '@fastify/passport'
import { AuthStrategy, type User } from './common.js'
import type { RouteHandlerMethod } from 'fastify'
import { fastifyPassport } from '../fastifyPassport.js'
import { promisify } from 'node:util'

export const authenticateLocal = (): RouteHandlerMethod => fastifyPassport.authenticate(AuthStrategy.LOCAL)
Expand Down
10 changes: 5 additions & 5 deletions backend/src/auth/oidc-strategy.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { custom, Issuer, Strategy as OpenIdStrategy, TokenSet, UserinfoResponse } from 'openid-client'
import { AuthStrategy, User } from './common.js'
import { AuthenticateOptions } from '@fastify/passport/dist/AuthenticationRoute.js'
import { RouteHandlerMethod } from 'fastify'
import fastifyPassport from '@fastify/passport'
import { custom, Issuer, Strategy as OpenIdStrategy, TokenSet, type UserinfoResponse } from 'openid-client'
import { AuthStrategy, type User } from './common.js'
import type { AuthenticateOptions } from '@fastify/passport/dist/AuthenticationRoute.js'
import type { RouteHandlerMethod } from 'fastify'
import { fastifyPassport } from '../fastifyPassport.js'

export const authenticateOidc = (options?: AuthenticateOptions): RouteHandlerMethod => fastifyPassport.authenticate(AuthStrategy.OIDC, options)

Expand Down
2 changes: 1 addition & 1 deletion backend/src/controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PodController } from './controllers/pod.js'
import { KubernetesApi } from './kubernetes/api.js'
import { LogsController } from './controllers/logs.js'
import { TriggerController } from './controllers/trigger.js'
import { BackendConfig } from './index.js'
import type { BackendConfig } from './index.js'

export interface Controllers {
cronJobController: CronJobController
Expand Down
2 changes: 1 addition & 1 deletion backend/src/controllers/cronjob.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { KubernetesApi } from '../kubernetes/api.js'
import { StrongCache } from '../util/cache.js'
import { BackendConfig } from '../index.js'
import type { BackendConfig } from '../index.js'
import { V1CronJob } from '@kubernetes/client-node'

export class CronJobController {
Expand Down
6 changes: 3 additions & 3 deletions backend/src/controllers/job.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { CronJobController } from './cronjob.js'
import { KubernetesApi } from '../kubernetes/api.js'
import type { CronJobController } from './cronjob.js'
import type { KubernetesApi } from '../kubernetes/api.js'
import assert from 'node:assert'
import { StrongCache } from '../util/cache.js'
import { V1CronJob, V1Job } from '@kubernetes/client-node'
import type { V1CronJob, V1Job } from '@kubernetes/client-node'
import { ForemanLabels } from '../metadata.js'

export class JobController {
Expand Down
4 changes: 2 additions & 2 deletions backend/src/controllers/logs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { KubernetesApi } from '../kubernetes/api.js'
import { PodController } from './pod.js'
import type { KubernetesApi } from '../kubernetes/api.js'
import type { PodController } from './pod.js'
import { WeakCache } from '../util/cache.js'
import { Mutex } from '../util/mutex.js'

Expand Down
6 changes: 3 additions & 3 deletions backend/src/controllers/pod.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { KubernetesApi } from '../kubernetes/api.js'
import { JobController } from './job.js'
import type { KubernetesApi } from '../kubernetes/api.js'
import type { JobController } from './job.js'
import { StrongCache } from '../util/cache.js'
import assert from 'node:assert'
import { V1Pod } from '@kubernetes/client-node'
import type { V1Pod } from '@kubernetes/client-node'

export class PodController {
private readonly cache = new StrongCache<V1Pod[]>(5000)
Expand Down
8 changes: 4 additions & 4 deletions backend/src/controllers/trigger.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { KubernetesApi } from '../kubernetes/api.js'
import { CronJobController } from './cronjob.js'
import type { KubernetesApi } from '../kubernetes/api.js'
import type { CronJobController } from './cronjob.js'
import assert from 'node:assert'
import { randomBytes } from 'node:crypto'
import { V1Job } from '@kubernetes/client-node'
import type { V1Job } from '@kubernetes/client-node'
import { ForemanAnnotations, ForemanLabels } from '../metadata.js'
import { JobController } from './job.js'
import type { JobController } from './job.js'

export class TriggerController {
constructor (
Expand Down
4 changes: 4 additions & 0 deletions backend/src/fastifyPassport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import passport from '@fastify/passport'

// Something is wrong with esModuleInterop... this is a workaround
export const fastifyPassport = passport.default
8 changes: 4 additions & 4 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { jobsRoute } from './api/jobs.js'
import { jobPodsRoute } from './api/job-pods.js'
import { createControllers } from './controllers.js'
import { triggerRoute } from './api/trigger.js'
import { FastifyPluginAsync } from 'fastify'
import type { FastifyPluginAsync } from 'fastify'
import { fastifySecureSession } from '@fastify/secure-session'
import fastifyPassport from '@fastify/passport'
import { fastifyPassport } from './fastifyPassport.js'
import { randomBytes } from 'node:crypto'
import { meAuthRoute } from './api/auth/me.js'
import { localLoginAuthRoute } from './api/auth/local-login.js'
Expand All @@ -18,9 +18,9 @@ import { getAvailableMemory } from './util/system.js'
import { oidcAuthRoute } from './api/auth/oidc.js'
import { makeLocalStrategy } from './auth/local-strategy.js'
import { makeOidcStrategy } from './auth/oidc-strategy.js'
import { AuthStrategy, User } from './auth/common.js'
import { AuthStrategy, type User } from './auth/common.js'
import { strategiesAuthRoute } from './api/auth/strategies.js'
import { BackendConfig } from './backend-config.js'
import type { BackendConfig } from './backend-config.js'

export type { BackendConfig } from './backend-config.js'
export * from './api/errors.js'
Expand Down
4 changes: 2 additions & 2 deletions backend/src/kubernetes/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import k8s, { HttpError, V1CronJob, V1EnvVar, V1Job, V1Pod } from '@kubernetes/client-node'
import k8s, { HttpError, type V1CronJob, type V1EnvVar, type V1Job, type V1Pod } from '@kubernetes/client-node'
import assert from 'node:assert'
import { BaseLogger } from 'pino'
import type { BaseLogger } from 'pino'

export const DEFAULT_NAMESPACE = 'default'

Expand Down
2 changes: 1 addition & 1 deletion backend/test/auth/oidc-strategy.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fastify, FastifyInstance } from 'fastify'
import { fastify, type FastifyInstance } from 'fastify'
import { makeOidcStrategy } from '../../src/auth/oidc-strategy.js'
import assert from 'node:assert'
import { Strategy } from 'openid-client'
Expand Down
4 changes: 2 additions & 2 deletions backend/test/kubernetes/api.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pino from 'pino'
import { pino } from 'pino'
import { KubernetesApi } from '../../src/kubernetes/api.js'
import { HttpError, KubeConfig, V1CronJob } from '@kubernetes/client-node'
import assert from 'node:assert'
import { fastify, FastifyInstance } from 'fastify'
import { fastify, type FastifyInstance } from 'fastify'

function assertEqualResources (actual: any, expected: any): void {
// Check for deep strict equality but ignore undefined values
Expand Down
5 changes: 3 additions & 2 deletions backend/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"compilerOptions": {
"lib": ["ES2022"],
"module": "ES2022",
"module": "NodeNext",
"target": "ES2022",
"moduleResolution": "Node",
"moduleResolution": "nodenext",
"strict": true,
"esModuleInterop": true,
"verbatimModuleSyntax": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"declaration": true,
Expand Down
6 changes: 3 additions & 3 deletions integration/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pino from 'pino'
import { pino } from 'pino'
import { KubeConfig } from '@kubernetes/client-node'
import { startServer } from '../src/server.js'
import { Config, createConfig } from '../src/config.js'
import { FastifyBaseLogger } from 'fastify'
import { type Config, createConfig } from '../src/config.js'
import type { FastifyBaseLogger } from 'fastify'

const testServerPort = 3333
const testClusterPort = 56443
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
coerce,
defaulted,
enums,
Infer,
type Infer,
instance,
integer,
literal,
Expand Down
2 changes: 1 addition & 1 deletion src/handle-error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FastifyError, FastifyReply } from 'fastify'
import type { FastifyError, FastifyReply } from 'fastify'
import { badRequest, internalServerError, payloadTooLarge, unsupportedMediaType } from 'backend'

/**
Expand Down
4 changes: 2 additions & 2 deletions src/kube-config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import k8s from '@kubernetes/client-node'
import { Config } from './config.js'
import { BaseLogger } from 'pino'
import type { Config } from './config.js'
import type { BaseLogger } from 'pino'

export function loadKubeConfig (log: BaseLogger, config: Config): k8s.KubeConfig {
const from = config.kubeConfig.source
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'node:path'
import { Config, readConfigDirectory } from './config.js'
import { type Config, readConfigDirectory } from './config.js'
import { StructError } from 'superstruct'
import pino from 'pino'
import { pino } from 'pino'
import { startServer } from './server.js'
import { getPort } from './environment.js'
import { KubeConfig } from '@kubernetes/client-node'
Expand Down
6 changes: 3 additions & 3 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { backend, notFound } from 'backend'

import { fastifyStatic } from '@fastify/static'
import path from 'node:path'
import { fastify, FastifyBaseLogger } from 'fastify'
import { Config } from './config.js'
import { KubeConfig } from '@kubernetes/client-node'
import { fastify, type FastifyBaseLogger } from 'fastify'
import type { Config } from './config.js'
import type { KubeConfig } from '@kubernetes/client-node'
import { handleError } from './handle-error.js'

type CloseFunction = () => Promise<void>
Expand Down
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"compilerOptions": {
"lib": ["ES2020"],
"module": "ES2022",
"module": "NodeNext",
"target": "ES2022",
"moduleResolution": "Node",
"moduleResolution": "nodenext",
"strict": true,
"esModuleInterop": true,
"verbatimModuleSyntax": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"declaration": false,
Expand Down

0 comments on commit 02a1741

Please sign in to comment.