@vltpkg/query 0.0.0-3 → 0.0.0-31

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 (247) hide show
  1. package/README.md +39 -82
  2. package/dist/esm/attribute.d.ts +1 -1
  3. package/dist/esm/attribute.d.ts.map +1 -1
  4. package/dist/esm/attribute.js +8 -13
  5. package/dist/esm/attribute.js.map +1 -1
  6. package/dist/esm/combinator.d.ts.map +1 -1
  7. package/dist/esm/combinator.js +5 -2
  8. package/dist/esm/combinator.js.map +1 -1
  9. package/dist/esm/id.d.ts.map +1 -1
  10. package/dist/esm/id.js +23 -7
  11. package/dist/esm/id.js.map +1 -1
  12. package/dist/esm/index.d.ts +40 -7
  13. package/dist/esm/index.d.ts.map +1 -1
  14. package/dist/esm/index.js +302 -23
  15. package/dist/esm/index.js.map +1 -1
  16. package/dist/esm/parser.d.ts +15 -0
  17. package/dist/esm/parser.d.ts.map +1 -0
  18. package/dist/esm/parser.js +93 -0
  19. package/dist/esm/parser.js.map +1 -0
  20. package/dist/esm/pseudo/abandoned.d.ts +7 -0
  21. package/dist/esm/pseudo/abandoned.d.ts.map +1 -0
  22. package/dist/esm/pseudo/abandoned.js +6 -0
  23. package/dist/esm/pseudo/abandoned.js.map +1 -0
  24. package/dist/esm/pseudo/attr.d.ts +2 -1
  25. package/dist/esm/pseudo/attr.d.ts.map +1 -1
  26. package/dist/esm/pseudo/attr.js +10 -2
  27. package/dist/esm/pseudo/attr.js.map +1 -1
  28. package/dist/esm/pseudo/built.d.ts +8 -0
  29. package/dist/esm/pseudo/built.d.ts.map +1 -0
  30. package/dist/esm/pseudo/built.js +16 -0
  31. package/dist/esm/pseudo/built.js.map +1 -0
  32. package/dist/esm/pseudo/confused.d.ts +9 -0
  33. package/dist/esm/pseudo/confused.d.ts.map +1 -0
  34. package/dist/esm/pseudo/confused.js +19 -0
  35. package/dist/esm/pseudo/confused.js.map +1 -0
  36. package/dist/esm/pseudo/cve.d.ts +13 -0
  37. package/dist/esm/pseudo/cve.d.ts.map +1 -0
  38. package/dist/esm/pseudo/cve.js +44 -0
  39. package/dist/esm/pseudo/cve.js.map +1 -0
  40. package/dist/esm/pseudo/cwe.d.ts +13 -0
  41. package/dist/esm/pseudo/cwe.d.ts.map +1 -0
  42. package/dist/esm/pseudo/cwe.js +43 -0
  43. package/dist/esm/pseudo/cwe.js.map +1 -0
  44. package/dist/esm/pseudo/debug.d.ts +7 -0
  45. package/dist/esm/pseudo/debug.d.ts.map +1 -0
  46. package/dist/esm/pseudo/debug.js +6 -0
  47. package/dist/esm/pseudo/debug.js.map +1 -0
  48. package/dist/esm/pseudo/deprecated.d.ts +7 -0
  49. package/dist/esm/pseudo/deprecated.d.ts.map +1 -0
  50. package/dist/esm/pseudo/deprecated.js +6 -0
  51. package/dist/esm/pseudo/deprecated.js.map +1 -0
  52. package/dist/esm/pseudo/dev.d.ts +6 -0
  53. package/dist/esm/pseudo/dev.d.ts.map +1 -0
  54. package/dist/esm/pseudo/dev.js +15 -0
  55. package/dist/esm/pseudo/dev.js.map +1 -0
  56. package/dist/esm/pseudo/dynamic.d.ts +7 -0
  57. package/dist/esm/pseudo/dynamic.d.ts.map +1 -0
  58. package/dist/esm/pseudo/dynamic.js +6 -0
  59. package/dist/esm/pseudo/dynamic.js.map +1 -0
  60. package/dist/esm/pseudo/empty.d.ts +7 -0
  61. package/dist/esm/pseudo/empty.d.ts.map +1 -0
  62. package/dist/esm/pseudo/empty.js +14 -0
  63. package/dist/esm/pseudo/empty.js.map +1 -0
  64. package/dist/esm/pseudo/entropic.d.ts +7 -0
  65. package/dist/esm/pseudo/entropic.d.ts.map +1 -0
  66. package/dist/esm/pseudo/entropic.js +6 -0
  67. package/dist/esm/pseudo/entropic.js.map +1 -0
  68. package/dist/esm/pseudo/env.d.ts +7 -0
  69. package/dist/esm/pseudo/env.d.ts.map +1 -0
  70. package/dist/esm/pseudo/env.js +6 -0
  71. package/dist/esm/pseudo/env.js.map +1 -0
  72. package/dist/esm/pseudo/eval.d.ts +7 -0
  73. package/dist/esm/pseudo/eval.d.ts.map +1 -0
  74. package/dist/esm/pseudo/eval.js +6 -0
  75. package/dist/esm/pseudo/eval.js.map +1 -0
  76. package/dist/esm/pseudo/fs.d.ts +7 -0
  77. package/dist/esm/pseudo/fs.d.ts.map +1 -0
  78. package/dist/esm/pseudo/fs.js +6 -0
  79. package/dist/esm/pseudo/fs.js.map +1 -0
  80. package/dist/esm/pseudo/helpers.d.ts +25 -1
  81. package/dist/esm/pseudo/helpers.d.ts.map +1 -1
  82. package/dist/esm/pseudo/helpers.js +53 -0
  83. package/dist/esm/pseudo/helpers.js.map +1 -1
  84. package/dist/esm/pseudo/host.d.ts +20 -0
  85. package/dist/esm/pseudo/host.d.ts.map +1 -0
  86. package/dist/esm/pseudo/host.js +80 -0
  87. package/dist/esm/pseudo/host.js.map +1 -0
  88. package/dist/esm/pseudo/license.d.ts +13 -0
  89. package/dist/esm/pseudo/license.d.ts.map +1 -0
  90. package/dist/esm/pseudo/license.js +75 -0
  91. package/dist/esm/pseudo/license.js.map +1 -0
  92. package/dist/esm/pseudo/link.d.ts +9 -0
  93. package/dist/esm/pseudo/link.d.ts.map +1 -0
  94. package/dist/esm/pseudo/link.js +25 -0
  95. package/dist/esm/pseudo/link.js.map +1 -0
  96. package/dist/esm/pseudo/malware.d.ts +24 -0
  97. package/dist/esm/pseudo/malware.d.ts.map +1 -0
  98. package/dist/esm/pseudo/malware.js +187 -0
  99. package/dist/esm/pseudo/malware.js.map +1 -0
  100. package/dist/esm/pseudo/minified.d.ts +7 -0
  101. package/dist/esm/pseudo/minified.d.ts.map +1 -0
  102. package/dist/esm/pseudo/minified.js +6 -0
  103. package/dist/esm/pseudo/minified.js.map +1 -0
  104. package/dist/esm/pseudo/missing.d.ts +8 -0
  105. package/dist/esm/pseudo/missing.d.ts.map +1 -0
  106. package/dist/esm/pseudo/missing.js +15 -0
  107. package/dist/esm/pseudo/missing.js.map +1 -0
  108. package/dist/esm/pseudo/native.d.ts +7 -0
  109. package/dist/esm/pseudo/native.d.ts.map +1 -0
  110. package/dist/esm/pseudo/native.js +6 -0
  111. package/dist/esm/pseudo/native.js.map +1 -0
  112. package/dist/esm/pseudo/network.d.ts +7 -0
  113. package/dist/esm/pseudo/network.d.ts.map +1 -0
  114. package/dist/esm/pseudo/network.js +6 -0
  115. package/dist/esm/pseudo/network.js.map +1 -0
  116. package/dist/esm/pseudo/obfuscated.d.ts +7 -0
  117. package/dist/esm/pseudo/obfuscated.d.ts.map +1 -0
  118. package/dist/esm/pseudo/obfuscated.js +6 -0
  119. package/dist/esm/pseudo/obfuscated.js.map +1 -0
  120. package/dist/esm/pseudo/optional.d.ts +6 -0
  121. package/dist/esm/pseudo/optional.d.ts.map +1 -0
  122. package/dist/esm/pseudo/optional.js +15 -0
  123. package/dist/esm/pseudo/optional.js.map +1 -0
  124. package/dist/esm/pseudo/outdated.d.ts +4 -4
  125. package/dist/esm/pseudo/outdated.d.ts.map +1 -1
  126. package/dist/esm/pseudo/outdated.js +44 -33
  127. package/dist/esm/pseudo/outdated.js.map +1 -1
  128. package/dist/esm/pseudo/overridden.d.ts +8 -0
  129. package/dist/esm/pseudo/overridden.d.ts.map +1 -0
  130. package/dist/esm/pseudo/overridden.js +17 -0
  131. package/dist/esm/pseudo/overridden.js.map +1 -0
  132. package/dist/esm/pseudo/path.d.ts +19 -0
  133. package/dist/esm/pseudo/path.d.ts.map +1 -0
  134. package/dist/esm/pseudo/path.js +113 -0
  135. package/dist/esm/pseudo/path.js.map +1 -0
  136. package/dist/esm/pseudo/peer.d.ts +6 -0
  137. package/dist/esm/pseudo/peer.d.ts.map +1 -0
  138. package/dist/esm/pseudo/peer.js +15 -0
  139. package/dist/esm/pseudo/peer.js.map +1 -0
  140. package/dist/esm/pseudo/prerelease.d.ts +18 -0
  141. package/dist/esm/pseudo/prerelease.d.ts.map +1 -0
  142. package/dist/esm/pseudo/prerelease.js +41 -0
  143. package/dist/esm/pseudo/prerelease.js.map +1 -0
  144. package/dist/esm/pseudo/private.d.ts +7 -0
  145. package/dist/esm/pseudo/private.d.ts.map +1 -0
  146. package/dist/esm/pseudo/private.js +16 -0
  147. package/dist/esm/pseudo/private.js.map +1 -0
  148. package/dist/esm/pseudo/prod.d.ts +6 -0
  149. package/dist/esm/pseudo/prod.d.ts.map +1 -0
  150. package/dist/esm/pseudo/prod.js +15 -0
  151. package/dist/esm/pseudo/prod.js.map +1 -0
  152. package/dist/esm/pseudo/published.d.ts +40 -0
  153. package/dist/esm/pseudo/published.d.ts.map +1 -0
  154. package/dist/esm/pseudo/published.js +180 -0
  155. package/dist/esm/pseudo/published.js.map +1 -0
  156. package/dist/esm/pseudo/root.d.ts +7 -0
  157. package/dist/esm/pseudo/root.d.ts.map +1 -0
  158. package/dist/esm/pseudo/root.js +18 -0
  159. package/dist/esm/pseudo/root.js.map +1 -0
  160. package/dist/esm/pseudo/scanned.d.ts +9 -0
  161. package/dist/esm/pseudo/scanned.d.ts.map +1 -0
  162. package/dist/esm/pseudo/scanned.js +17 -0
  163. package/dist/esm/pseudo/scanned.js.map +1 -0
  164. package/dist/esm/pseudo/score.d.ts +16 -0
  165. package/dist/esm/pseudo/score.d.ts.map +1 -0
  166. package/dist/esm/pseudo/score.js +133 -0
  167. package/dist/esm/pseudo/score.js.map +1 -0
  168. package/dist/esm/pseudo/scripts.d.ts +10 -0
  169. package/dist/esm/pseudo/scripts.d.ts.map +1 -0
  170. package/dist/esm/pseudo/scripts.js +44 -0
  171. package/dist/esm/pseudo/scripts.js.map +1 -0
  172. package/dist/esm/pseudo/semver.d.ts +2 -1
  173. package/dist/esm/pseudo/semver.d.ts.map +1 -1
  174. package/dist/esm/pseudo/semver.js +11 -24
  175. package/dist/esm/pseudo/semver.js.map +1 -1
  176. package/dist/esm/pseudo/severity.d.ts +15 -0
  177. package/dist/esm/pseudo/severity.d.ts.map +1 -0
  178. package/dist/esm/pseudo/severity.js +160 -0
  179. package/dist/esm/pseudo/severity.js.map +1 -0
  180. package/dist/esm/pseudo/shell.d.ts +7 -0
  181. package/dist/esm/pseudo/shell.d.ts.map +1 -0
  182. package/dist/esm/pseudo/shell.js +6 -0
  183. package/dist/esm/pseudo/shell.js.map +1 -0
  184. package/dist/esm/pseudo/shrinkwrap.d.ts +7 -0
  185. package/dist/esm/pseudo/shrinkwrap.d.ts.map +1 -0
  186. package/dist/esm/pseudo/shrinkwrap.js +6 -0
  187. package/dist/esm/pseudo/shrinkwrap.js.map +1 -0
  188. package/dist/esm/pseudo/spec.d.ts +17 -0
  189. package/dist/esm/pseudo/spec.d.ts.map +1 -0
  190. package/dist/esm/pseudo/spec.js +102 -0
  191. package/dist/esm/pseudo/spec.js.map +1 -0
  192. package/dist/esm/pseudo/squat.d.ts +15 -0
  193. package/dist/esm/pseudo/squat.d.ts.map +1 -0
  194. package/dist/esm/pseudo/squat.js +172 -0
  195. package/dist/esm/pseudo/squat.js.map +1 -0
  196. package/dist/esm/pseudo/suspicious.d.ts +7 -0
  197. package/dist/esm/pseudo/suspicious.d.ts.map +1 -0
  198. package/dist/esm/pseudo/suspicious.js +6 -0
  199. package/dist/esm/pseudo/suspicious.js.map +1 -0
  200. package/dist/esm/pseudo/tracker.d.ts +7 -0
  201. package/dist/esm/pseudo/tracker.d.ts.map +1 -0
  202. package/dist/esm/pseudo/tracker.js +6 -0
  203. package/dist/esm/pseudo/tracker.js.map +1 -0
  204. package/dist/esm/pseudo/trivial.d.ts +7 -0
  205. package/dist/esm/pseudo/trivial.d.ts.map +1 -0
  206. package/dist/esm/pseudo/trivial.js +6 -0
  207. package/dist/esm/pseudo/trivial.js.map +1 -0
  208. package/dist/esm/pseudo/type.d.ts +8 -0
  209. package/dist/esm/pseudo/type.d.ts.map +1 -0
  210. package/dist/esm/pseudo/type.js +22 -0
  211. package/dist/esm/pseudo/type.js.map +1 -0
  212. package/dist/esm/pseudo/undesirable.d.ts +7 -0
  213. package/dist/esm/pseudo/undesirable.d.ts.map +1 -0
  214. package/dist/esm/pseudo/undesirable.js +6 -0
  215. package/dist/esm/pseudo/undesirable.js.map +1 -0
  216. package/dist/esm/pseudo/unknown.d.ts +7 -0
  217. package/dist/esm/pseudo/unknown.d.ts.map +1 -0
  218. package/dist/esm/pseudo/unknown.js +6 -0
  219. package/dist/esm/pseudo/unknown.js.map +1 -0
  220. package/dist/esm/pseudo/unmaintained.d.ts +7 -0
  221. package/dist/esm/pseudo/unmaintained.d.ts.map +1 -0
  222. package/dist/esm/pseudo/unmaintained.js +6 -0
  223. package/dist/esm/pseudo/unmaintained.js.map +1 -0
  224. package/dist/esm/pseudo/unpopular.d.ts +7 -0
  225. package/dist/esm/pseudo/unpopular.d.ts.map +1 -0
  226. package/dist/esm/pseudo/unpopular.js +6 -0
  227. package/dist/esm/pseudo/unpopular.js.map +1 -0
  228. package/dist/esm/pseudo/unstable.d.ts +7 -0
  229. package/dist/esm/pseudo/unstable.d.ts.map +1 -0
  230. package/dist/esm/pseudo/unstable.js +6 -0
  231. package/dist/esm/pseudo/unstable.js.map +1 -0
  232. package/dist/esm/pseudo/workspace.d.ts +6 -0
  233. package/dist/esm/pseudo/workspace.d.ts.map +1 -0
  234. package/dist/esm/pseudo/workspace.js +20 -0
  235. package/dist/esm/pseudo/workspace.js.map +1 -0
  236. package/dist/esm/pseudo.d.ts.map +1 -1
  237. package/dist/esm/pseudo.js +153 -108
  238. package/dist/esm/pseudo.js.map +1 -1
  239. package/dist/esm/types.d.ts +98 -26
  240. package/dist/esm/types.d.ts.map +1 -1
  241. package/dist/esm/types.js +1 -106
  242. package/dist/esm/types.js.map +1 -1
  243. package/package.json +20 -15
  244. package/dist/esm/class.d.ts +0 -6
  245. package/dist/esm/class.d.ts.map +0 -1
  246. package/dist/esm/class.js +0 -128
  247. package/dist/esm/class.js.map +0 -1
