Skip to content

Commit

Permalink
feat(core): add ignoredPaths to arguments and support regex (#33)
Browse files Browse the repository at this point in the history
* feat(core): add ignoredPaths to arguments and support regex

* following type changes

* update lock npm install

* update lock file

---------

Co-authored-by: Elad Bezalel <[email protected]>
  • Loading branch information
itayper and EladBezalel authored Sep 29, 2024
1 parent 6128bf3 commit 84f0acc
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 18 deletions.
6 changes: 4 additions & 2 deletions libs/core/src/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ import { existsSync } from 'fs';
export function findNonSourceAffectedFiles(
cwd: string,
changedFilePath: string,
excludeFolderPaths: string[]
excludeFolderPaths: (string | RegExp)[]
): ChangedFiles[] {
const fileName = basename(changedFilePath);

const files = fastFindInFiles({
directory: cwd,
needle: fileName,
excludeFolderPaths: excludeFolderPaths.map((path) => join(cwd, path)),
excludeFolderPaths: excludeFolderPaths.map((path) =>
typeof path === 'string' ? join(cwd, path) : path
),
});

const relevantFiles = filterRelevantFiles(cwd, files, changedFilePath);
Expand Down
6 changes: 4 additions & 2 deletions libs/core/src/lock-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ export function hasLockfileChanged(changedFiles: ChangedFiles[]): boolean {
export function findAffectedFilesByLockfile(
cwd: string,
base: string,
excludePaths: string[]
excludePaths: (string | RegExp)[]
): ChangedFiles[] {
const dependencies = findAffectedModules(cwd, base);
const excludeFolderPaths = excludePaths.map((path) => join(cwd, path));
const excludeFolderPaths = excludePaths.map((path) =>
typeof path === 'string' ? join(cwd, path) : path
);

// fastFindInFiles supports regex but fails with `@` in the regex
const files = dependencies.flatMap((dep) =>
Expand Down
3 changes: 1 addition & 2 deletions libs/core/src/true-affected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const trueAffected = async ({
include = [DEFAULT_INCLUDE_TEST_FILES],
logger = DEFAULT_LOGGER,
compilerOptions = {},
ignoredPaths = [/node_modules/, './build', './dist', './.git'],
__experimentalLockfileCheck = false,
}: TrueAffected) => {
logger.debug('Getting affected projects');
Expand Down Expand Up @@ -98,8 +99,6 @@ export const trueAffected = async ({
({ filePath }) => project.getSourceFile(resolve(cwd, filePath)) != null
);

const ignoredPaths = ['./node_modules', './build', './dist', './.git'];

const nonSourceChangedFiles = changedFiles
.filter(
({ filePath }) =>
Expand Down
3 changes: 2 additions & 1 deletion libs/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export interface TrueAffected extends TrueAffectedLogging {
projects: TrueAffectedProject[];
include?: (string | RegExp)[];
compilerOptions?: CompilerOptions;

ignoredPaths?: (string | RegExp)[];

// **experimental** - this is an experimental feature and may be removed or changed at any time
__experimentalLockfileCheck?: boolean;
}
20 changes: 10 additions & 10 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"dependencies": {
"chalk": "^5.2.0",
"fast-find-in-files": "^1.0.1",
"fast-find-in-files": "^1.0.5",
"globby": "^13.1.4",
"microdiff": "^1.3.2",
"ts-morph": "^18.0.0",
Expand Down

0 comments on commit 84f0acc

Please sign in to comment.