From 84f0acc395f35fc448579525ade2b4619d493d5d Mon Sep 17 00:00:00 2001 From: Itay Perach Date: Sun, 29 Sep 2024 14:48:54 +0300 Subject: [PATCH] feat(core): add ignoredPaths to arguments and support regex (#33) * feat(core): add ignoredPaths to arguments and support regex * following type changes * update lock npm install * update lock file --------- Co-authored-by: Elad Bezalel --- libs/core/src/assets.ts | 6 ++++-- libs/core/src/lock-files.ts | 6 ++++-- libs/core/src/true-affected.ts | 3 +-- libs/core/src/types.ts | 3 ++- package-lock.json | 20 ++++++++++---------- package.json | 2 +- 6 files changed, 22 insertions(+), 18 deletions(-) diff --git a/libs/core/src/assets.ts b/libs/core/src/assets.ts index 5579365..e0137ee 100644 --- a/libs/core/src/assets.ts +++ b/libs/core/src/assets.ts @@ -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); diff --git a/libs/core/src/lock-files.ts b/libs/core/src/lock-files.ts index 343143d..59e3c0d 100644 --- a/libs/core/src/lock-files.ts +++ b/libs/core/src/lock-files.ts @@ -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) => diff --git a/libs/core/src/true-affected.ts b/libs/core/src/true-affected.ts index 316dc2c..1d86576 100644 --- a/libs/core/src/true-affected.ts +++ b/libs/core/src/true-affected.ts @@ -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'); @@ -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 }) => diff --git a/libs/core/src/types.ts b/libs/core/src/types.ts index 9bf8944..b3f5a5c 100644 --- a/libs/core/src/types.ts +++ b/libs/core/src/types.ts @@ -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; } diff --git a/package-lock.json b/package-lock.json index 89d116b..a242ecd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "MIT", "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", @@ -7531,20 +7531,15 @@ "dev": true }, "node_modules/fast-find-in-files": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/fast-find-in-files/-/fast-find-in-files-1.0.1.tgz", - "integrity": "sha512-PFH01hasNsfUkiFhtJik7JOiFKbpwv3p0+aicMqzXP+exXkn8YIPeXSuH7wLeH173PqeHPr43YYGdCSuptVayg==", + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/fast-find-in-files/-/fast-find-in-files-1.0.5.tgz", + "integrity": "sha512-PsNqIc58thhVku8gNDD605/qeQUmJKkXYz7cWvq+4tBdjwUKe7agDDGIUFq6Mn7QyH1hFGEhe/JBeSbWHYYy1Q==", "hasInstallScript": true, "dependencies": { "bindings": "^1.5.0", - "node-addon-api": "^2.0.0" + "node-addon-api": "^7.0.0" } }, - "node_modules/fast-find-in-files/node_modules/node-addon-api": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-2.0.2.tgz", - "integrity": "sha512-Ntyt4AIXyaLIuMHF6IOoTakB3K+RWxwtsHNRxllEoA6vPwP9o4866g6YWDLUdnucilZhmkxiHwHr11gAENw+QA==" - }, "node_modules/fast-glob": { "version": "3.2.7", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.7.tgz", @@ -10272,6 +10267,11 @@ "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", "dev": true }, + "node_modules/node-addon-api": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-7.1.1.tgz", + "integrity": "sha512-5m3bsyrjFWE1xf7nz7YXdN4udnVtXK6/Yfgn5qnahL6bCkf2yKt4k3nuTKAtT4r3IG8JNR2ncsIMdZuAzJjHQQ==" + }, "node_modules/node-fetch": { "version": "2.6.11", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.11.tgz", diff --git a/package.json b/package.json index c79cbff..cc976ec 100644 --- a/package.json +++ b/package.json @@ -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",