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.
Files changed (68) hide show
  1. package/README.md +118 -62
  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 +23 -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 +158 -75
  22. package/out/patterns/matcherStream.d.ts +30 -11
  23. package/out/patterns/matcherStream.js +70 -25
  24. package/out/patterns/packagejson.d.ts +2 -2
  25. package/out/patterns/packagejson.js +11 -14
  26. package/out/patterns/patternCompile.js +48 -19
  27. package/out/patterns/patternList.d.ts +12 -6
  28. package/out/patterns/patternList.js +8 -4
  29. package/out/patterns/resolveSources.d.ts +22 -5
  30. package/out/patterns/resolveSources.js +153 -97
  31. package/out/patterns/resource.d.ts +16 -0
  32. package/out/patterns/resource.js +1 -0
  33. package/out/patterns/rule.d.ts +63 -9
  34. package/out/patterns/rule.js +101 -66
  35. package/out/patterns/source.d.ts +9 -17
  36. package/out/scan.d.ts +11 -3
  37. package/out/scan.js +16 -4
  38. package/out/scanCb.d.ts +16 -0
  39. package/out/scanCb.js +73 -0
  40. package/out/scanParallel.d.ts +18 -0
  41. package/out/scanParallel.js +146 -0
  42. package/out/stream.d.ts +6 -1
  43. package/out/stream.js +7 -2
  44. package/out/targets/bun.js +43 -36
  45. package/out/targets/deno.js +25 -23
  46. package/out/targets/git.js +3 -3
  47. package/out/targets/jsr.js +25 -23
  48. package/out/targets/jsrManifest.d.ts +8 -7
  49. package/out/targets/jsrManifest.js +40 -9
  50. package/out/targets/npm.js +30 -23
  51. package/out/targets/npmManifest.d.ts +18 -46
  52. package/out/targets/npmManifest.js +96 -23
  53. package/out/targets/target.d.ts +8 -16
  54. package/out/targets/vsce.js +20 -27
  55. package/out/targets/vsceManifest.d.ts +7 -0
  56. package/out/targets/vsceManifest.js +18 -0
  57. package/out/targets/yarn.js +48 -39
  58. package/out/targets/yarnClassic.js +20 -18
  59. package/out/types.d.ts +8 -7
  60. package/out/unixify.d.ts +1 -1
  61. package/out/unixify.js +40 -21
  62. package/out/walk.d.ts +43 -4
  63. package/out/walk.js +146 -84
  64. package/package.json +27 -23
  65. package/out/getDepth.d.ts +0 -4
  66. package/out/getDepth.js +0 -21
  67. package/out/opendir.d.ts +0 -3
  68. package/out/opendir.js +0 -22
package/README.md CHANGED
@@ -1,27 +1,52 @@
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-v-18-or-later](https://img.shields.io/badge/node->=18-salad?repo=Mopsgamer/view-ignored)
7
+ [![speed-fast](https://img.shields.io/badge/speed-fast-salad?repo=Mopsgamer/view-ignored)](https://github.com/Mopsgamer/view-ignored/tree/main/benchmarks)
8
+
9
+ [![github issues](https://img.shields.io/github/issues/Mopsgamer/view-ignored.svg)](https://github.com/Mopsgamer/view-ignored/issues)
10
+ [![github](https://img.shields.io/github/stars/Mopsgamer/view-ignored.svg)](https://github.com/Mopsgamer/view-ignored)
7
11
 
8
12
  Retrieve list of files ignored/included
9
- by Git, NPM, Yarn, JSR, VSCE or other tools.
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
- ## Requirements
27
+ and more!
12
28
 
13
- Node.js 18 or later
29
+ [![issues](https://img.shields.io/github/issues-search?query=repo%3AMopsgamer%2Fview-ignored%20label%3Atargets%20type%3Aissue&label=issues)](https://github.com/search?q=repo%3AMopsgamer%2Fview-ignored+label%3Atargets+type%3Aissue&type=issues&query=repo%3AMopsgamer%2Fview-ignored+label%3Atargets)
30
+ [![suggest](https://img.shields.io/badge/suggest-salad?repo=Mopsgamer/view-ignored)](https://github.com/Mopsgamer/view-ignored/issues/new)
31
+ [![details](https://img.shields.io/badge/details-gray?repo=Mopsgamer/view-ignored)](#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
- - **TypeScript.** Written in TypeScript with type definitions included.
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
- - **Easy-to-modify.** Well-written and MIT-licensed.
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 = await vign.scanStream({ target })
104
-
105
- stream.on("dirent", console.log)
106
- stream.on("end", (ctx) => {
107
- ctx.paths.has(".git/HEAD") // false
108
- ctx.paths.has("node_modules/") // false
109
- ctx.paths.has("package.json") // true
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
- - Reads `.gitignore` and `.git/info/exclude` but does not consider global settings.
142
- - Starts searching from `/`.
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
- - Expecting to be compatible with PNPM, and others.
146
- - Validates `package.json`.
147
- - Reads `package.json` `files` field, `.npmignore` and `.gitignore`.
148
- - Starts searching from `.` (current working directory).
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
- - Validates `package.json`.
156
- - Reads `package.json` `files` field, `.npmignore` and `.gitignore`.
157
- - Requires `package.json`: includes paths from `main`, `module`, `browser` and `bin`.
158
- - Starts searching from `.` (current working directory).
159
- - `YarnClassic` is available. ([implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/yarnClassic.ts))
160
- - VSCE ([implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/vsce.ts))
161
- - Validates `package.json`.
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
- - Validates and reads `jsr.json(c)` `include` and `exclude` fields.
167
- - Starts searching from `.` (current working directory).
168
- - Deno ([implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/deno.ts))
169
- - Validates and reads `jsr.json(c)` and `deno.json(c)` `include` and `exclude` fields.
170
- - Starts searching from `.` (current working directory).
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
@@ -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(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
  }
@@ -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,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
- * Checks whether a given entry path should be ignored based on its patterns.
36
+ * @see {@link IgnoresCb}
18
37
  *
19
- * @see {@link resolveSources}
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 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;