@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
package/test/attribute.ts DELETED
@@ -1,273 +0,0 @@
1
- import { joinDepIDTuple } from '@vltpkg/dep-id'
2
- import type { EdgeLike, NodeLike } from '@vltpkg/types'
3
- import type { Attribute } from 'postcss-selector-parser'
4
- import t from 'tap'
5
- import {
6
- attribute,
7
- filterAttributes,
8
- getManifestPropertyValues,
9
- } from '../src/attribute.ts'
10
- import {
11
- getMissingNodeGraph,
12
- getSimpleGraph,
13
- } from './fixtures/graph.ts'
14
- import {
15
- copyGraphSelectionState,
16
- getGraphSelectionState,
17
- selectorFixture,
18
- } from './fixtures/selector.ts'
19
- import type { TestCase } from './fixtures/types.ts'
20
- import type {
21
- GraphSelectionState,
22
- ParserState,
23
- } from '../src/types.ts'
24
-
25
- type ManifestLike = Record<string, any>
26
-
27
- const testAttr = selectorFixture(attribute)
28
-
29
- t.test('attribute', async t => {
30
- const simpleGraph = getSimpleGraph()
31
- const all: GraphSelectionState = {
32
- edges: new Set<EdgeLike>(simpleGraph.edges),
33
- nodes: new Set<NodeLike>(simpleGraph.nodes.values()),
34
- }
35
- const b = getGraphSelectionState(simpleGraph, 'b')
36
- const empty: GraphSelectionState = {
37
- edges: new Set(),
38
- nodes: new Set(),
39
- }
40
-
41
- const queryToExpected = new Set<TestCase>([
42
- [
43
- '[version="1.0.0"]',
44
- all,
45
- ['my-project', 'a', 'c', 'd', 'e', 'f', '@x/y'],
46
- ], // attribute matches all
47
- [
48
- '[name]',
49
- all,
50
- ['my-project', 'a', 'b', 'c', 'd', 'e', 'f', '@x/y'],
51
- ], // attribute has any content
52
- ['[nonexistingattribute]', all, []], // non existing attribute
53
- ['[name="@x/y"]', all, ['@x/y']], // attribute matches scoped quoted
54
- ['[name^=m]', all, ['my-project']], // attribute starts with value
55
- ['[name^="m"]', all, ['my-project']], // attribute starts with value
56
- ['[name^=@x]', all, ['@x/y']], // attribute starts with scope
57
- ['[name^="@x"]', all, ['@x/y']], // attribute starts with scope
58
- ['[name$=project]', all, ['my-project']], // attribute ends with value
59
- ['[name$="project"]', all, ['my-project']], // attribute ends with value
60
- ['[name~=project]', all, ['my-project']], // attribute contains word
61
- ['[name~="project"]', all, ['my-project']], // attribute contains word
62
- ['[name~=notfound]', all, []], // attribute contains not found
63
- ['[name~="notfound"]', all, []], // attribute contains not found
64
- ['[name*=pro]', all, ['my-project']], // attribute contains string
65
- ['[name*="pro"]', all, ['my-project']], // attribute contains string
66
- ['[name|=my]', all, ['my-project']], // attribute starts with hyphened string
67
- ['[name|="my"]', all, ['my-project']], // attribute starts with hyphened string
68
- ['[name|="a"]', all, ['a']], // also matches on exact match
69
- ['[name="A"]', all, []], // case sensitive by default
70
- ['[name="A" i]', all, ['a']], // case insensitive flag
71
- ['[name="A" s]', all, []], // case insensitive flag
72
- ['[name="a"]', empty, []], // no matches if starting from empty partial
73
- ['[name="a"]', b, []], // no matches if node can't be find in partial
74
- ['[name="b"]', b, ['b']], // matches single node found
75
- ['[keywords=something]', all, ['c']], // matches item in array prop
76
- ['[keywords=missing]', all, []], // can not match missing item in array
77
- ])
78
- const initial = {
79
- edges: new Set(all.edges),
80
- nodes: new Set(all.nodes),
81
- }
82
- for (const [query, partial, expected] of queryToExpected) {
83
- const res = await testAttr(
84
- query,
85
- initial,
86
- copyGraphSelectionState(partial),
87
- )
88
- t.strictSame(
89
- res.nodes.map(i => i.name),
90
- expected,
91
- `query > "${query}"`,
92
- )
93
- t.matchSnapshot(
94
- {
95
- edges: res.edges.map(i => i.name).sort(),
96
- nodes: res.nodes.map(i => i.name).sort(),
97
- },
98
- `query > "${query}"`,
99
- )
100
- }
101
-
102
- await t.test('missing node', async t => {
103
- const missingNodeGraph = getMissingNodeGraph()
104
- const all: GraphSelectionState = {
105
- edges: new Set<EdgeLike>(missingNodeGraph.edges),
106
- nodes: new Set<NodeLike>(missingNodeGraph.nodes.values()),
107
- }
108
- const queryToExpected = new Set<TestCase>([
109
- ['[name]', all, ['node-missing-project']], // root node has a name
110
- ['[name=a]', all, []], // can't match missing node
111
- ])
112
- const initial = copyGraphSelectionState(all)
113
- for (const [query, partial, expected] of queryToExpected) {
114
- const res = await testAttr(
115
- query,
116
- initial,
117
- copyGraphSelectionState(partial),
118
- )
119
- t.strictSame(
120
- res.nodes.map(i => i.name),
121
- expected,
122
- `query > "${query}"`,
123
- )
124
- t.matchSnapshot(
125
- {
126
- edges: res.edges.map(i => i.name).sort(),
127
- nodes: res.nodes.map(i => i.name).sort(),
128
- },
129
- `query > "${query}"`,
130
- )
131
- }
132
- })
133
- })
134
-
135
- t.test('bad selector type', async t => {
136
- await t.rejects(
137
- testAttr(':dev'),
138
- /Mismatching query node/,
139
- 'should throw an error',
140
- )
141
- })
142
-
143
- t.test('bad operator', async t => {
144
- await t.rejects(
145
- testAttr('[name==foo]'),
146
- {
147
- message: 'Unsupported attribute operator: =',
148
- cause: {
149
- code: 'EQUERY',
150
- found: '[name==foo]',
151
- validOptions: ['=', '^=', '$=', '~=', '*=', '|='],
152
- },
153
- },
154
- 'should throw an error',
155
- )
156
- })
157
-
158
- t.test('bad operator [loose mode]', async t => {
159
- await t.resolves(
160
- testAttr('[name==foo]', undefined, undefined, true),
161
- 'should resolve with no error',
162
- )
163
- })
164
-
165
- t.test(
166
- 'unquotted scoped names are not supported by the parser',
167
- async t => {
168
- await t.rejects(
169
- testAttr('[name=@x/y]'),
170
- /Unexpected "\/" found./,
171
- 'should throw an error',
172
- )
173
- },
174
- )
175
-
176
- t.test('getManifestPropertyValues', async t => {
177
- const simpleGraph = getSimpleGraph()
178
- const b = simpleGraph.nodes.get(
179
- joinDepIDTuple(['registry', '', 'b@1.0.0']),
180
- )!
181
-
182
- t.strictSame(
183
- getManifestPropertyValues(
184
- b,
185
- ['scripts', 'postinstall'],
186
- 'postinstall',
187
- ),
188
- ['postinstall'],
189
- 'should return the postinstall script value',
190
- )
191
-
192
- t.strictSame(
193
- getManifestPropertyValues(b, ['contributors'], 'contributors'),
194
- ['[object Object]'],
195
- 'should return a stringified object value',
196
- )
197
-
198
- t.strictSame(
199
- getManifestPropertyValues(b, ['contributors', 'name'], 'name'),
200
- ['Ruy Adorno'],
201
- 'should return the value from a array-nested object',
202
- )
203
-
204
- b.manifest = { foo: 1 } as ManifestLike
205
- t.strictSame(
206
- getManifestPropertyValues(b, ['foo'], 'foo'),
207
- ['1'],
208
- 'should return values as strings',
209
- )
210
-
211
- b.manifest = { keywords: [undefined, 'foo'] } as ManifestLike
212
- t.strictSame(
213
- getManifestPropertyValues(b, ['keywords'], 'keywords'),
214
- ['', 'foo'],
215
- 'should turn falsy values into empty strings',
216
- )
217
-
218
- b.manifest = 'bad manifest' as unknown as ManifestLike
219
- t.strictSame(
220
- getManifestPropertyValues(b, ['name'], 'name'),
221
- undefined,
222
- 'should not return results from a bad manifest',
223
- )
224
-
225
- delete b.manifest
226
- t.strictSame(
227
- getManifestPropertyValues(b, ['name'], 'name'),
228
- undefined,
229
- 'should not return results from a missing manifest',
230
- )
231
- })
232
-
233
- t.test('filterAttributes', async t => {
234
- const simpleGraph = getSimpleGraph()
235
- const all: GraphSelectionState = {
236
- edges: new Set<EdgeLike>(simpleGraph.edges),
237
- nodes: new Set<NodeLike>(simpleGraph.nodes.values()),
238
- }
239
- const state = {
240
- cancellable: async () => {},
241
- collect: {
242
- edges: new Set<EdgeLike>(),
243
- nodes: new Set<NodeLike>(),
244
- },
245
- comment: '',
246
- current: { type: 'attribute', value: 'postinstall' } as Attribute,
247
- initial: copyGraphSelectionState(all),
248
- partial: all,
249
- loose: false,
250
- importers: simpleGraph.importers,
251
- hostContexts: new Map(),
252
- walk: async (state: ParserState) => state,
253
- retries: 0,
254
- securityArchive: undefined,
255
- signal: new AbortController().signal,
256
- specificity: { idCounter: 0, commonCounter: 0 },
257
- }
258
- filterAttributes(
259
- state,
260
- (attr: string) => !!attr,
261
- 'postinstall',
262
- 'scripts',
263
- false,
264
- ['scripts', 'postinstall'],
265
- )
266
- t.matchSnapshot(
267
- {
268
- edges: [...state.partial.edges].map(i => i.name).sort(),
269
- nodes: [...state.partial.nodes].map(i => i.name).sort(),
270
- },
271
- 'should have filtered out nodes with postinstall script only',
272
- )
273
- })
@@ -1,175 +0,0 @@
1
- import t from 'tap'
2
- import { combinator } from '../src/combinator.ts'
3
- import { walk } from '../src/index.ts'
4
- import { getCycleGraph, getSimpleGraph } from './fixtures/graph.ts'
5
- import {
6
- copyGraphSelectionState,
7
- getGraphSelectionState,
8
- selectorFixture,
9
- } from './fixtures/selector.ts'
10
- import type { TestCase } from './fixtures/types.ts'
11
- import type { EdgeLike, NodeLike } from '@vltpkg/types'
12
- import type { GraphSelectionState } from '../src/types.ts'
13
-
14
- const testCombinator = selectorFixture(combinator)
15
-
16
- t.test('combinator', async t => {
17
- const simpleGraph = getSimpleGraph()
18
- const all: GraphSelectionState = {
19
- edges: new Set<EdgeLike>(simpleGraph.edges),
20
- nodes: new Set<NodeLike>(simpleGraph.nodes.values()),
21
- }
22
- const root = {
23
- edges: new Set<EdgeLike>(),
24
- nodes: new Set<NodeLike>([simpleGraph.mainImporter]),
25
- }
26
- const b = getGraphSelectionState(simpleGraph, 'b')
27
- const d = getGraphSelectionState(simpleGraph, 'd')
28
- const bd: GraphSelectionState = {
29
- edges: new Set<EdgeLike>([...b.edges, ...d.edges]),
30
- nodes: new Set<NodeLike>([...b.nodes, ...d.nodes]),
31
- }
32
- const e = getGraphSelectionState(simpleGraph, 'e')
33
- const f = getGraphSelectionState(simpleGraph, 'f')
34
- const empty: GraphSelectionState = {
35
- edges: new Set(),
36
- nodes: new Set(),
37
- }
38
- const queryToExpected = new Set<TestCase>([
39
- // child combinator
40
- ['>', all, ['a', 'b', 'e', '@x/y', 'c', 'd', 'f']], // direct children of all nodes
41
- ['>', root, ['a', 'b', 'e', '@x/y']], // from root
42
- ['>', d, ['e', 'f']], // from transitive dep
43
- ['>', bd, ['c', 'd', 'e', 'f']], // from mutiple deps
44
- ['>', e, []], // from node with no deps
45
- ['>', empty, []], // from empty nodes
46
- // subsequent sibling combinator
47
- ['~', all, ['b', 'e', '@x/y', 'a', 'd', 'c', 'f']], // siblings of all nodes
48
- ['~', f, ['e']], // leaf node with a sibling
49
- ['~', d, ['c']], // transitive node
50
- ['~', e, ['a', 'b', '@x/y', 'f']], // node with siblings at multiple locations
51
- ['~', root, []], // root has no siblings
52
- ['~', empty, []], // sibling of empty nodes
53
- // descendent combinator
54
- [' ', root, ['a', 'b', 'e', '@x/y', 'c', 'd', 'f']], // from root
55
- [' ', f, []], // leaf node
56
- [' ', empty, []], // empty list of nodes
57
- [' ', d, ['e', 'f']], // transitive node
58
- [' ', b, ['c', 'd', 'e', 'f']], // direct dep
59
- ])
60
- const initial = copyGraphSelectionState(all)
61
- for (const [query, partial, expected] of queryToExpected) {
62
- const res = await testCombinator(
63
- { value: query, type: 'combinator' },
64
- initial,
65
- copyGraphSelectionState(partial),
66
- )
67
- t.strictSame(
68
- res.nodes.map(i => i.name),
69
- expected,
70
- `query > "${query}"`,
71
- )
72
- t.matchSnapshot(
73
- {
74
- edges: res.edges.map(i => i.name).sort(),
75
- nodes: res.nodes.map(i => i.name).sort(),
76
- },
77
- `query > "${query}"`,
78
- )
79
- }
80
-
81
- await t.test('cycle', async t => {
82
- const cycleGraph = getCycleGraph()
83
- const all: GraphSelectionState = {
84
- edges: new Set<EdgeLike>(cycleGraph.edges),
85
- nodes: new Set<NodeLike>(cycleGraph.nodes.values()),
86
- }
87
- const root = {
88
- edges: new Set<EdgeLike>(),
89
- nodes: new Set<NodeLike>([cycleGraph.mainImporter]),
90
- }
91
- const a = getGraphSelectionState(cycleGraph, 'a')
92
- const b = getGraphSelectionState(cycleGraph, 'b')
93
- const queryToExpected = new Set<TestCase>([
94
- ['>', all, ['a', 'b']], // direct children of all nodes
95
- ['>', a, ['b']], // direct children of a
96
- ['>', b, ['a']], // direct children of b
97
- [' ', root, ['a', 'b']], // descendents of :root
98
- [' ', a, ['b', 'a']], // descendents of a
99
- [' ', b, ['a', 'b']], // descendents of b
100
- ['~', root, []], // siblings of :root
101
- ['~', a, []], // siblings of a
102
- ['~', b, []], // siblings of b
103
- ])
104
- const initial = copyGraphSelectionState(all)
105
- for (const [query, partial, expected] of queryToExpected) {
106
- const result = await testCombinator(
107
- { value: query, type: 'combinator' },
108
- initial,
109
- copyGraphSelectionState(partial),
110
- )
111
- t.strictSame(
112
- result.nodes.map(i => i.name),
113
- expected,
114
- `query > "${query}"`,
115
- )
116
- t.matchSnapshot(
117
- {
118
- edges: result.edges.map(i => i.name).sort(),
119
- nodes: result.nodes.map(i => i.name).sort(),
120
- },
121
- `query > "${query}"`,
122
- )
123
- }
124
- })
125
-
126
- // space between tags are not descendent combinators
127
- await t.test('ignore spaces between tags', async t => {
128
- const test = selectorFixture(walk)
129
- const result = await test(
130
- '* { * }',
131
- all,
132
- copyGraphSelectionState(all),
133
- )
134
- t.strictSame(
135
- result.nodes.map(i => i.name),
136
- [...all.nodes].map(i => i.name),
137
- 'should not treat spaces between tags as descendent combinators',
138
- )
139
- })
140
- })
141
-
142
- t.test('bad selector type', async t => {
143
- await t.rejects(
144
- testCombinator(':dev'),
145
- /Mismatching query node/,
146
- 'should throw an error',
147
- )
148
- })
149
-
150
- t.test('usnupported combinator', async t => {
151
- await t.rejects(
152
- testCombinator({ value: '+', type: 'combinator' }),
153
- {
154
- message: 'Unsupported combinator: +',
155
- cause: {
156
- code: 'EQUERY',
157
- found: '+',
158
- validOptions: ['>', '~', ' '],
159
- },
160
- },
161
- 'should throw an error',
162
- )
163
- })
164
-
165
- t.test('usnupported combinator [loose mode]', async t => {
166
- await t.resolves(
167
- testCombinator(
168
- { value: '+', type: 'combinator' },
169
- undefined,
170
- undefined,
171
- true,
172
- ),
173
- 'should resolve with no error',
174
- )
175
- })
package/test/error.ts DELETED
@@ -1,60 +0,0 @@
1
- import t from 'tap'
2
- import { parse } from '@vltpkg/dss-parser'
3
- import type { PostcssNode } from '@vltpkg/dss-parser'
4
- import { didYouMean, queryError, selectorText } from '../src/error.ts'
5
-
6
- const first = (query: string): PostcssNode => {
7
- const node = parse(query, { loose: true }).nodes[0]?.nodes[0]
8
- if (!node) throw new Error(`no node parsed for ${query}`)
9
- return node
10
- }
11
-
12
- t.test('selectorText', async t => {
13
- t.equal(selectorText(first('.dev')), '.dev', 'unescapes')
14
- t.equal(selectorText(first('[name%=x]')), '[name%=x]', 'attribute')
15
- t.equal(selectorText(first('"foo"')), '"foo"', 'string')
16
- t.equal(selectorText(first(':root > *')), ':root', 'pseudo')
17
- t.equal(
18
- selectorText({ type: 'combinator', value: '+' } as PostcssNode),
19
- '+',
20
- 'falls back to the value of an unparsed node',
21
- )
22
- t.equal(
23
- selectorText({ type: 'combinator' } as PostcssNode),
24
- 'combinator',
25
- 'falls back to the type when there is no value',
26
- )
27
- })
28
-
29
- t.test('queryError', async t => {
30
- const er = queryError('Unsupported selector', first('.dev'), {
31
- wanted: ':dev',
32
- })
33
- t.match(er, {
34
- message: 'Unsupported selector',
35
- cause: { code: 'EQUERY', found: '.dev', wanted: ':dev' },
36
- })
37
- t.equal(
38
- typeof (er.cause as { found: unknown }).found,
39
- 'string',
40
- 'never carries the circular parsed node',
41
- )
42
- })
43
-
44
- t.test('didYouMean', async t => {
45
- const names = ['dev', 'diff', 'dist', 'prod']
46
- t.strictSame(didYouMean('difff', names), ['diff'])
47
- t.strictSame(didYouMean('dif', names), ['diff', 'dev', 'dist'])
48
- t.strictSame(didYouMean('nope', names), [], 'nothing close enough')
49
- t.strictSame(
50
- didYouMean('d', names, 0),
51
- [],
52
- 'a zero budget only matches exactly',
53
- )
54
- t.strictSame(didYouMean('dev', names, 0), ['dev'])
55
- t.strictSame(
56
- didYouMean('deviation', names),
57
- [],
58
- 'length gap alone rules a candidate out',
59
- )
60
- })