@dep-radius/core 0.1.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 (157) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +48 -0
  3. package/dist/analyze/brief.d.ts +18 -0
  4. package/dist/analyze/brief.d.ts.map +1 -0
  5. package/dist/analyze/brief.js +89 -0
  6. package/dist/analyze/verdict.d.ts +16 -0
  7. package/dist/analyze/verdict.d.ts.map +1 -0
  8. package/dist/analyze/verdict.js +134 -0
  9. package/dist/context.d.ts +4 -0
  10. package/dist/context.d.ts.map +1 -0
  11. package/dist/context.js +36 -0
  12. package/dist/debug.d.ts +2 -0
  13. package/dist/debug.d.ts.map +1 -0
  14. package/dist/debug.js +130 -0
  15. package/dist/index.d.ts +9 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +8 -0
  18. package/dist/infra/cache.d.ts +18 -0
  19. package/dist/infra/cache.d.ts.map +1 -0
  20. package/dist/infra/cache.js +66 -0
  21. package/dist/infra/hash.d.ts +4 -0
  22. package/dist/infra/hash.d.ts.map +1 -0
  23. package/dist/infra/hash.js +18 -0
  24. package/dist/infra/http.d.ts +24 -0
  25. package/dist/infra/http.d.ts.map +1 -0
  26. package/dist/infra/http.js +44 -0
  27. package/dist/infra/limit.d.ts +4 -0
  28. package/dist/infra/limit.d.ts.map +1 -0
  29. package/dist/infra/limit.js +34 -0
  30. package/dist/infra/log.d.ts +8 -0
  31. package/dist/infra/log.d.ts.map +1 -0
  32. package/dist/infra/log.js +13 -0
  33. package/dist/inventory/installed.d.ts +15 -0
  34. package/dist/inventory/installed.d.ts.map +1 -0
  35. package/dist/inventory/installed.js +241 -0
  36. package/dist/inventory/lockfiles/bun.d.ts +3 -0
  37. package/dist/inventory/lockfiles/bun.d.ts.map +1 -0
  38. package/dist/inventory/lockfiles/bun.js +24 -0
  39. package/dist/inventory/lockfiles/npm.d.ts +3 -0
  40. package/dist/inventory/lockfiles/npm.d.ts.map +1 -0
  41. package/dist/inventory/lockfiles/npm.js +29 -0
  42. package/dist/inventory/lockfiles/pnpm.d.ts +3 -0
  43. package/dist/inventory/lockfiles/pnpm.d.ts.map +1 -0
  44. package/dist/inventory/lockfiles/pnpm.js +84 -0
  45. package/dist/inventory/lockfiles/types.d.ts +9 -0
  46. package/dist/inventory/lockfiles/types.d.ts.map +1 -0
  47. package/dist/inventory/lockfiles/types.js +1 -0
  48. package/dist/inventory/lockfiles/yarn.d.ts +3 -0
  49. package/dist/inventory/lockfiles/yarn.d.ts.map +1 -0
  50. package/dist/inventory/lockfiles/yarn.js +46 -0
  51. package/dist/inventory/manifests.d.ts +9 -0
  52. package/dist/inventory/manifests.d.ts.map +1 -0
  53. package/dist/inventory/manifests.js +135 -0
  54. package/dist/inventory/specifiers.d.ts +8 -0
  55. package/dist/inventory/specifiers.d.ts.map +1 -0
  56. package/dist/inventory/specifiers.js +53 -0
  57. package/dist/labels.d.ts +2 -0
  58. package/dist/labels.d.ts.map +1 -0
  59. package/dist/labels.js +18 -0
  60. package/dist/model.d.ts +276 -0
  61. package/dist/model.d.ts.map +1 -0
  62. package/dist/model.js +2 -0
  63. package/dist/notes/changelog.d.ts +11 -0
  64. package/dist/notes/changelog.d.ts.map +1 -0
  65. package/dist/notes/changelog.js +60 -0
  66. package/dist/notes/collect.d.ts +13 -0
  67. package/dist/notes/collect.d.ts.map +1 -0
  68. package/dist/notes/collect.js +225 -0
  69. package/dist/notes/entries.d.ts +3 -0
  70. package/dist/notes/entries.d.ts.map +1 -0
  71. package/dist/notes/entries.js +209 -0
  72. package/dist/notes/github.d.ts +25 -0
  73. package/dist/notes/github.d.ts.map +1 -0
  74. package/dist/notes/github.js +132 -0
  75. package/dist/notes/match.d.ts +13 -0
  76. package/dist/notes/match.d.ts.map +1 -0
  77. package/dist/notes/match.js +75 -0
  78. package/dist/notes/repo-url.d.ts +9 -0
  79. package/dist/notes/repo-url.d.ts.map +1 -0
  80. package/dist/notes/repo-url.js +46 -0
  81. package/dist/options.d.ts +53 -0
  82. package/dist/options.d.ts.map +1 -0
  83. package/dist/options.js +27 -0
  84. package/dist/registry/candidates.d.ts +24 -0
  85. package/dist/registry/candidates.d.ts.map +1 -0
  86. package/dist/registry/candidates.js +139 -0
  87. package/dist/registry/npmrc.d.ts +13 -0
  88. package/dist/registry/npmrc.d.ts.map +1 -0
  89. package/dist/registry/npmrc.js +99 -0
  90. package/dist/registry/packument.d.ts +34 -0
  91. package/dist/registry/packument.d.ts.map +1 -0
  92. package/dist/registry/packument.js +85 -0
  93. package/dist/registry/tar.d.ts +2 -0
  94. package/dist/registry/tar.d.ts.map +1 -0
  95. package/dist/registry/tar.js +75 -0
  96. package/dist/registry/tarball.d.ts +16 -0
  97. package/dist/registry/tarball.d.ts.map +1 -0
  98. package/dist/registry/tarball.js +59 -0
  99. package/dist/render/groups.d.ts +16 -0
  100. package/dist/render/groups.d.ts.map +1 -0
  101. package/dist/render/groups.js +105 -0
  102. package/dist/render/index.d.ts +2 -0
  103. package/dist/render/index.d.ts.map +1 -0
  104. package/dist/render/index.js +3 -0
  105. package/dist/render/json.d.ts +119 -0
  106. package/dist/render/json.d.ts.map +1 -0
  107. package/dist/render/json.js +130 -0
  108. package/dist/render/limits.d.ts +3 -0
  109. package/dist/render/limits.d.ts.map +1 -0
  110. package/dist/render/limits.js +25 -0
  111. package/dist/render/markdown.d.ts +3 -0
  112. package/dist/render/markdown.d.ts.map +1 -0
  113. package/dist/render/markdown.js +62 -0
  114. package/dist/run.d.ts +10 -0
  115. package/dist/run.d.ts.map +1 -0
  116. package/dist/run.js +218 -0
  117. package/dist/surface/analyze.d.ts +13 -0
  118. package/dist/surface/analyze.d.ts.map +1 -0
  119. package/dist/surface/analyze.js +166 -0
  120. package/dist/surface/delta.d.ts +5 -0
  121. package/dist/surface/delta.d.ts.map +1 -0
  122. package/dist/surface/delta.js +173 -0
  123. package/dist/surface/entries.d.ts +16 -0
  124. package/dist/surface/entries.d.ts.map +1 -0
  125. package/dist/surface/entries.js +187 -0
  126. package/dist/surface/extract.d.ts +15 -0
  127. package/dist/surface/extract.d.ts.map +1 -0
  128. package/dist/surface/extract.js +460 -0
  129. package/dist/surface/signature.d.ts +6 -0
  130. package/dist/surface/signature.d.ts.map +1 -0
  131. package/dist/surface/signature.js +229 -0
  132. package/dist/surface/vfs-host.d.ts +5 -0
  133. package/dist/surface/vfs-host.d.ts.map +1 -0
  134. package/dist/surface/vfs-host.js +54 -0
  135. package/dist/symbol-path.d.ts +28 -0
  136. package/dist/symbol-path.d.ts.map +1 -0
  137. package/dist/symbol-path.js +223 -0
  138. package/dist/usage/files.d.ts +18 -0
  139. package/dist/usage/files.d.ts.map +1 -0
  140. package/dist/usage/files.js +83 -0
  141. package/dist/usage/link.d.ts +23 -0
  142. package/dist/usage/link.d.ts.map +1 -0
  143. package/dist/usage/link.js +588 -0
  144. package/dist/usage/opaque.d.ts +7 -0
  145. package/dist/usage/opaque.d.ts.map +1 -0
  146. package/dist/usage/opaque.js +193 -0
  147. package/dist/usage/parse.d.ts +73 -0
  148. package/dist/usage/parse.d.ts.map +1 -0
  149. package/dist/usage/parse.js +608 -0
  150. package/dist/usage/resolve-local.d.ts +35 -0
  151. package/dist/usage/resolve-local.d.ts.map +1 -0
  152. package/dist/usage/resolve-local.js +340 -0
  153. package/dist/usage/scan.d.ts +4 -0
  154. package/dist/usage/scan.d.ts.map +1 -0
  155. package/dist/usage/scan.js +92 -0
  156. package/package.json +79 -0
  157. package/schema/brief-v1.schema.json +319 -0
