@danielsimonjr/repo-tools 1.0.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.
Files changed (5) hide show
  1. package/CHANGELOG.md +774 -0
  2. package/LICENSE +21 -0
  3. package/README.md +214 -0
  4. package/dist/cli.js +11055 -0
  5. package/package.json +45 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DANIEL SIMON JR
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.
package/README.md ADDED
@@ -0,0 +1,214 @@
1
+ # repo-tools
2
+
3
+ `repo-tools` is one command-line tool with four subcommands for TypeScript repositories:
4
+
5
+ | Subcommand | Job |
6
+ |---|---|
7
+ | `depgraph` | Writes the dependency graph and the architecture reports of a TypeScript tree. |
8
+ | `chunk` | Splits a large file into chunks, merges the chunks back, and shows which chunks changed. |
9
+ | `compress` | Writes a compact copy of a file for a model context, and restores it. |
10
+ | `query` | Answers structural questions from the depgraph reports, and writes two derived reports. |
11
+
12
+ Status: version 1.0.0.
13
+
14
+ - All four subcommands work.
15
+ - `depgraph` and `query` read their settings from `repo-tools.config.json` in the root.
16
+ `--config=<file>` makes either subcommand read another file.
17
+ - `compress -d` restores JSON files only.
18
+
19
+ ## Install
20
+
21
+ Install one of the two forms.
22
+
23
+ ### npm package
24
+
25
+ The npm package needs Node 20 or later:
26
+
27
+ ```sh
28
+ npm i -g @danielsimonjr/repo-tools
29
+ repo-tools --version
30
+ ```
31
+
32
+ ### Compiled executable
33
+
34
+ The executable holds the tool and the Bun runtime. It needs no Bun, Node or `node_modules`.
35
+ Download the file for your platform and `SHA256SUMS` from the
36
+ [GitHub release](https://github.com/danielsimonjr/repo-tools/releases/tag/v1.0.0):
37
+
38
+ | Platform | File |
39
+ |---|---|
40
+ | Windows x64 | `repo-tools-windows-x64.exe` |
41
+ | Linux x64 | `repo-tools-linux-x64` |
42
+ | macOS arm64 | `repo-tools-darwin-arm64` |
43
+
44
+ Verify the file against `SHA256SUMS` before you run it:
45
+
46
+ ```sh
47
+ # Linux
48
+ sha256sum --ignore-missing -c SHA256SUMS
49
+ # macOS: compare the output with the line of the file in SHA256SUMS
50
+ shasum -a 256 repo-tools-darwin-arm64
51
+ # Windows (PowerShell): compare the output with the line of the file in SHA256SUMS
52
+ Get-FileHash repo-tools-windows-x64.exe -Algorithm SHA256
53
+ ```
54
+
55
+ On Linux and macOS, a downloaded file has no execute bit. The executable is not signed, so macOS
56
+ also marks a file that a browser downloads. Run these commands before the first run:
57
+
58
+ ```sh
59
+ chmod +x repo-tools-linux-x64 # or repo-tools-darwin-arm64
60
+ xattr -d com.apple.quarantine repo-tools-darwin-arm64 # macOS only
61
+ ```
62
+
63
+ ## Run from source
64
+
65
+ Run the tool from source with Bun:
66
+
67
+ ```sh
68
+ bun install
69
+ bun src/bin.ts --help
70
+ ```
71
+
72
+ ## Build an executable
73
+
74
+ The compiled executable is the main product: one file that holds the tool and the Bun runtime.
75
+ It needs no Bun, Node or `node_modules` on the machine that runs it.
76
+
77
+ Prerequisites: Bun 1.4.2 or later, and a clone of this repository.
78
+
79
+ 1. Install the dependencies from the lockfile:
80
+
81
+ ```sh
82
+ bun install --frozen-lockfile
83
+ ```
84
+
85
+ Do this after every pull. The executable bundles the installed dependencies, so the build
86
+ first compares `node_modules` with `bun.lock`. On a difference, the build stops with exit 1
87
+ and names each package. A frozen install does not remove a package that `bun.lock` no longer
88
+ names. When the build names such a package, remove `node_modules` and install again.
89
+
90
+ 2. Compile the executable for this computer:
91
+
92
+ ```sh
93
+ bun run compile
94
+ ```
95
+
96
+ To compile for another platform, give the target:
97
+
98
+ ```sh
99
+ bun scripts/build.ts --compile --target bun-linux-x64
100
+ ```
101
+
102
+ The file goes into `bin/`. Use `--outdir <dir>` to choose another folder.
103
+
104
+ | Target | File | Size (about) |
105
+ |---|---|---|
106
+ | `bun-windows-x64` | `bin/repo-tools-windows-x64.exe` | 86 MB |
107
+ | `bun-linux-x64` | `bin/repo-tools-linux-x64` | 82 MB |
108
+ | `bun-darwin-arm64` | `bin/repo-tools-darwin-arm64` | 62 MB |
109
+
110
+ 3. Run the executable:
111
+
112
+ ```sh
113
+ bin/repo-tools-windows-x64.exe --version
114
+ bin/repo-tools-windows-x64.exe depgraph --root=path/to/repo
115
+ ```
116
+
117
+ 4. Test the executable, not only the source. The executable is the artifact that ships:
118
+
119
+ ```sh
120
+ bun run smoke -- bin/repo-tools-windows-x64.exe
121
+ ```
122
+
123
+ `bun run build` writes a second channel, the Node bundle `dist/cli.js` (`node dist/cli.js --help`).
124
+
125
+ ## Reports
126
+
127
+ `repo-tools depgraph` writes its reports into `docs/architecture/` under the root. Every file is
128
+ generated: do not edit it by hand. Run `repo-tools depgraph` again to update it. Each Markdown
129
+ report starts with a "GENERATED FILE -- do not edit by hand" banner.
130
+
131
+ | File | What it answers |
132
+ |---|---|
133
+ | `DEPENDENCY_GRAPH.md` | How do the files and modules depend on each other? Per-file imports and exports, the dependency matrix, cyclic components (runtime and type-only), a Mermaid diagram, and statistics. |
134
+ | `dependency-graph.json` | The same graph as data, for tools: modules, files, imports, exports, entry points, cyclic components and statistics. |
135
+ | `dependency-graph.yaml` | The same data as YAML. |
136
+ | `dependency-summary.compact.json` | A small summary of the graph, with short keys, to give to a model. |
137
+ | `unused-analysis.md` | Which files and exports does nothing import? Dormant files, split into orphans (reachable from nothing) and test-only files. |
138
+ | `FILE_INVENTORY.md` | Where is every `.ts` file, and what is it? Area and disposition (reachable, build entry, test-only, orphan, test, tool, config, example, bench), and the result of the census self-check. |
139
+ | `file-inventory.json` | The same inventory as data. |
140
+ | `TEST_COVERAGE.md` | Which source files does a test import (directly, through a barrel, or through a side-effect import), and which files does no test reach? |
141
+ | `test-coverage.json` | The same coverage data, with the test-to-source map. |
142
+ | `duplicate-symbols.md` | Which names do two or more files define? Each name is classified. |
143
+ | `duplicate-symbols.json` | The same duplicate data as data. |
144
+ | `package-export-surfaces.json` | Which names does each package export publicly? |
145
+
146
+ `repo-tools query --emit` writes two more files into the same folder. They are also generated.
147
+
148
+ | File | What it answers |
149
+ |---|---|
150
+ | `dependency-reverse.json` | Which files import each file? The reverse edges of the graph. |
151
+ | `node-safety.json` | Which packages are browser-safe, which files import a `node:` builtin, and which of those files does the `.` entry of each browser-safe package reach? |
152
+
153
+ ## Query the graph
154
+
155
+ `repo-tools query` answers questions from `dependency-graph.json` and
156
+ `package-export-surfaces.json`. It parses no source file, so run `repo-tools depgraph` first.
157
+ The examples use a copy of `tests/fixtures/depgraph/mono-repo`:
158
+
159
+ ```sh
160
+ repo-tools depgraph
161
+ repo-tools query dependents packages/core/src/math.ts
162
+ # packages/core/src/index.ts
163
+ # packages/core/src/worker.ts
164
+ repo-tools query symbol-users add
165
+ # packages/cli/src/main.ts [@scope/core]
166
+ # packages/core/src/index.ts [internal]
167
+ repo-tools query is-public packages/core add
168
+ # PUBLIC: add is exported from packages/core
169
+ repo-tools query is-public packages/core double
170
+ # INTERNAL: double is not in the public export surface of packages/core
171
+ repo-tools query cycles
172
+ # runtime: 0 cyclic components
173
+ # type-only: 0 cyclic components
174
+ ```
175
+
176
+ A package is the folder above a `src/index.ts` entry (`.` for the root entry). Each package is
177
+ browser-safe, unless `--node-runtime=<pkg,...>` or the config key `query.nodeRuntimes` lists it.
178
+ The `.` entry of a browser-safe package must not reach a file that imports a `node:` builtin:
179
+
180
+ ```sh
181
+ repo-tools query node-safety
182
+ # packages/core: clean (the . entry reaches no node: code)
183
+ repo-tools query --check-browser-safety
184
+ # browser-safety check passed: the . entries of 1 browser-safe package reach no node: code.
185
+ repo-tools query --emit
186
+ # Written: docs/architecture/dependency-reverse.json (3 files)
187
+ # Written: docs/architecture/node-safety.json (0 node files, 0 leaks)
188
+ ```
189
+
190
+ `--check-browser-safety` exits 1 on a leak. The query reads its reports from `--out`, else from
191
+ the config key `query.out`, else from `depgraph.out`, else from `docs/architecture`. Run
192
+ `repo-tools query --help` for every option.
193
+
194
+ ## Develop
195
+
196
+ | Command | Job |
197
+ |---|---|
198
+ | `bun test` | Runs the unit tests. |
199
+ | `bun run typecheck` | Runs the TypeScript type check. |
200
+ | `bun run lint` | Runs the lint and format check. |
201
+ | `bun run build` | Writes the Node bundle `dist/cli.js`. |
202
+ | `bun run compile` | Writes the compiled executable for this platform into `bin/`. |
203
+ | `bun run smoke -- <command...>` | Runs the smoke test against one way to run the tool. |
204
+ | `bun run privacy` | Runs the privacy check on the tracked files and the commit messages. |
205
+ | `bun run hooks` | Installs the `commit-msg` hook that runs the privacy check on each message. |
206
+
207
+ ## Design
208
+
209
+ `docs/design.md` describes the modules, the output rules, the config, the extension contract,
210
+ the privacy check and the verification.
211
+
212
+ ## License
213
+
214
+ MIT. See `LICENSE`.