Skip to content
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

Add check command #7

Open
thdk opened this issue Dec 19, 2021 · 3 comments
Open

Add check command #7

thdk opened this issue Dec 19, 2021 · 3 comments

Comments

@thdk
Copy link
Owner

thdk commented Dec 19, 2021

Idea after reading comment by @andidev in #3

Add a package-changed check command that simply logs a warning that dependencies should be installed manually.

Now this is what we are trying to achieve:

  1. A developer checks out some branch and runs npm run start without running npm install since they are not aware that installed dependencies has changed. We want to make sure they run code with correct dependencies and install dependencies automatically.
    Solution: we add a script to run package install with options --lockfile, npm install and echo dependencies are updated
"start:localhost": "npm run package-changed:npm-install && npm run start",
"package-changed:npm-install": "npx --yes package-changed run \"echo \\\"\\\\033[0;32mDEPENDENCY CHANGES DETECTED running 'npm install' since package.json dependencies or package-lock.json has changed\\\\033[0m\\\" && npm install\" --lockfile",

npm run start 2021-12-17 12-24-17

  1. A developer checks out some code that requires npm install (package.json or package-lock.json is changed).
    We want them to get informed that new dependencies needs to be installed. We don't want to install them because that could be annoying if they are not gonna run code.
    Solution: we create a post-checkout githook where we run package-changed with options --lockfile --skip-write-hash and echo warning dependencies needs to be install. We don't want to update hash since we want npm install to be triggered by 1).
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

red='\033[0;31m'
no_color='\033[0m'
npx --yes package-changed run "echo \"${red}WARNING run 'npm install' since package.json dependencies or package-lock.json has changed${no_color}\"" --lockfile --skip-write-hash

anders@airsomtoranders~Workspaceswedishtechnologiesletseatmanager 2021-12-17 12-17-28

  1. A developer pulls or merges or pulls some code that requires npm install. We want to run npm install to make sure developer installs and runs correct dependencies automatically.
    Solution: we create a post-merge githook where we run package install with options --lockfile, npm install and echo dependencies are updated.
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yellow="\033[0;32m"
no_color='\033[0m'
npx --yes package-changed run "echo \"${yellow}DEPENDENCY CHANGES DETECTED running 'npm install' since package.json dependencies or package-lock.json has changed${no_color}\" && npm install" --lockfile

anders@airsomtoranders~Workspaceswedishtechnologiesletseatmanager 2021-12-17 12-14-58

Originally posted by @andidev in #3 (comment)

@thdk thdk changed the title Idea after reading comment by @andidev in #3 Add a package-changed check command that simply logs a warning that dependencies should be installed manually. ---- Now this is what we are trying to achieve: Add check command Dec 19, 2021
@andidev
Copy link
Contributor

andidev commented Dec 20, 2021

Regarding this command, would be great to log which file changed, package.json or package-lock.js
So instead of logging
letseatmanager 2021-12-20 09-53-17
log either:

WARNING run 'npm install' since package.json dependencies changed

or

WARNING run 'npm install' since package-lock.json changed

or both if both changes occurred.

@thdk
Copy link
Owner Author

thdk commented Dec 21, 2021

If dependencies in package.json have changed. So the packagehash (based on package.json dependencies) is different. We know already that npm install will be needed. In this case, do we still need to check for the package-lock.json hash?

@andidev
Copy link
Contributor

andidev commented Dec 21, 2021

Yeah thats right.

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

2 participants