Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ jobs:
@temporalio/external-storage-gcs @temporalio/external-storage-gcs-google-sdk
@temporalio/external-storage-s3 @temporalio/external-storage-s3-aws-sdk
@temporalio/plugin @temporalio/proto @temporalio/worker @temporalio/workflow
nexus-rpc
- run: npm run build
- run: npm run lint

Expand Down
55 changes: 5 additions & 50 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@temporalio/workflow": "^1.25.0",
"commander": "^8.3.0",
"ms": "^3.0.0-canary.1",
"nexus-rpc": "^0.0.1",
"nexus-rpc": "^0.0.3",
"protobufjs": "^8.7.1"
},
"devDependencies": {
Expand Down
43 changes: 42 additions & 1 deletion sdkbuild/typescript.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ func BuildTypeScriptProgram(ctx context.Context, options BuildTypeScriptProgramO
}
moreDeps := ""
for dep, version := range options.MoreDependencies {
if dep == "nexus-rpc" {
continue
}
moreDeps += fmt.Sprintf(` "%v": "%v",`, dep, version) + "\n"
}

Expand All @@ -141,7 +144,6 @@ func BuildTypeScriptProgram(ctx context.Context, options BuildTypeScriptProgramO
"@grpc/grpc-js": "^1.12.4",
"commander": "^8.3.0",
"ms": "^3.0.0-canary.1",
"nexus-rpc": "^0.0.1",
"protobufjs": "^8.7.1"
},
"devDependencies": {
Expand Down Expand Up @@ -240,6 +242,31 @@ func BuildTypeScriptProgram(ctx context.Context, options BuildTypeScriptProgramO
if err := cmd.Run(); err != nil {
return nil, fmt.Errorf("failed installing: %w", err)
}
// Read the selected SDK's dependency after installation. This works for
// both published packages and links to a local checkout, and avoids
// resolving a version range or tag separately from the SDK installation.
workerPackage, err := os.ReadFile(filepath.Join(dir, "node_modules", "@temporalio", "worker", "package.json"))
if err != nil {
return nil, fmt.Errorf("failed reading installed SDK package.json: %w", err)
}
nexusVersion, err := typeScriptNexusDependency(workerPackage)
if err != nil {
return nil, err
}
if version, ok := options.MoreDependencies["nexus-rpc"]; ok && version != nexusVersion {
return nil, fmt.Errorf("nexus-rpc dependency %q does not match SDK dependency %q", version, nexusVersion)
}
cmd = exec.CommandContext(ctx, "corepack", "pnpm", "add", "--ignore-scripts", "nexus-rpc@"+nexusVersion)
cmd.Dir = dir
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
if options.ApplyToCommand != nil {
if err := options.ApplyToCommand(ctx, cmd); err != nil {
return nil, err
}
}
if err := cmd.Run(); err != nil {
return nil, fmt.Errorf("failed installing matching nexus-rpc dependency: %w", err)
}

// Compile
cmd = exec.CommandContext(ctx, "corepack", "pnpm", "run", "build")
Expand All @@ -258,6 +285,20 @@ func BuildTypeScriptProgram(ctx context.Context, options BuildTypeScriptProgramO
return &TypeScriptProgram{dir}, nil
}

func typeScriptNexusDependency(data []byte) (string, error) {
var pkg struct {
Dependencies map[string]string `json:"dependencies"`
}
if err := json.Unmarshal(data, &pkg); err != nil {
return "", fmt.Errorf("failed decoding SDK package metadata: %w", err)
}
version := pkg.Dependencies["nexus-rpc"]
if version == "" {
return "", fmt.Errorf("nexus-rpc dependency not found in SDK package metadata")
}
return version, nil
}

// TypeScriptProgramFromDir recreates the TypeScript program from a Dir() result
// of a BuildTypeScriptProgram(). Note, the base directory of dir when it was
// built must also be present.
Expand Down
Loading