Resolve values of package.json scripts


I'm implementing the new `terminal.shellCommandHandler` extention in my plugin and at the moment I'm only able to detect commands directly referencing what I want to offer a smart handler for. IE: `stryker run` and `npx stryker run`. What I'd like to do is be able to scan the package.json scripts to see if there's an alias to `stryker run` somewhere. For example, if there's a script `"test:mutation": "stryker run"` in the package.json, I'd like to be able to detect that and offer a match if a user starts typing in `npm run test:mutation` or `yarn test:mutation`. 

I can't find a method like this in the NpmUtils class, is there a way to do this? 

1 comment
Comment actions Permalink

You can list all available tasks in the given package.json file using

NpmScriptsUtil.listTasks(project, file)


NpmScriptsUtil.findScriptProperty(project, file, "build")

You can access the JsonProperty holding the script value. A specific string is available in

NpmScriptsUtil.findScriptProperty(project, file, "build").value.text // "\"react-app-rewired build\""

Please sign in to leave a comment.