Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

updated typescript (#126)

ggrandidc5a2db2f9ee
diff --git a/.eslintrc.cjs b/.eslintrc.cjs
index 81f3199a..d8342689 100644
--- a/.eslintrc.cjs
+++ b/.eslintrc.cjs
@@ -7,6 +7,7 @@ const config = {
{
extends: ['plugin:@typescript-eslint/recommended-requiring-type-checking'],
files: ['*.ts', '*.tsx'],
+ excludedFiles: ['./monaco-editor.d.ts'],
parserOptions: {
project: path.join(__dirname, 'tsconfig.json'),
},
diff --git a/.gitignore b/.gitignore
index f10fbfd1..17c49527 100644
--- a/.gitignore
+++ b/.gitignore
@@ -43,3 +43,7 @@ yarn-error.log*
# vimrc
*vimrc*
+
+# monaco-editor dependency
+public/vs/
+monaco-editor.d.ts
diff --git a/next.config.mjs b/next.config.mjs
index 62f3d9d3..b82bd115 100644
--- a/next.config.mjs
+++ b/next.config.mjs
@@ -3,6 +3,7 @@
* for Docker builds.
*/
await import('./src/env.mjs');
+await import('./scripts/dl-monaco.mjs').then(({ download }) => download());
/** @type {import("next").NextConfig} */
const config = {
diff --git a/package.json b/package.json
index 327eba38..7c55f376 100644
--- a/package.json
+++ b/package.json
@@ -5,19 +5,21 @@
"scripts": {
"build": "next build",
"dev": "next dev",
- "postinstall": "prisma generate",
+ "postinstall": "prisma generate && pnpm dl-monaco",
"lint": "next lint",
"reset": "prisma db push --force-reset --preview-feature",
"format": "prettier -w 'src/**/*.{ts,tsx,css,cjs,mjs,json}'",
"start": "next start",
"refresh": "pnpm reset && pnpm prisma db seed",
"typecheck": "tsc --noEmit",
- "prepare": "husky install"
+ "prepare": "husky install",
+ "dl-monaco": "node scripts/dl-monaco.mjs"
},
"type": "module",
"dependencies": {
"@clerk/nextjs": "^4.19.0",
"@hookform/resolvers": "^3.1.1",
+ "@monaco-editor/loader": "^1.3.3",
"@monaco-editor/react": "^4.5.1",
"@next-auth/prisma-adapter": "^1.0.6",
"@prisma/client": "^4.14.0",
@@ -82,7 +84,6 @@
"eslint": "^8.40.0",
"eslint-config-next": "^13.4.2",
"husky": "^8.0.0",
- "monaco-editor": "=0.36.1",
"postcss": "^8.4.21",
"prettier": "^2.8.8",
"prettier-plugin-tailwindcss": "^0.2.8",
@@ -99,7 +100,8 @@
},
"pnpm": {
"patchedDependencies": {
+ "@monaco-editor/[email protected]": "patches/@[email protected]"
}
}
}
diff --git a/patches/@[email protected] b/patches/@[email protected]
new file mode 100644
index 00000000..cfadc630
--- /dev/null
+++ b/patches/@[email protected]
@@ -0,0 +1,13 @@
+diff --git a/dist/index.d.ts b/dist/index.d.ts
+index cb4dde7ee7ebc13c366548610d88e24ea672fd03..e0cd328d114b8025876495fb7d2fec5dece8cbe0 100644
+--- a/dist/index.d.ts
++++ b/dist/index.d.ts
+@@ -3,7 +3,7 @@ import * as react from 'react';
+ import { ReactNode } from 'react';
+ import * as monaco_editor from 'monaco-editor';
+ import { editor } from 'monaco-editor';
+-import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
++import * as monaco from 'monaco-editor';
+
+ type MonacoDiffEditor = editor.IStandaloneDiffEditor;
+ type DiffOnMount = (editor: MonacoDiffEditor, monaco: Monaco) => void;
\ No newline at end of file
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index f256be4b..766798f9 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1,10 +1,13 @@
-lockfileVersion: '6.0'
+lockfileVersion: '6.1'
settings:
autoInstallPeers: true
excludeLinksFromLockfile: false
patchedDependencies:
+ '@monaco-editor/[email protected]':
+ hash: xep4qb27qzc6gvlhv2fxe3r2ka
+ path: patches/@[email protected]
hash: mr6pbhgbmy4dt4xo4hxm5k4ym4
path: patches/[email protected]
@@ -16,9 +19,12 @@ dependencies:
'@hookform/resolvers':
specifier: ^3.1.1
version: 3.1.1([email protected])
+ '@monaco-editor/loader':
+ specifier: ^1.3.3
+ version: 1.3.3([email protected])
'@monaco-editor/react':
specifier: ^4.5.1
+ version: 4.5.1(patch_hash=xep4qb27qzc6gvlhv2fxe3r2ka)([email protected])([email protected])([email protected])
'@next-auth/prisma-adapter':
specifier: ^1.0.6
version: 1.0.6(@prisma/[email protected])([email protected])
@@ -204,9 +210,6 @@ devDependencies:
husky:
specifier: ^8.0.0
version: 8.0.0
- monaco-editor:
- specifier: '=0.36.1'
- version: 0.36.1
postcss:
specifier: ^8.4.21
version: 8.4.21
@@ -667,7 +670,7 @@ packages:
state-local: 1.0.7
dev: false
+ /@monaco-editor/[email protected](patch_hash=xep4qb27qzc6gvlhv2fxe3r2ka)([email protected])([email protected])([email protected]):
resolution: {integrity: sha512-NNDFdP+2HojtNhCkRfE6/D6ro6pBNihaOzMbGK84lNWzRu+CfBjwzGt4jmnqimLuqp5yE5viHS2vi+QOAnD5FQ==}
peerDependencies:
monaco-editor: '>= 0.25.0 < 1'
@@ -679,6 +682,7 @@ packages:
react: 18.2.0
react-dom: 18.2.0([email protected])
dev: false
+ patched: true
resolution: {integrity: sha512-Z7agwfSZEeEcqKqrnisBun7VndRPshd6vyDsoRU68MXbkui8storkHgvN2hnNDrqr/hSCF9aRn56a1qpihaB4A==}
@@ -4873,6 +4877,7 @@ packages:
resolution: {integrity: sha512-/CaclMHKQ3A6rnzBzOADfwdSJ25BFoFT0Emxsc4zYVyav5SkK9iA6lEtIeuN/oRYbwPgviJT+t3l+sjFa28jYg==}
+ dev: false
resolution: {integrity: sha512-+CsW0+Mvx2+eitkXS7OpUXIu57qXlqAL8oVkYhkPCEZ/c6+6gOp/IcG7w+Lb33YiZuTyvJ891+czkeJRPIEwVA==}
diff --git a/scripts/dl-monaco.mjs b/scripts/dl-monaco.mjs
new file mode 100644
index 00000000..af5a0f67
--- /dev/null
+++ b/scripts/dl-monaco.mjs
@@ -0,0 +1,66 @@
+import url from 'node:url';
+import fs from 'node:fs/promises';
+import path from 'node:path';
+
+//@ts-check
+const typescriptVersion = '5.1.6';
+
+/** @link https://github.com/microsoft/TypeScript-Make-Monaco-Builds */
+const baseUrl = `https://typescript.azureedge.net/cdn/${typescriptVersion}/monaco`;
+
+/**
+ *
+ * @param {readonly [remoteUrl: string, diskPath:string]} param0
+ */
+async function downloadAndSaveFile([remoteUrl, diskPath]) {
+ const file = await (await fetch(new URL(baseUrl + remoteUrl))).text();
+
+ const pathToSave = url.fileURLToPath(path.join(import.meta.url, '../../', diskPath));
+
+ const dir = path.join(pathToSave, '../');
+
+ await fs.mkdir(dir, { recursive: true });
+
+ await fs.writeFile(pathToSave, file, {});
+}
+
+const files = /** @type {const} */ ([
+ ['/esm/vs/editor/editor.api.d.ts', './monaco-editor.d.ts'],
+ // TODO switch to the local versions
+ // ['/min/vs/loader.js', './public/vs/loader.js'],
+ // ['/min/vs/editor/editor.main.js', './public/vs/editor/editor.main.js'],
+ // ['/min/vs/editor/editor.main.nls.js', './public/vs/editor/editor.main.nls.js'],
+ // [
+ // '/min/vs/basic-languages/typescript/typescript.js',
+ // './public/vs/basic-languages/typescript/typescript.js',
+ // ],
+ // ['/min/vs/language/typescript/tsMode.js', './public/vs/language/typescript/tsMode.js'],
+ // ['/min/vs/base/worker/workerMain.js', './public/vs/base/worker/workerMain.js'],
+ // [
+ // '/min/vs/base/common/worker/simpleWorker.nls.js',
+ // './public/vs/base/common/worker/simpleWorker.nls.js',
+ // ],
+ // ['/min/vs/language/typescript/tsWorker.js', './public/vs/language/typescript/tsWorker.js'],
+ // [
+ // '/min/vs/base/common/worker/simpleWorker.nls.js',
+ // './public/vs/base/common/worker/simpleWorker.nls.js',
+ // ],
+]);
+
+export const download = async (force = false) => {
+ if (
+ force ||
+ (await fs
+ .open(url.fileURLToPath(path.join(import.meta.url, '../../', files[0][1])))
+ .then((f) => f.close())
+ .then(() => false)
+ .catch(() => true))
+ ) {
+ console.log('downloading monaco-editor');
+ return Promise.all(files.map(downloadAndSaveFile));
+ }
+};
+
+if (process.argv[1] === url.fileURLToPath(import.meta.url)) {
+ download(true);
+}
diff --git a/truncate.js b/scripts/truncate.js
similarity index 87%
rename from truncate.js
rename to scripts/truncate.js
index 72b74752..7bf14f04 100644
--- a/truncate.js
+++ b/scripts/truncate.js
@@ -1,3 +1,4 @@
+// eslint-disable-next-line @typescript-eslint/no-var-requires
const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();
@@ -5,6 +6,7 @@ const prisma = new PrismaClient();
async function truncateTables() {
try {
// Get all table names
+ /** @type {{ table_name: string }[]} */
const tableNames = await prisma.$queryRaw`
SELECT table_name FROM information_schema.tables
WHERE table_schema = 'public' -- Replace 'public' with your schema name if necessary
diff --git a/src/components/challenge/editor/index.tsx b/src/components/challenge/editor/index.tsx
index 793326c5..18082fe9 100644
--- a/src/components/challenge/editor/index.tsx
+++ b/src/components/challenge/editor/index.tsx
@@ -1,9 +1,9 @@
'use client';
-import Editor from '@monaco-editor/react';
+import Editor, { loader } from '@monaco-editor/react';
import clsx from 'clsx';
import { Loader2, Settings } from 'lucide-react';
-import type * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
+import type * as monaco from 'monaco-editor';
import { useSession } from 'next-auth/react';
import { useTheme } from 'next-themes';
import { useRouter } from 'next/navigation';
@@ -28,6 +28,12 @@ import { libSource } from './editor-types';
import { createTwoslashInlayProvider } from './twoslash';
import { VimStatusBar } from './vimMode';
+loader.config({
+ paths: {
+ vs: 'https://typescript.azureedge.net/cdn/5.1.6/monaco/min/vs'
+ }
+})
+
const DEFAULT_OPTIONS = {
lineNumbers: 'on',
tabSize: 2,
@@ -40,8 +46,6 @@ const DEFAULT_OPTIONS = {
const LIB_URI = 'ts:filename/checking.d.ts';
-type Monaco = typeof monaco;
-
type Props = (
| {
mode: 'solve';
@@ -198,7 +202,8 @@ export const CodePanel = (props: Props) => {
const onMount =
(value: string, onError: (v: TsErrors) => void) =>
- async (editor: monaco.editor.IStandaloneCodeEditor, monaco: Monaco) => {
+ // eslint-disable-next-line @typescript-eslint/consistent-type-imports
+ async (editor: monaco.editor.IStandaloneCodeEditor, monaco: typeof import('monaco-editor')) => {
const lineWithUserCode = value
.split('\n')
.findIndex((line) => line.includes(USER_CODE_START));
diff --git a/src/components/challenge/editor/vimMode.tsx b/src/components/challenge/editor/vimMode.tsx
index c78a71b9..e4406df6 100644
--- a/src/components/challenge/editor/vimMode.tsx
+++ b/src/components/challenge/editor/vimMode.tsx
@@ -1,6 +1,6 @@
'use client';
-import type * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
+import type * as monaco from 'monaco-editor';
import { initVimMode, type VimMode } from 'monaco-vim';
import { useEffect, useRef } from 'react';
import { useEditorSettingsStore } from '../settings-store';
diff --git a/tsconfig.json b/tsconfig.json
index 92b25310..2fd286bc 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -36,13 +36,17 @@
".eslintrc.cjs",
"next-env.d.ts",
"*.ts",
+ "./scripts/*.js",
+ "./scripts/*.mjs",
+ "./scripts/*.cjs",
"./src/**/*.ts",
"./src/**/*.tsx",
"./src/**/*.cjs",
"./src/**/*.mjs",
".next/types/**/*.ts"
- ],
+, "scripts/dl-monaco.mjs" ],
"exclude": [
- "node_modules"
+ "node_modules",
+ "*.d.ts",
]
}