-
Notifications
You must be signed in to change notification settings - Fork 920
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
Remove ora, use Pino #735
Remove ora, use Pino #735
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/pikapkg/snowpack/7gtqdd9zq |
return result; | ||
} else { | ||
continue; | ||
logger.debug(`[${step.name}] running load()`); |
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.
Now we have the idea of debug! 🎉. These won’t show unless enabled.
TODO: add a --debug
flag or something because the current PR doesn’t have a way to actually show these
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.
Awesome! nit: If I was debugging, I'd want to see what file was loaded. Something like:
logger.debug(`[${step.name}] running load()`); | |
// TODO: const relativeSrcPath = ... | |
logger.debug(`[${step.name}] running load() for ${relativeSrcPath}`); |
ditto for other hooks as well (although fine to put off if it starts to get confusing about which path to print once the file no longer exists on disk. Maybe just the file name since the load() call would be right above it?)
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.
Added!
} else { | ||
continue; | ||
} | ||
} catch (err) { |
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.
Change I’ve been thinking about: let plugins throw errors, and we’ll show the result to the user. I personally like that approach better than logging (though they can log, too)
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.
+1, I'm on board, especially for the dev use case.
During build, I'd expect a thrown error to exit the build (or at least, cause it to return an exit code / fail in CI).
packages/snowpack/src/logger.ts
Outdated
const BRACKET_NAME_MATCH = /^\[[^\]]+\]/; // match [name] in brackets at beginning of string | ||
|
||
/** http://getpino.io/#/docs/pretty */ | ||
function prettifier() { |
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.
Since we’re piping all logs through a utility, this is where we can do some consistent formatting.
logError(err.message || err); | ||
if (err.hint) { | ||
// Note: Wait 1ms to guarantee a log message after the spinner | ||
setTimeout(() => console.log(err.hint), 1); |
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.
lol
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.
clensing snowpack of one of my many sins in this codebase
👍
I like the idea of exposing a Overall, I like the direction of this. |
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.
This looks amazing!
I don't see it here, but @snowpack/plugin-run-script
currently users the old log()
method, and TypeScript specifically was using the messageBus to report it's status via "WORKER_COMPLETE", etc. Make sure that that doesn't break in this PR (you can run a TypeScript CSA app locally to confirm).
I think the argument could be made for run()
to get a special logger, since it's sole purpose is to run tooling with Snowpack and connect it's output back into the dev console. A run plugin isn't just logging, but is actually representing a tool's "state" in the dev console / build (ex: "TypeScript is currently failing with 1 error: \n...\n", "TypeScript is currently passing with 0 errors.", etc.)
A good follow up discussion (and then PR) would be to decide what that interface would look like, and then publicly document it for the run hook.
@@ -83,8 +83,8 @@ | |||
"mkdirp": "^1.0.3", | |||
"npm-run-path": "^4.0.1", | |||
"open": "^7.0.4", | |||
"ora": "^4.0.4", |
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.
💯
return result; | ||
} else { | ||
continue; | ||
logger.debug(`[${step.name}] running load()`); |
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.
Awesome! nit: If I was debugging, I'd want to see what file was loaded. Something like:
logger.debug(`[${step.name}] running load()`); | |
// TODO: const relativeSrcPath = ... | |
logger.debug(`[${step.name}] running load() for ${relativeSrcPath}`); |
ditto for other hooks as well (although fine to put off if it starts to get confusing about which path to print once the file no longer exists on disk. Maybe just the file name since the load() call would be right above it?)
} else { | ||
continue; | ||
} | ||
} catch (err) { |
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.
+1, I'm on board, especially for the dev use case.
During build, I'd expect a thrown error to exit the build (or at least, cause it to return an exit code / fail in CI).
logError(err.message || err); | ||
if (err.hint) { | ||
// Note: Wait 1ms to guarantee a log message after the spinner | ||
setTimeout(() => console.log(err.hint), 1); |
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.
clensing snowpack of one of my many sins in this codebase
@@ -7,7 +7,7 @@ docs/index.md | |||
lerna-debug.log | |||
node_modules | |||
package-lock.json | |||
packages/**/build | |||
packages/@snowpack/**/build |
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.
So funny enough we were ignoring packages/snowpack/src/build
😅. Oops! (no wonder I could never jump straight to build-pipeline.ts
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 was wondering that too!
@@ -3,4 +3,5 @@ module.exports = { | |||
'<rootDir>/packages/@snowpack/app-template-', // don’t run tests intended as user examples | |||
'<rootDir>/test/create-snowpack-app/test-install', // don’t run tests inside our mock create-snowpack-app install | |||
], | |||
testEnvironment: 'node', |
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 was hoping this would speed up tests. Sadly, it didn’t.
/[\u001B\u009B][[\]()#;?]*(?:(?:(?:[a-zA-Z\d]*(?:;[-a-zA-Z\d\/#&.:=?%@~_]*)*)?\u0007)|(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PR-TZcf-ntqry=><~]))/g, | ||
'', | ||
); | ||
} |
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 actually handle this a little better now with the NO_COLOR
env var in our test command ("test": "NO_COLOR=true jest …"
)
// TODO: remove when ora is replaced | ||
if (['dep-types-only', 'error-node-builtin-unresolved'].includes(testName)) { | ||
continue; // this test is skipped because the ora failure message causes the output to flake depending on Node version + OS | ||
} |
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’re testing all the files again! 🎉
@@ -43,19 +44,15 @@ import { | |||
findMatchingAliasEntry, | |||
} from '../util.js'; | |||
|
|||
const logger = createLogger({name: 'snowpack'}); |
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.
Passing a name
in is how logs are prefixed with [snowpack]
. This can be changed for plugins (e.g. [@snowpack/plugin-babel] …
).
[snowpack] Entry module cannot be external (http). | ||
[snowpack] install skipped (nothing to install) | ||
[snowpack] ../../../node_modules/bad-node-builtin-pkg/entrypoint.js | ||
"XXXX" (Node.js built-in) could not be resolved. (https://www.snowpack.dev/#node-built-in-could-not-be-resolved) |
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.
@FredKSchott I tried
At least we sorta re-enabled this test! Now we’re not skipping anything 🎉
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.
this feels like a great solution
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.
+1, this is good to merge for me!
Comment for after merging: I know you mentioned wanting to add --debug
and --silent
modes, just checking that that's still in your plan since those are usually a more intuitive for a user who doesn't know what different log levels mean.
I'm fine supporting all 3 (those two + --log-level
) or just those two.
filePath, | ||
isDev, | ||
// @ts-ignore: internal API only | ||
log: (msg, data: any = {}) => { |
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.
now that we have a good logger, we can pass it directly to the different plugin hooks as our documented, public way to log. Since these are internal only at the moment, no worries about breaking changes.
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 like that. Also using a documented logger like Pino seems easy-to-use, too.
Yeah I went back-and-forth on that. Some things have them; others don’t. We’ll need |
Changes
Part of #648, but since all that won’t fit into one PR, it’s probably important to outline the intended scope of this change:
Goals
--silent
?), or make it noisier (--debug
?)Non-goals
Screenshots
Idea: prefix logs with a
[name]
so users can see what’s logging (e.g. if Snowpack is logging something, or Rollup, or a CLI tool, or it’s user debugging, etc.)Basic build
Basic install
Plugin errors (note the name)!
Other ideas
Some other thoughts
Testing
Tests should pass, but evaluating should come down to whether or not the
snowpack build
andsnowpack install
commands look good! ✨