FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

chore(incrementalBuild): invalidate all packages if yarn.lock changes by redallen · Pull Request #2548 · patternfly/patternfly-react · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
30 changes: 18 additions & 12 deletions scripts/hashDir.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,25 @@ function filewalker(dir) {

function hashDir(dirPath) {
const md5 = crypto.createHash('md5');
const stat = fs.statSync(dirPath);

const files = filewalker(dirPath);
files
.sort((f1, f2) => f1.path.localeCompare(f2.path))
.forEach(file => {
if (file.type === 'file') {
const fileContents = fs.readFileSync(file.path);
md5.update(fileContents);
}
else if (file.type === 'dir') {
md5.update(file.path);
}
});
if (stat && stat.isFile()) {
const fileContents = fs.readFileSync(dirPath);
md5.update(fileContents);
}
else {
filewalker(dirPath)
.sort((f1, f2) => f1.path.localeCompare(f2.path))
.forEach(file => {
if (file.type === 'file') {
const fileContents = fs.readFileSync(file.path);
md5.update(fileContents);
}
else if (file.type === 'dir') {
md5.update(file.path);
}
});
}
return md5.digest('hex');
}

Expand Down
13 changes: 10 additions & 3 deletions scripts/incrementalBuild.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ const Project = require('@lerna/project');
const RunCommand = require('@lerna/run')

// Load cache
const cacheFile = '.cache/incrementalCache'
let cache = {}
const cacheFile = '.cache/incrementalCache';
let cache = {};
if (fs.existsSync(cacheFile)) {
cache = JSON.parse(fs.readFileSync(cacheFile, 'utf8'));
}
const yarnLockHash = hashDir('yarn.lock');

// Package filtering
const isPf3 = process.argv.length > 2 && process.argv[2] === 'pf3';
Expand Down Expand Up @@ -48,7 +49,7 @@ async function getInvalidPackages() {
: true) // Based off argv
.filter(p => isPf4
? p.location.indexOf('patternfly-4') > 0 || commonPackages.indexOf(p.name) >= 0
: true) // Based off argv
: true); // Based off argv

for (let p of packages) {
p.hash = hashPackageSrc(p.location, p.name);
Expand All @@ -58,6 +59,11 @@ async function getInvalidPackages() {
}
}

// Invalidate everything if any deps change.
if (cache['yarn.lock'] !== yarnLockHash) {
return packages;
}

return packages.filter(p => !p.valid);
}

Expand All @@ -75,6 +81,7 @@ getInvalidPackages().then(packages => {
if (!fs.existsSync('.cache')) {
fs.mkdirSync('.cache');
}
cache['yarn.lock'] = yarnLockHash;
fs.writeFileSync(cacheFile, JSON.stringify(cache, null, 2));
})
}
Expand Down

Back | FazBrowse Home | New Git URL