view-ignored 0.10.0 → 0.11.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 +118 -62
- package/out/browser.d.ts +1 -0
- package/out/browser.js +1 -0
- package/out/browser_scan.d.ts +1 -3
- package/out/browser_scan.js +11 -46
- package/out/browser_stream.d.ts +6 -1
- package/out/browser_stream.js +6 -1
- package/out/index.d.ts +1 -0
- package/out/index.js +1 -0
- package/out/patterns/extractor.d.ts +7 -7
- package/out/patterns/gitignore.d.ts +2 -2
- package/out/patterns/gitignore.js +14 -6
- package/out/patterns/ignores.d.ts +23 -8
- package/out/patterns/index.d.ts +1 -0
- package/out/patterns/index.js +1 -0
- package/out/patterns/init.d.ts +2 -2
- package/out/patterns/initState.d.ts +0 -7
- package/out/patterns/jsrjson.d.ts +2 -3
- package/out/patterns/jsrjson.js +25 -38
- package/out/patterns/matcherContext.d.ts +12 -9
- package/out/patterns/matcherContextPatch.js +158 -75
- package/out/patterns/matcherStream.d.ts +30 -11
- package/out/patterns/matcherStream.js +70 -25
- package/out/patterns/packagejson.d.ts +2 -2
- package/out/patterns/packagejson.js +11 -14
- package/out/patterns/patternCompile.js +48 -19
- package/out/patterns/patternList.d.ts +12 -6
- package/out/patterns/patternList.js +8 -4
- package/out/patterns/resolveSources.d.ts +22 -5
- package/out/patterns/resolveSources.js +153 -97
- package/out/patterns/resource.d.ts +16 -0
- package/out/patterns/resource.js +1 -0
- package/out/patterns/rule.d.ts +63 -9
- package/out/patterns/rule.js +101 -66
- package/out/patterns/source.d.ts +9 -17
- package/out/scan.d.ts +11 -3
- package/out/scan.js +16 -4
- package/out/scanCb.d.ts +16 -0
- package/out/scanCb.js +73 -0
- package/out/scanParallel.d.ts +18 -0
- package/out/scanParallel.js +146 -0
- package/out/stream.d.ts +6 -1
- package/out/stream.js +7 -2
- package/out/targets/bun.js +43 -36
- package/out/targets/deno.js +25 -23
- package/out/targets/git.js +3 -3
- package/out/targets/jsr.js +25 -23
- package/out/targets/jsrManifest.d.ts +8 -7
- package/out/targets/jsrManifest.js +40 -9
- package/out/targets/npm.js +30 -23
- package/out/targets/npmManifest.d.ts +18 -46
- package/out/targets/npmManifest.js +96 -23
- package/out/targets/target.d.ts +8 -16
- package/out/targets/vsce.js +20 -27
- package/out/targets/vsceManifest.d.ts +7 -0
- package/out/targets/vsceManifest.js +18 -0
- package/out/targets/yarn.js +48 -39
- package/out/targets/yarnClassic.js +20 -18
- package/out/types.d.ts +8 -7
- package/out/unixify.d.ts +1 -1
- package/out/unixify.js +40 -21
- package/out/walk.d.ts +43 -4
- package/out/walk.js +146 -84
- package/package.json +27 -23
- package/out/getDepth.d.ts +0 -4
- package/out/getDepth.js +0 -21
- package/out/opendir.d.ts +0 -3
- package/out/opendir.js +0 -22
package/README.md
CHANGED
|
@@ -1,27 +1,52 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<h1>view-ignored</h1>
|
|
2
3
|
|
|
3
|
-
[](https://www.npmjs.com/package/view-ignored)
|
|
5
|
+
[](https://www.npmjs.com/package/view-ignored)
|
|
6
|
+

|
|
7
|
+
[](https://github.com/Mopsgamer/view-ignored/tree/main/benchmarks)
|
|
8
|
+
|
|
9
|
+
[](https://github.com/Mopsgamer/view-ignored/issues)
|
|
10
|
+
[](https://github.com/Mopsgamer/view-ignored)
|
|
7
11
|
|
|
8
12
|
Retrieve list of files ignored/included
|
|
9
|
-
by Git, NPM, Yarn, JSR,
|
|
13
|
+
by Git, NPM, Yarn, JSR, Deno, Bun, VSCode extension CLI and other tools.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
### `view-ignored` scans for
|
|
18
|
+
|
|
19
|
+
<img src="https://cdn.jsdelivr.net/gh/devicons/devicon@latest/icons/git/git-original.svg" width="32" height="32" alt="git" />
|
|
20
|
+
<img src="https://cdn.jsdelivr.net/gh/devicons/devicon@latest/icons/npm/npm-original-wordmark.svg" width="32" height="32" alt="npm" />
|
|
21
|
+
<img src="https://cdn.jsdelivr.net/gh/devicons/devicon@latest/icons/yarn/yarn-original.svg" width="32" height="32" alt="yarn" />
|
|
22
|
+
<img src="https://cdn.jsdelivr.net/gh/devicons/devicon@latest/icons/bun/bun-original.svg" width="32" height="32" alt="bun" />
|
|
23
|
+
<img src="https://unpkg.com/simple-icons@v14/icons/deno.svg" width="32" height="32" alt="deno" />
|
|
24
|
+
<img src="https://jsr.io/logo.svg" width="32" height="32" alt="jsr" />
|
|
25
|
+
<img src="https://cdn.jsdelivr.net/gh/devicons/devicon@latest/icons/vscode/vscode-original.svg" width="32" height="32" alt="vsce" />
|
|
10
26
|
|
|
11
|
-
|
|
27
|
+
and more!
|
|
12
28
|
|
|
13
|
-
|
|
29
|
+
[](https://github.com/search?q=repo%3AMopsgamer%2Fview-ignored+label%3Atargets+type%3Aissue&type=issues&query=repo%3AMopsgamer%2Fview-ignored+label%3Atargets)
|
|
30
|
+
[](https://github.com/Mopsgamer/view-ignored/issues/new)
|
|
31
|
+
[](#targets)
|
|
32
|
+
|
|
33
|
+
</div>
|
|
14
34
|
|
|
15
35
|
## Highlights
|
|
16
36
|
|
|
37
|
+
<!-- - **Faster alternative for `npm-packlist`, `ignore-walk` and `ignore`.** -->
|
|
38
|
+
|
|
17
39
|
- **Reader.** Get a list of included files using configuration file
|
|
18
40
|
readers, not command-line wrappers.
|
|
41
|
+
- **Reasoning.** Understand why certain files are included or excluded.
|
|
42
|
+
- **Fast.** Optimized for performance with minimal memory overhead.
|
|
19
43
|
- **Plugins.** Built-in [targets](#targets) for popular tools. Use custom
|
|
20
44
|
targets by implementing/extending the `Target` interface.
|
|
21
|
-
- **
|
|
45
|
+
- **Streaming.** Native `scanStream` support for processing massive file trees with minimal memory overhead.
|
|
46
|
+
- **Execution Control.** Use `fastDepth` and `fastInternal` options to fine-tune traversal depth and skip unnecessary directory checks. You can also enable them if you don't care about stats.
|
|
47
|
+
- **Abortable.** Full support for `AbortSignal` to cancel long-running scans instantly.
|
|
22
48
|
- **Lightweight.** Minimal dependencies for fast performance and small bundle size.
|
|
23
|
-
- **
|
|
24
|
-
- **Browser.** Can be bundled for browser use. See `ScanOptions.fs` and `import ... "view-ignored/browser"`.
|
|
49
|
+
- **Browser.** Can be bundled for browser use.
|
|
25
50
|
- **Windows.** Windows paths are converted to Unix paths for compatibility with `memfs` based tests and browsers.
|
|
26
51
|
|
|
27
52
|
> [!NOTE]
|
|
@@ -31,12 +56,32 @@ Node.js 18 or later
|
|
|
31
56
|
> You can invert the results if you need the ignored files
|
|
32
57
|
> by setting the `invert` option to `true`.
|
|
33
58
|
|
|
59
|
+
## v1 Roadmap
|
|
60
|
+
|
|
61
|
+
- [x] Works for common use cases.
|
|
62
|
+
- [ ] Follow `.gitignore` spec. (`ignore` does.)
|
|
63
|
+
- [ ] Handle Git config.
|
|
64
|
+
- [ ] Include node_modules bundled dependencies correctly. Missing: NPM, Yarn + Classic, Bun, Deno, JSR.
|
|
65
|
+
- [ ] \*Move targets into separate packages (or not).
|
|
66
|
+
- [ ] Import and pass upstream source tests.
|
|
67
|
+
- [ ] \*Make it standard: NPM cli, VS Code file tree, VSCE, GitHub.
|
|
68
|
+
- [ ] \*Upstream to Bun, PNPM and other package managers.
|
|
69
|
+
|
|
70
|
+
<sub>\* - Optional.</sub>
|
|
71
|
+
|
|
72
|
+
## Why this library exists?
|
|
73
|
+
|
|
74
|
+
Incorrect VS Code file tree git status, huge `npm-packlist` package, missing Git's wildmatch algorithm in JS ecosistem, and the fact that there's no lightweight way to get a list of ignored files, which would explain why specific files are being included or excluded.
|
|
75
|
+
|
|
34
76
|
## Usage
|
|
35
77
|
|
|
36
78
|
### Basic example
|
|
37
79
|
|
|
38
80
|
```ts
|
|
39
81
|
import * as vign from "view-ignored"
|
|
82
|
+
// also available:
|
|
83
|
+
// "/scan", "/stream"
|
|
84
|
+
// "/browser", "/browser/scan", "/browser/stream"
|
|
40
85
|
import { Git as target } from "view-ignored/targets"
|
|
41
86
|
|
|
42
87
|
const ctx = await vign.scan({ target })
|
|
@@ -52,7 +97,11 @@ if (match.kind === "external") {
|
|
|
52
97
|
|
|
53
98
|
### Using custom target
|
|
54
99
|
|
|
100
|
+
This is the internal implementation for the Git target:
|
|
101
|
+
|
|
55
102
|
```ts
|
|
103
|
+
import type { Target } from "view-ignored/targets"
|
|
104
|
+
|
|
56
105
|
import {
|
|
57
106
|
type Extractor,
|
|
58
107
|
extractGitignore,
|
|
@@ -61,8 +110,6 @@ import {
|
|
|
61
110
|
type Rule,
|
|
62
111
|
} from "view-ignored/patterns"
|
|
63
112
|
|
|
64
|
-
import type { Target } from "view-ignored/targets"
|
|
65
|
-
|
|
66
113
|
const extractors: Extractor[] = [
|
|
67
114
|
{
|
|
68
115
|
extract: extractGitignore,
|
|
@@ -76,38 +123,43 @@ const extractors: Extractor[] = [
|
|
|
76
123
|
|
|
77
124
|
const internal: Rule[] = [
|
|
78
125
|
ruleCompile({
|
|
126
|
+
compiled: null,
|
|
79
127
|
excludes: true,
|
|
80
128
|
pattern: [".git", ".DS_Store"],
|
|
81
|
-
compiled: null,
|
|
82
129
|
}),
|
|
83
130
|
]
|
|
84
131
|
|
|
85
|
-
export const Git: Target = {
|
|
86
|
-
internalRules: internal,
|
|
132
|
+
export const Git: Target = <Target>{
|
|
87
133
|
extractors,
|
|
88
|
-
root: "/",
|
|
89
134
|
// TODO: Git should read configs
|
|
90
|
-
init() {},
|
|
91
135
|
ignores: ruleTest,
|
|
136
|
+
internalRules: internal,
|
|
137
|
+
root: "/",
|
|
92
138
|
}
|
|
93
|
-
|
|
94
|
-
const ctx = await vign.scan({ target })
|
|
95
139
|
```
|
|
96
140
|
|
|
97
141
|
### Streaming results
|
|
98
142
|
|
|
99
143
|
```ts
|
|
100
144
|
import * as vign from "view-ignored"
|
|
145
|
+
// or import * as vign from "view-ignored/stream"
|
|
101
146
|
import { NPM as target } from "view-ignored/targets"
|
|
102
147
|
|
|
103
|
-
const stream =
|
|
104
|
-
|
|
105
|
-
stream.
|
|
106
|
-
stream.
|
|
107
|
-
|
|
108
|
-
ctx
|
|
109
|
-
|
|
110
|
-
|
|
148
|
+
const stream = vign.scanStream({ target })
|
|
149
|
+
|
|
150
|
+
stream.addEventListener("dirent", console.log)
|
|
151
|
+
stream.addEventListener(
|
|
152
|
+
"end",
|
|
153
|
+
(ctx) => {
|
|
154
|
+
ctx.paths.has(".git/HEAD")
|
|
155
|
+
// false
|
|
156
|
+
ctx.paths.has("node_modules/")
|
|
157
|
+
// false
|
|
158
|
+
ctx.paths.has("package.json")
|
|
159
|
+
// true
|
|
160
|
+
},
|
|
161
|
+
{ once: true },
|
|
162
|
+
)
|
|
111
163
|
stream.start() // important
|
|
112
164
|
```
|
|
113
165
|
|
|
@@ -122,14 +174,7 @@ import * as vign from "view-ignored/browser"
|
|
|
122
174
|
import { Git as target } from "view-ignored/targets"
|
|
123
175
|
|
|
124
176
|
export const cwd = process.cwd()
|
|
125
|
-
|
|
126
|
-
const customFs = {
|
|
127
|
-
promises: {
|
|
128
|
-
opendir,
|
|
129
|
-
readFile,
|
|
130
|
-
},
|
|
131
|
-
}
|
|
132
|
-
|
|
177
|
+
const customFs = { readdir, readFile }
|
|
133
178
|
vign.scan({ target, cwd, fs })
|
|
134
179
|
```
|
|
135
180
|
|
|
@@ -137,41 +182,52 @@ vign.scan({ target, cwd, fs })
|
|
|
137
182
|
|
|
138
183
|
The following built-in scanners are available:
|
|
139
184
|
|
|
140
|
-
- Git ([implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/git.ts))
|
|
141
|
-
-
|
|
142
|
-
-
|
|
185
|
+
- Git ([our implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/git.ts))
|
|
186
|
+
- `view-ignored` handles Git-specific ignoring almost identically to Git: does not consider config.
|
|
187
|
+
- Reads `.gitignore` and `.git/info/exclude`.
|
|
188
|
+
- Searches from `/`. (system's root)
|
|
143
189
|
- Check this scanner by running `git ls-files --others --exclude-standard --cached`.
|
|
144
|
-
- NPM ([implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/npm.ts))
|
|
145
|
-
-
|
|
146
|
-
-
|
|
147
|
-
-
|
|
148
|
-
-
|
|
190
|
+
- NPM ([our implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/npm.ts))
|
|
191
|
+
- `view-ignored` should be compatible with NPM, PNPM, and others.
|
|
192
|
+
- Reads `package.json` `files` field or `.npmignore` or `.gitignore`.
|
|
193
|
+
- Searches from `.` (current working directory).
|
|
194
|
+
- Requires `package.json`: `name`, `version`.
|
|
149
195
|
- Check this scanner by running `npm pack --dry-run`.
|
|
150
|
-
- Bun ([implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/bun.ts))
|
|
196
|
+
- Bun ([our implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/bun.ts))
|
|
151
197
|
- Bun tries to mimic NPM, but that does not mean it behaves the same way.
|
|
198
|
+
- Searches from `.` (current working directory).
|
|
199
|
+
- Requires `package.json`: `name`, `version`. Forces paths from `bin` to be included.
|
|
152
200
|
- Check this scanner by running `bun pm pack --dry-run`.
|
|
153
|
-
- Yarn ([implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/yarn.ts))
|
|
154
|
-
- Modern Berry behavior.
|
|
155
|
-
-
|
|
156
|
-
-
|
|
157
|
-
- Requires `package.json`:
|
|
158
|
-
|
|
159
|
-
- `
|
|
160
|
-
-
|
|
161
|
-
-
|
|
162
|
-
- Reads `package.json` `files` field, `.vscodeignore` and `.gitignore`.
|
|
163
|
-
- Starts searching from `.` (current working directory).
|
|
201
|
+
- Yarn ([our implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/yarn.ts))
|
|
202
|
+
- Modern Berry and ZPM behavior. `YarnClassic` is available. ([our implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/yarnClassic.ts))
|
|
203
|
+
- Reads `package.json` `files` field or `.npmignore` or `.gitignore`.
|
|
204
|
+
- Searches from `.` (current working directory).
|
|
205
|
+
- Requires `package.json`: `name`, `version`. Forces paths from `main`, `module`, `browser` and `bin` to be included.
|
|
206
|
+
- VSCE ([our implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/vsce.ts))
|
|
207
|
+
- Reads `package.json` `files` field or `.vscodeignore` or `.gitignore`.
|
|
208
|
+
- Searches from `.` (current working directory).
|
|
209
|
+
- Requires `package.json`: `name`, `version`, `engines.vscode`.
|
|
164
210
|
- Check this scanner by running `vsce ls`.
|
|
165
|
-
- JSR ([implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/jsr.ts))
|
|
166
|
-
-
|
|
167
|
-
-
|
|
168
|
-
-
|
|
169
|
-
|
|
170
|
-
-
|
|
211
|
+
- JSR ([our implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/jsr.ts))
|
|
212
|
+
- Searches from `.` (current working directory).
|
|
213
|
+
- Requires `jsr.json` or `jsr.jsonc`.
|
|
214
|
+
- Validates `publish.include` and `publish.exclude` or `include` and `exclude` fields.
|
|
215
|
+
- Deno ([our implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/deno.ts))
|
|
216
|
+
- Searches from `.` (current working directory).
|
|
217
|
+
- Requires `jsr.json` or `jsr.jsonc` or `deno.json` or `deno.jsonc`.
|
|
218
|
+
- Validates `publish.include` and `publish.exclude` or `include` and `exclude` fields.
|
|
171
219
|
|
|
172
220
|
## See also
|
|
173
221
|
|
|
222
|
+
- There are references in our implementations.
|
|
174
223
|
- https://jsr.io/@m234/path - Utility to sort, convert and format paths.
|
|
224
|
+
- https://github.com/git/git/blob/master/wildmatch.c - The original wildmatch implementation.
|
|
225
|
+
- https://npmx.dev/package/ignore-walk - A Node.js module for walking directories while respecting ignore files. (It does it incorrectly for Git).
|
|
226
|
+
- https://npmx.dev/package/npm-packlist - A Node.js module for listing files to be included in an npm package. (Heavy)
|
|
227
|
+
|
|
228
|
+
## Benchmarks
|
|
229
|
+
|
|
230
|
+
See [benchmarks directory](https://github.com/Mopsgamer/view-ignored/tree/main/benchmarks).
|
|
175
231
|
|
|
176
232
|
## License
|
|
177
233
|
|
package/out/browser.d.ts
CHANGED
package/out/browser.js
CHANGED
package/out/browser_scan.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import type { MatcherContext } from "./patterns/matcherContext.js";
|
|
2
2
|
import type { ScanOptions, FsAdapter } from "./types.js";
|
|
3
|
+
export { scanCb } from "./scanCb.js";
|
|
3
4
|
export type * from "./types.js";
|
|
4
5
|
/**
|
|
5
6
|
* Scan the directory for included files based on the provided targets.
|
|
6
7
|
*
|
|
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
8
|
* It also normalizes paths to use forward slashes.
|
|
10
|
-
* Please report any issues if you encounter problems related to this behavior.
|
|
11
9
|
*
|
|
12
10
|
* @param options Scan options.
|
|
13
11
|
* @returns A promise that resolves to a {@link MatcherContext} containing the scan results.
|
package/out/browser_scan.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { walkIncludes } from "./walk.js";
|
|
1
|
+
import { scanCb } from "./scanCb.js";
|
|
2
|
+
export { scanCb } from "./scanCb.js";
|
|
4
3
|
/**
|
|
5
4
|
* Scan the directory for included files based on the provided targets.
|
|
6
5
|
*
|
|
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
6
|
* It also normalizes paths to use forward slashes.
|
|
10
|
-
* Please report any issues if you encounter problems related to this behavior.
|
|
11
7
|
*
|
|
12
8
|
* @param options Scan options.
|
|
13
9
|
* @returns A promise that resolves to a {@link MatcherContext} containing the scan results.
|
|
@@ -15,44 +11,13 @@ import { walkIncludes } from "./walk.js";
|
|
|
15
11
|
* @since 0.6.0
|
|
16
12
|
*/
|
|
17
13
|
export function scan(options) {
|
|
18
|
-
const {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
totalFiles: 0,
|
|
28
|
-
totalMatchedFiles: 0,
|
|
29
|
-
totalDirs: 0,
|
|
30
|
-
};
|
|
31
|
-
const normalCwd = unixify(cwd);
|
|
32
|
-
const scanOptions = {
|
|
33
|
-
cwd: normalCwd,
|
|
34
|
-
within,
|
|
35
|
-
depth: maxDepth,
|
|
36
|
-
fastDepth,
|
|
37
|
-
fastInternal,
|
|
38
|
-
fs,
|
|
39
|
-
invert,
|
|
40
|
-
signal,
|
|
41
|
-
target,
|
|
42
|
-
};
|
|
43
|
-
return (async () => {
|
|
44
|
-
await target.init?.({ ctx, cwd, fs, signal, target });
|
|
45
|
-
let from = join(normalCwd, within);
|
|
46
|
-
await opendir(fs, from, (entry, from) => {
|
|
47
|
-
const path = from.substring(normalCwd.length + 1);
|
|
48
|
-
return walkIncludes({
|
|
49
|
-
path,
|
|
50
|
-
entry,
|
|
51
|
-
ctx,
|
|
52
|
-
stream: undefined,
|
|
53
|
-
scanOptions,
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
return ctx;
|
|
57
|
-
})();
|
|
14
|
+
const { promise, resolve, reject } = Promise.withResolvers();
|
|
15
|
+
scanCb(options, (err, ctx) => {
|
|
16
|
+
if (err) {
|
|
17
|
+
reject(err);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
resolve(ctx);
|
|
21
|
+
});
|
|
22
|
+
return promise;
|
|
58
23
|
}
|
package/out/browser_stream.d.ts
CHANGED
|
@@ -2,7 +2,12 @@ import type { ScanOptions, FsAdapter } from "./types.js";
|
|
|
2
2
|
import { MatcherStream } from "./patterns/matcherStream.js";
|
|
3
3
|
export type * from "./types.js";
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Scan the directory for included files based on the provided targets.
|
|
6
|
+
*
|
|
7
|
+
* It also normalizes paths to use forward slashes.
|
|
8
|
+
*
|
|
9
|
+
* @param options Scan options.
|
|
10
|
+
* @returns A stream containing the scan results.
|
|
6
11
|
*
|
|
7
12
|
* @since 0.6.0
|
|
8
13
|
*/
|
package/out/browser_stream.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { MatcherStream } from "./patterns/matcherStream.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Scan the directory for included files based on the provided targets.
|
|
4
|
+
*
|
|
5
|
+
* It also normalizes paths to use forward slashes.
|
|
6
|
+
*
|
|
7
|
+
* @param options Scan options.
|
|
8
|
+
* @returns A stream containing the scan results.
|
|
4
9
|
*
|
|
5
10
|
* @since 0.6.0
|
|
6
11
|
*/
|
package/out/index.d.ts
CHANGED
package/out/index.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import type { Target } from "../targets/target.js";
|
|
2
2
|
import type { FsAdapter } from "../types.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { Resource } from "./resource.js";
|
|
4
4
|
import type { Source } from "./source.js";
|
|
5
5
|
/**
|
|
6
6
|
* Populates the source object from the content of a source file.
|
|
7
7
|
* Results are available in `ctx.external`.
|
|
8
|
-
* If `
|
|
8
|
+
* If `null` returned or throwed, will skip the extractor.
|
|
9
9
|
*
|
|
10
|
-
* @see {@link Source.
|
|
10
|
+
* @see {@link Source.rules} for more details.
|
|
11
11
|
* @throws Error if extraction fails. Processing stops.
|
|
12
12
|
*
|
|
13
13
|
* @since 0.6.0
|
|
14
14
|
*/
|
|
15
|
-
export type ExtractorFn = (source: Source, content: Buffer
|
|
15
|
+
export type ExtractorFn = (source: Source, content: Buffer) => void | null | Error;
|
|
16
16
|
/**
|
|
17
17
|
* Defines a method for extracting patterns from a specific source file.
|
|
18
18
|
*
|
|
@@ -53,11 +53,11 @@ export interface PatternFinderOptions {
|
|
|
53
53
|
*/
|
|
54
54
|
fs: FsAdapter;
|
|
55
55
|
/**
|
|
56
|
-
* The
|
|
56
|
+
* The associated resource.
|
|
57
57
|
*
|
|
58
|
-
* @since 0.
|
|
58
|
+
* @since 0.11.0
|
|
59
59
|
*/
|
|
60
|
-
|
|
60
|
+
resource?: Resource;
|
|
61
61
|
/**
|
|
62
62
|
* The current working directory.
|
|
63
63
|
*
|
|
@@ -6,7 +6,7 @@ import { type Source } from "./source.js";
|
|
|
6
6
|
*
|
|
7
7
|
* @since 0.6.0
|
|
8
8
|
*/
|
|
9
|
-
export declare function extractGitignore(source: Source, content: Buffer): void;
|
|
9
|
+
export declare function extractGitignore(source: Source, content: Buffer): void | Error;
|
|
10
10
|
/**
|
|
11
11
|
* Extracts and compiles patterns from the file.
|
|
12
12
|
*
|
|
@@ -14,4 +14,4 @@ export declare function extractGitignore(source: Source, content: Buffer): void;
|
|
|
14
14
|
*
|
|
15
15
|
* @since 0.8.0
|
|
16
16
|
*/
|
|
17
|
-
export declare function extractGitignoreNocase(source: Source, content: Buffer): void;
|
|
17
|
+
export declare function extractGitignoreNocase(source: Source, content: Buffer): void | Error;
|
|
@@ -9,7 +9,7 @@ import { resolveNegatable } from "./source.js";
|
|
|
9
9
|
*/
|
|
10
10
|
export function extractGitignore(source, content) {
|
|
11
11
|
extract(source, content);
|
|
12
|
-
for (const element of source.
|
|
12
|
+
for (const element of source.rules) {
|
|
13
13
|
ruleCompile(element);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
@@ -22,7 +22,7 @@ export function extractGitignore(source, content) {
|
|
|
22
22
|
*/
|
|
23
23
|
export function extractGitignoreNocase(source, content) {
|
|
24
24
|
extract(source, content);
|
|
25
|
-
for (const element of source.
|
|
25
|
+
for (const element of source.rules) {
|
|
26
26
|
ruleCompile(element, { nocase: true });
|
|
27
27
|
}
|
|
28
28
|
}
|
|
@@ -30,16 +30,24 @@ extractGitignore;
|
|
|
30
30
|
function extract(source, content) {
|
|
31
31
|
const include = { compiled: null, excludes: false, pattern: [] };
|
|
32
32
|
const exclude = { compiled: null, excludes: true, pattern: [] };
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
let start = 0;
|
|
34
|
+
while (start < content.length) {
|
|
35
|
+
let end = content.indexOf(0x0a, start);
|
|
36
|
+
if (end === -1)
|
|
37
|
+
end = content.length;
|
|
38
|
+
// Convert only the current line to a string
|
|
39
|
+
let line = content.toString("utf8", start, end).trim();
|
|
40
|
+
start = end + 1;
|
|
35
41
|
if (line === "" || line.startsWith("#")) {
|
|
36
42
|
continue;
|
|
37
43
|
}
|
|
38
44
|
const cdx = line.indexOf("#");
|
|
39
45
|
if (cdx >= 0) {
|
|
40
|
-
line = line.
|
|
46
|
+
line = line.slice(0, cdx).trim();
|
|
47
|
+
if (line === "")
|
|
48
|
+
continue;
|
|
41
49
|
}
|
|
42
50
|
resolveNegatable(line, false, include, exclude);
|
|
43
51
|
}
|
|
44
|
-
source.
|
|
52
|
+
source.rules.push(include, exclude);
|
|
45
53
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { InitState } from "./initState.js";
|
|
2
|
+
import type { Resource } from "./resource.js";
|
|
2
3
|
import type { RuleMatch } from "./rule.js";
|
|
3
4
|
/**
|
|
4
|
-
* Used in {@link
|
|
5
|
+
* Used in {@link IgnoresCb}.
|
|
5
6
|
*
|
|
6
7
|
* @since 0.6.0
|
|
7
8
|
*/
|
|
@@ -12,14 +13,28 @@ export interface IgnoresOptions extends InitState {
|
|
|
12
13
|
* @since 0.6.0
|
|
13
14
|
*/
|
|
14
15
|
entry: string;
|
|
16
|
+
/**
|
|
17
|
+
* Pre-lowercased entry path.
|
|
18
|
+
*
|
|
19
|
+
* @since 0.11.1
|
|
20
|
+
*/
|
|
21
|
+
lowerEntry?: string;
|
|
22
|
+
/**
|
|
23
|
+
* The associated resource.
|
|
24
|
+
*
|
|
25
|
+
* @since 0.11.0
|
|
26
|
+
*/
|
|
27
|
+
resource: Resource;
|
|
28
|
+
/**
|
|
29
|
+
* Result of the `dirname(entry)` call.
|
|
30
|
+
*
|
|
31
|
+
* @since 0.10.1
|
|
32
|
+
*/
|
|
33
|
+
parentPath: string;
|
|
15
34
|
}
|
|
16
35
|
/**
|
|
17
|
-
*
|
|
36
|
+
* @see {@link IgnoresCb}
|
|
18
37
|
*
|
|
19
|
-
* @
|
|
20
|
-
* @see {@link ruleTest}
|
|
21
|
-
* @see {@link https://github.com/Mopsgamer/view-ignored/tree/main/src/targets} for usage examples.
|
|
22
|
-
*
|
|
23
|
-
* @since 0.6.0
|
|
38
|
+
* @since 0.11.0
|
|
24
39
|
*/
|
|
25
|
-
export type
|
|
40
|
+
export type IgnoresCb = (options: IgnoresOptions, cb: (err: Error | null, match: RuleMatch) => void) => void;
|
package/out/patterns/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from "./matcherStream.js";
|
|
|
10
10
|
export * from "./packagejson.js";
|
|
11
11
|
export * from "./patternList.js";
|
|
12
12
|
export * from "./resolveSources.js";
|
|
13
|
+
export * from "./resource.js";
|
|
13
14
|
export * from "./rule.js";
|
|
14
15
|
export * from "./source.js";
|
|
15
16
|
export * from "./patternCompile.js";
|
package/out/patterns/index.js
CHANGED
|
@@ -10,6 +10,7 @@ export * from "./matcherStream.js";
|
|
|
10
10
|
export * from "./packagejson.js";
|
|
11
11
|
export * from "./patternList.js";
|
|
12
12
|
export * from "./resolveSources.js";
|
|
13
|
+
export * from "./resource.js";
|
|
13
14
|
export * from "./rule.js";
|
|
14
15
|
export * from "./source.js";
|
|
15
16
|
export * from "./patternCompile.js";
|
package/out/patterns/init.d.ts
CHANGED
|
@@ -4,6 +4,6 @@ import type { InitState } from "./initState.js";
|
|
|
4
4
|
* Yarn reads `package.json` to find `main` and `bin` values,
|
|
5
5
|
* so it can forcefully include them.
|
|
6
6
|
*
|
|
7
|
-
* @since 0.
|
|
7
|
+
* @since 0.11.0
|
|
8
8
|
*/
|
|
9
|
-
export type
|
|
9
|
+
export type InitCb = (options: InitState, cb: (err?: Error | null) => void) => void;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Target } from "../targets/target.js";
|
|
2
2
|
import type { FsAdapter } from "../types.js";
|
|
3
|
-
import type { MatcherContext } from "./matcherContext.js";
|
|
4
3
|
/**
|
|
5
4
|
* Used in {@link IgnoresOptions}.
|
|
6
5
|
*
|
|
@@ -17,12 +16,6 @@ export interface InitState {
|
|
|
17
16
|
* @since 0.6.0
|
|
18
17
|
*/
|
|
19
18
|
cwd: string;
|
|
20
|
-
/**
|
|
21
|
-
* The context to populate.
|
|
22
|
-
*
|
|
23
|
-
* @since 0.6.0
|
|
24
|
-
*/
|
|
25
|
-
ctx: MatcherContext;
|
|
26
19
|
/**
|
|
27
20
|
* The target implementation.
|
|
28
21
|
*
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type { MatcherContext } from "./matcherContext.js";
|
|
2
1
|
import { type Source } from "./source.js";
|
|
3
2
|
/**
|
|
4
3
|
* Extracts and compiles patterns from the file.
|
|
5
4
|
*
|
|
6
5
|
* @since 0.6.0
|
|
7
6
|
*/
|
|
8
|
-
export declare function extractJsrJson(source: Source, content: Buffer
|
|
7
|
+
export declare function extractJsrJson(source: Source, content: Buffer): void | Error;
|
|
9
8
|
/**
|
|
10
9
|
* Extracts and compiles patterns from the file.
|
|
11
10
|
*
|
|
@@ -13,4 +12,4 @@ export declare function extractJsrJson(source: Source, content: Buffer, ctx: Mat
|
|
|
13
12
|
*
|
|
14
13
|
* @since 0.6.0
|
|
15
14
|
*/
|
|
16
|
-
export declare function extractJsrJsonc(source: Source, content: Buffer
|
|
15
|
+
export declare function extractJsrJsonc(source: Source, content: Buffer): void | Error;
|