@vltpkg/query 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. package/package.json +10 -12
  2. package/skills/dss-query/REFERENCE.md +0 -125
  3. package/skills/dss-query/SKILL.md +0 -190
  4. package/skills/dss-query/evals/README.md +0 -81
  5. package/skills/dss-query/evals/evals.json +0 -89
  6. package/skills/dss-query/evals/grade.mjs +0 -481
  7. package/src/attribute.ts +0 -190
  8. package/src/combinator.ts +0 -135
  9. package/src/error.ts +0 -78
  10. package/src/id.ts +0 -46
  11. package/src/index.ts +0 -670
  12. package/src/parser.ts +0 -122
  13. package/src/pseudo/abandoned.ts +0 -9
  14. package/src/pseudo/attr.ts +0 -92
  15. package/src/pseudo/built.ts +0 -19
  16. package/src/pseudo/confused.ts +0 -29
  17. package/src/pseudo/cve.ts +0 -93
  18. package/src/pseudo/cwe.ts +0 -97
  19. package/src/pseudo/debug.ts +0 -9
  20. package/src/pseudo/deprecated.ts +0 -9
  21. package/src/pseudo/dev.ts +0 -18
  22. package/src/pseudo/diff.ts +0 -90
  23. package/src/pseudo/dist.ts +0 -148
  24. package/src/pseudo/dynamic.ts +0 -9
  25. package/src/pseudo/empty.ts +0 -15
  26. package/src/pseudo/entropic.ts +0 -9
  27. package/src/pseudo/env.ts +0 -6
  28. package/src/pseudo/eval.ts +0 -9
  29. package/src/pseudo/fs.ts +0 -9
  30. package/src/pseudo/helpers.ts +0 -106
  31. package/src/pseudo/host.ts +0 -111
  32. package/src/pseudo/hostname.ts +0 -156
  33. package/src/pseudo/license.ts +0 -134
  34. package/src/pseudo/link.ts +0 -30
  35. package/src/pseudo/malware.ts +0 -41
  36. package/src/pseudo/minified.ts +0 -9
  37. package/src/pseudo/missing.ts +0 -16
  38. package/src/pseudo/native.ts +0 -9
  39. package/src/pseudo/network.ts +0 -9
  40. package/src/pseudo/obfuscated.ts +0 -9
  41. package/src/pseudo/optional.ts +0 -18
  42. package/src/pseudo/outdated.ts +0 -345
  43. package/src/pseudo/overridden.ts +0 -20
  44. package/src/pseudo/path.ts +0 -146
  45. package/src/pseudo/peer.ts +0 -18
  46. package/src/pseudo/prerelease.ts +0 -47
  47. package/src/pseudo/private.ts +0 -19
  48. package/src/pseudo/prod.ts +0 -18
  49. package/src/pseudo/published.ts +0 -250
  50. package/src/pseudo/registry.ts +0 -29
  51. package/src/pseudo/root.ts +0 -19
  52. package/src/pseudo/scanned.ts +0 -20
  53. package/src/pseudo/score.ts +0 -186
  54. package/src/pseudo/scripts.ts +0 -61
  55. package/src/pseudo/semver.ts +0 -320
  56. package/src/pseudo/severity.ts +0 -231
  57. package/src/pseudo/shell.ts +0 -9
  58. package/src/pseudo/shrinkwrap.ts +0 -9
  59. package/src/pseudo/skill.ts +0 -59
  60. package/src/pseudo/skills.ts +0 -29
  61. package/src/pseudo/spec.ts +0 -131
  62. package/src/pseudo/squat.ts +0 -225
  63. package/src/pseudo/suspicious.ts +0 -9
  64. package/src/pseudo/tracker.ts +0 -9
  65. package/src/pseudo/trivial.ts +0 -9
  66. package/src/pseudo/type.ts +0 -26
  67. package/src/pseudo/undesirable.ts +0 -9
  68. package/src/pseudo/unknown.ts +0 -9
  69. package/src/pseudo/unmaintained.ts +0 -9
  70. package/src/pseudo/unpopular.ts +0 -9
  71. package/src/pseudo/unstable.ts +0 -9
  72. package/src/pseudo/vuln.ts +0 -273
  73. package/src/pseudo/workspace.ts +0 -22
  74. package/src/pseudo.ts +0 -440
  75. package/src/types.ts +0 -206
  76. package/tap-snapshots/test/attribute.ts.test.cjs +0 -304
  77. package/tap-snapshots/test/combinator.ts.test.cjs +0 -333
  78. package/tap-snapshots/test/id.ts.test.cjs +0 -118
  79. package/tap-snapshots/test/parser.ts.test.cjs +0 -344
  80. package/tap-snapshots/test/pseudo/abandoned.ts.test.cjs +0 -18
  81. package/tap-snapshots/test/pseudo/attr.ts.test.cjs +0 -161
  82. package/tap-snapshots/test/pseudo/built.ts.test.cjs +0 -70
  83. package/tap-snapshots/test/pseudo/confused.ts.test.cjs +0 -32
  84. package/tap-snapshots/test/pseudo/cve.ts.test.cjs +0 -49
  85. package/tap-snapshots/test/pseudo/cwe.ts.test.cjs +0 -49
  86. package/tap-snapshots/test/pseudo/debug.ts.test.cjs +0 -18
  87. package/tap-snapshots/test/pseudo/deprecated.ts.test.cjs +0 -18
  88. package/tap-snapshots/test/pseudo/dist.ts.test.cjs +0 -30
  89. package/tap-snapshots/test/pseudo/dynamic.ts.test.cjs +0 -18
  90. package/tap-snapshots/test/pseudo/empty.ts.test.cjs +0 -50
  91. package/tap-snapshots/test/pseudo/entropic.ts.test.cjs +0 -18
  92. package/tap-snapshots/test/pseudo/env.ts.test.cjs +0 -18
  93. package/tap-snapshots/test/pseudo/eval.ts.test.cjs +0 -18
  94. package/tap-snapshots/test/pseudo/fs.ts.test.cjs +0 -18
  95. package/tap-snapshots/test/pseudo/helpers.ts.test.cjs +0 -18
  96. package/tap-snapshots/test/pseudo/hostname.ts.test.cjs +0 -148
  97. package/tap-snapshots/test/pseudo/license.ts.test.cjs +0 -41
  98. package/tap-snapshots/test/pseudo/link.ts.test.cjs +0 -36
  99. package/tap-snapshots/test/pseudo/malware.ts.test.cjs +0 -22
  100. package/tap-snapshots/test/pseudo/minified.ts.test.cjs +0 -18
  101. package/tap-snapshots/test/pseudo/missing.ts.test.cjs +0 -30
  102. package/tap-snapshots/test/pseudo/native.ts.test.cjs +0 -18
  103. package/tap-snapshots/test/pseudo/network.ts.test.cjs +0 -18
  104. package/tap-snapshots/test/pseudo/obfuscated.ts.test.cjs +0 -18
  105. package/tap-snapshots/test/pseudo/outdated.ts.test.cjs +0 -132
  106. package/tap-snapshots/test/pseudo/overridden.ts.test.cjs +0 -75
  107. package/tap-snapshots/test/pseudo/prerelease.ts.test.cjs +0 -101
  108. package/tap-snapshots/test/pseudo/private.ts.test.cjs +0 -38
  109. package/tap-snapshots/test/pseudo/published.ts.test.cjs +0 -171
  110. package/tap-snapshots/test/pseudo/registry.ts.test.cjs +0 -68
  111. package/tap-snapshots/test/pseudo/root.ts.test.cjs +0 -24
  112. package/tap-snapshots/test/pseudo/scanned.ts.test.cjs +0 -18
  113. package/tap-snapshots/test/pseudo/score.ts.test.cjs +0 -239
  114. package/tap-snapshots/test/pseudo/scripts.ts.test.cjs +0 -62
  115. package/tap-snapshots/test/pseudo/semver.ts.test.cjs +0 -575
  116. package/tap-snapshots/test/pseudo/severity.ts.test.cjs +0 -122
  117. package/tap-snapshots/test/pseudo/shell.ts.test.cjs +0 -18
  118. package/tap-snapshots/test/pseudo/shrinkwrap.ts.test.cjs +0 -18
  119. package/tap-snapshots/test/pseudo/skills.ts.test.cjs +0 -19
  120. package/tap-snapshots/test/pseudo/spec.ts.test.cjs +0 -148
  121. package/tap-snapshots/test/pseudo/squat.ts.test.cjs +0 -129
  122. package/tap-snapshots/test/pseudo/suspicious.ts.test.cjs +0 -18
  123. package/tap-snapshots/test/pseudo/tracker.ts.test.cjs +0 -18
  124. package/tap-snapshots/test/pseudo/trivial.ts.test.cjs +0 -18
  125. package/tap-snapshots/test/pseudo/type.ts.test.cjs +0 -51
  126. package/tap-snapshots/test/pseudo/undesirable.ts.test.cjs +0 -18
  127. package/tap-snapshots/test/pseudo/unknown.ts.test.cjs +0 -18
  128. package/tap-snapshots/test/pseudo/unmaintained.ts.test.cjs +0 -18
  129. package/tap-snapshots/test/pseudo/unpopular.ts.test.cjs +0 -18
  130. package/tap-snapshots/test/pseudo/unstable.ts.test.cjs +0 -18
  131. package/tap-snapshots/test/pseudo/vuln.ts.test.cjs +0 -208
  132. package/tap-snapshots/test/pseudo/vulnerable.ts.test.cjs +0 -20
  133. package/tap-snapshots/test/pseudo/workspace.ts.test.cjs +0 -19
  134. package/tap-snapshots/test/pseudo.ts.test.cjs +0 -1247
  135. package/test/attribute.ts +0 -273
  136. package/test/combinator.ts +0 -175
  137. package/test/error.ts +0 -60
  138. package/test/fixtures/graph.ts +0 -999
  139. package/test/fixtures/selector.ts +0 -103
  140. package/test/fixtures/types.ts +0 -7
  141. package/test/id.ts +0 -102
  142. package/test/index.ts +0 -1148
  143. package/test/parser.ts +0 -117
  144. package/test/pseudo/abandoned.ts +0 -98
  145. package/test/pseudo/attr.ts +0 -298
  146. package/test/pseudo/built.ts +0 -214
  147. package/test/pseudo/confused.ts +0 -160
  148. package/test/pseudo/cve.ts +0 -249
  149. package/test/pseudo/cwe.ts +0 -255
  150. package/test/pseudo/debug.ts +0 -98
  151. package/test/pseudo/deprecated.ts +0 -98
  152. package/test/pseudo/dev.ts +0 -61
  153. package/test/pseudo/diff.ts +0 -417
  154. package/test/pseudo/dist.ts +0 -215
  155. package/test/pseudo/dynamic.ts +0 -98
  156. package/test/pseudo/empty.ts +0 -108
  157. package/test/pseudo/entropic.ts +0 -101
  158. package/test/pseudo/env.ts +0 -98
  159. package/test/pseudo/eval.ts +0 -98
  160. package/test/pseudo/fs.ts +0 -98
  161. package/test/pseudo/helpers.ts +0 -370
  162. package/test/pseudo/host-context.ts +0 -276
  163. package/test/pseudo/hostname.ts +0 -314
  164. package/test/pseudo/license.ts +0 -265
  165. package/test/pseudo/link.ts +0 -94
  166. package/test/pseudo/malware.ts +0 -184
  167. package/test/pseudo/minified.ts +0 -98
  168. package/test/pseudo/missing.ts +0 -111
  169. package/test/pseudo/native.ts +0 -98
  170. package/test/pseudo/network.ts +0 -98
  171. package/test/pseudo/obfuscated.ts +0 -98
  172. package/test/pseudo/optional.ts +0 -73
  173. package/test/pseudo/outdated.ts +0 -461
  174. package/test/pseudo/overridden.ts +0 -317
  175. package/test/pseudo/path.ts +0 -680
  176. package/test/pseudo/peer.ts +0 -101
  177. package/test/pseudo/prerelease.ts +0 -279
  178. package/test/pseudo/private.ts +0 -108
  179. package/test/pseudo/prod.ts +0 -61
  180. package/test/pseudo/published.ts +0 -557
  181. package/test/pseudo/registry.ts +0 -122
  182. package/test/pseudo/root.ts +0 -66
  183. package/test/pseudo/scanned.ts +0 -144
  184. package/test/pseudo/score.ts +0 -591
  185. package/test/pseudo/scripts.ts +0 -324
  186. package/test/pseudo/semver.ts +0 -822
  187. package/test/pseudo/severity.ts +0 -342
  188. package/test/pseudo/shell.ts +0 -98
  189. package/test/pseudo/shrinkwrap.ts +0 -98
  190. package/test/pseudo/skill.ts +0 -189
  191. package/test/pseudo/skills.ts +0 -90
  192. package/test/pseudo/spec.ts +0 -525
  193. package/test/pseudo/squat.ts +0 -565
  194. package/test/pseudo/suspicious.ts +0 -98
  195. package/test/pseudo/tracker.ts +0 -98
  196. package/test/pseudo/trivial.ts +0 -98
  197. package/test/pseudo/type.ts +0 -105
  198. package/test/pseudo/undesirable.ts +0 -98
  199. package/test/pseudo/unknown.ts +0 -98
  200. package/test/pseudo/unmaintained.ts +0 -98
  201. package/test/pseudo/unpopular.ts +0 -98
  202. package/test/pseudo/unstable.ts +0 -98
  203. package/test/pseudo/vuln.ts +0 -625
  204. package/test/pseudo/vulnerable.ts +0 -137
  205. package/test/pseudo/workspace.ts +0 -111
  206. package/test/pseudo.ts +0 -584
  207. package/tsconfig.json +0 -3
  208. package/tsconfig.publish.json +0 -19
  209. package/tsconfig.publish.tsbuildinfo +0 -1
  210. package/typedoc.mjs +0 -2
