Skip to content

Commit ca59020

Browse files
feat: add fetch, sources, and lookup --context commands
Add three new CLI capabilities for debugging production websites: - `srcmap fetch <url>` — download a JS/CSS bundle and its source map from a URL, automatically resolving sourceMappingURL references (inline data URIs, external URLs, and conventional .map suffix fallback) - `srcmap sources <file.map>` — list or extract embedded sourcesContent entries to disk with directory structure preservation. Handles webpack://, file://, and relative path sanitization. - `srcmap lookup --context <n>` — show surrounding lines of original source code around a mapped position, with gutter display and highlighted target line. These commands enable the full remote debugging workflow: srcmap fetch https://cdn.example.com/app.min.js -o ./debug srcmap sources ./debug/app.min.js.map --extract -o ./src srcmap lookup ./debug/app.min.js.map 0 84729 --context 5 Also adds ureq HTTP client dependency, 43 integration tests (up from 32), webpack:// path fixture, and updated docs in both READMEs.
1 parent fcfc18b commit ca59020

8 files changed

Lines changed: 1267 additions & 13 deletions

File tree

Cargo.lock

Lines changed: 546 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ serde-wasm-bindgen = "0.6"
2929
js-sys = "0.3"
3030
clap = { version = "4", features = ["derive"] }
3131
rustc-hash = "2"
32+
ureq = "2"
3233

3334
[profile.release]
3435
lto = true

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ cargo install srcmap-cli
249249

250250
srcmap info bundle.js.map --json # Inspect metadata and statistics
251251
srcmap validate bundle.js.map --json # Validate a source map
252-
srcmap lookup bundle.js.map 42 10 --json # Original position (0-based)
252+
srcmap lookup bundle.js.map 42 10 --context 5 --json # Original position with source context
253253
srcmap resolve bundle.js.map --source src/app.ts 10 0 --json # Reverse lookup
254254
srcmap mappings bundle.js.map --limit 100 --json # List mappings
255255
srcmap decode "AAAA;AACA" --json # Decode VLQ mappings string
@@ -258,6 +258,8 @@ srcmap concat a.js.map b.js.map -o bundle.js.map # Concatenate
258258
srcmap remap minified.js.map --dir ./maps -o composed.js.map # Compose
259259
srcmap symbolicate stack.txt --dir ./maps --json # Symbolicate
260260
srcmap scopes bundle.js.map --json # Inspect ECMA-426 scopes & bindings
261+
srcmap fetch https://cdn.example.com/app.min.js -o ./debug # Fetch bundle + source map
262+
srcmap sources bundle.js.map --extract -o ./src # Extract original sources
261263
srcmap schema # All commands as JSON (for agents)
262264
```
263265

crates/cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ srcmap-scopes = { workspace = true }
2121
srcmap-symbolicate = { workspace = true }
2222
clap = { workspace = true }
2323
serde_json = { workspace = true }
24+
ureq = { workspace = true }
2425

2526
[dev-dependencies]
2627
serde_json = { workspace = true }

crates/cli/README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ cargo install srcmap-cli
2828
| `remap` | Compose/remap source maps through a transform chain |
2929
| `symbolicate` | Symbolicate a stack trace using source maps |
3030
| `scopes` | Inspect ECMA-426 scopes and variable bindings |
31+
| `fetch` | Fetch a JS/CSS bundle and its source map from a URL |
32+
| `sources` | List or extract original sources from a source map |
3133
| `schema` | Describe all commands as JSON (for agent introspection) |
3234

3335
## Usage
@@ -42,6 +44,9 @@ srcmap validate bundle.js.map
4244
# Look up original position (0-based line:column)
4345
srcmap lookup bundle.js.map 42 12
4446

47+
# Look up with surrounding source context
48+
srcmap lookup bundle.js.map 42 12 --context 5
49+
4550
# Reverse lookup
4651
srcmap resolve bundle.js.map --source src/app.ts 10 0
4752

@@ -63,6 +68,15 @@ srcmap symbolicate stacktrace.txt --dir ./sourcemaps
6368
# Inspect ECMA-426 scopes
6469
srcmap scopes bundle.js.map
6570

71+
# Fetch a bundle and its source map from a URL
72+
srcmap fetch https://cdn.example.com/app.min.js -o ./debug
73+
74+
# List embedded original sources
75+
srcmap sources bundle.js.map
76+
77+
# Extract all original sources to disk
78+
srcmap sources bundle.js.map --extract -o ./src
79+
6680
# All commands support --json for structured output
6781
srcmap info bundle.js.map --json
6882

@@ -78,7 +92,10 @@ srcmap schema
7892
- **Dry run**`--dry-run` on mutating commands (`concat`, `remap`) to validate without writing
7993
- **Input hardening** — rejects control characters, path traversals, and percent-encoding in source names
8094
- **Output sandboxing** — all file writes validated against the current working directory
81-
- **Structured errors** — error codes (`IO_ERROR`, `PARSE_ERROR`, `NOT_FOUND`, `VALIDATION_ERROR`, `PATH_TRAVERSAL`, `INVALID_INPUT`) in JSON mode
95+
- **Remote fetching**`srcmap fetch` downloads bundles and source maps from URLs, resolving `sourceMappingURL` automatically
96+
- **Source extraction**`srcmap sources --extract` writes embedded `sourcesContent` to disk with directory structure
97+
- **Context lines**`srcmap lookup --context N` shows surrounding original source around a mapped position
98+
- **Structured errors** — error codes (`IO_ERROR`, `PARSE_ERROR`, `NOT_FOUND`, `VALIDATION_ERROR`, `PATH_TRAVERSAL`, `INVALID_INPUT`, `FETCH_ERROR`) in JSON mode
8299

83100
## Part of [srcmap](https://github.com/BartWaardenburg/srcmap)
84101

0 commit comments

Comments
 (0)