lambda-live-debugger
Version:
Debug Lambda functions locally like it is running in the cloud
26 lines (25 loc) • 768 B
JavaScript
import * as fs from 'fs';
import * as path from 'path';
import { getModuleDirname } from './getDirname.mjs';
let versionStored = undefined;
/**
* Get the version of the package
* @returns the version of the package
*/
export async function getVersion() {
if (versionStored) {
return versionStored;
}
const pachageJsonPath = path.join(getModuleDirname(), '../', 'package.json');
try {
const packageJson = await fs.promises.readFile(pachageJsonPath, 'utf-8');
const { version } = JSON.parse(packageJson);
versionStored = version;
return version;
}
catch (error) {
throw new Error(`Error reading version from ${pachageJsonPath}: ${error.message}`, {
cause: error,
});
}
}