doc-detective 4.37.0 → 4.37.1

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.
@@ -35,9 +35,11 @@
35
35
  */
36
36
 
37
37
  import { spawn } from 'node:child_process';
38
+ import { realpathSync } from 'node:fs';
38
39
  import { mkdir, rm, writeFile } from 'node:fs/promises';
39
40
  import path from 'node:path';
40
41
  import process from 'node:process';
42
+ import { pathToFileURL } from 'node:url';
41
43
 
42
44
  const WORKSPACE_DIR = '/workspace';
43
45
  const SPECS_SUBDIR = 'specs';
@@ -767,10 +769,29 @@ async function main() {
767
769
  }
768
770
 
769
771
  // Module-import guard so the test file can `import` from this module
770
- // without triggering main(). Node's `import.meta.url === ...` idiom
771
- // for "am I the entrypoint?" — works under both `node` and `tsx` and
772
- // doesn't require require.main.
773
- const isEntry = import.meta.url === `file://${process.argv[1]}`;
772
+ // without triggering main().
773
+ //
774
+ // Both halves of this comparison matter. npm installs `bin` entries as
775
+ // symlinks, so when the container runs `doc-detective-runner`,
776
+ // process.argv[1] is /usr/local/bin/doc-detective-runner while
777
+ // import.meta.url is the realpath under node_modules — hence realpathSync
778
+ // before comparing. And a hand-built `file://${...}` template mangles
779
+ // Windows paths and anything containing a space or `#`, so the conversion
780
+ // goes through pathToFileURL. Getting either wrong makes this silently
781
+ // false: main() never runs, nothing is logged, and the process exits 0
782
+ // looking like a clean success. See ADR 01087.
783
+ const isEntry = (() => {
784
+ const argv1 = process.argv[1];
785
+ if (!argv1) return false;
786
+ try {
787
+ return import.meta.url === pathToFileURL(realpathSync(argv1)).href;
788
+ } catch {
789
+ // argv[1] can be unresolvable (deleted file, permission error). Not
790
+ // being the entrypoint is the safe answer — worst case the process
791
+ // no-ops, exactly as it would have before.
792
+ return false;
793
+ }
794
+ })();
774
795
  if (isEntry) {
775
796
  main()
776
797
  .then((code) => process.exit(code))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doc-detective",
3
- "version": "4.37.0",
3
+ "version": "4.37.1",
4
4
  "description": "Treat doc content as testable assertions to validate doc accuracy and product UX.",
5
5
  "bin": {
6
6
  "doc-detective": "bin/doc-detective.js",