Conversation
Add LEEWAY_NODE_MODULES_CACHE env var to cache node_modules between yarn package builds. Speeds up CI builds by avoiding repeated yarn install operations. Co-authored-by: Ona <no-reply@ona.com>
kylos101
left a comment
There was a problem hiding this comment.
✅ to unblock, added a couple non-blocking suggestions.
| yarnLockPath := filepath.Join(wd, "yarn.lock") | ||
| yarnLockHash, err := computeSHA256(yarnLockPath) | ||
| if err != nil { | ||
| log.WithField("package", p.FullName()).WithError(err).Debug("cannot compute yarn.lock hash for node_modules cache") |
There was a problem hiding this comment.
Suggestion, not blocking:
This feels like we should bump to warn. If this were to happen with an existing yarn component, we'd want to surface it more easily, I think.
There was a problem hiding this comment.
Suggestion, not blocking:
Consider adding unit tests to cover new feature. Perhaps in pkg/leeway/build_integration_test.go? Ona suggested peeking at TestYarnPackage_LinkDependencies_Integration for a reference.
To test node_modules caching, you could extend this pattern by:
- Setting LEEWAY_NODE_MODULES_CACHE env var to a temp directory
- Building the package once (should save to cache)
- Verifying the cache directory structure exists ($cache/pkg_name/hash[:12]/node_modules)
- Building again and checking logs for "Restoring node_modules from cache..."
- Modifying yarn.lock and rebuilding to verify cache invalidation (new hash directory)
The existing test at line 2427-2680 would be a good template - it already handles all the yarn package setup boilerplate.
| nodeModulesCachePath = filepath.Join(nodeModulesCacheDir, safePkgName, yarnLockHash[:12]) | ||
|
|
||
| // Restore node_modules from cache if it exists | ||
| restoreCmd := fmt.Sprintf("if [ -d \"%s/node_modules\" ]; then echo \"Restoring node_modules from cache...\"; cp -a \"%s/node_modules\" ./node_modules; fi", nodeModulesCachePath, nodeModulesCachePath) |
There was a problem hiding this comment.
TIL about -a flag with cp.
Description
Add
LEEWAY_NODE_MODULES_CACHEenvironment variable to enable caching ofnode_modulesdirectories between yarn package builds. This allows CI systems to cache and restore node_modules, avoiding repeatedyarn installoperations.Before:
After:
Related Issue(s)
N/A
How to test
LEEWAY_NODE_MODULES_CACHEto a directory pathleeway build :some-yarn-package