Skip to content

Add check command #7

@thdk

Description

@thdk

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions