Dart pub get generates link to packages in each folder and subfolders - dart

I try to avoid Dart to generate symbolic links (to packages) in each folder/sub-folder. For example, in pubspec.yaml I add polymer package and run pub get. After that I got:
Now each folder has packages symbolic link! As I understand it's because to ensure that we can use package:.. statement in any Dart file in any subdirectory.
I've already read the following topic (Why is dart pub suddenly trying to install packages in my css folder?), but it was created 2 years ago. Maybe something new here? How can I specify folders to exclude generating links by pub?

These symlinks are necessary for many tools. You can use the experimental command line option --no-package-symlinks for pub get/pub upgrade to disable symlink creation. I tried this a while ago but the DartEditor debugger stopped working (see http://dartbug.com/21749).
There are plans to get rid of symlinks entirely. A proposal exists and I assume it will be implemented within a few months (no promises).
Update
No packages directory and no symlinks might become default with Dart 1.13.

Related

Could not find pubspec.yaml in unittest 0.11.0+5

I'm running pub get and its reporting that it can't find a pubspec.yaml file in unittest package, anyone seen this before? Im on Dart Editor version 1.8.0.dev_00_00 (DEV) Dart SDK version 1.8.0-dev.0.0
The downloaded package in
C:\Users\daniel\AppData\Roaming\Pub\Cache\hosted\pub.dartlang.org\unittest-0.11.0+5
didn't have a pubspec.yaml file in it, and using pub cache repair wouldn't work for that very reason also so I had to manually open the directory and delete it then when I did a new pub get it did work. Sounds like cache repair might need tweaking to make it delete any corrupted packages that didnt have their pubspecs downloaded with them and I beleive this broken state was created by me running a pub get whislt a pub get was already in progress on the same pubspec.yaml file, so probably best you avoid doing that.

Dart: pub get vs pub upgrade

According to the pub get docs the main difference between pub get and pub upgrade is:
If a lockfile already exists, pub get uses the versions of dependencies locked in it if possible. If a dependency isn’t locked, pub will get the latest version of that dependency that satisfies all the version constraints. This is the primary difference between pub get and pub upgrade, which always tries to get the latest versions of all dependencies.
But this leaves me with a few questions.
What do they mean by "If a dependency isn't locked...? Locked?!? Like in version control? File system lock? What is this lock of which they speak?
Still not clearly understanding the difference between these two commands. Are they saying that pub get takes version constraints into account, and that pub upgrade doesn't?
It is locked when the pubspec.lock file contains an entry for this dependency.
You can change the dependency in pubspec.lock manually to specify exactly what version you want to use.
pub upgrade checks for the newest version that fits your pubspec.yaml configuration and updates your pubspec.lock file automatically.
when pubspec.lock is checked in with your package code in a CVS repository you are able to later reproduce the exact same setup as you had when you checked in your code even when your pubspec.yaml allowed a wider range of versions for a dependency.
see also
Upgrading a dependency
In Dart and Pub, should I add pubspec.lock to my .gitignore?

Dart Package Management via dart2js

I'm learning Dart and its dependency manager pub and am having a tough time seeing the "forest through the trees" here.
Say I want to use Polymer.dart in my project. So, in my project root, I create the following pubspec.yaml:
name: test_dart
description: A sample web application
dependencies:
browser: any
polymer: ">=0.9.0 <0.10.0"
I then run pub get, which goes to the pub repo and fetches the browser and polymer dependencies that I've specified. It then creates a packages directory in my project root, which now means I have a project that looks like:
MyDartProject/
pubspec.yaml
myapp.dart
packages/
browser/
...
...all the packages that ship with Polymer
Now I start coding my Dart web app (myapp.dart), which will references various Polymer and browser types/functions/etc. in its source code.
When I'm all done, I want to create a JavaScript file called myapp.js.
According to the dart2js docs, I need to run something like:
dart2js --out=myapp.js --package-root=??? myapp.dart
How do I include all the browser & polymer packages on the buildpath?
There is a "pub build" option now.
http://pub.dartlang.org/doc/pub-build.html
Use pub build when you’re ready to deploy your web app. When you run
pub build, it generates the assets for the current package and all of
its dependencies, putting them into a new directory named build.
$ cd ~/dart/helloworld
$ pub build
Building helloworld......
Built 5 files!
If the build directory already exists, pub build deletes it and then creates it again.
That should do everything you are after here. You can also launch it from the IDE by right clicking on the pubspec.yaml file and choose "pub build"
EDIT: You should also see the links in zoechi's answer.
If you run dart2js from your MyDartProject directory you don't have to provide --package-root parameter.
An alternative way is running pub build. If you use Polymer you need to add a transformers section.
see also
How to deploy a Dart Polymer app to Javascript using dart2js
How do I pass multiple entry_points to polymer transformer in pubspec.yaml?

Pub does not download dependencies on Windows 7 after the update to lib v2 (SDK 0.3.1_r17328)

After the update to the version 0.3.1_r17328 of Dart SDK and Dart Editor I have some trouble to import some library particulary Args library. I have the same problem both directly importing Args or importing Web_ui where Args is one of the dependencies.
Here is my pubspec.yaml:
name: notes
description: A sample application
dependencies:
web_ui: 0.3.0+1
or:
name: notes
description: A sample application
dependencies:
args: 0.3.1+1
Here is the error generate from build.dart
Unable to open file: C:/Users/Fabio/Dropbox/progetti/note/packages/args/args.dart'package:web_ui/component_build.dart': Error: line 25 pos 1: library handler failed
import 'package:args/args.dart';
'file:///C:/Users/Fabio/Dropbox/progetti/note/build.dart': Error: line 1 pos 1: library handler failed
import 'package:web_ui/component_build.dart';
I solved the problem. It seems that the Cache folder (Pub) has been corrupted.
I have deleted the folder Cache: C:\Users\<UserName>\AppData\Roaming\Pub
Then i run pub install from command line and it works.
Unfortunately, I was getting the same error with my windows XP machine.
In the end, I logged into my windows 7 machine and was able to
download the packages, zipped them up and pasted the libraries into my
windows XP dart editor. Success!
I had no reason to believe I had the exact proxy issue #shindokaku had as I am using my home computer.
I tried all the suggestions on deleting the .cache files, pub.lock files and the packages folder and retrying. I uninstalled dart editor and tried again. I also tried using the git resources to download web-ui and running commands through the command line to no avail
Including suggestions in this similar questions:
cannot-find-referenced-source-packages
is-there-a-workaround-for-pub-dependency-resolution-through-proxies
This problem has been haunting me over and over for a few weeks. I am not using Windows, so this answer is not intended to help the original poster who is using Windows 7.
If you are using Linux here are the steps I use to repair corrupted pub cache.
Go to the top level directory of your app. You should see at least pubspec.lock, pubspec.yaml, a folder named packages, and a folder named web.
Delete your pubspec.lock, and packages folder.
[Make sure you aren't storing your own libraries in the packages folder]
cd ~/dart/myApp/
rm -r packages
rm pubspec.lock
Now once you have removed these files:
pub cache repair
Note 1: if your dart-sdk is not in your systems $PATH, than you will want to use the absolute path to the sdk when using the above command. Comment if you need that explained.
Note 2: This is working solution with Dart 1.5.3. I have not tested this on earlier versions.
Try deleting your pubspec.lock file and packages directory in the root folder of the project. Then run pub install again, when things get wacky thats what I do.
You should try to run pub update. I have sometimes found that this doesn't work as expected from the editor, but generally works quite smoothly when called from the command line.

Why is dart pub suddenly trying to install packages in my css folder?

Running pub update ...
Pub update failed, [1] Resolving dependencies...
DirectoryIOException: Directory listing failed, path = <longpath>/web/css/packages (OS Error: No such file or directory, errno = 2)
Why would pub suddenly try to look for packages in my css folder?
The short answer, pub puts symlinks into subdirectories to ensure that you can use package: in any Dart file in any subdirectory of a "deployable" directory.
Because web is deployable in the sense that you'll likely take everything in web and throw it up on a web server, pub wants to make it easy for Dart files to work.
There are no conventions right now, so pub takes the optimistic approach because it can't anticipate where you might put Dart files.
Regardless, you shouldn't get an error, so this might be a bug. I just tried it on a brand new sample app with a web/css and pub install and pub update worked for me.
Can you please submit a bug at http://dartbug.com/new with details of your OS and the output of dart --version ? Many thanks!

Resources