From 561a5b2b2e40d22c94fb82ae8e74ff4c1095ebd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Cruz?= Date: Thu, 25 Apr 2013 13:27:47 +0100 Subject: [PATCH] Remove events. --- NOTES.md | 2 ++ README.md | 9 +----- lib/resolve/Resolver.js | 12 ++------ test/resolve/resolver.js | 64 ++++------------------------------------ 4 files changed, 11 insertions(+), 76 deletions(-) diff --git a/NOTES.md b/NOTES.md index 680e436f..606dbaf6 100644 --- a/NOTES.md +++ b/NOTES.md @@ -44,3 +44,5 @@ - bower could setup a git hook on folders that are github repos to make validation of the json (if it conforms with the spec) - in prod dont forget to Q.longStackJumpLimit = 0; - switch from events to promise progress + - wait for domenic response on twitter + - progress events: name_change, warn (deprecated json, mismatch version..), action diff --git a/README.md b/README.md index 2c959876..2fb948c6 100644 --- a/README.md +++ b/README.md @@ -157,8 +157,7 @@ TODO #### Resolver -The `Resolver` class extends `EventEmitter`. -Think of it as an abstract class that implements the resolver interface as well as serving as a base for other resolver types. +Think of `Resolver` as an abstract class that implements the resolver interface as well as serving as a base for other resolver types. Resolvers are responsible for the following: @@ -170,12 +169,6 @@ Resolvers are responsible for the following: - Storing the `package meta` into a `.bower.json` hidden file. -##### Events - -- `name_change`: fired when the name of the package has changed -- `action`: fired to inform the current action being performed by the resolver -- `warn`: fired to inform a warning, e.g.: deprecation - ##### Constructor `Resolver(source, options)` diff --git a/lib/resolve/Resolver.js b/lib/resolve/Resolver.js index 7a30da61..f8674aa2 100644 --- a/lib/resolve/Resolver.js +++ b/lib/resolve/Resolver.js @@ -1,7 +1,5 @@ -var util = require('util'); var fs = require('fs'); var path = require('path'); -var events = require('events'); var Q = require('q'); var tmp = require('tmp'); var mkdirp = require('mkdirp'); @@ -24,8 +22,6 @@ var Resolver = function (source, options) { this._config = options.config || config; }; -util.inherits(Resolver, events.EventEmitter); - // ----------------- Resolver.prototype.getSource = function () { @@ -112,7 +108,7 @@ Resolver.prototype._readJson = function (dir) { .then(function (filename) { // If it is a component.json, warn about the deprecation if (path.basename(filename) === 'component.json') { - this.emit('warn', 'Package "' + this._name + '" is using the deprecated component.json file'); + //deferred.notify({ type: 'warn', data: 'Package "' + this._name + '" is using the deprecated component.json file' }); } // Read it @@ -134,17 +130,13 @@ Resolver.prototype._applyPkgMeta = function (meta) { // If so and if the name was "guessed", assume the json name if (this._guessedName) { this._name = meta.name; - this.emit('name_change', this._name); - // Otherwise use/force the configured one + // Otherwise force the configured one } else { meta.name = this._name; } } // Handle ignore property, deleting all files from the temporary directory - // TODO: Think better about this... some concrete resolvers can handle the ignore property - // in a more efficient way. - // In such cases, this step should be skipped if (meta.ignore && meta.ignore.length) { return Q.nfcall(glob, '**/*', { cwd: this._tempDir, dot: true, mark: true }) .then(function (files) { diff --git a/test/resolve/resolver.js b/test/resolve/resolver.js index 2b007272..11b611e7 100644 --- a/test/resolve/resolver.js +++ b/test/resolve/resolver.js @@ -362,23 +362,16 @@ describe('Resolver', function () { .done(); }); - it('should fallback to component.json (emitting a "warn" event)', function (next) { - var resolver = new Resolver('foo'), - warn; + it('should fallback to component.json', function (next) { + var resolver = new Resolver('foo'); fs.writeFileSync(path.join(tempDir, 'component.json'), JSON.stringify({ name: 'bar', version: '0.0.0' })); - resolver.on('warn', function (data) { - warn = data; - }); - resolver._readJson(tempDir) .then(function (meta) { expect(meta).to.be.an('object'); expect(meta.name).to.equal('bar'); expect(meta.version).to.equal('0.0.0'); - - expect(warn).to.contain('deprecated'); next(); }) .done(); @@ -422,75 +415,30 @@ describe('Resolver', function () { .done(); }); - it('should fire the "name_change" event if the json name is different than the guessed one', function (next) { - var resolver = new Resolver('foo'), - newName; - - resolver.on('name_change', function (name) { - newName = name; - }); + it('should use the json name if the name was guessed', function (next) { + var resolver = new Resolver('foo'); resolver._applyPkgMeta({ name: 'bar' }) .then(function (retMeta) { expect(retMeta.name).to.equal('bar'); expect(resolver.getName()).to.equal('bar'); - expect(newName).to.equal('bar'); next(); }) .done(); }); - it('should not fire the "name_change" event if the json name is different but the name was not guessed', function (next) { - var resolver = new Resolver('foo', { name: 'foo' }), - newName; - - resolver.on('name_change', function (name) { - newName = name; - }); + it('should not use the json name if a name was passed in the constructor', function (next) { + var resolver = new Resolver('foo', { name: 'foo' }); resolver._applyPkgMeta({ name: 'bar' }) .then(function (retMeta) { expect(retMeta.name).to.equal('foo'); expect(resolver.getName()).to.equal('foo'); - expect(newName).to.not.be.ok(); next(); }) .done(); }); - it('should not fire the "name_change" event the json name is the same', function (next) { - var resolver = new Resolver('foo'), - newName; - - resolver.on('name_change', function (name) { - newName = name; - }); - - resolver._applyPkgMeta({ name: 'foo' }) - .then(function (retMeta) { - expect(retMeta.name).to.equal('foo'); - expect(resolver.getName()).to.equal('foo'); - expect(newName).to.not.be.ok(); - - resolver = new Resolver('foo', { name: 'foo' }); - - resolver.on('name_change', function (name) { - newName = name; - }); - - resolver._applyPkgMeta({ name: 'foo' }) - .then(function (retMeta) { - expect(retMeta.name).to.equal('foo'); - expect(resolver.getName()).to.equal('foo'); - expect(newName).to.not.be.ok(); - next(); - }) - .done(); - }) - .done(); - }); - - describe('handling of ignore property according to the .gitignore spec', function () { it.skip('A blank line matches no files, so it can serve as a separator for readability.'); it.skip('A line starting with # serves as a comment.');