view-ignored 0.7.1 → 0.8.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 (47) hide show
  1. package/README.md +23 -17
  2. package/out/browser_scan.d.ts +1 -1
  3. package/out/browser_scan.js +15 -16
  4. package/out/browser_stream.js +1 -43
  5. package/out/patterns/gitignore.d.ts +8 -0
  6. package/out/patterns/gitignore.js +16 -2
  7. package/out/patterns/ignores.d.ts +2 -25
  8. package/out/patterns/index.d.ts +3 -0
  9. package/out/patterns/index.js +3 -0
  10. package/out/patterns/init.d.ts +9 -0
  11. package/out/patterns/init.js +1 -0
  12. package/out/patterns/initState.d.ts +31 -0
  13. package/out/patterns/initState.js +1 -0
  14. package/out/patterns/matcherContextPatch.js +3 -4
  15. package/out/patterns/matcherStream.d.ts +15 -0
  16. package/out/patterns/matcherStream.js +57 -0
  17. package/out/patterns/packagejson.d.ts +8 -0
  18. package/out/patterns/packagejson.js +27 -5
  19. package/out/patterns/pattern.d.ts +2 -1
  20. package/out/patterns/pattern.js +2 -2
  21. package/out/patterns/resolveSources.d.ts +2 -1
  22. package/out/patterns/resolveSources.js +14 -7
  23. package/out/patterns/stringCompile.d.ts +15 -2
  24. package/out/patterns/stringCompile.js +4 -3
  25. package/out/scan.d.ts +1 -1
  26. package/out/scan.js +1 -1
  27. package/out/targets/bun.d.ts +5 -0
  28. package/out/targets/bun.js +78 -0
  29. package/out/targets/deno.d.ts +5 -0
  30. package/out/targets/deno.js +40 -0
  31. package/out/targets/git.js +1 -0
  32. package/out/targets/index.d.ts +3 -0
  33. package/out/targets/index.js +3 -0
  34. package/out/targets/jsr.js +1 -8
  35. package/out/targets/npm.js +36 -13
  36. package/out/targets/target.d.ts +13 -0
  37. package/out/targets/vsce.js +34 -1
  38. package/out/targets/yarn.js +72 -26
  39. package/out/targets/yarnClassic.d.ts +5 -0
  40. package/out/targets/yarnClassic.js +77 -0
  41. package/out/types.d.ts +1 -1
  42. package/out/unixify.d.ts +3 -0
  43. package/out/unixify.js +33 -0
  44. package/out/walk.js +2 -2
  45. package/package.json +4 -1
  46. package/out/normalizeCwd.d.ts +0 -1
  47. package/out/normalizeCwd.js +0 -4
package/README.md CHANGED
@@ -43,7 +43,11 @@ const ctx = await vign.scan({ target })
43
43
  ctx.paths.has(".git/HEAD") // false
44
44
  ctx.paths.has("src") // true
45
45
 
46
- ctx.paths.get("src") // { ignored, match, kind, ... }
46
+ const match = ctx.paths.get("src")
47
+ if (match.kind === "external") {
48
+ console.log(match.source.path) // ".gitignore"
49
+ console.log(match.pattern) // "src/**"
50
+ }
47
51
  ```
48
52
 
49
53
  ### Using custom target
@@ -107,6 +111,7 @@ stream.on("end", (ctx) => {
107
111
  ctx.paths.has("node_modules/") // false
108
112
  ctx.paths.has("package.json") // true
109
113
  })
114
+ stream.start() // important
110
115
  ```
111
116
 
112
117
  ### Browser and custom FS
@@ -133,36 +138,37 @@ vign.scan({ target, cwd, fs })
133
138
 
134
139
  ## Targets
135
140
 
136
- > [!NOTE]
137
- > Each scanner expects minimal configurations, but the actual tool can have
138
- > more/less complex rules. Refer to the documentation of each tool for details.
139
-
140
141
  The following built-in scanners are available:
141
142
 
142
- - Git
143
+ - Git ([implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/git.ts))
143
144
  - Reads `.gitignore` and `.git/info/exclude` but does not consider global settings.
144
145
  - Starts searching from `/`.
145
146
  - Check this scanner by running `git ls-files --others --exclude-standard --cached`.
