Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Typescript Community Bot",
"main": "dist/index.js",
"dependencies": {
"@typescript/twoslash": "^3.2.1",
"@typescript/twoslash": "^3.2.12",
"algoliasearch": "^4.14.2",
"discord.js": "^14.6.0",
"dotenv-safe": "^8.2.0",
Expand Down
23 changes: 16 additions & 7 deletions src/modules/twoslash.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
import { Message } from 'discord.js';
import { twoslasher, TwoSlashReturn } from '@typescript/twoslash';
import { ScriptTarget, type CompilerOptions } from 'typescript';
import type { CompilerOptions } from 'typescript';
import { makeCodeBlock, findCode } from '../util/codeBlocks';
import { sendWithMessageOwnership } from '../util/send';
import { getTypeScriptModule, TypeScript } from '../util/getTypeScriptModule';
import { splitCustomCommand } from '../util/customCommand';
import { Bot } from '../bot';

const defaultCompilerOptions: CompilerOptions = {
target: ScriptTarget.ESNext,
};

// Preload typescript@latest
getTypeScriptModule('latest');

function getDefaultCompilerOptions(
tsModule: typeof import('typescript'),
): CompilerOptions {
// TypeScript as of 6.0 has sane defaults for everything
if (parseFloat(tsModule.versionMajorMinor) >= 6.0) {
return {};
}

return {
target: tsModule.ScriptTarget.ESNext,
};
}

// Remove `@noErrorTruncation` from the source; this can cause lag/crashes for large errors
function redactNoErrorTruncation(code: string) {
return code.replace(/@noErrorTruncation/g, '');
Expand Down Expand Up @@ -86,7 +95,7 @@ async function twoslash(msg: Message, version: string, content: string) {
try {
ret = twoslasher(redactNoErrorTruncation(code), 'ts', {
tsModule,
defaultCompilerOptions,
defaultCompilerOptions: getDefaultCompilerOptions(tsModule),
defaultOptions: { noErrorValidation: true },
});
} catch (e) {
Expand Down Expand Up @@ -125,7 +134,7 @@ async function twoslashBlock(msg: Message, code: string, tsModule: TypeScript) {
try {
ret = twoslasher(redactNoErrorTruncation(code), 'ts', {
tsModule,
defaultCompilerOptions,
defaultCompilerOptions: getDefaultCompilerOptions(tsModule),
defaultOptions: {
noErrorValidation: true,
noStaticSemanticInfo: false,
Expand Down
46 changes: 29 additions & 17 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -320,21 +320,21 @@
dependencies:
"@types/node" "*"

"@typescript/twoslash@^3.2.1":
version "3.2.1"
resolved "https://registry.yarnpkg.com/@typescript/twoslash/-/twoslash-3.2.1.tgz#7ba5fb2a230925ccd773967b02daf38efc1a3377"
integrity sha512-tS4gLwOe1WCDspqBXhQCb2ESUqzEd1tOkmKpiZ1O+W1x+9l+9njETuXFkLErtH9is/uD1GSvClDjk/tEOJktjQ==
"@typescript/twoslash@^3.2.12":
version "3.2.12"
resolved "https://registry.yarnpkg.com/@typescript/twoslash/-/twoslash-3.2.12.tgz#2cdc2d7ac70e38126a9f22e0eed5b2691a998409"
integrity sha512-qY0ilcgkECIo4MCV8nPfBiK+rcLQRYdbKV0Om/zoHAbkeHqu9QKAjV0SIIhIPq/4JVUFUjNjKmFWlszTwnsn5A==
dependencies:
"@typescript/vfs" "1.4.0"
debug "^4.1.1"
lz-string "^1.4.4"
"@typescript/vfs" "1.6.4"
debug "^4.4.3"
lz-string "^1.5.0"

"@typescript/vfs@1.4.0":
version "1.4.0"
resolved "https://registry.yarnpkg.com/@typescript/vfs/-/vfs-1.4.0.tgz#2d22985c7666c9d4ce26eb025405e6f156aa32b0"
integrity sha512-Pood7yv5YWMIX+yCHo176OnF8WUlKGImFG7XlsuH14Zb1YN5+dYD3uUtS7lqZtsH7tAveNUi2NzdpQCN0yRbaw==
"@typescript/vfs@1.6.4":
version "1.6.4"
resolved "https://registry.yarnpkg.com/@typescript/vfs/-/vfs-1.6.4.tgz#7543a3bd961727eb51c8bdafc3ed5e0fb5f56dff"
integrity sha512-PJFXFS4ZJKiJ9Qiuix6Dz/OwEIqHD7Dme1UwZhTK11vR+5dqW2ACbdndWQexBzCx+CPuMe5WBYQWCsFyGlQLlQ==
dependencies:
debug "^4.1.1"
debug "^4.4.3"

acorn-walk@^8.1.1:
version "8.2.0"
Expand Down Expand Up @@ -652,13 +652,20 @@ date-fns@^2.28.0:
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.29.3.tgz#27402d2fc67eb442b511b70bbdf98e6411cd68a8"
integrity sha512-dDCnyH2WnnKusqvZZ6+jA1O51Ibt8ZMRNkDZdyAyK4YfbDwa/cEmuztzG5pk6hqlp9aSBPYcjOlktquahGwGeA==

debug@4, debug@^4.1.0, debug@^4.1.1, debug@^4.3.3:
debug@4, debug@^4.1.0, debug@^4.3.3:
version "4.3.4"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865"
integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==
dependencies:
ms "2.1.2"

debug@^4.4.3:
version "4.4.3"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.4.3.tgz#c6ae432d9bd9662582fce08709b038c58e9e3d6a"
integrity sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==
dependencies:
ms "^2.1.3"

delayed-stream@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
Expand Down Expand Up @@ -1077,6 +1084,11 @@ lz-string@^1.4.4:
resolved "https://registry.yarnpkg.com/lz-string/-/lz-string-1.4.4.tgz#c0d8eaf36059f705796e1e344811cf4c498d3a26"
integrity sha512-0ckx7ZHRPqb0oUm8zNr+90mtf9DQB60H1wMCjBtfi62Kl3a7JbHob6gA2bC+xRvZoOL+1hzUK8jeuEIQE8svEQ==

lz-string@^1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/lz-string/-/lz-string-1.5.0.tgz#c1ab50f77887b712621201ba9fd4e3a6ed099941"
integrity sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ==

make-error@^1.1.1:
version "1.3.6"
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
Expand Down Expand Up @@ -1229,7 +1241,7 @@ ms@2.1.2:
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==

ms@^2.0.0:
ms@^2.0.0, ms@^2.1.3:
version "2.1.3"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==
Expand Down Expand Up @@ -1860,9 +1872,9 @@ typeorm@^0.3.10:
yargs "^17.3.1"

typescript@^4.9.3:
version "4.9.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.3.tgz#3aea307c1746b8c384435d8ac36b8a2e580d85db"
integrity sha512-CIfGzTelbKNEnLpLdGFgdyKhG23CKdKgQPOBc+OUNrkJ2vr+KSzsSV5kq5iWhEQbok+quxgGzrAtGWCyU7tHnA==
version "4.9.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a"
integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==

undici@^5.11.0, undici@^5.12.0:
version "5.12.0"
Expand Down
Loading