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/out/scan.d.ts CHANGED
@@ -4,10 +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
8
- * custom recursion, instead of `fs.promises.readdir` with `{ withFileTypes: true }.
9
7
  * It also normalizes paths to use forward slashes.
10
- * Please report any issues if you encounter problems related to this behavior.
11
8
  *
12
9
  * @param options Scan options.
13
10
  * @returns A promise that resolves to a {@link MatcherContext} containing the scan results.
@@ -15,3 +12,14 @@ export type * from "./types.js";
15
12
  * @since 0.6.0
16
13
  */
17
14
  export declare function scan(options: ScanOptions): Promise<MatcherContext>;
15
+ /**
16
+ * Scan the directory for included files based on the provided targets.
17
+ *
18
+ * It also normalizes paths to use forward slashes.
19
+ *
20
+ * @param options Scan options.
21
+ * @param cb Callback function.
22
+ *
23
+ * @since 0.11.0
24
+ */
25
+ export declare function scanCb(options: ScanOptions, cb: (err: Error | null, ctx: MatcherContext) => void): void;
package/out/scan.js CHANGED
@@ -1,13 +1,11 @@
1
1
  import * as nodefs from "node:fs";
2
2
  import * as process from "node:process";
3
3
  import { scan as browserScan } from "./browser_scan.js";
4
+ import { scanCb as browserScanCb } from "./scanCb.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.
@@ -16,5 +14,19 @@ import { scan as browserScan } from "./browser_scan.js";
16
14
  */
17
15
  export function scan(options) {
18
16
  const { cwd = process.cwd(), fs = nodefs } = options;
19
- return browserScan({ fs, cwd, ...options });
17
+ return browserScan({ cwd, fs, ...options });
18
+ }
19
+ /**
20
+ * Scan the directory for included files based on the provided targets.
21
+ *
22
+ * It also normalizes paths to use forward slashes.
23
+ *
24
+ * @param options Scan options.
25
+ * @param cb Callback function.
26
+ *
27
+ * @since 0.11.0
28
+ */
29
+ export function scanCb(options, cb) {
30
+ const { cwd = process.cwd(), fs = nodefs } = options;
31
+ browserScanCb({ cwd, fs, ...options }, cb);
20
32
  }
@@ -0,0 +1,16 @@
1
+ import type { MatcherContext } from "./patterns/matcherContext.js";
2
+ import type { ScanOptions, FsAdapter } from "./types.js";
3
+ /**
4
+ * Scan the directory for included files based on the provided targets.
5
+ *
6
+ * It also normalizes paths to use forward slashes.
7
+ *
8
+ * @param options Scan options.
9
+ * @param cb Callback function.
10
+ *
11
+ * @since 0.11.0
12
+ */
13
+ export declare function scanCb(options: ScanOptions & {
14
+ fs: FsAdapter;
15
+ cwd: string;
16
+ }, cb: (err: Error | null, ctx: MatcherContext) => void): void;
package/out/scanCb.js ADDED
@@ -0,0 +1,73 @@
1
+ import { scanParallel } from "./scanParallel.js";
2
+ import { unixify } from "./unixify.js";
3
+ import { walkPatchResult, walkPatchTotal, propagateTotals } from "./walk.js";
4
+ /**
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
+ * @param cb Callback function.
11
+ *
12
+ * @since 0.11.0
13
+ */
14
+ export function scanCb(options, cb) {
15
+ const { target, cwd, within = ".", invert = false, depth: maxDepth = Infinity, signal = null, fastDepth = false, fastInternal = false, fs, } = options;
16
+ if (maxDepth < 0) {
17
+ cb(new TypeError("Depth must be a non-negative integer"), null);
18
+ return;
19
+ }
20
+ const ctx = {
21
+ external: new Map(),
22
+ failed: [],
23
+ paths: new Map(),
24
+ total: new Map([[".", { totalDirs: 0, totalFiles: 0, totalMatchedFiles: 0 }]]),
25
+ };
26
+ const normalCwd = unixify(cwd);
27
+ const scanOptions = {
28
+ cwd: normalCwd,
29
+ depth: maxDepth,
30
+ fastDepth,
31
+ fastInternal,
32
+ fs,
33
+ invert,
34
+ signal,
35
+ target,
36
+ within,
37
+ };
38
+ const startScan = () => {
39
+ scanParallel({
40
+ external: ctx.external,
41
+ failed: ctx.failed,
42
+ onResult: (result) => {
43
+ if ("dir" in result) {
44
+ walkPatchTotal(ctx, scanOptions.depth, result);
45
+ }
46
+ else {
47
+ walkPatchResult(ctx, result);
48
+ }
49
+ },
50
+ scanOptions,
51
+ within,
52
+ }, (err) => {
53
+ if (err) {
54
+ cb(err, null);
55
+ return;
56
+ }
57
+ propagateTotals(ctx.total);
58
+ cb(null, ctx);
59
+ });
60
+ };
61
+ if (target.init) {
62
+ target.init({ cwd: normalCwd, fs, signal, target }, (err) => {
63
+ if (err) {
64
+ cb(err, null);
65
+ return;
66
+ }
67
+ startScan();
68
+ });
69
+ }
70
+ else {
71
+ startScan();
72
+ }
73
+ }
@@ -0,0 +1,18 @@
1
+ import type { MatcherStream } from "./patterns/matcherStream.js";
2
+ import type { Resource, InvalidSource } from "./patterns/resource.js";
3
+ import type { ScanOptions } from "./types.js";
4
+ import { type WalkResult, type WalkTotal } from "./walk.js";
5
+ export interface ScanParallelOptions {
6
+ scanOptions: Required<ScanOptions>;
7
+ within: string;
8
+ stream?: MatcherStream;
9
+ external: Map<string, Resource>;
10
+ failed?: InvalidSource[];
11
+ onResult?: (result: WalkResult | WalkTotal) => void;
12
+ }
13
+ /**
14
+ * Executes a parallel directory scan.
15
+ *
16
+ * @since 0.11.0
17
+ */
18
+ export declare function scanParallel(options: ScanParallelOptions, cb: (err: Error | null, results: WalkResult[] | null) => void): void;
@@ -0,0 +1,146 @@
1
+ import { resolveSources } from "./patterns/resolveSources.js";
2
+ import { join, unixify } from "./unixify.js";
3
+ import { walkIncludes } from "./walk.js";
4
+ /**
5
+ * Executes a parallel directory scan.
6
+ *
7
+ * @since 0.11.0
8
+ */
9
+ export function scanParallel(options, cb) {
10
+ const { scanOptions, stream, external, failed, onResult } = options;
11
+ scanOptions.cwd = unixify(scanOptions.cwd);
12
+ let { within } = options;
13
+ if (within.startsWith("./"))
14
+ within = within.slice(2);
15
+ const results = onResult ? null : [];
16
+ let activeTasks = 0;
17
+ let errorOccurred = null;
18
+ function walk(relPath, depth, resource, lowerRelPath) {
19
+ if (errorOccurred)
20
+ return;
21
+ activeTasks++;
22
+ scanOptions.fs.readdir(join(scanOptions.cwd, relPath), { withFileTypes: true }, (err, entries) => {
23
+ if (err) {
24
+ handleError(err);
25
+ return;
26
+ }
27
+ resolveSources({ ...scanOptions, dir: relPath, entries, external, resource }, (err, res) => {
28
+ if (err) {
29
+ handleError(err);
30
+ return;
31
+ }
32
+ if (res && "error" in res && res.error) {
33
+ if (failed) {
34
+ failed.push(res);
35
+ }
36
+ else {
37
+ handleError(res.error);
38
+ return;
39
+ }
40
+ }
41
+ const len = entries.length;
42
+ const prefix = relPath === "." || relPath === "" ? "" : relPath + "/";
43
+ const lowerPrefix = lowerRelPath
44
+ ? lowerRelPath + "/"
45
+ : prefix
46
+ ? prefix.toLowerCase()
47
+ : "";
48
+ let pendingResults = len;
49
+ let dirFiles = 0;
50
+ let dirMatched = 0;
51
+ let dirDirs = 0;
52
+ if (len === 0) {
53
+ if (onResult) {
54
+ onResult({
55
+ depth,
56
+ dir: relPath,
57
+ dirs: 0,
58
+ files: 0,
59
+ ignored: false,
60
+ matched: 0,
61
+ type: "total",
62
+ });
63
+ }
64
+ }
65
+ for (let i = 0; i < len; i++) {
66
+ const entry = entries[i];
67
+ activeTasks++;
68
+ const name = entry.name;
69
+ const currentRelPath = prefix + name;
70
+ const currentLowerRelPath = lowerPrefix + name.toLowerCase();
71
+ walkIncludes({
72
+ depth,
73
+ entry,
74
+ lowerRelPath: currentLowerRelPath,
75
+ parentPath: relPath,
76
+ relPath: currentRelPath,
77
+ resource: res,
78
+ scanOptions,
79
+ stream,
80
+ }, (err, self) => {
81
+ if (err) {
82
+ handleError(err);
83
+ return;
84
+ }
85
+ if (self && self.match) {
86
+ if (self.isDir) {
87
+ dirDirs++;
88
+ }
89
+ else {
90
+ dirFiles++;
91
+ if (!self.match.ignored)
92
+ dirMatched++;
93
+ }
94
+ if (onResult) {
95
+ onResult(self);
96
+ }
97
+ else {
98
+ results.push(self);
99
+ }
100
+ if (entry.isDirectory() && self.next === 0) {
101
+ walk(currentRelPath, depth + 1, res, currentLowerRelPath);
102
+ }
103
+ }
104
+ pendingResults--;
105
+ if (pendingResults === 0) {
106
+ if (onResult) {
107
+ onResult({
108
+ depth,
109
+ dir: relPath,
110
+ dirs: dirDirs,
111
+ files: dirFiles,
112
+ ignored: false,
113
+ matched: dirMatched,
114
+ type: "total",
115
+ });
116
+ }
117
+ }
118
+ taskDone();
119
+ });
120
+ }
121
+ taskDone();
122
+ });
123
+ });
124
+ }
125
+ function handleError(err) {
126
+ if (!errorOccurred) {
127
+ errorOccurred = err;
128
+ cb(err, null);
129
+ }
130
+ }
131
+ function taskDone() {
132
+ activeTasks--;
133
+ if (activeTasks === 0 && !errorOccurred) {
134
+ cb(null, results);
135
+ }
136
+ }
137
+ let initialDepth = 0;
138
+ if (within !== "." && within !== "") {
139
+ const len = within.length;
140
+ for (let i = 0; i < len; i++) {
141
+ if (within.charCodeAt(i) === 47)
142
+ initialDepth++;
143
+ }
144
+ }
145
+ walk(within, initialDepth, undefined, within === "." || within === "" ? "" : within.toLowerCase());
146
+ }
package/out/stream.d.ts CHANGED
@@ -2,7 +2,12 @@ import type { MatcherStream } from "./patterns/matcherStream.js";
2
2
  import type { ScanOptions } from "./types.js";
3
3
  export type * from "./types.js";
4
4
  /**
5
- * @see {@link scan}
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
  */
package/out/stream.js CHANGED
@@ -2,11 +2,16 @@ import * as nodefs from "node:fs";
2
2
  import * as process from "node:process";
3
3
  import { scanStream as browserStream } from "./browser_stream.js";
4
4
  /**
5
- * @see {@link scan}
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
  */
9
14
  export function scanStream(options) {
10
15
  const { cwd = process.cwd(), fs = nodefs } = options;
11
- return browserStream({ fs, cwd, ...options });
16
+ return browserStream({ cwd, fs, ...options });
12
17
  }
@@ -1,4 +1,3 @@
1
- import { type } from "arktype";
2
1
  import { ruleTest, ruleCompile, extractPackageJson, extractGitignore, } from "../patterns/index.js";
3
2
  import { join, unixify } from "../unixify.js";
4
3
  import { npmManifestParse } from "./npmManifest.js";
@@ -17,13 +16,14 @@ const extractors = [
17
16
  },
18
17
  ];
19
18
  const internalInclude = {
19
+ compiled: [],
20
20
  excludes: false,
21
21
  pattern: [], // filled within init
22
- compiled: [],
23
22
  };
24
23
  const internal = [
25
24
  internalInclude,
26
25
  ruleCompile({
26
+ compiled: null,
27
27
  excludes: true,
28
28
  pattern: [
29
29
  // https://github.com/oven-sh/bun/blob/main/src/cli/pack_command.zig#L180
@@ -58,9 +58,9 @@ const internal = [
58
58
  // https://github.com/oven-sh/bun/blob/main/src/cli/pack_command.zig#L285
59
59
  "node_modules",
60
60
  ],
61
- compiled: null,
62
61
  }), // nocase should be false here
63
62
  ruleCompile({
63
+ compiled: null,
64
64
  excludes: true,
65
65
  pattern: [
66
66
  // https://github.com/oven-sh/bun/blob/main/src/cli/pack_command.zig#L2586
@@ -73,46 +73,53 @@ const internal = [
73
73
  "README",
74
74
  "README.*",
75
75
  ],
76
- compiled: null,
77
76
  }, { nocase: true }),
78
77
  ];
79
78
  /**
80
79
  * @since 0.8.1
81
80
  */
82
81
  export const Bun = {
83
- internalRules: internal,
84
82
  extractors,
85
- root: ".",
86
- async init({ fs, cwd }) {
87
- let content;
83
+ ignores: ruleTest,
84
+ init({ fs, cwd }, cb) {
88
85
  const normalCwd = unixify(cwd);
89
- try {
90
- content = await fs.promises.readFile(normalCwd + "/" + "package.json");
91
- }
92
- catch (error) {
93
- throw new Error("Error while initializing Bun", { cause: error });
94
- }
95
- const dist = npmManifestParse(content.toString());
96
- if (dist instanceof type.errors) {
97
- throw new Error("Invalid 'package.json': " + dist.summary, { cause: dist });
98
- }
99
- const set = new Set();
100
- function normal(path) {
101
- const result = unixify(join(normalCwd, path)).substring(normalCwd.length);
102
- return result;
103
- }
104
- // https://github.com/oven-sh/bun/blob/main/src/cli/pack_command.zig#L1440
105
- if (typeof dist.bin === "string") {
106
- set.add(normal(dist.bin));
107
- }
108
- else if (typeof dist.bin === "object" && dist.bin !== null) {
109
- Object.values(dist.bin).forEach((binPath) => set.add(normal(binPath)));
110
- }
111
- // TODO: Bun should include bundled deps
112
- // nothing else
113
- // link zig code
114
- internalInclude.pattern = Array.from(set);
115
- ruleCompile(internalInclude, { nocase: true });
86
+ fs.readFile(normalCwd + "/" + "package.json", (err, content) => {
87
+ if (err) {
88
+ cb(new Error("Error while initializing Bun", { cause: err }));
89
+ return;
90
+ }
91
+ let dist;
92
+ try {
93
+ dist = npmManifestParse(content.toString());
94
+ // const set = new Set<string>()
95
+ // TODO: NPM should include bundled deps
96
+ // internalInclude.pattern = Array.from(set)
97
+ // ruleCompile(internalInclude, { nocase: true })
98
+ }
99
+ catch (error) {
100
+ cb(new Error("Invalid 'package.json'", { cause: error }));
101
+ return;
102
+ }
103
+ const set = new Set();
104
+ function normal(path) {
105
+ const result = unixify(join(normalCwd, path)).substring(normalCwd.length);
106
+ return result;
107
+ }
108
+ // https://github.com/oven-sh/bun/blob/main/src/cli/pack_command.zig#L1440
109
+ if (typeof dist.bin === "string") {
110
+ set.add(normal(dist.bin));
111
+ }
112
+ else if (typeof dist.bin === "object") {
113
+ Object.values(dist.bin).forEach((binPath) => set.add(normal(binPath)));
114
+ }
115
+ // TODO: Bun should include bundled deps
116
+ // nothing else
117
+ // link zig code
118
+ internalInclude.pattern = Array.from(set);
119
+ ruleCompile(internalInclude, { nocase: true });
120
+ cb();
121
+ });
116
122
  },
117
- ignores: ruleTest,
123
+ internalRules: internal,
124
+ root: ".",
118
125
  };
@@ -1,4 +1,3 @@
1
- import { type } from "arktype";
2
1
  import { ruleTest, ruleCompile, extractJsrJson, extractJsrJsonc, extractPackageJson, } from "../patterns/index.js";
3
2
  import { unixify } from "../unixify.js";
4
3
  import { jsrManifestParse } from "./jsrManifest.js";
@@ -26,40 +25,43 @@ const extractors = [
26
25
  ];
27
26
  const internal = [
28
27
  ruleCompile({
28
+ compiled: null,
29
29
  excludes: true,
30
30
  pattern: [".git", ".DS_Store"],
31
- compiled: null,
32
31
  }),
33
32
  ];
34
33
  /**
35
34
  * @since 0.8.1
36
35
  */
37
36
  export const Deno = {
38
- internalRules: internal,
39
37
  extractors,
40
- root: ".",
41
- async init({ fs, cwd }) {
42
- let content;
38
+ ignores: ruleTest,
39
+ init({ fs, cwd }, cb) {
43
40
  const normalCwd = unixify(cwd);
44
- let path;
45
- for (const [i, { path: p }] of extractors.entries()) {
46
- path = p;
47
- try {
48
- content = await fs.promises.readFile(normalCwd + "/" + path);
41
+ let i = 0;
42
+ function next() {
43
+ if (i >= extractors.length) {
44
+ cb(new Error("Error while initializing Deno: No valid manifest found"));
45
+ return;
49
46
  }
50
- catch (error) {
51
- if (error.code === "ENOENT") {
52
- if (i < extractors.length - 1) {
53
- continue;
54
- }
47
+ const extractor = extractors[i++];
48
+ fs.readFile(normalCwd + "/" + extractor.path, (err, data) => {
49
+ if (err) {
50
+ next();
51
+ return;
55
52
  }
56
- throw new Error("Error while initializing Deno", { cause: error });
57
- }
58
- }
59
- const dist = jsrManifestParse(content.toString());
60
- if (dist instanceof type.errors) {
61
- throw new Error("Invalid '" + path + "': " + dist.summary, { cause: dist });
53
+ try {
54
+ jsrManifestParse(data.toString());
55
+ }
56
+ catch (error) {
57
+ cb(new Error("Invalid '" + extractor.path + "'", { cause: error }));
58
+ return;
59
+ }
60
+ cb();
61
+ });
62
62
  }
63
+ next();
63
64
  },
64
- ignores: ruleTest,
65
+ internalRules: internal,
66
+ root: ".",
65
67
  };
@@ -11,18 +11,18 @@ const extractors = [
11
11
  ];
12
12
  const internal = [
13
13
  ruleCompile({
14
+ compiled: null,
14
15
  excludes: true,
15
16
  pattern: [".git", ".DS_Store"],
16
- compiled: null,
17
17
  }),
18
18
  ];
19
19
  /**
20
20
  * @since 0.6.0
21
21
  */
22
22
  export const Git = {
23
- internalRules: internal,
24
23
  extractors,
25
- root: "/",
26
24
  // TODO: Git should read configs
27
25
  ignores: ruleTest,
26
+ internalRules: internal,
27
+ root: "/",
28
28
  };
@@ -1,4 +1,3 @@
1
- import { type } from "arktype";
2
1
  import { ruleTest, ruleCompile, extractJsrJson, extractJsrJsonc, } from "../patterns/index.js";
3
2
  import { unixify } from "../unixify.js";
4
3
  import { jsrManifestParse } from "./jsrManifest.js";
@@ -14,40 +13,43 @@ const extractors = [
14
13
  ];
15
14
  const internal = [
16
15
  ruleCompile({
16
+ compiled: null,
17
17
  excludes: true,
18
18
  pattern: [".git", ".DS_Store"],
19
- compiled: null,
20
19
  }),
21
20
  ];
22
21
  /**
23
22
  * @since 0.6.0
24
23
  */
25
24
  export const JSR = {
26
- internalRules: internal,
27
25
  extractors,
28
- root: ".",
29
- async init({ fs, cwd }) {
30
- let content;
26
+ ignores: ruleTest,
27
+ init({ fs, cwd }, cb) {
31
28
  const normalCwd = unixify(cwd);
32
- let path;
33
- for (const [i, { path: p }] of extractors.entries()) {
34
- path = p;
35
- try {
36
- content = await fs.promises.readFile(normalCwd + "/" + path);
29
+ let i = 0;
30
+ function next() {
31
+ if (i >= extractors.length) {
32
+ cb(new Error("Error while initializing JSR: No valid manifest found"));
33
+ return;
37
34
  }
38
- catch (error) {
39
- if (error.code === "ENOENT") {
40
- if (i < extractors.length - 1) {
41
- continue;
42
- }
35
+ const extractor = extractors[i++];
36
+ fs.readFile(normalCwd + "/" + extractor.path, (err, data) => {
37
+ if (err) {
38
+ next();
39
+ return;
43
40
  }
44
- throw new Error("Error while initializing Deno", { cause: error });
45
- }
46
- }
47
- const dist = jsrManifestParse(content.toString());
48
- if (dist instanceof type.errors) {
49
- throw new Error("Invalid '" + path + "': " + dist.summary, { cause: dist });
41
+ try {
42
+ jsrManifestParse(data.toString());
43
+ }
44
+ catch (error) {
45
+ cb(new Error("Invalid '" + extractor.path + "'", { cause: error }));
46
+ return;
47
+ }
48
+ cb();
49
+ });
50
50
  }
51
+ next();
51
52
  },
52
- ignores: ruleTest,
53
+ internalRules: internal,
54
+ root: ".",
53
55
  };
@@ -1,10 +1,11 @@
1
- export declare const jsrManifest: import("arktype/internal/variants/object.ts").ObjectType<{
1
+ export interface JsrPublishConfig {
2
+ include?: string[];
3
+ exclude?: string[];
4
+ }
5
+ export interface JsrManifest extends JsrPublishConfig {
2
6
  name: string;
3
7
  version: string;
4
8
  exports: string | Record<string, string>;
5
- }, {}>;
6
- export declare const jsrManifestParse: import("arktype/internal/variants/object.ts").ObjectType<(In: string) => import("arktype/internal/attributes.ts").To<{
7
- name: string;
8
- version: string;
9
- exports: string | Record<string, string>;
10
- }>, {}>;
9
+ publish?: JsrPublishConfig;
10
+ }
11
+ export declare function jsrManifestParse(s: string): JsrManifest;