@@ -0,0 +1,44 @@
1
+ import { removeNode, removeDanglingEdges } from "./helpers.js";
2
+ /**
3
+ * Checks if a node needs to be built based on the conditions from the reify build process:
4
+ * 1. Has install lifecycle scripts (install, preinstall, postinstall)
5
+ * 2. Is an importer or git dependency with prepare scripts (prepare, preprepare, postprepare)
6
+ */
7
+ const nodeNeedsBuild = (node) => {
8
+ const { manifest } = node;
9
+ /* c8 ignore next */
10
+ if (!manifest)
11
+ return false;
12
+ const { scripts = {} } = manifest;
13
+ // Check for install lifecycle scripts
14
+ const runInstall = !!(scripts.install ||
15
+ scripts.preinstall ||
16
+ scripts.postinstall);
17
+ if (runInstall)
18
+ return true;
19
+ // Check for prepare scripts on importers or git dependencies
20
+ const prepable = node.id.startsWith('git') || node.importer;
21
+ const runPrepare = !!((scripts.prepare || scripts.preprepare || scripts.postprepare)
22
+ /* c8 ignore next 2 */
23
+ ) && prepable;
24
+ if (runPrepare)
25
+ return true;
26
+ return false;
27
+ };
28
+ /**
29
+ * :scripts Pseudo-Selector filters nodes based on whether they need to be built.
30
+ *
31
+ * A node needs to be built if it has:
32
+ * - Install lifecycle scripts (install, preinstall, postinstall)
33
+ * - Prepare scripts on importers or git dependencies (prepare, preprepare, postprepare)
34
+ */
35
+ export const scripts = async (state) => {
36
+ for (const node of state.partial.nodes) {
37
+ if (!nodeNeedsBuild(node)) {
38
+ removeNode(state, node);
39
+ }
40
+ }
41
+ removeDanglingEdges(state);
42
+ return state;
43
+ };
44
+ //# sourceMappingURL=scripts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scripts.js","sourceRoot":"","sources":["../../../src/pseudo/scripts.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAE9D;;;;GAIG;AACH,MAAM,cAAc,GAAG,CAAC,IAAc,EAAW,EAAE;IACjD,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAA;IACzB,oBAAoB;IACpB,IAAI,CAAC,QAAQ;QAAE,OAAO,KAAK,CAAA;IAE3B,MAAM,EAAE,OAAO,GAAG,EAAE,EAAE,GAAG,QAAQ,CAAA;IAEjC,sCAAsC;IACtC,MAAM,UAAU,GAAG,CAAC,CAAC,CACnB,OAAO,CAAC,OAAO;QACf,OAAO,CAAC,UAAU;QAClB,OAAO,CAAC,WAAW,CACpB,CAAA;IACD,IAAI,UAAU;QAAE,OAAO,IAAI,CAAA;IAE3B,6DAA6D;IAC7D,MAAM,QAAQ,GAAG,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAA;IAC3D,MAAM,UAAU,GACd,CAAC,CAAC,CACA,CAAC,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,UAAU,IAAI,OAAO,CAAC,WAAW,CAAC;IAC9D,sBAAsB;KACvB,IAAI,QAAQ,CAAA;IACf,IAAI,UAAU;QAAE,OAAO,IAAI,CAAA;IAE3B,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAED;;;;;;GAMG;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,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1B,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 type { NodeLike } from '@vltpkg/types'\nimport type { ParserState } from '../types.ts'\nimport { removeNode, removeDanglingEdges } from './helpers.ts'\n\n/**\n * Checks if a node needs to be built based on the conditions from the reify build process:\n * 1. Has install lifecycle scripts (install, preinstall, postinstall)\n * 2. Is an importer or git dependency with prepare scripts (prepare, preprepare, postprepare)\n */\nconst nodeNeedsBuild = (node: NodeLike): boolean => {\n const { manifest } = node\n /* c8 ignore next */\n if (!manifest) return false\n\n const { scripts = {} } = manifest\n\n // Check for install lifecycle scripts\n const runInstall = !!(\n scripts.install ||\n scripts.preinstall ||\n scripts.postinstall\n )\n if (runInstall) return true\n\n // Check for prepare scripts on importers or git dependencies\n const prepable = node.id.startsWith('git') || node.importer\n const runPrepare =\n !!(\n (scripts.prepare || scripts.preprepare || scripts.postprepare)\n /* c8 ignore next 2 */\n ) && prepable\n if (runPrepare) return true\n\n return false\n}\n\n/**\n * :scripts Pseudo-Selector filters nodes based on whether they need to be built.\n *\n * A node needs to be built if it has:\n * - Install lifecycle scripts (install, preinstall, postinstall)\n * - Prepare scripts on importers or git dependencies (prepare, preprepare, postprepare)\n */\nexport const scripts = async (state: ParserState) => {\n for (const node of state.partial.nodes) {\n if (!nodeNeedsBuild(node)) {\n removeNode(state, node)\n }\n }\n\n removeDanglingEdges(state)\n\n return state\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, PostcssNode } from '../types.ts';
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;AAG7C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAc9C,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAG3D,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,M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AO,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, isClassNode, isCombinatorNode, isPseudoNode, isStringNode, } from "../types.js";
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 (e) {
48
- const err = e;
49
- if (err.message === 'Mismatching query node') {
50
- semverValue = '';
51
- for (const node of asPostcssNodeWithChildren(nodes[0]).nodes) {
52
- if (isClassNode(node)) {
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 (e) {
80
- const err = e;
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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C,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 { 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,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C,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"}
@@ -0,0 +1,160 @@
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 kindsMap = new Map([
5
+ ['critical', 'criticalCVE'],
6
+ ['high', 'cve'],
7
+ ['medium', 'potentialVulnerability'],
8
+ ['low', 'mildCVE'],
9
+ ['0', 'criticalCVE'],
10
+ ['1', 'cve'],
11
+ ['2', 'potentialVulnerability'],
12
+ ['3', 'mildCVE'],
13
+ ]);
14
+ // Map numerical values to their respective kinds for comparison operations
15
+ const kindLevelMap = new Map([
16
+ ['critical', 0],
17
+ ['high', 1],
18
+ ['medium', 2],
19
+ ['low', 3],
20
+ ['0', 0],
21
+ ['1', 1],
22
+ ['2', 2],
23
+ ['3', 3],
24
+ ]);
25
+ const kinds = new Set(kindsMap.keys());
26
+ export const isSeverityKind = (value) => kinds.has(value);
27
+ export const asSeverityKind = (value) => {
28
+ if (!isSeverityKind(value)) {
29
+ throw error('Expected a valid severity kind', {
30
+ found: value,
31
+ validOptions: Array.from(kinds),
32
+ });
33
+ }
34
+ return value;
35
+ };
36
+ export const parseInternals = (nodes) => {
37
+ let kind;
38
+ let comparator;
39
+ if (nodes.length === 0) {
40
+ throw error('Missing severity kind parameter');
41
+ }
42
+ let kindValue = '';
43
+ if (isStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {
44
+ kindValue = removeQuotes(asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])
45
+ .value);
46
+ }
47
+ else if (isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {
48
+ kindValue = asTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0]).value;
49
+ }
50
+ // Extract comparator if present
51
+ if (kindValue.startsWith('>=')) {
52
+ comparator = '>=';
53
+ kindValue = kindValue.substring(2);
54
+ }
55
+ else if (kindValue.startsWith('<=')) {
56
+ comparator = '<=';
57
+ kindValue = kindValue.substring(2);
58
+ }
59
+ else if (kindValue.startsWith('>')) {
60
+ comparator = '>';
61
+ kindValue = kindValue.substring(1);
62
+ }
63
+ else if (kindValue.startsWith('<')) {
64
+ comparator = '<';
65
+ kindValue = kindValue.substring(1);
66
+ }
67
+ // Parse kind value
68
+ if (kindValue) {
69
+ if (isSeverityKind(kindValue)) {
70
+ kind = kindValue;
71
+ }
72
+ else {
73
+ throw error('Expected a valid severity kind or number between 0-3', {
74
+ found: kindValue,
75
+ });
76
+ }
77
+ }
78
+ return { kind, comparator };
79
+ };
80
+ export const severity = async (state) => {
81
+ assertSecurityArchive(state, 'severity');
82
+ let internals;
83
+ try {
84
+ internals = parseInternals(asPostcssNodeWithChildren(state.current).nodes);
85
+ }
86
+ catch (err) {
87
+ throw error('Failed to parse :severity selector', { cause: err });
88
+ }
89
+ const { kind, comparator } = internals;
90
+ for (const node of state.partial.nodes) {
91
+ const report = state.securityArchive.get(node.id);
92
+ // Always exclude nodes that don't have security data or alerts
93
+ if (!report?.alerts || report.alerts.length === 0) {
94
+ removeNode(state, node);
95
+ }
96
+ }
97
+ for (const node of state.partial.nodes) {
98
+ const report = state.securityArchive.get(node.id);
99
+ let exclude = true;
100
+ if (report) {
101
+ if (comparator) {
102
+ // retrieve the value to compare against
103
+ const kindLevel = kindLevelMap.get(kind);
104
+ // the kindLevel value has already been validated at this point
105
+ // and thus can never return an undefined/falsy value but ts doesn't
106
+ // know about that, so we have the extra check here
107
+ /* c8 ignore next - impossible */
108
+ if (!kindLevel)
109
+ break;
110
+ // Check each alert to find any that match our comparison criteria
111
+ for (const alert of report.alerts) {
112
+ // Get the numerical value of the alert type
113
+ const alertType = alert.type;
114
+ // retrieve a key to the current alert level to be compared against
115
+ const currentAlertLevelKey = [...kindsMap.entries()].find(([_, alertValue]) => alertValue === alertType)?.[0];
116
+ // perform the comparison based on the user-provided kindLevel
117
+ if (currentAlertLevelKey) {
118
+ const currentAlertLevel = kindLevelMap.get(currentAlertLevelKey);
119
+ /* c8 ignore next - impossible but ts doesn't know */
120
+ if (currentAlertLevel == null)
121
+ continue;
122
+ switch (comparator) {
123
+ case '>':
124
+ if (currentAlertLevel > kindLevel) {
125
+ exclude = false;
126
+ }
127
+ break;
128
+ case '<':
129
+ if (currentAlertLevel < kindLevel) {
130
+ exclude = false;
131
+ }
132
+ break;
133
+ case '>=':
134
+ if (currentAlertLevel >= kindLevel) {
135
+ exclude = false;
136
+ }
137
+ break;
138
+ case '<=':
139
+ if (currentAlertLevel <= kindLevel) {
140
+ exclude = false;
141
+ }
142
+ break;
143
+ }
144
+ }
145
+ }
146
+ }
147
+ else {
148
+ // Original exact match behavior
149
+ const alertName = kindsMap.get(kind);
150
+ exclude = !report.alerts.some(alert => alert.type === alertName);
151
+ }
152
+ }
153
+ if (exclude) {
154
+ removeNode(state, node);
155
+ }
156
+ }
157
+ removeDanglingEdges(state);
158
+ return state;
159
+ };
160
+ //# sourceMappingURL=severity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"severity.js","sourceRoot":"","sources":["../../../src/pseudo/severity.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,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,UAAU,EACV,YAAY,GACb,MAAM,cAAc,CAAA;AAwBrB,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAoC;IAC1D,CAAC,UAAU,EAAE,aAAa,CAAC;IAC3B,CAAC,MAAM,EAAE,KAAK,CAAC;IACf,CAAC,QAAQ,EAAE,wBAAwB,CAAC;IACpC,CAAC,KAAK,EAAE,SAAS,CAAC;IAClB,CAAC,GAAG,EAAE,aAAa,CAAC;IACpB,CAAC,GAAG,EAAE,KAAK,CAAC;IACZ,CAAC,GAAG,EAAE,wBAAwB,CAAC;I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;gCACjB,CAAC;gCACD,MAAK;wBACT,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,gCAAgC;gBAChC,MAAM,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;gBACpC,OAAO,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAC3B,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAClC,CAAA;YACH,CAAC;QACH,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 { ParserState } from '../types.ts'\nimport type { PostcssNode } from '@vltpkg/dss-parser'\n\nexport type SeverityKinds =\n | '0'\n | '1'\n | '2'\n | '3'\n | 'critical'\n | 'high'\n | 'medium'\n | 'low'\n | undefined\n\nexport type SeverityAlertTypes =\n | 'criticalCVE'\n | 'cve'\n | 'potentialVulnerability'\n | 'mildCVE'\n | undefined\n\nexport type SeverityComparator = '>' | '<' | '>=' | '<=' | undefined\n\nconst kindsMap = new Map<SeverityKinds, SeverityAlertTypes>([\n ['critical', 'criticalCVE'],\n ['high', 'cve'],\n ['medium', 'potentialVulnerability'],\n ['low', 'mildCVE'],\n ['0', 'criticalCVE'],\n ['1', 'cve'],\n ['2', 'potentialVulnerability'],\n ['3', 'mildCVE'],\n])\n\n// Map numerical values to their respective kinds for comparison operations\nconst kindLevelMap = new Map<SeverityKinds, number>([\n ['critical', 0],\n ['high', 1],\n ['medium', 2],\n ['low', 3],\n ['0', 0],\n ['1', 1],\n ['2', 2],\n ['3', 3],\n])\n\nconst kinds = new Set(kindsMap.keys())\n\nexport const isSeverityKind = (\n value?: string,\n): value is SeverityKinds => kinds.has(value as SeverityKinds)\n\nexport const asSeverityKind = (value?: string): SeverityKinds => {\n if (!isSeverityKind(value)) {\n throw error('Expected a valid severity kind', {\n found: value,\n validOptions: Array.from(kinds),\n })\n }\n return value\n}\n\nexport const parseInternals = (\n nodes: PostcssNode[],\n): {\n kind: SeverityKinds\n comparator: SeverityComparator\n} => {\n let kind: SeverityKinds\n let comparator: SeverityComparator\n\n if (nodes.length === 0) {\n throw error('Missing severity kind parameter')\n }\n\n let kindValue = ''\n if (isStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {\n kindValue = removeQuotes(\n asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])\n .value,\n )\n } else if (\n isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])\n ) {\n kindValue = asTagNode(\n asPostcssNodeWithChildren(nodes[0]).nodes[0],\n ).value\n }\n\n // Extract comparator if present\n if (kindValue.startsWith('>=')) {\n comparator = '>='\n kindValue = kindValue.substring(2)\n } else if (kindValue.startsWith('<=')) {\n comparator = '<='\n kindValue = kindValue.substring(2)\n } else if (kindValue.startsWith('>')) {\n comparator = '>'\n kindValue = kindValue.substring(1)\n } else if (kindValue.startsWith('<')) {\n comparator = '<'\n kindValue = kindValue.substring(1)\n }\n\n // Parse kind value\n if (kindValue) {\n if (isSeverityKind(kindValue)) {\n kind = kindValue\n } else {\n throw error(\n 'Expected a valid severity kind or number between 0-3',\n {\n found: kindValue,\n },\n )\n }\n }\n\n return { kind, comparator }\n}\n\nexport const severity = async (state: ParserState) => {\n assertSecurityArchive(state, 'severity')\n\n let internals\n try {\n internals = parseInternals(\n asPostcssNodeWithChildren(state.current).nodes,\n )\n } catch (err) {\n throw error('Failed to parse :severity selector', { cause: err })\n }\n\n const { kind, comparator } = internals\n\n for (const node of state.partial.nodes) {\n const report = state.securityArchive.get(node.id)\n // Always exclude nodes that don't have security data or alerts\n if (!report?.alerts || report.alerts.length === 0) {\n removeNode(state, node)\n }\n }\n\n for (const node of state.partial.nodes) {\n const report = state.securityArchive.get(node.id)\n let exclude = true\n\n if (report) {\n if (comparator) {\n // retrieve the value to compare against\n const kindLevel = kindLevelMap.get(kind)\n // the kindLevel value has already been validated at this point\n // and thus can never return an undefined/falsy value but ts doesn't\n // know about that, so we have the extra check here\n /* c8 ignore next - impossible */\n if (!kindLevel) break\n\n // Check each alert to find any that match our comparison criteria\n for (const alert of report.alerts) {\n // Get the numerical value of the alert type\n const alertType = alert.type\n\n // retrieve a key to the current alert level to be compared against\n const currentAlertLevelKey = [...kindsMap.entries()].find(\n ([_, alertValue]) => alertValue === alertType,\n )?.[0]\n\n // perform the comparison based on the user-provided kindLevel\n if (currentAlertLevelKey) {\n const currentAlertLevel = kindLevelMap.get(\n currentAlertLevelKey,\n )\n /* c8 ignore next - impossible but ts doesn't know */\n if (currentAlertLevel == null) continue\n\n switch (comparator) {\n case '>':\n if (currentAlertLevel > kindLevel) {\n exclude = false\n }\n break\n case '<':\n if (currentAlertLevel < kindLevel) {\n exclude = false\n }\n break\n case '>=':\n if (currentAlertLevel >= kindLevel) {\n exclude = false\n }\n break\n case '<=':\n if (currentAlertLevel <= kindLevel) {\n exclude = false\n }\n break\n }\n }\n }\n } else {\n // Original exact match behavior\n const alertName = kindsMap.get(kind)\n exclude = !report.alerts.some(\n alert => alert.type === alertName,\n )\n }\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 a **shellAccess** report alert.
3
+ */
4
+ export declare const shell: (state: import("../types.ts").ParserState) => Promise<import("../types.ts").ParserState & {
5
+ securityArchive: NonNullable<import("../types.ts").ParserState["securityArchive"]>;
6
+ }>;
7
+ //# sourceMappingURL=shell.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shell.d.ts","sourceRoot":"","sources":["../../../src/pseudo/shell.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,KAAK;;EAGjB,CAAA"}
@@ -0,0 +1,6 @@
1
+ import { createSecuritySelectorFilter } from "./helpers.js";
2
+ /**
3
+ * Filters out any node that does not have a **shellAccess** report alert.
4
+ */
5
+ export const shell = createSecuritySelectorFilter('shell', 'shellAccess');
6
+ //# sourceMappingURL=shell.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shell.js","sourceRoot":"","sources":["../../../src/pseudo/shell.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAA;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,4BAA4B,CAC/C,OAAO,EACP,aAAa,CACd,CAAA","sourcesContent":["import { createSecuritySelectorFilter } from './helpers.ts'\n\n/**\n * Filters out any node that does not have a **shellAccess** report alert.\n */\nexport const shell = createSecuritySelectorFilter(\n 'shell',\n 'shellAccess',\n)\n"]}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Filters out any node that does not have a **shrinkwrap** report alert.
3
+ */
4
+ export declare const shrinkwrap: (state: import("../types.ts").ParserState) => Promise<import("../types.ts").ParserState & {
5
+ securityArchive: NonNullable<import("../types.ts").ParserState["securityArchive"]>;
6
+ }>;
7
+ //# sourceMappingURL=shrinkwrap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shrinkwrap.d.ts","sourceRoot":"","sources":["../../../src/pseudo/shrinkwrap.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,UAAU;;EAGtB,CAAA"}
@@ -0,0 +1,6 @@
1
+ import { createSecuritySelectorFilter } from "./helpers.js";
2
+ /**
3
+ * Filters out any node that does not have a **shrinkwrap** report alert.
4
+ */
5
+ export const shrinkwrap = createSecuritySelectorFilter('shrinkwrap', 'shrinkwrap');
6
+ //# sourceMappingURL=shrinkwrap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shrinkwrap.js","sourceRoot":"","sources":["../../../src/pseudo/shrinkwrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAA;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,4BAA4B,CACpD,YAAY,EACZ,YAAY,CACb,CAAA","sourcesContent":["import { createSecuritySelectorFilter } from './helpers.ts'\n\n/**\n * Filters out any node that does not have a **shrinkwrap** report alert.\n */\nexport const shrinkwrap = createSecuritySelectorFilter(\n 'shrinkwrap',\n 'shrinkwrap',\n)\n"]}
@@ -0,0 +1,17 @@
1
+ import type { ParserState } from '../types.ts';
2
+ import type { PostcssNode } from '@vltpkg/dss-parser';
3
+ export type SpecInternals = {
4
+ specValue: string;
5
+ };
6
+ export declare const parseInternals: (nodes: PostcssNode[]) => SpecInternals;
7
+ /**
8
+ * :spec Pseudo-Selector, matches edges where edge.spec.bareSpec equals the provided value.
9
+ *
10
+ * Examples:
11
+ * - :spec("*") matches edges with a package specifier equal to "*"
12
+ * - :spec(^1.0.0) matches edges with a package specifier equal to "^1.0.0"
13
+ * - :spec("catalog:") matches edges with a package specifier equal to "catalog:"
14
+ * - :spec("workspace:dev") matches edges with a package specifier equal to "workspace:dev"
15
+ */
16
+ export declare const spec: (state: ParserState) => Promise<ParserState>;
17
+ //# sourceMappingURL=spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spec.d.ts","sourceRoot":"","sources":["../../../src/pseudo/spec.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAErD,MAAM,MAAM,aAAa,GAAG;IAC1B,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,cAAc,UAClB,WAAW,EAAE,KACnB,aAyEF,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,IAAI,UAAiB,WAAW,yBAwB5C,CAAA"}
@@ -0,0 +1,102 @@
1
+ import { error } from '@vltpkg/error-cause';
2
+ import { asError } from '@vltpkg/types';
3
+ import { asPostcssNodeWithChildren, asStringNode, asTagNode, isTagNode, } from '@vltpkg/dss-parser';
4
+ import { removeEdge, removeUnlinkedNodes, removeQuotes, } from "./helpers.js";
5
+ export const parseInternals = (nodes) => {
6
+ // tries to parse the first param as a string node, otherwise defaults
7
+ // to reading all postcss nodes as just strings, since it just means
8
+ // the value was defined as an unquoted string
9
+ let specValue = '';
10
+ if (nodes.length === 0) {
11
+ throw new Error('No nodes provided to parseInternals');
12
+ }
13
+ const firstNode = asPostcssNodeWithChildren(nodes[0]);
14
+ if (firstNode.nodes.length === 0) {
15
+ throw new Error('First node has no child nodes');
16
+ }
17
+ // Try to parse as a quoted string first (single string node)
18
+ if (firstNode.nodes.length === 1) {
19
+ const targetNode = firstNode.nodes[0];
20
+ try {
21
+ specValue = removeQuotes(asStringNode(targetNode).value);
22
+ return { specValue };
23
+ }
24
+ catch (err) {
25
+ if (asError(err).message === 'Mismatching query node' &&
26
+ isTagNode(targetNode)
27
+ /* c8 ignore start */
28
+ ) {
29
+ // Handle simple unquoted single-token values like "1"
30
+ const tagNode = asTagNode(targetNode);
31
+ specValue = tagNode.value;
32
+ return { specValue };
33
+ /* c8 ignore stop */
34
+ }
35
+ else {
36
+ throw err;
37
+ }
38
+ }
39
+ }
40
+ // Handle unquoted complex values that get parsed into multiple nodes
41
+ // This happens when unquoted values contain dots, like ^1.0.0 which becomes:
42
+ // - Tag: "^1"
43
+ // - ClassName: "0" (from .0)
44
+ // - ClassName: "0" (from .0)
45
+ // We need to reconstruct the original value by concatenating all nodes
46
+ const parts = [];
47
+ for (const node of firstNode.nodes) {
48
+ switch (node.type) {
49
+ case 'tag':
50
+ parts.push(asTagNode(node).value);
51
+ break;
52
+ case 'class':
53
+ // Class nodes represent .className in CSS, so we need to add the dot back
54
+ parts.push('.' + node.value);
55
+ break;
56
+ case 'id':
57
+ // ID nodes represent #idName in CSS, so we need to add the hash back
58
+ parts.push('#' + node.value);
59
+ break;
60
+ case 'string':
61
+ parts.push(removeQuotes(asStringNode(node).value));
62
+ break;
63
+ default:
64
+ // For other node types, try to get the value property or convert to string
65
+ /* c8 ignore next */
66
+ parts.push(node.value ?? String(node));
67
+ break;
68
+ }
69
+ }
70
+ specValue = parts.join('');
71
+ return { specValue };
72
+ };
73
+ /**
74
+ * :spec Pseudo-Selector, matches edges where edge.spec.bareSpec equals the provided value.
75
+ *
76
+ * Examples:
77
+ * - :spec("*") matches edges with a package specifier equal to "*"
78
+ * - :spec(^1.0.0) matches edges with a package specifier equal to "^1.0.0"
79
+ * - :spec("catalog:") matches edges with a package specifier equal to "catalog:"
80
+ * - :spec("workspace:dev") matches edges with a package specifier equal to "workspace:dev"
81
+ */
82
+ export const spec = async (state) => {
83
+ let internals;
84
+ try {
85
+ internals = parseInternals(asPostcssNodeWithChildren(state.current).nodes);
86
+ }
87
+ catch (err) {
88
+ throw error('Failed to parse :spec selector', {
89
+ cause: err,
90
+ });
91
+ }
92
+ const { specValue } = internals;
93
+ for (const edge of state.partial.edges) {
94
+ if (edge.spec.bareSpec !== specValue) {
95
+ removeEdge(state, edge);
96
+ }
97
+ }
98
+ // Clean up unlinked nodes after removing edges
99
+ removeUnlinkedNodes(state);
100
+ return state;
101
+ };
102
+ //# sourceMappingURL=spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spec.js","sourceRoot":"","sources":["../../../src/pseudo/spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EACL,yBAAyB,EACzB,YAAY,EACZ,SAAS,EACT,SAAS,GACV,MAAM,oBAAoB,CAAA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b,MAAM,KAAK,CAAC,gCAAgC,EAAE;YAC5C,KAAK,EAAE,GAAG;SACX,CAAC,CAAA;IACJ,CAAC;IAED,MAAM,EAAE,SAAS,EAAE,GAAG,SAAS,CAAA;IAE/B,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACvC,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;YACrC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;QACzB,CAAC;IACH,CAAC;IAED,+CAA+C;IAC/C,mBAAmB,CAAC,KAAK,CAAC,CAAA;IAE1B,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport { asError } from '@vltpkg/types'\nimport {\n asPostcssNodeWithChildren,\n asStringNode,\n asTagNode,\n isTagNode,\n} from '@vltpkg/dss-parser'\nimport {\n removeEdge,\n removeUnlinkedNodes,\n removeQuotes,\n} from './helpers.ts'\nimport type { ParserState } from '../types.ts'\nimport type { PostcssNode } from '@vltpkg/dss-parser'\n\nexport type SpecInternals = {\n specValue: string\n}\n\nexport const parseInternals = (\n nodes: PostcssNode[],\n): SpecInternals => {\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 specValue = ''\n\n if (nodes.length === 0) {\n throw new Error('No nodes provided to parseInternals')\n }\n\n const firstNode = asPostcssNodeWithChildren(nodes[0])\n\n if (firstNode.nodes.length === 0) {\n throw new Error('First node has no child nodes')\n }\n\n // Try to parse as a quoted string first (single string node)\n if (firstNode.nodes.length === 1) {\n const targetNode = firstNode.nodes[0]\n try {\n specValue = removeQuotes(asStringNode(targetNode).value)\n return { specValue }\n } catch (err) {\n if (\n asError(err).message === 'Mismatching query node' &&\n isTagNode(targetNode)\n /* c8 ignore start */\n ) {\n // Handle simple unquoted single-token values like \"1\"\n const tagNode = asTagNode(targetNode)\n specValue = tagNode.value\n return { specValue }\n /* c8 ignore stop */\n } else {\n throw err\n }\n }\n }\n\n // Handle unquoted complex values that get parsed into multiple nodes\n // This happens when unquoted values contain dots, like ^1.0.0 which becomes:\n // - Tag: \"^1\"\n // - ClassName: \"0\" (from .0)\n // - ClassName: \"0\" (from .0)\n // We need to reconstruct the original value by concatenating all nodes\n const parts: string[] = []\n\n for (const node of firstNode.nodes) {\n switch (node.type) {\n case 'tag':\n parts.push(asTagNode(node).value)\n break\n case 'class':\n // Class nodes represent .className in CSS, so we need to add the dot back\n parts.push('.' + node.value)\n break\n case 'id':\n // ID nodes represent #idName in CSS, so we need to add the hash back\n parts.push('#' + node.value)\n break\n case 'string':\n parts.push(removeQuotes(asStringNode(node).value))\n break\n default:\n // For other node types, try to get the value property or convert to string\n /* c8 ignore next */\n parts.push(node.value ?? String(node))\n break\n }\n }\n\n specValue = parts.join('')\n return { specValue }\n}\n\n/**\n * :spec Pseudo-Selector, matches edges where edge.spec.bareSpec equals the provided value.\n *\n * Examples:\n * - :spec(\"*\") matches edges with a package specifier equal to \"*\"\n * - :spec(^1.0.0) matches edges with a package specifier equal to \"^1.0.0\"\n * - :spec(\"catalog:\") matches edges with a package specifier equal to \"catalog:\"\n * - :spec(\"workspace:dev\") matches edges with a package specifier equal to \"workspace:dev\"\n */\nexport const spec = 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 :spec selector', {\n cause: err,\n })\n }\n\n const { specValue } = internals\n\n for (const edge of state.partial.edges) {\n if (edge.spec.bareSpec !== specValue) {\n removeEdge(state, edge)\n }\n }\n\n // Clean up unlinked nodes after removing edges\n removeUnlinkedNodes(state)\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 SquatKinds = '0' | '2' | 'critical' | 'medium' | undefined;
4
+ export type SquatAlertTypes = 'didYouMean' | 'gptDidYouMean' | undefined;
5
+ export type SquatComparator = '>' | '<' | '>=' | '<=' | undefined;
6
+ export declare const isSquatKind: (value?: string) => value is SquatKinds;
7
+ export declare const asSquatKind: (value?: string) => SquatKinds;
8
+ export declare const parseInternals: (nodes: PostcssNode[]) => {
9
+ kind: SquatKinds;
10
+ comparator: SquatComparator;
11
+ };
12
+ export declare const squat: (state: ParserState) => Promise<ParserState & {
13
+ securityArchive: NonNullable<ParserState["securityArchive"]>;
14
+ }>;
15
+ //# sourceMappingURL=squat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"squat.d.ts","sourceRoot":"","sources":["../../../src/pseudo/squat.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAErD,MAAM,MAAM,UAAU,GAAG,GAAG,GAAG,GAAG,GAAG,UAAU,GAAG,QAAQ,GAAG,SAAS,CAAA;AAEtE,MAAM,MAAM,eAAe,GACvB,YAAY,GACZ,eAAe,GACf,SAAS,CAAA;AAEb,MAAM,MAAM,eAAe,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,CAAA;AAoBjE,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,IAAI,EAAE,UAAU,CAAA;IAChB,UAAU,EAAE,eAAe,CAAA;CA+C5B,CAAA;AAED,eAAO,MAAM,KAAK,UAAiB,WAAW;;EAmH7C,CAAA"}