@plannotator/tot 0.1.1 → 0.1.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.
package/dist/cli.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  #!/usr/bin/env node
2
2
  export declare function main(argv?: string[]): Promise<number>;
3
+ export declare function isCliEntrypoint(metaUrl: string, argv1?: string | undefined): boolean;
package/dist/cli.js CHANGED
@@ -1,4 +1,7 @@
1
1
  #!/usr/bin/env node
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { fileURLToPath } from "node:url";
2
5
  import { listCommand, loginCommand, publishCommand, removeCommand, updateCommand, } from "./commands.js";
3
6
  import { Config } from "./config.js";
4
7
  import { createHttpClient } from "./http.js";
@@ -97,8 +100,22 @@ export async function main(argv = process.argv.slice(2)) {
97
100
  await publishCommand(cmd, cfg, deps);
98
101
  return 0;
99
102
  }
103
+ function realPathForEntrypoint(value) {
104
+ const absolute = path.resolve(value);
105
+ try {
106
+ return fs.realpathSync(absolute);
107
+ }
108
+ catch {
109
+ return absolute;
110
+ }
111
+ }
112
+ export function isCliEntrypoint(metaUrl, argv1 = process.argv[1]) {
113
+ if (argv1 === undefined)
114
+ return false;
115
+ return realPathForEntrypoint(fileURLToPath(metaUrl)) === realPathForEntrypoint(argv1);
116
+ }
100
117
  // Only run when invoked as the CLI, not when imported (e.g. by tests).
101
- if (import.meta.url === `file://${process.argv[1]}`) {
118
+ if (isCliEntrypoint(import.meta.url)) {
102
119
  main().then((code) => process.exit(code), (err) => {
103
120
  const msg = err instanceof Error ? err.message : String(err);
104
121
  console.error("error:", msg);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plannotator/tot",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Git-backed publishing for Markdown and HTML: one living tot.page URL with immutable @hash snapshots.",
5
5
  "keywords": [
6
6
  "cli",