Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(scripts): realpath argv[1] in the remaining CLI entry guards

Yudhi Armyndharis9c558d7038e4
diff --git a/scripts/check-audit.mjs b/scripts/check-audit.mjs
index 6fbe82926..fd788732b 100644
--- a/scripts/check-audit.mjs
+++ b/scripts/check-audit.mjs
@@ -22,7 +22,7 @@
* Run locally: `npm run check:audit`.
*/
import { execFileSync } from 'node:child_process';
-import { resolve } from 'node:path';
+import { realpathSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
/**
@@ -167,13 +167,13 @@ export function evaluate(report, allowlist = ALLOWLIST) {
// Guarded so the spec can import the two functions above without running a real audit.
//
-// Compare RESOLVED PATHS, not a hand-built file URL. `import.meta.url` is percent-encoded, so any
+// Compare REAL PATHS, not a hand-built file URL. `import.meta.url` is percent-encoded, so any
// checkout path needing escaping (a space, a `#`, non-ASCII) made `file://${process.argv[1]}`
// differ and the gate exited 0 having run no audit at all. On Windows it never matched: argv[1] is
// a native path with backslashes and a drive letter. `fileURLToPath` decodes the URL to a native
-// path and `resolve` normalises argv[1], which is the comparison check-sdk-docs.mjs and
-// check-upstream-surface.mjs already use.
-if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
+// path and `realpathSync` resolves argv[1], symlinks included (Node realpaths the main module URL,
+// so an unresolved path through a symlink never matched).
+if (process.argv[1] && realpathSync(process.argv[1]) === fileURLToPath(import.meta.url)) {
const report = runAudit();
// A registry that cannot answer the audit request must not be read as a clean tree. On a merge
diff --git a/scripts/check-sdk-docs.mjs b/scripts/check-sdk-docs.mjs
index 698db357f..cd15edcb5 100644
--- a/scripts/check-sdk-docs.mjs
+++ b/scripts/check-sdk-docs.mjs
@@ -31,8 +31,8 @@
*
* Run locally: `npm run check:sdk-docs`.
*/
-import { readFileSync, readdirSync } from 'node:fs';
-import { join, resolve, dirname } from 'node:path';
+import { readFileSync, readdirSync, realpathSync } from 'node:fs';
+import { join, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
const root = join(dirname(fileURLToPath(import.meta.url)), '..');
@@ -222,6 +222,6 @@ function main() {
);
}
-if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
+if (process.argv[1] && realpathSync(process.argv[1]) === fileURLToPath(import.meta.url)) {
main();
}
diff --git a/scripts/check-upstream-surface.mjs b/scripts/check-upstream-surface.mjs
index fc2eb35b6..7c478aacc 100644
--- a/scripts/check-upstream-surface.mjs
+++ b/scripts/check-upstream-surface.mjs
@@ -19,7 +19,7 @@
* Same pattern as dockerfile-patchers.spec.js: a derived check over a surface that is otherwise
* maintained by hand and forgotten by accident.
*/
-import { readFileSync, writeFileSync, readdirSync } from 'node:fs';
+import { readFileSync, writeFileSync, readdirSync, realpathSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import path from 'node:path';
@@ -146,6 +146,6 @@ function main() {
process.exitCode = 1;
}
-if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
+if (process.argv[1] && realpathSync(process.argv[1]) === fileURLToPath(import.meta.url)) {
main();
}