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
@@ -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
  };
@@ -1,46 +1,18 @@
1
- export declare const npmManifest: import("arktype/internal/variants/object.ts").ObjectType<{
2
- main?: string | undefined;
3
- module?: string | undefined;
4
- browser?: string | undefined;
5
- files?: string[] | undefined;
6
- bin?: string | Record<string, string> | undefined;
7
- optionalDependencies?: Record<string, string> | undefined;
8
- devDependencies?: Record<string, string> | undefined;
9
- dependencies?: Record<string, string> | undefined;
10
- bundleDependencies?: string[] | undefined;
11
- bundledDependencies?: undefined;
12
- } | {
13
- main?: string | undefined;
14
- module?: string | undefined;
15
- browser?: string | undefined;
16
- files?: string[] | undefined;
17
- bin?: string | Record<string, string> | undefined;
18
- optionalDependencies?: Record<string, string> | undefined;
19
- devDependencies?: Record<string, string> | undefined;
20
- dependencies?: Record<string, string> | undefined;
21
- bundledDependencies?: string[] | undefined;
22
- bundleDependencies?: undefined;
23
- }, {}>;
24
- export declare const npmManifestParse: import("arktype/internal/variants/object.ts").ObjectType<(In: string) => import("arktype/internal/attributes.ts").To<{
25
- main?: string | undefined;
26
- module?: string | undefined;
27
- browser?: string | undefined;
28
- files?: string[] | undefined;
29
- bin?: string | Record<string, string> | undefined;
30
- optionalDependencies?: Record<string, string> | undefined;
31
- devDependencies?: Record<string, string> | undefined;
32
- dependencies?: Record<string, string> | undefined;
33
- bundleDependencies?: string[] | undefined;
34
- bundledDependencies?: undefined;
35
- }> | import("arktype/internal/attributes.ts").To<{
36
- main?: string | undefined;
37
- module?: string | undefined;
38
- browser?: string | undefined;
39
- files?: string[] | undefined;
40
- bin?: string | Record<string, string> | undefined;
41
- optionalDependencies?: Record<string, string> | undefined;
42
- devDependencies?: Record<string, string> | undefined;
43
- dependencies?: Record<string, string> | undefined;
44
- bundledDependencies?: string[] | undefined;
45
- bundleDependencies?: undefined;
46
- }>, {}>;
1
+ export interface PackageJson {
2
+ name: string;
3
+ version: string;
4
+ private?: boolean;
5
+ engines?: Record<string, string>;
6
+ scripts?: Record<string, string>;
7
+ bin?: string | Record<string, string>;
8
+ browser?: string;
9
+ dependencies?: Record<string, string>;
10
+ devDependencies?: Record<string, string>;
11
+ files?: string[];
12
+ main?: string;
13
+ module?: string;
14
+ optionalDependencies?: Record<string, string>;
15
+ bundleDependencies?: string[];
16
+ bundledDependencies?: string[];
17
+ }
18
+ export declare function npmManifestParse(s: string): PackageJson;
@@ -1,23 +1,96 @@
1
- import { type } from "arktype";
2
- const baseManifest = type({
3
- "main?": "string",
4
- "module?": "string",
5
- "browser?": "string",
6
- "files?": "string[]",
7
- "bin?": "string | Record<string, string>",
8
- "optionalDependencies?": "Record<string, string>",
9
- "devDependencies?": "Record<string, string>",
10
- "dependencies?": "Record<string, string>",
11
- });
12
- const withBundle = baseManifest.and({
13
- "bundleDependencies?": "string[]",
14
- "bundledDependencies?": "never",
15
- });
16
- const withBundled = baseManifest.and({
17
- "bundledDependencies?": "string[]",
18
- "bundleDependencies?": "never",
19
- });
20
- export const npmManifest = withBundle.or(withBundled);
21
- export const npmManifestParse = type("string")
22
- .pipe((s) => JSON.parse(s))
23
- .pipe(npmManifest);
1
+ function isValidNpmName(name) {
2
+ if (name.trim() !== name || name.length === 0 || name.length > 214) {
3
+ return false;
4
+ }
5
+ if (name.startsWith("@")) {
6
+ const parts = name.slice(1).split("/");
7
+ if (parts.length !== 2 || parts[0] === "" || parts[1] === "") {
8
+ return false;
9
+ }
10
+ return isValidNameComponent(parts[0]) && isValidNameComponent(parts[1]);
11
+ }
12
+ return isValidNameComponent(name);
13
+ }
14
+ function isValidNameComponent(part) {
15
+ if (part.startsWith(".") || part.startsWith("_") || part !== part.toLowerCase()) {
16
+ return false;
17
+ }
18
+ if (/[~!'()* ]/.test(part)) {
19
+ return false;
20
+ }
21
+ try {
22
+ return encodeURIComponent(part) === part;
23
+ }
24
+ catch {
25
+ return false;
26
+ }
27
+ }
28
+ function isRecordOfStrings(value) {
29
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
30
+ return false;
31
+ }
32
+ return Object.values(value).every((v) => typeof v === "string");
33
+ }
34
+ function isArrayOfStrings(value) {
35
+ return Array.isArray(value) && value.every((v) => typeof v === "string");
36
+ }
37
+ const SEMVER_REGEX = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
38
+ export function npmManifestParse(s) {
39
+ const parsed = JSON.parse(s);
40
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
41
+ throw new Error("npm manifest must be a JSON object");
42
+ }
43
+ if ("private" in parsed && typeof parsed.private !== "boolean") {
44
+ throw new Error("'private' field must be a boolean");
45
+ }
46
+ if (!parsed.private) {
47
+ if (typeof parsed.name !== "string") {
48
+ throw new Error("Manifest must have a non-empty string 'name'");
49
+ }
50
+ if (typeof parsed.version !== "string") {
51
+ throw new Error("Manifest must have a non-empty string 'version'");
52
+ }
53
+ if (!isValidNpmName(parsed.name)) {
54
+ throw new Error(`'${parsed.name}' is not a valid npm package name`);
55
+ }
56
+ // Strict SemVer verification
57
+ if (!SEMVER_REGEX.test(parsed.version)) {
58
+ throw new Error(`'${parsed.version}' is not a valid SemVer version (expected format: X.Y.Z)`);
59
+ }
60
+ }
61
+ if ("bundleDependencies" in parsed && "bundledDependencies" in parsed) {
62
+ throw new Error("Manifest cannot contain both 'bundleDependencies' and 'bundledDependencies'");
63
+ }
64
+ const stringFields = ["browser", "main", "module"];
65
+ for (const field of stringFields) {
66
+ if (field in parsed && typeof parsed[field] !== "string") {
67
+ throw new Error(`'${field}' field must be a string`);
68
+ }
69
+ }
70
+ const recordFields = [
71
+ "engines",
72
+ "scripts",
73
+ "dependencies",
74
+ "devDependencies",
75
+ "optionalDependencies",
76
+ ];
77
+ for (const field of recordFields) {
78
+ if (field in parsed && !isRecordOfStrings(parsed[field])) {
79
+ throw new Error(`'${field}' field must be an object with string values`);
80
+ }
81
+ }
82
+ const arrayFields = ["files", "bundleDependencies", "bundledDependencies"];
83
+ for (const field of arrayFields) {
84
+ if (field in parsed && !isArrayOfStrings(parsed[field])) {
85
+ throw new Error(`'${field}' field must be an array of strings`);
86
+ }
87
+ }
88
+ if ("bin" in parsed) {
89
+ const binValue = parsed.bin;
90
+ const isValidBin = typeof binValue === "string" || isRecordOfStrings(binValue);
91
+ if (!isValidBin) {
92
+ throw new Error("'bin' field must be a string or an object with string values");
93
+ }
94
+ }
95
+ return parsed;
96
+ }
@@ -1,6 +1,6 @@
1
1
  import type { Extractor } from "../patterns/extractor.js";
