view-ignored 0.2.2 → 0.3.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.
Files changed (58) hide show
  1. package/README.md +23 -27
  2. package/bin/viewig +4 -2
  3. package/out/src/browser/binds/index.d.ts +40 -21
  4. package/out/src/browser/binds/index.js +62 -48
  5. package/out/src/browser/binds/plugins/git.d.ts +22 -3
  6. package/out/src/browser/binds/plugins/git.js +57 -21
  7. package/out/src/browser/binds/plugins/npm.d.ts +36 -9
  8. package/out/src/browser/binds/plugins/npm.js +125 -59
  9. package/out/src/browser/binds/plugins/vsce.d.ts +24 -8
  10. package/out/src/browser/binds/plugins/vsce.js +56 -16
  11. package/out/src/browser/binds/plugins/yarn.d.ts +5 -10
  12. package/out/src/browser/binds/plugins/yarn.js +18 -68
  13. package/out/src/browser/binds/scanner.d.ts +56 -0
  14. package/out/src/browser/binds/scanner.js +134 -0
  15. package/out/src/browser/binds/targets.d.ts +35 -11
  16. package/out/src/browser/binds/targets.js +10 -17
  17. package/out/src/browser/errors.d.ts +58 -7
  18. package/out/src/browser/errors.js +40 -12
  19. package/out/src/browser/filtering.d.ts +15 -0
  20. package/out/src/browser/filtering.js +12 -0
  21. package/out/src/browser/fs/directory.d.ts +181 -0
  22. package/out/src/browser/fs/directory.js +235 -0
  23. package/out/src/browser/{fileinfo.d.ts → fs/file-info.d.ts} +38 -27
  24. package/out/src/browser/fs/file-info.js +86 -0
  25. package/out/src/browser/fs/file.d.ts +41 -0
  26. package/out/src/browser/fs/file.js +43 -0
  27. package/out/src/browser/fs/index.d.ts +4 -0
  28. package/out/src/browser/fs/index.js +4 -0
  29. package/out/src/browser/fs/source-info.d.ts +29 -0
  30. package/out/src/browser/fs/source-info.js +31 -0
  31. package/out/src/browser/index.d.ts +2 -2
  32. package/out/src/browser/index.js +2 -2
  33. package/out/src/browser/lib.d.ts +102 -101
  34. package/out/src/browser/lib.js +86 -120
  35. package/out/src/browser/sorting.d.ts +22 -2
  36. package/out/src/browser/sorting.js +37 -32
  37. package/out/src/browser/styling.d.ts +41 -15
  38. package/out/src/browser/styling.js +28 -97
  39. package/out/src/cli.d.ts +73 -34
  40. package/out/src/cli.js +308 -155
  41. package/out/src/config.d.ts +163 -65
  42. package/out/src/config.js +285 -171
  43. package/out/src/errors.d.ts +7 -0
  44. package/out/src/errors.js +1 -0
  45. package/out/src/index.d.ts +2 -2
  46. package/out/src/index.js +2 -2
  47. package/out/src/lib.d.ts +4 -4
  48. package/out/src/lib.js +4 -4
  49. package/out/src/styling.d.ts +10 -4
  50. package/out/src/styling.js +46 -33
  51. package/package.json +121 -107
  52. package/out/src/bin.d.ts +0 -2
  53. package/out/src/bin.js +0 -3
  54. package/out/src/browser/fileinfo.js +0 -78
  55. package/out/src/browser/scanner.d.ts +0 -103
  56. package/out/src/browser/scanner.js +0 -161
  57. package/out/src/browser/sourceinfo.d.ts +0 -62
  58. package/out/src/browser/sourceinfo.js +0 -107
@@ -1,19 +1,39 @@
1
- import { ScanFolderOptions, Methodology } from "../lib.js";
2
- import { DecorConditionOptions } from "../styling.js";
1
+ import { type ScanOptions } from '../lib.js';
2
+ /**
3
+ * The target icon/logo as a {@link https://www.nerdfonts.com/ NF} icon.
4
+ * @public
5
+ */
6
+ export type TargetIcon = {
7
+ /**
8
+ * Glyph character.
9
+ */
10
+ char: string;
11
+ /**
12
+ * The icon's color.
13
+ */
14
+ color?: number;
15
+ };
16
+ /**
17
+ * @public
18
+ */
19
+ export type TargetName = string;
3
20
  /**
4
21
  * Should satisfy RegExp: `/^[-a-zA-Z0-9]+$/`.
22
+ * @public
5
23
  */
