view-ignored 0.10.1 → 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 +116 -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 +17 -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 +153 -73
- 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 +35 -37
- package/out/patterns/patternList.d.ts +6 -2
- package/out/patterns/patternList.js +8 -3
- 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 +59 -11
- package/out/patterns/rule.js +101 -64
- 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 +42 -4
- package/out/walk.js +146 -92
- package/package.json +25 -22
- 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 -28
package/README.md
CHANGED
|
@@ -1,29 +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.
|
|
22
|
-
- **Execution Control.** Use `fastDepth` and `fastInternal` options to fine-tune traversal depth and skip unnecessary directory checks.
|
|
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.
|
|
23
47
|
- **Abortable.** Full support for `AbortSignal` to cancel long-running scans instantly.
|
|
24
48
|
- **Lightweight.** Minimal dependencies for fast performance and small bundle size.
|
|
25
|
-
- **
|
|
26
|
-
- **Browser.** Can be bundled for browser use. See `ScanOptions.fs` and `import ... "view-ignored/browser"`.
|
|
49
|
+
- **Browser.** Can be bundled for browser use.
|
|
27
50
|
- **Windows.** Windows paths are converted to Unix paths for compatibility with `memfs` based tests and browsers.
|
|
28
51
|
|
|
29
52
|
> [!NOTE]
|
|
@@ -33,12 +56,32 @@ Node.js 18 or later
|
|
|
33
56
|
> You can invert the results if you need the ignored files
|
|
34
57
|
> by setting the `invert` option to `true`.
|
|
35
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
|
+
|
|
36
76
|
## Usage
|
|
37
77
|
|
|
38
78
|
### Basic example
|
|
39
79
|
|
|
40
80
|
```ts
|
|
41
81
|
import * as vign from "view-ignored"
|
|
82
|
+
// also available:
|
|
83
|
+
// "/scan", "/stream"
|
|
84
|
+
// "/browser", "/browser/scan", "/browser/stream"
|
|
42
85
|
import { Git as target } from "view-ignored/targets"
|
|
43
86
|
|
|
44
87
|
const ctx = await vign.scan({ target })
|
|
@@ -54,7 +97,11 @@ if (match.kind === "external") {
|
|
|
54
97
|
|
|
55
98
|
### Using custom target
|
|
56
99
|
|
|
100
|
+
This is the internal implementation for the Git target:
|
|
101
|
+
|
|
57
102
|
```ts
|
|
103
|
+
import type { Target } from "view-ignored/targets"
|
|
104
|
+
|
|
58
105
|
import {
|
|
59
106
|
type Extractor,
|
|
60
107
|
extractGitignore,
|
|
@@ -63,8 +110,6 @@ import {
|
|
|
63
110
|
type Rule,
|
|
64
111
|
} from "view-ignored/patterns"
|
|
65
112
|
|
|
66
|
-
import type { Target } from "view-ignored/targets"
|
|
67
|
-
|
|
68
113
|
const extractors: Extractor[] = [
|
|
69
114
|
{
|
|
70
115
|
extract: extractGitignore,
|
|
@@ -78,38 +123,43 @@ const extractors: Extractor[] = [
|
|
|
78
123
|
|
|
79
124
|
const internal: Rule[] = [
|
|
80
125
|
ruleCompile({
|
|
126
|
+
compiled: null,
|
|
81
127
|
excludes: true,
|
|
82
128
|
pattern: [".git", ".DS_Store"],
|
|
83
|
-
compiled: null,
|
|
84
129
|
}),
|
|
85
130
|
]
|
|
86
131
|
|
|
87
|
-
export const Git: Target = {
|
|
88
|
-
internalRules: internal,
|
|
132
|
+
export const Git: Target = <Target>{
|
|
89
133
|
extractors,
|
|
90
|
-
root: "/",
|
|
91
134
|
// TODO: Git should read configs
|
|
92
|
-
init() {},
|
|
93
135
|
ignores: ruleTest,
|
|
136
|
+
internalRules: internal,
|
|
137
|
+
root: "/",
|
|
94
138
|
}
|
|
95
|
-
|
|
96
|
-
const ctx = await vign.scan({ target })
|
|
97
139
|
```
|
|
98
140
|
|
|
99
141
|
### Streaming results
|
|
100
142
|
|
|
101
143
|
```ts
|
|
102
144
|
import * as vign from "view-ignored"
|
|
145
|
+
// or import * as vign from "view-ignored/stream"
|
|
103
146
|
import { NPM as target } from "view-ignored/targets"
|
|
104
147
|
|
|
105
|
-
const stream =
|
|
106
|
-
|
|
107
|
-
stream.
|
|
108
|
-
stream.
|
|
109
|
-
|
|
110
|
-
ctx
|
|
111
|
-
|
|
112
|
-
|
|
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
|
+
)
|
|
113
163
|
stream.start() // important
|
|
114
164
|
```
|
|
115
165
|
|
|
@@ -124,14 +174,7 @@ import * as vign from "view-ignored/browser"
|
|
|
124
174
|
import { Git as target } from "view-ignored/targets"
|
|
125
175
|
|
|
126
176
|
export const cwd = process.cwd()
|
|
127
|
-
|
|
128
|
-
const customFs = {
|
|
129
|
-
promises: {
|
|
130
|
-
opendir,
|
|
131
|
-
readFile,
|
|
132
|
-
},
|
|
133
|
-
}
|
|
134
|
-
|
|
177
|
+
const customFs = { readdir, readFile }
|
|
135
178
|
vign.scan({ target, cwd, fs })
|
|
136
179
|
```
|
|
137
180
|
|
|
@@ -139,41 +182,52 @@ vign.scan({ target, cwd, fs })
|
|
|
139
182
|
|
|
140
183
|
The following built-in scanners are available:
|
|
141
184
|
|
|
142
|
-
- Git ([implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/git.ts))
|
|
143
|
-
-
|
|
144
|
-
-
|
|
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)
|
|
145
189
|
- Check this scanner by running `git ls-files --others --exclude-standard --cached`.
|
|
146
|
-
- NPM ([implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/npm.ts))
|
|
147
|
-
-
|
|
148
|
-
-
|
|
149
|
-
-
|
|
150
|
-
-
|
|
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`.
|
|
151
195
|
- Check this scanner by running `npm pack --dry-run`.
|
|
152
|
-
- 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))
|
|
153
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.
|
|
154
200
|
- Check this scanner by running `bun pm pack --dry-run`.
|
|
155
|
-
- Yarn ([implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/yarn.ts))
|
|
156
|
-
- Modern Berry behavior.
|
|
157
|
-
-
|
|
158
|
-
-
|
|
159
|
-
- Requires `package.json`:
|
|
160
|
-
|
|
161
|
-
- `
|
|
162
|
-
-
|
|
163
|
-
-
|
|
164
|
-
- Reads `package.json` `files` field, `.vscodeignore` and `.gitignore`.
|
|
165
|
-
- 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`.
|
|
166
210
|
- Check this scanner by running `vsce ls`.
|
|
167
|
-
- JSR ([implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/jsr.ts))
|
|
168
|
-
-
|
|
169
|
-
-
|
|
170
|
-
-
|
|
171
|
-
|
|
172
|
-
-
|
|
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.
|
|
173
219
|
|
|
174
220
|
## See also
|
|
175
221
|
|
|
222
|
+
- There are references in our implementations.
|
|
176
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).
|
|
177
231
|
|
|
178
232
|
## License
|
|
179
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({ ctx, cwd: normalCwd, fs, signal, target }, from, (entry, parentPath, path) => {
|
|
47
|
-
return walkIncludes({
|
|
48
|
-
path,
|
|
49
|
-
entry,
|
|
50
|
-
parentPath,
|
|
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,6 +13,18 @@ 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;
|
|
15
28
|
/**
|
|
16
29
|
* Result of the `dirname(entry)` call.
|
|
17
30
|
*
|
|
@@ -20,12 +33,8 @@ export interface IgnoresOptions extends InitState {
|
|
|
20
33
|
parentPath: string;
|
|
21
34
|
}
|
|
22
35
|
/**
|
|
23
|
-
*
|
|
36
|
+
* @see {@link IgnoresCb}
|
|
24
37
|
*
|
|
25
|
-
* @
|
|
26
|
-
* @see {@link ruleTest}
|
|
27
|
-
* @see {@link https://github.com/Mopsgamer/view-ignored/tree/main/src/targets} for usage examples.
|
|
28
|
-
*
|
|
29
|
-
* @since 0.6.0
|
|
38
|
+
* @since 0.11.0
|
|
30
39
|
*/
|
|
31
|
-
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;
|