discontinuedPackage pubspec2 has been discontinued and replaced by pubspec_manager.

PubSpec class

Represents a pubspec.

Example Usage:

// load it
var pubSpec = await PubSpec.load(myDirectory);

// change the dependencies to a single path dependency on project 'foo'
var PubSpec = pubSpec.copy(dependencies: { 'foo': PathReference('../foo') });

// save it
await PubSpec.save(myDirectory);

Constructors

PubSpec({String? name, String? author, Version? version, String? homepage, String? documentation, String? description, Uri? publishTo, Environment? environment, Map<String, DependencyReference> dependencies = const {}, Map<String, DependencyReference> devDependencies = const {}, Map<String, DependencyReference> dependencyOverrides = const {}, Map<String, Executable> executables = const {}, Map<String, Platform> platforms = const {}, Json? unParsedYaml = const {}})
const
PubSpec.fromYaml(YamlMap yamlMap)
Bounds conversion of an already loaded map. Loading performed by the caller is not protected; use PubSpec.fromYamlString for preflight checks.
factory
PubSpec.fromYamlString(String yamlString)
Checks collection keys, event count and source nesting before loading. Scalar keys are stringified; collisions are rejected during conversion.
factory

Properties

allDependencies → Map<String, DependencyReference>
dependencies and devDependencies combined. Does not include dependencyOverrides
no setter
author → String?
final
dependencies → Map<String, DependencyReference>
final
dependencyOverrides → Map<String, DependencyReference>
final
description → String?
final
devDependencies → Map<String, DependencyReference>
final
documentation → String?
final
environment → Environment?
final
executables → Map<String, Executable>
final
hashCode → int
The hash code for this object.
no setterinherited
homepage → String?
final
name → String?
final
platforms → Map<String, Platform>
final
publishTo → Uri?
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
unParsedYaml → Json?
final
version → Version?
final

Methods

copy({String? name, String? author, Version? version, String? homepage, String? documentation, String? description, Uri? publishTo, Environment? environment, Map<String, DependencyReference>? dependencies, Map<String, DependencyReference>? devDependencies, Map<String, DependencyReference>? dependencyOverrides, Map<String, Executable>? executables, Map<String, Platform>? platforms, Json? unParsedYaml}) → PubSpec
creates a copy of the pubspec with the changes provided
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
save(String projectDirectory) → Future
saves the pubspec to the projectDirectory
toJson() → Json
Converts to a Map that can be serialised to Yaml or Json
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

load(String projectDirectory) → Future<PubSpec>
loads the pubspec from the projectDirectory
loadFile(String file) → Future<PubSpec>
loads the pubspec from the file