fix: replace unpkg w/ jsdelivr & cdnjs (#59291)

Co-authored-by: Mrugesh Mohapatra <1884376+raisedadead@users.noreply.github.com>
Co-authored-by: Huyen Nguyen <25715018+huyenltnguyen@users.noreply.github.com>
This commit is contained in:
Sukka
2025-04-07 16:28:17 +08:00
committed by GitHub
parent 206293bf92
commit 14ced4f271
25 changed files with 92 additions and 87 deletions
@@ -39,18 +39,23 @@ interface CancelEvent extends MessageEvent {
};
}
const TS_VERSION = '5'; // hardcoding for now, in the future this may be dynamic
// Pin at the latest TS version available as cdnjs doesn't support version range.
const TS_VERSION = '5.7.3';
let tsEnv: VirtualTypeScriptEnvironment | null = null;
let compilerHost: CompilerHost | null = null;
let cachedVersion: string | null = null;
// NOTE: vfs.globals must only be imported once, otherwise it will throw.
importScripts('https://unpkg.com/@typescript/vfs@1.6.0/dist/vfs.globals.js');
importScripts(
'https://cdn.jsdelivr.net/npm/@typescript/vfs@1.6.0/dist/vfs.globals.js'
);
function importTS(version: string) {
if (cachedVersion == version) return;
importScripts('https://unpkg.com/typescript@' + version);
importScripts(
`https://cdnjs.cloudflare.com/ajax/libs/typescript/${version}/typescript.min.js`
);
cachedVersion = version;
}