CircleCI-Public / node-orb

An orb for working with Node.js on CircleCI
https://circleci.com/orbs/registry/orb/circleci/node
MIT License
52 stars 80 forks source link

Caching fails if no lockfile exists #198

Closed dotkas closed 9 months ago

dotkas commented 9 months ago

Orb version:

Latest

What happened:

If your project does not contain any lockfile at all, this logic falls through and does not copy anything to $TARGET_DIR/node-project-lockfile: https://github.com/CircleCI-Public/node-orb/blob/ab05d0e3718e32232bdd9c80a8ba6fac1c0bee02/src/scripts/packages/determine-lockfile.sh#L6-L16

However, if you run this without with-cache: false, this step fails: https://github.com/CircleCI-Public/node-orb/blob/ab05d0e3718e32232bdd9c80a8ba6fac1c0bee02/src/commands/install-packages.yml#L70

As:

error computing cache key: template: cacheKey:1:41: executing "cacheKey" at <checksum "/tmp/node-project-lockfile">: error calling checksum: open /tmp/node-project-lockfile: no such file or directory

Expected behavior:

Caching step should complete without a lockfile present.

Additional Information:

A quick fix would be to:

(END)...skipping...
diff --git a/src/scripts/packages/determine-lockfile.sh b/src/scripts/packages/determine-lockfile.sh
index 9ab65c5..5756da9 100644
--- a/src/scripts/packages/determine-lockfile.sh
+++ b/src/scripts/packages/determine-lockfile.sh
@@ -13,6 +13,9 @@ elif [ -f "npm-shrinkwrap.json" ]; then
 elif [ -f "yarn.lock" ]; then
     echo "Found yarn.lock file, assuming lockfile"
     cp yarn.lock $TARGET_DIR/node-project-lockfile
+else
+    echo "Found no lockfile, adding empty one"
+    touch $TARGET_DIR/node-project-lockfile
 fi

 cp package.json $TARGET_DIR/node-project-package.json

I wanted to do a PR, but seems I don't have sufficient access rights.

ramykl commented 9 months ago

To do a PR you just need to create a fork and then create a PR from that fork to this repository.

dotkas commented 9 months ago

Got it, will do.

dotkas commented 9 months ago

https://github.com/CircleCI-Public/node-orb/pull/200