cap-js / cds-typer

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

typer 0.28.0 breaks build on Windows due to quoted path #374

Closed Kyrodan closed 2 weeks ago

Kyrodan commented 1 month ago

Is there an existing issue for this?

Nature of Your Project

TypeScript

Current Behavior

After updating cds-type to 0.28.0 and cds 8.x, executing cds build throws error:

error TS5033: Could not write file 'C:/Entwicklung/myproject/gen/srv"/srv/my-service.js': EINVAL: invalid argument, mkdir 'C:\Entwicklung\myproject\gen\srv"'.

    at Plugin.build (C:\Entwicklung\cap-ih\node_modules\@cap-js\cds-typer\cds-plugin.js:139:19)
    at async Promise.allSettled (index 0)
    at async BuildTaskEngine._executePipeline (C:\Users\daniel.boelts\AppData\Roaming\npm\node_modules\@sap\cds-dk\lib\build\buildTaskEngine.js:159:29)
    at async BuildTaskEngine._executeBuildTasks (C:\Users\daniel.boelts\AppData\Roaming\npm\node_modules\@sap\cds-dk\lib\build\buildTaskEngine.js:150:25)
    at async BuildTaskEngine.processTasks (C:\Users\daniel.boelts\AppData\Roaming\npm\node_modules\@sap\cds-dk\lib\build\buildTaskEngine.js:59:33)
    at async build (C:\Users\daniel.boelts\AppData\Roaming\npm\node_modules\@sap\cds-dk\lib\build\index.js:19:16)
    at async Object.build (C:\Users\daniel.boelts\AppData\Roaming\npm\node_modules\@sap\cds-dk\bin\build.js:171:5)
    at async Object.exec (C:\Users\daniel.boelts\AppData\Roaming\npm\node_modules\@sap\cds-dk\bin\cds.js:87:16)

Expected Behavior

Does not throw error.

Steps To Reproduce

Just run cds build on a CAP-Project. It worked with an erlier version of cds-typer.

Environment

- **OS**: Windows 11 (also tested on Windows 10)
- **Node**: 20.18.0
- **npm**: 10.8.2
- **cds-typer**: 0.28.0
- **cds**: 8.3.1
- **tsc**: 5.6.3

Repository Containing a Minimal Reproducible Example

No response

Anything else?

Commit https://github.com/cap-js/cds-typer/commit/c58b8b6c8f78ac1275aba6136dc5035ca92323ef now double-quotes the outDir of tsc command. This leads to this issue. Removing the double quotes makes it work again. I also tried to replace the double-quotes with single-quotes: same behavior. Without double quotes and spaces in path names the issue is like in #330.

Running exactly the same command (with double-quotes) in cmd and powershell: everything works.

And now the interesting thing: the output of tsc shows unix/posix-style path separators. So i tried to convert the "this.task.dest" to posix-style separators (this.task.dest.replaceAll("\\", "/")): it works as expected.

So it seems there is an incompatibility with Windows-Paths, quotes, the exec-method and the tsc command

daogrady commented 3 weeks ago

Hi Daniel,

thanks for reporting this issue! I am currently out of office with limited access to my work devices. I'd therefore recommend you downgrade cds-typer to version 0.27.0 for now. I will be back by next week and look into the matter asap.

Best, Daniel

Note to self: add a test for the build task to avoid xplatform issues in the future.

chgeo commented 2 weeks ago

And now the interesting thing: the output of tsc shows unix/posix-style path separators. So i tried to convert the "this.task.dest" to posix-style separators (this.task.dest.replaceAll("\\", "/")): it works as expected.

So it seems there is an incompatibility with Windows-Paths, quotes, the exec-method and the tsc command

I could reproduce the error. After many tries I came to the same conclusion of this being a bug with a mixture of Windows, shell quoting, tsc and node's exec function.

The only fix I can add now is the proposed conversion of \ to / in the path.