@vltpkg/query 0.0.0-2 → 0.0.0-21
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 +39 -82
- package/dist/esm/attribute.d.ts.map +1 -1
- package/dist/esm/attribute.js +8 -13
- package/dist/esm/attribute.js.map +1 -1
- package/dist/esm/combinator.d.ts.map +1 -1
- package/dist/esm/combinator.js +5 -2
- package/dist/esm/combinator.js.map +1 -1
- package/dist/esm/id.d.ts.map +1 -1
- package/dist/esm/id.js +23 -7
- package/dist/esm/id.js.map +1 -1
- package/dist/esm/index.d.ts +35 -3
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +280 -16
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/parser.d.ts +15 -0
- package/dist/esm/parser.d.ts.map +1 -0
- package/dist/esm/parser.js +93 -0
- package/dist/esm/parser.js.map +1 -0
- package/dist/esm/pseudo/abandoned.d.ts +7 -0
- package/dist/esm/pseudo/abandoned.d.ts.map +1 -0
- package/dist/esm/pseudo/abandoned.js +6 -0
- package/dist/esm/pseudo/abandoned.js.map +1 -0
- package/dist/esm/pseudo/attr.d.ts +2 -1
- package/dist/esm/pseudo/attr.d.ts.map +1 -1
- package/dist/esm/pseudo/attr.js +10 -2
- package/dist/esm/pseudo/attr.js.map +1 -1
- package/dist/esm/pseudo/confused.d.ts +9 -0
- package/dist/esm/pseudo/confused.d.ts.map +1 -0
- package/dist/esm/pseudo/confused.js +19 -0
- package/dist/esm/pseudo/confused.js.map +1 -0
- package/dist/esm/pseudo/cve.d.ts +13 -0
- package/dist/esm/pseudo/cve.d.ts.map +1 -0
- package/dist/esm/pseudo/cve.js +44 -0
- package/dist/esm/pseudo/cve.js.map +1 -0
- package/dist/esm/pseudo/cwe.d.ts +13 -0
- package/dist/esm/pseudo/cwe.d.ts.map +1 -0
- package/dist/esm/pseudo/cwe.js +43 -0
- package/dist/esm/pseudo/cwe.js.map +1 -0
- package/dist/esm/pseudo/debug.d.ts +7 -0
- package/dist/esm/pseudo/debug.d.ts.map +1 -0
- package/dist/esm/pseudo/debug.js +6 -0
- package/dist/esm/pseudo/debug.js.map +1 -0
- package/dist/esm/pseudo/deprecated.d.ts +7 -0
- package/dist/esm/pseudo/deprecated.d.ts.map +1 -0
- package/dist/esm/pseudo/deprecated.js +6 -0
- package/dist/esm/pseudo/deprecated.js.map +1 -0
- package/dist/esm/pseudo/dev.d.ts +6 -0
- package/dist/esm/pseudo/dev.d.ts.map +1 -0
- package/dist/esm/pseudo/dev.js +15 -0
- package/dist/esm/pseudo/dev.js.map +1 -0
- package/dist/esm/pseudo/dynamic.d.ts +7 -0
- package/dist/esm/pseudo/dynamic.d.ts.map +1 -0
- package/dist/esm/pseudo/dynamic.js +6 -0
- package/dist/esm/pseudo/dynamic.js.map +1 -0
- package/dist/esm/pseudo/empty.d.ts +7 -0
- package/dist/esm/pseudo/empty.d.ts.map +1 -0
- package/dist/esm/pseudo/empty.js +14 -0
- package/dist/esm/pseudo/empty.js.map +1 -0
- package/dist/esm/pseudo/entropic.d.ts +7 -0
- package/dist/esm/pseudo/entropic.d.ts.map +1 -0
- package/dist/esm/pseudo/entropic.js +6 -0
- package/dist/esm/pseudo/entropic.js.map +1 -0
- package/dist/esm/pseudo/env.d.ts +7 -0
- package/dist/esm/pseudo/env.d.ts.map +1 -0
- package/dist/esm/pseudo/env.js +6 -0
- package/dist/esm/pseudo/env.js.map +1 -0
- package/dist/esm/pseudo/eval.d.ts +7 -0
- package/dist/esm/pseudo/eval.d.ts.map +1 -0
- package/dist/esm/pseudo/eval.js +6 -0
- package/dist/esm/pseudo/eval.js.map +1 -0
- package/dist/esm/pseudo/fs.d.ts +7 -0
- package/dist/esm/pseudo/fs.d.ts.map +1 -0
- package/dist/esm/pseudo/fs.js +6 -0
- package/dist/esm/pseudo/fs.js.map +1 -0
- package/dist/esm/pseudo/helpers.d.ts +25 -1
- package/dist/esm/pseudo/helpers.d.ts.map +1 -1
- package/dist/esm/pseudo/helpers.js +53 -0
- package/dist/esm/pseudo/helpers.js.map +1 -1
- package/dist/esm/pseudo/license.d.ts +13 -0
- package/dist/esm/pseudo/license.d.ts.map +1 -0
- package/dist/esm/pseudo/license.js +58 -0
- package/dist/esm/pseudo/license.js.map +1 -0
- package/dist/esm/pseudo/link.d.ts +9 -0
- package/dist/esm/pseudo/link.d.ts.map +1 -0
- package/dist/esm/pseudo/link.js +25 -0
- package/dist/esm/pseudo/link.js.map +1 -0
- package/dist/esm/pseudo/malware.d.ts +15 -0
- package/dist/esm/pseudo/malware.d.ts.map +1 -0
- package/dist/esm/pseudo/malware.js +165 -0
- package/dist/esm/pseudo/malware.js.map +1 -0
- package/dist/esm/pseudo/minified.d.ts +7 -0
- package/dist/esm/pseudo/minified.d.ts.map +1 -0
- package/dist/esm/pseudo/minified.js +6 -0
- package/dist/esm/pseudo/minified.js.map +1 -0
- package/dist/esm/pseudo/missing.d.ts +8 -0
- package/dist/esm/pseudo/missing.d.ts.map +1 -0
- package/dist/esm/pseudo/missing.js +15 -0
- package/dist/esm/pseudo/missing.js.map +1 -0
- package/dist/esm/pseudo/native.d.ts +7 -0
- package/dist/esm/pseudo/native.d.ts.map +1 -0
- package/dist/esm/pseudo/native.js +6 -0
- package/dist/esm/pseudo/native.js.map +1 -0
- package/dist/esm/pseudo/network.d.ts +7 -0
- package/dist/esm/pseudo/network.d.ts.map +1 -0
- package/dist/esm/pseudo/network.js +6 -0
- package/dist/esm/pseudo/network.js.map +1 -0
- package/dist/esm/pseudo/obfuscated.d.ts +7 -0
- package/dist/esm/pseudo/obfuscated.d.ts.map +1 -0
- package/dist/esm/pseudo/obfuscated.js +6 -0
- package/dist/esm/pseudo/obfuscated.js.map +1 -0
- package/dist/esm/pseudo/optional.d.ts +6 -0
- package/dist/esm/pseudo/optional.d.ts.map +1 -0
- package/dist/esm/pseudo/optional.js +15 -0
- package/dist/esm/pseudo/optional.js.map +1 -0
- package/dist/esm/pseudo/outdated.d.ts +3 -2
- package/dist/esm/pseudo/outdated.d.ts.map +1 -1
- package/dist/esm/pseudo/outdated.js +42 -31
- package/dist/esm/pseudo/outdated.js.map +1 -1
- package/dist/esm/pseudo/overridden.d.ts +8 -0
- package/dist/esm/pseudo/overridden.d.ts.map +1 -0
- package/dist/esm/pseudo/overridden.js +17 -0
- package/dist/esm/pseudo/overridden.js.map +1 -0
- package/dist/esm/pseudo/path.d.ts +19 -0
- package/dist/esm/pseudo/path.d.ts.map +1 -0
- package/dist/esm/pseudo/path.js +113 -0
- package/dist/esm/pseudo/path.js.map +1 -0
- package/dist/esm/pseudo/peer.d.ts +6 -0
- package/dist/esm/pseudo/peer.d.ts.map +1 -0
- package/dist/esm/pseudo/peer.js +15 -0
- package/dist/esm/pseudo/peer.js.map +1 -0
- package/dist/esm/pseudo/prerelease.d.ts +18 -0
- package/dist/esm/pseudo/prerelease.d.ts.map +1 -0
- package/dist/esm/pseudo/prerelease.js +41 -0
- package/dist/esm/pseudo/prerelease.js.map +1 -0
- package/dist/esm/pseudo/private.d.ts +7 -0
- package/dist/esm/pseudo/private.d.ts.map +1 -0
- package/dist/esm/pseudo/private.js +16 -0
- package/dist/esm/pseudo/private.js.map +1 -0
- package/dist/esm/pseudo/prod.d.ts +6 -0
- package/dist/esm/pseudo/prod.d.ts.map +1 -0
- package/dist/esm/pseudo/prod.js +15 -0
- package/dist/esm/pseudo/prod.js.map +1 -0
- package/dist/esm/pseudo/published.d.ts +41 -0
- package/dist/esm/pseudo/published.d.ts.map +1 -0
- package/dist/esm/pseudo/published.js +158 -0
- package/dist/esm/pseudo/published.js.map +1 -0
- package/dist/esm/pseudo/root.d.ts +8 -0
- package/dist/esm/pseudo/root.d.ts.map +1 -0
- package/dist/esm/pseudo/root.js +22 -0
- package/dist/esm/pseudo/root.js.map +1 -0
- package/dist/esm/pseudo/scanned.d.ts +9 -0
- package/dist/esm/pseudo/scanned.d.ts.map +1 -0
- package/dist/esm/pseudo/scanned.js +17 -0
- package/dist/esm/pseudo/scanned.js.map +1 -0
- package/dist/esm/pseudo/score.d.ts +16 -0
- package/dist/esm/pseudo/score.d.ts.map +1 -0
- package/dist/esm/pseudo/score.js +119 -0
- package/dist/esm/pseudo/score.js.map +1 -0
- package/dist/esm/pseudo/scripts.d.ts +7 -0
- package/dist/esm/pseudo/scripts.d.ts.map +1 -0
- package/dist/esm/pseudo/scripts.js +6 -0
- package/dist/esm/pseudo/scripts.js.map +1 -0
- package/dist/esm/pseudo/semver.d.ts +2 -1
- package/dist/esm/pseudo/semver.d.ts.map +1 -1
- package/dist/esm/pseudo/semver.js +11 -24
- package/dist/esm/pseudo/semver.js.map +1 -1
- package/dist/esm/pseudo/severity.d.ts +15 -0
- package/dist/esm/pseudo/severity.d.ts.map +1 -0
- package/dist/esm/pseudo/severity.js +160 -0
- package/dist/esm/pseudo/severity.js.map +1 -0
- package/dist/esm/pseudo/shell.d.ts +7 -0
- package/dist/esm/pseudo/shell.d.ts.map +1 -0
- package/dist/esm/pseudo/shell.js +6 -0
- package/dist/esm/pseudo/shell.js.map +1 -0
- package/dist/esm/pseudo/shrinkwrap.d.ts +7 -0
- package/dist/esm/pseudo/shrinkwrap.d.ts.map +1 -0
- package/dist/esm/pseudo/shrinkwrap.js +6 -0
- package/dist/esm/pseudo/shrinkwrap.js.map +1 -0
- package/dist/esm/pseudo/squat.d.ts +15 -0
- package/dist/esm/pseudo/squat.d.ts.map +1 -0
- package/dist/esm/pseudo/squat.js +161 -0
- package/dist/esm/pseudo/squat.js.map +1 -0
- package/dist/esm/pseudo/suspicious.d.ts +7 -0
- package/dist/esm/pseudo/suspicious.d.ts.map +1 -0
- package/dist/esm/pseudo/suspicious.js +6 -0
- package/dist/esm/pseudo/suspicious.js.map +1 -0
- package/dist/esm/pseudo/tracker.d.ts +7 -0
- package/dist/esm/pseudo/tracker.d.ts.map +1 -0
- package/dist/esm/pseudo/tracker.js +6 -0
- package/dist/esm/pseudo/tracker.js.map +1 -0
- package/dist/esm/pseudo/trivial.d.ts +7 -0
- package/dist/esm/pseudo/trivial.d.ts.map +1 -0
- package/dist/esm/pseudo/trivial.js +6 -0
- package/dist/esm/pseudo/trivial.js.map +1 -0
- package/dist/esm/pseudo/type.d.ts +8 -0
- package/dist/esm/pseudo/type.d.ts.map +1 -0
- package/dist/esm/pseudo/type.js +22 -0
- package/dist/esm/pseudo/type.js.map +1 -0
- package/dist/esm/pseudo/undesirable.d.ts +7 -0
- package/dist/esm/pseudo/undesirable.d.ts.map +1 -0
- package/dist/esm/pseudo/undesirable.js +6 -0
- package/dist/esm/pseudo/undesirable.js.map +1 -0
- package/dist/esm/pseudo/unknown.d.ts +7 -0
- package/dist/esm/pseudo/unknown.d.ts.map +1 -0
- package/dist/esm/pseudo/unknown.js +6 -0
- package/dist/esm/pseudo/unknown.js.map +1 -0
- package/dist/esm/pseudo/unmaintained.d.ts +7 -0
- package/dist/esm/pseudo/unmaintained.d.ts.map +1 -0
- package/dist/esm/pseudo/unmaintained.js +6 -0
- package/dist/esm/pseudo/unmaintained.js.map +1 -0
- package/dist/esm/pseudo/unpopular.d.ts +7 -0
- package/dist/esm/pseudo/unpopular.d.ts.map +1 -0
- package/dist/esm/pseudo/unpopular.js +6 -0
- package/dist/esm/pseudo/unpopular.js.map +1 -0
- package/dist/esm/pseudo/unstable.d.ts +7 -0
- package/dist/esm/pseudo/unstable.d.ts.map +1 -0
- package/dist/esm/pseudo/unstable.js +6 -0
- package/dist/esm/pseudo/unstable.js.map +1 -0
- package/dist/esm/pseudo/workspace.d.ts +6 -0
- package/dist/esm/pseudo/workspace.d.ts.map +1 -0
- package/dist/esm/pseudo/workspace.js +18 -0
- package/dist/esm/pseudo/workspace.js.map +1 -0
- package/dist/esm/pseudo.d.ts.map +1 -1
- package/dist/esm/pseudo.js +141 -106
- package/dist/esm/pseudo.js.map +1 -1
- package/dist/esm/types.d.ts +86 -23
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js +1 -106
- package/dist/esm/types.js.map +1 -1
- package/package.json +19 -15
- package/dist/esm/class.d.ts +0 -6
- package/dist/esm/class.d.ts.map +0 -1
- package/dist/esm/class.js +0 -128
- package/dist/esm/class.js.map +0 -1
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import pRetry, { AbortError } from 'p-retry';
|
|
2
|
+
import { hydrate, splitDepID } from '@vltpkg/dep-id/browser';
|
|
3
|
+
import { error } from '@vltpkg/error-cause';
|
|
4
|
+
import { asPostcssNodeWithChildren, asStringNode, asTagNode, isStringNode, isTagNode, } from '@vltpkg/dss-parser';
|
|
5
|
+
import { removeDanglingEdges, removeNode, removeQuotes, } from "./helpers.js";
|
|
6
|
+
/**
|
|
7
|
+
* Fetches the published date of a package version from the npm registry.
|
|
8
|
+
*/
|
|
9
|
+
export const retrieveRemoteDate = async (node, specOptions, signal) => {
|
|
10
|
+
const spec = hydrate(node.id, String(node.name), specOptions);
|
|
11
|
+
if (!spec.registry || !node.name || !node.version) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
const url = new URL(spec.registry);
|
|
15
|
+
url.pathname = `/${node.name}`;
|
|
16
|
+
const response = await fetch(String(url), {
|
|
17
|
+
signal,
|
|
18
|
+
});
|
|
19
|
+
// on missing valid auth or API, it should abort the retry logic
|
|
20
|
+
if (response.status === 404) {
|
|
21
|
+
throw new AbortError('Missing API');
|
|
22
|
+
}
|
|
23
|
+
if (!response.ok) {
|
|
24
|
+
throw error('Failed to fetch packument', {
|
|
25
|
+
name: String(node.name),
|
|
26
|
+
spec,
|
|
27
|
+
response,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
const packument = (await response.json());
|
|
31
|
+
const res = packument.time?.[node.version];
|
|
32
|
+
return res;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Retrieves what kind of check the :published selector should perform.
|
|
36
|
+
*/
|
|
37
|
+
export const parseInternals = (nodes) => {
|
|
38
|
+
let value = '';
|
|
39
|
+
if (isStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {
|
|
40
|
+
value = removeQuotes(asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])
|
|
41
|
+
.value);
|
|
42
|
+
}
|
|
43
|
+
else if (isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {
|
|
44
|
+
const tagNode = asTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0]);
|
|
45
|
+
value = tagNode.value;
|
|
46
|
+
}
|
|
47
|
+
// Check if the value starts with a comparator
|
|
48
|
+
let comparator;
|
|
49
|
+
let relativeDate = value;
|
|
50
|
+
if (value.startsWith('>=')) {
|
|
51
|
+
comparator = '>=';
|
|
52
|
+
relativeDate = value.slice(2);
|
|
53
|
+
}
|
|
54
|
+
else if (value.startsWith('<=')) {
|
|
55
|
+
comparator = '<=';
|
|
56
|
+
relativeDate = value.slice(2);
|
|
57
|
+
}
|
|
58
|
+
else if (value.startsWith('>')) {
|
|
59
|
+
comparator = '>';
|
|
60
|
+
relativeDate = value.slice(1);
|
|
61
|
+
}
|
|
62
|
+
else if (value.startsWith('<')) {
|
|
63
|
+
comparator = '<';
|
|
64
|
+
relativeDate = value.slice(1);
|
|
65
|
+
}
|
|
66
|
+
return { relativeDate, comparator };
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Filter nodes by queueing up for removal those that don't match the date criteria.
|
|
70
|
+
*/
|
|
71
|
+
export const queueNode = async (state, node, relativeDate, comparator) => {
|
|
72
|
+
if (!node.name || !node.version) {
|
|
73
|
+
return node;
|
|
74
|
+
}
|
|
75
|
+
let publishedDate;
|
|
76
|
+
try {
|
|
77
|
+
publishedDate = await pRetry(() => retrieveRemoteDate(node, state.specOptions, state.signal), {
|
|
78
|
+
retries: state.retries,
|
|
79
|
+
signal: state.signal,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
// eslint-disable-next-line no-console
|
|
84
|
+
console.warn(error('Could not retrieve registry publish date', {
|
|
85
|
+
name: String(node.name),
|
|
86
|
+
cause: err,
|
|
87
|
+
}));
|
|
88
|
+
return node;
|
|
89
|
+
}
|
|
90
|
+
if (!publishedDate) {
|
|
91
|
+
return node;
|
|
92
|
+
}
|
|
93
|
+
// only matches the same amount of date information
|
|
94
|
+
// as provided in the relative date
|
|
95
|
+
const nodeDate = new Date(publishedDate.slice(0, relativeDate.length));
|
|
96
|
+
const compareDate = new Date(relativeDate);
|
|
97
|
+
switch (comparator) {
|
|
98
|
+
case '>':
|
|
99
|
+
return nodeDate > compareDate ? undefined : node;
|
|
100
|
+
case '<':
|
|
101
|
+
return nodeDate < compareDate ? undefined : node;
|
|
102
|
+
case '>=':
|
|
103
|
+
return nodeDate >= compareDate ? undefined : node;
|
|
104
|
+
case '<=':
|
|
105
|
+
return nodeDate <= compareDate ? undefined : node;
|
|
106
|
+
default:
|
|
107
|
+
return nodeDate.getTime() === compareDate.getTime() ?
|
|
108
|
+
undefined
|
|
109
|
+
: node;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Filters out nodes that don't match the published date criteria.
|
|
114
|
+
*
|
|
115
|
+
* The :published() pseudo selector supports a date parameter that can be prefixed
|
|
116
|
+
* with a comparator (>, <, >=, <=). If no comparator is provided, it will match
|
|
117
|
+
* exact dates.
|
|
118
|
+
*
|
|
119
|
+
* Examples:
|
|
120
|
+
* - :published("2024-01-01") - Matches packages published exactly on January 1st, 2024
|
|
121
|
+
* - :published(">2024-01-01") - Matches packages published after January 1st, 2024
|
|
122
|
+
* - :published("<=2023-12-31") - Matches packages published on or before December 31st, 2023
|
|
123
|
+
*/
|
|
124
|
+
export const published = async (state) => {
|
|
125
|
+
let internals;
|
|
126
|
+
try {
|
|
127
|
+
internals = parseInternals(asPostcssNodeWithChildren(state.current).nodes);
|
|
128
|
+
}
|
|
129
|
+
catch (err) {
|
|
130
|
+
throw error('Failed to parse :published selector', {
|
|
131
|
+
cause: err,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
const { relativeDate, comparator } = internals;
|
|
135
|
+
const queue = [];
|
|
136
|
+
for (const node of state.partial.nodes) {
|
|
137
|
+
// filter out nodes that are always ignored by the published selector
|
|
138
|
+
if (node.mainImporter ||
|
|
139
|
+
node.manifest?.private ||
|
|
140
|
+
splitDepID(node.id)[0] !== 'registry') {
|
|
141
|
+
removeNode(state, node);
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
// fetch published date info and perform checks to define
|
|
145
|
+
// whether or not a node should be filtered out
|
|
146
|
+
queue.push(queueNode(state, node, relativeDate, comparator));
|
|
147
|
+
}
|
|
148
|
+
// nodes queued for removal are then finally removed
|
|
149
|
+
const removeNodeQueue = await Promise.all(queue);
|
|
150
|
+
for (const node of removeNodeQueue) {
|
|
151
|
+
if (node) {
|
|
152
|
+
removeNode(state, node);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
removeDanglingEdges(state);
|
|
156
|
+
return state;
|
|
157
|
+
};
|
|
158
|
+
//# sourceMappingURL=published.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"published.js","sourceRoot":"","sources":["../../../src/pseudo/published.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,EAAE,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAC5C,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EACL,yBAAyB,EACzB,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,SAAS,GACV,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EACL,mBAAmB,EACnB,UAAU,EACV,YAAY,GACb,MAAM,cAAc,CAAA;AAoBrB;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EACrC,IAAc,EACd,WAAwB,EACxB,MAAoB,EACS,EAAE;IAC/B,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EAAE,E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U,CAAC,CAAC,CAAA;IAC9D,CAAC;IAED,oDAAoD;IACpD,MAAM,eAAe,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IAChD,KAAK,MAAM,IAAI,IAAI,eAAe,EAAE,CAAC;QACnC,IAAI,IAAI,EAAE,CAAC;YACT,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;QACzB,CAAC;IACH,CAAC;IAED,mBAAmB,CAAC,KAAK,CAAC,CAAA;IAE1B,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["import pRetry, { AbortError } from 'p-retry'\nimport { hydrate, splitDepID } from '@vltpkg/dep-id/browser'\nimport { error } from '@vltpkg/error-cause'\nimport {\n asPostcssNodeWithChildren,\n asStringNode,\n asTagNode,\n isStringNode,\n isTagNode,\n} from '@vltpkg/dss-parser'\nimport {\n removeDanglingEdges,\n removeNode,\n removeQuotes,\n} from './helpers.ts'\nimport type { NodeLike } from '@vltpkg/graph'\nimport type { SpecOptions } from '@vltpkg/spec/browser'\nimport type { Packument } from '@vltpkg/types'\nimport type { ParserState } from '../types.ts'\nimport type { PostcssNode } from '@vltpkg/dss-parser'\n\n/**\n * The possible comparator values accepted by the :published() pseudo selector.\n */\nexport type PublishedComparator = '>' | '<' | '>=' | '<=' | undefined\n\n/**\n * Result of the internal parsing of the :published() pseudo selector.\n */\nexport type PublishedInternals = {\n relativeDate: string\n comparator: PublishedComparator\n}\n\n/**\n * Fetches the published date of a package version from the npm registry.\n */\nexport const retrieveRemoteDate = async (\n node: NodeLike,\n specOptions: SpecOptions,\n signal?: AbortSignal,\n): Promise<string | undefined> => {\n const spec = hydrate(node.id, String(node.name), specOptions)\n if (!spec.registry || !node.name || !node.version) {\n return undefined\n }\n\n const url = new URL(spec.registry)\n url.pathname = `/${node.name}`\n\n const response = await fetch(String(url), {\n signal,\n })\n // on missing valid auth or API, it should abort the retry logic\n if (response.status === 404) {\n throw new AbortError('Missing API')\n }\n if (!response.ok) {\n throw error('Failed to fetch packument', {\n name: String(node.name),\n spec,\n response,\n })\n }\n const packument = (await response.json()) as Packument\n const res = packument.time?.[node.version]\n return res\n}\n\n/**\n * Retrieves what kind of check the :published selector should perform.\n */\nexport const parseInternals = (\n nodes: PostcssNode[],\n): PublishedInternals => {\n let value = ''\n\n if (isStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {\n value = removeQuotes(\n asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])\n .value,\n )\n } else if (\n isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])\n ) {\n const tagNode = asTagNode(\n asPostcssNodeWithChildren(nodes[0]).nodes[0],\n )\n value = tagNode.value\n }\n\n // Check if the value starts with a comparator\n let comparator: PublishedComparator\n let relativeDate = value\n\n if (value.startsWith('>=')) {\n comparator = '>='\n relativeDate = value.slice(2)\n } else if (value.startsWith('<=')) {\n comparator = '<='\n relativeDate = value.slice(2)\n } else if (value.startsWith('>')) {\n comparator = '>'\n relativeDate = value.slice(1)\n } else if (value.startsWith('<')) {\n comparator = '<'\n relativeDate = value.slice(1)\n }\n\n return { relativeDate, comparator }\n}\n\n/**\n * Filter nodes by queueing up for removal those that don't match the date criteria.\n */\nexport const queueNode = async (\n state: ParserState,\n node: NodeLike,\n relativeDate: string,\n comparator: PublishedComparator,\n): Promise<NodeLike | undefined> => {\n if (!node.name || !node.version) {\n return node\n }\n\n let publishedDate: string | undefined\n try {\n publishedDate = await pRetry(\n () => retrieveRemoteDate(node, state.specOptions, state.signal),\n {\n retries: state.retries,\n signal: state.signal,\n },\n )\n } catch (err) {\n // eslint-disable-next-line no-console\n console.warn(\n error('Could not retrieve registry publish date', {\n name: String(node.name),\n cause: err,\n }),\n )\n return node\n }\n\n if (!publishedDate) {\n return node\n }\n\n // only matches the same amount of date information\n // as provided in the relative date\n const nodeDate = new Date(\n publishedDate.slice(0, relativeDate.length),\n )\n const compareDate = new Date(relativeDate)\n\n switch (comparator) {\n case '>':\n return nodeDate > compareDate ? undefined : node\n case '<':\n return nodeDate < compareDate ? undefined : node\n case '>=':\n return nodeDate >= compareDate ? undefined : node\n case '<=':\n return nodeDate <= compareDate ? undefined : node\n default:\n return nodeDate.getTime() === compareDate.getTime() ?\n undefined\n : node\n }\n}\n\n/**\n * Filters out nodes that don't match the published date criteria.\n *\n * The :published() pseudo selector supports a date parameter that can be prefixed\n * with a comparator (>, <, >=, <=). If no comparator is provided, it will match\n * exact dates.\n *\n * Examples:\n * - :published(\"2024-01-01\") - Matches packages published exactly on January 1st, 2024\n * - :published(\">2024-01-01\") - Matches packages published after January 1st, 2024\n * - :published(\"<=2023-12-31\") - Matches packages published on or before December 31st, 2023\n */\nexport const published = async (state: ParserState) => {\n let internals\n try {\n internals = parseInternals(\n asPostcssNodeWithChildren(state.current).nodes,\n )\n } catch (err) {\n throw error('Failed to parse :published selector', {\n cause: err,\n })\n }\n\n const { relativeDate, comparator } = internals\n const queue = []\n\n for (const node of state.partial.nodes) {\n // filter out nodes that are always ignored by the published selector\n if (\n node.mainImporter ||\n node.manifest?.private ||\n splitDepID(node.id)[0] !== 'registry'\n ) {\n removeNode(state, node)\n continue\n }\n\n // fetch published date info and perform checks to define\n // whether or not a node should be filtered out\n queue.push(queueNode(state, node, relativeDate, comparator))\n }\n\n // nodes queued for removal are then finally removed\n const removeNodeQueue = await Promise.all(queue)\n for (const node of removeNodeQueue) {\n if (node) {\n removeNode(state, node)\n }\n }\n\n removeDanglingEdges(state)\n\n return state\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ParserState } from '../types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* :root Pseudo-Element will return the project root node for the graph.
|
|
4
|
+
* It matches only the main importer node of the graph, which represents
|
|
5
|
+
* the root of the project.
|
|
6
|
+
*/
|
|
7
|
+
export declare const root: (state: ParserState) => Promise<ParserState>;
|
|
8
|
+
//# sourceMappingURL=root.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"root.d.ts","sourceRoot":"","sources":["../../../src/pseudo/root.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C;;;;GAIG;AACH,eAAO,MAAM,IAAI,UAAiB,WAAW,yBAc5C,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { error } from '@vltpkg/error-cause';
|
|
2
|
+
/**
|
|
3
|
+
* :root Pseudo-Element will return the project root node for the graph.
|
|
4
|
+
* It matches only the main importer node of the graph, which represents
|
|
5
|
+
* the root of the project.
|
|
6
|
+
*/
|
|
7
|
+
export const root = async (state) => {
|
|
8
|
+
const [anyNode] = state.initial.nodes.values();
|
|
9
|
+
const mainImporter = anyNode?.graph.mainImporter;
|
|
10
|
+
if (!mainImporter) {
|
|
11
|
+
throw error(':root pseudo-element works on local graphs only');
|
|
12
|
+
}
|
|
13
|
+
for (const edge of state.partial.edges) {
|
|
14
|
+
if (edge.to !== mainImporter) {
|
|
15
|
+
state.partial.edges.delete(edge);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
state.partial.nodes.clear();
|
|
19
|
+
state.partial.nodes.add(mainImporter);
|
|
20
|
+
return state;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=root.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"root.js","sourceRoot":"","sources":["../../../src/pseudo/root.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAG3C;;;;GAIG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,KAAK,EAAE,KAAkB,EAAE,EAAE;IAC/C,MAAM,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,CAAA;IAC9C,MAAM,YAAY,GAAG,OAAO,EAAE,KAAK,CAAC,YAAY,CAAA;IAChD,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,MAAM,KAAK,CAAC,iDAAiD,CAAC,CAAA;IAChE,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACvC,IAAI,IAAI,CAAC,EAAE,KAAK,YAAY,EAAE,CAAC;YAC7B,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QAClC,CAAC;IACH,CAAC;IACD,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;IAC3B,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;IACrC,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport type { ParserState } from '../types.ts'\n\n/**\n * :root Pseudo-Element will return the project root node for the graph.\n * It matches only the main importer node of the graph, which represents\n * the root of the project.\n */\nexport const root = async (state: ParserState) => {\n const [anyNode] = state.initial.nodes.values()\n const mainImporter = anyNode?.graph.mainImporter\n if (!mainImporter) {\n throw error(':root pseudo-element works on local graphs only')\n }\n for (const edge of state.partial.edges) {\n if (edge.to !== mainImporter) {\n state.partial.edges.delete(edge)\n }\n }\n state.partial.nodes.clear()\n state.partial.nodes.add(mainImporter)\n return state\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ParserState } from '../types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* :scanned pseudo selector.
|
|
4
|
+
*
|
|
5
|
+
* Remove all nodes that do not have available metadata
|
|
6
|
+
* in the security archive.
|
|
7
|
+
*/
|
|
8
|
+
export declare const scanned: (state: ParserState) => Promise<ParserState>;
|
|
9
|
+
//# sourceMappingURL=scanned.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanned.d.ts","sourceRoot":"","sources":["../../../src/pseudo/scanned.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C;;;;;GAKG;AACH,eAAO,MAAM,OAAO,UAAiB,WAAW,yBAU/C,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { removeDanglingEdges, removeNode } from "./helpers.js";
|
|
2
|
+
/**
|
|
3
|
+
* :scanned pseudo selector.
|
|
4
|
+
*
|
|
5
|
+
* Remove all nodes that do not have available metadata
|
|
6
|
+
* in the security archive.
|
|
7
|
+
*/
|
|
8
|
+
export const scanned = async (state) => {
|
|
9
|
+
for (const node of state.partial.nodes) {
|
|
10
|
+
if (!state.securityArchive?.has(node.id)) {
|
|
11
|
+
removeNode(state, node);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
removeDanglingEdges(state);
|
|
15
|
+
return state;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=scanned.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanned.js","sourceRoot":"","sources":["../../../src/pseudo/scanned.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAG9D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,KAAK,EAAE,KAAkB,EAAE,EAAE;IAClD,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACvC,IAAI,CAAC,KAAK,CAAC,eAAe,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;YACzC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;QACzB,CAAC;IACH,CAAC;IAED,mBAAmB,CAAC,KAAK,CAAC,CAAA;IAE1B,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["import { removeDanglingEdges, removeNode } from './helpers.ts'\nimport type { ParserState } from '../types.ts'\n\n/**\n * :scanned pseudo selector.\n *\n * Remove all nodes that do not have available metadata\n * in the security archive.\n */\nexport const scanned = async (state: ParserState) => {\n for (const node of state.partial.nodes) {\n if (!state.securityArchive?.has(node.id)) {\n removeNode(state, node)\n }\n }\n\n removeDanglingEdges(state)\n\n return state\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { PackageScore } from '@vltpkg/security-archive';
|
|
2
|
+
import type { ParserState } from '../types.ts';
|
|
3
|
+
import type { PostcssNode } from '@vltpkg/dss-parser';
|
|
4
|
+
export type ScoreKinds = keyof PackageScore;
|
|
5
|
+
export type ScoreComparator = '>' | '<' | '>=' | '<=' | '=' | undefined;
|
|
6
|
+
export declare const isScoreKind: (value?: string) => value is ScoreKinds;
|
|
7
|
+
export declare const asScoreKind: (value?: string) => ScoreKinds;
|
|
8
|
+
export declare const parseInternals: (nodes: PostcssNode[]) => {
|
|
9
|
+
comparator: ScoreComparator;
|
|
10
|
+
rate: number;
|
|
11
|
+
kind: ScoreKinds;
|
|
12
|
+
};
|
|
13
|
+
export declare const score: (state: ParserState) => Promise<ParserState & {
|
|
14
|
+
securityArchive: NonNullable<ParserState["securityArchive"]>;
|
|
15
|
+
}>;
|
|
16
|
+
//# sourceMappingURL=score.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"score.d.ts","sourceRoot":"","sources":["../../../src/pseudo/score.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAErD,MAAM,MAAM,UAAU,GAAG,MAAM,YAAY,CAAA;AAE3C,MAAM,MAAM,eAAe,GACvB,GAAG,GACH,GAAG,GACH,IAAI,GACJ,IAAI,GACJ,GAAG,GACH,SAAS,CAAA;AAYb,eAAO,MAAM,WAAW,WAAY,MAAM,KAAG,KAAK,IAAI,UACtB,CAAA;AAEhC,eAAO,MAAM,WAAW,WAAY,MAAM,KAAG,UAQ5C,CAAA;AAED,eAAO,MAAM,cAAc,UAClB,WAAW,EAAE,KACnB;IACD,UAAU,EAAE,eAAe,CAAA;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,UAAU,CAAA;CAsEjB,CAAA;AAED,eAAO,MAAM,KAAK,UAAiB,WAAW;;EAiD7C,CAAA"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { error } from '@vltpkg/error-cause';
|
|
2
|
+
import { asPostcssNodeWithChildren, asStringNode, asTagNode, isStringNode, isTagNode, } from '@vltpkg/dss-parser';
|
|
3
|
+
import { assertSecurityArchive, removeDanglingEdges, removeNode, removeQuotes, } from "./helpers.js";
|
|
4
|
+
const kinds = new Set([
|
|
5
|
+
'overall',
|
|
6
|
+
'license',
|
|
7
|
+
'maintenance',
|
|
8
|
+
'quality',
|
|
9
|
+
'supplyChain',
|
|
10
|
+
'vulnerability',
|
|
11
|
+
undefined,
|
|
12
|
+
]);
|
|
13
|
+
export const isScoreKind = (value) => kinds.has(value);
|
|
14
|
+
export const asScoreKind = (value) => {
|
|
15
|
+
if (!isScoreKind(value)) {
|
|
16
|
+
throw error('Expected a valid score kind', {
|
|
17
|
+
found: value,
|
|
18
|
+
validOptions: Array.from(kinds),
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
export const parseInternals = (nodes) => {
|
|
24
|
+
let rateStr = '';
|
|
25
|
+
let comparator = '=';
|
|
26
|
+
let kind = 'overall';
|
|
27
|
+
// Parse the first parameter (rate with optional comparator)
|
|
28
|
+
if (isStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {
|
|
29
|
+
rateStr = removeQuotes(asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])
|
|
30
|
+
.value);
|
|
31
|
+
}
|
|
32
|
+
else if (isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {
|
|
33
|
+
const tagNode = asTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0]);
|
|
34
|
+
rateStr = tagNode.value;
|
|
35
|
+
}
|
|
36
|
+
// Extract comparator if present
|
|
37
|
+
if (rateStr.startsWith('>=')) {
|
|
38
|
+
comparator = '>=';
|
|
39
|
+
rateStr = rateStr.substring(2);
|
|
40
|
+
}
|
|
41
|
+
else if (rateStr.startsWith('<=')) {
|
|
42
|
+
comparator = '<=';
|
|
43
|
+
rateStr = rateStr.substring(2);
|
|
44
|
+
}
|
|
45
|
+
else if (rateStr.startsWith('>')) {
|
|
46
|
+
comparator = '>';
|
|
47
|
+
rateStr = rateStr.substring(1);
|
|
48
|
+
}
|
|
49
|
+
else if (rateStr.startsWith('<')) {
|
|
50
|
+
comparator = '<';
|
|
51
|
+
rateStr = rateStr.substring(1);
|
|
52
|
+
}
|
|
53
|
+
// Parse rate as number
|
|
54
|
+
let rate = parseFloat(rateStr);
|
|
55
|
+
// Normalize to 0-1 range if needed
|
|
56
|
+
if (rate > 1) {
|
|
57
|
+
rate = rate / 100;
|
|
58
|
+
}
|
|
59
|
+
// Validate rate is in acceptable range
|
|
60
|
+
if (rate < 0 || rate > 1) {
|
|
61
|
+
throw error('Expected rate to be between 0 and 100', {
|
|
62
|
+
found: rateStr,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
// Parse the second parameter (kind) if present
|
|
66
|
+
if (nodes.length > 1) {
|
|
67
|
+
if (isStringNode(asPostcssNodeWithChildren(nodes[1]).nodes[0])) {
|
|
68
|
+
kind = asScoreKind(removeQuotes(asStringNode(asPostcssNodeWithChildren(nodes[1]).nodes[0])
|
|
69
|
+
.value));
|
|
70
|
+
}
|
|
71
|
+
else if (isTagNode(asPostcssNodeWithChildren(nodes[1]).nodes[0])) {
|
|
72
|
+
kind = asScoreKind(asTagNode(asPostcssNodeWithChildren(nodes[1]).nodes[0]).value);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return { comparator, rate, kind };
|
|
76
|
+
};
|
|
77
|
+
export const score = async (state) => {
|
|
78
|
+
assertSecurityArchive(state, 'score');
|
|
79
|
+
let internals;
|
|
80
|
+
try {
|
|
81
|
+
internals = parseInternals(asPostcssNodeWithChildren(state.current).nodes);
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
throw error('Failed to parse :score selector', { cause: err });
|
|
85
|
+
}
|
|
86
|
+
const { comparator, rate, kind } = internals;
|
|
87
|
+
for (const node of state.partial.nodes) {
|
|
88
|
+
const report = state.securityArchive.get(node.id);
|
|
89
|
+
if (!report) {
|
|
90
|
+
removeNode(state, node);
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const scoreValue = report.score[kind];
|
|
94
|
+
let exclude = false;
|
|
95
|
+
switch (comparator) {
|
|
96
|
+
case '>':
|
|
97
|
+
exclude = scoreValue <= rate;
|
|
98
|
+
break;
|
|
99
|
+
case '<':
|
|
100
|
+
exclude = scoreValue >= rate;
|
|
101
|
+
break;
|
|
102
|
+
case '>=':
|
|
103
|
+
exclude = scoreValue < rate;
|
|
104
|
+
break;
|
|
105
|
+
case '<=':
|
|
106
|
+
exclude = scoreValue > rate;
|
|
107
|
+
break;
|
|
108
|
+
default: // '='
|
|
109
|
+
exclude = scoreValue !== rate;
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
if (exclude) {
|
|
113
|
+
removeNode(state, node);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
removeDanglingEdges(state);
|
|
117
|
+
return state;
|
|
118
|
+
};
|
|
119
|
+
//# sourceMappingURL=score.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"score.js","sourceRoot":"","sources":["../../../src/pseudo/score.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EACL,yBAAyB,EACzB,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,SAAS,GACV,MAAM,oBAAoB,CAAA;AAC3B,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G,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QACjD,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;YACvB,SAAQ;QACV,CAAC;QAED,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QAErC,IAAI,OAAO,GAAG,KAAK,CAAA;QACnB,QAAQ,UAAU,EAAE,CAAC;YACnB,KAAK,GAAG;gBACN,OAAO,GAAG,UAAU,IAAI,IAAI,CAAA;gBAC5B,MAAK;YACP,KAAK,GAAG;gBACN,OAAO,GAAG,UAAU,IAAI,IAAI,CAAA;gBAC5B,MAAK;YACP,KAAK,IAAI;gBACP,OAAO,GAAG,UAAU,GAAG,IAAI,CAAA;gBAC3B,MAAK;YACP,KAAK,IAAI;gBACP,OAAO,GAAG,UAAU,GAAG,IAAI,CAAA;gBAC3B,MAAK;YACP,SAAS,MAAM;gBACb,OAAO,GAAG,UAAU,KAAK,IAAI,CAAA;gBAC7B,MAAK;QACT,CAAC;QAED,IAAI,OAAO,EAAE,CAAC;YACZ,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;QACzB,CAAC;IACH,CAAC;IAED,mBAAmB,CAAC,KAAK,CAAC,CAAA;IAE1B,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport {\n asPostcssNodeWithChildren,\n asStringNode,\n asTagNode,\n isStringNode,\n isTagNode,\n} from '@vltpkg/dss-parser'\nimport {\n assertSecurityArchive,\n removeDanglingEdges,\n removeNode,\n removeQuotes,\n} from './helpers.ts'\nimport type { PackageScore } from '@vltpkg/security-archive'\nimport type { ParserState } from '../types.ts'\nimport type { PostcssNode } from '@vltpkg/dss-parser'\n\nexport type ScoreKinds = keyof PackageScore\n\nexport type ScoreComparator =\n | '>'\n | '<'\n | '>='\n | '<='\n | '='\n | undefined\n\nconst kinds = new Set<ScoreKinds | undefined>([\n 'overall',\n 'license',\n 'maintenance',\n 'quality',\n 'supplyChain',\n 'vulnerability',\n undefined,\n])\n\nexport const isScoreKind = (value?: string): value is ScoreKinds =>\n kinds.has(value as ScoreKinds)\n\nexport const asScoreKind = (value?: string): ScoreKinds => {\n if (!isScoreKind(value)) {\n throw error('Expected a valid score kind', {\n found: value,\n validOptions: Array.from(kinds),\n })\n }\n return value\n}\n\nexport const parseInternals = (\n nodes: PostcssNode[],\n): {\n comparator: ScoreComparator\n rate: number\n kind: ScoreKinds\n} => {\n let rateStr = ''\n let comparator: ScoreComparator = '='\n let kind: ScoreKinds = 'overall'\n\n // Parse the first parameter (rate with optional comparator)\n if (isStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {\n rateStr = removeQuotes(\n asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])\n .value,\n )\n } else if (\n isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])\n ) {\n const tagNode = asTagNode(\n asPostcssNodeWithChildren(nodes[0]).nodes[0],\n )\n rateStr = tagNode.value\n }\n\n // Extract comparator if present\n if (rateStr.startsWith('>=')) {\n comparator = '>='\n rateStr = rateStr.substring(2)\n } else if (rateStr.startsWith('<=')) {\n comparator = '<='\n rateStr = rateStr.substring(2)\n } else if (rateStr.startsWith('>')) {\n comparator = '>'\n rateStr = rateStr.substring(1)\n } else if (rateStr.startsWith('<')) {\n comparator = '<'\n rateStr = rateStr.substring(1)\n }\n\n // Parse rate as number\n let rate = parseFloat(rateStr)\n\n // Normalize to 0-1 range if needed\n if (rate > 1) {\n rate = rate / 100\n }\n\n // Validate rate is in acceptable range\n if (rate < 0 || rate > 1) {\n throw error('Expected rate to be between 0 and 100', {\n found: rateStr,\n })\n }\n\n // Parse the second parameter (kind) if present\n if (nodes.length > 1) {\n if (isStringNode(asPostcssNodeWithChildren(nodes[1]).nodes[0])) {\n kind = asScoreKind(\n removeQuotes(\n asStringNode(asPostcssNodeWithChildren(nodes[1]).nodes[0])\n .value,\n ),\n )\n } else if (\n isTagNode(asPostcssNodeWithChildren(nodes[1]).nodes[0])\n ) {\n kind = asScoreKind(\n asTagNode(asPostcssNodeWithChildren(nodes[1]).nodes[0]).value,\n )\n }\n }\n\n return { comparator, rate, kind }\n}\n\nexport const score = async (state: ParserState) => {\n assertSecurityArchive(state, 'score')\n\n let internals\n try {\n internals = parseInternals(\n asPostcssNodeWithChildren(state.current).nodes,\n )\n } catch (err) {\n throw error('Failed to parse :score selector', { cause: err })\n }\n\n const { comparator, rate, kind } = internals\n for (const node of state.partial.nodes) {\n const report = state.securityArchive.get(node.id)\n if (!report) {\n removeNode(state, node)\n continue\n }\n\n const scoreValue = report.score[kind]\n\n let exclude = false\n switch (comparator) {\n case '>':\n exclude = scoreValue <= rate\n break\n case '<':\n exclude = scoreValue >= rate\n break\n case '>=':\n exclude = scoreValue < rate\n break\n case '<=':\n exclude = scoreValue > rate\n break\n default: // '='\n exclude = scoreValue !== rate\n break\n }\n\n if (exclude) {\n removeNode(state, node)\n }\n }\n\n removeDanglingEdges(state)\n\n return state\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filters out any node that does not have an **installScripts** report alert.
|
|
3
|
+
*/
|
|
4
|
+
export declare const scripts: (state: import("../types.ts").ParserState) => Promise<import("../types.ts").ParserState & {
|
|
5
|
+
securityArchive: NonNullable<import("../types.ts").ParserState["securityArchive"]>;
|
|
6
|
+
}>;
|
|
7
|
+
//# sourceMappingURL=scripts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scripts.d.ts","sourceRoot":"","sources":["../../../src/pseudo/scripts.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,OAAO;;EAGnB,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createSecuritySelectorFilter } from "./helpers.js";
|
|
2
|
+
/**
|
|
3
|
+
* Filters out any node that does not have an **installScripts** report alert.
|
|
4
|
+
*/
|
|
5
|
+
export const scripts = createSecuritySelectorFilter('scripts', 'installScripts');
|
|
6
|
+
//# sourceMappingURL=scripts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scripts.js","sourceRoot":"","sources":["../../../src/pseudo/scripts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAA;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,4BAA4B,CACjD,SAAS,EACT,gBAAgB,CACjB,CAAA","sourcesContent":["import { createSecuritySelectorFilter } from './helpers.ts'\n\n/**\n * Filters out any node that does not have an **installScripts** report alert.\n */\nexport const scripts = createSecuritySelectorFilter(\n 'scripts',\n 'installScripts',\n)\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Version } from '@vltpkg/semver';
|
|
2
2
|
import type { AttrInternals } from './attr.ts';
|
|
3
|
-
import type { ParserState
|
|
3
|
+
import type { ParserState } from '../types.ts';
|
|
4
|
+
import type { PostcssNode } from '@vltpkg/dss-parser';
|
|
4
5
|
export type SemverInternals = {
|
|
5
6
|
semverValue: string;
|
|
6
7
|
semverFunction: SemverComparatorFn;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"semver.d.ts","sourceRoot":"","sources":["../../../src/pseudo/semver.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"semver.d.ts","sourceRoot":"","sources":["../../../src/pseudo/semver.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAI7C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAc9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAErD,MAAM,MAAM,eAAe,GAAG;IAC5B,WAAW,EAAE,MAAM,CAAA;IACnB,cAAc,EAAE,kBAAkB,CAAA;IAClC,gBAAgB,EAAE,sBAAsB,CAAA;CACzC,CAAA;AAED,MAAM,MAAM,mBAAmB,GAC3B,WAAW,GACX,IAAI,GACJ,KAAK,GACL,IAAI,GACJ,KAAK,GACL,IAAI,GACJ,KAAK,CAAA;AACT,MAAM,MAAM,kBAAkB,GAAG,CAC/B,OAAO,EAAE,OAAO,GAAG,MAAM,EACzB,KAAK,EAAE,MAAM,KACV,OAAO,CAAA;AACZ,MAAM,MAAM,sBAAsB,GAC9B,IAAI,CAAC,aAAa,EAAE,WAAW,GAAG,YAAY,CAAC,GAC/C,SAAS,CAAA;AAWb,eAAO,MAAM,oBAAoB,SACzB,MAAM,KACX,IAAI,IAAI,mBAAoD,CAAA;AAE/D,eAAO,MAAM,oBAAoB,SACzB,MAAM,KACX,mBAQF,CAAA;AAeD,eAAO,MAAM,cAAc,UAClB,WAAW,EAAE,SACb,OAAO,KACb,eAkGF,CAAA;AAED,eAAO,MAAM,YAAY,UAAiB,WAAW,yBAyDpD,CAAA"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { satisfies, gt, gte, lt, lte, eq, neq, parse, parseRange, } from '@vltpkg/semver';
|
|
2
2
|
import { error } from '@vltpkg/error-cause';
|
|
3
|
+
import { asError } from '@vltpkg/types';
|
|
3
4
|
import { parseInternals as parseAttrInternals } from "./attr.js";
|
|
4
5
|
import { getManifestPropertyValues } from "../attribute.js";
|
|
5
|
-
import { asAttributeNode, asPostcssNodeWithChildren, asPseudoNode, asStringNode, asTagNode, isAttributeNode,
|
|
6
|
+
import { asAttributeNode, asPostcssNodeWithChildren, asPseudoNode, asStringNode, asTagNode, isAttributeNode, isPseudoNode, isStringNode, isTagNode, } from '@vltpkg/dss-parser';
|
|
6
7
|
import { removeNode, removeQuotes } from "./helpers.js";
|
|
7
8
|
const semverFunctionNames = new Set([
|
|
8
9
|
'satisfies',
|
|
@@ -32,34 +33,21 @@ const semverFunctions = new Map([
|
|
|
32
33
|
['eq', eq],
|
|
33
34
|
['neq', neq],
|
|
34
35
|
]);
|
|
35
|
-
// list a few css combinators that should never have
|
|
36
|
-
// spaces around when parsing as a semver range
|
|
37
|
-
const unspacedCombinators = new Set([' ', '+']);
|
|
38
36
|
export const parseInternals = (nodes, loose) => {
|
|
39
37
|
// tries to parse the first param as a string node, otherwise defaults
|
|
40
38
|
// to reading all postcss nodes as just strings, since it just means
|
|
41
39
|
// the value was defined as an unquoted string
|
|
42
|
-
let semverValue;
|
|
40
|
+
let semverValue = '';
|
|
43
41
|
try {
|
|
44
42
|
semverValue = removeQuotes(asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])
|
|
45
43
|
.value);
|
|
46
44
|
}
|
|
47
|
-
catch (
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
semverValue += '.';
|
|
54
|
-
}
|
|
55
|
-
else if (isCombinatorNode(node) &&
|
|
56
|
-
!unspacedCombinators.has(node.value)) {
|
|
57
|
-
semverValue += ' ';
|
|
58
|
-
}
|
|
59
|
-
if (node.value) {
|
|
60
|
-
semverValue += node.value;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
if (asError(err).message === 'Mismatching query node' &&
|
|
47
|
+
isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {
|
|
48
|
+
// Handle tag node (unquoted values like >=2.0.0)
|
|
49
|
+
const tagNode = asTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0]);
|
|
50
|
+
semverValue = tagNode.value;
|
|
63
51
|
}
|
|
64
52
|
else {
|
|
65
53
|
throw err;
|
|
@@ -76,9 +64,8 @@ export const parseInternals = (nodes, loose) => {
|
|
|
76
64
|
fnName = asSemverFunctionName(removeQuotes(asStringNode(asPostcssNodeWithChildren(nodes[1]).nodes[0])
|
|
77
65
|
.value));
|
|
78
66
|
}
|
|
79
|
-
catch (
|
|
80
|
-
|
|
81
|
-
if (err.message === 'Mismatching query node') {
|
|
67
|
+
catch (err) {
|
|
68
|
+
if (asError(err).message === 'Mismatching query node') {
|
|
82
69
|
fnName = asSemverFunctionName(asTagNode(asPostcssNodeWithChildren(nodes[1]).nodes[0])
|
|
83
70
|
.value);
|
|
84
71
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"semver.js","sourceRoot":"","sources":["../../../src/pseudo/semver.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,EAAE,EACF,GAAG,EACH,EAAE,EACF,GAAG,EACH,EAAE,EACF,GAAG,EACH,KAAK,EACL,UAAU,GACX,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,cAAc,IAAI,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAEhE,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAA;AAC3D,OAAO,EACL,eAAe,EACf,yBAAyB,EACzB,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,eAAe,EACf,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,YAAY,GACb,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAwBvD,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC;IAClC,WAAW;IACX,IAAI;IACJ,KAAK;IACL,IAAI;IACJ,KAAK;IACL,IAAI;IACJ,KAAK;CACN,CAAC,CAAA;AACF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,IAAY,EACiB,EAAE,CAAC,mBAAmB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;AAE/D,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,IAAY,EACS,EAAE;IACvB,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAE,CAAC;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I,CAAC,CAAA;YACzB,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,eAAe,GAAG,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAA;YAC9C,IACE,CAAC,eAAe;gBAChB,CAAC,cAAc,CAAC,eAAe,EAAE,WAAW,CAAC,EAC7C,CAAC;gBACD,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;YACzB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["import {\n satisfies,\n gt,\n gte,\n lt,\n lte,\n eq,\n neq,\n parse,\n parseRange,\n} from '@vltpkg/semver'\nimport type { Version } from '@vltpkg/semver'\nimport { error } from '@vltpkg/error-cause'\nimport { parseInternals as parseAttrInternals } from './attr.ts'\nimport type { AttrInternals } from './attr.ts'\nimport { getManifestPropertyValues } from '../attribute.ts'\nimport {\n asAttributeNode,\n asPostcssNodeWithChildren,\n asPseudoNode,\n asStringNode,\n asTagNode,\n isAttributeNode,\n isClassNode,\n isCombinatorNode,\n isPseudoNode,\n isStringNode,\n} from '../types.ts'\nimport type { ParserState, PostcssNode } from '../types.ts'\nimport { removeNode, removeQuotes } from './helpers.ts'\n\nexport type SemverInternals = {\n semverValue: string\n semverFunction: SemverComparatorFn\n compareAttribute: SemverCompareAttribute\n}\n\nexport type SemverFunctionNames =\n | 'satisfies'\n | 'gt'\n | 'gte'\n | 'lt'\n | 'lte'\n | 'eq'\n | 'neq'\nexport type SemverComparatorFn = (\n version: Version | string,\n range: string,\n) => boolean\nexport type SemverCompareAttribute =\n | Pick<AttrInternals, 'attribute' | 'properties'>\n | undefined\n\nconst semverFunctionNames = new Set([\n 'satisfies',\n 'gt',\n 'gte',\n 'lt',\n 'lte',\n 'eq',\n 'neq',\n])\nexport const isSemverFunctionName = (\n name: string,\n): name is SemverFunctionNames => semverFunctionNames.has(name)\n\nexport const asSemverFunctionName = (\n name: string,\n): SemverFunctionNames => {\n if (!isSemverFunctionName(name)) {\n throw error('Invalid semver function name', {\n found: name,\n validOptions: Array.from(semverFunctionNames),\n })\n }\n return name\n}\n\nconst semverFunctions = new Map<\n SemverFunctionNames,\n SemverComparatorFn\n>([\n ['satisfies', satisfies],\n ['gt', gt],\n ['gte', gte],\n ['lt', lt],\n ['lte', lte],\n ['eq', eq],\n ['neq', neq],\n])\n\n// list a few css combinators that should never have\n// spaces around when parsing as a semver range\nconst unspacedCombinators = new Set<string>([' ', '+'])\n\nexport const parseInternals = (\n nodes: PostcssNode[],\n loose: boolean,\n): SemverInternals => {\n // tries to parse the first param as a string node, otherwise defaults\n // to reading all postcss nodes as just strings, since it just means\n // the value was defined as an unquoted string\n let semverValue\n try {\n semverValue = removeQuotes(\n asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])\n .value,\n )\n } catch (e) {\n const err = e as Error\n if (err.message === 'Mismatching query node') {\n semverValue = ''\n for (const node of asPostcssNodeWithChildren(nodes[0]).nodes) {\n if (isClassNode(node)) {\n semverValue += '.'\n } else if (\n isCombinatorNode(node) &&\n !unspacedCombinators.has(node.value)\n ) {\n semverValue += ' '\n }\n\n if (node.value) {\n semverValue += node.value\n }\n }\n } else {\n throw err\n }\n }\n\n // second param is the function name\n let fnName: SemverFunctionNames = 'satisfies'\n try {\n // if there is a second node defined, try to parse it as a string node\n // first and if that fails, then parse it as a tag node which just means\n // it was defined as an unquoted string\n if (nodes[1]) {\n try {\n fnName = asSemverFunctionName(\n removeQuotes(\n asStringNode(asPostcssNodeWithChildren(nodes[1]).nodes[0])\n .value,\n ),\n )\n } catch (e) {\n const err = e as Error\n if (err.message === 'Mismatching query node') {\n fnName = asSemverFunctionName(\n asTagNode(asPostcssNodeWithChildren(nodes[1]).nodes[0])\n .value,\n )\n } else {\n throw err\n }\n }\n }\n } catch (e) {\n // allow invalid semver function names in loose mode, defaults to satisfies\n if (!loose) {\n throw e\n }\n }\n\n const semverFunction = semverFunctions.get(fnName)\n // the following should never happen as long as the semver function names\n // type and Set are correctly mirroring each other values\n /* c8 ignore start */\n if (!semverFunction) {\n throw error('Invalid semver function name', {\n found: fnName,\n validOptions: Array.from(semverFunctions.keys()),\n })\n }\n /* c8 ignore stop */\n\n // optional third param is the compare value\n let compareAttribute: SemverCompareAttribute\n if (nodes[2]) {\n const parentNode = asPostcssNodeWithChildren(nodes[2])\n const currNode = parentNode.nodes[0]\n if (isAttributeNode(currNode)) {\n const { attribute } = asAttributeNode(currNode)\n compareAttribute = {\n attribute,\n properties: [attribute],\n }\n } else if (isPseudoNode(currNode)) {\n compareAttribute = parseAttrInternals(\n asPseudoNode(currNode).nodes,\n )\n } else if (isStringNode(currNode)) {\n const attribute = removeQuotes(asStringNode(currNode).value)\n compareAttribute = {\n attribute,\n properties: [attribute],\n }\n }\n }\n\n return {\n semverValue,\n semverFunction,\n compareAttribute,\n }\n}\n\nexport const semverParser = async (state: ParserState) => {\n let internals\n try {\n internals = parseInternals(\n asPostcssNodeWithChildren(state.current).nodes,\n !!state.loose,\n )\n } catch (err) {\n throw error('Failed to parse :semver selector', {\n cause: err,\n })\n }\n\n const { semverValue, semverFunction, compareAttribute } = internals\n\n for (const node of state.partial.nodes) {\n if (compareAttribute) {\n const compareValues = getManifestPropertyValues(\n node,\n compareAttribute.properties,\n compareAttribute.attribute,\n )\n\n // if the provided semver value is a fixed semver version and the\n // compare attribute is resolving to a range value, then we flip the\n // order of comparison, in case it's a \"satisfies\" function check\n const compareValue = compareValues?.[0]\n const semverValueVersion = parse(semverValue)\n const compareValueRange =\n compareValue && parseRange(compareValue)\n if (\n semverFunction === satisfies &&\n semverValueVersion &&\n compareValueRange\n ) {\n if (!satisfies(semverValueVersion, compareValueRange)) {\n removeNode(state, node)\n }\n // otherwise just compares the read attribute to the semver value\n } else if (\n !compareValue ||\n !semverFunction(compareValue, semverValue)\n ) {\n removeNode(state, node)\n }\n } else {\n const manifestVersion = node.manifest?.version\n if (\n !manifestVersion ||\n !semverFunction(manifestVersion, semverValue)\n ) {\n removeNode(state, node)\n }\n }\n }\n\n return state\n}\n"]}
|
|
1
|
+
{"version":3,"file":"semver.js","sourceRoot":"","sources":["../../../src/pseudo/semver.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,EAAE,EACF,GAAG,EACH,EAAE,EACF,GAAG,EACH,EAAE,EACF,GAAG,EACH,KAAK,EACL,UAAU,GACX,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,cAAc,IAAI,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAEhE,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAA;AAC3D,OAAO,EACL,eAAe,EACf,yBAAyB,EACzB,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,SAAS,GACV,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AA0BvD,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC;IAClC,WAAW;IACX,IAAI;IACJ,KAAK;IACL,IAAI;IACJ,KAAK;IACL,IAAI;IACJ,KAAK;CACN,CAAC,CAAA;AACF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,IAAY,EACiB,EAAE,CAAC,mBAAmB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;AAE/D,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,IAAY,EACS,EAAE;IACvB,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAE,CAAC;QAChC,MAAM,KAAK,CAAC,8BAA8B,EAAE;YAC1C,KAAK,EAAE,IAAI;YACX,YAAY,EAAE,KAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC;SAC9C,CAAC,CAAA;IACJ,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAED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Aa,GAAG,yBAAyB,CAC7C,IAAI,EACJ,gBAAgB,CAAC,UAAU,EAC3B,gBAAgB,CAAC,SAAS,CAC3B,CAAA;YAED,iEAAiE;YACjE,oEAAoE;YACpE,iEAAiE;YACjE,MAAM,YAAY,GAAG,aAAa,EAAE,CAAC,CAAC,CAAC,CAAA;YACvC,MAAM,kBAAkB,GAAG,KAAK,CAAC,WAAW,CAAC,CAAA;YAC7C,MAAM,iBAAiB,GACrB,YAAY,IAAI,UAAU,CAAC,YAAY,CAAC,CAAA;YAC1C,IACE,cAAc,KAAK,SAAS;gBAC5B,kBAAkB;gBAClB,iBAAiB,EACjB,CAAC;gBACD,IAAI,CAAC,SAAS,CAAC,kBAAkB,EAAE,iBAAiB,CAAC,EAAE,CAAC;oBACtD,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;gBACzB,CAAC;gBACD,iEAAiE;YACnE,CAAC;iBAAM,IACL,CAAC,YAAY;gBACb,CAAC,cAAc,CAAC,YAAY,EAAE,WAAW,CAAC,EAC1C,CAAC;gBACD,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;YACzB,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,eAAe,GAAG,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAA;YAC9C,IACE,CAAC,eAAe;gBAChB,CAAC,cAAc,CAAC,eAAe,EAAE,WAAW,CAAC,EAC7C,CAAC;gBACD,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;YACzB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["import {\n satisfies,\n gt,\n gte,\n lt,\n lte,\n eq,\n neq,\n parse,\n parseRange,\n} from '@vltpkg/semver'\nimport type { Version } from '@vltpkg/semver'\nimport { error } from '@vltpkg/error-cause'\nimport { asError } from '@vltpkg/types'\nimport { parseInternals as parseAttrInternals } from './attr.ts'\nimport type { AttrInternals } from './attr.ts'\nimport { getManifestPropertyValues } from '../attribute.ts'\nimport {\n asAttributeNode,\n asPostcssNodeWithChildren,\n asPseudoNode,\n asStringNode,\n asTagNode,\n isAttributeNode,\n isPseudoNode,\n isStringNode,\n isTagNode,\n} from '@vltpkg/dss-parser'\nimport { removeNode, removeQuotes } from './helpers.ts'\nimport type { ParserState } from '../types.ts'\nimport type { PostcssNode } from '@vltpkg/dss-parser'\n\nexport type SemverInternals = {\n semverValue: string\n semverFunction: SemverComparatorFn\n compareAttribute: SemverCompareAttribute\n}\n\nexport type SemverFunctionNames =\n | 'satisfies'\n | 'gt'\n | 'gte'\n | 'lt'\n | 'lte'\n | 'eq'\n | 'neq'\nexport type SemverComparatorFn = (\n version: Version | string,\n range: string,\n) => boolean\nexport type SemverCompareAttribute =\n | Pick<AttrInternals, 'attribute' | 'properties'>\n | undefined\n\nconst semverFunctionNames = new Set([\n 'satisfies',\n 'gt',\n 'gte',\n 'lt',\n 'lte',\n 'eq',\n 'neq',\n])\nexport const isSemverFunctionName = (\n name: string,\n): name is SemverFunctionNames => semverFunctionNames.has(name)\n\nexport const asSemverFunctionName = (\n name: string,\n): SemverFunctionNames => {\n if (!isSemverFunctionName(name)) {\n throw error('Invalid semver function name', {\n found: name,\n validOptions: Array.from(semverFunctionNames),\n })\n }\n return name\n}\n\nconst semverFunctions = new Map<\n SemverFunctionNames,\n SemverComparatorFn\n>([\n ['satisfies', satisfies],\n ['gt', gt],\n ['gte', gte],\n ['lt', lt],\n ['lte', lte],\n ['eq', eq],\n ['neq', neq],\n])\n\nexport const parseInternals = (\n nodes: PostcssNode[],\n loose: boolean,\n): SemverInternals => {\n // tries to parse the first param as a string node, otherwise defaults\n // to reading all postcss nodes as just strings, since it just means\n // the value was defined as an unquoted string\n let semverValue = ''\n try {\n semverValue = removeQuotes(\n asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])\n .value,\n )\n } catch (err) {\n if (\n asError(err).message === 'Mismatching query node' &&\n isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])\n ) {\n // Handle tag node (unquoted values like >=2.0.0)\n const tagNode = asTagNode(\n asPostcssNodeWithChildren(nodes[0]).nodes[0],\n )\n semverValue = tagNode.value\n } else {\n throw err\n }\n }\n\n // second param is the function name\n let fnName: SemverFunctionNames = 'satisfies'\n try {\n // if there is a second node defined, try to parse it as a string node\n // first and if that fails, then parse it as a tag node which just means\n // it was defined as an unquoted string\n if (nodes[1]) {\n try {\n fnName = asSemverFunctionName(\n removeQuotes(\n asStringNode(asPostcssNodeWithChildren(nodes[1]).nodes[0])\n .value,\n ),\n )\n } catch (err) {\n if (asError(err).message === 'Mismatching query node') {\n fnName = asSemverFunctionName(\n asTagNode(asPostcssNodeWithChildren(nodes[1]).nodes[0])\n .value,\n )\n } else {\n throw err\n }\n }\n }\n } catch (e) {\n // allow invalid semver function names in loose mode, defaults to satisfies\n if (!loose) {\n throw e\n }\n }\n\n const semverFunction = semverFunctions.get(fnName)\n // the following should never happen as long as the semver function names\n // type and Set are correctly mirroring each other values\n /* c8 ignore start */\n if (!semverFunction) {\n throw error('Invalid semver function name', {\n found: fnName,\n validOptions: Array.from(semverFunctions.keys()),\n })\n }\n /* c8 ignore stop */\n\n // optional third param is the compare value\n let compareAttribute: SemverCompareAttribute\n if (nodes[2]) {\n const parentNode = asPostcssNodeWithChildren(nodes[2])\n const currNode = parentNode.nodes[0]\n if (isAttributeNode(currNode)) {\n const { attribute } = asAttributeNode(currNode)\n compareAttribute = {\n attribute,\n properties: [attribute],\n }\n } else if (isPseudoNode(currNode)) {\n compareAttribute = parseAttrInternals(\n asPseudoNode(currNode).nodes,\n )\n } else if (isStringNode(currNode)) {\n const attribute = removeQuotes(asStringNode(currNode).value)\n compareAttribute = {\n attribute,\n properties: [attribute],\n }\n }\n }\n\n return {\n semverValue,\n semverFunction,\n compareAttribute,\n }\n}\n\nexport const semverParser = async (state: ParserState) => {\n let internals\n try {\n internals = parseInternals(\n asPostcssNodeWithChildren(state.current).nodes,\n !!state.loose,\n )\n } catch (err) {\n throw error('Failed to parse :semver selector', {\n cause: err,\n })\n }\n\n const { semverValue, semverFunction, compareAttribute } = internals\n\n for (const node of state.partial.nodes) {\n if (compareAttribute) {\n const compareValues = getManifestPropertyValues(\n node,\n compareAttribute.properties,\n compareAttribute.attribute,\n )\n\n // if the provided semver value is a fixed semver version and the\n // compare attribute is resolving to a range value, then we flip the\n // order of comparison, in case it's a \"satisfies\" function check\n const compareValue = compareValues?.[0]\n const semverValueVersion = parse(semverValue)\n const compareValueRange =\n compareValue && parseRange(compareValue)\n if (\n semverFunction === satisfies &&\n semverValueVersion &&\n compareValueRange\n ) {\n if (!satisfies(semverValueVersion, compareValueRange)) {\n removeNode(state, node)\n }\n // otherwise just compares the read attribute to the semver value\n } else if (\n !compareValue ||\n !semverFunction(compareValue, semverValue)\n ) {\n removeNode(state, node)\n }\n } else {\n const manifestVersion = node.manifest?.version\n if (\n !manifestVersion ||\n !semverFunction(manifestVersion, semverValue)\n ) {\n removeNode(state, node)\n }\n }\n }\n\n return state\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ParserState } from '../types.ts';
|
|
2
|
+
import type { PostcssNode } from '@vltpkg/dss-parser';
|
|
3
|
+
export type SeverityKinds = '0' | '1' | '2' | '3' | 'critical' | 'high' | 'medium' | 'low' | undefined;
|
|
4
|
+
export type SeverityAlertTypes = 'criticalCVE' | 'cve' | 'potentialVulnerability' | 'mildCVE' | undefined;
|
|
5
|
+
export type SeverityComparator = '>' | '<' | '>=' | '<=' | undefined;
|
|
6
|
+
export declare const isSeverityKind: (value?: string) => value is SeverityKinds;
|
|
7
|
+
export declare const asSeverityKind: (value?: string) => SeverityKinds;
|
|
8
|
+
export declare const parseInternals: (nodes: PostcssNode[]) => {
|
|
9
|
+
kind: SeverityKinds;
|
|
10
|
+
comparator: SeverityComparator;
|
|
11
|
+
};
|
|
12
|
+
export declare const severity: (state: ParserState) => Promise<ParserState & {
|
|
13
|
+
securityArchive: NonNullable<ParserState["securityArchive"]>;
|
|
14
|
+
}>;
|
|
15
|
+
//# sourceMappingURL=severity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"severity.d.ts","sourceRoot":"","sources":["../../../src/pseudo/severity.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAErD,MAAM,MAAM,aAAa,GACrB,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,UAAU,GACV,MAAM,GACN,QAAQ,GACR,KAAK,GACL,SAAS,CAAA;AAEb,MAAM,MAAM,kBAAkB,GAC1B,aAAa,GACb,KAAK,GACL,wBAAwB,GACxB,SAAS,GACT,SAAS,CAAA;AAEb,MAAM,MAAM,kBAAkB,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,CAAA;AA2BpE,eAAO,MAAM,cAAc,WACjB,MAAM,KACb,KAAK,IAAI,aAAkD,CAAA;AAE9D,eAAO,MAAM,cAAc,WAAY,MAAM,KAAG,aAQ/C,CAAA;AAED,eAAO,MAAM,cAAc,UAClB,WAAW,EAAE,KACnB;IACD,IAAI,EAAE,aAAa,CAAA;IACnB,UAAU,EAAE,kBAAkB,CAAA;CAqD/B,CAAA;AAED,eAAO,MAAM,QAAQ,UAAiB,WAAW;;EA+FhD,CAAA"}
|