From b0330f8eed00fb81f50b5d8ff17824cfe2e734c5 Mon Sep 17 00:00:00 2001 From: Henning Dieterichs Date: Tue, 23 Jan 2024 16:39:35 +0100 Subject: [PATCH] Fixes monaco-editor nightly build (needed for verification) --- package-lock.json | 14 +++---- package.json | 2 +- test/unit/all.js | 4 ++ website/src/runner/debug.ts | 75 +++++++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 8 deletions(-) create mode 100644 website/src/runner/debug.ts diff --git a/package-lock.json b/package-lock.json index ce0b2375..e4042ee5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,7 +25,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", @@ -5337,9 +5337,9 @@ "dev": true }, "node_modules/monaco-editor-core": { - "version": "0.45.0-rc", - "resolved": "https://registry.npmjs.org/monaco-editor-core/-/monaco-editor-core-0.45.0-rc.tgz", - "integrity": "sha512-iNh84qarOK8KhJNaxitm+07m9sCCoF4OxQXDOru1pOSPNFGpMEOV/35agYm9ab9RAm2CPGGHz27eJUY1FY0iKg==", + "version": "0.46.0-dev-20240109", + "resolved": "https://registry.npmjs.org/monaco-editor-core/-/monaco-editor-core-0.46.0-dev-20240109.tgz", + "integrity": "sha512-HK4YgFFpBpZ0zGbNbN/Julb8AXaB8Z7wuy4bgezj4MEjMYnTB4zn/CQ+ogCy+ZblVB6pD1X4vXN2mfiTqDeOMw==", "dev": true }, "node_modules/mri": { @@ -11069,9 +11069,9 @@ } }, "monaco-editor-core": { - "version": "0.45.0-rc", - "resolved": "https://registry.npmjs.org/monaco-editor-core/-/monaco-editor-core-0.45.0-rc.tgz", - "integrity": "sha512-iNh84qarOK8KhJNaxitm+07m9sCCoF4OxQXDOru1pOSPNFGpMEOV/35agYm9ab9RAm2CPGGHz27eJUY1FY0iKg==", + "version": "0.46.0-dev-20240109", + "resolved": "https://registry.npmjs.org/monaco-editor-core/-/monaco-editor-core-0.46.0-dev-20240109.tgz", + "integrity": "sha512-HK4YgFFpBpZ0zGbNbN/Julb8AXaB8Z7wuy4bgezj4MEjMYnTB4zn/CQ+ogCy+ZblVB6pD1X4vXN2mfiTqDeOMw==", "dev": true }, "mri": { diff --git a/package.json b/package.json index 52641b0b..d03821cb 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/unit/all.js b/test/unit/all.js index 44a43feb..2cb2b0f7 100644 --- a/test/unit/all.js +++ b/test/unit/all.js @@ -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, diff --git a/website/src/runner/debug.ts b/website/src/runner/debug.ts new file mode 100644 index 00000000..d0a81a36 --- /dev/null +++ b/website/src/runner/debug.ts @@ -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 | 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(); + const stateStr = new URLSearchParams(window.location.search).get("state"); + const state = compressor.decodeData(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();