Skip to content

Commit 1beaaf8

Browse files
IwanKaramazowIwan
and
Iwan
authored
Tweak bsc path algorithm. (#59)
In certain cases the native bsc binaries might be put in an unknown location on the file system. Example: yarn workspaces. The only other guarantee we have is that the node bsc should be available in the `project root + ./node_modules/.bin` cf. package.json. See [npm package.json](https://docs.npmjs.com/cli/v6/configuring-npm/package-json#bin) or [yarn package.json](https://classic.yarnpkg.com/en/docs/package-json#bin) and [yarn run](https://classic.yarnpkg.com/en/docs/cli/run#toc-yarn-run-script) Co-authored-by: Iwan <[email protected]>
1 parent ac23419 commit 1beaaf8

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

server/src/constants.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ import * as path from "path";
44
// version is fixed to 2.0
55
export let jsonrpcVersion = "2.0";
66
export let bscPartialPath = path.join(
7-
"node_modules",
8-
"bs-platform",
9-
process.platform,
10-
"bsc.exe"
7+
"node_modules",
8+
"bs-platform",
9+
process.platform,
10+
"bsc.exe"
1111
);
12+
13+
export let bscNodePartialPath = path.join("node_modules", ".bin", "bsc");
14+
1215
// can't use the native bsb since we might need the watcher -w flag, which is only in the js wrapper
1316
// export let bsbPartialPath = path.join('node_modules', 'bs-platform', process.platform, 'bsb.exe');
1417
export let bsbPartialPath = path.join("node_modules", ".bin", "bsb");

server/src/server.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -425,11 +425,21 @@ process.on("message", (msg: m.Message) => {
425425
process.send!(fakeSuccessResponse);
426426
process.send!(response);
427427
} else {
428+
let bscExists = false;
428429
let bscPath = path.join(projectRootPath, c.bscPartialPath);
429-
if (!fs.existsSync(bscPath)) {
430+
bscExists = fs.existsSync(bscPath);
431+
if (!bscExists) {
432+
// In certain cases the native bsc binaries might be put in an unknown location
433+
// on the file system. Example: yarn workspaces.
434+
// The only other guarantee we have is that the node bsc should be available in the
435+
// project root + ./node_modules/.bin cf. package.json
436+
bscPath = path.join(projectRootPath, c.bscNodePartialPath);
437+
bscExists = fs.existsSync(bscPath);
438+
}
439+
if (!bscExists) {
430440
let params: p.ShowMessageParams = {
431441
type: p.MessageType.Error,
432-
message: `Cannot find a nearby ${c.bscPartialPath}. It's needed for formatting.`,
442+
message: `Cannot find a nearby ${c.bscNodePartialPath}. It's needed for formatting.`,
433443
};
434444
let response: m.NotificationMessage = {
435445
jsonrpc: c.jsonrpcVersion,

0 commit comments

Comments
 (0)