Why should I use ember install over NPM or yarn? - ember.js

I'm new to ember and I discover the command ember install pkg and I'm wondering why such package instead of using external package manager such as yarn or npm which are industry-wide/de-facto standard.
Question
Why should I use ember install over NPM or yarn?

ember install addon-name is a short hand for npm install --save-dev addon-name && ember g addon-name

The documentation provides the answer for this one (ctrl + f ember install):
Installs the given addon into your project and saves it to the
package.json file. If provided, the command will run the addon’s
default blueprint.
The release notes for version 0.1.5 provide a clue for this as well:
#2805 Added the install:addon command, which installs an addon with NPM and then runs the included generator of the same name if it
provides one.
So, ember install is just a replacement for npm in most cases but when a blueprint is provided it will run those as well.

Related

Using Gulp with Visual Studio Team Services

I'm looking to set up automated builds with Visual Studio Team Services but I keep running into trouble. My build definition:
npm install gulp
npm install --save-dev jshint gulp-jshint ruby
npm install gulp-ruby-sass gulp-autoprefixer gulp-cssnano gulp-concat gulp-uglify gulp-imagemin gulp-notify gulp-rename gulp-livereload gulp-cache del --save-dev
gem install sass
gulp
The build fails when attempting to install the sass gem with "'gem' is not recognized as an internal or external command". If I build without installing the sass gem first, gulp will fail with "'sass' is not recognized as an internal or external command". Anyone have experience with getting sass to work in Visual Studio Team Services?
There seem to be several issue here. First you might need to make you familiar how npm works, whats the meaning of --save-dev and whats the difference between local and globally installed modules.
--save-dev is used to save the package for development purpose, while --save is used to save the package required for the application to run. Both are commands which you run on your development machine and you put the resulting package.json under version control.
On the build server you will just run an npm install which will restore all the packages listed in the package.json.
These is for local modules. You can also install modules globally using the -g flag. This will store them outside of your current project, and binaries will be available in your PATH variable. Modules which you need inside your project (using require) need to be installed locally. Modules you'll call from the shell (eg gulp-cli) need to be installed globally.
Therefore what you need to do:
On your development machine add all local npm modules using npm install with either the --save or --save-dev flag.
Put the resulting package.json file under version control.
On the build server you need to make sure that all required global npm modules are installed.
Call npm install using the VSTS npm task to restore the local npm modules. You won't need to specify which modules need to be installed, since they're already listed in the package.json file.
Call gulp using the VSTS gulp task with the appropriate arguments.

Ember Addons and bower dependencies versioning

