Skip to content

Commit 7500d90

Browse files
committed
chore: replace enry library, reduce binary size
Signed-off-by: Luca Di Maio <[email protected]>
1 parent c0006e4 commit 7500d90

38 files changed

+351
-157877
lines changed

go.mod

+1-4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ require (
3131
github.com/loft-sh/go-github-selfupdate v1.0.0
3232
github.com/loft-sh/loft-util v0.0.9-alpha
3333
github.com/loft-sh/notify v0.0.0-20210827094439-0720dcc7feee
34+
github.com/loft-sh/programming-language-detection v0.0.5
3435
github.com/loft-sh/utils v0.0.16
3536
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b
3637
github.com/mitchellh/go-homedir v1.1.0
@@ -55,7 +56,6 @@ require (
5556
google.golang.org/grpc v1.50.1
5657
google.golang.org/protobuf v1.28.1
5758
gopkg.in/natefinch/lumberjack.v2 v2.0.0
58-
gopkg.in/src-d/enry.v1 v1.6.4
5959
gopkg.in/src-d/go-git.v4 v4.13.1
6060
gopkg.in/yaml.v3 v3.0.1
6161
gotest.tools v2.2.0+incompatible
@@ -146,13 +146,11 @@ require (
146146
github.com/russross/blackfriday/v2 v2.1.0 // indirect
147147
github.com/sergi/go-diff v1.1.0 // indirect
148148
github.com/src-d/gcfg v1.4.0 // indirect
149-
github.com/stretchr/testify v1.8.1 // indirect
150149
github.com/syncthing/notify v0.0.0-20210616190510-c6b7342338d2 // indirect
151150
github.com/tcnksm/go-gitconfig v0.1.2 // indirect
152151
github.com/tonistiigi/fsutil v0.0.0-20230105215944-fb433841cbfa // indirect
153152
github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea // indirect
154153
github.com/tonistiigi/vt100 v0.0.0-20210615222946-8066bb97264f // indirect
155-
github.com/toqueteos/trie v1.0.0 // indirect
156154
github.com/ulikunitz/xz v0.5.9 // indirect
157155
github.com/vbatts/tar-split v0.11.2 // indirect
158156
github.com/xanzy/ssh-agent v0.2.1 // indirect
@@ -177,7 +175,6 @@ require (
177175
google.golang.org/genproto v0.0.0-20221202195650-67e5cbc046fd // indirect
178176
gopkg.in/inf.v0 v0.9.1 // indirect
179177
gopkg.in/src-d/go-billy.v4 v4.3.2 // indirect
180-
gopkg.in/toqueteos/substring.v1 v1.0.2 // indirect
181178
gopkg.in/warnings.v0 v0.1.2 // indirect
182179
gopkg.in/yaml.v2 v2.4.0 // indirect
183180
k8s.io/kube-openapi v0.0.0-20220603121420-31174f50af60 // indirect

go.sum

+4-7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKV
1313
cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs=
1414
cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc=
1515
cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY=
16+
cloud.google.com/go v0.105.0 h1:DNtEKRBAAzeS4KyIory52wWHuClNaXJ5x1F7xa4q+5Y=
1617
cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o=
1718
cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE=
1819
cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc=
@@ -386,6 +387,8 @@ github.com/loft-sh/loft-util v0.0.9-alpha h1:kGcyTQWxWHWy7bbjhS8Hsq/JRdlSztAU++a
386387
github.com/loft-sh/loft-util v0.0.9-alpha/go.mod h1:lsjG5Exh5iEf7Z/87nqwkxx3GRQTizFRLGuS1knF6Cg=
387388
github.com/loft-sh/notify v0.0.0-20210827094439-0720dcc7feee h1:hZ79+pKEbCBrH1dVmgZ4jtFrrDPxgM4zqEP1lHlSnvI=
388389
github.com/loft-sh/notify v0.0.0-20210827094439-0720dcc7feee/go.mod h1:pq83B8lgfCY7tKdegTTXU6DZxGQkcWMowUTOTpTQmqk=
390+
github.com/loft-sh/programming-language-detection v0.0.5 h1:XiWlxtrf4t6Z7SQiob0JMKaCeMHCP3kWhB80wLt+EMY=
391+
github.com/loft-sh/programming-language-detection v0.0.5/go.mod h1:QGPQGKr9q1+rQS4OyisS5CPGY1a76SdNaZuk9oy+2cE=
389392
github.com/loft-sh/utils v0.0.16 h1:XnD6Sb6gRWIHgM34U94dHcQ5MtxN5kAGZQ5eddAxC+c=
390393
github.com/loft-sh/utils v0.0.16/go.mod h1:n2L3X4i7d8kb2NF+q5duKa41N+N6fBde6XY2AolgSBI=
391394
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
@@ -574,8 +577,8 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
574577
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
575578
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
576579
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
577-
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
578580
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
581+
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
579582
github.com/syncthing/notify v0.0.0-20210616190510-c6b7342338d2 h1:F4snRP//nIuTTW9LYEzVH4HVwDG9T3M4t8y/2nqMbiY=
580583
github.com/syncthing/notify v0.0.0-20210616190510-c6b7342338d2/go.mod h1:J0q59IWjLtpRIJulohwqEZvjzwOfTEPp8SVhDJl+y0Y=
581584
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
@@ -587,8 +590,6 @@ github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea h1:SXhTLE6pb6eld/
587590
github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea/go.mod h1:WPnis/6cRcDZSUvVmezrxJPkiO87ThFYsoUiMwWNDJk=
588591
github.com/tonistiigi/vt100 v0.0.0-20210615222946-8066bb97264f h1:DLpt6B5oaaS8jyXHa9VA4rrZloBVPVXeCtrOsrFauxc=
589592
github.com/tonistiigi/vt100 v0.0.0-20210615222946-8066bb97264f/go.mod h1:ulncasL3N9uLrVann0m+CDlJKWsIAP34MPcOJF6VRvc=
590-
github.com/toqueteos/trie v1.0.0 h1:8i6pXxNUXNRAqP246iibb7w/pSFquNTQ+uNfriG7vlk=
591-
github.com/toqueteos/trie v1.0.0/go.mod h1:Ywk48QhEqhU1+DwhMkJ2x7eeGxDHiGkAdc9+0DYcbsM=
592593
github.com/ulikunitz/xz v0.5.9 h1:RsKRIA2MO8x56wkkcd3LbtcE/uMszhb6DpRf+3uwa3I=
593594
github.com/ulikunitz/xz v0.5.9/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
594595
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
@@ -1000,8 +1001,6 @@ gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
10001001
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
10011002
gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8=
10021003
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
1003-
gopkg.in/src-d/enry.v1 v1.6.4 h1:mvuHcdnBN/sXjIwlO/7v4kRjK7EPvtGffe//BJMmzIY=
1004-
gopkg.in/src-d/enry.v1 v1.6.4/go.mod h1:lDDelHa5/fOO+o8klI8JOOoMszXxhqCYOgqFS2mnxQA=
10051004
gopkg.in/src-d/go-billy.v4 v4.3.2 h1:0SQA1pRztfTFx2miS8sA97XvooFeNOmvUenF4o0EcVg=
10061005
gopkg.in/src-d/go-billy.v4 v4.3.2/go.mod h1:nDjArDMp+XMs1aFAESLRjfGSgfvoYN0hDfzEk0GjC98=
10071006
gopkg.in/src-d/go-git-fixtures.v3 v3.5.0 h1:ivZFOIltbce2Mo8IjzUHAFoq/IylO9WHhNOAJK+LsJg=
@@ -1010,8 +1009,6 @@ gopkg.in/src-d/go-git.v4 v4.13.1 h1:SRtFyV8Kxc0UP7aCHcijOMQGPxHSmMOPrzulQWolkYE=
10101009
gopkg.in/src-d/go-git.v4 v4.13.1/go.mod h1:nx5NYcxdKxq5fpltdHnPa2Exj4Sx0EclMWZQbYDu2z8=
10111010
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
10121011
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
1013-
gopkg.in/toqueteos/substring.v1 v1.0.2 h1:urLqCeMm6x/eTuQa1oZerNw8N1KNOIp5hD5kGL7lFsE=
1014-
gopkg.in/toqueteos/substring.v1 v1.0.2/go.mod h1:Eb2Z1UYehlVK8LYW2WBVR2rwbujsz3aX8XDrM1vbNew=
10151012
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
10161013
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
10171014
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

pkg/devspace/generator/language.go

+5-91
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"path/filepath"
88
"regexp"
99
"strings"
10-
"time"
1110

1211
"github.com/loft-sh/devspace/pkg/util/fsutil"
1312
"github.com/loft-sh/devspace/pkg/util/git"
@@ -17,7 +16,7 @@ import (
1716
"github.com/pkg/errors"
1817
"github.com/sirupsen/logrus"
1918

20-
enry "gopkg.in/src-d/enry.v1"
19+
detector "github.com/loft-sh/programming-language-detection/pkg/detector"
2120
)
2221

2322
// DevSpaceContainerRepo is the default repository url
@@ -183,7 +182,7 @@ func (cg *LanguageHandler) GetLanguage() (string, error) {
183182
func (cg *LanguageHandler) IsSupportedLanguage(language string) (bool, string) {
184183
supportedLanguages, _ := cg.GetSupportedLanguages()
185184

186-
if language == "c#" {
185+
if language == "dotnet" {
187186
return true, langCSharpDotNet
188187
}
189188

@@ -256,95 +255,10 @@ func (cg *LanguageHandler) CreateDockerfile(language string) error {
256255
}
257256

258257
func (cg *LanguageHandler) detectLanguage() (string, error) {
259-
contentReadLimit := int64(16 * 1024 * 1024)
260-
bytesByLanguage := make(map[string]int64)
261-
262-
// Cancel the language detection after 10sec
263-
cancelDetect := false
264-
time.AfterFunc(10*time.Second, func() {
265-
cancelDetect = true
266-
})
267-
268-
walkError := filepath.Walk(".", func(path string, fileInfo os.FileInfo, err error) error {
269-
// If timeout is over, then cancel detect
270-
if cancelDetect {
271-
return filepath.SkipDir
272-
}
273-
274-
if err != nil {
275-
return filepath.SkipDir
276-
}
277-
278-
if !fileInfo.Mode().IsDir() && !fileInfo.Mode().IsRegular() {
279-
return nil
280-
}
281-
282-
relativePath, err := filepath.Rel(".", path)
283-
if err != nil {
284-
return nil
285-
}
286-
287-
if relativePath == "." {
288-
return nil
289-
}
290-
291-
if fileInfo.IsDir() {
292-
relativePath = relativePath + "/"
293-
}
294-
295-
if enry.IsVendor(relativePath) || enry.IsDotFile(relativePath) || enry.IsDocumentation(relativePath) || enry.IsConfiguration(relativePath) {
296-
if fileInfo.IsDir() {
297-
return filepath.SkipDir
298-
}
299-
300-
return nil
301-
}
258+
contentReadLimit := 16 * 1024 * 1024
302259

303-
if fileInfo.IsDir() {
304-
return nil
305-
}
306-
307-
language, ok := enry.GetLanguageByExtension(path)
308-
if !ok {
309-
if language, ok = enry.GetLanguageByFilename(path); !ok {
310-
content, err := fsutil.ReadFile(path, contentReadLimit)
311-
if err != nil {
312-
return nil
313-
}
314-
315-
language = enry.GetLanguage(filepath.Base(path), content)
316-
if language == enry.OtherLanguage {
317-
return nil
318-
}
319-
}
320-
}
321-
_, langExists := bytesByLanguage[language]
322-
if !langExists {
323-
bytesByLanguage[language] = 0
324-
}
325-
326-
bytesByLanguage[language] = bytesByLanguage[language] + fileInfo.Size()
327-
return nil
328-
})
329-
330-
if walkError != nil {
331-
return "", walkError
332-
}
333-
334-
detectedLanguage := ""
335-
currentMaxBytes := int64(0)
336-
for language, bytes := range bytesByLanguage {
337-
language = strings.ToLower(language)
338-
339-
if bytes > currentMaxBytes {
340-
isSupported, language := cg.IsSupportedLanguage(language)
341-
342-
if isSupported {
343-
detectedLanguage = language
344-
currentMaxBytes = bytes
345-
}
346-
}
347-
}
260+
detectedLanguage := detector.GetLanguage(".", contentReadLimit)
261+
detectedLanguage = strings.ToLower(detectedLanguage)
348262

349263
isSupported, language := cg.IsSupportedLanguage(detectedLanguage)
350264
if !isSupported {

0 commit comments

Comments
 (0)