close
Skip to content

Instantly share code, notes, and snippets.

@jakebailey
Last active December 11, 2023 20:18
Show Gist options
  • Select an option

  • Save jakebailey/3e73c7aab4da2044a95121467aa3b4e9 to your computer and use it in GitHub Desktop.

Select an option

Save jakebailey/3e73c7aab4da2044a95121467aa3b4e9 to your computer and use it in GitHub Desktop.
TS patchers

Largely found with a sourcegraph search. Maybe there are more?

Language service plugins

typescript-plugin-css-modules

API Why? Workaround?
ts.createLanguageServiceSourceFile Providing a d.ts file for css Proxy the LS host (what vue does)?
ts.updateLanguageServiceSourceFile Providing a d.ts file for css Proxy the LS host (what vue does)?

Being tested weekend of 5.0 RC, potentially.

vuejs/language-tools

API Why? Workaround?
ts.resolveModuleName "If vue file and resolutionMode == ESNext, replace with CommonJS" to silence Node16/NodeNext extensions Use moduleResolution=bundler, or if really needed, providie resolveModuleNameLiterals
ts.__VLS_pitched_resolveModuleNames Marker to not double patch Not needed if they don't patch. Otherwise, store elsewhere?

Should this plugin instead provide .d.vue.ts files?

Transformers

ttypescript

Link

API Why? Workaround?
ts.createProgram Replaces program.emit with a wrapper which adds customTransformers ?

Reads TypeScript's source, loads via new Module, then patches it, so other imports are not patched.

ts-patch

API Why? Workaround?
ts.createProgram Replaces program.emit with a wrapper which adds customTransformers ?
ts.* Adds extra top-level properties for caching, markers Put state somewhere else.

Same as ttypescript, except that it patches node_modules; "seamless" experience if you are using other tools with TypeScript as they also get patched version.

Compilers

stencil

API Why? Workaround?
ts.sys No sys in the browser by default; sets them to a shim ts.setSys (internal)
ts.sys.* New FS implementation No need, or ts.setSys (internal)
ts.resolveModuleName To add new module resolution. ?

There are some other functions overriden I've missed, though.

Build systems

heft

API Why? Workaround?
ts.readJson Caching No need; we cache now, can be removed.
ts.emitFiles Proxy, then rerun the original emitFiles up to 4 times per module target Run tsc multiple times? Or, modify compiler options and rerun emit; will be just as unsafe.

They say that this actually is safe, they've been "doing it for years". Are they right?

Other

Yarn

PR is not up to date; maintained on a fork instead.

Their patch builds TS from source, then diffs the output packages, which are then applied on user machines. This is not a runtime patch applied onto the TS API.

  • PnP resolutions need to change on update
    • File watching for PnP resolution file
    • New reload mode to clear resolutionCache
  • Completions
  • Module name resolver / specifiers
  • Forcing case sensitive file accesses (pretty sure this is wrong, becuase not every file has to go via PnP)
  • Passing PnP into watchGuard and typingsInstaller

Also above this patch is the fact that TypeScript is run via a Node process with modifications applied at runtime, including an extra API on node:module, node:fs modifications for zipfile support, etc. (So, if we are "just using" what appear to be the builtins, are we really doing code execution? Probably still not convenient for users because it has to be run specially.)

But, this has no impact for 5.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment