11import fs from 'node:fs' ;
2- import { join } from 'node:path' ;
2+ import { dirname , join } from 'node:path' ;
3+ import { fileURLToPath } from 'node:url' ;
34import {
45 type InspectConfigResult ,
56 mergeRsbuildConfig as mergeConfig ,
@@ -8,6 +9,13 @@ import type { Format, LibConfig, RslibConfig } from '@rslib/core';
89import { build , loadConfig } from '@rslib/core' ;
910import { globContentJSON } from './helper' ;
1011
12+ const __filename = fileURLToPath ( import . meta. url ) ;
13+ const __dirname = dirname ( __filename ) ;
14+
15+ export function getCwdByExample ( exampleName : string ) {
16+ return join ( __dirname , '../../examples' , exampleName ) ;
17+ }
18+
1119export function generateBundleEsmConfig ( config : LibConfig = { } ) : LibConfig {
1220 const esmBasicConfig : LibConfig = {
1321 format : 'esm' ,
@@ -136,6 +144,15 @@ export async function getResults(
136144 } ;
137145}
138146
147+ export async function rslibBuild ( fixturePath : string ) {
148+ const rslibConfig = await loadConfig ( {
149+ cwd : fixturePath ,
150+ } ) ;
151+ process . chdir ( fixturePath ) ;
152+ const rsbuildInstance = await build ( rslibConfig ) ;
153+ return { rsbuildInstance, rslibConfig } ;
154+ }
155+
139156export async function buildAndGetResults (
140157 fixturePath : string ,
141158 type : 'all' ,
@@ -152,11 +169,7 @@ export async function buildAndGetResults(
152169 fixturePath : string ,
153170 type : 'js' | 'dts' | 'css' | 'all' = 'js' ,
154171) {
155- const rslibConfig = await loadConfig ( {
156- cwd : fixturePath ,
157- } ) ;
158- process . chdir ( fixturePath ) ;
159- const rsbuildInstance = await build ( rslibConfig ) ;
172+ const { rsbuildInstance, rslibConfig } = await rslibBuild ( fixturePath ) ;
160173 const {
161174 origin : { bundlerConfigs, rsbuildConfig } ,
162175 } = await rsbuildInstance . inspectConfig ( { verbose : true } ) ;
0 commit comments