@vltpkg/query 1.5.0 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. package/dist/id.js +12 -5
  2. package/package.json +10 -12
  3. package/skills/dss-query/REFERENCE.md +0 -125
  4. package/skills/dss-query/SKILL.md +0 -190
  5. package/skills/dss-query/evals/README.md +0 -81
  6. package/skills/dss-query/evals/evals.json +0 -89
  7. package/skills/dss-query/evals/grade.mjs +0 -481
  8. package/src/attribute.ts +0 -190
  9. package/src/combinator.ts +0 -135
  10. package/src/error.ts +0 -78
  11. package/src/id.ts +0 -46
  12. package/src/index.ts +0 -670
  13. package/src/parser.ts +0 -122
  14. package/src/pseudo/abandoned.ts +0 -9
  15. package/src/pseudo/attr.ts +0 -92
  16. package/src/pseudo/built.ts +0 -19
  17. package/src/pseudo/confused.ts +0 -29
  18. package/src/pseudo/cve.ts +0 -93
  19. package/src/pseudo/cwe.ts +0 -97
  20. package/src/pseudo/debug.ts +0 -9
  21. package/src/pseudo/deprecated.ts +0 -9
  22. package/src/pseudo/dev.ts +0 -18
  23. package/src/pseudo/diff.ts +0 -90
  24. package/src/pseudo/dist.ts +0 -148
  25. package/src/pseudo/dynamic.ts +0 -9
  26. package/src/pseudo/empty.ts +0 -15
  27. package/src/pseudo/entropic.ts +0 -9
  28. package/src/pseudo/env.ts +0 -6
  29. package/src/pseudo/eval.ts +0 -9
  30. package/src/pseudo/fs.ts +0 -9
  31. package/src/pseudo/helpers.ts +0 -106
  32. package/src/pseudo/host.ts +0 -111
  33. package/src/pseudo/hostname.ts +0 -156
  34. package/src/pseudo/license.ts +0 -134
  35. package/src/pseudo/link.ts +0 -30
  36. package/src/pseudo/malware.ts +0 -41
  37. package/src/pseudo/minified.ts +0 -9
  38. package/src/pseudo/missing.ts +0 -16
  39. package/src/pseudo/native.ts +0 -9
  40. package/src/pseudo/network.ts +0 -9
  41. package/src/pseudo/obfuscated.ts +0 -9
  42. package/src/pseudo/optional.ts +0 -18
  43. package/src/pseudo/outdated.ts +0 -345
  44. package/src/pseudo/overridden.ts +0 -20
  45. package/src/pseudo/path.ts +0 -146
  46. package/src/pseudo/peer.ts +0 -18
  47. package/src/pseudo/prerelease.ts +0 -47
  48. package/src/pseudo/private.ts +0 -19
  49. package/src/pseudo/prod.ts +0 -18
  50. package/src/pseudo/published.ts +0 -250
  51. package/src/pseudo/registry.ts +0 -29
  52. package/src/pseudo/root.ts +0 -19
  53. package/src/pseudo/scanned.ts +0 -20
  54. package/src/pseudo/score.ts +0 -186
  55. package/src/pseudo/scripts.ts +0 -61
  56. package/src/pseudo/semver.ts +0 -320
  57. package/src/pseudo/severity.ts +0 -231
  58. package/src/pseudo/shell.ts +0 -9
  59. package/src/pseudo/shrinkwrap.ts +0 -9
  60. package/src/pseudo/skill.ts +0 -59
  61. package/src/pseudo/skills.ts +0 -29
  62. package/src/pseudo/spec.ts +0 -131
  63. package/src/pseudo/squat.ts +0 -225
  64. package/src/pseudo/suspicious.ts +0 -9
  65. package/src/pseudo/tracker.ts +0 -9
  66. package/src/pseudo/trivial.ts +0 -9
  67. package/src/pseudo/type.ts +0 -26
  68. package/src/pseudo/undesirable.ts +0 -9
  69. package/src/pseudo/unknown.ts +0 -9
  70. package/src/pseudo/unmaintained.ts +0 -9
  71. package/src/pseudo/unpopular.ts +0 -9
  72. package/src/pseudo/unstable.ts +0 -9
  73. package/src/pseudo/vuln.ts +0 -273
  74. package/src/pseudo/workspace.ts +0 -22
  75. package/src/pseudo.ts +0 -440
  76. package/src/types.ts +0 -206
  77. package/tap-snapshots/test/attribute.ts.test.cjs +0 -304
  78. package/tap-snapshots/test/combinator.ts.test.cjs +0 -333
  79. package/tap-snapshots/test/id.ts.test.cjs +0 -118
  80. package/tap-snapshots/test/parser.ts.test.cjs +0 -344
  81. package/tap-snapshots/test/pseudo/abandoned.ts.test.cjs +0 -18
  82. package/tap-snapshots/test/pseudo/attr.ts.test.cjs +0 -161
  83. package/tap-snapshots/test/pseudo/built.ts.test.cjs +0 -70
  84. package/tap-snapshots/test/pseudo/confused.ts.test.cjs +0 -32
  85. package/tap-snapshots/test/pseudo/cve.ts.test.cjs +0 -49
  86. package/tap-snapshots/test/pseudo/cwe.ts.test.cjs +0 -49
  87. package/tap-snapshots/test/pseudo/debug.ts.test.cjs +0 -18
  88. package/tap-snapshots/test/pseudo/deprecated.ts.test.cjs +0 -18
  89. package/tap-snapshots/test/pseudo/dist.ts.test.cjs +0 -30
  90. package/tap-snapshots/test/pseudo/dynamic.ts.test.cjs +0 -18
  91. package/tap-snapshots/test/pseudo/empty.ts.test.cjs +0 -50
  92. package/tap-snapshots/test/pseudo/entropic.ts.test.cjs +0 -18
  93. package/tap-snapshots/test/pseudo/env.ts.test.cjs +0 -18
  94. package/tap-snapshots/test/pseudo/eval.ts.test.cjs +0 -18
  95. package/tap-snapshots/test/pseudo/fs.ts.test.cjs +0 -18
  96. package/tap-snapshots/test/pseudo/helpers.ts.test.cjs +0 -18
  97. package/tap-snapshots/test/pseudo/hostname.ts.test.cjs +0 -148
  98. package/tap-snapshots/test/pseudo/license.ts.test.cjs +0 -41
  99. package/tap-snapshots/test/pseudo/link.ts.test.cjs +0 -36
  100. package/tap-snapshots/test/pseudo/malware.ts.test.cjs +0 -22
  101. package/tap-snapshots/test/pseudo/minified.ts.test.cjs +0 -18
  102. package/tap-snapshots/test/pseudo/missing.ts.test.cjs +0 -30
  103. package/tap-snapshots/test/pseudo/native.ts.test.cjs +0 -18
  104. package/tap-snapshots/test/pseudo/network.ts.test.cjs +0 -18
  105. package/tap-snapshots/test/pseudo/obfuscated.ts.test.cjs +0 -18
  106. package/tap-snapshots/test/pseudo/outdated.ts.test.cjs +0 -132
  107. package/tap-snapshots/test/pseudo/overridden.ts.test.cjs +0 -75
  108. package/tap-snapshots/test/pseudo/prerelease.ts.test.cjs +0 -101
  109. package/tap-snapshots/test/pseudo/private.ts.test.cjs +0 -38
  110. package/tap-snapshots/test/pseudo/published.ts.test.cjs +0 -171
  111. package/tap-snapshots/test/pseudo/registry.ts.test.cjs +0 -68
  112. package/tap-snapshots/test/pseudo/root.ts.test.cjs +0 -24
  113. package/tap-snapshots/test/pseudo/scanned.ts.test.cjs +0 -18
  114. package/tap-snapshots/test/pseudo/score.ts.test.cjs +0 -239
  115. package/tap-snapshots/test/pseudo/scripts.ts.test.cjs +0 -62
  116. package/tap-snapshots/test/pseudo/semver.ts.test.cjs +0 -575
  117. package/tap-snapshots/test/pseudo/severity.ts.test.cjs +0 -122
  118. package/tap-snapshots/test/pseudo/shell.ts.test.cjs +0 -18
  119. package/tap-snapshots/test/pseudo/shrinkwrap.ts.test.cjs +0 -18
  120. package/tap-snapshots/test/pseudo/skills.ts.test.cjs +0 -19
  121. package/tap-snapshots/test/pseudo/spec.ts.test.cjs +0 -148
  122. package/tap-snapshots/test/pseudo/squat.ts.test.cjs +0 -129
  123. package/tap-snapshots/test/pseudo/suspicious.ts.test.cjs +0 -18
  124. package/tap-snapshots/test/pseudo/tracker.ts.test.cjs +0 -18
  125. package/tap-snapshots/test/pseudo/trivial.ts.test.cjs +0 -18
  126. package/tap-snapshots/test/pseudo/type.ts.test.cjs +0 -51
  127. package/tap-snapshots/test/pseudo/undesirable.ts.test.cjs +0 -18
  128. package/tap-snapshots/test/pseudo/unknown.ts.test.cjs +0 -18
  129. package/tap-snapshots/test/pseudo/unmaintained.ts.test.cjs +0 -18
  130. package/tap-snapshots/test/pseudo/unpopular.ts.test.cjs +0 -18
  131. package/tap-snapshots/test/pseudo/unstable.ts.test.cjs +0 -18
  132. package/tap-snapshots/test/pseudo/vuln.ts.test.cjs +0 -208
  133. package/tap-snapshots/test/pseudo/vulnerable.ts.test.cjs +0 -20
  134. package/tap-snapshots/test/pseudo/workspace.ts.test.cjs +0 -19
  135. package/tap-snapshots/test/pseudo.ts.test.cjs +0 -1247
  136. package/test/attribute.ts +0 -273
  137. package/test/combinator.ts +0 -175
  138. package/test/error.ts +0 -60
  139. package/test/fixtures/graph.ts +0 -999
  140. package/test/fixtures/selector.ts +0 -103
  141. package/test/fixtures/types.ts +0 -7
  142. package/test/id.ts +0 -102
  143. package/test/index.ts +0 -1148
  144. package/test/parser.ts +0 -117
  145. package/test/pseudo/abandoned.ts +0 -98
  146. package/test/pseudo/attr.ts +0 -298
  147. package/test/pseudo/built.ts +0 -214
  148. package/test/pseudo/confused.ts +0 -160
  149. package/test/pseudo/cve.ts +0 -249
  150. package/test/pseudo/cwe.ts +0 -255
  151. package/test/pseudo/debug.ts +0 -98
  152. package/test/pseudo/deprecated.ts +0 -98
  153. package/test/pseudo/dev.ts +0 -61
  154. package/test/pseudo/diff.ts +0 -417
  155. package/test/pseudo/dist.ts +0 -215
  156. package/test/pseudo/dynamic.ts +0 -98
  157. package/test/pseudo/empty.ts +0 -108
  158. package/test/pseudo/entropic.ts +0 -101
  159. package/test/pseudo/env.ts +0 -98
  160. package/test/pseudo/eval.ts +0 -98
  161. package/test/pseudo/fs.ts +0 -98
  162. package/test/pseudo/helpers.ts +0 -370
  163. package/test/pseudo/host-context.ts +0 -276
  164. package/test/pseudo/hostname.ts +0 -314
  165. package/test/pseudo/license.ts +0 -265
  166. package/test/pseudo/link.ts +0 -94
  167. package/test/pseudo/malware.ts +0 -184
  168. package/test/pseudo/minified.ts +0 -98
  169. package/test/pseudo/missing.ts +0 -111
  170. package/test/pseudo/native.ts +0 -98
  171. package/test/pseudo/network.ts +0 -98
  172. package/test/pseudo/obfuscated.ts +0 -98
  173. package/test/pseudo/optional.ts +0 -73
  174. package/test/pseudo/outdated.ts +0 -461
  175. package/test/pseudo/overridden.ts +0 -317
  176. package/test/pseudo/path.ts +0 -680
  177. package/test/pseudo/peer.ts +0 -101
  178. package/test/pseudo/prerelease.ts +0 -279
  179. package/test/pseudo/private.ts +0 -108
  180. package/test/pseudo/prod.ts +0 -61
  181. package/test/pseudo/published.ts +0 -557
  182. package/test/pseudo/registry.ts +0 -122
  183. package/test/pseudo/root.ts +0 -66
  184. package/test/pseudo/scanned.ts +0 -144
  185. package/test/pseudo/score.ts +0 -591
  186. package/test/pseudo/scripts.ts +0 -324
  187. package/test/pseudo/semver.ts +0 -822
  188. package/test/pseudo/severity.ts +0 -342
  189. package/test/pseudo/shell.ts +0 -98
  190. package/test/pseudo/shrinkwrap.ts +0 -98
  191. package/test/pseudo/skill.ts +0 -189
  192. package/test/pseudo/skills.ts +0 -90
  193. package/test/pseudo/spec.ts +0 -525
  194. package/test/pseudo/squat.ts +0 -565
  195. package/test/pseudo/suspicious.ts +0 -98
  196. package/test/pseudo/tracker.ts +0 -98
  197. package/test/pseudo/trivial.ts +0 -98
  198. package/test/pseudo/type.ts +0 -105
  199. package/test/pseudo/undesirable.ts +0 -98
  200. package/test/pseudo/unknown.ts +0 -98
  201. package/test/pseudo/unmaintained.ts +0 -98
  202. package/test/pseudo/unpopular.ts +0 -98
  203. package/test/pseudo/unstable.ts +0 -98
  204. package/test/pseudo/vuln.ts +0 -625
  205. package/test/pseudo/vulnerable.ts +0 -137
  206. package/test/pseudo/workspace.ts +0 -111
  207. package/test/pseudo.ts +0 -584
  208. package/tsconfig.json +0 -3
  209. package/tsconfig.publish.json +0 -19
  210. package/tsconfig.publish.tsbuildinfo +0 -1
  211. package/typedoc.mjs +0 -2