2
- import type { Ignores } from "../patterns/ignores.js";
3
- import type { Init } from "../patterns/init.js";
2
+ import type { IgnoresCb } from "../patterns/ignores.js";
3
+ import type { InitCb } from "../patterns/init.js";
4
4
  import type { Rule } from "../patterns/rule.js";
5
5
  /**
6
6
  * Contains the matcher used for scanning.
@@ -29,23 +29,15 @@ export interface Target {
29
29
  */
30
30
  extractors: Extractor[];
31
31
  /**
32
- * Glob-pattern parser.
32
+ * @see {@link IgnoresCb}
33
33
  *
34
- * @see {@link Ignores}
35
- *
36
- * @since 0.6.0
34
+ * @since 0.11.0
37
35
  */
38
- ignores: Ignores;
36
+ ignores: IgnoresCb;
39
37
  /**
40
- * Initialization function.
41
- * Called by the scanner method.
42
- *
43
- * @example
44
- * scan({ target: { ...Git, init: undefined } })
45
- *
46
- * @see {@link Init}
38
+ * @see {@link InitCb}
47
39
  *
48
- * @since 0.8.0
40
+ * @since 0.11.0
49
41
  */
50
- init?: Init;
42
+ init?: InitCb;
51
43
  }
@@ -1,7 +1,6 @@
1
- import { type } from "arktype";
2
1
  import { ruleTest, ruleCompile, extractPackageJson, extractGitignore, } from "../patterns/index.js";
