view-ignored 0.5.2 → 0.6.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 +98 -41
- package/out/browser.d.ts +3 -0
- package/out/browser.js +2 -0
- package/out/browser_scan.d.ts +20 -0
- package/out/browser_scan.js +54 -0
- package/out/browser_stream.d.ts +12 -0
- package/out/browser_stream.js +46 -0
- package/out/getDepth.d.ts +4 -0
- package/out/getDepth.js +21 -0
- package/out/index.d.ts +3 -1
- package/out/index.js +2 -1
- package/out/normalizeCwd.d.ts +1 -0
- package/out/normalizeCwd.js +4 -0
- package/out/opendir.d.ts +3 -0
- package/out/opendir.js +18 -0
- package/out/patterns/extractor.d.ts +80 -0
- package/out/patterns/extractor.js +1 -0
- package/out/patterns/gitignore.d.ts +9 -3
- package/out/patterns/gitignore.js +13 -20
- package/out/patterns/ignores.d.ts +19 -0
- package/out/patterns/ignores.js +1 -0
- package/out/patterns/index.d.ts +13 -4
- package/out/patterns/index.js +13 -4
- package/out/patterns/jsrjson.d.ts +16 -4
- package/out/patterns/jsrjson.js +30 -13
- package/out/patterns/matcherContext.d.ts +71 -0
- package/out/patterns/matcherContext.js +1 -0
- package/out/patterns/matcherContextPatch.d.ts +16 -0
- package/out/patterns/matcherContextPatch.js +151 -0
- package/out/patterns/matcherStream.d.ts +64 -0
- package/out/patterns/matcherStream.js +9 -0
- package/out/patterns/packagejson.d.ts +9 -3
- package/out/patterns/packagejson.js +18 -7
- package/out/patterns/pattern.d.ts +44 -0
- package/out/patterns/pattern.js +21 -0
- package/out/patterns/patternMatcher.d.ts +23 -0
- package/out/patterns/patternMatcher.js +1 -0
- package/out/patterns/resolveSources.d.ts +34 -0
- package/out/patterns/resolveSources.js +142 -0
- package/out/patterns/signedPattern.d.ts +117 -0
- package/out/patterns/signedPattern.js +110 -0
- package/out/patterns/source.d.ts +57 -0
- package/out/patterns/source.js +20 -0
- package/out/patterns/stringCompile.d.ts +9 -0
- package/out/patterns/stringCompile.js +28 -0
- package/out/scan.d.ts +5 -37
- package/out/scan.js +8 -101
- package/out/stream.d.ts +9 -0
- package/out/stream.js +12 -0
- package/out/targets/git.d.ts +4 -1
- package/out/targets/git.js +26 -17
- package/out/targets/index.d.ts +6 -6
- package/out/targets/index.js +6 -6
- package/out/targets/jsr.d.ts +4 -1
- package/out/targets/jsr.js +34 -20
- package/out/targets/npm.d.ts +4 -1
- package/out/targets/npm.js +47 -40
- package/out/targets/target.d.ts +17 -3
- package/out/targets/vsce.d.ts +4 -1
- package/out/targets/vsce.js +30 -19
- package/out/targets/yarn.d.ts +4 -1
- package/out/targets/yarn.js +53 -43
- package/out/types.d.ts +116 -0
- package/out/types.js +1 -0
- package/out/walk.d.ts +11 -2
- package/out/walk.js +101 -13
- package/package.json +113 -78
- package/out/patterns/matcher.d.ts +0 -114
- package/out/patterns/matcher.js +0 -137
package/README.md
CHANGED
|
@@ -10,19 +10,19 @@ by Git, NPM, Yarn, JSR, VSCE or other tools.
|
|
|
10
10
|
|
|
11
11
|
## Requirements
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
- Node.js 20 or later for production type definitions
|
|
15
|
-
- Node.js 22 or later for development type definitions
|
|
13
|
+
Node.js 18 or later
|
|
16
14
|
|
|
17
15
|
## Highlights
|
|
18
16
|
|
|
19
|
-
- **
|
|
17
|
+
- **Reader.** Get a list of included files using configuration file
|
|
20
18
|
readers, not command-line wrappers.
|
|
21
19
|
- **Plugins.** Built-in [targets](#targets) for popular tools. Use custom
|
|
22
|
-
targets by implementing the `Target` interface.
|
|
20
|
+
targets by implementing/extending the `Target` interface.
|
|
23
21
|
- **TypeScript.** Written in TypeScript with type definitions included.
|
|
24
22
|
- **Lightweight.** Minimal dependencies for fast performance and small bundle size.
|
|
25
23
|
- **Easy-to-modify.** Well-written and MIT-licensed.
|
|
24
|
+
- **Browser.** Can be bundled for browser use. See `ScanOptions.fs` and `import ... "view-ignored/browser"`.
|
|
25
|
+
- **Windows.** Windows paths are converted to Unix paths for compatibility with `memfs` based tests and browsers.
|
|
26
26
|
|
|
27
27
|
> [!NOTE]
|
|
28
28
|
> Despite the name of the package being "view-ignored",
|
|
@@ -36,51 +36,99 @@ by Git, NPM, Yarn, JSR, VSCE or other tools.
|
|
|
36
36
|
### Basic example
|
|
37
37
|
|
|
38
38
|
```ts
|
|
39
|
-
import * as vign from "view-ignored"
|
|
40
|
-
import { Git } from "view-ignored/targets"
|
|
39
|
+
import * as vign from "view-ignored"
|
|
40
|
+
import { Git as target } from "view-ignored/targets"
|
|
41
41
|
|
|
42
|
-
const
|
|
43
|
-
|
|
42
|
+
const ctx = await vign.scan({ target })
|
|
43
|
+
ctx.paths.has(".git/HEAD") // false
|
|
44
|
+
ctx.paths.has("src") // true
|
|
45
|
+
|
|
46
|
+
ctx.paths.get("src") // { ignored, match, kind, ... }
|
|
44
47
|
```
|
|
45
48
|
|
|
46
49
|
### Using custom target
|
|
47
50
|
|
|
48
51
|
```ts
|
|
49
|
-
import * as vign from "view-ignored";
|
|
50
52
|
import {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
} from "view-ignored/patterns"
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
53
|
+
type Extractor,
|
|
54
|
+
extractGitignore,
|
|
55
|
+
signedPatternIgnores,
|
|
56
|
+
signedPatternCompile,
|
|
57
|
+
type SignedPattern,
|
|
58
|
+
} from "view-ignored/patterns"
|
|
59
|
+
|
|
60
|
+
import type { Target } from "view-ignored/targets"
|
|
61
|
+
|
|
62
|
+
const extractors: Extractor[] = [
|
|
63
|
+
{
|
|
64
|
+
extract: extractGitignore,
|
|
65
|
+
path: ".gitignore",
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
extract: extractGitignore,
|
|
69
|
+
path: ".git/info/exclude",
|
|
70
|
+
},
|
|
71
|
+
]
|
|
72
|
+
|
|
73
|
+
const internal: SignedPattern = {
|
|
74
|
+
exclude: [".git", ".DS_Store"],
|
|
75
|
+
include: [],
|
|
76
|
+
compiled: null,
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
signedPatternCompile(internal)
|
|
70
80
|
|
|
71
81
|
export const Git: Target = {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
82
|
+
extractors,
|
|
83
|
+
ignores(o) {
|
|
84
|
+
return signedPatternIgnores({
|
|
85
|
+
...o,
|
|
86
|
+
internal,
|
|
87
|
+
root: "/",
|
|
88
|
+
target: Git,
|
|
89
|
+
})
|
|
90
|
+
},
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const ctx = await vign.scan({ target })
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Streaming results
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
import * as vign from "view-ignored"
|
|
100
|
+
import { NPM as target } from "view-ignored/targets"
|
|
101
|
+
|
|
102
|
+
const stream = await vign.scanStream({ target })
|
|
103
|
+
|
|
104
|
+
stream.on("dirent", console.log)
|
|
105
|
+
stream.on("end", (ctx) => {
|
|
106
|
+
ctx.paths.has(".git/HEAD") // false
|
|
107
|
+
ctx.paths.has("node_modules/") // false
|
|
108
|
+
ctx.paths.has("package.json") // true
|
|
109
|
+
})
|
|
80
110
|
```
|
|
81
111
|
|
|
112
|
+
### Browser and custom FS
|
|
113
|
+
|
|
114
|
+
To avoid imports from `node:fs` and `node:process` modules,
|
|
115
|
+
use the browser submodule, which requires some additional options.
|
|
116
|
+
|
|
82
117
|
```ts
|
|
83
|
-
vign
|
|
118
|
+
import * as vign from "view-ignored/browser"
|
|
119
|
+
// or view-ignored/browser/scan
|
|
120
|
+
import { Git as target } from "view-ignored/targets"
|
|
121
|
+
|
|
122
|
+
export const cwd = process.cwd()
|
|
123
|
+
|
|
124
|
+
const customFs = {
|
|
125
|
+
promises: {
|
|
126
|
+
opendir,
|
|
127
|
+
readFile,
|
|
128
|
+
},
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
vign.scan({ target, cwd, fs })
|
|
84
132
|
```
|
|
85
133
|
|
|
86
134
|
## Targets
|
|
@@ -92,25 +140,34 @@ vign.scan({ target: Git });
|
|
|
92
140
|
The following built-in scanners are available:
|
|
93
141
|
|
|
94
142
|
- Git
|
|
95
|
-
- Reads `.gitignore`
|
|
96
|
-
-
|
|
143
|
+
- Reads `.gitignore` and `.git/info/exclude` but does not consider global settings.
|
|
144
|
+
- Starts searching from `/`.
|
|
145
|
+
- Check this scanner by running `git ls-files --others --exclude-standard --cached`.
|
|
97
146
|
- See the implementation of [Git target](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/git.ts) for details.
|
|
98
147
|
- NPM (compatible with Bun, PNPM, and others)
|
|
99
148
|
- Reads `.npmignore` and `package.json` `files` field.
|
|
149
|
+
- Starts searching from `.` (current working directory).
|
|
100
150
|
- No additional checks for `name`, `version` or `publishConfig`.
|
|
101
151
|
- Check this scanner by running `npm pack --dry-run`.
|
|
102
152
|
- See the implementation of [NPM target](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/npm.ts) for details.
|
|
103
153
|
- Yarn
|
|
104
154
|
- Same behavior as `npm`, but also reads `.yarnignore`.
|
|
155
|
+
- Starts searching from `.` (current working directory).
|
|
105
156
|
- See the implementation of [Yarn target](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/yarn.ts) for details.
|
|
106
157
|
- VSCE
|
|
107
|
-
- Reads
|
|
158
|
+
- Reads `package.json` `files` field, `.vscodeignore` and `.gitignore`.
|
|
159
|
+
- Starts searching from `.` (current working directory).
|
|
108
160
|
- Check this scanner by running `vsce ls`.
|
|
109
161
|
- See the implementation of [VSCE target](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/vsce.ts) for details.
|
|
110
162
|
- JSR (compatible with Deno)
|
|
111
163
|
- Reads `jsr.json(c)` and `deno.json(c)` `include` and `exclude` fields.
|
|
164
|
+
- Starts searching from `.` (current working directory).
|
|
112
165
|
- See the implementation of [JSR target](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/jsr.ts) for details.
|
|
113
166
|
|
|
167
|
+
## See also
|
|
168
|
+
|
|
169
|
+
- https://jsr.io/@m234/path - Utility to sort, convert and format paths.
|
|
170
|
+
|
|
114
171
|
## License
|
|
115
172
|
|
|
116
173
|
MIT License. See [LICENSE.txt](LICENSE.txt) for details.
|
package/out/browser.d.ts
ADDED
package/out/browser.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { MatcherContext } from "./patterns/matcherContext.js";
|
|
2
|
+
import type { ScanOptions, FsAdapter } from "./types.js";
|
|
3
|
+
export type * from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Scan the directory for included files based on the provided targets.
|
|
6
|
+
*
|
|
7
|
+
* Note that this function uses `fs/promises.readFile` and `fs/promises.opendir` without options within
|
|
8
|
+
* custom recursion, instead of `fs.promises.readdir` with `{ withFileTypes: true }.
|
|
9
|
+
* It also normalizes paths to use forward slashes.
|
|
10
|
+
* Please report any issues if you encounter problems related to this behavior.
|
|
11
|
+
*
|
|
12
|
+
* @param options Scan options.
|
|
13
|
+
* @returns A promise that resolves to a {@link MatcherContext} containing the scan results.
|
|
14
|
+
*
|
|
15
|
+
* @since 0.0.6
|
|
16
|
+
*/
|
|
17
|
+
export declare function scan(options: ScanOptions & {
|
|
18
|
+
fs: FsAdapter;
|
|
19
|
+
cwd: string;
|
|
20
|
+
}): Promise<MatcherContext>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { normalizeCwd } from "./normalizeCwd.js";
|
|
3
|
+
import { opendir } from "./opendir.js";
|
|
4
|
+
import { walkIncludes } from "./walk.js";
|
|
5
|
+
/**
|
|
6
|
+
* Scan the directory for included files based on the provided targets.
|
|
7
|
+
*
|
|
8
|
+
* Note that this function uses `fs/promises.readFile` and `fs/promises.opendir` without options within
|
|
9
|
+
* custom recursion, instead of `fs.promises.readdir` with `{ withFileTypes: true }.
|
|
10
|
+
* It also normalizes paths to use forward slashes.
|
|
11
|
+
* Please report any issues if you encounter problems related to this behavior.
|
|
12
|
+
*
|
|
13
|
+
* @param options Scan options.
|
|
14
|
+
* @returns A promise that resolves to a {@link MatcherContext} containing the scan results.
|
|
15
|
+
*
|
|
16
|
+
* @since 0.0.6
|
|
17
|
+
*/
|
|
18
|
+
export function scan(options) {
|
|
19
|
+
const { target, cwd, within: select = ".", invert = false, depth: maxDepth = Infinity, signal = null, fastDepth = false, fastInternal = false, fs, } = options;
|
|
20
|
+
if (maxDepth < 0) {
|
|
21
|
+
throw new TypeError("Depth must be a non-negative integer");
|
|
22
|
+
}
|
|
23
|
+
const ctx = {
|
|
24
|
+
paths: new Map(),
|
|
25
|
+
external: new Map(),
|
|
26
|
+
failed: [],
|
|
27
|
+
depthPaths: new Map(),
|
|
28
|
+
totalFiles: 0,
|
|
29
|
+
totalMatchedFiles: 0,
|
|
30
|
+
totalDirs: 0,
|
|
31
|
+
};
|
|
32
|
+
const normalCwd = normalizeCwd(cwd);
|
|
33
|
+
const scanOptions = {
|
|
34
|
+
cwd: normalCwd,
|
|
35
|
+
within: select,
|
|
36
|
+
depth: maxDepth,
|
|
37
|
+
fastDepth,
|
|
38
|
+
fastInternal,
|
|
39
|
+
fs,
|
|
40
|
+
invert,
|
|
41
|
+
signal,
|
|
42
|
+
target,
|
|
43
|
+
};
|
|
44
|
+
const result = opendir(fs, resolve(normalCwd, select), (entry) => walkIncludes({
|
|
45
|
+
entry,
|
|
46
|
+
ctx,
|
|
47
|
+
stream: undefined,
|
|
48
|
+
scanOptions,
|
|
49
|
+
}));
|
|
50
|
+
return (async () => {
|
|
51
|
+
await result;
|
|
52
|
+
return ctx;
|
|
53
|
+
})();
|
|
54
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MatcherStream } from "./patterns/matcherStream.js";
|
|
2
|
+
import type { ScanOptions, FsAdapter } from "./types.js";
|
|
3
|
+
export type * from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* @see {@link browserScan}
|
|
6
|
+
*
|
|
7
|
+
* @since 0.0.6
|
|
8
|
+
*/
|
|
9
|
+
export declare function scanStream(options: ScanOptions & {
|
|
10
|
+
fs: FsAdapter;
|
|
11
|
+
cwd: string;
|
|
12
|
+
}): MatcherStream;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { normalizeCwd } from "./normalizeCwd.js";
|
|
3
|
+
import { opendir } from "./opendir.js";
|
|
4
|
+
import { MatcherStream } from "./patterns/matcherStream.js";
|
|
5
|
+
import { walkIncludes } from "./walk.js";
|
|
6
|
+
/**
|
|
7
|
+
* @see {@link browserScan}
|
|
8
|
+
*
|
|
9
|
+
* @since 0.0.6
|
|
10
|
+
*/
|
|
11
|
+
export function scanStream(options) {
|
|
12
|
+
const { target, cwd, within: select = ".", invert = false, depth: maxDepth = Infinity, signal = null, fastDepth = false, fastInternal = false, fs, } = options;
|
|
13
|
+
const ctx = {
|
|
14
|
+
paths: new Map(),
|
|
15
|
+
external: new Map(),
|
|
16
|
+
failed: [],
|
|
17
|
+
depthPaths: new Map(),
|
|
18
|
+
totalFiles: 0,
|
|
19
|
+
totalMatchedFiles: 0,
|
|
20
|
+
totalDirs: 0,
|
|
21
|
+
};
|
|
22
|
+
const stream = new MatcherStream({ captureRejections: false });
|
|
23
|
+
const normalCwd = normalizeCwd(cwd);
|
|
24
|
+
const scanOptions = {
|
|
25
|
+
cwd: normalCwd,
|
|
26
|
+
within: select,
|
|
27
|
+
depth: maxDepth,
|
|
28
|
+
fastDepth,
|
|
29
|
+
fastInternal,
|
|
30
|
+
fs,
|
|
31
|
+
invert,
|
|
32
|
+
signal,
|
|
33
|
+
target,
|
|
34
|
+
};
|
|
35
|
+
const result = opendir(fs, resolve(normalCwd, select), (entry) => walkIncludes({
|
|
36
|
+
entry,
|
|
37
|
+
ctx,
|
|
38
|
+
stream,
|
|
39
|
+
scanOptions,
|
|
40
|
+
}));
|
|
41
|
+
void (async () => {
|
|
42
|
+
await result;
|
|
43
|
+
stream.emit("end", ctx);
|
|
44
|
+
})();
|
|
45
|
+
return stream;
|
|
46
|
+
}
|
package/out/getDepth.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export function getDepth(path, maxDepth) {
|
|
2
|
+
if (path.endsWith("/")) {
|
|
3
|
+
path = path.substring(0, path.length - 1);
|
|
4
|
+
}
|
|
5
|
+
const result = {
|
|
6
|
+
depth: 0,
|
|
7
|
+
depthSlash: -1,
|
|
8
|
+
};
|
|
9
|
+
let i = -1;
|
|
10
|
+
for (const c of path) {
|
|
11
|
+
i++;
|
|
12
|
+
if (c !== "/") {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
if (result.depth === maxDepth) {
|
|
16
|
+
result.depthSlash = i;
|
|
17
|
+
}
|
|
18
|
+
result.depth++;
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
}
|
package/out/index.d.ts
CHANGED
package/out/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { scan } from "./scan.js";
|
|
2
|
+
export { scanStream } from "./stream.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function normalizeCwd(cwd: string): string;
|
package/out/opendir.d.ts
ADDED
package/out/opendir.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export async function opendir(fs, path, cb) {
|
|
2
|
+
const dir = await fs.promises.opendir(path);
|
|
3
|
+
for await (const entry of dir) {
|
|
4
|
+
const r = await cb(entry);
|
|
5
|
+
if (r === 2) {
|
|
6
|
+
return 2;
|
|
7
|
+
}
|
|
8
|
+
if (r === 1) {
|
|
9
|
+
continue;
|
|
10
|
+
}
|
|
11
|
+
if (entry.isDirectory()) {
|
|
12
|
+
const r = await opendir(fs, path + "/" + entry.name, cb);
|
|
13
|
+
if (r === 2) {
|
|
14
|
+
return 2;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { Target } from "../targets/target.js";
|
|
2
|
+
import type { FsAdapter } from "../types.js";
|
|
3
|
+
import type { MatcherContext } from "./matcherContext.js";
|
|
4
|
+
import type { Source } from "./source.js";
|
|
5
|
+
/**
|
|
6
|
+
* Populates the source object from the content of a source file.
|
|
7
|
+
* Results are available in `ctx.external`.
|
|
8
|
+
* If `"none"` returned or throwed, will skip the extractor.
|
|
9
|
+
*
|
|
10
|
+
* @see {@link Source.pattern} for more details.
|
|
11
|
+
* @throws Error if extraction fails. Processing stops.
|
|
12
|
+
*
|
|
13
|
+
* @since 0.0.6
|
|
14
|
+
*/
|
|
15
|
+
export type ExtractorFn = (source: Source, content: Buffer, ctx: MatcherContext) => void | "none";
|
|
16
|
+
/**
|
|
17
|
+
* Defines a method for extracting patterns from a specific source file.
|
|
18
|
+
*
|
|
19
|
+
* @since 0.0.6
|
|
20
|
+
*/
|
|
21
|
+
export interface Extractor {
|
|
22
|
+
/**
|
|
23
|
+
* Relative path.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ".gitignore"
|
|
27
|
+
*
|
|
28
|
+
* @since 0.0.6
|
|
29
|
+
*/
|
|
30
|
+
path: string;
|
|
31
|
+
/**
|
|
32
|
+
* Populates the source object from the content of a source file.
|
|
33
|
+
*
|
|
34
|
+
* @see {@link ExtractorFn}
|
|
35
|
+
*
|
|
36
|
+
* @since 0.0.6
|
|
37
|
+
*/
|
|
38
|
+
extract: ExtractorFn;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Options for finding and extracting patterns from source files.
|
|
42
|
+
*
|
|
43
|
+
* @see {@link resolveSources}
|
|
44
|
+
* @see {@link signedPatternIgnores}
|
|
45
|
+
*
|
|
46
|
+
* @since 0.0.6
|
|
47
|
+
*/
|
|
48
|
+
export interface PatternFinderOptions {
|
|
49
|
+
/**
|
|
50
|
+
* The file system adapter for directory walking and reading files.
|
|
51
|
+
*
|
|
52
|
+
* @since 0.0.6
|
|
53
|
+
*/
|
|
54
|
+
fs: FsAdapter;
|
|
55
|
+
/**
|
|
56
|
+
* The context to modify.
|
|
57
|
+
*
|
|
58
|
+
* @since 0.0.6
|
|
59
|
+
*/
|
|
60
|
+
ctx: MatcherContext;
|
|
61
|
+
/**
|
|
62
|
+
* The current working directory.
|
|
63
|
+
*
|
|
64
|
+
* @since 0.0.6
|
|
65
|
+
*/
|
|
66
|
+
cwd: string;
|
|
67
|
+
/**
|
|
68
|
+
* The target implementation.
|
|
69
|
+
*
|
|
70
|
+
* @since 0.0.6
|
|
71
|
+
*/
|
|
72
|
+
target: Target;
|
|
73
|
+
/**
|
|
74
|
+
* Initial search directory.
|
|
75
|
+
* Relative to the `cwd` path or absolute path.
|
|
76
|
+
*
|
|
77
|
+
* @since 0.0.6
|
|
78
|
+
*/
|
|
79
|
+
root: string;
|
|
80
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
import { type Source } from
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { type Source } from "./source.js";
|
|
2
|
+
/**
|
|
3
|
+
* Extracts and compiles patterns from the file.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link signedPatternCompile}
|
|
6
|
+
*
|
|
7
|
+
* @since 0.0.6
|
|
8
|
+
*/
|
|
9
|
+
export declare function extractGitignore(source: Source, content: Buffer): void;
|
|
@@ -1,31 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { signedPatternCompile } from "./resolveSources.js";
|
|
2
|
+
import { sourcePushNegatable } from "./source.js";
|
|
3
|
+
/**
|
|
4
|
+
* Extracts and compiles patterns from the file.
|
|
5
|
+
*
|
|
6
|
+
* @see {@link signedPatternCompile}
|
|
7
|
+
*
|
|
8
|
+
* @since 0.0.6
|
|
9
|
+
*/
|
|
3
10
|
export function extractGitignore(source, content) {
|
|
4
|
-
for (let line of content.toString().split(
|
|
11
|
+
for (let line of content.toString().split("\n")) {
|
|
5
12
|
line = line.trim();
|
|
6
|
-
if (line ===
|
|
13
|
+
if (line === "" || line.startsWith("#")) {
|
|
7
14
|
continue;
|
|
8
15
|
}
|
|
9
|
-
const cdx = line.indexOf(
|
|
16
|
+
const cdx = line.indexOf("#");
|
|
10
17
|
if (cdx >= 0) {
|
|
11
18
|
line = line.substring(-cdx);
|
|
12
19
|
}
|
|
13
20
|
sourcePushNegatable(source, line);
|
|
14
21
|
}
|
|
15
|
-
|
|
22
|
+
signedPatternCompile(source.pattern);
|
|
16
23
|
}
|
|
17
24
|
extractGitignore;
|
|
18
|
-
export function gitignoreMatch(pattern, path) {
|
|
19
|
-
const o = { dot: true };
|
|
20
|
-
if (pattern.startsWith('/')) {
|
|
21
|
-
pattern = pattern.substring(1);
|
|
22
|
-
}
|
|
23
|
-
else if (!pattern.startsWith('**/')) {
|
|
24
|
-
if (minimatch(path, '**/' + pattern, o))
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
if (pattern.endsWith('/')) {
|
|
28
|
-
pattern = pattern.substring(-1);
|
|
29
|
-
}
|
|
30
|
-
return minimatch(path, pattern, o) || minimatch(path, pattern + '/**', o);
|
|
31
|
-
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { MatcherContext } from "../patterns/matcherContext.js";
|
|
2
|
+
import type { SignedPatternMatch } from "../patterns/signedPattern.js";
|
|
3
|
+
import type { FsAdapter } from "../types.js";
|
|
4
|
+
export interface IgnoresOptions {
|
|
5
|
+
fs: FsAdapter;
|
|
6
|
+
cwd: string;
|
|
7
|
+
entry: string;
|
|
8
|
+
ctx: MatcherContext;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Checks whether a given entry path should be ignored based on its patterns.
|
|
12
|
+
*
|
|
13
|
+
* @see {@link resolveSources}
|
|
14
|
+
* @see {@link signedPatternIgnores}
|
|
15
|
+
* @see {@link https://github.com/Mopsgamer/view-ignored/tree/main/src/targets} for usage examples.
|
|
16
|
+
*
|
|
17
|
+
* @since 0.0.6
|
|
18
|
+
*/
|
|
19
|
+
export type Ignores = (options: IgnoresOptions) => Promise<SignedPatternMatch>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/out/patterns/index.d.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
1
|
+
export * from "./extractor.js";
|
|
2
|
+
export * from "./gitignore.js";
|
|
3
|
+
export * from "./ignores.js";
|
|
4
|
+
export * from "./jsrjson.js";
|
|
5
|
+
export * from "./matcherContext.js";
|
|
6
|
+
export * from "./matcherContextPatch.js";
|
|
7
|
+
export * from "./matcherStream.js";
|
|
8
|
+
export * from "./packagejson.js";
|
|
9
|
+
export * from "./pattern.js";
|
|
10
|
+
export * from "./patternMatcher.js";
|
|
11
|
+
export * from "./resolveSources.js";
|
|
12
|
+
export * from "./signedPattern.js";
|
|
13
|
+
export * from "./source.js";
|
package/out/patterns/index.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
1
|
+
export * from "./extractor.js";
|
|
2
|
+
export * from "./gitignore.js";
|
|
3
|
+
export * from "./ignores.js";
|
|
4
|
+
export * from "./jsrjson.js";
|
|
5
|
+
export * from "./matcherContext.js";
|
|
6
|
+
export * from "./matcherContextPatch.js";
|
|
7
|
+
export * from "./matcherStream.js";
|
|
8
|
+
export * from "./packagejson.js";
|
|
9
|
+
export * from "./pattern.js";
|
|
10
|
+
export * from "./patternMatcher.js";
|
|
11
|
+
export * from "./resolveSources.js";
|
|
12
|
+
export * from "./signedPattern.js";
|
|
13
|
+
export * from "./source.js";
|
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { Source } from
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type { MatcherContext } from "./matcherContext.js";
|
|
2
|
+
import type { Source } from "./source.js";
|
|
3
|
+
/**
|
|
4
|
+
* Extracts and compiles patterns from the file.
|
|
5
|
+
*
|
|
6
|
+
* @since 0.0.6
|
|
7
|
+
*/
|
|
8
|
+
export declare function extractJsrJson(source: Source, content: Buffer, ctx: MatcherContext): void;
|
|
9
|
+
/**
|
|
10
|
+
* Extracts and compiles patterns from the file.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link signedPatternCompile}
|
|
13
|
+
*
|
|
14
|
+
* @since 0.0.6
|
|
15
|
+
*/
|
|
16
|
+
export declare function extractJsrJsonc(source: Source, content: Buffer, ctx: MatcherContext): void;
|