refactor(compiler): introduce TemplateSource abstraction for tsp init#11303
refactor(compiler): introduce TemplateSource abstraction for tsp init#11303timotheeguerin wants to merge 4 commits into
Conversation
Replace getExecutionRoot()-based template loading in `tsp init` with a first-class TemplateSource abstraction (filesystem, in-memory, and remote implementations). This decouples template resolution from the CompilerHost filesystem contract and enables offline/embedded template sources. Extracted from #11299 as an independent, self-contained refactor.
commit: |
|
All changed packages have been documented.
Show changes
|
|
You can try these changes here
|
Extracts the self-contained
tsp inittemplate-loading refactor out of #11299 into its own PR.What
Replaces
getExecutionRoot()-based template resolution intsp initwith a first-classTemplateSourceabstraction, with three implementations behind one interface:FileSystemTemplateSource— the default (installed/node) path; readstemplates/from the compiler package root. NogetExecutionRoot()dependency.InMemoryTemplateSource— serves the index and every template file from an in-memory map (used by the standalone single-executable to serve templates offline).RemoteTemplateSource—--templates-url; keeps the untrusted-source confirmation and relative-file resolution.Why
Template loading previously went through the
CompilerHostfilesystem contract anchored atgetExecutionRoot(), which also serves the stdlib. Serving templates from an embedded/offline source required masquerading an in-memory map as a real filesystem and overloadinggetExecutionRoot(). This refactor decouples template resolution from the host FS contract so each context supplies its own source, and leavesgetExecutionRoot()solely for the stdlib.Notes
initdefaults toFileSystemTemplateSource.getTypeSpecCoreTemplates/scaffoldNewProject) and the VS Code extension keep working; the extension threads aTemplateSourcethroughcreate-tsp-project.serverlib.ts/server/types.tsare unchanged.