diff --git a/.changeset/light-games-shave.md b/.changeset/light-games-shave.md new file mode 100644 index 000000000000..1def667e4aae --- /dev/null +++ b/.changeset/light-games-shave.md @@ -0,0 +1,7 @@ +--- +'@modern-js/storybook-builder': minor +--- + +feat(storybook): use uni-builder instead of modern.js builder as build tool + +feat(storybook): 使用 uni-builder 代替 modern.js builder 作为底层构建工具 diff --git a/.changeset/silent-candles-teach.md b/.changeset/silent-candles-teach.md new file mode 100644 index 000000000000..4ff21735d702 --- /dev/null +++ b/.changeset/silent-candles-teach.md @@ -0,0 +1,6 @@ +--- +'@modern-js/module-tools': patch +--- + +fix(module-tools): add js extension when pkg type is module +fix(module-tools): 当包类型为 module 时,给产物里的相对路径补全文件后缀 diff --git a/.changeset/slimy-dogs-hang.md b/.changeset/slimy-dogs-hang.md index b782bca0ca5f..28a528f3f174 100644 --- a/.changeset/slimy-dogs-hang.md +++ b/.changeset/slimy-dogs-hang.md @@ -2,6 +2,6 @@ '@modern-js/builder-doc': patch --- -chore(plugin-vue): builder vue & vue2 plugin is no longer maintained,, please use rsbuild instead +chore(plugin-vue): builder vue & vue2 plugin is no longer maintained, please use rsbuild instead chore(plugin-vue): builder vue & vue2 插件不再维护, 请使用 rsbuild 代替 diff --git a/packages/document/module-doc/docs/en/guide/basic/use-module-doc.mdx b/packages/document/module-doc/docs/en/guide/basic/use-module-doc.mdx index c0fb2159578b..cab6789e7dcd 100644 --- a/packages/document/module-doc/docs/en/guide/basic/use-module-doc.mdx +++ b/packages/document/module-doc/docs/en/guide/basic/use-module-doc.mdx @@ -56,7 +56,7 @@ The sidebars corresponding in turn to the above file paths and routing paths are ### Configure sidebar As shown in the figure above, the module documentation has automatically generated sidebars for file system routing, where the text of each column of the sidebar is determined by the file's first level title or directory name. -If you need to customize the sidebar, please use [_meta.json](https://rspress.dev/guide/basic/auto-nav-sidebar.html) or configure [sidebar](https://rspress.dev/api/config/config-theme.html#sidebar) directly. +If you need to customize the sidebar, please use [\_meta.json](https://rspress.dev/guide/basic/auto-nav-sidebar.html) or configure [sidebar](https://rspress.dev/api/config/config-theme.html#sidebar) directly. :::info If your document directory structure complies with internationalization, for example: @@ -146,9 +146,9 @@ export default defineConfig({ modulePluginDoc({ /** * Select the preview method - * @default web + * @default internal */ - previewMode: 'mobile', + previewMode: 'iframe', /** * Select iframe position * @default 'follow' @@ -167,12 +167,12 @@ If you only want to change the way a particular `jsx` and `tsx` block is preview // The content here will not be rendered ``` -```jsx web -// Used to render desktop components +```jsx internal +// Used to render components in documentation ``` -```jsx mobile -// Used to render mobile components +```jsx iframe +// Used to render components in iframe ``` ```` @@ -186,6 +186,12 @@ If our demo is very complex, then it is recommended to write the demo separately ``` +This also supports setting the preview method for each individual code block, for example: + +```mdx + +``` + ## Using built-in components The plugin implements some built-in components internally so that you can develop module documentation more easily. @@ -398,10 +404,10 @@ type ParseToolOptions = { ### previewMode -- Type:`'mobile' | 'web'` -- Default: `'web'` +- Type:`'iframe' | 'internal'` +- Default: `'internal'` -In case of `web`, the component will be rendered directly in the page, otherwise it will be loaded through an iframe. +In case of `internal`, the component will be rendered directly in the page, otherwise it will be loaded through an iframe. ### deprecated: languages @@ -417,6 +423,7 @@ or directly configure [sidebar](https://rspress.dev/api/config/config-theme.html ::: ## Scripts + - `modern dev`: Start dev server for doc site. - `modern build --platform`: Build doc site in production, by default output directories is `doc_build`. diff --git a/packages/document/module-doc/docs/zh/guide/basic/use-module-doc.mdx b/packages/document/module-doc/docs/zh/guide/basic/use-module-doc.mdx index feefb3160644..2d3baa1d95d0 100644 --- a/packages/document/module-doc/docs/zh/guide/basic/use-module-doc.mdx +++ b/packages/document/module-doc/docs/zh/guide/basic/use-module-doc.mdx @@ -55,10 +55,11 @@ docs ### 配置侧边栏 如上图所示,模块文档已经为文件系统路由自动生成了侧边栏,其中侧边栏每一栏的文本是由文件的一级标题或者目录名决定。 -如果你需要自定义侧边栏,请使用 [_meta.json](https://rspress.dev/zh/guide/basic/auto-nav-sidebar.html) 或者直接配置 [sidebar](https://rspress.dev/zh/api/config/config-theme.html#sidebar)。 +如果你需要自定义侧边栏,请使用 [\_meta.json](https://rspress.dev/zh/guide/basic/auto-nav-sidebar.html) 或者直接配置 [sidebar](https://rspress.dev/zh/api/config/config-theme.html#sidebar)。 :::info 如果你的文档目录结构是符合国际化的,例如: + ```bash docs ├── en @@ -68,6 +69,7 @@ docs ├── button.mdx ├── index.mdx ``` + 你需要按照[国际化](https://rspress.dev/zh/guide/default-theme/i18n.html)章节,同时配置 `lang` 和 `locales`,否则模块自动生成的侧边栏不会处理 `zh` 和 `en` 这两个目录。 ::: @@ -139,9 +141,9 @@ export default defineConfig({ modulePluginDoc({ /** * 选择预览方式 - * @default web + * @default internal */ - previewMode: 'mobile', + previewMode: 'iframe', /** * 设置 iframe 的位置 * @default 'follow' @@ -160,12 +162,12 @@ export default defineConfig({ // 这里的内容不会被渲染 ``` -```jsx web -// 用来渲染桌面端组件 +```jsx internal +// 内置在文档内容里渲染 ``` -```jsx mobile -// 用来渲染移动端组件 +```jsx iframe +// 使用 iframe 渲染 ``` ```` @@ -179,6 +181,12 @@ export default defineConfig({ ``` +这同样支持单独设置代码块的预览方式,例如: + +```mdx + +``` + ## 使用内置组件 插件内部实现了一部分内置组件,以便于你可以更轻松地开发模块文档。 @@ -245,15 +253,16 @@ export const Button = (props?: ButtonProps) => {}; :::warning 如果 Props 里使用了 React 的类型,你需要在 tsconfig.json 里添加 types ,否则会解析不到 React 命名空间下的类型。 + ```json { "compilerOptions": { - "types": ["react"], - }, + "types": ["react"] + } } ``` -::: +::: - `documentation`适用于工具库场景,用来解析 JSDoc 注释。 @@ -394,10 +403,10 @@ type ParseToolOptions = { 代码块预览方式。 -- 类型:`'mobile' | 'web'` -- 默认值: `'web'` +- 类型:`'internal' | 'iframe'` +- 默认值: `'internal'` -`web`时,代码块内容将会直接渲染在页面中,反之将会通过 iframe 加载。 +`internal`时,代码块内容将会直接渲染在页面中,反之将会通过 iframe 加载。 ### deprecated: languages @@ -408,11 +417,12 @@ type ParseToolOptions = { ### deprecated: useModuleSidebar :::warning -从 MAJOR_VERSION.44.0 版本开始,内部实现了嗅探机制,请直接使用 [_meta.json](https://rspress.dev/zh/guide/basic/auto-nav-sidebar.html) +从 MAJOR_VERSION.44.0 版本开始,内部实现了嗅探机制,请直接使用 [\_meta.json](https://rspress.dev/zh/guide/basic/auto-nav-sidebar.html) 或者直接配置 [sidebar](https://rspress.dev/zh/api/config/config-theme.html#sidebar) 来实现自定义侧边栏。 ::: ## 命令行 + - `modern dev`: 启动文档站本地开发。 - `modern build --platform`: 构建生产环境产物。 diff --git a/packages/solutions/module-tools/src/builder/feature/redirect.ts b/packages/solutions/module-tools/src/builder/feature/redirect.ts index bac87b49a40e..be790846eb27 100644 --- a/packages/solutions/module-tools/src/builder/feature/redirect.ts +++ b/packages/solutions/module-tools/src/builder/feature/redirect.ts @@ -46,6 +46,7 @@ async function redirectImport( filePath: string, outputDir: string, jsExtension: string, + isModule?: boolean, matchPath?: MatchPath, ): Promise { const str: MagicString = new MagicString(code); @@ -94,7 +95,11 @@ async function redirectImport( } if (redirect.autoExtension) { - if (ext === '' && jsExtension !== '.js' && name.startsWith('.')) { + if ( + ext === '' && + name.startsWith('.') && + (jsExtension !== '.js' || isModule) + ) { // add extension for relative path, no check if it's a directory. str.overwrite(start, end, `${name}${jsExtension}`); return; @@ -267,7 +272,7 @@ export const redirect = { if (!matchModule.length) { return args; } - const { jsExtension } = getDefaultOutExtension({ + const { jsExtension, isModule } = getDefaultOutExtension({ format, root, autoExtension, @@ -281,6 +286,7 @@ export const redirect = { id, dirname(outputPath), jsExtension, + isModule, matchPath, ); return { diff --git a/packages/solutions/module-tools/src/utils/outExtension.ts b/packages/solutions/module-tools/src/utils/outExtension.ts index 47bb40cc5250..c384fd2607c5 100644 --- a/packages/solutions/module-tools/src/utils/outExtension.ts +++ b/packages/solutions/module-tools/src/utils/outExtension.ts @@ -41,5 +41,6 @@ export const getDefaultOutExtension = (options: { return { jsExtension, dtsExtension, + isModule, }; }; diff --git a/packages/storybook/builder/package.json b/packages/storybook/builder/package.json index 0af29eee6bf2..ebafad1f7fa8 100644 --- a/packages/storybook/builder/package.json +++ b/packages/storybook/builder/package.json @@ -56,23 +56,23 @@ }, "license": "MIT", "dependencies": { - "@modern-js/builder": "workspace:*", - "@modern-js/builder-shared": "workspace:*", + "@rsbuild/shared": "0.4.3", + "@modern-js/uni-builder": "workspace:*", "@modern-js/core": "workspace:*", "@modern-js/runtime": "workspace:*", "@modern-js/utils": "workspace:*", "@rspack/plugin-react-refresh": "0.4.5", - "@storybook/components": "~7.6.1", - "@storybook/core-common": "~7.6.1", - "@storybook/csf-plugin": "~7.6.1", + "@storybook/components": "~7.6.12", + "@storybook/core-common": "~7.6.12", + "@storybook/csf-plugin": "~7.6.12", "@storybook/global": "~5.0.0", "@storybook/mdx1-csf": "~1.0.0", "@storybook/mdx2-csf": "~1.1.0", - "@storybook/preview": "~7.6.1", - "@storybook/preview-api": "~7.6.1", + "@storybook/preview": "~7.6.12", + "@storybook/preview-api": "~7.6.12", "@storybook/react-docgen-typescript-plugin": "1.0.6--canary.9.0c3f3b7.0", - "@storybook/router": "~7.6.1", - "@storybook/theming": "~7.6.1", + "@storybook/router": "~7.6.12", + "@storybook/theming": "~7.6.12", "ast-types": "^0.14.2", "minimatch": "^9.0.3", "react-docgen": "6.0.0-alpha.3", @@ -83,28 +83,14 @@ "webpack-hot-middleware": "^2.25.4" }, "devDependencies": { - "@modern-js/builder-rspack-provider": "workspace:*", - "@modern-js/builder-webpack-provider": "workspace:*", "@modern-js/core": "workspace:*", "@scripts/build": "workspace:*", - "@storybook/types": "~7.6.1", + "@storybook/types": "~7.6.12", "@types/babel__core": "^7.20.1", "@types/serve-static": "^1.13.10", "@types/webpack-hot-middleware": "^2.25.6", "typescript": "^5.2.2" }, - "peerDependencies": { - "@modern-js/builder-webpack-provider": "workspace:^2.46.1", - "@modern-js/builder-rspack-provider": "workspace:^2.46.1" - }, - "peerDependenciesMeta": { - "@modern-js/builder-webpack-provider": { - "optional": true - }, - "@modern-js/builder-rspack-provider": { - "optional": true - } - }, "publishConfig": { "registry": "https://registry.npmjs.org/", "access": "public", diff --git a/packages/storybook/builder/src/build.ts b/packages/storybook/builder/src/build.ts index 9851d5a32d3c..a9cf99348064 100644 --- a/packages/storybook/builder/src/build.ts +++ b/packages/storybook/builder/src/build.ts @@ -1,5 +1,5 @@ import { dirname, join, parse } from 'path'; -import webpackDevMiddleware from '@modern-js/builder-shared/webpack-dev-middleware'; +import webpackDevMiddleware from '@rsbuild/shared/webpack-dev-middleware'; import webpackHotMiddleware from 'webpack-hot-middleware'; import serveStatic from 'serve-static'; import type { Builder as RawStorybookBuilder, Stats } from '@storybook/types'; diff --git a/packages/storybook/builder/src/core.ts b/packages/storybook/builder/src/core.ts index adc738a8a5e4..cc2b2a071207 100644 --- a/packages/storybook/builder/src/core.ts +++ b/packages/storybook/builder/src/core.ts @@ -1,10 +1,11 @@ -import { createBuilder, mergeBuilderConfig } from '@modern-js/builder'; +import { createUniBuilder } from '@modern-js/uni-builder'; +import { mergeRsbuildConfig, type RsbuildConfig } from '@rsbuild/shared'; import { loadConfig } from '@modern-js/core'; import type { Options } from '@storybook/types'; -import type { Compiler } from '@modern-js/builder-shared/webpack-dev-middleware'; -import type { BuilderConfig, BuilderOptions } from './types'; -import { getConfigFileName, getProvider, runWithErrorMsg } from './utils'; -import { pluginStorybook } from './plugin-storybook'; +import type { Compiler } from '@rsbuild/shared/webpack-dev-middleware'; +import type { BuilderOptions, BuilderConfig } from './types'; +import { getConfigFileName, runWithErrorMsg } from './utils'; +import { pluginStorybook, addonBabelAdapter } from './plugin-storybook'; export async function getCompiler( cwd: string, @@ -27,27 +28,24 @@ export async function getCompiler( (await presets.apply('modern', loadedConfig)) || loadedConfig; - const provider = await getProvider( - bundler, - mergeBuilderConfig(finalConfig, builderOptions.builderConfig) || {}, - ); + const uniBuilderConfig = builderOptions.builderConfig + ? (mergeRsbuildConfig( + finalConfig as RsbuildConfig, + builderOptions.builderConfig as RsbuildConfig, + ) as BuilderConfig) + : finalConfig || {}; + + const bundlerType = bundler || 'webpack'; - if (!provider) { - if (bundler) { - throw new Error( - `You choose to use ${bundler}, but @modern-js/builder-${bundler}-provider not found in your project, please install it`, - ); - } else { - throw new Error( - `Please install one provider first, try install @modern-js/builder-rspack-provider or @modern-js/builder-webpack-provider first`, - ); - } - } - - const builder = await createBuilder(provider, { + const builder = await createUniBuilder({ + bundlerType, cwd, target: 'web', - framework: 'modern.js storybook', + frameworkConfigPath: res?.path ? res.path : undefined, + config: + bundlerType === 'webpack' + ? await addonBabelAdapter(uniBuilderConfig, options) + : uniBuilderConfig, entry: { main: entries, }, @@ -58,5 +56,5 @@ export async function getCompiler( ...(finalConfig.builderPlugins || []), ]); - return builder.createCompiler() as Promise; + return builder.createCompiler(); } diff --git a/packages/storybook/builder/src/docgen/index.ts b/packages/storybook/builder/src/docgen/index.ts index 7f2d5f375605..28c473ddd057 100644 --- a/packages/storybook/builder/src/docgen/index.ts +++ b/packages/storybook/builder/src/docgen/index.ts @@ -1,7 +1,6 @@ import type { Options } from '@storybook/types'; import { CHAIN_ID, logger } from '@modern-js/utils'; -import { RspackConfig } from '@modern-js/builder-rspack-provider'; -import { WebpackChain } from '@modern-js/builder-webpack-provider'; +import type { RspackConfig, WebpackChain } from '@rsbuild/shared'; export type DocgenOptions = { reactDocgen?: 'react-docgen' | 'react-docgen-typescript' | false; diff --git a/packages/storybook/builder/src/plugin-storybook.ts b/packages/storybook/builder/src/plugin-storybook.ts index ba899eece72a..7a2f03800449 100644 --- a/packages/storybook/builder/src/plugin-storybook.ts +++ b/packages/storybook/builder/src/plugin-storybook.ts @@ -7,12 +7,6 @@ import { applyOptionsChain, logger, } from '@modern-js/utils'; -import { - BuilderPlugin, - SharedBuilderConfig, - ToolsBabelConfig, - mergeBuilderConfig, -} from '@modern-js/builder-shared'; import { CompileOptions } from '@storybook/mdx2-csf'; import type { CoreConfig, @@ -30,17 +24,19 @@ import { } from '@storybook/core-common'; import { globalsNameReferenceMap } from '@storybook/preview/globals'; import type { PluginItem } from '@babel/core'; -import type { - BuilderPluginAPI as WebpackAPI, - WebpackConfig, -} from '@modern-js/builder-webpack-provider'; -import type { - BuilderPluginAPI as RspackAPI, - RspackConfig, -} from '@modern-js/builder-rspack-provider'; +import { + type RsbuildPlugin, + type RsbuildPluginAPI, + type RsbuildConfig, + type WebpackConfig, + type RspackConfig, + mergeRsbuildConfig, +} from '@rsbuild/shared'; + import { unplugin as csfPlugin } from '@storybook/csf-plugin'; import { minimatch } from 'minimatch'; -import { AllBuilderConfig, BuilderOptions } from './types'; +import type { UniBuilderConfig } from '@modern-js/uni-builder'; +import { BuilderConfig, BuilderOptions } from './types'; import { toImportFn, virtualModule, @@ -64,7 +60,7 @@ export async function finalize() { export const pluginStorybook: ( cwd: string, options: Options, -) => BuilderPlugin = (cwd, options) => { +) => RsbuildPlugin = (cwd, options) => { return { name: 'builder-plugin-storybook', @@ -89,7 +85,7 @@ export const pluginStorybook: ( return absolutePattern; }); - api.modifyBuilderConfig(async builderConfig => { + api.modifyRsbuildConfig(async builderConfig => { // storybook needs a virtual entry, // when new stories get created, the // entry needs to be recauculated @@ -120,14 +116,14 @@ export const pluginStorybook: ( await applyCsfPlugin(config, options); }; - if ('modifyWebpackConfig' in api) { + if (api.context.bundlerType === 'webpack') { addonAdapter(api, options); api.modifyWebpackConfig(modifyConfig); api.modifyWebpackChain(async chain => { await applyDocgenWebpack(chain, options); }); - } else if ('modifyRspackConfig' in api) { + } else { api.modifyRspackConfig(async config => { await modifyConfig(config); await applyDocgenRspack(config, options); @@ -168,7 +164,7 @@ async function prepareStorybookModules( tempDir: string, cwd: string, options: Options, - builderConfig: SharedBuilderConfig, + builderConfig: RsbuildConfig, storyPatterns: string[], ) { const mappings = await createStorybookModules(cwd, options, storyPatterns); @@ -196,6 +192,7 @@ async function prepareStorybookModules( ...mappingsAlias, }, builderConfig.source.alias, + { target: 'web' }, ); if (isDev()) { @@ -206,7 +203,7 @@ async function prepareStorybookModules( } } -async function applyDefines(builderConfig: AllBuilderConfig, options: Options) { +async function applyDefines(builderConfig: RsbuildConfig, options: Options) { const { presets } = options; const envs = await presets.apply>('env'); @@ -219,7 +216,7 @@ async function applyDefines(builderConfig: AllBuilderConfig, options: Options) { }; } -async function applyHTML(builderConfig: AllBuilderConfig, options: Options) { +async function applyHTML(builderConfig: RsbuildConfig, options: Options) { const { presets, packageJson, @@ -338,8 +335,8 @@ async function applyMdxLoader( ); } -function applyExternals(builderConfig: AllBuilderConfig) { - const config = mergeBuilderConfig( +function applyExternals(builderConfig: RsbuildConfig) { + const config = mergeRsbuildConfig( { output: { ...builderConfig.output, @@ -422,7 +419,7 @@ async function createStoriesEntry(cwd: string, storyPatterns: string[]) { return await toImportFn(cwd, stories); } -async function applyReact(config: AllBuilderConfig, options: Options) { +async function applyReact(config: RsbuildConfig, options: Options) { let version = '18.0.0'; try { // @ts-expect-error @@ -443,6 +440,7 @@ async function applyReact(config: AllBuilderConfig, options: Options) { '@storybook/react-dom-shim': '@storybook/react-dom-shim/dist/react-18', }, config.source.alias, + { target: 'web' }, ); } } @@ -488,63 +486,10 @@ async function watchStories( /** * Some addons expose babel plugins and presets, or modify webpack */ -function addonAdapter(api: WebpackAPI | RspackAPI, options: Options) { +function addonAdapter(api: RsbuildPluginAPI, options: Options) { const { presets } = options; - api.modifyBuilderConfig(async finalConfig => { - const babelOptions = await presets.apply('babel', {}, { ...options }); - finalConfig.tools ??= {}; - const userConfig = finalConfig.tools.babel; - finalConfig.tools.babel = (config, utils) => { - const getPluginName = (plugin: PluginItem) => - Array.isArray(plugin) ? plugin[0] : plugin; - const getOptions = (plugin: PluginItem) => - Array.isArray(plugin) ? plugin[1] : null; - - const replaceOrInsert = (plugin: PluginItem, plugins: PluginItem[]) => { - const pluginName = getPluginName(plugin); - - for (let i = 0; i < plugins.length; i++) { - if (getPluginName(plugins[i]) === pluginName) { - if (getOptions(plugin)) { - logger.info( - `Detected duplicated babel plugin or presets: ${pluginName}, overrides with the new one`, - ); - plugins[i] = plugin; - } - return; - } - } - - plugins.push(plugin); - }; - - const currentPlugins = config.plugins || []; - const currentPresets = config.presets || []; - - // O(n * n) but the number of plugins should be small - for (const plugin of babelOptions.plugins || []) { - replaceOrInsert(plugin, currentPlugins); - } - for (const preset of babelOptions.presets || []) { - replaceOrInsert(preset, currentPresets); - } - - const finalConfig: ToolsBabelConfig = { - ...babelOptions, - plugins: currentPlugins, - presets: currentPresets, - }; - - if (userConfig) { - return applyOptionsChain(finalConfig, userConfig, utils); - } else { - return finalConfig; - } - }; - }); - - (api as WebpackAPI).modifyWebpackConfig(async config => { + api.modifyWebpackConfig(async config => { const finalDefaultConfig = await presets.apply( 'webpackFinal', config, @@ -553,3 +498,63 @@ function addonAdapter(api: WebpackAPI | RspackAPI, options: Options) { return finalDefaultConfig; }); } + +export async function addonBabelAdapter( + finalConfig: BuilderConfig, + options: Options, +) { + const { presets } = options; + + const babelOptions = await presets.apply('babel', {}, { ...options }); + finalConfig.tools ??= {}; + const userConfig = finalConfig.tools.babel; + finalConfig.tools.babel = (config, utils) => { + const getPluginName = (plugin: PluginItem) => + Array.isArray(plugin) ? plugin[0] : plugin; + const getOptions = (plugin: PluginItem) => + Array.isArray(plugin) ? plugin[1] : null; + + const replaceOrInsert = (plugin: PluginItem, plugins: PluginItem[]) => { + const pluginName = getPluginName(plugin); + + for (let i = 0; i < plugins.length; i++) { + if (getPluginName(plugins[i]) === pluginName) { + if (getOptions(plugin)) { + logger.info( + `Detected duplicated babel plugin or presets: ${pluginName}, overrides with the new one`, + ); + plugins[i] = plugin; + } + return; + } + } + + plugins.push(plugin); + }; + + const currentPlugins = config.plugins || []; + const currentPresets = config.presets || []; + + // O(n * n) but the number of plugins should be small + for (const plugin of babelOptions.plugins || []) { + replaceOrInsert(plugin, currentPlugins); + } + for (const preset of babelOptions.presets || []) { + replaceOrInsert(preset, currentPresets); + } + + const finalConfig: NonNullable['babel'] = { + ...babelOptions, + plugins: currentPlugins, + presets: currentPresets, + }; + + if (userConfig) { + return applyOptionsChain(finalConfig, userConfig, utils); + } else { + return finalConfig; + } + }; + + return finalConfig; +} diff --git a/packages/storybook/builder/src/preset.ts b/packages/storybook/builder/src/preset.ts index 6d8d5d7cb420..154aca29af45 100644 --- a/packages/storybook/builder/src/preset.ts +++ b/packages/storybook/builder/src/preset.ts @@ -1,8 +1,8 @@ import { join, resolve } from 'path'; import type { Options } from '@storybook/types'; +import type { UniBuilderConfig } from '@modern-js/uni-builder'; 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'); @@ -38,12 +38,13 @@ export const entries = async (_: unknown, options: Options) => { }; export const modern = ( - builderConfig: BuilderConfig, + builderConfig: UniBuilderConfig, options: Options, -): BuilderConfig => { - // @ts-expect-error +): UniBuilderConfig => { return { ...builderConfig, + // modern plugin can't be used as Rsbuild plugin + plugins: [], output: { ...builderConfig.output, diff --git a/packages/storybook/builder/src/types.ts b/packages/storybook/builder/src/types.ts index 916e2d77a827..a8e0768199f8 100644 --- a/packages/storybook/builder/src/types.ts +++ b/packages/storybook/builder/src/types.ts @@ -1,21 +1,18 @@ -import type { BuilderConfig as WebpackBuilderConfig } from '@modern-js/builder-webpack-provider'; -import type { BuilderConfig as RspackBuilderConfig } from '@modern-js/builder-rspack-provider'; -import { BuilderPlugin } from '@modern-js/builder-shared'; +import type { RsbuildPlugin } from '@rsbuild/shared'; +import type { UniBuilderConfig } from '@modern-js/uni-builder'; export type BundlerType = 'webpack' | 'rspack'; -export type { WebpackBuilderConfig, RspackBuilderConfig }; - -export type AllBuilderConfig = WebpackBuilderConfig | RspackBuilderConfig; - export type BuilderOptions = { bundler?: BundlerType; - builderConfig?: AllBuilderConfig; + builderConfig?: UniBuilderConfig; configPath?: string; }; -export type BuilderConfig = AllBuilderConfig & { - builderPlugins?: BuilderPlugin[]; +export type BuilderConfig = UniBuilderConfig & { + builderPlugins?: RsbuildPlugin[]; }; -export { defineConfig } from '@modern-js/builder/cli'; +export function defineConfig(config: UniBuilderConfig) { + return config; +} diff --git a/packages/storybook/builder/src/utils.ts b/packages/storybook/builder/src/utils.ts index 15fa9b91ea42..6d9a4f00010f 100644 --- a/packages/storybook/builder/src/utils.ts +++ b/packages/storybook/builder/src/utils.ts @@ -2,13 +2,6 @@ import path, { dirname, join } from 'path'; import { createRequire } from 'node:module'; import { fs, logger } from '@modern-js/utils'; -import { BuilderWebpackProvider } from '@modern-js/builder-webpack-provider'; -import { BuilderRspackProvider } from '@modern-js/builder-rspack-provider'; -import { - AllBuilderConfig, - RspackBuilderConfig, - WebpackBuilderConfig, -} from './types'; export const VIRTUAL_MODULE_BASE = '.MODERN_STORYBOOK'; @@ -20,35 +13,6 @@ export const requireResolve = (importer: string, path: string) => { require.resolve(path); }; -export async function getProvider( - bundler: 'webpack' | 'rspack' | undefined, - builderConfig: AllBuilderConfig, -): Promise { - try { - if (bundler === 'webpack') { - const { builderWebpackProvider } = await import( - '@modern-js/builder-webpack-provider' - ); - return builderWebpackProvider({ - builderConfig: builderConfig as WebpackBuilderConfig, - }); - } else if (bundler === 'rspack') { - const { builderRspackProvider } = await import( - '@modern-js/builder-rspack-provider' - ); - return builderRspackProvider({ - builderConfig: builderConfig as RspackBuilderConfig, - }); - } else { - // auto detect - return ( - (await getProvider('webpack', builderConfig)) || - (await getProvider('rspack', builderConfig)) - ); - } - } catch (e) {} -} - // use this instead of virtualModuleWebpackPlugin for rspack compatibility export async function virtualModule( tempDir: string, diff --git a/packages/storybook/framework/package.json b/packages/storybook/framework/package.json index 7a68d806b062..f879d2081c9e 100644 --- a/packages/storybook/framework/package.json +++ b/packages/storybook/framework/package.json @@ -68,7 +68,7 @@ "storybook": "~7.6.1" }, "devDependencies": { - "@storybook/types": "~7.6.1", + "@storybook/types": "~7.6.12", "typescript": "^5.2.2", "@types/node": "^20.5.6" }, diff --git a/packages/storybook/framework/src/preset.ts b/packages/storybook/framework/src/preset.ts index 3eeb2a89175d..fdc29c01bad5 100644 --- a/packages/storybook/framework/src/preset.ts +++ b/packages/storybook/framework/src/preset.ts @@ -31,7 +31,6 @@ export const modern = ( config: BuilderConfig, _options: Options, ): BuilderConfig => { - // @ts-expect-error return { ...config, source: { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 107c2295aad9..28657480a92b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4850,33 +4850,33 @@ importers: packages/storybook/builder: dependencies: - '@modern-js/builder': - specifier: workspace:* - version: link:../../builder/builder - '@modern-js/builder-shared': - specifier: workspace:* - version: link:../../builder/builder-shared '@modern-js/core': specifier: workspace:* version: link:../../cli/core '@modern-js/runtime': specifier: workspace:* version: link:../../runtime/plugin-runtime + '@modern-js/uni-builder': + specifier: workspace:* + version: link:../../builder/uni-builder '@modern-js/utils': specifier: workspace:* version: link:../../toolkit/utils + '@rsbuild/shared': + specifier: 0.4.3 + version: 0.4.3(@swc/helpers@0.5.3) '@rspack/plugin-react-refresh': specifier: 0.4.5 version: 0.4.5(react-refresh@0.14.0) '@storybook/components': - specifier: ~7.6.1 - version: 7.6.3(@types/react-dom@18.0.6)(@types/react@18.0.21)(react-dom@18.2.0)(react@18.2.0) + specifier: ~7.6.12 + version: 7.6.12(@types/react-dom@18.0.6)(@types/react@18.0.21)(react-dom@18.2.0)(react@18.2.0) '@storybook/core-common': - specifier: ~7.6.1 - version: 7.6.3 + specifier: ~7.6.12 + version: 7.6.12 '@storybook/csf-plugin': - specifier: ~7.6.1 - version: 7.6.3 + specifier: ~7.6.12 + version: 7.6.12 '@storybook/global': specifier: ~5.0.0 version: 5.0.0 @@ -4887,20 +4887,20 @@ importers: specifier: ~1.1.0 version: 1.1.0 '@storybook/preview': - specifier: ~7.6.1 - version: 7.6.3 + specifier: ~7.6.12 + version: 7.6.12 '@storybook/preview-api': - specifier: ~7.6.1 - version: 7.6.3 + specifier: ~7.6.12 + version: 7.6.12 '@storybook/react-docgen-typescript-plugin': specifier: 1.0.6--canary.9.0c3f3b7.0 version: 1.0.6--canary.9.0c3f3b7.0(typescript@5.3.3)(webpack@5.89.0) '@storybook/router': - specifier: ~7.6.1 - version: 7.6.3 + specifier: ~7.6.12 + version: 7.6.12 '@storybook/theming': - specifier: ~7.6.1 - version: 7.6.3(react-dom@18.2.0)(react@18.2.0) + specifier: ~7.6.12 + version: 7.6.12(react-dom@18.2.0)(react@18.2.0) ast-types: specifier: ^0.14.2 version: 0.14.2 @@ -4926,18 +4926,12 @@ importers: specifier: ^2.25.4 version: 2.25.4 devDependencies: - '@modern-js/builder-rspack-provider': - specifier: workspace:* - version: link:../../builder/builder-rspack-provider - '@modern-js/builder-webpack-provider': - specifier: workspace:* - version: link:../../builder/builder-webpack-provider '@scripts/build': specifier: workspace:* version: link:../../../scripts/build '@storybook/types': - specifier: ~7.6.1 - version: 7.6.3 + specifier: ~7.6.12 + version: 7.6.12 '@types/babel__core': specifier: ^7.20.1 version: 7.20.3 @@ -4967,8 +4961,8 @@ importers: version: 7.6.3 devDependencies: '@storybook/types': - specifier: ~7.6.1 - version: 7.6.3 + specifier: ~7.6.12 + version: 7.6.12 '@types/node': specifier: ^20.5.6 version: 20.8.8 @@ -12366,7 +12360,7 @@ packages: resolution: {integrity: sha512-51Uv2oueWru4BvoE7VHai03wT0VZ1VFNPrDXR3Rd3DanRdM5BDBs28mB6+pz68SFQPjK7/f2ZgqRr0FjGWhUvg==} dependencies: '@swc/helpers': 0.5.1 - caniuse-lite: 1.0.30001566 + caniuse-lite: 1.0.30001584 lodash: 4.17.21 rslog: 1.1.0 @@ -15686,13 +15680,23 @@ packages: - supports-color dev: false + /@storybook/channels@7.6.12: + resolution: {integrity: sha512-TaPl5Y3lOoVi5kTLgKNRX8xh2sUPekH0Id1l4Ymw+lpgriEY6r60bmkZLysLG1GhlskpQ/da2+S2ap2ht8P2TQ==} + dependencies: + '@storybook/client-logger': 7.6.12 + '@storybook/core-events': 7.6.12 + '@storybook/global': 5.0.0 + qs: 6.11.2 + telejson: 7.2.0 + tiny-invariant: 1.3.1 + /@storybook/channels@7.6.3: resolution: {integrity: sha512-o9J0TBbFon16tUlU5V6kJgzAlsloJcS1cTHWqh3VWczohbRm+X1PLNUihJ7Q8kBWXAuuJkgBu7RQH7Ib46WyYg==} dependencies: '@storybook/client-logger': 7.6.3 '@storybook/core-events': 7.6.3 '@storybook/global': 5.0.0 - qs: 6.11.0 + qs: 6.11.2 telejson: 7.2.0 tiny-invariant: 1.3.1 @@ -15748,6 +15752,11 @@ packages: - utf-8-validate dev: false + /@storybook/client-logger@7.6.12: + resolution: {integrity: sha512-hiRv6dXsOttMPqm9SxEuFoAtDe9rs7TUS8XcO5rmJ9BgfwBJsYlHzAxXkazxmvlyZtKL7gMx6m8OYbCdZgUqtA==} + dependencies: + '@storybook/global': 5.0.0 + /@storybook/client-logger@7.6.3: resolution: {integrity: sha512-BpsCnefrBFdxD6ukMjAblm1D6zB4U5HR1I85VWw6LOqZrfzA6l/1uBxItz0XG96HTjngbvAabWf5k7ZFCx5UCg==} dependencies: @@ -15774,6 +15783,29 @@ packages: - supports-color dev: false + /@storybook/components@7.6.12(@types/react-dom@18.0.6)(@types/react@18.0.21)(react-dom@18.2.0)(react@18.2.0): + resolution: {integrity: sha512-PCijPqmlZd7qyTzNr+vD0Kf8sAI9vWJIaxbSjXwn/De3e63m4fsEcIf8FaUT8cMZ46AWZvaxaxX5km2u0UISJQ==} + peerDependencies: + react: ^16.8.0 || ^17.0.0 || ^18.0.0 + react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0 + dependencies: + '@radix-ui/react-select': 1.2.2(@types/react-dom@18.0.6)(@types/react@18.0.21)(react-dom@18.2.0)(react@18.2.0) + '@radix-ui/react-toolbar': 1.0.4(@types/react-dom@18.0.6)(@types/react@18.0.21)(react-dom@18.2.0)(react@18.2.0) + '@storybook/client-logger': 7.6.12 + '@storybook/csf': 0.1.2 + '@storybook/global': 5.0.0 + '@storybook/theming': 7.6.12(react-dom@18.2.0)(react@18.2.0) + '@storybook/types': 7.6.12 + memoizerific: 1.11.3 + react: 18.2.0 + react-dom: 18.2.0(react@18.2.0) + use-resize-observer: 9.1.0(react-dom@18.2.0)(react@18.2.0) + util-deprecate: 1.0.2 + transitivePeerDependencies: + - '@types/react' + - '@types/react-dom' + dev: false + /@storybook/components@7.6.3(@types/react-dom@18.0.6)(@types/react@18.0.21)(react-dom@18.2.0)(react@18.2.0): resolution: {integrity: sha512-UNV0WoUo+W0huOLvoEMuqRN/VB4p0CNswrXN1mi/oGWvAFJ8idu63lSuV4uQ/LKxAZ6v3Kpdd+oK/o+OeOoL6w==} peerDependencies: @@ -15795,6 +15827,7 @@ packages: transitivePeerDependencies: - '@types/react' - '@types/react-dom' + dev: true /@storybook/core-client@7.6.3: resolution: {integrity: sha512-RM0Svlajddl8PP4Vq7LK8T22sFefNcTDgo82iRPZzGz0oH8LT0oXGFanj2Nkn0jruOBFClkiJ7EcwrbGJZHELg==} @@ -15803,6 +15836,37 @@ packages: '@storybook/preview-api': 7.6.3 dev: false + /@storybook/core-common@7.6.12: + resolution: {integrity: sha512-kM9YiBBMM2x5v/oylL7gdO1PS4oehgJC21MivS9p5QZ8uuXKtCQ6UQvI3rzaV+1ZzUA4n+I8MyaMrNIQk8KDbw==} + dependencies: + '@storybook/core-events': 7.6.12 + '@storybook/node-logger': 7.6.12 + '@storybook/types': 7.6.12 + '@types/find-cache-dir': 3.2.1 + '@types/node': 18.11.17 + '@types/node-fetch': 2.6.7 + '@types/pretty-hrtime': 1.0.1 + chalk: 4.1.2 + esbuild: 0.18.20 + esbuild-register: 3.5.0(esbuild@0.18.20) + file-system-cache: 2.3.0 + find-cache-dir: 3.3.2 + find-up: 5.0.0 + fs-extra: 11.2.0 + glob: 10.3.10 + handlebars: 4.7.7 + lazy-universal-dotenv: 4.0.0 + node-fetch: 2.6.7(encoding@0.1.13) + picomatch: 2.3.1 + pkg-dir: 5.0.0 + pretty-hrtime: 1.0.3 + resolve-from: 5.0.0 + ts-dedent: 2.2.0 + transitivePeerDependencies: + - encoding + - supports-color + dev: false + /@storybook/core-common@7.6.3: resolution: {integrity: sha512-/ZE4BEyGwBHCQCOo681GyBKF4IqCiwVV/ZJCHTMTHFCPLJT2r+Qwv4tnI7xt1kwflOlbBlG6B6CvAqTjjVw/Ew==} dependencies: @@ -15819,7 +15883,7 @@ packages: file-system-cache: 2.3.0 find-cache-dir: 3.3.2 find-up: 5.0.0 - fs-extra: 11.1.1 + fs-extra: 11.2.0 glob: 10.3.10 handlebars: 4.7.7 lazy-universal-dotenv: 4.0.0 @@ -15833,6 +15897,11 @@ packages: - encoding - supports-color + /@storybook/core-events@7.6.12: + resolution: {integrity: sha512-IO4cwk7bBCKH6lLnnIlHO9FwQXt/9CzLUAoZSY9msWsdPppCdKlw8ynJI5YarSNKDBUn8ArIfnRf0Mve0KQr9Q==} + dependencies: + ts-dedent: 2.2.0 + /@storybook/core-events@7.6.3: resolution: {integrity: sha512-Vu3JX1mjtR8AX84lyqWsi2s2lhD997jKRWVznI3wx+UpTk8t7TTMLFk2rGYJRjaornhrqwvLYpnmtxRSxW9BOQ==} dependencies: @@ -15889,13 +15958,39 @@ packages: - utf-8-validate dev: false + /@storybook/csf-plugin@7.6.12: + resolution: {integrity: sha512-fe/84AyctJcrpH1F/tTBxKrbjv0ilmG3ZTwVcufEiAzupZuYjQ/0P+Pxs8m8VxiGJZZ1pWofFFDbYi+wERjamQ==} + dependencies: + '@storybook/csf-tools': 7.6.12 + unplugin: 1.6.0 + transitivePeerDependencies: + - supports-color + dev: false + /@storybook/csf-plugin@7.6.3: resolution: {integrity: sha512-8bMYPsWw2tv+fqZ5H436l4x1KLSB6gIcm6snsjyF916yCHG6WcWm+EI6+wNUoySEtrQY2AiwFJqE37wI5OUJFg==} dependencies: '@storybook/csf-tools': 7.6.3 - unplugin: 1.5.0 + unplugin: 1.6.0 + transitivePeerDependencies: + - supports-color + dev: true + + /@storybook/csf-tools@7.6.12: + resolution: {integrity: sha512-MdhkYYxSW5I6Jpk34gTkAZsuj9sxe0xdyeUQpNa8CgJxG43F+ehZ6scW/IPjoSG9gCXBUJMekq26UrmbVfsLCQ==} + dependencies: + '@babel/generator': 7.23.6 + '@babel/parser': 7.23.6 + '@babel/traverse': 7.23.6 + '@babel/types': 7.23.6 + '@storybook/csf': 0.1.2 + '@storybook/types': 7.6.12 + fs-extra: 11.2.0 + recast: 0.23.4 + ts-dedent: 2.2.0 transitivePeerDependencies: - supports-color + dev: false /@storybook/csf-tools@7.6.3: resolution: {integrity: sha512-Zi3pg2pg88/mvBKewkfWhFUR1J4uYpHI5fSjOE+J/FeZObX/DIE7r+wJxZ0UBGyrk0Wy7Jajlb2uSP56Y0i19w==} @@ -15978,6 +16073,10 @@ packages: /@storybook/mdx2-csf@1.1.0: resolution: {integrity: sha512-TXJJd5RAKakWx4BtpwvSNdgTDkKM6RkXU8GK34S/LhidQ5Pjz3wcnqb0TxEkfhK/ztbP8nKHqXFwLfa2CYkvQw==} + /@storybook/node-logger@7.6.12: + resolution: {integrity: sha512-iS44/EjfF6hLecKzICmcpQoB9bmVi4tXx5gVXnbI5ZyziBibRQcg/U191Njl7wY2ScN/RCQOr8lh5k57rI3Prg==} + dev: false + /@storybook/node-logger@7.6.3: resolution: {integrity: sha512-7yL0CMHuh1DhpUAoKCU0a53DvxBpkUom9SX5RaC1G2A9BK/B3XcHtDPAC0uyUwNCKLJMZo9QtmJspvxWjR0LtA==} @@ -15985,6 +16084,25 @@ packages: resolution: {integrity: sha512-WpgdpJpY6rionluxjFZLbKiSDjvQJ5cPgufjvBRuXTsnVOsH3JNRWnPdkQkJLT9uTUMoNcyBMxbjYkK3vU6wSg==} dev: true + /@storybook/preview-api@7.6.12: + resolution: {integrity: sha512-uSzeMSLnCRROjiofJP0F0niLWL+sboQ5ktHW6BAYoPwprumXduPxKBUVEZNxMbVYoAz9v/kEZmaLauh8LRP2Hg==} + dependencies: + '@storybook/channels': 7.6.12 + '@storybook/client-logger': 7.6.12 + '@storybook/core-events': 7.6.12 + '@storybook/csf': 0.1.2 + '@storybook/global': 5.0.0 + '@storybook/types': 7.6.12 + '@types/qs': 6.9.7 + dequal: 2.0.3 + lodash: 4.17.21 + memoizerific: 1.11.3 + qs: 6.11.2 + synchronous-promise: 2.0.15 + ts-dedent: 2.2.0 + util-deprecate: 1.0.2 + dev: false + /@storybook/preview-api@7.6.3: resolution: {integrity: sha512-uPaK7yLE1P++F+IOb/1j9pgdCwfMYZrUPHogF/Mf9r4cfEjDCcIeKgGMcsbU1KnkzNQQGPh8JRzRr/iYnLjswg==} dependencies: @@ -15998,13 +16116,13 @@ packages: dequal: 2.0.3 lodash: 4.17.21 memoizerific: 1.11.3 - qs: 6.11.0 + qs: 6.11.2 synchronous-promise: 2.0.15 ts-dedent: 2.2.0 util-deprecate: 1.0.2 - /@storybook/preview@7.6.3: - resolution: {integrity: sha512-obSmKN8arWSHuLbCDM1H0lTVRMvAP/l7vOi6TQtFi6TxBz9MRCJA3Ugc0PZrbDADVZP+cp0ZJA0JQtAm+SqNAA==} + /@storybook/preview@7.6.12: + resolution: {integrity: sha512-7vbeqQY3X+FCt/ccgCuBmj4rkbQebLHGEBAt8elcX0E2pr7SGW57lWhnasU3jeMaz7tNrkcs0gfl4hyVRWUHDg==} dev: false /@storybook/react-docgen-typescript-plugin@1.0.6--canary.9.0c3f3b7.0(typescript@5.3.3)(webpack@5.89.0): @@ -16075,12 +16193,21 @@ packages: - supports-color dev: false + /@storybook/router@7.6.12: + resolution: {integrity: sha512-1fqscJbePFJXhapqiv7fAIIqAvouSsdPnqWjJGJrUMR6JBtRYMcrb3MnDeqi9OYnU73r65BrQBPtSzWM8nP0LQ==} + dependencies: + '@storybook/client-logger': 7.6.12 + memoizerific: 1.11.3 + qs: 6.11.2 + dev: false + /@storybook/router@7.6.3: resolution: {integrity: sha512-NZfhJqsXYca9mZCL/LGx6FmZDbrxX2S4ImW7Tqdtcc/sSlZ0BpCDkNUTesCA287cmoKMhXZRh/+bU+C2h2a+bw==} dependencies: '@storybook/client-logger': 7.6.3 memoizerific: 1.11.3 - qs: 6.11.0 + qs: 6.11.2 + dev: true /@storybook/telemetry@7.6.3: resolution: {integrity: sha512-NDCZWhVIUI3M6Lq4M/HPOvZqDXqANDNbI3kyHr4pFGoVaCUXuDPokL9wR+CZcMvATkJ1gHrfLPBdcRq6Biw3Iw==} @@ -16098,6 +16225,20 @@ packages: - supports-color dev: false + /@storybook/theming@7.6.12(react-dom@18.2.0)(react@18.2.0): + resolution: {integrity: sha512-P4zoMKlSYbNrWJjQROuz+DZSDEpdf3TUvk203EqBRdElqw2EMHcqZ8+0HGPFfVHpqEj05+B9Mr6R/Z/BURj0lw==} + peerDependencies: + react: ^16.8.0 || ^17.0.0 || ^18.0.0 + react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0 + dependencies: + '@emotion/use-insertion-effect-with-fallbacks': 1.0.1(react@18.2.0) + '@storybook/client-logger': 7.6.12 + '@storybook/global': 5.0.0 + memoizerific: 1.11.3 + react: 18.2.0 + react-dom: 18.2.0(react@18.2.0) + dev: false + /@storybook/theming@7.6.3(react-dom@18.2.0)(react@18.2.0): resolution: {integrity: sha512-9ToNU2LM6a2kVBjOXitXEeEOuMurVLhn+uaZO1dJjv8NGnJVYiLwNPwrLsImiUD8/XXNuil972aanBR6+Aj9jw==} peerDependencies: @@ -16110,6 +16251,15 @@ packages: memoizerific: 1.11.3 react: 18.2.0 react-dom: 18.2.0(react@18.2.0) + dev: true + + /@storybook/types@7.6.12: + resolution: {integrity: sha512-Wsbd+NS10/2yMHQ/26rXHflXam0hm2qufTFiHOX6VXZWxij3slRU88Fnwzp+1QSyjXb0qkEr8dOx7aG00+ItVw==} + dependencies: + '@storybook/channels': 7.6.12 + '@types/babel__core': 7.20.3 + '@types/express': 4.17.13 + file-system-cache: 2.3.0 /@storybook/types@7.6.3: resolution: {integrity: sha512-vj9Jzg5eR52l8O9512QywbQpNdo67Z6BQWR8QoZRcG+/Bhzt08YI8IZMPQLFMKzcmWDPK0blQ4GfyKDYplMjPA==} @@ -19271,7 +19421,7 @@ packages: resolution: {integrity: sha512-sX/LQ7LqUhgyaxzbe7IqwPeTr2yfpfUIQ/dgpKo6ZI4y4lpQA0YxAomWIY+7I7rHWcG02PG+OuPREzMW/5tszQ==} dependencies: inflation: 2.0.0 - qs: 6.11.0 + qs: 6.11.2 raw-body: 2.5.1 type-is: 1.6.18 dev: false @@ -28367,18 +28517,11 @@ packages: dependencies: side-channel: 1.0.4 - /qs@6.11.0: - resolution: {integrity: sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==} - engines: {node: '>=0.6'} - dependencies: - side-channel: 1.0.4 - /qs@6.11.2: resolution: {integrity: sha512-tDNIz22aBzCDxLtVH++VnTfzxlfeK5CbqohpSqpJgj1Wg/cQbStNAz3NuqCs5vV+pjBsK4x4pN9HlVh7rcYRiA==} engines: {node: '>=0.6'} dependencies: side-channel: 1.0.4 - dev: false /qs@6.9.3: resolution: {integrity: sha512-EbZYNarm6138UKKq46tdx08Yo/q9ZhFoAXAI1meAFd2GtbRDhbZY2WQSICskT0c5q99aFzLG1D4nvTk9tqfXIw==} @@ -31437,7 +31580,7 @@ packages: formidable: 2.0.1 methods: 1.1.2 mime: 2.6.0 - qs: 6.11.0 + qs: 6.11.2 readable-stream: 3.6.0 semver: 7.6.0 transitivePeerDependencies: @@ -32640,13 +32783,13 @@ packages: resolution: {integrity: sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==} engines: {node: '>= 0.8'} - /unplugin@1.5.0: - resolution: {integrity: sha512-9ZdRwbh/4gcm1JTOkp9lAkIDrtOyOxgHmY7cjuwI8L/2RTikMcVG25GsZwNAgRuap3iDw2jeq7eoqtAsz5rW3A==} + /unplugin@1.6.0: + resolution: {integrity: sha512-BfJEpWBu3aE/AyHx8VaNE/WgouoQxgH9baAiH82JjX8cqVyi3uJQstqwD5J+SZxIK326SZIhsSZlALXVBCknTQ==} dependencies: acorn: 8.11.2 chokidar: 3.5.3 webpack-sources: 3.2.3 - webpack-virtual-modules: 0.5.0 + webpack-virtual-modules: 0.6.1 /untildify@4.0.0: resolution: {integrity: sha512-KK8xQ1mkzZeg9inewmFVDNkg3l5LUhoq9kN6iWYB/CC9YMG8HA+c1Q8HwDe6dEX7kErrEVNVBO3fWsVq5iDgtw==} @@ -33295,8 +33438,8 @@ packages: webpack: 5.89.0(esbuild@0.17.19) dev: false - /webpack-virtual-modules@0.5.0: - resolution: {integrity: sha512-kyDivFZ7ZM0BVOUteVbDFhlRt7Ah/CSPwJdi8hBpkK7QLumUqdLtVfm/PX/hkcnrvr0i77fO5+TjZ94Pe+C9iw==} + /webpack-virtual-modules@0.6.1: + resolution: {integrity: sha512-poXpCylU7ExuvZK8z+On3kX+S8o/2dQ/SVYueKA0D4WEMXROXgY8Ez50/bQEUmvoSMMrWcrJqCHuhAbsiwg7Dg==} /webpack@5.89.0(@swc/core@1.3.42)(esbuild@0.17.19): resolution: {integrity: sha512-qyfIC10pOr70V+jkmud8tMfajraGCZMBWJtrmuBymQKCrLTRejBI8STDp1MCyZu/QTdZSeacCQYpYNQVOzX5kw==} diff --git a/tests/integration/module/fixtures/build/autoExtension/type-module/modern.config.ts b/tests/integration/module/fixtures/build/autoExtension/type-module/modern.config.ts index 1dcd24dfb5e9..01bc25b5253d 100644 --- a/tests/integration/module/fixtures/build/autoExtension/type-module/modern.config.ts +++ b/tests/integration/module/fixtures/build/autoExtension/type-module/modern.config.ts @@ -8,13 +8,21 @@ export default defineConfig({ autoExtension: true, format: 'cjs', sourceMap: true, + outDir: 'dist/cjs', }, - { buildType: 'bundleless', autoExtension: true, format: 'cjs', sourceMap: true, + outDir: 'dist/cjs', + }, + { + buildType: 'bundleless', + autoExtension: true, + format: 'esm', + sourceMap: true, + outDir: 'dist/esm', }, ], }); diff --git a/tests/integration/module/fixtures/build/autoExtension/type-module/type-module.test.ts b/tests/integration/module/fixtures/build/autoExtension/type-module/type-module.test.ts index e16584827953..cc65cd47e9c7 100644 --- a/tests/integration/module/fixtures/build/autoExtension/type-module/type-module.test.ts +++ b/tests/integration/module/fixtures/build/autoExtension/type-module/type-module.test.ts @@ -12,7 +12,7 @@ describe('autoExtension', () => { appDirectory: fixtureDir, enableDts: true, }); - const cwd = path.join(fixtureDir, 'dist'); + const cwd = path.join(fixtureDir, 'dist/cjs'); const outputDeclarationFile = await globby('*.d.cts', { cwd, }); @@ -31,6 +31,12 @@ describe('autoExtension', () => { expect( content.includes('./common.cjs') && content.includes('//# sourceMappingURL=index.cjs.map'), + ).toBeTruthy(); + + const esmContent = await fs.readFile( + path.join(fixtureDir, 'dist/esm', 'index.js'), + 'utf-8', ); + expect(esmContent.includes('./common.js')).toBeTruthy(); }); });