Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip the enclosing package's lower-case name from a library's dir name #3883

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/src/model/library.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,17 @@ class Library extends ModelElement
'"$_restoredUri" must not start with "file:"');
// Strip the package prefix if the library is part of the default package
// or if it is being documented remotely.
var packageToHide = package.documentedWhere == DocumentLocation.remote
var defaultPackage = package.documentedWhere == DocumentLocation.remote
? package.packageMeta
: package.packageGraph.packageMeta;
var schemaToHide = 'package:$packageToHide/';
var packageNameToHide = defaultPackage.toString().toLowerCase();
var schemaToHide = 'package:$packageNameToHide/';

nameFromPath = _restoredUri;
if (nameFromPath.startsWith(schemaToHide)) {
nameFromPath = nameFromPath.substring(schemaToHide.length);
}
// Remove the trailing `.dart`.
if (nameFromPath.endsWith('.dart')) {
const dartExtensionLength = '.dart'.length;
nameFromPath = nameFromPath.substring(
Expand All @@ -184,6 +186,7 @@ class Library extends ModelElement
} else {
nameFromPath = name;
}
// Turn `package:foo/bar/baz` into `package-foo_bar_baz`.
return nameFromPath.replaceAll(':', '-').replaceAll('/', '_');
}();

Expand Down