@visual-check/cli 0.0.0 → 0.1.1
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/LICENSE +21 -0
- package/dist/addon-build.d.ts +3 -0
- package/dist/addon-build.d.ts.map +1 -0
- package/dist/addon-build.js +4 -0
- package/dist/addon-build.js.map +1 -0
- package/dist/addon-child/addon-child.d.ts +63 -0
- package/dist/addon-child/addon-child.d.ts.map +1 -0
- package/dist/addon-child/addon-child.js +85 -0
- package/dist/addon-child/addon-child.js.map +1 -0
- package/dist/addon-child/image-files.d.ts +11 -0
- package/dist/addon-child/image-files.d.ts.map +1 -0
- package/dist/addon-child/image-files.js +138 -0
- package/dist/addon-child/image-files.js.map +1 -0
- package/dist/addon-child/protocol.d.ts +181 -0
- package/dist/addon-child/protocol.d.ts.map +1 -0
- package/dist/addon-child/protocol.js +2 -0
- package/dist/addon-child/protocol.js.map +1 -0
- package/dist/addon-child/read-request.d.ts +7 -0
- package/dist/addon-child/read-request.d.ts.map +1 -0
- package/dist/addon-child/read-request.js +25 -0
- package/dist/addon-child/read-request.js.map +1 -0
- package/dist/addon-child.d.ts +2 -0
- package/dist/addon-child.d.ts.map +1 -0
- package/dist/addon-child.js +61 -0
- package/dist/addon-child.js.map +1 -0
- package/dist/affected-stories/affected-stories.d.ts +128 -0
- package/dist/affected-stories/affected-stories.d.ts.map +1 -0
- package/dist/affected-stories/affected-stories.js +168 -0
- package/dist/affected-stories/affected-stories.js.map +1 -0
- package/dist/affected-stories/changed-file-rules.d.ts +98 -0
- package/dist/affected-stories/changed-file-rules.d.ts.map +1 -0
- package/dist/affected-stories/changed-file-rules.js +167 -0
- package/dist/affected-stories/changed-file-rules.js.map +1 -0
- package/dist/affected-stories/fallow-graph.d.ts +67 -0
- package/dist/affected-stories/fallow-graph.d.ts.map +1 -0
- package/dist/affected-stories/fallow-graph.js +180 -0
- package/dist/affected-stories/fallow-graph.js.map +1 -0
- package/dist/affected-stories/git-changes.d.ts +57 -0
- package/dist/affected-stories/git-changes.d.ts.map +1 -0
- package/dist/affected-stories/git-changes.js +203 -0
- package/dist/affected-stories/git-changes.js.map +1 -0
- package/dist/affected-stories/group-changes.d.ts +48 -0
- package/dist/affected-stories/group-changes.d.ts.map +1 -0
- package/dist/affected-stories/group-changes.js +41 -0
- package/dist/affected-stories/group-changes.js.map +1 -0
- package/dist/affected-stories/import-graph.d.ts +33 -0
- package/dist/affected-stories/import-graph.d.ts.map +1 -0
- package/dist/affected-stories/import-graph.js +99 -0
- package/dist/affected-stories/import-graph.js.map +1 -0
- package/dist/affected-stories/limited-map.d.ts +9 -0
- package/dist/affected-stories/limited-map.d.ts.map +1 -0
- package/dist/affected-stories/limited-map.js +24 -0
- package/dist/affected-stories/limited-map.js.map +1 -0
- package/dist/affected-stories/package-folder.d.ts +8 -0
- package/dist/affected-stories/package-folder.d.ts.map +1 -0
- package/dist/affected-stories/package-folder.js +45 -0
- package/dist/affected-stories/package-folder.js.map +1 -0
- package/dist/affected-stories/storybook-rules.d.ts +153 -0
- package/dist/affected-stories/storybook-rules.d.ts.map +1 -0
- package/dist/affected-stories/storybook-rules.js +161 -0
- package/dist/affected-stories/storybook-rules.js.map +1 -0
- package/dist/affected-stories/walk-back.d.ts +16 -0
- package/dist/affected-stories/walk-back.d.ts.map +1 -0
- package/dist/affected-stories/walk-back.js +46 -0
- package/dist/affected-stories/walk-back.js.map +1 -0
- package/dist/agent-skill/install-skill.d.ts +34 -0
- package/dist/agent-skill/install-skill.d.ts.map +1 -0
- package/dist/agent-skill/install-skill.js +43 -0
- package/dist/agent-skill/install-skill.js.map +1 -0
- package/dist/agent-skill/refresh-skill.d.ts +62 -0
- package/dist/agent-skill/refresh-skill.d.ts.map +1 -0
- package/dist/agent-skill/refresh-skill.js +105 -0
- package/dist/agent-skill/refresh-skill.js.map +1 -0
- package/dist/agent-skill/setup-file.d.ts +41 -0
- package/dist/agent-skill/setup-file.d.ts.map +1 -0
- package/dist/agent-skill/setup-file.js +38 -0
- package/dist/agent-skill/setup-file.js.map +1 -0
- package/dist/agent-skill/skill-files.d.ts +19 -0
- package/dist/agent-skill/skill-files.d.ts.map +1 -0
- package/dist/agent-skill/skill-files.js +29 -0
- package/dist/agent-skill/skill-files.js.map +1 -0
- package/dist/agent-skill/skill-markdown.d.ts +31 -0
- package/dist/agent-skill/skill-markdown.d.ts.map +1 -0
- package/dist/agent-skill/skill-markdown.js +54 -0
- package/dist/agent-skill/skill-markdown.js.map +1 -0
- package/dist/baselines/baseline-clash.d.ts +31 -0
- package/dist/baselines/baseline-clash.d.ts.map +1 -0
- package/dist/baselines/baseline-clash.js +23 -0
- package/dist/baselines/baseline-clash.js.map +1 -0
- package/dist/baselines/baseline-error.d.ts +39 -0
- package/dist/baselines/baseline-error.d.ts.map +1 -0
- package/dist/baselines/baseline-error.js +42 -0
- package/dist/baselines/baseline-error.js.map +1 -0
- package/dist/baselines/baseline-files.d.ts +130 -0
- package/dist/baselines/baseline-files.d.ts.map +1 -0
- package/dist/baselines/baseline-files.js +292 -0
- package/dist/baselines/baseline-files.js.map +1 -0
- package/dist/baselines/baseline-set.d.ts +42 -0
- package/dist/baselines/baseline-set.d.ts.map +1 -0
- package/dist/baselines/baseline-set.js +104 -0
- package/dist/baselines/baseline-set.js.map +1 -0
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +57 -0
- package/dist/bin.js.map +1 -0
- package/dist/browser/browser-package.d.ts +54 -0
- package/dist/browser/browser-package.d.ts.map +1 -0
- package/dist/browser/browser-package.js +105 -0
- package/dist/browser/browser-package.js.map +1 -0
- package/dist/browser/browser-version.d.ts +67 -0
- package/dist/browser/browser-version.d.ts.map +1 -0
- package/dist/browser/browser-version.js +61 -0
- package/dist/browser/browser-version.js.map +1 -0
- package/dist/browser/chrome-for-testing-platform.d.ts +24 -0
- package/dist/browser/chrome-for-testing-platform.d.ts.map +1 -0
- package/dist/browser/chrome-for-testing-platform.js +39 -0
- package/dist/browser/chrome-for-testing-platform.js.map +1 -0
- package/dist/browser/image-marker.d.ts +46 -0
- package/dist/browser/image-marker.d.ts.map +1 -0
- package/dist/browser/image-marker.js +81 -0
- package/dist/browser/image-marker.js.map +1 -0
- package/dist/browser/read-browser-package.d.ts +58 -0
- package/dist/browser/read-browser-package.d.ts.map +1 -0
- package/dist/browser/read-browser-package.js +130 -0
- package/dist/browser/read-browser-package.js.map +1 -0
- package/dist/browser-download/browser-download-error.d.ts +19 -0
- package/dist/browser-download/browser-download-error.d.ts.map +1 -0
- package/dist/browser-download/browser-download-error.js +21 -0
- package/dist/browser-download/browser-download-error.js.map +1 -0
- package/dist/browser-download/cache-folder.d.ts +7 -0
- package/dist/browser-download/cache-folder.d.ts.map +1 -0
- package/dist/browser-download/cache-folder.js +34 -0
- package/dist/browser-download/cache-folder.js.map +1 -0
- package/dist/browser-download/download-file.d.ts +45 -0
- package/dist/browser-download/download-file.d.ts.map +1 -0
- package/dist/browser-download/download-file.js +340 -0
- package/dist/browser-download/download-file.js.map +1 -0
- package/dist/browser-download/install-headless-shell.d.ts +96 -0
- package/dist/browser-download/install-headless-shell.d.ts.map +1 -0
- package/dist/browser-download/install-headless-shell.js +491 -0
- package/dist/browser-download/install-headless-shell.js.map +1 -0
- package/dist/browser-download/proxy.d.ts +19 -0
- package/dist/browser-download/proxy.d.ts.map +1 -0
- package/dist/browser-download/proxy.js +102 -0
- package/dist/browser-download/proxy.js.map +1 -0
- package/dist/browser-download/unzip.d.ts +11 -0
- package/dist/browser-download/unzip.d.ts.map +1 -0
- package/dist/browser-download/unzip.js +96 -0
- package/dist/browser-download/unzip.js.map +1 -0
- package/dist/browser-process/start-browser-process.d.ts +30 -0
- package/dist/browser-process/start-browser-process.d.ts.map +1 -0
- package/dist/browser-process/start-browser-process.js +131 -0
- package/dist/browser-process/start-browser-process.js.map +1 -0
- package/dist/capture/capture-session.d.ts +479 -0
- package/dist/capture/capture-session.d.ts.map +1 -0
- package/dist/capture/capture-session.js +723 -0
- package/dist/capture/capture-session.js.map +1 -0
- package/dist/capture/driver/cdp/cdp-connection.d.ts +127 -0
- package/dist/capture/driver/cdp/cdp-connection.d.ts.map +1 -0
- package/dist/capture/driver/cdp/cdp-connection.js +243 -0
- package/dist/capture/driver/cdp/cdp-connection.js.map +1 -0
- package/dist/capture/driver/cdp/cdp-driver.d.ts +42 -0
- package/dist/capture/driver/cdp/cdp-driver.d.ts.map +1 -0
- package/dist/capture/driver/cdp/cdp-driver.js +270 -0
- package/dist/capture/driver/cdp/cdp-driver.js.map +1 -0
- package/dist/capture/driver/cdp/cdp-page.d.ts +10 -0
- package/dist/capture/driver/cdp/cdp-page.d.ts.map +1 -0
- package/dist/capture/driver/cdp/cdp-page.js +765 -0
- package/dist/capture/driver/cdp/cdp-page.js.map +1 -0
- package/dist/capture/driver/cdp/last-lines.d.ts +13 -0
- package/dist/capture/driver/cdp/last-lines.d.ts.map +1 -0
- package/dist/capture/driver/cdp/last-lines.js +49 -0
- package/dist/capture/driver/cdp/last-lines.js.map +1 -0
- package/dist/capture/driver/cdp/launch-arguments.d.ts +16 -0
- package/dist/capture/driver/cdp/launch-arguments.d.ts.map +1 -0
- package/dist/capture/driver/cdp/launch-arguments.js +142 -0
- package/dist/capture/driver/cdp/launch-arguments.js.map +1 -0
- package/dist/capture/driver/cdp/loaded-document.d.ts +61 -0
- package/dist/capture/driver/cdp/loaded-document.d.ts.map +1 -0
- package/dist/capture/driver/cdp/loaded-document.js +104 -0
- package/dist/capture/driver/cdp/loaded-document.js.map +1 -0
- package/dist/capture/driver/cdp/main-frame-navigation.d.ts +127 -0
- package/dist/capture/driver/cdp/main-frame-navigation.d.ts.map +1 -0
- package/dist/capture/driver/cdp/main-frame-navigation.js +214 -0
- package/dist/capture/driver/cdp/main-frame-navigation.js.map +1 -0
- package/dist/capture/driver/cdp/request-watch.d.ts +117 -0
- package/dist/capture/driver/cdp/request-watch.d.ts.map +1 -0
- package/dist/capture/driver/cdp/request-watch.js +244 -0
- package/dist/capture/driver/cdp/request-watch.js.map +1 -0
- package/dist/capture/driver/cdp/time-limit.d.ts +29 -0
- package/dist/capture/driver/cdp/time-limit.d.ts.map +1 -0
- package/dist/capture/driver/cdp/time-limit.js +51 -0
- package/dist/capture/driver/cdp/time-limit.js.map +1 -0
- package/dist/capture/driver/driver.d.ts +511 -0
- package/dist/capture/driver/driver.d.ts.map +1 -0
- package/dist/capture/driver/driver.js +283 -0
- package/dist/capture/driver/driver.js.map +1 -0
- package/dist/capture/end-state.d.ts +131 -0
- package/dist/capture/end-state.d.ts.map +1 -0
- package/dist/capture/end-state.js +818 -0
- package/dist/capture/end-state.js.map +1 -0
- package/dist/capture/page-roots.d.ts +18 -0
- package/dist/capture/page-roots.d.ts.map +1 -0
- package/dist/capture/page-roots.js +67 -0
- package/dist/capture/page-roots.js.map +1 -0
- package/dist/capture/page-script.d.ts +118 -0
- package/dist/capture/page-script.d.ts.map +1 -0
- package/dist/capture/page-script.js +399 -0
- package/dist/capture/page-script.js.map +1 -0
- package/dist/capture/prepare-capture.d.ts +228 -0
- package/dist/capture/prepare-capture.d.ts.map +1 -0
- package/dist/capture/prepare-capture.js +480 -0
- package/dist/capture/prepare-capture.js.map +1 -0
- package/dist/capture/read-options.d.ts +65 -0
- package/dist/capture/read-options.d.ts.map +1 -0
- package/dist/capture/read-options.js +211 -0
- package/dist/capture/read-options.js.map +1 -0
- package/dist/capture/remote-content.d.ts +45 -0
- package/dist/capture/remote-content.d.ts.map +1 -0
- package/dist/capture/remote-content.js +309 -0
- package/dist/capture/remote-content.js.map +1 -0
- package/dist/capture/worker-pool.d.ts +35 -0
- package/dist/capture/worker-pool.d.ts.map +1 -0
- package/dist/capture/worker-pool.js +51 -0
- package/dist/capture/worker-pool.js.map +1 -0
- package/dist/commands/abortable.d.ts +9 -0
- package/dist/commands/abortable.d.ts.map +1 -0
- package/dist/commands/abortable.js +18 -0
- package/dist/commands/abortable.js.map +1 -0
- package/dist/commands/browser-route.d.ts +86 -0
- package/dist/commands/browser-route.d.ts.map +1 -0
- package/dist/commands/browser-route.js +27 -0
- package/dist/commands/browser-route.js.map +1 -0
- package/dist/commands/capture-settings.d.ts +8 -0
- package/dist/commands/capture-settings.d.ts.map +1 -0
- package/dist/commands/capture-settings.js +17 -0
- package/dist/commands/capture-settings.js.map +1 -0
- package/dist/commands/check-story.d.ts +91 -0
- package/dist/commands/check-story.d.ts.map +1 -0
- package/dist/commands/check-story.js +52 -0
- package/dist/commands/check-story.js.map +1 -0
- package/dist/commands/check-storybooks.d.ts +71 -0
- package/dist/commands/check-storybooks.d.ts.map +1 -0
- package/dist/commands/check-storybooks.js +49 -0
- package/dist/commands/check-storybooks.js.map +1 -0
- package/dist/commands/consistency-check.d.ts +62 -0
- package/dist/commands/consistency-check.d.ts.map +1 -0
- package/dist/commands/consistency-check.js +63 -0
- package/dist/commands/consistency-check.js.map +1 -0
- package/dist/commands/consistency-output.d.ts +63 -0
- package/dist/commands/consistency-output.d.ts.map +1 -0
- package/dist/commands/consistency-output.js +63 -0
- package/dist/commands/consistency-output.js.map +1 -0
- package/dist/commands/docker-problem.d.ts +23 -0
- package/dist/commands/docker-problem.d.ts.map +1 -0
- package/dist/commands/docker-problem.js +18 -0
- package/dist/commands/docker-problem.js.map +1 -0
- package/dist/commands/launch-browser.d.ts +123 -0
- package/dist/commands/launch-browser.d.ts.map +1 -0
- package/dist/commands/launch-browser.js +113 -0
- package/dist/commands/launch-browser.js.map +1 -0
- package/dist/commands/missing-library.d.ts +6 -0
- package/dist/commands/missing-library.d.ts.map +1 -0
- package/dist/commands/missing-library.js +19 -0
- package/dist/commands/missing-library.js.map +1 -0
- package/dist/commands/network-warning.d.ts +36 -0
- package/dist/commands/network-warning.d.ts.map +1 -0
- package/dist/commands/network-warning.js +92 -0
- package/dist/commands/network-warning.js.map +1 -0
- package/dist/commands/parse-command-line.d.ts +133 -0
- package/dist/commands/parse-command-line.d.ts.map +1 -0
- package/dist/commands/parse-command-line.js +425 -0
- package/dist/commands/parse-command-line.js.map +1 -0
- package/dist/commands/place-browser.d.ts +75 -0
- package/dist/commands/place-browser.d.ts.map +1 -0
- package/dist/commands/place-browser.js +82 -0
- package/dist/commands/place-browser.js.map +1 -0
- package/dist/commands/plan-snapshots.d.ts +134 -0
- package/dist/commands/plan-snapshots.d.ts.map +1 -0
- package/dist/commands/plan-snapshots.js +278 -0
- package/dist/commands/plan-snapshots.js.map +1 -0
- package/dist/commands/platform-problem.d.ts +7 -0
- package/dist/commands/platform-problem.d.ts.map +1 -0
- package/dist/commands/platform-problem.js +12 -0
- package/dist/commands/platform-problem.js.map +1 -0
- package/dist/commands/read-image-fit.d.ts +16 -0
- package/dist/commands/read-image-fit.d.ts.map +1 -0
- package/dist/commands/read-image-fit.js +26 -0
- package/dist/commands/read-image-fit.js.map +1 -0
- package/dist/commands/remote-content-hint.d.ts +6 -0
- package/dist/commands/remote-content-hint.d.ts.map +1 -0
- package/dist/commands/remote-content-hint.js +37 -0
- package/dist/commands/remote-content-hint.js.map +1 -0
- package/dist/commands/report-entries.d.ts +94 -0
- package/dist/commands/report-entries.d.ts.map +1 -0
- package/dist/commands/report-entries.js +384 -0
- package/dist/commands/report-entries.js.map +1 -0
- package/dist/commands/run-browser.d.ts +128 -0
- package/dist/commands/run-browser.d.ts.map +1 -0
- package/dist/commands/run-browser.js +210 -0
- package/dist/commands/run-browser.js.map +1 -0
- package/dist/commands/run-cli.d.ts +125 -0
- package/dist/commands/run-cli.d.ts.map +1 -0
- package/dist/commands/run-cli.js +656 -0
- package/dist/commands/run-cli.js.map +1 -0
- package/dist/commands/run-output.d.ts +78 -0
- package/dist/commands/run-output.d.ts.map +1 -0
- package/dist/commands/run-output.js +71 -0
- package/dist/commands/run-output.js.map +1 -0
- package/dist/commands/run-report.d.ts +147 -0
- package/dist/commands/run-report.d.ts.map +1 -0
- package/dist/commands/run-report.js +137 -0
- package/dist/commands/run-report.js.map +1 -0
- package/dist/commands/run-selection.d.ts +191 -0
- package/dist/commands/run-selection.d.ts.map +1 -0
- package/dist/commands/run-selection.js +150 -0
- package/dist/commands/run-selection.js.map +1 -0
- package/dist/commands/run-snapshots.d.ts +272 -0
- package/dist/commands/run-snapshots.d.ts.map +1 -0
- package/dist/commands/run-snapshots.js +354 -0
- package/dist/commands/run-snapshots.js.map +1 -0
- package/dist/commands/same-address.d.ts +6 -0
- package/dist/commands/same-address.d.ts.map +1 -0
- package/dist/commands/same-address.js +32 -0
- package/dist/commands/same-address.js.map +1 -0
- package/dist/commands/select-stories.d.ts +40 -0
- package/dist/commands/select-stories.d.ts.map +1 -0
- package/dist/commands/select-stories.js +15 -0
- package/dist/commands/select-stories.js.map +1 -0
- package/dist/commands/shard-share.d.ts +41 -0
- package/dist/commands/shard-share.d.ts.map +1 -0
- package/dist/commands/shard-share.js +61 -0
- package/dist/commands/shard-share.js.map +1 -0
- package/dist/commands/snapshot-result.d.ts +165 -0
- package/dist/commands/snapshot-result.d.ts.map +1 -0
- package/dist/commands/snapshot-result.js +136 -0
- package/dist/commands/snapshot-result.js.map +1 -0
- package/dist/commands/stop-message.d.ts +65 -0
- package/dist/commands/stop-message.d.ts.map +1 -0
- package/dist/commands/stop-message.js +186 -0
- package/dist/commands/stop-message.js.map +1 -0
- package/dist/commands/stopped-run.d.ts +116 -0
- package/dist/commands/stopped-run.d.ts.map +1 -0
- package/dist/commands/stopped-run.js +103 -0
- package/dist/commands/stopped-run.js.map +1 -0
- package/dist/commands/story-run.d.ts +196 -0
- package/dist/commands/story-run.d.ts.map +1 -0
- package/dist/commands/story-run.js +258 -0
- package/dist/commands/story-run.js.map +1 -0
- package/dist/commands/take-snapshot.d.ts +27 -0
- package/dist/commands/take-snapshot.d.ts.map +1 -0
- package/dist/commands/take-snapshot.js +16 -0
- package/dist/commands/take-snapshot.js.map +1 -0
- package/dist/commands/test-plan.d.ts +100 -0
- package/dist/commands/test-plan.d.ts.map +1 -0
- package/dist/commands/test-plan.js +66 -0
- package/dist/commands/test-plan.js.map +1 -0
- package/dist/commands/test-snapshot.d.ts +52 -0
- package/dist/commands/test-snapshot.d.ts.map +1 -0
- package/dist/commands/test-snapshot.js +183 -0
- package/dist/commands/test-snapshot.js.map +1 -0
- package/dist/commands/update-baselines.d.ts +93 -0
- package/dist/commands/update-baselines.d.ts.map +1 -0
- package/dist/commands/update-baselines.js +120 -0
- package/dist/commands/update-baselines.js.map +1 -0
- package/dist/commands/update-snapshot.d.ts +69 -0
- package/dist/commands/update-snapshot.d.ts.map +1 -0
- package/dist/commands/update-snapshot.js +214 -0
- package/dist/commands/update-snapshot.js.map +1 -0
- package/dist/commands/update-story.d.ts +70 -0
- package/dist/commands/update-story.d.ts.map +1 -0
- package/dist/commands/update-story.js +64 -0
- package/dist/commands/update-story.js.map +1 -0
- package/dist/commands/warm-browser.d.ts +43 -0
- package/dist/commands/warm-browser.d.ts.map +1 -0
- package/dist/commands/warm-browser.js +192 -0
- package/dist/commands/warm-browser.js.map +1 -0
- package/dist/config/addon-image-folders.d.ts +13 -0
- package/dist/config/addon-image-folders.d.ts.map +1 -0
- package/dist/config/addon-image-folders.js +7 -0
- package/dist/config/addon-image-folders.js.map +1 -0
- package/dist/config/checks.d.ts +108 -0
- package/dist/config/checks.d.ts.map +1 -0
- package/dist/config/checks.js +190 -0
- package/dist/config/checks.js.map +1 -0
- package/dist/config/config-error.d.ts +23 -0
- package/dist/config/config-error.d.ts.map +1 -0
- package/dist/config/config-error.js +23 -0
- package/dist/config/config-error.js.map +1 -0
- package/dist/config/config-thread.d.ts +25 -0
- package/dist/config/config-thread.d.ts.map +1 -0
- package/dist/config/config-thread.js +73 -0
- package/dist/config/config-thread.js.map +1 -0
- package/dist/config/define-config.d.ts +192 -0
- package/dist/config/define-config.d.ts.map +1 -0
- package/dist/config/define-config.js +9 -0
- package/dist/config/define-config.js.map +1 -0
- package/dist/config/evaluate-config.d.ts +6 -0
- package/dist/config/evaluate-config.d.ts.map +1 -0
- package/dist/config/evaluate-config.js +39 -0
- package/dist/config/evaluate-config.js.map +1 -0
- package/dist/config/find-config.d.ts +35 -0
- package/dist/config/find-config.d.ts.map +1 -0
- package/dist/config/find-config.js +71 -0
- package/dist/config/find-config.js.map +1 -0
- package/dist/config/find-storybook-url-problem.d.ts +29 -0
- package/dist/config/find-storybook-url-problem.d.ts.map +1 -0
- package/dist/config/find-storybook-url-problem.js +34 -0
- package/dist/config/find-storybook-url-problem.js.map +1 -0
- package/dist/config/is-ci.d.ts +7 -0
- package/dist/config/is-ci.d.ts.map +1 -0
- package/dist/config/is-ci.js +10 -0
- package/dist/config/is-ci.js.map +1 -0
- package/dist/config/load-config.d.ts +72 -0
- package/dist/config/load-config.d.ts.map +1 -0
- package/dist/config/load-config.js +95 -0
- package/dist/config/load-config.js.map +1 -0
- package/dist/config/load-storybook-config.d.ts +71 -0
- package/dist/config/load-storybook-config.d.ts.map +1 -0
- package/dist/config/load-storybook-config.js +104 -0
- package/dist/config/load-storybook-config.js.map +1 -0
- package/dist/config/mode-rules.d.ts +42 -0
- package/dist/config/mode-rules.d.ts.map +1 -0
- package/dist/config/mode-rules.js +188 -0
- package/dist/config/mode-rules.js.map +1 -0
- package/dist/config/read-config-afresh.d.ts +13 -0
- package/dist/config/read-config-afresh.d.ts.map +1 -0
- package/dist/config/read-config-afresh.js +28 -0
- package/dist/config/read-config-afresh.js.map +1 -0
- package/dist/config/resolve-config.d.ts +162 -0
- package/dist/config/resolve-config.d.ts.map +1 -0
- package/dist/config/resolve-config.js +181 -0
- package/dist/config/resolve-config.js.map +1 -0
- package/dist/config/story-options.d.ts +73 -0
- package/dist/config/story-options.d.ts.map +1 -0
- package/dist/config/story-options.js +175 -0
- package/dist/config/story-options.js.map +1 -0
- package/dist/config/validate-config.d.ts +9 -0
- package/dist/config/validate-config.d.ts.map +1 -0
- package/dist/config/validate-config.js +185 -0
- package/dist/config/validate-config.js.map +1 -0
- package/dist/container/browser-container.d.ts +57 -0
- package/dist/container/browser-container.d.ts.map +1 -0
- package/dist/container/browser-container.js +112 -0
- package/dist/container/browser-container.js.map +1 -0
- package/dist/container/container-error.d.ts +47 -0
- package/dist/container/container-error.d.ts.map +1 -0
- package/dist/container/container-error.js +43 -0
- package/dist/container/container-error.js.map +1 -0
- package/dist/container/docker-probe.d.ts +37 -0
- package/dist/container/docker-probe.d.ts.map +1 -0
- package/dist/container/docker-probe.js +85 -0
- package/dist/container/docker-probe.js.map +1 -0
- package/dist/container/image-pull.d.ts +11 -0
- package/dist/container/image-pull.d.ts.map +1 -0
- package/dist/container/image-pull.js +40 -0
- package/dist/container/image-pull.js.map +1 -0
- package/dist/container/inside-container.d.ts +8 -0
- package/dist/container/inside-container.d.ts.map +1 -0
- package/dist/container/inside-container.js +11 -0
- package/dist/container/inside-container.js.map +1 -0
- package/dist/container/launch-through-proxy.d.ts +16 -0
- package/dist/container/launch-through-proxy.d.ts.map +1 -0
- package/dist/container/launch-through-proxy.js +51 -0
- package/dist/container/launch-through-proxy.js.map +1 -0
- package/dist/container/own-container.d.ts +12 -0
- package/dist/container/own-container.d.ts.map +1 -0
- package/dist/container/own-container.js +61 -0
- package/dist/container/own-container.js.map +1 -0
- package/dist/container/proxy-reach.d.ts +19 -0
- package/dist/container/proxy-reach.d.ts.map +1 -0
- package/dist/container/proxy-reach.js +101 -0
- package/dist/container/proxy-reach.js.map +1 -0
- package/dist/container/run-docker.d.ts +11 -0
- package/dist/container/run-docker.d.ts.map +1 -0
- package/dist/container/run-docker.js +61 -0
- package/dist/container/run-docker.js.map +1 -0
- package/dist/container/socks-proxy.d.ts +28 -0
- package/dist/container/socks-proxy.d.ts.map +1 -0
- package/dist/container/socks-proxy.js +335 -0
- package/dist/container/socks-proxy.js.map +1 -0
- package/dist/docs-site/docs-url.d.ts +7 -0
- package/dist/docs-site/docs-url.d.ts.map +1 -0
- package/dist/docs-site/docs-url.js +13 -0
- package/dist/docs-site/docs-url.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/init/addon-question.d.ts +99 -0
- package/dist/init/addon-question.d.ts.map +1 -0
- package/dist/init/addon-question.js +111 -0
- package/dist/init/addon-question.js.map +1 -0
- package/dist/init/closing-message.d.ts +182 -0
- package/dist/init/closing-message.d.ts.map +1 -0
- package/dist/init/closing-message.js +189 -0
- package/dist/init/closing-message.js.map +1 -0
- package/dist/init/detect-project.d.ts +111 -0
- package/dist/init/detect-project.d.ts.map +1 -0
- package/dist/init/detect-project.js +166 -0
- package/dist/init/detect-project.js.map +1 -0
- package/dist/init/existing-config.d.ts +68 -0
- package/dist/init/existing-config.d.ts.map +1 -0
- package/dist/init/existing-config.js +149 -0
- package/dist/init/existing-config.js.map +1 -0
- package/dist/init/find-storybooks.d.ts +93 -0
- package/dist/init/find-storybooks.d.ts.map +1 -0
- package/dist/init/find-storybooks.js +165 -0
- package/dist/init/find-storybooks.js.map +1 -0
- package/dist/init/init-checks.d.ts +49 -0
- package/dist/init/init-checks.d.ts.map +1 -0
- package/dist/init/init-checks.js +151 -0
- package/dist/init/init-checks.js.map +1 -0
- package/dist/init/install.d.ts +286 -0
- package/dist/init/install.d.ts.map +1 -0
- package/dist/init/install.js +226 -0
- package/dist/init/install.js.map +1 -0
- package/dist/init/list-of.d.ts +10 -0
- package/dist/init/list-of.d.ts.map +1 -0
- package/dist/init/list-of.js +18 -0
- package/dist/init/list-of.js.map +1 -0
- package/dist/init/package-manager.d.ts +214 -0
- package/dist/init/package-manager.d.ts.map +1 -0
- package/dist/init/package-manager.js +308 -0
- package/dist/init/package-manager.js.map +1 -0
- package/dist/init/package-scripts.d.ts +72 -0
- package/dist/init/package-scripts.d.ts.map +1 -0
- package/dist/init/package-scripts.js +29 -0
- package/dist/init/package-scripts.js.map +1 -0
- package/dist/init/prompter.d.ts +143 -0
- package/dist/init/prompter.d.ts.map +1 -0
- package/dist/init/prompter.js +65 -0
- package/dist/init/prompter.js.map +1 -0
- package/dist/init/questions.d.ts +144 -0
- package/dist/init/questions.d.ts.map +1 -0
- package/dist/init/questions.js +342 -0
- package/dist/init/questions.js.map +1 -0
- package/dist/init/run-command.d.ts +27 -0
- package/dist/init/run-command.d.ts.map +1 -0
- package/dist/init/run-command.js +63 -0
- package/dist/init/run-command.js.map +1 -0
- package/dist/init/run-init.d.ts +133 -0
- package/dist/init/run-init.d.ts.map +1 -0
- package/dist/init/run-init.js +330 -0
- package/dist/init/run-init.js.map +1 -0
- package/dist/init/segment.d.ts +60 -0
- package/dist/init/segment.d.ts.map +1 -0
- package/dist/init/segment.js +54 -0
- package/dist/init/segment.js.map +1 -0
- package/dist/init/setup-files.d.ts +85 -0
- package/dist/init/setup-files.d.ts.map +1 -0
- package/dist/init/setup-files.js +191 -0
- package/dist/init/setup-files.js.map +1 -0
- package/dist/init/setup-progress.d.ts +46 -0
- package/dist/init/setup-progress.d.ts.map +1 -0
- package/dist/init/setup-progress.js +36 -0
- package/dist/init/setup-progress.js.map +1 -0
- package/dist/init/skill-setup.d.ts +55 -0
- package/dist/init/skill-setup.d.ts.map +1 -0
- package/dist/init/skill-setup.js +47 -0
- package/dist/init/skill-setup.js.map +1 -0
- package/dist/init/storybook-scripts.d.ts +47 -0
- package/dist/init/storybook-scripts.d.ts.map +1 -0
- package/dist/init/storybook-scripts.js +114 -0
- package/dist/init/storybook-scripts.js.map +1 -0
- package/dist/init/storybook-start.d.ts +145 -0
- package/dist/init/storybook-start.d.ts.map +1 -0
- package/dist/init/storybook-start.js +109 -0
- package/dist/init/storybook-start.js.map +1 -0
- package/dist/init/unlisted-dependencies.d.ts +75 -0
- package/dist/init/unlisted-dependencies.d.ts.map +1 -0
- package/dist/init/unlisted-dependencies.js +142 -0
- package/dist/init/unlisted-dependencies.js.map +1 -0
- package/dist/init/workspace-packages.d.ts +58 -0
- package/dist/init/workspace-packages.d.ts.map +1 -0
- package/dist/init/workspace-packages.js +86 -0
- package/dist/init/workspace-packages.js.map +1 -0
- package/dist/init/workspace.d.ts +109 -0
- package/dist/init/workspace.d.ts.map +1 -0
- package/dist/init/workspace.js +433 -0
- package/dist/init/workspace.js.map +1 -0
- package/dist/report/display-path.d.ts +7 -0
- package/dist/report/display-path.d.ts.map +1 -0
- package/dist/report/display-path.js +10 -0
- package/dist/report/display-path.js.map +1 -0
- package/dist/report/report-document.d.ts +682 -0
- package/dist/report/report-document.d.ts.map +1 -0
- package/dist/report/report-document.js +90 -0
- package/dist/report/report-document.js.map +1 -0
- package/dist/report/report-folder.d.ts +102 -0
- package/dist/report/report-folder.d.ts.map +1 -0
- package/dist/report/report-folder.js +160 -0
- package/dist/report/report-folder.js.map +1 -0
- package/dist/reporter/counts-line.d.ts +14 -0
- package/dist/reporter/counts-line.d.ts.map +1 -0
- package/dist/reporter/counts-line.js +18 -0
- package/dist/reporter/counts-line.js.map +1 -0
- package/dist/reporter/duration.d.ts +8 -0
- package/dist/reporter/duration.d.ts.map +1 -0
- package/dist/reporter/duration.js +18 -0
- package/dist/reporter/duration.js.map +1 -0
- package/dist/reporter/end-block.d.ts +42 -0
- package/dist/reporter/end-block.d.ts.map +1 -0
- package/dist/reporter/end-block.js +121 -0
- package/dist/reporter/end-block.js.map +1 -0
- package/dist/reporter/log-reporter.d.ts +10 -0
- package/dist/reporter/log-reporter.d.ts.map +1 -0
- package/dist/reporter/log-reporter.js +23 -0
- package/dist/reporter/log-reporter.js.map +1 -0
- package/dist/reporter/reporter-choice.d.ts +27 -0
- package/dist/reporter/reporter-choice.d.ts.map +1 -0
- package/dist/reporter/reporter-choice.js +12 -0
- package/dist/reporter/reporter-choice.js.map +1 -0
- package/dist/reporter/run-event.d.ts +90 -0
- package/dist/reporter/run-event.d.ts.map +1 -0
- package/dist/reporter/run-event.js +2 -0
- package/dist/reporter/run-event.js.map +1 -0
- package/dist/sharding/shard.d.ts +17 -0
- package/dist/sharding/shard.d.ts.map +1 -0
- package/dist/sharding/shard.js +2 -0
- package/dist/sharding/shard.js.map +1 -0
- package/dist/sharding/split-stories-files.d.ts +43 -0
- package/dist/sharding/split-stories-files.d.ts.map +1 -0
- package/dist/sharding/split-stories-files.js +70 -0
- package/dist/sharding/split-stories-files.js.map +1 -0
- package/dist/step-summary/step-summary.d.ts +45 -0
- package/dist/step-summary/step-summary.d.ts.map +1 -0
- package/dist/step-summary/step-summary.js +263 -0
- package/dist/step-summary/step-summary.js.map +1 -0
- package/dist/storybook/options-encoding.d.ts +115 -0
- package/dist/storybook/options-encoding.d.ts.map +1 -0
- package/dist/storybook/options-encoding.js +117 -0
- package/dist/storybook/options-encoding.js.map +1 -0
- package/dist/storybook/options-read.d.ts +146 -0
- package/dist/storybook/options-read.d.ts.map +1 -0
- package/dist/storybook/options-read.js +192 -0
- package/dist/storybook/options-read.js.map +1 -0
- package/dist/storybook/preview-script.d.ts +172 -0
- package/dist/storybook/preview-script.d.ts.map +1 -0
- package/dist/storybook/preview-script.js +804 -0
- package/dist/storybook/preview-script.js.map +1 -0
- package/dist/storybook/read-stories.d.ts +72 -0
- package/dist/storybook/read-stories.d.ts.map +1 -0
- package/dist/storybook/read-stories.js +317 -0
- package/dist/storybook/read-stories.js.map +1 -0
- package/dist/storybook/stories-matchers.d.ts +39 -0
- package/dist/storybook/stories-matchers.d.ts.map +1 -0
- package/dist/storybook/stories-matchers.js +149 -0
- package/dist/storybook/stories-matchers.js.map +1 -0
- package/dist/storybook/storybook-error.d.ts +24 -0
- package/dist/storybook/storybook-error.d.ts.map +1 -0
- package/dist/storybook/storybook-error.js +24 -0
- package/dist/storybook/storybook-error.js.map +1 -0
- package/dist/storybook/storybook-version.d.ts +62 -0
- package/dist/storybook/storybook-version.d.ts.map +1 -0
- package/dist/storybook/storybook-version.js +105 -0
- package/dist/storybook/storybook-version.js.map +1 -0
- package/dist/storybook/test-path.d.ts +19 -0
- package/dist/storybook/test-path.d.ts.map +1 -0
- package/dist/storybook/test-path.js +47 -0
- package/dist/storybook/test-path.js.map +1 -0
- package/dist/storybook/wait-hook.d.ts +64 -0
- package/dist/storybook/wait-hook.d.ts.map +1 -0
- package/dist/storybook/wait-hook.js +50 -0
- package/dist/storybook/wait-hook.js.map +1 -0
- package/dist/system-error/system-reason.d.ts +8 -0
- package/dist/system-error/system-reason.d.ts.map +1 -0
- package/dist/system-error/system-reason.js +15 -0
- package/dist/system-error/system-reason.js.map +1 -0
- package/dist/terminal-ui/answered-line.d.ts +21 -0
- package/dist/terminal-ui/answered-line.d.ts.map +1 -0
- package/dist/terminal-ui/answered-line.js +12 -0
- package/dist/terminal-ui/answered-line.js.map +1 -0
- package/dist/terminal-ui/brand-header.d.ts +21 -0
- package/dist/terminal-ui/brand-header.d.ts.map +1 -0
- package/dist/terminal-ui/brand-header.js +12 -0
- package/dist/terminal-ui/brand-header.js.map +1 -0
- package/dist/terminal-ui/checklist-question.d.ts +26 -0
- package/dist/terminal-ui/checklist-question.d.ts.map +1 -0
- package/dist/terminal-ui/checklist-question.js +62 -0
- package/dist/terminal-ui/checklist-question.js.map +1 -0
- package/dist/terminal-ui/choice-line.d.ts +29 -0
- package/dist/terminal-ui/choice-line.d.ts.map +1 -0
- package/dist/terminal-ui/choice-line.js +13 -0
- package/dist/terminal-ui/choice-line.js.map +1 -0
- package/dist/terminal-ui/coloured-text.d.ts +19 -0
- package/dist/terminal-ui/coloured-text.d.ts.map +1 -0
- package/dist/terminal-ui/coloured-text.js +16 -0
- package/dist/terminal-ui/coloured-text.js.map +1 -0
- package/dist/terminal-ui/confirm-question.d.ts +8 -0
- package/dist/terminal-ui/confirm-question.d.ts.map +1 -0
- package/dist/terminal-ui/confirm-question.js +44 -0
- package/dist/terminal-ui/confirm-question.js.map +1 -0
- package/dist/terminal-ui/init-screen.d.ts +23 -0
- package/dist/terminal-ui/init-screen.d.ts.map +1 -0
- package/dist/terminal-ui/init-screen.js +74 -0
- package/dist/terminal-ui/init-screen.js.map +1 -0
- package/dist/terminal-ui/init-view-state.d.ts +294 -0
- package/dist/terminal-ui/init-view-state.d.ts.map +1 -0
- package/dist/terminal-ui/init-view-state.js +148 -0
- package/dist/terminal-ui/init-view-state.js.map +1 -0
- package/dist/terminal-ui/init-view.d.ts +70 -0
- package/dist/terminal-ui/init-view.d.ts.map +1 -0
- package/dist/terminal-ui/init-view.js +128 -0
- package/dist/terminal-ui/init-view.js.map +1 -0
- package/dist/terminal-ui/live-screen.d.ts +22 -0
- package/dist/terminal-ui/live-screen.d.ts.map +1 -0
- package/dist/terminal-ui/live-screen.js +41 -0
- package/dist/terminal-ui/live-screen.js.map +1 -0
- package/dist/terminal-ui/live-view-state.d.ts +64 -0
- package/dist/terminal-ui/live-view-state.d.ts.map +1 -0
- package/dist/terminal-ui/live-view-state.js +54 -0
- package/dist/terminal-ui/live-view-state.js.map +1 -0
- package/dist/terminal-ui/live-view.d.ts +37 -0
- package/dist/terminal-ui/live-view.d.ts.map +1 -0
- package/dist/terminal-ui/live-view.js +67 -0
- package/dist/terminal-ui/live-view.js.map +1 -0
- package/dist/terminal-ui/message-line.d.ts +31 -0
- package/dist/terminal-ui/message-line.d.ts.map +1 -0
- package/dist/terminal-ui/message-line.js +79 -0
- package/dist/terminal-ui/message-line.js.map +1 -0
- package/dist/terminal-ui/output-tail.d.ts +29 -0
- package/dist/terminal-ui/output-tail.d.ts.map +1 -0
- package/dist/terminal-ui/output-tail.js +52 -0
- package/dist/terminal-ui/output-tail.js.map +1 -0
- package/dist/terminal-ui/progress-bar.d.ts +47 -0
- package/dist/terminal-ui/progress-bar.d.ts.map +1 -0
- package/dist/terminal-ui/progress-bar.js +23 -0
- package/dist/terminal-ui/progress-bar.js.map +1 -0
- package/dist/terminal-ui/question-header.d.ts +23 -0
- package/dist/terminal-ui/question-header.d.ts.map +1 -0
- package/dist/terminal-ui/question-header.js +24 -0
- package/dist/terminal-ui/question-header.js.map +1 -0
- package/dist/terminal-ui/question.d.ts +85 -0
- package/dist/terminal-ui/question.d.ts.map +1 -0
- package/dist/terminal-ui/question.js +77 -0
- package/dist/terminal-ui/question.js.map +1 -0
- package/dist/terminal-ui/select-question.d.ts +19 -0
- package/dist/terminal-ui/select-question.d.ts.map +1 -0
- package/dist/terminal-ui/select-question.js +24 -0
- package/dist/terminal-ui/select-question.js.map +1 -0
- package/dist/terminal-ui/spinner.d.ts +26 -0
- package/dist/terminal-ui/spinner.d.ts.map +1 -0
- package/dist/terminal-ui/spinner.js +39 -0
- package/dist/terminal-ui/spinner.js.map +1 -0
- package/dist/terminal-ui/step-list.d.ts +36 -0
- package/dist/terminal-ui/step-list.d.ts.map +1 -0
- package/dist/terminal-ui/step-list.js +122 -0
- package/dist/terminal-ui/step-list.js.map +1 -0
- package/dist/terminal-ui/summary.d.ts +20 -0
- package/dist/terminal-ui/summary.d.ts.map +1 -0
- package/dist/terminal-ui/summary.js +96 -0
- package/dist/terminal-ui/summary.js.map +1 -0
- package/dist/terminal-ui/text-input.d.ts +65 -0
- package/dist/terminal-ui/text-input.d.ts.map +1 -0
- package/dist/terminal-ui/text-input.js +72 -0
- package/dist/terminal-ui/text-input.js.map +1 -0
- package/dist/terminal-ui/text-question.d.ts +18 -0
- package/dist/terminal-ui/text-question.d.ts.map +1 -0
- package/dist/terminal-ui/text-question.js +60 -0
- package/dist/terminal-ui/text-question.js.map +1 -0
- package/dist/terminal-ui/theme.d.ts +106 -0
- package/dist/terminal-ui/theme.d.ts.map +1 -0
- package/dist/terminal-ui/theme.js +97 -0
- package/dist/terminal-ui/theme.js.map +1 -0
- package/dist/terminal-ui/wrapped-lines.d.ts +15 -0
- package/dist/terminal-ui/wrapped-lines.d.ts.map +1 -0
- package/dist/terminal-ui/wrapped-lines.js +105 -0
- package/dist/terminal-ui/wrapped-lines.js.map +1 -0
- package/dist/terminal-ui/wrapped-segments.d.ts +27 -0
- package/dist/terminal-ui/wrapped-segments.d.ts.map +1 -0
- package/dist/terminal-ui/wrapped-segments.js +37 -0
- package/dist/terminal-ui/wrapped-segments.js.map +1 -0
- package/dist/terminal-ui/wrapped-text.d.ts +21 -0
- package/dist/terminal-ui/wrapped-text.d.ts.map +1 -0
- package/dist/terminal-ui/wrapped-text.js +11 -0
- package/dist/terminal-ui/wrapped-text.js.map +1 -0
- package/dist/visual-diff/diff-thread.d.ts +27 -0
- package/dist/visual-diff/diff-thread.d.ts.map +1 -0
- package/dist/visual-diff/diff-thread.js +233 -0
- package/dist/visual-diff/diff-thread.js.map +1 -0
- package/dist/visual-diff/visual-diff.d.ts +259 -0
- package/dist/visual-diff/visual-diff.d.ts.map +1 -0
- package/dist/visual-diff/visual-diff.js +317 -0
- package/dist/visual-diff/visual-diff.js.map +1 -0
- package/fallow-graph.json +1 -0
- package/package.json +61 -4
- package/skill/SKILL.md +93 -0
- package/skill/scripts/run.mjs +1532 -0
- package/README.md +0 -3
|
@@ -0,0 +1,1532 @@
|
|
|
1
|
+
// The agent skill's runner script. An agent runs it instead of the visual-check CLI:
|
|
2
|
+
//
|
|
3
|
+
// node .agents/skills/visual-check/scripts/run.mjs test [flags]
|
|
4
|
+
//
|
|
5
|
+
// It runs the CLI command from the skill's setup.json in its folder, with the caller's command and flags plus
|
|
6
|
+
// `--reporter json`. stdout carries the CLI's JSON report unchanged, stderr carries everything else, and the exit code
|
|
7
|
+
// is the CLI's. When the CLI exits 2 because Storybooks it needs are unreachable, the script starts those, waits until
|
|
8
|
+
// they answer and runs the CLI again. It runs every process tree it starts, the CLI's and each Storybook's, under a
|
|
9
|
+
// keeper, which stops the whole tree once the script is done, on an interrupt, or when the script itself is killed. It
|
|
10
|
+
// never stops a Storybook it didn't start.
|
|
11
|
+
//
|
|
12
|
+
// `visual-check init` installs this file, and local runs refresh it. It must stay plain JavaScript that imports only
|
|
13
|
+
// Node's built-in modules.
|
|
14
|
+
|
|
15
|
+
import { spawn } from 'node:child_process'
|
|
16
|
+
import { existsSync, readFileSync, realpathSync } from 'node:fs'
|
|
17
|
+
import { constants } from 'node:os'
|
|
18
|
+
import { basename, dirname, join, relative, resolve, sep } from 'node:path'
|
|
19
|
+
import { setTimeout as sleep } from 'node:timers/promises'
|
|
20
|
+
import { fileURLToPath } from 'node:url'
|
|
21
|
+
import { stripVTControlCharacters } from 'node:util'
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The flag that makes the script a keeper: `node run.mjs --keep-tree '<json {argv, cwd}>'`.
|
|
25
|
+
*/
|
|
26
|
+
const keepTreeFlag = '--keep-tree'
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* How long a keeper waits for a process group to go after SIGTERM before it sends SIGKILL, in milliseconds.
|
|
30
|
+
*/
|
|
31
|
+
const stopGraceMilliseconds = 5_000
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* How long a keeper's whole stop may take before the keeper gives up on the tree and exits, in milliseconds.
|
|
35
|
+
*/
|
|
36
|
+
const stopDeadlineMilliseconds = stopGraceMilliseconds + 5_000
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* How often a keeper checks whether a process group it stops is gone, in milliseconds.
|
|
40
|
+
*/
|
|
41
|
+
const stopPollMilliseconds = 100
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Whether the script runs on Windows, where every command runs through `cmd.exe` and a tree stops with `taskkill`.
|
|
45
|
+
*/
|
|
46
|
+
const windows = process.platform === 'win32'
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The signals that interrupt the script and stop a keeper's tree.
|
|
50
|
+
*
|
|
51
|
+
* @type {NodeJS.Signals[]}
|
|
52
|
+
*/
|
|
53
|
+
const interruptSignals = windows ? ['SIGINT', 'SIGTERM', 'SIGHUP', 'SIGBREAK'] : ['SIGINT', 'SIGTERM', 'SIGHUP']
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The path of this file, which a keeper runs again.
|
|
57
|
+
*/
|
|
58
|
+
const scriptPath = fileURLToPath(import.meta.url)
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* How long the script waits for an exited keeper's pipes to close before it stops reading them, in milliseconds.
|
|
62
|
+
*/
|
|
63
|
+
const pipeCloseGraceMilliseconds = 1_000
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* How long the script waits for a Storybook it started to answer, from its start, in milliseconds.
|
|
67
|
+
*/
|
|
68
|
+
const storybookStartTimeoutMilliseconds = 180_000
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* How often the script asks a Storybook it started whether it answers yet, in milliseconds.
|
|
72
|
+
*/
|
|
73
|
+
const storybookPollMilliseconds = 500
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* How long one request for a Storybook's index may take, in milliseconds.
|
|
77
|
+
*/
|
|
78
|
+
const probeTimeoutMilliseconds = 10_000
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* How many lines of a Storybook's output a failed start shows.
|
|
82
|
+
*/
|
|
83
|
+
const outputTailLimit = 15
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* A command the script runs: its words, the program first, and its absolute working directory.
|
|
87
|
+
*
|
|
88
|
+
* @typedef {object} Command
|
|
89
|
+
* @property {string[]} argv The command's words, the program first.
|
|
90
|
+
* @property {string} cwd The absolute folder the command runs in.
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* What the skill's `setup.json` says: the CLI command and each Storybook's start command, keyed by its config name.
|
|
95
|
+
*
|
|
96
|
+
* @typedef {object} Setup
|
|
97
|
+
* @property {Command} cli The command that runs the visual-check CLI.
|
|
98
|
+
* @property {Record<string, Command>} storybooks Each Storybook's start command, keyed by its config name.
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* A process tree the script started under a keeper.
|
|
103
|
+
*
|
|
104
|
+
* @typedef {object} Tree
|
|
105
|
+
* @property {import('node:child_process').ChildProcess} child The keeper.
|
|
106
|
+
* @property {Promise<number>} exited Settles with the keeper's exit code, the tree's own, once the keeper has exited
|
|
107
|
+
* and its pipes have closed, or `pipeCloseGraceMilliseconds` after it exited.
|
|
108
|
+
* @property {() => boolean} hasExited Whether the keeper has exited.
|
|
109
|
+
* @property {() => Promise<number>} stop Stops the tree and settles as `exited` does.
|
|
110
|
+
*/
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* What a CLI run gave: its exit code and the bytes it wrote on stdout.
|
|
114
|
+
*
|
|
115
|
+
* @typedef {object} CliRun
|
|
116
|
+
* @property {number} exitCode The CLI's exit code.
|
|
117
|
+
* @property {Buffer} stdout What the CLI wrote on stdout, its JSON report.
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* A Storybook as the CLI's report names it.
|
|
122
|
+
*
|
|
123
|
+
* @typedef {object} StorybookRef
|
|
124
|
+
* @property {string} name The Storybook's config name.
|
|
125
|
+
* @property {string} url The Storybook's URL.
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* What the script reads of the CLI's report.
|
|
130
|
+
*
|
|
131
|
+
* @typedef {object} ReportFacts
|
|
132
|
+
* @property {StorybookRef[]} storybooks The Storybooks of the run.
|
|
133
|
+
* @property {StorybookRef[]} unreachable The Storybooks where nothing answers, which made the run error.
|
|
134
|
+
* @property {boolean} runError Whether the run ended in a run error.
|
|
135
|
+
*/
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The end of a Storybook's output, kept as it comes in chunks.
|
|
139
|
+
*
|
|
140
|
+
* @typedef {object} OutputTail
|
|
141
|
+
* @property {(chunk: string) => string[]} add Adds a chunk of output and returns the non-empty lines it completed.
|
|
142
|
+
* @property {() => string[]} lines The last non-empty lines so far, the partial last one included.
|
|
143
|
+
*/
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* How the start of a Storybook ended: its tree answers, another server answers in its place, it failed with a message,
|
|
147
|
+
* or the script stopped waiting for it because of an interrupt or another start's failure.
|
|
148
|
+
*
|
|
149
|
+
* @typedef {{ kind: 'started' } | { kind: 'reused' } | { kind: 'failed'; message: string } | { kind: 'aborted' }} StorybookStart
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* The output of a Storybook's tree, as the script watches it while it waits.
|
|
154
|
+
*
|
|
155
|
+
* @typedef {object} StorybookOutput
|
|
156
|
+
* @property {OutputTail} tail The end of the output.
|
|
157
|
+
* @property {AbortSignal} mismatch Aborts once a line says the Storybook started on another port than its URL's.
|
|
158
|
+
* @property {() => number | undefined} startedPort The other port it started on, once a line says so.
|
|
159
|
+
*/
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* A tree the registry holds.
|
|
163
|
+
*
|
|
164
|
+
* @typedef {object} RegisteredTree
|
|
165
|
+
* @property {Tree} tree The tree.
|
|
166
|
+
* @property {string | undefined} storybook The name of the Storybook the tree serves, or `undefined` for the CLI's.
|
|
167
|
+
* @property {Promise<boolean> | undefined} stopping Settles with whether the tree still ran when its stop began, once
|
|
168
|
+
* it is gone. `undefined` until the stop begins.
|
|
169
|
+
*/
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Every tree the script started, so it can stop them all.
|
|
173
|
+
*
|
|
174
|
+
* @typedef {object} TreeRegistry
|
|
175
|
+
* @property {(command: Command, output: 'cli' | 'storybook', storybook?: string) => Tree} start Starts a tree and holds
|
|
176
|
+
* it. A tree started after an interrupt is stopped at once.
|
|
177
|
+
* @property {() => Promise<Set<string>>} stopAll Stops every tree it holds, in parallel, and settles once they are gone.
|
|
178
|
+
* Says `Stopped Storybook <name>.` for each Storybook that still ran, in start order, and settles with their names. A
|
|
179
|
+
* Storybook whose tree ended by itself isn't among them: what answered for it was another server.
|
|
180
|
+
*/
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* How the script's run went.
|
|
184
|
+
*
|
|
185
|
+
* @typedef {object} RunOutcome
|
|
186
|
+
* @property {CliRun} last The last CLI run.
|
|
187
|
+
* @property {boolean} failed Whether the script itself failed, which makes it exit 2.
|
|
188
|
+
*/
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* The script's watch for interrupt signals.
|
|
192
|
+
*
|
|
193
|
+
* @typedef {object} InterruptWatch
|
|
194
|
+
* @property {AbortSignal} signal Aborts on the first interrupt signal.
|
|
195
|
+
* @property {() => NodeJS.Signals | undefined} interruptedBy The first interrupt signal the script got, if any.
|
|
196
|
+
* @property {() => void} dispose Stops listening for interrupt signals.
|
|
197
|
+
*/
|
|
198
|
+
|
|
199
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
200
|
+
// Setup: reading the skill's setup.json.
|
|
201
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Reads the skill's `setup.json` text. Every `cwd` is resolved against `setupDir`, the folder holding `setup.json`, so
|
|
205
|
+
* a relative one is relative to it and an absolute one stays.
|
|
206
|
+
*
|
|
207
|
+
* Throws an `Error` whose message is the reason the text isn't a setup.
|
|
208
|
+
*
|
|
209
|
+
* @public
|
|
210
|
+
* @param {string} text The text of `setup.json`.
|
|
211
|
+
* @param {string} setupDir The folder holding `setup.json`.
|
|
212
|
+
* @returns {Setup}
|
|
213
|
+
*/
|
|
214
|
+
export function setupOf(text, setupDir) {
|
|
215
|
+
/** @type {unknown} */
|
|
216
|
+
let parsed
|
|
217
|
+
|
|
218
|
+
try {
|
|
219
|
+
parsed = JSON.parse(text)
|
|
220
|
+
} catch (error) {
|
|
221
|
+
throw new Error(`it isn't valid JSON (${messageOf(error)})`)
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const root = isRecord(parsed) ? parsed : {}
|
|
225
|
+
const cli = commandOf(root.cli, 'cli', setupDir)
|
|
226
|
+
|
|
227
|
+
if (!isRecord(root.storybooks)) {
|
|
228
|
+
throw new Error("storybooks must map each Storybook's name to its start command and folder")
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** @type {Record<string, Command>} */
|
|
232
|
+
const storybooks = {}
|
|
233
|
+
|
|
234
|
+
for (const [name, entry] of Object.entries(root.storybooks)) {
|
|
235
|
+
storybooks[name] = commandOf(entry, `storybooks.${name}`, setupDir)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return { cli, storybooks }
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Reads one command of `setup.json`, `{ command, cwd }`, named `name` in the reasons it throws.
|
|
243
|
+
*
|
|
244
|
+
* @param {unknown} value The command's entry in `setup.json`.
|
|
245
|
+
* @param {string} name Where the entry sits in `setup.json`, such as `cli` or `storybooks.web`.
|
|
246
|
+
* @param {string} setupDir The folder holding `setup.json`.
|
|
247
|
+
* @returns {Command}
|
|
248
|
+
*/
|
|
249
|
+
function commandOf(value, name, setupDir) {
|
|
250
|
+
const entry = isRecord(value) ? value : {}
|
|
251
|
+
const words = entry.command
|
|
252
|
+
|
|
253
|
+
if (!Array.isArray(words) || words.length === 0 || !words.every((word) => typeof word === 'string' && word !== '')) {
|
|
254
|
+
throw new Error(`${name}.command must be a list of words, starting with the program`)
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (typeof entry.cwd !== 'string' || entry.cwd === '') {
|
|
258
|
+
throw new Error(`${name}.cwd must be a folder`)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return { argv: /** @type {string[]} */ ([...words]), cwd: resolve(setupDir, entry.cwd) }
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Reads the skill's `setup.json`, beside the `scripts/` folder. Throws an `Error` whose message says why it can't.
|
|
266
|
+
*
|
|
267
|
+
* @returns {Setup}
|
|
268
|
+
*/
|
|
269
|
+
function readSetup() {
|
|
270
|
+
const path = join(import.meta.dirname, '..', 'setup.json')
|
|
271
|
+
|
|
272
|
+
try {
|
|
273
|
+
/** @type {string} */
|
|
274
|
+
let text
|
|
275
|
+
|
|
276
|
+
try {
|
|
277
|
+
text = readFileSync(path, 'utf8')
|
|
278
|
+
} catch (error) {
|
|
279
|
+
throw /** @type {NodeJS.ErrnoException} */ (error).code === 'ENOENT' ? new Error("it doesn't exist") : error
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return setupOf(text, dirname(path))
|
|
283
|
+
} catch (error) {
|
|
284
|
+
throw new Error(
|
|
285
|
+
`Can't read the skill's setup.json at ${folderOf(path)}: ${messageOf(error)}. Run visual-check init again to write it.`,
|
|
286
|
+
)
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Whether `value` is a plain object, not `null` nor a list.
|
|
292
|
+
*
|
|
293
|
+
* @param {unknown} value The value to check.
|
|
294
|
+
* @returns {value is Record<string, unknown>}
|
|
295
|
+
*/
|
|
296
|
+
function isRecord(value) {
|
|
297
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* The message of a thrown value.
|
|
302
|
+
*
|
|
303
|
+
* @param {unknown} error The thrown value.
|
|
304
|
+
* @returns {string}
|
|
305
|
+
*/
|
|
306
|
+
function messageOf(error) {
|
|
307
|
+
return error instanceof Error ? error.message : String(error)
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* `path` relative to the script's working directory, with `/` separators, or `.` when it is that folder.
|
|
312
|
+
*
|
|
313
|
+
* @param {string} path The absolute path.
|
|
314
|
+
* @returns {string}
|
|
315
|
+
*/
|
|
316
|
+
function folderOf(path) {
|
|
317
|
+
return relative(process.cwd(), path).split(sep).join('/') || '.'
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* The CLI's argv: the command from `setup.json`, the caller's arguments in order, then `--reporter json`, which wins
|
|
322
|
+
* over a reporter the caller gives, since the CLI takes the last one.
|
|
323
|
+
*
|
|
324
|
+
* @public
|
|
325
|
+
* @param {string[]} command The CLI command from `setup.json`, the program first.
|
|
326
|
+
* @param {string[]} args The caller's command and flags.
|
|
327
|
+
* @returns {string[]}
|
|
328
|
+
*/
|
|
329
|
+
export function cliArgvOf(command, args) {
|
|
330
|
+
return [...command, ...args, '--reporter', 'json']
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
334
|
+
// Windows command line: how a command's words reach cmd.exe.
|
|
335
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* The command line `cmd.exe` runs for `argv` on Windows. Each argument goes in double quotes, inside which `cmd.exe`
|
|
339
|
+
* takes `& | < > ^ ( )` literally, also when a `.cmd` shim passes them on. A word's trailing backslashes are doubled, so
|
|
340
|
+
* they don't escape the closing quote.
|
|
341
|
+
*
|
|
342
|
+
* The program goes in double quotes too, unless it is a bare name, such as `npm` or `pnpm.cmd`, which holds nothing
|
|
343
|
+
* `cmd.exe` could misread. A `.cmd` shim found through PATH by a quoted bare name gets the current folder, not its own,
|
|
344
|
+
* as `%~dp0`, so `npm.cmd` looks for npm in the command's folder. A quoted path is fine: `%~dp0` resolves it against
|
|
345
|
+
* the current folder, which is where it points.
|
|
346
|
+
*
|
|
347
|
+
* Throws an `Error` naming the first word that can't be passed safely: one holding a double quote or a line break, or
|
|
348
|
+
* a name between percent signs, such as `%PATH%`, which `cmd.exe` expands even inside double quotes.
|
|
349
|
+
*
|
|
350
|
+
* @public
|
|
351
|
+
* @param {string[]} argv The command's words, the program first.
|
|
352
|
+
* @returns {string}
|
|
353
|
+
*/
|
|
354
|
+
export function windowsCommandLineOf(argv) {
|
|
355
|
+
return argv
|
|
356
|
+
.map((word, index) => {
|
|
357
|
+
if (/["\r\n]|%[^%]+%/.test(word)) {
|
|
358
|
+
throw new Error(
|
|
359
|
+
`On Windows the script can't pass an argument that holds a double quote, a line break or a %name%: ${word}`,
|
|
360
|
+
)
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (index === 0 && /^[\w.-]+$/.test(word)) {
|
|
364
|
+
return word
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
return `"${word.replace(/(\\+)$/, '$1$1')}"`
|
|
368
|
+
})
|
|
369
|
+
.join(' ')
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
373
|
+
// Storybooks: what the report says of them, how to start them, what they print, and the messages about them.
|
|
374
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Reads what the script needs of the CLI's JSON report: the Storybooks of the run, those where nothing answers, and
|
|
378
|
+
* whether the run ended in a run error. `undefined` when `stdout` isn't a report. Entries without a string `name` and
|
|
379
|
+
* `url` are left out.
|
|
380
|
+
*
|
|
381
|
+
* @public
|
|
382
|
+
* @param {string} stdout What the CLI wrote on stdout.
|
|
383
|
+
* @returns {ReportFacts | undefined}
|
|
384
|
+
*/
|
|
385
|
+
export function reportOf(stdout) {
|
|
386
|
+
/** @type {unknown} */
|
|
387
|
+
let parsed
|
|
388
|
+
|
|
389
|
+
try {
|
|
390
|
+
parsed = JSON.parse(stdout.trim())
|
|
391
|
+
} catch {
|
|
392
|
+
return undefined
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
if (!isRecord(parsed) || !Array.isArray(parsed.storybooks)) {
|
|
396
|
+
return undefined
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
const error = parsed.error
|
|
400
|
+
|
|
401
|
+
return {
|
|
402
|
+
storybooks: storybookRefsOf(parsed.storybooks),
|
|
403
|
+
unreachable: isRecord(error) ? storybookRefsOf(error.storybooks) : [],
|
|
404
|
+
runError: error !== null,
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* The entries of `value` that name a Storybook, with a string `name` and `url`. None when `value` isn't a list.
|
|
410
|
+
*
|
|
411
|
+
* @param {unknown} value The report's list of Storybooks.
|
|
412
|
+
* @returns {StorybookRef[]}
|
|
413
|
+
*/
|
|
414
|
+
function storybookRefsOf(value) {
|
|
415
|
+
if (!Array.isArray(value)) {
|
|
416
|
+
return []
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
return value
|
|
420
|
+
.filter((entry) => isRecord(entry) && typeof entry.name === 'string' && typeof entry.url === 'string')
|
|
421
|
+
.map((entry) => ({ name: entry.name, url: entry.url }))
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* The argv that starts a Storybook: its start command with `--ci --exact-port`, so it never prompts and exits rather
|
|
426
|
+
* than serve on another port. Under npm they go after `--`, which npm needs to pass them on to the script; other package
|
|
427
|
+
* managers pass a `--` on as it is, so it goes in only for npm.
|
|
428
|
+
*
|
|
429
|
+
* @public
|
|
430
|
+
* @param {string[]} argv The Storybook's start command, the program first.
|
|
431
|
+
* @returns {string[]}
|
|
432
|
+
*/
|
|
433
|
+
export function storybookArgvOf(argv) {
|
|
434
|
+
const program = basename(argv[0] ?? '')
|
|
435
|
+
.toLowerCase()
|
|
436
|
+
.replace(/\.(cmd|exe)$/, '')
|
|
437
|
+
const separator = program === 'npm' && !argv.includes('--') ? ['--'] : []
|
|
438
|
+
|
|
439
|
+
return [...argv, ...separator, '--ci', '--exact-port']
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* The URL of a Storybook's `index.json`, as the CLI asks for it: the Storybook's URL without its query, hash and
|
|
444
|
+
* credentials, as a folder.
|
|
445
|
+
*
|
|
446
|
+
* @public
|
|
447
|
+
* @param {string} url The Storybook's URL.
|
|
448
|
+
* @returns {string}
|
|
449
|
+
*/
|
|
450
|
+
export function indexUrlOf(url) {
|
|
451
|
+
const { origin, pathname } = new URL(url)
|
|
452
|
+
const folder = pathname.endsWith('/') ? pathname : `${pathname}/`
|
|
453
|
+
|
|
454
|
+
return `${origin}${folder}index.json`
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* The port a URL points at: its own, else the scheme's default.
|
|
459
|
+
*
|
|
460
|
+
* @public
|
|
461
|
+
* @param {string} url The URL.
|
|
462
|
+
* @returns {number}
|
|
463
|
+
*/
|
|
464
|
+
export function portOf(url) {
|
|
465
|
+
const parsed = new URL(url)
|
|
466
|
+
|
|
467
|
+
if (parsed.port !== '') {
|
|
468
|
+
return Number(parsed.port)
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
return parsed.protocol === 'https:' ? 443 : 80
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* The port a line of Storybook's output says it started on, from the local URL of its started banner, such as
|
|
476
|
+
* `- Local: http://127.0.0.1:6006/`. `undefined` for any other line.
|
|
477
|
+
*
|
|
478
|
+
* @public
|
|
479
|
+
* @param {string} line A line of Storybook's output.
|
|
480
|
+
* @returns {number | undefined}
|
|
481
|
+
*/
|
|
482
|
+
export function startedPortOf(line) {
|
|
483
|
+
const match = /\bLocal:\s+(https?:\/\/[^\s│]+)/.exec(stripVTControlCharacters(line))
|
|
484
|
+
|
|
485
|
+
if (match?.[1] === undefined) {
|
|
486
|
+
return undefined
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
try {
|
|
490
|
+
return portOf(match[1])
|
|
491
|
+
} catch {
|
|
492
|
+
return undefined
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Keeps the last `limit` non-empty lines of an output that comes in chunks, without colours, carriage returns and
|
|
498
|
+
* trailing whitespace.
|
|
499
|
+
*
|
|
500
|
+
* @public
|
|
501
|
+
* @param {number} limit How many lines to keep.
|
|
502
|
+
* @returns {OutputTail}
|
|
503
|
+
*/
|
|
504
|
+
export function outputTail(limit) {
|
|
505
|
+
/** @type {string[]} */
|
|
506
|
+
const kept = []
|
|
507
|
+
let partial = ''
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* A line of output without colours, carriage returns and trailing whitespace.
|
|
511
|
+
*
|
|
512
|
+
* @param {string} line The line as it came.
|
|
513
|
+
* @returns {string}
|
|
514
|
+
*/
|
|
515
|
+
const clean = (line) => stripVTControlCharacters(line).replaceAll('\r', '').trimEnd()
|
|
516
|
+
|
|
517
|
+
return {
|
|
518
|
+
add: (chunk) => {
|
|
519
|
+
const parts = `${partial}${chunk}`.split('\n')
|
|
520
|
+
|
|
521
|
+
partial = parts.pop() ?? ''
|
|
522
|
+
|
|
523
|
+
const completed = parts.map(clean).filter((line) => line !== '')
|
|
524
|
+
|
|
525
|
+
kept.push(...completed)
|
|
526
|
+
kept.splice(0, Math.max(0, kept.length - limit))
|
|
527
|
+
|
|
528
|
+
return completed
|
|
529
|
+
},
|
|
530
|
+
lines: () => {
|
|
531
|
+
const last = clean(partial)
|
|
532
|
+
|
|
533
|
+
return (last === '' ? kept : [...kept, last]).slice(-limit)
|
|
534
|
+
},
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* Says that a Storybook started on another port than its URL's.
|
|
540
|
+
*
|
|
541
|
+
* @public
|
|
542
|
+
* @param {string} name The Storybook's config name.
|
|
543
|
+
* @param {number} startedPort The port it started on.
|
|
544
|
+
* @param {string} url Its URL.
|
|
545
|
+
* @returns {string}
|
|
546
|
+
*/
|
|
547
|
+
export function portMismatchMessageOf(name, startedPort, url) {
|
|
548
|
+
return `Storybook ${name} started on port ${startedPort}, but its URL ${url} is on port ${portOf(url)}. Make its start command and its URL use the same port.`
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* Says that a Storybook the script started never answered, because it exited or ran out of time, with the end of its
|
|
553
|
+
* output, each line indented two spaces.
|
|
554
|
+
*
|
|
555
|
+
* @public
|
|
556
|
+
* @param {string} name The Storybook's config name.
|
|
557
|
+
* @param {{ exitCode: number } | { timeout: true }} reason Why it never answered.
|
|
558
|
+
* @param {string} index The URL of its `index.json`.
|
|
559
|
+
* @param {string[]} tail The end of its output.
|
|
560
|
+
* @returns {string}
|
|
561
|
+
*/
|
|
562
|
+
export function failedStartMessageOf(name, reason, index, tail) {
|
|
563
|
+
const what =
|
|
564
|
+
'exitCode' in reason
|
|
565
|
+
? `Storybook ${name} exited with code ${reason.exitCode} before it answered at ${index}`
|
|
566
|
+
: `Storybook ${name} didn't answer at ${index} within ${storybookStartTimeoutMilliseconds / 1000} s`
|
|
567
|
+
|
|
568
|
+
if (tail.length === 0) {
|
|
569
|
+
return `${what}, and printed nothing.`
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
return [`${what}. The end of its output:`, ...tail.map((line) => ` ${line}`)].join('\n')
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* Says that a Storybook stopped answering during the run.
|
|
577
|
+
*
|
|
578
|
+
* @public
|
|
579
|
+
* @param {StorybookRef} storybook The Storybook.
|
|
580
|
+
* @returns {string}
|
|
581
|
+
*/
|
|
582
|
+
export function stoppedMidRunMessageOf(storybook) {
|
|
583
|
+
return `Storybook ${storybook.name} stopped answering at ${storybook.url} during the run, so the run's results can't be trusted. Another session may have stopped it. Run the script again.`
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* Says that the run used a Storybook the script didn't start.
|
|
588
|
+
*
|
|
589
|
+
* @public
|
|
590
|
+
* @param {StorybookRef} storybook The Storybook.
|
|
591
|
+
* @returns {string}
|
|
592
|
+
*/
|
|
593
|
+
export function reusedLineOf(storybook) {
|
|
594
|
+
return `Reused Storybook ${storybook.name}, which was already running at ${storybook.url}.`
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
598
|
+
// Keeper: the script run again as `run.mjs --keep-tree`, which starts one process tree and always stops it.
|
|
599
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* The exit code of a process that exited with `code` or was ended by `signal`: the code when there is one, else
|
|
603
|
+
* `128 +` the signal's number, else 2.
|
|
604
|
+
*
|
|
605
|
+
* @public
|
|
606
|
+
* @param {number | null} code The process's exit code, or `null` when a signal ended it.
|
|
607
|
+
* @param {string | null} signal The signal that ended the process, or `null`.
|
|
608
|
+
* @returns {number}
|
|
609
|
+
*/
|
|
610
|
+
export function exitCodeOf(code, signal) {
|
|
611
|
+
if (typeof code === 'number') {
|
|
612
|
+
return code
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
const signals = /** @type {Record<string, number | undefined>} */ (constants.signals)
|
|
616
|
+
const number = signal === null ? undefined : signals[signal]
|
|
617
|
+
|
|
618
|
+
return number === undefined ? 2 : 128 + number
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
* Runs as a keeper: starts the process tree of `command` and stops it when the keeper's stdin from the script closes,
|
|
623
|
+
* or on an interrupt signal. So the tree goes even when the script dies without running any handler. When the tree's
|
|
624
|
+
* root exits by itself, the keeper ends what's left of its process group and exits with the root's code.
|
|
625
|
+
*
|
|
626
|
+
* Outside Windows the tree runs in a process group of its own, which the stop ends with SIGTERM, then SIGKILL after
|
|
627
|
+
* `stopGraceMilliseconds`. On Windows the tree runs through `cmd.exe` and the stop ends it with `taskkill /T /F`. A
|
|
628
|
+
* stop that hasn't seen the tree go within `stopDeadlineMilliseconds`, or a `taskkill` that fails, gives up on it.
|
|
629
|
+
*
|
|
630
|
+
* @param {Command} command The command whose tree the keeper starts.
|
|
631
|
+
* @param {NodeJS.ProcessEnv} environment The keeper's environment, which names the Windows folder.
|
|
632
|
+
*/
|
|
633
|
+
function keepTree(command, environment) {
|
|
634
|
+
if (!existsSync(command.cwd)) {
|
|
635
|
+
failToRun(command, new Error("the folder doesn't exist"))
|
|
636
|
+
|
|
637
|
+
return
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
/** @type {import('node:child_process').ChildProcess} */
|
|
641
|
+
let root
|
|
642
|
+
|
|
643
|
+
try {
|
|
644
|
+
root = spawnTree(command)
|
|
645
|
+
} catch (error) {
|
|
646
|
+
failToRun(command, error)
|
|
647
|
+
|
|
648
|
+
return
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
const tree = root
|
|
652
|
+
const rootIsRunning = () => tree.exitCode === null && tree.signalCode === null
|
|
653
|
+
let stopping = false
|
|
654
|
+
|
|
655
|
+
/** @type {Promise<number>} */
|
|
656
|
+
const rootExited = new Promise((resolveExit) => {
|
|
657
|
+
tree.on('exit', (code, signal) => {
|
|
658
|
+
resolveExit(exitCodeOf(code, signal))
|
|
659
|
+
})
|
|
660
|
+
})
|
|
661
|
+
|
|
662
|
+
tree.on('error', (error) => {
|
|
663
|
+
if (tree.pid === undefined) {
|
|
664
|
+
failToRun(command, error)
|
|
665
|
+
}
|
|
666
|
+
})
|
|
667
|
+
|
|
668
|
+
tree.on('exit', (code, signal) => {
|
|
669
|
+
if (stopping) {
|
|
670
|
+
return
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
if (!windows && tree.pid !== undefined) {
|
|
674
|
+
signalGroup(tree.pid, 'SIGKILL')
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
process.exit(exitCodeOf(code, signal))
|
|
678
|
+
})
|
|
679
|
+
|
|
680
|
+
const stop = async () => {
|
|
681
|
+
// A tree that didn't spawn has nothing to stop, and `failToRun` exits once its message is out.
|
|
682
|
+
const pid = tree.pid
|
|
683
|
+
|
|
684
|
+
if (stopping || pid === undefined) {
|
|
685
|
+
return
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
stopping = true
|
|
689
|
+
setTimeout(() => giveUpStopping(command), stopDeadlineMilliseconds)
|
|
690
|
+
|
|
691
|
+
if (windows) {
|
|
692
|
+
// A root that exits just before `taskkill` runs makes it fail with "not found". `taskkill` runs asynchronously,
|
|
693
|
+
// so the root's exit is seen by then, and only a root that still runs means the tree didn't stop.
|
|
694
|
+
if (rootIsRunning() && !(await killWindowsTree(pid, environment)) && rootIsRunning()) {
|
|
695
|
+
giveUpStopping(command)
|
|
696
|
+
|
|
697
|
+
return
|
|
698
|
+
}
|
|
699
|
+
} else {
|
|
700
|
+
await stopGroup(pid)
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
process.exit(await rootExited)
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
process.stdin.on('end', () => void stop())
|
|
707
|
+
process.stdin.on('error', () => void stop())
|
|
708
|
+
process.stdin.resume()
|
|
709
|
+
|
|
710
|
+
for (const signal of interruptSignals) {
|
|
711
|
+
process.on(signal, () => void stop())
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* Spawns the process tree of `command`, with its stdout and stderr going straight into the keeper's. Outside Windows
|
|
717
|
+
* the root leads a process group of its own. On Windows the command runs through `cmd.exe`, since package managers are
|
|
718
|
+
* `.cmd` shims there.
|
|
719
|
+
*
|
|
720
|
+
* @param {Command} command The command to spawn.
|
|
721
|
+
* @returns {import('node:child_process').ChildProcess}
|
|
722
|
+
*/
|
|
723
|
+
function spawnTree(command) {
|
|
724
|
+
if (windows) {
|
|
725
|
+
return spawn(windowsCommandLineOf(command.argv), {
|
|
726
|
+
cwd: command.cwd,
|
|
727
|
+
shell: true,
|
|
728
|
+
windowsHide: true,
|
|
729
|
+
stdio: ['ignore', 'inherit', 'inherit'],
|
|
730
|
+
})
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
return spawn(command.argv[0] ?? '', command.argv.slice(1), {
|
|
734
|
+
cwd: command.cwd,
|
|
735
|
+
detached: true,
|
|
736
|
+
stdio: ['ignore', 'inherit', 'inherit'],
|
|
737
|
+
})
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* Writes why the keeper couldn't run `command` and exits 2.
|
|
742
|
+
*
|
|
743
|
+
* @param {Command} command The command that couldn't run.
|
|
744
|
+
* @param {unknown} error Why it couldn't run.
|
|
745
|
+
*/
|
|
746
|
+
function failToRun(command, error) {
|
|
747
|
+
process.stderr.write(`Couldn't run ${command.argv.join(' ')} in ${command.cwd}: ${messageOf(error)}\n`, () => {
|
|
748
|
+
process.exit(2)
|
|
749
|
+
})
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
/**
|
|
753
|
+
* Writes that the keeper couldn't stop the tree of `command` and exits as if SIGKILL had ended it.
|
|
754
|
+
*
|
|
755
|
+
* @param {Command} command The command whose tree didn't stop.
|
|
756
|
+
*/
|
|
757
|
+
function giveUpStopping(command) {
|
|
758
|
+
process.stderr.write(
|
|
759
|
+
`Couldn't stop ${command.argv.join(' ')} within ${stopDeadlineMilliseconds / 1000} s. Some of its processes may still run.\n`,
|
|
760
|
+
() => {
|
|
761
|
+
process.exit(exitCodeOf(null, 'SIGKILL'))
|
|
762
|
+
},
|
|
763
|
+
)
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* Ends the process tree rooted at `pid` on Windows with `taskkill /T /F`, run from System32 by its full path, since a
|
|
768
|
+
* bare name is looked up in the current folder first. Settles with whether `taskkill` succeeded.
|
|
769
|
+
*
|
|
770
|
+
* @param {number} pid The root's pid.
|
|
771
|
+
* @param {NodeJS.ProcessEnv} environment The keeper's environment, which names the Windows folder.
|
|
772
|
+
* @returns {Promise<boolean>}
|
|
773
|
+
*/
|
|
774
|
+
function killWindowsTree(pid, environment) {
|
|
775
|
+
const path = join(environment.SystemRoot ?? 'C:\\Windows', 'System32', 'taskkill.exe')
|
|
776
|
+
|
|
777
|
+
return new Promise((resolveKill) => {
|
|
778
|
+
const taskkill = spawn(path, ['/PID', String(pid), '/T', '/F'], { stdio: 'ignore', windowsHide: true })
|
|
779
|
+
|
|
780
|
+
taskkill.on('error', () => {
|
|
781
|
+
resolveKill(false)
|
|
782
|
+
})
|
|
783
|
+
taskkill.on('close', (code) => {
|
|
784
|
+
resolveKill(code === 0)
|
|
785
|
+
})
|
|
786
|
+
})
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
/**
|
|
790
|
+
* Ends the process group `pgid`: SIGTERM, then SIGKILL once `stopGraceMilliseconds` have passed, and settles once the
|
|
791
|
+
* group is gone. The keeper's stop deadline bounds the wait.
|
|
792
|
+
*
|
|
793
|
+
* @param {number} pgid The process group's id, its leader's pid.
|
|
794
|
+
* @returns {Promise<void>}
|
|
795
|
+
*/
|
|
796
|
+
async function stopGroup(pgid) {
|
|
797
|
+
signalGroup(pgid, 'SIGTERM')
|
|
798
|
+
|
|
799
|
+
const killAt = Date.now() + stopGraceMilliseconds
|
|
800
|
+
let killed = false
|
|
801
|
+
|
|
802
|
+
while (groupIsAlive(pgid)) {
|
|
803
|
+
if (!killed && Date.now() >= killAt) {
|
|
804
|
+
signalGroup(pgid, 'SIGKILL')
|
|
805
|
+
killed = true
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
await sleep(stopPollMilliseconds)
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
/**
|
|
813
|
+
* Sends `signal` to the process group `pgid`. A group that is already gone is fine.
|
|
814
|
+
*
|
|
815
|
+
* @param {number} pgid The process group's id.
|
|
816
|
+
* @param {NodeJS.Signals} signal The signal to send.
|
|
817
|
+
*/
|
|
818
|
+
function signalGroup(pgid, signal) {
|
|
819
|
+
try {
|
|
820
|
+
process.kill(-pgid, signal)
|
|
821
|
+
} catch {
|
|
822
|
+
// The group is already gone (ESRCH), which is what a stop wants.
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
/**
|
|
827
|
+
* Whether any process of the group `pgid` is still alive.
|
|
828
|
+
*
|
|
829
|
+
* @param {number} pgid The process group's id.
|
|
830
|
+
* @returns {boolean}
|
|
831
|
+
*/
|
|
832
|
+
function groupIsAlive(pgid) {
|
|
833
|
+
try {
|
|
834
|
+
process.kill(-pgid, 0)
|
|
835
|
+
|
|
836
|
+
return true
|
|
837
|
+
} catch (error) {
|
|
838
|
+
return /** @type {NodeJS.ErrnoException} */ (error).code === 'EPERM'
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
843
|
+
// Trees: the script's side of a keeper.
|
|
844
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
845
|
+
|
|
846
|
+
/**
|
|
847
|
+
* Starts the process tree of `command` under a keeper. The keeper of the CLI passes its stderr through to the
|
|
848
|
+
* script's, and the script reads its stdout. The script reads both of a Storybook's keeper.
|
|
849
|
+
*
|
|
850
|
+
* @param {Command} command The command whose tree to start.
|
|
851
|
+
* @param {'cli' | 'storybook'} output Whose tree it is, which sets what the script reads of it.
|
|
852
|
+
* @returns {Tree}
|
|
853
|
+
*/
|
|
854
|
+
function startTree(command, output) {
|
|
855
|
+
// The keeper runs in the script's working directory, so a missing `command.cwd` fails in the keeper, which names it.
|
|
856
|
+
// It is detached, so it outlives the script to stop its tree: outside Windows it leaves the script's process group,
|
|
857
|
+
// which a terminal's Ctrl+C or a group kill reaches. On Windows Node puts a child that isn't detached into a job that
|
|
858
|
+
// kills it when the script dies, and the keeper's own job then kills only `cmd.exe`, not the tree below it.
|
|
859
|
+
const keeper = spawn(process.execPath, [scriptPath, keepTreeFlag, JSON.stringify(command)], {
|
|
860
|
+
detached: true,
|
|
861
|
+
windowsHide: true,
|
|
862
|
+
stdio: output === 'cli' ? ['pipe', 'pipe', 'inherit'] : ['pipe', 'pipe', 'pipe'],
|
|
863
|
+
})
|
|
864
|
+
let hasExited = false
|
|
865
|
+
|
|
866
|
+
/** @type {Promise<number>} */
|
|
867
|
+
const exited = new Promise((resolveExit) => {
|
|
868
|
+
keeper.on('exit', (code, signal) => {
|
|
869
|
+
hasExited = true
|
|
870
|
+
|
|
871
|
+
const exitCode = exitCodeOf(code, signal)
|
|
872
|
+
// Wait until the keeper's pipes close, so all its output is read, but not for long: a process its tree left
|
|
873
|
+
// behind, which Windows doesn't end with the tree's root, may hold them open. Then stop reading them.
|
|
874
|
+
const giveUp = setTimeout(() => {
|
|
875
|
+
keeper.stdout?.destroy()
|
|
876
|
+
keeper.stderr?.destroy()
|
|
877
|
+
resolveExit(exitCode)
|
|
878
|
+
}, pipeCloseGraceMilliseconds)
|
|
879
|
+
|
|
880
|
+
keeper.once('close', () => {
|
|
881
|
+
clearTimeout(giveUp)
|
|
882
|
+
resolveExit(exitCode)
|
|
883
|
+
})
|
|
884
|
+
})
|
|
885
|
+
keeper.on('error', (error) => {
|
|
886
|
+
hasExited = true
|
|
887
|
+
process.stderr.write(`Couldn't run ${command.argv.join(' ')} in ${command.cwd}: ${error.message}\n`)
|
|
888
|
+
resolveExit(2)
|
|
889
|
+
})
|
|
890
|
+
})
|
|
891
|
+
|
|
892
|
+
// The keeper may already be gone when the script ends its stdin.
|
|
893
|
+
keeper.stdin?.on('error', () => undefined)
|
|
894
|
+
|
|
895
|
+
return {
|
|
896
|
+
child: keeper,
|
|
897
|
+
exited,
|
|
898
|
+
hasExited: () => hasExited,
|
|
899
|
+
stop: () => {
|
|
900
|
+
keeper.stdin?.end()
|
|
901
|
+
|
|
902
|
+
return exited
|
|
903
|
+
},
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
/**
|
|
908
|
+
* Holds every tree the script starts, the CLI's and each Storybook's, so that the end of the run, an interrupt or a
|
|
909
|
+
* failure stops them all. An interrupt stops them at once, and so a tree started after one.
|
|
910
|
+
*
|
|
911
|
+
* @param {AbortSignal} interruption Aborts on an interrupt.
|
|
912
|
+
* @returns {TreeRegistry}
|
|
913
|
+
*/
|
|
914
|
+
function treeRegistry(interruption) {
|
|
915
|
+
/** @type {RegisteredTree[]} */
|
|
916
|
+
const registered = []
|
|
917
|
+
|
|
918
|
+
/** @type {Set<string>} */
|
|
919
|
+
const stopped = new Set()
|
|
920
|
+
|
|
921
|
+
const stopAll = async () => {
|
|
922
|
+
for (const entry of registered) {
|
|
923
|
+
entry.stopping ??= stopRunning(entry.tree)
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
for (const entry of registered) {
|
|
927
|
+
const wasRunning = await entry.stopping
|
|
928
|
+
|
|
929
|
+
if (wasRunning && entry.storybook !== undefined && !stopped.has(entry.storybook)) {
|
|
930
|
+
stopped.add(entry.storybook)
|
|
931
|
+
process.stderr.write(`Stopped Storybook ${entry.storybook}.\n`)
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
return stopped
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
interruption.addEventListener('abort', () => void stopAll(), { once: true })
|
|
939
|
+
|
|
940
|
+
return {
|
|
941
|
+
start: (command, output, storybook) => {
|
|
942
|
+
const tree = startTree(command, output)
|
|
943
|
+
|
|
944
|
+
registered.push({ tree, storybook, stopping: undefined })
|
|
945
|
+
|
|
946
|
+
if (interruption.aborted) {
|
|
947
|
+
void stopAll()
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
return tree
|
|
951
|
+
},
|
|
952
|
+
stopAll,
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
/**
|
|
957
|
+
* Stops `tree` and settles, once it is gone, with whether it still ran when the stop began. A tree that ended by
|
|
958
|
+
* itself has nothing to stop.
|
|
959
|
+
*
|
|
960
|
+
* @param {Tree} tree The tree to stop.
|
|
961
|
+
* @returns {Promise<boolean>}
|
|
962
|
+
*/
|
|
963
|
+
async function stopRunning(tree) {
|
|
964
|
+
const wasRunning = !tree.hasExited()
|
|
965
|
+
|
|
966
|
+
await tree.stop()
|
|
967
|
+
|
|
968
|
+
return wasRunning
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
/**
|
|
972
|
+
* Runs the CLI with the caller's arguments under a keeper and collects its stdout. The registry stops its tree on an
|
|
973
|
+
* interrupt.
|
|
974
|
+
*
|
|
975
|
+
* @param {Setup} setup The skill's setup.
|
|
976
|
+
* @param {string[]} args The caller's command and flags.
|
|
977
|
+
* @param {TreeRegistry} trees The registry that holds the CLI's tree.
|
|
978
|
+
* @returns {Promise<CliRun>}
|
|
979
|
+
*/
|
|
980
|
+
async function runCli(setup, args, trees) {
|
|
981
|
+
const tree = trees.start({ argv: cliArgvOf(setup.cli.argv, args), cwd: setup.cli.cwd }, 'cli')
|
|
982
|
+
|
|
983
|
+
/** @type {Buffer[]} */
|
|
984
|
+
const chunks = []
|
|
985
|
+
|
|
986
|
+
tree.child.stdout?.on('data', (/** @type {Buffer} */ chunk) => {
|
|
987
|
+
chunks.push(chunk)
|
|
988
|
+
})
|
|
989
|
+
|
|
990
|
+
return { exitCode: await tree.exited, stdout: Buffer.concat(chunks) }
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
994
|
+
// Storybooks: start and wait.
|
|
995
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
996
|
+
|
|
997
|
+
/**
|
|
998
|
+
* Asks a Storybook for its index once. `ready` when it answers 200 with a Storybook index, `refused` when nothing
|
|
999
|
+
* listens on its port, else `not-ready`: an error, a timeout, another answer, or a server that is still starting.
|
|
1000
|
+
*
|
|
1001
|
+
* @param {string} url The Storybook's URL.
|
|
1002
|
+
* @param {number} timeoutMilliseconds How long the request may take.
|
|
1003
|
+
* @param {AbortSignal} [signal] Aborts the request early, which gives `not-ready`.
|
|
1004
|
+
* @returns {Promise<'ready' | 'refused' | 'not-ready'>}
|
|
1005
|
+
*/
|
|
1006
|
+
async function probe(url, timeoutMilliseconds, signal) {
|
|
1007
|
+
const timeout = AbortSignal.timeout(timeoutMilliseconds)
|
|
1008
|
+
|
|
1009
|
+
try {
|
|
1010
|
+
const response = await fetch(indexUrlOf(url), {
|
|
1011
|
+
signal: signal === undefined ? timeout : AbortSignal.any([timeout, signal]),
|
|
1012
|
+
redirect: 'manual',
|
|
1013
|
+
})
|
|
1014
|
+
|
|
1015
|
+
if (response.status !== 200) {
|
|
1016
|
+
await response.body?.cancel()
|
|
1017
|
+
|
|
1018
|
+
return 'not-ready'
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
const index = await response.json()
|
|
1022
|
+
|
|
1023
|
+
return isRecord(index) && isRecord(index.entries) ? 'ready' : 'not-ready'
|
|
1024
|
+
} catch (error) {
|
|
1025
|
+
const cause = error instanceof Error ? /** @type {NodeJS.ErrnoException | undefined} */ (error.cause) : undefined
|
|
1026
|
+
|
|
1027
|
+
return cause?.code === 'ECONNREFUSED' ? 'refused' : 'not-ready'
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
/**
|
|
1032
|
+
* Sleeps `milliseconds`, or less when `signal` aborts.
|
|
1033
|
+
*
|
|
1034
|
+
* @param {number} milliseconds How long to sleep.
|
|
1035
|
+
* @param {AbortSignal} signal Ends the sleep early.
|
|
1036
|
+
* @returns {Promise<void>}
|
|
1037
|
+
*/
|
|
1038
|
+
async function pause(milliseconds, signal) {
|
|
1039
|
+
try {
|
|
1040
|
+
await sleep(milliseconds, undefined, { signal })
|
|
1041
|
+
} catch {
|
|
1042
|
+
// The signal aborted, which ends the sleep: the caller checks why.
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
/**
|
|
1047
|
+
* Starts the Storybook `storybook` with its start command and waits until it answers at its URL. Its tree goes into
|
|
1048
|
+
* `trees`, which stops it. Its output is drained until then, so it never blocks on a full pipe, and its lines are
|
|
1049
|
+
* scanned for the port it started on: another port than its URL's fails the start at once.
|
|
1050
|
+
*
|
|
1051
|
+
* When its tree exits before it answers, something else may serve a Storybook on its port: the start ends `reused` once
|
|
1052
|
+
* that answers. A port that refuses, or nothing that answers before the deadline, fails the start with the end of its
|
|
1053
|
+
* output.
|
|
1054
|
+
*
|
|
1055
|
+
* @param {StorybookRef} storybook The Storybook to start.
|
|
1056
|
+
* @param {Command} command Its start command from `setup.json`.
|
|
1057
|
+
* @param {TreeRegistry} trees The registry that holds its tree.
|
|
1058
|
+
* @param {AbortSignal} signal Aborts the wait on an interrupt or another start's failure.
|
|
1059
|
+
* @returns {Promise<StorybookStart>}
|
|
1060
|
+
*/
|
|
1061
|
+
async function startStorybook(storybook, command, trees, signal) {
|
|
1062
|
+
const startCommand = { argv: storybookArgvOf(command.argv), cwd: command.cwd }
|
|
1063
|
+
|
|
1064
|
+
process.stderr.write(
|
|
1065
|
+
`Starting Storybook ${storybook.name} in ${folderOf(startCommand.cwd)}: ${startCommand.argv.join(' ')}\n`,
|
|
1066
|
+
)
|
|
1067
|
+
|
|
1068
|
+
const startedAt = Date.now()
|
|
1069
|
+
const tree = trees.start(startCommand, 'storybook', storybook.name)
|
|
1070
|
+
const output = watchOutput(tree, portOf(storybook.url))
|
|
1071
|
+
const wait = AbortSignal.any([output.mismatch, signal])
|
|
1072
|
+
|
|
1073
|
+
while (!wait.aborted) {
|
|
1074
|
+
const state = await stateOf(storybook, tree, wait)
|
|
1075
|
+
|
|
1076
|
+
if (state === 'started') {
|
|
1077
|
+
const seconds = ((Date.now() - startedAt) / 1000).toFixed(1)
|
|
1078
|
+
|
|
1079
|
+
process.stderr.write(`Storybook ${storybook.name} answers at ${storybook.url} after ${seconds}s.\n`)
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
if (state === 'started' || state === 'reused') {
|
|
1083
|
+
return { kind: state }
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
if (state === 'exited' || Date.now() - startedAt >= storybookStartTimeoutMilliseconds) {
|
|
1087
|
+
return { kind: 'failed', message: await failedStartOf(storybook, tree, output.tail) }
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
await pause(storybookPollMilliseconds, wait)
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
const startedPort = output.startedPort()
|
|
1094
|
+
|
|
1095
|
+
if (startedPort !== undefined) {
|
|
1096
|
+
return { kind: 'failed', message: portMismatchMessageOf(storybook.name, startedPort, storybook.url) }
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
return { kind: 'aborted' }
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
/**
|
|
1103
|
+
* Drains the output of a Storybook's tree into its tail, and watches its lines for the port it started on.
|
|
1104
|
+
*
|
|
1105
|
+
* @param {Tree} tree The Storybook's tree.
|
|
1106
|
+
* @param {number} expectedPort The port of the Storybook's URL.
|
|
1107
|
+
* @returns {StorybookOutput}
|
|
1108
|
+
*/
|
|
1109
|
+
function watchOutput(tree, expectedPort) {
|
|
1110
|
+
const tail = outputTail(outputTailLimit)
|
|
1111
|
+
const mismatch = new AbortController()
|
|
1112
|
+
|
|
1113
|
+
/** @type {number | undefined} */
|
|
1114
|
+
let startedPort
|
|
1115
|
+
|
|
1116
|
+
/**
|
|
1117
|
+
* Adds a chunk of the output to the tail, and aborts on the first line that names a port other than `expectedPort`.
|
|
1118
|
+
*
|
|
1119
|
+
* @param {string} chunk The chunk.
|
|
1120
|
+
*/
|
|
1121
|
+
const read = (chunk) => {
|
|
1122
|
+
const otherPort = tail
|
|
1123
|
+
.add(chunk)
|
|
1124
|
+
.map(startedPortOf)
|
|
1125
|
+
.find((port) => port !== undefined && port !== expectedPort)
|
|
1126
|
+
|
|
1127
|
+
if (startedPort === undefined && otherPort !== undefined) {
|
|
1128
|
+
startedPort = otherPort
|
|
1129
|
+
mismatch.abort()
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
for (const stream of [tree.child.stdout, tree.child.stderr]) {
|
|
1134
|
+
stream?.setEncoding('utf8')
|
|
1135
|
+
stream?.on('data', read)
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
return { tail, mismatch: mismatch.signal, startedPort: () => startedPort }
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
/**
|
|
1142
|
+
* Where the start of a Storybook stands after one request for its index: its own tree answers (`started`), another
|
|
1143
|
+
* server answers since its tree is gone (`reused`), its tree is gone and nothing listens on its port (`exited`), or
|
|
1144
|
+
* neither yet (`waiting`).
|
|
1145
|
+
*
|
|
1146
|
+
* @param {StorybookRef} storybook The Storybook.
|
|
1147
|
+
* @param {Tree} tree Its tree.
|
|
1148
|
+
* @param {AbortSignal} signal Ends the request early.
|
|
1149
|
+
* @returns {Promise<'started' | 'reused' | 'exited' | 'waiting'>}
|
|
1150
|
+
*/
|
|
1151
|
+
async function stateOf(storybook, tree, signal) {
|
|
1152
|
+
const exitedBefore = tree.hasExited()
|
|
1153
|
+
const answer = await probe(storybook.url, probeTimeoutMilliseconds, signal)
|
|
1154
|
+
|
|
1155
|
+
if (answer === 'ready') {
|
|
1156
|
+
return tree.hasExited() ? 'reused' : 'started'
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
return exitedBefore && answer === 'refused' ? 'exited' : 'waiting'
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
/**
|
|
1163
|
+
* Says why the start of a Storybook failed: its tree exited, or it ran out of time, with the end of its output.
|
|
1164
|
+
*
|
|
1165
|
+
* @param {StorybookRef} storybook The Storybook.
|
|
1166
|
+
* @param {Tree} tree Its tree.
|
|
1167
|
+
* @param {OutputTail} tail The end of its output.
|
|
1168
|
+
* @returns {Promise<string>}
|
|
1169
|
+
*/
|
|
1170
|
+
async function failedStartOf(storybook, tree, tail) {
|
|
1171
|
+
const reason = tree.hasExited() ? { exitCode: await tree.exited } : { timeout: /** @type {const} */ (true) }
|
|
1172
|
+
|
|
1173
|
+
return failedStartMessageOf(storybook.name, reason, indexUrlOf(storybook.url), tail.lines())
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
/**
|
|
1177
|
+
* Starts the Storybooks of `unreachable` in parallel and waits until each answers. The first that fails ends the wait
|
|
1178
|
+
* for the others and prints its message. A Storybook without a start command in `setup.json`, or, on Windows, whose
|
|
1179
|
+
* start command can't be passed, fails them all before any starts. Settles with whether every one answers, its own tree
|
|
1180
|
+
* or another server in its place.
|
|
1181
|
+
*
|
|
1182
|
+
* @param {StorybookRef[]} unreachable The Storybooks to start.
|
|
1183
|
+
* @param {Setup} setup The skill's setup, which holds their start commands.
|
|
1184
|
+
* @param {TreeRegistry} trees The registry that holds their trees.
|
|
1185
|
+
* @param {AbortSignal} interruption Aborts on an interrupt.
|
|
1186
|
+
* @returns {Promise<boolean>}
|
|
1187
|
+
*/
|
|
1188
|
+
async function startStorybooks(unreachable, setup, trees, interruption) {
|
|
1189
|
+
const problems = storybookStartProblems(unreachable, setup)
|
|
1190
|
+
|
|
1191
|
+
if (problems.length > 0) {
|
|
1192
|
+
process.stderr.write(`${problems.join('\n')}\n`)
|
|
1193
|
+
|
|
1194
|
+
return false
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
const failure = new AbortController()
|
|
1198
|
+
const signal = AbortSignal.any([failure.signal, interruption])
|
|
1199
|
+
|
|
1200
|
+
const starts = await Promise.all(
|
|
1201
|
+
unreachable.map(async (storybook) => {
|
|
1202
|
+
const command = /** @type {Command} */ (setup.storybooks[storybook.name])
|
|
1203
|
+
const start = await startStorybook(storybook, command, trees, signal)
|
|
1204
|
+
|
|
1205
|
+
if (start.kind === 'failed') {
|
|
1206
|
+
process.stderr.write(`${start.message}\n`)
|
|
1207
|
+
failure.abort()
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
return start
|
|
1211
|
+
}),
|
|
1212
|
+
)
|
|
1213
|
+
|
|
1214
|
+
return starts.every((start) => start.kind === 'started' || start.kind === 'reused')
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
1218
|
+
// Run: the script's own flow.
|
|
1219
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
1220
|
+
|
|
1221
|
+
/**
|
|
1222
|
+
* Listens for interrupt signals. The first one aborts the watch's signal, a later one changes nothing.
|
|
1223
|
+
*
|
|
1224
|
+
* @returns {InterruptWatch}
|
|
1225
|
+
*/
|
|
1226
|
+
function watchInterrupts() {
|
|
1227
|
+
const controller = new AbortController()
|
|
1228
|
+
|
|
1229
|
+
/** @type {NodeJS.Signals | undefined} */
|
|
1230
|
+
let interruptedBy
|
|
1231
|
+
|
|
1232
|
+
/**
|
|
1233
|
+
* Records the first interrupt signal and aborts what the script waits for.
|
|
1234
|
+
*
|
|
1235
|
+
* @param {NodeJS.Signals} signal The signal the script got.
|
|
1236
|
+
*/
|
|
1237
|
+
const onSignal = (signal) => {
|
|
1238
|
+
if (interruptedBy === undefined) {
|
|
1239
|
+
interruptedBy = signal
|
|
1240
|
+
controller.abort()
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
for (const signal of interruptSignals) {
|
|
1245
|
+
process.on(signal, onSignal)
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
return {
|
|
1249
|
+
signal: controller.signal,
|
|
1250
|
+
interruptedBy: () => interruptedBy,
|
|
1251
|
+
dispose: () => {
|
|
1252
|
+
for (const signal of interruptSignals) {
|
|
1253
|
+
process.off(signal, onSignal)
|
|
1254
|
+
}
|
|
1255
|
+
},
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
/**
|
|
1260
|
+
* Reads the setup and checks that the CLI's argv can be passed on this system. Throws an `Error` whose message says
|
|
1261
|
+
* why the script can't run.
|
|
1262
|
+
*
|
|
1263
|
+
* @param {string[]} args The caller's command and flags.
|
|
1264
|
+
* @returns {Setup}
|
|
1265
|
+
*/
|
|
1266
|
+
function prepare(args) {
|
|
1267
|
+
const setup = readSetup()
|
|
1268
|
+
|
|
1269
|
+
if (windows) {
|
|
1270
|
+
windowsCommandLineOf(cliArgvOf(setup.cli.argv, args))
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
return setup
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
/**
|
|
1277
|
+
* Writes `bytes` on stdout and settles once they are handed to the system, or once stdout fails, such as when the
|
|
1278
|
+
* reader has gone.
|
|
1279
|
+
*
|
|
1280
|
+
* @param {Buffer} bytes What to write.
|
|
1281
|
+
* @returns {Promise<void>}
|
|
1282
|
+
*/
|
|
1283
|
+
function writeStdout(bytes) {
|
|
1284
|
+
return new Promise((resolveWrite) => {
|
|
1285
|
+
if (bytes.length === 0) {
|
|
1286
|
+
resolveWrite()
|
|
1287
|
+
|
|
1288
|
+
return
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
process.stdout.once('error', () => {
|
|
1292
|
+
resolveWrite()
|
|
1293
|
+
})
|
|
1294
|
+
process.stdout.write(bytes, () => {
|
|
1295
|
+
resolveWrite()
|
|
1296
|
+
})
|
|
1297
|
+
})
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
/**
|
|
1301
|
+
* Runs the CLI as the skill's `setup.json` says, with the caller's arguments and the JSON reporter. When the CLI exits
|
|
1302
|
+
* 2 because Storybooks it needs are unreachable, starts those, waits until they answer and runs the CLI once more.
|
|
1303
|
+
* Then stops every tree it started, says which Storybooks the run reused, writes the last CLI run's stdout and sets its
|
|
1304
|
+
* exit code.
|
|
1305
|
+
*
|
|
1306
|
+
* On an interrupt it stops every tree, writes the CLI's stdout so far and exits `128 +` the signal's number. A failure
|
|
1307
|
+
* of the script itself, such as a Storybook that fails to start, goes on stderr and exits 2.
|
|
1308
|
+
*
|
|
1309
|
+
* @param {string[]} args The caller's command and flags.
|
|
1310
|
+
*/
|
|
1311
|
+
async function run(args) {
|
|
1312
|
+
const interrupts = watchInterrupts()
|
|
1313
|
+
|
|
1314
|
+
try {
|
|
1315
|
+
/** @type {Setup} */
|
|
1316
|
+
let setup
|
|
1317
|
+
|
|
1318
|
+
try {
|
|
1319
|
+
setup = prepare(args)
|
|
1320
|
+
} catch (error) {
|
|
1321
|
+
process.stderr.write(`${messageOf(error)}\n`)
|
|
1322
|
+
process.exitCode = 2
|
|
1323
|
+
|
|
1324
|
+
return
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
const trees = treeRegistry(interrupts.signal)
|
|
1328
|
+
|
|
1329
|
+
/** @type {RunOutcome} */
|
|
1330
|
+
let outcome
|
|
1331
|
+
|
|
1332
|
+
/** @type {Set<string>} */
|
|
1333
|
+
let stopped
|
|
1334
|
+
|
|
1335
|
+
try {
|
|
1336
|
+
outcome = await runWithStorybooks(setup, args, trees, interrupts.signal)
|
|
1337
|
+
} finally {
|
|
1338
|
+
stopped = await trees.stopAll()
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
const interruptedBy = interrupts.interruptedBy()
|
|
1342
|
+
const { last, failed } = outcome
|
|
1343
|
+
const report = reportOf(last.stdout.toString())
|
|
1344
|
+
|
|
1345
|
+
if (!failed && interruptedBy === undefined && report?.runError === false) {
|
|
1346
|
+
for (const storybook of report.storybooks.filter((each) => !stopped.has(each.name))) {
|
|
1347
|
+
process.stderr.write(`${reusedLineOf(storybook)}\n`)
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
if (interruptedBy !== undefined) {
|
|
1352
|
+
process.exitCode = exitCodeOf(null, interruptedBy)
|
|
1353
|
+
} else {
|
|
1354
|
+
process.exitCode = failed ? 2 : last.exitCode
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
await writeStdout(last.stdout)
|
|
1358
|
+
} finally {
|
|
1359
|
+
interrupts.dispose()
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
/**
|
|
1364
|
+
* Runs the CLI, and when it exits 2 naming unreachable Storybooks, starts those and runs it once more. Settles with
|
|
1365
|
+
* the last CLI run and whether the script failed. The trees stay running for the caller to stop.
|
|
1366
|
+
*
|
|
1367
|
+
* @param {Setup} setup The skill's setup.
|
|
1368
|
+
* @param {string[]} args The caller's command and flags.
|
|
1369
|
+
* @param {TreeRegistry} trees The registry that holds every tree started.
|
|
1370
|
+
* @param {AbortSignal} interruption Aborts on an interrupt.
|
|
1371
|
+
* @returns {Promise<RunOutcome>}
|
|
1372
|
+
*/
|
|
1373
|
+
async function runWithStorybooks(setup, args, trees, interruption) {
|
|
1374
|
+
const first = await runCli(setup, args, trees)
|
|
1375
|
+
|
|
1376
|
+
if (interruption.aborted) {
|
|
1377
|
+
return { last: first, failed: false }
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
const down = unreachableOf(first)
|
|
1381
|
+
|
|
1382
|
+
if (down.length === 0) {
|
|
1383
|
+
return checkedOutcomeOf(first, [], interruption)
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
if (!(await startStorybooks(down, setup, trees, interruption)) || interruption.aborted) {
|
|
1387
|
+
return { last: first, failed: true }
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
const last = await runCli(setup, args, trees)
|
|
1391
|
+
|
|
1392
|
+
if (interruption.aborted) {
|
|
1393
|
+
return { last, failed: false }
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1396
|
+
return checkedOutcomeOf(last, down, interruption)
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
/**
|
|
1400
|
+
* The Storybooks a CLI run that exited 2 names unreachable. None for any other run.
|
|
1401
|
+
*
|
|
1402
|
+
* @param {CliRun} cliRun The CLI run.
|
|
1403
|
+
* @returns {StorybookRef[]}
|
|
1404
|
+
*/
|
|
1405
|
+
function unreachableOf(cliRun) {
|
|
1406
|
+
if (cliRun.exitCode !== 2) {
|
|
1407
|
+
return []
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
return reportOf(cliRun.stdout.toString())?.unreachable ?? []
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
/**
|
|
1414
|
+
* The outcome of the last CLI run, checked for Storybooks that stopped answering during it, each of which it names on
|
|
1415
|
+
* stderr and which fail the script. The trees the script started still run, so they aren't mistaken for stopped ones.
|
|
1416
|
+
*
|
|
1417
|
+
* @param {CliRun} last The last CLI run.
|
|
1418
|
+
* @param {StorybookRef[]} down The Storybooks the script started or found answering before it.
|
|
1419
|
+
* @param {AbortSignal} interruption Aborts on an interrupt, which stops the Storybooks, so none counts as stopped mid-run.
|
|
1420
|
+
* @returns {Promise<RunOutcome>}
|
|
1421
|
+
*/
|
|
1422
|
+
async function checkedOutcomeOf(last, down, interruption) {
|
|
1423
|
+
const stoppedMidRun = await storybooksStoppedMidRun(last, down, interruption)
|
|
1424
|
+
|
|
1425
|
+
for (const storybook of stoppedMidRun) {
|
|
1426
|
+
process.stderr.write(`${stoppedMidRunMessageOf(storybook)}\n`)
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
return { last, failed: stoppedMidRun.length > 0 }
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
/**
|
|
1433
|
+
* Why the script can't start the Storybooks of `down`: one has no start command in `setup.json`, or, on Windows, its
|
|
1434
|
+
* start command holds an argument that can't be passed. None when it can start them all.
|
|
1435
|
+
*
|
|
1436
|
+
* @param {StorybookRef[]} down The Storybooks to start.
|
|
1437
|
+
* @param {Setup} setup The skill's setup.
|
|
1438
|
+
* @returns {string[]}
|
|
1439
|
+
*/
|
|
1440
|
+
function storybookStartProblems(down, setup) {
|
|
1441
|
+
return down.flatMap((storybook) => {
|
|
1442
|
+
const command = setup.storybooks[storybook.name]
|
|
1443
|
+
|
|
1444
|
+
if (command === undefined) {
|
|
1445
|
+
return [
|
|
1446
|
+
`setup.json has no start command for Storybook ${storybook.name}. Run visual-check init again to refresh it.`,
|
|
1447
|
+
]
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1450
|
+
if (!windows) {
|
|
1451
|
+
return []
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
try {
|
|
1455
|
+
windowsCommandLineOf(storybookArgvOf(command.argv))
|
|
1456
|
+
|
|
1457
|
+
return []
|
|
1458
|
+
} catch (error) {
|
|
1459
|
+
return [messageOf(error)]
|
|
1460
|
+
}
|
|
1461
|
+
})
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
/**
|
|
1465
|
+
* The Storybooks that stopped answering during the last CLI run. When it exits 2, those of `down`, which the script
|
|
1466
|
+
* started or found answering, that its report names unreachable. When it exits 1 without a run error, those of its
|
|
1467
|
+
* report that now refuse connections: stories failed because their Storybook went. None when it exits 0, since every
|
|
1468
|
+
* snapshot passed. None after an interrupt either, which stops the Storybooks the script started.
|
|
1469
|
+
*
|
|
1470
|
+
* @param {CliRun} last The last CLI run.
|
|
1471
|
+
* @param {StorybookRef[]} down The Storybooks the script started or found answering before it.
|
|
1472
|
+
* @param {AbortSignal} interruption Aborts on an interrupt.
|
|
1473
|
+
* @returns {Promise<StorybookRef[]>}
|
|
1474
|
+
*/
|
|
1475
|
+
async function storybooksStoppedMidRun(last, down, interruption) {
|
|
1476
|
+
const report = reportOf(last.stdout.toString())
|
|
1477
|
+
|
|
1478
|
+
if (report === undefined) {
|
|
1479
|
+
return []
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
if (last.exitCode === 2) {
|
|
1483
|
+
return report.unreachable.filter((storybook) => down.some((each) => each.name === storybook.name))
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
if (last.exitCode !== 1 || report.runError) {
|
|
1487
|
+
return []
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1490
|
+
const answers = await Promise.all(
|
|
1491
|
+
report.storybooks.map((storybook) => probe(storybook.url, probeTimeoutMilliseconds, interruption)),
|
|
1492
|
+
)
|
|
1493
|
+
|
|
1494
|
+
if (interruption.aborted) {
|
|
1495
|
+
return []
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
return report.storybooks.filter((_storybook, index) => answers[index] === 'refused')
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1501
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
1502
|
+
// Entry: runs only when this file is the process's entry, so importing it runs nothing.
|
|
1503
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
1504
|
+
|
|
1505
|
+
/**
|
|
1506
|
+
* Whether this file is the process's entry.
|
|
1507
|
+
*
|
|
1508
|
+
* @returns {boolean}
|
|
1509
|
+
*/
|
|
1510
|
+
function isEntry() {
|
|
1511
|
+
try {
|
|
1512
|
+
return realpathSync(process.argv[1] ?? '') === scriptPath
|
|
1513
|
+
} catch {
|
|
1514
|
+
return false
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1518
|
+
if (isEntry()) {
|
|
1519
|
+
if (process.argv[2] === keepTreeFlag) {
|
|
1520
|
+
keepTree(/** @type {Command} */ (JSON.parse(process.argv[3] ?? '')), process.env)
|
|
1521
|
+
} else {
|
|
1522
|
+
try {
|
|
1523
|
+
await run(process.argv.slice(2))
|
|
1524
|
+
} catch (error) {
|
|
1525
|
+
// A fault of the script itself. `run` has stopped every tree it started by now.
|
|
1526
|
+
process.stderr.write(
|
|
1527
|
+
`The runner script failed: ${error instanceof Error ? (error.stack ?? error.message) : String(error)}\n`,
|
|
1528
|
+
)
|
|
1529
|
+
process.exitCode = 2
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
}
|