Skip to content

Commit

Permalink
Merge pull request #27088 from storybookjs/valentin/provide-relaxed-t…
Browse files Browse the repository at this point in the history
…ypes-for-framework-builder-fields

Types: Fix typing for main.framework/builder fields
  • Loading branch information
valentinpalkovic authored May 14, 2024
2 parents e60fc12 + fdd0256 commit 1ae28db
Show file tree
Hide file tree
Showing 33 changed files with 94 additions and 43 deletions.
5 changes: 3 additions & 2 deletions code/frameworks/angular/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import {
BuilderOptions,
TypescriptOptions as TypescriptOptionsBuilder,
} from '@storybook/builder-webpack5';
import { CompatibleString } from '@storybook/types';

type FrameworkName = '@storybook/angular';
type BuilderName = '@storybook/builder-webpack5';
type FrameworkName = CompatibleString<'@storybook/angular'>;
type BuilderName = CompatibleString<'@storybook/builder-webpack5'>;

export type FrameworkOptions = AngularOptions & {
builder?: BuilderOptions;
Expand Down
5 changes: 3 additions & 2 deletions code/frameworks/ember/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import type {
BuilderOptions,
TypescriptOptions as TypescriptOptionsBuilder,
} from '@storybook/builder-webpack5';
import type { CompatibleString } from '@storybook/types';

type FrameworkName = '@storybook/ember-webpack5';
type BuilderName = '@storybook/builder-webpack5';
type FrameworkName = CompatibleString<'@storybook/ember-webpack5'>;
type BuilderName = CompatibleString<'@storybook/builder-webpack5'>;

export type FrameworkOptions = {
builder?: BuilderOptions;
Expand Down
1 change: 1 addition & 0 deletions code/frameworks/html-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@storybook/core-server": "workspace:*",
"@storybook/html": "workspace:*",
"@storybook/node-logger": "workspace:*",
"@storybook/types": "workspace:*",
"magic-string": "^0.30.0"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions code/frameworks/html-vite/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { StorybookConfig as StorybookConfigBase } from '@storybook/types';
import type { StorybookConfig as StorybookConfigBase, CompatibleString } from '@storybook/types';
import type { StorybookConfigVite, BuilderOptions } from '@storybook/builder-vite';

type FrameworkName = '@storybook/html-vite';
type BuilderName = '@storybook/builder-vite';
type FrameworkName = CompatibleString<'@storybook/html-vite'>;
type BuilderName = CompatibleString<'@storybook/builder-vite'>;

export type FrameworkOptions = {
builder?: BuilderOptions;
Expand Down
1 change: 1 addition & 0 deletions code/frameworks/html-webpack5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"@storybook/global": "^5.0.0",
"@storybook/html": "workspace:*",
"@storybook/preset-html-webpack": "workspace:*",
"@storybook/types": "workspace:*",
"@types/node": "^18.0.0"
},
"devDependencies": {
Expand Down
5 changes: 3 additions & 2 deletions code/frameworks/html-webpack5/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import type {
BuilderOptions,
TypescriptOptions as TypescriptOptionsBuilder,
} from '@storybook/builder-webpack5';
import type { CompatibleString } from '@storybook/types';

type FrameworkName = '@storybook/html-webpack5';
type BuilderName = '@storybook/builder-webpack5';
type FrameworkName = CompatibleString<'@storybook/html-webpack5'>;
type BuilderName = CompatibleString<'@storybook/builder-webpack5'>;

export type FrameworkOptions = {
builder?: BuilderOptions;
Expand Down
5 changes: 3 additions & 2 deletions code/frameworks/nextjs/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import type {
BuilderOptions,
TypescriptOptions as TypescriptOptionsBuilder,
} from '@storybook/builder-webpack5';
import type { CompatibleString } from '@storybook/types';
import type * as NextImage from 'next/image';

type FrameworkName = '@storybook/nextjs';
type BuilderName = '@storybook/builder-webpack5';
type FrameworkName = CompatibleString<'@storybook/nextjs'>;
type BuilderName = CompatibleString<'@storybook/builder-webpack5'>;

export type FrameworkOptions = ReactOptions & {
nextConfigPath?: string;
Expand Down
3 changes: 2 additions & 1 deletion code/frameworks/preact-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
},
"dependencies": {
"@storybook/builder-vite": "workspace:*",
"@storybook/preact": "workspace:*"
"@storybook/preact": "workspace:*",
"@storybook/types": "workspace:*"
},
"devDependencies": {
"@types/node": "^18.0.0",
Expand Down
6 changes: 3 additions & 3 deletions code/frameworks/preact-vite/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { StorybookConfig as StorybookConfigBase } from '@storybook/types';
import type { CompatibleString, StorybookConfig as StorybookConfigBase } from '@storybook/types';
import type { StorybookConfigVite, BuilderOptions } from '@storybook/builder-vite';

type FrameworkName = '@storybook/preact-vite';
type BuilderName = '@storybook/builder-vite';
type FrameworkName = CompatibleString<'@storybook/preact-vite'>;
type BuilderName = CompatibleString<'@storybook/builder-vite'>;

export type FrameworkOptions = {
builder?: BuilderOptions;
Expand Down
1 change: 1 addition & 0 deletions code/frameworks/preact-webpack5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@storybook/core-common": "workspace:*",
"@storybook/preact": "workspace:*",
"@storybook/preset-preact-webpack": "workspace:*",
"@storybook/types": "workspace:*",
"@types/node": "^18.0.0"
},
"devDependencies": {
Expand Down
5 changes: 3 additions & 2 deletions code/frameworks/preact-webpack5/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import type {
BuilderOptions,
TypescriptOptions as TypescriptOptionsBuilder,
} from '@storybook/builder-webpack5';
import type { CompatibleString } from '@storybook/types';

type FrameworkName = '@storybook/preact-webpack5';
type BuilderName = '@storybook/builder-webpack5';
type FrameworkName = CompatibleString<'@storybook/preact-webpack5'>;
type BuilderName = CompatibleString<'@storybook/builder-webpack5'>;

export type FrameworkOptions = {
builder?: BuilderOptions;
Expand Down
1 change: 1 addition & 0 deletions code/frameworks/react-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"@storybook/builder-vite": "workspace:*",
"@storybook/node-logger": "workspace:*",
"@storybook/react": "workspace:*",
"@storybook/types": "workspace:*",
"find-up": "^5.0.0",
"magic-string": "^0.30.0",
"react-docgen": "^7.0.0",
Expand Down
5 changes: 3 additions & 2 deletions code/frameworks/react-vite/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import type {
CompatibleString,
StorybookConfig as StorybookConfigBase,
TypescriptOptions as TypescriptOptionsBase,
} from '@storybook/types';
import type { StorybookConfigVite, BuilderOptions } from '@storybook/builder-vite';
import type docgenTypescript from '@joshwooding/vite-plugin-react-docgen-typescript';

type FrameworkName = '@storybook/react-vite';
type BuilderName = '@storybook/builder-vite';
type FrameworkName = CompatibleString<'@storybook/react-vite'>;
type BuilderName = CompatibleString<'@storybook/builder-vite'>;

export type FrameworkOptions = {
builder?: BuilderOptions;
Expand Down
1 change: 1 addition & 0 deletions code/frameworks/react-webpack5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@storybook/builder-webpack5": "workspace:*",
"@storybook/preset-react-webpack": "workspace:*",
"@storybook/react": "workspace:*",
"@storybook/types": "workspace:*",
"@types/node": "^18.0.0"
},
"peerDependencies": {
Expand Down
5 changes: 3 additions & 2 deletions code/frameworks/react-webpack5/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import type {
BuilderOptions,
TypescriptOptions as TypescriptOptionsBuilder,
} from '@storybook/builder-webpack5';
import type { CompatibleString } from '@storybook/types';

type FrameworkName = '@storybook/react-webpack5';
type BuilderName = '@storybook/builder-webpack5';
type FrameworkName = CompatibleString<'@storybook/react-webpack5'>;
type BuilderName = CompatibleString<'@storybook/builder-webpack5'>;

export type FrameworkOptions = ReactOptions & {
builder?: BuilderOptions;
Expand Down
1 change: 1 addition & 0 deletions code/frameworks/server-webpack5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@storybook/core-common": "workspace:*",
"@storybook/preset-server-webpack": "workspace:*",
"@storybook/server": "workspace:*",
"@storybook/types": "workspace:*",
"@types/node": "^18.0.0"
},
"devDependencies": {
Expand Down
5 changes: 3 additions & 2 deletions code/frameworks/server-webpack5/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import type {
BuilderOptions,
TypescriptOptions as TypescriptOptionsBuilder,
} from '@storybook/builder-webpack5';
import type { CompatibleString } from '@storybook/types';

type FrameworkName = '@storybook/server-webpack5';
type BuilderName = '@storybook/builder-webpack5';
type FrameworkName = CompatibleString<'@storybook/server-webpack5'>;
type BuilderName = CompatibleString<'@storybook/builder-webpack5'>;

export type FrameworkOptions = {
builder?: BuilderOptions;
Expand Down
1 change: 1 addition & 0 deletions code/frameworks/svelte-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@storybook/builder-vite": "workspace:*",
"@storybook/node-logger": "workspace:*",
"@storybook/svelte": "workspace:*",
"@storybook/types": "workspace:*",
"magic-string": "^0.30.0",
"svelte-preprocess": "^5.1.1",
"sveltedoc-parser": "^4.2.1",
Expand Down
6 changes: 3 additions & 3 deletions code/frameworks/svelte-vite/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { StorybookConfig as StorybookConfigBase } from '@storybook/types';
import type { CompatibleString, StorybookConfig as StorybookConfigBase } from '@storybook/types';
import type { StorybookConfigVite, BuilderOptions } from '@storybook/builder-vite';

type FrameworkName = '@storybook/svelte-vite';
type BuilderName = '@storybook/builder-vite';
type FrameworkName = CompatibleString<'@storybook/svelte-vite'>;
type BuilderName = CompatibleString<'@storybook/builder-vite'>;

export type FrameworkOptions = {
builder?: BuilderOptions;
Expand Down
3 changes: 2 additions & 1 deletion code/frameworks/svelte-webpack5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"@storybook/builder-webpack5": "workspace:*",
"@storybook/core-common": "workspace:*",
"@storybook/preset-svelte-webpack": "workspace:*",
"@storybook/svelte": "workspace:*"
"@storybook/svelte": "workspace:*",
"@storybook/types": "workspace:*"
},
"devDependencies": {
"svelte": "^4.0.0",
Expand Down
5 changes: 3 additions & 2 deletions code/frameworks/svelte-webpack5/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import type {
BuilderOptions,
TypescriptOptions as TypescriptOptionsBuilder,
} from '@storybook/builder-webpack5';
import type { CompatibleString } from '@storybook/types';

type FrameworkName = '@storybook/svelte-webpack5';
type BuilderName = '@storybook/builder-webpack5';
type FrameworkName = CompatibleString<'@storybook/svelte-webpack5'>;
type BuilderName = CompatibleString<'@storybook/builder-webpack5'>;

export type FrameworkOptions = SvelteOptions & {
builder?: BuilderOptions;
Expand Down
3 changes: 2 additions & 1 deletion code/frameworks/sveltekit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
"@storybook/addon-actions": "workspace:*",
"@storybook/builder-vite": "workspace:*",
"@storybook/svelte": "workspace:*",
"@storybook/svelte-vite": "workspace:*"
"@storybook/svelte-vite": "workspace:*",
"@storybook/types": "workspace:*"
},
"devDependencies": {
"@types/node": "^18.0.0",
Expand Down
6 changes: 3 additions & 3 deletions code/frameworks/sveltekit/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { BuilderOptions, StorybookConfigVite } from '@storybook/builder-vite';
import type { StorybookConfig as StorybookConfigBase } from '@storybook/types';
import type { CompatibleString, StorybookConfig as StorybookConfigBase } from '@storybook/types';
import type { enhance } from './mocks/app/forms';
import type { goto, invalidate, invalidateAll } from './mocks/app/navigation';

type FrameworkName = '@storybook/sveltekit';
type BuilderName = '@storybook/builder-vite';
type FrameworkName = CompatibleString<'@storybook/sveltekit'>;
type BuilderName = CompatibleString<'@storybook/builder-vite'>;

export type FrameworkOptions = {
builder?: BuilderOptions;
Expand Down
1 change: 1 addition & 0 deletions code/frameworks/vue3-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"dependencies": {
"@storybook/builder-vite": "workspace:*",
"@storybook/core-server": "workspace:*",
"@storybook/types": "workspace:*",
"@storybook/vue3": "workspace:*",
"find-package-json": "^1.2.0",
"magic-string": "^0.30.0",
Expand Down
6 changes: 3 additions & 3 deletions code/frameworks/vue3-vite/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { BuilderOptions, StorybookConfigVite } from '@storybook/builder-vite';
import type { StorybookConfig as StorybookConfigBase } from '@storybook/types';
import type { CompatibleString, StorybookConfig as StorybookConfigBase } from '@storybook/types';
import type { ComponentMeta } from 'vue-component-meta';
import type { ComponentDoc } from 'vue-docgen-api';

type FrameworkName = '@storybook/vue3-vite';
type BuilderName = '@storybook/builder-vite';
type FrameworkName = CompatibleString<'@storybook/vue3-vite'>;
type BuilderName = CompatibleString<'@storybook/builder-vite'>;

/**
* Available docgen plugins for vue.
Expand Down
1 change: 1 addition & 0 deletions code/frameworks/vue3-webpack5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@storybook/builder-webpack5": "workspace:*",
"@storybook/core-common": "workspace:*",
"@storybook/preset-vue3-webpack": "workspace:*",
"@storybook/types": "workspace:*",
"@storybook/vue3": "workspace:*",
"@types/node": "^18.0.0"
},
Expand Down
5 changes: 3 additions & 2 deletions code/frameworks/vue3-webpack5/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import type {
BuilderOptions,
TypescriptOptions as TypescriptOptionsBuilder,
} from '@storybook/builder-webpack5';
import type { CompatibleString } from '@storybook/types';

type FrameworkName = '@storybook/vue3-webpack5';
type BuilderName = '@storybook/builder-webpack5';
type FrameworkName = CompatibleString<'@storybook/vue3-webpack5'>;
type BuilderName = CompatibleString<'@storybook/builder-webpack5'>;

export type FrameworkOptions = {
builder?: BuilderOptions;
Expand Down
1 change: 1 addition & 0 deletions code/frameworks/web-components-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@storybook/builder-vite": "workspace:*",
"@storybook/core-server": "workspace:*",
"@storybook/node-logger": "workspace:*",
"@storybook/types": "workspace:*",
"@storybook/web-components": "workspace:*",
"magic-string": "^0.30.0"
},
Expand Down
6 changes: 3 additions & 3 deletions code/frameworks/web-components-vite/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { StorybookConfig as StorybookConfigBase } from '@storybook/types';
import type { CompatibleString, StorybookConfig as StorybookConfigBase } from '@storybook/types';
import type { StorybookConfigVite, BuilderOptions } from '@storybook/builder-vite';

type FrameworkName = '@storybook/web-components-vite';
type BuilderName = '@storybook/builder-vite';
type FrameworkName = CompatibleString<'@storybook/web-components-vite'>;
type BuilderName = CompatibleString<'@storybook/builder-vite'>;

export type FrameworkOptions = {
builder?: BuilderOptions;
Expand Down
1 change: 1 addition & 0 deletions code/frameworks/web-components-webpack5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"dependencies": {
"@storybook/builder-webpack5": "workspace:*",
"@storybook/core-common": "workspace:*",
"@storybook/types": "workspace:*",
"@storybook/web-components": "workspace:*",
"@types/node": "^18.0.0"
},
Expand Down
5 changes: 3 additions & 2 deletions code/frameworks/web-components-webpack5/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
CompatibleString,
StorybookConfig as StorybookConfigBase,
TypescriptOptions as TypescriptOptionsWebComponents,
} from '@storybook/types';
Expand All @@ -8,8 +9,8 @@ import type {
TypescriptOptions as TypescriptOptionsBuilder,
} from '@storybook/builder-webpack5';

type FrameworkName = '@storybook/web-components-webpack5';
type BuilderName = '@storybook/builder-webpack5';
type FrameworkName = CompatibleString<'@storybook/web-components-webpack5'>;
type BuilderName = CompatibleString<'@storybook/builder-webpack5'>;

export type FrameworkOptions = {
builder?: BuilderOptions;
Expand Down
12 changes: 12 additions & 0 deletions code/lib/types/src/modules/core-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,3 +571,15 @@ export interface CoreCommon_StorybookInfo {
previewConfig?: string;
managerConfig?: string;
}

/**
* Given a generic string type, returns that type but ensures that a string in general is compatible with it.
* We use this construct to ensure that IDEs can provide better autocompletion for string types.
* This is, for example, needed for main config fields, where we want to ensure that the user can provide
* a custom string, but also a string that is compatible with the type.
* @example
* type Framework = CompatibleString<'@storybook/nextjs'>
* const framework: Framework = '@storybook/nextjs'; // valid and will be autocompleted
* const framework: Framework = path.dirname(require.resolve(path.join("@storybook/nextjs", "package.json"))) // valid
*/
export type CompatibleString<T extends string> = T | (string & Record<string, never>);
Loading

0 comments on commit 1ae28db

Please sign in to comment.