Skip to content

Commit 5931162

Browse files
committed
Log messages received by debugger
1 parent 084b0df commit 5931162

File tree

7 files changed

+61
-43
lines changed

7 files changed

+61
-43
lines changed

.changeset/modern-chairs-hunt.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@solid-devtools/extension": patch
3+
"@solid-devtools/debugger": patch
4+
"@solid-devtools/shared": patch
5+
"solid-devtools": patch
6+
---
7+
8+
Log messages recieved.

build.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export function get_common_esbuild_options(is_dev: boolean, dist_dirname: string
6060
treeShaking: !is_dev,
6161
logLevel: is_dev ? 'debug' : 'warning',
6262
color: true,
63+
dropLabels: [is_dev ? 'PROD' : 'DEV'],
6364
}
6465
}
6566

packages/debugger/src/main/index.ts

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {createEventBus, createGlobalEmitter, type GlobalEmitter} from '@solid-primitives/event-bus'
22
import {createStaticStore} from '@solid-primitives/static-store'
33
import {defer} from '@solid-primitives/utils'
4-
import {batch, createComputed, createEffect, createMemo, createSignal} from 'solid-js'
4+
import * as s from 'solid-js'
5+
import {log_message} from '@solid-devtools/shared/utils'
56
import {createDependencyGraph, type DGraphUpdate} from '../dependency/index.ts'
67
import {createInspector, type InspectorUpdate, type ToggleInspectedValueData} from '../inspector/index.ts'
78
import {createLocator} from '../locator/index.ts'
@@ -69,14 +70,14 @@ const [modules, toggleModules] = createStaticStore({
6970
})
7071

