Skip to content

Commit b7974a7

Browse files
Support for publish_to field
1 parent c2b1a4b commit b7974a7

File tree

6 files changed

+74
-1
lines changed

6 files changed

+74
-1
lines changed

lib/src/internal/load_from_yaml.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ PubspecYaml loadFromYaml(String content) {
6363
executables: jsonMap.containsKey(Tokens.executables) && jsonMap[Tokens.executables] != null
6464
? _loadExecutables(jsonMap[Tokens.executables] as Map<String, dynamic>)
6565
: {},
66+
publishTo: Optional(jsonMap[Tokens.publishTo] as String),
6667
customFields: Map<String, dynamic>.fromEntries(jsonMap.entries.where((entry) => !_knownTokens.contains(entry.key))),
6768
);
6869
}
@@ -156,4 +157,5 @@ const _knownTokens = [
156157
Tokens.devDependencies,
157158
Tokens.dependencyOverrides,
158159
Tokens.environment,
160+
Tokens.publishTo,
159161
];

lib/src/internal/tokens.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ class Tokens {
4343
static const devDependencies = 'dev_dependencies';
4444
static const dependencyOverrides = 'dependency_overrides';
4545
static const environment = 'environment';
46+
static const publishTo = 'publish_to';
4647
}

lib/src/internal/yaml_formatter.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ String _packageMetadataToYaml(PubspecYaml pubspecYaml) => json2yaml(<String, dyn
5656
if (pubspecYaml.repository.hasValue) Tokens.repository: pubspecYaml.repository.valueOr(() => ''),
5757
if (pubspecYaml.issueTracker.hasValue) Tokens.issueTracker: pubspecYaml.issueTracker.valueOr(() => ''),
5858
if (pubspecYaml.documentation.hasValue) Tokens.documentation: pubspecYaml.documentation.valueOr(() => ''),
59+
if (pubspecYaml.publishTo.hasValue) Tokens.publishTo: pubspecYaml.publishTo.valueOr(() => ''),
5960
}, yamlStyle: YamlStyle.pubspecYaml);
6061

6162
String _dependenciesToYaml(

lib/src/pubspec_yaml.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class PubspecYaml extends $PubspecYaml {
5454
this.repository = const Optional.none(),
5555
this.issueTracker = const Optional.none(),
5656
this.documentation = const Optional.none(),
57+
this.publishTo = const Optional.none(),
5758
this.dependencies = const [],
5859
this.devDependencies = const [],
5960
this.dependencyOverrides = const [],
@@ -95,6 +96,12 @@ class PubspecYaml extends $PubspecYaml {
9596
///https://dart.dev/tools/pub/pubspec#documentation
9697
final Optional<String> documentation;
9798

99+
/// This setting can be used to specify a custom pub package server to publish.
100+
/// The default uses the pub.dev site.
101+
/// Specify none to prevent a package from being published.
102+
/// https://dart.dev/tools/pub/pubspec#publish_to
103+
final Optional<String> publishTo;
104+
98105
/// Regular dependencies that anyone using the package will also need
99106
/// https://dart.dev/tools/pub/pubspec#dependencies
100107
/// https://dart.dev/tools/pub/dependencies

lib/src/pubspec_yaml.g.dart

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2019 Alexei Sintotski
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*
24+
*/
25+
26+
import 'package:pubspec_yaml/src/pubspec_yaml.dart';
27+
import 'package:test/test.dart';
28+
29+
void main() {
30+
group('given pubspec.yaml with publish_to specification', () {
31+
final pubspecYaml = PubspecYaml.loadFromYamlString(pubspecYamlWithPublishToSpec);
32+
33+
group('$PubspecYaml.loadFromYamlString', () {
34+
test('produces object with publish_to data', () {
35+
expect(pubspecYaml.publishTo.valueOr(() => ''), publishTo);
36+
});
37+
test('produces object without custom fields', () {
38+
expect(pubspecYaml.customFields, isEmpty);
39+
});
40+
});
41+
42+
group('$PubspecYaml.toYamlString', () {
43+
final outputYaml = pubspecYaml.toYamlString();
44+
test('produces string equivalent to the input', () {
45+
expect(outputYaml, pubspecYamlWithPublishToSpec);
46+
});
47+
});
48+
});
49+
}
50+
51+
const publishTo = 'none';
52+
const pubspecYamlWithPublishToSpec = '''
53+
name: pubspec_yaml
54+
publish_to: $publishTo
55+
''';

0 commit comments

Comments
 (0)