dart-use-path-package
Cross-platform file and directory path manipulation, segment splitting, extension extraction, and context conversion using `package:path` and `package:file`…
от dart-lang★ 563 звезды на GitHub
Установить dart-use-path-package в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Safe Cross-Platform Path Manipulation in Dart
Contents
- 1. Core Principles & Cross-Platform Rules
- 2. Recommended package:path Idioms vs. String Anti-Patterns
- 3. Bridging Native Paths to POSIX, Git, & URL Contexts
- 4. Mockable File Systems (
package:filevs. Globalp.*) - 5. Extensions, Compound Extensions & Stem Extraction
- 6. Workflows & Audit Checklist
- References & Examples
1. Core Principles & Cross-Platform Rules
Avoid Treating File Paths as Raw Strings
- Native file paths on Windows use backslashes (
\), whereas macOS and Linux use forward slashes (/). - String operations like
.contains('foo/'),.startsWith('foo/'), or.split('/')silently fail on Windows native paths. - String interpolation like
'$dir/$file'injects forward slashes on Windows and produces duplicate slashes (//) when$dirends with a trailing slash.
Rule: Always decompose paths into segments using p.split(path) before inspecting directory hierarchy or segment names, and always join path components using p.join(...).
Pragmatic Boundary Joining vs. Multi-Segment Decomposition (p.join)
- Cross-Platform Libraries (Windows + POSIX): Pass individual path segments to
p.join(dir, 'sub', 'file.json')sopackage:pathinserts OS-native separators (\on Windows,/on POSIX) between every component. - POSIX-Only Tools & Static Subpath Greppability: In codebases exclusively targeting Linux/macOS (or when joining a dynamic base path to a known static subpath), decomposing 5–6 static segments into separate arguments (
p.join(home, '.local', 'share', 'app', 'bin', 'config.json')) causesdart formatto wrap across 6–8 vertical lines and destroys substring greppability (grep/code_searchfor.local/share/app/bin). - Rule for POSIX Targets: Prefer 2-argument boundary joining (
p.join(home, '.local/share/app/bin/config.json')). This prevents duplicate-slash bugs (//) at variable boundaries while preserving single-line readability and exact string searchability.
Lexical Canonicalization vs. Physical Symlink Resolution
p.normalize(path)resolves.,.., and redundant separators purely lexically while preserving relative vs. absolute form and case.p.canonicalize(path)converts to an absolute path, normalizes segments, and standardizes ASCII case on Windows—still purely lexically (package:pathnever consults the filesystem and does not resolve symlinks).- When comparing physical file or directory identity on disk or keying caches across symlinks (such as macOS
/tmp->/private/tmp) and relative CLI flags (-o out), resolve symlinks viaDirectory(path).resolveSymbolicLinksSync()orFile(path).resolveSymbolicLinksSync()(orfileSystem.directory(path).resolveSymbolicLinksSync()inpackage:file). Unlike lexicalp.canonicalize(path),resolveSymbolicLinksSync()throws aFileSystemExceptionif the path does not exist yet—ensure the target exists first or fall back top.canonicalize(path)/directory.absolute.pathonFileSystemException.
Strip Location Specifiers & Convert URIs Safely
- Strings formatted as
<path>:<line>-<col>or<path>:<line>are not pure file paths. Passing them directly top.normalizeorUri.parsecauses bugs (on Windows,Uri.parsemistakesC:for a URI scheme and:linefor a port). - Extract the trailing
:line-colsuffix via regular expression (RegExp(r'^(.*?):(\d+(?:-\d+)?)$')) before passing the file path topackage:path. - URI Boundary Conversions: When converting between file paths and
Uriobjects, always usep.toUri(path)andp.fromUri(uri)rather thanUri.parse(path)or manual string concatenation.
2. Recommended package:path Idioms vs. String Anti-Patterns
Path Joining
- Prefer:
p.join(dir, file) - Avoid:
'$dir/$file'or'a/$b' - Why: String interpolation injects
/on Windows and creates duplicate
slashes (//) when$dirends with a trailing separator.
Segment Matching
- Prefer:
p.split(path).contains('foo') - Avoid:
path.contains('foo/') - Why: String matching fails on Windows backslashes (
foo\bar) and produces
false positives on partial substring names (e.g.barfoo/).
Root and Directory Prefixes
- Prefer:
if (p.split(path) case ['foo', ...])(orcase ['foo', ...final rest]when extracting tail segments), orp.isWithin('foo', path) - Avoid:
path.startsWith('foo/')orp.split(path).first == 'foo' - Why: String prefix matching fails on Windows separators (
foo\bar). Callingp.split(path).firstthrows aStateErroron empty lists and requi
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- examples/cross_platform_paths.dart
- examples/file_system_context.dart
FAQ
Что делает скилл dart-use-path-package?
Cross-platform file and directory path manipulation, segment splitting, extension extraction, and context conversion using `package:path` and `package:file`. Use when writing, inspecting, joining, splitting, or refactoring file paths, directory names, or extensions, or replacing raw string path operations (`.split('/')`, `'$dir/$file'`, `.endsWith('.ext')`, `.replaceAll('\\', '/')`). Don't use for HTTP network URI routing, database query strings, or non-path string processing.
Как установить скилл dart-use-path-package?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл dart-use-path-package запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
AnthropicGuide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
academy-guide
AnthropicStop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
internal-comms
AnthropicA set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
skill-development
AnthropicThis skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…