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

entry configuration isn't being overwritten in Storybook plugin #289

Closed
chrisvltn opened this issue Oct 11, 2023 · 6 comments
Closed

entry configuration isn't being overwritten in Storybook plugin #289

chrisvltn opened this issue Oct 11, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@chrisvltn
Copy link
Contributor

In our project we're storing Storybook-related files in a non-standard directory (usually .storybook), and have this set in the storybook settings in knip.js

storybook: {
  config: ['components/storybook/{main,manager}.ts'],
  entry: [
    'components/storybook/preview.{js,jsx,ts,tsx}',
    'components/**/*.stories.{js,jsx,ts,tsx,mdx}',
  ],
  project: ['components/**/*.{js,jsx,ts,tsx}'],
}

Sadly, since version 2.32.0, knip started pointing out a few dependencies that are actually being imported and used in the preview file

@chrisvltn chrisvltn added the bug Something isn't working label Oct 11, 2023
@webpro
Copy link
Collaborator

webpro commented Oct 11, 2023

What does --debug give you for this workspace config?

Do you have a public repo maybe?

@chrisvltn
Copy link
Contributor Author

I created the repo with only the basics to reproduce the issue: https://github.com/chrisvltn/knip-storybook-issue-example

When running npm run storybook:dev we see Storybook is properly working.

When running npm run knip, we see the following report:

Unused files (1)
components/storybook/preview.tsx
Unused devDependencies (2)
@storybook/blocks  package.json
@storybook/types   package.json

components/storybook/preview.tsx is being used by Storybook. The blocks and types packages are being used by preview.tsx.

When running npm run knip -- --debug, we see the following report:

Output
> knip-storybook-issue@1.0.0 knip
> knip --debug

