@octane-xplat/devtools 0.0.0-nightly.g1b95ef7 → 0.0.1

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.
Files changed (64) hide show
  1. package/README.md +1 -3
  2. package/package.json +9 -86
  3. package/dist/app.d.ts +0 -28
  4. package/dist/app.js +0 -66
  5. package/dist/backend.d.ts +0 -31
  6. package/dist/backend.js +0 -182
  7. package/dist/client.d.ts +0 -49
  8. package/dist/client.js +0 -168
  9. package/dist/host/desktop.d.ts +0 -15
  10. package/dist/host/desktop.js +0 -133
  11. package/dist/host/panels.d.ts +0 -14
  12. package/dist/host/panels.js +0 -156
  13. package/dist/host/records.d.ts +0 -5
  14. package/dist/host/records.js +0 -46
  15. package/dist/host/server.d.ts +0 -8
  16. package/dist/host/server.js +0 -67
  17. package/dist/host/web.d.ts +0 -5
  18. package/dist/host/web.js +0 -74
  19. package/dist/macos/index.macos.d.ts +0 -3
  20. package/dist/macos/index.macos.js +0 -5
  21. package/dist/macos/servers.macos.d.ts +0 -4
  22. package/dist/macos/servers.macos.js +0 -57
  23. package/dist/macos/socket.macos.d.ts +0 -2
  24. package/dist/macos/socket.macos.js +0 -152
  25. package/dist/macos/ws-frames.d.ts +0 -24
  26. package/dist/macos/ws-frames.js +0 -205
  27. package/dist/node.d.ts +0 -12
  28. package/dist/node.js +0 -51
  29. package/dist/record.d.ts +0 -9
  30. package/dist/record.js +0 -38
  31. package/dist/types.d.ts +0 -128
  32. package/dist/types.js +0 -25
  33. package/src/app.ts +0 -105
  34. package/src/assets.d.ts +0 -2
  35. package/src/backend.ts +0 -278
  36. package/src/client.ts +0 -248
  37. package/src/desktop/Shell.macos.tsrx +0 -158
  38. package/src/desktop/Shell.ts +0 -16
  39. package/src/desktop/index.macos.ts +0 -7
  40. package/src/desktop/main.macos.ts +0 -130
  41. package/src/desktop/panels.d.ts +0 -10
  42. package/src/desktop/target.ts +0 -34
  43. package/src/host/desktop.ts +0 -176
  44. package/src/host/panels.ts +0 -193
  45. package/src/host/records.ts +0 -62
  46. package/src/host/server.ts +0 -92
  47. package/src/host/web.ts +0 -68
  48. package/src/macos/index.macos.ts +0 -7
  49. package/src/macos/servers.macos.ts +0 -83
  50. package/src/macos/socket.macos.ts +0 -218
  51. package/src/macos/ws-frames.ts +0 -249
  52. package/src/node.ts +0 -60
  53. package/src/panel/App.tsrx +0 -288
  54. package/src/panel/index.html +0 -12
  55. package/src/panel/index.ts +0 -24
  56. package/src/panel/main.tsrx +0 -2
  57. package/src/panel/main.web.tsrx +0 -89
  58. package/src/panel/model.ts +0 -216
  59. package/src/panel/panel.css +0 -189
  60. package/src/panel/plugin.ts +0 -65
  61. package/src/panel/styles.ts +0 -5
  62. package/src/panel/tsconfig.browser.json +0 -9
  63. package/src/record.ts +0 -66
  64. package/src/types.ts +0 -129
