@pyreon/reactivity 0.24.4 → 0.24.6
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/package.json +1 -4
- package/src/batch.ts +0 -196
- package/src/cell.ts +0 -72
- package/src/computed.ts +0 -313
- package/src/createSelector.ts +0 -109
- package/src/debug.ts +0 -134
- package/src/effect.ts +0 -467
- package/src/env.d.ts +0 -6
- package/src/index.ts +0 -60
- package/src/lpih.ts +0 -227
- package/src/manifest.ts +0 -660
- package/src/reactive-devtools.ts +0 -494
- package/src/reactive-trace.ts +0 -142
- package/src/reconcile.ts +0 -118
- package/src/resource.ts +0 -84
- package/src/scope.ts +0 -123
- package/src/signal.ts +0 -261
- package/src/store.ts +0 -250
- package/src/tests/batch.test.ts +0 -751
- package/src/tests/bind.test.ts +0 -84
- package/src/tests/branches.test.ts +0 -343
- package/src/tests/cell.test.ts +0 -159
- package/src/tests/computed.test.ts +0 -436
- package/src/tests/coverage-hardening.test.ts +0 -471
- package/src/tests/createSelector.test.ts +0 -291
- package/src/tests/debug.test.ts +0 -196
- package/src/tests/effect.test.ts +0 -464
- package/src/tests/fanout-repro.test.ts +0 -179
- package/src/tests/lpih-source-location.test.ts +0 -277
- package/src/tests/lpih.test.ts +0 -351
- package/src/tests/manifest-snapshot.test.ts +0 -96
- package/src/tests/reactive-devtools-treeshake.test.ts +0 -48
- package/src/tests/reactive-devtools.test.ts +0 -296
- package/src/tests/reactive-trace.test.ts +0 -102
- package/src/tests/reconcile-security.test.ts +0 -45
- package/src/tests/resource.test.ts +0 -326
- package/src/tests/scope.test.ts +0 -231
- package/src/tests/signal.test.ts +0 -368
- package/src/tests/store.test.ts +0 -286
- package/src/tests/tracking.test.ts +0 -158
- package/src/tests/vue-parity.test.ts +0 -191
- package/src/tests/watch.test.ts +0 -246
- package/src/tracking.ts +0 -139
- package/src/watch.ts +0 -68
package/src/lpih.ts
DELETED
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Live Program Inlay Hints — runtime bridge.
|
|
3
|
-
*
|
|
4
|
-
* Writes the current `getFireSummaries()` snapshot to a JSON file that
|
|
5
|
-
* the LSP server reads via the `PYREON_LPIH_CACHE` env var. This is the
|
|
6
|
-
* file-cache bridge mechanism — chosen over IPC/WebSocket because:
|
|
7
|
-
*
|
|
8
|
-
* 1. LSP servers are stdio-only — they can't easily talk to a browser.
|
|
9
|
-
* 2. Filesystem is a universal lowest-common-denominator transport.
|
|
10
|
-
* 3. The runtime side writes (atomic rename); the LSP side reads.
|
|
11
|
-
* 4. The LSP re-reads the file on every inlay-hint request, so live
|
|
12
|
-
* edits land immediately without coordination.
|
|
13
|
-
*
|
|
14
|
-
* Two consumer modes:
|
|
15
|
-
*
|
|
16
|
-
* **Dev-server polled mode**: a dev-server hook calls
|
|
17
|
-
* `writeLpihCache(path)` on every signal write or at a regular interval
|
|
18
|
-
* (e.g. 250ms throttle). The LSP picks it up on next inlay-hint request.
|
|
19
|
-
*
|
|
20
|
-
* **On-demand mode**: a test harness or devtools UI calls
|
|
21
|
-
* `writeLpihCache(path)` explicitly when it wants the LSP to see the
|
|
22
|
-
* current state.
|
|
23
|
-
*
|
|
24
|
-
* Atomic write semantics: writes to `<path>.tmp.<pid>.<seq>` then renames
|
|
25
|
-
* to `<path>`. Readers (the LSP server) never see a half-written file.
|
|
26
|
-
*
|
|
27
|
-
* Zero-cost when devtools is inactive: `getFireSummaries()` returns []
|
|
28
|
-
* unless `activateReactiveDevtools()` has been called. So calling
|
|
29
|
-
* `writeLpihCache()` against an inactive registry writes an empty
|
|
30
|
-
* `{ fires: [] }` — cheap, correct.
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
import { getFireSummaries } from './reactive-devtools'
|
|
34
|
-
|
|
35
|
-
let _seq = 0
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Canonical filename for the LPIH cache file. Co-located with the
|
|
39
|
-
* project — convention: `<cwd>/.pyreon-lpih.json`. The dot-prefix marks
|
|
40
|
-
* it as a hidden / generated file by filesystem convention; the
|
|
41
|
-
* extension makes its contents grep-able as JSON.
|
|
42
|
-
*
|
|
43
|
-
* @internal — exported for tests + symmetry with the LSP-side default.
|
|
44
|
-
*/
|
|
45
|
-
export const LPIH_DEFAULT_FILENAME = '.pyreon-lpih.json'
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Resolve the default LPIH cache path for the current process. The path
|
|
49
|
-
* is **`<cwd>/.pyreon-lpih.json`** — co-located with the project so the
|
|
50
|
-
* LSP can auto-discover it by walking up from any source file.
|
|
51
|
-
*
|
|
52
|
-
* Returns null in environments without `process.cwd()` (e.g. a fresh
|
|
53
|
-
* web worker without polyfills) — callers should fall back to an
|
|
54
|
-
* explicit path argument.
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* import { startLpihPolling, getDefaultLpihCachePath } from '@pyreon/reactivity/lpih'
|
|
58
|
-
* console.log(getDefaultLpihCachePath()) // → '/Users/me/proj/.pyreon-lpih.json'
|
|
59
|
-
* startLpihPolling() // writes to that path
|
|
60
|
-
*/
|
|
61
|
-
export function getDefaultLpihCachePath(): string | null {
|
|
62
|
-
if (typeof process === 'undefined') return null
|
|
63
|
-
// Pyreon's reactivity package narrows `process` to `{ env: ... }`.
|
|
64
|
-
// Cast through the runtime check so the call site typechecks under
|
|
65
|
-
// browser-target tsconfig while still working in Node where cwd exists.
|
|
66
|
-
const proc = process as unknown as { cwd?: () => string }
|
|
67
|
-
if (typeof proc.cwd !== 'function') return null
|
|
68
|
-
try {
|
|
69
|
-
const cwd = proc.cwd()
|
|
70
|
-
// Use forward-slash join; works on POSIX + Windows (Node accepts both).
|
|
71
|
-
return `${cwd.replace(/[/\\]+$/, '')}/${LPIH_DEFAULT_FILENAME}`
|
|
72
|
-
} catch {
|
|
73
|
-
return null
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Snapshot `getFireSummaries()` and write it to `path` atomically.
|
|
79
|
-
* Returns the number of fires written.
|
|
80
|
-
*
|
|
81
|
-
* **Path resolution**: when `path` is omitted, defaults to
|
|
82
|
-
* `<cwd>/.pyreon-lpih.json` (`getDefaultLpihCachePath()`). The LSP
|
|
83
|
-
* auto-discovers this convention by walking up from any source file to
|
|
84
|
-
* the nearest `package.json` — so projects that use the default need
|
|
85
|
-
* zero env-var configuration.
|
|
86
|
-
*
|
|
87
|
-
* Errors (filesystem permission, EACCES, etc.) are caught and re-thrown
|
|
88
|
-
* — the caller decides whether to swallow them. The runtime side wraps
|
|
89
|
-
* this in a try/catch when called from hot paths.
|
|
90
|
-
*
|
|
91
|
-
* Throws if `path` is omitted AND no default can be resolved (e.g.
|
|
92
|
-
* a web worker without `process.cwd()`).
|
|
93
|
-
*
|
|
94
|
-
* @example
|
|
95
|
-
* import { activateReactiveDevtools } from '@pyreon/reactivity'
|
|
96
|
-
* import { writeLpihCache } from '@pyreon/reactivity/lpih'
|
|
97
|
-
*
|
|
98
|
-
* activateReactiveDevtools()
|
|
99
|
-
* await writeLpihCache() // → writes to <cwd>/.pyreon-lpih.json
|
|
100
|
-
* // The LSP server auto-discovers this path; no env var needed.
|
|
101
|
-
*/
|
|
102
|
-
export async function writeLpihCache(path?: string): Promise<number> {
|
|
103
|
-
const resolvedPath = path ?? getDefaultLpihCachePath()
|
|
104
|
-
if (resolvedPath === null) {
|
|
105
|
-
throw new Error(
|
|
106
|
-
'[lpih] writeLpihCache: no path provided and no default could be resolved ' +
|
|
107
|
-
'(process.cwd() unavailable). Pass an explicit path.',
|
|
108
|
-
)
|
|
109
|
-
}
|
|
110
|
-
return await _writeToPath(resolvedPath)
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
async function _writeToPath(path: string): Promise<number> {
|
|
114
|
-
const summaries = getFireSummaries()
|
|
115
|
-
const payload = {
|
|
116
|
-
fires: summaries.map((s) => ({
|
|
117
|
-
file: s.loc.file,
|
|
118
|
-
line: s.loc.line,
|
|
119
|
-
count: s.count,
|
|
120
|
-
kind: s.kind,
|
|
121
|
-
lastFire: s.lastFire,
|
|
122
|
-
rate1s: s.rate1s,
|
|
123
|
-
})),
|
|
124
|
-
}
|
|
125
|
-
const pid =
|
|
126
|
-
typeof process !== 'undefined' && 'pid' in process
|
|
127
|
-
? (process as { pid?: number }).pid ?? 0
|
|
128
|
-
: 0
|
|
129
|
-
const tmp = `${path}.tmp.${pid}.${++_seq}`
|
|
130
|
-
const fs = await import('node:fs/promises')
|
|
131
|
-
// Single try/catch covering BOTH writeFile AND rename. The previous
|
|
132
|
-
// shape only guarded the rename — if `fs.writeFile` itself threw (disk
|
|
133
|
-
// full, EIO, EACCES, transient FS error), the partial tmp file leaked
|
|
134
|
-
// on disk with a unique PID+seq name. The same bug class lived in the
|
|
135
|
-
// vite-plugin's `writeLpihCacheFile` (R1); both fixed in lockstep.
|
|
136
|
-
try {
|
|
137
|
-
await fs.writeFile(tmp, JSON.stringify(payload), 'utf8')
|
|
138
|
-
await fs.rename(tmp, path)
|
|
139
|
-
} catch (err) {
|
|
140
|
-
// Rename / writeFile failed — clean up the tmp file so we don't leak
|
|
141
|
-
// it on disk. Covers BOTH paths: writeFile-failed (tmp may not exist
|
|
142
|
-
// → unlink ENOENT, swallowed) AND rename-failed (tmp exists). Common
|
|
143
|
-
// rename causes: cross-device link (rare; same dir → same FS), target
|
|
144
|
-
// is a directory, EACCES. The caller sees the original error; the
|
|
145
|
-
// cleanup is best-effort and silent (unlink may also fail if the FS
|
|
146
|
-
// is broken — re-throwing that would mask the real problem).
|
|
147
|
-
try {
|
|
148
|
-
await fs.unlink(tmp)
|
|
149
|
-
} catch {
|
|
150
|
-
/* swallow — original error is more useful */
|
|
151
|
-
}
|
|
152
|
-
throw err
|
|
153
|
-
}
|
|
154
|
-
return summaries.length
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Polling helper: call `writeLpihCache(path)` every `intervalMs`. Returns
|
|
159
|
-
* a disposer that stops the timer.
|
|
160
|
-
*
|
|
161
|
-
* **Path resolution**: same as `writeLpihCache` — `path` defaults to
|
|
162
|
-
* `<cwd>/.pyreon-lpih.json` when omitted. The LSP auto-discovers this
|
|
163
|
-
* convention so projects need zero configuration.
|
|
164
|
-
*
|
|
165
|
-
* Useful for dev servers that want the LSP to see live updates. The
|
|
166
|
-
* interval is throttled (not debounced); a fast-firing signal won't
|
|
167
|
-
* generate one write per fire. 250-500ms is the recommended range.
|
|
168
|
-
*
|
|
169
|
-
* Throws synchronously if `path` is omitted AND no default can be
|
|
170
|
-
* resolved — the caller catches this once at startup rather than
|
|
171
|
-
* silently never writing.
|
|
172
|
-
*
|
|
173
|
-
* @example
|
|
174
|
-
* import { activateReactiveDevtools } from '@pyreon/reactivity'
|
|
175
|
-
* import { startLpihPolling } from '@pyreon/reactivity/lpih'
|
|
176
|
-
*
|
|
177
|
-
* if (import.meta.env.DEV) {
|
|
178
|
-
* activateReactiveDevtools()
|
|
179
|
-
* startLpihPolling() // writes to <cwd>/.pyreon-lpih.json every 250ms
|
|
180
|
-
* }
|
|
181
|
-
*/
|
|
182
|
-
export function startLpihPolling(
|
|
183
|
-
path?: string,
|
|
184
|
-
intervalMs = 250,
|
|
185
|
-
): () => void {
|
|
186
|
-
const resolvedPath = path ?? getDefaultLpihCachePath()
|
|
187
|
-
if (resolvedPath === null) {
|
|
188
|
-
throw new Error(
|
|
189
|
-
'[lpih] startLpihPolling: no path provided and no default could be resolved ' +
|
|
190
|
-
'(process.cwd() unavailable). Pass an explicit path.',
|
|
191
|
-
)
|
|
192
|
-
}
|
|
193
|
-
return _startPollingAt(resolvedPath, intervalMs)
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
function _startPollingAt(path: string, intervalMs: number): () => void {
|
|
197
|
-
let active = true
|
|
198
|
-
let timer: ReturnType<typeof setTimeout> | null = null
|
|
199
|
-
const tick = async (): Promise<void> => {
|
|
200
|
-
if (!active) return
|
|
201
|
-
try {
|
|
202
|
-
// Skip the default-resolution check on every tick — path is already
|
|
203
|
-
// resolved at startup.
|
|
204
|
-
await _writeToPath(path)
|
|
205
|
-
} catch {
|
|
206
|
-
// Swallow — polling continues. The LSP degrades gracefully if the
|
|
207
|
-
// file is missing or stale.
|
|
208
|
-
}
|
|
209
|
-
if (active) {
|
|
210
|
-
timer = setTimeout(tick, intervalMs)
|
|
211
|
-
// .unref() so a forgotten startLpihPolling() doesn't block process
|
|
212
|
-
// exit. Node-only; the setTimeout return type in browsers is a
|
|
213
|
-
// number with no .unref. Type-narrow defensively.
|
|
214
|
-
if (typeof timer === 'object' && timer !== null && 'unref' in timer) {
|
|
215
|
-
;(timer as { unref(): void }).unref()
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
void tick()
|
|
220
|
-
return () => {
|
|
221
|
-
active = false
|
|
222
|
-
if (timer !== null) {
|
|
223
|
-
clearTimeout(timer)
|
|
224
|
-
timer = null
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|