Skip to content

Commit

Permalink
fix(storybook): parse package names out of addons array
Browse files Browse the repository at this point in the history
`addons` array can contain not only package names directly, but also nested paths to addon files within a package. Running the addons array through requirePackageName fixes that
  • Loading branch information
miluoshi committed Aug 22, 2023
1 parent fe84f6a commit db9fef3
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/parser/storybook.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ const { tryRequire } = require('../utils');
export default function storybookParser(filePath) {
const foundDeps = [];
const config = tryRequire(filePath);
const { addons, core, framework, typescript } = config;
const { addons = [], core, framework, typescript } = config;
if (typeof framework === 'string') {
foundDeps.push(framework);
}
if (Array.isArray(addons)) {
foundDeps.push(...addons);
}

foundDeps.push(...addons.map(requirePackageName));

if (core) {
const { builder } = core;
if (builder === 'webpack5') {
Expand Down
2 changes: 1 addition & 1 deletion test/fake_modules/storybook/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
'../packages/**/src/**/*.stories.@(js|ts|jsx|tsx|mdx)',
],
features: {},
addons: ['@storybook/addon-essentials', '@storybook/addon-links'],
addons: ['@storybook/addon-essentials', '@storybook/addon-links', '@nx/react/plugins/storybook'],
typescript: {
check: false,
checkOptions: {},
Expand Down
1 change: 1 addition & 0 deletions test/fake_modules/storybook/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "storybook",
"devDependencies": {
"@nx/react": "*",
"@storybook/react": "*",
"@storybook/addon-essentials": "*",
"@storybook/addon-unused": "*",
Expand Down
1 change: 1 addition & 0 deletions test/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,7 @@ export default [
'@storybook/manager-webpack5': ['.storybook/main.js'],
},
using: {
'@nx/react': ['.storybook/main.js'],
'@storybook/addon-essentials': ['.storybook/main.js'],
'@storybook/addon-links': ['.storybook/main.js'],
'@storybook/builder-webpack5': ['.storybook/main.js'],
Expand Down

0 comments on commit db9fef3

Please sign in to comment.