feat(api): support relative paths for plugin(SearchDir)s in config files (#4667)
* feat(api): support relative paths for plugin(SearchDir)s in config files * fix: convince appveyor
This commit is contained in:
3 files changed
+24
No files matched your search
@@ -48,6 +48,17 @@ function _resolveConfig(filePath, opts, sync) {
|
||||
mergeOverrides(Object.assign({}, result), filePath)
|
||||
);
|
||||
|
||||
["plugins", "pluginSearchDirs"].forEach(optionName => {
|
||||
if (Array.isArray(merged[optionName])) {
|
||||
merged[optionName] = merged[optionName].map(
|
||||
value =>
|
||||
typeof value === "string" && value.startsWith(".") // relative path
|
||||
? path.resolve(path.dirname(result.filepath), value)
|
||||
: value
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
if (!result && !editorConfigured) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -226,3 +226,12 @@ test("API resolveConfig.sync removes $schema option", () => {
|
||||
tabWidth: 42
|
||||
});
|
||||
});
|
||||
|
||||
test("API resolveConfig resolves relative path values based on config filepath", () => {
|
||||
const currentDir = path.join(__dirname, "../cli/config/resolve-relative");
|
||||
const parentDir = path.resolve(currentDir, "..");
|
||||
expect(prettier.resolveConfig.sync(`${currentDir}/index.js`)).toMatchObject({
|
||||
plugins: [path.join(parentDir, "path-to-plugin")],
|
||||
pluginSearchDirs: [path.join(parentDir, "path-to-plugin-search-dir")]
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": ["../path-to-plugin"],
|
||||
"pluginSearchDirs": ["../path-to-plugin-search-dir"]
|
||||
}
|
||||
Reference in new issue
Block a user