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

Conversation

ndelangen
Copy link
Member

@ndelangen ndelangen commented Mar 18, 2022

https://www.notion.so/chromatic-ui/Simplified-SB-addons-API-fcabe63977cb47d3959fdbab74b8fc4d

  • Rename register.js to manager.js
  • Add a new file preview.js which is added to the preview annotations by default
  • Rename config to previewAnnotations for consistency
  • Convert all of our addons to the new structure
  • Deprecate the old way in 6.5

@nx-cloud
Copy link

nx-cloud bot commented Mar 18, 2022

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 666f25d. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

@ndelangen ndelangen self-assigned this Mar 18, 2022
@ndelangen ndelangen requested a review from shilman March 18, 2022 12:38
@ndelangen ndelangen added the maintenance User-facing maintenance tasks label Mar 18, 2022
shilman and others added 5 commits March 23, 2022 13:44
# Conflicts:
#	addons/actions/package.json
#	addons/controls/package.json
#	addons/interactions/package.json
#	addons/jest/package.json
#	addons/toolbars/package.json
#	examples/web-components-kitchen-sink/yarn.lock
#	yarn.lock
@ndelangen ndelangen requested a review from shilman March 25, 2022 13:57
@winkerVSbecks
Copy link
Contributor

@ndelangen @shilman this is a much simpler API. Nice work!

I have a couple of questions:

  1. "Deprecate the old way in 6.5" will that break all community addons? Or are we just showing warnings for now?

  2. You've migrated all the core addons. Then why add this addons/outline/register.js file:

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. This is a pretty major change which means that we have to update: docs, addon tutorial and addon-kit. Could start with the docs update in this PR? Then we can use that as the basis for all other updates.

@shilman
Copy link
Member

shilman commented Mar 28, 2022

@winkerVSbecks thanks for the look!

"Deprecate the old way in 6.5" will that break all community addons? Or are we just showing warnings for now?

The warnings are actually implemented per-addon, so this only shows warnings for existing addons. AFAIK this is not a breaking change.

You've migrated all the core addons. Then why add this addons/outline/register.js file:

We didn't add it. We modified the existing register.js. addon-outline is configured via a preset, so register.js is actually kind of an internal implementation detail. However, since old-style addons used register.js explicitly, we were extra careful not to break that addon entry point even though technically probably could've done so without breaking semver.

This is a pretty major change which means that we have to update: docs, addon tutorial and addon-kit. Could start with the docs update in this PR? Then we can use that as the basis for all other updates.

Indeed, I'll update the docs as part of this PR.

const r = name.startsWith('/') ? safeResolve : safeResolveFrom.bind(null, configDir);
const resolved = r(name);

if (name.match(/\/(manager|register(-panel)?)(\.(js|ts|tsx|jsx))?$/)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we wanna constrain the file extensions? e.g. cjs, mjs

@yannbf
Copy link
Member

yannbf commented Mar 29, 2022

Looks good! But I believe there's a regression with addon-docs. Now every story is loaded in an iframe when opening the docs tab (at least locally in official-storybook, in comparison to the deployed next).

Just out of curiosity, this is how a possible "annotations" file would look like when generated with the new format:

[
    '../../app/react/dist/esm/client/docs/config',
    '../../app/react/dist/esm/client/preview/config',
    '../../addons/docs/preview.js',
    '../../addons/actions/preview.js',
    '../../addons/backgrounds/preview.js',
    '../../addons/measure/preview.js',
    '../../addons/outline/preview.js',
    '../../addons/interactions/preview.js',
    '../../addons/links/preview.js',
    '../../addons/a11y/preview.js',
    'preview.js'
  ]

The downside is now that the preview.js files are just targeting esm, so they will break in current Jest versions. Something to discuss later on!

@yannbf
Copy link
Member

yannbf commented Mar 29, 2022

I found out why the regression happened.

This is the annotations file before this change:

[
  '../../addons/docs/dist/esm/frameworks/common/config',
  '../../addons/actions/dist/esm/preset/addDecorator.js',
  '../../addons/actions/dist/esm/preset/addArgs.js',
  '../../addons/backgrounds/dist/esm/preset/addDecorator.js',
  '../../addons/backgrounds/dist/esm/preset/addParameter.js',
  '../../addons/measure/dist/esm/preset/addDecorator.js',
  '../../addons/outline/dist/esm/preset/addDecorator.js',
  '../../addons/interactions/dist/esm/preset/argsEnhancers.js',
  '../../addons/links/dist/esm/preset/addDecorator.js',
  '../../addons/a11y/dist/esm/a11yRunner.js',
  '../../addons/a11y/dist/esm/a11yHighlight.js',
  './preview.js',
]

This is the annotations file after this change:

[
  '../../app/react/dist/esm/client/docs/config',
  '../../app/react/dist/esm/client/preview/config',
  '../../addons/docs/preview.js',
  '../../addons/actions/preview.js',
  '../../addons/backgrounds/preview.js',
  '../../addons/measure/preview.js',
  '../../addons/outline/preview.js',
  '../../addons/interactions/preview.js',
  '../../addons/links/preview.js',
  '../../addons/a11y/preview.js',
  'preview.js'
]

Notice that before docs was always loading first, so that the framework docs presets could override it correctly! But now the framework presets come first, and get overriden by docs presets

@ndelangen
Copy link
Member Author

@yannbf looks like switching the order around does cause issues down the stream :'(

@ndelangen ndelangen force-pushed the tech/refactor-simplified-addons-api branch from cf2b7b6 to 8f8f903 Compare March 29, 2022 15:22
ndelangen and others added 5 commits March 30, 2022 13:45
# Conflicts:
#	MIGRATION.md
#	addons/actions/package.json
#	addons/controls/package.json
#	addons/interactions/package.json
#	addons/jest/package.json
#	addons/toolbars/package.json
#	lib/cli/src/versions.ts
#	yarn.lock
@shilman
Copy link
Member

shilman commented Apr 1, 2022

Going to merge this @ndelangen and we can work on the unrelated CI failures in parallel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants