Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import path from "node:path";
import {EOL} from "os";
import { availableProviders, match } from './provider.js'
Expand All @@ -25,6 +24,27 @@ function logOptionsAndEnvironmentsVariables(alongsideText,valueToBePrinted) {

}

function readAndPrintVersionFromPackageJson() {
let dirName
// new ESM way in nodeJS ( since node version 22 ) to bring module directory.
dirName = import.meta.dirname
// old ESM way in nodeJS ( before node versions 22.00 to bring module directory)
if (!dirName) {
dirName = url.fileURLToPath(new URL('.', import.meta.url));
}

try {
if (__dirname) {
dirName = __dirname;
}
} catch (e) {
console.log("__dirname is not defined, continue with fileUrlPath")
}

let packageJson = JSON.parse(fs.readFileSync(path.join(dirName, "..", "package.json")).toString())
logOptionsAndEnvironmentsVariables("exhort-javascript-api analysis started, version: ", packageJson.version)
}

/** This function is used to determine exhort theUrl backend according to the following logic:
* If EXHORT_DEV_MODE = true, then take the value of the EXHORT BACKEND URL of dev/staging environment in such a way:
* take it as environment variable if exists, otherwise, take it from opts object if exists, otherwise, use the hardcoded default of DEV environment.
Expand All @@ -38,21 +58,10 @@ function logOptionsAndEnvironmentsVariables(alongsideText,valueToBePrinted) {
* @private
*/
function selectExhortBackend(opts= {}) {

let dirName
// new ESM way in nodeJS ( since node version 22 ) to bring module directory.
dirName = import.meta.dirname
// old ESM way in nodeJS ( before node versions 22.00 to bring module directory)
if (!dirName) {
dirName = url.fileURLToPath(new URL('.', import.meta.url));
}

if (!dirName && __dirname !== undefined && __dirname !== null) {
dirName = __dirname;
}
let packageJson = JSON.parse(fs.readFileSync(path.join(dirName, "..","package.json" )).toString())
logOptionsAndEnvironmentsVariables("exhort-javascript-api analysis started, version: ",packageJson.version)
let result
if (process.env["EXHORT_DEBUG"] === "true") {
let packageJson = readAndPrintVersionFromPackageJson();
}
let exhortDevModeBundled = "false"
let exhortDevMode = getCustom("EXHORT_DEV_MODE",exhortDevModeBundled,opts)
if(exhortDevMode !== null && exhortDevMode.toString() === "true") {
Expand Down