Skip to content

Commit

Permalink
Make html fixups backward compatible (UKGovernmentBEIS#226)
Browse files Browse the repository at this point in the history
This was fixed to support the latest bundling of inspect-ai, but I didn’t implement in a way that was compatible with older installations of inspect. this fixes that, performing in a backward compatible way by applying fixups specifically based upon what is present in the html.
  • Loading branch information
dragonstyle authored Aug 9, 2024
1 parent 6a857f8 commit 1f256ca
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 11 deletions.
4 changes: 4 additions & 0 deletions tools/vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.3.27

- Minor fix to view rendering across differing versions of Inspect.

## 0.3.26

- Properly preserve focus When showing the log viewer upon task completion.
Expand Down
2 changes: 1 addition & 1 deletion tools/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"author": {
"name": "UK AI Safety Institute"
},
"version": "0.3.26",
"version": "0.3.27",
"license": "MIT",
"homepage": "https://inspect.ai-safety-institute.org.uk/",
"repository": {
Expand Down
53 changes: 43 additions & 10 deletions tools/vscode/src/providers/logview/logview-webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,22 +294,55 @@ class InspectLogviewWebview extends InspectWebview<LogviewState> {
.asWebviewUri(Uri.joinPath(viewDirUri, path))
.toString();

// fixup css references
indexHtml = indexHtml.replace(/href="([^"]+)"/g, (_, p1: string) => {
return `href="${resourceUri(p1)}"`;
});

// fixup js references
indexHtml = indexHtml.replace(/src="([^"]+)"/g, (_, p1: string) => {
return `src="${resourceUri(p1)}"`;
});

// nonces for scripts
indexHtml = indexHtml.replace(
/<script([ >])/g,
`<script nonce="${nonce}"$1`
);

// Determine whether this is the old index.html format (before bundling),
// or the newer one. Fix up the html properly in each case

if (indexHtml.match(/"\.(\/App\.mjs)"/g)) {
// Old unbundle html
// fixup css references
indexHtml = indexHtml.replace(/href="\.([^"]+)"/g, (_, p1: string) => {
return `href="${resourceUri(p1)}"`;
});

// fixup js references
indexHtml = indexHtml.replace(/src="\.([^"]+)"/g, (_, p1: string) => {
return `src="${resourceUri(p1)}"`;
});

// fixup import maps
indexHtml = indexHtml.replace(
/": "\.([^?"]+)(["?])/g,
(_, p1: string, p2: string) => {
return `": "${resourceUri(p1)}${p2}`;
}
);

// fixup App.mjs
indexHtml = indexHtml.replace(/"\.(\/App\.mjs)"/g, (_, p1: string) => {
return `"${resourceUri(p1)}"`;
});

} else {
// New bundled html
// fixup css references
indexHtml = indexHtml.replace(/href="([^"]+)"/g, (_, p1: string) => {
return `href="${resourceUri(p1)}"`;
});

// fixup js references
indexHtml = indexHtml.replace(/src="([^"]+)"/g, (_, p1: string) => {
return `src="${resourceUri(p1)}"`;
});


}

return indexHtml;
} else {
return `
Expand Down

0 comments on commit 1f256ca

Please sign in to comment.