size-report 3.2.0__py3-none-any.whl
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.
- size_report/__init__.py +7 -0
- size_report/__main__.py +6 -0
- size_report/cli.py +26 -0
- size_report/js/LICENSE +21 -0
- size_report/js/bin/size.js +6 -0
- size_report/js/package.json +81 -0
- size_report/js/src/args.js +277 -0
- size_report/js/src/artifact.js +66 -0
- size_report/js/src/check.js +139 -0
- size_report/js/src/cli.js +102 -0
- size_report/js/src/config.js +354 -0
- size_report/js/src/css.js +28 -0
- size_report/js/src/data.js +113 -0
- size_report/js/src/derived.js +150 -0
- size_report/js/src/diff.js +77 -0
- size_report/js/src/doctor.js +297 -0
- size_report/js/src/explain.js +139 -0
- size_report/js/src/filter.js +41 -0
- size_report/js/src/git.js +366 -0
- size_report/js/src/history.js +270 -0
- size_report/js/src/hook.js +385 -0
- size_report/js/src/init.js +230 -0
- size_report/js/src/journal.js +68 -0
- size_report/js/src/locales.js +143 -0
- size_report/js/src/log.js +78 -0
- size_report/js/src/metrics.js +252 -0
- size_report/js/src/minify.js +94 -0
- size_report/js/src/modes.js +197 -0
- size_report/js/src/now.js +49 -0
- size_report/js/src/optional.js +33 -0
- size_report/js/src/page/app.css +268 -0
- size_report/js/src/page/app.js +205 -0
- size_report/js/src/page/build.js +273 -0
- size_report/js/src/page/dom.js +35 -0
- size_report/js/src/page/panel.js +293 -0
- size_report/js/src/page/payload.js +168 -0
- size_report/js/src/page/state.js +285 -0
- size_report/js/src/page/table.js +440 -0
- size_report/js/src/parse-worker.js +34 -0
- size_report/js/src/parse.js +134 -0
- size_report/js/src/pathtree.js +61 -0
- size_report/js/src/project.js +327 -0
- size_report/js/src/query.js +124 -0
- size_report/js/src/refusal.js +163 -0
- size_report/js/src/revs.js +54 -0
- size_report/js/src/size-table.js +59 -0
- size_report/js/src/snapshot.js +88 -0
- size_report/js/src/strip/forms.js +29 -0
- size_report/js/src/strip/guard.js +115 -0
- size_report/js/src/strip/js.js +136 -0
- size_report/js/src/strip/py.js +277 -0
- size_report/js/src/strip/python-guard-worker.js +94 -0
- size_report/js/src/strip.js +56 -0
- size_report/js/src/table.css +144 -0
- size_report/js/src/textable.js +31 -0
- size_report/js/src/tiktoken-bridge-worker.js +107 -0
- size_report/js/src/tokens.js +215 -0
- size_report/js/src/toml.js +296 -0
- size_report/js/src/tool.js +37 -0
- size_report/js/templates/README.md +134 -0
- size_report/js/templates/ci-python.yml +71 -0
- size_report/js/templates/ci.yml +68 -0
- size_report/js/templates/size-report.config.json +53 -0
- size_report/runtime.py +259 -0
- size_report/tiktoken_worker.py +156 -0
- size_report-3.2.0.dist-info/METADATA +107 -0
- size_report-3.2.0.dist-info/RECORD +71 -0
- size_report-3.2.0.dist-info/WHEEL +5 -0
- size_report-3.2.0.dist-info/entry_points.txt +3 -0
- size_report-3.2.0.dist-info/licenses/LICENSE +21 -0
- size_report-3.2.0.dist-info/top_level.txt +1 -0
size_report/__init__.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"""The Python distribution of `size-report`.
|
|
2
|
+
|
|
3
|
+
The engine is JavaScript; this package is a thin launcher for it. Keeping this module free of imports
|
|
4
|
+
means `import size_report` stays cheap and cannot fail because a Node runtime is missing.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
__version__ = "3.2.0"
|
size_report/__main__.py
ADDED
size_report/cli.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""The console-script entry point: find the engine and a Node runtime, then get out of the way.
|
|
2
|
+
|
|
3
|
+
Everything the engine says is handed to the same file descriptors, with the same encoding and the same
|
|
4
|
+
exit code. This module does not parse flags, print results or interpret them: a second parser here would
|
|
5
|
+
drift from `--help` in `src/`.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import sys
|
|
9
|
+
|
|
10
|
+
from .runtime import LAUNCH_EXIT, LaunchError, engine_script, node_binary, run
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def main(argv=None):
|
|
14
|
+
"""Return the engine's exit code, or `LAUNCH_EXIT` when the launcher itself could not start it.
|
|
15
|
+
|
|
16
|
+
The engine's codes 0..5 are verdicts about the project; a launcher failure is not one of them, so it
|
|
17
|
+
gets a code of its own rather than borrowing a verdict (and lying about what was checked).
|
|
18
|
+
"""
|
|
19
|
+
args = list(sys.argv[1:] if argv is None else argv)
|
|
20
|
+
try:
|
|
21
|
+
engine = engine_script()
|
|
22
|
+
node = node_binary()
|
|
23
|
+
return run(node, engine, args)
|
|
24
|
+
except LaunchError as exc:
|
|
25
|
+
sys.stderr.write("size: " + str(exc) + "\n")
|
|
26
|
+
return LAUNCH_EXIT
|
size_report/js/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 vernikr
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vernikr/size-report",
|
|
3
|
+
"version": "3.2.0",
|
|
4
|
+
"author": "vernikr",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/vernikr/size-report.git"
|
|
8
|
+
},
|
|
9
|
+
"description": "Tracking how the volume of code and documents grows across git history: raw / min / tokens; the report is one self-contained file written where you name it",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"packageManager": "pnpm@10.6.1",
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=20.19"
|
|
15
|
+
},
|
|
16
|
+
"bin": {
|
|
17
|
+
"size": "bin/size.js"
|
|
18
|
+
},
|
|
19
|
+
"exports": {
|
|
20
|
+
".": "./src/size-table.js"
|
|
21
|
+
},
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"bin",
|
|
27
|
+
"src",
|
|
28
|
+
"templates",
|
|
29
|
+
"README.md",
|
|
30
|
+
"LICENSE"
|
|
31
|
+
],
|
|
32
|
+
"sideEffects": false,
|
|
33
|
+
"scripts": {
|
|
34
|
+
"test": "node tools/run-tests.js fast",
|
|
35
|
+
"test:all": "node tools/run-tests.js full",
|
|
36
|
+
"suites:measure": "node tools/run-tests.js measure",
|
|
37
|
+
"lint": "eslint . || true",
|
|
38
|
+
"lint:strict": "eslint .",
|
|
39
|
+
"parity": "node tools/parity-freeze.js",
|
|
40
|
+
"parity:live": "node tools/parity-live.js",
|
|
41
|
+
"pack:check": "node tools/pack-check.js",
|
|
42
|
+
"wheel:build": "node tools/build-wheel.js",
|
|
43
|
+
"wheel:check": "node tools/build-wheel.js --check",
|
|
44
|
+
"check:standards": "node tools/check-standards.js",
|
|
45
|
+
"fixture": "node tools/make-fixture.js",
|
|
46
|
+
"verify:fast": "node tools/gates/run.js fast",
|
|
47
|
+
"verify": "node tools/gates/run.js full",
|
|
48
|
+
"verify:slow": "node tools/gates/run.js slow",
|
|
49
|
+
"metrics": "node tools/gates/metrics.js",
|
|
50
|
+
"dup": "node tools/gates/dup.js",
|
|
51
|
+
"dup:ci": "node tools/gates/dup.js --ref origin/main",
|
|
52
|
+
"dup:baseline": "node tools/gates/dup.js --update",
|
|
53
|
+
"deps": "node tools/gates/deps.js",
|
|
54
|
+
"cover": "node tools/gates/coverage.js",
|
|
55
|
+
"gate:files": "node tools/gates/gatefiles.js",
|
|
56
|
+
"baseline:metrics": "eslint --config eslint.metrics.config.js --suppressions-location .eslint-suppressions.json --prune-suppressions src bin tools test && eslint --config eslint.metrics.config.js --suppressions-location .eslint-suppressions.json --suppress-all src bin tools test",
|
|
57
|
+
"baseline:dup": "node tools/gates/dup.js --update",
|
|
58
|
+
"baseline:coverage": "node tools/gates/coverage.js --update",
|
|
59
|
+
"hooks:install": "git config core.hooksPath .githooks"
|
|
60
|
+
},
|
|
61
|
+
"keywords": [
|
|
62
|
+
"size",
|
|
63
|
+
"tokens",
|
|
64
|
+
"minify",
|
|
65
|
+
"git-history",
|
|
66
|
+
"report"
|
|
67
|
+
],
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@vernikr/size-report": "3.0.2",
|
|
70
|
+
"c8": "10",
|
|
71
|
+
"dependency-cruiser": "17",
|
|
72
|
+
"eslint": "^9.18.0",
|
|
73
|
+
"eslint-plugin-sonarjs": "4",
|
|
74
|
+
"jscpd": "5.2.0",
|
|
75
|
+
"jsdom": "~26"
|
|
76
|
+
},
|
|
77
|
+
"optionalDependencies": {
|
|
78
|
+
"esbuild": "0.28.2",
|
|
79
|
+
"gpt-tokenizer": "4.0.0"
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { cliCommand, advicePath, refuseCause } from './refusal.js';
|
|
2
|
+
|
|
3
|
+
/* Command-line grammar: what the user named, and whether that combination is legal.
|
|
4
|
+
*
|
|
5
|
+
* One parse, at the entry, before the project is read. It settles everything at once —
|
|
6
|
+
* which mode was asked for, whether it fits the command and the other flags, whether every
|
|
7
|
+
* flag got a value, whether there are extra words — and answers with either a plan or a
|
|
8
|
+
* refusal. That is why the order of branches in `main` decides nothing: "you cannot do
|
|
9
|
+
* that" is a value, not a place in the code, and it surfaces in one way only — as a refusal
|
|
10
|
+
* naming the culprit and the command that fixes it.
|
|
11
|
+
*
|
|
12
|
+
* Flags come in three kinds: modes (mutually exclusive — they say what to do), value flags
|
|
13
|
+
* (they take the next argument) and switches. A command is the first word outside the
|
|
14
|
+
* flags, so its position in the line does not matter: `size check --config x` and
|
|
15
|
+
* `size --config x check` are the same.
|
|
16
|
+
*
|
|
17
|
+
* The file is separate from `cli.js` because the questions differ: here "what was asked and
|
|
18
|
+
* may it be so", there "what to do about it". Hence the price of a wrong rule here — it
|
|
19
|
+
* breaks every mode at once — and hence the checks split by subject, with the refusal
|
|
20
|
+
* catalogue (`tools/refusals.js`) counting their sites in the sources and demanding a test
|
|
21
|
+
* for each.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const MODES = ['--init', '--write', '--data'];
|
|
25
|
+
/* The flags of `diff`, `now` and `log` (the query commands): they say which point, which files and how to
|
|
26
|
+
* show them, so they mean nothing to another command — and not every query takes every one of them (`log`
|
|
27
|
+
* draws no tree and reads no working tree, only `log` counts commits). Three of them are repeatable — each
|
|
28
|
+
* occurrence adds a value — and `--worktree`, `--tree` are switches. */
|
|
29
|
+
const REPEATABLE = ['--include', '--exclude', '--category'];
|
|
30
|
+
export const QUERY_COMMANDS = ['diff', 'now', 'log'];
|
|
31
|
+
const FLAG_VERBS = {
|
|
32
|
+
'--worktree': ['diff', 'now'],
|
|
33
|
+
'--tree': ['diff', 'now'],
|
|
34
|
+
'--depth': ['diff', 'now'],
|
|
35
|
+
'-n': ['log']
|
|
36
|
+
};
|
|
37
|
+
['--metric'].concat(REPEATABLE).forEach((f) => { FLAG_VERBS[f] = QUERY_COMMANDS; });
|
|
38
|
+
const QUERY_FLAGS = Object.keys(FLAG_VERBS);
|
|
39
|
+
const VALUE_FLAGS = ['--config', '--init', '--write', '--depth', '--metric', '-n'].concat(REPEATABLE);
|
|
40
|
+
const FLAGS = ['--help', '-h'].concat(MODES, VALUE_FLAGS, ['--json', '--force'], QUERY_FLAGS);
|
|
41
|
+
const COMMANDS = ['check', 'explain', 'doctor', 'diff', 'now', 'log', 'install-hook', 'uninstall-hook', 'hook-run'];
|
|
42
|
+
const ANSWER_COMMANDS = ['check', 'explain', 'doctor', 'diff', 'now', 'log'];
|
|
43
|
+
|
|
44
|
+
/* What a value flag needs, in the words of a refusal: the placeholder of the fix and the thing named. `--init`
|
|
45
|
+
* and `--write` are missing here on purpose — an empty value is their legitimate default. */
|
|
46
|
+
const NEEDS = {
|
|
47
|
+
'--config': ['<file>', 'a settings file'],
|
|
48
|
+
'--depth': ['<n>', 'a number of levels'],
|
|
49
|
+
'--metric': ['<metric>', 'a metric name'],
|
|
50
|
+
'-n': ['<count>', 'a number of commits'],
|
|
51
|
+
'--include': ['<glob>', 'a pattern of paths'],
|
|
52
|
+
'--exclude': ['<glob>', 'a pattern of paths'],
|
|
53
|
+
'--category': ['<category>', 'a category name']
|
|
54
|
+
};
|
|
55
|
+
export const HOOK_COMMANDS = ['install-hook', 'uninstall-hook', 'hook-run'];
|
|
56
|
+
|
|
57
|
+
// The command a query flag's advice names: the one on the line that takes it, or the first that does.
|
|
58
|
+
function queryVerb(flag, args) {
|
|
59
|
+
const verbs = FLAG_VERBS[flag];
|
|
60
|
+
if (verbs === undefined) return '';
|
|
61
|
+
return (args.find((a) => verbs.indexOf(a) >= 0) || verbs[0]) + ' ';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// "the command "log"", "the commands "diff" and "now"", "the commands "diff", "now" and "log"".
|
|
65
|
+
function verbsText(verbs) {
|
|
66
|
+
const q = verbs.map((v) => '"' + v + '"');
|
|
67
|
+
return verbs.length === 1 ? 'the command ' + q[0] : 'the commands ' + q.slice(0, -1).join(', ') + ' and ' + q[q.length - 1];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/* A value flag takes the next argument and reports how many it consumed. An empty value is
|
|
71
|
+
* a legitimate "default" for `--init` and `--write`, but for the others it would be a
|
|
72
|
+
* silent skip: the settings read would not be the ones the user named, a filter would filter
|
|
73
|
+
* nothing. A repeatable flag collects its values into a list. */
|
|
74
|
+
function takeValue(flag, args, i, values) {
|
|
75
|
+
const next = args[i + 1];
|
|
76
|
+
const none = next === undefined || next[0] === '-';
|
|
77
|
+
if (none && NEEDS[flag] !== undefined) {
|
|
78
|
+
refuseCause('flag without a value', 'the flag "' + flag + '" has no value: ' + NEEDS[flag][1] + ' is needed'
|
|
79
|
+
+ '\n fix: ' + cliCommand(queryVerb(flag, args) + flag + ' ' + NEEDS[flag][0]));
|
|
80
|
+
}
|
|
81
|
+
if (REPEATABLE.indexOf(flag) >= 0) values[flag] = (values[flag] || []).concat([next]);
|
|
82
|
+
else values[flag] = none ? null : next;
|
|
83
|
+
return none ? 0 : 1;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/* One pass over the line: words, modes, flag values. Refusals here are about a single flag
|
|
87
|
+
* only (unknown, repeated, missing a value); combinations belong to `checkArgs`, because
|
|
88
|
+
* they are about what was named together rather than about one argument. */
|
|
89
|
+
function scan(args) {
|
|
90
|
+
const seen = new Set();
|
|
91
|
+
const modes = [];
|
|
92
|
+
const values = {};
|
|
93
|
+
const words = [];
|
|
94
|
+
for (let i = 0; i < args.length; i++) {
|
|
95
|
+
const a = args[i];
|
|
96
|
+
if (a[0] !== '-') { words.push(a); continue; }
|
|
97
|
+
if (FLAGS.indexOf(a) < 0) {
|
|
98
|
+
refuseCause('unknown flag', 'unknown flag "' + a + '"\n fix: ' + cliCommand('--help'));
|
|
99
|
+
}
|
|
100
|
+
if (seen.has(a) && REPEATABLE.indexOf(a) < 0) {
|
|
101
|
+
refuseCause('repeated flag', 'the flag "' + a + '" is named twice\n fix: ' + cliCommand('--help'));
|
|
102
|
+
}
|
|
103
|
+
seen.add(a);
|
|
104
|
+
if (VALUE_FLAGS.indexOf(a) >= 0) i += takeValue(a, args, i, values);
|
|
105
|
+
if (MODES.indexOf(a) >= 0) modes.push(a);
|
|
106
|
+
}
|
|
107
|
+
return { seen: seen, modes: modes, values: values, words: words };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/* The advice repeats the settings the user named: without it a command looks for the
|
|
111
|
+
* default file name, does not find it in a project that named the file otherwise, and sends
|
|
112
|
+
* the user into a second refusal — about a settings file they do not have. */
|
|
113
|
+
function advisor(values) {
|
|
114
|
+
const given = typeof values['--config'] === 'string'
|
|
115
|
+
? '--config ' + advicePath(values['--config']) + ' ' : '';
|
|
116
|
+
return (rest) => cliCommand(given + rest);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/* A mode against the flags: the modes exclude each other, and `--force` and `--config` do
|
|
120
|
+
* not go with every one of them. */
|
|
121
|
+
function checkModes(plan) {
|
|
122
|
+
const { modes, seen, mode, advice } = plan;
|
|
123
|
+
if (modes.length > 1) {
|
|
124
|
+
refuseCause('two modes at once', 'two modes at once: "' + modes[0] + '" and "' + modes[1]
|
|
125
|
+
+ '" — it is one mode' + '\n fix: ' + advice(modes[0]));
|
|
126
|
+
}
|
|
127
|
+
if (seen.has('--force') && mode !== '--init') {
|
|
128
|
+
refuseCause('incompatible flag', 'the flag "--force" works only with "--init"'
|
|
129
|
+
+ '\n fix: ' + cliCommand('--init --force'));
|
|
130
|
+
}
|
|
131
|
+
if (seen.has('--config') && mode === '--init') {
|
|
132
|
+
refuseCause('incompatible flag', '"--init" has a file of its own, while "--config" names the'
|
|
133
|
+
+ ' settings of the project' + '\n fix: ' + cliCommand('--init <file>'));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/* A query flag with a command that does not take it: it would be ignored in silence, and a filter that
|
|
138
|
+
* filtered nothing reads as an answer about the filtered set. */
|
|
139
|
+
function checkCommandFlags(plan) {
|
|
140
|
+
const foreign = QUERY_FLAGS.find((f) => plan.seen.has(f) && FLAG_VERBS[f].indexOf(plan.verb) < 0);
|
|
141
|
+
if (foreign === undefined) return;
|
|
142
|
+
const value = NEEDS[foreign] === undefined ? '' : ' ' + NEEDS[foreign][0];
|
|
143
|
+
refuseCause('incompatible flag', 'the flag "' + foreign + '" works only with ' + verbsText(FLAG_VERBS[foreign])
|
|
144
|
+
+ '\n fix: ' + plan.advice(FLAG_VERBS[foreign][0] + ' ' + foreign + value));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/* A word the command does not know. Its own question, because there are two possible
|
|
148
|
+
* culprits: a typo in the command, or an extra value for a mode that already took one
|
|
149
|
+
* (`--init` and `--write` take a single value). Either way the culprit has to be named: a
|
|
150
|
+
* leftover after `--config` is the command itself, and its call is parsed as a command
|
|
151
|
+
* rather than as an extra word. */
|
|
152
|
+
function checkUnknownWord(plan) {
|
|
153
|
+
const { verb, values, advice } = plan;
|
|
154
|
+
if (verb === null || COMMANDS.indexOf(verb) >= 0) return;
|
|
155
|
+
const valued = MODES.find((f) => VALUE_FLAGS.indexOf(f) >= 0 && typeof values[f] === 'string');
|
|
156
|
+
if (valued !== undefined) {
|
|
157
|
+
refuseCause('extra word', 'the extra word "' + verb + '": "' + valued + '" takes one value'
|
|
158
|
+
+ '\n fix: ' + advice(valued + ' ' + advicePath(values[valued])));
|
|
159
|
+
}
|
|
160
|
+
refuseCause('unknown command', 'unknown command "' + verb + '"\n fix: ' + cliCommand('--help'));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/* A word and a mode together: the command says what to answer, the mode what to write, and
|
|
164
|
+
* the two do not work at once. */
|
|
165
|
+
function checkWordAgainstMode(plan) {
|
|
166
|
+
const { verb, mode, advice } = plan;
|
|
167
|
+
if (verb === null || mode === null) return;
|
|
168
|
+
refuseCause('command and mode', 'the command "' + verb + '" and the mode "' + mode
|
|
169
|
+
+ '" are different things and do not work together' + '\n fix: ' + advice(verb));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/* How many words are accepted: `explain` takes exactly one commit and requires it, `diff` up
|
|
173
|
+
* to two revisions (one with `--worktree`, which is the target itself), the other commands
|
|
174
|
+
* take no argument at all. A missing commit and several commits are two dead ends with one
|
|
175
|
+
* and the same fix. */
|
|
176
|
+
/* How many revisions a query command takes: `diff` a base and a target, `now` a target; `--worktree` is the
|
|
177
|
+
* target itself, so it takes one word fewer. */
|
|
178
|
+
const MOST_WORDS = {
|
|
179
|
+
diff: { most: 2, fix: 'diff <base> <target>', worktree: 'diff <base> --worktree' },
|
|
180
|
+
now: { most: 1, fix: 'now <target>', worktree: 'now --worktree' },
|
|
181
|
+
log: { most: 1, fix: 'log <target>', worktree: 'log <target>' },
|
|
182
|
+
// The hook takes the place of the report (D6): one file at most.
|
|
183
|
+
'install-hook': { most: 1, fix: 'install-hook <file>', worktree: 'install-hook <file>' },
|
|
184
|
+
'hook-run': { most: 1, fix: 'hook-run <file>', worktree: 'hook-run <file>' }
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
function checkQueryWords(plan) {
|
|
188
|
+
const limit = MOST_WORDS[plan.verb];
|
|
189
|
+
if (limit === undefined) return;
|
|
190
|
+
const wt = plan.seen.has('--worktree');
|
|
191
|
+
const most = limit.most - (wt ? 1 : 0);
|
|
192
|
+
if (plan.arg.length <= most) return;
|
|
193
|
+
const what = HOOK_COMMANDS.indexOf(plan.verb) >= 0 ? ' file' : ' revision';
|
|
194
|
+
const takes = most === 0 ? 'no revision' : 'at most ' + most + what + (most > 1 ? 's' : '');
|
|
195
|
+
refuseCause('extra word', 'the command "' + plan.verb + '" takes ' + takes
|
|
196
|
+
+ (wt ? ' with "--worktree" (the working tree is the target)' : '') + ': "' + plan.arg[most] + '" is extra'
|
|
197
|
+
+ '\n fix: ' + plan.advice(wt ? limit.worktree : limit.fix));
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function checkWordCount(plan) {
|
|
201
|
+
const { verb, arg, advice } = plan;
|
|
202
|
+
checkQueryWords(plan);
|
|
203
|
+
if (verb === 'explain' && arg.length === 0) {
|
|
204
|
+
refuseCause('no commit', 'the command "explain" needs a commit: a revision name (HEAD, a branch,'
|
|
205
|
+
+ ' a tag), a sha or its beginning'
|
|
206
|
+
+ '\n fix: ' + advice('explain <commit>'));
|
|
207
|
+
}
|
|
208
|
+
if (verb === 'explain' && arg.length > 1) {
|
|
209
|
+
refuseCause('extra word', 'the command "explain" takes one commit, not ' + arg.length
|
|
210
|
+
+ ': "' + arg.slice(1).join('", "') + '" are extra\n fix: ' + advice('explain <commit>'));
|
|
211
|
+
}
|
|
212
|
+
if (verb !== null && verb !== 'explain' && MOST_WORDS[verb] === undefined && arg.length > 0) {
|
|
213
|
+
refuseCause('extra word', 'the command "' + verb + '" takes no arguments: "' + arg[0] + '" is extra'
|
|
214
|
+
+ '\n fix: ' + advice(verb));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/* The shape of the answer against everything else. `--json` is a shape, not a mode, and it
|
|
219
|
+
* has one rule: exactly three commands and a bare run have an answer — the bare run is the
|
|
220
|
+
* older data form, frozen by the parity fixture and therefore not removable. A command
|
|
221
|
+
* without an answer has nothing to ask for, and a mode already has one answer, the write;
|
|
222
|
+
* both are refusals, and each names its culprit. */
|
|
223
|
+
function checkAnswer(plan) {
|
|
224
|
+
const { verb, mode, seen, advice } = plan;
|
|
225
|
+
if (seen.has('--json') && verb !== null && ANSWER_COMMANDS.indexOf(verb) < 0) {
|
|
226
|
+
refuseCause('no JSON answer', 'the command "' + verb + '" has no answer in JSON'
|
|
227
|
+
+ '\n fix: ' + advice(verb));
|
|
228
|
+
}
|
|
229
|
+
if (seen.has('--json') && verb === null && mode !== null) {
|
|
230
|
+
refuseCause('two answers at once', '"--json" and the mode "' + mode + '" are different: the data or'
|
|
231
|
+
+ ' the write, not both' + '\n fix: ' + advice(mode));
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/* Combination checks, in groups over one plan: the plan holds what the parse already knows
|
|
236
|
+
* (the word, the argument, the mode, the named flags and the advice), each group answers for
|
|
237
|
+
* its own subject, and what comes back is a ready plan to run. */
|
|
238
|
+
/* Old names of commands that still answer: `show` became `now` in 3.1.0 (the user's call — the command answers with
|
|
239
|
+
* the sizes now). The entry point says the new name on stderr; the old one goes in 4.0.0. */
|
|
240
|
+
const RENAMED = new Map([['show', 'now']]);
|
|
241
|
+
|
|
242
|
+
function checkArgs(scanned) {
|
|
243
|
+
const { words, seen, values, modes } = scanned;
|
|
244
|
+
const word = words.length > 0 ? words[0] : null;
|
|
245
|
+
const plan = {
|
|
246
|
+
verb: RENAMED.has(word) ? RENAMED.get(word) : word,
|
|
247
|
+
arg: words.slice(1),
|
|
248
|
+
modes: modes,
|
|
249
|
+
mode: modes.length > 0 ? modes[0] : null,
|
|
250
|
+
seen: seen,
|
|
251
|
+
values: values,
|
|
252
|
+
advice: advisor(values)
|
|
253
|
+
};
|
|
254
|
+
checkModes(plan);
|
|
255
|
+
checkUnknownWord(plan);
|
|
256
|
+
checkCommandFlags(plan);
|
|
257
|
+
checkWordAgainstMode(plan);
|
|
258
|
+
checkWordCount(plan);
|
|
259
|
+
checkAnswer(plan);
|
|
260
|
+
return {
|
|
261
|
+
verb: plan.verb,
|
|
262
|
+
renamed: RENAMED.has(word) ? word : null,
|
|
263
|
+
mode: plan.mode,
|
|
264
|
+
arg: plan.arg,
|
|
265
|
+
json: seen.has('--json'),
|
|
266
|
+
force: seen.has('--force'),
|
|
267
|
+
worktree: seen.has('--worktree'),
|
|
268
|
+
tree: seen.has('--tree') || seen.has('--depth')
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export function parseArgs(args) {
|
|
273
|
+
// Help always answers, and answers first: it is the way out of any typo.
|
|
274
|
+
if (args.indexOf('--help') >= 0 || args.indexOf('-h') >= 0) return { help: true };
|
|
275
|
+
const scanned = scan(args);
|
|
276
|
+
return Object.assign({ help: false, values: scanned.values }, checkArgs(scanned));
|
|
277
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { reportData } from './data.js';
|
|
4
|
+
import { pageHtml } from './page/build.js';
|
|
5
|
+
import { cliCommand, refuseCause } from './refusal.js';
|
|
6
|
+
|
|
7
|
+
/* The report is one file: a self-sufficient page. It is the artifact because it carries everything itself
|
|
8
|
+
* (data, styling, program), and a second form of the same report does not exist: two outputs of one history
|
|
9
|
+
* would drift apart silently, with nothing to tell which of them is right.
|
|
10
|
+
*
|
|
11
|
+
* Both consumers pass through here — the writing mode (`--write`) and the hook after a commit
|
|
12
|
+
* (`src/hook.js`), so "what went into the file" cannot drift between them: the hook writes exactly the bytes
|
|
13
|
+
* `--write` shows.
|
|
14
|
+
*
|
|
15
|
+
* The directory is created here as well: `--write docs/size-report.html` in a fresh project is an ordinary run
|
|
16
|
+
* rather than a user's mistake. The settings draft (`--init`) is written the same way, which is why there is one
|
|
17
|
+
* such place in the package. */
|
|
18
|
+
|
|
19
|
+
/* Writing a file while creating the directory: not a single part of the path may exist, and that is not a
|
|
20
|
+
* mistake of whoever named it. */
|
|
21
|
+
export function writeFileEnsured(file, text) {
|
|
22
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
23
|
+
fs.writeFileSync(file, text);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/* The report's bytes built without writing: the check needs them too (it compares the file on disk with exactly
|
|
27
|
+
* these bytes and reports it as diverging from the history), and building them a second way would compare
|
|
28
|
+
* something other than what gets written. */
|
|
29
|
+
export function artifact(cfg, root) {
|
|
30
|
+
const data = reportData(cfg, root);
|
|
31
|
+
return { data: data, html: pageHtml(data, cfg), file: path.join(root, cfg.output) };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function rebuild(cfg, root) {
|
|
35
|
+
const out = artifact(cfg, root);
|
|
36
|
+
writeFileEnsured(out.file, out.html);
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/* The place of the report for this run: the file named on the command line (`--write <file>`, `hook-run <file>`), else the
|
|
41
|
+
* settings' `output`, else a default next to the repository folder. A named file becomes this run's `output`, as a path
|
|
42
|
+
* from the root (it may climb out), because the report names itself by the path it lies at. Derived settings also re-aim
|
|
43
|
+
* what depends on the place: the link to the journal (relative to the report) and the rebuild command quoted inside the report. */
|
|
44
|
+
export function withOutput(cfg, root, file) {
|
|
45
|
+
if (typeof file === 'string' && file !== '') {
|
|
46
|
+
const abs = path.resolve(file);
|
|
47
|
+
const rel = path.relative(root, abs).split(path.sep).join('/');
|
|
48
|
+
const named = Object.assign({}, cfg, { output: rel });
|
|
49
|
+
if (cfg.derived === true) aimDerived(named, root, abs, rel);
|
|
50
|
+
return named;
|
|
51
|
+
}
|
|
52
|
+
if (cfg.output) return cfg;
|
|
53
|
+
const rel = '../' + path.basename(root) + '.size-report.html';
|
|
54
|
+
const abs = path.resolve(root, rel);
|
|
55
|
+
const named = Object.assign({}, cfg, { output: rel });
|
|
56
|
+
if (cfg.derived === true) aimDerived(named, root, abs, rel);
|
|
57
|
+
return named;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function aimDerived(cfg, root, abs, rel) {
|
|
61
|
+
if (cfg.journal) {
|
|
62
|
+
const url = path.relative(path.dirname(abs), path.join(root, cfg.journal.path)).split(path.sep).join('/');
|
|
63
|
+
cfg.journal = Object.assign({}, cfg.journal, { url: url });
|
|
64
|
+
}
|
|
65
|
+
if (/ --write$/.test(cfg.fixCommand)) cfg.fixCommand += ' ' + (/[\s"'$`\\]/.test(rel) ? JSON.stringify(rel) : rel);
|
|
66
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { assertFullHistory, readHistory } from './git.js';
|
|
2
|
+
import { measureHistory } from './history.js';
|
|
3
|
+
import { sensorGaps } from './metrics.js';
|
|
4
|
+
import { outsideFix, pathRoles } from './config.js';
|
|
5
|
+
import { cliCommand } from './refusal.js';
|
|
6
|
+
|
|
7
|
+
/* Coverage — the answer to "did everything in the history get into the report". The project's rule of
|
|
8
|
+
* completeness is one: every path the history touched has to be either a column or a declared exception
|
|
9
|
+
* (`skip` and the report file itself), and a path that is neither is a violation — an edit went past the
|
|
10
|
+
* report.
|
|
11
|
+
*
|
|
12
|
+
* Hence coverage is counted over the facts of the history (the union of the changed paths of every commit)
|
|
13
|
+
* rather than over the file list in the tree: a file created and deleted before HEAD is invisible there
|
|
14
|
+
* while the history remembers it, and its edits went into no number at all. The same place explains what
|
|
15
|
+
* the tool does **not** claim: it does not say whether the project picked the "right" columns — only that
|
|
16
|
+
* nothing went past them, and what exactly did not fit.
|
|
17
|
+
*
|
|
18
|
+
* The rows are counted by the same run as the reports (`measureHistory`), for the usual reason: there is no
|
|
19
|
+
* second calculation in the package. That is the price — the answer costs one pass over the history, like
|
|
20
|
+
* any report. */
|
|
21
|
+
|
|
22
|
+
// How many paths and commits to show a person in the text: the rest as a number.
|
|
23
|
+
const SHOW = 8;
|
|
24
|
+
|
|
25
|
+
/* The list of commits of one reason — lines no longer than a screen: a large history gathers fifty dropped
|
|
26
|
+
* commits alone, and one line for all of them is not readable at all. Every one of them stays in the answer
|
|
27
|
+
* (in full in `--json`), while the wrapping is what makes it readable. */
|
|
28
|
+
function wrapped(head, items) {
|
|
29
|
+
const lines = [];
|
|
30
|
+
let line = head;
|
|
31
|
+
items.forEach((item, i) => {
|
|
32
|
+
const piece = (i === 0 ? '' : ' ') + item + (i === items.length - 1 ? '' : ',');
|
|
33
|
+
if (line.length + piece.length > 100) { lines.push(line); line = ' ' + piece.trim(); return; }
|
|
34
|
+
line += piece;
|
|
35
|
+
});
|
|
36
|
+
lines.push(line);
|
|
37
|
+
return lines;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const REASON_WORD = { merge: 'merges', report: 'report only', flat: 'no change of volume' };
|
|
41
|
+
|
|
42
|
+
function short(sha) {
|
|
43
|
+
return sha.slice(0, 7);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/* The paths the history touched, split in three: tracked by columns, excluded by declaration, and unknown.
|
|
47
|
+
* The judgement itself is one and lives with the settings (`pathRoles`); here it is only applied to the
|
|
48
|
+
* whole history. */
|
|
49
|
+
function pathCoverage(cfg, commits) {
|
|
50
|
+
const role = pathRoles(cfg);
|
|
51
|
+
const seen = { covered: new Set(), excluded: new Set() };
|
|
52
|
+
const unknown = new Map();
|
|
53
|
+
commits.forEach((c) => {
|
|
54
|
+
c.files.forEach((f) => {
|
|
55
|
+
const kind = role(f);
|
|
56
|
+
if (kind === 'columns') { seen.covered.add(f); return; }
|
|
57
|
+
if (kind === 'excluded') { seen.excluded.add(f); return; }
|
|
58
|
+
/* The commit that introduced the path is the first one in the history (reads run oldest first), and it
|
|
59
|
+
* is shown to a person as evidence: it tells whose edit it was. */
|
|
60
|
+
if (!unknown.has(f)) unknown.set(f, { path: f, since: c.sha, subject: c.subject });
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
return {
|
|
64
|
+
covered: [...seen.covered].sort(),
|
|
65
|
+
excluded: [...seen.excluded].sort(),
|
|
66
|
+
unknown: [...unknown.values()]
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/* The full answer: settings, history, paths, sensors — and the verdict. `ok` means only "nothing went past
|
|
71
|
+
* the report": a sensor counting another way does not change the verdict (it has an exit code of its own,
|
|
72
|
+
* as in every other mode). */
|
|
73
|
+
export function coverage(cfg, root, configFile) {
|
|
74
|
+
assertFullHistory(root);
|
|
75
|
+
const commits = readHistory(root);
|
|
76
|
+
const measured = measureHistory(cfg, root, commits);
|
|
77
|
+
const paths = pathCoverage(cfg, commits);
|
|
78
|
+
const byReason = { merge: 0, report: 0, flat: 0 };
|
|
79
|
+
measured.dropped.forEach((d) => { byReason[d.reason] += 1; });
|
|
80
|
+
return {
|
|
81
|
+
schema: 1,
|
|
82
|
+
ok: paths.unknown.length === 0,
|
|
83
|
+
config: {
|
|
84
|
+
file: configFile,
|
|
85
|
+
columns: cfg.columns.length,
|
|
86
|
+
metrics: cfg.metrics,
|
|
87
|
+
excluded: [...new Set([cfg.output].concat(cfg.skip || []))].sort()
|
|
88
|
+
},
|
|
89
|
+
history: {
|
|
90
|
+
commits: commits.length,
|
|
91
|
+
rows: measured.rows.length,
|
|
92
|
+
dropped: measured.dropped.map((d) => ({ sha: d.sha, reason: d.reason })),
|
|
93
|
+
byReason: byReason
|
|
94
|
+
},
|
|
95
|
+
paths: {
|
|
96
|
+
covered: paths.covered.length,
|
|
97
|
+
excluded: paths.excluded.length,
|
|
98
|
+
unknown: paths.unknown
|
|
99
|
+
},
|
|
100
|
+
sensors: sensorGaps(cfg)
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/* The text for a person: a short "yes", or the list of what did not fit — with the path, the commit that
|
|
105
|
+
* introduced it, and a ready command. `cli` does the printing rather than this module: a module has no
|
|
106
|
+
* output and must not have one. */
|
|
107
|
+
export function coverageText(rep) {
|
|
108
|
+
const lines = [];
|
|
109
|
+
const unknown = rep.paths.unknown;
|
|
110
|
+
const counts = ' history: ' + rep.history.commits + ' commits, ' + rep.history.rows + ' rows, without a row '
|
|
111
|
+
+ rep.history.dropped.length;
|
|
112
|
+
if (!rep.ok) {
|
|
113
|
+
lines.push('✗ coverage: ' + unknown.length
|
|
114
|
+
+ (unknown.length === 1
|
|
115
|
+
? ' path of the history is neither tracked nor excluded'
|
|
116
|
+
: ' paths of the history are neither tracked nor excluded'));
|
|
117
|
+
unknown.slice(0, SHOW).forEach((u) => {
|
|
118
|
+
lines.push(' ' + u.path + ' — since ' + short(u.since) + ' "' + u.subject.slice(0, 60) + '"');
|
|
119
|
+
});
|
|
120
|
+
if (unknown.length > SHOW) lines.push(' … and ' + (unknown.length - SHOW) + ' more');
|
|
121
|
+
lines.push(' fix: ' + outsideFix(unknown.map((u) => u.path))
|
|
122
|
+
+ '; a draft of columns by extension: ' + cliCommand('--init draft.json'));
|
|
123
|
+
} else {
|
|
124
|
+
lines.push('✓ coverage: ' + rep.history.commits + ' commits of the history, ' + rep.history.rows
|
|
125
|
+
+ ' rows, every touched path is tracked or excluded');
|
|
126
|
+
}
|
|
127
|
+
lines.push(counts + ' (' + Object.keys(rep.history.byReason)
|
|
128
|
+
.filter((k) => rep.history.byReason[k] > 0)
|
|
129
|
+
.map((k) => REASON_WORD[k] + ' ' + rep.history.byReason[k]).join(', ') + ')');
|
|
130
|
+
if (rep.history.dropped.length > 0) {
|
|
131
|
+
['merge', 'report', 'flat'].forEach((key) => {
|
|
132
|
+
const shas = rep.history.dropped.filter((d) => d.reason === key).map((d) => short(d.sha));
|
|
133
|
+
if (shas.length > 0) lines.push(...wrapped(' ' + REASON_WORD[key] + ' (' + shas.length + '): ', shas));
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
lines.push(' paths: ' + rep.paths.covered + ' tracked, ' + rep.paths.excluded + ' excluded'
|
|
137
|
+
+ (rep.ok ? '' : ', ' + unknown.length + ' unknown'));
|
|
138
|
+
return lines.join('\n');
|
|
139
|
+
}
|