Skip to content

Commit 62b18be

Browse files
authored
fix(ci): confirm file existence in redirect checks (#1131)
1 parent 8ac693b commit 62b18be

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

docs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@
986986
},
987987
{
988988
"source": "/v3/documentation/smart-contracts/fift/overview",
989-
"destination": "/languages/fift",
989+
"destination": "/languages/fift/overview",
990990
"permanent": true
991991
},
992992
{

scripts/check-redirects.mjs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
╚─────────────────────────────────────────────────────────────────────────────*/
1515

1616
// Node.js
17-
import { existsSync, mkdtempSync, rmSync, readFileSync } from 'node:fs';
17+
import { existsSync, statSync, mkdtempSync, rmSync, readFileSync } from 'node:fs';
1818
import { join } from 'node:path';
1919
import { tmpdir } from 'node:os';
2020
import { spawnSync } from 'node:child_process';
@@ -71,7 +71,7 @@ const checkUnique = (config) => {
7171
loops,
7272
'Redirect sources in docs.json must not self-reference in destinations!',
7373
),
74-
}
74+
};
7575
}
7676
const navLinks = getNavLinksSet(config);
7777
const navOverrides = redirectSources.filter((it) => navLinks.has(fmt(it)));
@@ -83,7 +83,7 @@ const checkUnique = (config) => {
8383
navOverrides,
8484
'Redirect sources in docs.json must not replace existing paths!',
8585
),
86-
}
86+
};
8787
}
8888
// Otherwise
8989
return { ok: true };
@@ -111,7 +111,11 @@ const checkExist = (config) => {
111111
return false;
112112
}
113113
const rel = it.replace(/^\/+/, '').replace(/#.*$/, '').replace(/\?.*$/, '');
114-
return [rel === '' ? `index.mdx` : `${rel}/index.mdx`, `${rel}.mdx`, `${rel}`].some(existsSync) === false;
114+
return (
115+
[rel === '' ? `index.mdx` : `${rel}/index.mdx`, `${rel}.mdx`, `${rel}`].some(
116+
(path) => existsSync(path) && statSync(path).isFile(),
117+
) === false
118+
);
115119
});
116120
if (repoIssuesDestsExist) {
117121
console.log(composeWarning('Found GitHub issue destinations!'));
@@ -304,11 +308,11 @@ const main = async () => {
304308
console.log(res.error);
305309
} else {
306310
console.log(composeSuccess(rawSuccessMsg));
307-
};
311+
}
308312
if (shouldRunAll) {
309313
console.log(); // intentional break
310314
}
311-
}
315+
};
312316

313317
if (shouldRunAll || argUnique) {
314318
console.log('🏁 Checking the uniqueness of redirect sources in docs.json...');

0 commit comments

Comments
 (0)