@@ -0,0 +1,193 @@
1
+ import { join, posix } from "node:path";
2
+ import { readFile } from "node:fs/promises";
3
+ import ts from "typescript";
4
+ import { STYLE_EXT } from "./files.js";
5
+ import { packageNameOf } from "../inventory/specifiers.js";
6
+ // Packages consumed mostly through file conventions: their import surface says little about how
7
+ // much of the project depends on them.
8
+ export const CONVENTION_FRAMEWORKS = new Set([
9
+ "next",
10
+ "nuxt",
11
+ "astro",
12
+ "gatsby",
13
+ "@remix-run/dev",
14
+ "@react-router/dev",
15
+ "@sveltejs/kit",
16
+ "@docusaurus/core",
17
+ "vitepress",
18
+ "expo-router",
19
+ "react-scripts",
20
+ "@angular/core",
21
+ "@nestjs/core",
22
+ ]);
23
+ const CONFIG_FILE = /(^|\/)([^/]*\.config\.[cm]?[jt]s|\.[a-z-]*rc(\.[cm]?[jt]s|\.json|\.ya?ml)?|[a-z-]*rc\.[cm]?js|tsconfig[^/]*\.json|jsconfig\.json|components\.json|turbo\.json|vercel\.json|biome\.jsonc?|renovate\.json5?|\.babelrc|babel\.config\.json|deno\.jsonc?)$/i;
24
+ export async function findOpaque(root, files, facts, inventory, resolver) {
25
+ const hits = new Map();
26
+ const add = (id, kind, s) => {
27
+ let m = hits.get(id);
28
+ if (!m) {
29
+ m = new Map();
30
+ hits.set(id, m);
31
+ }
32
+ const list = m.get(kind) ?? [];
33
+ list.push(s);
34
+ m.set(kind, list);
35
+ };
36
+ const byName = new Map();
37
+ for (const d of inventory.installed) {
38
+ for (const n of new Set([d.name, ...d.declaredBy.map((x) => x.key)])) {
39
+ const l = byName.get(n) ?? [];
40
+ if (!l.includes(d))
41
+ l.push(d);
42
+ byName.set(n, l);
43
+ }
44
+ }
45
+ const depsFor = (value) => {
46
+ const name = packageNameOf(value);
47
+ if (!name)
48
+ return [];
49
+ if (value !== name && !value.startsWith(`${name}/`))
50
+ return [];
51
+ return byName.get(name) ?? [];
52
+ };
53
+ // string references in JS or TS config files: plugins: ["prettier-plugin-tailwindcss"]
54
+ for (const [rel, f] of facts) {
55
+ if (!CONFIG_FILE.test(rel))
56
+ continue;
57
+ for (const s of f.stringLiterals) {
58
+ for (const d of depsFor(s.value))
59
+ add(d.id, "config-reference", site(rel, s.pos.line, s.pos.text));
60
+ }
61
+ }
62
+ // JSON configs, and the non-dependency fields of manifests ("prettier": "@acme/prettier-config")
63
+ for (const rel of files) {
64
+ const isManifest = rel === "package.json" || rel.endsWith("/package.json");
65
+ const isJsonConfig = /\.(json|jsonc|json5)$/i.test(rel) && CONFIG_FILE.test(rel);
66
+ const isRc = /(^|\/)\.[a-z-]*rc$/i.test(rel);
67
+ if (!isManifest && !isJsonConfig && !isRc)
68
+ continue;
69
+ let text;
70
+ try {
71
+ text = await readFile(join(root, rel), "utf8");
72
+ }
73
+ catch {
74
+ continue;
75
+ }
76
+ const parsed = ts.parseConfigFileTextToJson(rel, text);
77
+ const json = parsed.config;
78
+ if (json === undefined)
79
+ continue;
80
+ const strings = [];
81
+ collectStrings(json, strings, isManifest);
82
+ for (const value of strings) {
83
+ for (const d of depsFor(value))
84
+ add(d.id, "config-reference", site(rel, lineOfString(text, value), value));
85
+ }
86
+ }
87
+ // binaries run from scripts: "lint": "eslint . --max-warnings 0"
88
+ const binOwners = new Map();
89
+ for (const d of inventory.installed) {
90
+ for (const bin of await binNames(d)) {
91
+ const l = binOwners.get(bin) ?? [];
92
+ l.push(d);
93
+ binOwners.set(bin, l);
94
+ }
95
+ }
96
+ for (const m of inventory.manifests) {
97
+ const mRel = posix.relative(root.split("\\").join("/"), m.path.split("\\").join("/"));
98
+ for (const [name, script] of Object.entries(m.scripts)) {
99
+ for (const token of script.split(/[\s;&|()]+/)) {
100
+ const owners = binOwners.get(token);
101
+ if (!owners)
102
+ continue;
103
+ for (const d of owners) {
104
+ if (d.declaredBy.length === 0)
105
+ continue;
106
+ add(d.id, "script-bin", site(mRel, 1, `${name}: ${script}`.slice(0, 160)));
107
+ }
108
+ }
109
+ }
110
+ }
111
+ // stylesheets: @import "tailwindcss"; @plugin "@tailwindcss/typography"
112
+ for (const rel of files) {
113
+ if (!STYLE_EXT.test(rel))
114
+ continue;
115
+ let text;
116
+ try {
117
+ text = await readFile(join(root, rel), "utf8");
118
+ }
119
+ catch {
120
+ continue;
121
+ }
122
+ const re = /@(import|plugin|config|source|use|forward|reference)\s+(?:url\()?\s*["']([^"']+)["']/g;
123
+ for (let m = re.exec(text); m; m = re.exec(text)) {
124
+ const spec = (m[2] ?? "").replace(/^~/, "");
125
+ if (!packageNameOf(spec))
126
+ continue;
127
+ const t = await resolver.resolve(rel, spec);
128
+ const line = text.slice(0, m.index).split("\n").length;
129
+ if (t.kind === "pkg")
130
+ add(t.installedId, "css-import", site(rel, line, m[0]));
131
+ }
132
+ }
133
+ for (const d of inventory.installed) {
134
+ if (CONVENTION_FRAMEWORKS.has(d.name))
135
+ add(d.id, "convention-framework", site(d.declaredBy[0]?.manifest ?? "package.json", 1, d.name));
136
+ }
137
+ return hits;
138
+ }
139
+ async function binNames(d) {
140
+ if (!d.dir)
141
+ return [d.name.split("/").pop()];
142
+ try {
143
+ const pj = JSON.parse(await readFile(join(d.dir, "package.json"), "utf8"));
144
+ if (typeof pj.bin === "string")
145
+ return [(pj.name ?? d.name).split("/").pop()];
146
+ if (pj.bin && typeof pj.bin === "object")
147
+ return Object.keys(pj.bin);
148
+ }
149
+ catch {
150
+ // unreadable manifest
151
+ }
152
+ return [];
153
+ }
154
+ const DEP_BLOCKS = new Set([
155
+ "dependencies",
156
+ "devDependencies",
157
+ "peerDependencies",
158
+ "optionalDependencies",
159
+ "peerDependenciesMeta",
160
+ "bundleDependencies",
161
+ "bundledDependencies",
162
+ "overrides",
163
+ "resolutions",
164
+ "name",
165
+ "scripts",
166
+ "pnpm",
167
+ "workspaces",
168
+ "catalog",
169
+ "catalogs",
170
+ ]);
171
+ function collectStrings(v, out, manifest, depth = 0) {
172
+ if (depth > 20)
173
+ return;
174
+ if (typeof v === "string")
175
+ out.push(v);
176
+ else if (Array.isArray(v))
177
+ for (const x of v)
178
+ collectStrings(x, out, manifest, depth + 1);
179
+ else if (v && typeof v === "object") {
180
+ for (const [k, x] of Object.entries(v)) {
181
+ if (manifest && depth === 0 && DEP_BLOCKS.has(k))
182
+ continue;
183
+ collectStrings(x, out, manifest, depth + 1);
184
+ }
185
+ }
186
+ }
187
+ function lineOfString(text, value) {
188
+ const i = text.indexOf(JSON.stringify(value));
189
+ return i < 0 ? 1 : text.slice(0, i).split("\n").length;
190
+ }
191
+ function site(file, line, text) {
192
+ return { file, line, col: 1, typeOnly: false, text };
193
+ }
@@ -0,0 +1,73 @@
1
+ import type { SourceText } from "./files.ts";
2
+ import type { Binding, ChainSeg } from "../model.ts";
3
+ export interface Pos {
4
+ line: number;
5
+ col: number;
6
+ text: string;
7
+ }
8
+ export interface ImportBinding {
9
+ local: string;
10
+ specifier: string;
11
+ binding: Binding;
12
+ typeOnly: boolean;
13
+ pos: Pos;
14
+ }
15
+ export interface ReExport {
16
+ specifier: string;
17
+ kind: "star" | "named" | "star-as";
18
+ names: {
19
+ imported: string;
20
+ exported: string;
21
+ }[];
22
+ pos: Pos;
23
+ }
24
+ export interface Reference {
25
+ local: string;
26
+ chain: ChainSeg[];
27
+ callSelf: boolean;
28
+ typeOnly: boolean;
29
+ pos: Pos;
30
+ escape: boolean;
31
+ computed: boolean;
32
+ derivedInto?: string;
33
+ callbackInto?: string[];
34
+ }
35
+ export interface InlineUse {
36
+ specifier: string;
37
+ binding: Binding;
38
+ chain: ChainSeg[];
39
+ callSelf: boolean;
40
+ pos: Pos;
41
+ escape: boolean;
42
+ derivedInto?: string;
43
+ callbackInto?: string[];
44
+ }
45
+ export interface FileFacts {
46
+ imports: ImportBinding[];
47
+ sideEffects: {
48
+ specifier: string;
49
+ pos: Pos;
50
+ }[];
51
+ reExports: ReExport[];
52
+ exportedLocals: {
53
+ local: string;
54
+ exported: string;
55
+ }[];
56
+ declaredExports: string[];
57
+ references: Reference[];
58
+ inline: InlineUse[];
59
+ nonLiteralRequire: Pos[];
60
+ nonLiteralImport: Pos[];
61
+ prefixImports: {
62
+ prefix: string;
63
+ pos: Pos;
64
+ }[];
65
+ stringLiterals: {
66
+ value: string;
67
+ pos: Pos;
68
+ }[];
69
+ unparseable: boolean;
70
+ }
71
+ export declare const SCANNER_VERSION = 2;
72
+ export declare function parseSource(src: SourceText): FileFacts;
73
+ //# sourceMappingURL=parse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.d.ts","sourceRoot":"","s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