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.
- package/README.md +118 -62
- package/out/browser.d.ts +1 -0
- package/out/browser.js +1 -0
- package/out/browser_scan.d.ts +1 -3
- package/out/browser_scan.js +11 -46
- package/out/browser_stream.d.ts +6 -1
- package/out/browser_stream.js +6 -1
- package/out/index.d.ts +1 -0
- package/out/index.js +1 -0
- package/out/patterns/extractor.d.ts +7 -7
- package/out/patterns/gitignore.d.ts +2 -2
- package/out/patterns/gitignore.js +14 -6
- package/out/patterns/ignores.d.ts +23 -8
- package/out/patterns/index.d.ts +1 -0
- package/out/patterns/index.js +1 -0
- package/out/patterns/init.d.ts +2 -2
- package/out/patterns/initState.d.ts +0 -7
- package/out/patterns/jsrjson.d.ts +2 -3
- package/out/patterns/jsrjson.js +25 -38
- package/out/patterns/matcherContext.d.ts +12 -9
- package/out/patterns/matcherContextPatch.js +158 -75
- package/out/patterns/matcherStream.d.ts +30 -11
- package/out/patterns/matcherStream.js +70 -25
- package/out/patterns/packagejson.d.ts +2 -2
- package/out/patterns/packagejson.js +11 -14
- package/out/patterns/patternCompile.js +48 -19
- package/out/patterns/patternList.d.ts +12 -6
- package/out/patterns/patternList.js +8 -4
- package/out/patterns/resolveSources.d.ts +22 -5
- package/out/patterns/resolveSources.js +153 -97
- package/out/patterns/resource.d.ts +16 -0
- package/out/patterns/resource.js +1 -0
- package/out/patterns/rule.d.ts +63 -9
- package/out/patterns/rule.js +101 -66
- package/out/patterns/source.d.ts +9 -17
- package/out/scan.d.ts +11 -3
- package/out/scan.js +16 -4
- package/out/scanCb.d.ts +16 -0
- package/out/scanCb.js +73 -0
- package/out/scanParallel.d.ts +18 -0
- package/out/scanParallel.js +146 -0
- package/out/stream.d.ts +6 -1
- package/out/stream.js +7 -2
- package/out/targets/bun.js +43 -36
- package/out/targets/deno.js +25 -23
- package/out/targets/git.js +3 -3
- package/out/targets/jsr.js +25 -23
- package/out/targets/jsrManifest.d.ts +8 -7
- package/out/targets/jsrManifest.js +40 -9
- package/out/targets/npm.js +30 -23
- package/out/targets/npmManifest.d.ts +18 -46
- package/out/targets/npmManifest.js +96 -23
- package/out/targets/target.d.ts +8 -16
- package/out/targets/vsce.js +20 -27
- package/out/targets/vsceManifest.d.ts +7 -0
- package/out/targets/vsceManifest.js +18 -0
- package/out/targets/yarn.js +48 -39
- package/out/targets/yarnClassic.js +20 -18
- package/out/types.d.ts +8 -7
- package/out/unixify.d.ts +1 -1
- package/out/unixify.js +40 -21
- package/out/walk.d.ts +43 -4
- package/out/walk.js +146 -84
- package/package.json +27 -23
- package/out/getDepth.d.ts +0 -4
- package/out/getDepth.js +0 -21
- package/out/opendir.d.ts +0 -3
- package/out/opendir.js +0 -22
|
@@ -1,46 +1,18 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
dependencies?: Record<string, string
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
+
}
|
package/out/targets/target.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Extractor } from "../patterns/extractor.js";
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
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
|
-
*
|
|
32
|
+
* @see {@link IgnoresCb}
|
|
33
33
|
*
|
|
34
|
-
* @
|
|
35
|
-
*
|
|
36
|
-
* @since 0.6.0
|
|
34
|
+
* @since 0.11.0
|
|
37
35
|
*/
|
|
38
|
-
ignores:
|
|
36
|
+
ignores: IgnoresCb;
|
|
39
37
|
/**
|
|
40
|
-
*
|
|
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.
|
|
40
|
+
* @since 0.11.0
|
|
49
41
|
*/
|
|
50
|
-
init?:
|
|
42
|
+
init?: InitCb;
|
|
51
43
|
}
|
package/out/targets/vsce.js
CHANGED
|
@@ -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 {
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
let content;
|
|
63
|
+
ignores: ruleTest,
|
|
64
|
+
init({ fs, cwd }, cb) {
|
|
77
65
|
const normalCwd = unixify(cwd);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
81
|
+
internalRules: internal,
|
|
82
|
+
root: ".",
|
|
90
83
|
};
|
|
@@ -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
|
+
}
|
package/out/targets/yarn.js
CHANGED
|
@@ -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
|
-
|
|
64
|
-
|
|
65
|
-
let content;
|
|
61
|
+
ignores: ruleTest,
|
|
62
|
+
init({ fs, cwd }, cb) {
|
|
66
63
|
const normalCwd = unixify(cwd);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
106
|
+
internalRules: internal,
|
|
107
|
+
root: ".",
|
|
99
108
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type } from "arktype";
|
|
2
1
|
import { ruleTest, ruleCompile, extractPackageJsonNocase, extractGitignoreNocase, } from "../patterns/index.js";
|
|
3
2
|
import { unixify } from "../unixify.js";
|
|
4
3
|
import { npmManifestParse } from "./npmManifest.js";
|
|
@@ -22,6 +21,7 @@ const extractors = [
|
|
|
22
21
|
];
|
|
23
22
|
const internal = [
|
|
24
23
|
ruleCompile({
|
|
24
|
+
compiled: null,
|
|
25
25
|
excludes: true,
|
|
26
26
|
pattern: [
|
|
27
27
|
// https://github.com/yarnpkg/berry/blob/master/packages/plugin-pack/sources/packUtils.ts#L26
|
|
@@ -53,9 +53,9 @@ const internal = [
|
|
|
53
53
|
".gitignore",
|
|
54
54
|
".DS_Store",
|
|
55
55
|
],
|
|
56
|
-
compiled: null,
|
|
57
56
|
}, { nocase: true }),
|
|
58
57
|
ruleCompile({
|
|
58
|
+
compiled: null,
|
|
59
59
|
excludes: false,
|
|
60
60
|
pattern: [
|
|
61
61
|
// https://github.com/yarnpkg/berry/blob/master/packages/plugin-pack/sources/packUtils.ts#L10
|
|
@@ -67,29 +67,31 @@ const internal = [
|
|
|
67
67
|
"/changelog*",
|
|
68
68
|
"/history*",
|
|
69
69
|
],
|
|
70
|
-
compiled: null,
|
|
71
70
|
}, { nocase: true }),
|
|
72
71
|
];
|
|
73
72
|
/**
|
|
74
73
|
* @since 0.8.0
|
|
75
74
|
*/
|
|
76
75
|
export const YarnClassic = {
|
|
77
|
-
internalRules: internal,
|
|
78
76
|
extractors,
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
let content;
|
|
77
|
+
ignores: ruleTest,
|
|
78
|
+
init({ fs, cwd }, cb) {
|
|
82
79
|
const normalCwd = unixify(cwd);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
80
|
+
fs.readFile(normalCwd + "/package.json", (err, content) => {
|
|
81
|
+
if (err) {
|
|
82
|
+
cb(new Error("Error while initializing Yarn classic", { cause: err }));
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
npmManifestParse(content.toString());
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
cb(new Error("Invalid 'package.json'", { cause: error }));
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
cb();
|
|
93
|
+
});
|
|
93
94
|
},
|
|
94
|
-
|
|
95
|
+
internalRules: internal,
|
|
96
|
+
root: ".",
|
|
95
97
|
};
|
package/out/types.d.ts
CHANGED
|
@@ -6,10 +6,11 @@ import type { Target } from "./targets/target.js";
|
|
|
6
6
|
* @since 0.6.0
|
|
7
7
|
*/
|
|
8
8
|
export interface FsAdapter {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
/**
|
|
10
|
+
* `readdir` is better than `opendir`.
|
|
11
|
+
*/
|
|
12
|
+
readdir: typeof fs.readdir;
|
|
13
|
+
readFile: typeof fs.readFile;
|
|
13
14
|
}
|
|
14
15
|
/**
|
|
15
16
|
* Used in multiple methods, primarily `scan`, `scanStream`, and their browser versions.
|
|
@@ -76,10 +77,10 @@ export type ScanOptions = {
|
|
|
76
77
|
* {@link MatcherContext.totalDirs},
|
|
77
78
|
* {@link MatcherContext.totalFiles},
|
|
78
79
|
* {@link MatcherContext.totalMatchedFiles}
|
|
79
|
-
* and {@link MatcherContext.depthPaths}.
|
|
80
|
+
* and {@link MatcherContext.depthPaths} numbers.
|
|
80
81
|
*
|
|
81
82
|
* It's recommended to use this option unless you
|
|
82
|
-
*
|
|
83
|
+
* care about these stats.
|
|
83
84
|
*
|
|
84
85
|
* @default `false`
|
|
85
86
|
*
|
|
@@ -97,7 +98,7 @@ export type ScanOptions = {
|
|
|
97
98
|
* and {@link MatcherContext.depthPaths}.
|
|
98
99
|
*
|
|
99
100
|
* It's recommended to use this option unless the target
|
|
100
|
-
* allows overriding internal patterns.
|
|
101
|
+
* allows overriding internal patterns and you don't care about these stats.
|
|
101
102
|
* This option should never affect {@link MatcherContext.totalMatchedFiles}.
|
|
102
103
|
*
|
|
103
104
|
* @default `false`
|
package/out/unixify.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare function unixify(path: string): string;
|
|
2
2
|
export declare function join(from: string, p2: string): string;
|
|
3
3
|
export declare function relative(base: string, to: string): string;
|
|
4
|
-
export declare function
|
|
4
|
+
export declare function dirname(path: string): string;
|
package/out/unixify.js
CHANGED
|
@@ -1,38 +1,57 @@
|
|
|
1
1
|
const strippedCwd = strip(process.cwd());
|
|
2
2
|
export function unixify(path) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const result = strip(path);
|
|
4
|
+
const c0 = result.charCodeAt(0);
|
|
5
|
+
if (c0 === 46 && result.charCodeAt(1) === 47) {
|
|
6
|
+
// "./"
|
|
7
|
+
return strippedCwd + result.substring(1);
|
|
6
8
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
if (c0 !== 47 && c0 !== 92) {
|
|
10
|
+
// not starts with "/" or "\"
|
|
11
|
+
return strippedCwd + "/" + result;
|
|
9
12
|
}
|
|
10
13
|
return result;
|
|
11
14
|
}
|
|
12
15
|
export function join(from, p2) {
|
|
13
|
-
if (p2 === "." || p2 === "./")
|
|
16
|
+
if (p2 === "." || p2 === "./")
|
|
14
17
|
return from;
|
|
18
|
+
const p2startsDotSlash = p2.charCodeAt(0) === 46 && p2.charCodeAt(1) === 47;
|
|
19
|
+
const start = p2startsDotSlash ? 2 : 0;
|
|
20
|
+
let res = from;
|
|
21
|
+
if (from.charCodeAt(0) === 46 && from.charCodeAt(1) === 47) {
|
|
22
|
+
res = from.substring(2);
|
|
15
23
|
}
|
|
16
|
-
|
|
17
|
-
if (
|
|
18
|
-
|
|
24
|
+
const resLen = res.length;
|
|
25
|
+
if (resLen > 0 && res.charCodeAt(resLen - 1) !== 47) {
|
|
26
|
+
res += "/";
|
|
19
27
|
}
|
|
20
|
-
|
|
21
|
-
from += "/";
|
|
22
|
-
}
|
|
23
|
-
from += p2.substring(start);
|
|
24
|
-
return from;
|
|
28
|
+
return res + p2.substring(start);
|
|
25
29
|
}
|
|
26
30
|
export function relative(base, to) {
|
|
27
|
-
|
|
31
|
+
const blen = base.length;
|
|
32
|
+
if (blen > 0 && base.charCodeAt(blen - 1) !== 47) {
|
|
28
33
|
base += "/";
|
|
29
34
|
}
|
|
30
|
-
|
|
31
|
-
return result;
|
|
32
|
-
}
|
|
33
|
-
export function base(path) {
|
|
34
|
-
return path.substring(path.lastIndexOf("/") + 1);
|
|
35
|
+
return to.replace(base, "");
|
|
35
36
|
}
|
|
36
37
|
function strip(path) {
|
|
37
|
-
|
|
38
|
+
let res = path.indexOf("\\") === -1 ? path : path.replaceAll("\\", "/");
|
|
39
|
+
if (res.length > 1 && res.charCodeAt(1) === 58) {
|
|
40
|
+
// X:
|
|
41
|
+
res = res.substring(2);
|
|
42
|
+
}
|
|
43
|
+
return res;
|
|
44
|
+
}
|
|
45
|
+
export function dirname(path) {
|
|
46
|
+
if (path === "/" || path === ".")
|
|
47
|
+
return path;
|
|
48
|
+
const len = path.length;
|
|
49
|
+
const lastIdx = len - 1;
|
|
50
|
+
const endsWithSlash = path.charCodeAt(lastIdx) === 47;
|
|
51
|
+
const lastSlash = path.lastIndexOf("/", endsWithSlash ? lastIdx - 1 : lastIdx);
|
|
52
|
+
if (lastSlash === -1)
|
|
53
|
+
return ".";
|
|
54
|
+
if (lastSlash === 0)
|
|
55
|
+
return "/";
|
|
56
|
+
return path.substring(0, lastSlash);
|
|
38
57
|
}
|