view-ignored 0.5.2 → 0.7.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 (69) hide show
  1. package/README.md +98 -41
  2. package/out/browser.d.ts +3 -0
  3. package/out/browser.js +2 -0
  4. package/out/browser_scan.d.ts +20 -0
  5. package/out/browser_scan.js +59 -0
  6. package/out/browser_stream.d.ts +12 -0
  7. package/out/browser_stream.js +51 -0
  8. package/out/getDepth.d.ts +4 -0
  9. package/out/getDepth.js +21 -0
  10. package/out/index.d.ts +3 -1
  11. package/out/index.js +2 -1
  12. package/out/normalizeCwd.d.ts +1 -0
  13. package/out/normalizeCwd.js +4 -0
  14. package/out/opendir.d.ts +3 -0
  15. package/out/opendir.js +18 -0
  16. package/out/patterns/extractor.d.ts +80 -0
  17. package/out/patterns/extractor.js +1 -0
  18. package/out/patterns/gitignore.d.ts +9 -3
  19. package/out/patterns/gitignore.js +13 -20
  20. package/out/patterns/ignores.d.ts +19 -0
  21. package/out/patterns/ignores.js +1 -0
  22. package/out/patterns/index.d.ts +13 -4
  23. package/out/patterns/index.js +13 -4
  24. package/out/patterns/jsrjson.d.ts +16 -4
  25. package/out/patterns/jsrjson.js +30 -13
  26. package/out/patterns/matcherContext.d.ts +71 -0
  27. package/out/patterns/matcherContext.js +1 -0
  28. package/out/patterns/matcherContextPatch.d.ts +16 -0
  29. package/out/patterns/matcherContextPatch.js +156 -0
  30. package/out/patterns/matcherStream.d.ts +64 -0
  31. package/out/patterns/matcherStream.js +9 -0
  32. package/out/patterns/packagejson.d.ts +9 -3
  33. package/out/patterns/packagejson.js +18 -7
  34. package/out/patterns/pattern.d.ts +44 -0
  35. package/out/patterns/pattern.js +21 -0
  36. package/out/patterns/patternMatcher.d.ts +23 -0
  37. package/out/patterns/patternMatcher.js +1 -0
  38. package/out/patterns/resolveSources.d.ts +34 -0
  39. package/out/patterns/resolveSources.js +135 -0
  40. package/out/patterns/signedPattern.d.ts +126 -0
  41. package/out/patterns/signedPattern.js +145 -0
  42. package/out/patterns/source.d.ts +57 -0
  43. package/out/patterns/source.js +20 -0
  44. package/out/patterns/stringCompile.d.ts +9 -0
  45. package/out/patterns/stringCompile.js +28 -0
  46. package/out/scan.d.ts +5 -37
  47. package/out/scan.js +8 -101
  48. package/out/stream.d.ts +9 -0
  49. package/out/stream.js +12 -0
  50. package/out/targets/git.d.ts +4 -1
  51. package/out/targets/git.js +26 -17
  52. package/out/targets/index.d.ts +6 -6
  53. package/out/targets/index.js +6 -6
  54. package/out/targets/jsr.d.ts +4 -1
  55. package/out/targets/jsr.js +34 -20
  56. package/out/targets/npm.d.ts +4 -1
  57. package/out/targets/npm.js +47 -40
  58. package/out/targets/target.d.ts +17 -3
  59. package/out/targets/vsce.d.ts +4 -1
  60. package/out/targets/vsce.js +30 -19
  61. package/out/targets/yarn.d.ts +4 -1
  62. package/out/targets/yarn.js +53 -43
  63. package/out/types.d.ts +116 -0
  64. package/out/types.js +1 -0
  65. package/out/walk.d.ts +12 -2
  66. package/out/walk.js +98 -13
  67. package/package.json +113 -78
  68. package/out/patterns/matcher.d.ts +0 -114
  69. package/out/patterns/matcher.js +0 -137
