About pub-package-explorer
A workflow for inspecting Dart or Flutter package source, including packages not yet added to a project. It resolves installed package paths from package_config.json or downloads source with dart pub unpack.
Key features
- 01Resolve installed package paths
- 02Inspect package source files
- 03Unpack packages before adding them
- 04Handle package versions
- 05Guide missing-config recovery
Use cases
- 01Inspect a dependency's public API
- 02Review a package before adding it
- 03Check the version resolved by a project
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ hexsis-llc/ skills --skill pub-package-explorerAfter installing, type/pub-package-explorerin Claude Code to confirm it loaded.
Details
From the project READMEPub Package Explorer
Use this workflow to read package source code for Dart or Flutter, including packages not currently installed in the project.
Choose the Source Strategy
- Prefer
.dart_tool/package_config.jsonwhen the package is already in the project dependency graph. - Use
dart pub unpackwhen the package is missing frompackage_config.jsonor when source needs inspection before adding the dependency. - Prefer the installed package path when both are available to match the project-resolved version.
Resolve a Package Source Path
- Confirm the project contains
.dart_tool/package_config.json. - Read the package entry from
packages[]byname. - Extract:
rootUri(package root, usually in pub cache)packageUri(usuallylib/)
- Build source path as
rootUri + packageUri. - Convert
file://URI to a filesystem path before reading files.
Use this command pattern:
PACKAGE="analyzer"
CONFIG=".dart_tool/package_config.json"
SOURCE_URI="$(jq -r --arg pkg "$PACKAGE" '
.packages[]
| select(.name == $pkg)
| (.rootUri + (if (.rootUri | endswith("/")) then "" else "/" end) + .packageUri)
' "$CONFIG")"
Convert the URI to a local path:
SOURCE_PATH="$(printf '%s\n' "$SOURCE_URI" | sed 's#^file://##')"
Then inspect source files under that directory (rg, ls, cat).
Unpack a Package That Is Not Installed
Use this path when the package is not in .dart_tool/package_config.json or when pre-install inspection is needed.
PACKAGE="analyzer" # or "analyzer:7.4.0"
OUTPUT_DIR="/tmp/pub-unpack"
mkdir -p "$OUTPUT_DIR"
dart pub unpack "$PACKAGE" --output "$OUTPUT_DIR"
Find the extracted directory and inspect it:
PACKAGE_NAME="${PACKAGE%%:*}"
UNPACKED_DIR="$(find "$OUTPUT_DIR" -maxdepth 1 -type d -name "${PACKAGE_NAME}-*" | sort | tail -n 1)"
ls "$UNPACKED_DIR"
ls "$UNPACKED_DIR/lib"
rg --files "$UNPACKED_DIR/lib"
Notes:
dart pub unpackdownloads and extracts a package even when it is not in the current project's dependencies.- Use
--forceif the output directory already contains an unpacked copy that must be overwritten. --outputcontrols where the extracted<package>-<version>folder is created.
Useful Variants
- Return only the package root:
jq -r --arg pkg "$PACKAGE" '
.packages[]
| select(.name == $pkg)
| .rootUri
' .dart_tool/package_config.json
- Return both root and package URI:
jq -r --arg pkg "$PACKAGE" '
.packages[]
| select(.name == $pkg)
| "\(.rootUri)\t\(.packageUri)"
' .dart_tool/package_config.json
Verification and Error Handling
- If no package matches in
package_config.json, switch todart pub unpackinstead of stopping. - If
.dart_tool/package_config.jsonis missing, run dependency resolution first (dart pub getorflutter pub get) and retry. - Prefer reading from
rootUri + packageUribecause package APIs are exposed from that subpath, not always from the package root. - If
dart pub unpackfails, report the exact failure (for example network access, invalid descriptor, or permissions for output path).
Comments
Markdown supported