Skip to content

Commit

Permalink
Merge pull request #25740 from storybookjs/valentin/fix-storybook-con…
Browse files Browse the repository at this point in the history
…fig-typing-for-webpack-projects

Webpack: Update StorybookConfig import in core-webpack types.ts
  • Loading branch information
valentinpalkovic authored Jan 31, 2024
2 parents d9e1720 + dec75ae commit a91240a
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 79 deletions.
5 changes: 3 additions & 2 deletions code/builders/builder-webpack5/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import type {
Options,
BuilderResult as BuilderResultBase,
StorybookConfig,
TypescriptOptions as WebpackTypescriptOptions,
} from '@storybook/core-webpack';

import type ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';

type TypeScriptOptionsBase = Required<StorybookConfig>['typescript'];
type TypeScriptOptionsBase = Partial<WebpackTypescriptOptions>;

/**
* Options for TypeScript usage within Storybook.
Expand All @@ -19,7 +20,7 @@ export interface TypescriptOptions extends TypeScriptOptionsBase {
checkOptions?: ConstructorParameters<typeof ForkTsCheckerWebpackPlugin>[0];
}

export interface StorybookConfigWebpack extends Pick<StorybookConfig, 'webpack' | 'webpackFinal'> {
export interface StorybookConfigWebpack extends Omit<StorybookConfig, 'webpack' | 'webpackFinal'> {
/**
* Modify or return a custom Webpack config after the Storybook's default configuration
* has run (mostly used by addons).
Expand Down
4 changes: 2 additions & 2 deletions code/frameworks/angular/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const previewAnnotations: PresetProperty<'previewAnnotations'> = (entries
return annotations;
};

export const core: PresetProperty<'core', StorybookConfig> = async (config, options) => {
export const core: PresetProperty<'core'> = async (config, options) => {
const framework = await options.presets.apply('framework');

return {
Expand All @@ -34,7 +34,7 @@ export const core: PresetProperty<'core', StorybookConfig> = async (config, opti
};
};

export const typescript: PresetProperty<'typescript', StorybookConfig> = async (config) => {
export const typescript: PresetProperty<'typescript'> = async (config) => {
return {
...config,
skipCompiler: true,
Expand Down
2 changes: 1 addition & 1 deletion code/frameworks/ember/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const webpackFinal: StorybookConfig['webpackFinal'] = async (baseConfig,
};
};

export const core: PresetProperty<'core', StorybookConfig> = async (config, options) => {
export const core: PresetProperty<'core'> = async (config, options) => {
const framework = await options.presets.apply('framework');

return {
Expand Down
3 changes: 1 addition & 2 deletions code/frameworks/html-vite/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import type { PresetProperty } from '@storybook/types';
import { dirname, join } from 'path';
import type { StorybookConfig } from './types';

function getAbsolutePath<I extends string>(value: I): I {
return dirname(require.resolve(join(value, 'package.json'))) as any;
}

export const core: PresetProperty<'core', StorybookConfig> = {
export const core: PresetProperty<'core'> = {
builder: getAbsolutePath('@storybook/builder-vite'),
renderer: getAbsolutePath('@storybook/html'),
};
28 changes: 0 additions & 28 deletions code/frameworks/nextjs/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,6 @@ export const addons: PresetProperty<'addons'> = [
dirname(require.resolve(join('@storybook/preset-react-webpack', 'package.json'))),
];

const defaultFrameworkOptions: FrameworkOptions = {};

export const frameworkOptions: PresetProperty<'framework'> = async (_, options) => {
const config = await options.presets.apply('framework');

if (typeof config === 'string') {
return {
name: config,
options: defaultFrameworkOptions,
};
}
if (typeof config === 'undefined') {
return {
name: require.resolve('@storybook/nextjs') as '@storybook/nextjs',
options: defaultFrameworkOptions,
};
}

return {
name: config.name,
options: {
...defaultFrameworkOptions,
...config.options,
},
};
};

export const core: PresetProperty<'core'> = async (config, options) => {
const framework = await options.presets.apply('framework');

Expand Down Expand Up @@ -137,7 +110,6 @@ export const babel: PresetProperty<'babel'> = async (baseConfig: TransformOption
};

export const webpackFinal: StorybookConfig['webpackFinal'] = async (baseConfig, options) => {
// eslint-disable-next-line @typescript-eslint/no-shadow
const frameworkOptions = await options.presets.apply<{ options: FrameworkOptions }>(
'frameworkOptions'
);
Expand Down
2 changes: 1 addition & 1 deletion code/frameworks/preact-vite/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { StorybookConfig } from './types';
const getAbsolutePath = <I extends string>(input: I): I =>
dirname(require.resolve(join(input, 'package.json'))) as any;

export const core: PresetProperty<'core', StorybookConfig> = {
export const core: PresetProperty<'core'> = {
builder: getAbsolutePath('@storybook/builder-vite'),
renderer: getAbsolutePath('@storybook/preact'),
};
Expand Down
2 changes: 1 addition & 1 deletion code/frameworks/react-vite/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { StorybookConfig } from './types';
const getAbsolutePath = <I extends string>(input: I): I =>
dirname(require.resolve(join(input, 'package.json'))) as any;

export const core: PresetProperty<'core', StorybookConfig> = {
export const core: PresetProperty<'core'> = {
builder: getAbsolutePath('@storybook/builder-vite'),
renderer: getAbsolutePath('@storybook/react'),
};
Expand Down
36 changes: 2 additions & 34 deletions code/frameworks/react-webpack5/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { dirname, join } from 'path';
import type { PresetProperty, Options } from '@storybook/types';
import type { FrameworkOptions, StorybookConfig } from './types';
import type { PresetProperty } from '@storybook/types';
import type { StorybookConfig } from './types';

const getAbsolutePath = <I extends string>(input: I): I =>
dirname(require.resolve(join(input, 'package.json'))) as any;
Expand All @@ -9,38 +9,6 @@ export const addons: PresetProperty<'addons'> = [
getAbsolutePath('@storybook/preset-react-webpack'),
];

const defaultFrameworkOptions: FrameworkOptions = {
legacyRootApi: true,
};

export const frameworkOptions = async (
_: never,
options: Options
): Promise<StorybookConfig['framework']> => {
const config = await options.presets.apply<StorybookConfig['framework']>('framework');

if (typeof config === 'string') {
return {
name: config,
options: defaultFrameworkOptions,
};
}
if (typeof config === 'undefined') {
return {
name: getAbsolutePath('@storybook/react-webpack5'),
options: defaultFrameworkOptions,
};
}

return {
name: config.name,
options: {
...defaultFrameworkOptions,
...config.options,
},
};
};

export const core: PresetProperty<'core'> = async (config, options) => {
const framework = await options.presets.apply('framework');

Expand Down
2 changes: 1 addition & 1 deletion code/frameworks/svelte-vite/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { svelteDocgen } from './plugins/svelte-docgen';
const getAbsolutePath = <I extends string>(input: I): I =>
dirname(require.resolve(join(input, 'package.json'))) as any;

export const core: PresetProperty<'core', StorybookConfig> = {
export const core: PresetProperty<'core'> = {
builder: getAbsolutePath('@storybook/builder-vite'),
renderer: getAbsolutePath('@storybook/svelte'),
};
Expand Down
5 changes: 1 addition & 4 deletions code/frameworks/vue3-webpack5/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { dirname, join } from 'path';
import type { PresetProperty } from '@storybook/types';
import type { StorybookConfig } from './types';

const getAbsolutePath = <I extends string>(input: I): I =>
dirname(require.resolve(join(input, 'package.json'))) as any;

export const addons: PresetProperty<'addons', StorybookConfig> = [
getAbsolutePath('@storybook/preset-vue3-webpack'),
];
export const addons: PresetProperty<'addons'> = [getAbsolutePath('@storybook/preset-vue3-webpack')];

export const core: PresetProperty<'core'> = async (config, options) => {
const framework = await options.presets.apply('framework');
Expand Down
3 changes: 1 addition & 2 deletions code/frameworks/web-components-vite/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { PresetProperty } from '@storybook/types';
import { dirname, join } from 'path';
import type { StorybookConfig } from './types';

const getAbsolutePath = <I extends string>(input: I): I =>
dirname(require.resolve(join(input, 'package.json'))) as any;

export const core: PresetProperty<'core', StorybookConfig> = {
export const core: PresetProperty<'core'> = {
builder: getAbsolutePath('@storybook/builder-vite'),
renderer: getAbsolutePath('@storybook/web-components'),
};
2 changes: 1 addition & 1 deletion code/lib/core-webpack/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Options, StorybookConfigRaw as StorybookConfigBase } from '@storybook/types';
import type { Options, StorybookConfig as StorybookConfigBase } from '@storybook/types';

export type { Options, Preset, BuilderResult, TypescriptOptions } from '@storybook/types';

Expand Down

0 comments on commit a91240a

Please sign in to comment.