@@ -0,0 +1,9 @@
1
+ import type { MatcherStream } from "./patterns/matcherStream.js";
2
+ import type { ScanOptions } from "./types.js";
3
+ export type * from "./types.js";
4
+ /**
5
+ * @see {@link scan}
6
+ *
7
+ * @since 0.6.0
8
+ */
9
+ export declare function scanStream(options: ScanOptions): MatcherStream;
package/out/stream.js ADDED
@@ -0,0 +1,12 @@
1
+ import * as nodefs from "node:fs";
2
+ import * as process from "node:process";
3
+ import { scanStream as browserStream } from "./browser_stream.js";
4
+ /**
5
+ * @see {@link scan}
6
+ *
7
+ * @since 0.6.0
8
+ */
9
+ export function scanStream(options) {
10
+ const { cwd = process.cwd(), fs = nodefs } = options;
11
+ return browserStream({ fs, cwd, ...options });
12
+ }
@@ -1,2 +1,5 @@
1
- import type { Target } from './target.js';
1
+ import type { Target } from "./target.js";
2
+ /**
3
+ * @since 0.6.0
4
+ */
2
5
  export declare const Git: Target;
@@ -1,22 +1,31 @@
1
- import { signedPatternIgnores, findAndExtract } from '../patterns/matcher.js';
2
- import { extractGitignore } from '../patterns/gitignore.js';
3
- const gitSources = ['.gitignore'];
4
- const gitSourceMap = new Map([
5
- ['.gitignore', extractGitignore],
6
- ]);
7
- const gitPattern = {
8
- exclude: [
9
- '.git',
10
- '.DS_Store',
11
- ],
1
+ import { extractGitignore, signedPatternIgnores, signedPatternCompile, } from "../patterns/index.js";
2
+ const extractors = [
3
+ {
4
+ extract: extractGitignore,
5
+ path: ".gitignore",
6
+ },
7
+ {
8
+ extract: extractGitignore,
9
+ path: ".git/info/exclude",
10
+ },
11
+ ];
12
+ const internal = {
13
+ exclude: [".git", ".DS_Store"],
12
14
  include: [],
15
+ compiled: null,
13
16
  };
17
+ signedPatternCompile(internal);
18
+ /**
19
+ * @since 0.6.0
20
+ */
14
21
  export const Git = {
15
- async matcher(entry, isDir, ctx) {
16
- if (isDir) {
17
- await findAndExtract(entry, gitSources, gitSourceMap, ctx);
18
- return true;
19
- }
20
- return await signedPatternIgnores(gitPattern, entry, gitSources, gitSourceMap, ctx);
22
+ extractors,
23
+ ignores(o) {
24
+ return signedPatternIgnores({
25
+ ...o,
26
+ internal,
27
+ root: "/",
28
+ target: Git,
29
+ });
21
30
  },
22
31
  };
@@ -1,6 +1,6 @@
1
- export * from './git.js';
2
- export * from './jsr.js';
3
- export * from './npm.js';
4
- export * from './target.js';
5
- export * from './vsce.js';
6
- export * from './yarn.js';
1
+ export * from "./git.js";
2
+ export * from "./jsr.js";
3
+ export * from "./npm.js";
4
+ export * from "./target.js";
5
+ export * from "./vsce.js";
6
+ export * from "./yarn.js";
@@ -1,6 +1,6 @@
1
- export * from './git.js';
2
- export * from './jsr.js';
3
- export * from './npm.js';
4
- export * from './target.js';
5
- export * from './vsce.js';
6
- export * from './yarn.js';
1
+ export * from "./git.js";
2
+ export * from "./jsr.js";
3
+ export * from "./npm.js";
4
+ export * from "./target.js";
5
+ export * from "./vsce.js";
6
+ export * from "./yarn.js";
@@ -1,2 +1,5 @@
1
- import type { Target } from './target.js';
1
+ import type { Target } from "./target.js";
2
+ /**
3
+ * @since 0.6.0
4
+ */
2
5
  export declare const JSR: Target;
@@ -1,25 +1,39 @@
1
- import { signedPatternIgnores, findAndExtract } from '../patterns/matcher.js';
2
- import { extractJsrJson, extractJsrJsonc } from '../patterns/jsrjson.js';
3
- const jsrSources = ['deno.json', 'deno.jsonc', 'jsr.json', 'jsr.jsonc'];
4
- const jsrSourceMap = new Map([
5
- ['deno.json', extractJsrJson],
6
- ['deno.jsonc', extractJsrJsonc],
7
- ['jsr.json', extractJsrJson],
8
- ['jsr.jsonc', extractJsrJsonc],
9
- ]);
10
- const vscePattern = {
11
- exclude: [
12
- '.git',
13
- '.DS_Store',
14
- ],
1
+ import { signedPatternIgnores, signedPatternCompile, extractJsrJson, extractJsrJsonc, } from "../patterns/index.js";
2
+ const extractors = [
3
+ {
4
+ extract: extractJsrJson,
5
+ path: "deno.json",
6
+ },
7
+ {
8
+ extract: extractJsrJsonc,
9
+ path: "deno.jsonc",
10
+ },
11
+ {
12
+ extract: extractJsrJson,
13
+ path: "jsr.json",
14
+ },
15
+ {
16
+ extract: extractJsrJsonc,
17
+ path: "jsr.jsonc",
18
+ },
19
+ ];
20
+ const internal = {
21
+ exclude: [".git", ".DS_Store"],
15
22
  include: [],
23
+ compiled: null,
16
24
  };
25
+ signedPatternCompile(internal);
26
+ /**
27
+ * @since 0.6.0
28
+ */
17
29
  export const JSR = {
18
- async matcher(entry, isDir, ctx) {
19
- if (isDir) {
20
- await findAndExtract(entry, jsrSources, jsrSourceMap, ctx);
21
- return true;
22
- }
23
- return await signedPatternIgnores(vscePattern, entry, jsrSources, jsrSourceMap, ctx);
30
+ extractors,
31
+ ignores(o) {
32
+ return signedPatternIgnores({
33
+ ...o,
34
+ internal,
35
+ root: ".",
36
+ target: JSR,
37
+ });
24
38
  },
25
39
  };
@@ -1,2 +1,5 @@
1
- import type { Target } from './target.js';
1
+ import type { Target } from "./target.js";
2
+ /**
3
+ * @since 0.6.0
4
+ */
2
5
  export declare const NPM: Target;
@@ -1,46 +1,53 @@
1
- import { signedPatternIgnores, findAndExtract } from '../patterns/matcher.js';
2
- import { extractGitignore } from '../patterns/gitignore.js';
3
- import { extractPackageJson } from '../patterns/packagejson.js';
4
- const npmSources = ['package.json', '.npmignore', '.gitignore'];
5
- const npmSourceMap = new Map([
6
- ['package.json', extractPackageJson],
7
- ['.npmignore', extractGitignore],
8
- ['.gitignore', extractGitignore],
9
- ]);
10
- const npmPattern = {
1
+ import { signedPatternIgnores, signedPatternCompile, extractPackageJson, extractGitignore, } from "../patterns/index.js";
2
+ const extractors = [
3
+ {
4
+ extract: extractPackageJson,
5
+ path: "package.json",
6
+ },
7
+ {
8
+ extract: extractGitignore,
9
+ path: ".npmignore",
10
+ },
11
+ {
12
+ extract: extractGitignore,
13
+ path: ".gitignore",
14
+ },
15
+ ];
16
+ const internal = {
11
17
  exclude: [
12
- '.git',
13
- '.DS_Store',
14
- 'node_modules',
15
- '.*.swp',
16
- '._*',
17
- '.DS_Store',
18
- '.git',
19
- '.gitignore',
20
- '.hg',
21
- '.npmignore',
22
- '.npmrc',
23
- '.lock-wscript',
24
- '.svn',
25
- '.wafpickle-*',
26
- 'config.gypi',
27
- 'CVS',
28
- 'npm-debug.log',
29
- ],
30
- include: [
31
- 'bin',
32
- 'package.json',
33
- 'README*',
34
- 'LICENSE*',
35
- 'LICENCE*',
18
+ ".git",
19
+ ".DS_Store",
20
+ "node_modules",
21
+ ".*.swp",
22
+ "._*",
23
+ ".DS_Store",
24
+ ".git",
25
+ ".gitignore",
26
+ ".hg",
27
+ ".npmignore",
28
+ ".npmrc",
29
+ ".lock-wscript",
30
+ ".svn",
31
+ ".wafpickle-*",
32
+ "config.gypi",
33
+ "CVS",
34
+ "npm-debug.log",
36
35
  ],
36
+ include: ["bin", "package.json", "README*", "LICENSE*", "LICENCE*"],
37
+ compiled: null,
37
38
  };
39
+ signedPatternCompile(internal);
40
+ /**
41
+ * @since 0.6.0
42
+ */
38
43
  export const NPM = {
39
- async matcher(entry, isDir, ctx) {
40
- if (isDir) {
41
- await findAndExtract(entry, npmSources, npmSourceMap, ctx);
42
- return true;
43
- }
44
- return await signedPatternIgnores(npmPattern, entry, npmSources, npmSourceMap, ctx);
44
+ extractors,
45
+ ignores(o) {
46
+ return signedPatternIgnores({
47
+ ...o,
48
+ internal,
49
+ root: ".",
50
+ target: NPM,
51
+ });
45
52
  },
46
53
  };
@@ -1,10 +1,24 @@
1
- import type { PathChecker } from '../patterns/matcher.js';
1
+ import type { Extractor } from "../patterns/extractor.js";
2
+ import type { Ignores } from "../patterns/ignores.js";
2
3
  /**
3
- * Contains the matcher used for target scanning.
4
+ * Contains the matcher used for scanning.
5
+ *
6
+ * @since 0.6.0
4
7
  */
5
8
  export interface Target {
9
+ /**
10
+ * The set of extractors.
11
+ * Required for context-patching APIs (ctx add/remove path).
12
+ *
13
+ * @since 0.6.0
14
+ */
15
+ extractors: Extractor[];
6
16
  /**
7
17
  * Glob-pattern parser.
18
+ *
19
+ * @see {@link Ignores}
20
+ *
21
+ * @since 0.6.0
8
22
  */
9
- matcher: PathChecker;
23
+ ignores: Ignores;
10
24
  }
@@ -1,2 +1,5 @@
1
- import type { Target } from './target.js';
1
+ import type { Target } from "./target.js";
2
+ /**
3
+ * @since 0.6.0
4
+ */
2
5
  export declare const VSCE: Target;
@@ -1,24 +1,35 @@
1
- import { signedPatternIgnores, findAndExtract } from '../patterns/matcher.js';
2
- import { extractGitignore } from '../patterns/gitignore.js';
3
- import { extractPackageJson } from '../patterns/packagejson.js';
4
- const vsceSources = ['package.json', '.vscodeignore'];
5
- const vsceSourceMap = new Map([
6
- ['package.json', extractPackageJson],
7
- ['.vscodeignore', extractGitignore],
8
- ]);
9
- const vscePattern = {
10
- exclude: [
11
- '.git',
12
- '.DS_Store',
13
- ],
1
+ import { signedPatternIgnores, signedPatternCompile, extractPackageJson, extractGitignore, } from "../patterns/index.js";
2
+ const extractors = [
3
+ {
4
+ extract: extractPackageJson,
5
+ path: "package.json",
6
+ },
7
+ {
8
+ extract: extractGitignore,
9
+ path: ".vscodeignore",
10
+ },
11
+ {
12
+ extract: extractGitignore,
13
+ path: ".gitignore",
14
+ },
15
+ ];
16
+ const internal = {
17
+ exclude: [".git", ".DS_Store"],
14
18
  include: [],
19
+ compiled: null,
15
20
  };
21
+ signedPatternCompile(internal);
22
+ /**
23
+ * @since 0.6.0
24
+ */
16
25
  export const VSCE = {
17
- async matcher(entry, isDir, ctx) {
18
- if (isDir) {
19
- await findAndExtract(entry, vsceSources, vsceSourceMap, ctx);
20
- return true;
21
- }
22
- return await signedPatternIgnores(vscePattern, entry, vsceSources, vsceSourceMap, ctx);
26
+ extractors,
27
+ ignores(o) {
28
+ return signedPatternIgnores({
29
+ ...o,
30
+ internal,
31
+ root: ".",
32
+ target: VSCE,
33
+ });
23
34
  },
24
35
  };
@@ -1,2 +1,5 @@
1
- import type { Target } from './target.js';
1
+ import type { Target } from "./target.js";
2
+ /**
3
+ * @since 0.6.0
4
+ */
2
5
  export declare const Yarn: Target;
@@ -1,49 +1,59 @@
1
- import { signedPatternIgnores, findAndExtract } from '../patterns/matcher.js';
2
- import { extractGitignore } from '../patterns/gitignore.js';
3
- import { extractPackageJson } from '../patterns/packagejson.js';
4
- const yarnSources = ['package.json', '.yarnignore', '.npmignore', '.gitignore'];
5
- const yarnSourceMap = new Map([
6
- ['package.json', extractPackageJson],
7
- ['.yarnignore', extractGitignore],
8
- ['.npmignore', extractGitignore],
9
- ['.gitignore', extractGitignore],
10
- ]);
11
- const yarnPattern = {
1
+ import { signedPatternIgnores, signedPatternCompile, extractPackageJson, extractGitignore, } from "../patterns/index.js";
2
+ const extractors = [
3
+ {
4
+ extract: extractPackageJson,
5
+ path: "package.json",
6
+ },
7
+ {
8
+ extract: extractGitignore,
9
+ path: ".yarnignore",
10
+ },
11
+ {
12
+ extract: extractGitignore,
13
+ path: ".npmignore",
14
+ },
15
+ {
16
+ extract: extractGitignore,
17
+ path: ".gitignore",
18
+ },
19
+ ];
20
+ const internal = {
12
21
  exclude: [
13
- '.git',
14
- '.DS_Store',
15
- 'node_modules',
16
- '.*.swp',
17
- '._*',
18
- '.DS_Store',
19
- '.git',
20
- '.gitignore',
21
- '.hg',
22
- '.npmignore',
23
- '.npmrc',
24
- '.lock-wscript',
25
- '.svn',
26
- '.wafpickle-*',
27
- 'config.gypi',
28
- 'CVS',
29
- 'npm-debug.log',
30
- '.yarnignore',
31
- '.yarnrc',
32
- ],
33
- include: [
34
- 'bin',
35
- 'package.json',
36
- 'README*',
37
- 'LICENSE*',
38
- 'LICENCE*',
22
+ ".git",
23
+ ".DS_Store",
24
+ "node_modules",
25
+ ".*.swp",
26
+ "._*",
27
+ ".DS_Store",
28
+ ".git",
29
+ ".gitignore",
30
+ ".hg",
31
+ ".npmignore",
32
+ ".npmrc",
33
+ ".lock-wscript",
34
+ ".svn",
35
+ ".wafpickle-*",
36
+ "config.gypi",
37
+ "CVS",
38
+ "npm-debug.log",
39
+ ".yarnignore",
40
+ ".yarnrc",
39
41
  ],
42
+ include: ["bin", "package.json", "README*", "LICENSE*", "LICENCE*"],
43
+ compiled: null,
40
44
  };
45
+ signedPatternCompile(internal);
46
+ /**
47
+ * @since 0.6.0
48
+ */
41
49
  export const Yarn = {
42
- async matcher(entry, isDir, ctx) {
43
- if (isDir) {
44
- await findAndExtract(entry, yarnSources, yarnSourceMap, ctx);
45
- return true;
46
- }
47
- return await signedPatternIgnores(yarnPattern, entry, yarnSources, yarnSourceMap, ctx);
50
+ extractors,
51
+ ignores(o) {
52
+ return signedPatternIgnores({
53
+ ...o,
54
+ internal,
55
+ root: ".",
56
+ target: Yarn,
57
+ });
48
58
  },
49
59
  };
package/out/types.d.ts ADDED
@@ -0,0 +1,116 @@
1
+ import type * as fs from "node:fs";
2
+ import type { Target } from "./targets/target.js";
3
+ /**
4
+ * Minimal FS implementation needed for `scan`, `scanStream`, and their browser versions.
5
+ *
6
+ * @since 0.6.0
7
+ */
8
+ export interface FsAdapter {
9
+ promises: {
10
+ opendir: typeof fs.promises.opendir;
11
+ readFile: typeof fs.promises.readFile;
12
+ };
13
+ }
14
+ /**
15
+ * Used in multiple methods, primarily `scan`, `scanStream`, and their browser versions.
16
+ *
17
+ * @since 0.6.0
18
+ */
19
+ export type ScanOptions = {
20
+ /**
21
+ * Provides the matcher to use for scanning.
22
+ *
23
+ * @since 0.6.0
24
+ */
25
+ target: Target;
26
+ /**
27
+ * Current working directory to start the scan from.
28
+ *
29
+ * @default `normalizeCwd(process.cwd())`
30
+ *
31
+ * @since 0.6.0
32
+ */
33
+ cwd?: string;
34
+ /**
35
+ * Limits the scan to a subdirectory of `cwd`.
36
+ * Traversal starts from this subdirectory, but returned paths
37
+ * remain relative to `cwd`, and ignore files from `cwd`
38
+ * are still applied.
39
+ *
40
+ * @default `"."`
41
+ *
42
+ * @since 0.6.0
43
+ */
44
+ within?: string;
45
+ /**
46
+ * If enabled, the scan will return files that are ignored by the target matcher.
47
+ *
48
+ * @default `false`
49
+ *
50
+ * @since 0.6.0
51
+ */
52
+ invert?: boolean;
53
+ /**
54
+ * Starting from depth `0` means you will see
55
+ * children of the current working directory.
56
+ *
57
+ * @default `Infinity`
58
+ *
59
+ * @since 0.6.0
60
+ */
61
+ depth?: number;
62
+ /**
63
+ * Return as soon as possible.
64
+ *
65
+ * @default `undefined`
66
+ *
67
+ * @since 0.6.0
68
+ */
69
+ signal?: AbortSignal | null;
70
+ /**
71
+ * Works together with {@link ScanOptions.depth}.
72
+ * If enabled, directories will be processed faster
73
+ * by skipping files after first match.
74
+ *
75
+ * This makes the scan faster but affects
76
+ * {@link MatcherContext.totalDirs},
77
+ * {@link MatcherContext.totalFiles},
78
+ * {@link MatcherContext.totalMatchedFiles}
79
+ * and {@link MatcherContext.depthPaths}.
80
+ *
81
+ * It's recommended to use this option unless you
82
+ * need precise statistics
83
+ *
84
+ * @default `false`
85
+ *
86
+ * @since 0.6.0
87
+ */
88
+ fastDepth?: boolean;
89
+ /**
90
+ * Enables skipping entire directories for internal matches.
91
+ * For example, when scanning a Git repository,
92
+ * '.git' directory will be skipped without reading its contents.
93
+ *
94
+ * This makes the scan faster but affects
95
+ * {@link MatcherContext.totalDirs},
96
+ * {@link MatcherContext.totalFiles},
97
+ * and {@link MatcherContext.depthPaths}.
98
+ *
99
+ * It's recommended to use this option unless the target
100
+ * allows overriding internal patterns.
101
+ * This option should never affect {@link MatcherContext.totalMatchedFiles}.
102
+ *
103
+ * @default `false`
104
+ *
105
+ * @since 0.6.0
106
+ */
107
+ fastInternal?: boolean;
108
+ /**
109
+ * File system interface.
110
+ *
111
+ * @default `await import("node:fs")`
112
+ *
113
+ * @since 0.6.0
114
+ */
115
+ fs?: FsAdapter;
116
+ };
package/out/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/out/walk.d.ts CHANGED
@@ -1,2 +1,12 @@
1
- import type { Dirent, PathLike } from 'node:fs';
2
- export declare function opendir(path: PathLike, cb: (entry: Dirent) => Promise<0 | 1 | 2>): Promise<void | 2>;
1
+ import type { Dirent } from "node:fs";
2
+ import type { MatcherContext } from "./patterns/matcherContext.js";
3
+ import type { MatcherStream } from "./patterns/matcherStream.js";
4
+ import type { ScanOptions } from "./types.js";
5
+ export type WalkOptions = {
6
+ path: string;
7
+ entry: Dirent;
8
+ ctx: MatcherContext;
9
+ stream: MatcherStream | undefined;
10
+ scanOptions: Required<ScanOptions>;
11
+ };
12
+ export declare function walkIncludes(options: WalkOptions): Promise<0 | 1 | 2>;