Skip to content

Commit

Permalink
Change cwd detection for mono-repos
Browse files Browse the repository at this point in the history
  • Loading branch information
hrabe committed Dec 11, 2023
1 parent b281b23 commit 27d8763
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import os from "os";
import path from "path";
import process from "process";
import url from "url";
import { resolveConfigFile } from "prettier";

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

const default_options = {
const options = {
env: Object.assign({}, process.env, { LANG: getLang() }),
stdio: ["ignore", "ignore", "inherit"],
detached: true
};
const options = opts.filepath
? { cwd: path.dirname(opts.filepath), ...default_options }
: default_options;

if (opts.filepath) {
const prettierConfig = await resolveConfigFile(opts.filepath);
options.cwd = path.dirname(prettierConfig);
}

const server = spawn(
opts.rubyExecutablePath || "ruby",
Expand Down

0 comments on commit 27d8763

Please sign in to comment.