Skip to content

Commit

Permalink
Expand rationale for importModuleCriminally.
Browse files Browse the repository at this point in the history
  • Loading branch information
whitequark committed Jan 11, 2025
1 parent 59d32f5 commit 0e68692
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/workerThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ if (USE_WEB_WORKERS) {
// Thus, crimes.
//
// Almost all of this can be deleted when VS Code ships Node v18.19.0 or later.
//
// Update (2025-01-11): VS Code ships Node v20.18.0 and this code still cannot
// be removed because `importModuleDynamically` is feature-gated behind a flag
// (`--experimental-vm-modules`) that VS Code doesn't pass.
//
// I could use `require('node:module').register()` but this will enable all
// extensions within the same extension host to import anything they want from
// any https:// URL, which seems sketchy at best. Crimes continue.
async function importModuleCriminally(url: URL | string): Promise<any> {
let code = await fetch(url).then((resp) => resp.text());
code = code.replace(/\bimport\.meta\.url\b/g, JSON.stringify(url));
Expand Down

0 comments on commit 0e68692

Please sign in to comment.