Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit cb32dd4

Browse files
authored
Merge pull request #56 from Ricbet/feat/upgrade-monaco-version
feat: adapt to the latest github
2 parents 0f4ec9b + a9f60a9 commit cb32dd4

File tree

7 files changed

+84
-110
lines changed

7 files changed

+84
-110
lines changed

package.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"author": "Henning Dieterichs <[email protected]>",
66
"license": "UNLICENSED",
77
"scripts": {
8-
"dev": "webpack --watch --mode development --env=use-cdn-for-monaco=true",
8+
"dev": "NODE_OPTIONS=--openssl-legacy-provider webpack --watch --mode development",
99
"dev-without-cdn": "webpack --watch --mode development",
10-
"build": "yarn build-js && yarn bundle",
10+
"build": "NODE_OPTIONS=--openssl-legacy-provider yarn build-js && yarn bundle",
1111
"build-js": "webpack --mode production",
1212
"bundle": "yarn shx rm -rf ./dist/extension.zip && yarn jszip-cli add -o ./dist/extension.zip -i *.map dist manifest.json logo.drawio.png",
1313
"update-actions": "yarn pin-github-action ./.github/workflows/master.yml && yarn prettier ./.github/workflows/master.yml -w"
@@ -19,12 +19,13 @@
1919
"@types/mini-css-extract-plugin": "^1.2.2",
2020
"@types/webpack": "^4.41.6",
2121
"clean-webpack-plugin": "^3.0.0",
22-
"css-loader": "^5.1.3",
22+
"css-loader": "^7.1.2",
2323
"file-loader": "^6.2.0",
2424
"fork-ts-checker-webpack-plugin": "^6.2.0",
2525
"html-webpack-plugin": "^5.3.1",
2626
"mini-css-extract-plugin": "^1.3.3",
2727
"monaco-editor-webpack-plugin": "~7.0.1",
28+
"postcss": "^8.4.47",
2829
"prettier": "^2.2.1",
2930
"raw-loader": "^4.0.0",
3031
"sass": "^1.25.0",
@@ -41,7 +42,7 @@
4142
"@types/copy-webpack-plugin": "^6.4.0",
4243
"copy-webpack-plugin": "^8.0.0",
4344
"gemoji": "^6.1.0",
44-
"monaco-editor": "~0.34.1",
45+
"monaco-editor": "~0.52.2",
4546
"pin-github-action": "^1.1.3"
4647
}
47-
}
48+
}

