Skip to content

Commit 9f1f463

Browse files
committed
fix: use es-main package for proper ESM main module detection
The original `fileURLToPath(import.meta.url) === process.argv[1]` check fails when the binary is run via npm symlinks (npm link, npx), causing the main function to never execute and resulting in no output. Replaced with the es-main package which properly handles symlinks and other edge cases for detecting if an ESM module is run directly.
1 parent cddb690 commit 9f1f463

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

package-lock.json

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
},
4747
"homepage": "https://github.com/limulus/tcx2webvtt#readme",
4848
"dependencies": {
49+
"es-main": "^1.3.0",
4950
"fast-xml-parser": "^5.2.3",
5051
"prettier": "^3.5.3",
5152
"tslib": "^2.8.1"

src/bin/tcx2webvtt.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env node
22

3+
import esMain from 'es-main'
34
import { existsSync } from 'node:fs'
45
import { readFile } from 'node:fs/promises'
56
import { join, dirname } from 'node:path'
@@ -41,7 +42,7 @@ Examples:
4142
tcx2webvtt --fcp project.fcpxmld --clip-offset '*,-1.0' workout.tcx
4243
tcx2webvtt --fcp project.fcpxmld --clip-offset GX010163,2.5 --clip-offset GX020163,-1.0 workout.tcx
4344
tcx2webvtt --hls ./hls-output workout.tcx
44-
`)
45+
`)
4546
}
4647

4748
export interface ProcessLike {
@@ -206,7 +207,7 @@ export async function main(proc: ProcessLike) {
206207
}
207208

208209
/* c8 ignore start */
209-
if (fileURLToPath(import.meta.url) === process.argv[1]) {
210+
if (esMain(import.meta)) {
210211
await main(process)
211212
}
212213
/* c8 ignore stop */

0 commit comments

Comments
 (0)