{"id":13649222,"url":"https://github.com/GoogleFeud/ts-macros","last_synced_at":"2025-04-22T14:31:02.217Z","repository":{"id":40381558,"uuid":"384339804","full_name":"GoogleFeud/ts-macros","owner":"GoogleFeud","description":"A typescript transformer / plugin that allows you to write macros for typescript!","archived":false,"fork":false,"pushed_at":"2024-09-24T12:23:21.000Z","size":8059,"stargazers_count":374,"open_issues_count":11,"forks_count":11,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-12T22:03:44.704Z","etag":null,"topics":["hacktoberfest","macros","typescript"],"latest_commit_sha":null,"homepage":"https://googlefeud.github.io/ts-macros/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GoogleFeud.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","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":"2021-07-09T06:13:01.000Z","updated_at":"2025-04-01T18:15:04.000Z","dependencies_parsed_at":"2024-06-18T17:04:12.885Z","dependency_job_id":"6317b6dc-1f49-4577-bfe4-d070e13f62e7","html_url":"https://github.com/GoogleFeud/ts-macros","commit_stats":{"total_commits":186,"total_committers":4,"mean_commits":46.5,"dds":"0.037634408602150504","last_synced_commit":"ec2eeccc06bcdb897740265a36c847442a0a7fb3"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleFeud%2Fts-macros","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleFeud%2Fts-macros/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleFeud%2Fts-macros/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleFeud%2Fts-macros/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GoogleFeud","download_url":"https://codeload.github.com/GoogleFeud/ts-macros/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250258864,"owners_count":21400983,"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":["hacktoberfest","macros","typescript"],"created_at":"2024-08-02T01:04:50.967Z","updated_at":"2025-04-22T14:30:57.207Z","avatar_url":"https://github.com/GoogleFeud.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# ts-macros\n\nts-macros is a typescript transformer which allows you to create function macros that expand to javascript code during the transpilation phase of your program. \n\n📖 **[Documentation](https://github.com/GoogleFeud/ts-macros/wiki)**\n🎮 **[Playground](https://googlefeud.github.io/ts-macros/)**\n✍️ **[Examples](https://github.com/GoogleFeud/ts-macros/wiki/Practical-Macro-Examples)**\n\n## The Basics\n\nAll macro names must start with a dollar sign (`$`) and must be declared using the function keyword. Macros can then be called just like a normal function, but with a `!` after it's name: `$macro!(params)`. All the code inside of the macro is going to \"expand\" where the macro is called.\n\n![showcase](https://github.com/GoogleFeud/ts-macros/blob/dev/.github/assets/intro_gif.gif)\n\n**What you can do with ts-macros**:\n- Generate repetitive code\n- Generate code conditionally, based on enviourment variables or other configuration files\n- Generate types which you can use in your code (read more [here](https://github.com/GoogleFeud/ts-macros/wiki/Type-Resolver-Transformer))\n- Create abstractions without the runtime cost\n\n## Usage\n\n```\nnpm i --save-dev ts-macros\n```\n\n\u003cdetails\u003e\n    \u003csummary\u003eUsage with ts-patch\u003c/summary\u003e\n\n```\nnpm i --save-dev ts-patch\n```\n\nand add the ts-macros transformer to your tsconfig.json:\n\n```json\n\"compilerOptions\": {\n//... other options\n\"plugins\": [\n        { \"transform\": \"ts-macros\" }\n    ]\n}\n```\n\nAfterwards you can either:\n- Transpile your code using the `tspc` command that ts-patch provides.\n- Patch the instance of typescript that's in your `node_modules` folder with the `ts-patch install` command and then use the `tsc` command to transpile your code.\n\u003c/details\u003e\n\n\u003cdetails\u003e\n    \u003csummary\u003eUsage with ts-loader\u003c/summary\u003e\n\n```js\nconst TsMacros = require(\"ts-macros\").default;\n\noptions: {\n      getCustomTransformers: program =\u003e {\n        before: [TsMacros(program)]\n      }\n}\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n    \u003csummary\u003eUsage with ts-node\u003c/summary\u003e\n\nTo use transformers with ts-node, you'll have to change the compiler in the `tsconfig.json`:\n\n```\nnpm i --save-dev ts-node\n```\n\n```json\n\"ts-node\": {\n    \"compiler\": \"ts-patch/compiler\"\n  },\n  \"compilerOptions\": {\n    \"plugins\": [\n        { \"transform\": \"ts-macros\" }\n    ]\n  }\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n    \u003csummary\u003eCLI Usage (esbuild, vite, watchers)\u003c/summary\u003e\n\nIf you want to use ts-macros with:\n- tools that don't support typescript\n- tools that aren't written in javascript and therefore cannot run typescript transformers (tools that use swc, for example)\n- any tools' watch mode (webpack, vite, esbuild, etc)\n\nyou can use the CLI - [read more about the CLI and example here](https://github.com/GoogleFeud/ts-macros/wiki/CLI-usage)\n\n\u003c/details\u003e\n\n## Security\n\nThis library has 2 built-in macros (`$raw` and `$comptime`) which execute arbitrary code during transpile time. The code is **not** sandboxed in any way and has access to your file system and all node modules.\n\nIf you're transpiling an untrusted codebase which uses this library, make sure to set the `noComptime` option to `true`. Enabling it will replace all calls to these macros with `null` without executing the code inside them. It's always best to review all call sites to `$$raw` and `$$comptime` yourself before transpiling any untrusted codebases.\n\n**ttypescript/ts-patch:**\n```json\n\"plugins\": [\n        { \"transform\": \"ts-macros\", \"noComptime\": true }\n    ]\n```\n\n**manually creating the factory:**\n```js\nTsMacros(program, { noComptime: true });\n```\n\n## Contributing\n\n`ts-macros` is being maintained by a single person. Contributions are welcome and appreciated. Feel free to open an issue or create a pull request at https://github.com/GoogleFeud/ts-macros.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGoogleFeud%2Fts-macros","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FGoogleFeud%2Fts-macros","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGoogleFeud%2Fts-macros/lists"}