Repository navigation
Conversation
…t a build doctor finds each Storybook project in the repository and checks its config file, package.json script, git history, project token and CI jobs, the way a build would read them. Each problem says why it matters, and --fix applies the fixes that are certain: plain JSON config edits, the build script, .gitignore and CI checkout depth when a CI job is confirmed. It exits 1 when a check fails and 0 on warnings. Amp-Thread-ID: https://ampcode.com/threads/T-01a1d7b7-69d0-75bd-a184-7440f6a67cef
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
|
| */ | ||
| export function readJson(filePath: string): Record<string, any> | undefined { | ||
| try { | ||
| return JSON.parse(readFileSync(filePath, 'utf8')); |
There was a problem hiding this comment.
Potential file inclusion attack via reading file - high severity
If an attacker can control the input leading into the ReadFile function, they might be able to read sensitive files and launch further attacks with that information.
Show fix
Remediation: Ignore this issue only after you've verified or sanitized the input going into this function. This issue is only relevant in the backend, not in the frontend!
Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info
There was a problem hiding this comment.
These paths come from the user's own project or command line, and the CLI runs with the user's permissions, so it can only read files the user can already read. Nothing to fix here.
| * @returns The edit for a fix. | ||
| */ | ||
| export function packageJsonEdit(file: string, change: (json: Record<string, any>) => void) { | ||
| const previous = readFileSync(file, 'utf8'); |
There was a problem hiding this comment.
Potential file inclusion attack via reading file - high severity
If an attacker can control the input leading into the ReadFile function, they might be able to read sensitive files and launch further attacks with that information.
Show fix
Remediation: Ignore this issue only after you've verified or sanitized the input going into this function. This issue is only relevant in the backend, not in the frontend!
Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info
There was a problem hiding this comment.
These paths come from the user's own project or command line, and the CLI runs with the user's permissions, so it can only read files the user can already read. Nothing to fix here.
| const runs = detectCi(files).flatMap(({ provider, files: found }) => | ||
| found.flatMap((file) => { | ||
| try { | ||
| const raw = readFileSync(path.join(gitRoot, file), 'utf8'); |
There was a problem hiding this comment.
Potential file inclusion attack via reading file - medium severity
If an attacker can control the input leading into the ReadFile function, they might be able to read sensitive files and launch further attacks with that information.
Show fix
Remediation: Ignore this issue only after you've verified or sanitized the input going into this function. This issue is only relevant in the backend, not in the frontend!
Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info
There was a problem hiding this comment.
These paths come from the user's own project or command line, and the CLI runs with the user's permissions, so it can only read files the user can already read. Nothing to fix here.
|
|
||
| function storybookProject(gitRoot: string, relative: string, file: string): Project { | ||
| const directory = path.join(gitRoot, relative); | ||
| const main = readFileSync(path.join(gitRoot, file), 'utf8'); |
There was a problem hiding this comment.
Potential file inclusion attack via reading file - medium severity
If an attacker can control the input leading into the ReadFile function, they might be able to read sensitive files and launch further attacks with that information.
Show fix
Remediation: Ignore this issue only after you've verified or sanitized the input going into this function. This issue is only relevant in the backend, not in the frontend!
Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info
There was a problem hiding this comment.
These paths come from the user's own project or command line, and the CLI runs with the user's permissions, so it can only read files the user can already read. Nothing to fix here.
| } | ||
| if (!configuration.configFile) return { configuration, configEditable: true }; | ||
| const configFile = path.resolve(cwd, configuration.configFile); | ||
| const configText = readFileSync(configFile, 'utf8'); |
There was a problem hiding this comment.
Potential file inclusion attack via reading file - medium severity
If an attacker can control the input leading into the ReadFile function, they might be able to read sensitive files and launch further attacks with that information.
Show fix
Remediation: Ignore this issue only after you've verified or sanitized the input going into this function. This issue is only relevant in the backend, not in the frontend!
Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info
There was a problem hiding this comment.
These paths come from the user's own project or command line, and the CLI runs with the user's permissions, so it can only read files the user can already read. Nothing to fix here.
| ); | ||
| change(json); | ||
| const file = input.configFile ?? path.join(input.cwd, 'chromatic.config.json'); | ||
| const previous = existsSync(file) ? readFileSync(file, 'utf8') : undefined; |
There was a problem hiding this comment.
Potential file inclusion attack via reading file - medium severity
If an attacker can control the input leading into the ReadFile function, they might be able to read sensitive files and launch further attacks with that information.
Show fix
Remediation: Ignore this issue only after you've verified or sanitized the input going into this function. This issue is only relevant in the backend, not in the frontend!
Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info
There was a problem hiding this comment.
These paths come from the user's own project or command line, and the CLI runs with the user's permissions, so it can only read files the user can already read. Nothing to fix here.
| const { fix } = next; | ||
| const preview = fix.edits | ||
| .map(({ file, content }) => { | ||
| const before = existsSync(file) ? readFileSync(file, 'utf8') : ''; |
There was a problem hiding this comment.
Potential file inclusion attack via reading file - medium severity
If an attacker can control the input leading into the ReadFile function, they might be able to read sensitive files and launch further attacks with that information.
Show fix
Remediation: Ignore this issue only after you've verified or sanitized the input going into this function. This issue is only relevant in the backend, not in the frontend!
Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info
There was a problem hiding this comment.
These paths come from the user's own project or command line, and the CLI runs with the user's permissions, so it can only read files the user can already read. Nothing to fix here.
| reason: `git tracks ${relativeOrDot(gitRoot, file)}, so the token would be committed`, | ||
| }; | ||
| } | ||
| const text = existsSync(file) ? readFileSync(file, 'utf8') : ''; |
There was a problem hiding this comment.
Potential file inclusion attack via reading file - medium severity
If an attacker can control the input leading into the ReadFile function, they might be able to read sensitive files and launch further attacks with that information.
Show fix
Remediation: Ignore this issue only after you've verified or sanitized the input going into this function. This issue is only relevant in the backend, not in the frontend!
Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info
There was a problem hiding this comment.
These paths come from the user's own project or command line, and the CLI runs with the user's permissions, so it can only read files the user can already read. Nothing to fix here.
|
📦 Package Size: 8168 KB Bundled dependencies compared with PR base 82312b5. Bundled dependency changesVersions from emitted source maps; external dependencies are not included. CLI / Node API
GitHub Action
|
CI files can't say reliably which project a job builds: monorepos pick the package through pnpm, Turbo, Nx or Yarn workspaces, a script, a composite action, or a matrix value, so doctor missed most real setups and read the rest as the wrong project. doctor now reads only the project's own files. The three fixes that are only right for some CI setups (moving the token out of the config, rewriting storybookConfigDir or removing storybookBaseDir, and turning on onlyChanged) ask how CI runs Chromatic instead, and --yes skips them. Project detection now streams git's file list and keeps only the files that can make a project, so a large repository needs no output buffer and no scan per package.json. Amp-Thread-ID: https://ampcode.com/threads/T-01a1d7b7-69d0-75bd-a184-7440f6a67cef
Adds
chromatic doctor, which checks a project's Chromatic setup without starting a build and fixes what it can be sure of. It's modeled onstorybook doctorandstorybook automigrate. This is the bottom of a stack: the rebuiltchromatic initsits on top of it and ends by running these checks.🎬 Demo
chromatic doctor, thenchromatic doctor --fixinpackages/uiof an npm monorepo with a misconfiguredchromatic.config.json(valid JSON, wrong values).The GIF was recorded on an earlier commit that still read CI files, so it shows CI checks and fixes that no longer exist. The run today is in the verification table.
📋 What changed
bin-src/doctor.tsdoctorsubcommand: checks the setup without starting a build;--fixapplies fixes one at a time after showing a diffbin-src/setup/checks.ts,valueChecks.tsbin-src/setup/doctorInput.tsgetPartialOptions, config file and the project's.env, and which file owns each optionbin-src/setup/report.tsbin-src/setup/detect.ts,fixes.ts,shared.tsnode-src/lib/getOptions.ts,getStorybookMetadata.tsfindBuildScriptNameandfindConfigFlagssodoctorfinds the build script and-cfolder the same way a build doesbin-src/register.jsdoctor💡 Why
🛠️ How it works
--build-command,--vitest,--project-token,--config-file, …), config file, environment and the project's.envthrough the main command's own option handling. The Storybook config directory comes from the build'sfindConfigDirectory, and--storybook-build-dirgoes through the samevalidateFilesas an upload.doctornever reads or edits CI files.chromatic, grouped by project, and lists the rest as not set up."onlyChanged": "true"(a string, read as a branch name)true"onlyChanged": true, creating the config file if needed, after asking: "Does CI let Chromatic build Storybook, rather than pass --storybook-build-dir?" Not offered when the config or a script uploads a prebuilt Storybook, which may have no stats fileonlyChangedon Playwright or CypressstorybookConfigDirwritten from the repo root,storybookBaseDirthat repeats the directory Chromatic runs fromstorybookBaseDir, after asking: "Does CI run Chromatic from packages/ui?" A CI that runs from the root with--config-filereads the paths as writtenuntraced/externalsglobs that match nothingprojectTokenin the config file.envthat git confirms is ignored, including any nested.gitignore, after asking: "Does CI already pass the token as CHROMATIC_PROJECT_TOKEN?"build-storybookscriptbuildScriptNameat a script that runsstorybook build, or add"build-storybook": "storybook build"chromaticnot a dependencydevDependencies"playwright": true(or Cypress, Vitest) when the folder has exactly one of those config files; with two, a failure that names both and no fix--yes:--yesapplies every fix except those with a question, and names each one it skipped with the question to answer in a terminal.storybookBuildDirfolder that hasn't been built yet (CI may build it first). A folder that exists but isn't a Storybook build fails, still with no fix.--fixapplies nothing and says to rerun with--fix --yes.git ls-files -zand keeps onlypackage.json, Storybook main configs and E2E configs, so there's no output buffer to overflow and no scan per package. Glob counts foruntracedandexternalsare taken in the same kind of single streamed pass.⚖️ Trade-offs & decisions
pnpm --filter,turbo run --filter,nx run,yarn workspace,npm run --workspace, root scripts, shell scripts, composite actions, matrices and reusable workflows, because the package is chosen by name or at runtime, not written as a path. Getting those right would mean reimplementing each workspace tool and GitHub's expressions, sodoctordoesn't try.--yesor in CI they stay warnings with instructions, so nothing gets applied that could break a pipelinedoctorcan't see.--only-changed,doctorsays "TurboSnap isn't on here", and the detail says it's on in CI if CI passes the flag.storybookBaseDirorstorybookConfigDir. Making a config file in another directory act as the project root is deferred, because it would break setups that already compensate with root-relative paths.🧪 Verification
doctoron a monorepo with a misconfigured configCI=1 node dist/bin.cjs doctorinpackages/ui--fix --yesskips the questionsCI=1 node dist/bin.cjs doctor --fix --yeson the same projectonlyChangedstring, both globs); skips thestorybookConfigDir,storybookBaseDirand token fixes, each with its question; ends at 7 passed, 3 warnings, 1 failed, exit 1. The token stays in the configdoctor --fixin a real terminal (tmux), Enter at each prompt.env, ends at 8 passed, 1 warningdoctorinpackages/uiof a repo with 300,000 tracked files and 1,505package.jsonfiles--yesapplyFixes, reranreport.test.tsdoctorresolves paths like a build--build-commandwith no build script;--build-commandwith-c missingin the build script;--storybook-build-dirmissing, then a prebuilt folder with no.storybook; an emptystorybookConfigDir;--project packages/ui --config-file configs/selected.json.storybookas the build does; fails, then passes; fails; readsselected.json-cdoctorwithstorybook build -c storybook-configmain.tsdeleted from diskdoctorfrom the rootdoctor --vitestnext toplaywright.config.ts;doctor --fix --yesin a Playwright app with no configonlyChangedkept; fails like a build, then sets"playwright": truedoctor --fixwith{ "projectToken" : "…" }; with.envthen!.envin.gitignore; with!.envinpackages/ui/.gitignore.env.envbugstokenEnvironmentEdits, put back: the tracked, root and nested negation checks, dropping the first ignore check, a duplicated token line, no ignore rule after./.env, a second# Chromaticsection👀 Reviewer notes
bin-src/setup/doctorInput.ts, which decides whatdoctorbelieves, thenvalueChecks.tsfor the fixes that ask a question..envtoken helper and the fix loop's question have tests; the doctor checks anddoctorInputdon't yet. Several functions still turn off thecomplexitylint rule, mostly the check lists andmain.📦 Published PR as canary version:
18.15.2--canary.1729.44930361334.0✨ Test out this PR locally via:
npm install chromatic@18.15.2--canary.1729.44930361334.0 # or yarn add chromatic@18.15.2--canary.1729.44930361334.0