6
24
  export type TargetId = string;
7
25
  /**
8
26
  * @param value Target's id. Simple name.
9
27
  * @returns `true`, if the id is available for binding.
28
+ * @public
10
29
  */
11
30
  export declare function isTargetId(value: unknown): value is TargetId;
12
31
  /**
13
32
  * The bind which allows use predefined options for scan functions.
14
- * @see {@link scanProject}
33
+ * @see {@link scanFolder}
34
+ * @public
15
35
  */
16
- export interface TargetBind {
36
+ export type TargetBind = {
17
37
  /**
18
38
  * Simple name.
19
39
  * @see {@link isTargetId}
@@ -22,15 +42,15 @@ export interface TargetBind {
22
42
  /**
23
43
  * Readable name.
24
44
  */
25
- name: string | DecorConditionOptions;
45
+ name: TargetName;
26
46
  /**
27
- * The walkthrough. Files including patterns.
47
+ * Optional icon/logo.
28
48
  */
29
- methodology: Methodology[];
49
+ icon?: TargetIcon;
30
50
  /**
31
51
  * Folder deep scanning options for the target.
32
52
  */
33
- scanOptions?: ScanFolderOptions;
53
+ scanOptions?: ScanOptions;
34
54
  /**
35
55
  * Test command.
36
56
  * @example
@@ -38,21 +58,24 @@ export interface TargetBind {
38
58
  * "vsce ls"
39
59
  */
40
60
  testCommand?: string;
41
- }
61
+ };
42
62
  /**
43
63
  * Checks if the value is the {@link TargetBind}.
64
+ * @public
44
65
  */
45
66
  export declare function isTargetBind(value: unknown): value is TargetBind;
46
67
  /**
47
68
  * Allows to create targets for view-ignored scan* functions.
69
+ * @public
48
70
  * @example
49
- * scanProject("abc") // error
71
+ * scanFolder("abc") // error
50
72
  * Bindings.targetSet("abc", {...})
51
- * scanProject("abc") // ok
73
+ * scanFolder("abc") // ok
52
74
  */
53
75
  export declare function targetSet(bind: TargetBind): void;
54
76
  /**
55
77
  * Get all target ids.
78
+ * @public
56
79
  * @example
57
80
  * ["git", "npm", "vsce", ...]
58
81
  */
@@ -60,5 +83,6 @@ export declare function targetList(): string[];
60
83
  /**
61
84
  * Get target bind by target id.
62
85
  * @param id Target id.
86
+ * @public
63
87
  */
64
88
  export declare function targetGet(id: TargetId): TargetBind | undefined;
@@ -1,45 +1,37 @@
1
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
- import { isMethodology } from "../lib.js";
3
1
  /**
4
2
  * @param value Target's id. Simple name.
5
3
  * @returns `true`, if the id is available for binding.
4
+ * @public
6
5
  */
7
6
  export function isTargetId(value) {
8
- return typeof value === "string" && value.match(/^[-a-zA-Z0-9]+$/) != null;
7
+ return typeof value === 'string' && (/^[-a-zA-Z\d]+$/.exec(value)) !== null;
9
8
  }
10
9
  /**
11
10
  * Checks if the value is the {@link TargetBind}.
11
+ * @public
12
12
  */
13
13
  export function isTargetBind(value) {
14
- if (value?.constructor !== Object) {
15
- return false;
16
- }
17
- const v = value;
18
- return (isTargetId(v.id))
19
- && (typeof v.name === "string" || v.name?.constructor === Object)
20
- && (Array.isArray(v.methodology) && v.methodology.every(isMethodology))
21
- && (v.scanOptions === undefined || v.scanOptions?.constructor === Object)
22
- && (v.testCommand === undefined || typeof v.testCommand === "string");
14
+ return value?.constructor === Object;
23
15
  }
24
16
  /**
25
17
  * The container for binds: id=bind.
18
+ * @private
26
19
  */
27
20
  const targetBindMap = new Map();
28
21
  /**
29
22
  * Allows to create targets for view-ignored scan* functions.
23
+ * @public
30
24
  * @example
31
- * scanProject("abc") // error
25
+ * scanFolder("abc") // error
32
26
  * Bindings.targetSet("abc", {...})
33
- * scanProject("abc") // ok
27
+ * scanFolder("abc") // ok
34
28
  */
35
29
  export function targetSet(bind) {
36
- if (!isTargetId(bind.id)) {
37
- throw TypeError(`view-ignored can not bind target with id '${bind.id}'`);
38
- }
39
30
  targetBindMap.set(bind.id, bind);
40
31
  }
