Skip to content

Commit 80e02e7

Browse files
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
1 parent f55990e commit 80e02e7

8 files changed

Lines changed: 44 additions & 19 deletions

File tree

‎bun.lock‎

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

‎docs/packages/cli.mdx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2545,7 +2545,8 @@ video to disk.
25452545

25462546
The zip excludes root `renders` and `snapshots`, `.git`, `node_modules`, `dist`,
25472547
`.next`, `coverage`, dotfiles, and anything your `.hyperframesignore` rules
2548-
match. Those rules use gitignore syntax and apply to `hyperframes publish` too.
2548+
match. Those rules use gitignore syntax and apply to `hyperframes publish` too, and
2549+
the project lint behind `lint`, `check`, `snapshot` and `render` does not read compositions they match.
25492550
Keep them narrow — a dynamically selected asset may have no static reference to
25502551
protect it.
25512552

‎packages/cli/src/utils/publishProject.ts‎

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import {
1212
} from "node:fs";
1313
import { parseHTML } from "linkedom";
1414
import AdmZip from "adm-zip";
15-
import ignore, { type Ignore } from "ignore";
15+
import type { Ignore } from "ignore";
16+
import { projectIgnore } from "@hyperframes/lint";
1617
import { CSS_URL_RE, isNonRelativeUrl, isPathInside, rewriteSrcsetUrls } from "@hyperframes/core";
1718
import { decodeUrlPathVariants, encodeUrlPath } from "@hyperframes/parsers";
1819
import { buildAuthHeaders } from "../auth/client.js";
@@ -24,12 +25,6 @@ import { writeProjectLink } from "./projectLink.js";
2425

