Skip to content

Commit

Permalink
Remove reactOptions & angularOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
shilman committed Apr 26, 2022
1 parent 3c49831 commit 5e160ee
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 78 deletions.
14 changes: 14 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- [From version 6.5.x to 7.0.0](#from-version-65x-to-700)
- [Breaking changes](#breaking-changes)
- [Framework field mandatory](#framework-field-mandatory)
- [frameworkOptions renamed](#frameworkoptions-renamed)
- [From version 6.4.x to 6.5.0](#from-version-64x-to-650)
- [React18 new root API](#react18-new-root-api)
- [Deprecated register.js](#deprecated-registerjs)
Expand Down Expand Up @@ -209,6 +210,19 @@

In 6.4 we introduced a new `main.js` field called [`framework`](#mainjs-framework-field). Starting in 7.0, this field is mandatory.

#### frameworkOptions renamed

In 7.0, the `main.js` fields `reactOptions` and `angularOptions` have been renamed. They are now options on the `framework` field:

```js
module.exports = {
framework: {
name: '@storybook/react',
options: { fastRefresh: true };
}
}
```

## From version 6.4.x to 6.5.0

### React18 new root API
Expand Down
11 changes: 4 additions & 7 deletions app/angular/src/server/framework-preset-angular-ivy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Configuration } from 'webpack';
import * as path from 'path';
import type { Preset } from '@storybook/core-common';

import type { PresetOptions } from './preset-options';
import type { AngularOptions } from '../types';

/**
* Source : https://github.com/angular/angular-cli/blob/ebccb5de4a455af813c5e82483db6af20666bdbd/packages/angular_devkit/build_angular/src/utils/load-esm.ts#L23
Expand Down Expand Up @@ -48,13 +50,8 @@ export const runNgcc = async () => {
};

export const webpack = async (webpackConfig: Configuration, options: PresetOptions) => {
const angularOptions = await options.presets.apply(
'angularOptions',
{} as {
enableIvy?: boolean;
},
options
);
const framework = await options.presets.apply<Preset>('framework');
const angularOptions = (typeof framework === 'object' ? framework.options : {}) as AngularOptions;

// Default to true, if undefined
if (angularOptions.enableIvy === false) {
Expand Down
16 changes: 13 additions & 3 deletions app/angular/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import type { StorybookConfig as BaseConfig } from '@storybook/core-common';

export interface AngularOptions {
enableIvy: boolean;
}

/**
* The interface for Storybook configuration in `main.ts` files.
*/
export interface StorybookConfig extends BaseConfig {
angularOptions?: {
enableIvy: boolean;
};
framework:
| string
| {
name: '@storybook/angular';
options: AngularOptions;
};
}
37 changes: 10 additions & 27 deletions app/react/src/server/framework-preset-react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,18 @@ import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
import type { Configuration } from 'webpack';

import { logger } from '@storybook/node-logger';
import type { Options } from '@storybook/core-common';
import type { Options, Preset } from '@storybook/core-common';
import type { ReactOptions } from '../types';

export async function babel(config: TransformOptions, options: Options) {
const useFastRefresh = async (options: Options) => {
const isDevelopment = options.configType === 'DEVELOPMENT';
const reactOptions = await options.presets.apply(
'reactOptions',
{} as {
fastRefresh?: boolean;
},
options
);
const fastRefreshEnabled =
isDevelopment && (reactOptions.fastRefresh || process.env.FAST_REFRESH === 'true');
const framework = await options.presets.apply<Preset>('framework');
const reactOptions = (typeof framework === 'object' ? framework.options : {}) as ReactOptions;
return isDevelopment && (reactOptions.fastRefresh || process.env.FAST_REFRESH === 'true');
};

if (!fastRefreshEnabled) {
return config;
}
export async function babel(config: TransformOptions, options: Options) {
if (!(await useFastRefresh(options))) return config;

return {
...config,
Expand Down Expand Up @@ -59,20 +54,8 @@ export async function babelDefault(config: TransformOptions): Promise<TransformO
}

export async function webpackFinal(config: Configuration, options: Options) {
const isDevelopment = options.configType === 'DEVELOPMENT';
const reactOptions = await options.presets.apply(
'reactOptions',
{} as {
fastRefresh?: boolean;
},
options
);
const fastRefreshEnabled =
isDevelopment && (reactOptions.fastRefresh || process.env.FAST_REFRESH === 'true');
if (!(await useFastRefresh(options))) return config;

if (!fastRefreshEnabled) {
return config;
}
// matches the name of the plugin in CRA.
const hasReactRefresh = config.plugins.find((p) => p.constructor.name === 'ReactRefreshPlugin');

Expand Down
26 changes: 26 additions & 0 deletions app/react/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { StorybookConfig as BaseConfig } from '@storybook/core-common';

export interface ReactOptions {
fastRefresh?: boolean;
strictMode?: boolean;
/**
* Use React's legacy root API to mount components
* @description
* React has introduced a new root API with React 18.x to enable a whole set of new features (e.g. concurrent features)
* If this flag is true, the legacy Root API is used to mount components to make it easier to migrate step by step to React 18.
* @default false
*/
legacyRootApi?: boolean;
}

/**
* The interface for Storybook configuration in `main.ts` files.
*/
export interface StorybookConfig extends BaseConfig {
framework:
| string
| {
name: '@storybook/react';
options: ReactOptions;
};
}
1 change: 1 addition & 0 deletions app/react/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './dist/ts3.9/types/index.d';
19 changes: 0 additions & 19 deletions app/react/types/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion app/vue3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
}
},
"files": [
"bin/**/*",
"dist/**/*",
"README.md",
"*.js",
Expand Down
23 changes: 15 additions & 8 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ module.exports = {
addons: [
/* ... */
],
angularOptions: {
enableIvy: false,
framework: {
name: '@storybook/angular',
options: {
enableIvy: false,
},
},
};
```
Expand Down Expand Up @@ -73,8 +76,11 @@ FAST_REFRESH=true

```js
module.exports = {
reactOptions: {
fastRefresh: true,
framework: {
name: '@storybook/react',
options: {
fastRefresh: true,
},
},
};
```
Expand Down Expand Up @@ -145,8 +151,8 @@ With the release of version 6.0, we updated our documentation as well. That does

We're only covering versions 5.3 and 5.0 as they were important milestones for Storybook. If you want to go back in time a little more, you'll have to check the specific release in the monorepo.

| Section | Page | Current Location | Version 5.3 location | Version 5.0 location |
|------------------|-------------------------------------------|------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|
| Section | Page | Current Location | Version 5.3 location | Version 5.0 location |
| ---------------- | ----------------------------------------- | --------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Get started | Install | [See current documentation](./get-started/install.md) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/guides/quick-start-guide) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/guides/quick-start-guide) |
| | What's a story | [See current documentation](./get-started/whats-a-story.md) | [See versioned documentation for your framework](https://github.com/storybookjs/storybook/blob/release/5.3/docs/src/pages/guides) | [See versioned documentation for your framework](https://github.com/storybookjs/storybook/blob/release/5.0/docs/src/pages/guides) |
| | Browse Stories | [See current documentation](./get-started/browse-stories.md) | [See versioned documentation for your framework](https://github.com/storybookjs/storybook/blob/release/5.3/docs/src/pages/guides) | [See versioned documentation for your framework](https://github.com/storybookjs/storybook/blob/release/5.0/docs/src/pages/guides) |
Expand All @@ -161,7 +167,7 @@ We're only covering versions 5.3 and 5.0 as they were important milestones for S
| | MDX | [See current documentation](./writing-docs/mdx.md) | See versioned addon documentation | Non existing feature or undocumented |
| | Doc Blocks/Argstable | [See current documentation](./writing-docs/doc-block-argstable.md) | [See versioned addon documentation](https://github.com/storybookjs/storybook/tree/release/5.3/addons/docs/) | Non existing feature or undocumented |
| | Doc Blocks/Canvas | [See current documentation](./writing-docs/doc-block-canvas.md) | [See versioned addon documentation](https://github.com/storybookjs/storybook/tree/release/5.3/addons/docs/) | Non existing feature or undocumented |
| | Doc Blocks/Color Palette | [See current documentation](./writing-docs/doc-block-colorpalette.md) | [See versioned addon documentation](https://github.com/storybookjs/storybook/tree/release/5.3/addons/docs/) | Non existing feature or undocumented |
| | Doc Blocks/Color Palette | [See current documentation](./writing-docs/doc-block-colorpalette.md) | [See versioned addon documentation](https://github.com/storybookjs/storybook/tree/release/5.3/addons/docs/) | Non existing feature or undocumented |
| | Doc Blocks/Description | [See current documentation](./writing-docs/doc-block-description.md) | [See versioned addon documentation](https://github.com/storybookjs/storybook/tree/release/5.3/addons/docs/) | Non existing feature or undocumented |
| | Doc Blocks/Icon Gallery | [See current documentation](./writing-docs/doc-block-icongallery.md) | [See versioned addon documentation](https://github.com/storybookjs/storybook/tree/release/5.3/addons/docs/) | Non existing feature or undocumented |
| | Doc Blocks/Source | [See current documentation](./writing-docs/doc-block-source.md) | [See versioned addon documentation](https://github.com/storybookjs/storybook/tree/release/5.3/addons/docs/) | Non existing feature or undocumented |
Expand Down Expand Up @@ -203,9 +209,10 @@ We're only covering versions 5.3 and 5.0 as they were important milestones for S
| | Addons API | [See current documentation](./addons/addons-api.md) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/addons/api) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/addons/api) |
| API | Stories/Component Story Format | [See current documentation](./api/csf.md) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/formats/component-story-format) | Non existing feature or undocumented |
| | Stories/MDX syntax | [See current documentation](./api/mdx.md) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/formats/mdx-syntax) | Non existing feature or undocumented |
| | Stories/StoriesOF format (see note below) | [See current documentation](../lib/core/docs/storiesOf.md) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/formats/storiesof-api) | Non existing feature or undocumented |
| | Stories/StoriesOF format (see note below) | [See current documentation](../lib/core/docs/storiesOf.md) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/formats/storiesof-api) | Non existing feature or undocumented |
| | Frameworks | [See current documentation](./api/new-frameworks.md) | Non existing feature or undocumented | Non existing feature or undocumented |
| | CLI options | [See current documentation](./api/cli-options.md) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/configurations/cli-options) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/configurations/cli-options) |
<div class="aside">
With the release of version 5.3, we've updated how you can write your stories more compactly and easily. It doesn't mean that the <code>storiesOf</code> format has been removed. For the time being, we're still supporting it, and we have documentation for it. But be advised that this is bound to change in the future.
</div>
Expand Down
10 changes: 6 additions & 4 deletions examples/angular-cli/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ module.exports = {
core: {
builder: 'webpack4',
},
angularOptions: {
enableIvy: true,
},
// These are just here to test composition. They could be added to any storybook example project
refs: {
react: {
Expand All @@ -44,5 +41,10 @@ module.exports = {
buildStoriesJson: true,
breakingChangesV7: true,
},
framework: '@storybook/angular',
framework: {
name: '@storybook/angular',
options: {
enableIvy: true,
},
},
};
Loading

0 comments on commit 5e160ee

Please sign in to comment.