view-ignored 0.5.1 → 0.5.2

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.
@@ -1,3 +1,3 @@
1
- import type { Source } from './matcher.js';
1
+ import { type Source } from './matcher.js';
2
2
  export declare function extractGitignore(source: Source, content: Buffer<ArrayBuffer>): void;
3
3
  export declare function gitignoreMatch(pattern: string, path: string): boolean;
@@ -1,3 +1,4 @@
1
+ import { sourcePushNegatable } from './matcher.js';
1
2
  import { minimatch } from 'minimatch';
2
3
  export function extractGitignore(source, content) {
3
4
  for (let line of content.toString().split('\n')) {
@@ -9,12 +10,7 @@ export function extractGitignore(source, content) {
9
10
  if (cdx >= 0) {
10
11
  line = line.substring(-cdx);
11
12
  }
12
- if (line.startsWith('!')) {
13
- source.pattern.include.push(line.substring(1));
14
- }
15
- else {
16
- source.pattern.exclude.push(line);
17
- }
13
+ sourcePushNegatable(source, line);
18
14
  }
19
15
  // TODO: validate gitignore
20
16
  }
@@ -46,6 +46,8 @@ export declare function patternMatches(pattern: Pattern, path: string): boolean;
46
46
  /**
47
47
  * Represents a set of include and exclude patterns.
48
48
  * These patterns are positive minimatch patterns.
49
+ *
50
+ * @see {@link PatternMatcher}
49
51
  */
50
52
  export type SignedPattern = {
51
53
  include: Pattern;
@@ -53,7 +55,11 @@ export type SignedPattern = {
53
55
  };
54
56
  /**
55
57
  * Combined internal and external patterns for matching.
56
- * Used in {@link signedPatternIgnores} function.
58
+ *
59
+ * `exclude` patterns take precedence over `include` patterns.
60
+ *
61
+ * `internal` patterns take precedence over `external` patterns.
62
+ * @see {@link signedPatternIgnores}
57
63
  */
58
64
  export type PatternMatcher = {
59
65
  internal: SignedPattern;
@@ -86,6 +92,12 @@ export type Source = {
86
92
  */
87
93
  inverted: boolean;
88
94
  };
95
+ /**
96
+ * Adds a negatable pattern to the source's pattern lists.
97
+ * Strips the leading '!' for include patterns,
98
+ * and adds to exclude patterns otherwise.
99
+ */
100
+ export declare function sourcePushNegatable(source: Source, pattern: string): void;
89
101
  /**
90
102
  * Populates a `Source` object from the content of a source file.
91
103
  * @see {@link Source.pattern} for more details.
@@ -10,6 +10,18 @@ export function patternMatches(pattern, path) {
10
10
  }
11
11
  return false;
12
12
  }
13
+ /**
14
+ * Adds a negatable pattern to the source's pattern lists.
15
+ * Strips the leading '!' for include patterns,
16
+ * and adds to exclude patterns otherwise.
17
+ */
18
+ export function sourcePushNegatable(source, pattern) {
19
+ if (pattern.startsWith('!')) {
20
+ source.pattern.include.push(pattern.substring(1));
21
+ return;
22
+ }
23
+ source.pattern.exclude.push(pattern);
24
+ }
13
25
  /**
14
26
  * Populates the {@link MatcherContext.external} map with {@link Source} objects.
15
27
  */
@@ -1,3 +1,3 @@
1
1
  import { type } from 'arktype';
2
- import type { Source } from './matcher.js';
2
+ import { type Source } from './matcher.js';
3
3
  export declare function extractPackageJson(source: Source, content: Buffer<ArrayBuffer>): type.errors | undefined;
@@ -1,4 +1,5 @@
1
1
  import { type } from 'arktype';
2
+ import { sourcePushNegatable, } from './matcher.js';
2
3
  const nodeJsManifest = type({
3
4
  files: 'string[]?',
4
5
  });
@@ -12,13 +13,8 @@ export function extractPackageJson(source, content) {
12
13
  if (!dist.files) {
13
14
  return;
14
15
  }
15
- for (const p of dist.files) {
16
- if (p.startsWith('!')) {
17
- source.pattern.exclude.push(...p.substring(1));
18
- }
19
- else {
20
- source.pattern.include.push(...p);
21
- }
16
+ for (const pattern of dist.files) {
17
+ sourcePushNegatable(source, pattern);
22
18
  }
23
19
  return;
24
20
  }
package/out/scan.js CHANGED
@@ -13,6 +13,9 @@ import { opendir } from './walk.js';
13
13
  */
14
14
  export async function scan(options) {
15
15
  const { target, cwd: cwdo = (await import('node:process')).cwd(), depth: maxDepth = Infinity, invert = false, signal = undefined, fastDepth = false, } = options;
16
+ if (maxDepth < 0) {
17
+ throw new TypeError('Depth must be a non-negative integer');
18
+ }
16
19
  const cwd = cwdo.replaceAll('\\', '/');
17
20
  const ctx = {
18
21
  paths: new Set(),
@@ -24,9 +27,7 @@ export async function scan(options) {
24
27
  totalDirs: 0,
25
28
  };
26
29
  await opendir(cwd, async (entry) => {
27
- if (signal?.aborted) {
28
- return 2;
29
- }
30
+ signal?.throwIfAborted();
30
31
  const path = posix.join(posix.relative(cwd, entry.parentPath.replaceAll('\\', '/')), entry.name);
31
32
  if (entry.isDirectory()) {
32
33
  ctx.totalDirs++;
@@ -79,9 +80,7 @@ export async function scan(options) {
79
80
  }
80
81
  return 0;
81
82
  });
82
- if (signal?.aborted) {
83
- return ctx;
84
- }
83
+ signal?.throwIfAborted();
85
84
  for (const [dir, count] of ctx.depthPaths) {
86
85
  if (count === 0) {
87
86
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "view-ignored",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "Retrieve list of files ignored/included by Git, NPM, Yarn, JSR, VSCE or other tools.",
5
5
  "type": "module",
6
6
  "scripts": {