Giter VIP home page Giter VIP logo

yarnhook's Introduction

yarnhook npm version

yarnhook

yarnhook keeps your node_modules up-to-date when your yarn.lock, package-lock.json or shrinkwrap.yaml changes due to git operations like checkout, merge, rebase, pull etc.

Easy installation

You can install yarnhook to your project with mrm.

npx mrm yarnhook

Manual installation

This package should be used with husky.

yarn add --dev yarnhook husky
# or
npm install --save-dev yarnhook husky
# or
pnpm install --save-dev yarnhook husky

Configuration

You should let yarnhook handle git hooks that change the dependencies. Example package.json is as follows:

{
  "husky": {
    "hooks": {
      "post-checkout": "yarnhook",
      "post-merge": "yarnhook",
      "post-rewrite": "yarnhook"
    }
  }
}

Flags

Prepend these flags to your git command to use them.

  • YARNHOOK_BYPASS: Run git command bypassing yarnhook completely
  • YARNHOOK_DEBUG: Print debug information
  • YARNHOOK_DRYRUN: Don't install dependencies, only notify

An example:

YARNHOOK_BYPASS=true git checkout feature-branch

Artwork

Project logo: @anilkilic

Font: PT Sans

yarnhook's People

Contributors

allybee avatar andersdjohnson avatar christophehurpeau avatar dependabot[bot] avatar evgenykochetkov avatar frontsideair avatar mathdroid avatar rowno avatar rwu823 avatar straub avatar zkochan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

yarnhook's Issues

Use yarn install with --prefer-offline and --pure-lockfile ?

--prefer-offline:

use network only if dependencies are not available in local cache

Make yarn install faster when switching branches

--pure-lockfile

don't generate a lockfile

yarnhook should not change yarn lockfile, and I don't think we should use frozen-lockfile which could fail when the lockfile is not synced with package.json yet.

Add `bun` support

bun.sh is a new JS tool which also has package management skills, with accompanying bun.lockb lockfile. Let's add support for it.

Handle other languages package managers

Hi,

I was going to implement a git hook to do just the same thing that yarnhook does, but for Composer (PHP package manager). But I thought it would be a shame to have yarnhook for yarn, and something specific for Composer. So I'm wondering if you are opened to handling not node-related package managers? In which case I can open a PR to add composer.

Thanks!

Support appending additional arguments

Would it be possible to add the ability to accept additional arguments so I could do something like this:

"husky": {
  "hooks": {
    "post-checkout": "yarnhook --ignore-optional",
    "post-merge": "yarnhook --ignore-optional",
    "post-rewrite": "yarnhook --ignore-optional"
  }
}

I'd really like to prevent yarnhook from installing optional dependencies.

Logo

Something like this
crochet-hook-yarn-brooch-purple-sparkle

pnpm v7 support

thanks for the great package, it really makes life a lot easier.

Version 7 of pnpm was recently released, and --prefer-frozen-shrinkwrap was deprecated in favor of --prefer-frozen-lockfile, causing the hook to exit with an error (and also not work as expected, since the installation does take place, just not with a frozen lock file). See the release notes here.

To the best of my understanding, it is impossible to detect pnpm's version through filesystem checks, since v7 uses the same lockfile as previous versions, so looks like resorting to pnpm -v is the only way around this

Consider dropping execa

The project can have zero dependencies without execa, which has listed their benefits but maybe we don't need any of them? Test extensively.

Support monorepos

Thanks for the great lib!

Currently, doesn't detect changes in nested package.json and yarn.lock. What do you think about adding support for monorepos?

Adding pnpm support

Adding pnpm support should be really easy.

I see currently this tool checks for a lockfile to decide what pm should be used for installation. pnpm has its own lockfile called shrinkwrap.yaml.

Alternatively, which-pm can be used, which will correctly identify the pm even when installing was done w/o a lockfile creation

Support just messaging, no install

It would be nice to support an option to just log a message (hopefully loud), instead of forcing an install. The lockfile detection logic and execution of git diff command is still helpful to abstract away.

git error when running yarnhook

I cloned a project that uses yarnhook, changed a file, and then ran git checkout on that file. yarnhook got triggered, but it failed with this output:

<path_to_project>/node_modules/.bin/yarnhook
<path_to_project>/node_modules/yarnhook/node_modules/execa/index.js:303

                throw (result.error || new Error(result.stderr === '' ? result.stdout : result.stderr));
                ^
Error: fatal: Log for 'HEAD' only has 1 entries.
    at Function.module.exports.sync (<path_to_project>/node_modules/yarnhook/node_modules/execa/index.js:303:26)
    at Object.<anonymous> (<path_to_project>/node_modules/yarnhook/index.js:58:38)
    at Module._compile (internal/modules/cjs/loader.js:1147:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
    at Module.load (internal/modules/cjs/loader.js:996:32)
    at Function.Module._load (internal/modules/cjs/loader.js:896:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47
error Command failed with exit code 1.

Tried googling but found nothing. Any advice?

Rename project (lockfilehook?)

It was suggested at #2 and now we have pnpm support I'm much more sympathetic to the name. One issue is we already have a neat logo, should we change it to something that looks like a lock?

Yarn 2 (berry) support

Hi,

thanks for the awesome package. We have been using it for a couple of months, but since we migrated to yarn berry, we are having issues since --frozen-lockfile flag was deprecated in favour of --immutable. Hence, the hook no longer works.

Would it be possible to detect whether yarn classic or yarn 2 is used?

Upgrade to husky 1.0.0

This will enable pnpm support as well.

  • Update documentation to use new husky package.json fields
  • Cut a release for pnpm support

Use `npm ci` instead of `npm i` if it's supported

npm ci is way faster than npm install so we should use it when it's available. Requirements:

  • npm version is >5.7.0
  • a package-lock.json or npm-shrinkwrap.json exists (we already check for package-lock.json)

Things to do:

  • Check npm version
  • Add checking for npm-shrinkwrap.json #19
  • Add a flag for using npm install instead of npm ci
  • Can we fallback to npm install if npm ci fails?

Support sourcing environment variables from `.env` files

Some project support loading environment variables from .env files to allow permanent variables to be committed and shared among project members. Examples include create-react-app and Docker Compose. I think it would be great if yarnhook did as well. That way, a project team could share a variable such as YARNHOOK_DRYRUN=true without requiring each member to set it in a global .bashrc file.

Though this may seem to limit individual preference in environment variables, yarnhook could also recognize .env.local, which overrides .env and is usually listed in .gitignore

Add tests

  • Add a single smoke test (branch change)
  • Integrate testing with GitHub Actions
  • Make test run on dev version
  • Add a test for each supported package manager
  • Add pull test (merge)
  • Add pull test (rebase)
  • Add pull test (fast-forward)
  • Add reset/restore test
  • Add checkout test (should not fail) (#39)
  • Add single file checkout test
  • Add switch test
  • Add merge/rebase test
  • Add stash test
  • Add cherry-pick test
  • Add revert test
  • Add branch switch from yarnhook-installed to yarnhook-not-installed (should break, consult to husky) (#13)

Adoption

Stale node_modules is a source of bugs, footguns, headaches. Angular has a bullet in the readme just for it. Consider sending PRs to large projects to increase adoption, this will also benefit the project.

Proposal:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.