-
Notifications
You must be signed in to change notification settings - Fork 365
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
feat: check for deno vs code ext and download when prompted #4698
Conversation
📊 Benchmark resultsComparing with a67ec05 Package size: 226 MB(no change)
Legend
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! I left some comments that I think we should address before merging.
Also, I think we should use the feat:
prefix for this PR and not fix:
, so that we generate a minor version and not a patch.
src/recipes/vscode/index.js
Outdated
} | ||
|
||
const getDenoExtPrompt = () => { | ||
const message = 'The Deno VSCode extension is recommended. Would you like to install it now?' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const message = 'The Deno VSCode extension is recommended. Would you like to install it now?' | |
const message = 'The Deno VSCode extension is recommended. Would you like to install it now?' |
src/recipes/vscode/index.js
Outdated
@@ -27,6 +29,30 @@ const getEdgeFunctionsPath = ({ config, repositoryRoot }) => | |||
|
|||
const getSettingsPath = (repositoryRoot) => join(repositoryRoot, '.vscode', 'settings.json') | |||
|
|||
const hasDenoVSCodeExt = () => { | |||
const ext = execSync('code --list-extensions', { encoding: 'utf-8' }).trim() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use execa
to spawn subprocesses. You can search the codebase for it to see how it's being used.
Also, we should try to use asynchronous methods as much as possible (so we prefer execa
over execaSync
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Would you like to add some tests?
src/recipes/vscode/index.js
Outdated
log( | ||
`${NETLIFYDEVWARN} If you don't have the Deno VS Code extension, install it by visiting ${chalk.blue( | ||
`${NETLIFYDEVWARN} Unable to install Deno VS Code extension, install it by visiting ${chalk.blue( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small change to make this a bit more friendly.
`${NETLIFYDEVWARN} Unable to install Deno VS Code extension, install it by visiting ${chalk.blue( | |
`${NETLIFYDEVWARN} Unable to install Deno VS Code extension. To install it manually, visit ${chalk.blue( |
src/recipes/vscode/index.js
Outdated
} | ||
|
||
const getDenoVSCodeExt = async () => { | ||
await execa('code', ['--install-extension', 'denoland.vscode-deno']).stdout.pipe(process.stdout) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also pipe stderr
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we do not even need to manually pipe stdout (or stderr for this matter) as this is the default behavior of execa
. At least by looking at the options: https://github.com/sindresorhus/execa#stdout-1
So if we remove the .stdout.pipe(...)
part does it still work/log something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my local testing, if I remove the pipe commands it does not log anything, I would have to save the stdout from the response like const { stdout } = await execa... then console.log(stdout) etc. Which is a roundabout way of doing the same thing as piping it imo.
EDIT: just now found out about stdio: 'inherit' option and feel kind of silly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the default behaviour is to capture the output into the return value of the execa
call. If you also want to pipe it into stdout/stderr, you need to make that explicit.
@@ -242,4 +242,4 @@ Generated by [AVA](https://avajs.dev). | |||
> node -p process.env.GATSBY_LOGGER␊ | |||
␊ | |||
yurnalist␊ | |||
◈ "npm run develop" exited with code *. Shutting down Netlify Dev server` | |||
.◈ "npm run develop" exited with code *. Shutting down Netlify Dev server` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this about?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A flaky test that I was trying to get around, there is a helper function that concats a series of loading dots .... down to a single dot. But occasionally the load happens fast enough to not have any dots at all (at least that is my theory). I was toying with the regex in the helper but gave up on it. This change was actually an error, since it's an autogenerated file anyway, and isn't going to help me pass the test at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see! Do you want to revert before we merge?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessary, I have another PR going to fix that test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, but why would we merge this change? We should revert and let the other PR fix the test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, that makes sense. Sorry, I'm still in weekend mode!
@@ -27,6 +28,26 @@ const getEdgeFunctionsPath = ({ config, repositoryRoot }) => | |||
|
|||
const getSettingsPath = (repositoryRoot) => join(repositoryRoot, '.vscode', 'settings.json') | |||
|
|||
const hasDenoVSCodeExt = async () => { | |||
const { stdout: extensions } = await execa('code', ['--list-extensions'], { stderr: 'inherit' }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious why you've used inherit
here and on L37?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to save the data from the extensions if the stdout is ok, but log the error to the screen if it is going to stderr.
Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one! It'd be great to add some tests, even if that happens on a follow up PR. Have you given any thought to how you'd approach that?
I wanted to add tests, but honestly I'm not quite sure how to approach it. Any advice? |
🎉 Thanks for submitting a pull request! 🎉
Summary
Fixes # https://github.com/netlify/pillar-runtime/issues/356
Adds a check on first run to see if user has Deno VS Code extension installed, and if not, prompts them to ask if they would like to install it. If they select yes, it installs the Deno VS Code Extension. This helps with some syntax highlighting.
Looking for a bit of help in testing this. I uninstalled my local version a few times and tried that way, but looking for advice on what would be a standard way to do this? Maybe a container or something? Do we have a docker image we use for such cases?
For us to review and ship your PR efficiently, please perform the following steps:
passes our tests.
A picture of a cute animal (not mandatory, but encouraged)