dxfrontier / cds-ts-dispatcher

SAP CAP TypeScript entity handler dispatcher.
13 stars 3 forks source link

[BUG] ENV postinstall script doesn't work on Windows #117

Open hakimio opened 2 hours ago

hakimio commented 2 hours ago

Current behavior

Try to debug to see why the postinstall script doesn't correctly generate CDS_ENV for me and doesn't compile it. Here is what I get on Windows 10:

Command: cds Result:

{
  error: Error: spawnSync cds ENOENT
      at Object.spawnSync (node:internal/child_process:1124:20)
      at spawnSync (node:child_process:877:24)
      at _class.executeShellCommand (node_modules\@dxfrontier\cds-ts-dispatcher\postinstall\PostInstall.js:103:45)
      at _class.generateEnvFile (node_modules\@dxfrontier\cds-ts-dispatcher\postinstall\PostInstall.js:45:31)
      at _class.run (node_modules\@dxfrontier\cds-ts-dispatcher\postinstall\PostInstall.js:116:12)
      at PostInstall2.run (node_modules\@dxfrontier\cds-ts-dispatcher\postinstall\PostInstall.js:135:23)
      at Object.<anonymous> (node_modules\@dxfrontier\cds-ts-dispatcher\postinstall\PostInstall.js:138:19)
      at Module._compile (node:internal/modules/cjs/loader:1469:14)
      at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)
      at Module.load (node:internal/modules/cjs/loader:1288:32) {
    errno: -4058,
    code: 'ENOENT',
    syscall: 'spawnSync cds',
    path: 'cds',
    spawnargs: [ 'env', 'get' ]
  },
  status: null,
  signal: null,
  output: null,
  pid: 0,
  stdout: null,
  stderr: null
}

Command: npx tsc Result:

{
  error: Error: spawnSync npx tsc ENOENT
      at Object.spawnSync (node:internal/child_process:1124:20)
      at spawnSync (node:child_process:877:24)
      at _class.executeShellCommand (@dxfrontier\cds-ts-dispatcher\postinstall\PostInstall.js:103:45)
      at _class.compileEnvFile (@dxfrontier\cds-ts-dispatcher\postinstall\PostInstall.js:54:10)
      at _class.run (@dxfrontier\cds-ts-dispatcher\postinstall\PostInstall.js:117:12)
      at PostInstall2.run (@dxfrontier\cds-ts-dispatcher\postinstall\PostInstall.js:135:23)
      at Object.<anonymous> (@dxfrontier\cds-ts-dispatcher\postinstall\PostInstall.js:138:19)
      at Module._compile (node:internal/modules/cjs/loader:1469:14)
      at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)
      at Module.load (node:internal/modules/cjs/loader:1288:32) {
    errno: -4058,
    code: 'ENOENT',
    syscall: 'spawnSync npx tsc',
    path: 'npx tsc',
    spawnargs: [
      'C:\\Users\\PC1\\WebstormProjects\\cds-ts-samples\\@dispatcher\\index.ts',
      '--outDir',
      'C:\\Users\\PC1\\WebstormProjects\\cds-ts-samples\\@dispatcher'
    ]
  },
  status: null,
  signal: null,
  output: null,
  pid: 0,
  stdout: null,
  stderr: null
}

Expected behavior

CDS_ENV is generated and transpiled.

Steps to reproduce

Try to install cds-ts-dispatcher on Windows.

Environment

Additional Info

Getting this working is not a priority for me, but, if you have access to Windows machine, would be nice if this could fixed.

dragolea commented 2 hours ago

Hi, Do you have the cds installed globally ? Do you use mbt build ? or just the normal npm install ?

hakimio commented 2 hours ago

Yes, both cds env and npx tsc works normally and are installed globally.

dragolea commented 2 hours ago

Ok, looks like it's about Windows 10, have you tried on Windows 11 or latest version ?

strategy:
      matrix:
        version: [20, 18]
        platform: [ubuntu-latest, windows-latest, macos-latest]

I am doing a strategy matrix and checking the following and for me worked, but I didn't checked on windows 10

hakimio commented 2 hours ago

Tested with just npm install. BTW, when running npx tsc command manually, noticed that I have to add --skipLibCheck. Otherwise I get missing mocha dependency error from cds types.

hakimio commented 2 hours ago

No, I haven't checked on Windows 11.

dragolea commented 2 hours ago

You use tsc for building the gen/srv/ ?

can you try Deploy cds-ts-dispatcher

hakimio commented 2 hours ago

Which script/command exactly do you want me to try to run? "build:ts": "tsc"? mbt build? The demo app doesn't compile right now because of CDS_ENV:

 npm run build:ts

> cds-ts-samples@1.0.0 build:ts
> tsc

srv/controller/cat-service/handler/BookHandler.ts:105:19 - error TS2345: Argument of type 'string' is not assignable to parameter of type 'never'.

105     @Env<CDS_ENV>('requires.auth.users') users: any[],
                      ~~~~~~~~~~~~~~~~~~~~~

Found 1 error in srv/controller/cat-service/handler/BookHandler.ts:105
hakimio commented 2 hours ago

Anyway, this is not very important for me personally. Just wanted to let you know. So, no rush. Feel free to look into this when you have time and access to Windows 10 machine.

dragolea commented 2 hours ago

Appreciate, like always your input ! :)

hakimio commented 1 hour ago

Ok, got it to work on Windows after some googling. Turns out the trick is pretty simple. You just have to add shell: true. Source: StackOverflow post.

Will you add the fix or should I do it?

BTW, there are some libraries which supposedly helps you avoid those kind of cross platform issues:

EDIT: might be a good idea to check both result.stderr and result.error for errors when deciding if command succeeded.

dragolea commented 1 hour ago

yes, I am having a look over cross-spawn :) Which option you've used the cross-spawn or shell: true ?

If you have time, you can create a PR defently :)

hakimio commented 1 hour ago

I only tested with shell: true.

dragolea commented 1 hour ago

Ok, shell might be a problem on mac, or unix.

hakimio commented 1 hour ago

Then cross-spawn could be a good option too.

dragolea commented 1 hour ago

ok, I will check cross-spawn Thanks