Skip to content

Add getProjectPath() to compute path to parent project #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 1, 2017
Merged

Conversation

alisianoi
Copy link
Collaborator

Previously, process.cwd() did the job just fine but with node v8.1.2
(compared to 7.10.0 at least) the output has changed. So, use the
following hack: when installing a node package, npm adds it to PATH.
Since we know:
a) the suffix of that path entry (commitplease/node_modules/.bin)
b) the fact that the other project is installing commitplease

then find that entry and use its prefix as parent project path

Refs: jquery/jquery#3708

@alisianoi alisianoi force-pushed the fix-3708 branch 4 times, most recently from 73e6b6b to f0adfd8 Compare July 5, 2017 07:48
@jzaefferer
Copy link
Owner

Looks alright to me. Can we do this without adding the ends-with dependency?

@alisianoi
Copy link
Collaborator Author

I see two ways here: drop node 0.12 (which I know you secretly want to, wink-wink) or code it completely by hand. Your choice.

@jzaefferer
Copy link
Owner

Let's drop node 0.12! Anything before 4.x has been dead to me for a while :shipit:

@jzaefferer
Copy link
Owner

Can bump a major version to make that drop more obvious.

@alisianoi
Copy link
Collaborator Author

Ok, done. I've also manually tested installing/uninstalling commitplease which resulted in further changes to getProjectPath, please try it out before you decide to merge. The install.js script needed adjusting because path.relative also relies on current working directory (source https://nodejs.org/api/path.html#path_path_relative_from_to) and silently failed to work properly too. Should be alright now though.

@alisianoi alisianoi requested a review from jzaefferer July 18, 2017 10:07
@alisianoi
Copy link
Collaborator Author

Spoke too soon. Travis tells me I have not accounted for self-install. Fair enough, let me hack a bit more.

@alisianoi alisianoi removed the request for review from jzaefferer July 18, 2017 10:54
@alisianoi
Copy link
Collaborator Author

Add early opt-out check for self-install, ready for review.

@alisianoi alisianoi requested a review from jzaefferer July 18, 2017 10:57
Copy link
Owner

@jzaefferer jzaefferer left a comment

Choose a reason for hiding this comment

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

Looks good! I didn't test anything locally, though what you described from your tests seems good enough. Thank you!

var pkg = fs.existsSync(pkgPath) && require(pkgPath)

if (pkg && pkg.name && pkg.name === 'commitplease') {
console.log('commitplease: self-install detected, skipping hooks')
Copy link
Owner

Choose a reason for hiding this comment

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

I was surprised that this was missing, apparently we lost it earlier - I remember writing a similar check originally. After a bit of digging I found the original code: 2021ce3#diff-fcd5628e27bdebc81efd345a905292c3L1

I guess this new implementation using options.projectPath makes more sense, now that we have that in place. I didn't notice anything from the old implementation that would change this one - do you?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, now I remember: setup.js was reused in both install.js and uninstall.js, I did not fully understand it and split the two files completely, dropping setup.js. That is when I lost the self-install check.

Anyway, on the one hand I still do not fully understand how that setup used to work. On the other hand, current getOptions() -> getProjectPath() logic is clear to me: while constructing the options, find the best candidate for the project path. If that project path contains a package.json with name: commitpealse, then do not copy the hooks. That logic I tested and it works.

@jzaefferer
Copy link
Owner

Let's land it.

Alexander Lisianoi added 9 commits October 1, 2017 15:24
Previously, process.cwd() did the job just fine but with node v8.1.2
(compared to 7.10.0 at least) the output has changed. So, use the
following hack: when installing a node package, npm adds it to PATH.
Since we know:
a) the suffix of that path entry (commitplease/node_modules/.bin)
b) the fact that the other project is installing commitplease

then find that entry and use its prefix as parent project path

Refs: jquery/jquery#3708
- during install, look for `node_modules/commitplease/node_modules/.bin`
- during usual trigger, look for `node_modules/.bin`
Commitplease is called by either npm or git which in turn supply
different process.cwd() information. Use custom getProjectPath()
function to more reliably determine where the project is actually
located.
@alisianoi alisianoi merged commit b81d9c1 into master Oct 1, 2017
@alisianoi
Copy link
Collaborator Author

Done, I've also written a short release summary:

https://github.com/jzaefferer/commitplease/releases/tag/v3.0.0

The v3.1.0 tag is there just not to bother with picking/rebasing the v3.0.0 tag.

@jzaefferer jzaefferer deleted the fix-3708 branch October 1, 2017 16:40
@jzaefferer
Copy link
Owner

Nice :-) Summary is looking good, helps explain the major version bump.

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.

2 participants