@noahnu/unused-files 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +9 -1
- package/lib/api/index.d.ts +4 -4
- package/lib/api/index.js +22 -11
- package/lib/api/walkDependencyTree.js +1 -2
- package/lib/bin.js +1 -1
- package/package.json +7 -6
package/CHANGELOG.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
<!--
|
3
|
+
<!-- MONOWEAVE:BELOW -->
|
4
|
+
|
5
|
+
## @noahnu/unused-files (v0.0.2) <a name="0.0.2"></a>
|
6
|
+
|
7
|
+
Update ESLint config and plugins to ESLint v9.
|
8
|
+
|
9
|
+
Update misc. dependencies.
|
10
|
+
|
11
|
+
|
4
12
|
|
5
13
|
## [0.0.1](https://github.com/noahnu/nodejs-tools/compare/@noahnu/unused-files@0.0.0...@noahnu/unused-files@0.0.1) "@noahnu/unused-files" (2024-01-15)<a name="0.0.1"></a>
|
6
14
|
|
package/lib/api/index.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
export
|
1
|
+
export interface FindUnusedFilesOptions {
|
2
2
|
/**
|
3
3
|
* Entry files into the codebase. These files are known to be used and any files that
|
4
4
|
* are dependencies of these entry files are also considered used files.
|
@@ -23,8 +23,8 @@ export type FindUnusedFilesOptions = {
|
|
23
23
|
*/
|
24
24
|
depth?: number;
|
25
25
|
cwd?: string;
|
26
|
-
}
|
27
|
-
export
|
26
|
+
}
|
27
|
+
export interface UnusedFilesResult {
|
28
28
|
unusedFiles: string[];
|
29
|
-
}
|
29
|
+
}
|
30
30
|
export declare function findUnusedFiles({ entryFiles, ignorePatterns, sourceDirectories, aliases, depth, cwd, }: FindUnusedFilesOptions): Promise<UnusedFilesResult>;
|
package/lib/api/index.js
CHANGED
@@ -3,36 +3,48 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.findUnusedFiles =
|
6
|
+
exports.findUnusedFiles = findUnusedFiles;
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
7
8
|
const node_path_1 = __importDefault(require("node:path"));
|
8
9
|
const debug_1 = __importDefault(require("debug"));
|
9
10
|
const fast_glob_1 = __importDefault(require("fast-glob"));
|
10
11
|
const walkDependencyTree_1 = require("./walkDependencyTree");
|
11
12
|
const debug = (0, debug_1.default)('unused-files');
|
12
13
|
async function findUnusedFiles({ entryFiles, ignorePatterns = ['**/node_modules'], sourceDirectories = [], aliases, depth, cwd = process.cwd(), }) {
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
cwd = await node_fs_1.default.promises.realpath(cwd);
|
15
|
+
const globFromSource = async (source) => {
|
16
|
+
const files = await fast_glob_1.default.glob(fast_glob_1.default.isDynamicPattern(source) ? source : node_path_1.default.join(source, '**'), {
|
17
|
+
dot: false,
|
18
|
+
ignore: ignorePatterns,
|
19
|
+
absolute: true,
|
20
|
+
cwd,
|
21
|
+
});
|
22
|
+
return Promise.all(files.map(async (file) => await node_fs_1.default.promises.realpath(file).catch(() => file)));
|
23
|
+
};
|
19
24
|
const sourceDirs = sourceDirectories.length > 0 ? sourceDirectories : [cwd];
|
20
25
|
const files = new Set([].concat(...(await Promise.all(sourceDirs.map((source) => globFromSource(source))))));
|
21
26
|
const unvisitedFiles = new Set(files);
|
22
27
|
for (const entryFile of entryFiles) {
|
23
|
-
const entry = node_path_1.default.resolve(cwd, entryFile);
|
28
|
+
const entry = await node_fs_1.default.promises.realpath(node_path_1.default.resolve(cwd, entryFile));
|
24
29
|
unvisitedFiles.delete(entry);
|
25
30
|
for await (const { source, dependency } of (0, walkDependencyTree_1.walkDependencyTree)(entry, {
|
26
31
|
aliases,
|
27
32
|
depth,
|
28
33
|
})) {
|
34
|
+
let resolvedDependency = dependency;
|
29
35
|
if (files.has(dependency)) {
|
30
36
|
debug(`${source}: ${dependency} [dependency]`);
|
31
37
|
}
|
32
38
|
else {
|
33
|
-
|
39
|
+
const realpath = await node_fs_1.default.promises.realpath(dependency);
|
40
|
+
if (files.has(realpath)) {
|
41
|
+
resolvedDependency = realpath;
|
42
|
+
}
|
43
|
+
else {
|
44
|
+
debug(`${source}: ${dependency} [unknown dependency]`);
|
45
|
+
}
|
34
46
|
}
|
35
|
-
unvisitedFiles.delete(
|
47
|
+
unvisitedFiles.delete(resolvedDependency);
|
36
48
|
}
|
37
49
|
}
|
38
50
|
return {
|
@@ -41,4 +53,3 @@ async function findUnusedFiles({ entryFiles, ignorePatterns = ['**/node_modules'
|
|
41
53
|
.sort(),
|
42
54
|
};
|
43
55
|
}
|
44
|
-
exports.findUnusedFiles = findUnusedFiles;
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.walkDependencyTree =
|
6
|
+
exports.walkDependencyTree = walkDependencyTree;
|
7
7
|
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");
|
@@ -96,4 +96,3 @@ async function* walkDependencyTree(source, { aliases, visited, depth = DEFAULT_D
|
|
96
96
|
}
|
97
97
|
}
|
98
98
|
}
|
99
|
-
exports.walkDependencyTree = walkDependencyTree;
|
package/lib/bin.js
CHANGED
@@ -5,7 +5,7 @@ const command_1 = require("./command");
|
|
5
5
|
const cli = new clipanion_1.Cli({
|
6
6
|
binaryLabel: '@noahnu/unused-files',
|
7
7
|
binaryName: 'yarn @noahnu/unused-files',
|
8
|
-
// eslint-disable-next-line @typescript-eslint/no-
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
9
9
|
binaryVersion: require('../package.json').version,
|
10
10
|
enableCapture: true,
|
11
11
|
});
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@noahnu/unused-files",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.2",
|
4
4
|
"repository": {
|
5
5
|
"type": "git",
|
6
6
|
"url": "https://github.com/noahnu/nodejs-tools.git",
|
@@ -15,7 +15,7 @@
|
|
15
15
|
"scripts": {
|
16
16
|
"clean": "run workspace:clean \"$(pwd)\"",
|
17
17
|
"prepack": "run workspace:build \"$(pwd)\"",
|
18
|
-
"run-local": "run -T
|
18
|
+
"run-local": "run -T tsx ./src/bin.ts"
|
19
19
|
},
|
20
20
|
"bin": "./lib/bin.js",
|
21
21
|
"main": "./lib/api/index.js",
|
@@ -31,16 +31,17 @@
|
|
31
31
|
],
|
32
32
|
"dependencies": {
|
33
33
|
"@types/debug": "^4.1.12",
|
34
|
-
"@typescript-eslint/typescript-estree": "^
|
35
|
-
"clipanion": "4.0.0-rc.
|
36
|
-
"debug": "^4.3.
|
34
|
+
"@typescript-eslint/typescript-estree": "^8.13.0",
|
35
|
+
"clipanion": "^4.0.0-rc.4",
|
36
|
+
"debug": "^4.3.7",
|
37
37
|
"fast-glob": "^3.3.2",
|
38
38
|
"typanion": "^3.14.0"
|
39
39
|
},
|
40
40
|
"devDependencies": {
|
41
41
|
"@jest/globals": "^29.7.0",
|
42
42
|
"@noahnu/internal-test-utils": "0.0.0",
|
43
|
-
"@types/node": "^
|
43
|
+
"@types/node": "^22.9.0",
|
44
|
+
"typescript": "^5.6.3"
|
44
45
|
},
|
45
46
|
"types": "./lib/api/index.d.ts"
|
46
47
|
}
|