(related, very similar, but not the same as this question, as my question is looking for the scenario where node_modules is lost and re-fetched through npm install and on the topic of keeping deps current in general.)
Let A be an addon in version a1, and let B be a bower dependency of that addon in version b1. The addon installs its bower package through the default blueprint like
afterInstall: function() {
// b1 is the version.
return this.addBowerPackageToProject('B', 'b1');
}
Now let C be an application consuming A. When A is installed using ember install A
The bower package is actually installed in C. Up to here, things are fine. Now A is updated to version a2, including B in version b2. In C,
rm -R node_modules
npm cache clean
npm install
(checking out C with no node_modules and running npm install will run into a similar problem if the bower.json is old)
will fetch A.a2.
Should A.a2's default blueprint run and cause C to install B.b2 as well? (this is the actual question asked here)
if the blueprint is run manually, B.b2 actually gets prompted for, that is, you get to see that the project has a bower conflict now and are asked how to resolve it.
I tried it out now, it doesn't work. If I specify a postinstall script for npm (ember g testaddon), it doesn't work either (because npm tries to install the packages in a different order and ember-cli isn't installed when the postinstall script runs).
What good is it to have blueprints propagate bower dependencies if one does have to check them manually anyway? Am I understanding this wrongly? Is this intended behaviour?
I totally agree. ember-cli currently does nothing on upgrade or uninstall of an npm package, and this is a problem for addons. Addons should be able to specify blueprints that run on version upgrade and uninstall. Alternatively, there should be an 'ember upgrade' and 'ember uninstall' commands that run such blueprints if available.
The addon could then in the upgrade blueprint cause C to install B.b2 if it is not already installed.
Anyone who would like to formally propose this, the way to do so is opening a pull request at https://github.com/ember-cli/rfcs

Installing Ember.js 2.2

I tried do install Ember.js v2.2 by following the official instructions: http://guides.emberjs.com/v2.2.0/getting-started/
installed Node.js and npm
installed Git
installed the Ember CLI via npm install -g ember-cli
Everything should be fine now.
But when I type ember -v to verify the Ember version, it says: 1.13.13
I did follow the 2.2 Instructions to the point, but I didn't get Ember.js 2.2 installed.
Any suggestions? I use Win 7.
For ember 2.2 + ember-data 2.3.1:
ember new <project> && cd <project>
Edit bower.json in your project root directory (you're there already if you followed the previous command):
Replace ember-cli-shims version number to 0.1.0
Replace ember version number to 2.2
Remove the ember-data dependency line
Add the following code just above the last }
,
"resolutions": {
"ember": "^2.2.0"
}
Edit package.json in your project root directory:
Replace ember-data version number to 2.3.1
Clean the caches, update the project dependencies and then restart ember:
npm cache clean && bower cache clean && npm install && bower install
ember serve
And you're done. Open your browser console and you should see debug messages with the 2.2 version of ember and 2.3.1 version of ember-data.
ember on the command line is actually invoking Ember-CLI, so ember -v will show you the version you have for Ember-CLI. When you do ember new <your project> to create a project then you can manually change the Ember and Ember Data dependency versions in bower.json and package.json. Make sure to update both files (for now at least) and rerun npm install and bower install in the project's root directory.
The Ember version set by default with ember-cli does not track the most recent version of Ember, but you can update to 2.x. See the changelog.
Ember itself you will interact with in the browser after running ember server and going to your localhost.

How do I use my fork of ember-data in ember-cli?

I'm working on a pull-request for ember-data, and I'd like to be able to test these changes in my ember-cli app.
It doesn't work to follow the directions for using canary here or here, as my fork does not get built my components.
I've tried referencing my fork and branch in packages.json as well as bower.json; then I get this error:
Path or pattern "bower_components/ember-data/ember-data.js" did not match any files
I can then build ember-data manually and copy the file to bower_components/ember-data/ember-data.js. However, I would like a streamlined way to use a fork of ember-data so I can use and test my pull-request without a lengthy install process.
Is there a better way?
Thanks!
You can use a symlink to your local version of a bower and/or npm dependency.
Go to your local (forked) version of ember-data and
npm link
bower link
This will make a global symlink to your local version.
Then go to where you're using the dependency and
npm link ember-data
bower link ember-data
This will make node_modules/ember-data and bower_components/ember-data a symlink to your local version.
See https://docs.npmjs.com/cli/link and http://bower.io/docs/api/#link for more details on how these work.
You are getting that error because you are trying to use the NPM package of ember-data with Bower, and Bower needs ember-data to be precompiled. You were correct to fork emberjs/data and reference your fork in package.json. Here is how I compiled my fork for bower:
In your forked repo, run npm install and npm run build:production to compile your fork in the dist directory.
Then fork the ember-data shim for bower: components/ember-data. Copy the following files from your ember-data fork's dist directory into the shim's directory:
bower.json
component.json
composer.json
ember-data.js
ember-data.js.map
ember-data.min.js
ember-data.prod.js
package.json
Edit the bower/package files if you want to add your own version tag. Commit the shim repo to a branch or master, and then reference that commit in your ember-cli app's bower.json file. Then run npm install and bower install in your ember-cli app.

Not possible to install add-on for ember-cli

I am trying to test the ember-select-2 component. It is advertised as very easy to set-up. According to the readme:
# install addon from npm repository
$ npm install ember-select-2
# install dependencies
$ ember g ember-select-2
Installing the add-on works:
» npm install ember-select-2
But installing the dependency fails:
» ember g ember-select-2
version: 0.1.2
Unknown blueprint: ember-select-2
The only thing I have been able to find is that ember-select-2 is an extraneous npm package (whatever that means)
» npm list ember-select-2
test13#0.0.0 .../test13
└── ember-select-2#1.0.1 extraneous
This is my ember-cli installatioon:
» ember --version
version: 0.1.2
node: 0.10.25
npm: 2.1.3
How did I manage to break such a simple how-to?
EDIT
I did some research: extraneous just means that it is not in the package.json. Adding --save solves that. So that is just a warning, and not the source of my problem.
If you don't set the save flag, the package isn't added to your package.json file as a dependency it is only downloaded into node_modules, you will either have to add it manually or use the flag and have it save you a step.
--save: Package will appear in your dependencies.
--save-dev: Package will appear in your devDependencies.
--save-optional: Package will appear in your optionalDependencies.
When using any of the above options to save dependencies to your
package.json, there is an additional, optional flag:
--save-exact: Saved dependencies will be configured with an exact version rather than using npm's default semver range operator.
More info can be found in the npm install docs.
As the maintainer of the package, I apologize for the inconvenience caused by the documentation.
I immediately fixed the command to include --save-dev, which seems to be the right way to install ember-cli addons.