src/content-script-main/EditorWrapper.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ HTMLTextAreaElement.prototype.addEventListener = function (
4242
e.clipboardData &&
4343
e.clipboardData.files.length > 0 &&
4444
(e.currentTarget as any)?.className ===
45-
"inputarea monaco-mouse-cursor-text"
45+
"inputarea monaco-mouse-cursor-text"
4646
) {
4747
// Disable monaco paste handler for files, as GitHub handles this already
4848
return;
@@ -92,7 +92,7 @@ export class EditorWrapper {
9292

9393
private fullscreen = false;
9494
private showPreview = true;
95-
private editorHeight: number = 200;
95+
private editorHeight: number = this.textArea.offsetHeight ?? 200;
9696

9797
private constructor(
9898
private readonly textArea: HTMLTextAreaElement,

src/content-script-main/index.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ async function main() {
3434
);
3535

3636
function updateDocument() {
37-
for (const textArea of [
38-
...(document.getElementsByClassName(
39-
"comment-form-textarea"
40-
) as any),
41-
]) {
37+
const issueCommentBox = document.getElementById("issue_body");
38+
const wikiBox = document.getElementById("gollum-editor-body");
39+
for (const textArea of [issueCommentBox, wikiBox] as any[]) {
40+
if (!textArea) {
41+
continue;
42+
}
43+
4244
EditorWrapper.wrap(
4345
textArea,
4446
monaco,

src/monaco-loader.ts

+4-36
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,8 @@ import type * as monaco from "monaco-editor";
33
export type Monaco = typeof monaco;
44

55
export async function loadMonaco(): Promise<Monaco> {
6-
if (process.env.USE_CDN_FOR_MONACO === "1") {
7-
console.warn("Loading monaco from CDN...");
8-
9-
function getMonaco(): Monaco | undefined {
10-
return (window as any).monaco;
11-
}
12-
13-
function loadScript(url: string) {
14-
const pluginScript = document.createElement("script");
15-
pluginScript.type = "text/javascript";
16-
const p = new Promise((res) => {
17-
pluginScript.onload = res;
18-
});
19-
pluginScript.src = url;
20-
document.getElementsByTagName("head")[0].appendChild(pluginScript);
21-
return p;
22-
}
23-
24-
const baseUrl =
25-
"https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.34.1/min/vs";
26-
await loadScript(`${baseUrl}/loader.min.js`);
27-
const $require = eval("require"); // to prevent webpack from compiling the require
28-
$require.config({
29-
paths: {
30-
vs: baseUrl,
31-
},
32-
});
33-
34-
return new Promise((res) => {
35-
$require(["vs/editor/editor.main"], function () {
36-
res(getMonaco()!);
37-
});
38-
});
39-
} else {
40-
return require("monaco-editor");
41-
}
6+
/**
7+
* CSP policy prevents loading monaco cdn on github
8+
*/
9+
return require("monaco-editor");
4210
}

src/settings.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const defaultSettings: MonacoOptions & {
2525
contextmenu: true,
2626
copyWithSyntaxHighlighting: true,
2727
cursorBlinking: "blink",
28-
cursorSmoothCaretAnimation: false,
28+
cursorSmoothCaretAnimation: "off",
2929
cursorStyle: "line",
3030
// If cursorStyle is "line", the next one also applies:
3131
cursorWidth: 0,
@@ -62,12 +62,12 @@ export const defaultSettings: MonacoOptions & {
6262
multiCursorMergeOverlapping: true,
6363
multiCursorModifier: "alt",
6464
multiCursorPaste: "spread",
65-
occurrencesHighlight: true,
65+
occurrencesHighlight: "singleFile",
6666
overviewRulerBorder: true,
6767
quickSuggestions: true,
6868
quickSuggestionsDelay: 10,
6969
renderControlCharacters: false,
70-
renderFinalNewline: true,
70+
renderFinalNewline: "on",
7171
renderLineHighlight: "line", // The docs says the default is "all", but this is wrong
7272
renderWhitespace: "none",
7373
roundedSelection: true,
@@ -91,7 +91,7 @@ export const defaultSettings: MonacoOptions & {
9191
tabSize: 4,
9292
trimAutoWhitespace: true,
9393
useTabStops: true,
94-
wordBasedSuggestions: true,
94+
wordBasedSuggestions: "allDocuments",
9595
wordSeparators: "`~!@#$%^&*()-=+[{]}\\|;:'\",.<>/?",
9696
wrappingIndent: "none",
9797
wrappingStrategy: "simple",

webpack.config.ts

+3-11
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import CopyWebpackPlugin = require("copy-webpack-plugin");
99
const r = (file: string) => path.resolve(__dirname, file);
1010

1111
module.exports = (env: any) => {
12-
const useCdnForMonaco = !!env["use-cdn-for-monaco"];
1312
return {
1413
entry: {
1514
"content-script": r("./src/content-script"),
@@ -60,9 +59,6 @@ module.exports = (env: any) => {
6059
plugins: [
6160
new MiniCssExtractPlugin(),
6261
new CleanWebpackPlugin(),
63-
new webpack.EnvironmentPlugin({
64-
USE_CDN_FOR_MONACO: useCdnForMonaco ? "1" : "0",
65-
}),
6662
new ForkTsCheckerWebpackPlugin(),
6763
new CopyWebpackPlugin({
6864
patterns: [
@@ -73,13 +69,9 @@ module.exports = (env: any) => {
7369
],
7470
}),
7571
new CleanWebpackPlugin(),
76-
...(useCdnForMonaco
77-
? []
78-
: [
79-
new MonacoWebpackPlugin({
80-
languages: ["markdown"],
81-
}),
82-
]),
72+
new MonacoWebpackPlugin({
73+
languages: ["markdown"],
74+
}),
8375
],
8476
} as webpack.Configuration;
8577
};

yarn.lock

+58-47
Original file line numberDiff line numberDiff line change
@@ -738,11 +738,6 @@ camel-case@^4.1.1:
738738
pascal-case "^3.1.2"
739739
tslib "^2.0.3"
740740

741-
camelcase@^6.2.0:
742-
version "6.2.0"
743-
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.2.0.tgz#924af881c9d525ac9d87f40d964e5cea982a1809"
744-
integrity sha512-c7wVvbw3f37nuobQNtgsgG9POC9qMbNuMQmTCqZv23b6MIz0fcYpBiOlv9gEN/hdLdnZTDQhg6e9Dq5M1vKvfg==
745-
746741
caniuse-lite@^1.0.30001181:
747742
version "1.0.30001203"
748743
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001203.tgz#a7a34df21a387d9deffcd56c000b8cf5ab540580"
@@ -835,7 +830,7 @@ color-name@~1.1.4:
835830
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
836831
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==
837832

838-
colorette@^1.2.1, colorette@^1.2.2:
833+
colorette@^1.2.1:
839834
version "1.2.2"
840835
resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.2.2.tgz#cbcc79d5e99caea2dbf10eb3a26fd8b3e6acfa94"
841836
integrity sha512-MKGMzyfeuutC/ZJ1cba9NqcNpfeqMUcYmyF1ZFY6/Cn7CNSAKx6a+s48sqLqyAiZuaP2TcqMhoo+dlwFnVxT9w==
@@ -919,23 +914,19 @@ cross-spawn@^7.0.3:
919914
shebang-command "^2.0.0"
920915
which "^2.0.1"
921916

922-
css-loader@^5.1.3:
923-
version "5.1.3"
924-
resolved "https://registry.yarnpkg.com/css-loader/-/css-loader-5.1.3.tgz#87f6fc96816b20debe3cf682f85c7e56a963d0d1"
925-
integrity sha512-CoPZvyh8sLiGARK3gqczpfdedbM74klGWurF2CsNZ2lhNaXdLIUks+3Mfax3WBeRuHoglU+m7KG/+7gY6G4aag==
917+
css-loader@^7.1.2:
918+
version "7.1.2"
919+
resolved "https://registry.yarnpkg.com/css-loader/-/css-loader-7.1.2.tgz#64671541c6efe06b0e22e750503106bdd86880f8"
920+
integrity sha512-6WvYYn7l/XEGN8Xu2vWFt9nVzrCn39vKyTEFf/ExEyoksJjjSZV/0/35XPlMbpnr6VGhZIUg5yJrL8tGfes/FA==
926921
dependencies:
927-
camelcase "^6.2.0"
928-
cssesc "^3.0.0"
929922
icss-utils "^5.1.0"
930-
loader-utils "^2.0.0"
931-
postcss "^8.2.8"
932-
postcss-modules-extract-imports "^3.0.0"
933-
postcss-modules-local-by-default "^4.0.0"
934-
postcss-modules-scope "^3.0.0"
923+
postcss "^8.4.33"
924+
postcss-modules-extract-imports "^3.1.0"
925+
postcss-modules-local-by-default "^4.0.5"
926+
postcss-modules-scope "^3.2.0"
935927
postcss-modules-values "^4.0.0"
936-
postcss-value-parser "^4.1.0"
937-
schema-utils "^3.0.0"
938-
semver "^7.3.4"
928+
postcss-value-parser "^4.2.0"
929+
semver "^7.5.4"
939930

940931
css-select@^2.0.2:
941932
version "2.1.0"
@@ -1811,15 +1802,15 @@ monaco-editor-webpack-plugin@~7.0.1:
18111802
dependencies:
18121803
loader-utils "^2.0.2"
18131804

1814-
monaco-editor@~0.34.1:
1815-
version "0.34.1"
1816-
resolved "https://registry.yarnpkg.com/monaco-editor/-/monaco-editor-0.34.1.tgz#1b75c4ad6bc4c1f9da656d740d98e0b850a22f87"
1817-
integrity sha512-FKc80TyiMaruhJKKPz5SpJPIjL+dflGvz4CpuThaPMc94AyN7SeC9HQ8hrvaxX7EyHdJcUY5i4D0gNyJj1vSZQ==
1805+
monaco-editor@~0.52.2:
1806+
version "0.52.2"
1807+
resolved "https://registry.yarnpkg.com/monaco-editor/-/monaco-editor-0.52.2.tgz#53c75a6fcc6802684e99fd1b2700299857002205"
1808+
integrity sha512-GEQWEZmfkOGLdd3XK8ryrfWz3AIP8YymVXiPHEdewrUq7mh0qrKrfHLNCXcbB6sTnMLnOZ3ztSiKcciFUkIJwQ==
18181809

1819-
nanoid@^3.1.20:
1820-
version "3.1.22"
1821-
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.1.22.tgz#b35f8fb7d151990a8aebd5aa5015c03cf726f844"
1822-
integrity sha512-/2ZUaJX2ANuLtTvqTlgqBQNJoQO398KyJgZloL0PZkC0dpysjncRUPsFe3DUPzz/y3h+u7C46np8RMuvF3jsSQ==
1810+
nanoid@^3.3.7:
1811+
version "3.3.7"
1812+
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.7.tgz#d0c301a691bc8d54efa0a2226ccf3fe2fd656bd8"
1813+
integrity sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==
18231814

18241815
neo-async@^2.6.2:
18251816
version "2.6.2"
@@ -2016,6 +2007,11 @@ path-type@^4.0.0:
20162007
resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b"
20172008
integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==
20182009

2010+
picocolors@^1.1.0:
2011+
version "1.1.1"
2012+
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.1.1.tgz#3d321af3eab939b083c8f929a1d12cda81c26b6b"
2013+
integrity sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==
2014+
20192015
picomatch@^2.0.4, picomatch@^2.0.5, picomatch@^2.2.1:
20202016
version "2.2.2"
20212017
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.2.2.tgz#21f333e9b6b8eaff02468f5146ea406d345f4dad"
@@ -2060,24 +2056,24 @@ pkg-dir@^4.2.0:
20602056
dependencies:
20612057
find-up "^4.0.0"
20622058

2063-
postcss-modules-extract-imports@^3.0.0:
2064-
version "3.0.0"
2065-
resolved "https://registry.yarnpkg.com/postcss-modules-extract-imports/-/postcss-modules-extract-imports-3.0.0.tgz#cda1f047c0ae80c97dbe28c3e76a43b88025741d"
2066-
integrity sha512-bdHleFnP3kZ4NYDhuGlVK+CMrQ/pqUm8bx/oGL93K6gVwiclvX5x0n76fYMKuIGKzlABOy13zsvqjb0f92TEXw==
2059+
postcss-modules-extract-imports@^3.1.0:
2060+
version "3.1.0"
2061+
resolved "https://registry.yarnpkg.com/postcss-modules-extract-imports/-/postcss-modules-extract-imports-3.1.0.tgz#b4497cb85a9c0c4b5aabeb759bb25e8d89f15002"
2062+
integrity sha512-k3kNe0aNFQDAZGbin48pL2VNidTF0w4/eASDsxlyspobzU3wZQLOGj7L9gfRe0Jo9/4uud09DsjFNH7winGv8Q==
20672063

2068-
postcss-modules-local-by-default@^4.0.0:
2069-
version "4.0.0"
2070-
resolved "https://registry.yarnpkg.com/postcss-modules-local-by-default/-/postcss-modules-local-by-default-4.0.0.tgz#ebbb54fae1598eecfdf691a02b3ff3b390a5a51c"
2071-
integrity sha512-sT7ihtmGSF9yhm6ggikHdV0hlziDTX7oFoXtuVWeDd3hHObNkcHRo9V3yg7vCAY7cONyxJC/XXCmmiHHcvX7bQ==
2064+
postcss-modules-local-by-default@^4.0.5:
2065+
version "4.0.5"
2066+
resolved "https://registry.yarnpkg.com/postcss-modules-local-by-default/-/postcss-modules-local-by-default-4.0.5.tgz#f1b9bd757a8edf4d8556e8d0f4f894260e3df78f"
2067+
integrity sha512-6MieY7sIfTK0hYfafw1OMEG+2bg8Q1ocHCpoWLqOKj3JXlKu4G7btkmM/B7lFubYkYWmRSPLZi5chid63ZaZYw==
20722068
dependencies:
20732069
icss-utils "^5.0.0"
20742070
postcss-selector-parser "^6.0.2"
20752071
postcss-value-parser "^4.1.0"
20762072

2077-
postcss-modules-scope@^3.0.0:
2078-
version "3.0.0"
2079-
resolved "https://registry.yarnpkg.com/postcss-modules-scope/-/postcss-modules-scope-3.0.0.tgz#9ef3151456d3bbfa120ca44898dfca6f2fa01f06"
2080-
integrity sha512-hncihwFA2yPath8oZ15PZqvWGkWf+XUfQgUGamS4LqoP1anQLOsOJw0vr7J7IwLpoY9fatA2qiGUGmuZL0Iqlg==
2073+
postcss-modules-scope@^3.2.0:
2074+
version "3.2.0"
2075+
resolved "https://registry.yarnpkg.com/postcss-modules-scope/-/postcss-modules-scope-3.2.0.tgz#a43d28289a169ce2c15c00c4e64c0858e43457d5"
2076+
integrity sha512-oq+g1ssrsZOsx9M96c5w8laRmvEu9C3adDSjI8oTcbfkrTE8hx/zfyobUoWIxaKPO8bt6S62kxpw5GqypEw1QQ==
20812077
dependencies:
20822078
postcss-selector-parser "^6.0.4"
20832079

@@ -2103,14 +2099,19 @@ postcss-value-parser@^4.1.0:
21032099
resolved "https://registry.yarnpkg.com/postcss-value-parser/-/postcss-value-parser-4.1.0.tgz#443f6a20ced6481a2bda4fa8532a6e55d789a2cb"
21042100
integrity sha512-97DXOFbQJhk71ne5/Mt6cOu6yxsSfM0QGQyl0L25Gca4yGWEGJaig7l7gbCX623VqTBNGLRLaVUCnNkcedlRSQ==
21052101

2106-
postcss@^8.2.8:
2107-
version "8.2.8"
2108-
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.2.8.tgz#0b90f9382efda424c4f0f69a2ead6f6830d08ece"
2109-
integrity sha512-1F0Xb2T21xET7oQV9eKuctbM9S7BC0fetoHCc4H13z0PT6haiRLP4T0ZY4XWh7iLP0usgqykT6p9B2RtOf4FPw==
2102+
postcss-value-parser@^4.2.0:
2103+
version "4.2.0"
2104+
resolved "https://registry.yarnpkg.com/postcss-value-parser/-/postcss-value-parser-4.2.0.tgz#723c09920836ba6d3e5af019f92bc0971c02e514"
2105+
integrity sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==
2106+
2107+
postcss@^8.4.33, postcss@^8.4.47:
2108+
version "8.4.47"
2109+
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.47.tgz#5bf6c9a010f3e724c503bf03ef7947dcb0fea365"
2110+
integrity sha512-56rxCq7G/XfB4EkXq9Egn5GCqugWvDFjafDOThIdMBsI15iqPqR5r15TfSr1YPYeEI19YeaXMCbY6u88Y76GLQ==
21102111
dependencies:
2111-
colorette "^1.2.2"
2112-
nanoid "^3.1.20"
2113-
source-map "^0.6.1"
2112+
nanoid "^3.3.7"
2113+
picocolors "^1.1.0"
2114+
source-map-js "^1.2.1"
21142115

21152116
prettier@^2.2.1:
21162117
version "2.2.1"
@@ -2335,6 +2336,11 @@ semver@^7.3.2, semver@^7.3.4:
23352336
dependencies:
23362337
lru-cache "^6.0.0"
23372338

2339+
semver@^7.5.4:
2340+
version "7.6.3"
2341+
resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.3.tgz#980f7b5550bc175fb4dc09403085627f9eb33143"
2342+
integrity sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==
2343+
23382344
serialize-javascript@^5.0.1:
23392345
version "5.0.1"
23402346
resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-5.0.1.tgz#7886ec848049a462467a97d3d918ebb2aaf934f4"
@@ -2417,6 +2423,11 @@ source-list-map@^2.0.0:
24172423
resolved "https://registry.yarnpkg.com/source-list-map/-/source-list-map-2.0.1.tgz#3993bd873bfc48479cca9ea3a547835c7c154b34"
24182424
integrity sha512-qnQ7gVMxGNxsiL4lEuJwe/To8UnK7fAnmbGEEH8RpLouuKbeEm0lhbQVFIrNSuB+G7tVrAlVsZgETT5nljf+Iw==
24192425

2426+
source-map-js@^1.2.1:
2427+
version "1.2.1"
2428+
resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-1.2.1.tgz#1ce5650fddd87abc099eda37dcff024c2667ae46"
2429+
integrity sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==
2430+
24202431
source-map-support@~0.5.12:
24212432
version "0.5.19"
24222433
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61"

0 commit comments

Comments
 (0)