Skip to content

Commit 5d04719

Browse files
committed
feat: skip for tgz
Signed-off-by: Dmitry Mordvinov <dmitry.mordvinov@flant.com>
1 parent 1c4ba13 commit 5d04719

File tree

4 files changed

+46
-17
lines changed

4 files changed

+46
-17
lines changed

pkg/action/package.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (p *Package) Run(path string, _ map[string]interface{}, opts helmopts.HelmO
6464
}
6565

6666
if tsbundle.BundleEnabled {
67-
if err := tsbundle.ProcessChartRecursive(context.Background(), ch, path, true); err != nil {
67+
if err := tsbundle.BundleTSChartsRecursive(context.Background(), ch, path, true); err != nil {
6868
return "", errors.Wrap(err, "unable to process TypeScript files in chart")
6969
}
7070
}

pkg/chart/chart.go

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"regexp"
2121
"strings"
2222

23+
"github.com/samber/lo"
2324
"github.com/werf/3p-helm/pkg/werf/secrets/runtimedata"
2425
)
2526

@@ -55,8 +56,6 @@ type Chart struct {
5556
Files []*File `json:"files" copy:"shallow"`
5657
// Files that are used at runtime, but should not be saved to secret/configmap.
5758
RuntimeFiles []*File `json:"-" copy:"shallow"`
58-
// Dependencies for RuntimeFiles that are used at runtime, but should not be saved to secret/configmap and not added to packaged chart.
59-
RuntimeDepsFiles []*File `json:"-" copy:"shallow"`
6059

6160
parent *Chart
6261
dependencies []*Chart
@@ -176,18 +175,40 @@ func (ch *Chart) CRDObjects() []CRD {
176175
return crds
177176
}
178177

178+
func hasManifestExtension(fname string) bool {
179+
ext := filepath.Ext(fname)
180+
return strings.EqualFold(ext, ".yaml") || strings.EqualFold(ext, ".yml") || strings.EqualFold(ext, ".json")
181+
}
182+
179183
func (ch *Chart) AddRuntimeFile(name string, data []byte) {
180184
ch.Raw = append(ch.Raw, &File{Name: name, Data: data})
181185

182-
ch.RuntimeFiles = append(ch.RuntimeFiles, &File{name, data})
186+
ch.RuntimeFiles = append(ch.RuntimeFiles, &File{Name: name, Data: data})
183187
if !ch.IsRoot() {
184188
root := ch.Root()
185-
rawName := filepath.Join(strings.TrimPrefix(ch.ChartFullPath(), root.Name()+"/"), name)
189+
rawName := getRootRawFileName(ch, name)
186190
root.Raw = append(root.Raw, &File{Name: rawName, Data: data})
187191
}
188192
}
189193

190-
func hasManifestExtension(fname string) bool {
191-
ext := filepath.Ext(fname)
192-
return strings.EqualFold(ext, ".yaml") || strings.EqualFold(ext, ".yml") || strings.EqualFold(ext, ".json")
194+
func (ch *Chart) RemoveRuntimeFile(name string) {
195+
ch.Raw = lo.Reject(ch.Raw, func(f *File, _ int) bool {
196+
return f.Name == name
197+
})
198+
199+
ch.RuntimeFiles = lo.Reject(ch.RuntimeFiles, func(f *File, _ int) bool {
200+
return f.Name == name
201+
})
202+
203+
if !ch.IsRoot() {
204+
root := ch.Root()
205+
rawName := getRootRawFileName(ch, name)
206+
root.Raw = lo.Reject(root.Raw, func(f *File, _ int) bool {
207+
return f.Name == rawName
208+
})
209+
}
210+
}
211+
212+
func getRootRawFileName(ch *Chart, name string) string {
213+
return filepath.Join(strings.TrimPrefix(ch.ChartFullPath(), ch.Root().Name()+"/"), name)
193214
}

pkg/chart/loader/load.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,7 @@ func LoadFiles(files []*BufferedFile, opts helmopts.HelmOptions) (*chart.Chart,
173173
fname := strings.TrimPrefix(f.Name, "charts/")
174174
cname := strings.SplitN(fname, "/", 2)[0]
175175
subcharts[cname] = append(subcharts[cname], &BufferedFile{Name: fname, Data: f.Data})
176-
case strings.HasPrefix(f.Name, "ts/node_modules/"):
177-
c.RuntimeDepsFiles = append(c.RuntimeDepsFiles, &chart.File{Name: f.Name, Data: f.Data})
178-
case strings.HasPrefix(f.Name, "ts/"):
176+
case strings.HasPrefix(f.Name, "ts/") && !strings.HasPrefix(f.Name, "ts/node_modules/"):
179177
c.RuntimeFiles = append(c.RuntimeFiles, &chart.File{Name: f.Name, Data: f.Data})
180178
default:
181179
c.Files = append(c.Files, &chart.File{Name: f.Name, Data: f.Data})

pkg/werf/ts/bundle.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func RunDenoBundle(ctx context.Context, chartPath, entryPoint string) ([]uint8,
5656
return output, nil
5757
}
5858

59-
func ProcessChartRecursive(ctx context.Context, chart *helmchart.Chart, path string, rebuild bool) error {
59+
func BundleTSChartsRecursive(ctx context.Context, chart *helmchart.Chart, path string, rebuild bool) error {
6060
entrypoint, bundle := GetEntrypointAndBundle(chart.RuntimeFiles)
6161
if entrypoint == "" {
6262
return nil
@@ -68,8 +68,11 @@ func ProcessChartRecursive(ctx context.Context, chart *helmchart.Chart, path str
6868
return fmt.Errorf("build TypeScript bundle: %w", err)
6969
}
7070

71-
bundle = bundleRes
72-
chart.AddRuntimeFile(ChartTSBundleFile, bundle)
71+
if rebuild && bundle != nil {
72+
chart.RemoveRuntimeFile(ChartTSBundleFile)
73+
}
74+
75+
chart.AddRuntimeFile(ChartTSBundleFile, bundleRes)
7376
}
7477

7578
deps := chart.Dependencies()
@@ -79,15 +82,22 @@ func ProcessChartRecursive(ctx context.Context, chart *helmchart.Chart, path str
7982

8083
for _, dep := range deps {
8184
depPath := filepath.Join(path, "charts", dep.Name())
82-
if err := ProcessChartRecursive(ctx, dep, depPath, rebuild); err != nil {
85+
86+
if _, err := os.Stat(depPath); err != nil {
87+
// Subchart loaded from .tgz or missing on disk — skip,
88+
// deno bundle needs a real directory to work with.
89+
continue
90+
}
91+
92+
if err := BundleTSChartsRecursive(ctx, dep, depPath, rebuild); err != nil {
8393
return fmt.Errorf("process dependency %q: %w", dep.Name(), err)
8494
}
8595
}
8696

8797
return nil
8898
}
8999

90-
func GetEntrypointAndBundle(files []*helmchart.File) (string, []byte) {
100+
func GetEntrypointAndBundle(files []*helmchart.File) (string, *helmchart.File) {
91101
entrypoint := findEntrypointInFiles(files)
92102
if entrypoint == "" {
93103
return "", nil
@@ -101,7 +111,7 @@ func GetEntrypointAndBundle(files []*helmchart.File) (string, []byte) {
101111
return entrypoint, nil
102112
}
103113

104-
return entrypoint, bundleFile.Data
114+
return entrypoint, bundleFile
105115
}
106116

107117
func findEntrypointInFiles(files []*helmchart.File) string {

0 commit comments

Comments
 (0)