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
package/README.md CHANGED
@@ -1,7 +1,9 @@
1
1
  # view-ignored
2
2
 
3
- [![npm version](https://badge.fury.io/js/view-ignored.svg)](https://www.npmjs.com/package/view-ignored)
4
- [![Downloads](https://img.shields.io/npm/dm/view-ignored.svg)](https://www.npmjs.com/package/view-ignored)
3
+ [![npm version](https://img.shields.io/npm/v/view-ignored.svg?style=flat)](https://www.npmjs.com/package/view-ignored)
4
+ [![npm downloads](https://img.shields.io/npm/dm/view-ignored.svg?style=flat)](https://www.npmjs.com/package/view-ignored)
5
+ [![github](https://img.shields.io/github/stars/Mopsgamer/view-ignored.svg?style=flat)](https://github.com/Mopsgamer/view-ignored)
6
+ [![github issues](https://img.shields.io/github/issues/Mopsgamer/view-ignored.svg?style=flat)](https://github.com/Mopsgamer/view-ignored/issues)
5
7
 
6
8
  Retrieve list of files ignored/included by Git, NPM, Yarn and VSC Extension.
7
9
 
@@ -34,10 +36,11 @@ viewig scan . --target=npm
34
36
  viewig scan . --parsable
35
37
 
36
38
  # scan: plugins (space, comma or pipe separated)
37
- viewig scan . --plugins="vign-p-tsx, vign-p-jsdoc"
38
- viewig scan . --plugins="vign-p-tsx vign-p-jsdoc"
39
- viewig scan . --plugins vign-p-tsx vign-p-jsdoc
40
- viewig scan . --plugins vign-p-tsx, vign-p-jsdoc
39
+ # all built-in plugins loaded automatically
40
+ viewig scan . --plugins="example1, example2"
41
+ viewig scan . --plugins="example1 example2"
42
+ viewig scan . --plugins example1 example2
43
+ viewig scan . --plugins example1, example2
41
44
 
42
45
  # config: print configuration entries
43
46
  viewig config get
@@ -50,24 +53,27 @@ viewig config set style=tree
50
53
  # config: always use nerdfonts
51
54
  viewig config set decor=nerdfonts
52
55
  # config: always use plugins
53
- viewig config set plugins=typescript-viewig,eslint-vign-plugin
56
+ viewig config set plugins=example1,example2
54
57
  ```
55
58
 
56
59
  ### Programmatically
57
60
 
61
+ All you need it to add
62
+
58
63
  ```js
59
- import * as vign from "view-ignored";
60
- import * as vign from "view-ignored/out/src/browser"; // for web environment apps
64
+ import * as vign from "view-ignored"; // or "view-ignored/browser"
61
65
 
62
- const fileInfoList = await vign.scanProject("git");
63
- const fileInfo = await vign.scanFile("./path/to/file", "git");
66
+ await vign.Plugins.loadBuiltIns(["git", "npm"]); // load built-in plugins
67
+ await vign.Plugins.loadBuiltIns(); // load all built-in plugins
68
+ await vign.Plugins.loadPlugins(["example"]); // load third-party plugins
64
69
 
65
- // options available
66
- const fileInfoList = await vign.scanProject("git", { cwd, ... });
70
+ // scan - options available
71
+ const fileInfoList = await vign.scan(".", { target: "git", cwd: process.cwd() });
72
+ const fileInfoList = await vign.scan(["./path/to/file"], { target: "git", process.cwd() });
67
73
 
68
74
  // use results
69
75
  if (fileInfo.ignored) {
70
- superCodeEditor.explorer.colorFile(fileInfo.filePath, "gray");
76
+ superCodeEditor.explorer.colorFile(fileInfo.relativePath, "gray");
71
77
  }
72
78
  ```
73
79
 
@@ -75,24 +81,14 @@ if (fileInfo.ignored) {
75
81
 
76
82
  ```js
77
83
  const sorter = vign.Sorting.firstFolders;
78
- const fileInfoList = await vign.scanProject("npm");
79
- const fileInfoSorted = fileInfoList.map(String).sort(sorter);
80
- ```
81
-
82
- ```js
83
- const sorter = vign.Sorting.modified;
84
- const fileInfoList = await vign.scanProject("npm");
85
-
86
- const cache = new Map<string, number>(fileInfoList.map(String).map(
87
- filePath => [filePath, fs.statSync(filePath).mtime.getTime()])
88
- );
89
- const lookedSorted = fileInfoList.sort((a, b) => sorter(a.toString(), b.toString(), cache));
84
+ const fileInfoList = await vign.scan(".", {target: "npm"});
85
+ const fileInfoSorted = fileInfoList.sort((a, b) => sorter(String(a), String(b)));
90
86
  ```
91
87
 
92
88
  ### Targets
93
89
 
94
90
  - `git`
95
- - `npm` (can be usable for PNPM and Bun)
91
+ - `npm` (use it for PNPM and Bun)
96
92
  - `yarn`
97
93
  - `vsce`
98
94
  - `jsr` *planned*
package/bin/viewig CHANGED
@@ -1,2 +1,4 @@
1
- #! /usr/bin/env node
2
- import "../out/src/bin.js"
1
+ #! /usr/bin/env node
2
+ import {programInit} from '../out/src/cli.js';
3
+
4
+ programInit();
@@ -1,45 +1,64 @@
1
- import { TargetBind } from "./targets.js";
2
- export * from "./targets.js";
1
+ import { type TargetBind } from './targets.js';
2
+ export * from './scanner.js';
3
+ export * from './targets.js';
4
+ /**
5
+ * Built-in name list.
6
+ * @public
7
+ */
8
+ export declare const builtInNameList: readonly ["git", "npm", "vsce", "yarn"];
9
+ /**
10
+ * Built-in name type.
11
+ * @public
12
+ */
13
+ export type BuiltInName = typeof builtInNameList[number];
3
14
  /**
4
15
  * The result of loading.
16
+ * @public
5
17
  */
6
- export interface PluginLoaded {
7
- moduleName: string;
18
+ export type PluginLoaded = {
19
+ resource: string;
8
20
  isLoaded: boolean;
9
21
  exports: unknown;
10
- }
22
+ };
11
23
  /**
12
- * If a plugin wants to change something, it must export it as default.
24
+ * If a plugin wants to change something, it must export default.
25
+ * @private
13
26
  */
14
- export interface PluginExport {
27
+ export type PluginExport = {
15
28
  viewignored: {
16
29
  addTargets: TargetBind[];
17
30
  };
18
- }
31
+ };
19
32
  /**
20
33
  * Checks if the value is the {@link PluginExport}.
34
+ * @public
21
35
  */
22
36
  export declare function isPluginExport(value: unknown): value is PluginExport;
23
37
  /**
24
38
  * Imports the plugin's exported data.
39
+ * @public
25
40
  */
26
41
  export declare function importPlugin(exportData: PluginExport): void;
27
42
  /**
28
- * No rejects.
29
- * @param moduleName Plugin name.
30
- * @returns Import result for the module.
43
+ * @param modulePath The plugin name.
44
+ * @returns The import result for the module.
45
+ * @public
46
+ */
47
+ export declare function loadPlugin(modulePath: string, useImport?: boolean): Promise<PluginLoaded>;
48
+ /**
49
+ * @param modulePathList The plugin name list.
50
+ * @returns The import result for the list of modules.
51
+ * @public
31
52
  */
32
- export declare function loadPlugin(moduleName: string): Promise<PluginLoaded>;
53
+ export declare function loadPlugins(modulePathList: string[]): Promise<PluginLoaded[]>;
33
54
  /**
34
- * Loads plugins one by one using {@link loadPlugin}.
35
- * @param moduleNameList The list of plugins.
55
+ * Load any built-in plugin.
56
+ * @public
36
57
  */
37
- export declare function loadPluginsQueue(moduleNameList?: string[]): Promise<PluginLoaded[]>;
38
- export declare const BuiltInGit: Promise<typeof import("./plugins/git.js")>;
39
- export declare const BuiltInVsce: Promise<typeof import("./plugins/vsce.js")>;
40
- export declare const BuiltInNpm: Promise<typeof import("./plugins/npm.js")>;
41
- export declare const BuiltInYarn: Promise<typeof import("./plugins/yarn.js")>;
58
+ export declare function loadBuiltIn(builtIn: BuiltInName): Promise<PluginLoaded>;
42
59
  /**
43
- * Built-in plugins loading queue.
60
+ * @param modulePathList The plugin name list.
61
+ * @returns The import result for the list of modules.
62
+ * @public
44
63
  */
45
- export declare const BuiltIns: Promise<[PromiseSettledResult<typeof import("./plugins/git.js")>, PromiseSettledResult<typeof import("./plugins/vsce.js")>, PromiseSettledResult<typeof import("./plugins/npm.js")>, PromiseSettledResult<typeof import("./plugins/yarn.js")>]>;
64
+ export declare function loadBuiltIns(builtInList?: BuiltInName[]): Promise<PluginLoaded[]>;
@@ -1,8 +1,25 @@
1
- import { isTargetBind, targetSet } from "./targets.js";
2
- import { loadPlugin as load } from "load-plugin";
3
- export * from "./targets.js";
1
+ import { loadPlugin as load } from 'load-plugin';
2
+ import pLimit from 'p-limit';
3
+ import { isTargetBind, targetSet } from './targets.js';
4
+ export * from './scanner.js';
5
+ export * from './targets.js';
6
+ /**
7
+ * @private
8
+ */
9
+ const builtInImportMap = {
10
+ git: './plugins/git.js',
11
+ npm: './plugins/npm.js',
12
+ vsce: './plugins/vsce.js',
13
+ yarn: './plugins/yarn.js',
14
+ };
15
+ /**
16
+ * Built-in name list.
17
+ * @public
18
+ */
19
+ export const builtInNameList = ['git', 'npm', 'vsce', 'yarn'];
4
20
  /**
5
21
  * Checks if the value is the {@link PluginExport}.
22
+ * @public
6
23
  */
7
24
  export function isPluginExport(value) {
8
25
  if (value?.constructor !== Object) {
@@ -10,10 +27,11 @@ export function isPluginExport(value) {
10
27
  }
11
28
  const vign = value.viewignored;
12
29
  return (vign?.constructor === Object)
13
- && 'addTargets' in vign && Array.isArray(vign.addTargets) && vign.addTargets.every(isTargetBind);
30
+ && 'addTargets' in vign && Array.isArray(vign.addTargets) && vign.addTargets.every(v => isTargetBind(v));
14
31
  }
15
32
  /**
16
33
  * Imports the plugin's exported data.
34
+ * @public
17
35
  */
18
36
  export function importPlugin(exportData) {
19
37
  const { addTargets } = exportData.viewignored;
@@ -22,57 +40,53 @@ export function importPlugin(exportData) {
22
40
  }
23
41
  }
24
42
  /**
25
- * No rejects.
26
- * @param moduleName Plugin name.
27
- * @returns Import result for the module.
43
+ * @param modulePath The plugin name.
44
+ * @returns The import result for the module.
45
+ * @public
28
46
  */
29
- export function loadPlugin(moduleName) {
47
+ export async function loadPlugin(modulePath, useImport = false) {
30
48
  try {
31
- return new Promise((resolve) => {
32
- load(moduleName)
33
- .catch((reason) => {
34
- const r = reason;
35
- if (r?.code === 'ERR_MODULE_NOT_FOUND') {
36
- reason = r.message;
37
- }
38
- const fail = { moduleName, isLoaded: false, exports: reason };
39
- resolve(fail);
40
- })
41
- .then((exports) => {
42
- const result = { moduleName, isLoaded: true, exports };
43
- if (isPluginExport(exports)) {
44
- importPlugin(exports);
45
- }
46
- resolve(result);
47
- });
48
- });
49
+ const exports = useImport ? Object.getOwnPropertyDescriptor(await import(modulePath), 'default')?.value : await load(modulePath);
50
+ const result = { resource: modulePath, isLoaded: true, exports };
51
+ if (isPluginExport(exports)) {
52
+ importPlugin(exports);
53
+ }
54
+ return result;
49
55
  }
50
- catch (reason) {
51
- const fail = { moduleName, isLoaded: false, exports: reason };
52
- return Promise.resolve(fail);
56
+ catch (error) {
57
+ const r = error;
58
+ let reason = r;
59
+ if (r?.code === 'ERR_MODULE_NOT_FOUND') {
60
+ reason = r.message;
61
+ }
62
+ const fail = { resource: modulePath, isLoaded: false, exports: reason };
63
+ return fail;
53
64
  }
54
65
  }
55
66
  /**
56
- * Loads plugins one by one using {@link loadPlugin}.
57
- * @param moduleNameList The list of plugins.
67
+ * @param modulePathList The plugin name list.
68
+ * @returns The import result for the list of modules.
69
+ * @public
58
70
  */
59
- export async function loadPluginsQueue(moduleNameList) {
60
- const resultList = [];
61
- for (const module of moduleNameList ?? []) {
62
- const result = await loadPlugin(module);
63
- resultList.push(result);
64
- }
65
- return resultList;
71
+ export async function loadPlugins(modulePathList) {
72
+ const limit = pLimit(5);
73
+ const allLoaded = await Promise.all(modulePathList.map(modulePath => limit(() => loadPlugin(modulePath))));
74
+ return allLoaded;
66
75
  }
67
- export const BuiltInGit = import("./plugins/git.js");
68
- BuiltInGit.then(e => e.default).then(importPlugin);
69
- export const BuiltInVsce = import("./plugins/vsce.js");
70
- BuiltInVsce.then(e => e.default).then(importPlugin);
71
- export const BuiltInNpm = import("./plugins/npm.js");
72
- BuiltInNpm.then(e => e.default).then(importPlugin);
73
- export const BuiltInYarn = import("./plugins/yarn.js");
74
- BuiltInYarn.then(e => e.default).then(importPlugin);
75
76
  /**
76
- * Built-in plugins loading queue.
77
+ * Load any built-in plugin.
78
+ * @public
77
79
  */
78
- export const BuiltIns = Promise.allSettled([BuiltInGit, BuiltInVsce, BuiltInNpm, BuiltInYarn]);
80
+ export function loadBuiltIn(builtIn) {
81
+ return loadPlugin(builtInImportMap[builtIn], true);
82
+ }
83
+ /**
84
+ * @param modulePathList The plugin name list.
85
+ * @returns The import result for the list of modules.
86
+ * @public
87
+ */
88
+ export async function loadBuiltIns(builtInList = Array.from(builtInNameList)) {
89
+ const limit = pLimit(5);
90
+ const allLoaded = await Promise.all(builtInList.map(modulePath => limit(() => loadBuiltIn(modulePath))));
91
+ return allLoaded;
92
+ }
@@ -1,3 +1,22 @@
1
- import { Plugins } from "../../index.js";
2
- declare const _default: Plugins.PluginExport;
3
- export default _default;
1
+ import { type Plugins, type Methodology, File, SourceInfo, type Scanner } from '../../index.js';
2
+ /**
3
+ * @private
4
+ */
5
+ export declare const matcherExclude: string[];
6
+ /**
7
+ * For the source file parent directory we are getting all the cache recursively for all files.
8
+ * @param map The output.
9
+ * @param scanner The scanner.
10
+ * @param sourceFile This file will be converted to a {@link SourceInfo}.
11
+ * @private
12
+ */
13
+ export declare function useSourceFile(map: Map<File, SourceInfo>, sourceFile: File, scanner: Scanner & {
14
+ pattern: string | string[];
15
+ }): Map<File, SourceInfo>;
16
+ /**
17
+ * @param base The name for gitignore-like file.
18
+ * @private
19
+ */
20
+ export declare const methodologyGitignoreLike: (base: string) => Methodology;
21
+ declare const git: Plugins.PluginExport;
22
+ export default git;
@@ -1,24 +1,60 @@
1
- const id = "git";
2
- const name = {
3
- ifNormal: "Git",
4
- ifNerd: "\ue65d Git"
5
- };
6
- const testCommand = `git ls-tree -r <git-branch-name> --name-only`;
7
- const matcherExclude = [
8
- ".git/**",
9
- ".DS_Store/**"
1
+ import { icons } from '@m234/nerd-fonts';
2
+ import { File, NoSourceError, SourceInfo, InvalidPatternError, Directory, } from '../../index.js';
3
+ import { ScannerGitignore } from '../scanner.js';
4
+ const id = 'git';
5
+ const name = 'Git';
6
+ const icon = { ...icons['nf-seti-git'], color: 0xF4_4E_28 };
7
+ const testCommand = 'git ls-tree -r <git-branch-name> --name-only';
8
+ /**
9
+ * @private
10
+ */
11
+ export const matcherExclude = [
12
+ '**/.git/**',
13
+ '**/.DS_Store/**',
10
14
  ];
11
- const scan = function (fileInfo) {
12
- const { scanner, content } = fileInfo;
13
- const pat = content?.toString();
14
- if (!scanner.patternIsValid(pat)) {
15
- return false;
15
+ /**
16
+ * For the source file parent directory we are getting all the cache recursively for all files.
17
+ * @param map The output.
18
+ * @param scanner The scanner.
19
+ * @param sourceFile This file will be converted to a {@link SourceInfo}.
20
+ * @private
21
+ */
22
+ export function useSourceFile(map, sourceFile, scanner) {
23
+ const sourceInfo = SourceInfo.from(sourceFile, scanner);
24
+ for (const file of sourceFile.parent.deepIterator()) {
25
+ if (file instanceof Directory) {
26
+ continue;
27
+ }
28
+ map.set(file, sourceInfo);
29
+ }
30
+ return map;
31
+ }
32
+ /**
33
+ * @param base The name for gitignore-like file.
34
+ * @private
35
+ */
36
+ export const methodologyGitignoreLike = (base) => function (tree, o) {
37
+ const sourceList = tree.deep(File).filter(dirent => dirent.base === base);
38
+ const map = new Map();
39
+ for (const sourceFile of sourceList) {
40
+ const scanner = new ScannerGitignore({ exclude: matcherExclude });
41
+ if (sourceFile === undefined) {
42
+ throw new NoSourceError(base);
43
+ }
44
+ const content = o.modules.fs.readFileSync(sourceFile.absolutePath).toString();
45
+ const pattern = content;
46
+ if (!scanner.isValid(pattern)) {
47
+ throw new InvalidPatternError(sourceFile, pattern);
48
+ }
49
+ scanner.pattern = pattern;
50
+ useSourceFile(map, sourceFile, scanner);
16
51
  }
17
- scanner.add(pat);
18
- return true;
52
+ return map;
19
53
  };
20
- const methodology = [
21
- { pattern: "**/.gitignore", matcher: "gitignore", scan, matcherExclude },
22
- ];
23
- const bind = { id, name, methodology, testCommand };
24
- export default { viewignored: { addTargets: [bind] } };
54
+ const bind = {
55
+ id, icon, name, testCommand, scanOptions: {
56
+ target: methodologyGitignoreLike('.gitignore'),
57
+ },
58
+ };
59
+ const git = { viewignored: { addTargets: [bind] } };
60
+ export default git;
@@ -1,11 +1,38 @@
1
- import { Plugins, ScanMethod, Methodology } from "../../index.js";
2
- export declare const id = "npm";
3
- export declare const name = "NPM";
4
- export declare const testCommand = "npm pack --dry-run";
1
+ import { type Plugins, type Methodology, type File, Directory, type SourceInfo } from '../../index.js';
2
+ import { type PatternScanner } from '../scanner.js';
3
+ /**
4
+ * @private
5
+ */
5
6
  export declare const matcherExclude: string[];
7
+ /**
8
+ * @private
9
+ */
6
10
  export declare const matcherInclude: string[];
7
- export declare const scanGit: ScanMethod;
8
- export declare const scanPackageJsonFiles: ScanMethod;
9
- export declare const methodology: Methodology[];
10
- declare const _default: Plugins.PluginExport;
11
- export default _default;
11
+ /**
12
+ * @private
13
+ */
14
+ export type ValidManifestNpm = {
15
+ name: string;
16
+ version: string;
17
+ files?: string[];
18
+ };
19
+ /**
20
+ * @private
21
+ */
22
+ export declare function isValidManifest(value: unknown): value is ValidManifestNpm;
23
+ /**
24
+ * @private
25
+ */
26
+ export declare function useChildren(tree: Directory, map: Map<File, SourceInfo>, getMap: (child: Directory) => Map<File, SourceInfo>): Map<File, SourceInfo>;
27
+ /**
28
+ * @private
29
+ */
30
+ export declare const sourceSearch: (priority: string[], scanner: PatternScanner) => Methodology;
31
+ /**
32
+ * @param priority The list of file names from highest to lowest priority.
33
+ * @param scanner The pattern scanner.
34
+ * @private
35
+ */
36
+ export declare const methodologyManifestNpmLike: (priority: string[], scanner: PatternScanner) => Methodology;
37
+ declare const npm: Plugins.PluginExport;
38
+ export default npm;