cap-js / cds-typer

CDS type generator for JavaScript
Apache License 2.0
29 stars 10 forks source link

[BUG] Missing option to pass CLI options to typer during 'cds build' #323

Closed stockbal closed 2 months ago

stockbal commented 2 months ago

Is there an existing issue for this?

Nature of Your Project

TypeScript

Current Behavior

I added the new cli option --useEntitiesProxy true to my VS Code settings (i.e. "cds.typeGenerator.command") and during development the types are getting generated correctly.

However, during the build, cds-typer is using the function compileFromFile directly and only passes the output directory as option. This results in not having the proxy exports in the final cds build output.

Expected Behavior

Some central way to specify cds-typer parameters that are used during development and during build, so the generated types output between dev and build does not differ.

Steps To Reproduce

No response

Environment

| Module                 | Version |
| ---------------------- | --------|
| @cap-js/asyncapi       | 1.0.2   |
| @cap-js/cds-typer      | 0.26.0  |
| @cap-js/cds-types      | 0.2.0   |
| @cap-js/change-tracking| 1.0.7   |
| @cap-js/hana           | 1.2.0   |
| @cap-js/openapi        | 1.0.5   |
| @cap-js/sqlite         | 1.7.3   |
| @sap/cds               | 8.2.1   |
| @sap/cds-compiler      | 5.2.0   |
| @sap/cds-dk            | 8.2.0   |
| @sap/cds-dk (global)   | 7.9.6   |
| @sap/cds-fiori         | 1.2.7   |
| @sap/cds-foss          | 5.0.1   |
| @sap/cds-mtxs          | 2.1.0   |
| @sap/eslint-plugin-cds | 3.0.4   |
| Node.js                | v20.16.0|

Repository Containing a Minimal Reproducible Example

No response

Anything else?

No response

daogrady commented 2 months ago

Hi Ludwig,

thanks for pointing this out. I have some good news, then some bad news, then some more good news: cds-typer can be fully configured using cds.env. More specifically, you can place any of the relevant options under cds.env.typer just as you would pass them in as parameters. Those should then be picked up by cds-typer, regardless of whether you run it from the IDE or as part of your build process. But as I have recently found out, camelCased environment options can not be used in all constellations for technical reasons. I am therefore currently in the process of allowing any option to be passed in both camelcase and snake_case. It's a bit more involved than I had originally anticipated, but once that is done, you'll be able to use cds: { typer: { use_entities_proxy: true } } as part of your package.json, or in any other way you can use to modify cds.env.

Best, Daniel

daogrady commented 2 months ago

Hi Ludwig,

I have now merged the configuration via snake case, so it is available in main now if you would like to confirm this works.

Best, Daniel

stockbal commented 2 months ago

Hi @daogrady,

I checked it and it works. I configured it via cds in my package.json.

...
"cds": {
   "typer": {
      "useEntitiesProxy": "true",
      "outputDirectory": "@cds-models"
    }
}
...

but as you can see, I also have to configure the outputDirectory in the env, otherwise the cds-typer build-plugin fails, as the output directory is ignored:

/cds-plugins.js image

/lib/compile.js image

daogrady commented 2 months ago

Hi Ludwig,

thanks for pointing this out! I will revisit the build-plugin, which was not built with configuration via cds.env in mind.

Best, Daniel

daogrady commented 2 months ago

Hi Ludwig,

I have attached a PR to prioritise configuration passed through cds.env. If you would like to check it before I merge, just let me know.

Best, Daniel

stockbal commented 2 months ago

Hi Daniel,

i left you a comment on the PR.

Regards, Ludwig