diff --git a/src/config/resolve-config.js b/src/config/resolve-config.js index 229caf3d5..c8f0f4343 100644 --- a/src/config/resolve-config.js +++ b/src/config/resolve-config.js @@ -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; } diff --git a/tests_integration/__tests__/config-resolution.js b/tests_integration/__tests__/config-resolution.js index 25a610e53..d78a55eb8 100644 --- a/tests_integration/__tests__/config-resolution.js +++ b/tests_integration/__tests__/config-resolution.js @@ -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")] + }); +}); diff --git a/tests_integration/cli/config/resolve-relative/.prettierrc b/tests_integration/cli/config/resolve-relative/.prettierrc new file mode 100644 index 000000000..8d5619642 --- /dev/null +++ b/tests_integration/cli/config/resolve-relative/.prettierrc @@ -0,0 +1,4 @@ +{ + "plugins": ["../path-to-plugin"], + "pluginSearchDirs": ["../path-to-plugin-search-dir"] +}