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

feat: check for deno vs code ext and download when prompted #4698

Merged
merged 18 commits into from
Jun 21, 2022

Conversation

JWhist
Copy link
Contributor

@JWhist JWhist commented Jun 13, 2022

🎉 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:

  • Open a bug/issue before writing your code 🧑‍💻. This ensures we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a typo or something that`s on fire 🔥 (e.g. incident related), you can skip this step.
  • Read the contribution guidelines 📖. This ensures your code follows our style guide and
    passes our tests.
  • Make sure the status checks below are successful ✅

A picture of a cute animal (not mandatory, but encouraged)

@JWhist JWhist self-assigned this Jun 13, 2022
@github-actions github-actions bot added the type: bug code to address defects in shipped code label Jun 13, 2022
@JWhist JWhist added type: chore work needed to keep the product and development running smoothly and removed type: bug code to address defects in shipped code labels Jun 13, 2022
@github-actions
Copy link

github-actions bot commented Jun 13, 2022

📊 Benchmark results

Comparing with a67ec05

Package size: 226 MB

(no change)

^                                                          291 MB  294 MB  294 MB  294 MB  294 MB         
│                                                           ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐          
│                                                           |  |    |  |    |  |    |  |    |  |          
│                                                           |  |    |  |    |  |    |  |    |  |          
│ ──────────────────────────────────────────────────────────┼──┼────┼──┼────┼──┼────┼──┼────┼──┼──────────
│  226 MB  226 MB  226 MB  226 MB  226 MB  221 MB  221 MB   |  |    |  |    |  |    |  |    |  |   226 MB 
│   ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    |  |    |  |    |  |    |  |    |  |    ┌──┐  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
└───┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴──>
    T-12    T-11    T-10    T-9     T-8     T-7     T-6     T-5     T-4     T-3     T-2     T-1      T    
Legend

@github-actions github-actions bot added the type: bug code to address defects in shipped code label Jun 14, 2022
@JWhist JWhist marked this pull request as ready for review June 14, 2022 15:01
Copy link
Member

@eduardoboucas eduardoboucas left a 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.

}

const getDenoExtPrompt = () => {
const message = 'The Deno VSCode extension is recommended. Would you like to install it now?'
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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?'

@@ -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()
Copy link
Member

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).

@JWhist JWhist changed the title fix: check for deno vs code ext and download when prompted feat: check for deno vs code ext and download when prompted Jun 15, 2022
@github-actions github-actions bot added the type: feature code contributing to the implementation of a feature and/or user facing functionality label Jun 15, 2022
@JWhist JWhist requested a review from eduardoboucas June 15, 2022 16:30
src/recipes/vscode/index.js Outdated Show resolved Hide resolved
@JWhist JWhist requested review from a team and eduardoboucas June 15, 2022 20:13
Copy link
Member

@eduardoboucas eduardoboucas left a 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?

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(
Copy link
Member

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.

Suggested change
`${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(

}

const getDenoVSCodeExt = async () => {
await execa('code', ['--install-extension', 'denoland.vscode-deno']).stdout.pipe(process.stdout)
Copy link
Member

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?

Copy link
Contributor

@danez danez Jun 17, 2022

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?

Copy link
Contributor Author

@JWhist JWhist Jun 17, 2022

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

Copy link
Member

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.

@JWhist JWhist requested review from danez and eduardoboucas June 21, 2022 14:21
src/recipes/vscode/index.js Outdated Show resolved Hide resolved
@@ -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`
Copy link
Member

Choose a reason for hiding this comment

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

What is this about?

Copy link
Contributor Author

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.

Copy link
Member

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?

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 necessary, I have another PR going to fix that test

Copy link
Member

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?

Copy link
Contributor Author

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' })
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 curious why you've used inherit here and on L37?

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 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.

Copy link
Member

@eduardoboucas eduardoboucas left a 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?

@JWhist
Copy link
Contributor Author

JWhist commented Jun 21, 2022

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?

@JWhist JWhist merged commit b09b86e into main Jun 21, 2022
@JWhist JWhist deleted the checkForDenoExt branch June 21, 2022 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code type: chore work needed to keep the product and development running smoothly type: feature code contributing to the implementation of a feature and/or user facing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants