diff --git a/build/tasks/format/format-dockerfile.mts b/build/tasks/format/format-dockerfile.mts index 13af0e929..0e34a0944 100644 --- a/build/tasks/format/format-dockerfile.mts +++ b/build/tasks/format/format-dockerfile.mts @@ -5,7 +5,7 @@ * @module {type ES6Module} build/tasks/format/format-dockerfile */ -import { exec, glob, quote } from '@openinf/portal/build/utils'; +import { exec, glob, matched, quote } from '@openinf/portal/build/utils'; const dockerfileFiles = await glob([ '.devcontainer/**/Dockerfile', @@ -14,7 +14,9 @@ const dockerfileFiles = await glob([ ]); let exitCode = 0; -const scripts = [`dprint fmt ${quote(dockerfileFiles)}`]; +const scripts = matched(dockerfileFiles, '.devcontainer/**/Dockerfile') + ? [`dprint fmt ${quote(dockerfileFiles)}`] + : []; for (const element of scripts) { exitCode = await exec(element); diff --git a/build/tasks/format/format-js.mts b/build/tasks/format/format-js.mts index 5a0a44886..671ca6684 100644 --- a/build/tasks/format/format-js.mts +++ b/build/tasks/format/format-js.mts @@ -5,7 +5,7 @@ * @module {type ES6Module} build/tasks/format/format-js */ -import { exec, glob, quote } from '@openinf/portal/build/utils'; +import { exec, glob, matched, quote } from '@openinf/portal/build/utils'; const jsFiles = await glob([ '**/*.js', @@ -16,7 +16,9 @@ const jsFiles = await glob([ ]); let exitCode = 0; -const scripts = [`biome check --write ${quote(jsFiles)}`]; +const scripts = matched(jsFiles, '**/*.js, **/*.mjs') + ? [`biome check --write ${quote(jsFiles)}`] + : []; for (const element of scripts) { exitCode = await exec(element); diff --git a/build/tasks/format/format-json.mts b/build/tasks/format/format-json.mts index b043d5128..c0d17632c 100644 --- a/build/tasks/format/format-json.mts +++ b/build/tasks/format/format-json.mts @@ -5,7 +5,7 @@ * @module {type ES6Module} build/tasks/format/format-json */ -import { exec, glob, quote } from '@openinf/portal/build/utils'; +import { exec, glob, matched, quote } from '@openinf/portal/build/utils'; const EXCLUDED = ['!_site/', '!node_modules/']; @@ -17,9 +17,15 @@ const jsonFiles = await glob(['**/*.json', '**/*.jsonc', ...EXCLUDED]); const json5Files = await glob(['**/*.json5', ...EXCLUDED]); let exitCode = 0; +// Two lists, two tools, and a guard each: JSON5 going unformatted because no +// plain JSON matched would be the silence this guard exists to prevent. const scripts = [ - `biome check --write ${quote(jsonFiles)}`, - ...(json5Files.length > 0 ? [`prettier --write ${quote(json5Files)}`] : []), + ...(matched(jsonFiles, '**/*.json, **/*.jsonc') + ? [`biome check --write ${quote(jsonFiles)}`] + : []), + ...(matched(json5Files, '**/*.json5') + ? [`prettier --write ${quote(json5Files)}`] + : []), ]; for (const element of scripts) { diff --git a/build/tasks/format/format-liquid.mts b/build/tasks/format/format-liquid.mts index 6a405b647..e6a971f62 100644 --- a/build/tasks/format/format-liquid.mts +++ b/build/tasks/format/format-liquid.mts @@ -5,7 +5,7 @@ * @module {type ES6Module} build/tasks/format/format-liquid */ -import { exec, glob, quote } from '@openinf/portal/build/utils'; +import { exec, glob, matched, quote } from '@openinf/portal/build/utils'; const LiquidFiles = await glob([ '**/*.html', @@ -15,7 +15,9 @@ const LiquidFiles = await glob([ ]); let exitCode = 0; -const scripts = [`prettier --write ${quote(LiquidFiles)}`]; +const scripts = matched(LiquidFiles, '**/*.html, **/*.liquid') + ? [`prettier --write ${quote(LiquidFiles)}`] + : []; for (const element of scripts) { exitCode = await exec(element); diff --git a/build/tasks/format/format-md.mts b/build/tasks/format/format-md.mts index bc5bb21fb..80f0951d2 100644 --- a/build/tasks/format/format-md.mts +++ b/build/tasks/format/format-md.mts @@ -5,7 +5,7 @@ * @module {type ES6Module} build/tasks/format/format-md */ -import { exec, glob, quote } from '@openinf/portal/build/utils'; +import { exec, glob, matched, quote } from '@openinf/portal/build/utils'; const markdownFiles = await glob([ '**/*.md', @@ -23,10 +23,12 @@ const markdownFiles = await glob([ ]); let exitCode = 0; -const scripts = [ - `prettier --write ${quote(markdownFiles)}`, - `markdownlint-cli2 --fix ${quote(markdownFiles)}`, -]; +const scripts = matched(markdownFiles, '**/*.md') + ? [ + `prettier --write ${quote(markdownFiles)}`, + `markdownlint-cli2 --fix ${quote(markdownFiles)}`, + ] + : []; for (const element of scripts) { exitCode = await exec(element); diff --git a/build/tasks/format/format-scss.mts b/build/tasks/format/format-scss.mts index d2e1ef011..06de357db 100644 --- a/build/tasks/format/format-scss.mts +++ b/build/tasks/format/format-scss.mts @@ -5,15 +5,17 @@ * @module {type ES6Module} build/tasks/format/format-scss */ -import { exec, glob, quote } from '@openinf/portal/build/utils'; +import { exec, glob, matched, quote } from '@openinf/portal/build/utils'; const scssFiles = await glob(['**/*.scss', '!_site/', '!node_modules/']); let exitCode = 0; -const scripts = [ - `prettier --write ${quote(scssFiles)}`, - `stylelint --fix ${quote(scssFiles)}`, -]; +const scripts = matched(scssFiles, '**/*.scss') + ? [ + `prettier --write ${quote(scssFiles)}`, + `stylelint --fix ${quote(scssFiles)}`, + ] + : []; for (const element of scripts) { exitCode = await exec(element); diff --git a/build/tasks/format/format-svg.mts b/build/tasks/format/format-svg.mts index bde614b6d..a52cfecee 100644 --- a/build/tasks/format/format-svg.mts +++ b/build/tasks/format/format-svg.mts @@ -5,12 +5,14 @@ * @module {type ES6Module} build/tasks/format/format-svg */ -import { exec, glob, quote } from '@openinf/portal/build/utils'; +import { exec, glob, matched, quote } from '@openinf/portal/build/utils'; const svgFiles = await glob(['**/*.svg', '!_site/', '!node_modules/']); let exitCode = 0; -const scripts = [`prettier --write ${quote(svgFiles)}`]; +const scripts = matched(svgFiles, '**/*.svg') + ? [`prettier --write ${quote(svgFiles)}`] + : []; for (const element of scripts) { exitCode = await exec(element); diff --git a/build/tasks/format/format-toml.mts b/build/tasks/format/format-toml.mts index 90bbba11b..8f8f5dfaa 100644 --- a/build/tasks/format/format-toml.mts +++ b/build/tasks/format/format-toml.mts @@ -5,12 +5,14 @@ * @module {type ES6Module} build/tasks/format/format-toml */ -import { exec, glob, quote } from '@openinf/portal/build/utils'; +import { exec, glob, matched, quote } from '@openinf/portal/build/utils'; const tomlFiles = await glob(['**/*.toml', '!_site/', '!node_modules/']); let exitCode = 0; -const scripts = [`dprint fmt ${quote(tomlFiles)}`]; +const scripts = matched(tomlFiles, '**/*.toml') + ? [`dprint fmt ${quote(tomlFiles)}`] + : []; for (const element of scripts) { exitCode = await exec(element); diff --git a/build/tasks/format/format-ts.mts b/build/tasks/format/format-ts.mts index 4acd1f74b..fa75fadb7 100644 --- a/build/tasks/format/format-ts.mts +++ b/build/tasks/format/format-ts.mts @@ -5,7 +5,7 @@ * @module {type ES6Module} build/tasks/format/format-ts */ -import { exec, glob, quote } from '@openinf/portal/build/utils'; +import { exec, glob, matched, quote } from '@openinf/portal/build/utils'; const tsFiles = await glob([ '**/*.ts', @@ -15,7 +15,9 @@ const tsFiles = await glob([ ]); let exitCode = 0; -const scripts = [`biome check --write ${quote(tsFiles)}`]; +const scripts = matched(tsFiles, '**/*.ts, **/*.mts') + ? [`biome check --write ${quote(tsFiles)}`] + : []; for (const element of scripts) { exitCode = await exec(element); diff --git a/build/tasks/format/format-yaml.mts b/build/tasks/format/format-yaml.mts index 088e8b301..ca20dee19 100644 --- a/build/tasks/format/format-yaml.mts +++ b/build/tasks/format/format-yaml.mts @@ -5,7 +5,7 @@ * @module {type ES6Module} build/tasks/format/format-yaml */ -import { exec, glob, quote } from '@openinf/portal/build/utils'; +import { exec, glob, matched, quote } from '@openinf/portal/build/utils'; const yamlFiles = await glob([ '**/*.yml', @@ -15,7 +15,9 @@ const yamlFiles = await glob([ ]); let exitCode = 0; -const scripts = [`prettier --write ${quote(yamlFiles)}`]; +const scripts = matched(yamlFiles, '**/*.yml, **/*.yaml') + ? [`prettier --write ${quote(yamlFiles)}`] + : []; for (const element of scripts) { exitCode = await exec(element); diff --git a/build/tasks/verify/verify-dockerfile.mts b/build/tasks/verify/verify-dockerfile.mts index d5e689b36..0f3baf160 100644 --- a/build/tasks/verify/verify-dockerfile.mts +++ b/build/tasks/verify/verify-dockerfile.mts @@ -5,7 +5,7 @@ * @module {type ES6Module} build/tasks/verify/verify-dockerfile */ -import { exec, glob, quote } from '@openinf/portal/build/utils'; +import { exec, glob, matched, quote } from '@openinf/portal/build/utils'; const dockerfileFiles = await glob([ '.devcontainer/**/Dockerfile', @@ -14,7 +14,9 @@ const dockerfileFiles = await glob([ ]); let exitCode = 0; -const scripts = [`dprint check ${quote(dockerfileFiles)}`]; +const scripts = matched(dockerfileFiles, '.devcontainer/**/Dockerfile') + ? [`dprint check ${quote(dockerfileFiles)}`] + : []; for (const element of scripts) { exitCode = await exec(element); diff --git a/build/tasks/verify/verify-filenames.mts b/build/tasks/verify/verify-filenames.mts index 8630e35e7..b69dc0211 100644 --- a/build/tasks/verify/verify-filenames.mts +++ b/build/tasks/verify/verify-filenames.mts @@ -5,7 +5,7 @@ * @module {type ES6Module} build/tasks/verify/verify-filenames */ -import { glob } from '@openinf/portal/build/utils'; +import { glob, matched } from '@openinf/portal/build/utils'; /** * Lowercase words joined by hyphens. A leading underscore is Eleventy's and @@ -33,6 +33,10 @@ const EXEMPT = new Set([ const files = await glob(['**/*', '!_site/', '!node_modules/']); +// This one hands nothing to a tool, but `glob` finding nothing would still +// leave it looping zero times and reporting success. +if (!matched(files, '**/*')) process.exit(1); + // A directory is only ever seen here as part of some file's path, and the // same directory is part of many, so each is judged once. const checked = new Set(); diff --git a/build/tasks/verify/verify-js.mts b/build/tasks/verify/verify-js.mts index 3ec594207..ae05ce59e 100644 --- a/build/tasks/verify/verify-js.mts +++ b/build/tasks/verify/verify-js.mts @@ -5,7 +5,7 @@ * @module {type ES6Module} build/tasks/verify/verify-js */ -import { exec, glob, quote } from '@openinf/portal/build/utils'; +import { exec, glob, matched, quote } from '@openinf/portal/build/utils'; const jsFiles = await glob([ '**/*.js', @@ -16,7 +16,9 @@ const jsFiles = await glob([ ]); let exitCode = 0; -const scripts = [`biome check ${quote(jsFiles)}`]; +const scripts = matched(jsFiles, '**/*.js, **/*.mjs') + ? [`biome check ${quote(jsFiles)}`] + : []; for (const element of scripts) { exitCode = await exec(element); diff --git a/build/tasks/verify/verify-json.mts b/build/tasks/verify/verify-json.mts index dffb0f415..1c679c215 100644 --- a/build/tasks/verify/verify-json.mts +++ b/build/tasks/verify/verify-json.mts @@ -5,7 +5,7 @@ * @module {type ES6Module} build/tasks/verify/verify-json */ -import { exec, glob, quote } from '@openinf/portal/build/utils'; +import { exec, glob, matched, quote } from '@openinf/portal/build/utils'; const EXCLUDED = ['!_site/', '!node_modules/']; @@ -17,9 +17,15 @@ const jsonFiles = await glob(['**/*.json', '**/*.jsonc', ...EXCLUDED]); const json5Files = await glob(['**/*.json5', ...EXCLUDED]); let exitCode = 0; +// Two lists, two tools, and a guard each: JSON5 going unchecked because no +// plain JSON matched would be the silence this guard exists to prevent. const scripts = [ - `biome check ${quote(jsonFiles)}`, - ...(json5Files.length > 0 ? [`prettier --check ${quote(json5Files)}`] : []), + ...(matched(jsonFiles, '**/*.json, **/*.jsonc') + ? [`biome check ${quote(jsonFiles)}`] + : []), + ...(matched(json5Files, '**/*.json5') + ? [`prettier --check ${quote(json5Files)}`] + : []), ]; for (const element of scripts) { diff --git a/build/tasks/verify/verify-liquid.mts b/build/tasks/verify/verify-liquid.mts index cc67eeb23..3f79a2523 100644 --- a/build/tasks/verify/verify-liquid.mts +++ b/build/tasks/verify/verify-liquid.mts @@ -5,7 +5,7 @@ * @module {type ES6Module} build/tasks/verify/verify-liquid */ -import { exec, glob, quote } from '@openinf/portal/build/utils'; +import { exec, glob, matched, quote } from '@openinf/portal/build/utils'; const liquidFiles = await glob([ '**/*.html', @@ -15,7 +15,9 @@ const liquidFiles = await glob([ ]); let exitCode = 0; -const scripts = [`prettier --check ${quote(liquidFiles)}`]; +const scripts = matched(liquidFiles, '**/*.html, **/*.liquid') + ? [`prettier --check ${quote(liquidFiles)}`] + : []; for (const element of scripts) { exitCode = await exec(element); diff --git a/build/tasks/verify/verify-md.mts b/build/tasks/verify/verify-md.mts index 5dd673a15..362e3ac72 100644 --- a/build/tasks/verify/verify-md.mts +++ b/build/tasks/verify/verify-md.mts @@ -5,7 +5,7 @@ * @module {type ES6Module} build/tasks/verify/verify-md */ -import { exec, glob, quote } from '@openinf/portal/build/utils'; +import { exec, glob, matched, quote } from '@openinf/portal/build/utils'; const markdownFiles = await glob([ '**/*.md', @@ -23,11 +23,13 @@ const markdownFiles = await glob([ ]); let exitCode = 0; -const scripts = [ - `prettier --check ${quote(markdownFiles)}`, - `markdownlint-cli2 ${quote(markdownFiles)}`, - `remark -f --silently-ignore ${quote(markdownFiles)}`, -]; +const scripts = matched(markdownFiles, '**/*.md') + ? [ + `prettier --check ${quote(markdownFiles)}`, + `markdownlint-cli2 ${quote(markdownFiles)}`, + `remark -f --silently-ignore ${quote(markdownFiles)}`, + ] + : []; for (const element of scripts) { exitCode = await exec(element); diff --git a/build/tasks/verify/verify-scss.mts b/build/tasks/verify/verify-scss.mts index afabbf023..ce3a36e16 100644 --- a/build/tasks/verify/verify-scss.mts +++ b/build/tasks/verify/verify-scss.mts @@ -5,15 +5,14 @@ * @module {type ES6Module} build/tasks/verify/verify-scss */ -import { exec, glob, quote } from '@openinf/portal/build/utils'; +import { exec, glob, matched, quote } from '@openinf/portal/build/utils'; const scssFiles = await glob(['**/*.scss', '!_site/', '!node_modules/']); let exitCode = 0; -const scripts = [ - `prettier --check ${quote(scssFiles)}`, - `stylelint ${quote(scssFiles)}`, -]; +const scripts = matched(scssFiles, '**/*.scss') + ? [`prettier --check ${quote(scssFiles)}`, `stylelint ${quote(scssFiles)}`] + : []; for (const element of scripts) { exitCode = await exec(element); diff --git a/build/tasks/verify/verify-spelling.mts b/build/tasks/verify/verify-spelling.mts index 7ef3ddbd9..1d510d0ef 100644 --- a/build/tasks/verify/verify-spelling.mts +++ b/build/tasks/verify/verify-spelling.mts @@ -5,7 +5,7 @@ * @module {type ES6Module} build/tasks/verify/verify-spelling */ -import { exec, glob, quote } from '@openinf/portal/build/utils'; +import { exec, glob, matched, quote } from '@openinf/portal/build/utils'; // Comments and template prose are read as often as the documentation is, and // cspell's `en` dictionary is the American one, so this is also what holds the @@ -30,4 +30,9 @@ const files = await glob([ '!collections/_pages/vision.md', ]); -process.exitCode = await exec(`cspell lint ${quote(files)}`); +process.exitCode = matched( + files, + '**/*.{md,html,liquid,scss,mts,mjs,json,yml,yaml,sh}' +) + ? await exec(`cspell lint ${quote(files)}`) + : 1; diff --git a/build/tasks/verify/verify-svg.mts b/build/tasks/verify/verify-svg.mts index e89c31763..cf66c690b 100644 --- a/build/tasks/verify/verify-svg.mts +++ b/build/tasks/verify/verify-svg.mts @@ -5,16 +5,18 @@ * @module {type ES6Module} build/tasks/verify/verify-svg */ -import { exec, glob, quote } from '@openinf/portal/build/utils'; +import { exec, glob, matched, quote } from '@openinf/portal/build/utils'; import vnu from 'vnu-jar'; const svgFiles = await glob(['**/*.svg', '!_site/', '!node_modules/']); let exitCode = 0; -const scripts = [ - `prettier --check ${quote(svgFiles)}`, - `java -jar ${quote(vnu)} --svg ${quote(svgFiles)}`, -]; +const scripts = matched(svgFiles, '**/*.svg') + ? [ + `prettier --check ${quote(svgFiles)}`, + `java -jar ${quote(vnu)} --svg ${quote(svgFiles)}`, + ] + : []; for (const element of scripts) { exitCode = await exec(element); diff --git a/build/tasks/verify/verify-toml.mts b/build/tasks/verify/verify-toml.mts index 051625019..c8db8d471 100644 --- a/build/tasks/verify/verify-toml.mts +++ b/build/tasks/verify/verify-toml.mts @@ -5,12 +5,14 @@ * @module {type ES6Module} build/tasks/verify/verify-toml */ -import { exec, glob, quote } from '@openinf/portal/build/utils'; +import { exec, glob, matched, quote } from '@openinf/portal/build/utils'; const tomlFiles = await glob(['**/*.toml', '!_site/', '!node_modules/']); let exitCode = 0; -const scripts = [`dprint check ${quote(tomlFiles)}`]; +const scripts = matched(tomlFiles, '**/*.toml') + ? [`dprint check ${quote(tomlFiles)}`] + : []; for (const element of scripts) { exitCode = await exec(element); diff --git a/build/tasks/verify/verify-ts.mts b/build/tasks/verify/verify-ts.mts index 81d83e6b7..5102410fc 100644 --- a/build/tasks/verify/verify-ts.mts +++ b/build/tasks/verify/verify-ts.mts @@ -5,7 +5,7 @@ * @module {type ES6Module} build/tasks/verify/verify-ts */ -import { exec, glob, quote } from '@openinf/portal/build/utils'; +import { exec, glob, matched, quote } from '@openinf/portal/build/utils'; const tsFiles = await glob([ '**/*.ts', @@ -18,7 +18,15 @@ let exitCode = 0; // tsc reads its file list from tsconfig.json rather than taking one, and // `erasableSyntaxOnly` there is what stops syntax node refuses to strip from // reaching a task script. -const scripts = [`biome check ${quote(tsFiles)}`, 'tsc --noEmit']; +// Only Biome is handed the list. tsc reads its own from tsconfig.json, whose +// input set is wider than this glob, so gating it on this list would let a +// checkout of nothing this glob names go unchecked. +const scripts = [ + ...(matched(tsFiles, '**/*.ts, **/*.mts') + ? [`biome check ${quote(tsFiles)}`] + : []), + 'tsc --noEmit', +]; for (const element of scripts) { exitCode = await exec(element); diff --git a/build/tasks/verify/verify-yaml.mts b/build/tasks/verify/verify-yaml.mts index 83662e5ce..2f766fa57 100644 --- a/build/tasks/verify/verify-yaml.mts +++ b/build/tasks/verify/verify-yaml.mts @@ -5,7 +5,7 @@ * @module {type ES6Module} build/tasks/verify/verify-yaml */ -import { exec, glob, quote } from '@openinf/portal/build/utils'; +import { exec, glob, matched, quote } from '@openinf/portal/build/utils'; const yamlFiles = await glob([ '**/*.yml', @@ -15,7 +15,9 @@ const yamlFiles = await glob([ ]); let exitCode = 0; -const scripts = [`prettier --check ${quote(yamlFiles)}`]; +const scripts = matched(yamlFiles, '**/*.yml, **/*.yaml') + ? [`prettier --check ${quote(yamlFiles)}`] + : []; for (const element of scripts) { exitCode = await exec(element); diff --git a/build/utils.mts b/build/utils.mts index c8eb16233..043b89421 100644 --- a/build/utils.mts +++ b/build/utils.mts @@ -51,6 +51,37 @@ export const quote = (paths: string | string[]) => }) .join(' '); +/** + * Says whether a task has anything to work on, and objects when it has not. + * + * A tool handed no files does not fail. `prettier --check` with an empty + * argument list prints `No parser and no file path given` and exits 0; + * `node --test` given a pattern matching nothing exits 0 having run no tests. + * Either way the task reports success over nothing, which is the one answer a + * check must never give -- a glob that stopped matching, because a directory + * was renamed or an extension changed, would go green for ever. + * + * `verify.unit` has guarded itself this way from the start. This is the same + * guard, said once. + * + * A project that genuinely has none of a kind should delete the task rather + * than leave it matching nothing. Deleting it is how a repository says so out + * loud, and this is what makes staying quiet impossible. + * @param {string[]} files What the glob found. + * @param {string} what The patterns it looked for, named in the complaint. + * @returns {boolean} Whether there is anything to check. + */ +export function matched(files: string[], what: string) { + if (files.length > 0) return true; + + console.error( + `Nothing matched ${what}. A check that read no files has not passed; if this project has none, delete the task rather than let it report success over an empty list.` + ); + process.exitCode = 1; + + return false; +} + /** * Expands a trailing-slash directory pattern (e.g. `_site/`) to cover * everything beneath it. On its own, a trailing slash matches just the one