@hhkaos/webmentions-widget 0.5.1 → 0.5.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/bin/snapshot.js +21 -6
  2. package/package.json +1 -1
package/bin/snapshot.js CHANGED
@@ -17,6 +17,7 @@
17
17
 
18
18
  import {readFile, writeFile, mkdir} from 'node:fs/promises';
19
19
  import {dirname} from 'node:path';
20
+ import {pathToFileURL} from 'node:url';
20
21
 
21
22
  import {getSnapshotMentions, mergeSnapshot, parseWebmentionJson} from '../src/core.js';
22
23
 
@@ -27,7 +28,7 @@ const RETRIES = 8;
27
28
  const RETRY_DELAY_MS = 3000;
28
29
  const MAX_RETRY_DELAY_MS = 30000;
29
30
 
30
- function parseArgs(argv) {
31
+ export function parseArgs(argv) {
31
32
  const args = {};
32
33
 
33
34
  argv.forEach((arg, index) => {
@@ -36,7 +37,18 @@ function parseArgs(argv) {
36
37
  }
37
38
 
38
39
  const [flag, inline] = arg.slice(2).split('=');
39
- args[flag] = inline ?? (argv[index + 1]?.startsWith('--') ? true : argv[index + 1]);
40
+
41
+ if (inline !== undefined) {
42
+ args[flag] = inline;
43
+ return;
44
+ }
45
+
46
+ const next = argv[index + 1];
47
+
48
+ // A flag is boolean when nothing follows it, or when what follows is
49
+ // another flag. `--full` as the last argument is the common case, and
50
+ // reading it as its (missing) value silently disabled it.
51
+ args[flag] = next === undefined || next.startsWith('--') ? true : next;
40
52
  });
41
53
 
42
54
  return args;
@@ -170,7 +182,10 @@ async function main() {
170
182
  console.log(`Snapshot updated: ${before} → ${snapshot.count} mentions (lastId ${snapshot.lastId}).`);
171
183
  }
172
184
 
173
- main().catch((error) => {
174
- console.error(error);
175
- process.exit(1);
176
- });
185
+ // Only run when invoked as a command, so the helpers above stay testable.
186
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
187
+ main().catch((error) => {
188
+ console.error(error);
189
+ process.exit(1);
190
+ });
191
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hhkaos/webmentions-widget",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "Framework-agnostic, dependency-free widget to fetch and render webmention.io mentions for the current page.",
5
5
  "type": "module",
6
6
  "license": "MIT",