41
32
  /**
42
33
  * Get all target ids.
34
+ * @public
43
35
  * @example
44
36
  * ["git", "npm", "vsce", ...]
45
37
  */
@@ -50,6 +42,7 @@ export function targetList() {
50
42
  /**
51
43
  * Get target bind by target id.
52
44
  * @param id Target id.
45
+ * @public
53
46
  */
54
47
  export function targetGet(id) {
55
48
  return targetBindMap.get(id);
@@ -1,10 +1,61 @@
1
- import { Methodology } from "../lib.js";
2
- export declare class SomeError extends Error {
1
+ import { type File } from './lib.js';
2
+ /**
3
+ * @public
4
+ */
5
+ export declare class ViewIgnoredError extends Error {
6
+ name: string;
3
7
  }
4
- export declare class ErrorNoSources extends SomeError {
5
- constructor(sources?: (readonly Methodology[]) | string);
6
- static walk(sources?: (readonly Methodology[]) | string): string;
8
+ /**
9
+ * @public
10
+ */
11
+ export declare class NoSourceError extends ViewIgnoredError {
12
+ static joinOr(fileBaseList: string[]): string;
13
+ static joinAnd(fileBaseList: string[]): string;
14
+ name: string;
15
+ /**
16
+ * @param fileBase Excpected message in the brackets. Describes which files was expected (e.g. 'config.json').
17
+ * @example
18
+ * new NoSourceError('\'package.json\'')
19
+ * new NoSourceError(NoSourceError.joinOr(['package.json', '.npmignore']))
20
+ * new NoSourceError(NoSourceError.joinAnd(['package.json', '.npmignore']))
21
+ */
22
+ constructor(fileBase: string);
23
+ /**
24
+ * @param file The {@link File} instance ('relativePath' property will be used).
25
+ */
26
+ constructor(file: File);
7
27
  }
8
- export declare class ErrorTargetNotBound extends SomeError {
9
- constructor(targetId: unknown);
28
+ /**
29
+ * @public
30
+ */
31
+ export declare class BadSourceError extends ViewIgnoredError {
32
+ name: string;
33
+ /**
34
+ * @param fileBase The base of the file (e.g. 'config.json').
35
+ * @param message The following message after the colon. First letter uppercase, no dot.
36
+ * @example
37
+ * new BadSourceError('package.json', 'Must have name and version')
38
+ */
39
+ constructor(fileBase: string, message: string);
40
+ /**
41
+ * @param fileBase The {@link File} instance ('relativePath' property will be used).
42
+ * @param message The following message after the colon. First letter uppercase, no dot.
43
+ * @example
44
+ * new BadSourceError('package.json', 'Must have name and version')
45
+ */
46
+ constructor(file: File, message: string);
47
+ }
48
+ /**
49
+ * @public
50
+ */
51
+ export declare class InvalidPatternError extends ViewIgnoredError {
52
+ name: string;
53
+ constructor(file: File, pattern?: string | string[]);
54
+ }
55
+ /**
56
+ * @public
57
+ */
58
+ export declare class TargetNotBoundError extends ViewIgnoredError {
59
+ name: string;
60
+ constructor(targetId: string);
10
61
  }
@@ -1,19 +1,47 @@
1
- import { targetGet } from "./binds/targets.js";
2
- export class SomeError extends Error {
1
+ /**
2
+ * @public
3
+ */
4
+ export class ViewIgnoredError extends Error {
5
+ name = 'ViewIgnoredError';
3
6
  }
4
- export class ErrorNoSources extends SomeError {
5
- constructor(sources) {
6
- super("No available sources for methodology: " + ErrorNoSources.walk(sources));
7
+ /**
8
+ * @public
9
+ */
10
+ export class NoSourceError extends ViewIgnoredError {
11
+ static joinOr(fileBaseList) {
12
+ return fileBaseList.map(base => `'${base}'`).join(' or ');
7
13
  }
8
- static walk(sources) {
9
- const s = typeof sources === "string" ? targetGet(sources)?.methodology : sources;
10
- if (!s) {
11
- return `bad bind for target '${s}'`;
12
- }
13
- return s.map(m => `'${m.pattern}'`).join(" -> ");
14
+ static joinAnd(fileBaseList) {
15
+ return fileBaseList.map(base => `'${base}'`).join(' and ');
16
+ }
17
+ name = 'NoSourceError';
18
+ constructor(argument0) {
19
+ super(`There was no configuration file (${typeof argument0 === 'string' ? argument0 : argument0.relativePath}) in the folders and subfolders that would correctly describe the ignoring.`);
20
+ }
21
+ }
22
+ /**
23
+ * @public
24
+ */
25
+ export class BadSourceError extends ViewIgnoredError {
26
+ name = 'BadSourceError';
27
+ constructor(argument0, message) {
28
+ super(`Invalid ${typeof argument0 === 'string' ? argument0 : argument0.relativePath}: ${message}`);
29
+ }
30
+ }
31
+ /**
32
+ * @public
33
+ */
34
+ export class InvalidPatternError extends ViewIgnoredError {
35
+ name = 'InvalidPatternError';
36
+ constructor(file, pattern) {
37
+ super(`Invalid pattern in ${file.relativePath}: ${pattern === undefined ? '' : ` Pattern: ${JSON.stringify(pattern)}`}`);
14
38
  }
15
39
  }
16
- export class ErrorTargetNotBound extends SomeError {
40
+ /**
41
+ * @public
42
+ */
43
+ export class TargetNotBoundError extends ViewIgnoredError {
44
+ name = 'TargetNotBoundError';
17
45
  constructor(targetId) {
18
46
  super(`The target has no bound: '${targetId}'.`);
19
47
  }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Contains all filter names.
3
+ * @public
4
+ */
5
+ export declare const filterNameList: readonly ["ignored", "included", "all"];
6
+ /**
7
+ * Contains all filter names as a type.
8
+ * @public
9
+ */
10
+ export type FilterName = typeof filterNameList[number];
11
+ /**
12
+ * Checks if the value is the {@link FilterName}.
13
+ * @public
14
+ */
15
+ export declare function isFilterName(value: unknown): value is FilterName;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Contains all filter names.
3
+ * @public
4
+ */
5
+ export const filterNameList = ['ignored', 'included', 'all'];
6
+ /**
7
+ * Checks if the value is the {@link FilterName}.
8
+ * @public
9
+ */
10
+ export function isFilterName(value) {
11
+ return typeof value === 'string' && filterNameList.includes(value);
12
+ }
@@ -0,0 +1,181 @@
1
+ import { type ParsedPath } from 'node:path';
2
+ import EventEmitter from 'node:events';
3
+ import { type RealScanOptions } from '../lib.js';
4
+ import { File } from './file.js';
5
+ /**
6
+ * @public
7
+ */
8
+ export type DeepStreamEventEmitter = EventEmitter<DeepStreamEventMap> & {
9
+ endPromise: Promise<DeepStreamDataRoot>;
10
+ run(): void;
11
+ };
12
+ /**
13
+ * @public
14
+ */
15
+ export type DeepStreamDataRoot = {
16
+ tree: Directory;
17
+ progress: DeepStreamProgress;
18
+ };
19
+ /**
20
+ * @public
21
+ */
22
+ export type DeepStreamData = {
23
+ target: Entry;
24
+ progress: DeepStreamProgress;
25
+ };
26
+ /**
27
+ * @public
28
+ */
29
+ export type DeepStreamProgress = {
30
+ directories: number;
31
+ files: number;
32
+ current: number;
33
+ total: number;
34
+ };
35
+ /**
36
+ * @public
37
+ */
38
+ export type DeepStreamEventMap = {
39
+ 'data': [DeepStreamData];
40
+ 'end': [DeepStreamDataRoot];
41
+ 'progress': [DeepStreamProgress];
42
+ };
43
+ /**
44
+ * @public
45
+ */
46
+ export type DeepStream = ReadableStream<Entry>;
47
+ /**
48
+ * @private
49
+ */
50
+ type DeepStreamNestedOptions = DeepStreamOptions & {
51
+ controller?: DeepStreamEventEmitter;
52
+ parent?: Directory;
53
+ progress?: DeepStreamProgress;
54
+ };
55
+ /**
56
+ * @public
57
+ */
58
+ export type DeepCountOptions = Pick<DeepStreamNestedOptions, 'modules' | 'cwd' | 'concurrency' | 'progress'>;
59
+ /**
60
+ * @public
61
+ */
62
+ export type DeepModifiedTimeOptions = Pick<RealScanOptions, 'concurrency' | 'modules'>;
63
+ /**
64
+ * @public
65
+ */
66
+ export type DeepStreamOptions = Pick<RealScanOptions, 'cwd' | 'modules' | 'concurrency'>;
67
+ /**
68
+ * @public
69
+ */
70
+ export type Entry = Directory | File;
71
+ /**
72
+ * @public
73
+ */
74
+ export type EntryClass = typeof Directory | typeof File;
75
+ /**
76
+ * @public
77
+ */
78
+ export type EntryInstanceFrom<T extends undefined | EntryClass> = T extends undefined ? Entry : T extends typeof Directory ? Directory : File;
79
+ /**
80
+ * File system directory representation.
81
+ * @public
82
+ */
83
+ export declare class Directory implements ParsedPath {
84
+ /**
85
+ * The parent of the directory.
86
+ */
87
+ readonly parent: Directory | undefined;
88
+ /**
89
+ * The relative path to the directory.
90
+ */
91
+ readonly relativePath: string;
92
+ /**
93
+ * The absolute path to the file.
94
+ */
95
+ readonly absolutePath: string;
96
+ /**
97
+ * The content of the directory. It is a Map for performance reasons: you can find any file or folder without a loop if you know the name.
98
+ *
99
+ * Keys: {@link File.base} or {@link Directory.base}. Directory base ends with '/'.
100
+ *
101
+ * Values: {@link File} or {@link Directory} itself.
102
+ */
103
+ readonly children: Map<string, Entry>;
104
+ /**
105
+ * Get the number of directories and files.
106
+ * @param directoryPath Relative path to the directory.
107
+ * @param options The counter and reader options.
108
+ */
109
+ static deepCount(directoryPath: {
110
+ toString(): string;
111
+ }, options: DeepCountOptions): Promise<DeepStreamProgress>;
112
+ /**
113
+ * Read directories and files progressively.
114
+ * @param directoryPath Relative path to the directory.
115
+ * @param options The reader options.
116
+ */
117
+ static deepStream(directoryPath: string, optionsReal: DeepStreamOptions): DeepStreamEventEmitter;
118
+ /**
119
+ * Get the {@link Directory} instance from a file path list. Paths should be relative.
120
+ */
121
+ static from(pathList: Array<{
122
+ toString(): string;
123
+ }>, cwd?: string): Directory;
124
+ /**
125
+ * Get deep iterator for the directory.
126
+ */
127
+ static deepIterator: <T extends undefined | EntryClass>(directory: Directory, instanceOf?: T) => IterableIterator<EntryInstanceFrom<T>>;
128
+ /**
129
+ * Read directories and files progressively.
130
+ * @private This function should be wrapped by {@link deepStream}.
131
+ * @param directoryPath Relative path to the directory.
132
+ * @param options The reader options.
133
+ */
134
+ private static deepStreamNested;
135
+ readonly base: string;
136
+ readonly dir: string;
137
+ readonly ext: string;
138
+ readonly name: string;
139
+ readonly root: string;
140
+ constructor(
141
+ /**
142
+ * The parent of the directory.
143
+ */
144
+ parent: Directory | undefined,
145
+ /**
146
+ * The relative path to the directory.
147
+ */
148
+ relativePath: string,
149
+ /**
150
+ * The absolute path to the file.
151
+ */
152
+ absolutePath: string,
153
+ /**
154
+ * The content of the directory. It is a Map for performance reasons: you can find any file or folder without a loop if you know the name.
155
+ *
156
+ * Keys: {@link File.base} or {@link Directory.base}. Directory base ends with '/'.
157
+ *
158
+ * Values: {@link File} or {@link Directory} itself.
159
+ */
160
+ children: Map<string, Entry>);
161
+ /**
162
+ * @param instanceOf Optionally filter children by type.
163
+ */
164
+ deepIterator<T extends undefined | typeof File | typeof Directory>(instanceOf?: T): IterableIterator<EntryInstanceFrom<T>>;
165
+ /**
166
+ * @param instanceOf Optionally filter children by type.
167
+ */
168
+ deep<T extends undefined | typeof File | typeof Directory>(instanceOf?: T): EntryInstanceFrom<T>[];
169
+ /**
170
+ * @returns The relative path to the directory.
171
+ */
172
+ toString(): string;
173
+ get<T extends string>(key: T): (T extends `${string}/` ? Directory : File) | undefined;
174
+ set<T extends string>(key: T, value: (T extends `${string}/` ? Directory : File)): typeof this.children;
175
+ /**
176
+ * @returns The cache for each file of the directory with last time edited number.
177
+ * @see {@link modified}.
178
+ */
179
+ deepModifiedTime(out: Map<File, number>, realOptions: DeepModifiedTimeOptions): Promise<Map<File, number>>;
180
+ }
181
+ export {};