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

Dev server improvements #762

Merged
merged 6 commits into from
Aug 13, 2020
Merged

Dev server improvements #762

merged 6 commits into from
Aug 13, 2020

Conversation

drwpow
Copy link
Collaborator

@drwpow drwpow commented Aug 7, 2020

Changes

This improves the dev server logging. Now:

  • ✅ All console.* messages log and keep (even across page loads!)
  • ✅ Plugins can throw and the output will bubble up to the dev server
  • ✅ Dev server shows state as ERROR or READY, along with error log (error persists even after fix)

Screenshots

Default (no errors)

Screen Shot 2020-08-11 at 5 27 14 PM

React

2020-08-11 17-33-18 2020-08-11 17_34_28

Vue

Screen Shot 2020-08-11 at 6 26 59 PM

Svelte

Screen Shot 2020-08-11 at 5 55 56 PM

Lit Element

Screen Shot 2020-08-11 at 6 01 03 PM

How about the status bar at bottom? Any changes needed there?

Testing

@vercel
Copy link

vercel bot commented Aug 7, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/pikapkg/snowpack/btpz1ahx3
✅ Preview: https://snowpack-git-dev-dashboard-2.pikapkg.vercel.app

@@ -275,6 +236,12 @@ export async function command(commandOptions: CommandOptions) {
await updateLockfileHash(DEV_DEPENDENCIES_DIR);
}

// Start painting dev dashboard after successful install
Copy link
Collaborator Author

@drwpow drwpow Aug 12, 2020

Choose a reason for hiding this comment

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

One annoying thing: we still have a pino instance in install.ts, which means any install errors get wiped away when the dev server starts (because it logs to stderr, not console.error, so changing that means changing all pino instances too). We don’t throw an error in install, currently. And we don’t allow passing a logger in that function.

What should we do here? Should we throw an error in install.ts? Should we add dev vs build logic in install to handle different logging ability (pino vs messageBus)? Unclear what the simplest way would be to take an install error and pass it to the dev server’s array of logs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

currentlyRunningCommand = null;
});
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No more auto-install on dev! 🎉

if (errors && errors.length > 0) {
console.error(JSON.stringify(errors));
throw new Error(displayError({error: errors[0], contents, filePath}));
Copy link
Collaborator Author

@drwpow drwpow Aug 12, 2020

Choose a reason for hiding this comment

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

This error display for Vue was real bad, so I added one (see screenshots)

@stramel
Copy link
Contributor

stramel commented Aug 12, 2020

Wow! Huge improvement! I'm going to try to pull it down tomorrow and play around with it. How does the proxy output look? Might be nice to have that listed below the main line?

@stramel
Copy link
Contributor

stramel commented Aug 12, 2020

My previous csa generated app just sits at loading...

image

Copy link
Owner

@FredKSchott FredKSchott left a comment

Choose a reason for hiding this comment

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

This is already a huge improvement!

I have some basic design feedback of the output, but if it's alright with you I'd love to play around with the PR a bit to test some ideas before making any suggestions.

@@ -95,12 +102,22 @@ async function runPipelineLoadStep(
// if source maps disabled, don’t return any
if (!sourceMaps) result[ext].map = undefined;
});
if (devMessageBus && isDev) {
devMessageBus.emit('SUCCESS', {id: step.name});
Copy link
Owner

Choose a reason for hiding this comment

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

already talked through this in person, but this is the bit that isn't really compatible with our current idea of a whole plugin b eing SUCCESS or FAIL.

example 1:

  • App.svelte loads in the dev server, has an error, fails
  • Icon.svelte also loads, succeeds, "SUCCESS" overwrites "ERROR"
  • End result is no error shown

example 2:

  • App.svelte loads in the dev server, has an error, fails
  • "Svelte" plugin is now in the "error" state
  • What does it mean to go back to the "success" state? Do we need to track which files failed, and then only go to "SUCCESS" state when that file succeeds? what if the file is deleted? etc etc

Copy link
Collaborator Author

@drwpow drwpow Aug 12, 2020

Choose a reason for hiding this comment

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

Right. I thought of that convo while doing this, and I agree it’s a bit hacky. But one thing I realized in playing with the dev server we didn’t discuss was it felt “broken” in a sense to show the READY status if the dev server was running but there was an error and nothing was showing. It felt a lot better to either show READY or ERROR based on the state, but to your point this isn’t a perfect implementation.

Maybe we change that READY status to RUNNING? Or something else? Or maybe we just take the green color away? Open to a solution where an error is visible and it doesn’t feel like the dev server is “lying” to us telling us everything is good when it’s not.

@FredKSchott
Copy link
Owner

Made some changes! Will let the screenshots show:

Startup, Simple Project (Preact), No Workers

Screen Shot 2020-08-12 at 3 44 45 PM

load() Error, Simple Project (Preact), No Workers

Screen Shot 2020-08-12 at 3 44 59 PM

Startup, Complex Project (Svelte + TypeScript)

Screen Shot 2020-08-12 at 3 35 57 PM

Errors, Complex Project (Svelte + TypeScript)

Screen Shot 2020-08-12 at 3 35 15 PM

White Color Scheme

Screen Shot 2020-08-12 at 3 44 29 PM

@stramel
Copy link
Contributor

stramel commented Aug 13, 2020

Seems like the latest batch of changes fixed the issue with it not starting.

One thing I noticed which is probably unrelated to these changes, but missing files are a bit annoying.

image

Would still love to see proxy get some love with these changes but I can submit a PR after the fact if you want.

Currently, it just logs to console which is now greatly improved to where we can at least see the errors.

image

It would be nice to see something like this (example of Next.js):

image

};

