Ver código fonte

Fixes monaco-editor nightly build (needed for verification)

Henning Dieterichs 1 ano atrás
pai
commit
b0330f8eed
4 arquivos alterados com 87 adições e 8 exclusões
  1. 7 7
      package-lock.json
  2. 1 1
      package.json
  3. 4 0
      test/unit/all.js
  4. 75 0
      website/src/runner/debug.ts

+ 7 - 7
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": {

+ 1 - 1
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",

+ 4 - 0
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,

+ 75 - 0
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<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();