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

Core: Add simplified manager.js/preview.js API for addons #17755

Merged
merged 59 commits into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
7aff6df
rename /register to /manager
ndelangen Mar 18, 2022
f5e8483
change the presets resolutions so we can have preview & manager files…
ndelangen Mar 18, 2022
7300670
change background to use new structure
ndelangen Mar 18, 2022
ec87967
add deprecation message to register file in addon-docs
ndelangen Mar 18, 2022
2288a26
change a11y to new structure
ndelangen Mar 18, 2022
fd79ffb
change addon-actions to new structure
ndelangen Mar 18, 2022
ec120ad
change addon-controls to new structure
ndelangen Mar 18, 2022
abf1b0b
change addon-viewport to new structure
ndelangen Mar 18, 2022
5c1ffe7
remove unused file
ndelangen Mar 18, 2022
f1220de
change addon-jest to new structure
ndelangen Mar 18, 2022
0953a47
change addon-toolbars to new structure
ndelangen Mar 18, 2022
3de6aa7
change addon-outline to new structure
ndelangen Mar 18, 2022
2cbae9a
change addon-links to new structure
ndelangen Mar 18, 2022
61bcd00
add migration info
ndelangen Mar 18, 2022
09ef0eb
change addon-measure to new preview.js structure
shilman Mar 18, 2022
5b5aa15
Merge branch 'tech/refactor-simplified-addons-api' of github.com:stor…
shilman Mar 18, 2022
784f773
update test and lockfile
ndelangen Mar 18, 2022
0b15186
changes trying to fix the presets loading behavior
ndelangen Mar 18, 2022
fe750f3
fix trying to resolve something in a safe way when it should instead …
ndelangen Mar 18, 2022
a2ec44d
update snapshots and change behavior of presets resolutions code
ndelangen Mar 18, 2022
7e845e1
fix snapshot
ndelangen Mar 18, 2022
48efd4e
fix example in comment
ndelangen Mar 18, 2022
cb0ee65
Merge branch 'next' into tech/refactor-simplified-addons-api
ndelangen Mar 18, 2022
48442be
Fix viewport main/module/types settings
shilman Mar 18, 2022
4c50f40
Revert "remove unused file"
ndelangen Mar 18, 2022
4ad56ff
Merge branch 'tech/refactor-simplified-addons-api' of github.com:stor…
ndelangen Mar 18, 2022
62efca6
Revert "Fix viewport main/module/types settings"
ndelangen Mar 18, 2022
140cc3d
swap the spread of values from config & previewAnnotation so the newe…
ndelangen Mar 21, 2022
7ad2e1e
change & simplify & fix the preset resolution
ndelangen Mar 21, 2022
6336797
fix tests
ndelangen Mar 21, 2022
657040d
apply resolveAddon to objects too
ndelangen Mar 22, 2022
bbbb1b5
Merge branch 'next' into tech/refactor-simplified-addons-api
ndelangen Mar 22, 2022
bc5aa0e
improve tests
ndelangen Mar 22, 2022
4de6aff
make builders backwards compatible
ndelangen Mar 22, 2022
e40463f
fix snapshots
ndelangen Mar 22, 2022
14e3d85
clean up addons preview/manager refactor
shilman Mar 22, 2022
b948755
Addon-docs: manager/preview addon refactor
shilman Mar 22, 2022
ce6efb7
Addon-interactions: manager/preview addons refactor
shilman Mar 22, 2022
8b5ec34
Merge branch 'addons-api-docs-refactor' into tech/refactor-simplified…
shilman Mar 22, 2022
3435932
Update snapshots
shilman Mar 22, 2022
d92eff6
Fix interactions entry
shilman Mar 22, 2022
6e3d51e
Switch frameworks to use previewAnnotations
shilman Mar 23, 2022
c60e104
Update snapshots
shilman Mar 23, 2022
30ee7a7
Ensure options get passed to virtual preset
shilman Mar 23, 2022
966ece8
Fix StorybookConfig type
shilman Mar 23, 2022
04b4954
Fix lockfile
shilman Mar 23, 2022
789a272
Merge branch 'next' into tech/refactor-simplified-addons-api
ndelangen Mar 24, 2022
b4c2468
change some references back to register, and update a few docs
ndelangen Mar 25, 2022
0b9412d
update snapshots
ndelangen Mar 25, 2022
0a42711
bump
ndelangen Mar 25, 2022
c8e7a0c
add storybook/csf as alias
ndelangen Mar 25, 2022
513da1f
merge next
ndelangen Mar 28, 2022
ff48f94
Merge branch 'next' into tech/refactor-simplified-addons-api
ndelangen Mar 29, 2022
8f8f903
fix thanks to shilman 😘
ndelangen Mar 29, 2022
b6e2c66
Merge branch 'next' into tech/refactor-simplified-addons-api
ndelangen Mar 30, 2022
3ee4170
Merge branch 'next' into tech/refactor-simplified-addons-api
ndelangen Mar 31, 2022
19bb2e3
Merge branch 'next' into tech/refactor-simplified-addons-api
shilman Mar 31, 2022
2832361
Merge branch 'next' into tech/refactor-simplified-addons-api
shilman Mar 31, 2022
666f25d
Merge branch 'next' into tech/refactor-simplified-addons-api
shilman Apr 1, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<h1>Migration</h1>