3
2
  import { unixify } from "../unixify.js";
4
- import { npmManifest } from "./npmManifest.js";
3
+ import { vsceManifestParse } from "./vsceManifest.js";
5
4
  const extractors = [
6
5
  {
7
6
  extract: extractPackageJson,
@@ -18,6 +17,7 @@ const extractors = [
18
17
  ];
19
18
  const internal = [
20
19
  ruleCompile({
20
+ compiled: null,
21
21
  excludes: true,
22
22
  pattern: [
23
23
  // https://github.com/microsoft/vscode-vsce/blob/main/src/package.ts#L1633
@@ -53,38 +53,31 @@ const internal = [
53
53
  ".vscode-test",
54
54
  ".vscode-test-web",
55
55
  ],
56
- compiled: null,
57
56
  }),
58
57
  ];
59
- const vsceManifest = npmManifest.and({
60
- engines: {
61
- // https://github.com/microsoft/vscode-vsce/blob/main/src/validation.ts#L52
62
- vscode: "/^\\*$|^(\\^|>=)?((\\d+)|x)\\.((\\d+)|x)\\.((\\d+)|x)(\\-.*)?$/",
63
- },
64
- });
65
- const vsceManifestParse = type("string")
66
- .pipe((s) => JSON.parse(s))
67
- .pipe(vsceManifest);
68
58
  /**
69
59
  * @since 0.6.0
70
60
  */
71
61
  export const VSCE = {
72
- internalRules: internal,
73
62
  extractors,
74
- root: ".",
75
- async init({ fs, cwd }) {
76
- let content;
63
+ ignores: ruleTest,
64
+ init({ fs, cwd }, cb) {
77
65
  const normalCwd = unixify(cwd);
78
- try {
79
- content = await fs.promises.readFile(normalCwd + "/" + "package.json");
80
- }
81
- catch (error) {
82
- throw new Error("Error while initializing VSCE", { cause: error });
83
- }
84
- const dist = vsceManifestParse(content.toString());
85
- if (dist instanceof type.errors) {
86
- throw new Error("Invalid 'package.json': " + dist.summary, { cause: dist });
87
- }
66
+ fs.readFile(normalCwd + "/package.json", (err, content) => {
67
+ if (err) {
68
+ cb(new Error("Error while initializing VSCE", { cause: err }));
69
+ return;
70
+ }
71
+ try {
72
+ vsceManifestParse(content.toString());
73
+ }
74
+ catch (error) {
75
+ cb(new Error("Invalid 'package.json'", { cause: error }));
76
+ return;
77
+ }
78
+ cb();
79
+ });
88
80
  },
89
- ignores: ruleTest,
81
+ internalRules: internal,
82
+ root: ".",
90
83
  };
@@ -0,0 +1,7 @@
1
+ import { type PackageJson } from "./npmManifest.js";
2
+ export interface VsceManifest extends PackageJson {
3
+ engines: {
4
+ vscode: string;
5
+ };
6
+ }
7
+ export declare function vsceManifestParse(s: string): VsceManifest;
@@ -0,0 +1,18 @@
1
+ import { npmManifestParse } from "./npmManifest.js";
2
+ // Regex source: https://github.com/microsoft/vscode-vsce/blob/main/src/validation.ts#L52
3
+ const VSCODE_ENGINE_REGEX = /^\*$|^(\^|>=)?((\d+)|x)\.((\d+)|x)\.((\d+)|x)(-.*)?$/;
4
+ export function vsceManifestParse(s) {
5
+ const parsed = npmManifestParse(s);
6
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
7
+ throw new Error("VSCE manifest must be a JSON object");
8
+ }
9
+ if (!parsed.engines ||
10
+ typeof parsed.engines !== "object" ||
11
+ typeof parsed.engines.vscode !== "string") {
12
+ throw new Error("VSCE manifest must include an 'engines.vscode' string");
13
+ }
14
+ if (!VSCODE_ENGINE_REGEX.test(parsed.engines.vscode)) {
15
+ throw new Error(`Invalid 'engines.vscode' version format: "${parsed.engines.vscode}"`);
16
+ }
17
+ return parsed;
18
+ }
@@ -1,4 +1,3 @@
1
- import { type } from "arktype";
2
1
  import { ruleTest, ruleCompile, extractPackageJsonNocase, extractGitignoreNocase, } 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: [],
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/yarnpkg/berry/blob/master/packages/plugin-pack/sources/packUtils.ts#L26
@@ -37,9 +37,9 @@ const internal = [
37
37
  ".#*",
38
38
  ".DS_Store",
39
39
  ],
40
- compiled: null,
41
40
  }),
42
41
  ruleCompile({
42
+ compiled: null,
43
43
  excludes: false,
44
44
  pattern: [
45
45
  // https://github.com/yarnpkg/berry/blob/master/packages/plugin-pack/sources/packUtils.ts#L10
@@ -51,49 +51,58 @@ const internal = [
51
51
  "/LICENCE",
52
52
  "/LICENCE.*",
53
53
  ],
54
- compiled: null,
55
54
  }, { nocase: true }),
56
55
  ];
57
56
  /**
58
57
  * @since 0.6.0
59
58
  */
60
59
  export const Yarn = {
61
- internalRules: internal,
62
60
  extractors,
63
- root: ".",
64
- async init({ fs, cwd }) {
65
- let content;
61
+ ignores: ruleTest,
62
+ init({ fs, cwd }, cb) {
66
63
  const normalCwd = unixify(cwd);
67
- try {
68
- content = await fs.promises.readFile(normalCwd + "/" + "package.json");
69
- }
70
- catch (error) {
71
- throw new Error("Error while initializing Yarn", { cause: error });
72
- }
73
- const dist = npmManifestParse(content.toString());
74
- if (dist instanceof type.errors) {
75
- throw new Error("Invalid 'package.json': " + dist.summary, { cause: dist });
76
- }
77
- // https://github.com/yarnpkg/berry/blob/master/packages/plugin-pack/sources/packUtils.ts#L215-L231
78
- const set = new Set();
79
- function normal(path) {
80
- const result = unixify(join(normalCwd, path)).substring(normalCwd.length);
81
- return result;
82
- }
83
- if (dist.main)
84
- set.add(normal(dist.main));
85
- if (dist.module)
86
- set.add(normal(dist.module));
87
- if (dist.browser)
88
- set.add(normal(dist.browser));
89
- if (typeof dist.bin === "string") {
90
- set.add(normal(dist.bin));
91
- }
92
- else if (typeof dist.bin === "object" && dist.bin !== null) {
93
- Object.values(dist.bin).forEach((binPath) => set.add(normal(binPath)));
94
- }
95
- internalInclude.pattern = Array.from(set);
96
- ruleCompile(internalInclude, { nocase: true });
64
+ fs.readFile(normalCwd + "/package.json", (err, content) => {
65
+ if (err) {
66
+ const error = err;
67
+ if (error.code === "ENOENT") {
68
+ cb();
69
+ return;
70
+ }
71
+ cb(new Error("Error while initializing Yarn", { cause: error }));
72
+ return;
73
+ }
74
+ let dist;
75
+ try {
76
+ dist = npmManifestParse(content.toString());
77
+ }
78
+ catch (error) {
79
+ cb(new Error("Invalid 'package.json'", { cause: error }));
80
+ return;
81
+ }
82
+ const set = new Set();
83
+ function normal(path) {
84
+ return unixify(join(normalCwd, path)).substring(normalCwd.length);
85
+ }
86
+ if (typeof dist.main === "string")
87
+ set.add(normal(dist.main));
88
+ if (typeof dist.module === "string")
89
+ set.add(normal(dist.module));
90
+ if (typeof dist.browser === "string")
91
+ set.add(normal(dist.browser));
92
+ if (typeof dist.bin === "string") {
93
+ set.add(normal(dist.bin));
94
+ }
95
+ else if (typeof dist.bin === "object" && dist.bin !== null) {
96
+ Object.values(dist.bin).forEach((binPath) => {
97
+ if (typeof binPath === "string")
98
+ set.add(normal(binPath));
99
+ });
100
+ }
101
+ internalInclude.pattern = Array.from(set);
102
+ ruleCompile(internalInclude, { nocase: true });
103
+ cb();
104
+ });
97
105
  },
98
- ignores: ruleTest,
106
+ internalRules: internal,
107
+ root: ".",
99
108
  };