Skip to content

Commit

Permalink
Merge pull request #139 from RHEcosystemAppEng/hotfix/directory-resol…
Browse files Browse the repository at this point in the history
…ve-cjs

fix: commonjs clients crash
  • Loading branch information
zvigrinberg authored May 16, 2024
2 parents 15cd52a + da52427 commit a1da46e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import path from "node:path";
import {EOL} from "os";
import { availableProviders, match } from './provider.js'
Expand Down Expand Up @@ -37,11 +38,17 @@ function logOptionsAndEnvironmentsVariables(alongsideText,valueToBePrinted) {
* @private
*/
function selectExhortBackend(opts= {}) {

let dirName
// new ESM way in nodeJS ( since node version 22 ) to bring module directory.
let dirName = import.meta.dirname
// old ESM way in nodeJS ( before node versions 22.00 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));
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)
Expand Down

0 comments on commit a1da46e

Please sign in to comment.