Skip to content

Commit

Permalink
Merge branch 'next' into fix-docs-blank-canvases
Browse files Browse the repository at this point in the history
  • Loading branch information
JReinhold committed Mar 8, 2023
2 parents 951473b + a7d76d4 commit 1e0cb5e
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 52 deletions.
3 changes: 2 additions & 1 deletion code/addons/docs/src/DocsRenderer.tsx
Expand Up @@ -51,8 +51,9 @@ export class DocsRenderer<TRenderer extends Renderer> {
return new Promise((resolve, reject) => {
import('@mdx-js/react')
.then(({ MDXProvider }) =>
// We use a `key={}` here to reset the `hasError` state each time we render ErrorBoundary
renderElement(
<ErrorBoundary showException={reject}>
<ErrorBoundary showException={reject} key={Math.random()}>
<MDXProvider components={components}>
<Docs context={context} docsParameter={docsParameter} />
</MDXProvider>
Expand Down
4 changes: 2 additions & 2 deletions code/lib/cli/src/automigrate/fixes/add-react.ts
Expand Up @@ -49,11 +49,11 @@ export const addReact: Fix<AddReactOptions> = {
return dedent`
We've detected that you're using ${dependentsFormatted}.
Starting in Storybook 7 we now require the following peer dependencies:
Starting in Storybook 7, we now require these peer dependencies to render docs:
${additionalDependenciesFormatted}
We can add these for you automatically.
We can add these for you automatically as dev dependencies.
More info: ${chalk.yellow(
'https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#react-peer-dependencies-required'
Expand Down
4 changes: 2 additions & 2 deletions code/lib/cli/src/automigrate/fixes/autodocs-true.ts
Expand Up @@ -64,7 +64,7 @@ export const autodocsTrue: Fix<AutodocsTrueFrameworkRunOptions> = {
${autodocsFormatted}
${value === 'tag' ? tagWarning : ''}
More info: ${chalk.yellow(
'https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#autodocs'
'https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#autodocs-changes'
)}
`;
}
Expand All @@ -77,7 +77,7 @@ export const autodocsTrue: Fix<AutodocsTrueFrameworkRunOptions> = {
${autodocsFormatted}
More info: ${chalk.yellow(
'https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#autodocs'
'https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#autodocs-changes'
)}
`;
},
Expand Down
24 changes: 24 additions & 0 deletions code/lib/codemod/src/transforms/__tests__/mdx-to-csf.test.ts
Expand Up @@ -138,6 +138,30 @@ test('convert correct story nodes', () => {
`);
});

test('convert addon-docs imports', () => {
const input = dedent`
import { Meta } from '@storybook/addon-docs';
import { Story } from '@storybook/addon-docs/blocks';
<Meta title="Foobar" />
<Story name="Primary">Story</Story>
`;

const mdx = jscodeshift({ source: input, path: 'Foobar.stories.mdx' });

expect(mdx).toMatchInlineSnapshot(`
import { Meta } from '@storybook/blocks';
import { Story } from '@storybook/blocks';
import * as FoobarStories from './Foobar.stories';
<Meta of={FoobarStories} />
<Story of={FoobarStories.Primary} />
`);
});

test('convert story nodes with spaces', () => {
const input = dedent`
import { Meta, Story } from '@storybook/addon-docs';
Expand Down
4 changes: 2 additions & 2 deletions code/lib/codemod/src/transforms/mdx-to-csf.ts
Expand Up @@ -75,8 +75,8 @@ export function transform(source: string, baseName: string): [mdx: string, csf:
// rewrite addon docs import
visit(root, ['mdxjsEsm'], (node: MdxjsEsm) => {
node.value = node.value
.replaceAll('@storybook/addon-docs', '@storybook/blocks')
.replaceAll('@storybook/addon-docs/blocks', '@storybook/blocks');
.replaceAll('@storybook/addon-docs/blocks', '@storybook/blocks')
.replaceAll('@storybook/addon-docs', '@storybook/blocks');
});

const file = getEsmAst(root);
Expand Down
18 changes: 17 additions & 1 deletion code/lib/core-server/src/utils/StoryIndexGenerator.test.ts
Expand Up @@ -11,7 +11,7 @@ import { normalizeStoriesEntry } from '@storybook/core-common';
import type { NormalizedStoriesSpecifier, StoryIndexer, StoryIndexEntry } from '@storybook/types';
import { loadCsf, getStorySortParameter } from '@storybook/csf-tools';
import { toId } from '@storybook/csf';
import { logger } from '@storybook/node-logger';
import { logger, once } from '@storybook/node-logger';

import { StoryIndexGenerator } from './StoryIndexGenerator';

Expand Down Expand Up @@ -61,6 +61,7 @@ describe('StoryIndexGenerator', () => {
const actual = jest.requireActual('@storybook/csf-tools');
loadCsfMock.mockImplementation(actual.loadCsf);
jest.mocked(logger.warn).mockClear();
jest.mocked(once.warn).mockClear();
});
describe('extraction', () => {
const storiesSpecifier: NormalizedStoriesSpecifier = normalizeStoriesEntry(
Expand Down Expand Up @@ -925,6 +926,21 @@ describe('StoryIndexGenerator', () => {
});
});

describe('warnings', () => {
it('when entries do not match any files', async () => {
const generator = new StoryIndexGenerator(
[normalizeStoriesEntry('./src/docs2/wrong.js', options)],
options
);
await generator.initialize();
await generator.getIndex();

expect(once.warn).toHaveBeenCalledTimes(1);
const logMessage = jest.mocked(once.warn).mock.calls[0][0];
expect(logMessage).toContain(`No story files found for the specified pattern`);
});
});

describe('duplicates', () => {
it('warns when two MDX entries reference the same CSF file without a name', async () => {
const docsErrorSpecifier: NormalizedStoriesSpecifier = normalizeStoriesEntry(
Expand Down
11 changes: 10 additions & 1 deletion code/lib/core-server/src/utils/StoryIndexGenerator.ts
Expand Up @@ -21,7 +21,7 @@ import type {
} from '@storybook/types';
import { userOrAutoTitleFromSpecifier, sortStoriesV7 } from '@storybook/preview-api';
import { normalizeStoryPath } from '@storybook/core-common';
import { logger } from '@storybook/node-logger';
import { logger, once } from '@storybook/node-logger';
import { getStorySortParameter } from '@storybook/csf-tools';
import { toId } from '@storybook/csf';
import { analyze } from '@storybook/docs-mdx';
Expand Down Expand Up @@ -122,6 +122,15 @@ export class StoryIndexGenerator {
path.join(this.options.workingDir, specifier.directory, specifier.files)
);
const files = await glob(fullGlob);

if (files.length === 0) {
once.warn(
`No story files found for the specified pattern: ${chalk.blue(
path.join(specifier.directory, specifier.files)
)}`
);
}

files.sort().forEach((absolutePath: Path) => {
const ext = path.extname(absolutePath);
if (ext === '.storyshot') {
Expand Down
2 changes: 1 addition & 1 deletion code/lib/csf-tools/package.json
@@ -1,7 +1,7 @@
{
"name": "@storybook/csf-tools",
"version": "7.0.0-beta.62",
"description": "",
"description": "Parse and manipulate CSF and Storybook config files",
"keywords": [
"storybook"
],
Expand Down
2 changes: 1 addition & 1 deletion code/lib/csf-tools/src/CsfFile.test.ts
Expand Up @@ -556,7 +556,7 @@ describe('CsfFile', () => {
`,
true
)
).toThrow('CSF: unexpected storiesOf call');
).toThrow('Unexpected `storiesOf` usage:');
});

