@noahnu/unused-files 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,7 +2,13 @@
2
2
 
3
3
  <!-- MONOWEAVE:BELOW -->
4
4
 
5
- ## @noahnu/unused-files (v0.1.0) <a name="0.1.0"></a>
5
+ ## @noahnu/unused-files (v0.2.1) <a name="0.2.1"></a>
6
+
7
+ Respect ignorePatterns for visiting files.
8
+
9
+
10
+
11
+ ## @noahnu/unused-files (v0.2.0) <a name="0.2.0"></a>
6
12
 
7
13
  Support custom resolvers.
8
14
 
package/lib/api/index.js CHANGED
@@ -32,6 +32,7 @@ async function findUnusedFiles({ entryFiles, ignorePatterns = ['**/node_modules'
32
32
  resolvers,
33
33
  depth,
34
34
  visited: visitedFiles,
35
+ ignorePatterns,
35
36
  })) {
36
37
  let resolvedDependency = dependency;
37
38
  if (files.has(dependency)) {
@@ -1,8 +1,9 @@
1
1
  import { type Resolver } from './types';
2
- export declare function walkDependencyTree(source: string, { resolvers, visited, depth, }?: {
2
+ export declare function walkDependencyTree(source: string, { resolvers, visited, depth, ignorePatterns, }?: {
3
3
  resolvers?: Resolver[];
4
4
  visited?: Set<string>;
5
5
  depth?: number;
6
+ ignorePatterns?: string[];
6
7
  }): AsyncGenerator<{
7
8
  source: string;
8
9
  dependency: string;
@@ -8,10 +8,11 @@ const node_fs_1 = __importDefault(require("node:fs"));
8
8
  const node_path_1 = __importDefault(require("node:path"));
9
9
  const typescript_estree_1 = require("@typescript-eslint/typescript-estree");
10
10
  const debug_1 = __importDefault(require("debug"));
11
+ const micromatch_1 = __importDefault(require("micromatch"));
11
12
  const debug = (0, debug_1.default)('unused-files:parse');
12
13
  const DEFAULT_DEPTH_LIMIT = -1; // no depth limit
13
14
  const VALID_EXTENSIONS = new Set(['ts', 'tsx', 'mts', 'cts', 'js', 'jsx', 'mjs', 'cjs']);
14
- async function* walkDependencyTree(source, { resolvers, visited, depth = DEFAULT_DEPTH_LIMIT, } = {}) {
15
+ async function* walkDependencyTree(source, { resolvers, visited, depth = DEFAULT_DEPTH_LIMIT, ignorePatterns, } = {}) {
15
16
  const ext = node_path_1.default.extname(source).substring(1);
16
17
  if (!VALID_EXTENSIONS.has(ext)) {
17
18
  debug(`${source}: Unknown file extension '${ext}' [skipping]`);
@@ -89,12 +90,16 @@ async function* walkDependencyTree(source, { resolvers, visited, depth = DEFAULT
89
90
  for (const importFrom of Array.from(importFroms)) {
90
91
  const absPath = await resolveToAbsPath(importFrom);
91
92
  if (absPath) {
93
+ if (ignorePatterns && micromatch_1.default.isMatch(absPath, ignorePatterns)) {
94
+ continue;
95
+ }
92
96
  yield { dependency: absPath, source };
93
97
  if (depth === -1 || depth > 0) {
94
98
  yield* walkDependencyTree(absPath, {
95
99
  resolvers,
96
100
  visited: visitedSet,
97
101
  depth: depth === -1 ? depth : depth - 1,
102
+ ignorePatterns,
98
103
  });
99
104
  }
100
105
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noahnu/unused-files",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/noahnu/nodejs-tools.git",
@@ -35,11 +35,13 @@
35
35
  "clipanion": "^4.0.0-rc.4",
36
36
  "debug": "^4.3.7",
37
37
  "fast-glob": "^3.3.2",
38
+ "micromatch": "^4.0.8",
38
39
  "typanion": "^3.14.0"
39
40
  },
40
41
  "devDependencies": {
41
42
  "@jest/globals": "^29.7.0",
42
43
  "@noahnu/internal-test-utils": "0.0.0",
44
+ "@types/micromatch": "^4.0.9",
43
45
  "@types/node": "^22.9.0",
44
46
  "typescript": "^5.6.3"
45
47
  },