@@ -1,146 +0,0 @@
1
- import { minimatch } from 'minimatch'
2
- import { error } from '@vltpkg/error-cause'
3
- import { splitDepID } from '@vltpkg/dep-id/browser'
4
- import { asError } from '@vltpkg/types'
5
- import {
6
- asPostcssNodeWithChildren,
7
- asStringNode,
8
- isStringNode,
9
- } from '@vltpkg/dss-parser'
10
- import {
11
- removeNode,
12
- removeDanglingEdges,
13
- removeQuotes,
14
- clear,
15
- } from './helpers.ts'
16
- import type { ParserState } from '../types.ts'
17
-
18
- /**
19
- * Normalizes a path by trimming whitespace and removing leading './' or '.' prefix.
20
- * This ensures consistent path comparison regardless of how paths are specified.
21
- */
22
- export function normalizePath(path: string): string {
23
- const trimmed = path.trim().replaceAll('\\', '/')
24
-
25
- if (trimmed === '.') {
26
- return ''
27
- }
28
-
29
- if (trimmed.startsWith('./')) {
30
- return trimmed.slice(2)
31
- }
32
-
33
- return trimmed
34
- }
35
-
36
- /**
37
- * Creates a path matcher function that tests if
38
- * a given path matches a glob pattern.
39
- */
40
- export function createPathMatcher(pattern: string, loose = false) {
41
- const normalizedPattern = normalizePath(pattern)
42
- const isRoot = normalizedPattern === '' || pattern.trim() === '.'
43
-
44
- return (path: string) => {
45
- const normalizedPath = normalizePath(path)
46
-
47
- if (isRoot) {
48
- return normalizedPath === '' || normalizedPath === '.'
49
- }
50
- try {
51
- return minimatch(normalizedPath, normalizedPattern, {
52
- dot: true,
53
- nocase: false,
54
- matchBase: normalizedPattern === '*',
55
- })
56
- } catch (err) {
57
- // In loose mode, return false for invalid patterns
58
- if (loose) {
59
- return false
60
- }
61
- // In strict mode, throw an error
62
- throw error(
63
- 'Invalid glob pattern in :path selector',
64
- asError(err),
65
- )
66
- }
67
- }
68
- }
69
-
70
- /**
71
- * :path("glob") Pseudo-Selector will match only workspace & file
72
- * nodes whose file path matches the provided glob pattern relative
73
- * to the project root. Path patterns must be quoted strings to avoid
74
- * parser conflicts with special characters.
75
- */
76
- export const path = async (state: ParserState) => {
77
- // Extract path container and handle empty parameters
78
- const pathContainer = asPostcssNodeWithChildren(state.current)
79
- if (!pathContainer.nodes[0]) {
80
- return clear(state)
81
- }
82
-
83
- // Extract the selector node and handle empty selectors
84
- const selector = asPostcssNodeWithChildren(pathContainer.nodes[0])
85
- if (!selector.nodes[0]) {
86
- return clear(state)
87
- }
88
-
89
- // Extract and validate the path pattern
90
- let pathPattern = ''
91
- if (isStringNode(selector.nodes[0])) {
92
- pathPattern = removeQuotes(asStringNode(selector.nodes[0]).value)
93
- } else {
94
- if (state.loose) {
95
- return clear(state)
96
- }
97
- throw error(
98
- 'Failed to parse path pattern in :path selector',
99
- new Error('Path pattern must be a quoted string'),
100
- )
101
- }
102
-
103
- // If no pattern provided, match nothing
104
- if (!pathPattern) {
105
- return clear(state)
106
- }
107
-
108
- // Check for unmatched brackets
109
- if (
110
- pathPattern === '[' ||
111
- (pathPattern.includes('[') && !pathPattern.includes(']'))
112
- ) {
113
- if (state.loose) {
114
- return clear(state)
115
- }
116
- throw error(
117
- 'Invalid glob pattern in :path selector',
118
- new Error(`Unmatched bracket in pattern: ${pathPattern}`),
119
- )
120
- }
121
-
122
- // Create path matcher function
123
- const matchPath = createPathMatcher(pathPattern, state.loose)
124
-
125
- // Filter nodes by path
126
- for (const node of state.partial.nodes) {
127
- /* c8 ignore next */
128
- const nodePath = node.location || ''
129
- const [type] = splitDepID(node.id)
130
-
131
- // Special case for main importer with root path pattern
132
- if (pathPattern === '.' && node.mainImporter) {
133
- continue // Keep main importer node for root path pattern
134
- }
135
-
136
- // Only match workspace or file nodes with matching paths
137
- const pathBased = type === 'workspace' || type === 'file'
138
- if (!pathBased || !matchPath(nodePath)) {
139
- removeNode(state, node)
140
- }
141
- }
142
-
143
- // Clean up any dangling edges
144
- removeDanglingEdges(state)
145
- return state
146
- }
@@ -1,18 +0,0 @@
1
- import type { ParserState } from '../types.ts'
2
- import { removeEdge, removeUnlinkedNodes } from './helpers.ts'
3
-
4
- /**
5
- * :peer Pseudo-Selector will only match peer dependencies.
6
- */
7
- export const peer = async (state: ParserState) => {
8
- // filter edges that aren't marked as peer
9
- for (const edge of state.partial.edges) {
10
- if (!edge.peer) {
11
- removeEdge(state, edge)
12
- }
13
- }
14
-
15
- removeUnlinkedNodes(state)
16
-
17
- return state
18
- }
@@ -1,47 +0,0 @@
1
- import { parse } from '@vltpkg/semver'
2
- import { removeNode, removeDanglingEdges } from './helpers.ts'
3
- import type { ParserState } from '../types.ts'
4
-
5
- /**
6
- * :prerelease Pseudo-selector, matches only nodes that have prerelease
7
- * elements in their parsed semver value.
8
- *
9
- * Examples of versions that should match:
10
- * - 19.2.0-canary-fa3feba6-20250623
11
- * - 1.0.0-beta.0
12
- * - 0.0.0-16
13
- * - 1.2.3-rc.1+rev.2
14
- *
15
- * Examples of versions that should NOT match:
16
- * - 1.0.0
17
- * - 99.9.9
18
- * - 0.0.1
19
- */
20
- export const prerelease = async (state: ParserState) => {
21
- for (const node of state.partial.nodes) {
22
- const version = node.manifest?.version
23
-
24
- // Skip nodes without a version (like root/importer nodes)
25
- if (!version) {
26
- removeNode(state, node)
27
- continue
28
- }
29
-
30
- const parsedVersion = parse(version)
31
- if (!parsedVersion) {
32
- // Remove nodes with invalid semver versions
33
- removeNode(state, node)
34
- continue
35
- }
36
-
37
- // Check if the version has prerelease identifiers
38
- if (!parsedVersion.prerelease?.length) {
39
- // Remove nodes that don't have prerelease identifiers
40
- removeNode(state, node)
41
- }
42
- }
43
-
44
- removeDanglingEdges(state)
45
-
46
- return state
47
- }
@@ -1,19 +0,0 @@
1
- import { asManifest } from '@vltpkg/types'
2
- import type { ParserState } from '../types.ts'
3
- import { removeNode, removeDanglingEdges } from './helpers.ts'
4
-
5
- /**
6
- * :private Pseudo-Selector will only match packages that have
7
- * a `private: true` key set in their `package.json` metadata.
8
- */
9
- export const privateParser = async (state: ParserState) => {
10
- for (const node of state.partial.nodes) {
11
- if (!node.manifest || !asManifest(node.manifest).private) {
12
- removeNode(state, node)
13
- }
14
- }
15
-
16
- removeDanglingEdges(state)
17
-
18
- return state
19
- }
@@ -1,18 +0,0 @@
1
- import type { ParserState } from '../types.ts'
2
- import { removeEdge, removeUnlinkedNodes } from './helpers.ts'
3
-
4
- /**
5
- * :prod Pseudo-Selector will only match production dependencies.
6
- */
7
- export const prod = async (state: ParserState) => {
8
- // filter edges that don't have type 'prod'
9
- for (const edge of state.partial.edges) {
10
- if (edge.type !== 'prod') {
11
- removeEdge(state, edge)
12
- }
13
- }
14
-
15
- removeUnlinkedNodes(state)
16
-
17
- return state
18
- }
@@ -1,250 +0,0 @@
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 { userAgentHeaders } from '@vltpkg/user-agent'
5
- import { asError } from '@vltpkg/types'
6
- import {
7
- asPostcssNodeWithChildren,
8
- asStringNode,
9
- asTagNode,
10
- isStringNode,
11
- isTagNode,
12
- } from '@vltpkg/dss-parser'
13
- import {
14
- removeDanglingEdges,
15
- removeNode,
16
- removeQuotes,
17
- } from './helpers.ts'
18
- import type { NodeLike, Packument } from '@vltpkg/types'
19
- import type { ParserState } from '../types.ts'
20
- import type { PostcssNode } from '@vltpkg/dss-parser'
21
-
22
- /**
23
- * The possible comparator values accepted by the :published() pseudo selector.
24
- */
25
- export type PublishedComparator = '>' | '<' | '>=' | '<=' | undefined
26
-
27
- /**
28
- * Result of the internal parsing of the :published() pseudo selector.
29
- */
30
- export type PublishedInternals = {
31
- relativeDate: string
32
- comparator: PublishedComparator
33
- }
34
-
35
- /**
36
- * Fetches the published date of a package version from the npm registry.
37
- */
38
- export const retrieveRemoteDate = async (
39
- node: NodeLike,
40
- signal?: AbortSignal,
41
- ): Promise<string | undefined> => {
42
- const spec = hydrate(node.id, String(node.name), node.options)
43
- if (!spec.registry || !node.name || !node.version) {
44
- return undefined
45
- }
46
-
47
- const url = new URL(spec.registry)
48
- url.pathname = `/${node.name}`
49
-
50
- const response = await fetch(String(url), {
51
- headers: { ...userAgentHeaders },
52
- signal,
53
- })
54
- // on missing valid auth or API, it should abort the retry logic
55
- if (response.status === 404) {
56
- throw new AbortError('Missing API')
57
- }
58
- if (!response.ok) {
59
- throw error('Failed to fetch packument', {
60
- name: node.name,
61
- spec,
62
- response,
63
- })
64
- }
65
- const packument = (await response.json()) as Packument
66
- const res = packument.time?.[node.version]
67
- return res
68
- }
69
-
70
- /**
71
- * Retrieves what kind of check the :published selector should perform.
72
- */
73
- export const parseInternals = (
74
- nodes: PostcssNode[],
75
- ): PublishedInternals => {
76
- let value = ''
77
-
78
- if (isStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {
79
- value = removeQuotes(
80
- asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])
81
- .value,
82
- )
83
- } else if (
84
- isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])
85
- ) {
86
- const tagNode = asTagNode(
87
- asPostcssNodeWithChildren(nodes[0]).nodes[0],
88
- )
89
- value = tagNode.value
90
- }
91
-
92
- // Check if the value starts with a comparator
93
- let comparator: PublishedComparator
94
- let relativeDate = value
95
-
96
- if (value.startsWith('>=')) {
97
- comparator = '>='
98
- relativeDate = value.slice(2)
99
- } else if (value.startsWith('<=')) {
100
- comparator = '<='
101
- relativeDate = value.slice(2)
102
- } else if (value.startsWith('>')) {
103
- comparator = '>'
104
- relativeDate = value.slice(1)
105
- } else if (value.startsWith('<')) {
106
- comparator = '<'
107
- relativeDate = value.slice(1)
108
- }
109
-
110
- return { relativeDate, comparator }
111
- }
112
-
113
- /**
114
- * Filter nodes by queueing up for removal those that don't match the date criteria.
115
- */
116
- export const queueNode = async (
117
- state: ParserState,
118
- node: NodeLike,
119
- relativeDate: string,
120
- comparator: PublishedComparator,
121
- ): Promise<NodeLike | undefined> => {
122
- if (!node.name || !node.version) {
123
- return node
124
- }
125
-
126
- let publishedDate: string | undefined
127
- try {
128
- publishedDate = await pRetry(
129
- () => retrieveRemoteDate(node, state.signal),
130
- {
131
- retries: state.retries,
132
- signal: state.signal,
133
- },
134
- )
135
- } catch (err) {
136
- // eslint-disable-next-line no-console
137
- console.warn(
138
- error('Could not retrieve registry publish date', {
139
- name: node.name,
140
- cause: err,
141
- }),
142
- )
143
- return node
144
- }
145
-
146
- if (!publishedDate) {
147
- return node
148
- }
149
-
150
- // only matches the same amount of date information
151
- // as provided in the relative date
152
- const nodeDate = new Date(
153
- publishedDate.slice(0, relativeDate.length),
154
- )
155
- const compareDate = new Date(relativeDate)
156
-
157
- switch (comparator) {
158
- case '>':
159
- return nodeDate > compareDate ? undefined : node
160
- case '<':
161
- return nodeDate < compareDate ? undefined : node
162
- case '>=':
163
- return nodeDate >= compareDate ? undefined : node
164
- case '<=':
165
- return nodeDate <= compareDate ? undefined : node
166
- default:
167
- return nodeDate.getTime() === compareDate.getTime() ?
168
- undefined
169
- : node
170
- }
171
- }
172
-
173
- /**
174
- * Filters out nodes that don't match the published date criteria.
175
- *
176
- * The :published() pseudo selector supports a date parameter that can be prefixed
177
- * with a comparator (>, <, >=, <=). If no comparator is provided, it will match
178
- * exact dates.
179
- *
180
- * Examples:
181
- * - :published("2024-01-01") - Matches packages published exactly on January 1st, 2024
182
- * - :published(">2024-01-01") - Matches packages published after January 1st, 2024
183
- * - :published("<=2023-12-31") - Matches packages published on or before December 31st, 2023
184
- */
185
- export const published = async (state: ParserState) => {
186
- let internals
187
- try {
188
- internals = parseInternals(
189
- asPostcssNodeWithChildren(state.current).nodes,
190
- )
191
- } catch (err) {
192
- if (asError(err).message === 'Expected a query node') {
193
- // No parameters provided - pseudo state form: match ANY published metadata
194
- for (const node of state.partial.nodes) {
195
- // filter out nodes that are always ignored by the published selector
196
- if (
197
- node.mainImporter ||
198
- node.manifest?.private ||
199
- splitDepID(node.id)[0] !== 'registry'
200
- ) {
201
- removeNode(state, node)
202
- continue
203
- }
204
-
205
- // For pseudo state form, we just check if the node has published metadata
206
- // This is equivalent to checking if it's a registry package with version info
207
- if (!node.name || !node.version) {
208
- removeNode(state, node)
209
- }
210
- }
211
- removeDanglingEdges(state)
212
- return state
213
- } else {
214
- throw error('Failed to parse :published selector', {
215
- cause: err,
216
- })
217
- }
218
- }
219
-
220
- const { relativeDate, comparator } = internals
221
- const queue = []
222
-
223
- for (const node of state.partial.nodes) {
224
- // filter out nodes that are always ignored by the published selector
225
- if (
226
- node.mainImporter ||
227
- node.manifest?.private ||
228
- splitDepID(node.id)[0] !== 'registry'
229
- ) {
230
- removeNode(state, node)
231
- continue
232
- }
233
-
234
- // fetch published date info and perform checks to define
235
- // whether or not a node should be filtered out
236
- queue.push(queueNode(state, node, relativeDate, comparator))
237
- }
238
-
239
- // nodes queued for removal are then finally removed
240
- const removeNodeQueue = await Promise.all(queue)
241
- for (const node of removeNodeQueue) {
242
- if (node) {
243
- removeNode(state, node)
244
- }
245
- }
246
-
247
- removeDanglingEdges(state)
248
-
249
- return state
250
- }
@@ -1,29 +0,0 @@
1
- import { splitDepID } from '@vltpkg/dep-id/browser'
2
- import {
3
- asPostcssNodeWithChildren,
4
- asTagNode,
5
- } from '@vltpkg/dss-parser'
6
- import { removeDanglingEdges, removeNode } from './helpers.ts'
7
- import type { ParserState } from '../types.ts'
8
-
9
- /**
10
- * :registry(name) Pseudo-Selector, matches only nodes that
11
- * belong to the specified registry configuration alias.
12
- *
13
- * For example, `:registry(npm)` matches deps from the default
14
- * npm registry, and `:registry(custom)` matches deps from a
15
- * custom-named registry.
16
- */
17
- export const registry = async (state: ParserState) => {
18
- const top = asPostcssNodeWithChildren(state.current)
19
- const selector = asPostcssNodeWithChildren(top.nodes[0])
20
- const name = asTagNode(selector.nodes[0]).value
21
- for (const node of state.partial.nodes) {
22
- const tuple = splitDepID(node.id)
23
- if (tuple[0] !== 'registry' || tuple[1] !== name) {
24
- removeNode(state, node)
25
- }
26
- }
27
- removeDanglingEdges(state)
28
- return state
29
- }
@@ -1,19 +0,0 @@
1
- import type { ParserState } from '../types.ts'
2
-
3
- /**
4
- * :root Pseudo-Element will return the project root node for the graph.
5
- * It matches only nodes marked as `mainImporter`.
6
- */
7
- export const root = async (state: ParserState) => {
8
- for (const edge of state.partial.edges) {
9
- if (!edge.to?.mainImporter) {
10
- state.partial.edges.delete(edge)
11
- }
12
- }
13
- for (const node of state.partial.nodes) {
14
- if (!node.mainImporter) {
15
- state.partial.nodes.delete(node)
16
- }
17
- }
18
- return state
19
- }
@@ -1,20 +0,0 @@
1
- import { removeDanglingEdges, removeNode } from './helpers.ts'
2
- import type { ParserState } from '../types.ts'
3
-
4
- /**
5
- * :scanned pseudo selector.
6
- *
7
- * Remove all nodes that do not have available metadata
8
- * in the security archive.
9
- */
10
- export const scanned = async (state: ParserState) => {
11
- for (const node of state.partial.nodes) {
12
- if (!state.securityArchive?.has(node.id)) {
13
- removeNode(state, node)
14
- }
15
- }
16
-
17
- removeDanglingEdges(state)
18
-
19
- return state
20
- }