From 51358582a832afcd0c540cbe4a67b26406bf81be Mon Sep 17 00:00:00 2001 From: David Sanders Date: Wed, 21 May 2025 11:12:36 -0700 Subject: [PATCH] fix: resolve symlinks when checking if script is entrypoint --- bin/lint-markdown-api-history.ts | 4 ++-- bin/lint-markdown-links.ts | 2 +- bin/lint-markdown-standard.ts | 2 +- bin/lint-markdown-ts-check.ts | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/lint-markdown-api-history.ts b/bin/lint-markdown-api-history.ts index 1a5c835..3291fd1 100644 --- a/bin/lint-markdown-api-history.ts +++ b/bin/lint-markdown-api-history.ts @@ -1,6 +1,6 @@ #!/usr/bin/env node -import { access, constants, readFile } from 'node:fs/promises'; +import { readFile, realpath } from 'node:fs/promises'; import { resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; import { parseArgs } from 'node:util'; @@ -512,7 +512,7 @@ async function init() { } } -if (process.argv[1] === fileURLToPath(import.meta.url)) { +if ((await realpath(process.argv[1])) === fileURLToPath(import.meta.url)) { init().catch((error) => { console.error(error); process.exit(1); diff --git a/bin/lint-markdown-links.ts b/bin/lint-markdown-links.ts index 4d72baf..c7a3a71 100644 --- a/bin/lint-markdown-links.ts +++ b/bin/lint-markdown-links.ts @@ -210,7 +210,7 @@ function parseCommandLine() { } } -if (process.argv[1] === fileURLToPath(import.meta.url)) { +if ((await fs.promises.realpath(process.argv[1])) === fileURLToPath(import.meta.url)) { const { values: opts, positionals } = parseCommandLine(); if (!opts.root) { diff --git a/bin/lint-markdown-standard.ts b/bin/lint-markdown-standard.ts index edfa33b..bb7c689 100644 --- a/bin/lint-markdown-standard.ts +++ b/bin/lint-markdown-standard.ts @@ -209,7 +209,7 @@ function parseCommandLine() { } } -if (process.argv[1] === fileURLToPath(import.meta.url)) { +if ((await fs.promises.realpath(process.argv[1])) === fileURLToPath(import.meta.url)) { const { values: opts, positionals } = parseCommandLine(); if (!opts.root) { diff --git a/bin/lint-markdown-ts-check.ts b/bin/lint-markdown-ts-check.ts index 26cc736..62f5af0 100644 --- a/bin/lint-markdown-ts-check.ts +++ b/bin/lint-markdown-ts-check.ts @@ -319,7 +319,7 @@ function parseCommandLine() { } } -if (process.argv[1] === fileURLToPath(import.meta.url)) { +if ((await fs.promises.realpath(process.argv[1])) === fileURLToPath(import.meta.url)) { const { values: opts, positionals } = parseCommandLine(); if (!opts.root) {