146
- - See the implementation of [Git target](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/git.ts) for details.
147
- - NPM (compatible with Bun, PNPM, and others)
148
- - Reads `.npmignore` and `package.json` `files` field.
147
+ - NPM ([implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/npm.ts))
148
+ - Expecting to be compatible with PNPM, and others.
149
+ - Reads `package.json` `files` field, `.npmignore` and `.gitignore`.
149
150
  - Starts searching from `.` (current working directory).
150
151
  - No additional checks for `name`, `version` or `publishConfig`.
151
152
  - Check this scanner by running `npm pack --dry-run`.
152
- - See the implementation of [NPM target](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/npm.ts) for details.
153
- - Yarn
154
- - Same behavior as `npm`, but also reads `.yarnignore`.
153
+ - Bun ([implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/bun.ts))
154
+ - Bun tries to mimic NPM, but that does not mean it behaves the same way.
155
+ - Check this scanner by running `bun pm pack --dry-run`.
156
+ - Yarn ([implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/yarn.ts))
157
+ - Modern Berry behavior.
158
+ - Reads `package.json` `files` field, `.npmignore` and `.gitignore`.
159
+ - Requires `package.json`: includes paths from `main`, `module`, `browser` and `bin`.
155
160
  - Starts searching from `.` (current working directory).
156
- - See the implementation of [Yarn target](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/yarn.ts) for details.
157
- - VSCE
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))
158
163
  - Reads `package.json` `files` field, `.vscodeignore` and `.gitignore`.
159
164
  - Starts searching from `.` (current working directory).
160
165
  - Check this scanner by running `vsce ls`.
161
- - See the implementation of [VSCE target](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/vsce.ts) for details.
162
- - JSR (compatible with Deno)
166
+ - JSR ([implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/jsr.ts))
167
+ - Reads `jsr.json(c)` `include` and `exclude` fields.
168
+ - Starts searching from `.` (current working directory).
169
+ - Deno ([implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/deno.ts))
163
170
  - Reads `jsr.json(c)` and `deno.json(c)` `include` and `exclude` fields.
164
171
  - Starts searching from `.` (current working directory).
165
- - See the implementation of [JSR target](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/jsr.ts) for details.
166
172
 
167
173
  ## See also
168
174
 
@@ -4,7 +4,7 @@ export type * from "./types.js";
4
4
  /**
5
5
  * Scan the directory for included files based on the provided targets.
6
6
  *
7
- * Note that this function uses `fs/promises.readFile` and `fs/promises.opendir` without options within
7
+ * Note that this function uses `fs.promises.readFile` and `fs.promises.opendir` without options within
8
8
  * custom recursion, instead of `fs.promises.readdir` with `{ withFileTypes: true }.
9
9
  * It also normalizes paths to use forward slashes.
10
10
  * Please report any issues if you encounter problems related to this behavior.
@@ -1,12 +1,10 @@
1
- import { resolve } from "node:path";
2
- import { relative } from "node:path/posix";
3
- import { normalizeCwd } from "./normalizeCwd.js";
4
1
  import { opendir } from "./opendir.js";
2
+ import { unixify, relative, join } from "./unixify.js";
5
3
  import { walkIncludes } from "./walk.js";
6
4
  /**
7
5
  * Scan the directory for included files based on the provided targets.
8
6
  *
9
- * Note that this function uses `fs/promises.readFile` and `fs/promises.opendir` without options within
7
+ * Note that this function uses `fs.promises.readFile` and `fs.promises.opendir` without options within
10
8
  * custom recursion, instead of `fs.promises.readdir` with `{ withFileTypes: true }.
11
9
  * It also normalizes paths to use forward slashes.
12
10
  * Please report any issues if you encounter problems related to this behavior.
@@ -30,7 +28,7 @@ export function scan(options) {
30
28
  totalMatchedFiles: 0,
31
29
  totalDirs: 0,
32
30
  };
33
- const normalCwd = normalizeCwd(cwd);
31
+ const normalCwd = unixify(cwd);
34
32
  const scanOptions = {
35
33
  cwd: normalCwd,
36
34
  within,
@@ -42,18 +40,19 @@ export function scan(options) {
42
40
  signal,
43
41
  target,
44
42
  };
45
- const result = opendir(fs, normalizeCwd(resolve(normalCwd, within)), (entry) => {
46
- const path = relative(normalCwd, normalizeCwd(entry.parentPath) + "/" + entry.name);
47
- return walkIncludes({
48
- path,
49
- entry,
50
- ctx,
51
- stream: undefined,
52
- scanOptions,
53
- });
54
- });
55
43
  return (async () => {
56
- await result;
44
+ await target.init?.({ ctx, cwd, fs, signal });
45
+ let from = join(unixify(normalCwd), within);
46
+ await opendir(fs, from, (entry) => {
47
+ const path = relative(normalCwd, unixify(entry.parentPath) + "/" + entry.name);
48
+ return walkIncludes({
49
+ path,
50
+ entry,
51
+ ctx,
52
+ stream: undefined,
53
+ scanOptions,
54
+ });
55
+ });
57
56
  return ctx;
58
57
  })();
59
58
  }
@@ -1,51 +1,9 @@
1
- import { resolve } from "node:path";
2
- import { relative } from "node:path/posix";
3
- import { normalizeCwd } from "./normalizeCwd.js";
4
- import { opendir } from "./opendir.js";
5
1
  import { MatcherStream } from "./patterns/matcherStream.js";
6
- import { walkIncludes } from "./walk.js";
7
2
  /**
8
3
  * @see {@link browserScan}
9
4
  *
10
5
  * @since 0.6.0
11
6
  */
