@intx/tool-packaging 0.2.2
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/LICENSE +176 -0
- package/README.md +116 -0
- package/dist/atomic-apply.d.ts +65 -0
- package/dist/atomic-apply.js +223 -0
- package/dist/cache.d.ts +89 -0
- package/dist/cache.js +750 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +30 -0
- package/dist/loader.d.ts +189 -0
- package/dist/loader.js +1387 -0
- package/dist/package-json-extract.d.ts +56 -0
- package/dist/package-json-extract.js +125 -0
- package/dist/resolver.d.ts +241 -0
- package/dist/resolver.js +821 -0
- package/package.json +39 -0
package/dist/cache.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export interface TarballCacheConfig {
|
|
2
|
+
readonly rootDir: string;
|
|
3
|
+
readonly maxBytes: number;
|
|
4
|
+
}
|
|
5
|
+
export interface TarballCache {
|
|
6
|
+
get(integrity: string): Promise<Uint8Array | null>;
|
|
7
|
+
/**
|
|
8
|
+
* Presence probe. Returns true when an entry for `integrity` is
|
|
9
|
+
* resident on disk. Cheaper than `get` for callers that only need
|
|
10
|
+
* to decide whether a fetch is required — `has` checks file
|
|
11
|
+
* existence without reading bytes or touching atime.
|
|
12
|
+
*/
|
|
13
|
+
has(integrity: string): Promise<boolean>;
|
|
14
|
+
put(integrity: string, bytes: Uint8Array): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Mark the cache entry for `integrity` as poisoned and remove its
|
|
17
|
+
* tarball bytes immediately so a subsequent `extractTarball` call
|
|
18
|
+
* cannot reuse the on-disk extraction. The extraction directory's
|
|
19
|
+
* physical reclaim is deferred until every in-flight reader released
|
|
20
|
+
* by `extractTarball` has dropped its reference, so an evict that
|
|
21
|
+
* races a concurrent `hardlinkTree` walk of the same extraction does
|
|
22
|
+
* not pull the tree out from under the walk and surface as ENOENT.
|
|
23
|
+
*
|
|
24
|
+
* Until every reader releases, the on-disk extraction is left in
|
|
25
|
+
* place but is no longer reachable via a fresh `extractTarball`
|
|
26
|
+
* (because the tarball blob is gone). Callers that need the bytes
|
|
27
|
+
* back must re-fetch and `put` them, which will trigger a fresh
|
|
28
|
+
* extraction into a new directory once the deferred reclaim
|
|
29
|
+
* completes.
|
|
30
|
+
*/
|
|
31
|
+
evict(integrity: string): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Unpack the cached tarball for `integrity` into a content-addressable
|
|
34
|
+
* extraction directory and return its absolute path along with a
|
|
35
|
+
* `release` callback the caller MUST invoke when it is done walking
|
|
36
|
+
* the directory. The directory is reference-counted: a concurrent
|
|
37
|
+
* `evict` for the same integrity defers the physical removal of the
|
|
38
|
+
* extraction tree until every outstanding `release` has been called.
|
|
39
|
+
*
|
|
40
|
+
* The same path is returned on subsequent calls without re-extracting;
|
|
41
|
+
* concurrent callers for the same integrity each get a path to a
|
|
42
|
+
* fully-populated directory and each get their own `release` handle.
|
|
43
|
+
*
|
|
44
|
+
* Throws if `integrity` is not present in the cache; callers must
|
|
45
|
+
* `put` (or otherwise materialize) the bytes first.
|
|
46
|
+
*/
|
|
47
|
+
extractTarball(integrity: string): Promise<{
|
|
48
|
+
readonly dir: string;
|
|
49
|
+
readonly release: () => void;
|
|
50
|
+
}>;
|
|
51
|
+
/**
|
|
52
|
+
* Walk the cache tree and remove any staged tmp paths left behind
|
|
53
|
+
* by a `put` or `extractTarball` that crashed between staging and
|
|
54
|
+
* the final rename. Callers should invoke this once at sidecar
|
|
55
|
+
* boot, before any apply runs. Idempotent: a no-op if the tree
|
|
56
|
+
* holds no orphans.
|
|
57
|
+
*
|
|
58
|
+
* Orphans take the shape `<entryDir>/tarball.tgz.tmp.<pid>.<rand>`
|
|
59
|
+
* (from `put`) and `<entryDir>/extracted.tmp.<pid>.<rand>` (from
|
|
60
|
+
* `extractTarball`). The single-process contract means a tmp path
|
|
61
|
+
* surviving across boots cannot be in use by another process; it
|
|
62
|
+
* is always safe to remove.
|
|
63
|
+
*/
|
|
64
|
+
sweepOrphans(): Promise<void>;
|
|
65
|
+
/** Test-only: total bytes currently stored. */
|
|
66
|
+
size(): Promise<number>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Thrown by `put` when supplied bytes do not match the supplied
|
|
70
|
+
* integrity. The cache never stores bytes that fail this check.
|
|
71
|
+
*/
|
|
72
|
+
export declare class TarballIntegrityMismatchError extends Error {
|
|
73
|
+
readonly integrity: string;
|
|
74
|
+
constructor(integrity: string);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Construct a TarballCache rooted at `config.rootDir`.
|
|
78
|
+
*
|
|
79
|
+
* **Single-process contract.** Pointing two sidecar processes at the
|
|
80
|
+
* same cache root is unsupported. The pid-prefixed staging path is
|
|
81
|
+
* decorative for intra-process races — it keeps two concurrent puts
|
|
82
|
+
* in the same process from clobbering each other's tmp files — but
|
|
83
|
+
* cross-process races on the same integrity can still collide during
|
|
84
|
+
* the final rename (one process moves the staged file into place, the
|
|
85
|
+
* other's rename overwrites or fails depending on the platform's
|
|
86
|
+
* rename-over-existing semantics). The atomicity guarantees in this
|
|
87
|
+
* module assume a single owning process per `rootDir`.
|
|
88
|
+
*/
|
|
89
|
+
export declare function createTarballCache(config: TarballCacheConfig): TarballCache;
|