From 09b0b3833391e309a2f086ed1ba512fe873cb75b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leosvel=20P=C3=A9rez=20Espinosa?= Date: Fri, 26 Jul 2024 14:59:53 +0200 Subject: [PATCH] cleanup(angular): replace old util with devkit util and remove "ignore" dependency (#27126) ## Current Behavior ## Expected Behavior ## Related Issue(s) Fixes # --- packages/angular/package.json | 1 - .../utils/storybook-ast/component-info.ts | 8 +++-- .../utils/storybook-ast/tree-utilities.ts | 35 ------------------- 3 files changed, 6 insertions(+), 38 deletions(-) delete mode 100644 packages/angular/src/generators/utils/storybook-ast/tree-utilities.ts diff --git a/packages/angular/package.json b/packages/angular/package.json index c67d4538057d4..2c36014e65438 100644 --- a/packages/angular/package.json +++ b/packages/angular/package.json @@ -51,7 +51,6 @@ "@typescript-eslint/type-utils": "^7.16.0", "chalk": "^4.1.0", "find-cache-dir": "^3.3.2", - "ignore": "^5.0.4", "magic-string": "~0.30.2", "minimatch": "9.0.3", "semver": "^7.5.3", diff --git a/packages/angular/src/generators/utils/storybook-ast/component-info.ts b/packages/angular/src/generators/utils/storybook-ast/component-info.ts index 98398a373aa2f..977f7017159b5 100644 --- a/packages/angular/src/generators/utils/storybook-ast/component-info.ts +++ b/packages/angular/src/generators/utils/storybook-ast/component-info.ts @@ -11,7 +11,6 @@ import type { Identifier, SourceFile, Statement } from 'typescript'; import { getTsSourceFile } from '../../../utils/nx-devkit/ast-utils'; import type { EntryPoint } from './entry-point'; import { getModuleDeclaredComponents } from './module-info'; -import { getAllFilesRecursivelyFromDir } from './tree-utilities'; let tsModule: typeof import('typescript'); let tsquery: typeof import('@phenomnomnominal/tsquery').tsquery; @@ -242,7 +241,12 @@ function getComponentInfoFromDir( ): ComponentInfo { let path = null; let componentFileName = null; - const componentImportPathChildren = getAllFilesRecursivelyFromDir(tree, dir); + + const componentImportPathChildren: string[] = []; + visitNotIgnoredFiles(tree, dir, (filePath) => { + componentImportPathChildren.push(filePath); + }); + for (const candidateFile of componentImportPathChildren) { if (candidateFile.endsWith('.ts')) { const content = tree.read(candidateFile, 'utf-8'); diff --git a/packages/angular/src/generators/utils/storybook-ast/tree-utilities.ts b/packages/angular/src/generators/utils/storybook-ast/tree-utilities.ts deleted file mode 100644 index 71ad36d1bf3a9..0000000000000 --- a/packages/angular/src/generators/utils/storybook-ast/tree-utilities.ts +++ /dev/null @@ -1,35 +0,0 @@ -import type { Tree } from '@nx/devkit'; -import { joinPathFragments } from '@nx/devkit'; -import ignore from 'ignore'; - -export function getAllFilesRecursivelyFromDir( - tree: Tree, - dir: string -): string[] { - if (isPathIgnored(tree, dir)) { - return []; - } - - const files: string[] = []; - const children = tree.children(dir); - children.forEach((child) => { - const childPath = joinPathFragments(dir, child); - if (tree.isFile(childPath)) { - files.push(childPath); - } else { - files.push(...getAllFilesRecursivelyFromDir(tree, childPath)); - } - }); - - return files; -} - -function isPathIgnored(tree: Tree, path: string): boolean { - let ig: ReturnType; - if (tree.exists('.gitignore')) { - ig = ignore(); - ig.add(tree.read('.gitignore', 'utf-8')); - } - - return path !== '' && ig?.ignores(path); -}