Skip to content

Prefer packages from package.json #12

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

Closed
mgol opened this issue Mar 24, 2014 · 15 comments
Closed

Prefer packages from package.json #12

mgol opened this issue Mar 24, 2014 · 15 comments

Comments

@mgol
Copy link

mgol commented Mar 24, 2014

Currently jit-grunt first checks for grunt-contrib-package and then for grunt-package in the node_modules directory. I have a branch in my project switching from grunt-contrib-sass to grunt-sass. When I switch between branches I don't want or need to delete the other version as normally it's not loaded/used etc. However, jit-grunt first checks for grunt-contrib-sass, executes it & breaks because my config on this branch is targeted at grunt-sass.

jit-grunt should first check packages declared in package.json and only if no matching ones are found it should fall back to checking all packages present in node_modules.

@jrencz
Copy link

jrencz commented Mar 24, 2014

+1

@henrahmagix
Copy link

I think that's too much for jit-grunt to assume. Instead, have a git post-checkout hook reset your node_modules directory.

# .git/hooks/post-checkout
prevHEAD=$1
newHEAD=$2
checkoutType=$3
[[ $checkoutType == 1 ]] && checkoutType='branch' || checkoutType='file';

if [[ $checkoutType == 'branch' ]]
then
    rm -rf node_modules
    npm install
fi

For more on git hooks, see http://stackoverflow.com/a/20892987/3150057

@mgol
Copy link
Author

mgol commented Mar 24, 2014

This would take too long, I want to be able to switch between branches quickly.

Why is it too much to assume? This is only about the order in which packages are checked.

@henrahmagix
Copy link

Or you could create a static mapping: require('jit-grunt')(grunt, {'sass', 'grunt-sass'});

But perhaps you're right: package.json should already be available, and reducing the paths to be checked based on the dependencies would be possible.

@shootaroo
Copy link
Owner

I think this is rare case. Please use static mapping,
or uninstall only grunt-contrib-sass before npm install:

npm uninstall grunt-contrib-sass; npm install

I think npm install will be needed anyway if changed the branch, because version of the grunt plugins that is required will also change, etc.

@mgol
Copy link
Author

mgol commented Mar 25, 2014

Not necessarily. If I work on switching one of the plugins to a different one or do any other small changes, almost all dependencies will stay the same. This is exactly my use case.

Besides, if you are used to just doing npm install if a problem arises, you will be fine in 99% cases but not here. I'm sure other people using this project will stumble into problems after the switch unless I notify all of them they have to manually uninstall a package (which is less than ideal, not all of them will read the message etc.) or use a static mapping which is not really needed (to be consistent I'd have to define static mappings for all other ~20 packages that normally I don't have to).

@henrahmagix
Copy link

@mzgol I think the main point here is that your development environment should match the branch you're working on. In your case, having grunt-contrib-sass and grunt-sass installed alongside each other is causing you a problem that is solved by refreshing your development environment. It's not jit-grunt's task to assume your environment has other stuff in you want to ignore.

An alternative solution is to add grunt.loadNpmTasks('grunt-contrib-sass) and grunt.loadNpmTasks('grunt-sass) to your branches to distinguish them. jit-grunt won't bother loading a sass grunt task because it will already be available.

@shootaroo
Copy link
Owner

@mzgol I wrote a "rare case", but was means "exceptional case".
To be used by switching multiple plugins that use the same task name, this is a rare (exceptional) case.

(to be consistent I'd have to define static mappings for all other ~20 packages that normally I don't have to)

Has become a problem only that the grunt-contrib-sass is being used instead of grunt-sass. Add only static mapping to the grunt-sass.

require('jit-grunt')(grunt, {
    sass: 'grunt-sass'
});

Or PR please. I will merging if that is fast enough and simple.

@henrahmagix
Copy link

I think a PR fix for this will cause more problems, e.g. what about tasks that aren't listed in package.json? That file shouldn't be the decider of what tasks jit-grunt should find.

@shootaroo
Copy link
Owner

@henrahmagix Yes, of course. Resolution of that point is also a condition of the merge.

@henrahmagix
Copy link

👍 =D

@mgol
Copy link
Author

mgol commented Mar 26, 2014

I think a PR fix for this will cause more problems, e.g. what about tasks that aren't listed in package.json? That file shouldn't be the decider of what tasks jit-grunt should find.

Please read my report again. I explicitly stated that in the absence of the package in package.json the code should fallback to the current lookup algorithm.

I'll submit a PR soon.

@henrahmagix
Copy link

Oh yeah, sorry about that =)

@paazmaya
Copy link

I had the exact same need, but ended up moving the node_modules/grunt-*sass directory outside of the scope depending on which one I wanted to use.

@shootaroo
Copy link
Owner

Closing due to inactivity.

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

No branches or pull requests

5 participants