cap-js / cds-typer

CDS type generator for JavaScript
Apache License 2.0
28 stars 9 forks source link

[QUESTION] How to integrate cds-typer into the CI #142

Closed mcastrup closed 9 months ago

mcastrup commented 9 months ago

Question

I have problems to integrate cds-typer in our CI process. I already had a look at the documentation and I also tried to adapt the mta.yaml file. However, I always get an error like Error: lib/masterData/businessPartners/DbBusinessPartnerRepository.ts(17,38): error TS2307: Cannot find module '#cds-models/sap/erp4sme/c4b/masterData/businessPartners' or its corresponding type declarations. in the build process of the pipeline.

The build job on github is defined in our pr_voter.yml file. Here, npm run build is executed. Thus, I added to the build script in the package.json the script: "cds-typer": "npx @cap-js/cds-typer \"*\" --outputDirectory @cds-models && npx @cap-js/cds-typer \"*\" --outputDirectory gen/srv/@cds-models", I tried several options and finally decided to run cds-typer twice, once with the output directory @cds-models and once with gen/srv/@cds-models. But the result is always the same: the error mentioned above.

E.g. the generated types cannot be found in the file DbBusinessPartnerRepository.ts.

Locally in Visual Studio Code, everything works fine.

It would be great if you can have a look at our repository and the PR error and give some advice. If needed, we can schedule a meeting.

Thanks and best regards, Michael

daogrady commented 9 months ago

Hi Michael,

thanks for bringing up this issue. I checked your repository and the tsconfig.json appears to be missing the aliasing for #cds-models. Running cds add typer should add this section automatically. Does adding this section help?

Best, Daniel

mcastrup commented 9 months ago

Hi Daniel,

thanks for the hint. I executed cds add typer and it indeed touched the tsconfig.json file, however, the file just got only formatted newly, no actual content was changed. The file already included the following line "paths": { "#cds-models/*": ["./@cds-models/*/index.ts"] } if this is ment with

missing the aliasing for #cds-models

Or is anything else missing?

Best regards, Michael

mcastrup commented 9 months ago

Hi Daniel,

finally, I noticed that we have besides the tsconfig.json also a tsconfig.deploy.json file. I added the path alias also to this file. The above mentioend errors are gone now. :-)

Please thinks about to include this informatuion also into your documentation. And the cds add typer command should also take care of such a tsconfig.deploy.json file.

Best regards, Michael

daogrady commented 9 months ago

Hi Michael,

glad you could fix the issue!

Best, Daniel