UNPKG

storybook

Version:

Storybook: Develop, document, and test UI components in isolation

105 lines (99 loc) 4.33 kB
import CJS_COMPAT_NODE_URL_qjinduibsyq from 'node:url'; import CJS_COMPAT_NODE_PATH_qjinduibsyq from 'node:path'; import CJS_COMPAT_NODE_MODULE_qjinduibsyq from "node:module"; var __filename = CJS_COMPAT_NODE_URL_qjinduibsyq.fileURLToPath(import.meta.url); var __dirname = CJS_COMPAT_NODE_PATH_qjinduibsyq.dirname(__filename); var require = CJS_COMPAT_NODE_MODULE_qjinduibsyq.createRequire(import.meta.url); // ------------------------------------------------------------ // end of CJS compatibility banner, injected by Storybook's esbuild configuration // ------------------------------------------------------------ // src/cli/tools/sdk/attach-messages.ts var RESTART_GUIDANCE = "From your project directory, restart Storybook (for example `npx storybook dev`) and re-run this command from there."; function formatNoInstance(records) { let lines = [ "No running Storybook was found for this project. Start it first (for example `npm run storybook`), then retry with `--attach`." ]; if (records.length > 0) { lines.push( "", "Running Storybook instances that did not match this project \u2014 target one by re-running this command from its project directory, or with `--config-dir <dir>`:" ); for (let record of records) { let configDir = record.configDir ? `; configDir \`${record.configDir}\`` : ""; lines.push(`- ${record.url} (cwd \`${record.cwd}\`${configDir})`); } } return lines.join(` `); } function formatPortMismatch(port, candidates) { let lines = [ `No running Storybook instance is on port ${port}. Retry with one of the running instances below, or omit \`--port\` to match on the project's cwd/config dir instead:` ]; for (let record of candidates) lines.push(`- ${record.url} (port \`${record.port}\`, cwd \`${record.cwd}\`)`); return lines.join(` `); } function formatOldServer(version) { return `Restart Storybook (v${version}+) to enable attach. The running instance was started with an older Storybook that does not publish a channel token.`; } function formatConnectionFailed(record) { return `Could not connect to the Storybook at ${record.url}. The instance registry may be stale \u2014 if that Storybook is no longer running, start it again (for example \`npm run storybook\`) and retry.`; } function formatInstallationMismatch({ callerPath, callerVersion, instancePath, instanceVersion, configDir }) { let instanceConfigDir = configDir ? `; config dir \`${configDir}\`` : ""; return [ "The running Storybook and this CLI are different `storybook` installations:", `- running instance: \`${instancePath}\` (version ${instanceVersion ?? "unknown"}${instanceConfigDir})`, `- this CLI: \`${callerPath}\` (version ${callerVersion})`, `They must be the same installation. ${RESTART_GUIDANCE}` ].join(` `); } function formatUnknownInstallation() { return `Could not verify that the running Storybook and this CLI are the same \`storybook\` installation. ${RESTART_GUIDANCE}`; } function formatAttachFallback(remediation) { return `${remediation} Falling back to loading this project's Storybook configuration.`; } function formatMultiInstanceNotice(storybook) { let lines = [ `Warning: Multiple Storybook instances match this project. This command used ${storybook.url ?? "the selected instance"}${instanceDetails(storybook)}.`, "", "Other matching instances \u2014 target one with `--port <port>`:" ]; for (let sibling of storybook.siblings ?? []) lines.push(`- ${sibling.url}${instanceDetails(sibling)}`); return lines.push( "", "If results look unexpected, ask the user whether they want to stop the other instance(s)." ), lines.join(` `); } function instanceDetails(instance) { let details = [ instance.port != null ? `port \`${instance.port}\`` : null, instance.pid != null ? `pid \`${instance.pid}\`` : null, instance.cwd ? `cwd \`${instance.cwd}\`` : null, instance.configDir ? `config dir \`${instance.configDir}\`` : null ].filter((detail) => detail != null); return details.length > 0 ? ` (${details.join(", ")})` : ""; } export { formatNoInstance, formatPortMismatch, formatOldServer, formatConnectionFailed, formatInstallationMismatch, formatUnknownInstallation, formatAttachFallback, formatMultiInstanceNotice };