Skip to content

Commit

Permalink
Tweak bsc path algorithm. (#59)
Browse files Browse the repository at this point in the history
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 <mvalcke@hubspot.com>
  • Loading branch information
IwanKaramazow and Iwan authored Jan 6, 2021
1 parent ac23419 commit 1beaaf8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
11 changes: 7 additions & 4 deletions server/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import * as path from "path";
// version is fixed to 2.0
export let jsonrpcVersion = "2.0";
export let bscPartialPath = path.join(
"node_modules",
"bs-platform",
process.platform,
"bsc.exe"
"node_modules",
"bs-platform",
process.platform,
"bsc.exe"
);

export let bscNodePartialPath = path.join("node_modules", ".bin", "bsc");

// can't use the native bsb since we might need the watcher -w flag, which is only in the js wrapper
// export let bsbPartialPath = path.join('node_modules', 'bs-platform', process.platform, 'bsb.exe');
export let bsbPartialPath = path.join("node_modules", ".bin", "bsb");
Expand Down
14 changes: 12 additions & 2 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,21 @@ process.on("message", (msg: m.Message) => {
process.send!(fakeSuccessResponse);
process.send!(response);
} else {
let bscExists = false;
let bscPath = path.join(projectRootPath, c.bscPartialPath);
if (!fs.existsSync(bscPath)) {
bscExists = fs.existsSync(bscPath);
if (!bscExists) {
// 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
bscPath = path.join(projectRootPath, c.bscNodePartialPath);
bscExists = fs.existsSync(bscPath);
}
if (!bscExists) {
let params: p.ShowMessageParams = {
type: p.MessageType.Error,
message: `Cannot find a nearby ${c.bscPartialPath}. It's needed for formatting.`,
message: `Cannot find a nearby ${c.bscNodePartialPath}. It's needed for formatting.`,
};
let response: m.NotificationMessage = {
jsonrpc: c.jsonrpcVersion,
Expand Down

0 comments on commit 1beaaf8

Please sign in to comment.