Skip to content

Commit 27d8763

Browse files
committed
Change cwd detection for mono-repos
1 parent b281b23 commit 27d8763

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/plugin.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import os from "os";
55
import path from "path";
66
import process from "process";
77
import url from "url";
8+
import { resolveConfigFile } from "prettier";
89

910
// In order to properly parse ruby code, we need to tell the ruby process to
1011
// parse using UTF-8. Unfortunately, the way that you accomplish this looks
@@ -67,14 +68,16 @@ export async function spawnServer(opts, killOnExit = true) {
6768
const tmpdir = os.tmpdir();
6869
const filepath = path.join(tmpdir, `prettier-ruby-parser-${process.pid}.txt`);
6970

70-
const default_options = {
71+
const options = {
7172
env: Object.assign({}, process.env, { LANG: getLang() }),
7273
stdio: ["ignore", "ignore", "inherit"],
7374
detached: true
7475
};
75-
const options = opts.filepath
76-
? { cwd: path.dirname(opts.filepath), ...default_options }
77-
: default_options;
76+
77+
if (opts.filepath) {
78+
const prettierConfig = await resolveConfigFile(opts.filepath);
79+
options.cwd = path.dirname(prettierConfig);
80+
}
7881

7982
const server = spawn(
8083
opts.rubyExecutablePath || "ruby",

0 commit comments

Comments
 (0)