diff --git a/src/helpers/conformance/conformance.ts b/src/helpers/conformance/conformance.ts index a80566a..e178fa3 100644 --- a/src/helpers/conformance/conformance.ts +++ b/src/helpers/conformance/conformance.ts @@ -1,12 +1,14 @@ -/** - * © Copyright Outburn Ltd. 2022-2024 All Rights Reserved - * Project name: FUME-COMMUNITY - */ +/** + * © Copyright Outburn Ltd. 2022-2024 All Rights Reserved + * Project name: FUME-COMMUNITY + */ -import config from '../../config'; -import { getFhirClient } from '../fhirServer'; -import expressions from '../jsonataExpression'; -import { getLogger } from '../logger'; +import fs from 'fs-extra'; + +import config from '../../config'; +import { getFhirClient } from '../fhirServer'; +import expressions from '../jsonataExpression'; +import { getLogger } from '../logger'; import { getFhirPackageIndex } from './loadFhirPackageIndex'; export const getStructureDefinition = async (definitionId: string): Promise => { @@ -26,8 +28,7 @@ export const getStructureDefinition = async (definitionId: string): Promise throw (error); } else { const path: string = indexed; - // eslint-disable-next-line @typescript-eslint/no-var-requires - const fullDef = require(path); // load file + const fullDef = JSON.parse(fs.readFileSync(path).toString()); // load file return fullDef; }; }; diff --git a/src/helpers/conformance/loadFhirPackageIndex.ts b/src/helpers/conformance/loadFhirPackageIndex.ts index 02b6075..d5340a1 100644 --- a/src/helpers/conformance/loadFhirPackageIndex.ts +++ b/src/helpers/conformance/loadFhirPackageIndex.ts @@ -20,8 +20,7 @@ const createPackageIndexFile = (packagePath: string) => { const fileList = fs.readdirSync(path.join(packagePath, 'package')); const files = fileList.flatMap((file: string) => { if (file.endsWith('.json') && file !== 'package.json') { - // eslint-disable-next-line @typescript-eslint/no-var-requires - const content = require(path.join(packagePath, 'package', file)); + const content = JSON.parse(fs.readFileSync(path.join(packagePath, 'package', file)).toString()); const indexEntry = { filename: file, resourceType: content.resourceType, @@ -58,8 +57,8 @@ const buildFhirCacheIndex = async () => { return { package: pack, path: path.join(cachePath, pack, 'package'), - packageManifest: require(path.join(cachePath, pack, 'package', 'package.json')), - packageIndex: require(path.join(cachePath, pack, 'package', '.index.json')) + packageManifest: JSON.parse(fs.readFileSync(path.join(cachePath, pack, 'package', 'package.json')).toString()), + packageIndex: JSON.parse(fs.readFileSync(path.join(cachePath, pack, 'package', '.index.json')).toString()) }; } else { getLogger().warn(`Folder '${pack}' found in the local FHIR cache does not seem to be a FHIR package (no package.json file found). Skipping it...`); @@ -72,8 +71,7 @@ const buildFhirCacheIndex = async () => { pathJoin: path.join, require: (filePath: string) => { try { - // eslint-disable-next-line @typescript-eslint/no-var-requires - const payload = require(filePath); + const payload = JSON.parse(fs.readFileSync(filePath).toString()); return payload; } catch (e) { getLogger().error(e); @@ -93,13 +91,12 @@ const parseFhirPackageIndex = async (): Promise => { if (fs.existsSync(fumeIndexPath)) { getLogger().info(`Found global package index file at ${fumeIndexPath}`); const dirList: string[] = getCachedPackageDirs(); - // eslint-disable-next-line @typescript-eslint/no-var-requires - const currentIndex = require(fumeIndexPath); + const currentIndex = JSON.parse(fs.readFileSync(fumeIndexPath).toString()); const currentPackages = await expressions.extractCurrentPackagesFromIndex.evaluate(currentIndex); const diff: string[] = await expressions.checkPackagesMissingFromIndex.evaluate({ dirList, packages: currentPackages }); if (diff.length === 0) { getLogger().info('Global package index file is up-to-date'); - return require(fumeIndexPath); + return JSON.parse(fs.readFileSync(fumeIndexPath).toString()); } else { getLogger().info('Global package index file is outdated'); }; diff --git a/src/helpers/jsonataFunctions/getStructureDefinition.ts b/src/helpers/jsonataFunctions/getStructureDefinition.ts index c44269e..a6769f1 100644 --- a/src/helpers/jsonataFunctions/getStructureDefinition.ts +++ b/src/helpers/jsonataFunctions/getStructureDefinition.ts @@ -2,6 +2,8 @@ * © Copyright Outburn Ltd. 2022-2024 All Rights Reserved * Project name: FUME-COMMUNITY */ +import fs from 'fs-extra'; + import config from '../../config'; import { getFhirPackageIndex } from '../conformance'; import fhirFuncs from '../fhirFunctions'; @@ -34,9 +36,7 @@ export const getStructureDefinition = (definitionId: string): any => { try { const path: string = getStructureDefinitionPath(definitionId); - // eslint-disable-next-line @typescript-eslint/no-var-requires - const fullDef = require(path); // load file - // getLogger().info(`Definition loaded: ${path}`); + const fullDef = JSON.parse(fs.readFileSync(path).toString()); // load file return fullDef; } catch (e) { return thrower.throwParseError(`A Problem occured while getting the structure definition of '${definitionId}'. The error is: ${e}`);