Skip to content

Commit b84e8c5

Browse files
authored
Validate that GAP directories only contain allowed files (#35)
Adds a file allowlist check to `validate-structure.js` — GAP directories may now only contain `*.md` files and `metadata.yml`. Rejects unexpected files or subdirectories with a message pointing contributors to @graphql/gaps-editors. Motivation: prevent files like `.nvmrc` from being merged that could inadvertently affect developer environments.
2 parents cc6e6c2 + 10979d0 commit b84e8c5

6 files changed

Lines changed: 336 additions & 156 deletions

File tree

package-lock.json

Lines changed: 57 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@
1212
"suggest:format": "echo \"\nTo resolve this, run: $(tput bold)npm run format$(tput sgr0)\" && exit 1",
1313
"test:format": "prettier --check . || npm run suggest:format",
1414
"test:spelling": "cspell \"spec/**/*.md\" README.md LICENSE.md",
15-
"test:structure": "find ./gaps -maxdepth 1 -type d -name 'GAP-*' | xargs -I{} ./scripts/validate-structure.js {}",
16-
"sync:codeowners": "node scripts/sync-codeowners.js"
15+
"test:structure": "node scripts/validate-structure.ts",
16+
"sync:codeowners": "node scripts/sync-codeowners.ts"
1717
},
1818
"devDependencies": {
1919
"@mlarah/spec-md": "^3.1.0",
20+
"@tsconfig/node-ts": "^23.6.4",
21+
"@tsconfig/node24": "^24.0.4",
22+
"@types/node": "^24.13.2",
23+
"@types/validator": "^13.15.10",
2024
"ajv": "^8.17.1",
2125
"cspell": "5.9.1",
2226
"handlebars": "^4.7.9",
@@ -25,6 +29,7 @@
2529
"nodemon": "2.0.20",
2630
"p-limit": "^7.3.0",
2731
"prettier": "^3.8.1",
32+
"typescript": "^6.0.3",
2833
"validator": "^13.12.0",
2934
"yaml": "^2.7.0"
3035
}
Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
11
#!/usr/bin/env node
22

33
import { readdir, readFile, writeFile } from "node:fs/promises";
4-
import { join, dirname } from "node:path";
5-
import { fileURLToPath } from "node:url";
4+
import { join } from "node:path";
65
import { parse as parseYaml } from "yaml";
76

8-
const __dirname = dirname(fileURLToPath(import.meta.url));
9-
const rootDir = join(__dirname, "..");
7+
const rootDir = join(import.meta.dirname, "..");
108
const gapsDir = join(rootDir, "gaps");
119

1210
async function getGapDirs() {
1311
const entries = await readdir(gapsDir, { withFileTypes: true });
14-
return entries.filter((d) => d.isDirectory() && /^GAP-[1-9]\d*$/.test(d.name));
12+
return entries.filter(
13+
(d) => d.isDirectory() && /^GAP-[1-9]\d*$/.test(d.name),
14+
);
1515
}
1616

1717
async function main() {
1818
const dirs = await getGapDirs();
19-
dirs.sort((a, b) => parseInt(a.name.split("-")[1], 10) - parseInt(b.name.split("-")[1], 10));
19+
dirs.sort(
20+
(a, b) =>
21+
parseInt(a.name.split("-")[1], 10) - parseInt(b.name.split("-")[1], 10),
22+
);
2023

2124
const lines = await Promise.all(
2225
dirs.map(async (dir) => {
2326
const metadataPath = join(gapsDir, dir.name, "metadata.yml");
2427
const metadata = parseYaml(await readFile(metadataPath, "utf8"));
25-
const owners = metadata.authors.map((a) => a.githubUsername.replace(/^@/, ""));
28+
const owners = metadata.authors.map((a) =>
29+
a.githubUsername.replace(/^@/, ""),
30+
);
2631
const ownerList = owners.map((o) => `@${o}`).join(" ");
2732
return `/gaps/${dir.name}/ ${ownerList}`;
2833
}),

scripts/validate-structure.js

Lines changed: 0 additions & 147 deletions
This file was deleted.

0 commit comments

Comments
 (0)