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.
- package/README.md +37 -54
- package/bin/viewig +2 -2
- package/out/src/bin.d.ts +2 -0
- package/out/src/bin.js +3 -0
- package/out/src/browser/binds/index.d.ts +45 -0
- package/out/src/browser/binds/index.js +78 -0
- package/out/src/browser/binds/plugins/git.d.ts +3 -0
- package/out/src/browser/binds/plugins/git.js +24 -0
- package/out/src/browser/binds/plugins/npm.d.ts +11 -0
- package/out/src/browser/binds/plugins/npm.js +71 -0
- package/out/src/browser/binds/plugins/vsce.d.ts +9 -0
- package/out/src/browser/binds/plugins/vsce.js +21 -0
- package/out/src/browser/binds/plugins/yarn.d.ts +16 -0
- package/out/src/browser/binds/plugins/yarn.js +78 -0
- package/out/src/browser/binds/targets.d.ts +64 -0
- package/out/src/browser/binds/targets.js +56 -0
- package/out/src/browser/errors.d.ts +10 -0
- package/out/src/browser/errors.js +20 -0
- package/out/src/browser/fileinfo.d.ts +82 -0
- package/out/src/browser/fileinfo.js +78 -0
- package/{lib → out/src/browser}/index.d.ts +0 -1
- package/{lib → out/src}/browser/index.js +0 -1
- package/out/src/browser/lib.d.ts +141 -0
- package/out/src/browser/lib.js +126 -0
- package/out/src/browser/scanner.d.ts +103 -0
- package/out/src/browser/scanner.js +161 -0
- package/out/src/browser/sorting.d.ts +41 -0
- package/out/src/browser/sorting.js +133 -0
- package/out/src/browser/sourceinfo.d.ts +62 -0
- package/out/src/browser/sourceinfo.js +105 -0
- package/out/src/browser/styling.d.ts +90 -0
- package/out/src/browser/styling.js +153 -0
- package/out/src/cli.d.ts +92 -0
- package/out/src/cli.js +249 -0
- package/out/src/config.d.ts +141 -0
- package/out/src/config.js +257 -0
- package/{lib/browser → out/src}/index.d.ts +0 -1
- package/{lib → out/src}/index.js +0 -1
- package/{lib → out/src}/lib.d.ts +1 -2
- package/{lib → out/src}/lib.js +1 -2
- package/out/src/styling.d.ts +4 -0
- package/out/src/styling.js +40 -0
- package/package.json +20 -14
- package/lib/bin.d.ts +0 -3
- package/lib/bin.d.ts.map +0 -1
- package/lib/bin.js +0 -4
- package/lib/bin.js.map +0 -1
- package/lib/browser/binds/index.d.ts +0 -2
- package/lib/browser/binds/index.d.ts.map +0 -1
- package/lib/browser/binds/index.js +0 -2
- package/lib/browser/binds/index.js.map +0 -1
- package/lib/browser/binds/targets.d.ts +0 -38
- package/lib/browser/binds/targets.d.ts.map +0 -1
- package/lib/browser/binds/targets.js +0 -38
- package/lib/browser/binds/targets.js.map +0 -1
- package/lib/browser/binds.d.ts +0 -22
- package/lib/browser/binds.d.ts.map +0 -1
- package/lib/browser/binds.js +0 -14
- package/lib/browser/binds.js.map +0 -1
- package/lib/browser/fileinfo.d.ts +0 -35
- package/lib/browser/fileinfo.d.ts.map +0 -1
- package/lib/browser/fileinfo.js +0 -42
- package/lib/browser/fileinfo.js.map +0 -1
- package/lib/browser/index.d.ts.map +0 -1
- package/lib/browser/index.js.map +0 -1
- package/lib/browser/lib.d.ts +0 -122
- package/lib/browser/lib.d.ts.map +0 -1
- package/lib/browser/lib.js +0 -115
- package/lib/browser/lib.js.map +0 -1
- package/lib/browser/looker.d.ts +0 -60
- package/lib/browser/looker.d.ts.map +0 -1
- package/lib/browser/looker.js +0 -80
- package/lib/browser/looker.js.map +0 -1
- package/lib/browser/plugins/git.d.ts +0 -10
- package/lib/browser/plugins/git.d.ts.map +0 -1
- package/lib/browser/plugins/git.js +0 -23
- package/lib/browser/plugins/git.js.map +0 -1
- package/lib/browser/plugins/npm.d.ts +0 -12
- package/lib/browser/plugins/npm.d.ts.map +0 -1
- package/lib/browser/plugins/npm.js +0 -70
- package/lib/browser/plugins/npm.js.map +0 -1
- package/lib/browser/plugins/vsce.d.ts +0 -10
- package/lib/browser/plugins/vsce.d.ts.map +0 -1
- package/lib/browser/plugins/vsce.js +0 -23
- package/lib/browser/plugins/vsce.js.map +0 -1
- package/lib/browser/plugins/yarn.d.ts +0 -15
- package/lib/browser/plugins/yarn.d.ts.map +0 -1
- package/lib/browser/plugins/yarn.js +0 -46
- package/lib/browser/plugins/yarn.js.map +0 -1
- package/lib/browser/sorting.d.ts +0 -31
- package/lib/browser/sorting.d.ts.map +0 -1
- package/lib/browser/sorting.js +0 -121
- package/lib/browser/sorting.js.map +0 -1
- package/lib/browser/sourcepattern.d.ts +0 -25
- package/lib/browser/sourcepattern.d.ts.map +0 -1
- package/lib/browser/sourcepattern.js +0 -45
- package/lib/browser/sourcepattern.js.map +0 -1
- package/lib/browser/styling.d.ts +0 -16
- package/lib/browser/styling.d.ts.map +0 -1
- package/lib/browser/styling.js +0 -116
- package/lib/browser/styling.js.map +0 -1
- package/lib/browser/tools/index.d.ts +0 -3
- package/lib/browser/tools/index.d.ts.map +0 -1
- package/lib/browser/tools/index.js +0 -3
- package/lib/browser/tools/index.js.map +0 -1
- package/lib/browser/tools/sorting.d.ts +0 -31
- package/lib/browser/tools/sorting.d.ts.map +0 -1
- package/lib/browser/tools/sorting.js +0 -121
- package/lib/browser/tools/sorting.js.map +0 -1
- package/lib/browser/tools/styles.d.ts +0 -16
- package/lib/browser/tools/styles.d.ts.map +0 -1
- package/lib/browser/tools/styles.js +0 -116
- package/lib/browser/tools/styles.js.map +0 -1
- package/lib/cli.d.ts +0 -26
- package/lib/cli.d.ts.map +0 -1
- package/lib/cli.js +0 -134
- package/lib/cli.js.map +0 -1
- package/lib/config.d.ts +0 -80
- package/lib/config.d.ts.map +0 -1
- package/lib/config.js +0 -105
- package/lib/config.js.map +0 -1
- package/lib/git.d.ts +0 -13
- package/lib/git.d.ts.map +0 -1
- package/lib/git.js +0 -37
- package/lib/git.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/lib.d.ts.map +0 -1
- package/lib/lib.js.map +0 -1
- package/lib/plugins/git.d.ts +0 -9
- package/lib/plugins/git.js +0 -22
- package/lib/plugins/git.js.map +0 -1
- package/lib/plugins/npm.d.ts +0 -12
- package/lib/plugins/npm.js +0 -74
- package/lib/plugins/npm.js.map +0 -1
- package/lib/plugins/vsce.d.ts +0 -9
- package/lib/plugins/vsce.js +0 -22
- package/lib/plugins/vsce.js.map +0 -1
- package/lib/plugins/yarn.d.ts +0 -15
- package/lib/plugins/yarn.js +0 -50
- package/lib/plugins/yarn.js.map +0 -1
- package/lib/tools/index.d.ts +0 -3
- package/lib/tools/index.js +0 -4
- package/lib/tools/index.js.map +0 -1
- package/lib/tools/methods.d.ts +0 -16
- package/lib/tools/methods.js +0 -81
- package/lib/tools/methods.js.map +0 -1
- package/lib/tools/sorting.d.ts +0 -30
- package/lib/tools/sorting.js +0 -121
- package/lib/tools/sorting.js.map +0 -1
- package/lib/tools/styles.d.ts +0 -15
- package/lib/tools/styles.js +0 -123
- package/lib/tools/styles.js.map +0 -1
- package/lib/util/index.d.ts +0 -3
- package/lib/util/index.js +0 -4
- package/lib/util/index.js.map +0 -1
- package/lib/util/presets.d.ts +0 -24
- package/lib/util/presets.js +0 -129
- package/lib/util/presets.js.map +0 -1
- package/lib/util/sorting.d.ts +0 -30
- package/lib/util/sorting.js +0 -121
- package/lib/util/sorting.js.map +0 -1
- package/lib/util/styles.d.ts +0 -8
- package/lib/util/styles.js +0 -52
- 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
|
|
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
|
|
13
|
-
- **Plugins.** view-ignored allows you to add new [targets](#targets) programmatically. Command
|
|
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
|
|
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
|
-
#
|
|
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
|
-
|
|
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
|
|
43
|
-
viewig config set style=
|
|
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/
|
|
60
|
+
import * as vign from "view-ignored/out/src/browser"; // for web environment apps
|
|
51
61
|
|
|
52
|
-
const fileInfoList = vign.scanProject("git");
|
|
53
|
-
const
|
|
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
|
-
|
|
70
|
+
superCodeEditor.explorer.colorFile(fileInfo.filePath, "gray");
|
|
79
71
|
}
|
|
80
72
|
```
|
|
81
73
|
|
|
82
|
-
#### Sorting
|
|
74
|
+
#### Sorting
|
|
83
75
|
|
|
84
76
|
```js
|
|
85
|
-
const
|
|
86
|
-
const
|
|
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
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const lookedSorted =
|
|
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
|
-
|
|
116
|
-
|
|
98
|
+
- `jsr` *planned*
|
|
99
|
+
- `deno` *planned*
|
package/bin/viewig
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
import "../
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
import "../out/src/bin.js"
|
package/out/src/bin.d.ts
ADDED
package/out/src/bin.js
ADDED
|
@@ -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,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
|
+
}
|