Skip to content

Commit 22cabe5

Browse files
committed
Fix twoslash with TS 6 release
1 parent 02b8dc2 commit 22cabe5

3 files changed

Lines changed: 46 additions & 25 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Typescript Community Bot",
55
"main": "dist/index.js",
66
"dependencies": {
7-
"@typescript/twoslash": "^3.2.1",
7+
"@typescript/twoslash": "^3.2.12",
88
"algoliasearch": "^4.14.2",
99
"discord.js": "^14.6.0",
1010
"dotenv-safe": "^8.2.0",

src/modules/twoslash.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
import { Message } from 'discord.js';
22
import { twoslasher, TwoSlashReturn } from '@typescript/twoslash';
3-
import { ScriptTarget, type CompilerOptions } from 'typescript';
3+
import type { CompilerOptions } from 'typescript';
44
import { makeCodeBlock, findCode } from '../util/codeBlocks';
55
import { sendWithMessageOwnership } from '../util/send';
66
import { getTypeScriptModule, TypeScript } from '../util/getTypeScriptModule';
77
import { splitCustomCommand } from '../util/customCommand';
88
import { Bot } from '../bot';
99

10-
const defaultCompilerOptions: CompilerOptions = {
11-
target: ScriptTarget.ESNext,
12-
};
13-
1410
// Preload typescript@latest
1511
getTypeScriptModule('latest');
1612

13+
function getDefaultCompilerOptions(
14+
tsModule: typeof import('typescript'),
15+
): CompilerOptions {
16+
// TypeScript as of 6.0 has sane defaults for everything
17+
if (parseFloat(tsModule.versionMajorMinor) >= 6.0) {
18+
return {};
19+
}
20+
21+
return {
22+
target: tsModule.ScriptTarget.ESNext,
23+
};
24+
}
25+
1726
// Remove `@noErrorTruncation` from the source; this can cause lag/crashes for large errors
1827
function redactNoErrorTruncation(code: string) {
1928
return code.replace(/@noErrorTruncation/g, '');
@@ -86,7 +95,7 @@ async function twoslash(msg: Message, version: string, content: string) {
8695
try {
8796
ret = twoslasher(redactNoErrorTruncation(code), 'ts', {
8897
tsModule,
89-
defaultCompilerOptions,
98+
defaultCompilerOptions: getDefaultCompilerOptions(tsModule),
9099
defaultOptions: { noErrorValidation: true },
91100
});
92101
} catch (e) {
@@ -125,7 +134,7 @@ async function twoslashBlock(msg: Message, code: string, tsModule: TypeScript) {
125134
try {
126135
ret = twoslasher(redactNoErrorTruncation(code), 'ts', {
127136
tsModule,
128-
defaultCompilerOptions,
137+
defaultCompilerOptions: getDefaultCompilerOptions(tsModule),
129138
defaultOptions: {
130139
noErrorValidation: true,
131140
noStaticSemanticInfo: false,

yarn.lock

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -320,21 +320,21 @@
320320
dependencies:
321321
"@types/node" "*"
322322

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

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

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

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

662+
debug@^4.4.3:
663+
version "4.4.3"
664+
resolved "https://registry.yarnpkg.com/debug/-/debug-4.4.3.tgz#c6ae432d9bd9662582fce08709b038c58e9e3d6a"
665+
integrity sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==
666+
dependencies:
667+
ms "^2.1.3"
668+
662669
delayed-stream@~1.0.0:
663670
version "1.0.0"
664671
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
@@ -1077,6 +1084,11 @@ lz-string@^1.4.4:
10771084
resolved "https://registry.yarnpkg.com/lz-string/-/lz-string-1.4.4.tgz#c0d8eaf36059f705796e1e344811cf4c498d3a26"
10781085
integrity sha512-0ckx7ZHRPqb0oUm8zNr+90mtf9DQB60H1wMCjBtfi62Kl3a7JbHob6gA2bC+xRvZoOL+1hzUK8jeuEIQE8svEQ==
10791086

1087+
lz-string@^1.5.0:
1088+
version "1.5.0"
1089+
resolved "https://registry.yarnpkg.com/lz-string/-/lz-string-1.5.0.tgz#c1ab50f77887b712621201ba9fd4e3a6ed099941"
1090+
integrity sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ==
1091+
10801092
make-error@^1.1.1:
10811093
version "1.3.6"
10821094
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
@@ -1229,7 +1241,7 @@ ms@2.1.2:
12291241
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
12301242
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==
12311243

1232-
ms@^2.0.0:
1244+
ms@^2.0.0, ms@^2.1.3:
12331245
version "2.1.3"
12341246
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
12351247
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==
@@ -1860,9 +1872,9 @@ typeorm@^0.3.10:
18601872
yargs "^17.3.1"
18611873

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

18671879
undici@^5.11.0, undici@^5.12.0:
18681880
version "5.12.0"

0 commit comments

Comments
 (0)