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
@@ -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;
@@ -1,9 +1,40 @@
1
- import { type } from "arktype";
2
- export const jsrManifest = type({
3
- name: "string",
4
- version: "string",
5
- exports: "string | Record<string, string>",
6
- });
7
- export const jsrManifestParse = type("string")
8
- .pipe((s) => JSON.parse(s))
9
- .pipe(jsrManifest);
1
+ function isArrayOfStrings(value) {
2
+ return Array.isArray(value) && value.every((v) => typeof v === "string");
3
+ }
4
+ export function jsrManifestParse(s) {
5
+ const parsed = JSON.parse(s);
6
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
7
+ throw new Error("JSR manifest must be a JSON object");
8
+ }
9
+ // Basic runtime validation for required fields
10
+ const { name, version, exports, include, exclude, publish } = parsed;
11
+ if (typeof name !== "string") {
12
+ throw new Error("Missing or invalid 'name' in manifest");
13
+ }
14
+ if (typeof version !== "string") {
15
+ throw new Error("Missing or invalid 'version' in manifest");
16
+ }
17
+ if (typeof exports !== "string" && (typeof exports !== "object" || exports === null)) {
18
+ throw new Error("Missing or invalid 'exports' in manifest");
19
+ }
20
+ // Validation for include / exclude
21
+ if ("include" in parsed && !isArrayOfStrings(include)) {
22
+ throw new Error("'include' field must be an array of strings");
23
+ }
24
+ if ("exclude" in parsed && !isArrayOfStrings(exclude)) {
25
+ throw new Error("'exclude' field must be an array of strings");
26
+ }
27
+ // Validation for publish block
28
+ if ("publish" in parsed) {
29
+ if (!publish || typeof publish !== "object" || Array.isArray(publish)) {
30
+ throw new Error("'publish' field must be an object");
31
+ }
32
+ if ("include" in publish && !isArrayOfStrings(publish.include)) {
33
+ throw new Error("'publish.include' field must be an array of strings");
34
+ }
35
+ if ("exclude" in publish && !isArrayOfStrings(publish.exclude)) {
36
+ throw new Error("'publish.exclude' field must be an array of strings");
37
+ }
38
+ }
39
+ return parsed;
40
+ }
@@ -1,4 +1,3 @@
1
- import { type } from "arktype";
2
1
  import { ruleTest, ruleCompile, extractPackageJson, extractGitignore, } from "../patterns/index.js";
3
2
  import { 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/npm/npm-packlist/blob/main/lib/index.js#L16
@@ -54,9 +54,9 @@ const internal = [
54
54
  "/pnpm-lock.yaml",
55
55
  "/bun.lockb",
56
56
  ],
57
- compiled: null,
58
57
  }),
59
58
  ruleCompile({
59
+ compiled: null,
60
60
  excludes: false,
61
61
  pattern: [
62
62
  // https://github.com/npm/npm-packlist/blob/main/lib/index.js#L287
@@ -71,33 +71,40 @@ const internal = [
71
71
  "LICENSE.*",
72
72
  "LICENCE.*",
73
73
  ],
74
- compiled: null,
75
74
  }),
76
75
  ];
77
76
  /**
78
77
  * @since 0.6.0
79
78
  */
80
79
  export const NPM = {
81
- internalRules: internal,
82
80
  extractors,
83
- root: ".",
84
- async init({ fs, cwd }) {
85
- let content;
81
+ ignores: ruleTest,
82
+ init({ fs, cwd }, cb) {
86
83
  const normalCwd = unixify(cwd);
87
- try {
88
- content = await fs.promises.readFile(normalCwd + "/" + "package.json");
89
- }
90
- catch (error) {
91
- throw new Error("Error while initializing NPM", { cause: error });
92
- }
93
- const dist = npmManifestParse(content.toString());
94
- if (dist instanceof type.errors) {
95
- throw new Error("Invalid 'package.json': " + dist.summary, { cause: dist });
96
- }
97
- // const set = new Set<string>()
98
- // TODO: NPM should include bundled deps
99
- // internalInclude.pattern = Array.from(set)
100
- // ruleCompile(internalInclude, { nocase: true })
84
+ fs.readFile(normalCwd + "/package.json", (err, content) => {
85
+ if (err) {
86
+ const error = err;
87
+ if (error.code === "ENOENT") {
88
+ cb(new Error("'package.json' not found", { cause: error }));
89
+ return;
90
+ }
91
+ cb(new Error("Error while initializing NPM", { cause: error }));
92
+ return;
93
+ }
94
+ try {
95
+ npmManifestParse(content.toString());
96
+ }
97
+ catch (error) {
98
+ cb(new Error("Invalid 'package.json'", { cause: error }));
99
+ return;
100
+ }
101
+ // const set = new Set<string>()
102
+ // TODO: NPM should include bundled deps
103
+ // internalInclude.pattern = Array.from(set)
104
+ // ruleCompile(internalInclude, { nocase: true })
105
+ cb();
106
+ });
101
107
  },
102
- ignores: ruleTest,
108
+ internalRules: internal,
109
+ root: ".",
103
110
  };