12
7
  export function scanStream(options) {
13
- const { target, cwd, within = ".", invert = false, depth: maxDepth = Infinity, signal = null, fastDepth = false, fastInternal = false, fs, } = options;
14
- const ctx = {
15
- paths: new Map(),
16
- external: new Map(),
17
- failed: [],
18
- depthPaths: new Map(),
19
- totalFiles: 0,
20
- totalMatchedFiles: 0,
21
- totalDirs: 0,
22
- };
23
- const stream = new MatcherStream({ captureRejections: false });
24
- const normalCwd = normalizeCwd(cwd);
25
- const scanOptions = {
26
- cwd: normalCwd,
27
- within,
28
- depth: maxDepth,
29
- fastDepth,
30
- fastInternal,
31
- fs,
32
- invert,
33
- signal,
34
- target,
35
- };
36
- const result = opendir(fs, normalizeCwd(resolve(normalCwd, within)), (entry) => {
37
- const path = relative(normalCwd, normalizeCwd(entry.parentPath) + "/" + entry.name);
38
- return walkIncludes({
39
- path,
40
- entry,
41
- ctx,
42
- stream,
43
- scanOptions,
44
- });
45
- });
46
- void (async () => {
47
- await result;
48
- stream.emit("end", ctx);
49
- })();
50
- return stream;
8
+ return new MatcherStream(options);
51
9
  }
@@ -7,3 +7,11 @@ import { type Source } from "./source.js";
7
7
  * @since 0.6.0
8
8
  */
9
9
  export declare function extractGitignore(source: Source, content: Buffer): void;
10
+ /**
11
+ * Extracts and compiles patterns from the file.
12
+ *
13
+ * @see {@link signedPatternCompile}
14
+ *
15
+ * @since 0.6.0
16
+ */
17
+ export declare function extractGitignoreNocase(source: Source, content: Buffer): void;
@@ -8,6 +8,22 @@ import { sourcePushNegatable } from "./source.js";
8
8
  * @since 0.6.0
9
9
  */
