{"id":13452460,"url":"https://github.com/cevek/ttypescript","last_synced_at":"2025-05-14T04:10:31.310Z","repository":{"id":40459386,"uuid":"112488313","full_name":"cevek/ttypescript","owner":"cevek","description":"Over TypeScript tool to use custom transformers in the tsconfig.json","archived":false,"fork":false,"pushed_at":"2023-06-23T09:38:51.000Z","size":242,"stargazers_count":1539,"open_issues_count":23,"forks_count":56,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-05-06T09:08:35.778Z","etag":null,"topics":["custom-transformer","transformer-typescript","transformers","typescript"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cevek.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-29T14:52:43.000Z","updated_at":"2025-05-06T06:01:02.000Z","dependencies_parsed_at":"2024-06-18T11:28:45.534Z","dependency_job_id":null,"html_url":"https://github.com/cevek/ttypescript","commit_stats":{"total_commits":143,"total_committers":25,"mean_commits":5.72,"dds":"0.30069930069930073","last_synced_commit":"835c77bfe1a84bdafc7e223ece93f8a5a949243c"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cevek%2Fttypescript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cevek%2Fttypescript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cevek%2Fttypescript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cevek%2Fttypescript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cevek","download_url":"https://codeload.github.com/cevek/ttypescript/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253303024,"owners_count":21886873,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["custom-transformer","transformer-typescript","transformers","typescript"],"created_at":"2024-07-31T07:01:24.682Z","updated_at":"2025-05-14T04:10:26.299Z","avatar_url":"https://github.com/cevek.png","language":"TypeScript","readme":"# Deprecation Notice\n\n\u003e **`ttypescript` is deprecated**. It currently works with TS below 5.0, but it will not be updated.\n \nFor TypeScript 5+, please use [ts-patch](https://github.com/nonara/ts-patch).\n\n---\n\n[![npm version](https://badge.fury.io/js/ttypescript.svg)](https://badge.fury.io/js/ttypescript) [![Build Status](https://travis-ci.org/cevek/ttypescript.svg?branch=master)](https://travis-ci.org/cevek/ttypescript)\n\n# ttypescript\n\n## What it is\nCurrently TypeScript doesn't support custom transformers in the tsconfig.json, but supports it programmatically.\n\nAnd there is no way to compile your files using custom transformers using `tsc` command.\n\nTTypescript (Transformer TypeScript) solves this problem by patching on the fly the compile module to use transformers from `tsconfig.json`.\n\n\u003c!---\nTTypescript is a drop-in replacement for all typescript modules, located in ``` node_modules/typescript/lib ``` directory:\n\n```ts\nimport * as ts from 'ttypescript'\nimport * as tsServer from 'ttypescript/lib/tsserver'\nimport * as watchGuard from 'ttypescript/lib/watchGuard'\n```\n---\u003e\nInstead of tsc and tsserver, use ttsc and ttsserver wrappers. This wrappers try to use locally installed typescript first.\n\nNo version lock-ins - typescript used as peer dependency.\n\n## How to install\n\n```\nnpm i ttypescript -D\n```\n\nttypescript uses your installed `typescript` in your `node_modules`\n\n## How to use\n\n### tsconfig.json\n\nSet a transformer path to the `tsconfig.json` in `compilerOptions` section `plugin` array:\n```\n{\n    \"compilerOptions\": {\n        \"plugins\": [\n            { \"transform\": \"transformer-module\" },\n        ]\n    }\n}\n```\n\nplugin entries described in `PluginConfig`:\n\n```ts\nexport interface PluginConfig {\n    /**\n     * Path to transformer or transformer module name\n     */\n    transform?: string;\n\n    /**\n     * The optional name of the exported transform plugin in the transform module.\n     */\n    import?: string;\n\n    /**\n     * Plugin entry point format type, default is program\n     */\n    type?: 'program' | 'config' | 'checker' | 'raw' | 'compilerOptions';\n\n    /**\n     * Should transformer applied after all ones\n     */\n    after?: boolean;\n\n    /**\n     * Should transformer applied for d.ts files, supports from TS2.9\n     */\n    afterDeclarations?: boolean;\n    /**\n     * any other properties provided to the transformer as config argument\n     * */\n    [options: string]: any;\n}\n```\n\nYou just need to add the `transform` block with optional `import`, `type`, `after`, `afterDeclarations` and plugin-related options.\n\n`transform` can accept npm module or local file path (.ts or .js) related to `tsconfig.json`\n\n### PluginConfig.type\nBecause currently transformers can run only programmatically, most of them use factory wrapper with different signatures.\nFor the possible to work with any of them you can specify `type` in the plugin config.\n\nBy default will be used a `program` type.\n\u003c!---\n\nMost of transformers exports ``` ts.TransformerFactory\u003cts.SourceFile\u003e ```. \nBut better to export TransformerBasePlugin, described below. In most cases it's a plugin responsibility to when run a transformer.\n\n```ts\nexport interface TransformerBasePlugin {\n    before?: ts.TransformerFactory\u003cts.SourceFile\u003e;\n    after?: ts.TransformerFactory\u003cts.SourceFile\u003e;\n    afterDeclarations?: ts.TransformerFactory\u003cts.SourceFile\u003e;\n}\n\nexport type TransformerPlugin = TransformerBasePlugin | ts.TransformerFactory\u003cts.SourceFile\u003e;\n```\n---\u003e\n#### program \nIf the transformer has a factory signature using `program` as first argument: \n```ts\n(program: ts.Program, config?: PluginConfig) =\u003e ts.TransformerFactory\nwhere \nts.TransformerFactory = (context: ts.TransformationContext) =\u003e (sourceFile: ts.SourceFile) =\u003e ts.SourceFile\n```\nPlugin config entry: `{ \"transform\": \"transformer-module\" }`.\n\n\n#### config\nFor the signature with transformer's config:\n```ts\n(config: PluginConfig) =\u003e ts.TransformerFactory\n```\nPlugin config entry: `{ \"transform\": \"transformer-module\", type: \"config\" }`.\n\n#### checker\nFor the signature with ts.TypeChecker:\n```ts\n(checker: ts.TypeChecker, config?: PluginConfig) =\u003e ts.TransformerFactory\n```\nPlugin config entry: `{ \"transform\": \"transformer-module\", type: \"checker\" }`.\n\n#### raw\nFor the signature without factory wrapper:\n```ts\nts.TransformerFactory\n```\nPlugin config entry: `{ \"transform\": \"transformer-module\", type: \"raw\" }`.\n\n#### compilerOptions\n```ts\n(compilerOpts: ts.CompilerOptions, config?: PluginConfig) =\u003e ts.TransformerFactory\n```\nPlugin config entry: `{ \"transform\": \"transformer-module\", type: \"compilerOptions\" }`.\n\n```json\n{\n    \"compilerOptions\": {\n        \"plugins\": [\n            { \"transform\": \"transformer-module\", \"someOption1\": 123, \"someOption2\": 321 },\n            { \"transform\": \"./transformers/my-transformer.ts\" },\n            { \"transform\": \"transformer-module\", \"after\": true },\n            { \"transform\": \"transformer-module\", \"afterDeclarations\": true },\n            { \"transform\": \"transformer-module\", \"type\": \"ls\" }\n        ]\n    },\n}\n```\n\n### Command line\n\nLike usual `tsc`, all arguments work the same way.\n```\nttsc\n```\n\n### ts-node\n\n```\nts-node --compiler ttypescript index.ts\nor\nts-node -C ttypescript index.ts\n```\n\n### Parcel\n\nJust install a parcel plugin\n```\nnpm i parcel-plugin-ttypescript\n```\n\n\n### Webpack\n```js\n    {\n        test: /\\.(ts|tsx)$/,\n        loader: require.resolve('awesome-typescript-loader'),\n        // or\n        loader: require.resolve('ts-loader'),\n        options: {\n            compiler: 'ttypescript'\n        }\n    }\n```\n\n### Rollup\n```js\n// rollup.config.js\nimport ttypescript from 'ttypescript'\nimport tsPlugin from 'rollup-plugin-typescript2'\n\nexport default {\n    // ...\n    plugins: [\n        // ...\n        tsPlugin({\n            typescript: ttypescript\n        })\n    ]\n}\n```\n\n### VS Code\nIf you want to compile your project with VS Code task runner you need to overwrite the config `typescript.tsdk` to path of the installed `ttypescript`: \n```\n\"typescript.tsdk\": \"/usr/local/lib/node_modules/ttypescript/lib\",\nor \n\"typescript.tsdk\": \"node_modules/ttypescript/lib\",\n```\n\n### Jest, ts-jest\n```js\nmodule.exports = {\n  // [...]\n  globals: {\n    'ts-jest': {\n      compiler: 'ttypescript'\n    }\n  }\n};\n```\nor in `package.json`\n```json\n{\n  \"jest\": {\n    \"globals\": {\n      \"ts-jest\": {\n        \"compiler\": \"ttypescript\"\n      }\n    }\n  }\n}\n```\n\n## Transformers\n\nYou can use transformers written in ts or js\n\n```ts\n// transformer1-module\nimport * as ts from 'typescript';\nexport default function(program: ts.Program, pluginOptions: {}) {\n    return (ctx: ts.TransformationContext) =\u003e {\n        return (sourceFile: ts.SourceFile) =\u003e {\n            function visitor(node: ts.Node): ts.Node {\n                // if (ts.isCallExpression(node)) {\n                //     return ts.createLiteral('call');\n                // }\n                return ts.visitEachChild(node, visitor, ctx);\n            }\n            return ts.visitEachChild(sourceFile, visitor, ctx);\n        };\n    };\n}\n\n```\n\nExamples of transformers:\n\n[`{ \"transform\": \"ts-nameof\", type: \"raw\"}`](https://github.com/dsherret/ts-nameof) \n\n[`{ \"transform\": \"ts-optchain/transform\" }`](https://github.com/rimeto/ts-optchain) \n\n[`{ \"transform\": \"ts-transform-asset\" }`](https://github.com/slune-org/ts-transform-asset) \n\n[`{ \"transform\": \"ts-transform-auto-require\" }`](https://github.com/slune-org/ts-transform-auto-require) \n\n[`{ \"transform\": \"ts-transform-css-modules/dist/transform\", type: \"config\" }`](https://github.com/longlho/ts-transform-css-modules) \n\n[`{ \"transform\": \"ts-transform-graphql-tag/dist/transformer\" }`](https://github.com/firede/ts-transform-graphql-tag) \n\n[`{ \"transform\": \"ts-transform-img/dist/transform\", type: \"config\" }`](https://github.com/longlho/ts-transform-img) \n\n[`{ \"transform\": \"ts-transform-react-intl/dist/transform\", import: \"transform\", type: \"config\" }`](https://github.com/longlho/ts-transform-react-intl) \n\n[`{ \"transform\": \"ts-transformer-enumerate/transformer\" }`](https://github.com/kimamula/ts-transformer-enumerate)\n\n[`{ \"transform\": \"ts-transformer-keys/transformer\" }`](https://github.com/kimamula/ts-transformer-keys) \n\n[`{ \"transform\": \"ts-transformer-minify-privates\" }`](https://github.com/timocov/ts-transformer-minify-privates) \n\n[`{ \"transform\": \"typescript-is/lib/transform-inline/transformer\" }`](https://github.com/woutervh-/typescript-is) \n\n[`{ \"transform\": \"typescript-plugin-styled-components\", type: \"config\" }`](https://github.com/Igorbek/typescript-plugin-styled-components#ttypescript-compiler)\n\n[`{ \"transform\": \"typescript-transform-jsx\" }`](https://github.com/LeDDGroup/typescript-transform-jsx) \n\n[`{ \"transform\": \"typescript-transform-macros\" }`](https://github.com/LeDDGroup/typescript-transform-macros) \n\n[`{ \"transform\": \"typescript-transform-paths\" }`](https://github.com/LeDDGroup/typescript-transform-paths) \n\n[`{ \"transform\": \"@zerollup/ts-transform-paths\" }`](https://github.com/zerkalica/zerollup/tree/master/packages/ts-transform-paths)\n\n[`{ \"transform\": \"@zoltu/typescript-transformer-append-js-extension\" }`](https://github.com/Zoltu/typescript-transformer-append-js-extension)\n\n[`{ \"transform\": \"@magic-works/ttypescript-browser-like-import-transformer\" }`](https://github.com/Jack-Works/ttypescript-browser-like-import-transformer)\n\n[`{ \"transform\": \"typescript-transform-react-jsx-source\" }`](https://github.com/alexgorbatchev/typescript-transform-react-jsx-source)\n\n[`{ \"transform\": \"ts-transformer-remove-named-export\" }`](https://github.com/dominguezcelada/ts-transformer-remove-named-export)\n\n[`{ \"transform\": \"ts-transformer-export-default-name\" }`](https://github.com/jirutka/ts-transformer-export-default-name)\n\n[`{ \"transform\": \"ts-transformer-inline-file/transformer\" }`](https://github.com/jirutka/ts-transformer-inline-file)\n\n[`{ \"transform\": \"ts-transformer-strip-const-enums\", \"entrySourceFiles\": [\"./src/index.ts\" }`](https://github.com/timocov/ts-transformer-strip-const-enums)\n\n[`{ \"transform\": \"ts-transformer-properties-rename\", \"entrySourceFiles\": [\"./src/index.ts\"] }`](https://github.com/timocov/ts-transformer-properties-rename)\n\n[`{ \"transform\": \"tsc-progress\", \"name\": \"TSC\", \"color\": \"green\" }`](https://github.com/JiangWeixian/tsc-progress)\n\n[Tutorial how to write a typescript transformer](https://dev.doctorevidence.com/how-to-write-a-typescript-transform-plugin-fc5308fdd943)\n\n- [Tutorial how to write a typescript transformer](https://dev.doctorevidence.com/how-to-write-a-typescript-transform-plugin-fc5308fdd943)\n- [Transformer framework](https://github.com/slune-org/simple-ts-transform)\n- [Unit testing transformer compiler](https://github.com/slune-org/ts-transform-test-compiler)\n\n## Example\nAn example project is in the [example](./packages/ttypescript-examples) directory\n\n## License\nMIT License\n","funding_links":[],"categories":["TypeScript","Tools"],"sub_categories":["Optimization"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcevek%2Fttypescript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcevek%2Fttypescript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcevek%2Fttypescript/lists"}