-
Notifications
You must be signed in to change notification settings - Fork 734
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: add more types that get logged via console
methods
#294
Conversation
🦋 Changeset detectedLatest commit: aff14b6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
packages/wrangler/src/inspect.ts
Outdated
@@ -539,5 +575,7 @@ function logConsoleMessage(evt: Protocol.Runtime.ConsoleAPICalledEvent): void { | |||
} | |||
} | |||
|
|||
console[evt.type](...args); | |||
const method = mapConsoleAPIMessageTypeToConsoleMethod[evt.type]; | |||
//@ts-expect-error I dunno how to make this type pass 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.
🤪 halp
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.
You need to exclude the constructor from the list of keys:
export const mapConsoleAPIMessageTypeToConsoleMethod: {
[key in Protocol.Runtime.ConsoleAPICalledEvent["type"]]: Exclude<
keyof Console,
"Console"
>;
But then TS complains that args
must be a tuple or be passed to a rest argument.
We can work around that by using apply()
(telling eslint not to stress):
// eslint-disable-next-line prefer-spread
console[method].apply(console, args);
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.
Tests needed.... 🙏
This PR adds more special logic for some data types that get logged via `console` methods. Types like `Promise`, `Date`, `WeakMaps`, and some more, now get logged correctly (or at least, better than they used to). This PR also fixes a sinister bug - the `type` of the `ConsoleAPICalled` events don't match 1:1 with actual console methods (eg: `console.warn` message type is `warning`). This PR adds a mapping between those types and method names. Some methods don't seem to have a message type, I'm not sure why, but we'll get to them later.
6ce866d
to
aff14b6
Compare
Working on tests right now, in a separate PR, based on the description here #188 (comment). Going to be a bit involved, don't want to block this bugfix here. |
This PR adds more special logic for some data types that get logged via
console
methods. Types likePromise
,Date
,WeakMaps
, and some more, now get logged correctly (or at least, better than they used to).This PR also fixes a sinister bug - the
type
of theConsoleAPICalled
events don't match 1:1 with actual console methods (eg:console.warn
message type iswarning
). This PR adds a mapping between those types and method names. Some methods don't seem to have a message type, I'm not sure why, but we'll get to them later.