@@ -1,417 +0,0 @@
1
- import t from 'tap'
2
- import { diff, packageHasChanges } from '../../src/pseudo/diff.ts'
3
- import { pseudo } from '../../src/pseudo.ts'
4
- import { walk } from '../../src/index.ts'
5
- import {
6
- getPathBasedGraph,
7
- getSimpleGraph,
8
- } from '../fixtures/graph.ts'
9
- import type { ParserState } from '../../src/types.ts'
10
- import type { GraphLike, NodeLike } from '@vltpkg/types'
11
- import { parse } from '@vltpkg/dss-parser'
12
-
13
- const getState = (
14
- query: string,
15
- graph: GraphLike = getPathBasedGraph(),
16
- changedFiles?: Set<string>,
17
- ) => {
18
- const ast = parse(query)
19
- const current = ast.first.first
20
- const state: ParserState = {
21
- comment: '',
22
- current,
23
- diffFiles: changedFiles ? () => changedFiles : undefined,
24
- initial: {
25
- edges: new Set(graph.edges.values()),
26
- nodes: new Set(graph.nodes.values()),
27
- },
28
- partial: {
29
- edges: new Set(graph.edges.values()),
30
- nodes: new Set(graph.nodes.values()),
31
- },
32
- collect: {
33
- edges: new Set(),
34
- nodes: new Set(),
35
- },
36
- cancellable: async () => {},
37
- walk: async i => i,
38
- retries: 0,
39
- securityArchive: undefined,
40
- importers: new Set(graph.importers),
41
- signal: new AbortController().signal,
42
- specificity: { idCounter: 0, commonCounter: 0 },
43
- }
44
- return state
45
- }
46
-
47
- t.test('packageHasChanges', async t => {
48
- t.test(
49
- 'returns true when files match package location',
50
- async t => {
51
- const changedFiles = new Set([
52
- 'packages/a/src/index.ts',
53
- 'packages/b/test/foo.ts',
54
- 'README.md',
55
- ])
56
- t.equal(packageHasChanges(changedFiles, 'packages/a'), true)
57
- t.equal(packageHasChanges(changedFiles, 'packages/b'), true)
58
- },
59
- )
60
-
61
- t.test(
62
- 'returns false when no files match package location',
63
- async t => {
64
- const changedFiles = new Set([
65
- 'packages/a/src/index.ts',
66
- 'README.md',
67
- ])
68
- t.equal(packageHasChanges(changedFiles, 'packages/c'), false)
69
- },
70
- )
71
-
72
- t.test('handles root package location', async t => {
73
- const changedFiles = new Set(['README.md'])
74
- t.equal(packageHasChanges(changedFiles, '.'), true)
75
- t.equal(packageHasChanges(changedFiles, ''), true)
76
- const empty = new Set<string>()
77
- t.equal(packageHasChanges(empty, '.'), false)
78
- t.equal(packageHasChanges(empty, ''), false)
79
- })
80
-
81
- t.test('handles leading ./ in package location', async t => {
82
- const changedFiles = new Set(['packages/a/src/index.ts'])
83
- t.equal(packageHasChanges(changedFiles, './packages/a'), true)
84
- })
85
-
86
- t.test('does not match partial directory names', async t => {
87
- const changedFiles = new Set(['packages/abc/src/index.ts'])
88
- t.equal(
89
- packageHasChanges(changedFiles, 'packages/ab'),
90
- false,
91
- 'should not match partial dir name',
92
- )
93
- })
94
-
95
- t.test('matches exact file as package location', async t => {
96
- const changedFiles = new Set(['packages/a'])
97
- t.equal(packageHasChanges(changedFiles, 'packages/a'), true)
98
- })
99
- })
100
-
101
- t.test(':diff pseudo-selector', async t => {
102
- t.test('filters nodes based on changed files', async t => {
103
- const graph = getPathBasedGraph()
104
- const changedFiles = new Set([
105
- 'packages/a/src/index.ts',
106
- 'packages/b/test/foo.ts',
107
- ])
108
- const state = getState(':diff(main)', graph, changedFiles)
109
-
110
- const res = await diff(state)
111
- const names = [...res.partial.nodes].map(n => n.name).sort()
112
- t.ok(names.includes('a'), 'should include a')
113
- t.ok(names.includes('b'), 'should include b')
114
- })
115
-
116
- t.test(
117
- 'returns no non-root nodes when no files changed',
118
- async t => {
119
- const graph = getPathBasedGraph()
120
- const changedFiles = new Set<string>()
121
- const state = getState(':diff(HEAD~1)', graph, changedFiles)
122
-
123
- const res = await diff(state)
124
- const names = [...res.partial.nodes].map(n => n.name)
125
- t.strictSame(
126
- names.filter(n => n !== 'path-based-project'),
127
- [],
128
- 'should have no non-root nodes when no changes',
129
- )
130
- },
131
- )
132
-
133
- t.test('defaults to HEAD when no argument provided', async t => {
134
- const graph = getPathBasedGraph()
135
- let capturedCommitish = ''
136
- const state = getState(':diff()', graph, new Set<string>())
137
- state.diffFiles = (commitish: string) => {
138
- capturedCommitish = commitish
139
- return new Set<string>()
140
- }
141
- await diff(state)
142
- t.equal(
143
- capturedCommitish,
144
- 'HEAD',
145
- 'should default to HEAD for empty :diff()',
146
- )
147
- })
148
-
149
- t.test('throws on invalid argument', async t => {
150
- const graph = getPathBasedGraph()
151
- const state = getState(':diff([attr])', graph, new Set<string>())
152
- await t.rejects(
153
- async () => diff(state),
154
- {
155
- message: 'Failed to parse :diff selector',
156
- },
157
- 'should throw for unparseable :diff() argument',
158
- )
159
- })
160
-
161
- t.test('throws when diffFiles provider is missing', async t => {
162
- const graph = getSimpleGraph()
163
- // state without diffFiles
164
- const state = getState(':diff(main)', graph)
165
- await t.rejects(
166
- async () => diff(state),
167
- {
168
- message: 'The :diff() selector requires a diffFiles provider',
169
- },
170
- 'should throw when diffFiles not provided',
171
- )
172
- })
173
-
174
- t.test('throws when diffFiles provider throws', async t => {
175
- const graph = getSimpleGraph()
176
- const ast = parse(':diff(main)')
177
- const current = ast.first.first
178
- const state: ParserState = {
179
- comment: '',
180
- current,
181
- diffFiles: () => {
182
- throw new Error('git diff failed')
183
- },
184
- initial: {
185
- edges: new Set(graph.edges.values()),
186
- nodes: new Set(graph.nodes.values()),
187
- },
188
- partial: {
189
- edges: new Set(graph.edges.values()),
190
- nodes: new Set(graph.nodes.values()),
191
- },
192
- collect: {
193
- edges: new Set(),
194
- nodes: new Set(),
195
- },
196
- cancellable: async () => {},
197
- walk: async i => i,
198
- retries: 0,
199
- securityArchive: undefined,
200
- importers: new Set(graph.importers),
201
- signal: new AbortController().signal,
202
- specificity: { idCounter: 0, commonCounter: 0 },
203
- }
204
- t.throws(
205
- () => state.diffFiles?.('main'),
206
- { message: 'git diff failed' },
207
- 'diffFiles provider should propagate errors',
208
- )
209
- })
210
-
211
- t.test(
212
- 'works with path-based graph and matching changes',
213
- async t => {
214
- const graph = getPathBasedGraph()
215
- const changedFiles = new Set([
216
- 'packages/a/src/index.ts',
217
- 'c/lib/util.ts',
218
- ])
219
- const state = getState(':diff(main)', graph, changedFiles)
220
-
221
- const res = await diff(state)
222
- const names = [...res.partial.nodes].map(n => n.name).sort()
223
- t.ok(names.includes('a'), 'should include a (packages/a)')
224
- t.ok(names.includes('c'), 'should include c')
225
- t.notOk(
226
- names.includes('b'),
227
- 'should not include b (packages/b has no changes)',
228
- )
229
- },
230
- )
231
-
232
- t.test('registered as pseudo selector in map', async t => {
233
- // Verify :diff is in the pseudo selector map by
234
- // testing through the pseudo function directly with
235
- // a properly configured state
236
- const graph = getPathBasedGraph()
237
- const changedFiles = new Set(['packages/a/src/index.ts'])
238
- const ast = parse(':diff(main)')
239
- const current = ast.first.first
240
- const state: ParserState = {
241
- comment: '',
242
- current,
243
- diffFiles: () => changedFiles,
244
- initial: {
245
- edges: new Set(graph.edges.values()),
246
- nodes: new Set(graph.nodes.values()),
247
- },
248
- partial: {
249
- edges: new Set(graph.edges.values()),
250
- nodes: new Set(graph.nodes.values()),
251
- },
252
- collect: {
253
- edges: new Set(),
254
- nodes: new Set(),
255
- },
256
- cancellable: async () => {},
257
- walk: async i => i,
258
- retries: 0,
259
- securityArchive: undefined,
260
- importers: new Set(graph.importers),
261
- signal: new AbortController().signal,
262
- specificity: { idCounter: 0, commonCounter: 0 },
263
- }
264
- const res = await pseudo(state)
265
- t.ok(
266
- [...res.partial.nodes].some(n => n.name === 'a'),
267
- 'should return results when called through pseudo',
268
- )
269
- t.equal(
270
- res.specificity.commonCounter,
271
- 1,
272
- 'should increment specificity commonCounter',
273
- )
274
- })
275
-
276
- t.test('passes commitish to diffFiles provider', async t => {
277
- const graph = getPathBasedGraph()
278
- let capturedCommitish = ''
279
- const ast = parse(':diff(HEAD~3)')
280
- const current = ast.first.first
281
- const state: ParserState = {
282
- comment: '',
283
- current,
284
- diffFiles: (commitish: string) => {
285
- capturedCommitish = commitish
286
- return new Set<string>()
287
- },
288
- initial: {
289
- edges: new Set(graph.edges.values()),
290
- nodes: new Set(graph.nodes.values()),
291
- },
292
- partial: {
293
- edges: new Set(graph.edges.values()),
294
- nodes: new Set(graph.nodes.values()),
295
- },
296
- collect: {
297
- edges: new Set(),
298
- nodes: new Set(),
299
- },
300
- cancellable: async () => {},
301
- walk: async i => i,
302
- retries: 0,
303
- securityArchive: undefined,
304
- importers: new Set(graph.importers),
305
- signal: new AbortController().signal,
306
- specificity: { idCounter: 0, commonCounter: 0 },
307
- }
308
- await diff(state)
309
- t.equal(
310
- capturedCommitish,
311
- 'HEAD~3',
312
- 'should pass commitish to provider',
313
- )
314
- })
315
- })
316
-
317
- t.test(':diff inside nested selectors', async t => {
318
- const makeNestedState = (
319
- query: string,
320
- graph: GraphLike,
321
- changedFiles: Set<string>,
322
- ): ParserState => {
323
- const ast = parse(query)
324
- return {
325
- comment: '',
326
- current: ast,
327
- diffFiles: () => changedFiles,
328
- initial: {
329
- edges: new Set(graph.edges.values()),
330
- nodes: new Set(graph.nodes.values()),
331
- },
332
- partial: {
333
- edges: new Set(graph.edges.values()),
334
- nodes: new Set(graph.nodes.values()),
335
- },
336
- collect: {
337
- edges: new Set(),
338
- nodes: new Set<NodeLike>(),
339
- },
340
- cancellable: async () => {},
341
- walk,
342
- retries: 0,
343
- securityArchive: undefined,
344
- importers: new Set(graph.importers),
345
- signal: new AbortController().signal,
346
- specificity: { idCounter: 0, commonCounter: 0 },
347
- }
348
- }
349
-
350
- t.test(
351
- ':has(> :diff) propagates diffFiles to nested state',
352
- async t => {
353
- const graph = getPathBasedGraph()
354
- const changedFiles = new Set(['packages/a/src/index.ts'])
355
- const state = makeNestedState(
356
- ':has(> :diff(main))',
357
- graph,
358
- changedFiles,
359
- )
360
- const res = await walk(state)
361
- const names = [...res.collect.nodes].map(n => n.name).sort()
362
- t.ok(
363
- names.includes('path-based-project'),
364
- 'root should match because it has child "a" that changed',
365
- )
366
- },
367
- )
368
-
369
- t.test(
370
- ':not(:diff) propagates diffFiles to nested state',
371
- async t => {
372
- const graph = getPathBasedGraph()
373
- const changedFiles = new Set(['packages/a/src/index.ts'])
374
- const state = makeNestedState(
375
- ':not(:diff(main))',
376
- graph,
377
- changedFiles,
378
- )
379
- const res = await walk(state)
380
- const names = [...res.collect.nodes].map(n => n.name).sort()
381
- t.notOk(
382
- names.includes('a'),
383
- 'a should be excluded by :not(:diff) since it changed',
384
- )
385
- t.ok(
386
- names.includes('x'),
387
- 'x should remain since its files did not change',
388
- )
389
- },
390
- )
391
-
392
- t.test(
393
- ':is(:diff) propagates diffFiles to nested state',
394
- async t => {
395
- const graph = getPathBasedGraph()
396
- const changedFiles = new Set([
397
- 'packages/a/src/index.ts',
398
- 'packages/b/test/foo.ts',
399
- ])
400
- const state = makeNestedState(
401
- ':is(:diff(main))',
402
- graph,
403
- changedFiles,
404
- )
405
- const res = await walk(state)
406
- const names = [...res.collect.nodes].map(n => n.name).sort()
407
- t.ok(
408
- names.includes('a'),
409
- 'a should match :is(:diff) since it changed',
410
- )
411
- t.ok(
412
- names.includes('b'),
413
- 'b should match :is(:diff) since it changed',
414
- )
415
- },
416
- )
417
- })
@@ -1,215 +0,0 @@
1
- import t from 'tap'
2
- import { joinDepIDTuple } from '@vltpkg/dep-id'
3
- import { parse, asPostcssNodeWithChildren } from '@vltpkg/dss-parser'
4
- import {
5
- dist,
6
- queueNode,
7
- retrieveDistTags,
8
- } from '../../src/pseudo/dist.ts'
9
- import { getSimpleGraph } from '../fixtures/graph.ts'
10
- import type { NodeLike } from '@vltpkg/types'
11
- import type { ParserState } from '../../src/types.ts'
12
-
13
- global.fetch = (async (url: string) => {
14
- if (url === 'https://registry.npmjs.org/c') {
15
- return {
16
- status: 404,
17
- ok: false,
18
- }
19
- } else if (url === 'https://registry.npmjs.org/d') {
20
- return {
21
- ok: false,
22
- }
23
- } else if (url === 'https://registry.npmjs.org/e') {
24
- throw new Error('ERR')
25
- }
26
- return {
27
- ok: true,
28
- json: async () => {
29
- switch (url) {
30
- case 'https://registry.npmjs.org/a': {
31
- return {
32
- 'dist-tags': {
33
- latest: '1.0.0',
34
- nightly: '2.0.0',
35
- },
36
- }
37
- }
38
- case 'https://registry.npmjs.org/b': {
39
- return {
40
- 'dist-tags': {
41
- latest: '2.0.0',
42
- beta: '1.0.0',
43
- },
44
- }
45
- }
46
- case 'https://registry.npmjs.org/f': {
47
- return {
48
- 'dist-tags': {
49
- latest: '1.0.0',
50
- },
51
- }
52
- }
53
- }
54
- },
55
- }
56
- }) as unknown as typeof global.fetch
57
-
58
- const getState = (query: string, graph = getSimpleGraph()) => {
59
- const ast = parse(query)
60
- const current = asPostcssNodeWithChildren(ast.first.first)
61
- const state: ParserState = {
62
- comment: '',
63
- current,
64
- initial: {
65
- edges: new Set(graph.edges.values()),
66
- nodes: new Set(graph.nodes.values()),
67
- },
68
- partial: {
69
- edges: new Set(graph.edges.values()),
70
- nodes: new Set(graph.nodes.values()),
71
- },
72
- collect: {
73
- edges: new Set(),
74
- nodes: new Set(),
75
- },
76
- cancellable: async () => {},
77
- walk: async i => i,
78
- retries: 0,
79
- securityArchive: undefined,
80
- importers: new Set(graph.importers),
81
- signal: new AbortController().signal,
82
- specificity: { idCounter: 0, commonCounter: 0 },
83
- }
84
- return state
85
- }
86
-
87
- t.test(':dist pseudo-selector', async t => {
88
- t.capture(console, 'warn')
89
-
90
- await t.test('matches nodes at the latest dist-tag', async t => {
91
- const res = await dist(getState(':dist(latest)'))
92
- const names = [...res.partial.nodes].map(n => n.name).sort()
93
- t.strictSame(
94
- names,
95
- ['a', 'f'],
96
- 'should match only nodes whose version equals the latest dist-tag',
97
- )
98
- t.matchSnapshot({
99
- nodes: names,
100
- edges: [...res.partial.edges].map(e => e.name).sort(),
101
- })
102
- })
103
-
104
- await t.test('matches nodes at the beta dist-tag', async t => {
105
- const res = await dist(getState(':dist(beta)'))
106
- const names = [...res.partial.nodes].map(n => n.name).sort()
107
- t.strictSame(
108
- names,
109
- ['b'],
110
- 'should match only nodes whose version equals the beta dist-tag',
111
- )
112
- t.matchSnapshot({
113
- nodes: names,
114
- edges: [...res.partial.edges].map(e => e.name).sort(),
115
- })
116
- })
117
-
118
- await t.test('matches nodes at the nightly dist-tag', async t => {
119
- const res = await dist(getState(':dist(nightly)'))
120
- const names = [...res.partial.nodes].map(n => n.name).sort()
121
- t.strictSame(
122
- names,
123
- [],
124
- 'should match nothing since no installed version is 2.0.0',
125
- )
126
- })
127
-
128
- await t.test('supports quoted tag name', async t => {
129
- const res = await dist(getState(':dist("latest")'))
130
- const names = [...res.partial.nodes].map(n => n.name).sort()
131
- t.strictSame(
132
- names,
133
- ['a', 'f'],
134
- 'should work with quoted tag names',
135
- )
136
- })
137
-
138
- await t.test('unknown dist-tag returns no matches', async t => {
139
- const res = await dist(getState(':dist(nonexistent)'))
140
- const names = [...res.partial.nodes].map(n => n.name).sort()
141
- t.strictSame(
142
- names,
143
- [],
144
- 'should return no matches for an unknown dist-tag',
145
- )
146
- })
147
-
148
- await t.test('handles empty partial state', async t => {
149
- const state = getState(':dist(latest)')
150
- state.partial.nodes.clear()
151
- state.partial.edges.clear()
152
-
153
- const res = await dist(state)
154
- t.strictSame(
155
- [...res.partial.nodes].map(n => n.name),
156
- [],
157
- 'should return empty results from an empty partial state',
158
- )
159
- })
160
-
161
- await t.test('gracefully handles fetch errors', async t => {
162
- const res = await dist(getState(':dist(latest)'))
163
- const names = [...res.partial.nodes].map(n => n.name).sort()
164
- t.ok(
165
- !names.includes('d') && !names.includes('e'),
166
- 'nodes with fetch errors should not be in results',
167
- )
168
- })
169
- })
170
-
171
- t.test('retrieveDistTags', async t => {
172
- const missingName = {
173
- id: joinDepIDTuple(['registry', '', 'a@1.0.0']),
174
- } as NodeLike
175
- t.strictSame(
176
- await retrieveDistTags(missingName),
177
- {},
178
- 'should return empty object if missing essential info',
179
- )
180
-
181
- await t.test('no response from registry', async t => {
182
- const node = {
183
- name: 'd',
184
- id: joinDepIDTuple(['registry', '', 'd@1.0.0']),
185
- } as NodeLike
186
- await t.rejects(
187
- retrieveDistTags(node),
188
- /Failed to fetch packument/,
189
- 'should throw an internal error so that it may be retried',
190
- )
191
- })
192
-
193
- await t.test('fetch error', async t => {
194
- const node = {
195
- name: 'e',
196
- id: joinDepIDTuple(['registry', '', 'e@1.0.0']),
197
- } as NodeLike
198
- await t.rejects(
199
- retrieveDistTags(node),
200
- /ERR/,
201
- 'should throw the original error that will be retried',
202
- )
203
- })
204
- })
205
-
206
- t.test('queueNode', async t => {
207
- const missingName = {
208
- id: joinDepIDTuple(['registry', '', 'a@1.0.0']),
209
- } as NodeLike
210
- t.strictSame(
211
- await queueNode(getState(':dist(latest)'), missingName, 'latest'),
212
- missingName,
213
- 'should return node for removal if missing essential info',
214
- )
215
- })