Skip to content

Commit

Permalink
Fixes monaco-editor nightly build (needed for verification)
Browse files Browse the repository at this point in the history
  • Loading branch information
hediet committed Jan 23, 2024
1 parent 6c7087b commit b0330f8
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 8 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"jsdom": "^19.0.0",
"jsonc-parser": "^3.0.0",
"mocha": "^9.2.0",
"monaco-editor-core": "0.45.0-rc",
"monaco-editor-core": "0.46.0-dev-20240109",
"parcel": "^2.7.0",
"pin-github-action": "^1.8.0",
"playwright": "^1.32.2",
Expand Down
4 changes: 4 additions & 0 deletions test/unit/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ global.UIEvent = tmp.window.UIEvent;
global.window = {
location: {},
navigator: tmp.window.navigator,
document: {
body: tmp.window.document.body,
addEventListener: (...args) => tmp.window.document.addEventListener(...args)
},
matchMedia: function () {
return {
matches: false,
Expand Down
75 changes: 75 additions & 0 deletions website/src/runner/debug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { loadMonaco } from "../monaco-loader";
import { IPreviewState } from "../shared";
import { LzmaCompressor } from "../website/utils/lzmaCompressor";
import "./style.scss";

let monacoPromise: Promise<any> | undefined = undefined;

async function initialize(state: IPreviewState) {
if (monacoPromise) {
throw new Error("already initialized");
}

const loadingContainerDiv = document.createElement("div");
loadingContainerDiv.className = "loader-container";
const loadingDiv = document.createElement("div");
loadingDiv.className = "loader";
loadingContainerDiv.appendChild(loadingDiv);
document.body.appendChild(loadingContainerDiv);

monacoPromise = loadMonaco(state.monacoSetup);
await monacoPromise;

loadingContainerDiv.remove();

const style = document.createElement("style");
style.id = "custom-style";
style.innerHTML = state.css; // CodeQL [SM03712] This is safe because the runner runs in an isolated iframe. This feature is essential to the functionality of the playground. // CodeQL [SM02688] This is safe because the runner runs in an isolated iframe. This feature is essential to the functionality of the playground.
document.body.appendChild(style);

document.body.innerHTML += state.html;

const js = state.js;

try {
eval(js); // CodeQL [SM01632] This is safe because the runner runs in an isolated iframe. This feature is essential to the functionality of the playground. // CodeQL [SM02688] This is safe because the runner runs in an isolated iframe. This feature is essential to the functionality of the playground.
} catch (err) {
const pre = document.createElement("pre");
pre.appendChild(
document.createTextNode(`${err}: ${(err as any).state}`)
);
document.body.insertBefore(pre, document.body.firstChild);
}
}

async function main() {
const compressor = new LzmaCompressor<IPreviewState>();
const stateStr = new URLSearchParams(window.location.search).get("state");
const state = compressor.decodeData<IPreviewState>(stateStr!);

const previousStateStr = localStorage.getItem("stateStr");
if (previousStateStr === stateStr) {
initialize(state);
} else {
// If it does not, show the load button
const loadButton = document.createElement("button");
loadButton.style.position = "absolute";
loadButton.style.top = "50%";
loadButton.style.left = "50%";
loadButton.style.transform = "translate(-50%, -50%)";
loadButton.innerText = "Load";
loadButton.style.padding = "10px 20px";
loadButton.onclick = () => {
loadButton.remove();
localStorage.setItem("stateStr", stateStr!);
initialize(state);
};
document.body.appendChild(loadButton);
}
}
main();

0 comments on commit b0330f8

Please sign in to comment.