view-ignored 0.0.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 (123) hide show
  1. package/README.md +85 -0
  2. package/bin/viewig +2 -0
  3. package/lib/bin.d.ts +3 -0
  4. package/lib/bin.d.ts.map +1 -0
  5. package/lib/bin.js +4 -0
  6. package/lib/bin.js.map +1 -0
  7. package/lib/browser/binds.d.ts +22 -0
  8. package/lib/browser/binds.d.ts.map +1 -0
  9. package/lib/browser/binds.js +14 -0
  10. package/lib/browser/binds.js.map +1 -0
  11. package/lib/browser/fileinfo.d.ts +35 -0
  12. package/lib/browser/fileinfo.d.ts.map +1 -0
  13. package/lib/browser/fileinfo.js +42 -0
  14. package/lib/browser/fileinfo.js.map +1 -0
  15. package/lib/browser/index.d.ts +4 -0
  16. package/lib/browser/index.d.ts.map +1 -0
  17. package/lib/browser/index.js +4 -0
  18. package/lib/browser/index.js.map +1 -0
  19. package/lib/browser/lib.d.ts +122 -0
  20. package/lib/browser/lib.d.ts.map +1 -0
  21. package/lib/browser/lib.js +114 -0
  22. package/lib/browser/lib.js.map +1 -0
  23. package/lib/browser/looker.d.ts +60 -0
  24. package/lib/browser/looker.d.ts.map +1 -0
  25. package/lib/browser/looker.js +80 -0
  26. package/lib/browser/looker.js.map +1 -0
  27. package/lib/browser/plugins/git.d.ts +10 -0
  28. package/lib/browser/plugins/git.d.ts.map +1 -0
  29. package/lib/browser/plugins/git.js +23 -0
  30. package/lib/browser/plugins/git.js.map +1 -0
  31. package/lib/browser/plugins/npm.d.ts +12 -0
  32. package/lib/browser/plugins/npm.d.ts.map +1 -0
  33. package/lib/browser/plugins/npm.js +70 -0
  34. package/lib/browser/plugins/npm.js.map +1 -0
  35. package/lib/browser/plugins/vsce.d.ts +10 -0
  36. package/lib/browser/plugins/vsce.d.ts.map +1 -0
  37. package/lib/browser/plugins/vsce.js +23 -0
  38. package/lib/browser/plugins/vsce.js.map +1 -0
  39. package/lib/browser/plugins/yarn.d.ts +15 -0
  40. package/lib/browser/plugins/yarn.d.ts.map +1 -0
  41. package/lib/browser/plugins/yarn.js +46 -0
  42. package/lib/browser/plugins/yarn.js.map +1 -0
  43. package/lib/browser/sorting.d.ts +31 -0
  44. package/lib/browser/sorting.d.ts.map +1 -0
  45. package/lib/browser/sorting.js +121 -0
  46. package/lib/browser/sorting.js.map +1 -0
  47. package/lib/browser/sourcepattern.d.ts +25 -0
  48. package/lib/browser/sourcepattern.d.ts.map +1 -0
  49. package/lib/browser/sourcepattern.js +45 -0
  50. package/lib/browser/sourcepattern.js.map +1 -0
  51. package/lib/browser/styling.d.ts +16 -0
  52. package/lib/browser/styling.d.ts.map +1 -0
  53. package/lib/browser/styling.js +116 -0
  54. package/lib/browser/styling.js.map +1 -0
  55. package/lib/browser/tools/index.d.ts +3 -0
  56. package/lib/browser/tools/index.d.ts.map +1 -0
  57. package/lib/browser/tools/index.js +3 -0
  58. package/lib/browser/tools/index.js.map +1 -0
  59. package/lib/browser/tools/sorting.d.ts +31 -0
  60. package/lib/browser/tools/sorting.d.ts.map +1 -0
  61. package/lib/browser/tools/sorting.js +121 -0
  62. package/lib/browser/tools/sorting.js.map +1 -0
  63. package/lib/browser/tools/styles.d.ts +16 -0
  64. package/lib/browser/tools/styles.d.ts.map +1 -0
  65. package/lib/browser/tools/styles.js +116 -0
  66. package/lib/browser/tools/styles.js.map +1 -0
  67. package/lib/cli.d.ts +26 -0
  68. package/lib/cli.d.ts.map +1 -0
  69. package/lib/cli.js +134 -0
  70. package/lib/cli.js.map +1 -0
  71. package/lib/config.d.ts +80 -0
  72. package/lib/config.d.ts.map +1 -0
  73. package/lib/config.js +105 -0
  74. package/lib/config.js.map +1 -0
  75. package/lib/git.d.ts +13 -0
  76. package/lib/git.d.ts.map +1 -0
  77. package/lib/git.js +37 -0
  78. package/lib/git.js.map +1 -0
  79. package/lib/index.d.ts +4 -0
  80. package/lib/index.d.ts.map +1 -0
  81. package/lib/index.js +4 -0
  82. package/lib/index.js.map +1 -0
  83. package/lib/lib.d.ts +5 -0
  84. package/lib/lib.d.ts.map +1 -0
  85. package/lib/lib.js +5 -0
  86. package/lib/lib.js.map +1 -0
  87. package/lib/plugins/git.d.ts +9 -0
  88. package/lib/plugins/git.js +22 -0
  89. package/lib/plugins/git.js.map +1 -0
  90. package/lib/plugins/npm.d.ts +12 -0
  91. package/lib/plugins/npm.js +74 -0
  92. package/lib/plugins/npm.js.map +1 -0
  93. package/lib/plugins/vsce.d.ts +9 -0
  94. package/lib/plugins/vsce.js +22 -0
  95. package/lib/plugins/vsce.js.map +1 -0
  96. package/lib/plugins/yarn.d.ts +15 -0
  97. package/lib/plugins/yarn.js +50 -0
  98. package/lib/plugins/yarn.js.map +1 -0
  99. package/lib/tools/index.d.ts +3 -0
  100. package/lib/tools/index.js +4 -0
  101. package/lib/tools/index.js.map +1 -0
  102. package/lib/tools/methods.d.ts +16 -0
  103. package/lib/tools/methods.js +81 -0
  104. package/lib/tools/methods.js.map +1 -0
  105. package/lib/tools/sorting.d.ts +30 -0
  106. package/lib/tools/sorting.js +121 -0
  107. package/lib/tools/sorting.js.map +1 -0
  108. package/lib/tools/styles.d.ts +15 -0
  109. package/lib/tools/styles.js +123 -0
  110. package/lib/tools/styles.js.map +1 -0
  111. package/lib/util/index.d.ts +3 -0
  112. package/lib/util/index.js +4 -0
  113. package/lib/util/index.js.map +1 -0
  114. package/lib/util/presets.d.ts +24 -0
  115. package/lib/util/presets.js +129 -0
  116. package/lib/util/presets.js.map +1 -0
  117. package/lib/util/sorting.d.ts +30 -0
  118. package/lib/util/sorting.js +121 -0
  119. package/lib/util/sorting.js.map +1 -0
  120. package/lib/util/styles.d.ts +8 -0
  121. package/lib/util/styles.js +52 -0
  122. package/lib/util/styles.js.map +1 -0
  123. package/package.json +94 -0
