@hhkaos/webmentions-widget 0.5.2 → 0.5.3
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/bin/snapshot.js +23 -3
- package/package.json +1 -1
package/bin/snapshot.js
CHANGED
|
@@ -15,9 +15,10 @@
|
|
|
15
15
|
* WEBMENTION_IO_TOKEN, or --token. Domain queries require it.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
+
import {realpathSync} from 'node:fs';
|
|
18
19
|
import {readFile, writeFile, mkdir} from 'node:fs/promises';
|
|
19
20
|
import {dirname} from 'node:path';
|
|
20
|
-
import {
|
|
21
|
+
import {fileURLToPath} from 'node:url';
|
|
21
22
|
|
|
22
23
|
import {getSnapshotMentions, mergeSnapshot, parseWebmentionJson} from '../src/core.js';
|
|
23
24
|
|
|
@@ -182,8 +183,27 @@ async function main() {
|
|
|
182
183
|
console.log(`Snapshot updated: ${before} → ${snapshot.count} mentions (lastId ${snapshot.lastId}).`);
|
|
183
184
|
}
|
|
184
185
|
|
|
185
|
-
|
|
186
|
-
|
|
186
|
+
/**
|
|
187
|
+
* True when this file is the process entry point.
|
|
188
|
+
*
|
|
189
|
+
* Compared through realpath on both sides: npm installs a bin as a symlink in
|
|
190
|
+
* node_modules/.bin, so argv[1] is that link rather than this file, and a
|
|
191
|
+
* naive URL comparison makes the command a silent no-op.
|
|
192
|
+
*/
|
|
193
|
+
function isEntryPoint() {
|
|
194
|
+
if (!process.argv[1]) {
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
try {
|
|
199
|
+
return realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url));
|
|
200
|
+
} catch {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Guarded so the helpers above stay importable by tests.
|
|
206
|
+
if (isEntryPoint()) {
|
|
187
207
|
main().catch((error) => {
|
|
188
208
|
console.error(error);
|
|
189
209
|
process.exit(1);
|
package/package.json
CHANGED