it('function exports', () => {
Expand Down
5 changes: 3 additions & 2 deletions code/lib/csf-tools/src/CsfFile.ts
Expand Up @@ -414,9 +414,10 @@ export class CsfFile {
const { callee } = node;
if (t.isIdentifier(callee) && callee.name === 'storiesOf') {
throw new Error(dedent`
CSF: unexpected storiesOf call ${formatLocation(node, self._fileName)}
Unexpected \`storiesOf\` usage: ${formatLocation(node, self._fileName)}.
More info: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#story-store-v7
In SB7, we use the next-generation \`storyStoreV7\` by default, which does not support \`storiesOf\`.
More info, with details about how to opt-out here: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#storystorev7-enabled-by-default
`);
}
},
Expand Down
2 changes: 1 addition & 1 deletion code/lib/manager-api/package.json
@@ -1,7 +1,7 @@
{
"name": "@storybook/manager-api",
"version": "7.0.0-beta.62",
"description": "Core Storybook API & Context",
"description": "Core Storybook Manager API & Context",
"keywords": [
"storybook"
],
Expand Down
1 change: 1 addition & 0 deletions code/lib/telemetry/src/telemetry.ts
Expand Up @@ -31,6 +31,7 @@ export async function sendTelemetry(
: {
anonymousId: getAnonymousProjectId(),
inCI: Boolean(process.env.CI),
isTTY: process.stdout.isTTY,
};
const eventId = nanoid();
const body = { ...rest, eventType, eventId, sessionId, metadata, payload, context };
Expand Down
2 changes: 1 addition & 1 deletion code/lib/types/package.json
@@ -1,7 +1,7 @@
{
"name": "@storybook/types",
"version": "7.0.0-beta.62",
"description": "Core Storybook Types",
"description": "Core Storybook TS Types",
"keywords": [
"storybook"
],
Expand Down
3 changes: 1 addition & 2 deletions code/ui/blocks/src/blocks/useOf.ts
@@ -1,6 +1,5 @@
import type {
DocsContextProps,
ModuleExport,
ResolvedModuleExportType,
ResolvedModuleExportFromType,
} from '@storybook/types';
Expand All @@ -16,7 +15,7 @@ export type Of = Parameters<DocsContextProps['resolveOf']>[0];
* if the resolved module is a component it will include the project annotations
*/
export const useOf = <TType extends ResolvedModuleExportType>(
moduleExportOrType: ModuleExport | TType,
moduleExportOrType: Of,
validTypes?: TType[]
): ResolvedModuleExportFromType<TType> => {
const context = useContext(DocsContext);
Expand Down
28 changes: 0 additions & 28 deletions docs/get-started/introduction.md

This file was deleted.

Binary file not shown.
Binary file removed docs/get-started/storybook-relationship.png
Binary file not shown.
11 changes: 4 additions & 7 deletions docs/toc.js
@@ -1,19 +1,16 @@
module.exports = {
toc: [
{
title: '📕 Why Storybook?',
pathSegment: 'why-storybook',
type: 'link',
},

{
title: '🚀 Get started',
pathSegment: 'get-started',
type: 'menu',
children: [
{
pathSegment: 'introduction',
title: 'Introduction',
pathSegment: 'why-storybook',
title: 'Why Storybook?',
type: 'bullet-link',
description: 'Learn why Storybook can help you build better UIs',
},
{
pathSegment: 'install',
Expand Down

0 comments on commit 1e0cb5e

Please sign in to comment.