Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Executed command from GUI and terminal are not equal. #2207

Closed
cre8 opened this issue Jul 11, 2024 · 5 comments
Closed

Executed command from GUI and terminal are not equal. #2207

cre8 opened this issue Jul 11, 2024 · 5 comments
Labels
type: bug Something isn't working

Comments

@cre8
Copy link

cre8 commented Jul 11, 2024

Current Behavior

I have defined this command in one of my projects:

"api": {
      "executor": "nx:run-commands",
      "options": {
        "commands": [
          "npx @openapitools/openapi-generator-cli generate -g typescript-angular --skip-validate-spec -i http:https://localhost:3001/api-json -o libs/issuer-shared/src/lib/api --additional-properties=supportsES6=true,enumPropertyNaming=original,serviceSuffix=ApiService"
        ]
      }
    }

When I execute it via the terminal with nx run issuer-shared:api, it works fine by running the task (generating the SDK).

But when I run it via the extension in VS-Code, I get this output:

Executing task: pnpm exec nx run issuer-shared:api 

> nx run issuer-shared:api

> npx @openapitools/openapi-generator-cli generate -g typescript-angular --skip-validate-spec -i http:https://localhost:3001/api-json -o libs/issuer-shared/src/lib/api --additional-properties=supportsES6=true,enumPropertyNaming=original,serviceSuffix=ApiService

/Users/mirko/.npm/_npx/6e21a6866cba782f/node_modules/@openapitools/openapi-generator-cli/main.js:2
(()=>{"use strict";var e=[,e=>{e.exports=require("@nestjs/core")},(e,t,r)=>{var i,o,a;Object.defineProperty(t,"__esModule",{value:!0}),t.AppModule=void 0;const s=r(3),n=r(4),p=r(5),c=r(6),l=r(7),d=r(8),g=r(10),h=r(28),u=process.env.HTTP_PROXY||process.env.HTTPS_PROXY,m={};u&&(m.proxy=!1,m.httpsAgent=new h.HttpsProxyAgent(u));let f=class AppModule{constructor(e,t,r){this.program=e,this.versionManager=t,this.passThroughService=r,this.onApplicationBootstrap=async()=>{let e=this.versionManager.getSelectedVersion();if(!e){const[{version:t}]=await this.versionManager.search(["latest"]).toPromise();await this.versionManager.setSelectedVersion(t),e=t}await this.versionManager.downloadIfNeeded(e),await this.passThroughService.init(),this.program.parse(process.argv)}}};t.AppModule=f,t.AppModule=f=s.__decorate([(0,n.Module)({imports:[p.HttpModule.register({...m})],controllers:[d.VersionManagerController],providers:[g.UIService,g.ConfigService,g.GeneratorService,g.PassThroughService,g.VersionManagerService,{provide:l.COMMANDER_PROGRAM,useValue:new c.Command("openapi-generator-cli").helpOption(!1).usage("<command> [<args>]").option("--openapitools <openapitools.json>","Use the specified openapi-generator-cli configuration file")},{provide:l.LOGGER,useValue:console}]}),s.__param(0,(0,n.Inject)(l.COMMANDER_PROGRAM)),s.__metadata("design:paramtypes",["function"==typeof(i=void 0!==c.Command&&c.Command)?i:Object,"function"==typeof(o=void 0!==g.VersionManagerService&&g.VersionManagerService)?o:Object,"function"==typeof(a=void 0!==g.PassThroughService&&g.PassThroughService)?a:Object])],f)},e=>{e.exports=require("tslib")},e=>{e.exports=require("@nestjs/common")},e=>{e.exports=require("@nestjs/axios")},e=>{e.exports=require("commander")},(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.COMMANDER_PROGRAM=t.LOGGER=void 0,t.LOGGER=Symbol("LOGGER"),t.COMMANDER_PROGRAM=Symbol("COMMANDER_PROGRAM")},(e,t,r)=>{var i,o,a,s;Object.defineProperty(t,"__esModule",{value:!0}),t.VersionManagerController=void 0;const n=r(3),p=r(4),c=r(7),l=r(6),d=n.__importDefault(r(9)),g=r(10);let h=class VersionManagerController{constructor(e,t,r,i){this.logger=e,this.program=t,this.ui=r,this.service=i,this.mainCommand=this.program.command("version-manager").description("Manage used / installed generator version"),this.listCommand=this.mainCommand.command("list [versionTags...]").description("lists all published versions").option("-j, --json","print as json",!1).action((e=>this.list(e))),this.setCommand=this.mainCommand.command("set <versionTags...>").description("set version to use").action((e=>this.set(e))),this.list=async e=>{const t=await this.service.search(e).toPromise();if(this.listCommand.opts().json)return void this.logger.log(JSON.stringify(t,null,2));if(t.length<1)return void this.logger.log(d.default.red("No results for: "+e.join(" ")));const{version:r,installed:i}=await this.table(t),o=await this.service.isSelectedVersion(r),a=(e,t=(()=>null),r=(e=>e))=>({name:r(e),value:t}),s=[a("exit")];i?o||s.unshift(a("remove",(()=>this.service.remove(r)),d.default.red)):s.unshift(a("download",(()=>this.service.download(r)),d.default.yellow)),o||s.unshift(a("use",(()=>this.service.setSelectedVersion(r)),d.default.green)),await(await this.ui.list({name:"next",message:"Whats next?",choices:s}))()},this.set=async e=>{const t=await this.service.search(e).toPromise();t.length>0?await this.service.setSelectedVersion(t[0].version):this.logger.log(d.default.red(`Unable to find version matching criteria "${e.join(" ")}"`))},this.table=e=>this.ui.table({printColNum:!1,message:"The following releases are available:",name:"version",rows:e.map((e=>{const t=e.versionTags.includes("stable"),r=this.service.isSelectedVersion(e.version),i=e.versionTags.map((e=>"latest"===e?d.default.green(e):e));return{value:e,short:e.version,row:{"\u2610":r?"\u2612":"\u2610",releasedAt:e.releaseDate.toISOString().split("T")[0],version:t?d.default.yellow(e.version):d.default.gray(e.version),installed:e.installed?d.default.green("yes"):d.default.red("no"),versionTags:i.join(" ")}}}))})}};t.VersionManagerController=h,t.VersionManagerController=h=n.__decorate([(0,p.Controller)(),n.__param(0,(0,p.Inject)(c.LOGGER)),n.__param(1,(0,p.Inject)(c.COMMANDER_PROGRAM)),n.__metadata("design:paramtypes",["function"==typeof(i=void 0!==c.LOGGER&&c.LOGGER)?i:Object,"function"==typeof(o=void 0!==l.Command&&l.Command)?o:Object,"function"==typeof(a=void 0!==g.UIService&&g.UIService)?a:Object,"function"==typeof(s=void 0!==g.VersionManagerService&&g.VersionManagerService)?s:Object])],h)},e=>{e.exports=require("chalk")},(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});const i=r(3);i.__exportStar(r(11),t),i.__exportStar(r(14),t),i.__exportStar(r(18),t),i.__exportStar(r(27),t),i.__exportStar(r(22),t)},(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.UIService=void 0;const i=r(3),o=r(4),a=r(12),s=r(13);let n=class UIService{async table(e){const t=(0,s.getTable)(e.rows.map((({row:t},r)=>!1===e.printColNum?t:{"#":r+1,...t}))),[r,i,...o]=t.trim().split("\n");return this.list({name:e.name,message:e.message,choices:[new a.Separator(r),new a.Separator(i),...o.map(((t,r)=>({name:t,short:e.rows[r].short,value:e.rows[r].value}))),new a.Separator(i),new a.Separator(" ".repeat(i.length))]})}async list(e){const t=e.choices.filter((e=>e instanceof a.Separator)).length;return(await(0,a.prompt)([{type:"list",name:e.name,pageSize:process.stdout.rows-t-1,message:e.message,choices:e.choices}]))[e.name]}};t.UIService=n,t.UIService=n=i.__decorate([(0,o.Injectable)()],n)},e=>{e.exports=require("inquirer")},e=>{e.exports=require("console.table")},(e,t,r)=>{var i,o;Object.defineProperty(t,"__esModule",{value:!0}),t.ConfigService=void 0;const a=r(3),s=r(4),n=a.__importStar(r(15)),p=r(7),c=r(16),l=a.__importStar(r(17)),d=r(6);let g=class ConfigService{configFileOrDefault(){this.program.parseOptions(process.argv);const e=this.program.opts().openapitools;return e?n.isAbsolute(e)?e:n.resolve(this.cwd,e):n.resolve(this.cwd,"openapitools.json")}get useDocker(){return this.get("generator-cli.useDocker",!1)}get dockerImageName(){return this.get("generator-cli.dockerImageName","openapitools/openapi-generator-cli")}constructor(e,t){this.logger=e,this.program=t,this.cwd=process.env.PWD||process.env.INIT_CWD||process.cwd(),this.configFile=this.configFileOrDefault(),this.defaultConfig={$schema:"./node_modules/@openapitools/openapi-generator-cli/config.schema.json",spaces:2,"generator-cli":{version:void 0}}}get(e,t){return(0,c.get)(this.read(),e,t)}has(e){return(0,c.has)(this.read(),e)}set(e,t){return this.write((0,c.set)(this.read(),e,t)),this}read(){return l.ensureFileSync(this.configFile),(0,c.merge)(this.defaultConfig,l.readJSONSync(this.configFile,{throws:!1,encoding:"utf8"}))}write(e){l.writeJSONSync(this.configFile,e,{encoding:"utf8",spaces:e.spaces||2})}};t.ConfigService=g,t.ConfigService=g=a.__decorate([(0,s.Injectable)(),a.__param(0,(0,s.Inject)(p.LOGGER)),a.__param(1,(0,s.Inject)(p.COMMANDER_PROGRAM)),a.__metadata("design:paramtypes",["function"==typeof(i=void 0!==p.LOGGER&&p.LOGGER)?i:Object,"function"==typeof(o=void 0!==d.Command&&d.Command)?o:Object])],g)},e=>{e.exports=require("path")},e=>{e.exports=require("lodash")},e=>{e.exports=require("fs-extra")},(e,t,r)=>{var i,o,a;Object.defineProperty(t,"__esModule",{value:!0}),t.GeneratorService=void 0;const s=r(3),n=r(4),p=r(16),c=s.__importDefault(r(19)),l=s.__importStar(r(15)),d=s.__importStar(r(17)),g=s.__importStar(r(20)),h=s.__importDefault(r(9)),u=s.__importStar(r(21)),m=r(22),f=r(14),v=r(7);let y=class GeneratorService{constructor(e,t,r){this.logger=e,this.configService=t,this.versionManager=r,this.configPath="generator-cli.generators",this.enabled=this.configService.has(this.configPath),this.cmd=(e,t,r={})=>{if(this.configService.useDocker){const e=Object.entries(r).map((([e,t])=>`-v "${t}:${e}"`)).join(" "),i=u.userInfo();return["docker run --rm",-1!==i.uid?`--user ${i.uid}:${i.gid}`:"",e,this.versionManager.getDockerImageName(),"generate",t].join(" ")}const i=this.versionManager.filePath(Warning: command "npx @openapitools/openapi-generator-cli generate -g typescript-angular --skip-validate-spec -i http:https://localhost:3001/api-json -o libs/issuer-shared/src/lib/api --additional-properties=supportsES6=true,enumPropertyNaming=original,serviceSuffix=ApiService" exited with non-zero status code
—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 NX   Ran target api for project issuer-shared (4s)

   ✖  1/1 failed
   ✔  0/1 succeeded [0 read from cache]

Expected Behavior

Since the execution via the GUI gives the feedback that the command nx run issuer-shared:api gets executed, I would expect the same result. When running the command via different terminals, it is working fine.

Steps to Reproduce

Environment

  • Nx Console version: 18.24.1
  • VSCode version: 1.91
@cre8 cre8 added the type: bug Something isn't working label Jul 11, 2024
@MaxKless
Copy link
Collaborator

Hey thanks for the report @cre8!
This looks like it could be due to different node versions being loaded by vscode & your shell.
Can you go through the Nx Console Troubleshooting Steps and Node.js installation issues and try out the recommended steps?
Then report back with the results :)

@cre8
Copy link
Author

cre8 commented Jul 11, 2024

@MaxKless thank you for the links. I removed nvm from my system and checked for other node installation. After this I made a fresh nvm install.
This is the output of my nx report:

Node   : 22.4.1
OS     : darwin-arm64
pnpm   : 8.15.8

nx                 : 19.3.2
@nx/js             : 19.3.2
@nx/jest           : 19.3.2
@nx/linter         : 19.3.2
@nx/eslint         : 19.3.2
@nx/workspace      : 19.3.2
@nx/angular        : 19.3.2
@nx/devkit         : 19.3.2
@nx/eslint-plugin  : 19.3.2
@nx/nest           : 19.3.2
@nx/node           : 19.3.2
@nx/playwright     : 19.3.2
@nrwl/tao          : 19.3.2
@nx/vite           : 19.3.2
@nx/web            : 19.3.2
@nx/webpack        : 19.3.2
typescript         : 5.4.5
---------------------------------------
Registered Plugins:
@nx/vite/plugin
@nx/webpack/plugin
@nx/eslint/plugin
@nx/jest/plugin
@nx/playwright/plugin
---------------------------------------
Community plugins:
@nx-tools/nx-container : 6.0.1

I only have one installed node version and the command worked fine in the zsh terimal started inside vscode, but not via the GUI when I start it from the sidebar.

I also printed out the $SHELL variable to make sure both approaches are using the same. They both use /bin/zsh.

Before I worked on Windows and had no problem with the vscode plugin.

@MaxKless
Copy link
Collaborator

Thanks for checking it out... I'm not sure what's going on there. Just to be sure: when you're running it via the integrated terminal, are you also using pnpm exec?

@cre8
Copy link
Author

cre8 commented Jul 12, 2024

I digged deeper and it's not a problem of nx. When I call the the command npx @open ... as a task in vscode, I get a missmatch in the java versions. It seems like vscode is not using the same JAVA_HOME variable for the tasks as it does in the terminal, so here is the error. Unfortunately this error was not thrown when called via nx...
So closing this since this is not a problem of NX, but more of my configuration.
Ty for your help :)

I found out when I open the project via the terminal via code . everything works fine. But when I start vscode via the finder in os x, it will not load the the zshrc file when I want to run tasks and therefore not the correct JAVA_HOME variable

Update: adding "terminal.integrated.profiles.osx": { "zsh": { "path": "/bin/zsh", "args": ["-l", "-i"] } } in the vscode settings solved my problem in case anyone is having the same problem :)

@cre8 cre8 closed this as completed Jul 12, 2024
@MaxKless
Copy link
Collaborator

Glad you were able to resolve this! environment stuff like this is tricky, you're definitely not the first person to report an issue like this :)
Thanks for reporting the issue and trying to make Nx Console better. Feel free to leave a review on the VSCode extension marketplace if you enjoy it and are so inclined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants