Skip to content

Commit

Permalink
Avoid doing a no-op npm install.
Browse files Browse the repository at this point in the history
  • Loading branch information
danfuzz committed Mar 18, 2024
1 parent 83030f7 commit c64ec02
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions scripts/lib/bashy-node/node-project/build-main-module
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ function build-project {
|| return 1
local srcPackageJson="${srcMainModule}/package.json"
local srcPackageLockJson="${srcMainModule}/package-lock.json"
local destLibPackageJson="${destLibDir}/package.json"
local destLibPackageNewJson="${destLibDir}/package-new.json"

jget >"${destLibDir}/package.json" \
jget >"${destLibPackageNewJson}" \
--file="${srcPackageJson}" \
localCodeDirName="${localCodeDirName}" \
deps:json="${deps}" \
Expand Down Expand Up @@ -151,9 +153,20 @@ function build-project {
&& copy-scripts "${srcMainModule}" "${destDir}" \
&& copy-local-modules "${destLocalModules}" "${deps}" \
&& remove-dead-local-modules "${destLocalModules}" "${deps}" \
&& npm-install "${destLibDir}" \
|| return "$?"

# Do `npm install`, but only if it hasn't yet been done _or_ the top-level
# `package.json` file has changed since the last time it was run.
if [[ ! -d "${destLibDir}/node_modules" ]] \
|| ! cmp --silent "${destLibPackageNewJson}" "${destLibPackageJson}"; then
mv "${destLibPackageNewJson}" "${destLibPackageJson}"
npm-install "${destLibDir}" || {
error="$?"
rm -rf "${destLibDir}/node_modules"
return "${error}"
}
fi

cp "${destLibDir}/package-lock.json" "${srcPackageLockJson}"
}

Expand Down

0 comments on commit c64ec02

Please sign in to comment.