view-ignored 0.10.1 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +116 -66
  2. package/out/browser.d.ts +1 -0
  3. package/out/browser.js +1 -0
  4. package/out/browser_scan.d.ts +1 -3
  5. package/out/browser_scan.js +11 -46
  6. package/out/browser_stream.d.ts +6 -1
  7. package/out/browser_stream.js +6 -1
  8. package/out/index.d.ts +1 -0
  9. package/out/index.js +1 -0
  10. package/out/patterns/extractor.d.ts +7 -7
  11. package/out/patterns/gitignore.d.ts +2 -2
  12. package/out/patterns/gitignore.js +14 -6
  13. package/out/patterns/ignores.d.ts +17 -8
  14. package/out/patterns/index.d.ts +1 -0
  15. package/out/patterns/index.js +1 -0
  16. package/out/patterns/init.d.ts +2 -2
  17. package/out/patterns/initState.d.ts +0 -7
  18. package/out/patterns/jsrjson.d.ts +2 -3
  19. package/out/patterns/jsrjson.js +25 -38
  20. package/out/patterns/matcherContext.d.ts +12 -9
  21. package/out/patterns/matcherContextPatch.js +153 -73
  22. package/out/patterns/matcherStream.d.ts +19 -59
  23. package/out/patterns/matcherStream.js +75 -25
  24. package/out/patterns/matcherStreamTypes.d.ts +65 -0
  25. package/out/patterns/matcherStreamTypes.js +1 -0
  26. package/out/patterns/packagejson.d.ts +2 -2
  27. package/out/patterns/packagejson.js +11 -14
  28. package/out/patterns/patternCompile.js +35 -37
  29. package/out/patterns/patternList.d.ts +6 -2
  30. package/out/patterns/patternList.js +8 -3
  31. package/out/patterns/resolveSources.d.ts +22 -5
  32. package/out/patterns/resolveSources.js +153 -97
  33. package/out/patterns/resource.d.ts +16 -0
  34. package/out/patterns/resource.js +1 -0
  35. package/out/patterns/rule.d.ts +59 -11
  36. package/out/patterns/rule.js +101 -64
  37. package/out/patterns/source.d.ts +9 -17
  38. package/out/scan.d.ts +11 -3
  39. package/out/scan.js +16 -4
  40. package/out/scanCb.d.ts +16 -0
  41. package/out/scanCb.js +73 -0
  42. package/out/scanParallel.d.ts +18 -0
  43. package/out/scanParallel.js +146 -0
  44. package/out/stream.d.ts +6 -1
  45. package/out/stream.js +7 -2
  46. package/out/targets/bun.js +43 -36
  47. package/out/targets/deno.js +25 -23
  48. package/out/targets/git.js +3 -3
  49. package/out/targets/jsr.js +25 -23
  50. package/out/targets/jsrManifest.d.ts +8 -7
  51. package/out/targets/jsrManifest.js +40 -9
  52. package/out/targets/npm.js +30 -23
  53. package/out/targets/npmManifest.d.ts +18 -46
  54. package/out/targets/npmManifest.js +96 -23
  55. package/out/targets/target.d.ts +8 -16
  56. package/out/targets/vsce.js +20 -27
  57. package/out/targets/vsceManifest.d.ts +7 -0
  58. package/out/targets/vsceManifest.js +18 -0
  59. package/out/targets/yarn.js +48 -39
  60. package/out/targets/yarnClassic.js +20 -18
  61. package/out/types.d.ts +8 -7
  62. package/out/unixify.d.ts +1 -1
  63. package/out/unixify.js +40 -21
  64. package/out/walk.d.ts +42 -4
  65. package/out/walk.js +146 -92
  66. package/package.json +42 -27
  67. package/out/getDepth.d.ts +0 -4
  68. package/out/getDepth.js +0 -21
  69. package/out/opendir.d.ts +0 -3
  70. package/out/opendir.js +0 -28
package/README.md CHANGED
@@ -1,29 +1,46 @@
1
- # view-ignored
1
+ <div align="center">
2
+ <h1>view-ignored</h1>
2
3
 
3
- [![npm version](https://img.shields.io/npm/v/view-ignored.svg?style=flat)](https://www.npmjs.com/package/view-ignored)
4
- [![npm downloads](https://img.shields.io/npm/dm/view-ignored.svg?style=flat)](https://www.npmjs.com/package/view-ignored)
5
- [![github](https://img.shields.io/github/stars/Mopsgamer/view-ignored.svg?style=flat)](https://github.com/Mopsgamer/view-ignored)
6
- [![github issues](https://img.shields.io/github/issues/Mopsgamer/view-ignored.svg?style=flat)](https://github.com/Mopsgamer/view-ignored/issues)
4
+ [![npm-version](https://img.shields.io/npm/v/view-ignored.svg)](https://www.npmjs.com/package/view-ignored)
5
+ [![npm-downloads](https://img.shields.io/npm/dm/view-ignored.svg)](https://www.npmjs.com/package/view-ignored)
6
+ ![node-v20-or-later](https://img.shields.io/badge/node->=22-salad?repo=Mopsgamer/view-ignored.svg)
7
+ ![ts-v5-or-later](https://img.shields.io/badge/ts->=5.7-salad?repo=Mopsgamer/view-ignored)
8
+ [![speed-fast](https://img.shields.io/badge/speed-fast-salad?repo=Mopsgamer/view-ignored.svg)](https://github.com/Mopsgamer/view-ignored/tree/main/benchmarks)
7
9
 
8
10
  Retrieve list of files ignored/included
9
- by Git, NPM, Yarn, JSR, VSCE or other tools.
11
+ by Git, NPM, Yarn, JSR, Deno, Bun, VSCode extension CLI and other tools.
10
12
 
11
- ## Requirements
13
+ <img src="https://cdn.jsdelivr.net/gh/devicons/devicon@latest/icons/git/git-original.svg" width="32" height="32" alt="git" />
14
+ <img src="https://cdn.jsdelivr.net/gh/devicons/devicon@latest/icons/npm/npm-original-wordmark.svg" width="32" height="32" alt="npm" />
15
+ <img src="https://cdn.jsdelivr.net/gh/devicons/devicon@latest/icons/yarn/yarn-original.svg" width="32" height="32" alt="yarn" />
16
+ <img src="https://cdn.jsdelivr.net/gh/devicons/devicon@latest/icons/bun/bun-original.svg" width="32" height="32" alt="bun" />
17
+ <img src="https://unpkg.com/simple-icons@v14/icons/deno.svg" width="32" height="32" alt="deno" />
18
+ <img src="https://jsr.io/logo.svg" width="32" height="32" alt="jsr" />
19
+ <img src="https://cdn.jsdelivr.net/gh/devicons/devicon@latest/icons/vscode/vscode-original.svg" width="32" height="32" alt="vsce" />
12
20
 
13
- Node.js 18 or later
21
+ [![github-issues](https://img.shields.io/github/issues/Mopsgamer/view-ignored.svg)](https://github.com/Mopsgamer/view-ignored/issues)
22
+ [![github](https://img.shields.io/github/stars/Mopsgamer/view-ignored)](https://github.com/Mopsgamer/view-ignored)
23
+ [![issues-for-targets](https://img.shields.io/badge/issues-targets-blue)](https://github.com/search?q=repo%3AMopsgamer%2Fview-ignored+label%3Atargets+type%3Aissue&type=issues&query=repo%3AMopsgamer%2Fview-ignored+label%3Atargets)
24
+ [![suggest](https://img.shields.io/badge/suggest-salad?repo=Mopsgamer/view-ignored)](https://github.com/Mopsgamer/view-ignored/issues/new)
25
+ [![details](https://img.shields.io/badge/details-gray)](#targets)
26
+
27
+ </div>
14
28
 
15
29
  ## Highlights
16
30
 
31
+ <!-- - **Faster alternative for `npm-packlist`, `ignore-walk` and `ignore`.** -->
32
+
17
33
  - **Reader.** Get a list of included files using configuration file
18
34
  readers, not command-line wrappers.
35
+ - **Reasoning.** Understand why certain files are included or excluded.
36
+ - **Fast.** Optimized for performance with minimal memory overhead.
19
37
  - **Plugins.** Built-in [targets](#targets) for popular tools. Use custom
20
38
  targets by implementing/extending the `Target` interface.
21
39
  - **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.
40
+ - **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
41
  - **Abortable.** Full support for `AbortSignal` to cancel long-running scans instantly.
24
42
  - **Lightweight.** Minimal dependencies for fast performance and small bundle size.
25
- - **Easy-to-modify.** Well-written and MIT-licensed.
26
- - **Browser.** Can be bundled for browser use. See `ScanOptions.fs` and `import ... "view-ignored/browser"`.
43
+ - **Browser.** Can be bundled for browser use.
27
44
  - **Windows.** Windows paths are converted to Unix paths for compatibility with `memfs` based tests and browsers.
28
45
 
29
46
  > [!NOTE]
@@ -33,20 +50,41 @@ Node.js 18 or later
33
50
  > You can invert the results if you need the ignored files
34
51
  > by setting the `invert` option to `true`.
35
52
 
53
+ ## v1 Roadmap
54
+
55
+ - [x] Works for common use cases.
56
+ - [ ] Follow `.gitignore` spec. (`ignore` does.)
57
+ - [ ] Handle Git config.
58
+ - [ ] Include node_modules bundled dependencies correctly. Missing: NPM, Yarn + Classic, Bun, Deno, JSR.
59
+ - [ ] \*Move targets into separate packages (or not).
60
+ - [ ] Import and pass upstream source tests.
61
+ - [ ] \*Make it standard: NPM cli, VS Code file tree, VSCE, GitHub.
62
+ - [ ] \*Upstream to Bun, PNPM and other package managers.
63
+
64
+ <sub>\* - Optional.</sub>
65
+
66
+ ## Why this library exists?
67
+
68
+ 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.
69
+
36
70
  ## Usage
37
71
 
38
72
  ### Basic example
39
73
 
40
74
  ```ts
41
75
  import * as vign from "view-ignored"
76
+ // also available:
77
+ // "/scan", "/stream"
78
+ // "/browser", "/browser/scan", "/browser/stream"
42
79
  import { Git as target } from "view-ignored/targets"
80
+ import { RuleMatchKind } from "view-ignored/patterns"
43
81
 
44
82
  const ctx = await vign.scan({ target })
45
83
  ctx.paths.has(".git/HEAD") // false
46
84
  ctx.paths.has("src") // true
47
85
 
48
- const match = ctx.paths.get("src")
49
- if (match.kind === "external") {
86
+ const match = ctx.paths.get("src")!
87
+ if (match.kind === RuleMatchKind.external) {
50
88
  console.log(match.source.path) // ".gitignore"
51
89
  console.log(match.pattern) // "src/**"
52
90
  }
@@ -54,7 +92,11 @@ if (match.kind === "external") {
54
92
 
55
93
  ### Using custom target
56
94
 
95
+ This is the internal implementation for the Git target:
96
+
57
97
  ```ts
98
+ import type { Target } from "view-ignored/targets"
99
+
58
100
  import {
59
101
  type Extractor,
60
102
  extractGitignore,
@@ -63,8 +105,6 @@ import {
63
105
  type Rule,
64
106
  } from "view-ignored/patterns"
65
107
 
66
- import type { Target } from "view-ignored/targets"
67
-
68
108
  const extractors: Extractor[] = [
69
109
  {
70
110
  extract: extractGitignore,
@@ -78,38 +118,43 @@ const extractors: Extractor[] = [
78
118
 
79
119
  const internal: Rule[] = [
80
120
  ruleCompile({
121
+ compiled: null,
81
122
  excludes: true,
82
123
  pattern: [".git", ".DS_Store"],
83
- compiled: null,
84
124
  }),
85
125
  ]
86
126
 
87
- export const Git: Target = {
88
- internalRules: internal,
127
+ export const Git: Target = <Target>{
89
128
  extractors,
90
- root: "/",
91
129
  // TODO: Git should read configs
92
- init() {},
93
130
  ignores: ruleTest,
131
+ internalRules: internal,
132
+ root: "/",
94
133
  }
95
-
96
- const ctx = await vign.scan({ target })
97
134
  ```
98
135
 
99
136
  ### Streaming results
100
137
 
101
138
  ```ts
102
139
  import * as vign from "view-ignored"
140
+ // or import * as vign from "view-ignored/stream"
103
141
  import { NPM as target } from "view-ignored/targets"
104
142
 
105
- const stream = await vign.scanStream({ target })
106
-
107
- stream.on("dirent", console.log)
108
- stream.on("end", (ctx) => {
109
- ctx.paths.has(".git/HEAD") // false
110
- ctx.paths.has("node_modules/") // false
111
- ctx.paths.has("package.json") // true
112
- })
143
+ const stream = vign.scanStream({ target })
144
+
145
+ stream.addEventListener("dirent", console.log)
146
+ stream.addEventListener(
147
+ "end",
148
+ ({ detail: ctx }) => {
149
+ ctx.paths.has(".git/HEAD")
150
+ // false
151
+ ctx.paths.has("node_modules/")
152
+ // false
153
+ ctx.paths.has("package.json")
154
+ // true
155
+ },
156
+ { once: true },
157
+ )
113
158
  stream.start() // important
114
159
  ```
115
160
 
@@ -120,60 +165,65 @@ use the browser submodule, which requires some additional options.
120
165
 
121
166
  ```ts
122
167
  import * as vign from "view-ignored/browser"
123
- // or view-ignored/browser/scan
168
+ // or "/browser/scan"
124
169
  import { Git as target } from "view-ignored/targets"
170
+ import { readFile, readdir } from "original-fs"
125
171
 
126
172
  export const cwd = process.cwd()
127
-
128
- const customFs = {
129
- promises: {
130
- opendir,
131
- readFile,
132
- },
133
- }
134
-
135
- vign.scan({ target, cwd, fs })
173
+ const customFs = { readFile, readdir }
174
+ await vign.scan({ cwd, fs: customFs, target })
136
175
  ```
137
176
 
138
177
  ## Targets
139
178
 
140
179
  The following built-in scanners are available:
141
180
 
142
- - Git ([implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/git.ts))
143
- - Reads `.gitignore` and `.git/info/exclude` but does not consider global settings.
144
- - Starts searching from `/`.
181
+ - Git ([our implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/git.ts))
182
+ - `view-ignored` handles Git-specific ignoring almost identically to Git: does not consider config.
183
+ - Reads `.gitignore` and `.git/info/exclude`.
184
+ - Searches from `/`. (system's root)
145
185
  - 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
- - Expecting to be compatible with PNPM, and others.
148
- - Validates `package.json`.
149
- - Reads `package.json` `files` field, `.npmignore` and `.gitignore`.
150
- - Starts searching from `.` (current working directory).
186
+ - NPM ([our implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/npm.ts))
187
+ - `view-ignored` should be compatible with NPM, PNPM, and others.
188
+ - Reads `package.json` `files` field or `.npmignore` or `.gitignore`.
189
+ - Searches from `.` (current working directory).
190
+ - Requires `package.json`: `name`, `version`.
151
191
  - Check this scanner by running `npm pack --dry-run`.
152
- - Bun ([implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/bun.ts))
192
+ - Bun ([our implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/bun.ts))
153
193
  - Bun tries to mimic NPM, but that does not mean it behaves the same way.
194
+ - Searches from `.` (current working directory).
195
+ - Requires `package.json`: `name`, `version`. Forces paths from `bin` to be included.
154
196
  - 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
- - Validates `package.json`.
158
- - Reads `package.json` `files` field, `.npmignore` and `.gitignore`.
159
- - Requires `package.json`: includes paths from `main`, `module`, `browser` and `bin`.
160
- - Starts searching from `.` (current working directory).
161
- - `YarnClassic` is available. ([implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/yarnClassic.ts))
162
- - VSCE ([implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/vsce.ts))
163
- - Validates `package.json`.
164
- - Reads `package.json` `files` field, `.vscodeignore` and `.gitignore`.
165
- - Starts searching from `.` (current working directory).
197
+ - Yarn ([our implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/yarn.ts))
198
+ - Modern Berry and ZPM behavior. `YarnClassic` is available. ([our implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/yarnClassic.ts))
199
+ - Reads `package.json` `files` field or `.npmignore` or `.gitignore`.
200
+ - Searches from `.` (current working directory).
201
+ - Requires `package.json`: `name`, `version`. Forces paths from `main`, `module`, `browser` and `bin` to be included.
202
+ - VSCE ([our implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/vsce.ts))
203
+ - Reads `package.json` `files` field or `.vscodeignore` or `.gitignore`.
204
+ - Searches from `.` (current working directory).
205
+ - Requires `package.json`: `name`, `version`, `engines.vscode`.
166
206
  - Check this scanner by running `vsce ls`.
167
- - JSR ([implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/jsr.ts))
168
- - Validates and reads `jsr.json(c)` `include` and `exclude` fields.
169
- - Starts searching from `.` (current working directory).
170
- - Deno ([implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/deno.ts))
171
- - Validates and reads `jsr.json(c)` and `deno.json(c)` `include` and `exclude` fields.
172
- - Starts searching from `.` (current working directory).
207
+ - JSR ([our implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/jsr.ts))
208
+ - Searches from `.` (current working directory).
209
+ - Requires `jsr.json` or `jsr.jsonc`.
210
+ - Validates `publish.include` and `publish.exclude` or `include` and `exclude` fields.
211
+ - Deno ([our implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/deno.ts))
212
+ - Searches from `.` (current working directory).
213
+ - Requires `jsr.json` or `jsr.jsonc` or `deno.json` or `deno.jsonc`.
214
+ - Validates `publish.include` and `publish.exclude` or `include` and `exclude` fields.
173
215
 
174
216
  ## See also
175
217
 
218
+ - There are references in our implementations.
176
219
  - https://jsr.io/@m234/path - Utility to sort, convert and format paths.
220
+ - https://github.com/git/git/blob/master/wildmatch.c - The original wildmatch implementation.
221
+ - https://npmx.dev/package/ignore-walk - A Node.js module for walking directories while respecting ignore files. (It does it incorrectly for Git).
222
+ - https://npmx.dev/package/npm-packlist - A Node.js module for listing files to be included in an npm package. (Heavy)
223
+
224
+ ## Benchmarks
225
+
226
+ See [benchmarks directory](https://github.com/Mopsgamer/view-ignored/tree/main/benchmarks).
177
227
 
178
228
  ## License
179
229
 
package/out/browser.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { scan } from "./browser_scan.js";
2
+ export { scanCb } from "./scanCb.js";
2
3
  export { scanStream as stream } from "./browser_stream.js";
3
4
  export type * from "./types.js";
package/out/browser.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export { scan } from "./browser_scan.js";
2
+ export { scanCb } from "./scanCb.js";
2
3
  export { scanStream as stream } from "./browser_stream.js";
@@ -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.
@@ -1,13 +1,9 @@
1
- import { opendir } from "./opendir.js";
2
- import { unixify, join } from "./unixify.js";
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 { target, cwd, within = ".", invert = false, depth: maxDepth = Infinity, signal = null, fastDepth = false, fastInternal = false, fs, } = options;
19
- if (maxDepth < 0) {
20
- throw new TypeError("Depth must be a non-negative integer");
21
- }
22
- const ctx = {
23
- paths: new Map(),
24
- external: new Map(),
25
- failed: [],
26
- depthPaths: new Map(),
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
  }
@@ -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
- * @see {@link browserScan}
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
  */
@@ -1,6 +1,11 @@
1
1
  import { MatcherStream } from "./patterns/matcherStream.js";
2
2
  /**
3
- * @see {@link browserScan}
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
@@ -1,3 +1,4 @@
1
1
  export { scan } from "./scan.js";
2
+ export { scanCb } from "./scanCb.js";
2
3
  export { scanStream } from "./stream.js";
3
4
  export type * from "./types.js";
package/out/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export { scan } from "./scan.js";
2
+ export { scanCb } from "./scanCb.js";
2
3
  export { scanStream } from "./stream.js";
@@ -1,18 +1,18 @@
1
1
  import type { Target } from "../targets/target.js";
2
2
  import type { FsAdapter } from "../types.js";
3
- import type { MatcherContext } from "./matcherContext.js";
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 `"none"` returned or throwed, will skip the extractor.
8
+ * If `null` returned or throwed, will skip the extractor.
9
9
  *
10
- * @see {@link Source.pattern} for more details.
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, ctx: MatcherContext) => void | "none";
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 context to modify.
56
+ * The associated resource.
57
57
  *
58
- * @since 0.6.0
58
+ * @since 0.11.0
59
59
  */
60
- ctx: MatcherContext;
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.pattern) {
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.pattern) {
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
- for (let line of content.toString().split("\n")) {
34
- line = line.trim();
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.substring(-cdx);
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.pattern.push(include, exclude);
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 Ignores}.
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
- * Checks whether a given entry path should be ignored based on its patterns.
36
+ * @see {@link IgnoresCb}
24
37
  *
25
- * @see {@link resolveSources}
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 Ignores = (options: IgnoresOptions) => Promise<RuleMatch>;
40
+ export type IgnoresCb = (options: IgnoresOptions, cb: (err: Error | null, match: RuleMatch) => void) => void;
@@ -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";
@@ -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";
@@ -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.8.0
7
+ * @since 0.11.0
8
8
  */
9
- export type Init = (options: InitState) => Promise<void>;
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, ctx: MatcherContext): void;
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, ctx: MatcherContext): void;
15
+ export declare function extractJsrJsonc(source: Source, content: Buffer): void | Error;