Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Run local coursier if available to avoid using bootstraped one #1385

Merged
merged 1 commit into from
Apr 17, 2023

Conversation

tgodzik
Copy link
Contributor

@tgodzik tgodzik commented Apr 11, 2023

This might help out in corporate environements since it will require installing coursier only once and Metals will be able to use it.

In later steps I will try to automatically download coursier or native image via metals if not available.

Continuation of scalameta/metals-languageclient#524

@tgodzik tgodzik force-pushed the coursier-local branch 2 times, most recently from 9d28ed7 to 94ce9d6 Compare April 11, 2023 16:58
(process.platform === "win32" && p.endsWith(path.sep + "cs.bat"))
);
if (possibleCoursier) {
const coursierVersion = spawnSync(possibleCoursier, ["version"]);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how to work around this, I can't find a way to chain ChildProcess since then is only available on Promise. Alternatively, we could make a spawn with a wait to make sure this doesn't take too long. Ideas?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is already dependency on promisify-child-process which provides a promisfied equivalents of child_process, did you check it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I did? Doing .then on ChildProcessPromise was only returning Promise<Output> and not sure of there is a way around it really.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe https://github.com/sindresorhus/execa help?
As long as we use raw child_process stuffs (without writing a wrapper) there's no way to do that (get stdout wrapped by Promise if success, and Promise failed if return code isn't 0).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't look like it :/ We want to pipe the output from coursier to VS Code output, but it seems I can do it only via ChildProcessPromise. I tried returning a Promise, but that seems to have a wrong type in the actual javascript underneath:
906323d

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Och actually if I have an intermediate object it works, not 100% pretty, but feels ok.

@tgodzik tgodzik requested review from tanishiking, gabro and kpodsiad and removed request for tanishiking April 11, 2023 17:00
@tgodzik tgodzik marked this pull request as ready for review April 11, 2023 17:00
@tgodzik tgodzik force-pushed the coursier-local branch 7 times, most recently from 509aba3 to 022a78c Compare April 11, 2023 17:26
Copy link
Member

@tanishiking tanishiking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few comments, but overall it looks good 👍

}

export function validateCoursier(pathEnv: string): string | undefined {
const isWindows = process.platform === "win32";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[note]
I thought this might fail to detect windows when it's 64bit system, but it looks like there's only win32 😄
https://nodejs.org/api/process.html#process_process_platform

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep :P I checked the docs

"-p",
];

const path = process.env["PATH"];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this work for Windows (while CI tests pass), maybe it's Path instead of PATH on windows?
avajs/ava#3014

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"sourceMaps": true,
"outFiles": ["${workspaceRoot}/out/**/*.js"],
"outFiles": ["${workspaceRoot}/packages/metals-vscode/out/**/*.js"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need these changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise it's not possible to start the extension inside VS Code, I can move it separate, but this is just a follow up from the PR that merged the language client


export function validateCoursier(pathEnv: string): string | undefined {
const isWindows = process.platform === "win32";
const possibleCoursier = pathEnv
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we want to use https://github.com/otiai10/lookpath to find commands from PATH, this library deals well with the platform differences (and it takes care of PATHEXT to checking cs.bat and cs.exe)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I would add the library if we see any issue, but this seems to work correctly both in linux and windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also it seems that the alst release was in 2021 so I would rather tweak our logic if needed.

(process.platform === "win32" && p.endsWith(path.sep + "cs.bat"))
);
if (possibleCoursier) {
const coursierVersion = spawnSync(possibleCoursier, ["version"]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe https://github.com/sindresorhus/execa help?
As long as we use raw child_process stuffs (without writing a wrapper) there's no way to do that (get stdout wrapped by Promise if success, and Promise failed if return code isn't 0).

@tgodzik tgodzik requested a review from tanishiking April 12, 2023 14:00
@tgodzik tgodzik force-pushed the coursier-local branch 2 times, most recently from a2fc784 to b665fdc Compare April 12, 2023 14:33
This might help out in corporate environements since it will require installing coursier only once and Metals will be able to use it.

In later steps I will try to automatically download coursier or native image via metals if not available.
Copy link
Member

@tanishiking tanishiking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM:+1:

@tgodzik tgodzik merged commit e7b29b5 into scalameta:main Apr 17, 2023
@tgodzik tgodzik deleted the coursier-local branch April 17, 2023 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants