-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improves project file detection #220
Conversation
- Renamed "package" to "project" to move away from NodeJS terminology - Replaced fixed project file names with predicate matching + a description for logging - Implemented .csproj file detection for C#
pkg/input/readdir.go
Outdated
f, err = addFile(fsys, path, relPath, lang.projectFileOpener) | ||
lang.foundProjectFile = true | ||
isProjectFile = true | ||
projectDirs[lang.name] = append(projectDirs[lang.name], prjDir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this also enabling the ability to have multiple languages in the same klotho compilation? Or what is projectDirs alluding to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
projectDirs
refers to directories in which we've detected project files for each supported language. For the moment it's used to enable language-specific file/directory exclusions, and to ensure that compilation fails if two project files exist for the same language in the same directory.
Support for multiple languages in a single compilation is not specifically handled here. The executable plugins don't currently support multiple languages in a single execution unit.
just some lint errors as well |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Linter caught some things that need to be fixed.
pkg/input/readdir.go
Outdated
} | ||
} | ||
|
||
func hasSuffix(expected string) predicate.Predicate[string] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this should probably be hasExtension
and use the filepath.Ext(name)
to test. In this case it's close to functionally the same, but I think it makes the intention clearer. There's a few edge cases that it'd catch too (like the file who's name is .csproj
)
pkg/input/readdir.go
Outdated
|
||
case "bin", "obj": | ||
dir, _ := filepath.Split(info.Name()) | ||
for _, projectDir := range projectDirs[CSharp] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is susceptible to iteration order problems. What if the csproj was found after the bin/obj directories?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. I got the wrong impression regarding iteration order since these directories are lowercase and the .csproj file I was testing had an uppercase name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An alternative might be to instead just look at the peers of bin
/obj
and see if there's a *.csproj
file. So you don't need to read it beforehand.
pkg/input/readdir.go
Outdated
lang.foundPackageFile = true | ||
isPackageFile = true | ||
if lang.projectFilePredicate != nil && lang.projectFilePredicate(info.Name()) { | ||
prjDir, _ := filepath.Split(info.Name()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prjDir, _ := filepath.Split(info.Name()) | |
prjDir := filepath.Dir(info.Name()) |
c4d7f77
to
c08da13
Compare
pkg/input/readdir.go
Outdated
func hasExtension(expected string) predicate.Predicate[string] { | ||
extension := "." + expected | ||
return func(name string) bool { | ||
return extension != name && strings.HasSuffix(name, extension) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return extension != name && strings.HasSuffix(name, extension) | |
return filepath.Ext(name) == extension |
pkg/input/readdir.go
Outdated
} | ||
|
||
func hasExtension(expected string) predicate.Predicate[string] { | ||
extension := "." + expected |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO require the caller to include the .
which matches prior art with filepath.Ext
pkg/input/readdir.go
Outdated
} | ||
yamlLang := &languageFiles{name: Yaml} | ||
dockerfileLang := &languageFiles{name: DockerFile} | ||
allLangs := []*languageFiles{jsLang, pyLang, goLang, yamlLang} | ||
allLangs := []*languageFiles{jsLang, pyLang, goLang, yamlLang, csLang} | ||
projectDirs := map[languageName][]string{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's projectDirs
used for? Seems like it's only used to skip folders. Seems like a lot of complication compared to just processing them normally. At least for now seems like premature optimization unless there's something you've already run into (in which case, can you document those cases in the comments?).
pkg/input/readdir.go
Outdated
|
||
case "bin", "obj": | ||
dir, _ := filepath.Split(info.Name()) | ||
for _, projectDir := range projectDirs[CSharp] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An alternative might be to instead just look at the peers of bin
/obj
and see if there's a *.csproj
file. So you don't need to read it beforehand.
pkg/input/readdir.go
Outdated
projectFile, err = func() (core.File, error) { | ||
defer f.Close() | ||
return lang.projectFileOpener(prjFilePath, f) | ||
}() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't really idiomatic for Go. Something more like
projectFile, err := lang.projectFileOpener(prjFilePath, f)
f.Close()
if err != nil {
// ...
}
|
This PR supports #105
ReadDir()
to move away from NodeJS terminologyStandard checks