|
1 | 1 | package node |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "bytes" |
| 5 | + "compress/gzip" |
4 | 6 | "context" |
| 7 | + "encoding/base64" |
5 | 8 | "encoding/json" |
6 | 9 | "fmt" |
| 10 | + "io" |
7 | 11 | "os" |
8 | 12 | "os/exec" |
9 | 13 | "path/filepath" |
@@ -125,7 +129,32 @@ func (yi *YarnInstaller) PrepareYarnEnvironment(workDir string, yarnLock string, |
125 | 129 | // If yarn.lock is provided, write it to the temporary directory |
126 | 130 | if yarnLock != "" { |
127 | 131 | yarnLockPath := filepath.Join(workDir, "yarn.lock") |
128 | | - if err := os.WriteFile(yarnLockPath, []byte(yarnLock), 0644); err != nil { |
| 132 | + |
| 133 | + // Attempt to base64-decode and gunzip the provided yarn.lock |
| 134 | + var toWrite []byte |
| 135 | + if decoded, err := base64.StdEncoding.DecodeString(yarnLock); err == nil { |
| 136 | + if zr, err := gzip.NewReader(bytes.NewReader(decoded)); err == nil { |
| 137 | + defer zr.Close() |
| 138 | + if unzipped, err := io.ReadAll(zr); err == nil { |
| 139 | + toWrite = unzipped |
| 140 | + logger.Info("Decoded base64 and gunzipped yarn.lock") |
| 141 | + } else { |
| 142 | + logger.WithField("error", err.Error()). |
| 143 | + Warn("Failed to read gunzipped yarn.lock, falling back to raw content") |
| 144 | + } |
| 145 | + } else { |
| 146 | + logger.WithField("error", err.Error()). |
| 147 | + Warn("Failed to create gzip reader for yarn.lock, falling back to raw content") |
| 148 | + } |
| 149 | + } else { |
| 150 | + // Not base64-encoded; fall back to raw content |
| 151 | + } |
| 152 | + |
| 153 | + if toWrite == nil { |
| 154 | + toWrite = []byte(yarnLock) |
| 155 | + } |
| 156 | + |
| 157 | + if err := os.WriteFile(yarnLockPath, toWrite, 0644); err != nil { |
129 | 158 | logger.WithField("error", err.Error()). |
130 | 159 | Warn("Failed to write yarn.lock to temporary directory") |
131 | 160 | } else { |
|
0 commit comments