Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Monorepo getAbsolutePath results in broken project.json #29664

Open
shilman opened this issue Nov 19, 2024 · 0 comments
Open

[Bug]: Monorepo getAbsolutePath results in broken project.json #29664

shilman opened this issue Nov 19, 2024 · 0 comments

Comments

@shilman
Copy link
Member

shilman commented Nov 19, 2024

Describe the bug

Currently Storybook's project.json reports the addons that are listed in .storybook/main.ts. It does this by calling getActualPacakgeVersion on each of the addons:

https://github.com/storybookjs/storybook/blob/next/code/core/src/telemetry/package-json.ts

However, in monorepos we recommend using absolute paths with the following pattern:

import { dirname, join } from 'node:path';

const getAbsolutePath = <I extends string>(input: I): I =>
  dirname(require.resolve(join(input, 'package.json'))) as any;

const config: StorybookConfig = {
  stories: ['../stories/**/*.mdx', '../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
  addons: [
    getAbsolutePath('@storybook/addon-onboarding'),
    getAbsolutePath('@storybook/addon-essentials'),
    getAbsolutePath('@chromatic-com/storybook'),
  ]
},

This generates addon entries like the following:

info     "addons": {
info       "$SNIP/node_modules/.pnpm/@storybook+addon-onboarding@8.5.0-alpha.8_react@18.3.1_storybook@8.5.0-alpha.8/node_modules/@storybook/addon-onboarding": {
info         "version": null
info       },
info       "$SNIP/node_modules/.pnpm/@storybook+addon-essentials@8.5.0-alpha.8_@types+react@18.3.12_storybook@8.5.0-alpha.8/node_modules/@storybook/addon-essentials": {
info         "version": null
info       },
info       "$SNIP/node_modules/.pnpm/@chromatic-com+storybook@3.2.2_react@18.3.1_storybook@8.5.0-alpha.8/node_modules/@chromatic-com/storybook": {
info         "version": null
info       },

Instead, it should produce:

info     "addons": {
info       "@storybook/addon-onboarding": {
info         "version": "8.5.0-alpha.8"
info       },
info       "@storybook/addon-essentials": {
info         "version": "8.5.0-alpha.8"
info       },
info       "@chromatic-com/storybook": {
info         "version": "3.2.2"
info       },

Reproduction link

N/A

Reproduction steps

See above

System

Any

Additional context

No response

@shilman shilman changed the title [Bug]: getAbsolutePath results in broken project.json [Bug]: Monorepo getAbsolutePath results in broken project.json Nov 19, 2024
@yannbf yannbf moved this to Empathy Backlog in Core Team Projects Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Empathy Backlog
Development

No branches or pull requests

1 participant