@@ -10,7 +10,6 @@ import gulp from 'gulp';
1010import glob from 'glob' ;
1111import fs from 'fs-extra' ;
1212import rimraf from 'rimraf' ;
13-
1413import { getProjectPath , getConfig } from './utils/projectHelper' ;
1514import getBabelCommonConfig from './getBabelCommonConfig' ;
1615import getTSCommonConfig from './getTSCommonConfig' ;
@@ -28,10 +27,12 @@ const packageJson = fs.readJsonSync(getProjectPath('package.json'));
2827
2928const tsDefaultReporter = ts . reporter . defaultReporter ( ) ;
3029const cwd = process . cwd ( ) ;
31- const libDir = getProjectPath ( 'lib' ) ;
30+ const cjsDir = getProjectPath ( 'lib' ) ;
3231const esDir = getProjectPath ( 'es' ) ;
3332const localeDir = getProjectPath ( 'locale' ) ;
3433
34+ const libDir = process . env . LIB_DIR || 'components' ;
35+
3536// FIXME: hard code, not find typescript can modify the path resolution
3637const localeDts = `import type { Locale } from '../lib/locale';
3738declare const localeValues: Locale;
@@ -144,18 +145,14 @@ gulp.task(
144145 } )
145146) ;
146147
147- const _libDir = process . env . LIB_DIR || 'components' ;
148-
149148function babelify ( js : ICompileStream [ 'js' ] , modules : boolean ) {
150- const babelConfig = getBabelCommonConfig ( modules , {
151- enabledReactCompiler : _libDir === 'dist' ,
152- } ) ;
149+ const babelConfig = getBabelCommonConfig ( modules , { enabledReactCompiler : libDir === 'dist' } ) ;
153150 delete babelConfig . cacheDirectory ;
154151 if ( modules === false ) {
155152 babelConfig . plugins . push ( replaceLib ) ;
156153 }
157154 const stream = js . pipe ( babel ( babelConfig as Parameters < typeof babel > [ 0 ] ) ) ;
158- return stream . pipe ( gulp . dest ( modules === false ? esDir : libDir ) ) ;
155+ return stream . pipe ( gulp . dest ( modules === false ? esDir : cjsDir ) ) ;
159156}
160157
161158function insertUseClient ( ) {
@@ -178,15 +175,15 @@ function insertUseClient() {
178175
179176async function compile ( modules ?: boolean ) {
180177 const { compile : { transformTSFile, transformFile } = { } } = await getConfig ( ) ;
181- rimraf . sync ( modules !== false ? libDir : esDir ) ;
178+ rimraf . sync ( modules !== false ? cjsDir : esDir ) ;
182179
183180 const assets = gulp
184181 . src ( [ 'components/**/*.@(png|svg|json)' ] )
185- . pipe ( gulp . dest ( modules === false ? esDir : libDir ) ) ;
182+ . pipe ( gulp . dest ( modules === false ? esDir : cjsDir ) ) ;
186183 let error = 0 ;
187184
188185 // =============================== FILE ===============================
189- let transformFileStream ;
186+ let transformFileStream : NodeJS . ReadWriteStream ;
190187
191188 if ( transformFile ) {
192189 transformFileStream = gulp
@@ -199,7 +196,7 @@ async function compile(modules?: boolean) {
199196 next ( ) ;
200197 } )
201198 )
202- . pipe ( gulp . dest ( modules === false ? esDir : libDir ) ) ;
199+ . pipe ( gulp . dest ( modules === false ? esDir : cjsDir ) ) ;
203200 }
204201
205202 // ================================ TS ================================
@@ -252,7 +249,7 @@ async function compile(modules?: boolean) {
252249 tsResult . on ( 'finish' , check ) ;
253250 tsResult . on ( 'end' , check ) ;
254251 const tsFilesStream = babelify ( tsResult . js , modules ) ;
255- const tsd = tsResult . dts . pipe ( gulp . dest ( modules === false ? esDir : libDir ) ) ;
252+ const tsd = tsResult . dts . pipe ( gulp . dest ( modules === false ? esDir : cjsDir ) ) ;
256253 return merge2 ( [ tsFilesStream , tsd , assets , transformFileStream ] . filter ( s => s ) ) ;
257254}
258255
0 commit comments