Developing a VSCode extension and trying to use sonarqube-scanner-npm package. When run the script below explicitly on a terminal with the following command node sonarqube-scanner-script.ts, it works as expected.
const scanner = require("sonarqube-scanner");
scanner(
{
serverUrl: "https://sonarcloud.io",
token: "my_api_key",
options: {
"sonar.projectName": "My project name",
"sonar.projectDescription": "",
"sonar.organisation": "My org",
"sonar.sources": "src",
"sonar.tests": "test",
},
},
() => process.exit()
);
However, when put the code inside the extension it causes an error.
export function activate(context: vscode.ExtensionContext) {
//...
let sonarqubeTest = vscode.commands.registerCommand(
"myextension.sonarqubeTest",
() => {
// The code placed here will be executed every time the command is executed
scanner(
{
serverUrl: "https://sonarcloud.io",
token: "my_api_key",
options: {
"sonar.projectName": "My project name",
"sonar.projectDescription": "",
"sonar.organisation": "My org",
"sonar.sources": "src",
"sonar.tests": "test",
},
},
() => process.exit()
);
}
);
context.subscriptions.push(sonarqubeTest);
//...
}
This is the error encountered:
rejected promise not handled within 1 second: Error: Command failed: /Users/[me]/.sonar/native-sonar-scanner/sonar-scanner-5.0.1.3006-macosx/bin/sonar-scanner --from=ScannerNpm/3.3.0
extensionHostProcess.js:144
stack trace: Error: Command failed: /Users/[me]/.sonar/native-sonar-scanner/sonar-scanner-5.0.1.3006-macosx/bin/sonar-scanner --from=ScannerNpm/3.3.0
at checkExecSyncError (node:child_process:934:11)
at execFileSync (node:child_process:970:15)
at func (node:electron/js2c/asar_bundle:2:2131)
at scan (/Users/[me]/[...]/node_modules/sonarqube-scanner/src/index.js:40:3)