Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preset: Add common preset overrides mechanism #23915

Merged
merged 2 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion code/lib/core-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
"node": "./dist/presets/common-preset.js",
"require": "./dist/presets/common-preset.js"
},
"./dist/presets/common-override-preset": {
"types": "./dist/presets/common-override-preset.d.ts",
"node": "./dist/presets/common-override-preset.js",
"require": "./dist/presets/common-override-preset.js"
},
"./public/favicon.svg": "./public/favicon.svg",
"./package.json": "./package.json"
},
Expand Down Expand Up @@ -119,7 +124,8 @@
"entries": [
"./src/index.ts",
"./src/presets/babel-cache-preset.ts",
"./src/presets/common-preset.ts"
"./src/presets/common-preset.ts",
"./src/presets/common-override-preset.ts"
],
"platform": "node"
},
Expand Down
9 changes: 7 additions & 2 deletions code/lib/core-server/src/build-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ export async function buildDevStandalone(
// We hope to remove this in SB8
let presets = await loadAllPresets({
corePresets,
overridePresets: [],
overridePresets: [
require.resolve('@storybook/core-server/dist/presets/common-override-preset'),
],
...options,
});

Expand Down Expand Up @@ -112,7 +114,10 @@ export async function buildDevStandalone(
...corePresets,
require.resolve('@storybook/core-server/dist/presets/babel-cache-preset'),
],
overridePresets: previewBuilder.overridePresets ?? [],
overridePresets: [
...(previewBuilder.overridePresets || []),
require.resolve('@storybook/core-server/dist/presets/common-override-preset'),
],
...options,
});

Expand Down
9 changes: 7 additions & 2 deletions code/lib/core-server/src/build-static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ export async function buildStaticStandalone(options: BuildStaticStandaloneOption
require.resolve('@storybook/core-server/dist/presets/common-preset'),
...corePresets,
],
overridePresets: [],
overridePresets: [
require.resolve('@storybook/core-server/dist/presets/common-override-preset'),
],
...options,
});

Expand All @@ -103,7 +105,10 @@ export async function buildStaticStandalone(options: BuildStaticStandaloneOption
...corePresets,
require.resolve('@storybook/core-server/dist/presets/babel-cache-preset'),
],
overridePresets: previewBuilder.overridePresets || [],
overridePresets: [
...(previewBuilder.overridePresets || []),
require.resolve('@storybook/core-server/dist/presets/common-override-preset'),
],
...options,
});

Expand Down
14 changes: 14 additions & 0 deletions code/lib/core-server/src/presets/common-override-preset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { PresetProperty, StorybookConfig } from '@storybook/types';

export const framework: PresetProperty<'framework', StorybookConfig> = async (config) => {
// This will get called with the values from the user's main config, but before
// framework preset from framework packages e.g. react-webpack5 gets called.
// This means we can add default values to the framework config, before it's requested by other packages.
const name = typeof config === 'string' ? config : config?.name;
const options = typeof config === 'string' ? {} : config?.options || {};

return {
name,
options,
};
};