I try to figure out how to manage pub packages. For example, I have the following pubspec.yaml:
name: app
dependencies:
intl: any
browser: any
polymer: any
transformers:
- polymer
After time I consider to remove intl package. As far as I understand running pub get again automatically remove unused packages (to be more precise it removes links but not actual files). If so how can I list/remove actual packages available globally (on Ubuntu under /home/username/.pub-cache/hosted/pub.dartlang.org/)?
Use the den tool. It's a community-contributed tool that provides various utilities for working with pub packages.
den uninstall thing_i_do_not_need_anymore
Only manually by deleting them using your OS tools. There is no pub ... support for that.
pub ... only works for the current project (current working directory) and it doesn't know if versions are used by other projects on your disk.
Related
Why can't I install this aqueduct?
Although I have installed dart before as shown in the picture:
It's important to ensure that the dart SDK is in the PATH. You can easily test it by trying to use pub or dart.
One way to ensure it's in the PATH is by creating a .bashrc file in your user's folder.
Then add the following:
export PATH="$PATH:/path/to/dart/installation/bin/folder"
First of all check if dart is installed using dart --version if it gives a command not found error that means it is not installed (hence why you cannot install aqueduct since it requires pub which is shipped with the dart sdk).
To install dart on macOS first install brew and the follow the instruction here https://dart.dev/get-dart (don't run brew switch dart 2.1.0 as shown in the screenshot since it makes no sense because current the latest stable is 2.9.1 and 2.1.0 is pretty old).
If you don't want to install brew you can download the sdk here (for your system) extract it, and update your path variable as #gabriel-octávio says.
I was studying basics of Flutter and Dart development and came across package manager called pub. What is it and what is it's importance in Flutter development?
Pub is the package manager for the Dart programming language, containing reusable libraries & packages for Flutter, AngularDart, and general Dart programs.
Some basic command:
Use pub get to get dependencies
Use pub upgrade to upgrade a dependency
Use pub publish to make your library available for others
You can find all packages here.
Also you can develop your own package, find the details on official site.
Pub is a package manager for dart to know more about pub see this: https://www.dartlang.org/tools/pub
What is the difference in dependencies and dev_dependencies in a pubspec.yaml? It seems that when I run pub get the dev_dependencies aren't downloaded.
dev_dependencies are dependencies that are not available for code in the resulting application, but only for tests, examples, tools, or to add executable tools like for code generation to your project.
dev_dependencies of any dependencies in your project (dependencies or dev_dependencies) are always ignored when you publish to pub.dev.
See also https://dart.dev/tools/pub/pubspec
There are two types of dependencies, one is regular and the other is dev.
dependencies:
Regular dependencies are listed under dependencies:—these are packages that anyone using your package will also need.
dev_dependencies:
Dependencies that are only needed in the development phase of the package itself are listed under dev_dependencies.
If your package (say A) depends on another package (say B) (which has dev-dependencies), then your package A ignores the dev-dependencies of package B.
However, your package A depends on the packages listed by Package B's dependencies.
Pub supports two flavors of dependencies : dependencies and dev dependencies.
Dev dependencies differ from regular dependencies in that dev dependencies of packages you depend on are ignored.
Here’s an example:
Say the transmogrify package uses the test package in its tests and only in its tests. If someone just wants to use transmogrify—import its libraries—it doesn’t actually need test. In this case, it specifies test as a dev dependency.
Its pubspec will have something like:
dev_dependencies:
test: '>=0.5.0 <0.12.0'
Pub gets every package that your package depends on, and everything
those packages depend on, transitively. It also gets your package’s
dev dependencies, but it ignores the dev dependencies of any dependent
packages. Pub only gets your package’s dev dependencies. So when your
package depends on transmogrify it will get transmogrify but not test.
The rule for deciding between a regular or dev dependency is simple: If the dependency is imported from something in your lib or bin directories, it needs to be a regular dependency. If it’s only imported from test, example, etc. it can and should be a dev dependency.
Using dev dependencies makes dependency graphs smaller. That makes pub run faster, and makes it easier to find a set of package versions that satisfies all constraints.
Here, You can learn more about dependencies
According to "pub --help" the "upgrade" command is used to:
Upgrade the current package's dependencies to latest versions.
However, I just had to run "pub upgrade" several times to reach the current latest versions of packages that my pubspec.yaml depends on. It seemed like each run upgraded only incrementally. What am I missing?
Specific example I observed was mustache: ">=0.1.5", which was first upgraded to 0.1.6 and on a second run to 0.1.7.
pub version: Pub 1.1.0-dev.5.11
It should upgrade all dependencies to the latest version available, or the latest version allowed in pubspec.yaml (see the Pub Package Manager docs).
But if it jumps only over one new version per upgrade, try to fill in the bug
I have never seen that behavior. It should go straight to the highest available (not-dev) release that fulfills your dependency constraints.
You can see this behaviour if a new version of your dependency lands between your 2 runs.
Looking at the versions of mustache (click on the Versions tab) you can see if a new version has landed during your test. It may explain what you observed.
I wanted to give the latest Dart Polymer lib a spin, so I updated the pubspec file and ran a pub install. However, the install fails with the following message:
Pub install failed, [1] Resolving dependencies.........
Package polymer requires SDK version >=0.8.1+1 but the current SDK is
0.7.6+4.r28108
Is it somehow possible to use the latest Polymer version via pubspec, or do I need to build the SDK myself from the sources?
https://www.dartlang.org/tools/editor/ has links to the bleeding edge, continuous build DartEditor
https://storage.googleapis.com/dart-editor-archive-continuous/latest/darteditor-win32-32.zip
https://storage.googleapis.com/dart-editor-archive-continuous/latest/darteditor-win32-64.zip
As of today, you should be able to upgrade 0.8.1.2 if you go to Help > About Dart Editor.
It seems pretty common that the libraries update a day or two before the SDK, so normally when I run into this problem I put in the pubspec something like the following until I can update the SDK:
dependencies:
polymer: "< 8.0.0"