Skip to content

Commit

Permalink
Storybook: Fix CSF parsing error (#98231)
Browse files Browse the repository at this point in the history
* Storybook: Fix CSF parsing error

* Update readme
  • Loading branch information
mirka authored Jan 13, 2025
1 parent 9eea835 commit 1ceb527
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ storybookConfig.previewHead = ( head ) => `
</script>
`;

module.exports = storybookConfig;
module.exports = { ...storybookConfig };
11 changes: 9 additions & 2 deletions packages/calypso-storybook/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ Default config for Storybook

## Usage

Create a file `./.storybook/main.js` in your package with this content
Create a file `./.storybook/main.js` in your package with this content:

```
```js
const storybookDefaultConfig = require( '@automattic/calypso-storybook' );
module.exports = { ...storybookDefaultConfig() };
```

Note that the default export must be statically analyzable as an object expression, in order to avoid a [CSF parsing error](https://github.com/storybookjs/storybook/issues/26778) from Storybook.

```js
// ❌ This will cause a CSF parsing error
module.exports = storybookDefaultConfig();
```
3 changes: 2 additions & 1 deletion packages/components/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
module.exports = require( '@automattic/calypso-storybook' )();
const storybookDefaultConfig = require( '@automattic/calypso-storybook' );
module.exports = { ...storybookDefaultConfig() };
14 changes: 8 additions & 6 deletions packages/composite-checkout/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const { join } = require( 'path' );
const storybookDefaultConfig = require( '@automattic/calypso-storybook' );

module.exports = storybookDefaultConfig( {
stories: [ '../demo' ],
webpackAliases: {
'@automattic/composite-checkout': join( __dirname, '../src/public-api.ts' ),
},
} );
module.exports = {
...storybookDefaultConfig( {
stories: [ '../demo' ],
webpackAliases: {
'@automattic/composite-checkout': join( __dirname, '../src/public-api.ts' ),
},
} ),
};
20 changes: 11 additions & 9 deletions packages/plans-grid-next/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const storybookDefaultConfig = require( '@automattic/calypso-storybook' );

module.exports = storybookDefaultConfig( {
staticDirs: [ '../static' ],
webpackAliases: {
// We are mocking wpcom-proxy-request because calls to wpcomRequest() (eg. inside the
// usePlans hook) are not working with MSW. This is a temporary workaround until we can
// figure out why.
[ 'wpcom-proxy-request' ]: require.resolve( '../src/__mocks__/wpcom-proxy-request.js' ),
},
} );
module.exports = {
...storybookDefaultConfig( {
staticDirs: [ '../static' ],
webpackAliases: {
// We are mocking wpcom-proxy-request because calls to wpcomRequest() (eg. inside the
// usePlans hook) are not working with MSW. This is a temporary workaround until we can
// figure out why.
[ 'wpcom-proxy-request' ]: require.resolve( '../src/__mocks__/wpcom-proxy-request.js' ),
},
} ),
};
2 changes: 1 addition & 1 deletion packages/privacy-toolset/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const storybookDefaultConfig = require( '@automattic/calypso-storybook' );

module.exports = storybookDefaultConfig();
module.exports = { ...storybookDefaultConfig() };
16 changes: 9 additions & 7 deletions packages/search/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ const webpack = require( 'webpack' );
const path = require( 'path' );
const storybookDefaultConfig = require( '@automattic/calypso-storybook' );

module.exports = storybookDefaultConfig( {
plugins: [
new webpack.ProvidePlugin( {
process: 'process/browser.js',
} ),
],
} );
module.exports = {
...storybookDefaultConfig( {
plugins: [
new webpack.ProvidePlugin( {
process: 'process/browser.js',
} ),
],
} ),
};

0 comments on commit 1ceb527

Please sign in to comment.