Skip to content

Commit 6824a8f

Browse files
mustard-mhroboquat
authored andcommitted
[codehelper] replace product.json only
1 parent 4cf5618 commit 6824a8f

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

components/ide/code/codehelper/main.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package main
66

77
import (
8+
"bytes"
89
"context"
910
"errors"
1011
"io"
@@ -36,7 +37,10 @@ var (
3637
Version = ""
3738
)
3839

39-
const Code = "/ide/bin/gitpod-code"
40+
const (
41+
Code = "/ide/bin/gitpod-code"
42+
ProductJsonLocation = "/ide/product.json"
43+
)
4044

4145
func main() {
4246
enableDebug := os.Getenv("SUPERVISOR_DEBUG_ENABLE") == "true"
@@ -45,6 +49,10 @@ func main() {
4549
log.Info("codehelper started")
4650
startTime := time.Now()
4751

52+
if err := replaceOpenVSXUrl(); err != nil {
53+
log.WithError(err).Error("failed to replace OpenVSX URL")
54+
}
55+
4856
phaseDone := phaseLogging("ResolveWsInfo")
4957
wsInfo, err := resolveWorkspaceInfo(context.Background())
5058
if err != nil || wsInfo == nil {
@@ -258,3 +266,22 @@ func phaseLogging(phase string) context.CancelFunc {
258266
}()
259267
return cancel
260268
}
269+
270+
func replaceOpenVSXUrl() error {
271+
phase := phaseLogging("ReplaceOpenVSXUrl")
272+
defer phase()
273+
b, err := os.ReadFile(ProductJsonLocation)
274+
if err != nil {
275+
return errors.New("failed to read product.json: " + err.Error())
276+
}
277+
registryUrl := os.Getenv("VSX_REGISTRY_URL")
278+
if registryUrl != "" {
279+
b = bytes.ReplaceAll(b, []byte("https://open-vsx.org"), []byte(registryUrl))
280+
}
281+
b = bytes.ReplaceAll(b, []byte("{{extensionsGalleryItemUrl}}"), []byte("https://open-vsx.org/vscode/item"))
282+
b = bytes.ReplaceAll(b, []byte("{{trustedDomain}}"), []byte("https://open-vsx.org"))
283+
if err := os.WriteFile(ProductJsonLocation, b, 0644); err != nil {
284+
return errors.New("failed to write product.json: " + err.Error())
285+
}
286+
return nil
287+
}

components/ide/code/startup.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,5 @@ export USER=gitpod
3232
# shellcheck disable=SC1090,SC1091
3333
[ -s ~/.nvm/nvm-lazy.sh ] && source /home/gitpod/.nvm/nvm-lazy.sh
3434

35-
# Replace OpenVSX URL
36-
grep -rl open-vsx.org /ide | xargs sed -i "s|https://open-vsx.org|$VSX_REGISTRY_URL|g"
37-
grep -rl "{{extensionsGalleryItemUrl}}\|{{trustedDomain}}" /ide | xargs sed -i "s|{{extensionsGalleryItemUrl}}|https://open-vsx.org/vscode/item|g;s|{{trustedDomain}}|https://open-vsx.org|g"
38-
3935
cd /ide || exit
4036
exec /ide/codehelper "$@"

0 commit comments

Comments
 (0)