- [From version 6.4.x to 6.5.0](#from-version-64x-to-650)
- [Deprecated register.js](#deprecated-registerjs)
- [Dropped support for addon-actions addDecorators](#dropped-support-for-addon-actions-adddecorators)
- [Vite builder renamed](#vite-builder-renamed)
- [Docs framework refactor for React](#docs-framework-refactor-for-react)
- [Opt-in MDX2 support](#opt-in-mdx2-support)
Expand Down Expand Up @@ -197,6 +199,26 @@

## From version 6.4.x to 6.5.0

### Deprecated register.js

In ancient versions of Storybook, addons were registered by referring to `addon-name/register.js`. This is going away in SB7.0. Instead you should just add `addon-name` to the `addons` array in `.storybook/main.js`.

Before:

```js
module.exports = { addons: ['my-addon/register.js'] }
```

After:

```js
module.exports = { addons: ['my-addon'] }
```

### Dropped support for addon-actions addDecorators

Prior to SB6.5, `addon-actions` provided an option called `addDecorators`. In SB6.5, decorators are applied always. This is technically a breaking change, so if this affects you please file an issue in Github and we can consider reverting this in a patch release.

### Vite builder renamed

SB6.5 renames Storybook's [Vite builder](https://github.com/storybookjs/builder-vite) from `storybook-builder-vite` to `@storybook/builder-vite`. This move is part of a larger effort to improve Vite support in Storybook.
Expand Down
1 change: 1 addition & 0 deletions addons/a11y/manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './dist/esm/manager';
13 changes: 0 additions & 13 deletions addons/a11y/preset.js

This file was deleted.

1 change: 1 addition & 0 deletions addons/a11y/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './dist/esm/preview';
7 changes: 6 additions & 1 deletion addons/a11y/register.js
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
require('./dist/esm/register');
import { once } from '@storybook/client-logger';
import './manager';

once.warn(
'register.js is deprecated see https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-registerjs'
);
3 changes: 0 additions & 3 deletions addons/a11y/src/addDecorator.ts

This file was deleted.

File renamed without changes.
2 changes: 2 additions & 0 deletions addons/a11y/src/preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './a11yRunner';
import './a11yHighlight';
1 change: 1 addition & 0 deletions addons/actions/manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './dist/esm/manager';
3 changes: 2 additions & 1 deletion addons/actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@
"dependencies": {
"@storybook/addons": "6.5.0-alpha.52",
"@storybook/api": "6.5.0-alpha.52",
"@storybook/client-logger": "6.5.0-alpha.52",
"@storybook/components": "6.5.0-alpha.52",
"@storybook/core-events": "6.5.0-alpha.52",
"@storybook/csf": "0.0.2--canary.507502b.0",
"@storybook/csf": "0.0.2--canary.87bc651.0",
"@storybook/theming": "6.5.0-alpha.52",
"core-js": "^3.8.2",
"fast-deep-equal": "^3.1.3",
Expand Down
16 changes: 0 additions & 16 deletions addons/actions/preset.js

This file was deleted.

1 change: 1 addition & 0 deletions addons/actions/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './dist/esm/preset/preview';
7 changes: 6 additions & 1 deletion addons/actions/register.js
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
require('./dist/esm/register');
import { once } from '@storybook/client-logger';
import './manager';

once.warn(
'register.js is deprecated see https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-registerjs'
);
File renamed without changes.
2 changes: 2 additions & 0 deletions addons/actions/src/preset/preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './addDecorator';
export * from './addArgs';
1 change: 1 addition & 0 deletions addons/backgrounds/manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './dist/esm/manager';
16 changes: 0 additions & 16 deletions addons/backgrounds/preset.js

This file was deleted.

1 change: 1 addition & 0 deletions addons/backgrounds/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './dist/esm/preview';
7 changes: 6 additions & 1 deletion addons/backgrounds/register.js
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
require('./dist/esm/register');
import { once } from '@storybook/client-logger';
import './manager';

once.warn(
'register.js is deprecated see https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-registerjs'
);
2 changes: 0 additions & 2 deletions addons/backgrounds/src/decorators/index.ts

This file was deleted.

File renamed without changes.
3 changes: 0 additions & 3 deletions addons/backgrounds/src/preset/addDecorator.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { withBackground } from './decorators/withBackground';
import { withGrid } from './decorators/withGrid';

export const decorators = [withGrid, withBackground];
export const parameters = {
backgrounds: {
grid: {
Expand Down
1 change: 1 addition & 0 deletions addons/controls/manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './dist/esm/manager';
6 changes: 3 additions & 3 deletions addons/controls/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"url": "https://opencollective.com/storybook"
},
"license": "MIT",
"main": "dist/cjs/register.js",
"module": "dist/esm/register.js",
"main": "dist/cjs/manager.js",
"module": "dist/esm/manager.js",
"types": "dist/ts3.9/index.d.ts",
"typesVersions": {
"<3.8": {
Expand Down Expand Up @@ -74,7 +74,7 @@
"access": "public"
},
"gitHead": "863b3811b24a4703645a09286059bc6d95bd2e65",
"sbmodern": "dist/modern/register.js",
"sbmodern": "dist/modern/manager.js",
"storybook": {
"displayName": "Controls",
"icon": "https://user-images.githubusercontent.com/263385/101991669-479cc600-3c7c-11eb-93d9-38b67e8371f2.png",
Expand Down
8 changes: 0 additions & 8 deletions addons/controls/preset.js

This file was deleted.

7 changes: 6 additions & 1 deletion addons/controls/register.js
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
import './dist/esm/register';
import { once } from '@storybook/client-logger';
import './manager';

once.warn(
'register.js is deprecated see https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-registerjs'
);
File renamed without changes.
1 change: 1 addition & 0 deletions addons/docs/manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './dist/esm/manager';
17 changes: 1 addition & 16 deletions addons/docs/preset.js
Original file line number Diff line number Diff line change
@@ -1,16 +1 @@
const { findDistEsm } = require('@storybook/core-common');
const { webpack } = require('./dist/cjs/frameworks/common/preset');

function managerEntries(entry = [], options) {
return [...entry, findDistEsm(__dirname, 'register')];
}

function config(entry = [], options = {}) {
return [findDistEsm(__dirname, 'frameworks/common/config'), ...entry];
}

module.exports = {
webpack,
managerEntries,
config,
};
module.exports = require('./dist/cjs/preset');
1 change: 1 addition & 0 deletions addons/docs/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './dist/esm/preview';
8 changes: 6 additions & 2 deletions addons/docs/register.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
/* eslint-disable import/extensions */
require('./dist/esm/register.js');
import { once } from '@storybook/client-logger';
import './manager';

once.warn(
'register.js is deprecated see https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-registerjs'
);
8 changes: 0 additions & 8 deletions addons/docs/src/frameworks/common/config.ts

This file was deleted.

File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions addons/docs/src/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const parameters = {
docs: {
getContainer: async () => (await import('./blocks')).DocsContainer,
getPage: async () => (await import('./blocks')).DocsPage,
},
};
9 changes: 2 additions & 7 deletions addons/essentials/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path, { join } from 'path';
import path, { dirname, join } from 'path';
import { logger } from '@storybook/node-logger';
import { serverRequire } from '@storybook/core-common';

Expand Down Expand Up @@ -50,12 +50,7 @@ export function addons(options: PresetOptions = {}) {
// as it's done in `lib/core/src/server/presets.js`.
.map((addon) => {
try {
return require.resolve(join(addon, 'preset'));
// eslint-disable-next-line no-empty
} catch (err) {}

try {
return require.resolve(join(addon, 'register'));
return dirname(require.resolve(join(addon, 'package.json')));
// eslint-disable-next-line no-empty
} catch (err) {}

Expand Down
1 change: 1 addition & 0 deletions addons/interactions/manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './dist/esm/manager';
7 changes: 4 additions & 3 deletions addons/interactions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"url": "https://opencollective.com/storybook"
},
"license": "MIT",
"main": "dist/cjs/register.js",
"module": "dist/esm/register.js",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "dist/ts3.9/index.d.ts",
"typesVersions": {
"<3.8": {
Expand All @@ -43,10 +43,11 @@
"dependencies": {
"@storybook/addons": "6.5.0-alpha.52",
"@storybook/api": "6.5.0-alpha.52",
"@storybook/client-logger": "6.5.0-alpha.52",
"@storybook/components": "6.5.0-alpha.52",
"@storybook/core-common": "6.5.0-alpha.52",
"@storybook/core-events": "6.5.0-alpha.52",
"@storybook/csf": "0.0.2--canary.507502b.0",
"@storybook/csf": "0.0.2--canary.87bc651.0",
"@storybook/instrumenter": "6.5.0-alpha.52",
"@storybook/theming": "6.5.0-alpha.52",
"core-js": "^3.8.2",
Expand Down
13 changes: 4 additions & 9 deletions addons/interactions/preset.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
function config(entry = []) {
return [...entry, require.resolve('./dist/esm/preset/argsEnhancers')];
}
const { checkActionsLoaded } = require('./dist/cjs/preset/checkActionsLoaded');

function managerEntries(entry = [], options) {
// eslint-disable-next-line global-require
const { checkActionsLoaded } = require('./dist/cjs/preset/checkActionsLoaded');
function previewAnnotations(entry = [], options) {
checkActionsLoaded(options.configDir);
return [...entry, require.resolve('./dist/esm/register')];
return entry;
}

module.exports = {
config,
managerEntries,
previewAnnotations,
};
1 change: 1 addition & 0 deletions addons/interactions/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './dist/esm/preset/preview';
7 changes: 6 additions & 1 deletion addons/interactions/register.js
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
import './dist/esm/register';
import { once } from '@storybook/client-logger';
import './manager';

once.warn(
'register.js is deprecated see https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-registerjs'
);
1 change: 1 addition & 0 deletions addons/jest/manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './dist/esm/manager';
1 change: 1 addition & 0 deletions addons/jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"dependencies": {
"@storybook/addons": "6.5.0-alpha.52",
"@storybook/api": "6.5.0-alpha.52",
"@storybook/client-logger": "6.5.0-alpha.52",
"@storybook/components": "6.5.0-alpha.52",
"@storybook/core-events": "6.5.0-alpha.52",
"@storybook/theming": "6.5.0-alpha.52",
Expand Down
7 changes: 6 additions & 1 deletion addons/jest/register.js
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
require('./dist/esm/register');
import { once } from '@storybook/client-logger';
import './manager';

once.warn(
'register.js is deprecated see https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-registerjs'
);
File renamed without changes.
1 change: 1 addition & 0 deletions addons/links/manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './dist/esm/manager';
13 changes: 0 additions & 13 deletions addons/links/preset.js

This file was deleted.

1 change: 1 addition & 0 deletions addons/links/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './dist/esm/preview';
7 changes: 6 additions & 1 deletion addons/links/register.js
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
require('./dist/esm/register');
import { once } from '@storybook/client-logger';
import './manager';

once.warn(
'register.js is deprecated see https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-registerjs'
);
2 changes: 1 addition & 1 deletion addons/links/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function LinkTo(): null {
return null;
}

export { linkTo, hrefTo, withLinks, navigate } from './preview';
export { linkTo, hrefTo, withLinks, navigate } from './utils';

if (module && module.hot && module.hot.decline) {
module.hot.decline();
Expand Down
File renamed without changes.
3 changes: 0 additions & 3 deletions addons/links/src/preset/addDecorator.ts

This file was deleted.

Loading