view-ignored 0.1.0 → 0.2.0

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 (165) hide show
  1. package/README.md +37 -54
  2. package/bin/viewig +2 -2
  3. package/out/src/bin.d.ts +2 -0
  4. package/out/src/bin.js +3 -0
  5. package/out/src/browser/binds/index.d.ts +45 -0
  6. package/out/src/browser/binds/index.js +78 -0
  7. package/out/src/browser/binds/plugins/git.d.ts +3 -0
  8. package/out/src/browser/binds/plugins/git.js +24 -0
  9. package/out/src/browser/binds/plugins/npm.d.ts +11 -0
  10. package/out/src/browser/binds/plugins/npm.js +71 -0
  11. package/out/src/browser/binds/plugins/vsce.d.ts +9 -0
  12. package/out/src/browser/binds/plugins/vsce.js +21 -0
  13. package/out/src/browser/binds/plugins/yarn.d.ts +16 -0
  14. package/out/src/browser/binds/plugins/yarn.js +78 -0
  15. package/out/src/browser/binds/targets.d.ts +64 -0
  16. package/out/src/browser/binds/targets.js +56 -0
  17. package/out/src/browser/errors.d.ts +10 -0
  18. package/out/src/browser/errors.js +20 -0
  19. package/out/src/browser/fileinfo.d.ts +82 -0
  20. package/out/src/browser/fileinfo.js +78 -0
  21. package/{lib → out/src/browser}/index.d.ts +0 -1
  22. package/{lib → out/src}/browser/index.js +0 -1
  23. package/out/src/browser/lib.d.ts +141 -0
  24. package/out/src/browser/lib.js +126 -0
  25. package/out/src/browser/scanner.d.ts +103 -0
  26. package/out/src/browser/scanner.js +161 -0
  27. package/out/src/browser/sorting.d.ts +41 -0
  28. package/out/src/browser/sorting.js +133 -0
  29. package/out/src/browser/sourceinfo.d.ts +62 -0
  30. package/out/src/browser/sourceinfo.js +105 -0
  31. package/out/src/browser/styling.d.ts +90 -0
  32. package/out/src/browser/styling.js +153 -0
  33. package/out/src/cli.d.ts +92 -0
  34. package/out/src/cli.js +249 -0
  35. package/out/src/config.d.ts +141 -0
  36. package/out/src/config.js +257 -0
  37. package/{lib/browser → out/src}/index.d.ts +0 -1
  38. package/{lib → out/src}/index.js +0 -1
  39. package/{lib → out/src}/lib.d.ts +1 -2
  40. package/{lib → out/src}/lib.js +1 -2
  41. package/out/src/styling.d.ts +4 -0
  42. package/out/src/styling.js +40 -0
  43. package/package.json +20 -14
  44. package/lib/bin.d.ts +0 -3
  45. package/lib/bin.d.ts.map +0 -1
  46. package/lib/bin.js +0 -4
  47. package/lib/bin.js.map +0 -1
  48. package/lib/browser/binds/index.d.ts +0 -2
  49. package/lib/browser/binds/index.d.ts.map +0 -1
  50. package/lib/browser/binds/index.js +0 -2
  51. package/lib/browser/binds/index.js.map +0 -1
  52. package/lib/browser/binds/targets.d.ts +0 -38
  53. package/lib/browser/binds/targets.d.ts.map +0 -1
  54. package/lib/browser/binds/targets.js +0 -38
  55. package/lib/browser/binds/targets.js.map +0 -1
  56. package/lib/browser/binds.d.ts +0 -22
  57. package/lib/browser/binds.d.ts.map +0 -1
  58. package/lib/browser/binds.js +0 -14
  59. package/lib/browser/binds.js.map +0 -1
  60. package/lib/browser/fileinfo.d.ts +0 -35
  61. package/lib/browser/fileinfo.d.ts.map +0 -1
  62. package/lib/browser/fileinfo.js +0 -42
  63. package/lib/browser/fileinfo.js.map +0 -1
  64. package/lib/browser/index.d.ts.map +0 -1
  65. package/lib/browser/index.js.map +0 -1
  66. package/lib/browser/lib.d.ts +0 -122
  67. package/lib/browser/lib.d.ts.map +0 -1
  68. package/lib/browser/lib.js +0 -115
  69. package/lib/browser/lib.js.map +0 -1
  70. package/lib/browser/looker.d.ts +0 -60
  71. package/lib/browser/looker.d.ts.map +0 -1
  72. package/lib/browser/looker.js +0 -80
  73. package/lib/browser/looker.js.map +0 -1
  74. package/lib/browser/plugins/git.d.ts +0 -10
  75. package/lib/browser/plugins/git.d.ts.map +0 -1
  76. package/lib/browser/plugins/git.js +0 -23
  77. package/lib/browser/plugins/git.js.map +0 -1
  78. package/lib/browser/plugins/npm.d.ts +0 -12
  79. package/lib/browser/plugins/npm.d.ts.map +0 -1
  80. package/lib/browser/plugins/npm.js +0 -70
  81. package/lib/browser/plugins/npm.js.map +0 -1
  82. package/lib/browser/plugins/vsce.d.ts +0 -10
  83. package/lib/browser/plugins/vsce.d.ts.map +0 -1
  84. package/lib/browser/plugins/vsce.js +0 -23
  85. package/lib/browser/plugins/vsce.js.map +0 -1
  86. package/lib/browser/plugins/yarn.d.ts +0 -15
  87. package/lib/browser/plugins/yarn.d.ts.map +0 -1
  88. package/lib/browser/plugins/yarn.js +0 -46
  89. package/lib/browser/plugins/yarn.js.map +0 -1
  90. package/lib/browser/sorting.d.ts +0 -31
  91. package/lib/browser/sorting.d.ts.map +0 -1
  92. package/lib/browser/sorting.js +0 -121
  93. package/lib/browser/sorting.js.map +0 -1
  94. package/lib/browser/sourcepattern.d.ts +0 -25
  95. package/lib/browser/sourcepattern.d.ts.map +0 -1
  96. package/lib/browser/sourcepattern.js +0 -45
  97. package/lib/browser/sourcepattern.js.map +0 -1
  98. package/lib/browser/styling.d.ts +0 -16
  99. package/lib/browser/styling.d.ts.map +0 -1
  100. package/lib/browser/styling.js +0 -116
  101. package/lib/browser/styling.js.map +0 -1
  102. package/lib/browser/tools/index.d.ts +0 -3
  103. package/lib/browser/tools/index.d.ts.map +0 -1
  104. package/lib/browser/tools/index.js +0 -3
  105. package/lib/browser/tools/index.js.map +0 -1
  106. package/lib/browser/tools/sorting.d.ts +0 -31
  107. package/lib/browser/tools/sorting.d.ts.map +0 -1
  108. package/lib/browser/tools/sorting.js +0 -121
  109. package/lib/browser/tools/sorting.js.map +0 -1
  110. package/lib/browser/tools/styles.d.ts +0 -16
  111. package/lib/browser/tools/styles.d.ts.map +0 -1
  112. package/lib/browser/tools/styles.js +0 -116
  113. package/lib/browser/tools/styles.js.map +0 -1
  114. package/lib/cli.d.ts +0 -26
  115. package/lib/cli.d.ts.map +0 -1
  116. package/lib/cli.js +0 -134
  117. package/lib/cli.js.map +0 -1
  118. package/lib/config.d.ts +0 -80
  119. package/lib/config.d.ts.map +0 -1
  120. package/lib/config.js +0 -105
  121. package/lib/config.js.map +0 -1
  122. package/lib/git.d.ts +0 -13
  123. package/lib/git.d.ts.map +0 -1
  124. package/lib/git.js +0 -37
  125. package/lib/git.js.map +0 -1
  126. package/lib/index.d.ts.map +0 -1
  127. package/lib/index.js.map +0 -1
  128. package/lib/lib.d.ts.map +0 -1
  129. package/lib/lib.js.map +0 -1
  130. package/lib/plugins/git.d.ts +0 -9
  131. package/lib/plugins/git.js +0 -22
  132. package/lib/plugins/git.js.map +0 -1
  133. package/lib/plugins/npm.d.ts +0 -12
  134. package/lib/plugins/npm.js +0 -74
  135. package/lib/plugins/npm.js.map +0 -1
  136. package/lib/plugins/vsce.d.ts +0 -9
  137. package/lib/plugins/vsce.js +0 -22
  138. package/lib/plugins/vsce.js.map +0 -1
  139. package/lib/plugins/yarn.d.ts +0 -15
  140. package/lib/plugins/yarn.js +0 -50
  141. package/lib/plugins/yarn.js.map +0 -1
  142. package/lib/tools/index.d.ts +0 -3
  143. package/lib/tools/index.js +0 -4
  144. package/lib/tools/index.js.map +0 -1
  145. package/lib/tools/methods.d.ts +0 -16
  146. package/lib/tools/methods.js +0 -81
  147. package/lib/tools/methods.js.map +0 -1
  148. package/lib/tools/sorting.d.ts +0 -30
  149. package/lib/tools/sorting.js +0 -121
  150. package/lib/tools/sorting.js.map +0 -1
  151. package/lib/tools/styles.d.ts +0 -15
  152. package/lib/tools/styles.js +0 -123
  153. package/lib/tools/styles.js.map +0 -1
  154. package/lib/util/index.d.ts +0 -3
  155. package/lib/util/index.js +0 -4
  156. package/lib/util/index.js.map +0 -1
  157. package/lib/util/presets.d.ts +0 -24
  158. package/lib/util/presets.js +0 -129
  159. package/lib/util/presets.js.map +0 -1
  160. package/lib/util/sorting.d.ts +0 -30
  161. package/lib/util/sorting.js +0 -121
  162. package/lib/util/sorting.js.map +0 -1
  163. package/lib/util/styles.d.ts +0 -8
  164. package/lib/util/styles.js +0 -52
  165. package/lib/util/styles.js.map +0 -1
