@jenslys/curldown 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/cli.js +23 -2
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import { createHash } from "node:crypto";
3
+ import { realpathSync } from "node:fs";
3
4
  import { Command, CommanderError } from "commander";
4
- import { pathToFileURL } from "node:url";
5
+ import { fileURLToPath, pathToFileURL } from "node:url";
5
6
  import { DEFAULT_DYNAMIC_TIMEOUT_MS, DEFAULT_STATIC_TIMEOUT_MS, VERSION } from "./constants.js";
6
7
  import { asCurldownError, ConversionError, InputError } from "./errors.js";
7
8
  import { fetchDynamicHtml } from "./fetch-dynamic.js";
@@ -275,7 +276,27 @@ export async function run(argv, deps = defaultDependencies) {
275
276
  return curldownError.exitCode;
276
277
  }
277
278
  }
278
- const isMain = process.argv[1] !== undefined && pathToFileURL(process.argv[1]).href === import.meta.url;
279
+ function resolvePathStrict(pathInput) {
280
+ return realpathSync(pathInput);
281
+ }
282
+ /**
283
+ * Determine whether this module was invoked as the CLI entrypoint.
284
+ * Resolves symlinks for both paths so global installs that expose a symlinked bin still execute.
285
+ */
286
+ export function isMainModule(argvPath = process.argv[1]) {
287
+ if (argvPath === undefined) {
288
+ return false;
289
+ }
290
+ try {
291
+ const invokedPath = resolvePathStrict(argvPath);
292
+ const modulePath = resolvePathStrict(fileURLToPath(import.meta.url));
293
+ return invokedPath === modulePath;
294
+ }
295
+ catch {
296
+ return pathToFileURL(argvPath).href === import.meta.url;
297
+ }
298
+ }
299
+ const isMain = isMainModule();
279
300
  if (isMain) {
280
301
  void run(process.argv.slice(2)).then((exitCode) => {
281
302
  process.exitCode = exitCode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jenslys/curldown",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Fetch URL content and convert it to markdown.",
5
5
  "repository": {
6
6
  "type": "git",