Skip to content

Commit

Permalink
Merge branch 'next' into docs_fix_api_csf
Browse files Browse the repository at this point in the history
  • Loading branch information
jonniebigodes authored Feb 19, 2024
2 parents cd4b848 + 15ed50a commit 0bd91ce
Show file tree
Hide file tree
Showing 48 changed files with 1,551 additions and 293 deletions.
7 changes: 5 additions & 2 deletions code/builders/builder-vite/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function build(options: Options) {

const turbosnapPluginName = 'rollup-plugin-turbosnap';
const hasTurbosnapPlugin =
finalConfig.plugins && hasVitePlugins(finalConfig.plugins, [turbosnapPluginName]);
finalConfig.plugins && (await hasVitePlugins(finalConfig.plugins, [turbosnapPluginName]));
if (hasTurbosnapPlugin) {
logger.warn(dedent`Found '${turbosnapPluginName}' which is now included by default in Storybook 8.
Removing from your plugins list. Ensure you pass \`--webpack-stats-json\` to generate stats.
Expand All @@ -53,6 +53,9 @@ export async function build(options: Options) {

await viteBuild(await sanitizeEnvVars(options, finalConfig));

const statsPlugin = findPlugin(finalConfig, 'rollup-plugin-webpack-stats') as WebpackStatsPlugin;
const statsPlugin = findPlugin(
finalConfig,
'storybook:rollup-plugin-webpack-stats'
) as WebpackStatsPlugin;
return statsPlugin?.storybookGetStats();
}
3 changes: 1 addition & 2 deletions code/e2e-tests/addon-docs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ test.describe('addon-docs', () => {
await expect(anotherStory).toContainText('Another button, just to show multiple stories');
});

// FIXME - get rid of the flake
test.skip('should show source=code view for stories', async ({ page }) => {
test('should show source=code view for stories', async ({ page }) => {
const skipped = [
// SSv6 does not render stories in the correct order in our sandboxes
'internal\\/ssv6',
Expand Down
3 changes: 1 addition & 2 deletions code/e2e-tests/tags.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { SbPage } from './util';

const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:8001';

// FIXME - get rid of the flake
test.describe.skip('tags', () => {
test.describe('tags', () => {
test.beforeEach(async ({ page }) => {
await page.goto(storybookUrl);
await new SbPage(page).waitUntilLoaded();
Expand Down
3 changes: 2 additions & 1 deletion code/frameworks/nextjs/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ export const webpackFinal: StorybookConfig['webpackFinal'] = async (baseConfig,
});

const babelRCPath = join(getProjectRoot(), '.babelrc');
const hasBabelConfig = fs.existsSync(babelRCPath);
const babelConfigPath = join(getProjectRoot(), 'babel.config.js');
const hasBabelConfig = fs.existsSync(babelRCPath) || fs.existsSync(babelConfigPath);
const nextjsVersion = getNextjsVersion();
const isDevelopment = options.configType !== 'PRODUCTION';

Expand Down
1 change: 1 addition & 0 deletions code/lib/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"prep": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/bundle.ts"
},
"dependencies": {
"@babel/core": "^7.23.0",
"@babel/types": "^7.23.0",
"@ndelangen/get-tarball": "^3.0.7",
"@storybook/codemod": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface AngularBuildersMultiprojectRunOptions {}

export const angularBuildersMultiproject: Fix<AngularBuildersMultiprojectRunOptions> = {
id: 'angular-builders-multiproject',
promptOnly: true,
promptType: 'manual',

async check({ packageManager, mainConfig }) {
// Skip in case of NX
Expand Down
2 changes: 1 addition & 1 deletion code/lib/cli/src/automigrate/fixes/incompatible-addons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface IncompatibleAddonsOptions {

export const incompatibleAddons: Fix<IncompatibleAddonsOptions> = {
id: 'incompatible-addons',
promptOnly: true,
promptType: 'manual',

async check({ mainConfig, packageManager }) {
const incompatibleAddonList = await getIncompatibleAddons(mainConfig, packageManager);
Expand Down
4 changes: 4 additions & 0 deletions code/lib/cli/src/automigrate/fixes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { wrapRequire } from './wrap-require';
import { reactDocgen } from './react-docgen';
import { removeReactDependency } from './prompt-remove-react';
import { storyshotsMigration } from './storyshots-migration';
import { removeArgtypesRegex } from './remove-argtypes-regex';
import { webpack5CompilerSetup } from './webpack5-compiler-setup';
import { removeJestTestingLibrary } from './remove-jest-testing-library';

export * from '../types';
Expand All @@ -37,6 +39,7 @@ export const allFixes: Fix[] = [
sbBinary,
sbScripts,
incompatibleAddons,
removeArgtypesRegex,
removeJestTestingLibrary,
removedGlobalClientAPIs,
mdx1to2,
Expand All @@ -48,6 +51,7 @@ export const allFixes: Fix[] = [
reactDocgen,
storyshotsMigration,
removeReactDependency,
webpack5CompilerSetup,
];

export const initFixes: Fix[] = [eslintPlugin];
2 changes: 1 addition & 1 deletion code/lib/cli/src/automigrate/fixes/prompt-remove-react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Fix } from '../types';

export const removeReactDependency: Fix<{}> = {
id: 'remove-react-dependency',
promptOnly: true,
promptType: 'manual',

async check({ packageManager, mainConfig, storybookVersion }) {
// when the user is using the react renderer, we should not prompt them to remove react
Expand Down
81 changes: 81 additions & 0 deletions code/lib/cli/src/automigrate/fixes/remove-argtypes-regex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import type { Fix } from '../types';
import * as fs from 'node:fs/promises';
import * as babel from '@babel/core';
import type { BabelFile, NodePath } from '@babel/core';
import { babelParse } from '@storybook/csf-tools';
import dedent from 'ts-dedent';
import chalk from 'chalk';

export const removeArgtypesRegex: Fix<{ argTypesRegex: NodePath; previewConfigPath: string }> = {
id: 'remove-argtypes-regex',
promptType: 'manual',
async check({ previewConfigPath }) {
if (!previewConfigPath) return null;

const previewFile = await fs.readFile(previewConfigPath, { encoding: 'utf-8' });

// @ts-expect-error File is not yet exposed, see https://github.com/babel/babel/issues/11350#issuecomment-644118606
const file: BabelFile = new babel.File(
{ filename: previewConfigPath },
{ code: previewFile, ast: babelParse(previewFile) }
);

let argTypesRegex;

file.path.traverse({
Identifier: (path) => {
if (path.node.name === 'argTypesRegex') {
argTypesRegex = path;
}
},
});

return argTypesRegex ? { argTypesRegex, previewConfigPath } : null;
},
prompt({ argTypesRegex, previewConfigPath }) {
const snippet = dedent`
import { fn } from '@storybook/test';
export default {
args: { onClick: fn() }, // will log to the action panel when clicked
};`;

// @ts-expect-error File is not yet exposed, see https://github.com/babel/babel/issues/11350#issuecomment-644118606
const file: BabelFile = new babel.File(
{ file: 'story.tsx' },
{ code: snippet, ast: babelParse(snippet) }
);

let formattedSnippet;
file.path.traverse({
Identifier: (path) => {
if (path.node.name === 'fn') {
formattedSnippet = path.buildCodeFrameError(``).message;
}
},
});

return dedent`
${chalk.bold('Attention')}: We've detected that you're using argTypesRegex:
${argTypesRegex.buildCodeFrameError(`${previewConfigPath}`).message}
In Storybook 8, we recommend removing this regex.
Assign explicit spies with the ${chalk.cyan('fn')} function instead:
${formattedSnippet}
The above pattern is needed when using spies in the play function, ${chalk.bold(
'even'
)} if you keep using argTypesRegex.
Implicit spies (based on a combination of argTypesRegex and docgen) is not supported in Storybook 8.
Use the following command to check for spy usages in your play functions:
${chalk.cyan(
'npx storybook migrate find-implicit-spies --glob="**/*.stories.@(js|jsx|ts|tsx)"'
)}
Make sure to assign an explicit ${chalk.cyan('fn')} to your args for those usages.
For more information please visit our migration guide: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#implicit-actions-can-not-be-used-during-rendering-for-example-in-the-play-function
`;
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface GlobalClientAPIOptions {

export const removedGlobalClientAPIs: Fix<GlobalClientAPIOptions> = {
id: 'removedglobalclientapis',
promptOnly: true,
promptType: 'manual',

async check({ previewConfigPath }) {
if (previewConfigPath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Fix } from '../types';

export const removeJestTestingLibrary: Fix<{ incompatiblePackages: string[] }> = {
id: 'remove-jest-testing-library',
promptOnly: true,
promptType: 'manual',
async check({ mainConfig, packageManager }) {
const deps = await packageManager.getAllDependencies();

Expand Down
2 changes: 1 addition & 1 deletion code/lib/cli/src/automigrate/fixes/storyshots-migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Fix } from '../types';

export const storyshotsMigration: Fix = {
id: 'storyshots-migration',
promptOnly: true,
promptType: 'manual',

async check({ mainConfig, packageManager }) {
const allDeps = await packageManager.getAllDependencies();
Expand Down
4 changes: 2 additions & 2 deletions code/lib/cli/src/automigrate/fixes/vite-config-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getFrameworkPackageName } from '../helpers/mainConfigFile';
import { frameworkToRenderer } from '../../helpers';
import { frameworkPackages } from '@storybook/core-common';

interface Webpack5RunOptions {
interface ViteConfigFileRunOptions {
plugins: string[];
existed: boolean;
}
Expand Down Expand Up @@ -108,4 +108,4 @@ export const viteConfigFile = {
This change was necessary to support newer versions of Vite.
`;
},
} satisfies Fix<Webpack5RunOptions>;
} satisfies Fix<ViteConfigFileRunOptions>;
4 changes: 2 additions & 2 deletions code/lib/cli/src/automigrate/fixes/vite4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Fix } from '../types';

const logger = console;

interface Webpack5RunOptions {
interface Vite4RunOptions {
viteVersion: string | null;
}

Expand Down Expand Up @@ -40,4 +40,4 @@ export const vite4 = {
await packageManager.addDependencies({ installAsDevDependencies: true }, deps);
}
},
} satisfies Fix<Webpack5RunOptions>;
} satisfies Fix<Vite4RunOptions>;
Loading

0 comments on commit 0bd91ce

Please sign in to comment.