real-size 0.1.0 → 0.1.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.
- package/README.md +49 -14
- package/index.d.mts +17 -4
- package/index.mjs +21 -2
- package/package.json +2 -2
- package/prebuilds/darwin-arm64/real-size +0 -0
- package/prebuilds/darwin-x64/real-size +0 -0
- package/prebuilds/linux-arm64/real-size +0 -0
- package/prebuilds/linux-x64/real-size +0 -0
- package/prebuilds/win32-arm64/real-size.exe +0 -0
- package/prebuilds/win32-x64/real-size.exe +0 -0
- package/skill/SKILL.md +7 -2
package/README.md
CHANGED
|
@@ -71,7 +71,7 @@ prints the version and the binary's platform, for example `0.1.0
|
|
|
71
71
|
## Command line
|
|
72
72
|
|
|
73
73
|
```text
|
|
74
|
-
real-size [--json] <path>...
|
|
74
|
+
real-size [--json] [--no-progress] <path>...
|
|
75
75
|
```
|
|
76
76
|
|
|
77
77
|
Each path is measured on its own. Plain output prints one line per path, and a
|
|
@@ -97,23 +97,54 @@ that is not exact.
|
|
|
97
97
|
"allocated": 4767227904,
|
|
98
98
|
"private": 90292224,
|
|
99
99
|
"files": 168433,
|
|
100
|
-
"exact": false
|
|
100
|
+
"exact": false,
|
|
101
|
+
"skipped": 0
|
|
101
102
|
}
|
|
102
103
|
],
|
|
103
104
|
"total": {
|
|
104
105
|
"allocated": 4767227904,
|
|
105
106
|
"private": 90292224,
|
|
106
107
|
"files": 168433,
|
|
107
|
-
"exact": false
|
|
108
|
+
"exact": false,
|
|
109
|
+
"skipped": 0
|
|
108
110
|
}
|
|
109
111
|
}
|
|
110
112
|
```
|
|
111
113
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
114
|
+
### Errors and exit status
|
|
115
|
+
|
|
116
|
+
An entry below a path that cannot be read, such as a directory without read
|
|
117
|
+
permission, is skipped and the walk goes on. Each one is named on stderr with
|
|
118
|
+
its own path, relative to the path as given, and the reason, up to ten lines;
|
|
119
|
+
the rest are counted in a last line:
|
|
120
|
+
|
|
121
|
+
```console
|
|
122
|
+
$ real-size ~/Library
|
|
123
|
+
real-size: /Users/me/Library/Mail: Operation not permitted
|
|
124
|
+
real-size: and 3 more entries could not be read
|
|
125
|
+
/Users/me/Library: at least 2.1 GB private, 9.8 GB allocated, 210377 files (4 entries could not be read)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
The sizes are then lower bounds: `skipped` counts the entries left out and
|
|
129
|
+
`exact` is `false`. Like `du`, the command prints the result and exits with
|
|
130
|
+
status 1. An entry deleted while the walk runs is not an error: it frees
|
|
131
|
+
nothing, so it is left out without a message and does not count in `skipped`.
|
|
132
|
+
|
|
133
|
+
| Exit status | Meaning |
|
|
134
|
+
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
135
|
+
| 0 | Every path was measured in full. |
|
|
136
|
+
| 1 | Some entries could not be read: the result is on stdout with `skipped` above 0. Or a usage error, or a path itself could not be read: the reason is on stderr, stdout is empty. |
|
|
137
|
+
| 2 | The filesystem cannot report what deleting a path would free. Stdout is empty. |
|
|
138
|
+
|
|
139
|
+
With exit status 1, a result on stdout tells the two cases apart.
|
|
140
|
+
|
|
141
|
+
### Progress
|
|
142
|
+
|
|
143
|
+
When stderr is a terminal and a walk has run for more than two seconds,
|
|
144
|
+
`real-size` shows one status line on stderr with the files counted so far and
|
|
145
|
+
the directory it is in, and clears it before printing the result. It shows
|
|
146
|
+
nothing when stderr is not a terminal, so pipes, scripts and the library never
|
|
147
|
+
see it. `--no-progress` turns it off.
|
|
117
148
|
|
|
118
149
|
`--version` prints the version and `--help` prints usage.
|
|
119
150
|
|
|
@@ -136,8 +167,12 @@ the promise rejects at once. It rejects with a `RealSizeError` whose `code` is:
|
|
|
136
167
|
|
|
137
168
|
- `unsupported`: no prebuilt binary for this platform, or exit status 2.
|
|
138
169
|
- `timeout`: `timeoutMs` ran out.
|
|
139
|
-
- `failed`: exit status 1
|
|
140
|
-
binary's error.
|
|
170
|
+
- `failed`: exit status 1 without a result (a path that cannot be read) or the
|
|
171
|
+
binary could not start. `message` holds the binary's error.
|
|
172
|
+
|
|
173
|
+
When some entries below a path could not be read, the promise resolves with
|
|
174
|
+
the result and `total.skipped` above 0, rather than rejecting. Version 0.1.0
|
|
175
|
+
rejected the whole measurement instead.
|
|
141
176
|
|
|
142
177
|
An aborted `signal` rejects with the signal's reason.
|
|
143
178
|
|
|
@@ -155,6 +190,8 @@ TypeScript types are included. Node `^20.19.4 || >=22.12.0`.
|
|
|
155
190
|
- `files`: the regular files counted, each hard-linked file once.
|
|
156
191
|
- `exact`: `true` when `private` is the exact answer, `false` when it is a
|
|
157
192
|
lower bound.
|
|
193
|
+
- `skipped`: entries that could not be read and were left out. Above 0, every
|
|
194
|
+
size is a lower bound and `exact` is `false`. Added in 0.1.1.
|
|
158
195
|
|
|
159
196
|
Directories, symbolic links and metadata are not counted. Symbolic links are
|
|
160
197
|
never followed, and neither are Windows junctions.
|
|
@@ -279,10 +316,8 @@ on APFS, the extent map on btrfs and XFS, and the link count on Windows.
|
|
|
279
316
|
- Each path is measured on its own and the total is their sum. Two paths that
|
|
280
317
|
hard-link or clone each other's files each report those bytes as shared, so
|
|
281
318
|
the total can be lower than what deleting both would free.
|
|
282
|
-
- The
|
|
283
|
-
|
|
284
|
-
- A path that cannot be read, such as a directory without read permission,
|
|
285
|
-
exits with status 1 rather than reporting a partial size.
|
|
319
|
+
- The walks stop at 256 nested directories; a deeper directory is skipped and
|
|
320
|
+
counted in `skipped`.
|
|
286
321
|
- Files changed during the walk may be counted in either state.
|
|
287
322
|
- The plain output's sizes are rounded; use `--json` for bytes.
|
|
288
323
|
- On Linux, filesystems other than ext2/3/4, tmpfs, btrfs and XFS exit with
|
package/index.d.mts
CHANGED
|
@@ -5,8 +5,17 @@ export interface TreeSize {
|
|
|
5
5
|
private: number;
|
|
6
6
|
/** Regular files, each counted once however many links it has in the tree. */
|
|
7
7
|
files: number;
|
|
8
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* False when `private` is a lower bound: some counted file shares blocks with another file, or some entries could
|
|
10
|
+
* not be read (`skipped` above 0).
|
|
11
|
+
*/
|
|
9
12
|
exact: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Entries the walk could not read, for example a directory without read permission, and left out of every other
|
|
15
|
+
* field. When above 0 every size is a lower bound; the binary names the entries on stderr and exits with status 1.
|
|
16
|
+
* Entries deleted during the walk are not counted here.
|
|
17
|
+
*/
|
|
18
|
+
skipped: number;
|
|
10
19
|
}
|
|
11
20
|
|
|
12
21
|
export interface PathSize extends TreeSize {
|
|
@@ -38,15 +47,19 @@ export declare class RealSizeError extends Error {
|
|
|
38
47
|
readonly name: "RealSizeError";
|
|
39
48
|
/**
|
|
40
49
|
* `unsupported`: no prebuilt binary for this platform, or the filesystem cannot report the bytes deleting the path
|
|
41
|
-
* would free (exit status 2). `timeout`: `timeoutMs` ran out. `failed`: a usage or
|
|
42
|
-
* binary could not run.
|
|
50
|
+
* would free (exit status 2). `timeout`: `timeoutMs` ran out. `failed`: a usage error or a path that cannot be read (exit
|
|
51
|
+
* status 1 without a result), or the binary could not run.
|
|
43
52
|
*/
|
|
44
53
|
readonly code: RealSizeErrorCode;
|
|
45
54
|
/** The binary's exit status, null when it did not exit on its own. */
|
|
46
55
|
readonly exitCode: number | null;
|
|
47
56
|
}
|
|
48
57
|
|
|
49
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* Measures each directory in its own walk, run in a child process. Resolves when every path was measured, including
|
|
60
|
+
* when some entries below a path could not be read (`total.skipped` above 0). Rejects when a path itself cannot be
|
|
61
|
+
* read.
|
|
62
|
+
*/
|
|
50
63
|
export declare function realSize(
|
|
51
64
|
paths: string | readonly string[],
|
|
52
65
|
options?: RealSizeOptions,
|
package/index.mjs
CHANGED
|
@@ -91,8 +91,13 @@ export function realSize(paths, options = {}) {
|
|
|
91
91
|
);
|
|
92
92
|
child.on("close", (exitCode, exitSignal) =>
|
|
93
93
|
finish(() => {
|
|
94
|
-
const message = stderr.trim().
|
|
95
|
-
|
|
94
|
+
const message = (stderr.trim().split(/\r?\n/).at(-1) ?? "").replace(
|
|
95
|
+
/^real-size: /,
|
|
96
|
+
"",
|
|
97
|
+
);
|
|
98
|
+
const partial = exitCode === 1 ? parsePartial(stdout) : null;
|
|
99
|
+
if (partial) resolve(partial);
|
|
100
|
+
else if (exitCode === 0) {
|
|
96
101
|
try {
|
|
97
102
|
resolve(JSON.parse(stdout));
|
|
98
103
|
} catch (error) {
|
|
@@ -117,3 +122,17 @@ export function realSize(paths, options = {}) {
|
|
|
117
122
|
);
|
|
118
123
|
});
|
|
119
124
|
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Exit status 1 with a document on stdout means some entries could not be read and were skipped.
|
|
128
|
+
* @param {string} stdout
|
|
129
|
+
* @returns {import("./index.d.mts").RealSizeResult | null}
|
|
130
|
+
*/
|
|
131
|
+
function parsePartial(stdout) {
|
|
132
|
+
try {
|
|
133
|
+
const result = JSON.parse(stdout);
|
|
134
|
+
return result?.total?.skipped > 0 ? result : null;
|
|
135
|
+
} catch {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "real-size",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "The bytes deleting a folder would actually free, on APFS clones, hard links and reflinks",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"license": "MIT",
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "node scripts/build.mjs",
|
|
51
|
-
"test": "node --test --test-concurrency=1 test/cli.test.mjs test/api.test.mjs test/launcher.test.mjs test/darwin.test.mjs test/linux.test.mjs test/windows.test.mjs test/package.test.mjs",
|
|
51
|
+
"test": "node --test --test-concurrency=1 test/cli.test.mjs test/errors.test.mjs test/api.test.mjs test/launcher.test.mjs test/darwin.test.mjs test/linux.test.mjs test/windows.test.mjs test/package.test.mjs",
|
|
52
52
|
"test:package": "node scripts/package-smoke.mjs",
|
|
53
53
|
"pack:release": "node scripts/pack-release.mjs",
|
|
54
54
|
"typecheck": "tsc",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/skill/SKILL.md
CHANGED
|
@@ -19,9 +19,14 @@ Fields:
|
|
|
19
19
|
- `allocated`: bytes the tree's files occupy on disk, each file counted once.
|
|
20
20
|
- `private`: bytes deleting the tree would free. Report this one as reclaimable.
|
|
21
21
|
- `files`: regular files counted.
|
|
22
|
-
- `exact`: `false` means `private` is a lower bound: some file shares blocks with another file, possibly one inside the same tree,
|
|
22
|
+
- `exact`: `false` means `private` is a lower bound: some file shares blocks with another file, possibly one inside the same tree, or some entries could not be read. Deleting the whole tree may free more. Say "at least".
|
|
23
|
+
- `skipped`: entries that could not be read (no permission, an I/O error, nesting deeper than 256 directories) and were left out of every number.
|
|
23
24
|
|
|
24
|
-
Exit status
|
|
25
|
+
Exit status 1 with a result on stdout means some entries were skipped: stderr names each one with its reason (the first ten, then a count). Still use the result: report `private` as "at least", give the number of entries that could not be read and the paths stderr names, and suggest rerunning with the needed permissions if the user wants the full figure. Exit status 1 with nothing on stdout is a usage error or a path that cannot be read at all, with the reason on stderr.
|
|
26
|
+
|
|
27
|
+
Exit status 2 means the filesystem cannot report this (for example NFS, overlayfs, a network share, or a non-APFS volume on macOS). Then say real-size cannot tell on this filesystem, fall back to `du -sh`, and present that number as an upper bound.
|
|
28
|
+
|
|
29
|
+
Entries deleted while the walk runs are left out without a message; they free nothing.
|
|
25
30
|
|
|
26
31
|
Example, a pnpm worktree's `node_modules` on macOS:
|
|
27
32
|
|