tsc-hooks

raw JSON →
1.1.2 verified Fri May 01 auth: no javascript

tsc-hooks (v1.1.2) is a TypeScript compiler hook system that extends tsc's functionality by allowing custom scripts to run before or after compilation. It integrates via a new 'hooks' array in tsconfig.json, enabling built-in hooks like 'copy-files' (to copy non-TypeScript files) and 'file-permissions' (to set file permissions). The package requires TypeScript ^4.3.2 || ^5.0.2 as a peer dependency. It is actively maintained with a simple configuration approach, differing from alternatives like ts-patch or ttypescript by providing a hook interface rather than patching the compiler API.

error Cannot find module 'tsc-hooks'
cause Package not installed or not in NODE_PATH.
fix
Run npm install --save-dev tsc-hooks
error Unknown compiler option 'hooks'.
cause tsc-hooks not loaded; tsc itself doesn't recognize this option.
fix
Use npx tsc instead of plain tsc, or ensure tsc-hooks is required before tsc.
error TypeError: (0 , tscHooks.default) is not a function
cause Using require('tsc-hooks') instead of import.
fix
Use ES module import syntax: import tscHooks from 'tsc-hooks'
breaking Hooks property is a new tsconfig key not supported by tsc directly
fix Ensure tsc-hooks is installed and invoked (e.g., via npx tsc) to process hooks; otherwise they are ignored.
broken Hook execution order depends on array order in tsconfig.json
fix Arrange hooks array in desired execution order.
gotcha copy-files hook copies all files matched by 'include' pattern, not just non-TypeScript files; exclude .ts files explicitly if not desired.
fix Use 'exclude' in tsconfig to skip .ts files if they should not be copied.
deprecated TypeScript 4.x support deprecated; only 5.x recommended.
fix Upgrade TypeScript to ^5.0.2 or later.
npm install tsc-hooks
yarn add tsc-hooks
pnpm add tsc-hooks

Shows how to configure and use the copy-files hook via tsconfig.json to copy static assets after compilation.

// Install: npm install --save-dev tsc-hooks typescript
// tsconfig.json
{
  "compilerOptions": {
    "outDir": "dist",
    "rootDir": "src"
  },
  "include": ["src/**/*"],
  "hooks": ["copy-files"],
  "copyFiles": {
    "./src/static/": "./dist/static/"
  }
}
// Then run: npx tsc
// The copy-files hook will copy static files not handled by tsc.