[knip] Unresolved configuration (from CLI arguments)
{
  cwd: '/PROJECT_PATH/knip-storybook-issue',
  tsConfigFile: undefined,
  gitignore: true,
  isProduction: false,
  isStrict: false,
  isIgnoreInternal: false,
  isShowProgress: false,
  isIncludeEntryExports: false
}
[knip] Included workspaces
[ 'knip-storybook-issue' ]
[knip] Included workspace configs
[
  {
    name: '.',
    pkgName: 'knip-storybook-issue',
    config: {
      entry: [],
      project: [ '**/*.{js,mjs,cjs,jsx,ts,tsx,mts,cts}!' ],
      paths: {},
      ignore: [],
      ignoreBinaries: [],
      ignoreDependencies: [],
      storybook: {
        config: [ 'components/storybook/{main,manager}.ts' ],
        entry: [
          'components/storybook/preview.{js,jsx,ts,tsx}',
          'components/**/*.stories.{js,jsx,ts,tsx,mdx}'
        ],
        project: [ 'components/**/*.{js,jsx,ts,tsx}' ]
      }
    },
    ancestors: []
  }
]
[knip] Enabled plugins (.)
[ 'Storybook', 'TypeScript' ]
[knip] Found definition paths (.) (0)
[]
[knip] Globbing (.)
{
  cwd: '/PROJECT_PATH/knip-storybook-issue',
  globPatterns: [ 'index.js' ],
  ignorePatterns: [ '**/node_modules/**', '.yarn' ]
}
[knip] Found entry paths in package.json (.) (0)
[]
[knip] Found Storybook config file paths (2)
[
  '/PROJECT_PATH/knip-storybook-issue/components/storybook/main.ts',
  '/PROJECT_PATH/knip-storybook-issue/components/storybook/manager.ts'
]
[knip] Dependencies referenced in Storybook (7)
[
  '@storybook/addon-designs',
  '@storybook/addon-essentials',
  '@storybook/addon-links',
  '@storybook/addon-styling',
  '@storybook/react-vite',
  'entry:**/*.stories.{js,jsx,ts,tsx}',
  'entry:.storybook/preview.{js,jsx,ts,tsx}'
]
[knip] Found TypeScript config file paths (1)
[ '/PROJECT_PATH/knip-storybook-issue/tsconfig.json' ]
[knip] Dependencies referenced in TypeScript (0)
[]
[knip] Found entry paths (.) (0)
[]
[knip] Globbing (.)
{
  cwd: '/PROJECT_PATH/knip-storybook-issue',
  globPatterns: [
    '**/*.{js,mjs,cjs,jsx,ts,tsx,mts,cts}',
    '!components/storybook/{main,manager}.ts',
    '!tsconfig.json',
    '!tsconfig.*.json',
    '!components/**/*.{js,jsx,ts,tsx}'
  ],
  ignorePatterns: [ '**/node_modules/**', '.yarn' ]
}
[knip] Found project paths (.) (1)
[ '/PROJECT_PATH/knip-storybook-issue/knip.js' ]
[knip] Globbing (.)
{
  cwd: '/PROJECT_PATH/knip-storybook-issue',
  globPatterns: [
    '**/*.stories.{js,jsx,ts,tsx}',
    '.storybook/preview.{js,jsx,ts,tsx}'
  ],
  ignorePatterns: [ '**/node_modules/**', '.yarn' ]
}
[knip] Found plugin entry paths (.) (1)
[
  '/PROJECT_PATH/knip-storybook-issue/components/app/Button/Button.stories.tsx'
]
[knip] Globbing (.)
{
  cwd: '/PROJECT_PATH/knip-storybook-issue',
  globPatterns: [ 'components/**/*.{js,jsx,ts,tsx}' ],
  ignorePatterns: [ '**/node_modules/**', '.yarn' ]
}
[knip] Found plugin project paths (.) (5)
[
  '/PROJECT_PATH/knip-storybook-issue/components/app/Button/Button.stories.tsx',
  '/PROJECT_PATH/knip-storybook-issue/components/app/Button/index.tsx',
  '/PROJECT_PATH/knip-storybook-issue/components/storybook/main.ts',
  '/PROJECT_PATH/knip-storybook-issue/components/storybook/manager.ts',
  '/PROJECT_PATH/knip-storybook-issue/components/storybook/preview.tsx'
]
[knip] Globbing (.)
{
  cwd: '/PROJECT_PATH/knip-storybook-issue',
  globPatterns: [
    'tsconfig.*.json',
    'tsconfig.json',
    'components/storybook/{main,manager}.ts'
  ],
  ignorePatterns: [ '**/node_modules/**', '.yarn' ]
}
[knip] Found plugin configuration paths (.) (3)
[
  '/PROJECT_PATH/knip-storybook-issue/components/storybook/main.ts',
  '/PROJECT_PATH/knip-storybook-issue/components/storybook/manager.ts',
  '/PROJECT_PATH/knip-storybook-issue/tsconfig.json'
]
[knip] Installed 1 principals for 1 workspaces
[knip] Analyzing used resolved files [P1/1] (5)
[
  '/PROJECT_PATH/knip-storybook-issue/components/app/Button/Button.stories.tsx',
  '/PROJECT_PATH/knip-storybook-issue/components/app/Button/index.tsx',
  '/PROJECT_PATH/knip-storybook-issue/components/storybook/main.ts',
  '/PROJECT_PATH/knip-storybook-issue/components/storybook/manager.ts',
  '/PROJECT_PATH/knip-storybook-issue/knip.js'
]
Unused files (1)
components/storybook/preview.tsx
Unused devDependencies (2)
@storybook/blocks  package.json
@storybook/types   package.json

@webpro webpro closed this as completed in 7488701 Oct 12, 2023
@webpro
Copy link
Collaborator

webpro commented Oct 12, 2023

🚀 This issue has been resolved in v2.33.2. See Release 2.33.2 for release notes.

@webpro
Copy link
Collaborator

webpro commented Oct 12, 2023

Thanks @chrisvltn! The repro helped a lot, very useful.

@webpro
Copy link
Collaborator

webpro commented Oct 12, 2023

Oh almost forgot, the config for Storybook can now be simplified a bit to this:

const config = {
  storybook: {
    config: 'components/storybook/main.ts',
    entry: 'components/storybook/{manager,preview}.{ts,tsx}'
  }
};

@chrisvltn
Copy link
Contributor Author

Amazing! Thank you for the quick fix :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants