diff --git a/index.js b/index.js index 9f554df..96e42cb 100644 --- a/index.js +++ b/index.js @@ -1,17 +1,15 @@ // eslint-disable-next-line eslint-comments/disable-enable-pair /* eslint-disable security/detect-non-literal-fs-filename, security/detect-object-injection */ import fs from 'node:fs/promises'; -import path from 'node:path'; let codeTypes = {}; let codeTypeFieldValues = {}; -const currentFolder = path.dirname(import.meta.filename ?? '.'); /** * Returns an object of code types. * @returns {Promise>} - An object with "code type" keys and "code type description" values. */ export async function getCodeTypes() { if (Object.keys(codeTypes).length === 0) { - const codeTypesData = await fs.readFile(path.join(currentFolder, 'data', 'codeTypes.json')); + const codeTypesData = await fs.readFile(new URL('data/codeTypes.json', import.meta.url)); codeTypes = JSON.parse(codeTypesData); } return codeTypes; @@ -42,7 +40,7 @@ export async function getCodeTypeDescription(codeType) { export async function getFieldValues(codeType) { if ((await isCodeType(codeType)) && !Object.hasOwn(codeTypeFieldValues, codeType)) { - const fieldValueData = await fs.readFile(path.join(currentFolder, 'data', `${codeType}.json`)); + const fieldValueData = await fs.readFile(new URL(`data/${codeType}.json`, import.meta.url)); codeTypeFieldValues[codeType] = JSON.parse(fieldValueData); } return codeTypeFieldValues[codeType] ?? {}; diff --git a/index.ts b/index.ts index ebda0dd..f04a402 100644 --- a/index.ts +++ b/index.ts @@ -2,20 +2,19 @@ /* eslint-disable security/detect-non-literal-fs-filename, security/detect-object-injection */ import fs from 'node:fs/promises' -import path from 'node:path' let codeTypes: Record = {} let codeTypeFieldValues: Record> = {} -const currentFolder = path.dirname(import.meta.filename ?? '.') - /** * Returns an object of code types. * @returns {Promise>} - An object with "code type" keys and "code type description" values. */ export async function getCodeTypes(): Promise> { if (Object.keys(codeTypes).length === 0) { - const codeTypesData = await fs.readFile(path.join(currentFolder, 'data', 'codeTypes.json')) + const codeTypesData = await fs.readFile( + new URL('data/codeTypes.json', import.meta.url) + ) codeTypes = JSON.parse(codeTypesData as unknown as string) } @@ -56,7 +55,9 @@ export async function getFieldValues( (await isCodeType(codeType)) && !Object.hasOwn(codeTypeFieldValues, codeType) ) { - const fieldValueData = await fs.readFile(path.join(currentFolder, 'data', `${codeType}.json`)) + const fieldValueData = await fs.readFile( + new URL(`data/${codeType}.json`, import.meta.url) + ) codeTypeFieldValues[codeType] = JSON.parse( fieldValueData as unknown as string diff --git a/package-lock.json b/package-lock.json index 4f62163..1ec3609 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@cityssm/ncic-lookup", - "version": "0.1.1", + "version": "0.1.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@cityssm/ncic-lookup", - "version": "0.1.1", + "version": "0.1.2", "license": "MIT", "devDependencies": { "@types/mocha": "^10.0.6", diff --git a/package.json b/package.json index 3bf1aa1..0e56807 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@cityssm/ncic-lookup", - "version": "0.1.1", + "version": "0.1.2", "type": "module", "engines": { "node": ">=18.0.0"