10
10
  export function extractGitignore(source, content) {
11
+ extract(source, content);
12
+ signedPatternCompile(source.pattern);
13
+ }
14
+ /**
15
+ * Extracts and compiles patterns from the file.
16
+ *
17
+ * @see {@link signedPatternCompile}
18
+ *
19
+ * @since 0.6.0
20
+ */
21
+ export function extractGitignoreNocase(source, content) {
22
+ extract(source, content);
23
+ signedPatternCompile(source.pattern, { nocase: true });
24
+ }
25
+ extractGitignore;
26
+ function extract(source, content) {
11
27
  for (let line of content.toString().split("\n")) {
12
28
  line = line.trim();
13
29
  if (line === "" || line.startsWith("#")) {
@@ -19,6 +35,4 @@ export function extractGitignore(source, content) {
19
35
  }
20
36
  sourcePushNegatable(source, line);
21
37
  }
22
- signedPatternCompile(source.pattern);
23
38
  }
24
- extractGitignore;
@@ -1,40 +1,17 @@
1
- import type { MatcherContext } from "../patterns/matcherContext.js";
2
1
  import type { SignedPatternMatch } from "../patterns/signedPattern.js";
3
- import type { FsAdapter } from "../types.js";
2
+ import type { InitState } from "./initState.js";
4
3
  /**
5
4
  * Used in {@link Ignores}.
6
5
  *
7
6
  * @since 0.6.0
8
7
  */
9
- export interface IgnoresOptions {
10
- /**
11
- * The file system adapter for directory walking and reading files.
12
- *
13
- * @since 0.6.0
14
- */
15
- fs: FsAdapter;
16
- /**
17
- * @since 0.6.0
18
- */
19
- cwd: string;
8
+ export interface IgnoresOptions extends InitState {
20
9
  /**
21
10
  * File or directory without the slash suffix.
22
11
  *
23
12
  * @since 0.6.0
24
13
  */
25
14
  entry: string;
26
- /**
27
- * The context to populate.
28
- *
29
- * @since 0.6.0
30
- */
31
- ctx: MatcherContext;
32
- /**
33
- * Return as soon as possible.
34
- *
35
- * @since 0.7.1
36
- */
37
- signal: AbortSignal | null;
38
15
  }
39
16
  /**
40
17
  * Checks whether a given entry path should be ignored based on its patterns.
@@ -1,6 +1,8 @@
1
1
  export * from "./extractor.js";
2
2
  export * from "./gitignore.js";
3
3
  export * from "./ignores.js";
4
+ export * from "./init.js";
5
+ export * from "./initState.js";
4
6
  export * from "./jsrjson.js";
5
7
  export * from "./matcherContext.js";
6
8
  export * from "./matcherContextPatch.js";
@@ -11,3 +13,4 @@ export * from "./patternMatcher.js";
11
13
  export * from "./resolveSources.js";
12
14
  export * from "./signedPattern.js";
13
15
  export * from "./source.js";
16
+ export * from "./stringCompile.js";
@@ -1,6 +1,8 @@
1
1
  export * from "./extractor.js";
2
2
  export * from "./gitignore.js";
3
3
  export * from "./ignores.js";
4
+ export * from "./init.js";
5
+ export * from "./initState.js";
4
6
  export * from "./jsrjson.js";
5
7
  export * from "./matcherContext.js";
6
8
  export * from "./matcherContextPatch.js";
@@ -11,3 +13,4 @@ export * from "./patternMatcher.js";
11
13
  export * from "./resolveSources.js";
12
14
  export * from "./signedPattern.js";
13
15
  export * from "./source.js";
16
+ export * from "./stringCompile.js";
@@ -0,0 +1,9 @@
1
+ import type { InitState } from "./initState.js";
2
+ /**
3
+ * Initializes the target. For example,
4
+ * Yarn reads `package.json` to find `main` and `bin` values,
5
+ * so it can forcefully include them.
6
+ *
7
+ * @since 0.8.0
8
+ */
9
+ export type Init = (options: InitState) => Promise<void>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,31 @@
1
+ import type { FsAdapter } from "../types.js";
2
+ import type { MatcherContext } from "./matcherContext.js";
3
+ /**
4
+ * Used in {@link IgnoresOptions}.
5
+ *
6
+ * @since 0.8.0
7
+ */
8
+ export interface InitState {
9
+ /**
10
+ * The file system adapter for directory walking and reading files.
11
+ *
12
+ * @since 0.6.0
13
+ */
14
+ fs: FsAdapter;
15
+ /**
16
+ * @since 0.6.0
17
+ */
18
+ cwd: string;
19
+ /**
20
+ * The context to populate.
21
+ *
22
+ * @since 0.6.0
23
+ */
24
+ ctx: MatcherContext;
25
+ /**
26
+ * Return as soon as possible.
27
+ *
28
+ * @since 0.7.1
29
+ */
30
+ signal: AbortSignal | null;
31
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,8 +1,7 @@
1
1
  import { resolve, dirname } from "node:path";
2
- import { relative } from "node:path/posix";
3
2
  import { getDepth } from "../getDepth.js";
4
- import { normalizeCwd } from "../normalizeCwd.js";
5
3
  import { opendir } from "../opendir.js";
4
+ import { unixify, relative } from "../unixify.js";
6
5
  import { walkIncludes } from "../walk.js";
7
6
  /**
8
7
  * Provides patching abilities for the given {@link MatcherContext}.
@@ -141,9 +140,9 @@ export async function matcherContextRemovePath(ctx, options, entry) {
141
140
  return true;
142
141
  }
143
142
  async function rescan(ctx, options) {
144
- const normalCwd = normalizeCwd(options.cwd);
143
+ const normalCwd = unixify(options.cwd);
145
144
  await opendir(options.fs, resolve(normalCwd, options.within), (entry) => {
146
- const path = relative(normalCwd, normalizeCwd(entry.parentPath) + "/" + entry.name);
145
+ const path = relative(normalCwd, unixify(entry.parentPath) + "/" + entry.name);
147
146
  return walkIncludes({
148
147
  path,
149
148
  entry,
@@ -1,6 +1,7 @@
1
1
  import { EventEmitter } from "node:events";
2
2
  import type { Dirent } from "node:fs";
3
3
  import type { MatcherContext } from "../patterns/matcherContext.js";
4
+ import type { ScanOptions, FsAdapter } from "../types.js";
4
5
  import type { SignedPatternMatch } from "./signedPattern.js";
5
6
  /**
6
7
  * Post-scan entry information.
@@ -61,4 +62,18 @@ export type EventMap = {
61
62
  * @since 0.6.0
62
63
  */
63
64
  export declare class MatcherStream extends EventEmitter<EventMap> {
65
+ #private;
66
+ constructor(options: ScanOptions & {
67
+ fs: FsAdapter;
68
+ cwd: string;
69
+ noTimeout?: boolean;
70
+ } & {
71
+ captureRejections?: boolean;
72
+ });
73
+ /**
74
+ * Resolves when everything is scanned.
75
+ *
76
+ * @since 0.8.0
77
+ */
78
+ start(): Promise<void>;
64
79
  }
@@ -1,4 +1,7 @@
1
1
  import { EventEmitter } from "node:events";
2
+ import { opendir } from "../opendir.js";
3
+ import { join, relative, unixify } from "../unixify.js";
4
+ import { walkIncludes } from "../walk.js";
2
5
  /**
3
6
  * Event emitter.
4
7
  * @extends EventEmitter
@@ -6,4 +9,58 @@ import { EventEmitter } from "node:events";
6
9
  * @since 0.6.0
7
10
  */
8
11
  export class MatcherStream extends EventEmitter {
12
+ #timeout;
13
+ #options;
14
+ constructor(options) {
15
+ super({ captureRejections: options.captureRejections });
16
+ this.#options = options;
17
+ if (!options.noTimeout) {
18
+ this.#timeout = setTimeout(() => {
19
+ throw new Error("Stream did not start within 5 seconds. Call MatcherStream.start() or enable noTimeout.");
20
+ }, 5e3);
21
+ }
22
+ }
23
+ /**
24
+ * Resolves when everything is scanned.
25
+ *
26
+ * @since 0.8.0
27
+ */
28
+ async start() {
29
+ clearTimeout(this.#timeout);
30
+ const { target, cwd, within = ".", invert = false, depth: maxDepth = Infinity, signal = null, fastDepth = false, fastInternal = false, fs, } = this.#options;
31
+ const ctx = {
32
+ paths: new Map(),
33
+ external: new Map(),
34
+ failed: [],
35
+ depthPaths: new Map(),
36
+ totalFiles: 0,
37
+ totalMatchedFiles: 0,
38
+ totalDirs: 0,
39
+ };
40
+ const normalCwd = unixify(cwd);
41
+ const scanOptions = {
42
+ cwd: normalCwd,
43
+ within,
44
+ depth: maxDepth,
45
+ fastDepth,
46
+ fastInternal,
47
+ fs,
48
+ invert,
49
+ signal,
50
+ target,
51
+ };
52
+ await target.init?.({ ctx, cwd, fs, signal });
53
+ let from = join(unixify(normalCwd), within);
54
+ await opendir(fs, from, (entry) => {
55
+ const path = relative(normalCwd, unixify(entry.parentPath) + "/" + entry.name);
56
+ return walkIncludes({
57
+ path,
58
+ entry,
59
+ ctx,
60
+ stream: this,
61
+ scanOptions,
62
+ });
63
+ });
64
+ this.emit("end", ctx);
65
+ }
9
66
  }
@@ -7,3 +7,11 @@ import { type Source } from "./source.js";
7
7
  * @since 0.6.0
8
8
  */
9
9
  export declare function extractPackageJson(source: Source, content: Buffer): void | "none";
10
+ /**
11
+ * Extracts and compiles patterns from the file.
12
+ *
13
+ * @see {@link signedPatternCompile}
14
+ *
15
+ * @since 0.8.0
16
+ */
17
+ export declare function extractPackageJsonNocase(source: Source, content: Buffer): void | "none";
@@ -1,12 +1,12 @@
1
1
  import { type } from "arktype";
2
2
  import { signedPatternCompile } from "./resolveSources.js";
3
3
  import { sourcePushNegatable } from "./source.js";
4
- const nodeJsManifest = type({
5
- files: "string[]?",
4
+ const npmManifest = type({
5
+ "files?": "string[]",
6
6
  });
7
7
  const parse = type("string")
8
8
  .pipe((s) => JSON.parse(s))
9
- .pipe(nodeJsManifest);
9
+ .pipe(npmManifest);
10
10
  /**
11
11
  * Extracts and compiles patterns from the file.
12
12
  *
@@ -15,11 +15,34 @@ const parse = type("string")
15
15
  * @since 0.6.0
16
16
  */
17
17
  export function extractPackageJson(source, content) {
18
+ const result = extract(source, content);
19
+ if (result === undefined)
20
+ signedPatternCompile(source.pattern);
21
+ if (result === "error")
22
+ return;
23
+ return result;
24
+ }
25
+ /**
26
+ * Extracts and compiles patterns from the file.
27
+ *
28
+ * @see {@link signedPatternCompile}
29
+ *
30
+ * @since 0.8.0
31
+ */
32
+ export function extractPackageJsonNocase(source, content) {
33
+ const result = extract(source, content);
34
+ if (result === undefined)
35
+ signedPatternCompile(source.pattern, { nocase: true });
36
+ if (result === "error")
37
+ return;
38
+ return result;
39
+ }
40
+ function extract(source, content) {
18
41
  source.inverted = true;
19
42
  const dist = parse(content.toString());
20
43
  if (dist instanceof type.errors) {
21
44
  source.error = new Error("Invalid '" + source.path + "': " + dist.summary, { cause: dist });
22
- return;
45
+ return "error";
23
46
  }
24
47
  if (!dist.files) {
25
48
  return "none";
@@ -27,6 +50,5 @@ export function extractPackageJson(source, content) {
27
50
  for (const pattern of dist.files) {
28
51
  sourcePushNegatable(source, pattern);
29
52
  }
30
- signedPatternCompile(source.pattern);
31
53
  }
32
54
  extractPackageJson;
@@ -1,3 +1,4 @@
1
+ import { type StringCompileOptions } from "./stringCompile.js";
1
2
  /**
2
3
  * Compiled pattern.
3
4
  *
@@ -41,4 +42,4 @@ export type Pattern = string[];
41
42
  *
42
43
  * @since 0.6.0
43
44
  */
44
- export declare function patternCompile(pattern: Pattern): PatternMinimatch[];
45
+ export declare function patternCompile(pattern: Pattern, options?: StringCompileOptions): PatternMinimatch[];
@@ -16,6 +16,6 @@ export function patternMinimatchTest(pattern, path) {
16
16
  *
17
17
  * @since 0.6.0
18
18
  */
19
- export function patternCompile(pattern) {
20
- return pattern.map(stringCompile);
19
+ export function patternCompile(pattern, options) {
20
+ return pattern.map((p, _, pattern) => stringCompile(p, pattern, options));
21
21
  }
@@ -1,5 +1,6 @@
1
1
  import type { PatternFinderOptions } from "./extractor.js";
2
2
  import type { SignedPattern } from "./signedPattern.js";
3
+ import type { StringCompileOptions } from "./stringCompile.js";
3
4
  /**
4
5
  * Compiles the {@link SignedPattern} (forced).
5
6
  * Can be compiled at any time.
@@ -9,7 +10,7 @@ import type { SignedPattern } from "./signedPattern.js";
9
10
  *
10
11
  * @since 0.6.0
11
12
  */
12
- export declare function signedPatternCompile(signedPattern: SignedPattern): SignedPattern;
13
+ export declare function signedPatternCompile(signedPattern: SignedPattern, options?: StringCompileOptions): SignedPattern;
13
14
  /**
14
15
  * @see {@link resolveSources}
15
16
  *
@@ -1,4 +1,5 @@
1
- import { dirname, relative, resolve } from "node:path";
1
+ import { dirname } from "node:path";
2
+ import { unixify, relative, join } from "../unixify.js";
2
3
  import { patternCompile } from "./pattern.js";
3
4
  /**
4
5
  * Compiles the {@link SignedPattern} (forced).
@@ -9,10 +10,10 @@ import { patternCompile } from "./pattern.js";
9
10
  *
10
11
  * @since 0.6.0
11
12
  */
12
- export function signedPatternCompile(signedPattern) {
13
+ export function signedPatternCompile(signedPattern, options) {
13
14
  signedPattern.compiled = {
14
- include: patternCompile(signedPattern.include),
15
- exclude: patternCompile(signedPattern.exclude),
15
+ include: patternCompile(signedPattern.include, options),
16
+ exclude: patternCompile(signedPattern.exclude, options),
16
17
  };
17
18
  return signedPattern;
18
19
  }
@@ -73,8 +74,8 @@ export async function resolveSources(options) {
73
74
  ctx.external.set(noSourceDir, source);
74
75
  }
75
76
  }
76
- const rels = noSourceDirList.map((rel) => resolve(cwd, rel).replaceAll("\\", "/").replace(/\w:/, ""));
77
- source = await findSourceForAbsoluteDirs(rels, ctx, fs, target, signal);
77
+ const absPaths = noSourceDirList.map((rel) => join(cwd, rel));
78
+ source = await findSourceForAbsoluteDirs(absPaths, ctx, fs, target, signal);
78
79
  if (source !== undefined) {
79
80
  for (const noSourceDir of noSourceDirList) {
80
81
  signal?.throwIfAborted();
@@ -99,7 +100,13 @@ async function findSourceForAbsoluteDirs(paths, ctx, fs, target, signal) {
99
100
  return "none";
100
101
  }
101
102
  async function tryExtractor(cwd, fs, ctx, extractor) {
102
- const abs = resolve(cwd, extractor.path);
103
+ let abs = unixify(cwd);
104
+ if (abs.endsWith("/")) {
105
+ abs += extractor.path;
106
+ }
107
+ else {
108
+ abs += "/" + extractor.path;
109
+ }
103
110
  const path = relative(cwd, abs);
104
111
  const name = path.substring(path.lastIndexOf("/") + 1);
105
112
  const newSource = {
@@ -1,9 +1,22 @@
1
1
  import type { PatternMinimatch, Pattern } from "./pattern.js";
2
+ /**
3
+ * @since 0.8.0
4
+ */
5
+ export type StringCompileOptions = {
6
+ /**
7
+ * Disables case sensitivity.
8
+ *
9
+ * @default false
10
+ *
11
+ * @since 0.8.0
12
+ */
13
+ nocase?: boolean;
14
+ };
2
15
  /**
3
16
  * Compiles a string of the {@link Pattern}.
4
17
  *
5
18
  * @see {@link patternCompile}
6
19
  *
7
- * @since 0.6.0
20
+ * @since 0.8.0
8
21
  */
9
- export declare function stringCompile(pattern: string, _?: number, array?: Pattern): PatternMinimatch;
22
+ export declare function stringCompile(pattern: string, context?: Pattern, options?: StringCompileOptions): PatternMinimatch;