@@ -1,193 +0,0 @@
1
- // Panel-plugin discovery for the project DevTools bundles: a package opts in
2
- // with `"octaneXplat": { "devtoolsPanel": "./devtools" }` in its package.json
3
- // (a subpath or an array of subpaths; each module must
4
- // default-export a DevtoolsPanelPlugin). `devtoolsPanels` serves the
5
- // discovered modules as `virtual:octane-devtools-panels` to the web and desktop
6
- // shells.
7
- //
8
- // Scan scope is one level: the selected project's dependencies +
9
- // devDependencies, plus octane-xplat's own dependencies when the umbrella is
10
- // installed (resolved from the umbrella's location, so Bun's isolated install
11
- // layout keeps transitive panel packages reachable). Candidates are resolved
12
- // through createRequire from the declaring package and must realpath inside
13
- // the plugin package's root — nothing outside a package's own files may be
14
- // bundled. Malformed or unresolvable candidates are skipped with one stderr
15
- // warning each; a package without the field is simply not a candidate.
16
-
17
- import { createRequire } from 'node:module'
18
- import { lstatSync, readFileSync, realpathSync, statSync } from 'node:fs'
19
- import { dirname, join, sep } from 'node:path'
20
- import type { Plugin } from 'vite'
21
-
22
- export interface DiscoveredDevtoolsPanel {
23
- /** The declaring package name. */
24
- name: string
25
- /** Realpath'd entry file the virtual module default-imports. */
26
- file: string
27
- }
28
-
29
- const FIELD = 'devtoolsPanel'
30
-
31
- function readManifest(file: string): Record<string, unknown> | null {
32
- try {
33
- return JSON.parse(readFileSync(file, 'utf8')) as Record<string, unknown>
34
- } catch {
35
- return null
36
- }
37
- }
38
-
39
- /** Locate a dependency's package.json: its exports map first, then a physical
40
- * node_modules walk for packages that do not export ./package.json. */
41
- function locatePackage(name: string, requireFrom: NodeRequire, fromDir: string): string | null {
42
- try {
43
- return requireFrom.resolve(`${name}/package.json`)
44
- } catch {
45
- // Fall through to the physical walk — a package without ./package.json in
46
- // its exports map still carries the file on disk.
47
- }
48
-
49
- for (let at = fromDir; ; at = dirname(at)) {
50
- const candidate = join(at, 'node_modules', name, 'package.json')
51
-
52
- try {
53
- if (lstatSync(candidate).isFile()) {
54
- return candidate
55
- }
56
- } catch {
57
- // keep walking
58
- }
59
-
60
- if (dirname(at) === at) {
61
- return null
62
- }
63
- }
64
- }
65
-
66
- function warn(message: string) {
67
- console.error(`[devtools] ${message}`)
68
- }
69
-
70
- export function discoverDevtoolsPanels(projectRoot: string): DiscoveredDevtoolsPanel[] {
71
- const projectManifest = readManifest(join(projectRoot, 'package.json')) ?? {}
72
- const names = new Set<string>([
73
- ...Object.keys((projectManifest.dependencies as Record<string, string>) ?? {}),
74
- ...Object.keys((projectManifest.devDependencies as Record<string, string>) ?? {}),
75
- ])
76
-
77
- // Scan sources in stable order: project deps (alphabetical), then the
78
- // umbrella's dependencies (alphabetical, deduped against project names).
79
- const sources: { dir: string; names: string[] }[] = [
80
- { dir: projectRoot, names: [...names].sort() },
81
- ]
82
-
83
- if (names.has('octane-xplat')) {
84
- try {
85
- const requireFrom = createRequire(join(projectRoot, 'package.json'))
86
- const umbrellaDir = dirname(requireFrom.resolve('octane-xplat/package.json'))
87
- const umbrella = readManifest(join(umbrellaDir, 'package.json')) ?? {}
88
- const extra = Object.keys((umbrella.dependencies as Record<string, string>) ?? {})
89
- .filter((name) => !names.has(name))
90
- .sort()
91
-
92
- if (extra.length) {
93
- sources.push({ dir: umbrellaDir, names: extra })
94
- }
95
- } catch (error) {
96
- warn(`skipping octane-xplat dependency scan — ${String(error)}`)
97
- }
98
- }
99
-
100
- const out: DiscoveredDevtoolsPanel[] = []
101
-
102
- for (const source of sources) {
103
- const requireFrom = createRequire(join(source.dir, 'package.json'))
104
-
105
- for (const name of source.names) {
106
- const manifestPath = locatePackage(name, requireFrom, source.dir)
107
-
108
- if (!manifestPath) {
109
- continue
110
- }
111
-
112
- let packageRoot: string
113
- let manifest: Record<string, unknown> | null
114
-
115
- try {
116
- packageRoot = realpathSync(dirname(manifestPath))
117
- manifest = readManifest(join(packageRoot, 'package.json'))
118
- } catch {
119
- continue
120
- }
121
-
122
- const field = (manifest?.octaneXplat as Record<string, unknown> | undefined)?.[FIELD]
123
-
124
- if (field === undefined) {
125
- continue
126
- }
127
-
128
- const fail = (why: string) => warn(`skipping devtools panel candidate "${name}" — ${why}`)
129
-
130
- const subpaths: unknown[] = Array.isArray(field) ? field : [field]
131
-
132
- for (const subpath of subpaths) {
133
- if (typeof subpath !== 'string' || !subpath.startsWith('./') || subpath.includes('..')) {
134
- fail(
135
- `octaneXplat.${FIELD} must be an export subpath like "./devtools" or an array of subpaths`,
136
- )
137
-
138
- continue
139
- }
140
-
141
- let file: string
142
-
143
- try {
144
- file = realpathSync(requireFrom.resolve(`${name}/${subpath.slice(2)}`))
145
- } catch (error) {
146
- fail(`cannot resolve ${name}/${subpath.slice(2)} — ${String(error)}`)
147
- continue
148
- }
149
-
150
- try {
151
- if (!file.startsWith(packageRoot + sep) || !statSync(file).isFile()) {
152
- fail(`resolved panel module escapes its package root — ${file}`)
153
- continue
154
- }
155
- } catch {
156
- fail(`resolved panel module is not a file — ${file}`)
157
- continue
158
- }
159
-
160
- out.push({ name, file })
161
- }
162
- }
163
- }
164
-
165
- return out
166
- }
167
-
168
- export const DEVTOOLS_PANELS_VIRTUAL_ID = 'virtual:octane-devtools-panels'
169
-
170
- const RESOLVED_ID = '\0' + DEVTOOLS_PANELS_VIRTUAL_ID
171
-
172
- /** Vite plugin serving `virtual:octane-devtools-panels`: a default-exported
173
- * array of the discovered panel plugins (`[]` when none). */
174
- export function devtoolsPanels(options: { root: string }): Plugin {
175
- return {
176
- name: 'octane-devtools-panels',
177
- resolveId(id) {
178
- return id === DEVTOOLS_PANELS_VIRTUAL_ID ? RESOLVED_ID : null
179
- },
180
- load(id) {
181
- if (id !== RESOLVED_ID) {
182
- return null
183
- }
184
-
185
- const panels = discoverDevtoolsPanels(options.root)
186
- const imports = panels
187
- .map((panel, i) => `import p${i} from ${JSON.stringify(panel.file)}`)
188
- .join('\n')
189
-
190
- return `${imports}\nexport default [${panels.map((_, i) => `p${i}`).join(', ')}]`
191
- },
192
- }
193
- }
@@ -1,62 +0,0 @@
1
- // Enumerates live `xplat dev` server discovery records for the panel picker.
2
- // Mirrors dev_server_record.go: records live under the native history cache in
3
- // dev-servers-v1/<app-key>/server.json, one per app, each carrying the panel's
4
- // devtoolsToken. The RPC token is never returned to the panel.
5
-
6
- import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
7
- import { homedir, platform } from 'node:os'
8
- import { isAbsolute, join } from 'node:path'
9
- import { parseDevtoolsServerRecord, type ListedDevtoolsServer } from '../record.ts'
10
-
11
- export type { ListedDevtoolsServer } from '../record.ts'
12
-
13
- function cacheRoot(): string {
14
- if (platform() === 'darwin') {
15
- return join(homedir(), 'Library', 'Caches')
16
- }
17
-
18
- if (process.platform === 'win32') {
19
- return process.env.LOCALAPPDATA ?? join(homedir(), 'AppData', 'Local')
20
- }
21
-
22
- return process.env.XDG_CACHE_HOME ?? join(homedir(), '.cache')
23
- }
24
-
25
- export function devServerRecordsDir(): string {
26
- return (
27
- process.env.XPLAT_DEV_RECORDS_DIR ??
28
- join(cacheRoot(), 'octane-xplat', 'cli-go', 'dev-servers-v1')
29
- )
30
- }
31
-
32
- /** Returns every structurally valid live record, newest first. */
33
- export function listDevtoolsServers(): ListedDevtoolsServer[] {
34
- const root = devServerRecordsDir()
35
- const found: { server: ListedDevtoolsServer; written: number }[] = []
36
-
37
- if (!existsSync(root)) {
38
- return []
39
- }
40
-
41
- for (const key of readdirSync(root)) {
42
- const file = join(root, key, 'server.json')
43
-
44
- try {
45
- const info = statSync(file)
46
-
47
- if (!info.isFile()) {
48
- continue
49
- }
50
-
51
- const server = parseDevtoolsServerRecord(key, readFileSync(file, 'utf8'), isAbsolute)
52
-
53
- if (server) {
54
- found.push({ server, written: info.mtimeMs })
55
- }
56
- } catch {
57
- continue
58
- }
59
- }
60
-
61
- return found.sort((a, b) => b.written - a.written).map(({ server }) => server)
62
- }
@@ -1,92 +0,0 @@
1
- // Loopback HTTP host for the devtools panel: serves the built panel bundle
2
- // (dist/panel) and the live dev-server records the picker lists. Loopback only
3
- // and no CORS headers — records carry the panel credential, so the API stays
4
- // unreadable to other origins while remaining trivially usable by the served
5
- // page.
6
-
7
- import { createServer, type Server } from 'node:http'
8
- import { readFileSync, realpathSync } from 'node:fs'
9
- import { dirname, extname, join, normalize, sep } from 'node:path'
10
- import { fileURLToPath } from 'node:url'
11
- import { listDevtoolsServers } from './records.ts'
12
-
13
- const TYPES: Record<string, string> = {
14
- '.html': 'text/html; charset=utf-8',
15
- '.js': 'text/javascript; charset=utf-8',
16
- '.css': 'text/css; charset=utf-8',
17
- '.json': 'application/json; charset=utf-8',
18
- '.svg': 'image/svg+xml',
19
- '.png': 'image/png',
20
- '.woff2': 'font/woff2',
21
- }
22
-
23
- export interface DevtoolsHost {
24
- /** http://127.0.0.1:<port> the panel is served on. */
25
- endpoint: string
26
- close(): Promise<void>
27
- }
28
-
29
- function packageRoot(): string {
30
- // host/ sits under src/ (source runs) or dist/ (published runs).
31
- return dirname(dirname(dirname(fileURLToPath(import.meta.url))))
32
- }
33
-
34
- export async function serveDevtools({ port = 0 }: { port?: number } = {}): Promise<DevtoolsHost> {
35
- const root = realpathSync(packageRoot())
36
- const panel = join(root, 'dist', 'panel')
37
-
38
- const server: Server = createServer((req, res) => {
39
- const send = (
40
- status: number,
41
- body: string | Buffer,
42
- type = 'application/json; charset=utf-8',
43
- ) => {
44
- res.writeHead(status, { 'content-type': type, 'cache-control': 'no-store' })
45
- res.end(body)
46
- }
47
-
48
- if (req.method !== 'GET') {
49
- return send(405, '{"error":"method not allowed"}')
50
- }
51
-
52
- const path = normalize(new URL(req.url ?? '/', 'http://127.0.0.1').pathname)
53
-
54
- if (path === '/devtools/servers') {
55
- return send(200, JSON.stringify({ servers: listDevtoolsServers() }))
56
- }
57
-
58
- // '/' and '/app/...' map to the built panel bundle — strict containment,
59
- // no traversal out of dist/panel.
60
- const file =
61
- path === '/' || path === '/app'
62
- ? join(panel, 'index.html')
63
- : path.startsWith('/app/')
64
- ? join(panel, path.slice('/app'.length))
65
- : null
66
-
67
- if (!file || (path.startsWith('/app/') && !file.startsWith(panel + sep))) {
68
- return send(404, '{"error":"not found"}')
69
- }
70
-
71
- try {
72
- send(200, readFileSync(file), TYPES[extname(file)] ?? 'application/octet-stream')
73
- } catch {
74
- send(404, '{"error":"not found"}')
75
- }
76
- })
77
-
78
- await new Promise<void>((resolve, reject) => {
79
- server.once('error', reject)
80
- server.listen(port, '127.0.0.1', () => resolve())
81
- })
82
-
83
- const address = server.address()
84
-
85
- return {
86
- endpoint: `http://127.0.0.1:${typeof address === 'object' && address ? address.port : port}`,
87
- close: () =>
88
- new Promise((resolve, reject) => {
89
- server.close((error) => (error ? reject(error) : resolve()))
90
- }),
91
- }
92
- }
package/src/host/web.ts DELETED
@@ -1,68 +0,0 @@
1
- import { createRequire } from 'node:module'
2
- import { join } from 'node:path'
3
- import { fileURLToPath, pathToFileURL } from 'node:url'
4
- import type { InlineConfig } from 'vite'
5
- import { devtoolsPanels } from './panels.ts'
6
-
7
- const packageRoot = fileURLToPath(new URL('../../', import.meta.url))
8
-
9
- /** The toolchain comes from the selected app. The bundled shell and its TS
10
- * configuration come from this installed DevTools package. */
11
- export async function devtoolsWebConfig(
12
- toolsRoot: string,
13
- outDir: string,
14
- mode: string,
15
- project: string | null = null,
16
- ): Promise<InlineConfig> {
17
- const require = createRequire(join(toolsRoot, 'package.json'))
18
- const load = (name: string) => import(pathToFileURL(require.resolve(name)).href)
19
- const [{ octane }, { css, boundary, nodeEnvDefine }] = await Promise.all([
20
- load('@octanejs/vite-plugin'),
21
- load('@octane-xplat/cli/vite'),
22
- ])
23
-
24
- const root = join(packageRoot, 'src', 'panel')
25
-
26
- return {
27
- // The package's default tsconfig references generated typecheck projects.
28
- tsconfig: join(root, 'tsconfig.browser.json'),
29
- root,
30
- plugins: [css('web'), ...octane(), boundary('web'), devtoolsPanels({ root: project ?? root })],
31
- define: {
32
- ...nodeEnvDefine(mode),
33
- __XPLAT_DEVTOOLS_PROJECT__: JSON.stringify(project),
34
- },
35
- base: './',
36
- build: {
37
- outDir,
38
- emptyOutDir: true,
39
- rollupOptions: { input: join(root, 'index.html') },
40
- },
41
- resolve: {
42
- conditions: ['web'],
43
- extensions: [
44
- '.web.tsrx',
45
- '.tsrx',
46
- '.web.tsx',
47
- '.tsx',
48
- '.web.ts',
49
- '.mjs',
50
- '.mts',
51
- '.ts',
52
- '.jsx',
53
- '.js',
54
- '.json',
55
- ],
56
- dedupe: ['octane'],
57
- },
58
- }
59
- }
60
-
61
- export async function buildDevtoolsWeb(project: string, outDir: string) {
62
- const require = createRequire(join(project, 'package.json'))
63
- const { build } = await import(pathToFileURL(require.resolve('vite')).href)
64
- await build({
65
- ...(await devtoolsWebConfig(project, outDir, 'production', project)),
66
- configFile: false,
67
- })
68
- }
@@ -1,7 +0,0 @@
1
- // macOS leaf barrel — `@octane-xplat/devtools/macos`. JSC-host-only pieces for
2
- // the native devtools app: the Network.framework DevSocket and the Foundation
3
- // discovery-record reader.
4
-
5
- export { nwDevSocket } from './socket.macos.ts'
6
- export { listDevtoolsServers } from './servers.macos.ts'
7
- export type { ListedDevtoolsServer } from '../record.ts'
@@ -1,83 +0,0 @@
1
- // Enumerates live `xplat dev` server discovery records on the macOS JSC host —
2
- // the Foundation counterpart of src/host/records.ts's node:fs reader. Records
3
- // live in ~/Library/Caches/octane-xplat/cli-go/dev-servers-v1/<key>/server.json
4
- // (XPLAT_DEV_RECORDS_DIR overrides for tests). Unreadable dirs and malformed
5
- // entries are skipped; connectivity failures surface through the connection's
6
- // closed state, not here.
7
- import {
8
- NSFileManager,
9
- NSFileModificationDate,
10
- NSHomeDirectory,
11
- NSString,
12
- } from '@octane-xplat/platform/macos'
13
-
14
- import { parseDevtoolsServerRecord, type ListedDevtoolsServer } from '../record.ts'
15
-
16
- export type { ListedDevtoolsServer } from '../record.ts'
17
-
18
- const RECORDS_DIR = 'Library/Caches/octane-xplat/cli-go/dev-servers-v1'
19
-
20
- function recordsDir(): string {
21
- return process.env.XPLAT_DEV_RECORDS_DIR ?? `${NSHomeDirectory()}/${RECORDS_DIR}`
22
- }
23
-
24
- function readEntries(): ListedDevtoolsServer[] {
25
- const dir = recordsDir()
26
- const manager = NSFileManager.defaultManager
27
- let names: { count: number; objectAtIndex(index: number): unknown } | undefined
28
-
29
- try {
30
- names = manager.contentsOfDirectoryAtPathError(dir, null)
31
- } catch {
32
- return []
33
- }
34
-
35
- if (!names) {
36
- return []
37
- }
38
-
39
- const found: { server: ListedDevtoolsServer; written: number }[] = []
40
-
41
- for (let i = 0; i < names.count; i++) {
42
- const name = String(names.objectAtIndex(i))
43
- const file = `${dir}/${name}/server.json`
44
-
45
- try {
46
- const attrs = manager.attributesOfItemAtPathError(file, null)
47
-
48
- if (!attrs) {
49
- continue
50
- }
51
-
52
- const text = NSString.stringWithContentsOfFileEncodingError(
53
- file,
54
- 4, // NSUTF8StringEncoding
55
- null,
56
- )
57
-
58
- const server = parseDevtoolsServerRecord(name, String(text), (path) => path.startsWith('/'))
59
-
60
- if (!server) {
61
- continue
62
- }
63
-
64
- const modified = attrs.objectForKey(NSFileModificationDate)
65
- const written =
66
- modified &&
67
- typeof (modified as { timeIntervalSince1970?: unknown }).timeIntervalSince1970 === 'number'
68
- ? (modified as { timeIntervalSince1970: number }).timeIntervalSince1970
69
- : 0
70
-
71
- found.push({ server, written })
72
- } catch {
73
- continue
74
- }
75
- }
76
-
77
- return found.sort((a, b) => b.written - a.written).map(({ server }) => server)
78
- }
79
-
80
- /** Returns every structurally valid live record, newest first. */
81
- export function listDevtoolsServers(): ListedDevtoolsServer[] {
82
- return readEntries()
83
- }