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)
Related
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
I have a ASP.Net 4.5 MVC application which uses Angular 1.5. The JS code is Typescript and a post build action builds the js code and deploys it to the folder where my application refers to.
I have a Slot on my azure web app which is backed my gitlab repo. Committing to the repo, triggers the deployment, however the post deployment build frequently seems to have issues when a bower/npm or typings library is updated (which is resolved by manually clearing the folder via the kudu console). Does someone have an example of a deploy.cmd script which does the equivalent of
npm install
typings install
at the correct point in the pipeline so that the files get deployed correctly.
I want to start scratch with a new slot, and to get the existing slot to work in the past i had to manually install typings for example "npm install typings --global" in order to get the build to work without a typings error.
Update Output Below
I'm guessing that the errors below are due to azure running typescript 1.6 compiler over reference files which need typescript > 1.6.
My csproj has <TypeScriptToolsVersion>2.0</TypeScriptToolsVersion>
(ive removed my files from the compile output, but the _all.d.ts file does reference the errored files below
CompileTypeScript:
D:\Program Files (x86)\Microsoft SDKs\TypeScript\1.6\tsc.exe --sourcemap --target ES5 --noEmitOnError "REMOVED MY TYPESCRIPTFILES" "D:\home\site\repository\mymvcproject\app\src\_all.d.ts"
D:\home\site\repository\mymvcproject\typings\globals\angular\index.d.ts(1824,32): error TS1110: Build: Type expected. [D:\home\site\repository\mymvcproject\mymvcproject.csproj]
D:\home\site\repository\mymvcproject\typings\globals\angular\index.d.ts(1824,50): error TS1005: Build: ']' expected. [D:\home\site\repository\mymvcproject\mymvcproject.csproj]
D:\home\site\repository\mymvcproject\typings\globals\angular\index.d.ts(1824,58): error TS1005: Build: ',' expected. [D:\home\site\repository\mymvcproject\mymvcproject.csproj]
D:\home\site\repository\mymvcproject\typings\globals\angular\index.d.ts(1824,59): error TS1136: Build: Property assignment expected. [D:\home\site\repository\mymvcproject\mymvcproject.csproj]
D:\home\site\repository\mymvcproject\typings\globals\angular\index.d.ts(1941,1): error TS1128: Build: Declaration or statement expected. [D:\home\site\repository\mymvcproject\mymvcproject.csproj]
Done Building Project "D:\home\site\repository\mymvcproject\mymvcproject.csproj" (Build;pipelinePreDeployCopyAllFilesToOneFolder target(s)) -- FAILED.
FINAL UPDATE
After the typescript team finally generated a version of typescript 2.* which could be installed on Azure, and then the Kudu team deployed it. Now the whole process works! the note from below about using
"preinstall": "npm install typescript -g && npm install typings -g"
Was the other part of the solution!
According to your requirement, you could follow the steps below to achieve your purpose.
Create a deployment script
You could log in to KUDU tool (https://.scm.azurewebsites.net/), click "Tool" > "Download deployment script". Also, you could leverage azure-cli to generate the script. For more details about how to generate deployment script via azure-cli, you could refer to this tutorial.
Customize the deployment script
For using NPM to manage your packages, you could add the following scripts in your package.json file.
"scripts":{
"preinstall": "npm install typescript -g && npm install typings -g"
}
Then, you need to add the following scripts to the deploy.cmd file.
IF EXIST "%DEPLOYMENT_SOURCE%\package.json" (
pushd "%DEPLOYMENT_SOURCE%"
echo installing npm package
call :ExecuteCmd npm install --production
IF !ERRORLEVEL! NEQ 0 goto error
popd
)
Or you could add the following scripts to install typescript and typings directly via command line.
echo Installing typescript and typings
call npm install typescript -g && npm install typings -g
IF !ERRORLEVEL! NEQ 0 goto error
Note: The .deployment, deploy.cmd files need to be placed in the root directory of your solution. You could refer to this sample project for details.
I have a deploy.cmd script that I built using these steps. It is being used to package a project up for deployment to Azure. In it there is this line:
IF EXIST "%DEPLOYMENT_TARGET%\bower.json" (
pushd "%DEPLOYMENT_TARGET%"
call :ExecuteCmd .\node_modules\.bin\bower install
IF !ERRORLEVEL! NEQ 0 goto error
popd
When I test the script locally, it fails because there is no bower command in the .bin directory. I have installed bower using -g and have used it to install project packages. But I can't figure out how it's supposed to make it into this folder.
It'll make it to that folder if you run npm install bower without -g. -g is meant to install tools globally to be available anywhere on your commandline, while not adding -g will install it locally in the node_modules folder
After starting with a new ionic app, I can see at bower.json that comes with ionic is in devdependencies. Why is it a devdependency and not a normal dependency?
"devDependencies": {
"ionic": "driftyco/ionic-bower#1.0.0-rc.0"
},
Thanks, I feel confused right now
having devDependencies gives you the opportunity to simplify the steps that drive you from the source files (a git clone of the project) to the production ready app
when you don't need to make changes and (develop) the application, you could just run
bower install --production
or
npm install --production
they work the same
bower install options
-F, --force-latest: Force latest version on conflict
-p, --production: Do not install project devDependencies
-S, --save: Save installed packages into the project’s bower.json dependencies
-D, --save-dev: Save installed packages into the project’s bower.json devDependencies
-E, --save-exact: Configure installed packages with an exact version rather than semver
bower documentation
npm install options
By default, npm install will install all modules listed as
dependencies. With the --production flag (or when the NODE_ENV
environment variable is set to production), npm will not install
modules listed in devDependencies.
npm documentation
This way you take less time to ship the app and don't waste bandwidth downloading stuff you won't need.
Given that, to me, the choice of listing ionic as devDependecy is a poor one: it implies that I could take advantage of this choice to get ready the app for execution this way:
git clone my-project
git cd my-project
npm install --production # ionic not installed here
ionic state restore
ionic build ios
Now, if you ignore the content of /lib folder in your sources, this should not work, and if it works because the ionic-cli does some more checks to save your ass, I think this is unclear.
From what I understand, dependencies are required to run, and devDependencies are only for development, like minification, unit tests, etc.
Both will install when you do npm install but only dependencies will install when you do npm install $package, unless you add the --dev option
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.