cds-plugin-typescript
A CDS build task that compiles TypeScript sources during cds build, so the deployed artefact is JavaScript without a separate build step in the pipeline.
Facts
Where it sits
Who is behind it
In the atlas: maintains 1, contributes to 1@pwasemmaintainer
What it declares
Every artifact
- Type
- Build tool
- Origin
- Independently maintained
As a build tool
- Declared for
- >=8
- Distributed through
- npm
Connections
How an application is arranged once written in TypeScript
Download
Install
npm add cds-plugin-typescriptDerived from the package name. No recipe recorded; the README has the configuration.
README
quoted from pwasem/cds-plugin-typescript under MIT, readcds-plugin-typescript
A CDS build plugin for SAP CAP that compiles TypeScript sources to JavaScript as part of cds build.
It is similar to cds-typer but focused exclusively on TypeScript compilation. It also supports resolving TypeScript path aliases via tsc-alias.
Prerequisites
- Node.js
>=22 - npm
>=10 @sap/cds>=8typescript>=5tsc-alias>=1(optional — automatically detected and used if listed in your project'spackage.json)
Installation
npm install --save-dev cds-plugin-typescript
Usage
Once installed, the plugin is automatically discovered and activated — no manual registration needed. It's a cds-plugin and will be loaded by CAP automatically.
Simply run cds build and the plugin will:
- Detect your tsconfig file (see tsconfig resolution below)
- Compile TypeScript sources with
tsc - Resolve path aliases with
tsc-alias(automatic — runs iftsc-aliasis found in your project's dependencies or devDependencies) - Remove
.tssource files from the build output
Configuration
Zero configuration is required by default. Simply:
- Install the plugin (
npm install --save-dev cds-plugin-typescript) - Maintain a tsconfig file — the plugin automatically looks for
tsconfig.cdsbuild.json,tsconfig.build.json, ortsconfig.json(first found wins) - Run
cds build
That's it — no package.json changes needed.
Custom tsConfig path
The cds.build.tasks configuration in package.json is only needed if you want to point the plugin at a tsconfig file with a non-standard name (i.e. something other than the three files listed above):
{
"cds": {
"build": {
"tasks": [
{ "for": "nodejs" },
{
"for": "typescript",
"options": {
"tsConfig": "tsconfig.custom.json"
}
}
]
}
}
}
| Option | Type | Default | Description |
|---|---|---|---|
tsConfig | string | — | Custom TypeScript config file path. When provided, this takes highest priority in the resolution order. |
tsconfig resolution
The plugin resolves the tsconfig file using the following priority order:
- Custom path via the
tsConfigoption (if provided in the build task configuration) tsconfig.cdsbuild.json— a CDS-build-specific configtsconfig.build.json— a general build-specific configtsconfig.json— the standard TypeScript config
The plugin uses the first file found in this order. This allows you to maintain separate TypeScript configurations for CDS builds, general builds, and development without conflicts.
The default/recommended tsconfig for the default CDS folder structure is:
{
"compilerOptions": {
"rootDir": "srv",
"outDir": "gen/srv/srv",
"declaration": true,
"sourceMap": true,
"removeComments": true
},
"include": [
"srv/**/*"
]
}
The
outDirin your tsconfig determines where compiled output lands — make sure it aligns with your CDS build target (default:gen).
Path aliases
If your project uses TypeScript path aliases (e.g. @/* → src/*), simply add tsc-alias to your project's dependencies or devDependencies:
npm install --save-dev tsc-alias
The plugin automatically detects whether tsc-alias is listed in your package.json (under dependencies or devDependencies) and runs it after tsc to rewrite the aliases in the compiled JavaScript. No additional configuration is needed.
If tsc-alias is not listed in your package.json, the path alias resolution step is skipped entirely.
How it works
The plugin extends cds.build.Plugin and is registered under the task type typescript.
Build steps:
- Resolve the tsconfig path (priority:
tsConfigoption →tsconfig.cdsbuild.json→tsconfig.build.json→tsconfig.json) - Run
npx tsc -p <tsconfig>from the task source directory — logs: "Compiling TypeScript using <tsconfig>" - If
tsc-aliasis detected inpackage.json: runnpx tsc-alias -p <tsconfig>— logs: "Resolving path aliases" - Delete all
.tsfiles (excluding.d.ts) from the build output — logs: "Removing TypeScript sources"
Clean step:
cds build --clean removes all .js and .map files emitted by this plugin from the destination directory.
TypeScript 7
TypeScript 7.0 is a native Go port and does not ship with a programmatic API yet. Tools that rely on import('typescript') (such as tsc-alias, typescript-eslint, and CAP itself) still need the TypeScript 6 API.
Microsoft provides a compatibility package @typescript/typescript6 that re-exports the TypeScript 6 API but renames its binary to tsc6, allowing TypeScript 6 and 7 to coexist. You can install both via npm aliases so that npx tsc uses TypeScript 7 while tooling that calls import('typescript') gets the TypeScript 6 API:
{
"devDependencies": {
"@typescript/native": "npm:typescript@^7.0.2",
"typescript": "npm:@typescript/typescript6@^6.0.2"
}
}
This plugin works with this setup out of the box — it shells out to npx tsc (TypeScript 7) and detects tsc-alias in your package.json (which continues to use the TypeScript 6 API transparently).
Related
License
History
Others providing
Compare all 8 on the TypeScript patterns page →- @dxfrontier/cds-ts-dispatcher@dxfrontier/cds-ts-dispatcherDecorator-driven handler registration for CAP in TypeScript, where handlers are declared on a class rather than wired up one by one in an init function.independent, capDecorator-driven handler registration for CAP in TypeScript
- @dxfrontier/cds-ts-repository@dxfrontier/cds-ts-repositoryA typed BaseRepository over CAP entities, so persistence is called through a class with methods rather than through CQN written inline in each handler.independent, capTyped BaseRepository over CAP entities
- cds-plugin-handlerscds-plugin-handlersA CAP plugin that structures handlers as one file per entity, in a folder per service, instead of one service implementation that keeps growing.independent, capOne handler file per entity in CAP services
- cds-routing-handlerscds-routing-handlersDecorator-based routing of CAP service handlers in TypeScript, from before the core had an opinion — the framework the CDS-TS-Dispatcher post names as its unmaintained predecessor.independent, capDecorator-based routing of CAP service handlers in TypeScript
- cds2typescds2typesA command-line tool that generates TypeScript interfaces from a CDS model, written before @cap-js/cds-typer existed.independent, capCLI generating TypeScript interfaces from a CDS model
- cap-handler-frameworkcap-handler-frameworkConvention-based handler layer for CAP: methods named beforeCreate, onRead or afterUpdate are mapped automatically, with the draft lifecycle given its own explicit hooks rather than folded into the active-entity ones.independent, capConvention-based handler layer for CAP with draft lifecycle hooks
- cds-hyper-app-servicecds-hyper-app-serviceA typed service implementation layer over CAP ApplicationService, for writing handlers as class members rather than registrations; last released July 2022, with no repository declared.independent, capTyped class-based service layer over CAP ApplicationService
Details
Sources
Sources are graph entities: the same page may back several entries, and an unreachable source flags every row that rests on it.
Compatibility and provenance
Flavors
“It's a [cds-plugin](https://cap.cloud.sap/docs/node.js/cds-plugins) and will be loaded by CAP automatically.” — pwasem/cds-plugin-typescript — README
History in the atlas
- The edge carried no sentence. It now says what the plugin does at build time and that it says nothing about the arrangement of the code it compiles. Whether the edge belongs on typescript-patterns is an open editorial question recorded with the capability's review: capire now ships a cds build task for TypeScript in @cap-js/cds-typer, which puts this plugin beside the core's toolchain answer rather than beside the arrangement options. No facet values are stated, because the capability's four facets ask about the arrangement and the README answers none of them.
- Typed cds-plugin by placement, which defaults every candidate to that. It is not one.
- A CDS build task that compiles TypeScript sources during `cds build`, so the deployed artefact is JavaScript without a separate build step in the pipeline.
- First seen.
For your agent
- Ref
artifact:pwasem-cds-plugin-typescript- JSON
- /artifacts/pwasem-cds-plugin-typescript.json
- MCP
- Connecting an agent