mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-09 00:19:13 +08:00
Fix types in presets
This commit is contained in:
parent
82b63d5459
commit
ec359a442d
@ -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.
|
||||
@ -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).
|
||||
|
@ -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 {
|
||||
@ -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,
|
||||
|
@ -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 {
|
||||
|
@ -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'),
|
||||
};
|
||||
|
@ -27,33 +27,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');
|
||||
|
||||
@ -136,7 +109,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'
|
||||
);
|
||||
|
@ -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'),
|
||||
};
|
||||
|
@ -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'),
|
||||
};
|
||||
|
@ -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;
|
||||
@ -9,46 +9,14 @@ 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');
|
||||
const presetFramework = await options.presets.apply('framework');
|
||||
|
||||
return {
|
||||
...config,
|
||||
builder: {
|
||||
name: getAbsolutePath('@storybook/builder-webpack5'),
|
||||
options: typeof framework === 'string' ? {} : framework.options.builder || {},
|
||||
options: typeof presetFramework === 'string' ? {} : presetFramework.options.builder || {},
|
||||
},
|
||||
renderer: getAbsolutePath('@storybook/react'),
|
||||
};
|
||||
|
@ -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'),
|
||||
};
|
||||
|
@ -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');
|
||||
|
@ -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'),
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user