Registry / devops / tsc-hooks

tsc-hooks

JSON →
library1.1.2jsnpmunverified

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.

npm install tsc-hooks
INSTALL
IMPORT
SIG · TSC-HOOKS
T
tsc-hooks
devopsjavascriptv1.1.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import tscHooks from 'tsc-hooks'
const tscHooks = require('tsc-hooks')
ESM-only package; no CommonJS export. Use import syntax.
TSCHooks
import { TSCHooks } from 'tsc-hooks'
import { TscHooks } from 'tsc-hooks'
Named export is TSCHooks (capitalized). Not default.
HookFunction
import type { HookFunction } from 'tsc-hooks'
import { HookFunction } from 'tsc-hooks'
HookFunction is a type; use import type for type-only import.
HookConfig
import type { HookConfig } from 'tsc-hooks'
import { HookConfig } from 'tsc-hooks'
HookConfig is a type; use import type to avoid runtime errors.

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.
Debug
Known issues
breakingHooks 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.
affects: all
brokenHook execution order depends on array order in tsconfig.json
fix
Arrange hooks array in desired execution order.
affects: all
gotchacopy-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.
affects: all
deprecatedTypeScript 4.x support deprecated; only 5.x recommended.
fix
Upgrade TypeScript to ^5.0.2 or later.
affects: >=1.1.0
Errors
Common errors & fixes
Cannot find module 'tsc-hooks'
Package not installed or not in NODE_PATH.
fix
Run `npm install --save-dev tsc-hooks`
Unknown compiler option 'hooks'.
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.
TypeError: (0 , tscHooks.default) is not a function
Using require('tsc-hooks') instead of import.
fix
Use ES module import syntax: import tscHooks from 'tsc-hooks'
Upgrade
Version history
1.1.2latest on npm
Audit
Dependencies
typescriptrequiredPeer dependency: requires TypeScript 4.3.2+ or 5.0.2+ for the compiler API and tsc binary.
Agent activity
2 hits · last 30 days
node
2
Resources
tsc-hooks — npm install tsc-hooks · libregistry