const MAX_CONSOLE_LENGTH = 500;
const NO_COLOR_ENABLED = process.env.FORCE_COLOR === '0' || process.env.NO_COLOR;
Copy link
Contributor

@stramel stramel Aug 13, 2020

Choose a reason for hiding this comment

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

I don't know if this is necessary unless we want to support NO_COLOR which isn't supported by kleur yet. I opened a PR to address this, lukeed/kleur#37

If we want to support NO_COLOR before this, we should be able to do colors.$.enabled = !process.env.NO_COLOR && colors.$.enabled. This should allow all colors.* calls to do nothing. https://github.com/lukeed/kleur#conditional-support

Copy link
Contributor

Choose a reason for hiding this comment

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

Just kidding, Luke is on top of it!

https://github.com/lukeed/kleur/releases/tag/v4.1.0

Now we shouldn't need to add anything to support disabling colors.

Copy link
Owner

@FredKSchott FredKSchott Aug 13, 2020

Choose a reason for hiding this comment

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

Nice! Upstream contributions, ftw!

@FredKSchott
Copy link
Owner

+1 for better proxy output, can take a look at that similar to Next.js

Not sure what the service worker issue is but most likely not related to this PR, would love more info if you want to spin up an issue/discussion to debug/triage

@stramel
Copy link
Contributor

stramel commented Aug 13, 2020

Not sure what the service worker issue is but most likely not related to this PR, would love more info if you want to spin up an issue/discussion to debug/triage

I previously had a service worker registered on that localhost:port, so when I started the app it requested a /service-worker.js file. I just thought it was a lot of output for a missing file. Is there a way we could condense the fact that we're checking different file extensions? maybe like service-worker.[js|mjs|jsx|ts|tsx]?

I just pulled in the latest and ran it again, seems like something changed? Might be an issue with linking? I know at one point it wasn't adding the absolute path

image

Also, just curious if it would make sense to make paths relative to the running directory instead of absolute? For example,

/Users/mstramel/Projects/testing/snowpack-tests/test-1/public/service-worker.js

to

/public/service-worker.js

since the project is being ran out of /Users/mstramel/Projects/testing/snowpack-tests/test-1

@FredKSchott
Copy link
Owner

Lets keep output as is for now, but would be curious to clean up in a follow up PR. I have definitely made mistakes mapping a relative path to an absolute path in my head (when a tool doesn't give you the full absolute path) so I'm sensitive to it as a debugging tool.

@stramel I'm confused why the plugin name is that full path in your logs, are you on the latest version of the babel plugin? If updating doesn't fix it, can you share your config file? That's definitely a bug

@stramel
Copy link
Contributor

stramel commented Aug 13, 2020

@stramel I'm confused why the plugin name is that full path in your logs, are you on the latest version of the babel plugin? If updating doesn't fix it, can you share your config file? That's definitely a bug

It went away after I updated my dependencies. 👍

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