Skip to content

Formatting document fails in monorepo #572

Closed
@Minnozz

Description

@Minnozz

Extension version: 1.7.6 (latest master)

The Format document feature uses the bsc.exe binary:

let projectRootPath = utils.findProjectRootOfFile(filePath);
let bscBinaryPath =
projectRootPath === null ? null : findBscBinary(projectRootPath);

The location of the bsc.exe binary is determined as follows:

let findBscBinary = (projectRootPath: p.DocumentUri) => {
let rescriptBinaryPath = findRescriptBinary(projectRootPath);
if (rescriptBinaryPath !== null) {
let rescriptDirPath = path.join(
path.dirname(rescriptBinaryPath),
"..",
"rescript"
);
let bscBinaryPath = path.join(rescriptDirPath, c.platformDir, c.bscExeName);

It is "reverse engineered" from the location of the rescript binary:

let findRescriptBinary = (projectRootPath: p.DocumentUri) =>
extensionConfiguration.binaryPath == null
? findBinaryPathFromProjectRoot(projectRootPath)
: utils.findRescriptBinary(extensionConfiguration.binaryPath);

export let findRescriptBinary = (
binaryDirPath: p.DocumentUri | null
): p.DocumentUri | null => {
return findBinary(binaryDirPath, c.rescriptBinName);
};

The node_modules/.bin/rescript symlink exists both at the monorepo top level node_modules and the subdir node_modules, which makes findRescriptBinary return src/monorepo/subdir/node_modules/.bin/rescript.

However, the node_modules/rescript directory usually exists only at the monorepo top level, so when the path of the rescript binary is used to derive the location of bsc.exe, this results in the non-existent path src/monorepo/subdir/node_modules/rescript/linux/bsc.exe. It should actually return src/monorepo/node_modules/rescript/linux/bsc.exe (without subdir).

To make things more complicated, if node_modules/rescript does exist in the subdir, that directory should be used. This may be the case when multiple rescript versions are used in the same monorepo.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions