Page MenuHomeSealhub

webhint.ts
No OneTemporary

webhint.ts

import _locreq from "locreq";
import { module_dirname } from "../utils/module_dirname.js";
const locreq = _locreq(module_dirname(import.meta.url));
import { spawn } from "child_process";
import { hasShape, is, predicates } from "@sealcode/ts-predicates";
import { promises as fs } from "fs";
export const LONG_TEST_TIMEOUT = 100 * 1000;
export const VERY_LONG_TEST_TIMEOUT = 75 * 1000;
export async function webhintURL(url: string, config = locreq.resolve(".hintrc")) {
// eslint-disable-next-line no-console
console.log("scanning with webhint....", url);
try {
const subprocess = spawn(
"node",
[locreq.resolve("webhint/node_modules/.bin/hint"), "--config", config, url],
{ cwd: locreq.resolve("webhint") } // to prevent webhint from trying to parese source code
);
subprocess.stderr.on("data", (b) => console.error(String(b)));
// eslint-disable-next-line no-console
subprocess.stdout.on("data", (b) => console.log(String(b)));
await new Promise<void>((resolve, reject) => {
subprocess.on("close", (code) =>
code === 0 ? resolve() : reject(new Error("Webhint tests failed"))
);
});
} catch (e) {
if (is(e, predicates.object) && hasShape({ stdout: predicates.string }, e)) {
throw new Error(e.stdout);
} else {
throw e;
}
}
}
export async function webhintHTML(html: string) {
await fs.writeFile("/tmp/index.html", html);
await webhintURL("/tmp/index.html", locreq.resolve(".hintrc.local.json"));
}

File Metadata

Mime Type
text/x-java
Expires
Fri, Jan 24, 15:16 (17 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
599860
Default Alt Text
webhint.ts (1 KB)

Event Timeline