@visulima/task-runner 1.0.0-alpha.4 → 1.0.0-alpha.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/CHANGELOG.md +48 -0
- package/dist/archive.d.ts +38 -0
- package/dist/cache.d.ts +39 -4
- package/dist/chrome-trace.d.ts +53 -0
- package/dist/file-access-tracker.d.ts +7 -1
- package/dist/fingerprint.d.ts +9 -0
- package/dist/flow-controllers/input-handler.d.ts +1 -1
- package/dist/incremental-hasher.d.ts +18 -0
- package/dist/index.d.ts +9 -4
- package/dist/index.js +23 -20
- package/dist/life-cycle.d.ts +2 -0
- package/dist/log-reporter.d.ts +34 -0
- package/dist/output-resolver.d.ts +20 -0
- package/dist/packem_shared/{Cache-C23LywYn.js → Cache-CWaX_c8U.js} +137 -46
- package/dist/packem_shared/{CompositeLifeCycle-7AtYw1dv.js → CompositeLifeCycle-CSVbRC_5.js} +10 -0
- package/dist/packem_shared/{FileAccessTracker-CrtBAt5D.js → FileAccessTracker-CQ5Ot7Hd.js} +68 -16
- package/dist/packem_shared/{FingerprintManager-Cu-ta9ee.js → FingerprintManager-CV7U4f4f.js} +22 -1
- package/dist/packem_shared/{IncrementalFileHasher-Cm_kJY5V.js → IncrementalFileHasher-BRS76-mb.js} +26 -0
- package/dist/packem_shared/LogReporter-BDt52HLu.js +44 -0
- package/dist/packem_shared/{RemoteCache-BFceSe4a.js → RemoteCache-DSU3lc87.js} +77 -37
- package/dist/packem_shared/{TaskOrchestrator-lLn-PH1m.js → TaskOrchestrator-rf45vW5c.js} +94 -15
- package/dist/packem_shared/{TerminalBuffer-D6zP2zLh.js → TerminalBuffer-qVJvbRQZ.js} +53 -37
- package/dist/packem_shared/{TrackedTaskExecutor-BGUKFE-7.js → TrackedTaskExecutor-CFPpQfXF.js} +1 -1
- package/dist/packem_shared/archive-UQHAnZUa.js +102 -0
- package/dist/packem_shared/{buildForwardDependencyMap-Cu08NWB1.js → buildForwardDependencyMap-DLPgKEto.js} +6 -3
- package/dist/packem_shared/{computeTaskHash-B2SVZqgp.js → computeTaskHash-DYqfrDGq.js} +122 -6
- package/dist/packem_shared/{createTaskGraph-CcsFaSrz.js → createTaskGraph-B7nH0kY_.js} +2 -2
- package/dist/packem_shared/{defaultTaskRunner-X1MIynHu.js → defaultTaskRunner-Cp7jCmIl.js} +28 -6
- package/dist/packem_shared/{enforceProjectConstraints-_Ej0zHch.js → enforceProjectConstraints-C5Jp_C3u.js} +23 -2
- package/dist/packem_shared/{extractPackageName-CbVNW-dr.js → extractPackageName-BllKetnz.js} +2 -1
- package/dist/packem_shared/{generateRunSummary-qn-_jKwt.js → generateRunSummary-BE1jnQ3H.js} +19 -1
- package/dist/packem_shared/{parsePartition-C4-P5RjK.js → parsePartition-BfLbHGAx.js} +18 -0
- package/dist/packem_shared/{projectGraphToDot-C8uYeaPo.js → projectGraphToDot-DU1lSe-c.js} +1 -1
- package/dist/packem_shared/resolveOutputs-n6MCKoTe.js +111 -0
- package/dist/packem_shared/{runConcurrentFallback-3q46z4AS.js → runConcurrentFallback-BTmgGV1H.js} +20 -6
- package/dist/packem_shared/{runConcurrently-ATDwJNR6.js → runConcurrently-CmfC4r-f.js} +1 -1
- package/dist/packem_shared/toChromeTrace-B2tZoJ-7.js +121 -0
- package/dist/project-constraints.d.ts +3 -10
- package/dist/remote-cache.d.ts +45 -0
- package/dist/run-summary.d.ts +26 -4
- package/dist/task-hasher.d.ts +37 -0
- package/dist/task-orchestrator.d.ts +2 -2
- package/dist/types.d.ts +168 -15
- package/index.js +723 -553
- package/package.json +13 -13
|
@@ -18,40 +18,45 @@ const __cjs_getBuiltinModule = (module) => {
|
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
const {
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
createHmac,
|
|
22
|
+
timingSafeEqual
|
|
23
|
+
} = __cjs_getBuiltinModule("node:crypto");
|
|
23
24
|
const {
|
|
24
|
-
createWriteStream
|
|
25
|
+
createWriteStream,
|
|
26
|
+
createReadStream
|
|
25
27
|
} = __cjs_getBuiltinModule("node:fs");
|
|
26
28
|
const {
|
|
27
29
|
mkdir,
|
|
28
30
|
rm,
|
|
29
|
-
stat
|
|
30
|
-
readFile
|
|
31
|
+
stat
|
|
31
32
|
} = __cjs_getBuiltinModule("node:fs/promises");
|
|
32
33
|
const {
|
|
33
34
|
pipeline
|
|
34
35
|
} = __cjs_getBuiltinModule("node:stream/promises");
|
|
35
36
|
import { join } from '@visulima/path';
|
|
37
|
+
import { e as extractTarBrotli, a as extractTarGz, c as createTarBrotli, b as createTarGz } from './archive-UQHAnZUa.js';
|
|
36
38
|
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
39
|
+
const SIGNATURE_HEADER = "X-Artifact-Signature";
|
|
40
|
+
const MIN_SECRET_LENGTH = 16;
|
|
41
|
+
const computeArtifactSignatureStream = async (secret, hash, archivePath) => {
|
|
42
|
+
const hmac = createHmac("sha256", secret);
|
|
43
|
+
hmac.update(hash);
|
|
44
|
+
const source = createReadStream(archivePath);
|
|
45
|
+
for await (const chunk of source) {
|
|
46
|
+
hmac.update(chunk);
|
|
47
|
+
}
|
|
48
|
+
return hmac.digest("hex");
|
|
49
|
+
};
|
|
50
|
+
const signaturesMatch = (a, b) => {
|
|
51
|
+
if (a.length !== b.length) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
return timingSafeEqual(Buffer.from(a, "hex"), Buffer.from(b, "hex"));
|
|
56
|
+
} catch {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
55
60
|
class RemoteCache {
|
|
56
61
|
#url;
|
|
57
62
|
#token;
|
|
@@ -60,6 +65,9 @@ class RemoteCache {
|
|
|
60
65
|
#read;
|
|
61
66
|
#write;
|
|
62
67
|
#onUploadError;
|
|
68
|
+
#compression;
|
|
69
|
+
#signingSecret;
|
|
70
|
+
#verifyOnDownload;
|
|
63
71
|
constructor(options) {
|
|
64
72
|
this.#url = options.url.replace(/\/$/, "");
|
|
65
73
|
this.#token = options.token;
|
|
@@ -68,6 +76,17 @@ class RemoteCache {
|
|
|
68
76
|
this.#read = options.read ?? true;
|
|
69
77
|
this.#write = options.write ?? true;
|
|
70
78
|
this.#onUploadError = options.onUploadError;
|
|
79
|
+
this.#compression = options.compression ?? "gzip";
|
|
80
|
+
if (options.signing) {
|
|
81
|
+
if (options.signing.secret.length < MIN_SECRET_LENGTH) {
|
|
82
|
+
throw new Error(`Remote cache signing secret must be at least ${String(MIN_SECRET_LENGTH)} characters.`);
|
|
83
|
+
}
|
|
84
|
+
this.#signingSecret = options.signing.secret;
|
|
85
|
+
this.#verifyOnDownload = options.signing.verifyOnDownload ?? false;
|
|
86
|
+
} else {
|
|
87
|
+
this.#signingSecret = void 0;
|
|
88
|
+
this.#verifyOnDownload = false;
|
|
89
|
+
}
|
|
71
90
|
}
|
|
72
91
|
/**
|
|
73
92
|
* Retrieves a cached artifact from the remote cache.
|
|
@@ -89,15 +108,23 @@ class RemoteCache {
|
|
|
89
108
|
if (!response.ok) {
|
|
90
109
|
return false;
|
|
91
110
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
111
|
+
const receivedSignature = this.#signingSecret ? response.headers.get(SIGNATURE_HEADER.toLowerCase()) ?? response.headers.get(SIGNATURE_HEADER) : null;
|
|
112
|
+
if (this.#signingSecret && !receivedSignature && this.#verifyOnDownload) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
if (!response.body) {
|
|
95
116
|
return false;
|
|
96
117
|
}
|
|
97
|
-
|
|
98
|
-
await pipeline(body,
|
|
118
|
+
await mkdir(localCacheDirectory, { recursive: true });
|
|
119
|
+
await pipeline(response.body, createWriteStream(archivePath));
|
|
120
|
+
if (this.#signingSecret && receivedSignature) {
|
|
121
|
+
const expected = await computeArtifactSignatureStream(this.#signingSecret, hash, archivePath);
|
|
122
|
+
if (!signaturesMatch(receivedSignature, expected)) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
99
126
|
await mkdir(entryDirectory, { recursive: true });
|
|
100
|
-
await extractTarGz(archivePath, entryDirectory);
|
|
127
|
+
await (this.#compression === "brotli" ? extractTarBrotli(archivePath, entryDirectory) : extractTarGz(archivePath, entryDirectory));
|
|
101
128
|
await rm(archivePath, { force: true });
|
|
102
129
|
return true;
|
|
103
130
|
} catch {
|
|
@@ -119,16 +146,29 @@ class RemoteCache {
|
|
|
119
146
|
const archivePath = join(localCacheDirectory, `.upload-${hash}.tar.gz`);
|
|
120
147
|
try {
|
|
121
148
|
await stat(join(entryDirectory, ".commit"));
|
|
122
|
-
await createTarGz(entryDirectory, archivePath);
|
|
149
|
+
await (this.#compression === "brotli" ? createTarBrotli(entryDirectory, archivePath) : createTarGz(entryDirectory, archivePath));
|
|
123
150
|
const artifactUrl = this.#buildUrl(`/v8/artifacts/${hash}`);
|
|
124
|
-
const
|
|
151
|
+
const { size } = await stat(archivePath);
|
|
152
|
+
const uploadHeaders = {
|
|
153
|
+
...this.#buildHeaders(),
|
|
154
|
+
"Content-Length": String(size),
|
|
155
|
+
// Advertise the compression format in a custom header so
|
|
156
|
+
// spec-compatible servers (and the matching download side)
|
|
157
|
+
// can branch if needed. The body is still an opaque blob
|
|
158
|
+
// from the server's perspective.
|
|
159
|
+
"Content-Type": "application/octet-stream",
|
|
160
|
+
"X-Artifact-Compression": this.#compression
|
|
161
|
+
};
|
|
162
|
+
if (this.#signingSecret) {
|
|
163
|
+
uploadHeaders[SIGNATURE_HEADER] = await computeArtifactSignatureStream(this.#signingSecret, hash, archivePath);
|
|
164
|
+
}
|
|
125
165
|
const response = await fetch(artifactUrl, {
|
|
126
|
-
body:
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
166
|
+
body: createReadStream(archivePath),
|
|
167
|
+
// @ts-expect-error — `duplex` is a Node-specific fetch
|
|
168
|
+
// option required when the body is a stream. The DOM
|
|
169
|
+
// `RequestInit` type doesn't include it yet.
|
|
170
|
+
duplex: "half",
|
|
171
|
+
headers: uploadHeaders,
|
|
132
172
|
method: "PUT",
|
|
133
173
|
signal: AbortSignal.timeout(this.#timeout)
|
|
134
174
|
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { d as resolveTaskCwd, a as createFailureResult, e as createXxh3Hasher } from './utils-zO0ZRgtf.js';
|
|
2
|
-
import { join } from '@visulima/path';
|
|
3
|
-
import { FingerprintManager } from './FingerprintManager-
|
|
4
|
-
import { generateRunSummary, writeRunSummary } from './generateRunSummary-
|
|
5
|
-
import { computeTaskHash } from './computeTaskHash-
|
|
6
|
-
import { TrackedTaskExecutor } from './TrackedTaskExecutor-
|
|
2
|
+
import { resolve, join } from '@visulima/path';
|
|
3
|
+
import { FingerprintManager } from './FingerprintManager-CV7U4f4f.js';
|
|
4
|
+
import { generateRunSummary, writeLastRunSummary, writeRunSummary } from './generateRunSummary-BE1jnQ3H.js';
|
|
5
|
+
import { computeTaskHash } from './computeTaskHash-DYqfrDGq.js';
|
|
6
|
+
import { TrackedTaskExecutor } from './TrackedTaskExecutor-CFPpQfXF.js';
|
|
7
7
|
|
|
8
8
|
const hashFingerprint = (fingerprint) => {
|
|
9
9
|
const hash = createXxh3Hasher();
|
|
@@ -26,11 +26,11 @@ const hashFingerprint = (fingerprint) => {
|
|
|
26
26
|
return hash.digest();
|
|
27
27
|
};
|
|
28
28
|
const createDeferred = () => {
|
|
29
|
-
let
|
|
29
|
+
let resolve2;
|
|
30
30
|
const promise = new Promise((r) => {
|
|
31
|
-
|
|
31
|
+
resolve2 = r;
|
|
32
32
|
});
|
|
33
|
-
return { promise, resolve };
|
|
33
|
+
return { promise, resolve: resolve2 };
|
|
34
34
|
};
|
|
35
35
|
class TaskOrchestrator {
|
|
36
36
|
#taskHasher;
|
|
@@ -101,9 +101,12 @@ class TaskOrchestrator {
|
|
|
101
101
|
process.removeListener("SIGTERM", signalHandler);
|
|
102
102
|
this.#lifeCycle.endCommand?.();
|
|
103
103
|
}
|
|
104
|
-
if (this.#
|
|
104
|
+
if (this.#taskGraph && !this.#aborted) {
|
|
105
105
|
const summary = generateRunSummary(this.#results, this.#taskGraph, this.#startTime);
|
|
106
|
-
await
|
|
106
|
+
await writeLastRunSummary(summary, this.#workspaceRoot);
|
|
107
|
+
if (this.#summarize) {
|
|
108
|
+
await writeRunSummary(summary, this.#workspaceRoot);
|
|
109
|
+
}
|
|
107
110
|
}
|
|
108
111
|
return this.#results;
|
|
109
112
|
}
|
|
@@ -243,7 +246,13 @@ class TaskOrchestrator {
|
|
|
243
246
|
};
|
|
244
247
|
this.#results.set(task.id, result);
|
|
245
248
|
if (code === 0 && task.cache !== false && task.hash) {
|
|
246
|
-
await this.#
|
|
249
|
+
const modified = await this.#detectSelfModifiedInputs(task);
|
|
250
|
+
if (modified.length > 0) {
|
|
251
|
+
result.selfModified = true;
|
|
252
|
+
this.#lifeCycle.printSelfModifyingSkip?.(task, modified);
|
|
253
|
+
} else {
|
|
254
|
+
await this.#cache.put(task.hash, terminalOutput, task.outputs, code);
|
|
255
|
+
}
|
|
247
256
|
}
|
|
248
257
|
return result;
|
|
249
258
|
} catch (error) {
|
|
@@ -252,6 +261,28 @@ class TaskOrchestrator {
|
|
|
252
261
|
return result;
|
|
253
262
|
}
|
|
254
263
|
}
|
|
264
|
+
/**
|
|
265
|
+
* Re-hashes every file recorded in `task.hashDetails.nodes` and returns
|
|
266
|
+
* the workspace-relative paths whose post-execution hash differs from the
|
|
267
|
+
* pre-execution hash. A non-empty result means the task wrote to its own
|
|
268
|
+
* tracked inputs and the cache entry would be unsafe to persist.
|
|
269
|
+
*/
|
|
270
|
+
async #detectSelfModifiedInputs(task) {
|
|
271
|
+
const nodes = task.hashDetails?.nodes;
|
|
272
|
+
if (!nodes || typeof this.#taskHasher.rehashFile !== "function") {
|
|
273
|
+
return [];
|
|
274
|
+
}
|
|
275
|
+
const rehash = this.#taskHasher.rehashFile.bind(this.#taskHasher);
|
|
276
|
+
const entries = Object.entries(nodes);
|
|
277
|
+
const checks = await Promise.all(
|
|
278
|
+
entries.map(async ([path, priorHash]) => {
|
|
279
|
+
const absolute = resolve(this.#workspaceRoot, path);
|
|
280
|
+
const fresh = await rehash(absolute);
|
|
281
|
+
return fresh !== void 0 && fresh !== priorHash ? path : void 0;
|
|
282
|
+
})
|
|
283
|
+
);
|
|
284
|
+
return checks.filter((path) => path !== void 0);
|
|
285
|
+
}
|
|
255
286
|
async #executeTaskWithTracking(task, startTime) {
|
|
256
287
|
if (!this.#fingerprintManager) {
|
|
257
288
|
return this.#executeTask(task, startTime);
|
|
@@ -262,12 +293,18 @@ class TaskOrchestrator {
|
|
|
262
293
|
let code;
|
|
263
294
|
let terminalOutput;
|
|
264
295
|
let fingerprint;
|
|
296
|
+
let trackerAccessCount = 0;
|
|
297
|
+
let usedRealTracker = false;
|
|
298
|
+
let autoWrites;
|
|
265
299
|
const shellCommand = this.#resolveCommand?.(task);
|
|
266
300
|
const canTrack = shellCommand && this.#trackedExecutor?.isTrackingSupported;
|
|
267
301
|
if (canTrack && this.#trackedExecutor) {
|
|
268
302
|
const trackedResult = await this.#trackedExecutor.execute(task, { captureOutput: this.#captureOutput, cwd }, shellCommand);
|
|
269
303
|
code = trackedResult.code;
|
|
270
304
|
terminalOutput = trackedResult.terminalOutput;
|
|
305
|
+
trackerAccessCount = trackedResult.accesses.length;
|
|
306
|
+
usedRealTracker = true;
|
|
307
|
+
autoWrites = trackedResult.accesses.filter((a) => a.type === "write").map((a) => a.path);
|
|
271
308
|
fingerprint = await this.#fingerprintManager.createFingerprint(
|
|
272
309
|
trackedResult.accesses,
|
|
273
310
|
taskCommand,
|
|
@@ -309,10 +346,20 @@ class TaskOrchestrator {
|
|
|
309
346
|
};
|
|
310
347
|
this.#results.set(task.id, result);
|
|
311
348
|
if (code === 0 && task.cache !== false && fingerprint) {
|
|
312
|
-
const
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
349
|
+
const modified = this.#detectSelfModifiedFingerprint(fingerprint);
|
|
350
|
+
const emptyFingerprintReason = this.#describeEmptyFingerprint(fingerprint, usedRealTracker, trackerAccessCount);
|
|
351
|
+
if (modified.length > 0) {
|
|
352
|
+
result.selfModified = true;
|
|
353
|
+
this.#lifeCycle.printSelfModifyingSkip?.(task, modified);
|
|
354
|
+
} else if (emptyFingerprintReason) {
|
|
355
|
+
result.emptyFingerprint = true;
|
|
356
|
+
this.#lifeCycle.printEmptyFingerprintWarning?.(task, emptyFingerprintReason);
|
|
357
|
+
} else {
|
|
358
|
+
const hash = hashFingerprint(fingerprint);
|
|
359
|
+
Object.assign(task, { hash });
|
|
360
|
+
await this.#cache.put(hash, terminalOutput, task.outputs, code, fingerprint, autoWrites);
|
|
361
|
+
await this.#cache.setTaskIndex(task.id, hash);
|
|
362
|
+
}
|
|
316
363
|
}
|
|
317
364
|
return result;
|
|
318
365
|
} catch (error) {
|
|
@@ -321,6 +368,38 @@ class TaskOrchestrator {
|
|
|
321
368
|
return result;
|
|
322
369
|
}
|
|
323
370
|
}
|
|
371
|
+
/**
|
|
372
|
+
* In auto-fingerprint mode, returns the workspace-relative paths the
|
|
373
|
+
* task both read *and* wrote during execution. {@link FingerprintManager}
|
|
374
|
+
* populates `modifiedInputs` from the tracker's `"write"`-typed accesses;
|
|
375
|
+
* backends that don't yet emit write accesses leave it empty.
|
|
376
|
+
*/
|
|
377
|
+
// eslint-disable-next-line class-methods-use-this
|
|
378
|
+
#detectSelfModifiedFingerprint(fingerprint) {
|
|
379
|
+
return fingerprint.modifiedInputs ?? [];
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Returns a human-readable reason string when a fingerprint looks
|
|
383
|
+
* suspiciously empty (tracker ran but observed no workspace files),
|
|
384
|
+
* or `undefined` when the fingerprint is trustworthy. Caching is
|
|
385
|
+
* skipped for empty fingerprints — silently persisting one would
|
|
386
|
+
* guarantee false cache hits on every subsequent run.
|
|
387
|
+
*
|
|
388
|
+
* Only flags results from the real tracker; the glob-based fallback
|
|
389
|
+
* path legitimately produces wide fingerprints and isn't at risk.
|
|
390
|
+
*/
|
|
391
|
+
// eslint-disable-next-line class-methods-use-this
|
|
392
|
+
#describeEmptyFingerprint(fingerprint, usedRealTracker, trackerAccessCount) {
|
|
393
|
+
if (!usedRealTracker) {
|
|
394
|
+
return void 0;
|
|
395
|
+
}
|
|
396
|
+
const hasAnyAccess = Object.keys(fingerprint.fileHashes).length > 0 || Object.keys(fingerprint.directoryListings).length > 0 || fingerprint.missingFiles.length > 0;
|
|
397
|
+
if (hasAnyAccess) {
|
|
398
|
+
return void 0;
|
|
399
|
+
}
|
|
400
|
+
const zeroAccesses = trackerAccessCount === 0;
|
|
401
|
+
return zeroAccesses ? "Tracker observed no workspace file accesses — likely a static binary on a platform without strace. Caching skipped." : "Tracker returned accesses but none fell inside the workspace. Caching skipped to avoid false cache hits.";
|
|
402
|
+
}
|
|
324
403
|
#dryRunResult(task, startTime) {
|
|
325
404
|
const cacheStatus = task.hash ? `[hash: ${task.hash.slice(0, 12)}...]` : "[no hash]";
|
|
326
405
|
const result = {
|
|
@@ -23,11 +23,7 @@ class TerminalBuffer {
|
|
|
23
23
|
i = consumed;
|
|
24
24
|
continue;
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
i += 3;
|
|
28
|
-
} else {
|
|
29
|
-
i += 2;
|
|
30
|
-
}
|
|
26
|
+
i += data[i + 1] === "(" || data[i + 1] === ")" ? 3 : 2;
|
|
31
27
|
continue;
|
|
32
28
|
}
|
|
33
29
|
if (ch === "\r") {
|
|
@@ -61,7 +57,7 @@ class TerminalBuffer {
|
|
|
61
57
|
let j = start;
|
|
62
58
|
let params = "";
|
|
63
59
|
while (j < data.length && (data[j] >= "0" && data[j] <= "9" || data[j] === ";")) {
|
|
64
|
-
params += data[j];
|
|
60
|
+
params += data[j] ?? "";
|
|
65
61
|
j++;
|
|
66
62
|
}
|
|
67
63
|
if (j >= data.length) {
|
|
@@ -70,36 +66,42 @@ class TerminalBuffer {
|
|
|
70
66
|
const cmd = data[j];
|
|
71
67
|
const n = Number.parseInt(params, 10) || 1;
|
|
72
68
|
switch (cmd) {
|
|
73
|
-
case "A":
|
|
69
|
+
case "A": {
|
|
74
70
|
this.#row = Math.max(0, this.#row - n);
|
|
75
71
|
break;
|
|
76
|
-
|
|
72
|
+
}
|
|
73
|
+
case "B": {
|
|
77
74
|
this.#row = Math.min(this.#lines.length - 1, this.#row + n);
|
|
78
75
|
break;
|
|
79
|
-
|
|
76
|
+
}
|
|
77
|
+
case "C": {
|
|
80
78
|
this.#col += n;
|
|
81
79
|
break;
|
|
82
|
-
|
|
80
|
+
}
|
|
81
|
+
case "D": {
|
|
83
82
|
this.#col = Math.max(0, this.#col - n);
|
|
84
83
|
break;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
case "H":
|
|
89
|
-
// cursor position (row;col, 1-based)
|
|
90
|
-
case "f": {
|
|
84
|
+
}
|
|
85
|
+
case "f":
|
|
86
|
+
case "H": {
|
|
91
87
|
const parts = params.split(";");
|
|
92
88
|
this.#row = Math.max(0, (Number.parseInt(parts[0] ?? "1", 10) || 1) - 1);
|
|
93
89
|
this.#col = Math.max(0, (Number.parseInt(parts[1] ?? "1", 10) || 1) - 1);
|
|
94
90
|
this.#ensureRow(this.#row);
|
|
95
91
|
break;
|
|
96
92
|
}
|
|
97
|
-
case "
|
|
93
|
+
case "G": {
|
|
94
|
+
this.#col = Math.max(0, n - 1);
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
case "J": {
|
|
98
98
|
this.#eraseDisplay(Number.parseInt(params, 10) || 0);
|
|
99
99
|
break;
|
|
100
|
-
|
|
100
|
+
}
|
|
101
|
+
case "K": {
|
|
101
102
|
this.#eraseLine(Number.parseInt(params, 10) || 0);
|
|
102
103
|
break;
|
|
104
|
+
}
|
|
103
105
|
case "m": {
|
|
104
106
|
const seq = `\x1B[${params}m`;
|
|
105
107
|
this.#ensureRow(this.#row);
|
|
@@ -161,30 +163,44 @@ class TerminalBuffer {
|
|
|
161
163
|
this.#lines[this.#row] = line.slice(0, strIndex) + seq + line.slice(strIndex);
|
|
162
164
|
}
|
|
163
165
|
#eraseDisplay(mode) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
166
|
+
switch (mode) {
|
|
167
|
+
case 0: {
|
|
168
|
+
this.#ensureRow(this.#row);
|
|
169
|
+
this.#truncateLineAtCol(this.#row, this.#col);
|
|
170
|
+
this.#lines.length = this.#row + 1;
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
case 1: {
|
|
174
|
+
for (let r = 0; r < this.#row; r++) {
|
|
175
|
+
this.#lines[r] = "";
|
|
176
|
+
}
|
|
177
|
+
this.#ensureRow(this.#row);
|
|
178
|
+
this.#fillLineToCol(this.#row, this.#col);
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
case 2: {
|
|
182
|
+
this.#lines = [""];
|
|
183
|
+
this.#row = 0;
|
|
184
|
+
this.#col = 0;
|
|
185
|
+
break;
|
|
175
186
|
}
|
|
176
|
-
this.#ensureRow(this.#row);
|
|
177
|
-
this.#fillLineToCol(this.#row, this.#col);
|
|
178
187
|
}
|
|
179
188
|
}
|
|
180
189
|
#eraseLine(mode) {
|
|
181
190
|
this.#ensureRow(this.#row);
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
191
|
+
switch (mode) {
|
|
192
|
+
case 0: {
|
|
193
|
+
this.#truncateLineAtCol(this.#row, this.#col);
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
case 1: {
|
|
197
|
+
this.#fillLineToCol(this.#row, this.#col);
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
case 2: {
|
|
201
|
+
this.#lines[this.#row] = "";
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
188
204
|
}
|
|
189
205
|
}
|
|
190
206
|
/** Truncate a line at the given visual column. */
|
package/dist/packem_shared/{TrackedTaskExecutor-BGUKFE-7.js → TrackedTaskExecutor-CFPpQfXF.js}
RENAMED
|
@@ -27,7 +27,7 @@ const {
|
|
|
27
27
|
rm
|
|
28
28
|
} = __cjs_getBuiltinModule("node:fs/promises");
|
|
29
29
|
import { join } from '@visulima/path';
|
|
30
|
-
import { FileAccessTracker, generatePreloadScript } from './FileAccessTracker-
|
|
30
|
+
import { FileAccessTracker, generatePreloadScript } from './FileAccessTracker-CQ5Ot7Hd.js';
|
|
31
31
|
import { u as uniqueId } from './utils-zO0ZRgtf.js';
|
|
32
32
|
|
|
33
33
|
class TrackedTaskExecutor {
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
+
|
|
7
|
+
const __cjs_getBuiltinModule = (module) => {
|
|
8
|
+
// Check if we're in Node.js and version supports getBuiltinModule
|
|
9
|
+
if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
|
|
10
|
+
const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
|
|
11
|
+
// Node.js 20.16.0+ and 22.3.0+
|
|
12
|
+
if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
|
|
13
|
+
return __cjs_getProcess.getBuiltinModule(module);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// Fallback to createRequire
|
|
17
|
+
return __cjs_require(module);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
execFile
|
|
22
|
+
} = __cjs_getBuiltinModule("node:child_process");
|
|
23
|
+
const {
|
|
24
|
+
createReadStream,
|
|
25
|
+
createWriteStream
|
|
26
|
+
} = __cjs_getBuiltinModule("node:fs");
|
|
27
|
+
const {
|
|
28
|
+
rm
|
|
29
|
+
} = __cjs_getBuiltinModule("node:fs/promises");
|
|
30
|
+
const {
|
|
31
|
+
pipeline
|
|
32
|
+
} = __cjs_getBuiltinModule("node:stream/promises");
|
|
33
|
+
const {
|
|
34
|
+
createBrotliDecompress,
|
|
35
|
+
createBrotliCompress,
|
|
36
|
+
constants
|
|
37
|
+
} = __cjs_getBuiltinModule("node:zlib");
|
|
38
|
+
|
|
39
|
+
const BROTLI_COMPRESS_OPTIONS = {
|
|
40
|
+
params: {
|
|
41
|
+
[constants.BROTLI_PARAM_MODE]: constants.BROTLI_MODE_TEXT,
|
|
42
|
+
[constants.BROTLI_PARAM_QUALITY]: 4
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const createTar = (sourceDirectory, outputPath) => new Promise((resolve, reject) => {
|
|
46
|
+
execFile("tar", ["-cf", outputPath, "-C", sourceDirectory, "."], (error) => {
|
|
47
|
+
if (error) {
|
|
48
|
+
reject(error);
|
|
49
|
+
} else {
|
|
50
|
+
resolve();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
const extractTar = (archivePath, destinationDirectory) => new Promise((resolve, reject) => {
|
|
55
|
+
execFile("tar", ["-xf", archivePath, "-C", destinationDirectory], (error) => {
|
|
56
|
+
if (error) {
|
|
57
|
+
reject(error);
|
|
58
|
+
} else {
|
|
59
|
+
resolve();
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
const createTarGz = (sourceDirectory, outputPath) => new Promise((resolve, reject) => {
|
|
64
|
+
execFile("tar", ["-czf", outputPath, "-C", sourceDirectory, "."], (error) => {
|
|
65
|
+
if (error) {
|
|
66
|
+
reject(error);
|
|
67
|
+
} else {
|
|
68
|
+
resolve();
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
const extractTarGz = (archivePath, destinationDirectory) => new Promise((resolve, reject) => {
|
|
73
|
+
execFile("tar", ["-xzf", archivePath, "-C", destinationDirectory], (error) => {
|
|
74
|
+
if (error) {
|
|
75
|
+
reject(error);
|
|
76
|
+
} else {
|
|
77
|
+
resolve();
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
const createTarBrotli = async (sourceDirectory, outputPath) => {
|
|
82
|
+
const tarPath = `${outputPath}.tar`;
|
|
83
|
+
try {
|
|
84
|
+
await createTar(sourceDirectory, tarPath);
|
|
85
|
+
await pipeline(createReadStream(tarPath), createBrotliCompress(BROTLI_COMPRESS_OPTIONS), createWriteStream(outputPath));
|
|
86
|
+
} finally {
|
|
87
|
+
await rm(tarPath, { force: true }).catch(() => {
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const extractTarBrotli = async (archivePath, destinationDirectory) => {
|
|
92
|
+
const tarPath = `${archivePath}.tar`;
|
|
93
|
+
try {
|
|
94
|
+
await pipeline(createReadStream(archivePath), createBrotliDecompress(), createWriteStream(tarPath));
|
|
95
|
+
await extractTar(tarPath, destinationDirectory);
|
|
96
|
+
} finally {
|
|
97
|
+
await rm(tarPath, { force: true }).catch(() => {
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export { extractTarGz as a, createTarGz as b, createTarBrotli as c, extractTarBrotli as e };
|
|
@@ -22,8 +22,10 @@ const {
|
|
|
22
22
|
} = __cjs_getBuiltinModule("node:child_process");
|
|
23
23
|
|
|
24
24
|
const validateGitRef = (ref) => {
|
|
25
|
-
if (!/^[\w.\-/~^@{}]
|
|
26
|
-
throw new Error(
|
|
25
|
+
if (!/^[\w./~^@{}][\w.\-/~^@{}]*$/.test(ref)) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
`Invalid git ref: "${ref}". Refs must start with an alphanumeric character or one of _ . / ~ ^ @ { } and may only contain letters, digits, dots, dashes, underscores, slashes, tildes, carets, @, and braces.`
|
|
28
|
+
);
|
|
27
29
|
}
|
|
28
30
|
};
|
|
29
31
|
const findProjectForFile = (filePath, projects) => {
|
|
@@ -31,7 +33,8 @@ const findProjectForFile = (filePath, projects) => {
|
|
|
31
33
|
let bestLength = 0;
|
|
32
34
|
for (const [name, config] of Object.entries(projects)) {
|
|
33
35
|
const { root } = config;
|
|
34
|
-
if ((filePath.startsWith(`${root}/`) || filePath === root) &&
|
|
36
|
+
if ((filePath.startsWith(`${root}/`) || filePath === root) && // Prefer the most specific (longest) match
|
|
37
|
+
root.length > bestLength) {
|
|
35
38
|
bestMatch = name;
|
|
36
39
|
bestLength = root.length;
|
|
37
40
|
}
|