Skip to content

Commit

Permalink
NORSUB-eMRU: v1.0.5
Browse files Browse the repository at this point in the history
__dirname for ESM and CJS
  • Loading branch information
crisconru authored May 16, 2024
2 parents 8f38f99 + 1b9638b commit 8d11e46
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
8 changes: 4 additions & 4 deletions clean_monorepo.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions packages/norsub-emru/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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": {
Expand Down
13 changes: 13 additions & 0 deletions packages/norsub-emru/src/constants.ts
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
3 changes: 2 additions & 1 deletion packages/norsub-emru/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 })
}

Expand Down

0 comments on commit 8d11e46

Please sign in to comment.