From 04ea7402de46835102dce34eb31d46fa46d6405f Mon Sep 17 00:00:00 2001 From: jserfeng <1114550440@qq.com> Date: Wed, 6 Sep 2023 21:18:23 +0800 Subject: [PATCH] feat(storybook): add integration test --- packages/storybook/builder/src/core.ts | 7 ++++--- .../storybook/builder/src/plugin-storybook.ts | 4 +++- packages/storybook/builder/src/preset.ts | 20 +++++++++++++++++++ packages/storybook/framework/src/preset.ts | 10 +++++++++- packages/toolkit/utils/package.json | 2 +- pnpm-lock.yaml | 3 +-- 6 files changed, 38 insertions(+), 8 deletions(-) diff --git a/packages/storybook/builder/src/core.ts b/packages/storybook/builder/src/core.ts index c6230c5161e2..248334ac8777 100644 --- a/packages/storybook/builder/src/core.ts +++ b/packages/storybook/builder/src/core.ts @@ -15,15 +15,16 @@ export async function getCompiler( const { presets } = options; const entries = await presets.apply('entries', []); - const otherBuilderConfig = - (await presets.apply('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('modern', loadedConfig)) || {}; + const builderConfig = mergeBuilderConfig(otherBuilderConfig, loadedConfig); const provider = await getProvider(bundler, builderConfig); diff --git a/packages/storybook/builder/src/plugin-storybook.ts b/packages/storybook/builder/src/plugin-storybook.ts index df1969a2e4bb..774d1ef905fe 100644 --- a/packages/storybook/builder/src/plugin-storybook.ts +++ b/packages/storybook/builder/src/plugin-storybook.ts @@ -46,6 +46,9 @@ export const pluginStorybook: ( ) => BuilderPlugin = (cwd, options) => { return { name: 'builder-plugin-storybook', + + remove: ['builder-plugin-inline'], + async setup(api) { api.modifyBuilderConfig(async builderConfig => { await applyDefines(builderConfig, options); @@ -63,7 +66,6 @@ export const pluginStorybook: ( ...(config.resolve.conditionNames || []), ]; config.resolve.fullySpecified = false; - await applyMdxLoader(config, options); await applyCsfPlugin(config, options); }; diff --git a/packages/storybook/builder/src/preset.ts b/packages/storybook/builder/src/preset.ts index 5c4e7acfa62a..2d4325f427fe 100644 --- a/packages/storybook/builder/src/preset.ts +++ b/packages/storybook/builder/src/preset.ts @@ -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'); @@ -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'; diff --git a/packages/storybook/framework/src/preset.ts b/packages/storybook/framework/src/preset.ts index 8e64f1c84bf6..3ab55fb39f41 100644 --- a/packages/storybook/framework/src/preset.ts +++ b/packages/storybook/framework/src/preset.ts @@ -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'); @@ -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'), }, }, diff --git a/packages/toolkit/utils/package.json b/packages/toolkit/utils/package.json index 3f5006617230..ca4c3f588ff2 100644 --- a/packages/toolkit/utils/package.json +++ b/packages/toolkit/utils/package.json @@ -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": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b65b5954db25..9838a7ba1c52 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -30856,7 +30856,7 @@ packages: dependencies: lilconfig: 2.1.0 postcss: 8.4.21 - ts-node: 10.9.1(@types/node@18.11.17)(typescript@5.0.4) + ts-node: 10.9.1(@types/node@16.11.68)(typescript@5.0.4) yaml: 1.10.2 /postcss-load-config@3.1.4(postcss@8.4.27)(ts-node@10.9.1): @@ -36537,7 +36537,6 @@ packages: typescript: 5.0.4 v8-compile-cache-lib: 3.0.1 yn: 3.1.1 - dev: true /ts-node@10.9.1(@types/node@18.11.17)(typescript@5.0.4): resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==}