vouchington-tooling 0.63.0 → 0.64.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +88 -0
- package/dist/cli/commands/cloc.d.mts +7 -0
- package/dist/cli/commands/cloc.mjs +47 -0
- package/dist/cli/commands/storybook-browser-runner.d.mts +7 -0
- package/dist/cli/commands/storybook-browser-runner.mjs +29 -0
- package/dist/cli/index.mjs +4 -0
- package/dist/cli/parse-forwarded-commands.d.mts +6 -0
- package/dist/cli/parse-forwarded-commands.mjs +4 -0
- package/dist/cli/parse.d.mts +6 -0
- package/dist/cli/usage-text.d.mts +1 -1
- package/dist/cli/usage-text.mjs +18 -0
- package/dist/cloc/child-process.d.mts +3 -0
- package/dist/cloc/child-process.mjs +14 -0
- package/dist/cloc/classify.d.mts +8 -0
- package/dist/cloc/classify.mjs +20 -0
- package/dist/cloc/config-load.d.mts +7 -0
- package/dist/cloc/config-load.mjs +26 -0
- package/dist/cloc/config.d.mts +55 -0
- package/dist/cloc/config.mjs +109 -0
- package/dist/cloc/count.d.mts +9 -0
- package/dist/cloc/count.mjs +33 -0
- package/dist/cloc/index.d.mts +12 -0
- package/dist/cloc/index.mjs +7 -0
- package/dist/cloc/layout.test-helpers.d.mts +8 -0
- package/dist/cloc/layout.test-helpers.mjs +42 -0
- package/dist/cloc/paths.d.mts +7 -0
- package/dist/cloc/paths.mjs +29 -0
- package/dist/cloc/patterns.d.mts +10 -0
- package/dist/cloc/patterns.mjs +25 -0
- package/dist/cloc/rows.d.mts +13 -0
- package/dist/cloc/rows.mjs +42 -0
- package/dist/cloc/scc.d.mts +10 -0
- package/dist/cloc/scc.mjs +55 -0
- package/dist/cloc/tracked.d.mts +4 -0
- package/dist/cloc/tracked.mjs +40 -0
- package/dist/storybook-browser-runner/args.d.mts +8 -0
- package/dist/storybook-browser-runner/args.mjs +52 -0
- package/dist/storybook-browser-runner/attempt-result.d.mts +41 -0
- package/dist/storybook-browser-runner/attempt-result.mjs +108 -0
- package/dist/storybook-browser-runner/bootstrap-telemetry.d.mts +35 -0
- package/dist/storybook-browser-runner/bootstrap-telemetry.mjs +138 -0
- package/dist/storybook-browser-runner/cache-plan.d.mts +22 -0
- package/dist/storybook-browser-runner/cache-plan.mjs +53 -0
- package/dist/storybook-browser-runner/diagnostics.d.mts +8 -0
- package/dist/storybook-browser-runner/diagnostics.mjs +29 -0
- package/dist/storybook-browser-runner/env.d.mts +2 -0
- package/dist/storybook-browser-runner/env.mjs +59 -0
- package/dist/storybook-browser-runner/fixtures.test-helpers.d.mts +49 -0
- package/dist/storybook-browser-runner/fixtures.test-helpers.mjs +95 -0
- package/dist/storybook-browser-runner/index.d.mts +15 -0
- package/dist/storybook-browser-runner/index.mjs +70 -0
- package/dist/storybook-browser-runner/observer-state.d.mts +22 -0
- package/dist/storybook-browser-runner/observer-state.mjs +21 -0
- package/dist/storybook-browser-runner/options.d.mts +18 -0
- package/dist/storybook-browser-runner/options.mjs +49 -0
- package/dist/storybook-browser-runner/output-observer.d.mts +37 -0
- package/dist/storybook-browser-runner/output-observer.mjs +130 -0
- package/dist/storybook-browser-runner/output-patterns.d.mts +14 -0
- package/dist/storybook-browser-runner/output-patterns.mjs +26 -0
- package/dist/storybook-browser-runner/quiet-output.d.mts +16 -0
- package/dist/storybook-browser-runner/quiet-output.mjs +79 -0
- package/dist/storybook-browser-runner/run-attempt.d.mts +14 -0
- package/dist/storybook-browser-runner/run-attempt.mjs +111 -0
- package/dist/storybook-browser-runner/runtime-metadata.d.mts +12 -0
- package/dist/storybook-browser-runner/runtime-metadata.mjs +50 -0
- package/dist/storybook-browser-runner/session-deps.d.mts +11 -0
- package/dist/storybook-browser-runner/session-deps.mjs +70 -0
- package/dist/storybook-browser-runner/types.d.mts +49 -0
- package/dist/storybook-browser-runner/types.mjs +1 -0
- package/dist/storybook-browser-runner/vite-detectors.d.mts +6 -0
- package/dist/storybook-browser-runner/vite-detectors.mjs +20 -0
- package/dist/storybook-browser-runner/watchdog.d.mts +23 -0
- package/dist/storybook-browser-runner/watchdog.mjs +55 -0
- package/package.json +11 -1
- package/scripts/__pycache__/run_bounded_process.cpython-312.pyc +0 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
|
+
import { createPathPolicy } from "./paths.mjs";
|
|
3
|
+
import { readSccFiles } from "./scc.mjs";
|
|
4
|
+
import { gitTopLevel, listTrackedFiles } from "./tracked.mjs";
|
|
5
|
+
/** Lists tracked files with git, then counts the configured targets with scc. */
|
|
6
|
+
export async function countFiles(config, options) {
|
|
7
|
+
const root = await gitTopLevel(options.cwd);
|
|
8
|
+
const tracked = await listTrackedFiles(root);
|
|
9
|
+
const policy = createPathPolicy(config);
|
|
10
|
+
const targets = policy.countTargetsFor(tracked);
|
|
11
|
+
// scc with no target would scan the whole working directory.
|
|
12
|
+
if (targets.length === 0)
|
|
13
|
+
return [];
|
|
14
|
+
const requested = options.sccBin ?? (options.env ?? process.env).SCC_BIN ?? config.sccBin ?? 'scc';
|
|
15
|
+
// The child runs from the repository top level; a path-like binary is relative to the caller.
|
|
16
|
+
const sccBin = requested.includes('/') ? resolve(options.cwd, requested) : requested;
|
|
17
|
+
try {
|
|
18
|
+
return await readSccFiles({
|
|
19
|
+
sccBin,
|
|
20
|
+
targets,
|
|
21
|
+
excludedDirs: config.excludedDirs,
|
|
22
|
+
cwd: root,
|
|
23
|
+
keep: (filePath) => policy.shouldCountFile(filePath, tracked),
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
if (err.code === 'ENOENT') {
|
|
28
|
+
const hint = config.missingSccHint === undefined ? '' : ` ${config.missingSccHint}`;
|
|
29
|
+
throw new Error(`scc is required but "${sccBin}" was not found.${hint}`, { cause: err });
|
|
30
|
+
}
|
|
31
|
+
throw err;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { createClassifier } from './classify.mts';
|
|
2
|
+
export type { CategoryKey, Classification } from './classify.mts';
|
|
3
|
+
export { loadClocConfig } from './config-load.mts';
|
|
4
|
+
export type { LoadModule } from './config-load.mts';
|
|
5
|
+
export { normalizeClocConfig } from './config.mts';
|
|
6
|
+
export type { ClocCategories, ClocConfig, ClocConfigInput, ClocServiceRule, ClocServiceRuleInput, } from './config.mts';
|
|
7
|
+
export { countFiles } from './count.mts';
|
|
8
|
+
export type { CountOptions } from './count.mts';
|
|
9
|
+
export { createPathPolicy } from './paths.mts';
|
|
10
|
+
export { compilePatterns, normalizePath } from './patterns.mts';
|
|
11
|
+
export { buildRows, formatRows } from './rows.mts';
|
|
12
|
+
export type { ClocRow, CountedFile } from './rows.mts';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createClassifier } from "./classify.mjs";
|
|
2
|
+
export { loadClocConfig } from "./config-load.mjs";
|
|
3
|
+
export { normalizeClocConfig } from "./config.mjs";
|
|
4
|
+
export { countFiles } from "./count.mjs";
|
|
5
|
+
export { createPathPolicy } from "./paths.mjs";
|
|
6
|
+
export { compilePatterns, normalizePath } from "./patterns.mjs";
|
|
7
|
+
export { buildRows, formatRows } from "./rows.mjs";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ClocConfig, type ClocConfigInput } from './config.mts';
|
|
2
|
+
export declare const LAYOUT: ClocConfigInput;
|
|
3
|
+
export declare function layoutConfig(overrides?: ClocConfigInput): ClocConfig;
|
|
4
|
+
export declare function tempRepo(files: Record<string, string>): string;
|
|
5
|
+
/** An executable stand-in for scc that prints the given stdout and exits with `status`. */
|
|
6
|
+
export declare function fakeScc(stdout: string, status?: number): string;
|
|
7
|
+
export declare const SCC_HEADER = "Language,Provider,Filename,Lines,Code,Comments,Blanks,Complexity,Bytes\n";
|
|
8
|
+
export declare function sccCsv(rows: Record<string, number>): string;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { chmodSync, mkdirSync, mkdtempSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { execFileSync } from 'node:child_process';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { dirname, join } from 'node:path';
|
|
5
|
+
import { normalizeClocConfig } from "./config.mjs";
|
|
6
|
+
export const LAYOUT = {
|
|
7
|
+
services: [
|
|
8
|
+
{ name: 'api', match: ['api/'] },
|
|
9
|
+
{ name: 'ui', match: ['ui/', 'e2e/'] },
|
|
10
|
+
{ name: 'docs', match: ['docs/', 'README.md'] },
|
|
11
|
+
],
|
|
12
|
+
defaultService: 'tooling',
|
|
13
|
+
testPatterns: ['*.test.*', '**/__tests__/**', 'e2e/'],
|
|
14
|
+
toolingPatterns: ['.github/', '**/scripts/**', 'package.json', '*.config.*'],
|
|
15
|
+
countedRoots: ['.github', 'api', 'docs', 'e2e', 'scripts', 'ui'],
|
|
16
|
+
countedRootFiles: ['README.md', 'package.json', 'missing.json'],
|
|
17
|
+
};
|
|
18
|
+
export function layoutConfig(overrides = {}) {
|
|
19
|
+
return normalizeClocConfig({ ...LAYOUT, ...overrides });
|
|
20
|
+
}
|
|
21
|
+
export function tempRepo(files) {
|
|
22
|
+
const root = mkdtempSync(join(tmpdir(), 'cloc-'));
|
|
23
|
+
for (const [file, content] of Object.entries(files)) {
|
|
24
|
+
mkdirSync(dirname(join(root, file)), { recursive: true });
|
|
25
|
+
writeFileSync(join(root, file), content);
|
|
26
|
+
}
|
|
27
|
+
execFileSync('git', ['init', '-q'], { cwd: root });
|
|
28
|
+
execFileSync('git', ['add', '-A'], { cwd: root });
|
|
29
|
+
return root;
|
|
30
|
+
}
|
|
31
|
+
/** An executable stand-in for scc that prints the given stdout and exits with `status`. */
|
|
32
|
+
export function fakeScc(stdout, status = 0) {
|
|
33
|
+
const file = join(mkdtempSync(join(tmpdir(), 'scc-')), 'scc');
|
|
34
|
+
writeFileSync(file, `#!/usr/bin/env node\nprocess.stdout.write(${JSON.stringify(stdout)})\nprocess.exit(${status})\n`);
|
|
35
|
+
chmodSync(file, 0o755);
|
|
36
|
+
return file;
|
|
37
|
+
}
|
|
38
|
+
export const SCC_HEADER = 'Language,Provider,Filename,Lines,Code,Comments,Blanks,Complexity,Bytes\n';
|
|
39
|
+
export function sccCsv(rows) {
|
|
40
|
+
const body = Object.entries(rows).map(([path, code]) => `TypeScript,${path},x,${code},${code},0,0,0,0\n`);
|
|
41
|
+
return SCC_HEADER + body.join('');
|
|
42
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ClocConfig } from './config.mts';
|
|
2
|
+
/** Decides which tracked paths are counted and which scc targets to hand the binary. */
|
|
3
|
+
export declare function createPathPolicy(config: ClocConfig): {
|
|
4
|
+
isCountedPath: (filePath: string) => boolean;
|
|
5
|
+
shouldCountFile: (filePath: string, trackedFiles: ReadonlySet<string>) => boolean;
|
|
6
|
+
countTargetsFor: (trackedFiles: ReadonlySet<string>) => string[];
|
|
7
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Decides which tracked paths are counted and which scc targets to hand the binary. */
|
|
2
|
+
export function createPathPolicy(config) {
|
|
3
|
+
const { countedRoots, countedRootFiles, ignoredDirs } = config;
|
|
4
|
+
const countAll = countedRoots.length === 0 && countedRootFiles.length === 0;
|
|
5
|
+
const ignored = new Set(ignoredDirs);
|
|
6
|
+
function isCountedPath(filePath) {
|
|
7
|
+
return (countAll ||
|
|
8
|
+
countedRootFiles.includes(filePath) ||
|
|
9
|
+
countedRoots.some((root) => filePath === root || filePath.startsWith(`${root}/`)));
|
|
10
|
+
}
|
|
11
|
+
function isIgnoredPath(filePath) {
|
|
12
|
+
return filePath
|
|
13
|
+
.split('/')
|
|
14
|
+
.slice(0, -1)
|
|
15
|
+
.some((segment) => ignored.has(segment));
|
|
16
|
+
}
|
|
17
|
+
function shouldCountFile(filePath, trackedFiles) {
|
|
18
|
+
return trackedFiles.has(filePath) && isCountedPath(filePath) && !isIgnoredPath(filePath);
|
|
19
|
+
}
|
|
20
|
+
function countTargetsFor(trackedFiles) {
|
|
21
|
+
if (countAll)
|
|
22
|
+
return trackedFiles.size === 0 ? [] : ['.'];
|
|
23
|
+
const files = [...trackedFiles];
|
|
24
|
+
const present = [...new Set([...countedRoots, ...countedRootFiles])].filter((target) => trackedFiles.has(target) || files.some((file) => file.startsWith(`${target}/`)));
|
|
25
|
+
// scc counts a file once per target that reaches it, so drop targets nested under another.
|
|
26
|
+
return present.filter((target) => !present.some((other) => other !== target && target.startsWith(`${other}/`)));
|
|
27
|
+
}
|
|
28
|
+
return { isCountedPath, shouldCountFile, countTargetsFor };
|
|
29
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function normalizePath(filePath: string): string;
|
|
2
|
+
/**
|
|
3
|
+
* Compiles path patterns into one predicate over repository-relative POSIX paths.
|
|
4
|
+
*
|
|
5
|
+
* - No `/` (`*.test.*`, `package.json`): matched against the basename, anywhere in the tree.
|
|
6
|
+
* - Trailing `/` (`docs/`) or a `/` with no glob characters (`docs/api`): the path itself or
|
|
7
|
+
* anything under it.
|
|
8
|
+
* - A `/` with glob characters (`**` + `/tests/**`): a full-path glob. Dotfiles match.
|
|
9
|
+
*/
|
|
10
|
+
export declare function compilePatterns(patterns: readonly string[]): (filePath: string) => boolean;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import picomatch from 'picomatch';
|
|
3
|
+
export function normalizePath(filePath) {
|
|
4
|
+
return filePath.replaceAll(path.sep, '/').replace(/^\.\//u, '');
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Compiles path patterns into one predicate over repository-relative POSIX paths.
|
|
8
|
+
*
|
|
9
|
+
* - No `/` (`*.test.*`, `package.json`): matched against the basename, anywhere in the tree.
|
|
10
|
+
* - Trailing `/` (`docs/`) or a `/` with no glob characters (`docs/api`): the path itself or
|
|
11
|
+
* anything under it.
|
|
12
|
+
* - A `/` with glob characters (`**` + `/tests/**`): a full-path glob. Dotfiles match.
|
|
13
|
+
*/
|
|
14
|
+
export function compilePatterns(patterns) {
|
|
15
|
+
const matchers = patterns.map((pattern) => {
|
|
16
|
+
if (!pattern.includes('/'))
|
|
17
|
+
return picomatch(pattern, { basename: true, dot: true });
|
|
18
|
+
if (picomatch.scan(pattern).isGlob) {
|
|
19
|
+
return picomatch(pattern.endsWith('/') ? `${pattern}**` : pattern, { dot: true });
|
|
20
|
+
}
|
|
21
|
+
const prefix = normalizePath(pattern).replace(/\/+$/u, '');
|
|
22
|
+
return (filePath) => filePath === prefix || filePath.startsWith(`${prefix}/`);
|
|
23
|
+
});
|
|
24
|
+
return (filePath) => matchers.some((matches) => matches(filePath));
|
|
25
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ClocConfig } from './config.mts';
|
|
2
|
+
export type CountedFile = {
|
|
3
|
+
code: number;
|
|
4
|
+
path: string;
|
|
5
|
+
};
|
|
6
|
+
/** One table row: per-category line counts keyed by the configured category names. */
|
|
7
|
+
export type ClocRow = {
|
|
8
|
+
service: string;
|
|
9
|
+
counts: Record<string, number>;
|
|
10
|
+
total: number;
|
|
11
|
+
};
|
|
12
|
+
export declare function buildRows(files: readonly CountedFile[], config: ClocConfig): ClocRow[];
|
|
13
|
+
export declare function formatRows(rows: readonly ClocRow[], config: ClocConfig): string;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { createClassifier } from "./classify.mjs";
|
|
2
|
+
export function buildRows(files, config) {
|
|
3
|
+
const classify = createClassifier(config);
|
|
4
|
+
const names = config.categories;
|
|
5
|
+
const blank = (service) => ({
|
|
6
|
+
service,
|
|
7
|
+
counts: { [names.source]: 0, [names.tests]: 0, [names.tooling]: 0 },
|
|
8
|
+
total: 0,
|
|
9
|
+
});
|
|
10
|
+
const rows = new Map(config.services.map((rule) => [rule.name, blank(rule.name)]));
|
|
11
|
+
const total = blank('total');
|
|
12
|
+
for (const file of files) {
|
|
13
|
+
const { category, service } = classify(file.path);
|
|
14
|
+
const label = names[category];
|
|
15
|
+
for (const target of [rows.get(service), total]) {
|
|
16
|
+
target.counts[label] = Number(target.counts[label]) + file.code;
|
|
17
|
+
target.total += file.code;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return [...rows.values(), total];
|
|
21
|
+
}
|
|
22
|
+
export function formatRows(rows, config) {
|
|
23
|
+
const { source, tests, tooling } = config.categories;
|
|
24
|
+
const columns = ['service', source, tests, tooling, 'total'];
|
|
25
|
+
const cell = (row, column) => {
|
|
26
|
+
if (column === 'service')
|
|
27
|
+
return row.service;
|
|
28
|
+
return String(column === 'total' ? row.total : (row.counts[column] ?? 0));
|
|
29
|
+
};
|
|
30
|
+
const table = columns.map((name) => {
|
|
31
|
+
const width = Math.max(name.length, ...rows.map((row) => cell(row, name).length));
|
|
32
|
+
return { name, width };
|
|
33
|
+
});
|
|
34
|
+
const line = (cells) => table
|
|
35
|
+
.map(({ name, width }, index) => index === 0 ? cells(name).padEnd(width) : cells(name).padStart(width))
|
|
36
|
+
.join(' ');
|
|
37
|
+
return [
|
|
38
|
+
line((name) => name),
|
|
39
|
+
table.map(({ width }) => '-'.repeat(width)).join(' '),
|
|
40
|
+
...rows.map((row) => line((name) => cell(row, name))),
|
|
41
|
+
].join('\n');
|
|
42
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CountedFile } from './rows.mts';
|
|
2
|
+
export type SccRun = {
|
|
3
|
+
sccBin: string;
|
|
4
|
+
targets: readonly string[];
|
|
5
|
+
excludedDirs: readonly string[];
|
|
6
|
+
cwd: string;
|
|
7
|
+
keep: (filePath: string) => boolean;
|
|
8
|
+
};
|
|
9
|
+
/** Streams `scc --by-file` CSV and returns the rows `keep` accepts. */
|
|
10
|
+
export declare function readSccFiles(run: SccRun): Promise<CountedFile[]>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { createInterface } from 'node:readline';
|
|
3
|
+
import { parse } from 'csv-parse/sync';
|
|
4
|
+
import { requireSuccess, terminateChild } from "./child-process.mjs";
|
|
5
|
+
import { normalizePath } from "./patterns.mjs";
|
|
6
|
+
function parseRecord(row) {
|
|
7
|
+
const records = parse(row);
|
|
8
|
+
const fields = records.length === 1 ? records[0] : undefined;
|
|
9
|
+
const path = fields?.[1];
|
|
10
|
+
const code = Number(fields?.[4]);
|
|
11
|
+
if (!path || !fields?.[4]?.trim() || !Number.isSafeInteger(code)) {
|
|
12
|
+
throw new Error('Invalid CSV record from scc');
|
|
13
|
+
}
|
|
14
|
+
return { code, path: normalizePath(path) };
|
|
15
|
+
}
|
|
16
|
+
/** Streams `scc --by-file` CSV and returns the rows `keep` accepts. */
|
|
17
|
+
export async function readSccFiles(run) {
|
|
18
|
+
const args = ['--format', 'csv-stream', '--by-file', '--no-cocomo', '--no-complexity'];
|
|
19
|
+
if (run.excludedDirs.length > 0)
|
|
20
|
+
args.push('--exclude-dir', run.excludedDirs.join(','));
|
|
21
|
+
const child = spawn(run.sccBin, [...args, '--', ...run.targets], {
|
|
22
|
+
cwd: run.cwd,
|
|
23
|
+
stdio: ['ignore', 'pipe', 'inherit'],
|
|
24
|
+
});
|
|
25
|
+
const completion = requireSuccess(child, 'scc');
|
|
26
|
+
// A spawn error (ENOENT) can reject before the stream loop reaches `await completion`.
|
|
27
|
+
completion.catch(() => { });
|
|
28
|
+
const files = [];
|
|
29
|
+
const rows = createInterface({ input: child.stdout, crlfDelay: Infinity });
|
|
30
|
+
let sawHeader = false;
|
|
31
|
+
let completed = false;
|
|
32
|
+
try {
|
|
33
|
+
for await (const row of rows) {
|
|
34
|
+
if (!sawHeader) {
|
|
35
|
+
if (!row.startsWith('Language,'))
|
|
36
|
+
throw new Error('Unexpected CSV header from scc');
|
|
37
|
+
sawHeader = true;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const file = parseRecord(row);
|
|
41
|
+
if (run.keep(file.path))
|
|
42
|
+
files.push(file);
|
|
43
|
+
}
|
|
44
|
+
await completion;
|
|
45
|
+
if (!sawHeader)
|
|
46
|
+
throw new Error('scc produced no CSV header');
|
|
47
|
+
completed = true;
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
rows.close();
|
|
51
|
+
if (!completed)
|
|
52
|
+
await terminateChild(child, completion);
|
|
53
|
+
}
|
|
54
|
+
return files;
|
|
55
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Streams `git ls-files -z` (every entry is NUL-terminated) so the listing has no size cap. */
|
|
2
|
+
export declare function listTrackedFiles(cwd: string): Promise<Set<string>>;
|
|
3
|
+
/** The repository top level, so a run from a subdirectory still sees repository-relative paths. */
|
|
4
|
+
export declare function gitTopLevel(cwd: string): Promise<string>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { execFile, spawn } from 'node:child_process';
|
|
2
|
+
import { promisify } from 'node:util';
|
|
3
|
+
import { requireSuccess, terminateChild } from "./child-process.mjs";
|
|
4
|
+
import { normalizePath } from "./patterns.mjs";
|
|
5
|
+
/** Streams `git ls-files -z` (every entry is NUL-terminated) so the listing has no size cap. */
|
|
6
|
+
export async function listTrackedFiles(cwd) {
|
|
7
|
+
const child = spawn('git', ['ls-files', '-z'], { cwd, stdio: ['ignore', 'pipe', 'inherit'] });
|
|
8
|
+
const completion = requireSuccess(child, 'git ls-files');
|
|
9
|
+
completion.catch(() => { });
|
|
10
|
+
const files = new Set();
|
|
11
|
+
let remainder = Buffer.alloc(0);
|
|
12
|
+
let completed = false;
|
|
13
|
+
try {
|
|
14
|
+
for await (const chunk of child.stdout) {
|
|
15
|
+
const data = Buffer.concat([remainder, chunk]);
|
|
16
|
+
let start = 0;
|
|
17
|
+
for (;;) {
|
|
18
|
+
const end = data.indexOf(0, start);
|
|
19
|
+
if (end === -1)
|
|
20
|
+
break;
|
|
21
|
+
files.add(normalizePath(data.subarray(start, end).toString('utf8')));
|
|
22
|
+
start = end + 1;
|
|
23
|
+
}
|
|
24
|
+
remainder = data.subarray(start);
|
|
25
|
+
}
|
|
26
|
+
await completion;
|
|
27
|
+
completed = true;
|
|
28
|
+
}
|
|
29
|
+
finally {
|
|
30
|
+
if (!completed)
|
|
31
|
+
await terminateChild(child, completion);
|
|
32
|
+
}
|
|
33
|
+
return files;
|
|
34
|
+
}
|
|
35
|
+
const execFileAsync = promisify(execFile);
|
|
36
|
+
/** The repository top level, so a run from a subdirectory still sees repository-relative paths. */
|
|
37
|
+
export async function gitTopLevel(cwd) {
|
|
38
|
+
const { stdout } = await execFileAsync('git', ['rev-parse', '--show-toplevel'], { cwd });
|
|
39
|
+
return stdout.trim();
|
|
40
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { StorybookBrowserProject } from './types.mts';
|
|
2
|
+
export type ParsedStorybookBrowserRunnerArgs = StorybookBrowserProject;
|
|
3
|
+
/**
|
|
4
|
+
* Parses the `storybook-browser-runner` flags. Arguments after `--` replace the default argv
|
|
5
|
+
* (`exec vitest run --project <name>`), so they may begin with a dash. Flag values that begin
|
|
6
|
+
* with a dash use the `--flag=value` form. Throws an Error naming the first problem.
|
|
7
|
+
*/
|
|
8
|
+
export declare function parseStorybookBrowserRunnerArgs(argv: readonly string[]): ParsedStorybookBrowserRunnerArgs;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { parseArgs } from 'node:util';
|
|
2
|
+
function required(raw, flag) {
|
|
3
|
+
if (raw.length === 0 || raw.startsWith('-'))
|
|
4
|
+
throw new Error(`${flag} requires a value`);
|
|
5
|
+
return raw;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Parses the `storybook-browser-runner` flags. Arguments after `--` replace the default argv
|
|
9
|
+
* (`exec vitest run --project <name>`), so they may begin with a dash. Flag values that begin
|
|
10
|
+
* with a dash use the `--flag=value` form. Throws an Error naming the first problem.
|
|
11
|
+
*/
|
|
12
|
+
export function parseStorybookBrowserRunnerArgs(argv) {
|
|
13
|
+
const { positionals, values } = parseArgs({
|
|
14
|
+
allowPositionals: true,
|
|
15
|
+
args: [...argv],
|
|
16
|
+
options: {
|
|
17
|
+
command: { type: 'string' },
|
|
18
|
+
'completion-file': { type: 'string' },
|
|
19
|
+
'coverage-arg': { type: 'string', multiple: true },
|
|
20
|
+
'env-prefix': { type: 'string' },
|
|
21
|
+
'optimize-deps-config': { type: 'string' },
|
|
22
|
+
'progress-prefix': { type: 'string' },
|
|
23
|
+
project: { type: 'string' },
|
|
24
|
+
'result-file': { type: 'string', multiple: true },
|
|
25
|
+
},
|
|
26
|
+
strict: true,
|
|
27
|
+
});
|
|
28
|
+
if (values.project === undefined)
|
|
29
|
+
throw new Error('--project <name> is required');
|
|
30
|
+
const optional = (flag) => {
|
|
31
|
+
const raw = values[flag];
|
|
32
|
+
return raw === undefined ? undefined : required(raw, `--${flag}`);
|
|
33
|
+
};
|
|
34
|
+
const project = { projectName: required(values.project, '--project') };
|
|
35
|
+
const assign = (key, value) => {
|
|
36
|
+
if (value !== undefined)
|
|
37
|
+
project[key] = value;
|
|
38
|
+
};
|
|
39
|
+
assign('command', optional('command'));
|
|
40
|
+
assign('completionFile', optional('completion-file'));
|
|
41
|
+
assign('envPrefix', optional('env-prefix'));
|
|
42
|
+
assign('optimizeDepsConfigPath', optional('optimize-deps-config'));
|
|
43
|
+
assign('progressPrefix', optional('progress-prefix'));
|
|
44
|
+
if (values['coverage-arg'])
|
|
45
|
+
project.coverageArgs = values['coverage-arg'];
|
|
46
|
+
if (values['result-file']) {
|
|
47
|
+
project.resultFiles = values['result-file'].map((file) => required(file, '--result-file'));
|
|
48
|
+
}
|
|
49
|
+
if (positionals.length > 0)
|
|
50
|
+
project.args = positionals;
|
|
51
|
+
return project;
|
|
52
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { BrowserSessionResult } from '../browser-session-runner/index.mts';
|
|
2
|
+
import type { StorybookBrowserBootstrapSnapshot } from './bootstrap-telemetry.mts';
|
|
3
|
+
import type { OutputObserverSnapshot } from './observer-state.mts';
|
|
4
|
+
import type { WatchdogOutcome } from './watchdog.mts';
|
|
5
|
+
export type AttemptResult = {
|
|
6
|
+
bootstrap: StorybookBrowserBootstrapSnapshot;
|
|
7
|
+
budgetExpired: boolean;
|
|
8
|
+
code: number;
|
|
9
|
+
durationMs: number;
|
|
10
|
+
exitCode: number | null;
|
|
11
|
+
firstTestOutputAtMs: number | null;
|
|
12
|
+
hung: boolean;
|
|
13
|
+
isStall: boolean;
|
|
14
|
+
lastOutputAgeMs: number;
|
|
15
|
+
newOptimizeDeps: string[];
|
|
16
|
+
optimizerReadyAtMs: number | null;
|
|
17
|
+
optimizerReloadFromNewDeps: boolean;
|
|
18
|
+
resultFileDetectedAtMs: number | null;
|
|
19
|
+
retryable: boolean;
|
|
20
|
+
runnerMissing: boolean;
|
|
21
|
+
semanticProgress: boolean;
|
|
22
|
+
semanticStall: boolean;
|
|
23
|
+
signal: NodeJS.Signals | null;
|
|
24
|
+
viteFetchFailure: boolean;
|
|
25
|
+
viteReady: boolean;
|
|
26
|
+
};
|
|
27
|
+
export type AttemptFacts = {
|
|
28
|
+
bootstrap: StorybookBrowserBootstrapSnapshot;
|
|
29
|
+
finishedAt: number;
|
|
30
|
+
observed: OutputObserverSnapshot;
|
|
31
|
+
outcome: WatchdogOutcome;
|
|
32
|
+
spawnFailed: boolean;
|
|
33
|
+
startedAt: number;
|
|
34
|
+
};
|
|
35
|
+
/** Maps the session exit plus the observed output to the attempt result and its retry rule. */
|
|
36
|
+
export declare function buildAttemptResult(session: Pick<BrowserSessionResult, 'exit' | 'reason'>, facts: AttemptFacts): AttemptResult;
|
|
37
|
+
/** The command could not be started: failed, never retryable. */
|
|
38
|
+
export declare function failedSpawnAttempt(bootstrap: StorybookBrowserBootstrapSnapshot, startedAt: number, lastOutputAt: number, now: number): AttemptResult;
|
|
39
|
+
/** The session budget ran out before the session produced a result. */
|
|
40
|
+
export declare function expiredAttempt(bootstrap: StorybookBrowserBootstrapSnapshot, startedAt: number, now: number): AttemptResult;
|
|
41
|
+
export declare function formatAttemptResult(attempt: number, result: AttemptResult): string;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
const relativeTo = (startedAt, at) => (at == null ? null : at - startedAt);
|
|
2
|
+
/** Maps the session exit plus the observed output to the attempt result and its retry rule. */
|
|
3
|
+
export function buildAttemptResult(session, facts) {
|
|
4
|
+
const { bootstrap, finishedAt, observed, outcome, spawnFailed, startedAt } = facts;
|
|
5
|
+
const optimizerReloadFromNewDeps = observed.sawNewOptimizeDeps && observed.sawOptimizerReload;
|
|
6
|
+
const runnerMissing = observed.sawAddonVitestSetupFile &&
|
|
7
|
+
observed.sawRunnerMissingMessage &&
|
|
8
|
+
!observed.storybookBrowserOutputSeen;
|
|
9
|
+
const connectionTimeout = observed.browserSessionConnectionTimedOut && !observed.semanticProgressSeen;
|
|
10
|
+
const budgetExpired = session.reason === 'deadline';
|
|
11
|
+
const killedByWatchdog = outcome.stalled ||
|
|
12
|
+
outcome.hung ||
|
|
13
|
+
outcome.semanticStall ||
|
|
14
|
+
budgetExpired ||
|
|
15
|
+
session.reason === 'parent-signal';
|
|
16
|
+
return {
|
|
17
|
+
bootstrap,
|
|
18
|
+
budgetExpired,
|
|
19
|
+
code: spawnFailed || killedByWatchdog ? 1 : (session.exit.code ?? 1),
|
|
20
|
+
durationMs: finishedAt - startedAt,
|
|
21
|
+
exitCode: spawnFailed ? 1 : session.exit.code,
|
|
22
|
+
firstTestOutputAtMs: relativeTo(startedAt, observed.firstTestOutputAt),
|
|
23
|
+
hung: outcome.hung || connectionTimeout,
|
|
24
|
+
isStall: outcome.stalled,
|
|
25
|
+
lastOutputAgeMs: finishedAt - observed.lastOutputAt,
|
|
26
|
+
newOptimizeDeps: observed.newOptimizeDeps,
|
|
27
|
+
optimizerReadyAtMs: relativeTo(startedAt, observed.optimizerReadyAt),
|
|
28
|
+
optimizerReloadFromNewDeps,
|
|
29
|
+
resultFileDetectedAtMs: relativeTo(startedAt, outcome.resultFileDetectedAt),
|
|
30
|
+
retryable: !spawnFailed &&
|
|
31
|
+
!budgetExpired &&
|
|
32
|
+
session.reason !== 'parent-signal' &&
|
|
33
|
+
!outcome.semanticStall &&
|
|
34
|
+
!optimizerReloadFromNewDeps &&
|
|
35
|
+
(observed.retryableViteFailure ||
|
|
36
|
+
runnerMissing ||
|
|
37
|
+
(!observed.semanticProgressSeen && (outcome.stalled || outcome.hung || connectionTimeout))),
|
|
38
|
+
runnerMissing,
|
|
39
|
+
semanticProgress: observed.semanticProgressSeen,
|
|
40
|
+
semanticStall: outcome.semanticStall,
|
|
41
|
+
signal: session.exit.signal,
|
|
42
|
+
viteFetchFailure: observed.retryableViteFailure,
|
|
43
|
+
viteReady: observed.startupComplete,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const baseResult = (bootstrap) => ({
|
|
47
|
+
bootstrap,
|
|
48
|
+
budgetExpired: false,
|
|
49
|
+
code: 1,
|
|
50
|
+
durationMs: 0,
|
|
51
|
+
exitCode: null,
|
|
52
|
+
firstTestOutputAtMs: null,
|
|
53
|
+
hung: false,
|
|
54
|
+
isStall: false,
|
|
55
|
+
lastOutputAgeMs: 0,
|
|
56
|
+
newOptimizeDeps: [],
|
|
57
|
+
optimizerReadyAtMs: null,
|
|
58
|
+
optimizerReloadFromNewDeps: false,
|
|
59
|
+
resultFileDetectedAtMs: null,
|
|
60
|
+
retryable: false,
|
|
61
|
+
runnerMissing: false,
|
|
62
|
+
semanticProgress: false,
|
|
63
|
+
semanticStall: false,
|
|
64
|
+
signal: null,
|
|
65
|
+
viteFetchFailure: false,
|
|
66
|
+
viteReady: false,
|
|
67
|
+
});
|
|
68
|
+
/** The command could not be started: failed, never retryable. */
|
|
69
|
+
export function failedSpawnAttempt(bootstrap, startedAt, lastOutputAt, now) {
|
|
70
|
+
return {
|
|
71
|
+
...baseResult(bootstrap),
|
|
72
|
+
durationMs: now - startedAt,
|
|
73
|
+
exitCode: 1,
|
|
74
|
+
lastOutputAgeMs: now - lastOutputAt,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/** The session budget ran out before the session produced a result. */
|
|
78
|
+
export function expiredAttempt(bootstrap, startedAt, now) {
|
|
79
|
+
return { ...baseResult(bootstrap), budgetExpired: true, durationMs: now - startedAt };
|
|
80
|
+
}
|
|
81
|
+
export function formatAttemptResult(attempt, result) {
|
|
82
|
+
return `${[
|
|
83
|
+
`[storybook-browser] attempt=${attempt} finished in ${result.durationMs}ms`,
|
|
84
|
+
`code=${result.exitCode ?? 'null'}`,
|
|
85
|
+
`signal=${result.signal ?? 'null'}`,
|
|
86
|
+
`resolvedCode=${result.code}`,
|
|
87
|
+
`retryable=${String(result.retryable)}`,
|
|
88
|
+
`stall=${String(result.isStall)}`,
|
|
89
|
+
`hang=${String(result.hung)}`,
|
|
90
|
+
`runnerMissing=${String(result.runnerMissing)}`,
|
|
91
|
+
`budgetExpired=${String(result.budgetExpired)}`,
|
|
92
|
+
`semanticProgress=${String(result.semanticProgress)}`,
|
|
93
|
+
`semanticStall=${String(result.semanticStall)}`,
|
|
94
|
+
`viteReady=${String(result.viteReady)}`,
|
|
95
|
+
`optimizerReadyAtMs=${result.optimizerReadyAtMs ?? 'none'}`,
|
|
96
|
+
`firstTestOutputAtMs=${result.firstTestOutputAtMs ?? 'none'}`,
|
|
97
|
+
`lastOutputAgeMs=${result.lastOutputAgeMs}`,
|
|
98
|
+
`resultFileAtMs=${result.resultFileDetectedAtMs ?? 'none'}`,
|
|
99
|
+
`bootstrapStage=${result.bootstrap.terminalStage}`,
|
|
100
|
+
`bootstrapTimeline=${JSON.stringify(result.bootstrap.timeline)}`,
|
|
101
|
+
`orchestratorDisconnectCount=${result.bootstrap.orchestratorDisconnectCount}`,
|
|
102
|
+
`requestFailureCount=${result.bootstrap.requestFailureCount}`,
|
|
103
|
+
`requestFailureSamples=${JSON.stringify(result.bootstrap.requestFailureSamples)}`,
|
|
104
|
+
`viteFetchFailure=${String(result.viteFetchFailure)}`,
|
|
105
|
+
`optimizerReloadFromNewDeps=${String(result.optimizerReloadFromNewDeps)}`,
|
|
106
|
+
`newOptimizeDeps=${result.newOptimizeDeps.join(',') || 'none'}`,
|
|
107
|
+
].join('; ')}\n`;
|
|
108
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
type OutputStream = 'stderr' | 'stdout';
|
|
2
|
+
export type StorybookBrowserBootstrapMilestone = 'context-ready' | 'navigation-requested' | 'orchestrator-connected' | 'page-ready' | 'provider-started' | 'semantic-progress';
|
|
3
|
+
type StorybookBrowserBootstrapTerminalStage = 'context-to-page' | 'handshake-after-websocket' | 'launch-or-context' | 'navigation-to-websocket' | 'no-provider-evidence' | 'page-to-navigation' | 'semantic-progress';
|
|
4
|
+
export interface StorybookBrowserBootstrapSnapshot {
|
|
5
|
+
orchestratorDisconnectCount: number;
|
|
6
|
+
requestFailureCount: number;
|
|
7
|
+
requestFailureSamples: string[];
|
|
8
|
+
terminalStage: StorybookBrowserBootstrapTerminalStage;
|
|
9
|
+
timeline: Array<{
|
|
10
|
+
atMs: number;
|
|
11
|
+
milestone: StorybookBrowserBootstrapMilestone;
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
14
|
+
interface ConsumedOutput {
|
|
15
|
+
hasNonDiagnosticOutput: boolean;
|
|
16
|
+
output: string;
|
|
17
|
+
}
|
|
18
|
+
export declare class StorybookBrowserBootstrapTelemetry {
|
|
19
|
+
private readonly lineBuffers;
|
|
20
|
+
private readonly milestones;
|
|
21
|
+
private readonly requestFailureSamples;
|
|
22
|
+
private readonly timeline;
|
|
23
|
+
private playwrightBrowserLineCount;
|
|
24
|
+
private orchestratorDisconnectCount;
|
|
25
|
+
private requestFailureCount;
|
|
26
|
+
consume(stream: OutputStream, chunk: string | Buffer, atMs: number): ConsumedOutput;
|
|
27
|
+
flush(stream: OutputStream, atMs: number): ConsumedOutput;
|
|
28
|
+
recordSemanticProgress(atMs: number): void;
|
|
29
|
+
snapshot(): StorybookBrowserBootstrapSnapshot;
|
|
30
|
+
private consumeLines;
|
|
31
|
+
private observeLine;
|
|
32
|
+
private filterLine;
|
|
33
|
+
private recordMilestone;
|
|
34
|
+
}
|
|
35
|
+
export {};
|