7172
// The debugger can be enabled by devtools or by the locator
72-
const debuggerEnabled = createMemo(() => modules.debugger || modules.locatorKeyPressSignal())
73-
const dgraphEnabled = createMemo(() => modules.dgraph && debuggerEnabled())
73+
const debuggerEnabled = s.createMemo(() => modules.debugger || modules.locatorKeyPressSignal())
74+
const dgraphEnabled = s.createMemo(() => modules.dgraph && debuggerEnabled())
7475
// locator is enabled if debugger is enabled, and user pressed the key to activate it, or the plugin activated it
75-
const locatorEnabled = createMemo(
76+
const locatorEnabled = s.createMemo(
7677
() => (modules.locatorKeyPressSignal() || modules.locator) && debuggerEnabled(),
7778
)
7879

79-
createEffect(
80+
s.createEffect(
8081
defer(debuggerEnabled, enabled => {
8182
hub.output.emit('DebuggerEnabled', enabled)
8283
}),
@@ -90,7 +91,7 @@ let currentView: DevtoolsMainView = DEFAULT_MAIN_VIEW
9091
const viewChange = createEventBus<DevtoolsMainView>()
9192

9293
function setView(view: DevtoolsMainView) {
93-
batch(() => {
94+
s.batch(() => {
9495
// setStructureEnabled(view === DevtoolsMainView.Structure)
9596
// setDgraphEnabled(view === DevtoolsMainView.Dgraph)
9697
viewChange.emit((currentView = view))
@@ -125,12 +126,12 @@ const INITIAL_INSPECTED_STATE = {
125126
treeWalkerOwnerId: null,
126127
} as const satisfies Debugger.OutputChannels['InspectedState']
127128

128-
const [inspectedState, setInspectedState] = createSignal<
129+
const [inspectedState, setInspectedState] = s.createSignal<
129130
Debugger.OutputChannels['InspectedState']
130131
>(INITIAL_INSPECTED_STATE, {equals: false})
131-
const inspectedOwnerId = createMemo(() => inspectedState().ownerId)
132+
const inspectedOwnerId = s.createMemo(() => inspectedState().ownerId)
132133

133-
createEffect(() => hub.output.emit('InspectedState', inspectedState()))
134+
s.createEffect(() => hub.output.emit('InspectedState', inspectedState()))
134135

135136
function getTreeWalkerOwnerId(ownerId: NodeID | null): NodeID | null {
136137
const owner = ownerId && getObjectById(ownerId, ObjectType.Owner)
@@ -161,7 +162,7 @@ function setInspectedNode(data: Debugger.InputChannels['InspectNode']): void {
161162
})
162163
}
163164

164-
createComputed(
165+
s.createComputed(
165166
defer(debuggerEnabled, enabled => {
166167
if (!enabled) resetInspectedNode()
167168
}),
@@ -225,36 +226,39 @@ function openInspectedNodeLocation() {
225226
}
226227

227228
// send the state of the client locator mode
228-
createEffect(
229+
s.createEffect(
229230
defer(modules.locatorKeyPressSignal, state => hub.output.emit('LocatorModeChange', state)),
230231
)
231232

232233
hub.input.listen(e => {
234+
235+
DEV: {log_message('Debugger', 'Client', e)}
236+
233237
switch (e.name) {
234-
case 'ResetState': {
235-
// reset all the internal state
236-
batch(() => {
237-
resetInspectedNode()
238-
currentView = DEFAULT_MAIN_VIEW
239-
structure.resetTreeWalkerMode()
240-
locator.setDevtoolsHighlightTarget(null)
241-
})
242-
break
243-
}
244-
case 'HighlightElementChange':
245-
return locator.setDevtoolsHighlightTarget(e.details)
246-
case 'InspectNode':
247-
return setInspectedNode(e.details)
248-
case 'InspectValue':
249-
return inspector.toggleValueNode(e.details)
250-
case 'OpenLocation':
251-
return openInspectedNodeLocation()
252-
case 'TreeViewModeChange':
253-
return structure.setTreeWalkerMode(e.details)
254-
case 'ViewChange':
255-
return setView(e.details)
256-
case 'ToggleModule':
257-
return toggleModule(e.details)
238+
case 'ResetState': {
239+
// reset all the internal state
240+
s.batch(() => {
241+
resetInspectedNode()
242+
currentView = DEFAULT_MAIN_VIEW
243+
structure.resetTreeWalkerMode()
244+
locator.setDevtoolsHighlightTarget(null)
245+
})
246+
break
247+
}
248+
case 'HighlightElementChange':
249+
return locator.setDevtoolsHighlightTarget(e.details)
250+
case 'InspectNode':
251+
return setInspectedNode(e.details)
252+
case 'InspectValue':
253+
return inspector.toggleValueNode(e.details)
254+
case 'OpenLocation':
255+
return openInspectedNodeLocation()
256+
case 'TreeViewModeChange':
257+
return structure.setTreeWalkerMode(e.details)
258+
case 'ViewChange':
259+
return setView(e.details)
260+
case 'ToggleModule':
261+
return toggleModule(e.details)
258262
}
259263
})
260264

packages/extension/background/background.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ let last_disconnected_tab_data: TabData | undefined
165165
let last_disconnected_tab_id: number | undefined
166166

167167
chrome.runtime.onConnect.addListener(async port => {
168+
168169
switch (port.name) {
169170
case bridge.ConnectionName.Content: {
170171
const tab_id = port.sender?.tab?.id
@@ -241,7 +242,9 @@ chrome.runtime.onConnect.addListener(async port => {
241242
// "Versions" means the devtools client is present
242243
data.onVersions(v => devtools_messanger.postPortMessage('Versions', v))
243244

244-
port.onDisconnect.addListener(() => content_messanger.post('DevtoolsClosed'))
245+
port.onDisconnect.addListener(() => {
246+
content_messanger.post('DevtoolsClosed')
247+
})
245248

246249
break
247250
}

packages/extension/shared/bridge.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ File for utilities, constants and types related to the communication between the
44
55
*/
66

7-
import {log} from '@solid-devtools/shared/utils'
7+
import {log, log_message} from '@solid-devtools/shared/utils'
88

99
export const DEVTOOLS_ID_PREFIX = '[solid-devtools]_'
1010

@@ -75,9 +75,7 @@ export function createPortMessanger<
7575

7676
if (typeof name !== 'string') return
7777

78-
if (LOG_MESSAGES) {
79-
log(`${place_name_here} <- ${place_name_conn} - ${name}:`, details)
80-
}
78+
if (LOG_MESSAGES) {log_message(place_name_here, place_name_conn, e)}
8179

8280
let arr = listeners[name]
8381
if (arr) {
@@ -183,9 +181,7 @@ export function makeMessageListener
183181

184182
if (typeof name !== 'string') return
185183

186-
if (LOG_MESSAGES) {
187-
log(`${place_name} <- Window - ${name}:`, details)
188-
}
184+
if (LOG_MESSAGES) {log_message(place_name, 'Window', e.data)}
189185

190186
let arr = window_listeners[name]
191187
if (arr) {

packages/main/build.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ async function main() {
4141
},
4242
external: external,
4343
define: {
44+
...common.define,
4445
'process.env.CLIENT_VERSION': JSON.stringify(pkg.version),
4546
'process.env.SOLID_VERSION': JSON.stringify(solid_pkg.version),
4647
'process.env.EXPECTED_SOLID_VERSION': JSON.stringify(pkg.peerDependencies['solid-js'].match(/\d+.\d+.\d+/)![0]),

packages/shared/src/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ export function error(...args: any[]): undefined {
2626
return
2727
}
2828

29+
export function log_message(to: string, from: string, e: {name: string, details: any}) {
30+
// eslint-disable-next-line no-console
31+
console.log(...getLogLabel(), `${to.padEnd(20, ' ')} <- ${from.padEnd(14, ' ')} - ${e.name.padEnd(20, ' ')}:`, e.details)
32+
}
33+
2934
export function formatTime(d: Date = new Date()): string {
3035
return (
3136
('0' + d.getHours()).slice(-2) +

0 commit comments

Comments
 (0)