11package main
22
33import (
4+ "encoding/json"
45 "fmt"
56 "os"
67 "path/filepath"
@@ -93,9 +94,13 @@ func buildClient(gameName, output, url string, typescript bool, runtime string)
9394 return err
9495 }
9596 } else if runtime == "browser" {
97+ dependencies , err := npmDependencies ()
98+ if err != nil {
99+ return err
100+ }
96101 err = cp .Copy ("." , output , cp.Options {
97102 Skip : func (src string ) (bool , error ) {
98- return src == filepath .Clean (output ) || (src != "node_modules" && strings .HasPrefix (src , "node_modules" ) && ! strings . Contains (src , "@code-game-project" )) || src == ".codegame.json" || src == "package.json" || src == "package-lock.json" , nil
103+ return src == filepath .Clean (output ) || (src != "node_modules" && strings .HasPrefix (src , "node_modules" ) && ! containsAny (src , dependencies )) || src == ".codegame.json" || src == "package.json" || src == "package-lock.json" , nil
99104 },
100105 })
101106 if err != nil {
@@ -118,6 +123,36 @@ func buildClient(gameName, output, url string, typescript bool, runtime string)
118123 return nil
119124}
120125
126+ func npmDependencies () ([]string , error ) {
127+ type pkgJSON struct {
128+ Dependencies map [string ]string `json:"dependencies"`
129+ }
130+ file , err := os .Open ("package.json" )
131+ if err != nil {
132+ return nil , fmt .Errorf ("failed to open package.json: %w" , err )
133+ }
134+ defer file .Close ()
135+ var data pkgJSON
136+ err = json .NewDecoder (file ).Decode (& data )
137+ if err != nil {
138+ return nil , fmt .Errorf ("failed to parse package.json: %w" , err )
139+ }
140+ dependencies := make ([]string , 0 , len (data .Dependencies ))
141+ for dep := range data .Dependencies {
142+ dependencies = append (dependencies , strings .Split (dep , "/" )[0 ])
143+ }
144+ return dependencies , nil
145+ }
146+
147+ func containsAny (s string , substrs []string ) bool {
148+ for _ , sub := range substrs {
149+ if strings .Contains (s , sub ) {
150+ return true
151+ }
152+ }
153+ return false
154+ }
155+
121156func replaceInFile (filename , old , new string ) error {
122157 content , err := os .ReadFile (filename )
123158 if err != nil {
0 commit comments