package/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # view-ignored
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)
5
+
6
+ Retrieve list of files ignored/included by Git, NPM, Yarn and VSC Extension.
7
+
8
+ ## Highlights
9
+
10
+ - **Multi-target.** Get list of included files, using configuration files reader, not command line wrapper.
11
+ - **Use in browser.** view-ignored supports file system adapter.
12
+ - **Command line.** Supports no-color and multiple output styles, including [nerd fonts](https://github.com/ryanoasis/nerd-fonts).
13
+ - **Plugins.** API allows to add new [targets](#targets) programmatically. Command line interface does NOT support plugins.
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ npm i view-ignored
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ### Command line
24
+
25
+ ```bash
26
+ # get started
27
+ npm i -g view-ignored
28
+ viewig --help
29
+ view-ignored --help
30
+
31
+ # scan for git and npm
32
+ viewig scan .
33
+ viewig scan . --target=npm
34
+
35
+ # always scan npm by default
36
+ viewig config set target=npm
37
+ viewig scan .
38
+
39
+ # always use nerd font
40
+ viewig config set style=treeNerd
41
+ ```
42
+
43
+ ### Programmatically
44
+
45
+ ```js
46
+ import * as vign from "view-ignored";
47
+ import * as vign from "view-ignored/lib/browser"; // for web environment apps
48
+
49
+ const looked = vign.scanProject("git");
50
+ ```
51
+
52
+ #### Sorting:
53
+
54
+ ```js
55
+ const looked = vign.scanProject("npm");
56
+ const sorter = vign.Sorting.Sorters.firstFolders;
57
+ looked.map(String).sort(sorter);
58
+ ```
59
+
60
+ ```js
61
+ const looked = vign.scanProject("npm")
62
+ const sorter = Sorting.Sorters[flags.sort]
63
+ const cacheEditDates = new Map<FileInfo, Date>()
64
+ for (const look of looked) {
65
+ cacheEditDates.set(look, fs.statSync(look.filePath).mtime)
66
+ }
67
+ const lookedSorted = looked.sort((a, b) => sorter(
68
+ a.toString(), b.toString(),
69
+ cacheEditDates.get(a)!, cacheEditDates.get(b)!
70
+ ))
71
+ ```
72
+
73
+ ### Targets
74
+
75
+ - `git`
76
+ - Check: `git ls-tree -r <git-branch-name> --name-only`
77
+ - Sources walkthrough: '.gitignore' and git config `core.excludesFile`.
78
+ - `npm` (btw usable for PNPM and Bun)
79
+ - Check: `npm pack --dry-run`
80
+ - Sources walkthrough: 'package.json' otherwise '.npmignore' otherwise '.gitignore'.
81
+ - `yarn`
82
+ - Sources walkthrough: 'package.json' otherwise '.yarnignore' otherwise '.npmignore' otherwise '.gitignore'.
83
+ - `vsce`
84
+ - Check: `vsce ls`
85
+ - Sources walkthrough: '.vscodeignore' otherwise '.gitignore'.
package/bin/viewig ADDED
@@ -0,0 +1,2 @@
1
+ #! /usr/bin/env node
2
+ import "../lib/bin.js"
package/lib/bin.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #! /usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=bin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":""}
package/lib/bin.js ADDED
@@ -0,0 +1,4 @@
1
+ #! /usr/bin/env node
2
+ import { program } from "./cli.js";
3
+ program.parse();
4
+ //# sourceMappingURL=bin.js.map
package/lib/bin.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AACA,OAAO,EAAC,OAAO,EAAC,MAAM,UAAU,CAAC;AACjC,OAAO,CAAC,KAAK,EAAE,CAAA"}
@@ -0,0 +1,22 @@
1
+ import { LookFolderOptions, Source } from "./lib.js";
2
+ export interface TargetBind {
3
+ id: string;
4
+ name: string;
5
+ sources: Source[];
6
+ scanOptions?: LookFolderOptions;
7
+ /**
8
+ * Check command hint.
9
+ *
10
+ * @example
11
+ * "npm pack --dry run"
12
+ * "vsce ls"
13
+ */
14
+ check?: string;
15
+ }
16
+ export declare const targetBindMap: Map<string, TargetBind>;
17
+ export declare function isValidTargetId(id: unknown): boolean;
18
+ /**
19
+ * Allows to create defaults.
20
+ */
21
+ export declare function targetBind(bind: TargetBind): void;
22
+ //# sourceMappingURL=binds.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binds.d.ts","sourceRoot":"","sources":["../../src/browser/binds.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEpD,MAAM,WAAW,UAAU;IAC1B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACT,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,WAAW,CAAC,EAAE,iBAAiB,CAAA;IAC/B;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;CACjB;AACD,eAAO,MAAM,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAa,CAAA;AAC/D,wBAAgB,eAAe,CAAC,EAAE,EAAE,OAAO,WAE1C;AACD;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,QAK1C"}
@@ -0,0 +1,14 @@
1
+ export const targetBindMap = new Map();
2
+ export function isValidTargetId(id) {
3
+ return typeof id === "string" && id.match(/^[-a-zA-Z0-9]+$/) != null;
4
+ }
5
+ /**
6
+ * Allows to create defaults.
7
+ */
8
+ export function targetBind(bind) {
9
+ if (!isValidTargetId(bind.id)) {
10
+ throw TypeError(`view-ignored can not bind target with id '${bind.id}'`);
11
+ }
12
+ targetBindMap.set(bind.id, bind);
13
+ }
14
+ //# sourceMappingURL=binds.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binds.js","sourceRoot":"","sources":["../../src/browser/binds.ts"],"names":[],"mappings":"AAgBA,MAAM,CAAC,MAAM,aAAa,GAA4B,IAAI,GAAG,EAAE,CAAA;AAC/D,MAAM,UAAU,eAAe,CAAC,EAAW;IACvC,OAAO,OAAO,EAAE,KAAK,QAAQ,IAAI,EAAE,CAAC,KAAK,CAAC,iBAAiB,CAAC,IAAI,IAAI,CAAA;AACxE,CAAC;AACD;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,IAAgB;IACvC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;QAC5B,MAAM,SAAS,CAAC,6CAA6C,IAAI,CAAC,EAAE,GAAG,CAAC,CAAA;IAC5E,CAAC;IACD,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;AACpC,CAAC"}
@@ -0,0 +1,35 @@
1
+ import { ChalkInstance } from "chalk";
2
+ import { StyleName } from "./styling.js";
3
+ import { SourceFile } from "./lib.js";
4
+ import { Looker } from "./looker.js";
5
+ export interface FileInfoToStringOptions {
6
+ /**
7
+ * Determines if file icon should be used.
8
+ * @default
9
+ * undefined
10
+ */
11
+ styleName?: StyleName;
12
+ /**
13
+ * `true` if should add prefix: `+` or `!`.
14
+ */
15
+ usePrefix?: boolean;
16
+ chalk?: ChalkInstance;
17
+ }
18
+ /**
19
+ * Result of the file path scan.
20
+ */
21
+ export declare class FileInfo {
22
+ readonly filePath: string;
23
+ readonly looker: Looker;
24
+ readonly source: SourceFile;
25
+ readonly ignored: boolean;
26
+ constructor(filePath: string, looker: Looker, source: SourceFile);
27
+ static from(paths: string[], looker: Looker, source?: SourceFile | string): FileInfo[];
28
+ static from(path: string, looker: Looker, source?: SourceFile | string): FileInfo;
29
+ /**
30
+ * @param options Styling options.
31
+ * @param formatEntire Determines if path base or entire file path should be formatted. Default `true`.
32
+ */
33
+ toString(options?: FileInfoToStringOptions, formatEntire?: boolean): string;
34
+ }
35
+ //# sourceMappingURL=fileinfo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fileinfo.d.ts","sourceRoot":"","sources":["../../src/browser/fileinfo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AACrC,OAAO,EAAsB,SAAS,EAAE,MAAM,cAAc,CAAA;AAE5D,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,MAAM,WAAW,uBAAuB;IACvC;;;;OAIG;IACH,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,KAAK,CAAC,EAAE,aAAa,CAAA;CACrB;AACD;;GAEG;AACH,qBAAa,QAAQ;aAGH,QAAQ,EAAE,MAAM;aAChB,MAAM,EAAE,MAAM;aACd,MAAM,EAAE,UAAU;IAJnC,SAAgB,OAAO,EAAE,OAAO,CAAA;gBAEf,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,UAAU;IAInC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,UAAU,GAAG,MAAM,GAAG,QAAQ,EAAE;IACtF,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,UAAU,GAAG,MAAM,GAAG,QAAQ;IAQjF;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,uBAAuB,EAAE,YAAY,UAAO,GAAG,MAAM;CAiBxE"}
@@ -0,0 +1,42 @@
1
+ import { styleConditionFile } from "./styling.js";
2
+ import path from "path";
3
+ /**
4
+ * Result of the file path scan.
5
+ */
6
+ export class FileInfo {
7
+ constructor(filePath, looker, source) {
8
+ this.filePath = filePath;
9
+ this.looker = looker;
10
+ this.source = source;
11
+ this.ignored = looker.ignores(filePath);
12
+ }
13
+ static from(arg, looker, source) {
14
+ if (Array.isArray(arg)) {
15
+ return arg.map(path => FileInfo.from(path, looker, source));
16
+ }
17
+ const src = typeof source === "object" ? source : { path: '<no-source>', content: source !== null && source !== void 0 ? source : '' };
18
+ return new FileInfo(arg, looker, src);
19
+ }
20
+ /**
21
+ * @param options Styling options.
22
+ * @param formatEntire Determines if path base or entire file path should be formatted. Default `true`.
23
+ */
24
+ toString(options, formatEntire = true) {
25
+ const { styleName, usePrefix = false, chalk } = options !== null && options !== void 0 ? options : {};
26
+ const parsed = path.parse(this.filePath);
27
+ const fileIcon = styleConditionFile(styleName, this.filePath);
28
+ const prefix = usePrefix ? (this.ignored ? '!' : '+') : '';
29
+ if (chalk) {
30
+ const clr = chalk[this.ignored ? "red" : "green"];
31
+ if (formatEntire) {
32
+ return fileIcon + clr(prefix + this.filePath);
33
+ }
34
+ return parsed.dir + '/' + fileIcon + clr(prefix + parsed.base);
35
+ }
36
+ if (formatEntire) {
37
+ return prefix + this.filePath;
38
+ }
39
+ return parsed.dir + '/' + fileIcon + prefix + parsed.base;
40
+ }
41
+ }
42
+ //# sourceMappingURL=fileinfo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fileinfo.js","sourceRoot":"","sources":["../../src/browser/fileinfo.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAa,MAAM,cAAc,CAAA;AAC5D,OAAO,IAAI,MAAM,MAAM,CAAA;AAiBvB;;GAEG;AACH,MAAM,OAAO,QAAQ;IAEpB,YACiB,QAAgB,EAChB,MAAc,EACd,MAAkB;QAFlB,aAAQ,GAAR,QAAQ,CAAQ;QAChB,WAAM,GAAN,MAAM,CAAQ;QACd,WAAM,GAAN,MAAM,CAAY;QAElC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IACxC,CAAC;IAGD,MAAM,CAAC,IAAI,CAAC,GAAsB,EAAE,MAAc,EAAE,MAA4B;QAC/E,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;YACxB,OAAO,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;QAC5D,CAAC;QACD,MAAM,GAAG,GAAG,OAAO,MAAM,K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D,OAAO,MAAM,CAAC,GAAG,GAAG,GAAG,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC,IAAI,CAAA;IAC1D,CAAC;CACD"}
@@ -0,0 +1,4 @@
1
+ import * as ViewIgnored from "./lib.js";
2
+ export default ViewIgnored;
3
+ export * from "./lib.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,UAAU,CAAA;AACvC,eAAe,WAAW,CAAA;AAC1B,cAAc,UAAU,CAAA"}
@@ -0,0 +1,4 @@
1
+ import * as ViewIgnored from "./lib.js";
2
+ export default ViewIgnored;
3
+ export * from "./lib.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,UAAU,CAAA;AACvC,eAAe,WAAW,CAAA;AAC1B,cAAc,UAAU,CAAA"}
@@ -0,0 +1,122 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import { Looker } from "./looker.js";
3
+ import FastGlob from "fast-glob";
4
+ import { FileInfo } from "./fileinfo.js";
5
+ import { SourcePattern } from "./sourcepattern.js";
6
+ export * from "./looker.js";
7
+ export * from "./fileinfo.js";
8
+ export * from "./sourcepattern.js";
9
+ export * as Styling from "./styling.js";
10
+ export * as Sorting from "./sorting.js";
11
+ export * as Binding from "./binds.js";
12
+ import "./plugins/git.js";
13
+ import "./plugins/npm.js";
14
+ import "./plugins/vsce.js";
15
+ import "./plugins/yarn.js";
16
+ export type PatternType = ".*ignore" | "minimatch";
17
+ export declare const filterNameList: readonly ["ignored", "included", "all"];
18
+ export type FilterName = typeof filterNameList[number];
19
+ export interface FileSystemAdapter extends FastGlob.FileSystemAdapter {
20
+ readFileSync: (path: string) => Buffer;
21
+ }
22
+ /**
23
+ * @see {@link ScanMethod}
24
+ */
25
+ export interface LookMethodData {
26
+ looker: Looker;
27
+ filePath: string;
28
+ sourceFile: SourceFile;
29
+ }
30
+ /**
31
+ * Returns `true` if given source is valid, writes rules to the looker.
32
+ */
33
+ export type ScanMethod = (data: LookMethodData) => boolean;
34
+ export interface SourceFile {
35
+ /**
36
+ * Source file path
37
+ */
38
+ path: string;
39
+ /**
40
+ * Source file content
41
+ */
42
+ content: string;
43
+ }
44
+ export interface Source {
45
+ /**
46
+ * Git configuration property.
47
+ *
48
+ * @see {@link https://git-scm.com/docs/git-config#Documentation/git-config.txt-coreignoreCase|git-config ignorecase}.
49
+ * @default false
50
+ */
51
+ ignoreCase?: boolean;
52
+ /**
53
+ * Additional patterns, which will be used as
54
+ * other patterns in the `.gitignore` file, or `package.json` "files" property.
55
+ *
56
+ * @default []
57
+ */
58
+ addPatterns?: string[];
59
+ /**
60
+ * First valid source will be used as {@link Looker}.
61
+ */
62
+ sources: SourceFile[] | SourcePattern;
63
+ /**
64
+ * Pattern parser name.
65
+ */
66
+ patternType: PatternType;
67
+ /**
68
+ * {@link Looker} maker.
69
+ */
70
+ method: ScanMethod;
71
+ }
72
+ export interface ScanFileOptions {
73
+ /**
74
+ * Custom implementation of methods for working with the file system.
75
+ *
76
+ * @default fs.*
77
+ */
78
+ fs?: FileSystemAdapter;
79
+ /**
80
+ * The current working directory in which to search.
81
+ *
82
+ * @default process.cwd()
83
+ */
84
+ cwd?: string;
85
+ /**
86
+ * Specifies the maximum number of concurrent requests from a reader to read
87
+ * directories.
88
+ *
89
+ * @default os.cpus().length
90
+ */
91
+ concurrency?: number;
92
+ /**
93
+ * Specifies the maximum depth of a read directory relative to the start
94
+ * directory.
95
+ *
96
+ * @default Infinity
97
+ */
98
+ deep?: number;
99
+ }
100
+ export interface LookFolderOptions extends ScanFileOptions {
101
+ /**
102
+ * Filter output.
103
+ *
104
+ * @default "included"
105
+ */
106
+ filter?: FilterName;
107
+ }
108
+ /**
109
+ * Returns `undefined`, if the source is bad.
110
+ */
111
+ export declare function scanFile(filePath: string, sources: Source[], options: ScanFileOptions): Promise<FileInfo | undefined>;
112
+ /**
113
+ * Scan project directory paths with results for each file path.
114
+ */
115
+ export declare function scanPaths(allFilePaths: string[], sources: Source[], options: LookFolderOptions): Promise<FileInfo[] | undefined>;
116
+ export declare function scanPaths(allFilePaths: string[], target: string, options: LookFolderOptions): Promise<FileInfo[] | undefined>;
117
+ /**
118
+ * Scan project directory with results for each file path.
119
+ */
120
+ export declare function scanProject(sources: Source[], options: LookFolderOptions): Promise<FileInfo[] | undefined>;
121
+ export declare function scanProject(target: string, options: LookFolderOptions): Promise<FileInfo[] | undefined>;
122
+ //# sourceMappingURL=lib.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../src/browser/lib.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,QAAQ,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAkB,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnE,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,oBAAoB,CAAA;AAClC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,KAAK,OAAO,MAAM,YAAY,CAAA;AAGrC,OAAO,kBAAkB,CAAA;AACzB,OAAO,kBAAkB,CAAA;AACzB,OAAO,mBAAmB,CAAA;AAC1B,OAAO,mBAAmB,CAAA;AAG1B,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,WAAW,CAAA;AAClD,eAAO,MAAM,cAAc,yCAA0C,CAAA;AACrE,MAAM,MAAM,UAAU,GAAG,OAAO,cAAc,CAAC,MAAM,CAAC,CAAA;AAEtD,MAAM,WA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wBAAsB,SAAS,CAAC,YAAY,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,QAAQ,EAAE,GAAG,SAAS,CAAC,CAAA;AACvI,wBAAsB,SAAS,CAAC,YAAY,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,QAAQ,EAAE,GAAG,SAAS,CAAC,CAAA;AAiDpI;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,QAAQ,EAAE,GAAG,SAAS,CAAC,CAAA;AAC3G,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,QAAQ,EAAE,GAAG,SAAS,CAAC,CAAA"}
@@ -0,0 +1,114 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { Looker } from "./looker.js";
11
+ import { targetBindMap } from "./binds.js";
12
+ import { FileInfo } from "./fileinfo.js";
13
+ import { findDomination, SourcePattern } from "./sourcepattern.js";
14
+ export * from "./looker.js";
15
+ export * from "./fileinfo.js";
16
+ export * from "./sourcepattern.js";
17
+ export * as Styling from "./styling.js";
18
+ export * as Sorting from "./sorting.js";
19
+ export * as Binding from "./binds.js";
20
+ //#region default binds
21
+ import "./plugins/git.js";
22
+ import "./plugins/npm.js";
23
+ import "./plugins/vsce.js";
24
+ import "./plugins/yarn.js";
25
+ export const filterNameList = ["ignored", "included", "all"];
26
+ /**
27
+ * Returns `undefined`, if the source is bad.
28
+ */
29
+ export function scanFile(filePath, sources, options) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ for (const source of sources) {
32
+ const looker = new Looker({
33
+ addPatterns: source.addPatterns,
34
+ ignoreCase: source.ignoreCase,
35
+ patternType: source.patternType,
36
+ });
37
+ const sources = source.sources instanceof SourcePattern
38
+ ? yield source.sources.read(options)
39
+ : source.sources;
40
+ for (const file of sources) {
41
+ const l = looker.clone();
42
+ const isGoodSource = source.method({
43
+ sourceFile: file,
44
+ filePath: filePath,
45
+ looker: l
46
+ });
47
+ if (isGoodSource) {
48
+ return FileInfo.from(filePath, l, file);
49
+ }
50
+ }
51
+ }
52
+ });
53
+ }
54
+ export function scanPaths(allFilePaths, arg2, options) {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ var _a;
57
+ if (typeof arg2 === "string") {
58
+ const bind = targetBindMap.get(arg2);
59
+ if (bind === undefined) {
60
+ throw TypeError(`view-ignored can not find target '${arg2}'`);
61
+ }
62
+ return scanPaths(allFilePaths, bind.sources, (_a = bind.scanOptions) !== null && _a !== void 0 ? _a : {});
63
+ }
64
+ // Find good source
65
+ const { filter = "included" } = options;
66
+ const cache = new Map();
67
+ for (const source of arg2) {
68
+ let goodFound = false;
69
+ const resultList = [];
70
+ const sourceList = source.sources instanceof SourcePattern ? yield source.sources.read(options) : source.sources;
71
+ for (const filePath of allFilePaths) {
72
+ const possibleSource = findDomination(filePath, sourceList);
73
+ if (possibleSource === undefined) {
74
+ break;
75
+ }
76
+ const looker = cache.get(possibleSource.path);
77
+ let info;
78
+ if (looker === undefined) {
79
+ const newInfo = yield scanFile(filePath, [source], options);
80
+ if (newInfo === undefined) {
81
+ break;
82
+ }
83
+ info = newInfo;
84
+ cache.set(possibleSource.path, info.looker);
85
+ }
86
+ else {
87
+ info = FileInfo.from(filePath, looker, possibleSource);
88
+ }
89
+ const filterIgnore = (filter === "ignored") && info.ignored;
90
+ const filterInclude = (filter === "included") && !info.ignored;
91
+ const filterAll = filter === "all";
92
+ const shouldPush = filterIgnore || filterInclude || filterAll;
93
+ if (shouldPush) {
94
+ resultList.push(info);
95
+ }
96
+ goodFound || (goodFound = true);
97
+ }
98
+ if (goodFound) {
99
+ return resultList;
100
+ }
101
+ }
102
+ return undefined;
103
+ });
104
+ }
105
+ export function scanProject(arg, options) {
106
+ return new SourcePattern("**").scan(options).then(paths => {
107
+ if (typeof arg === "string") {
108
+ return scanPaths(paths, arg, options);
109
+ }
110
+ return scanPaths(paths, arg, options);
111
+ });
112
+ }
113
+ //#endregion
114
+ //# sourceMappingURL=lib.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lib.js","sourceRoot":"","sources":["../../src/browser/lib.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnE,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,oBAAoB,CAAA;AAClC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,KAAK,OAAO,MAAM,YAAY,CAAA;AAErC,uBAAuB;AACvB,OAAO,kBAAkB,CAAA;AACzB,OAAO,kBAAkB,CAAA;AACzB,OAAO,mBAAmB,CAAA;AAC1B,OAAO,mBAAmB,CAAA;AAI1B,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,CAAU,CAAA;AAiGrE;;GAEG;AACH,MAAM,UAA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AG,CAAC,MAAM,KAAK,SAAS,CAAC,IAAI,IAAI,CAAC,OAAO,CAAA;gBAC3D,MAAM,aAAa,GAAG,CAAC,MAAM,KAAK,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAA;gBAC9D,MAAM,SAAS,GAAG,MAAM,KAAK,KAAK,CAAA;gBAClC,MAAM,UAAU,GAAG,YAAY,IAAI,aAAa,IAAI,SAAS,CAAA;gBAC7D,IAAI,UAAU,EAAE,CAAC;oBAChB,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;gBACtB,CAAC;gBACD,SAAS,KAAT,SAAS,GAAK,IAAI,EAAA;YACnB,CAAC;YACD,IAAI,SAAS,EAAE,CAAC;gBACf,OAAO,UAAU,CAAA;YAClB,CAAC;QACF,CAAC;QACD,OAAO,SAAS,CAAA;IACjB,CAAC;CAAA;AAMD,MAAM,UAAU,WAAW,CAAC,GAAsB,EAAE,OAA0B;IAC7E,OAAO,IAAI,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;QACzD,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YAC7B,OAAO,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,CAAC,CAAA;QACtC,CAAC;QACD,OAAO,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,CAAC,CAAA;IACtC,CAAC,CAAC,CAAA;AACH,CAAC;AACD,YAAY"}
@@ -0,0 +1,60 @@
1
+ import { PatternType } from "./lib.js";
2
+ export interface LookerOptions {
3
+ /**
4
+ * @see {@link Looker.isNegated}
5
+ */
6
+ negated?: boolean;
7
+ patternType?: PatternType;
8
+ /**
9
+ * Git configuration property.
10
+ *
11
+ * @see {@link https://git-scm.com/docs/git-config#Documentation/git-config.txt-coreignoreCase|git-config ignorecase}.
12
+ * @default false
13
+ */
14
+ ignoreCase?: boolean;
15
+ /**
16
+ * Additional patterns, which will be used as
17
+ * other patterns in the `.gitignore` file, or `package.json` "files" property.
18
+ *
19
+ * @default []
20
+ */
21
+ addPatterns?: string[];
22
+ }
23
+ export type LookerPattern = string | string[];
24
+ export declare class Looker {
25
+ /**
26
+ * If `true`, when calling {@link Looker.ignores}, method will return `true` for ignored path.
27
+ *
28
+ * @default false
29
+ */
30
+ isNegated: boolean;
31
+ /**
32
+ * Defines way to check paths.
33
+ *
34
+ * @default ".*ignore"
35
+ */
36
+ patternType: PatternType;
37
+ readonly ignoreCase: boolean;
38
+ private patternList;
39
+ private ignoreInstance;
40
+ constructor(options?: LookerOptions);
41
+ clone(): Looker;
42
+ negate(): this;
43
+ /**
44
+ * Adds new ignore rule.
45
+ * @param pattern .gitignore file specification pattern.
46
+ */
47
+ add(pattern: LookerPattern): this;
48
+ /**
49
+ * Checks if the Looker should ignore dir entry path.
50
+ * @see {@link Looker.isNegated} can change the return value.
51
+ * @param path Dir entry path.
52
+ */
53
+ ignores(path: string): boolean;
54
+ /**
55
+ * Checks if given pattern is valid.
56
+ * @param pattern Dir entry path.
57
+ */
58
+ isValidPattern(pattern: LookerPattern): boolean;
59
+ }
60
+ //# sourceMappingURL=looker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"looker.d.ts","sourceRoot":"","sources":["../../src/browser/looker.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAEtC,MAAM,WAAW,aAAa;IAC7B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AACD,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,EAAE,CAAA;AAC7C,qBAAa,MAAM;IAClB;;;;OAIG;IACI,SAAS,EAAE,OAAO,CAAA;IACzB;;;;OAIG;IACI,WAAW,EAAE,WAAW,CAAA;IAC/B,SAAgB,UAAU,EAAE,OAAO,CAAA;IACnC,OAAO,CAAC,WAAW,CAAe;IAClC,OAAO,CAAC,cAAc,CAAQ;gBAElB,OAAO,CAAC,EAAE,aAAa;IAQnC,KAAK,IAAI,MAAM;IASf,MAAM,IAAI,IAAI;IAKd;;;OAGG;IACH,GAAG,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI;IAajC;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAU9B;;;OAGG;IACH,cAAc,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO;CAiB/C"}
@@ -0,0 +1,80 @@
1
+ import ignore from "ignore";
2
+ import { minimatch } from "minimatch";
3
+ export class Looker {
4
+ constructor(options) {
5
+ var _a, _b, _c, _d;
6
+ this.patternList = [];
7
+ this.isNegated = (_a = options === null || options === void 0 ? void 0 : options.negated) !== null && _a !== void 0 ? _a : false;
8
+ this.patternType = (_b = options === null || options === void 0 ? void 0 : options.patternType) !== null && _b !== void 0 ? _b : ".*ignore";
9
+ this.ignoreCase = (_c = options === null || options === void 0 ? void 0 : options.ignoreCase) !== null && _c !== void 0 ? _c : false;
10
+ this.ignoreInstance = ignore.default(options);
11
+ this.add((_d = options === null || options === void 0 ? void 0 : options.addPatterns) !== null && _d !== void 0 ? _d : []);
12
+ }
13
+ clone() {
14
+ const cloned = new Looker({
15
+ addPatterns: this.patternList,
16
+ negated: this.isNegated,
17
+ patternType: this.patternType,
18
+ });
19
+ return cloned;
20
+ }
21
+ negate() {
22
+ this.isNegated = !this.isNegated;
23
+ return this;
24
+ }
25
+ /**
26
+ * Adds new ignore rule.
27
+ * @param pattern .gitignore file specification pattern.
28
+ */
29
+ add(pattern) {
30
+ if (typeof pattern === "string") {
31
+ this.patternList.push(pattern);
32
+ this.ignoreInstance.add(pattern);
33
+ }
34
+ else {
35
+ for (const pat of pattern) {
36
+ this.patternList.push(pat);
37
+ this.ignoreInstance.add(pat);
38
+ }
39
+ }
40
+ return this;
41
+ }
42
+ /**
43
+ * Checks if the Looker should ignore dir entry path.
44
+ * @see {@link Looker.isNegated} can change the return value.
45
+ * @param path Dir entry path.
46
+ */
47
+ ignores(path) {
48
+ let ignores;
49
+ if (this.patternType === ".*ignore") {
50
+ ignores = this.ignoreInstance.ignores(path);
51
+ }
52
+ else { // minimatch
53
+ ignores = this.patternList.some(pattern => minimatch(path, pattern));
54
+ }
55
+ return this.isNegated ? !ignores : ignores;
56
+ }
57
+ /**
58
+ * Checks if given pattern is valid.
59
+ * @param pattern Dir entry path.
60
+ */
61
+ isValidPattern(pattern) {
62
+ if (Array.isArray(pattern)) {
63
+ return pattern.every(p => ignore.default.isPathValid(p));
64
+ }
65
+ if (this.patternType === ".*ignore") {
66
+ return ignore.default.isPathValid(pattern);
67
+ }
68
+ if (this.patternType === "minimatch") {
69
+ try {
70
+ minimatch.makeRe(pattern);
71
+ return true;
72
+ }
73
+ catch (error) {
74
+ return false;
75
+ }
76
+ }
77
+ throw new TypeError(`Unknown pattern type '${this.patternType}'.`);
78
+ }
79
+ }
80
+ //# sourceMappingURL=looker.js.map