2526
const IGNORED_DIRS = new Set([".git", "node_modules", "dist", ".next", "coverage"]);
2627
const IGNORED_FILES = new Set([".DS_Store", "Thumbs.db"]);
27-
const HYPERFRAMES_IGNORE_FILE = ".hyperframesignore";
28-
// Unanchored (no leading/mid slash) so it matches a dot-prefixed name at any
29-
// depth, same as the segments it replaces below — but as a matcher pattern
30-
// instead of a hard skip, a project's own `.hyperframesignore` negation can
31-
// still override it.
32-
const DEFAULT_PROJECT_IGNORE = ["/renders/", "/snapshots/", ".*"];
3328
const PUBLISH_CONTENT_TYPE = "application/zip";
3429
const PUBLISH_METADATA_TIMEOUT_MS = 30_000;
3530
const PUBLISH_UPLOAD_MIN_TIMEOUT_MS = 120_000;
@@ -301,21 +296,12 @@ export function uploadTimeoutMs(byteLength: number): number {
301296

302297
// Absolute, non-negotiable exclusions only — anything a `.hyperframesignore`
303298
// negation rule should be able to override (including dot-prefixed paths;
304-
// see DEFAULT_PROJECT_IGNORE) must go through the ignore matcher instead of
299+
// see projectIgnore) must go through the ignore matcher instead of
305300
// short-circuiting here.
306301
function shouldIgnoreSegment(segment: string): boolean {
307302
return IGNORED_DIRS.has(segment) || IGNORED_FILES.has(segment);
308303
}
309304

310-
function createProjectIgnore(rootDir: string): Ignore {
311-
const matcher = ignore().add(DEFAULT_PROJECT_IGNORE);
312-
const ignorePath = join(rootDir, HYPERFRAMES_IGNORE_FILE);
313-
if (existsSync(ignorePath)) {
314-
matcher.add(readFileSync(ignorePath, "utf-8"));
315-
}
316-
return matcher;
317-
}
318-
319305
function collectProjectFiles(
320306
rootDir: string,
321307
currentDir: string,
@@ -636,7 +622,7 @@ export function stagePublishFiles(
636622
): Map<string, StagedFile> {
637623
const absProjectDir = resolve(projectDir);
638624
const filePaths: string[] = [];
639-
collectProjectFiles(absProjectDir, absProjectDir, filePaths, createProjectIgnore(absProjectDir));
625+
collectProjectFiles(absProjectDir, absProjectDir, filePaths, projectIgnore(absProjectDir));
640626
if (!filePaths.includes("index.html")) {
641627
throw new Error(
642628
"Project archive must include index.html at the root. Check that .hyperframesignore does not exclude it.",

‎packages/lint/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"acorn": "^8.17.0",
5858
"acorn-walk": "^8.3.5",
5959
"htmlparser2": "^10.1.0",
60+
"ignore": "^5.3.2",
6061
"linkedom": "^0.18.12",
6162
"postcss": "^8.5.8",
6263
"postcss-selector-parser": "^7.1.4"

‎packages/lint/src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ export {
1313
} from "./hyperframeLinter.js";
1414
export { collectExternalStyles, lintProject, shouldBlockRender } from "./project.js";
1515
export type { ProjectLintResult } from "./project.js";
16+
export { projectIgnore } from "./projectIgnore.js";
1617
export { audioAttributeShapeError, type AudioAttribute } from "./rules/audioAttributes.js";

‎packages/lint/src/project.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ function makeProject(indexHtml: string, subComps?: Record<string, string>): stri
3434
const compsDir = join(dir, "compositions");
3535
mkdirSync(compsDir, { recursive: true });
3636
for (const [name, html] of Object.entries(subComps)) {
37+
mkdirSync(dirname(join(compsDir, name)), { recursive: true });
3738
writeFileSync(join(compsDir, name), html);
3839
}
3940
}
@@ -114,6 +115,24 @@ describe("blank_root_with_standalone_composition", () => {
114115
expect(finding?.suggestedComposition).toBe("compositions/index.html");
115116
});
116117

118+
it("does not count a composition in a folder the project's .hyperframesignore leaves out", async () => {
119+
const project = makeProject(validHtml(), {
120+
"archive/index.html": `<!doctype html><html><body>
121+
<div data-composition-id="old-cut" data-width="1920" data-height="1080" data-start="0" data-duration="5">
122+
<div class="clip" data-start="0" data-duration="5">Old cut</div>
123+
</div>
124+
</body></html>`,
125+
});
126+
writeFileSync(join(project, ".hyperframesignore"), "compositions/archive/\n");
127+
128+
const { results } = await lintProject(project);
129+
130+
expect(results.map((entry) => entry.file)).toEqual(["index.html"]);
131+
expect(
132+
results.flatMap((entry) => entry.result.findings).map((finding) => finding.code),
133+
).not.toContain("blank_root_with_standalone_composition");
134+
});
135+
117136
it("treats non-rendering script, style, link, meta, and template children as blank", async () => {
118137
const shellOnlyRoot = validHtml().replace(
119138
"</div>",

‎packages/lint/src/project.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export { shouldBlockRender } from "./shouldBlockRender.js";
22
import { createHash } from "node:crypto";
33
import { existsSync, readdirSync } from "node:fs";
4+
import { projectIgnore } from "./projectIgnore.js";
45
import { dirname, extname, join, relative, resolve } from "node:path";
56
import { rewriteAssetPath } from "@hyperframes/parsers/asset-paths";
67
import { spansOverlap } from "@hyperframes/parsers/time-spans";
@@ -315,10 +316,12 @@ export async function lintProject(
315316
const allHtmlSources: HtmlSource[] = [{ html: rootHtml, compSrcPath: rootCompSrcPath }];
316317
const compositionsDir = resolve(projectDir, "compositions");
317318
if (!entryFile && existsSync(compositionsDir)) {
319+
const ignored = projectIgnore(projectDir);
318320
const collectHtmlFiles = (dir: string, rel: string): string[] => {
319321
const out: string[] = [];
320322
for (const entry of readdirSync(dir, { withFileTypes: true })) {
321323
const relPath = rel ? `${rel}/${entry.name}` : entry.name;
324+
if (ignored.ignores(`compositions/${relPath}${entry.isDirectory() ? "/" : ""}`)) continue;
322325
if (entry.isDirectory()) {
323326
// Registry components are source snippets, not independently mounted
324327
// sub-compositions. Linting every installed template here makes an

‎packages/lint/src/projectIgnore.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { existsSync, readFileSync } from "node:fs";
2+
import { join } from "node:path";
3+
import ignore, { type Ignore } from "ignore";
4+
5+
const DEFAULT_PROJECT_IGNORE = ["/renders/", "/snapshots/", ".*"];
6+
7+
/** What the project leaves out; ask with a relative `/` path, a folder with a trailing `/`. */
8+
export function projectIgnore(projectDir: string): Ignore {
9+
const matcher = ignore().add(DEFAULT_PROJECT_IGNORE);
10+
const ignorePath = join(projectDir, ".hyperframesignore");
11+
if (existsSync(ignorePath)) matcher.add(readFileSync(ignorePath, "utf-8"));
12+
return matcher;
13+
}

0 commit comments

Comments
 (0)