Repository: compiler-explorer/compiler-explorer
Pull request #7382 (2025-02-09 19:48:24)

Add missing js suffixes to imports
Seems to be required by es6 and accepted by the current es5 



Patch:
diff --git a/lib/base-compiler.ts b/lib/base-compiler.ts
index c76dd0ef2..13897946f 100644
--- a/lib/base-compiler.ts
+++ b/lib/base-compiler.ts
@@ -120,6 +120,7 @@ import type {IAsmParser} from './parsers/asm-parser.interfaces.js';
 import {AsmParser} from './parsers/asm-parser.js';
 import {LlvmPassDumpParser} from './parsers/llvm-pass-dump-parser.js';
 import type {PropertyGetter} from './properties.interfaces.js';
+import {propsFor} from './properties.js';
 import {HeaptrackWrapper} from './runtime-tools/heaptrack-wrapper.js';
 import {LibSegFaultHelper} from './runtime-tools/libsegfault-helper.js';
 import {SentryCapture} from './sentry.js';
@@ -211,6 +212,8 @@ export class BaseCompiler {
     protected externalparser: null | ExternalParserBase;
     protected supportedLibraries?: Record<string, OptionsHandlerLibrary>;
     protected packager: Packager;
+    protected executionType: string;
+    protected sandboxType: string;
     protected defaultRpathFlag = '-Wl,-rpath,';
     private static objdumpAndParseCounter = new PromClient.Counter({
         name: 'ce_objdumpandparsetime_total',
@@ -255,6 +258,10 @@ export class BaseCompiler {
             this.compiler.disabledFilters = (this.compiler.disabledFilters as any).split(',');
         }
 
+        const execProps = propsFor('execution');
+        this.executionType = execProps('executionType', 'none');
+        this.sandboxType = execProps('sandboxType', 'none');
+
         this.asm = new AsmParser(this.compilerProps);
         const irDemangler = new LLVMIRDemangler(this.compiler.demangler, this);
         this.llvmIr = new LlvmIrParser(this.compilerProps, irDemangler);
diff --git a/lib/clientstate-normalizer.ts b/lib/clientstate-normalizer.ts
index dec7b5db1..5b44edccb 100644
--- a/lib/clientstate-normalizer.ts
+++ b/lib/clientstate-normalizer.ts
@@ -339,10 +339,7 @@ export class ClientStateNormalizer {
                     const session = this.normalized.findSessionById(file.editorId);
                     if (session) {
                         file.content = session.source;
-                        if (!file.filename && session.filename) {
-                            // it's fine if the session doesn't contain the filename, the filename in the tree is always leading
-                            file.filename = session.filename;
-                        }
+                        file.filename = session.filename;
                     }
                 }
             }
diff --git a/lib/compilers/clean.ts b/lib/compilers/clean.ts
index 8cbd1f848..6a27ea619 100644
--- a/lib/compilers/clean.ts
+++ b/lib/compilers/clean.ts
@@ -29,7 +29,6 @@ import fs from 'fs-extra';
 import type {ExecutionOptionsWithEnv} from '../../types/compilation/compilation.interfaces.js';
 import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js';
 import {BaseCompiler} from '../base-compiler.js';
-import {propsFor} from '../properties.js';
 import * as utils from '../utils.js';
 
 export class CleanCompiler extends BaseCompiler {
@@ -115,8 +114,7 @@ export class CleanCompiler extends BaseCompiler {
         await fs.mkdir(execOptions.env.CLEANABCPATH);
         await fs.mkdir(execOptions.env.CLEANOPATH);
 
-        const execProps = propsFor('execution');
-        if (execProps<string>('executionType') === 'nsjail') {
+        if (this.executionType === 'nsjail') {
             execOptions.env.CLEANABCPATH = '/app/Clean System Files';
             execOptions.env.CLEANOPATH = '/app/obj';
         }
diff --git a/lib/handlers/route-api.ts b/lib/handlers/route-api.ts
index a1ddb6b7e..b2f7caff4 100644
--- a/lib/handlers/route-api.ts
+++ b/lib/handlers/route-api.ts
@@ -29,7 +29,7 @@ import express from 'express';
 import {AppDefaultArguments, CompilerExplorerOptions} from '../../app.js';
 import {isString} from '../../shared/common-utils.js';
 import {Language} from '../../types/languages.interfaces.js';
-import {assert} from '../assert.js';
+import {assert, unwrap} from '../assert.js';
 import {ClientStateGoldenifier, ClientStateNormalizer} from '../clientstate-normalizer.js';
 import {ClientState} from '../clientstate.js';
 import {CompilationEnvironment} from '../compilation-env.js';
@@ -281,7 +281,7 @@ export class RouteAPI {
 
                     if (tree.isCMakeProject) {
                         const firstSource = tree.files.find(file => {
-                            return file.filename?.startsWith('CMakeLists.txt');
+                            return unwrap(file.filename).startsWith('CMakeLists.txt');
                         });
 
                         if (firstSource) {
@@ -289,7 +289,7 @@ export class RouteAPI {
                         }
                     } else {
                         const firstSource = tree.files.find(file => {
-                            return file.filename?.startsWith('example.');
+                            return unwrap(file.filename).startsWith('example.');
                         });
 
                         if (firstSource) {
diff --git a/static/panes/device-view.ts b/static/panes/device-view.ts
index 75403605e..70b4114a9 100644
--- a/static/panes/device-view.ts
+++ b/static/panes/device-view.ts
@@ -36,8 +36,8 @@ import {Hub} from '../hub.js';
 import {InstructionSet} from '../instructionsets.js';
 import * as monacoConfig from '../monaco-config.js';
 import * as utils from '../utils.js';
-import {Alert} from '../widgets/alert';
-import {Compiler} from './compiler';
+import {Alert} from '../widgets/alert.js';
+import {Compiler} from './compiler.js';
 import {DeviceAsmState} from './device-view.interfaces.js';
 import {MonacoPaneState} from './pane.interfaces.js';
 import {MonacoPane} from './pane.js';
diff --git a/static/panes/editor.ts b/static/panes/editor.ts
index 93cf019e4..f5a3b48cf 100644
--- a/static/panes/editor.ts
+++ b/static/panes/editor.ts
@@ -47,7 +47,7 @@ import {EditorState, LanguageSelectData} from './editor.interfaces.js';
 import {MonacoPaneState, PaneState} from './pane.interfaces.js';
 import {MonacoPane} from './pane.js';
 import IModelDeltaDecoration = editor.IModelDeltaDecoration;
-import type {escape_html} from 'tom-select/dist/types/utils';
+import type {escape_html} from 'tom-select/dist/types/utils.js';
 import {escapeHTML, isString} from '../../shared/common-utils.js';
 import {CompilationResult} from '../../types/compilation/compilation.interfaces.js';
 import {CompilerInfo} from '../../types/compiler.interfaces.js';
diff --git a/static/print-view.ts b/static/print-view.ts
index fed6a633a..284b79c4c 100644
--- a/static/print-view.ts
+++ b/static/print-view.ts
@@ -26,10 +26,10 @@ import $ from 'jquery';
 
 import * as monaco from 'monaco-editor';
 
-import {unwrap} from './assert';
-import {EventHub} from './event-hub';
-import {Hub} from './hub';
-import {Themer, themes} from './themes';
+import {unwrap} from './assert.js';
+import {EventHub} from './event-hub.js';
+import {Hub} from './hub.js';
+import {Themer, themes} from './themes.js';
 
 export class Printerinator {
     printview: JQuery;
diff --git a/static/widgets/compiler-picker-popup.ts b/static/widgets/compiler-picker-popup.ts
index 25d1ed847..f3594b19c 100644
--- a/static/widgets/compiler-picker-popup.ts
+++ b/static/widgets/compiler-picker-popup.ts
@@ -26,12 +26,12 @@ import $ from 'jquery';
 
 import * as sifter from '@orchidjs/sifter';
 
-import {escapeHTML, intersection, remove, unique} from '../../shared/common-utils';
-import {CompilerInfo} from '../../types/compiler.interfaces';
-import {unwrap, unwrapString} from '../assert';
-import {CompilerService} from '../compiler-service';
-import {highlight} from '../highlight';
-import {CompilerPicker} from './compiler-picker';
+import {escapeHTML, intersection, remove, unique} from '../../shared/common-utils.js';
+import {CompilerInfo} from '../../types/compiler.interfaces.js';
+import {unwrap, unwrapString} from '../assert.js';
+import {CompilerService} from '../compiler-service.js';
+import {highlight} from '../highlight.js';
+import {CompilerPicker} from './compiler-picker.js';
 
 export class CompilerPickerPopup {
     modal: JQuery<HTMLElement>;
diff --git a/static/widgets/compiler-version-info.ts b/static/widgets/compiler-version-info.ts
index c8ce72aac..44da2e15d 100644
--- a/static/widgets/compiler-version-info.ts
+++ b/static/widgets/compiler-version-info.ts
@@ -23,7 +23,7 @@
 // POSSIBILITY OF SUCH DAMAGE.
 
 import $ from 'jquery';
-import {escapeHTML} from '../../shared/common-utils';
+import {escapeHTML} from '../../shared/common-utils.js';
 import {options} from '../options.js';
 
 export type CompilerVersionInfo = {version: string; fullVersion?: string};
diff --git a/static/widgets/libs-widget.ts b/static/widgets/libs-widget.ts
index b27471c31..bcf133b3d 100644
--- a/static/widgets/libs-widget.ts
+++ b/static/widgets/libs-widget.ts
@@ -28,7 +28,7 @@ import {localStorage} from '../local.js';
 import {Library, LibraryVersion} from '../options.interfaces.js';
 import {options} from '../options.js';
 import {SentryCapture} from '../sentry.js';
-import {Alert} from './alert';
+import {Alert} from './alert.js';
 import {Lib, WidgetState} from './libs-widget.interfaces.js';
 
 const FAV_LIBS_STORE_KEY = 'favlibs';
diff --git a/static/widgets/load-save.ts b/static/widgets/load-save.ts
index 3ce617252..58549e7d1 100644
--- a/static/widgets/load-save.ts
+++ b/static/widgets/load-save.ts
@@ -27,7 +27,7 @@ import $ from 'jquery';
 import _ from 'underscore';
 import {escapeHTML} from '../../shared/common-utils.js';
 import {Language} from '../../types/languages.interfaces.js';
-import {SourceApiEntry} from '../../types/source.interfaces';
+import {SourceApiEntry} from '../../types/source.interfaces.js';
 import {unwrap, unwrapString} from '../assert.js';
 import {localStorage} from '../local.js';
 import {Alert} from './alert.js';


Test patch:
diff --git a/test/library-tests.ts b/test/library-tests.ts
index c1fc0c332..d01d6ab69 100644
--- a/test/library-tests.ts
+++ b/test/library-tests.ts
@@ -111,7 +111,7 @@ describe('Library directories (c++)', () => {
         } as unknown as ClientOptionsType);
     });
 
-    it('should add libpaths and link to libraries 1', () => {
+    it('should add libpaths and link to libraries', () => {
         const links = compiler.getSharedLibraryLinks([{id: 'fmt', version: '10'}]);
         expect(links).toContain('-lfmtd');
 
@@ -133,7 +133,9 @@ describe('Library directories (c++)', () => {
         expect(qtpaths).toContain('-L' + path.normalize('/tmp/compiler-explorer-compiler-123/qt/lib'));
     });
 
-    it('should add libpaths and link to libraries 2', () => {
+    it('should add libpaths and link to libraries when using nsjail', () => {
+        (compiler as any).executionType = 'nsjail';
+
         const fmtpaths = (compiler as any).getSharedLibraryPathsAsArguments(
             [{id: 'fmt', version: '10'}],
             undefined,
@@ -154,6 +156,8 @@ describe('Library directories (c++)', () => {
     });
 
     it('should add extra include paths when using packagedheaders', () => {
+        (compiler as any).executionType = 'nsjail';
+
         const fmtpaths = (compiler as any).getIncludeArguments(
             [{id: 'fmt', version: '10'}],
             '/tmp/compiler-explorer-compiler-123',
@@ -172,6 +176,8 @@ describe('Library directories (c++)', () => {
     });
 
     it('should set LD_LIBRARY_PATH when executing', () => {
+        (compiler as any).sandboxType = 'nsjail';
+
         const qtpaths = (compiler as BaseCompiler).getSharedLibraryPathsAsLdLibraryPathsForExecution(
             {
                 libraries: [{id: 'qt', version: '660'}],
@@ -189,6 +195,8 @@ describe('Library directories (c++)', () => {
     });
 
     it('should add libpaths and link when statically linking', () => {
+        (compiler as any).executionType = 'nsjail';
+
         const staticlinks = compiler.getStaticLibraryLinks([{id: 'cpptrace', version: '030'}], []);
         expect(staticlinks).toContain('-lcpptrace');
         expect(staticlinks).toContain('-ldwarf');
@@ -264,6 +272,8 @@ describe('Library directories (fortran)', () => {
     });
 
     it('should not add libpaths and link to libraries when they dont exist', async () => {
+        (compiler as any).executionType = 'nsjail';
+
         const dirPath = await compiler.newTempDir();
 
         const libPath = path.join(dirPath, 'json_fortran/lib');
@@ -279,6 +289,8 @@ describe('Library directories (fortran)', () => {
     });
 
     it('should add libpaths and link to libraries', async () => {
+        (compiler as any).executionType = 'nsjail';
+
         const dirPath = await compiler.newTempDir();
         const libPath = path.join(dirPath, 'json_fortran/lib');
         await fs.mkdir(libPath, {recursive: true});
@@ -303,6 +315,7 @@ describe('Library directories (fortran)', () => {
     });
 
     it('should add includes for packaged libraries', async () => {
+        (compiler as any).executionType = 'nsjail';
         (compiler as any).compiler.includeFlag = '-isystem';
 
         const dirPath = await compiler.newTempDir();
@@ -315,6 +328,7 @@ describe('Library directories (fortran)', () => {
     });
 
     it('should add includes for non-packaged C libraries', async () => {
+        (compiler as any).executionType = 'nsjail';
         (compiler as any).compiler.includeFlag = '-isystem';
 
         const dirPath = await compiler.newTempDir();