@ttsc/strip
v0.18.4
Published
First-party ttsc plugin that removes configured calls and statements from emitted JavaScript.
Maintainers
Readme
@ttsc/strip

@ttsc/strip removes configured debug calls and debugger statements from TypeScript source AST before emit.
Setup
Install ttsc and TypeScript-Go, then the strip plugin:
npm install -D ttsc typescript
npm install -D @ttsc/stripRun your normal ttsc command:
npx ttscWith no extra config, @ttsc/strip removes console.log, console.debug, assert.*, and debugger.
Only the configured patterns are removed. @ttsc/strip is not a minifier, tree-shaker, or dead-code-elimination pass.
Stripping removes the entire statement, including its arguments. A side-effecting call nested inside a stripped statement-level call goes with it: console.log(recordMetric()) drops recordMetric() along with the console.log statement.
Configuration
Default behavior removes these statement patterns:
{
"calls": ["console.log", "console.debug", "assert.*"],
"statements": ["debugger"]
}Call patterns match statement-level calls such as console.log("debug") or assert.equal(left, right). A wildcard is supported at the end of a dotted call pattern, such as assert.*.
To customize the strip list, add a strip.config.ts next to your tsconfig.json:
// strip.config.ts
import type { ITtscStripConfig } from "@ttsc/strip";
export default {
calls: ["console.log", "console.debug", "assert.*"],
statements: ["debugger"],
} satisfies ITtscStripConfig;@ttsc/strip discovers its config by walking upward from the tsconfig directory, looking for strip.config.{ts,cts,mts,js,cjs,mjs,json}. To point at a specific file, set configFile on the tsconfig entry:
{
"compilerOptions": {
"plugins": [
{ "transform": "@ttsc/strip", "configFile": "./config/strip.config.ts" }
]
}
}Sponsors
Thanks for your support.
Your donation encourages ttsc development.
