@@ -2,6 +2,7 @@ package workers
22
33import (
44 "context"
5+ "encoding/json"
56 "fmt"
67 "html"
78 "io"
@@ -151,20 +152,23 @@ func (b *Builder) buildTypeScript(ctx context.Context, baseDir string) (sdkbuild
151152 // If version not provided, try to read it from package.json
152153 version := b .SdkOptions .Version
153154 if version == "" {
154- b , err := os .ReadFile (filepath .Join (baseDir , "package.json" ))
155+ packageJSON , err := os .ReadFile (filepath .Join (baseDir , "package.json" ))
155156 if err != nil {
156157 return nil , fmt .Errorf ("failed reading package.json: %w" , err )
157158 }
158- for line := range strings .SplitSeq (string (b ), "\n " ) {
159- line = strings .TrimSpace (line )
160- if strings .HasPrefix (line , "\" temporalio:\" " ) || strings .HasPrefix (line , "\" @temporalio/" ) {
161- split := strings .Split (line , "\" " )
162- version = split [len (split )- 2 ]
163- break
164- }
159+
160+ var pkg struct {
161+ Dependencies map [string ]string `json:"dependencies"`
162+ }
163+ if err := json .Unmarshal (packageJSON , & pkg ); err != nil {
164+ return nil , fmt .Errorf ("failed parsing package.json: %w" , err )
165165 }
166+ // Pick a single temporal dependency, assumption is that the version for
167+ // other temporal dependency versions will match.
168+ const temporalTypeScriptSDKPackage = "@temporalio/client"
169+ version = pkg .Dependencies [temporalTypeScriptSDKPackage ]
166170 if version == "" {
167- return nil , fmt .Errorf ("version not found in package.json" )
171+ return nil , fmt .Errorf ("version not found in package.json for %s" , temporalTypeScriptSDKPackage )
168172 }
169173 }
170174
@@ -193,7 +197,8 @@ func (b *Builder) buildTypeScript(ctx context.Context, baseDir string) (sdkbuild
193197 ApplyToCommand : nil ,
194198 Includes : []string {"../src/**/*.ts" , "../src/protos/json-module.js" , "../src/protos/root.js" },
195199 MoreDependencies : map [string ]string {
196- "winston" : "^3.11.0" ,
200+ "@temporalio/omes-project-harness" : "file:../harness" ,
201+ "winston" : "^3.11.0" ,
197202 },
198203 Stdout : b .stdout ,
199204 Stderr : b .stderr ,
0 commit comments