From a78feabbd99bc889fc96e4f3ba03048a4bba095e Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Mon, 19 May 2025 09:18:58 -0500 Subject: [PATCH] More fixes, cc @junlarsen --- lib/app/compilation-env.ts | 11 +---- lib/app/main.ts | 14 ++++--- lib/app/static-assets.ts | 7 +--- lib/compilation-env.ts | 4 +- ...lation-env.ts => compilation-env-tests.ts} | 40 +++++++++---------- 5 files changed, 32 insertions(+), 44 deletions(-) rename test/{compilation-env.ts => compilation-env-tests.ts} (86%) diff --git a/lib/app/compilation-env.ts b/lib/app/compilation-env.ts index a0011aac8..ffe69debe 100644 --- a/lib/app/compilation-env.ts +++ b/lib/app/compilation-env.ts @@ -30,13 +30,6 @@ import {CompileHandler} from '../handlers/compile.js'; import {PropertyGetter} from '../properties.interfaces.js'; import {CompilerProps} from '../properties.js'; -export interface CompilationEnvResult { - compilationQueue: CompilationQueue; - compilationEnvironment: CompilationEnvironment; - compileHandler: CompileHandler; - formattingService: FormattingService; -} - /** * Initialize the compilation environment components * @param appArgs - Application arguments @@ -50,7 +43,7 @@ export async function initializeCompilationEnvironment( compilerProps: CompilerProps, ceProps: PropertyGetter, awsProps: PropertyGetter, -): Promise { +) { const formattingService = new FormattingService(); await formattingService.initialize(ceProps); @@ -67,9 +60,7 @@ export async function initializeCompilationEnvironment( compilationEnvironment.setCompilerFinder(compileHandler.findCompiler.bind(compileHandler)); return { - compilationQueue, compilationEnvironment, compileHandler, - formattingService, }; } diff --git a/lib/app/main.ts b/lib/app/main.ts index 30ef465df..db3cca5c2 100644 --- a/lib/app/main.ts +++ b/lib/app/main.ts @@ -25,8 +25,6 @@ import fs from 'node:fs/promises'; import path from 'node:path'; -import _ from 'underscore'; - import type {AppArguments} from '../app.interfaces.js'; import {initializeCompilationEnvironment} from './compilation-env.js'; import {setupCompilerChangeHandling} from './compiler-changes.js'; @@ -68,8 +66,12 @@ export async function initialiseApplication(options: ApplicationOptions): Promis RemoteExecutionQuery.initRemoteExecutionArchs(ceProps, appArgs.env); - const {compilationQueue, compilationEnvironment, compileHandler, formattingService} = - await initializeCompilationEnvironment(appArgs, compilerProps, ceProps, awsProps); + const {compilationEnvironment, compileHandler} = await initializeCompilationEnvironment( + appArgs, + compilerProps, + ceProps, + awsProps, + ); const clientOptionsHandler = new ClientOptionsHandler(sources, compilerProps, appArgs); const storageType = getStorageTypeByKey(storageSolution); @@ -84,8 +86,8 @@ export async function initialiseApplication(options: ApplicationOptions): Promis const controllers = setupControllersAndHandlers( compileHandler, - formattingService, - compilationQueue, + compilationEnvironment.formattingService, + compilationEnvironment.compilationQueue, healthCheckFilePath, isExecutionWorker, formDataHandler, diff --git a/lib/app/static-assets.ts b/lib/app/static-assets.ts index 1765c815a..30def38b8 100644 --- a/lib/app/static-assets.ts +++ b/lib/app/static-assets.ts @@ -30,12 +30,7 @@ import urljoin from 'url-join'; import {ElementType} from '../../shared/common-utils.js'; import {logger} from '../logger.js'; -import {ServerOptions} from './server.interfaces.js'; - -/** - * Function signature for handling Pug template requires - */ -export type PugRequireHandler = (path: string) => string; +import {PugRequireHandler, ServerOptions} from './server.interfaces.js'; /** * Creates a default handler for Pug requires diff --git a/lib/compilation-env.ts b/lib/compilation-env.ts index 2b0ac0897..032793fdd 100644 --- a/lib/compilation-env.ts +++ b/lib/compilation-env.ts @@ -48,7 +48,7 @@ type FindCompiler = (langId: LanguageKey, compilerId: string) => BaseCompiler | export class CompilationEnvironment { ceProps: PropertyGetter; awsProps: PropFunc; - compilationQueue: CompilationQueue | undefined; + compilationQueue: CompilationQueue; compilerProps: PropFunc; okOptions: RegExp; badOptions: RegExp; @@ -67,7 +67,7 @@ export class CompilationEnvironment { constructor( compilerProps: CompilerProps, awsProps: PropFunc, - compilationQueue: CompilationQueue | undefined, + compilationQueue: CompilationQueue, public formattingService: FormattingService, doCache?: boolean, ) { diff --git a/test/compilation-env.ts b/test/compilation-env-tests.ts similarity index 86% rename from test/compilation-env.ts rename to test/compilation-env-tests.ts index 1b97d4f81..fdc5630d9 100644 --- a/test/compilation-env.ts +++ b/test/compilation-env-tests.ts @@ -26,6 +26,7 @@ import './utils.js'; import {beforeAll, describe, expect, it} from 'vitest'; import {CompilationEnvironment} from '../lib/compilation-env.js'; +import {CompilationQueue} from '../lib/compilation-queue.js'; import {FormattingService} from '../lib/formatting-service.js'; import {CompilerProps, fakeProps} from '../lib/properties.js'; @@ -36,48 +37,47 @@ const props = { }; describe('Compilation environment', () => { - let compilerProps; + let compilerProps: CompilerProps; + let compilationQueue: CompilationQueue; beforeAll(() => { compilerProps = new CompilerProps({}, fakeProps(props)); + compilationQueue = new CompilationQueue(1, 1000, 1000); }); it('Should cache by default', async () => { - // TODO: Work will need to be done here when CompilationEnvironment's constructor is typed better - const ce = new CompilationEnvironment( - compilerProps, - fakeProps({}), - undefined, - new FormattingService(), - undefined, - ); + const ce = new CompilationEnvironment(compilerProps, fakeProps({}), compilationQueue, new FormattingService()); await expect(ce.cacheGet('foo')).resolves.toBeNull(); await ce.cachePut('foo', {res: 'bar'}, undefined); await expect(ce.cacheGet('foo')).resolves.toEqual({res: 'bar'}); await expect(ce.cacheGet('baz')).resolves.toBeNull(); }); it('Should cache when asked', async () => { - const ce = new CompilationEnvironment(compilerProps, fakeProps({}), undefined, new FormattingService(), true); + const ce = new CompilationEnvironment( + compilerProps, + fakeProps({}), + compilationQueue, + new FormattingService(), + true, + ); await expect(ce.cacheGet('foo')).resolves.toBeNull(); await ce.cachePut('foo', {res: 'bar'}, undefined); await expect(ce.cacheGet('foo')).resolves.toEqual({res: 'bar'}); }); it("Shouldn't cache when asked", async () => { - // TODO: Work will need to be done here when CompilationEnvironment's constructor is typed better - const ce = new CompilationEnvironment(compilerProps, fakeProps({}), undefined, new FormattingService(), false); + const ce = new CompilationEnvironment( + compilerProps, + fakeProps({}), + compilationQueue, + new FormattingService(), + false, + ); await expect(ce.cacheGet('foo')).resolves.toBeNull(); await ce.cachePut('foo', {res: 'bar'}, undefined); await expect(ce.cacheGet('foo')).resolves.toBeNull(); }); it('Should filter bad options', () => { - // TODO: Work will need to be done here when CompilationEnvironment's constructor is typed better - const ce = new CompilationEnvironment( - compilerProps, - fakeProps({}), - undefined, - new FormattingService(), - undefined, - ); + const ce = new CompilationEnvironment(compilerProps, fakeProps({}), compilationQueue, new FormattingService()); expect(ce.findBadOptions(['-O3', '-flto'])).toEqual([]); expect(ce.findBadOptions(['-O3', '-plugin'])).toEqual(['-plugin']); });