import Fs from 'fs' ; import semverValid from 'semver/functions/valid' ; interface PackageJson { name : string ; version : string ; dependencies : Record < string , string > ; devDependencies : Record < string , string > ; [ key ] : unknown ; } const PKG_PATH = require . resolve ( '../../package.json' ) ; export const PKG = JSON . parse ( Fs . readFileSync ( PKG_PATH , 'utf8' ) ) ; export const PKG_VERSION = PKG . version ; export const PKG_NAME = PKG . name ; if ( ! PKG_VERSION ) { throw new Error ( 'No "version" found in package.json' ) ; } if ( ! PKG_NAME ) { throw new Error ( 'No "name" found in package.json' ) ; } if ( ! semverValid ( PKG_VERSION ) ) { throw new Error ( `Version is not valid semver: ${ PKG_VERSION }` ) ; }