deno/tests/specs/bundle/html/file-has.ts
Nathan Whitaker 4e4bbf2fcc
feat(bundle): support html entrypoint (#29856)
For instance

`deno bundle --outdir dist index.html`

It will find scripts referenced in the html, bundle them, and then
update the paths in index.html for the bundled assets.

Right now it doesn't handle other assets (from `link` elements), but it
could
2025-09-09 12:18:10 -07:00

26 lines
556 B
TypeScript

const path = Deno.args[0];
const pattern = Deno.args[1];
declare global {
interface RegExpConstructor {
escape(string: string): string;
}
}
const contents = Deno.readTextFileSync(path);
let matcher: RegExp | string = pattern;
if (pattern.startsWith("regex:")) {
matcher = pattern.slice(6);
matcher = new RegExp(matcher);
} else {
matcher = new RegExp(RegExp.escape(pattern));
}
if (matcher.test(contents)) {
console.log("true");
} else {
console.log("false");
console.log("wanted: ", matcher);
console.log("found: ", contents);
}