diff --git a/clean_monorepo.sh b/clean_monorepo.sh index b0871ee..bb00ef6 100644 --- a/clean_monorepo.sh +++ b/clean_monorepo.sh @@ -1,5 +1,5 @@ rm -rf node_modules \ - packages/nmea-parser/dist \ - packages/norsub-emru/dist \ - packages/septentrio-sbf/dist \ - packages/thelmabiotel-tblive/dist + packages/nmea-parser/dist packages/nmea-parser/node_modules packages/nmea-parser/coverage \ + packages/norsub-emru/dist packages/norsub-emru/node_modules packages/norsub-emru/coverage \ + packages/septentrio-sbf/dist packages/septentrio-sbf/node_modules packages/septentrio-sbf/coverage \ + packages/thelmabiotel-tblive/dist packages/thelmabiotel-tblive/node_modules packages/thelmabiotel-tblive/coverage diff --git a/packages/norsub-emru/package.json b/packages/norsub-emru/package.json index f621aa6..a83670b 100644 --- a/packages/norsub-emru/package.json +++ b/packages/norsub-emru/package.json @@ -1,6 +1,6 @@ { "name": "@coremarine/norsub-emru", - "version": "1.0.4", + "version": "1.0.5", "description": "Library to work with eMRU devices of NorSub company", "author": "Core Marine", "license": "MIT", @@ -51,7 +51,7 @@ "test:coverage": "vitest run --coverage" }, "dependencies": { - "@coremarine/nmea-parser": ">=1.6.11", + "@coremarine/nmea-parser": ">=1.6.13", "@schemasjs/valibot-numbers": "^1.0.8" }, "peerDependencies": { diff --git a/packages/norsub-emru/src/constants.ts b/packages/norsub-emru/src/constants.ts index 413b615..79ab729 100644 --- a/packages/norsub-emru/src/constants.ts +++ b/packages/norsub-emru/src/constants.ts @@ -1,3 +1,16 @@ +import path from 'node:path' +import { fileURLToPath } from 'node:url' +// DIR +export const DIRNAME = ((): string => { + try { + // CJS + return __dirname + } catch (error) { + // ESM + const filename = fileURLToPath(import.meta.url) + return path.dirname(filename) + } +})() // GENERATE NUMBERS export const UINT8_MAX = Uint8Array.from([0b1111_1111])[0] export const UINT16_MAX = Uint16Array.from([0b1111_1111_1111_1111])[0] diff --git a/packages/norsub-emru/src/parser.ts b/packages/norsub-emru/src/parser.ts index be2b782..aef593f 100644 --- a/packages/norsub-emru/src/parser.ts +++ b/packages/norsub-emru/src/parser.ts @@ -7,6 +7,7 @@ import { getStatus } from './status' import { NorsubSentence } from './types' import { BooleanSchema } from './schemas' import { UnsignedIntegerSchema } from '@schemasjs/valibot-numbers' +import { DIRNAME } from './constants' export class NorsubParser { // Parser @@ -20,7 +21,7 @@ export class NorsubParser { constructor (memory: boolean = true, limit: number = MAX_CHARACTERS) { this.memory = memory this.bufferLimit = limit - const NORSUB_FILE = path.join(__dirname, 'norsub.yaml') + const NORSUB_FILE = path.join(DIRNAME, 'norsub.yaml') this.addProtocols({ file: NORSUB_FILE }) }