@octane-xplat/devtools 0.0.0-nightly.g1b95ef7 → 0.0.0-stage
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -4
- package/package.json +5 -87
- package/dist/app.d.ts +0 -28
- package/dist/app.js +0 -66
- package/dist/backend.d.ts +0 -31
- package/dist/backend.js +0 -182
- package/dist/client.d.ts +0 -49
- package/dist/client.js +0 -168
- package/dist/host/desktop.d.ts +0 -15
- package/dist/host/desktop.js +0 -133
- package/dist/host/panels.d.ts +0 -14
- package/dist/host/panels.js +0 -156
- package/dist/host/records.d.ts +0 -5
- package/dist/host/records.js +0 -46
- package/dist/host/server.d.ts +0 -8
- package/dist/host/server.js +0 -67
- package/dist/host/web.d.ts +0 -5
- package/dist/host/web.js +0 -74
- package/dist/macos/index.macos.d.ts +0 -3
- package/dist/macos/index.macos.js +0 -5
- package/dist/macos/servers.macos.d.ts +0 -4
- package/dist/macos/servers.macos.js +0 -57
- package/dist/macos/socket.macos.d.ts +0 -2
- package/dist/macos/socket.macos.js +0 -152
- package/dist/macos/ws-frames.d.ts +0 -24
- package/dist/macos/ws-frames.js +0 -205
- package/dist/node.d.ts +0 -12
- package/dist/node.js +0 -51
- package/dist/record.d.ts +0 -9
- package/dist/record.js +0 -38
- package/dist/types.d.ts +0 -128
- package/dist/types.js +0 -25
- package/src/app.ts +0 -105
- package/src/assets.d.ts +0 -2
- package/src/backend.ts +0 -278
- package/src/client.ts +0 -248
- package/src/desktop/Shell.macos.tsrx +0 -158
- package/src/desktop/Shell.ts +0 -16
- package/src/desktop/index.macos.ts +0 -7
- package/src/desktop/main.macos.ts +0 -130
- package/src/desktop/panels.d.ts +0 -10
- package/src/desktop/target.ts +0 -34
- package/src/host/desktop.ts +0 -176
- package/src/host/panels.ts +0 -193
- package/src/host/records.ts +0 -62
- package/src/host/server.ts +0 -92
- package/src/host/web.ts +0 -68
- package/src/macos/index.macos.ts +0 -7
- package/src/macos/servers.macos.ts +0 -83
- package/src/macos/socket.macos.ts +0 -218
- package/src/macos/ws-frames.ts +0 -249
- package/src/node.ts +0 -60
- package/src/panel/App.tsrx +0 -288
- package/src/panel/index.html +0 -12
- package/src/panel/index.ts +0 -24
- package/src/panel/main.tsrx +0 -2
- package/src/panel/main.web.tsrx +0 -89
- package/src/panel/model.ts +0 -216
- package/src/panel/panel.css +0 -189
- package/src/panel/plugin.ts +0 -65
- package/src/panel/styles.ts +0 -5
- package/src/panel/tsconfig.browser.json +0 -9
- package/src/record.ts +0 -66
- package/src/types.ts +0 -129
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
/** @jsxImportSource @octane-xplat/jsx */
|
|
2
|
-
// Desktop shell — owns discovery-record polling and the single window's
|
|
3
|
-
// waiting/picking/targeted states. `xplat devtools` passes the app it was
|
|
4
|
-
// launched from as preferredRoot; the apps/devtools harness passes null.
|
|
5
|
-
import '../panel/styles.ts'
|
|
6
|
-
import { useEffect, useRef, useState } from 'octane'
|
|
7
|
-
import { Button, Center, HStack, Pressable, ScrollableArea, Text, VStack } from '@octane-xplat/ui'
|
|
8
|
-
import { listDevtoolsServers, nwDevSocket } from '../macos/index.macos.ts'
|
|
9
|
-
import type { ListedDevtoolsServer } from '../macos/index.macos.ts'
|
|
10
|
-
import { App } from '../panel/index.ts'
|
|
11
|
-
import { autoTarget } from './target.ts'
|
|
12
|
-
import type { DevtoolsShellProps } from './Shell.ts'
|
|
13
|
-
import panelPlugins from 'virtual:octane-devtools-panels'
|
|
14
|
-
|
|
15
|
-
export type { DevtoolsShellProps } from './Shell.ts'
|
|
16
|
-
|
|
17
|
-
const POLL_MS = 2000
|
|
18
|
-
|
|
19
|
-
function basename(path: string): string {
|
|
20
|
-
const parts = path.split('/').filter(Boolean)
|
|
21
|
-
|
|
22
|
-
return parts[parts.length - 1] ?? path
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function Shell(props: DevtoolsShellProps) @{
|
|
26
|
-
const [records, setRecords] = useState<ListedDevtoolsServer[]>([])
|
|
27
|
-
const [target, setTarget] = useState<ListedDevtoolsServer | null>(null)
|
|
28
|
-
// Mirrors of rendered state for the poll/selftest closures.
|
|
29
|
-
const recordsRef = useRef<ListedDevtoolsServer[]>([])
|
|
30
|
-
const targetRef = useRef<ListedDevtoolsServer | null>(null)
|
|
31
|
-
// Auto-targeting applies only until the first target is chosen — auto or
|
|
32
|
-
// by click — or Switch is pressed; after that the user owns selection.
|
|
33
|
-
const autoPick = useRef(true)
|
|
34
|
-
const [onTop, setOnTop] = useState(false)
|
|
35
|
-
|
|
36
|
-
const choose = (record: ListedDevtoolsServer | null) => {
|
|
37
|
-
autoPick.current = false
|
|
38
|
-
targetRef.current = record
|
|
39
|
-
setTarget(record)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
useEffect(() => {
|
|
43
|
-
const scan = () => {
|
|
44
|
-
let next: ListedDevtoolsServer[]
|
|
45
|
-
|
|
46
|
-
try {
|
|
47
|
-
next = listDevtoolsServers()
|
|
48
|
-
} catch (error) {
|
|
49
|
-
console.error('[devtools] record scan failed', error)
|
|
50
|
-
return
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
recordsRef.current = next
|
|
54
|
-
setRecords(next)
|
|
55
|
-
|
|
56
|
-
const current = targetRef.current
|
|
57
|
-
|
|
58
|
-
if (current) {
|
|
59
|
-
// Same key with a new instanceId is a server restart — reconnect the
|
|
60
|
-
// panel in place; a vanished record keeps App mounted on its
|
|
61
|
-
// disconnected state rather than bouncing to the picker.
|
|
62
|
-
const again = next.find((record) => record.key === current.key)
|
|
63
|
-
|
|
64
|
-
if (again && again.instanceId !== current.instanceId) {
|
|
65
|
-
targetRef.current = again
|
|
66
|
-
setTarget(again)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (autoPick.current) {
|
|
73
|
-
const chosen = autoTarget(next, props.preferredRoot)
|
|
74
|
-
|
|
75
|
-
if (chosen) {
|
|
76
|
-
autoPick.current = false
|
|
77
|
-
targetRef.current = chosen
|
|
78
|
-
setTarget(chosen)
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
scan()
|
|
84
|
-
|
|
85
|
-
const timer = setInterval(scan, POLL_MS)
|
|
86
|
-
|
|
87
|
-
return () => clearInterval(timer)
|
|
88
|
-
}, [])
|
|
89
|
-
|
|
90
|
-
useEffect(() => {
|
|
91
|
-
props.onTitle?.(target ? `devtools — ${basename(target.appRoot)}` : 'devtools')
|
|
92
|
-
}, [target])
|
|
93
|
-
|
|
94
|
-
useEffect(() => {
|
|
95
|
-
if (props.selftest) {
|
|
96
|
-
props.selftest.pick = (index: number) => {
|
|
97
|
-
const record = recordsRef.current[index]
|
|
98
|
-
|
|
99
|
-
if (record) {
|
|
100
|
-
choose(record)
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}, [])
|
|
105
|
-
|
|
106
|
-
<VStack className="dt-root">
|
|
107
|
-
@if (target !== null) {
|
|
108
|
-
const focused = target
|
|
109
|
-
|
|
110
|
-
<>
|
|
111
|
-
<HStack className="dt-target-bar">
|
|
112
|
-
<Text className="dt-target-name">{basename(focused.appRoot)}</Text>
|
|
113
|
-
<HStack className="dt-right">
|
|
114
|
-
@if (props.onKeepOnTop) {
|
|
115
|
-
<Button
|
|
116
|
-
label={onTop ? 'Unpin' : 'Keep on top'}
|
|
117
|
-
onPress={() => {
|
|
118
|
-
const next = !onTop
|
|
119
|
-
|
|
120
|
-
setOnTop(next)
|
|
121
|
-
props.onKeepOnTop?.(next)
|
|
122
|
-
}}
|
|
123
|
-
/>
|
|
124
|
-
}
|
|
125
|
-
<Button label="Switch…" onPress={() => choose(null)} />
|
|
126
|
-
</HStack>
|
|
127
|
-
</HStack>
|
|
128
|
-
<VStack className="dt-targeted">
|
|
129
|
-
<App
|
|
130
|
-
key={`${focused.key}:${focused.instanceId}`}
|
|
131
|
-
record={focused}
|
|
132
|
-
socket={nwDevSocket}
|
|
133
|
-
plugins={panelPlugins}
|
|
134
|
-
initialTab={props.initialTab}
|
|
135
|
-
/>
|
|
136
|
-
</VStack>
|
|
137
|
-
</>
|
|
138
|
-
} @else if (records.length === 0) {
|
|
139
|
-
<Center style={{ flex: 1 }}>
|
|
140
|
-
<Text className="dt-empty">No xplat dev servers running</Text>
|
|
141
|
-
</Center>
|
|
142
|
-
} @else {
|
|
143
|
-
<ScrollableArea className="dt-main">
|
|
144
|
-
<VStack className="dt-content">
|
|
145
|
-
<Text className={['dt-heading', 'dt-heading-first']}>Select a dev server</Text>
|
|
146
|
-
@for (const record of records; key `${record.key}:${record.instanceId}`) {
|
|
147
|
-
<Pressable className="dt-pick-row" onPress={() => choose(record)}>
|
|
148
|
-
<VStack>
|
|
149
|
-
<Text className="dt-pick-name">{basename(record.appRoot)}</Text>
|
|
150
|
-
<Text className="dt-pick-path">{record.appRoot}</Text>
|
|
151
|
-
</VStack>
|
|
152
|
-
</Pressable>
|
|
153
|
-
}
|
|
154
|
-
</VStack>
|
|
155
|
-
</ScrollableArea>
|
|
156
|
-
}
|
|
157
|
-
</VStack>
|
|
158
|
-
}
|
package/src/desktop/Shell.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// Type contract for the desktop devtools shell — the AppKit implementation
|
|
2
|
-
// lives in Shell.macos.tsrx.
|
|
3
|
-
export interface DevtoolsShellProps {
|
|
4
|
-
/** The selected project root `xplat devtools` ran from; null in the harness. */
|
|
5
|
-
preferredRoot: string | null
|
|
6
|
-
/** Tab to show on mount (DEVTOOLS_SELFTEST_TAB). */
|
|
7
|
-
initialTab?: string
|
|
8
|
-
/** Toggle the main window's level (keep-on-top); absent → no toggle shown. */
|
|
9
|
-
onKeepOnTop?: (onTop: boolean) => void
|
|
10
|
-
/** Main-window title updates: `devtools` until a server is targeted. */
|
|
11
|
-
onTitle?: (title: string) => void
|
|
12
|
-
/** Dev-only selftest hook — receives the row-pick function on mount. */
|
|
13
|
-
selftest?: { pick?: (index: number) => void }
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export declare function Shell(props: DevtoolsShellProps): unknown
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
// Devtools desktop app entry — `@octane-xplat/devtools/desktop`. Imported for
|
|
2
|
-
// its side effects: NSApplication startup and a single window whose Shell
|
|
3
|
-
// polls discovery records and picks (or asks for) the dev server to target.
|
|
4
|
-
// Built by apps/devtools (monorepo harness) and by the generated Vite config
|
|
5
|
-
// behind `xplat devtools`.
|
|
6
|
-
|
|
7
|
-
import './main.macos.ts'
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
// Octane Xplat devtools desktop: the shared devtools panel from
|
|
2
|
-
// @octane-xplat/devtools/panel over the Network.framework socket from
|
|
3
|
-
// @octane-xplat/devtools/macos, in a single AppKit window. The Shell asks
|
|
4
|
-
// which live `xplat dev` server record to target when several exist, and
|
|
5
|
-
// auto-targets the app selected at launch when that record resolves.
|
|
6
|
-
// runMacOSApp owns NSApplication startup and the event loop.
|
|
7
|
-
import '@nativescript/macos-node-api'
|
|
8
|
-
import { runMacOSApp } from '@octane-xplat/macos-appkit/host'
|
|
9
|
-
import type { NSView } from '@octane-xplat/platform/macos'
|
|
10
|
-
import { writeFileSync } from 'node:fs'
|
|
11
|
-
import { Shell } from './Shell.macos.tsrx'
|
|
12
|
-
|
|
13
|
-
// The project-built variant sets a Vite define for direct development launches.
|
|
14
|
-
declare const __XPLAT_DEVTOOLS_PREFERRED_ROOT__: string
|
|
15
|
-
|
|
16
|
-
const PREFERRED_ROOT =
|
|
17
|
-
typeof __XPLAT_DEVTOOLS_PREFERRED_ROOT__ === 'string'
|
|
18
|
-
? __XPLAT_DEVTOOLS_PREFERRED_ROOT__
|
|
19
|
-
: (process.env.XPLAT_DEVTOOLS_PREFERRED_ROOT ?? null)
|
|
20
|
-
|
|
21
|
-
const SELFTEST = process.env.DEVTOOLS_SELFTEST === '1'
|
|
22
|
-
const VIEWDUMP = process.env.DEVTOOLS_VIEWDUMP ?? '/tmp/devtools-desktop-viewtree.json'
|
|
23
|
-
const SELFTEST_PICK = Number.parseInt(process.env.DEVTOOLS_SELFTEST_PICK ?? '', 10)
|
|
24
|
-
const SELFTEST_TAB = process.env.DEVTOOLS_SELFTEST_TAB
|
|
25
|
-
|
|
26
|
-
const selftest: { pick?: (index: number) => void } = {}
|
|
27
|
-
|
|
28
|
-
runMacOSApp(
|
|
29
|
-
{
|
|
30
|
-
title: 'devtools',
|
|
31
|
-
size: { width: 420, height: 720 },
|
|
32
|
-
terminateAfterLastWindowClosed: true,
|
|
33
|
-
},
|
|
34
|
-
({ window, root }) => {
|
|
35
|
-
window.contentMinSize = { width: 380, height: 360 }
|
|
36
|
-
root.render(Shell as never, {
|
|
37
|
-
preferredRoot: PREFERRED_ROOT,
|
|
38
|
-
initialTab: SELFTEST_TAB,
|
|
39
|
-
onKeepOnTop: (onTop: boolean) => {
|
|
40
|
-
// NSFloatingWindowLevel (3) above NSNormalWindowLevel (0).
|
|
41
|
-
const level = onTop ? 3 : 0
|
|
42
|
-
const host = window as unknown as {
|
|
43
|
-
setLevel?: (level: number) => void
|
|
44
|
-
level?: number
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (typeof host.setLevel === 'function') {
|
|
48
|
-
host.setLevel(level)
|
|
49
|
-
} else {
|
|
50
|
-
host.level = level
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
onTitle: (title: string) => {
|
|
54
|
-
window.title = title
|
|
55
|
-
},
|
|
56
|
-
selftest,
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
if (!SELFTEST) {
|
|
60
|
-
return
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function viewTree(v: NSView): Record<string, unknown> {
|
|
64
|
-
const f = v.frame ?? { origin: { x: 0, y: 0 }, size: { width: 0, height: 0 } }
|
|
65
|
-
const node: Record<string, unknown> = {
|
|
66
|
-
class: String(v.className ?? 'NSView'),
|
|
67
|
-
x: f.origin?.x ?? 0,
|
|
68
|
-
y: f.origin?.y ?? 0,
|
|
69
|
-
w: f.size?.width ?? 0,
|
|
70
|
-
h: f.size?.height ?? 0,
|
|
71
|
-
hidden: Boolean(v.isHidden?.() ?? v.hidden ?? false),
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
for (const prop of ['stringValue', 'title', 'label', 'string', 'placeholderString']) {
|
|
75
|
-
try {
|
|
76
|
-
const raw = (v as never as Record<string, unknown>)[prop]
|
|
77
|
-
const t = typeof raw === 'function' ? raw.call(v) : raw
|
|
78
|
-
|
|
79
|
-
if (typeof t === 'string' && t.length) {
|
|
80
|
-
node.text = t
|
|
81
|
-
} else if (t && typeof t === 'object') {
|
|
82
|
-
node.text = String(t)
|
|
83
|
-
}
|
|
84
|
-
} catch {}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const subs = v.subviews
|
|
88
|
-
|
|
89
|
-
if (subs && typeof subs.count === 'number' && subs.count > 0) {
|
|
90
|
-
node.children = []
|
|
91
|
-
for (let i = 0; i < subs.count; i++) {
|
|
92
|
-
try {
|
|
93
|
-
;(node.children as unknown[]).push(viewTree(subs.objectAtIndex(i) as NSView))
|
|
94
|
-
} catch {}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return node
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Dev-only self-test: dump the main window's NSView tree
|
|
102
|
-
// (class/frame/hidden/text) as JSON so picker/panel content can be
|
|
103
|
-
// asserted without screenshots. Gated by DEVTOOLS_SELFTEST=1.
|
|
104
|
-
// DEVTOOLS_SELFTEST_PICK=<index> additionally picks that picker row after
|
|
105
|
-
// the first dump and writes a second dump to `${VIEWDUMP}.picked.json` —
|
|
106
|
-
// this proves the state transition, not OS hit-testing.
|
|
107
|
-
function dumpViews(path: string) {
|
|
108
|
-
try {
|
|
109
|
-
const json = JSON.stringify({
|
|
110
|
-
windows: [{ title: String(window.title ?? ''), tree: viewTree(window.contentView) }],
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
writeFileSync(path, json)
|
|
114
|
-
console.log(`[selftest] viewtree written ${path} bytes=${json.length}`)
|
|
115
|
-
} catch (error) {
|
|
116
|
-
console.error('[selftest] viewtree dump failed', error)
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// Give the picker a moment to list records / the panel socket to connect,
|
|
121
|
-
// then dump; a pick index renders its transition in the second dump.
|
|
122
|
-
setTimeout(() => {
|
|
123
|
-
dumpViews(VIEWDUMP)
|
|
124
|
-
if (Number.isInteger(SELFTEST_PICK)) {
|
|
125
|
-
selftest.pick?.(SELFTEST_PICK)
|
|
126
|
-
setTimeout(() => dumpViews(`${VIEWDUMP}.picked.json`), 4000)
|
|
127
|
-
}
|
|
128
|
-
}, 4000)
|
|
129
|
-
},
|
|
130
|
-
)
|
package/src/desktop/panels.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
// Ambient types for the virtual module served by `devtoolsPanels`
|
|
2
|
-
// (src/host/panels.ts) — wired into the generated `xplat devtools` config and
|
|
3
|
-
// the apps/devtools harness config.
|
|
4
|
-
declare module 'virtual:octane-devtools-panels' {
|
|
5
|
-
import type { DevtoolsPanelPlugin } from '../panel/index.ts'
|
|
6
|
-
|
|
7
|
-
const plugins: readonly DevtoolsPanelPlugin[]
|
|
8
|
-
|
|
9
|
-
export default plugins
|
|
10
|
-
}
|
package/src/desktop/target.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// Pure dev-server targeting rule for the desktop shell — deliberately
|
|
2
|
-
// non-suffixed so Node tests import it and no `.macos.ts` sibling shadows it.
|
|
3
|
-
import type { ListedDevtoolsServer } from '../record.ts'
|
|
4
|
-
|
|
5
|
-
function normalizeRoot(path: string): string {
|
|
6
|
-
let end = path.length
|
|
7
|
-
|
|
8
|
-
while (end > 1 && path[end - 1] === '/') {
|
|
9
|
-
end--
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return path.slice(0, end)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// Order: an explicit preferred root (the app `xplat devtools` ran from) wins;
|
|
16
|
-
// a sole record auto-targets; otherwise the picker decides. Both sides are
|
|
17
|
-
// canonical real paths — Go writes appRoot through osfs.Canonical and the
|
|
18
|
-
// launcher realpaths the selected project — so trailing-slash
|
|
19
|
-
// normalization is defensive only.
|
|
20
|
-
export function autoTarget(
|
|
21
|
-
records: ListedDevtoolsServer[],
|
|
22
|
-
preferredRoot: string | null,
|
|
23
|
-
): ListedDevtoolsServer | null {
|
|
24
|
-
if (preferredRoot) {
|
|
25
|
-
const root = normalizeRoot(preferredRoot)
|
|
26
|
-
const match = records.find((record) => normalizeRoot(record.appRoot) === root)
|
|
27
|
-
|
|
28
|
-
if (match) {
|
|
29
|
-
return match
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return records.length === 1 ? records[0] : null
|
|
34
|
-
}
|
package/src/host/desktop.ts
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
// `xplat devtools` launcher: resolves the selected project's macOS dev engine,
|
|
2
|
-
// generates a disposable Vite config whose entry is this package's desktop app
|
|
3
|
-
// (src/desktop/main.macos.ts), and runs it through runMacOSDev. The service
|
|
4
|
-
// worker (packages/cli devtools-desktop op) calls this from the app's own
|
|
5
|
-
// Node process; Go owns argv/cwd/env and the process group.
|
|
6
|
-
|
|
7
|
-
import { createRequire } from 'node:module'
|
|
8
|
-
import { lstatSync, realpathSync, statSync } from 'node:fs'
|
|
9
|
-
import { mkdtemp, rm, writeFile } from 'node:fs/promises'
|
|
10
|
-
import { tmpdir } from 'node:os'
|
|
11
|
-
import { dirname, join, relative, sep } from 'node:path'
|
|
12
|
-
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
13
|
-
|
|
14
|
-
export const DEVTOOLS_DESKTOP_LIFECYCLE_VERSION = 1
|
|
15
|
-
|
|
16
|
-
export { discoverDevtoolsPanels, devtoolsPanels } from './panels.ts'
|
|
17
|
-
export type { DiscoveredDevtoolsPanel } from './panels.ts'
|
|
18
|
-
|
|
19
|
-
interface MacOSDevEngine {
|
|
20
|
-
runMacOSDev(
|
|
21
|
-
appRoot: string,
|
|
22
|
-
options: {
|
|
23
|
-
target?: Record<string, unknown>
|
|
24
|
-
workshop?: boolean
|
|
25
|
-
resourceRoot?: string
|
|
26
|
-
onReady?: (metadata: {
|
|
27
|
-
pid: number
|
|
28
|
-
renderer: string
|
|
29
|
-
executable: string
|
|
30
|
-
observedAt?: string
|
|
31
|
-
url?: string
|
|
32
|
-
}) => void
|
|
33
|
-
},
|
|
34
|
-
): Promise<void>
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Resolve the selected project's explicit engine, never a global fallback.
|
|
38
|
-
async function loadMacOSDevEngine(project: string): Promise<MacOSDevEngine> {
|
|
39
|
-
const require = createRequire(join(project, 'package.json'))
|
|
40
|
-
|
|
41
|
-
for (let at = project; ; at = dirname(at)) {
|
|
42
|
-
const candidate = join(at, 'node_modules/@octane-xplat/macos-build')
|
|
43
|
-
let found = false
|
|
44
|
-
|
|
45
|
-
try {
|
|
46
|
-
lstatSync(candidate)
|
|
47
|
-
found = true
|
|
48
|
-
} catch (error) {
|
|
49
|
-
if (!(error instanceof Error) || !('code' in error) || error.code !== 'ENOENT') {
|
|
50
|
-
throw error
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (found) {
|
|
55
|
-
const root = realpathSync(candidate)
|
|
56
|
-
let entry: string
|
|
57
|
-
|
|
58
|
-
try {
|
|
59
|
-
entry = realpathSync(require.resolve('@octane-xplat/macos-build/dev-engine'))
|
|
60
|
-
} catch (error) {
|
|
61
|
-
throw new Error(
|
|
62
|
-
`Update or reinstall @octane-xplat/macos-build in the selected project: development engine export unavailable; ${String(error)}`,
|
|
63
|
-
{ cause: error },
|
|
64
|
-
)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (!entry.startsWith(root + sep) || !statSync(entry).isFile()) {
|
|
68
|
-
throw new Error(
|
|
69
|
-
'Reinstall @octane-xplat/macos-build: its development engine must stay inside the selected package',
|
|
70
|
-
)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const api = (await import(pathToFileURL(entry).href)) as MacOSDevEngine
|
|
74
|
-
|
|
75
|
-
if (typeof api.runMacOSDev !== 'function') {
|
|
76
|
-
throw new Error(
|
|
77
|
-
'Update @octane-xplat/macos-build in the selected project: development engine API is missing',
|
|
78
|
-
)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return api
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (dirname(at) === at) {
|
|
85
|
-
break
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
throw new Error(
|
|
90
|
-
'Install the macOS project engine before launching devtools: bun add -D @octane-xplat/macos-build',
|
|
91
|
-
)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export interface DevtoolsDesktopOptions {
|
|
95
|
-
cwd?: string
|
|
96
|
-
resourceRoot?: string
|
|
97
|
-
profileRoot?: string
|
|
98
|
-
onStarted?: (evidence: { kind: string; pid?: number; url?: string }) => void
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/** Generate a separate consumer-owned cache profile; leave app entries untouched. */
|
|
102
|
-
export async function devtoolsDesktop({
|
|
103
|
-
cwd,
|
|
104
|
-
resourceRoot,
|
|
105
|
-
profileRoot,
|
|
106
|
-
onStarted,
|
|
107
|
-
}: DevtoolsDesktopOptions = {}): Promise<void> {
|
|
108
|
-
if (process.platform !== 'darwin' || (process.arch !== 'arm64' && process.arch !== 'x64')) {
|
|
109
|
-
throw new Error('The native devtools app requires a macOS arm64 or x86_64 execution host')
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const root = realpathSync(cwd ?? process.cwd())
|
|
113
|
-
const { runMacOSDev } = await loadMacOSDevEngine(root)
|
|
114
|
-
const require = createRequire(join(root, 'package.json'))
|
|
115
|
-
|
|
116
|
-
for (const name of [
|
|
117
|
-
'@octane-xplat/macos-appkit',
|
|
118
|
-
'@nativescript/macos-node-api',
|
|
119
|
-
'octane',
|
|
120
|
-
'@octanejs/vite-plugin',
|
|
121
|
-
'vite',
|
|
122
|
-
]) {
|
|
123
|
-
try {
|
|
124
|
-
require.resolve(name)
|
|
125
|
-
} catch {
|
|
126
|
-
throw new Error(`Devtools desktop prerequisite missing: bun add -D ${name}`)
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// Generated config/bundle live only in an owned per-run directory: the
|
|
131
|
-
// service worker's unique compiler profile, or OS temp for direct calls.
|
|
132
|
-
// Nothing may land in project output dirs — `xplat dev` holds that lock.
|
|
133
|
-
const directory = profileRoot
|
|
134
|
-
? await mkdtemp(join(profileRoot, 'session-'))
|
|
135
|
-
: await mkdtemp(join(tmpdir(), 'octane-devtools-desktop-'))
|
|
136
|
-
|
|
137
|
-
// This module runs from src/ in the monorepo and dist/host/ in an install —
|
|
138
|
-
// the desktop entry is shipped as source, so resolve through src/ either way.
|
|
139
|
-
const source = dirname(fileURLToPath(import.meta.url)).replace('/dist/', '/src/')
|
|
140
|
-
const entry = join(source, '../desktop/main.macos.ts')
|
|
141
|
-
const bundle = join(directory, 'devtools.cjs')
|
|
142
|
-
|
|
143
|
-
await writeFile(
|
|
144
|
-
join(directory, 'devtools.config.ts'),
|
|
145
|
-
`import { macos } from '@octane-xplat/cli/macos/vite'
|
|
146
|
-
import { devtoolsPanels } from '@octane-xplat/devtools/desktop-node'
|
|
147
|
-
const root = ${JSON.stringify(root)}
|
|
148
|
-
const entry = ${JSON.stringify(entry)}
|
|
149
|
-
|
|
150
|
-
export default async ({ mode }) => {
|
|
151
|
-
const settings = await macos(mode, { root, hmr: false, entry })
|
|
152
|
-
return { ...settings, plugins: [...(settings.plugins ?? []), devtoolsPanels({ root })], build: { ...settings.build, outDir: ${JSON.stringify(directory)}, emptyOutDir: false,
|
|
153
|
-
lib: { entry, formats: ['cjs'], fileName: () => 'devtools.cjs' } },
|
|
154
|
-
define: { ...(settings.define ?? {}), __XPLAT_DEVTOOLS_PREFERRED_ROOT__: ${JSON.stringify(JSON.stringify(root))} } }
|
|
155
|
-
}
|
|
156
|
-
`,
|
|
157
|
-
)
|
|
158
|
-
|
|
159
|
-
try {
|
|
160
|
-
await runMacOSDev(root, {
|
|
161
|
-
resourceRoot,
|
|
162
|
-
onReady: (meta) => onStarted?.({ kind: 'native-host-spawned', pid: meta.pid }),
|
|
163
|
-
target: {
|
|
164
|
-
runtime: 'appkit-node-api',
|
|
165
|
-
renderer: 'appkit',
|
|
166
|
-
dev: {
|
|
167
|
-
productName: 'Octane Xplat devtools',
|
|
168
|
-
viteConfig: relative(root, join(directory, 'devtools.config.ts')),
|
|
169
|
-
bundleFile: relative(root, bundle),
|
|
170
|
-
},
|
|
171
|
-
},
|
|
172
|
-
})
|
|
173
|
-
} finally {
|
|
174
|
-
await rm(directory, { recursive: true, force: true })
|
|
175
|
-
}
|
|
176
|
-
}
|