Skip to content

Commit

Permalink
feat(storybook): add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
JSerFeng committed Sep 6, 2023
1 parent 79de3b1 commit 04ea740
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 8 deletions.
7 changes: 4 additions & 3 deletions packages/storybook/builder/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ export async function getCompiler(

const { presets } = options;
const entries = await presets.apply<string[]>('entries', []);
const otherBuilderConfig =
(await presets.apply<BuilderConfig | void>('modern')) || {};

const res = await runWithErrorMsg(
() => loadConfig(cwd, frameworkConfig.configPath || 'modern.config.ts'),
'Failed to load config',
);

const loadedConfig = (res ? res.config : {}) as BuilderConfig;

const otherBuilderConfig =
(await presets.apply<BuilderConfig | void>('modern', loadedConfig)) || {};

const builderConfig = mergeBuilderConfig(otherBuilderConfig, loadedConfig);

const provider = await getProvider(bundler, builderConfig);
Expand Down
4 changes: 3 additions & 1 deletion packages/storybook/builder/src/plugin-storybook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export const pluginStorybook: (
) => BuilderPlugin<WebpackAPI | RspackAPI> = (cwd, options) => {
return {
name: 'builder-plugin-storybook',

remove: ['builder-plugin-inline'],

async setup(api) {
api.modifyBuilderConfig(async builderConfig => {
await applyDefines(builderConfig, options);
Expand All @@ -63,7 +66,6 @@ export const pluginStorybook: (
...(config.resolve.conditionNames || []),
];
config.resolve.fullySpecified = false;

await applyMdxLoader(config, options);
await applyCsfPlugin(config, options);
};
Expand Down
20 changes: 20 additions & 0 deletions packages/storybook/builder/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { join, resolve } from 'path';
import type { Options } from '@storybook/types';
import { getConfig } from './build';
import { STORYBOOK_CONFIG_ENTRY } from './utils';
import { BuilderConfig } from './types';

export const previewMainTemplate = () => {
return require.resolve('@modern-js/storybook-builder/templates/preview.ejs');
Expand Down Expand Up @@ -36,4 +37,23 @@ export const entries = async (_: unknown, options: Options) => {
return result;
};

export const modern = (
builderConfig: BuilderConfig,
options: Options,
): BuilderConfig => {
// @ts-expect-error
return {
...builderConfig,

output: {
...builderConfig.output,
disableInlineRuntimeChunk: true,
distPath: {
...builderConfig.output?.distPath,
root: options.outputDir,
},
},
};
};

export { decorators } from './addons/preset/preview';
10 changes: 9 additions & 1 deletion packages/storybook/framework/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'path';
import type { Options } from '@storybook/types';
import type { BuilderConfig } from '@modern-js/storybook-builder/types';

export const frameworkOptions = async (_: never, options: Options) => {
const config = await options.presets.apply('framework');
Expand All @@ -25,10 +26,17 @@ export const frameworkOptions = async (_: never, options: Options) => {
};
};

export const modern = async (_options: Options) => {
export const modern = (
config: BuilderConfig,
_options: Options,
): BuilderConfig => {
// @ts-expect-error
return {
...config,
source: {
...config.source,
alias: {
...config.source?.alias,
'@storybook/react': absPath('@storybook/react'),
},
},
Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"exports": {
".": {
"jsnext:source": "./src/index.ts",
"types": "./dist/index.d.ts",
"types": "./dist/types/index.d.ts",
"default": "./dist/cjs/index.js"
},
"./logger": {
Expand Down
3 changes: 1 addition & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 04ea740

Please sign in to comment.