package/README.md CHANGED
@@ -7,10 +7,10 @@ Retrieve list of files ignored/included by Git, NPM, Yarn and VSC Extension.
7
7
 
8
8
  ## Highlights
9
9
 
10
- - **Multi-target.** Get list of included files, using configuration files reader, not command line wrapper.
10
+ - **Multi-target.** Get list of included files, using configuration files reader, not command-line wrapper.
11
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.** view-ignored allows you to add new [targets](#targets) programmatically. Command line interface does NOT support plugins.
12
+ - **Command-line.** Supports no-color and multiple output styles, including [nerd fonts](https://github.com/ryanoasis/nerd-fonts).
13
+ - **Plugins.** view-ignored allows you to add new [targets](#targets) programmatically. Command-line interface supports plugins throught `--plugin` option.
14
14
 
15
15
  ## Install
16
16
 
@@ -20,7 +20,7 @@ npm i view-ignored
20
20
 
21
21
  ## Usage
22
22
 
23
- ### Command line
23
+ ### Command-line
24
24
 
25
25
  ```bash
26
26
  # get started
@@ -31,86 +31,69 @@ view-ignored --help
31
31
  # scan: git (default) and npm
32
32
  viewig scan .
33
33
  viewig scan . --target=npm
34
+ viewig scan . --parsable
34
35
 
35
- # config: print all
36
+ # 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
41
+
42
+ # config: print configuration entries
36
43
  viewig config get
37
- # config: print with defaults
38
- viewig config get --safe
44
+ viewig config get --real
39
45
  # config: set npm as default target and scan for npm
40
46
  viewig config set target=npm
41
47
  viewig scan .
42
- # config: always use nerd font
43
- viewig config set style=treeNerd
48
+ # config: always use nerdfonts
49
+ viewig config set style=tree
50
+ # config: always use nerdfonts
51
+ viewig config set decor=nerdfonts
52
+ # config: always use plugins
53
+ viewig config set plugins=typescript-viewig,eslint-vign-plugin
44
54
  ```
45
55
 
46
56
  ### Programmatically
47
57
 
48
58
  ```js
49
59
  import * as vign from "view-ignored";
50
- import * as vign from "view-ignored/lib/browser"; // for web environment apps
60
+ import * as vign from "view-ignored/out/src/browser"; // for web environment apps
51
61
 
52
- const fileInfoList = vign.scanProject("git");
53
- const fileInfoList = vign.scanPaths(pathList, "git");
54
- const fileInfo = vign.scanFile(pathToFile, "git");
62
+ const fileInfoList = await vign.scanProject("git");
63
+ const fileInfo = await vign.scanFile("./path/to/file", "git");
55
64
 
56
65
  // options available
57
- const fileInfoList = vign.scanProject("git", { cwd, ... });
58
-
59
- // custom
60
- /**@type {vign.ScanMethod}*/
61
- export const method = function (data) {
62
- const { looker, sourceFile: source } = data
63
- if (!looker.isValidPattern(source.content)) {
64
- return false
65
- }
66
- looker.add(source.content)
67
- return true
68
- }
69
-
70
- /**@type {vign.Source[]}*/
71
- export const sources = [
72
- { sources: new SourcePattern("**/.gitignore"), patternType: ".*ignore", method, addPatterns: addPatternsExclude },
73
- ]
74
- vign.scanProject(sources)
66
+ const fileInfoList = await vign.scanProject("git", { cwd, ... });
75
67
 
76
68
  // use results
77
69
  if (fileInfo.ignored) {
78
- vscode.explorer.colorFile(fileInfo.filePath, "gray")
70
+ superCodeEditor.explorer.colorFile(fileInfo.filePath, "gray");
79
71
  }
80
72
  ```
81
73
 
82
- #### Sorting:
74
+ #### Sorting
83
75
 
84
76
  ```js
85
- const fileInfoList = vign.scanProject("npm");
86
- const sorter = vign.Sorting.Sorters.firstFolders;
87
- fileInfoList.map(String).sort(sorter);
77
+ const sorter = vign.Sorting.firstFolders;
78
+ const fileInfoList = await vign.scanProject("npm");
79
+ const fileInfoSorted = fileInfoList.map(String).sort(sorter);
88
80
  ```
89
81
 
90
82
  ```js
91
- const fileInfoList = vign.scanProject("npm")
92
- const sorter = Sorting.Sorters[flags.sort]
93
- const cacheEditDates = new Map<FileInfo, Date>()
94
- for (const look of looked) {
95
- cacheEditDates.set(look, fs.statSync(look.filePath).mtime)
96
- }
97
- const lookedSorted = looked.sort((a, b) => sorter(
98
- a.toString(), b.toString(),
99
- cacheEditDates.get(a)!, cacheEditDates.get(b)!
100
- ))
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));
101
90
  ```
102
91
 
103
92
  ### Targets
104
93
 
105
94
  - `git`
106
- - Test command: `git ls-tree -r <git-branch-name> --name-only`
107
- - Sources walkthrough: '.gitignore' and git config `core.excludesFile`.
108
- - `core.excludesFile` does not work at this moment.
109
95
  - `npm` (can be usable for PNPM and Bun)
110
- - Test command: `npm pack --dry-run`
111
- - Sources walkthrough: 'package.json'>"files" otherwise '.npmignore' otherwise '.gitignore'.
112
96
  - `yarn`
113
- - Sources walkthrough: 'package.json'>"files" otherwise '.yarnignore' otherwise '.npmignore' otherwise '.gitignore'.
114
97
  - `vsce`
115
- - Test command: `vsce ls`
116
- - Sources walkthrough: '.vscodeignore'.
98
+ - `jsr` *planned*
99
+ - `deno` *planned*
package/bin/viewig CHANGED
@@ -1,2 +1,2 @@
1
- #! /usr/bin/env node
2
- import "../lib/bin.js"
1
+ #! /usr/bin/env node
2
+ import "../out/src/bin.js"
@@ -0,0 +1,2 @@
1
+ #! /usr/bin/env node
2
+ export {};
package/out/src/bin.js ADDED
@@ -0,0 +1,3 @@
1
+ #! /usr/bin/env node
2
+ import { programInit } from "./cli.js";
3
+ programInit();
@@ -0,0 +1,45 @@
1
+ import { TargetBind } from "./targets.js";
2
+ export * from "./targets.js";
3
+ /**
4
+ * The result of loading.
5
+ */
6
+ export interface PluginLoaded {
7
+ moduleName: string;
8
+ isLoaded: boolean;
9
+ exports: unknown;
10
+ }
11
+ /**
12
+ * If a plugin wants to change something, it must export it as default.
13
+ */
14
+ export interface PluginExport {
15
+ viewignored: {
16
+ addTargets: TargetBind[];
17
+ };
18
+ }
19
+ /**
20
+ * Checks if the value is the {@link PluginExport}.
21
+ */
22
+ export declare function isPluginExport(value: unknown): value is PluginExport;
23
+ /**
24
+ * Imports the plugin's exported data.
25
+ */
26
+ export declare function importPlugin(exportData: PluginExport): void;
27
+ /**
28
+ * No rejects.
29
+ * @param moduleName Plugin name.
30
+ * @returns Import result for the module.
31
+ */
32
+ export declare function loadPlugin(moduleName: string): Promise<PluginLoaded>;
33
+ /**
34
+ * Loads plugins one by one using {@link loadPlugin}.
35
+ * @param moduleNameList The list of plugins.
36
+ */
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")>;
42
+ /**
43
+ * Built-in plugins loading queue.
44
+ */
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")>]>;
@@ -0,0 +1,78 @@
1
+ import { isTargetBind, targetSet } from "./targets.js";
2
+ import { loadPlugin as load } from "load-plugin";
3
+ export * from "./targets.js";
4
+ /**
5
+ * Checks if the value is the {@link PluginExport}.
6
+ */
7
+ export function isPluginExport(value) {
8
+ if (value?.constructor !== Object) {
9
+ return false;
10
+ }
11
+ const vign = value.viewignored;
12
+ return (vign?.constructor === Object)
13
+ && 'addTargets' in vign && Array.isArray(vign.addTargets) && vign.addTargets.every(isTargetBind);
14
+ }
15
+ /**
16
+ * Imports the plugin's exported data.
17
+ */
18
+ export function importPlugin(exportData) {
19
+ const { addTargets } = exportData.viewignored;
20
+ for (const targetBind of addTargets) {
21
+ targetSet(targetBind);
22
+ }
23
+ }
24
+ /**
25
+ * No rejects.
26
+ * @param moduleName Plugin name.
27
+ * @returns Import result for the module.
28
+ */
29
+ export function loadPlugin(moduleName) {
30
+ 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
+ }
50
+ catch (reason) {
51
+ const fail = { moduleName, isLoaded: false, exports: reason };
52
+ return Promise.resolve(fail);
53
+ }
54
+ }
55
+ /**
56
+ * Loads plugins one by one using {@link loadPlugin}.
57
+ * @param moduleNameList The list of plugins.
58
+ */
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;
66
+ }
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
+ * Built-in plugins loading queue.
77
+ */
78
+ export const BuiltIns = Promise.allSettled([BuiltInGit, BuiltInVsce, BuiltInNpm, BuiltInYarn]);
@@ -0,0 +1,3 @@
1
+ import { Plugins } from "../../index.js";
2
+ declare const _default: Plugins.PluginExport;
3
+ export default _default;
@@ -0,0 +1,24 @@
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/**"
10
+ ];
11
+ const scan = function (fileInfo) {
12
+ const { scanner, content } = fileInfo;
13
+ const pat = content?.toString();
14
+ if (!scanner.patternIsValid(pat)) {
15
+ return false;
16
+ }
17
+ scanner.add(pat);
18
+ return true;
19
+ };
20
+ const methodology = [
21
+ { pattern: "**/.gitignore", matcher: "gitignore", scan, matcherExclude },
22
+ ];
23
+ const bind = { id, name, methodology, testCommand };
24
+ export default { viewignored: { addTargets: [bind] } };
@@ -0,0 +1,11 @@
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";
5
+ export declare const matcherExclude: string[];
6
+ 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;
@@ -0,0 +1,71 @@
1
+ import getValue from "get-value";
2
+ export const id = "npm";
3
+ export const name = "NPM";
4
+ export const testCommand = "npm pack --dry-run";
5
+ export const matcherExclude = [
6
+ 'node_modules/**',
7
+ '.*.swp',
8
+ '._*',
9
+ '.DS_Store/**',
10
+ '.git/**',
11
+ '.gitignore',
12
+ '.hg/**',
13
+ '.npmignore',
14
+ '.npmrc',
15
+ '.lock-wscript',
16
+ '.svn/**',
17
+ '.wafpickle-*',
18
+ 'config.gypi',
19
+ 'CVS/**',
20
+ 'npm-debug.log',
21
+ ];
22
+ export const matcherInclude = [
23
+ '/bin/',
24
+ '/package.json',
25
+ '/README',
26
+ '/README.*',
27
+ '/LICENSE',
28
+ '/LICENSE.*',
29
+ '/LICENCE',
30
+ '/LICENCE.*',
31
+ ];
32
+ export const scanGit = function (data) {
33
+ const { scanner, content } = data;
34
+ const pat = content?.toString();
35
+ if (!scanner.patternIsValid(pat)) {
36
+ return false;
37
+ }
38
+ scanner.add(pat);
39
+ return true;
40
+ };
41
+ export const scanPackageJsonFiles = function (data) {
42
+ const { scanner, content } = data;
43
+ let parsed;
44
+ try {
45
+ const pat = content?.toString();
46
+ if (!pat) {
47
+ return false;
48
+ }
49
+ const json = JSON.parse(pat);
50
+ if (json?.constructor !== Object) {
51
+ return false;
52
+ }
53
+ parsed = json;
54
+ }
55
+ catch {
56
+ return false;
57
+ }
58
+ const propVal = getValue(parsed, "files");
59
+ if (!scanner.patternIsValid(propVal)) {
60
+ return false;
61
+ }
62
+ scanner.add(propVal);
63
+ return true;
64
+ };
65
+ export const methodology = [
66
+ { pattern: ["**/package.json"], matcherNegated: true, matcher: "gitignore", scan: scanPackageJsonFiles, matcherInclude, matcherExclude },
67
+ { pattern: ["**/.npmignore"], matcher: "gitignore", scan: scanGit, matcherInclude, matcherExclude },
68
+ { pattern: ["**/.gitignore"], matcher: "gitignore", scan: scanGit, matcherInclude, matcherExclude },
69
+ ];
70
+ const bind = { id, name, methodology, testCommand };
71
+ export default { viewignored: { addTargets: [bind] } };
@@ -0,0 +1,9 @@
1
+ import { Plugins, ScanMethod, Methodology } from "../../index.js";
2
+ export declare const id = "vsce";
3
+ export declare const name = "VSC Extension";
4
+ export declare const testCommand = "vsce ls";
5
+ export declare const matcherExclude: string[];
6
+ export declare const scan: ScanMethod;
7
+ export declare const methodology: Methodology[];
8
+ declare const _default: Plugins.PluginExport;
9
+ export default _default;
@@ -0,0 +1,21 @@
1
+ export const id = "vsce";
2
+ export const name = "VSC Extension";
3
+ export const testCommand = "vsce ls";
4
+ export const matcherExclude = [
5
+ ".git/**",
6
+ ".DS_Store/**"
7
+ ];
8
+ export const scan = function (data) {
9
+ const { scanner, content } = data;
10
+ const pat = content?.toString();
11
+ if (!scanner.patternIsValid(pat)) {
12
+ return false;
13
+ }
14
+ scanner.add(pat);
15
+ return true;
16
+ };
17
+ export const methodology = [
18
+ { pattern: "**/.vscodeignore", matcher: "minimatch", scan, matcherExclude },
19
+ ];
20
+ const bind = { id, name, methodology, testCommand };
21
+ export default { viewignored: { addTargets: [bind] } };
@@ -0,0 +1,16 @@
1
+ import { Plugins, Methodology, ScanMethod } from "../../index.js";
2
+ export declare const id = "yarn";
3
+ export declare const name = "Yarn";
4
+ /**
5
+ * [!WARNING] All patterns copied from npm plugin, so they should be verified with yarn docs.
6
+ */
7
+ export declare const matcherExclude: string[];
8
+ /**
9
+ * [!WARNING] All patterns copied from npm plugin, so they should be verified with yarn docs.
10
+ */
11
+ export declare const matcherInclude: string[];
12
+ export declare const scanGit: ScanMethod;
13
+ export declare const scanPackageJsonFiles: ScanMethod;
14
+ export declare const methodology: Methodology[];
15
+ declare const _default: Plugins.PluginExport;
16
+ export default _default;
@@ -0,0 +1,78 @@
1
+ import getValue from "get-value";
2
+ export const id = "yarn";
3
+ export const name = "Yarn";
4
+ /**
5
+ * [!WARNING] All patterns copied from npm plugin, so they should be verified with yarn docs.
6
+ */
7
+ export const matcherExclude = [
8
+ 'node_modules/**',
9
+ '.*.swp',
10
+ '._*',
11
+ '.DS_Store/**',
12
+ '.git/**',
13
+ '.gitignore',
14
+ '.hg/**',
15
+ '.yarnignore',
16
+ '.npmignore',
17
+ '.npmrc',
18
+ '.lock-wscript',
19
+ '.svn/**',
20
+ '.wafpickle-*',
21
+ 'config.gypi',
22
+ 'CVS/**',
23
+ 'npm-debug.log',
24
+ ];
25
+ /**
26
+ * [!WARNING] All patterns copied from npm plugin, so they should be verified with yarn docs.
27
+ */
28
+ export const matcherInclude = [
29
+ '/bin/',
30
+ '/package.json',
31
+ '/README',
32
+ '/README.*',
33
+ '/LICENSE',
34
+ '/LICENSE.*',
35
+ '/LICENCE',
36
+ '/LICENCE.*',
37
+ ];
38
+ export const scanGit = function (data) {
39
+ const { scanner, content } = data;
40
+ const pat = content?.toString();
41
+ if (!scanner.patternIsValid(pat)) {
42
+ return false;
43
+ }
44
+ scanner.add(pat);
45
+ return true;
46
+ };
47
+ export const scanPackageJsonFiles = function (data) {
48
+ const { scanner, content } = data;
49
+ let parsed;
50
+ try {
51
+ const pat = content?.toString();
52
+ if (!pat) {
53
+ return false;
54
+ }
55
+ const json = JSON.parse(pat);
56
+ if (json?.constructor !== Object) {
57
+ return false;
58
+ }
59
+ parsed = json;
60
+ }
61
+ catch {
62
+ return false;
63
+ }
64
+ const propVal = getValue(parsed, "files");
65
+ if (!scanner.patternIsValid(propVal)) {
66
+ return false;
67
+ }
68
+ scanner.add(propVal);
69
+ return true;
70
+ };
71
+ export const methodology = [
72
+ { pattern: "**/package.json", matcherNegated: true, matcher: "gitignore", scan: scanPackageJsonFiles, matcherInclude, matcherExclude },
73
+ { pattern: "**/.yarnignore", matcher: "gitignore", scan: scanGit, matcherInclude, matcherExclude },
74
+ { pattern: "**/.npmignore", matcher: "gitignore", scan: scanGit, matcherInclude, matcherExclude },
75
+ { pattern: "**/.gitignore", matcher: "gitignore", scan: scanGit, matcherInclude, matcherExclude },
76
+ ];
77
+ const bind = { id, name, methodology };
78
+ export default { viewignored: { addTargets: [bind] } };
@@ -0,0 +1,64 @@
1
+ import { ScanFolderOptions, Methodology } from "../lib.js";
2
+ import { DecorConditionOptions } from "../styling.js";
3
+ /**
4
+ * Should satisfy RegExp: `/^[-a-zA-Z0-9]+$/`.
5
+ */
6
+ export type TargetId = string;
7
+ /**
8
+ * @param value Target's id. Simple name.
9
+ * @returns `true`, if the id is available for binding.
10
+ */
11
+ export declare function isTargetId(value: unknown): value is TargetId;
12
+ /**
13
+ * The bind which allows use predefined options for scan functions.
14
+ * @see {@link scanProject}
15
+ */
16
+ export interface TargetBind {
17
+ /**
18
+ * Simple name.
19
+ * @see {@link isTargetId}
20
+ */
21
+ id: TargetId;
22
+ /**
23
+ * Readable name.
24
+ */
25
+ name: string | DecorConditionOptions;
26
+ /**
27
+ * The walkthrough. Files including patterns.
28
+ */
29
+ methodology: Methodology[];
30
+ /**
31
+ * Folder deep scanning options for the target.
32
+ */
33
+ scanOptions?: ScanFolderOptions;
34
+ /**
35
+ * Test command.
36
+ * @example
37
+ * "npm pack --dry run"
38
+ * "vsce ls"
39
+ */
40
+ testCommand?: string;
41
+ }
42
+ /**
43
+ * Checks if the value is the {@link TargetBind}.
44
+ */
45
+ export declare function isTargetBind(value: unknown): value is TargetBind;
46
+ /**
47
+ * Allows to create targets for view-ignored scan* functions.
48
+ * @example
49
+ * scanProject("abc") // error
50
+ * Bindings.targetSet("abc", {...})
51
+ * scanProject("abc") // ok
52
+ */
53
+ export declare function targetSet(bind: TargetBind): void;
54
+ /**
55
+ * Get all target ids.
56
+ * @example
57
+ * ["git", "npm", "vsce", ...]
58
+ */
59
+ export declare function targetList(): string[];
60
+ /**
61
+ * Get target bind by target id.
62
+ * @param id Target id.
63
+ */
64
+ export declare function targetGet(id: TargetId): TargetBind | undefined;
@@ -0,0 +1,56 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
+ import { isMethodology } from "../lib.js";
3
+ /**
4
+ * @param value Target's id. Simple name.
5
+ * @returns `true`, if the id is available for binding.
6
+ */
7
+ export function isTargetId(value) {
8
+ return typeof value === "string" && value.match(/^[-a-zA-Z0-9]+$/) != null;
9
+ }
10
+ /**
11
+ * Checks if the value is the {@link TargetBind}.
12
+ */
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");
23
+ }
24
+ /**
25
+ * The container for binds: id=bind.
26
+ */
27
+ const targetBindMap = new Map();
28
+ /**
29
+ * Allows to create targets for view-ignored scan* functions.
30
+ * @example
31
+ * scanProject("abc") // error
32
+ * Bindings.targetSet("abc", {...})
33
+ * scanProject("abc") // ok
34
+ */
35
+ export function targetSet(bind) {
36
+ if (!isTargetId(bind.id)) {
37
+ throw TypeError(`view-ignored can not bind target with id '${bind.id}'`);
38
+ }
39
+ targetBindMap.set(bind.id, bind);
40
+ }
41
+ /**
42
+ * Get all target ids.
43
+ * @example
44
+ * ["git", "npm", "vsce", ...]
45
+ */
46
+ export function targetList() {
47
+ const list = Array.from(targetBindMap.keys());
48
+ return list;
49
+ }
50
+ /**
51
+ * Get target bind by target id.
52
+ * @param id Target id.
53
+ */
54
+ export function targetGet(id) {
55
+ return targetBindMap.get(id);
56
+ }
@@ -0,0 +1,10 @@
1
+ import { Methodology } from "../lib.js";
2
+ export declare class SomeError extends Error {
3
+ }
4
+ export declare class ErrorNoSources extends SomeError {
5
+ constructor(sources?: (readonly Methodology[]) | string);
6
+ static walk(sources?: (readonly Methodology[]) | string): string;
7
+ }
8
+ export declare class ErrorTargetNotBound extends SomeError {
9
+ constructor(targetId: unknown);
10
+ }
@@ -0,0 +1,20 @@
1
+ import { targetGet } from "./binds/targets.js";
2
+ export class SomeError extends Error {
3
+ }
4
+ export class ErrorNoSources extends SomeError {
5
+ constructor(sources) {
6
+ super("No available sources for methodology: " + ErrorNoSources.walk(sources));
7
+ }
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
+ }
15
+ }
16
+ export class ErrorTargetNotBound extends SomeError {
17
+ constructor(targetId) {
18
+ super(`The target has no bound: '${targetId}'.`);
19
+ }
20
+ }