Skip to content
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

[WIP] fix: detect config in umbrella apps #473

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions src/credo-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,38 @@ export class CredoUtils {
return mixProjectPath || workspace?.uri.fsPath || path.dirname(documentPath)
}

/**
* Checks whether the folder path is an app inside an Umbrella project
* and returns the root of the Umbrella project.
*/
static getUmbrellaRoot(folderPath: string): string | null {
const umbrellaRoot = path.join(folderPath, '..', '..')
const appsDir = path.join(umbrellaRoot, 'apps')
if (!fs.existsSync(appsDir)) return null
if (!fs.existsSync(path.join(umbrellaRoot, 'mix.exs'))) return null

return umbrellaRoot
}

static getCredoConfigFilePath(documentUri?: vscode.Uri): string | null {
const configFilePath = config.resolved.configurationFile || DEFAULT_CONFIG_FILENAME
// ^?

// add unchanged value of `configurationFile` in case it is an absolute path
if (path.isAbsolute(configFilePath) && fs.existsSync(configFilePath)) return configFilePath

const projectFolder = documentUri ? CredoUtils.getProjectFolder(documentUri) : undefined
const found = projectFolder
? [path.join(projectFolder, configFilePath), path.join(projectFolder, 'config', configFilePath)].filter(
(fullPath: string) => fs.existsSync(fullPath),
)
const umbrellaRoot = projectFolder ? CredoUtils.getUmbrellaRoot(projectFolder) : undefined
const candidates = projectFolder
? [
path.join(projectFolder, configFilePath),
path.join(projectFolder, 'config', configFilePath),
...(umbrellaRoot ? [path.join(umbrellaRoot, configFilePath), path.join(umbrellaRoot, configFilePath)] : []),
]
: []

const found = candidates.filter((fullPath) => fs.existsSync(fullPath))

if (found.length === 0) {
logger.warn(`${configFilePath} file does not exist. Ignoring...`)
notifier.warn(`${configFilePath} file does not exist. Ignoring...`)
Expand Down
Loading