view-ignored 0.5.0 → 0.5.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/README.md +25 -12
- package/out/patterns/matcher.d.ts +63 -0
- package/out/patterns/matcher.js +7 -0
- package/out/scan.d.ts +9 -6
- package/out/scan.js +5 -4
- package/out/targets/target.d.ts +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -85,19 +85,32 @@ vign.scan({ target: Git });
|
|
|
85
85
|
|
|
86
86
|
## Targets
|
|
87
87
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
-
|
|
95
|
-
- `
|
|
88
|
+
> [!NOTE]
|
|
89
|
+
> Each scanner expects minimal configurations, but the actual tool can have
|
|
90
|
+
> more/less complex rules. Refer to the documentation of each tool for details.
|
|
91
|
+
|
|
92
|
+
The following built-in scanners are available:
|
|
93
|
+
|
|
94
|
+
- Git
|
|
95
|
+
- Reads `.gitignore` files but does not consider global settings.
|
|
96
|
+
- Check this scanner by running `git ls-tree -r HEAD --name-only`.
|
|
97
|
+
- See the implementation of [Git target](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/git.ts) for details.
|
|
98
|
+
- NPM (compatible with Bun, PNPM, and others)
|
|
99
|
+
- Reads `.npmignore` and `package.json` `files` field.
|
|
100
|
+
- No additional checks for `name`, `version` or `publishConfig`.
|
|
101
|
+
- Check this scanner by running `npm pack --dry-run`.
|
|
102
|
+
- See the implementation of [NPM target](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/npm.ts) for details.
|
|
103
|
+
- Yarn
|
|
104
|
+
- Same behavior as `npm`, but also reads `.yarnignore`.
|
|
105
|
+
- See the implementation of [Yarn target](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/yarn.ts) for details.
|
|
106
|
+
- VSCE
|
|
107
|
+
- Reads `.vscodeignore` and `package.json` `files` field.
|
|
108
|
+
- Check this scanner by running `vsce ls`.
|
|
109
|
+
- See the implementation of [VSCE target](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/vsce.ts) for details.
|
|
110
|
+
- JSR (compatible with Deno)
|
|
111
|
+
- Reads `jsr.json(c)` and `deno.json(c)` `include` and `exclude` fields.
|
|
112
|
+
- See the implementation of [JSR target](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/jsr.ts) for details.
|
|
96
113
|
|
|
97
114
|
## License
|
|
98
115
|
|
|
99
116
|
MIT License. See [LICENSE.txt](LICENSE.txt) for details.
|
|
100
|
-
|
|
101
|
-
## Target implementations
|
|
102
|
-
<!-- .ts links -->
|
|
103
|
-
See [Target implementations](src/targets/README.md) for details.
|
|
@@ -1,10 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The results and statistics of a scanning operation.
|
|
3
|
+
*/
|
|
1
4
|
export type MatcherContext = {
|
|
5
|
+
/**
|
|
6
|
+
* `Set` can be sorted, but `view-ignored`
|
|
7
|
+
* does not sort paths.
|
|
8
|
+
* @example
|
|
9
|
+
* new Set(sort(new Set(['a/b', 'a/a'])))
|
|
10
|
+
*/
|
|
2
11
|
paths: Set<string>;
|
|
12
|
+
/**
|
|
13
|
+
* Maps directory paths to their corresponding sources.
|
|
14
|
+
* @example
|
|
15
|
+
* "src" => Source
|
|
16
|
+
*/
|
|
3
17
|
external: Map<string, Source>;
|
|
18
|
+
/**
|
|
19
|
+
* Maps directory paths to the quantity of path segments they contain.
|
|
20
|
+
* @example
|
|
21
|
+
* "src/components" => 2
|
|
22
|
+
*/
|
|
4
23
|
depthPaths: Map<string, number>;
|
|
24
|
+
/**
|
|
25
|
+
* Any errors encountered while processing source files.
|
|
26
|
+
*/
|
|
5
27
|
sourceErrors: Error[];
|
|
28
|
+
/**
|
|
29
|
+
* Total number of files scanned.
|
|
30
|
+
*/
|
|
6
31
|
totalFiles: number;
|
|
32
|
+
/**
|
|
33
|
+
* Total number of files matched by the target.
|
|
34
|
+
*/
|
|
7
35
|
totalMatchedFiles: number;
|
|
36
|
+
/**
|
|
37
|
+
* Total number of directories scanned.
|
|
38
|
+
*/
|
|
8
39
|
totalDirs: number;
|
|
9
40
|
};
|
|
10
41
|
/**
|
|
@@ -28,12 +59,44 @@ export type PatternMatcher = {
|
|
|
28
59
|
internal: SignedPattern;
|
|
29
60
|
external: SignedPattern;
|
|
30
61
|
};
|
|
62
|
+
/**
|
|
63
|
+
* Checks whether a given path should be ignored based on its patterns.
|
|
64
|
+
* @see {@link findAndExtract}
|
|
65
|
+
* @see {@link signedPatternIgnores}
|
|
66
|
+
* @see {@link https://github.com/Mopsgamer/view-ignored/tree/main/src/targets} for usage examples.
|
|
67
|
+
*/
|
|
31
68
|
export type PathChecker = (path: string, isDir: boolean, ctx: MatcherContext) => Promise<boolean>;
|
|
69
|
+
/**
|
|
70
|
+
* Represents a source of patterns for matching paths.
|
|
71
|
+
*/
|
|
32
72
|
export type Source = {
|
|
73
|
+
/**
|
|
74
|
+
* Patterns defined within the source file.
|
|
75
|
+
* Those patterns are for ignoring files.
|
|
76
|
+
*/
|
|
33
77
|
pattern: SignedPattern;
|
|
78
|
+
/**
|
|
79
|
+
* Name of the source file.
|
|
80
|
+
*/
|
|
34
81
|
name: string;
|
|
82
|
+
/**
|
|
83
|
+
* Indicates if the matching logic is inverted.
|
|
84
|
+
* For example, `package.json` `files` field inverts the matching logic,
|
|
85
|
+
* because it specifies files to include rather than exclude.
|
|
86
|
+
*/
|
|
35
87
|
inverted: boolean;
|
|
36
88
|
};
|
|
89
|
+
/**
|
|
90
|
+
* Populates a `Source` object from the content of a source file.
|
|
91
|
+
* @see {@link Source.pattern} for more details.
|
|
92
|
+
*/
|
|
37
93
|
export type SourceExtractor = (source: Source, content: Buffer<ArrayBuffer>) => void;
|
|
94
|
+
/**
|
|
95
|
+
* Populates the {@link MatcherContext.external} map with {@link Source} objects.
|
|
96
|
+
*/
|
|
38
97
|
export declare function findAndExtract(directory: string, sources: string[], matcher: Map<string, SourceExtractor>, ctx: MatcherContext): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Checks whether a given file should be ignored based on internal and external patterns.
|
|
100
|
+
* Populates unknown sources using {@link findAndExtract}.
|
|
101
|
+
*/
|
|
39
102
|
export declare function signedPatternIgnores(internal: SignedPattern, file: string, sources: string[], sourceMap: Map<string, SourceExtractor>, ctx: MatcherContext): Promise<boolean>;
|
package/out/patterns/matcher.js
CHANGED
|
@@ -10,6 +10,9 @@ export function patternMatches(pattern, path) {
|
|
|
10
10
|
}
|
|
11
11
|
return false;
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Populates the {@link MatcherContext.external} map with {@link Source} objects.
|
|
15
|
+
*/
|
|
13
16
|
export async function findAndExtract(directory, sources, matcher, ctx) {
|
|
14
17
|
const keys = [];
|
|
15
18
|
for (const sourceFileName of sources) {
|
|
@@ -74,6 +77,10 @@ export async function findAndExtract(directory, sources, matcher, ctx) {
|
|
|
74
77
|
}
|
|
75
78
|
}
|
|
76
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Checks whether a given file should be ignored based on internal and external patterns.
|
|
82
|
+
* Populates unknown sources using {@link findAndExtract}.
|
|
83
|
+
*/
|
|
77
84
|
export async function signedPatternIgnores(internal, file, sources, sourceMap, ctx) {
|
|
78
85
|
const parent = dirname(file);
|
|
79
86
|
let source = ctx.external.get(parent);
|
package/out/scan.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export type ScanOptions = {
|
|
|
11
11
|
*/
|
|
12
12
|
cwd?: string;
|
|
13
13
|
/**
|
|
14
|
-
* If enabled, the scan will return files that are ignored by the target
|
|
14
|
+
* If enabled, the scan will return files that are ignored by the target matcher.
|
|
15
15
|
*/
|
|
16
16
|
invert?: boolean;
|
|
17
17
|
/**
|
|
@@ -24,8 +24,9 @@ export type ScanOptions = {
|
|
|
24
24
|
*/
|
|
25
25
|
signal?: AbortSignal;
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
27
|
+
* Requires depth >= 0.
|
|
28
|
+
* If enabled, directories will be processed faster
|
|
29
|
+
* by skipping files after first match.
|
|
29
30
|
* This makes the scan faster but affects
|
|
30
31
|
* {@link MatcherContext.totalDirs},
|
|
31
32
|
* {@link MatcherContext.totalFiles},
|
|
@@ -37,10 +38,12 @@ export type ScanOptions = {
|
|
|
37
38
|
/**
|
|
38
39
|
* Scan the directory for included files based on the provided targets.
|
|
39
40
|
*
|
|
40
|
-
* Note that this function uses `fs/promises.opendir`
|
|
41
|
-
*
|
|
41
|
+
* Note that this function uses `fs/promises.readFile` and `fs/promises.opendir` without options within
|
|
42
|
+
* custom recursion, instead of `fs.promises.readdir` with `{ withFileTypes: true }.
|
|
43
|
+
* It also normalizes paths to use forward slashes.
|
|
44
|
+
* Please report any issues if you encounter problems related to this behavior.
|
|
42
45
|
*
|
|
43
46
|
* @param options Scan options.
|
|
44
|
-
* @returns A promise that resolves to a
|
|
47
|
+
* @returns A promise that resolves to a {@link MatcherContext} containing the scan results.
|
|
45
48
|
*/
|
|
46
49
|
export declare function scan(options: ScanOptions): Promise<MatcherContext>;
|
package/out/scan.js
CHANGED
|
@@ -3,11 +3,13 @@ import { opendir } from './walk.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* Scan the directory for included files based on the provided targets.
|
|
5
5
|
*
|
|
6
|
-
* Note that this function uses `fs/promises.opendir`
|
|
7
|
-
*
|
|
6
|
+
* Note that this function uses `fs/promises.readFile` and `fs/promises.opendir` without options within
|
|
7
|
+
* custom recursion, instead of `fs.promises.readdir` with `{ withFileTypes: true }.
|
|
8
|
+
* It also normalizes paths to use forward slashes.
|
|
9
|
+
* Please report any issues if you encounter problems related to this behavior.
|
|
8
10
|
*
|
|
9
11
|
* @param options Scan options.
|
|
10
|
-
* @returns A promise that resolves to a
|
|
12
|
+
* @returns A promise that resolves to a {@link MatcherContext} containing the scan results.
|
|
11
13
|
*/
|
|
12
14
|
export async function scan(options) {
|
|
13
15
|
const { target, cwd: cwdo = (await import('node:process')).cwd(), depth: maxDepth = Infinity, invert = false, signal = undefined, fastDepth = false, } = options;
|
|
@@ -86,7 +88,6 @@ export async function scan(options) {
|
|
|
86
88
|
}
|
|
87
89
|
ctx.paths.add(dir + '/');
|
|
88
90
|
}
|
|
89
|
-
console.log(ctx.paths);
|
|
90
91
|
return ctx;
|
|
91
92
|
}
|
|
92
93
|
function getDepth(path, maxDepth) {
|
package/out/targets/target.d.ts
CHANGED