Skip to content

Commit

Permalink
Supporting ignore-pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
sharonamr committed Aug 12, 2024
1 parent 1f22fee commit e7cfbb1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ npx workspaces-affected build --base COMMIT_ID --ignore-private
| --base | true | master | git ref to compare changes to. |
| --with-side | false | false | When true, listing also side affected packages. |
| --ignore-private | false | false | When true, private packages will be ignored. |
| --ignore-pattern | false | "" | Glob pattern to be ignored when fetching affected files. |
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions packages/affected/bin/affected.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ const supportedArgs = {
'--base': 'string',
'--with-side': 'boolean',
'--ignore-private': 'boolean',
'--ignore-pattern': 'string',
};
const [parsedFlags, args] = flagsParser(supportedArgs, allArgs);
const base = parsedFlags['--base'];
console.log('affected args:', parsedFlags);

const ignoredFiles = glob.sync(parsedFlags['--ignore-pattern']);
const affectedFiles = getAffectedFiles(base);

export const getFileContent = (filePath) => {
Expand Down Expand Up @@ -56,9 +58,13 @@ const packages = workspaces.reduce((acc, pattern) => {
return acc;
}, {});
console.log('packages:', Object.values(packages).map(({name, path}) => ({name, path})));
console.log('affectedFiles:', affectedFiles);
console.log('Affected files:', affectedFiles);
console.log('Ignored files:', ignoredFiles);

const affectedPackages = Object.values(packages).reduce((acc, pkg) => {
if (affectedFiles.some(file => file.startsWith(pkg.path))) {
if (affectedFiles
.filter(file => !ignoredFiles.includes(file))
.some(file => file.startsWith(pkg.path))) {
if(pkg.private !== true || parsedFlags['--ignore-private'] !== true) {
acc.add(pkg.name);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/affected/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "workspaces-affected",
"version": "1.0.13",
"version": "1.0.14",
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
Expand Down
4 changes: 3 additions & 1 deletion packages/affected/src/flags-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ export const flagsParser = (supportedFlags, args) => {
const parsed = Object.entries(supportedFlags).reduce((flagsAcc, [flag, flagType]) => {
const value = args.reduce((acc, arg, index) => {
if (arg === flag) {
usedArgs.push(arg);
let argValue = args[index + 1];
if (flagType === 'boolean') {
usedArgs.push(arg);
if (argValue === 'true') {
argValue = true;
} else if (argValue === 'false') {
argValue = false;
} else {
argValue = true;
}
} else {
usedArgs.push(arg, args[index + 1]);
}
acc = argValue;
} else if (arg.startsWith(`${flag}=`)) {
Expand Down

0 comments on commit e7cfbb1

Please sign in to comment.