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.
- package/README.md +116 -66
- 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 +17 -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 +153 -73
- package/out/patterns/matcherStream.d.ts +19 -59
- package/out/patterns/matcherStream.js +75 -25
- package/out/patterns/matcherStreamTypes.d.ts +65 -0
- package/out/patterns/matcherStreamTypes.js +1 -0
- package/out/patterns/packagejson.d.ts +2 -2
- package/out/patterns/packagejson.js +11 -14
- package/out/patterns/patternCompile.js +35 -37
- package/out/patterns/patternList.d.ts +6 -2
- package/out/patterns/patternList.js +8 -3
- 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 +59 -11
- package/out/patterns/rule.js +101 -64
- 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 +42 -4
- package/out/walk.js +146 -92
- package/package.json +42 -27
- 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 -28
|
@@ -1,9 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
+
}
|
package/out/targets/npm.js
CHANGED
|
@@ -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
|
-
|
|
84
|
-
|
|
85
|
-
let content;
|
|
81
|
+
ignores: ruleTest,
|
|
82
|
+
init({ fs, cwd }, cb) {
|
|
86
83
|
const normalCwd = unixify(cwd);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
108
|
+
internalRules: internal,
|
|
109
|
+
root: ".",
|
|
103
110
|
};
|
|
@@ -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
|
};
|