- Wraps the compiler API objects to provide helper methods for getting information and programmatically changing files.
- Allows falling back to the compiler API objects if necessary (ex.
- All changes are kept in memory (including file and directory moves) until specifying to save to the underlying file system.
- Changes are made to the text and wrapped nodes can be held onto between manipulations.
This library is still under active development. Most common code manipulation/generation use cases are implemented, but there's still a lot of work to do. Please open an issue if you find a feature missing, bug, or question that isn't in the issue tracker.
;// initialize;// add source filesproject.addSourceFilesAtPaths"src/**/*.ts";;;// get information;myClass.getName; // returns: "MyClass"myClass.hasExportKeyword; // returns: truemyClass.isDefaultExport; // returns: false// manipulate;myClass.rename"NewName";myClass.addImplementsmyInterface.getName;myClass.addProperty;project.getSourceFileOrThrow"src/ExistingFile.ts".delete;// asynchronously save all the changes aboveawait project.save;// get underlying compiler node from the typescript AST from any node;
Or navigate existing compiler nodes created with the TypeScript compiler (the
ts named export is the TypeScript compiler):
;// some code that creates a class declaration using the ts object;// create and use a wrapped node;;// ... do more stuff here ...