I am trying this, and it works great for terminal applications to reference $HOME/.pub-cache/bin
Can I use an activated local package from other local projects?
Steps:
1. pub global activate --source path . From package project
2. Then how to use this in another project pubspec.yaml dependencies: section?
I know I can use path, but this is much better for dynamic reference reasons.
If I add this in pubspect.yaml dependencies in the project using cli2 package:
dependencies:
cli2: 0.0.0 # name of: pub global activate --source path .
I get this error:
Because usecli2 depends on cli2 any which doesn't exist (could not find package cli2 at https://pub.dartlang.org), version solving failed.
pub global activate is to install Dart scripts from bin/ of a package as command line executables and is completely unrelated to adding dependencies to a project.
You can use relative paths to add local dependencies:
dependencies:
cli2
path: ../cli2
Related
Does Pub Package Manager provide a way to install packages globally?
I have been a node.js developer for a while and I was wondering if there was a pub equivalent of npm install -g <package_name>
If there is a way to install packages globally, is there a way to register binary scripts which can be installed to be invoked like shell commands.
dependencies
All pub packages are installed globally (a unique subdirectory below ~/.pub-cache/ for Mac/Linux AppData\Roaming\Pub\Cache in Windows, for each package version) and is then only linked to your project you add the dependency in pubspec.yaml.
Actually ~/pub-cache is only global for a user not global as for the entire system. I don't know npm well but I think npm install -g installs it global to the system. There is nothing similar in Dart but you don't install a package in Dart anyway. When you use a Pub package in the same version in different packages it is saved only once on the drive.
global package executables
Packages containing executable scripts can be globally (per user) activated using pub global activate .... If you add the ~/.pub-cache/bin/ directory to your path you can run these executable Dart scripts just by their name (like tuneup for the tuneup package) or with pub global run packagename:scriptName (like pub global run tuneup:tuneup) If script and package name are the same you can omit the :scriptName part.
local package executables
You can also run scripts from dependencies of your current project with pub run packageName:scriptName (like pub run test for running unit tests)
I'm trying to play with https://github.com/dart-lang/web-ui-code-lab for dart development. If I follow the pdf and open step05, then try to run chat_server.dart, I get this error (my path has no spaces in it, in case that's relevant):
dart --enable-checked-mode bin/chat_server.dart
Unable to open file: path/to/web-ui-code-lab-master/step05/bin/packages/dart_chat/file_logger.dart'file:///path/to/dart/web-ui-code-lab-master/step05/bin/chat_server.dart': Error: line 5 pos 1: library handler failed
import 'package:dart_chat/file_logger.dart' as log;
^
I presume this means that there are some missing dependencies, but I can't run pub install because I'm behind a corporate http proxy:
Running pub install ...
Pub install failed, [1] Resolving dependencies...
Timed out trying to find package "web_ui 0.2.8+6" at http://pub.dartlang.org.
Hence, I started looking for a temporary workaround for pub dependency resolution. I tried changing the pubspec.yaml to go through the git:// protocol instead of http (which won't resolve without going through the proxy):
name: dart_chat
description: This is a chat app written in Dart using the Dart Web UI package
dependencies:
web_ui:
git: git://github.com/dart-lang/web-ui.git
I get further than before with pub install, so I think it successfully went through the git protocol and is trying to resolve web_ui's dependencies, but unfortunately doing so fails on web_ui's dependency for logging (which looks like it's still going through http://):
Running pub install ...
Pub install failed, [1] Resolving dependencies...
Timed out trying to find package "logging 0.2.7" at http://pub.dartlang.org.
It looks like I can't change the yaml to use the sdk's logging dependency either:
logging:
sdk: logging
because that's an incompatible source with web_ui:
Pub install failed, [1] Resolving dependencies...
Incompatible dependencies on 'logging':
- 'dart_chat' depends on it from source 'sdk'
- 'web_ui' depends on it from source 'hosted'
Is there any other way to get around this proxy issue with the current dev tools? Could I mirror pub.dartlang.org somehow? Or mirror the git repositories for each dependency? Thanks.
You said that you're using a Mac. If it's a laptop, why don't you try doing it from home? I'll notify the author of pub about this issue to see if he has any suggestions.
Currently there is no way to set a proxy in the Dart Editor, you can star this issue to check when it will be available.
I found a workaround to run the Pub install/update behind a proxy: in Windows, you can acess the "Environment variables" and add a variable named HTTP_PROXY with the value
https://USER:PASSWORD#my.proxy.adress:PORT
I installed the dependencies from this tutorial http://docs.rikulo.org/rikulo/latest/UXL/Fundamentals/UXL_Overview.html
dependencies:
rikulo_uxl:
git: git://github.com/rikulo/uxl.git
trying to compile with uc.dart
I get:
Error: line 8 pos 1: library handler failed
import 'package:args/args.dart';
what is wrong? missing path?
This normally happens when you reference a package that isn't found on disk. You should ensure you have the package listed in your pubspec.yaml and that you've run pub get. You can also check that inside your packages folder you can see a folder named args.
I've created a simple project. This is my pubspec.yaml
name: testapp
description: test application
dependencies:
html5lib: 0.0.12
And now i get this error
Pub install fail, Resolving dependencies...
Package "html5lib" doesn't have a pubspec.yaml file.
I'm guessing you are on windows? Dart seems to setup shortcuts (hard dir links?) between the packages folder in a project and where the packages are stored. So if you delete your packages dir from within Eclipse, it will trash the folder that stores the actual package.
On Windows 7, the folder is:
C:\Users\[user]\AppData\Roaming\Pub\
Go ahead and delete its contents and run pub install again.
If you start getting errors about UnitTest or other core libraries, you may need to re-download the Dark-SDK (or dart editor) and replace it.
I am trying to install glmatrix using pub install. My OS is Windows 7 and I have Git installed.
Here is my pubspec.yaml
name: WebGLTut1
description: A sample application
dependencies:
glmatrix:
git: git://github.com/pjako/glmatrix.dart.git
When I run pub install I get the following error:
Running pub install ... Pub install fail, FormatException: Could not
parse "git://github.com/pjako/glmatrix.dart.git".".
I googled a while to find a solution but couldn't. Please help.
UPDATE#1:
I found the problem. There has to be a TAB/Space when specifying git: url in pubsec.yaml as follows.
glmatrix:
git: git://github.com/pjako/glmatrix.dart.git
This solved the previouse problem of FormatException. But now when I run pub install again it throws theis error.
Running pub install ... Pub install fail, Git failed.
As you identified you update, yaml files are whitespace sensitive; that's why you don't have to use lots of curly braces like json. :)
I see a few of possible problems here:
First
Glmatrix doesn't appear to have its own pubspec defined. Libraries participating in the package system much declare a pubspec file with the name property defined. The name is important because pub uses it when you declare your dependencies. Let's say you had a project called toast with the following simple pubspec:
name: butter
version: 0.0.0
Then you would need to declare your dependency to that project like so:
dependencies:
butter:
git: git://github.com/foo/toast.git
Have the project owner make the changes or fork it yourself, add the pubspec, and then reference your fork in your pubspec.
Second
Glmatrix is does not conform to the pubspec package layout conventions (your own projects should also conform to this). Although I believe that pub may handle non-conforming layouts currently, it may not in the future. So again, you can either ask the project owner to fix, or fork and fix it yourself.
Third
Since you are on windows, make sure git is in your system PATH variable. If you are using the bash shell, git will work, but it's not going to work outside of bash (like from Dart editor) until you add it to your PATH.