Skip to content

Refactor env.register logic (Fix #353)#354

Merged
addyosmani merged 1 commit intoyeoman:masterfrom
SBoudrias:test-76
Oct 20, 2013
Merged

Refactor env.register logic (Fix #353)#354
addyosmani merged 1 commit intoyeoman:masterfrom
SBoudrias:test-76

Conversation

@SBoudrias
Copy link
Member

env.register now only accept the generator path as a String. This force
the generator.resolved behaviour to be consistent. At the same time,
removed any check for generator.raw; this is an unexpected side effect
and obfuscate the code for very little gain.

Added env.registerStub method to allow adding stub generators as
function to the environment. A check is made on the function passed
to force stubbed generators to extend Base (this is done automatically).

Some test mechanics needed to be fixed in order to pass. This shouldn't
have changed the tests logic.


The motivation behind this change is explained in #353. Basically it's a follow up after the 1.0 release bug to update what felt to me like an error prone logic and to make sure generator.resolved value was consistent no matter what.

@SBoudrias
Copy link
Member Author

BTW, I sent the PR right now to follow up on the issue and some review.

I'll clean up some tests as I only added env.registerStub later on the refactor process to make it easier to update tests. So some changes in the tests could be reverted to make the diff smaller.

Also, env.register require every available generator. That's not super smart, so I'll fix that too.

edit, adding stuff to the todos:

  • Updating inline doc
  • Add unit test for registerStub
  • Add unit test for rootGeneratorName

test/env.js Outdated
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to refactor this test to use regexp rather than plain text comparison as using Object.defineProperty in register does not order objects the same way in Node.js 0.8 and 0.10

(As a side effect, now this test can pass on Windows)

Relevant Travis.CI failed job: https://travis-ci.org/yeoman/generator/builds/11264918

@SBoudrias
Copy link
Member Author

Ok, I cleared the remaining points I had forgotten yesterday.

I also added unit test for the generator.rootGeneratorName as this was missing previously, and as this PR slighty changed the behavior (so it won't break on failure).

Should be ready for revision 😋

lib/env.js Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there perhaps some nicer way to expand this?

// @sindresorhus

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, there's a feature request for it on node core issue tracker, but that's the best way right now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though I would go with if (filepath[0] === '~') {

@SBoudrias
Copy link
Member Author

Any news on this?

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 390faf7dde6b522d9159d3b649ddfb46dc05e15d on SBoudrias:test-76 into 4b330bb on yeoman:master.

@sindresorhus
Copy link
Member

Tests fail on node 0.8

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling dd8fa6406e856a604913cf3a828e5d29f838923f on SBoudrias:test-76 into 24d93b5 on yeoman:master.

env.register now only accept the generator path as a String. This force
the generator.resolved behavior to be consistent. At the same time,
removed any check for `generator.raw`; this is an unexpected side effect
and obfuscate the code for very little gain.

Added env.registerStub method to allow adding stub generators as
function to the environment. A check is made on the function passed
to force stubbed generators to extend Base (this is done automatically).

Some test mechanics needed to be fixed in order to pass. This shouldn't
have changed the test logic.
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.04%) when pulling 17afe79 on SBoudrias:test-76 into 24d93b5 on yeoman:master.

@SBoudrias
Copy link
Member Author

@sindresorhus Yeah, I rebased yesterday, and I wasn't happy with how the failing test was resolved. I fixed that on the lastest.

@addyosmani
Copy link
Member

Reviewed. Thanks for rebasing, Simon!

addyosmani added a commit that referenced this pull request Oct 20, 2013
Refactor env.register logic (Fix #353)
@addyosmani addyosmani merged commit 53eafa6 into yeoman:master Oct 20, 2013
@SBoudrias
Copy link
Member Author

Yay! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants