fix(lint): compositions in .hyperframesignore no longer count as the project's (#7239)

* fix(lint): compositions in .hyperframesignore no longer count as the project's

* fix(lint): keep the ignore helper under the package's comment share
This commit is contained in:
Miguel Ángel
2026-11-05 13:18:42 +00:00
committed by GitHub
parent f55990ebca
commit 80e02e74a0
8 changed files with 44 additions and 19 deletions
+1
View File
@@ -234,6 +234,7 @@
"acorn": "^8.17.0",
"acorn-walk": "^8.3.5",
"htmlparser2": "^10.1.0",
"ignore": "^5.3.2",
"linkedom": "^0.18.12",
"postcss": "^8.5.8",
"postcss-selector-parser": "^7.1.4",
+2 -1
View File
@@ -2545,7 +2545,8 @@ video to disk.
The zip excludes root `renders` and `snapshots`, `.git`, `node_modules`, `dist`,
`.next`, `coverage`, dotfiles, and anything your `.hyperframesignore` rules
match. Those rules use gitignore syntax and apply to `hyperframes publish` too.
match. Those rules use gitignore syntax and apply to `hyperframes publish` too, and
the project lint behind `lint`, `check`, `snapshot` and `render` does not read compositions they match.
Keep them narrow — a dynamically selected asset may have no static reference to
protect it.
+4 -18
View File
@@ -12,7 +12,8 @@ import {
} from "node:fs";
import { parseHTML } from "linkedom";
import AdmZip from "adm-zip";
import ignore, { type Ignore } from "ignore";
import type { Ignore } from "ignore";
import { projectIgnore } from "@hyperframes/lint";
import { CSS_URL_RE, isNonRelativeUrl, isPathInside, rewriteSrcsetUrls } from "@hyperframes/core";
import { decodeUrlPathVariants, encodeUrlPath } from "@hyperframes/parsers";
import { buildAuthHeaders } from "../auth/client.js";
@@ -24,12 +25,6 @@ import { writeProjectLink } from "./projectLink.js";
const IGNORED_DIRS = new Set([".git", "node_modules", "dist", ".next", "coverage"]);
const IGNORED_FILES = new Set([".DS_Store", "Thumbs.db"]);
const HYPERFRAMES_IGNORE_FILE = ".hyperframesignore";
// Unanchored (no leading/mid slash) so it matches a dot-prefixed name at any
// depth, same as the segments it replaces below — but as a matcher pattern
// instead of a hard skip, a project's own `.hyperframesignore` negation can
// still override it.
const DEFAULT_PROJECT_IGNORE = ["/renders/", "/snapshots/", ".*"];
const PUBLISH_CONTENT_TYPE = "application/zip";
const PUBLISH_METADATA_TIMEOUT_MS = 30_000;
const PUBLISH_UPLOAD_MIN_TIMEOUT_MS = 120_000;
@@ -301,21 +296,12 @@ export function uploadTimeoutMs(byteLength: number): number {
// Absolute, non-negotiable exclusions only — anything a `.hyperframesignore`
// negation rule should be able to override (including dot-prefixed paths;
// see DEFAULT_PROJECT_IGNORE) must go through the ignore matcher instead of
// see projectIgnore) must go through the ignore matcher instead of
// short-circuiting here.
function shouldIgnoreSegment(segment: string): boolean {
return IGNORED_DIRS.has(segment) || IGNORED_FILES.has(segment);
}
function createProjectIgnore(rootDir: string): Ignore {
const matcher = ignore().add(DEFAULT_PROJECT_IGNORE);
const ignorePath = join(rootDir, HYPERFRAMES_IGNORE_FILE);
if (existsSync(ignorePath)) {
matcher.add(readFileSync(ignorePath, "utf-8"));
}
return matcher;
}
function collectProjectFiles(
rootDir: string,
currentDir: string,
@@ -636,7 +622,7 @@ export function stagePublishFiles(
): Map<string, StagedFile> {
const absProjectDir = resolve(projectDir);
const filePaths: string[] = [];
collectProjectFiles(absProjectDir, absProjectDir, filePaths, createProjectIgnore(absProjectDir));
collectProjectFiles(absProjectDir, absProjectDir, filePaths, projectIgnore(absProjectDir));
if (!filePaths.includes("index.html")) {
throw new Error(
"Project archive must include index.html at the root. Check that .hyperframesignore does not exclude it.",
+1
View File
@@ -57,6 +57,7 @@
"acorn": "^8.17.0",
"acorn-walk": "^8.3.5",
"htmlparser2": "^10.1.0",
"ignore": "^5.3.2",
"linkedom": "^0.18.12",
"postcss": "^8.5.8",
"postcss-selector-parser": "^7.1.4"
+1
View File
@@ -13,4 +13,5 @@ export {
} from "./hyperframeLinter.js";
export { collectExternalStyles, lintProject, shouldBlockRender } from "./project.js";
export type { ProjectLintResult } from "./project.js";
export { projectIgnore } from "./projectIgnore.js";
export { audioAttributeShapeError, type AudioAttribute } from "./rules/audioAttributes.js";
+19
View File
@@ -34,6 +34,7 @@ function makeProject(indexHtml: string, subComps?: Record<string, string>): stri
const compsDir = join(dir, "compositions");
mkdirSync(compsDir, { recursive: true });
for (const [name, html] of Object.entries(subComps)) {
mkdirSync(dirname(join(compsDir, name)), { recursive: true });
writeFileSync(join(compsDir, name), html);
}
}
@@ -114,6 +115,24 @@ describe("blank_root_with_standalone_composition", () => {
expect(finding?.suggestedComposition).toBe("compositions/index.html");
});
it("does not count a composition in a folder the project's .hyperframesignore leaves out", async () => {
const project = makeProject(validHtml(), {
"archive/index.html": `<!doctype html><html><body>
<div data-composition-id="old-cut" data-width="1920" data-height="1080" data-start="0" data-duration="5">
<div class="clip" data-start="0" data-duration="5">Old cut</div>
</div>
</body></html>`,
});
writeFileSync(join(project, ".hyperframesignore"), "compositions/archive/\n");
const { results } = await lintProject(project);
expect(results.map((entry) => entry.file)).toEqual(["index.html"]);
expect(
results.flatMap((entry) => entry.result.findings).map((finding) => finding.code),
).not.toContain("blank_root_with_standalone_composition");
});
it("treats non-rendering script, style, link, meta, and template children as blank", async () => {
const shellOnlyRoot = validHtml().replace(
"</div>",
+3
View File
@@ -1,6 +1,7 @@
export { shouldBlockRender } from "./shouldBlockRender.js";
import { createHash } from "node:crypto";
import { existsSync, readdirSync } from "node:fs";
import { projectIgnore } from "./projectIgnore.js";
import { dirname, extname, join, relative, resolve } from "node:path";
import { rewriteAssetPath } from "@hyperframes/parsers/asset-paths";
import { spansOverlap } from "@hyperframes/parsers/time-spans";
@@ -315,10 +316,12 @@ export async function lintProject(
const allHtmlSources: HtmlSource[] = [{ html: rootHtml, compSrcPath: rootCompSrcPath }];
const compositionsDir = resolve(projectDir, "compositions");
if (!entryFile && existsSync(compositionsDir)) {
const ignored = projectIgnore(projectDir);
const collectHtmlFiles = (dir: string, rel: string): string[] => {
const out: string[] = [];
for (const entry of readdirSync(dir, { withFileTypes: true })) {
const relPath = rel ? `${rel}/${entry.name}` : entry.name;
if (ignored.ignores(`compositions/${relPath}${entry.isDirectory() ? "/" : ""}`)) continue;
if (entry.isDirectory()) {
// Registry components are source snippets, not independently mounted
// sub-compositions. Linting every installed template here makes an
+13
View File
@@ -0,0 +1,13 @@
import { existsSync, readFileSync } from "node:fs";
import { join } from "node:path";
import ignore, { type Ignore } from "ignore";
const DEFAULT_PROJECT_IGNORE = ["/renders/", "/snapshots/", ".*"];
/** What the project leaves out; ask with a relative `/` path, a folder with a trailing `/`. */
export function projectIgnore(projectDir: string): Ignore {
const matcher = ignore().add(DEFAULT_PROJECT_IGNORE);
const ignorePath = join(projectDir, ".hyperframesignore");
if (existsSync(ignorePath)) matcher.add(readFileSync(ignorePath, "utf-8"));
return matcher;
}