perf(scripts): browser-file-storage 경계 검사를 ESLint 한 번으로 돌린다
문제: check:browser-file-storage-boundaries는 fixture마다
`pnpm exec eslint`를 새로 띄운다(파일 21개 + stdin 13번). 프로세스마다
flat config를 다시 읽어 desktop에서 53초가 걸리고, FE-GATE-010(66초)의
대부분이다. 같은 검사를 FE-GATE-020의 feature-scaffold 드릴이 복사본에서
한 번 더 돌아(62초) merge 1회에 약 2분을 쓴다.
고른 방법: ESLint Node API 인스턴스 하나로 같은 fixture를 같은 옵션으로
돈다. --no-ignore는 `ignore: false`, --max-warnings=0은 경고가 하나라도
있으면 실패, 파일이 없거나 설정을 못 읽으면 CLI처럼 2로 둔다. 실패
보고는 CLI 기본과 같은 stylish 형식이다. 같은 repo의 check-architecture.ts
·check-i18n.ts가 이미 API를 쓴다. 검사 대상·판정·통과 문구는 그대로다.
위험·한계: CLI가 아닌 API로 돌아 eslint CLI만의 동작(캐시, 색) 차이는
있다. 판정에는 쓰지 않는다.
검증(desktop, 38c0dc7d 위):
- 같은 트리: 전·후 모두 PASS, "34 direct or misplaced native access
cases rejected". 53초 → 3.3초.
- 변이(forbidden/direct-indexeddb.ts를 무해한 코드로): 전·후 모두 rc=1,
실패 목록 같음(2건). 변이(allowed fixture에 코드 추가) 두 개: 전·후
모두 rc=0.
- tsc -p tsconfig.node.json, eslint 이 파일: rc=0
This commit is contained in:
@@ -1,50 +1,38 @@
|
|||||||
import { spawnSync } from "node:child_process";
|
|
||||||
import { readFile, readdir } from "node:fs/promises";
|
import { readFile, readdir } from "node:fs/promises";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
|
|
||||||
function requiredPnpmCli(): string {
|
import { ESLint } from "eslint";
|
||||||
const executable = process.env.npm_execpath;
|
|
||||||
if (!executable) {
|
/** A lint run's verdict as `eslint --no-ignore --max-warnings=0` would exit, and its report. */
|
||||||
throw new Error(
|
type LintOutcome = Readonly<{ status: number; output: string }>;
|
||||||
"check:browser-file-storage-boundaries must run through pnpm",
|
|
||||||
);
|
// One ESLint instance lints every fixture. The check used to start
|
||||||
|
// `pnpm exec eslint` once per fixture (about 30 processes), and loading the
|
||||||
|
// flat config each time was most of FE-GATE-010's minute. The options match
|
||||||
|
// that command line: --no-ignore is `ignore: false`, --max-warnings=0 makes a
|
||||||
|
// warning fail like an error.
|
||||||
|
const eslint = new ESLint({ ignore: false });
|
||||||
|
const formatter = await eslint.loadFormatter("stylish");
|
||||||
|
|
||||||
|
async function lintOutcome(results: ESLint.LintResult[]): Promise<LintOutcome> {
|
||||||
|
const failed = results.some((result) => result.errorCount > 0 || result.warningCount > 0);
|
||||||
|
return { status: failed ? 1 : 0, output: await formatter.format(results) };
|
||||||
|
}
|
||||||
|
|
||||||
|
async function runEslint(target: string): Promise<LintOutcome> {
|
||||||
|
try {
|
||||||
|
return await lintOutcome(await eslint.lintFiles([target]));
|
||||||
|
} catch (error) {
|
||||||
|
// The CLI exits 2 when nothing matches or the config fails to load.
|
||||||
|
return { status: 2, output: `${error instanceof Error ? error.message : String(error)}\n` };
|
||||||
}
|
}
|
||||||
return executable;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function runEslint(path: string) {
|
async function runEslintSource(source: string, virtualPath: string): Promise<LintOutcome> {
|
||||||
return spawnSync(
|
return lintOutcome(await eslint.lintText(source, { filePath: virtualPath, warnIgnored: true }));
|
||||||
process.execPath,
|
|
||||||
[
|
|
||||||
requiredPnpmCli(),
|
|
||||||
"exec",
|
|
||||||
"eslint",
|
|
||||||
path,
|
|
||||||
"--no-ignore",
|
|
||||||
"--max-warnings=0",
|
|
||||||
],
|
|
||||||
{ encoding: "utf8" },
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function runEslintSource(source: string, virtualPath: string) {
|
const allowed = await runEslint(
|
||||||
return spawnSync(
|
|
||||||
process.execPath,
|
|
||||||
[
|
|
||||||
requiredPnpmCli(),
|
|
||||||
"exec",
|
|
||||||
"eslint",
|
|
||||||
"--stdin",
|
|
||||||
"--stdin-filename",
|
|
||||||
virtualPath,
|
|
||||||
"--no-ignore",
|
|
||||||
"--max-warnings=0",
|
|
||||||
],
|
|
||||||
{ encoding: "utf8", input: source },
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const allowed = runEslint(
|
|
||||||
"tests/fixtures/browser-file-storage-boundaries/allowed",
|
"tests/fixtures/browser-file-storage-boundaries/allowed",
|
||||||
);
|
);
|
||||||
const forbiddenRoot =
|
const forbiddenRoot =
|
||||||
@@ -54,10 +42,10 @@ const forbiddenFiles = (
|
|||||||
)
|
)
|
||||||
.filter((entry) => entry.isFile() && /\.tsx?$/u.test(entry.name))
|
.filter((entry) => entry.isFile() && /\.tsx?$/u.test(entry.name))
|
||||||
.map((entry) => path.join(forbiddenRoot, entry.name));
|
.map((entry) => path.join(forbiddenRoot, entry.name));
|
||||||
const forbiddenResults = forbiddenFiles.map((file) => ({
|
const forbiddenResults: Array<{ file: string; result: LintOutcome }> = [];
|
||||||
file,
|
for (const file of forbiddenFiles) {
|
||||||
result: runEslint(file),
|
forbiddenResults.push({ file, result: await runEslint(file) });
|
||||||
}));
|
}
|
||||||
const acceptedForbidden = forbiddenResults.filter(
|
const acceptedForbidden = forbiddenResults.filter(
|
||||||
({ result }) => result.status === 0,
|
({ result }) => result.status === 0,
|
||||||
);
|
);
|
||||||
@@ -102,28 +90,28 @@ const protectedSourceFixtures = await Promise.all(
|
|||||||
const approvedAdapterResults = [
|
const approvedAdapterResults = [
|
||||||
{
|
{
|
||||||
file: "src/adapters/storage/indexeddb/boundary-fixture.ts",
|
file: "src/adapters/storage/indexeddb/boundary-fixture.ts",
|
||||||
result: runEslintSource(
|
result: await runEslintSource(
|
||||||
indexedDbBypassSource,
|
indexedDbBypassSource,
|
||||||
"src/adapters/storage/indexeddb/boundary-fixture.ts",
|
"src/adapters/storage/indexeddb/boundary-fixture.ts",
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
file: "src/adapters/cross-context-invalidation/boundary-fixture.ts",
|
file: "src/adapters/cross-context-invalidation/boundary-fixture.ts",
|
||||||
result: runEslintSource(
|
result: await runEslintSource(
|
||||||
crossContextAdapterSource,
|
crossContextAdapterSource,
|
||||||
"src/adapters/cross-context-invalidation/boundary-fixture.ts",
|
"src/adapters/cross-context-invalidation/boundary-fixture.ts",
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
file: "src/adapters/storage/boundary-fixture.ts",
|
file: "src/adapters/storage/boundary-fixture.ts",
|
||||||
result: runEslintSource(
|
result: await runEslintSource(
|
||||||
browserStorageAdapterSource,
|
browserStorageAdapterSource,
|
||||||
"src/adapters/storage/boundary-fixture.ts",
|
"src/adapters/storage/boundary-fixture.ts",
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
file: "src/adapters/browser-transfer/boundary-fixture.ts",
|
file: "src/adapters/browser-transfer/boundary-fixture.ts",
|
||||||
result: runEslintSource(
|
result: await runEslintSource(
|
||||||
blobBypassSource,
|
blobBypassSource,
|
||||||
"src/adapters/browser-transfer/boundary-fixture.ts",
|
"src/adapters/browser-transfer/boundary-fixture.ts",
|
||||||
),
|
),
|
||||||
@@ -135,40 +123,40 @@ const rejectedApprovedAdapters = approvedAdapterResults.filter(
|
|||||||
const misplacedAdapterResults = [
|
const misplacedAdapterResults = [
|
||||||
{
|
{
|
||||||
file: "src/adapters/http/boundary-fixture.ts",
|
file: "src/adapters/http/boundary-fixture.ts",
|
||||||
result: runEslintSource(
|
result: await runEslintSource(
|
||||||
indexedDbBypassSource,
|
indexedDbBypassSource,
|
||||||
"src/adapters/http/boundary-fixture.ts",
|
"src/adapters/http/boundary-fixture.ts",
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
file: "src/features/fixture-feature/adapters/boundary-fixture.ts",
|
file: "src/features/fixture-feature/adapters/boundary-fixture.ts",
|
||||||
result: runEslintSource(
|
result: await runEslintSource(
|
||||||
objectUrlBypassSource,
|
objectUrlBypassSource,
|
||||||
"src/features/fixture-feature/adapters/boundary-fixture.ts",
|
"src/features/fixture-feature/adapters/boundary-fixture.ts",
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
file: "src/adapters/http/cross-context-boundary-fixture.ts",
|
file: "src/adapters/http/cross-context-boundary-fixture.ts",
|
||||||
result: runEslintSource(
|
result: await runEslintSource(
|
||||||
crossContextAdapterSource,
|
crossContextAdapterSource,
|
||||||
"src/adapters/http/cross-context-boundary-fixture.ts",
|
"src/adapters/http/cross-context-boundary-fixture.ts",
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
file: "src/adapters/http/browser-storage-boundary-fixture.ts",
|
file: "src/adapters/http/browser-storage-boundary-fixture.ts",
|
||||||
result: runEslintSource(
|
result: await runEslintSource(
|
||||||
browserStorageAdapterSource,
|
browserStorageAdapterSource,
|
||||||
"src/adapters/http/browser-storage-boundary-fixture.ts",
|
"src/adapters/http/browser-storage-boundary-fixture.ts",
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
...protectedSourceFixtures.map(({ file, source }) => {
|
|
||||||
const virtualPath = `src/presentation/${file}`;
|
|
||||||
return {
|
|
||||||
file: virtualPath,
|
|
||||||
result: runEslintSource(source, virtualPath),
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
];
|
];
|
||||||
|
for (const { file, source } of protectedSourceFixtures) {
|
||||||
|
const virtualPath = `src/presentation/${file}`;
|
||||||
|
misplacedAdapterResults.push({
|
||||||
|
file: virtualPath,
|
||||||
|
result: await runEslintSource(source, virtualPath),
|
||||||
|
});
|
||||||
|
}
|
||||||
const acceptedMisplacedAdapters = misplacedAdapterResults.filter(
|
const acceptedMisplacedAdapters = misplacedAdapterResults.filter(
|
||||||
({ result }) => result.status === 0,
|
({ result }) => result.status === 0,
|
||||||
);
|
);
|
||||||
@@ -180,24 +168,24 @@ if (
|
|||||||
acceptedForbidden.length > 0 ||
|
acceptedForbidden.length > 0 ||
|
||||||
acceptedMisplacedAdapters.length > 0
|
acceptedMisplacedAdapters.length > 0
|
||||||
) {
|
) {
|
||||||
process.stderr.write(allowed.stderr || allowed.stdout);
|
process.stderr.write(allowed.output);
|
||||||
for (const { file, result } of rejectedApprovedAdapters) {
|
for (const { file, result } of rejectedApprovedAdapters) {
|
||||||
process.stderr.write(
|
process.stderr.write(
|
||||||
`${file}: owned browser capability adapter was rejected\n`,
|
`${file}: owned browser capability adapter was rejected\n`,
|
||||||
);
|
);
|
||||||
process.stderr.write(result.stderr || result.stdout);
|
process.stderr.write(result.output);
|
||||||
}
|
}
|
||||||
for (const { file, result } of acceptedForbidden) {
|
for (const { file, result } of acceptedForbidden) {
|
||||||
process.stderr.write(
|
process.stderr.write(
|
||||||
`${file}: forbidden browser API fixture was accepted\n`,
|
`${file}: forbidden browser API fixture was accepted\n`,
|
||||||
);
|
);
|
||||||
process.stderr.write(result.stderr || result.stdout);
|
process.stderr.write(result.output);
|
||||||
}
|
}
|
||||||
for (const { file, result } of acceptedMisplacedAdapters) {
|
for (const { file, result } of acceptedMisplacedAdapters) {
|
||||||
process.stderr.write(
|
process.stderr.write(
|
||||||
`${file}: native browser storage access outside its owned adapter was accepted\n`,
|
`${file}: native browser storage access outside its owned adapter was accepted\n`,
|
||||||
);
|
);
|
||||||
process.stderr.write(result.stderr || result.stdout);
|
process.stderr.write(result.output);
|
||||||
}
|
}
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user