Skip to content

Commit 8f4f32c

Browse files
committed
SDK version file
1 parent 5bc4d56 commit 8f4f32c

File tree

5 files changed

+57
-50
lines changed

5 files changed

+57
-50
lines changed

lib/src/dartdoc_options.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,6 @@ class _OptionValueWithContext<T> {
468468
.cast<String>()
469469
.toList() as T;
470470
} else if (value is String) {
471-
//print(
472-
// 'canonicalising for $runtimeType; ${value} to ${pathContext.canonicalize(resolveTildePath(value as String))}');
473471
return pathContext.canonicalize(resolveTildePath(value as String)) as T;
474472
} else if (value is Map<String, String>) {
475473
return (value as Map<String, String>)

lib/src/model/documentable.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ abstract class Documentable extends Nameable {
3030
}
3131

3232
/// For a given package, indicate with this enum whether it should be documented
33-
/// [local]ly, whether we should treat the package as [missing] and any references
34-
/// to it made canonical to this package, or [remote], indicating that
35-
/// we can build hrefs to an external source.
33+
/// [local]ly, whether we should treat the package as [missing] and any
34+
/// references to it made canonical to this package, or [remote], indicating
35+
/// that we can build hrefs to an external source.
3636
enum DocumentLocation {
3737
local,
3838
missing,

lib/src/model/package.dart

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import 'package:dartdoc/src/warnings.dart';
1212
import 'package:path/path.dart' as path;
1313
import 'package:pub_semver/pub_semver.dart';
1414

15-
final RegExp substituteNameVersion = RegExp(r'%([bnv])%');
15+
@Deprecated('Public variable intended to be private; will be removed as early '
16+
'as Dartdoc 1.0.0')
17+
RegExp get substituteNameVersion => Package._substituteNameVersion;
1618

1719
// All hrefs are emitted as relative paths from the output root. We are unable
1820
// to compute them from the page we are generating, and many properties computed
@@ -224,51 +226,56 @@ class Package extends LibraryContainer
224226
String _baseHref;
225227

226228
String get baseHref {
227-
if (_baseHref == null) {
228-
if (documentedWhere == DocumentLocation.remote) {
229-
_baseHref =
230-
config.linkToUrl.replaceAllMapped(substituteNameVersion, (m) {
231-
switch (m.group(1)) {
232-
// Return the prerelease tag of the release if a prerelease,
233-
// or 'stable' otherwise. Mostly coded around
234-
// the Dart SDK's use of dev/stable, but theoretically applicable
235-
// elsewhere.
236-
case 'b':
237-
{
238-
var version = Version.parse(packageMeta.version);
239-
var tag = 'stable';
240-
if (version.isPreRelease) {
241-
// version.preRelease is a List<dynamic> with a mix of
242-
// integers and strings. Given this, handle
243-
// 2.8.0-dev.1.0, 2.9.0-1.0.dev, and similar
244-
// variations.
245-
tag = version.preRelease.whereType<String>().first;
246-
// Who knows about non-SDK packages, but assert that SDKs
247-
// must conform to the known format.
248-
assert(
249-
packageMeta.isSdk == false || int.tryParse(tag) == null,
250-
'Got an integer as string instead of the expected "dev" tag');
251-
}
252-
return tag;
253-
}
254-
case 'n':
255-
return name;
256-
// The full version string of the package.
257-
case 'v':
258-
return packageMeta.version;
259-
default:
260-
assert(false, 'Unsupported case: ${m.group(1)}');
261-
return null;
262-
}
263-
});
264-
if (!_baseHref.endsWith('/')) _baseHref = '${_baseHref}/';
265-
} else {
266-
_baseHref = config.useBaseHref ? '' : HTMLBASE_PLACEHOLDER;
267-
}
229+
if (_baseHref != null) {
230+
return _baseHref;
268231
}
232+
233+
if (documentedWhere == DocumentLocation.remote) {
234+
_baseHref = _remoteBaseHref;
235+
if (!_baseHref.endsWith('/')) _baseHref = '${_baseHref}/';
236+
} else {
237+
_baseHref = config.useBaseHref ? '' : HTMLBASE_PLACEHOLDER;
238+
}
239+
269240
return _baseHref;
270241
}
271242

243+
String get _remoteBaseHref {
244+
return config.linkToUrl.replaceAllMapped(_substituteNameVersion, (m) {
245+
switch (m.group(1)) {
246+
// Return the prerelease tag of the release if a prerelease, or 'stable'
247+
// otherwise. Mostly coded around the Dart SDK's use of dev/stable, but
248+
// theoretically applicable elsewhere.
249+
case 'b':
250+
{
251+
var version = Version.parse(packageMeta.version);
252+
var tag = 'stable';
253+
if (version.isPreRelease) {
254+
// `version.preRelease` is a `List<dynamic>` with a mix of
255+
// integers and strings. Given this, handle
256+
// "2.8.0-dev.1.0, 2.9.0-1.0.dev", and similar variations.
257+
tag = version.preRelease.whereType<String>().first;
258+
// Who knows about non-SDK packages, but SDKs must conform to the
259+
// known format.
260+
assert(packageMeta.isSdk == false || int.tryParse(tag) == null,
261+
'Got an integer as string instead of the expected "dev" tag');
262+
}
263+
return tag;
264+
}
265+
case 'n':
266+
return name;
267+
// The full version string of the package.
268+
case 'v':
269+
return packageMeta.version;
270+
default:
271+
assert(false, 'Unsupported case: ${m.group(1)}');
272+
return null;
273+
}
274+
});
275+
}
276+
277+
static final _substituteNameVersion = RegExp(r'%([bnv])%');
278+
272279
@override
273280
String get href => '$baseHref$filePath';
274281

lib/src/package_meta.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ abstract class PackageMeta {
9999

100100
p.Context get pathContext => resourceProvider.pathContext;
101101

102-
/// Returns true if this represents a 'Dart' SDK. A package can be part of
103-
/// Dart and Flutter at the same time, but if we are part of a Dart SDK
104-
/// sdkType should never return null.
102+
/// Returns true if this represents a 'Dart' SDK.
103+
///
104+
/// A package can be part of Dart and Flutter at the same time, but if we are
105+
/// part of a Dart SDK, [sdkType] should never return null.
105106
bool get isSdk;
106107

107108
/// Returns 'Dart' or 'Flutter' (preferentially, 'Flutter' when the answer is

test/package_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ void main() {
3434
sdkFolder = resourceProvider.getFolder(resourceProvider.pathContext
3535
.canonicalize(resourceProvider.convertPath(sdkRoot)))
3636
..create();
37+
sdkFolder.getChildAssumingFile('version').writeAsStringSync('2.9.0');
3738
var sdkBinFolder = sdkFolder.getChildAssumingFolder('bin')..create();
3839
sdkBinFolder.getChildAssumingFile('dart').writeAsStringSync('');
3940
sdkBinFolder.getChildAssumingFile('pub').writeAsStringSync('');

0 commit comments

Comments
 (0)