@@ -2,7 +2,7 @@ import { existsSync } from 'node:fs'
22import { mkdir , readFile , writeFile } from 'node:fs/promises'
33import { basename , dirname , join , relative , resolve } from 'node:path'
44
5- import { codeExtract , hasDevupUI } from '@devup-ui/wasm'
5+ import * as wasmModule from '@devup-ui/wasm'
66import { plugin } from 'bun'
77
88const libPackage = '@devup-ui/react'
@@ -11,23 +11,16 @@ const distDir = 'df'
1111const cssDir = resolve ( distDir , 'devup-ui' )
1212const singleCss = true
1313
14- // Lazy load wasm module
15- let wasmModule : typeof import ( '@devup-ui/wasm' ) | null = null
16- async function getWasm ( ) {
17- if ( ! wasmModule ) {
18- wasmModule = await import ( '@devup-ui/wasm' )
14+ let wasmInitialized = false
15+
16+ function getWasm ( ) {
17+ if ( ! wasmInitialized ) {
1918 wasmModule . setDebug ( true )
19+ wasmInitialized = true
2020 }
2121 return wasmModule
2222}
2323
24- function _getFileNumByFilename ( filename : string ) {
25- if ( filename . endsWith ( 'devup-ui.css' ) ) return null
26- const parts = filename . split ( 'devup-ui-' ) [ 1 ]
27- if ( ! parts ) return null
28- return parseInt ( parts . split ( '.' ) [ 0 ] )
29- }
30-
3124async function writeDataFiles ( ) {
3225 const wasm = await getWasm ( )
3326 try {
@@ -64,7 +57,6 @@ async function writeDataFiles() {
6457 ] )
6558}
6659
67- const _cssMap = new Map < number | null , string > ( )
6860let initialized = false
6961
7062async function initialize ( ) {
@@ -132,8 +124,9 @@ plugin({
132124 : 'js'
133125 const contents = await Bun . file ( filePath ) . text ( )
134126
135- if ( hasDevupUI ( filePath , contents , libPackage ) ) {
136- const code = codeExtract (
127+ const wasm = await getWasm ( )
128+ if ( wasm . hasDevupUI ( filePath , contents , libPackage ) ) {
129+ const code = wasm . codeExtract (
137130 filePath ,
138131 contents ,
139132 libPackage ,
@@ -148,18 +141,3 @@ plugin({
148141 } )
149142 } ,
150143} )
151-
152- export async function getDevupDefaultTheme ( ) : Promise < string | undefined > {
153- const wasm = await getWasm ( )
154- return wasm . getDefaultTheme ( )
155- }
156-
157- export async function getDevupDefine ( ) : Promise < Record < string , string > > {
158- const wasm = await getWasm ( )
159- const theme = wasm . getDefaultTheme ( )
160- const define : Record < string , string > = { }
161- if ( theme ) {
162- define [ 'process.env.DEVUP_UI_DEFAULT_THEME' ] = JSON . stringify ( theme )
163- }
164- return define
165- }
0 commit comments