@neuledge/context 1.2.10 → 1.3.0
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 +8 -0
- package/dist/build.js +9 -10
- package/dist/build.js.map +1 -1
- package/dist/cli.d.ts +15 -0
- package/dist/cli.js +66 -56
- package/dist/cli.js.map +1 -1
- package/dist/download.d.ts +1 -1
- package/dist/download.js +9 -21
- package/dist/download.js.map +1 -1
- package/dist/html.js +25 -2
- package/dist/html.js.map +1 -1
- package/dist/package-builder.js +13 -4
- package/dist/package-builder.js.map +1 -1
- package/dist/package-file.d.ts +14 -0
- package/dist/package-file.js +50 -0
- package/dist/package-file.js.map +1 -0
- package/dist/server.d.ts +29 -1
- package/dist/server.js +59 -25
- package/dist/server.js.map +1 -1
- package/dist/staging.d.ts +46 -0
- package/dist/staging.js +148 -0
- package/dist/staging.js.map +1 -0
- package/dist/store.d.ts +10 -0
- package/dist/store.js +80 -1
- package/dist/store.js.map +1 -1
- package/dist/watch.d.ts +38 -0
- package/dist/watch.js +139 -0
- package/dist/watch.js.map +1 -0
- package/package.json +1 -1
package/dist/staging.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ownership and reclamation for `.context-*` package staging directories.
|
|
3
|
+
*
|
|
4
|
+
* `createPackageTempFile` stages a package inside a private `.context-*`
|
|
5
|
+
* directory and removes it in the operation's `finally`. A hard shutdown
|
|
6
|
+
* (SIGKILL, power loss, or a crash before `finally` runs) can leave that
|
|
7
|
+
* directory behind. Each new staging directory therefore carries a small
|
|
8
|
+
* owner marker, published atomically before the directory is handed back to
|
|
9
|
+
* the writer, so a later setup step can tell an abandoned directory from one
|
|
10
|
+
* whose writer is still alive.
|
|
11
|
+
*
|
|
12
|
+
* Scope note: only directories created after this protocol (`owner.json`)
|
|
13
|
+
* can be reclaimed safely. Legacy `.downloading-*` temporary files predate the
|
|
14
|
+
* protocol, carry no owner marker, and may belong to an active older writer,
|
|
15
|
+
* so they are deliberately left untouched here. Unmarked `.context-*`
|
|
16
|
+
* directories are likewise preserved.
|
|
17
|
+
*
|
|
18
|
+
* PID liveness is meaningful only within one PID namespace. The default package
|
|
19
|
+
* directory is local to the user; do not use this sweep for a shared directory
|
|
20
|
+
* mounted by processes in separate containers or hosts.
|
|
21
|
+
*/
|
|
22
|
+
import { lstatSync, mkdirSync, readdirSync, readFileSync, readlinkSync, renameSync, rmSync, writeFileSync, } from "node:fs";
|
|
23
|
+
import { hostname } from "node:os";
|
|
24
|
+
import { join } from "node:path";
|
|
25
|
+
export const STAGING_PREFIX = ".context-";
|
|
26
|
+
export const OWNER_FILE_NAME = "owner.json";
|
|
27
|
+
export const OWNER_VERSION = 1;
|
|
28
|
+
/** Ensure a package directory exists and reclaim abandoned staging left in it. */
|
|
29
|
+
export function ensurePackagesDirectory(directory) {
|
|
30
|
+
mkdirSync(directory, { recursive: true });
|
|
31
|
+
sweepAbandonedStaging(directory);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Remove `.context-*` staging directories whose recorded owner process is no
|
|
35
|
+
* longer running. Only immediate child directories participate; symlinks are
|
|
36
|
+
* never followed or removed, and legacy `.downloading-*` entries are never
|
|
37
|
+
* touched. Any entry without a valid owner marker is preserved: the writer may
|
|
38
|
+
* be an older version that predates the protocol, or the marker may not have
|
|
39
|
+
* been published yet.
|
|
40
|
+
*/
|
|
41
|
+
export function sweepAbandonedStaging(directory) {
|
|
42
|
+
let entries;
|
|
43
|
+
try {
|
|
44
|
+
entries = readdirSync(directory, { withFileTypes: true });
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// Cleanup is best-effort: a directory that cannot be listed must not stop
|
|
48
|
+
// the build or download that triggered the sweep.
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
for (const entry of entries) {
|
|
52
|
+
if (!entry.name.startsWith(STAGING_PREFIX))
|
|
53
|
+
continue;
|
|
54
|
+
// A Windows junction may look like an ordinary directory to Dirent and
|
|
55
|
+
// lstat, but readlink succeeds for both junctions and symbolic links.
|
|
56
|
+
if (!entry.isDirectory() && !entry.isSymbolicLink())
|
|
57
|
+
continue;
|
|
58
|
+
const stagingDirectory = join(directory, entry.name);
|
|
59
|
+
try {
|
|
60
|
+
readlinkSync(stagingDirectory);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
// EINVAL is how readlink reports a real directory. On any other error,
|
|
65
|
+
// preserve the path because it may be an inaccessible link or junction.
|
|
66
|
+
if (error.code !== "EINVAL")
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
if (!lstatSync(stagingDirectory).isDirectory())
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// The entry may have disappeared or be inaccessible; preserve it.
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const owner = readOwnerMetadata(stagingDirectory);
|
|
78
|
+
if (!owner)
|
|
79
|
+
continue;
|
|
80
|
+
// Hostname is a conservative extra check, not proof that PID namespaces
|
|
81
|
+
// match; the configured package directory must remain local to one namespace.
|
|
82
|
+
if (owner.hostname !== hostname())
|
|
83
|
+
continue;
|
|
84
|
+
if (isProcessAbsent(owner.pid)) {
|
|
85
|
+
try {
|
|
86
|
+
rmSync(stagingDirectory, { recursive: true, force: true });
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
// Reclamation is best-effort; a locked or unreadable leftover must not
|
|
90
|
+
// make subsequent package work fail.
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Write the current process's ownership marker atomically: a sweep that runs
|
|
97
|
+
* concurrently sees either no marker (preserve) or a complete marker (owner
|
|
98
|
+
* process already recorded), never a half-written one.
|
|
99
|
+
*/
|
|
100
|
+
export function writeOwnerMetadata(stagingDirectory, owner = {
|
|
101
|
+
version: OWNER_VERSION,
|
|
102
|
+
pid: process.pid,
|
|
103
|
+
hostname: hostname(),
|
|
104
|
+
}) {
|
|
105
|
+
const target = join(stagingDirectory, OWNER_FILE_NAME);
|
|
106
|
+
const temporary = `${target}.${process.pid}.tmp`;
|
|
107
|
+
writeFileSync(temporary, JSON.stringify(owner));
|
|
108
|
+
renameSync(temporary, target);
|
|
109
|
+
}
|
|
110
|
+
function readOwnerMetadata(stagingDirectory) {
|
|
111
|
+
try {
|
|
112
|
+
const raw = readFileSync(join(stagingDirectory, OWNER_FILE_NAME), "utf8");
|
|
113
|
+
const parsed = JSON.parse(raw);
|
|
114
|
+
return isOwnerMetadata(parsed) ? parsed : null;
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function isOwnerMetadata(value) {
|
|
121
|
+
if (typeof value !== "object" || value === null)
|
|
122
|
+
return false;
|
|
123
|
+
const record = value;
|
|
124
|
+
return (record.version === OWNER_VERSION &&
|
|
125
|
+
typeof record.pid === "number" &&
|
|
126
|
+
Number.isInteger(record.pid) &&
|
|
127
|
+
record.pid > 0 &&
|
|
128
|
+
typeof record.hostname === "string" &&
|
|
129
|
+
record.hostname.length > 0);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Probe a recorded owner PID without signaling it. A process is considered
|
|
133
|
+
* absent only when `process.kill(pid, 0)` throws `ESRCH`. Success means the
|
|
134
|
+
* process is alive; `EPERM` means it exists but belongs to someone else; any
|
|
135
|
+
* other error is ambiguous. All of those preserve the directory, so PID reuse
|
|
136
|
+
* or a transient probe failure can only leave a directory behind, never delete
|
|
137
|
+
* an active writer's staging.
|
|
138
|
+
*/
|
|
139
|
+
function isProcessAbsent(pid) {
|
|
140
|
+
try {
|
|
141
|
+
process.kill(pid, 0);
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
return error.code === "ESRCH";
|
|
146
|
+
}
|
|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AC"}
|
package/dist/store.d.ts
CHANGED
|
@@ -56,5 +56,15 @@ export declare class PackageStore {
|
|
|
56
56
|
/** Open a package database for searching. Accepts the same specs as `get`. */
|
|
57
57
|
openDb(spec: string): DatabaseConnection | null;
|
|
58
58
|
}
|
|
59
|
+
/** Load installed packages, ignoring staged downloads and invalid databases. */
|
|
60
|
+
export declare function loadPackages(store: PackageStore, directory: string): void;
|
|
61
|
+
/**
|
|
62
|
+
* Reconcile a live store with the packages on disk: add newly installed
|
|
63
|
+
* packages and drop entries whose files are gone. A package whose file still
|
|
64
|
+
* exists but cannot be read (a partial or unreadable database) is left
|
|
65
|
+
* untouched — its absence is not confirmed, and a later reload may succeed once
|
|
66
|
+
* the writer finishes.
|
|
67
|
+
*/
|
|
68
|
+
export declare function reloadPackages(store: PackageStore, directory: string): void;
|
|
59
69
|
/** Read package info from a database file. */
|
|
60
70
|
export declare function readPackageInfo(packagePath: string): PackageInfo;
|
package/dist/store.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { statSync } from "node:fs";
|
|
1
|
+
import { existsSync, readdirSync, statSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
2
3
|
import { openDatabase } from "./database.js";
|
|
3
4
|
import { getMetaValue, getSectionCount, validatePackageSchema } from "./db.js";
|
|
4
5
|
/** Create a filesystem-safe filename for an installed package database. */
|
|
@@ -152,6 +153,84 @@ export class PackageStore {
|
|
|
152
153
|
return openDatabase(pkg.path, { readonly: true });
|
|
153
154
|
}
|
|
154
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* True for package database files. Staged `.downloading-*` downloads are
|
|
158
|
+
* excluded: their names may end in `.db` before the write is finished.
|
|
159
|
+
*/
|
|
160
|
+
function isPackageFile(file) {
|
|
161
|
+
return file.endsWith(".db") && !file.startsWith(".downloading-");
|
|
162
|
+
}
|
|
163
|
+
/** Load installed packages, ignoring staged downloads and invalid databases. */
|
|
164
|
+
export function loadPackages(store, directory) {
|
|
165
|
+
if (!existsSync(directory))
|
|
166
|
+
return;
|
|
167
|
+
for (const file of readdirSync(directory)) {
|
|
168
|
+
if (!isPackageFile(file))
|
|
169
|
+
continue;
|
|
170
|
+
try {
|
|
171
|
+
store.add(readPackageInfo(join(directory, file)));
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
// Skip invalid packages.
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* True only when a package file is positively gone: `stat` reports ENOENT (the
|
|
180
|
+
* file does not exist) or ENOTDIR (a path component is not a directory, so the
|
|
181
|
+
* file cannot exist there). Permission errors and other transient failures are
|
|
182
|
+
* not proof of absence, so the entry is kept.
|
|
183
|
+
*/
|
|
184
|
+
function isFileConfirmedAbsent(path) {
|
|
185
|
+
try {
|
|
186
|
+
statSync(path);
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
const code = error.code;
|
|
191
|
+
if (code !== "ENOENT" && code !== "ENOTDIR") {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Reconcile a live store with the packages on disk: add newly installed
|
|
199
|
+
* packages and drop entries whose files are gone. A package whose file still
|
|
200
|
+
* exists but cannot be read (a partial or unreadable database) is left
|
|
201
|
+
* untouched — its absence is not confirmed, and a later reload may succeed once
|
|
202
|
+
* the writer finishes.
|
|
203
|
+
*/
|
|
204
|
+
export function reloadPackages(store, directory) {
|
|
205
|
+
let files;
|
|
206
|
+
try {
|
|
207
|
+
// A missing package directory is not proof that its packages were removed:
|
|
208
|
+
// keep the store as-is so a later reload reconciles once it returns.
|
|
209
|
+
if (!existsSync(directory))
|
|
210
|
+
return;
|
|
211
|
+
files = readdirSync(directory);
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
// The directory cannot be inspected; keep the store as-is rather than drop
|
|
215
|
+
// entries whose absence cannot be confirmed.
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
for (const file of files) {
|
|
219
|
+
if (!isPackageFile(file))
|
|
220
|
+
continue;
|
|
221
|
+
try {
|
|
222
|
+
store.add(readPackageInfo(join(directory, file)));
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
// Keep any existing entry: the file is still present.
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
for (const pkg of store.list()) {
|
|
229
|
+
if (isFileConfirmedAbsent(pkg.path)) {
|
|
230
|
+
store.remove(packageKey(pkg));
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
155
234
|
/** Read package info from a database file. */
|
|
156
235
|
export function readPackageInfo(packagePath) {
|
|
157
236
|
const db = openDatabase(packagePath, { readonly: true });
|
package/dist/store.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAA2B,YAAY,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAe/E,2EAA2E;AAC3E,MAAM,UAAU,kBAAkB,CAAC,IAAY,EAAE,OAAe;IAC9D,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC5C,MAAM,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAClD,OAAO,GAAG,QAAQ,IAAI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AAC,EAAE,CAAC,CAAC;QAE1B,MAAM,IAAI,GAAG,YAAY,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QACtC,MAAM,OAAO,GAAG,YAAY,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC;QAE5C,IAAI,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;QAC5E,CAAC;QAED,OAAO;YACL,IAAI;YACJ,OAAO;YACP,WAAW,EAAE,YAAY,CAAC,EAAE,EAAE,aAAa,CAAC;YAC5C,SAAS,EAAE,YAAY,CAAC,EAAE,EAAE,YAAY,CAAC;YACzC,IAAI,EAAE,WAAW;YACjB,SAAS,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC,IAAI;YACrC,YAAY,EAAE,eAAe,CAAC,EAAE,CAAC;SAClC,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,EAAE,CAAC,KAAK,EAAE,CAAC;IACb,CAAC;AACH,CAAC"}
|
package/dist/watch.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Debounced directory watching for the long-running `context serve` process.
|
|
3
|
+
*
|
|
4
|
+
* A running stdio server shares the package directory with separate
|
|
5
|
+
* `context add` / `context remove` processes. Watching that directory lets the
|
|
6
|
+
* server reload its package store and refresh `get_docs` when a package is
|
|
7
|
+
* installed or removed underneath it.
|
|
8
|
+
*
|
|
9
|
+
* The watcher is deliberately defensive: it never keeps the process alive on
|
|
10
|
+
* its own (`unref`), it contains callback exceptions, and it survives both
|
|
11
|
+
* `fs.watch` errors (such as ENOSPC) and the watched directory being removed
|
|
12
|
+
* and recreated.
|
|
13
|
+
*/
|
|
14
|
+
/** The subset of `fs.FSWatcher` used here, so tests can inject a fake. */
|
|
15
|
+
export interface WatchHandle {
|
|
16
|
+
close(): void;
|
|
17
|
+
on(event: "error", listener: (error: Error) => void): this;
|
|
18
|
+
unref?(): void;
|
|
19
|
+
}
|
|
20
|
+
/** A filesystem watch factory, injectable for tests. */
|
|
21
|
+
export type WatchFn = (directory: string, listener: (eventType: string, filename: string | null) => void) => WatchHandle;
|
|
22
|
+
export interface WatchDirectoryOptions {
|
|
23
|
+
/** Coalesce events that arrive within this many milliseconds. Default: 200. */
|
|
24
|
+
debounceMs?: number;
|
|
25
|
+
/** Poll interval while waiting for a removed directory to be recreated. */
|
|
26
|
+
retryMs?: number;
|
|
27
|
+
/** Filesystem watch factory, injectable for tests. */
|
|
28
|
+
watchFn?: WatchFn;
|
|
29
|
+
/** Path existence check, injectable for tests. */
|
|
30
|
+
exists?: (path: string) => boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Watch a directory and call `callback` (debounced) after its contents change.
|
|
34
|
+
*
|
|
35
|
+
* Returns a stop function. The watcher and its timers are unref'd, so a caller
|
|
36
|
+
* that wants the process to stay alive must have some other handle open.
|
|
37
|
+
*/
|
|
38
|
+
export declare function watchDirectory(directory: string, callback: () => void, options?: WatchDirectoryOptions): () => void;
|
package/dist/watch.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Debounced directory watching for the long-running `context serve` process.
|
|
3
|
+
*
|
|
4
|
+
* A running stdio server shares the package directory with separate
|
|
5
|
+
* `context add` / `context remove` processes. Watching that directory lets the
|
|
6
|
+
* server reload its package store and refresh `get_docs` when a package is
|
|
7
|
+
* installed or removed underneath it.
|
|
8
|
+
*
|
|
9
|
+
* The watcher is deliberately defensive: it never keeps the process alive on
|
|
10
|
+
* its own (`unref`), it contains callback exceptions, and it survives both
|
|
11
|
+
* `fs.watch` errors (such as ENOSPC) and the watched directory being removed
|
|
12
|
+
* and recreated.
|
|
13
|
+
*/
|
|
14
|
+
import { existsSync, watch } from "node:fs";
|
|
15
|
+
const defaultWatchFn = (directory, listener) => watch(directory, listener);
|
|
16
|
+
/**
|
|
17
|
+
* Watch a directory and call `callback` (debounced) after its contents change.
|
|
18
|
+
*
|
|
19
|
+
* Returns a stop function. The watcher and its timers are unref'd, so a caller
|
|
20
|
+
* that wants the process to stay alive must have some other handle open.
|
|
21
|
+
*/
|
|
22
|
+
export function watchDirectory(directory, callback, options = {}) {
|
|
23
|
+
const debounceMs = options.debounceMs ?? 200;
|
|
24
|
+
const retryMs = options.retryMs ?? debounceMs;
|
|
25
|
+
const watchFn = options.watchFn ?? defaultWatchFn;
|
|
26
|
+
const exists = options.exists ?? existsSync;
|
|
27
|
+
let watcher = null;
|
|
28
|
+
let debounceTimer = null;
|
|
29
|
+
let retryTimer = null;
|
|
30
|
+
let stopped = false;
|
|
31
|
+
const clearDebounce = () => {
|
|
32
|
+
if (debounceTimer !== null) {
|
|
33
|
+
clearTimeout(debounceTimer);
|
|
34
|
+
debounceTimer = null;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const detach = () => {
|
|
38
|
+
if (watcher === null)
|
|
39
|
+
return;
|
|
40
|
+
const current = watcher;
|
|
41
|
+
watcher = null;
|
|
42
|
+
try {
|
|
43
|
+
current.close();
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
// The watcher may already be gone; closing is best-effort.
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const scheduleRetry = () => {
|
|
50
|
+
if (stopped || retryTimer !== null)
|
|
51
|
+
return;
|
|
52
|
+
retryTimer = setTimeout(() => {
|
|
53
|
+
retryTimer = null;
|
|
54
|
+
if (stopped)
|
|
55
|
+
return;
|
|
56
|
+
if (exists(directory)) {
|
|
57
|
+
attach();
|
|
58
|
+
schedule();
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
scheduleRetry();
|
|
62
|
+
}
|
|
63
|
+
}, retryMs);
|
|
64
|
+
retryTimer.unref();
|
|
65
|
+
};
|
|
66
|
+
const schedule = () => {
|
|
67
|
+
clearDebounce();
|
|
68
|
+
debounceTimer = setTimeout(() => {
|
|
69
|
+
debounceTimer = null;
|
|
70
|
+
if (stopped)
|
|
71
|
+
return;
|
|
72
|
+
// A watched directory can vanish without an error event (Linux keeps the
|
|
73
|
+
// watch on the old inode and emits one final rename). Drop the dead
|
|
74
|
+
// watcher and poll until the directory is recreated, then reload.
|
|
75
|
+
if (!exists(directory)) {
|
|
76
|
+
detach();
|
|
77
|
+
scheduleRetry();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
callback();
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
// A failing reload must not kill the watcher: later events still fire.
|
|
85
|
+
}
|
|
86
|
+
}, debounceMs);
|
|
87
|
+
debounceTimer.unref();
|
|
88
|
+
};
|
|
89
|
+
const handleEvent = (eventType) => {
|
|
90
|
+
// A `rename` is how `fs.watch` reports both the watched directory being
|
|
91
|
+
// removed/recreated and entries being added or removed inside it. The
|
|
92
|
+
// directory may already exist again when the event is handled (a quick
|
|
93
|
+
// remove/recreate inside the debounce window), but the old watcher is still
|
|
94
|
+
// attached to the dead inode. Detach and re-attach so the watcher always
|
|
95
|
+
// follows the current directory, then reload.
|
|
96
|
+
if (eventType === "rename") {
|
|
97
|
+
detach();
|
|
98
|
+
if (exists(directory)) {
|
|
99
|
+
attach();
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
scheduleRetry();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
schedule();
|
|
106
|
+
};
|
|
107
|
+
const handleError = () => {
|
|
108
|
+
detach();
|
|
109
|
+
scheduleRetry();
|
|
110
|
+
};
|
|
111
|
+
const attach = () => {
|
|
112
|
+
if (stopped || watcher !== null)
|
|
113
|
+
return;
|
|
114
|
+
if (!exists(directory)) {
|
|
115
|
+
scheduleRetry();
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
watcher = watchFn(directory, handleEvent);
|
|
120
|
+
watcher.on("error", handleError);
|
|
121
|
+
watcher.unref?.();
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
// `watch` can throw synchronously (missing directory, resource limits).
|
|
125
|
+
handleError();
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
attach();
|
|
129
|
+
return () => {
|
|
130
|
+
stopped = true;
|
|
131
|
+
clearDebounce();
|
|
132
|
+
if (retryTimer !== null) {
|
|
133
|
+
clearTimeout(retryTimer);
|
|
134
|
+
retryTimer = null;
|
|
135
|
+
}
|
|
136
|
+
detach();
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=watch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watch.js","sourceRoot":"","sources":["../src/watch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AA0B5C,MAAM,cAAc,GAAY,CAAC,SAAS,EAAE,QAAQ,EAAE,EAAE,CACtD,KAAK,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;AAE7B;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAC5B,SAAiB,EACjB,QAAoB,EACpB,UAAiC,EAAE;IAEnC,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,GAAG,CAAC;IAC7C,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,UAAU,CAAC;IAC9C,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,cAAc,CAAC;IAClD,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,UAAU,CAAC;IAE5C,IAAI,OAAO,GAAuB,IAAI,CAAC;IACvC,IAAI,aAAa,GAAyC,IAAI,CAAC;IAC/D,IAAI,UAAU,GAAyC,IAAI,CAAC;IAC5D,IAAI,OAAO,GAAG,KAAK,CAAC;IAEpB,MAAM,aAAa,GAAG,GAAS,EAAE;QAC/B,IAAI,aAAa,KAAK,IAAI,EAAE,CAAC;YAC3B,YAAY,CAAC,aAAa,CAAC,CAAC;YAC5B,aAAa,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