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

fix: search file path when no --config option #692

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 15 additions & 6 deletions bin/cli.js
Expand Up @@ -53,7 +53,7 @@ import i18nTransform from '../dist/transform.js'

let config = {}
try {
const result = await lilconfig(pkg.name, {
const configReader = lilconfig(pkg.name, {
searchPlaces: [
`${pkg.name}.config.js`,
`${pkg.name}.config.json`,
Expand All @@ -67,7 +67,13 @@ import i18nTransform from '../dist/transform.js'
'.yaml': yamlConfigLoader,
'.yml': yamlConfigLoader,
},
}).load(program.opts().config)
})
let result
if (program.opts().config) {
result = await configReader.load(program.opts().config)
} else {
result = await configReader.search()
}
config = result.config
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still possibly problematic as if there is no config file this will fail (result.config is then undefined). I've pushed a fix as 7.0.2

} catch (err) {
if (err.code === 'MODULE_NOT_FOUND') {
Expand Down Expand Up @@ -117,16 +123,19 @@ import i18nTransform from '../dist/transform.js'
}
}

let basePath = process.cwd()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you make a PR with only that part of the code? I've missed that in my fix.


if (program.opts().config) {
basePath = path.dirname(path.resolve(program.opts().config))
}

globs = config.input.map(function (s) {
var negate = ''
if (s.startsWith('!')) {
negate = '!'
s = s.substr(1)
}
return (
negate +
path.resolve(path.dirname(path.resolve(program.opts().config)), s)
)
return negate + path.resolve(basePath, s)
})
}

Expand Down