@@ -3,6 +3,8 @@ package build
33import (
44 "bufio"
55 "fmt"
6+ "go/parser"
7+ "go/token"
68 "io"
79 "log"
810 "os"
@@ -21,6 +23,7 @@ import (
2123)
2224
2325const MinSupportedGoMinorVersion = 22
26+ const TsunamiUIImportPath = "github.com/wavetermdev/waveterm/tsunami/ui"
2427
2528type BuildOpts struct {
2629 Dir string
@@ -138,7 +141,7 @@ func createGoMod(tempDir, appDirName, goVersion string, opts BuildOpts, verbose
138141 if verbose {
139142 log .Printf ("Found existing go.mod, copying from %s" , originalGoModPath )
140143 }
141-
144+
142145 // Copy existing go.mod to temp directory
143146 tempGoModPath := filepath .Join (tempDir , "go.mod" )
144147 if err := copyFile (originalGoModPath , tempGoModPath ); err != nil {
@@ -160,7 +163,7 @@ func createGoMod(tempDir, appDirName, goVersion string, opts BuildOpts, verbose
160163 if verbose {
161164 log .Printf ("No existing go.mod found, creating new one" )
162165 }
163-
166+
164167 modFile = & modfile.File {}
165168 if err := modFile .AddModuleStmt (modulePath ); err != nil {
166169 return fmt .Errorf ("failed to add module statement: %w" , err )
@@ -320,6 +323,31 @@ func verifyScaffoldPath(scaffoldPath string) error {
320323 return nil
321324}
322325
326+ func buildImportsMap (dir string ) (map [string ]bool , error ) {
327+ imports := make (map [string ]bool )
328+
329+ files , err := filepath .Glob (filepath .Join (dir , "*.go" ))
330+ if err != nil {
331+ return nil , fmt .Errorf ("failed to list go files: %w" , err )
332+ }
333+
334+ fset := token .NewFileSet ()
335+ for _ , file := range files {
336+ node , err := parser .ParseFile (fset , file , nil , parser .ImportsOnly )
337+ if err != nil {
338+ continue // Skip files that can't be parsed
339+ }
340+
341+ for _ , imp := range node .Imports {
342+ // Remove quotes from import path
343+ importPath := strings .Trim (imp .Path .Value , `"` )
344+ imports [importPath ] = true
345+ }
346+ }
347+
348+ return imports , nil
349+ }
350+
323351func (be * BuildEnv ) cleanupTempDir (keepTemp bool , verbose bool ) {
324352 if be == nil || be .cleanupOnce == nil {
325353 return
@@ -430,14 +458,24 @@ func tsunamiBuildInternal(opts BuildOpts) (*BuildEnv, error) {
430458 return buildEnv , fmt .Errorf ("failed to create go.mod: %w" , err )
431459 }
432460
433- // Create symlink to SDK ui directory so Tailwind can see those classes
434- uiLinkPath := filepath .Join (tempDir , "ui" )
435- uiTargetPath := filepath .Join (opts .SdkReplacePath , "ui" )
436- if err := os .Symlink (uiTargetPath , uiLinkPath ); err != nil {
437- return buildEnv , fmt .Errorf ("failed to create ui symlink: %w" , err )
461+ // Build imports map from Go files
462+ imports , err := buildImportsMap (tempDir )
463+ if err != nil {
464+ return buildEnv , fmt .Errorf ("failed to build imports map: %w" , err )
438465 }
439- if opts .Verbose {
440- log .Printf ("Created symlink: %s -> %s" , uiLinkPath , uiTargetPath )
466+
467+ // Create symlink to SDK ui directory only if UI package is imported
468+ if imports [TsunamiUIImportPath ] {
469+ uiLinkPath := filepath .Join (tempDir , "ui" )
470+ uiTargetPath := filepath .Join (opts .SdkReplacePath , "ui" )
471+ if err := os .Symlink (uiTargetPath , uiLinkPath ); err != nil {
472+ return buildEnv , fmt .Errorf ("failed to create ui symlink: %w" , err )
473+ }
474+ if opts .Verbose {
475+ log .Printf ("Created UI symlink: %s -> %s" , uiLinkPath , uiTargetPath )
476+ }
477+ } else if opts .Verbose {
478+ log .Printf ("Skipping UI symlink creation - no UI package imports found" )
441479 }
442480
443481 // Generate Tailwind CSS
0 commit comments