Forger Help

Building with ts-patch

Any pipeline that compiles TypeScript through tsc can apply Forger's transformer via ts-patch — Webpack loaders that call tsc, custom build scripts, CI pre-publish steps.

1. Install

npm install --save-dev ts-patch

2. Declare the transformer

{ "compilerOptions": { "plugins": [ { "transform": "@artstesh/forger/lib/utils/transformer" } ] } }

3. Compile with tspc instead of tsc

{ "scripts": { "build": "tspc -p tsconfig.json" } }

tspc is a drop-in replacement for the tsc CLI: same arguments, same behavior, plus execution of the declared transformers. The compiled output has every Forger.create<T>() call site rewritten with the injected type description.

Verify the output

After a build, the emitted JavaScript contains the injected argument — a compact JSON tree after the regular arguments:

// input const student = Forger.create<Student>(); // emitted (simplified) const student = Forger.create({}, 1, {"type":0,"children":[{"name":"name","type":5}, …]});

If the emitted call has no trailing JSON argument, the transformer did not run for that file.

Notes

  • The transformer path @artstesh/forger/lib/utils/transformer resolves to the compiled transformer inside the installed package.

  • Consumers building through bundlers with their own TypeScript loaders (ts-loader, fork-ts-checker) should configure the transformer in the loader's getCustomTransformers hook, using the same module — the factory exported from @artstesh/forger/lib/utils/transformer accepts the program and returns the transformer.

  • Test pipelines have their own topics: Jest and Angular.

08 September 2026