@cplieger/deadset-ts 8.0.0-dev.15 → 8.0.0-dev.17

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 (207) hide show
  1. package/dist/src/alias-chain.js +0 -5
  2. package/dist/src/amd.js +81 -0
  3. package/dist/src/analysis.js +94 -54
  4. package/dist/src/augmentations.js +23 -24
  5. package/dist/src/bindings.js +382 -0
  6. package/dist/src/calls.js +25 -8
  7. package/dist/src/commands/read.js +6 -7
  8. package/dist/src/commands/tools.js +5 -9
  9. package/dist/src/component-files.js +3 -2
  10. package/dist/src/conformance-record.js +1 -1
  11. package/dist/src/consumers.js +9 -10
  12. package/dist/src/contextual-uses.js +1 -17
  13. package/dist/src/contract/config.generated.js +5 -2
  14. package/dist/src/contract/contract.generated.js +119 -2
  15. package/dist/src/contract/report.generated.js +6 -2
  16. package/dist/src/dependencies.js +98 -71
  17. package/dist/src/destructuring.js +1 -19
  18. package/dist/src/element-access.js +179 -164
  19. package/dist/src/entries/build-scripts.js +222 -0
  20. package/dist/src/{configuration-files.js → entries/configuration-files.js} +22 -64
  21. package/dist/src/{convention-rows.js → entries/convention-rows.js} +120 -27
  22. package/dist/src/entries/conventions.js +739 -0
  23. package/dist/src/{html-entries.js → entries/html-entries.js} +9 -12
  24. package/dist/src/{mdx-entries.js → entries/mdx-entries.js} +3 -3
  25. package/dist/src/entries/run-directories.js +77 -0
  26. package/dist/src/entries/sources.js +144 -0
  27. package/dist/src/entries/static-module.js +670 -0
  28. package/dist/src/entries/test-runners.js +684 -0
  29. package/dist/src/{workflow-steps.js → entries/workflow-steps.js} +18 -8
  30. package/dist/src/extensions.js +37 -0
  31. package/dist/src/facts.js +38 -0
  32. package/dist/src/findings/completion.js +40 -4
  33. package/dist/src/findings/emitters.js +5 -8
  34. package/dist/src/{implementations.js → findings/implementations.js} +3 -3
  35. package/dist/src/{in-operands.js → findings/in-operands.js} +2 -2
  36. package/dist/src/findings/self-check.js +36 -20
  37. package/dist/src/findings-pass.js +5 -6
  38. package/dist/src/framework-lifecycle.js +42 -15
  39. package/dist/src/fs/manifest.js +15 -20
  40. package/dist/src/generated-file.js +172 -29
  41. package/dist/src/graph.js +14 -8
  42. package/dist/src/import-bindings.js +73 -28
  43. package/dist/src/index/sites.js +557 -0
  44. package/dist/src/index.js +1 -1
  45. package/dist/src/indexed-access.js +523 -478
  46. package/dist/src/injection-container.js +1 -1
  47. package/dist/src/interface-satisfaction.js +1 -1
  48. package/dist/src/inventory/commonjs.js +62 -17
  49. package/dist/src/inventory/enumerate.js +2 -1
  50. package/dist/src/javascript-file.js +26 -11
  51. package/dist/src/keyof-comparisons.js +124 -103
  52. package/dist/src/load/classify.js +28 -9
  53. package/dist/src/load/diagnostics.js +8 -1
  54. package/dist/src/load/discover.js +15 -7
  55. package/dist/src/load/expected-module.js +2 -2
  56. package/dist/src/load/plan.js +2 -2
  57. package/dist/src/load/specifiers.js +2 -4
  58. package/dist/src/load/synthesize.js +10 -5
  59. package/dist/src/load/workspace-manifests.js +1 -1
  60. package/dist/src/load/workspace-resolution.js +2 -2
  61. package/dist/src/matrix.js +12 -17
  62. package/dist/src/module-declarations.js +70 -85
  63. package/dist/src/overrides.js +134 -112
  64. package/dist/src/paths.js +56 -1
  65. package/dist/src/platform-calls.js +78 -0
  66. package/dist/src/platform-symbols.js +134 -0
  67. package/dist/src/references/read-rule.js +1 -0
  68. package/dist/src/references/read-rules.js +48 -0
  69. package/dist/src/references/sink.js +151 -0
  70. package/dist/src/references/sources.js +450 -0
  71. package/dist/src/references.js +111 -1116
  72. package/dist/src/resolve.js +1 -1
  73. package/dist/src/{configured-declarations.js → roots/configured-declarations.js} +7 -4
  74. package/dist/src/{entry-point-gaps.js → roots/entry-point-gaps.js} +5 -8
  75. package/dist/src/{manifest.js → roots/manifest.js} +4 -4
  76. package/dist/src/roots/published-reach.js +412 -0
  77. package/dist/src/roots/root-set.js +489 -0
  78. package/dist/src/roots/unseen-loads.js +236 -0
  79. package/dist/src/serialization-contract.js +9 -4
  80. package/dist/src/source-files.js +5 -9
  81. package/dist/src/stores.js +4 -2
  82. package/dist/src/suppress.js +30 -32
  83. package/dist/src/sweep.js +25 -13
  84. package/dist/src/symbol-keys.js +89 -83
  85. package/dist/src/tests/file-class.js +76 -0
  86. package/dist/src/{outside-tests.js → tests/outside.js} +7 -7
  87. package/dist/src/{test-support.js → tests/support.js} +5 -12
  88. package/dist/src/type-parameter-reads.js +178 -139
  89. package/dist/src/unimplemented-callees.js +262 -242
  90. package/dist/src/verbs/analyze.js +15 -3
  91. package/dist/src/verbs/describe.js +5 -3
  92. package/dist/src/verbs/explain.js +50 -28
  93. package/dist/src/verbs/print-retained.js +2 -2
  94. package/jsr.json +1 -1
  95. package/package.json +3 -3
  96. package/src/alias-chain.ts +0 -7
  97. package/src/amd.ts +130 -0
  98. package/src/analysis.ts +156 -70
  99. package/src/augmentations.ts +41 -27
  100. package/src/automatic-types.ts +1 -1
  101. package/src/bindings.ts +460 -0
  102. package/src/calls.ts +25 -7
  103. package/src/commands/read.ts +6 -8
  104. package/src/commands/tools.ts +5 -11
  105. package/src/component-files.ts +4 -2
  106. package/src/conformance-record.ts +1 -1
  107. package/src/consumers.ts +12 -11
  108. package/src/contextual-uses.ts +2 -22
  109. package/src/contract/config.generated.ts +5 -2
  110. package/src/contract/contract.generated.ts +138 -2
  111. package/src/contract/report.generated.ts +6 -2
  112. package/src/dependencies.ts +117 -71
  113. package/src/destructuring.ts +1 -31
  114. package/src/element-access.ts +188 -182
  115. package/src/entries/build-scripts.ts +292 -0
  116. package/src/{configuration-files.ts → entries/configuration-files.ts} +33 -82
  117. package/src/{convention-rows.ts → entries/convention-rows.ts} +167 -28
  118. package/src/{conventions.ts → entries/conventions.ts} +349 -523
  119. package/src/{html-entries.ts → entries/html-entries.ts} +19 -18
  120. package/src/{mdx-entries.ts → entries/mdx-entries.ts} +5 -5
  121. package/src/entries/run-directories.ts +108 -0
  122. package/src/entries/sources.ts +266 -0
  123. package/src/entries/static-module.ts +858 -0
  124. package/src/entries/test-runners.ts +868 -0
  125. package/src/{workflow-steps.ts → entries/workflow-steps.ts} +29 -11
  126. package/src/exempt.ts +3 -2
  127. package/src/extensions.ts +45 -0
  128. package/src/facts.ts +46 -0
  129. package/src/file-facts.ts +1 -1
  130. package/src/findings/boundary.ts +2 -0
  131. package/src/findings/completion.ts +43 -4
  132. package/src/findings/emitter.ts +1 -1
  133. package/src/findings/emitters.ts +14 -10
  134. package/src/{implementations.ts → findings/implementations.ts} +4 -4
  135. package/src/{in-operands.ts → findings/in-operands.ts} +3 -3
  136. package/src/findings/self-check.ts +41 -22
  137. package/src/findings/visibility-narrowing.ts +1 -1
  138. package/src/findings-pass.ts +5 -12
  139. package/src/framework-lifecycle.ts +43 -15
  140. package/src/fs/manifest.ts +25 -21
  141. package/src/generated-file.ts +240 -36
  142. package/src/graph.ts +27 -11
  143. package/src/import-bindings.ts +98 -29
  144. package/src/index/sites.ts +781 -0
  145. package/src/index.ts +1 -1
  146. package/src/indexed-access.ts +570 -527
  147. package/src/injection-container.ts +1 -1
  148. package/src/interface-satisfaction.ts +1 -1
  149. package/src/inventory/commonjs.ts +102 -17
  150. package/src/inventory/enumerate.ts +2 -1
  151. package/src/javascript-file.ts +29 -12
  152. package/src/keyof-comparisons.ts +131 -116
  153. package/src/load/classify.ts +49 -13
  154. package/src/load/diagnostics.ts +11 -1
  155. package/src/load/discover.ts +27 -11
  156. package/src/load/expected-module.ts +8 -2
  157. package/src/load/plan.ts +11 -2
  158. package/src/load/specifiers.ts +8 -5
  159. package/src/load/synthesize.ts +12 -6
  160. package/src/load/test-globals.ts +1 -1
  161. package/src/load/workspace-manifests.ts +1 -1
  162. package/src/load/workspace-resolution.ts +9 -2
  163. package/src/load/workspace-run.ts +1 -1
  164. package/src/matrix.ts +13 -17
  165. package/src/module-declarations.ts +74 -98
  166. package/src/overrides.ts +162 -134
  167. package/src/paths.ts +65 -1
  168. package/src/platform-calls.ts +119 -0
  169. package/src/platform-symbols.ts +189 -0
  170. package/src/references/read-rule.ts +60 -0
  171. package/src/references/read-rules.ts +55 -0
  172. package/src/references/sink.ts +213 -0
  173. package/src/references/sources.ts +632 -0
  174. package/src/references.ts +174 -1492
  175. package/src/report.ts +2 -2
  176. package/src/resolve.ts +1 -1
  177. package/src/{configured-declarations.ts → roots/configured-declarations.ts} +10 -7
  178. package/src/{entry-point-gaps.ts → roots/entry-point-gaps.ts} +5 -8
  179. package/src/{manifest.ts → roots/manifest.ts} +5 -5
  180. package/src/roots/published-reach.ts +481 -0
  181. package/src/{roots.ts → roots/root-set.ts} +203 -630
  182. package/src/roots/unseen-loads.ts +345 -0
  183. package/src/serialization-contract.ts +9 -4
  184. package/src/source-files.ts +5 -10
  185. package/src/stores.ts +13 -2
  186. package/src/suppress.ts +48 -33
  187. package/src/sweep.ts +37 -14
  188. package/src/symbol-keys.ts +102 -102
  189. package/src/tests/file-class.ts +118 -0
  190. package/src/{outside-tests.ts → tests/outside.ts} +16 -10
  191. package/src/{test-support.ts → tests/support.ts} +15 -21
  192. package/src/type-parameter-reads.ts +187 -158
  193. package/src/unimplemented-callees.ts +297 -280
  194. package/src/verbs/analyze.ts +19 -5
  195. package/src/verbs/describe.ts +5 -2
  196. package/src/verbs/explain.ts +75 -32
  197. package/src/verbs/print-retained.ts +2 -2
  198. package/dist/src/build-scripts.js +0 -418
  199. package/dist/src/conventions.js +0 -907
  200. package/dist/src/entry-points.js +0 -444
  201. package/dist/src/own-body.js +0 -28
  202. package/dist/src/roots.js +0 -865
  203. package/dist/src/unseen-loads.js +0 -189
  204. package/src/build-scripts.ts +0 -536
  205. package/src/entry-points.ts +0 -584
  206. package/src/own-body.ts +0 -42
  207. package/src/unseen-loads.ts +0 -282
@@ -0,0 +1,292 @@
1
+ /**
2
+ * The files a bundler's JavaScript API builds from, read from the build scripts a
3
+ * manifest's scripts run: the strings an options object passes as the bundler's entries.
4
+ * A script is read without running it, so a value that is not written out, a computed
5
+ * path or an options object built at run time among them, names nothing.
6
+ */
7
+
8
+ import {
9
+ isArrowFunction,
10
+ isCallExpression,
11
+ isConstructorDeclaration,
12
+ isFunctionDeclaration,
13
+ isFunctionExpression,
14
+ isGetAccessorDeclaration,
15
+ isIdentifier,
16
+ isMethodDeclaration,
17
+ isNewExpression,
18
+ isSetAccessorDeclaration,
19
+ isVariableDeclaration,
20
+ type CallExpression,
21
+ type Node,
22
+ type SourceFile,
23
+ } from "@typescript/native/ast";
24
+ import { declarationOf, membersNamed, staticModule, type Value } from "./static-module.ts";
25
+ import { filesNamedBy, type ParseFile } from "./configuration-files.ts";
26
+ import type { Host } from "../host.ts";
27
+ import { ancestors, dirnamePath, isExplicitPath, relativePath, resolvePath } from "../paths.ts";
28
+ import type { SourceFiles } from "../source-files.ts";
29
+ import { bytewise } from "../text/compare.ts";
30
+ import { unwrapped } from "../unwrap.ts";
31
+ import { holdsManifest, inInstalledPackages, manifestAt } from "../fs/manifest.ts";
32
+ import { globExpression } from "../text/glob.ts";
33
+ import { pathsNamed, readCommands } from "../commands/read.ts";
34
+ import { manifestCommands } from "../roots/manifest.ts";
35
+ import { extensionOf, MODULE_EXTENSIONS } from "../extensions.ts";
36
+
37
+ /** One bundler API: the module, the functions it exports that build, and the option naming entries. */
38
+ interface BundlerAPI {
39
+ readonly module: string;
40
+ /** The exported names of the building functions; `default` is the module's own value called. */
41
+ readonly calls: readonly string[];
42
+ /** The option whose strings name the entries, read as `entries` states. */
43
+ readonly option: string;
44
+ /** The option that moves the directory the entries are read against. */
45
+ readonly base: string;
46
+ /** Whether an entry string is a path, glob characters matching, or a module request, only a relative one naming a file. */
47
+ readonly paths: boolean;
48
+ }
49
+
50
+ /**
51
+ * The bundlers whose build call names its entries: esbuild resolves `entryPoints` against
52
+ * `absWorkingDir` (https://esbuild.github.io/api/#working-directory), webpack `entry`
53
+ * against `context` (https://webpack.js.org/configuration/entry-context/), and Rollup
54
+ * `input` against the working directory, each the manifest's directory when its script runs.
55
+ */
56
+ const BUNDLERS: readonly BundlerAPI[] = [
57
+ {
58
+ module: "esbuild",
59
+ calls: ["build", "buildSync", "context"],
60
+ option: "entryPoints",
61
+ base: "absWorkingDir",
62
+ paths: true,
63
+ },
64
+ { module: "webpack", calls: ["default"], option: "entry", base: "context", paths: false },
65
+ { module: "rollup", calls: ["rollup", "watch"], option: "input", base: "", paths: true },
66
+ ];
67
+
68
+ /** One own file a build script's bundler call names as an entry. */
69
+ interface BuildEntry {
70
+ readonly file: SourceFile;
71
+ /** The string that named it. */
72
+ readonly source: string;
73
+ }
74
+
75
+ /** One path an entry value writes. */
76
+ interface EntryPath {
77
+ readonly path: string;
78
+ /** What the script writes for it. */
79
+ readonly text: string;
80
+ /** Whether it is written as neither a relative nor an absolute path. */
81
+ readonly request: boolean;
82
+ }
83
+
84
+ /** The one value an object writes last for a key, undefined where it writes none or may hide it. */
85
+ function lastMember(object: Value, key: string): Value | undefined {
86
+ return membersNamed(object, key)?.at(-1);
87
+ }
88
+
89
+ /**
90
+ * The path one entry value writes, read against `dir`: a literal, or a join of the
91
+ * script's own directory and literals, read against that directory.
92
+ */
93
+ function pathOf(value: Value, dir: string, scriptDir: string): EntryPath | undefined {
94
+ if (value.kind === "text") {
95
+ const { text } = value;
96
+ const request = !isExplicitPath(text);
97
+ return { path: resolvePath(dir, text), text, request };
98
+ }
99
+ if (value.kind === "directory") {
100
+ const joined = value.segments.join("/");
101
+ return { path: resolvePath(scriptDir, joined), text: joined, request: false };
102
+ }
103
+ return undefined;
104
+ }
105
+
106
+ /** The entry values one entries option writes: a value, an array of them, an object of them. */
107
+ function entryValues(value: Value): readonly Value[] {
108
+ if (value.kind === "array") {
109
+ return value.elements.flatMap(entryValues);
110
+ }
111
+ if (value.kind === "object") {
112
+ const imported = lastMember(value, "import") ?? lastMember(value, "in");
113
+ if (imported !== undefined) {
114
+ return entryValues(imported);
115
+ }
116
+ return value.members.flatMap((member) => entryValues(member.value));
117
+ }
118
+ return [value];
119
+ }
120
+
121
+ /** The own files one entry string names, read as `api` reads it. */
122
+ function entriesNamed(
123
+ files: SourceFiles,
124
+ api: BundlerAPI,
125
+ entry: EntryPath,
126
+ ): readonly SourceFile[] {
127
+ if (!api.paths && entry.request) {
128
+ return [];
129
+ }
130
+ if (api.paths && /[*?[{]/u.test(entry.text)) {
131
+ const expression = globExpression(entry.path);
132
+ return [...files.byName.values()].filter((file) => expression.test(file.fileName));
133
+ }
134
+ const dir = dirnamePath(entry.path);
135
+ return filesNamedBy(files, dir, entry.path.slice(dir.length + 1));
136
+ }
137
+
138
+ /** Whether one node is a function, whose body runs only where something calls it. */
139
+ function isFunction(node: Node): boolean {
140
+ return (
141
+ isFunctionDeclaration(node) ||
142
+ isFunctionExpression(node) ||
143
+ isArrowFunction(node) ||
144
+ isMethodDeclaration(node) ||
145
+ isConstructorDeclaration(node) ||
146
+ isGetAccessorDeclaration(node) ||
147
+ isSetAccessorDeclaration(node)
148
+ );
149
+ }
150
+
151
+ /**
152
+ * The calls one build script runs: those of its top level, and those of each function a
153
+ * call it runs calls or passes on, as a callee, an argument or a function called where it
154
+ * is written, a name read through to the function it declares.
155
+ */
156
+ function runCalls(file: SourceFile, each: (call: CallExpression) => void): void {
157
+ const ran = new Set<Node>();
158
+ const run = (fn: Node): void => {
159
+ if (!ran.has(fn)) {
160
+ ran.add(fn);
161
+ fn.forEachChild(visit);
162
+ }
163
+ };
164
+ const runs = (node: Node): void => {
165
+ const at = unwrapped(node);
166
+ const declared = isIdentifier(at) ? declarationOf(at) : undefined;
167
+ const fn =
168
+ declared !== undefined && isVariableDeclaration(declared) && declared.initializer
169
+ ? unwrapped(declared.initializer)
170
+ : (declared ?? at);
171
+ if (isFunction(fn)) {
172
+ run(fn);
173
+ }
174
+ };
175
+ const visit = (node: Node): void => {
176
+ if (isFunction(node)) {
177
+ return;
178
+ }
179
+ if (isCallExpression(node) || isNewExpression(node)) {
180
+ if (isCallExpression(node)) {
181
+ each(node);
182
+ }
183
+ runs(node.expression);
184
+ for (const argument of node.arguments ?? []) {
185
+ runs(argument);
186
+ }
187
+ }
188
+ node.forEachChild(visit);
189
+ };
190
+ file.forEachChild(visit);
191
+ }
192
+
193
+ /** The entries every bundler call one build script runs names, read against `dir`. */
194
+ function scriptEntries(file: SourceFile, dir: string, files: SourceFiles): readonly BuildEntry[] {
195
+ const module = staticModule(file);
196
+ const building = new Map<CallExpression, BundlerAPI>();
197
+ for (const api of BUNDLERS) {
198
+ for (const one of module.calls(api.module)) {
199
+ if (api.calls.includes(one.export)) {
200
+ building.set(one.call, api);
201
+ }
202
+ }
203
+ }
204
+ const scriptDir = dirnamePath(file.fileName);
205
+ const found: BuildEntry[] = [];
206
+ runCalls(file, (call) => {
207
+ const api = building.get(call);
208
+ if (api === undefined) {
209
+ return;
210
+ }
211
+ for (const options of module.argument(call)) {
212
+ const entries = lastMember(options, api.option);
213
+ const base = api.base === "" ? undefined : lastMember(options, api.base);
214
+ const against = base === undefined ? { path: dir } : pathOf(base, dir, scriptDir);
215
+ if (entries === undefined || against === undefined) {
216
+ continue;
217
+ }
218
+ for (const value of entryValues(entries)) {
219
+ const named = pathOf(value, against.path, scriptDir);
220
+ if (named === undefined) {
221
+ continue;
222
+ }
223
+ for (const entry of entriesNamed(files, api, named)) {
224
+ found.push({ file: entry, source: named.text });
225
+ }
226
+ }
227
+ }
228
+ });
229
+ return found;
230
+ }
231
+
232
+ /** The modules one manifest's command strings run or name, by absolute path, each below the target root. */
233
+ function scriptModules(host: Host, root: string, dir: string): readonly string[] {
234
+ const manifest = manifestAt(host, dir);
235
+ const found = new Set<string>();
236
+ for (const { command } of manifest === undefined ? [] : manifestCommands(host, dir, manifest)) {
237
+ for (const { path } of pathsNamed(readCommands(command, dir))) {
238
+ if (
239
+ extensionOf(path, MODULE_EXTENSIONS) !== undefined &&
240
+ relativePath(root, path) !== undefined &&
241
+ !inInstalledPackages(path) &&
242
+ host.kindOf(path) === "file"
243
+ ) {
244
+ found.add(path);
245
+ }
246
+ }
247
+ }
248
+ return [...found].sort(bytewise);
249
+ }
250
+
251
+ /**
252
+ * Every own file of one project a build script names as a bundler's entry: a module a
253
+ * script of a manifest at or above an own file runs, below the target root, read from
254
+ * the program where it holds the module and parsed alone otherwise, where a parser is given.
255
+ */
256
+ export function buildScriptEntries(
257
+ host: Host,
258
+ targetRoot: string,
259
+ files: SourceFiles,
260
+ parse: ParseFile | undefined,
261
+ ): readonly BuildEntry[] {
262
+ const root = resolvePath(host.workingDirectory(), targetRoot);
263
+ const dirs = new Set<string>([root]);
264
+ for (const file of files.byName.values()) {
265
+ for (const dir of ancestors(dirnamePath(file.fileName), root)) {
266
+ if (dirs.has(dir)) {
267
+ break;
268
+ }
269
+ dirs.add(dir);
270
+ }
271
+ }
272
+ const found: BuildEntry[] = [];
273
+ for (const dir of [...dirs].sort(bytewise)) {
274
+ if (!holdsManifest(host, dir)) {
275
+ continue;
276
+ }
277
+ for (const path of scriptModules(host, root, dir)) {
278
+ let script = files.byName.get(path);
279
+ if (script === undefined && parse !== undefined) {
280
+ try {
281
+ script = parse(path, host.readFile(path));
282
+ } catch {
283
+ continue;
284
+ }
285
+ }
286
+ if (script !== undefined) {
287
+ found.push(...scriptEntries(script, dir, files));
288
+ }
289
+ }
290
+ }
291
+ return found;
292
+ }
@@ -8,37 +8,48 @@
8
8
  */
9
9
 
10
10
  import {
11
- isCallExpression,
12
- isExportDeclaration,
13
- isIdentifier,
14
- isImportDeclaration,
15
11
  isNoSubstitutionTemplateLiteral,
16
12
  isStringLiteral,
17
- SyntaxKind,
18
13
  type Node,
19
14
  type SourceFile,
20
15
  } from "@typescript/native/ast";
21
- import type { Host } from "./host.ts";
22
- import { ancestors, dirnamePath, joinPath, relativePath, resolvePath } from "./paths.ts";
23
- import type { SourceFiles } from "./source-files.ts";
24
- import { bytewise } from "./text/compare.ts";
25
- import { isRecord } from "./json-document.ts";
26
- import { filesIn } from "./fs/tree.ts";
16
+ import { relativeSpecifiers } from "./static-module.ts";
17
+ import type { Host } from "../host.ts";
18
+ import {
19
+ ancestors,
20
+ dirnamePath,
21
+ isAbsolutePath,
22
+ joinPath,
23
+ relativePath,
24
+ resolvePath,
25
+ startsRelativePath,
26
+ } from "../paths.ts";
27
+ import type { SourceFiles } from "../source-files.ts";
28
+ import { bytewise } from "../text/compare.ts";
29
+ import { isRecord } from "../json-document.ts";
30
+ import { filesIn } from "../fs/tree.ts";
27
31
  import {
28
32
  DEPENDENCY_SECTIONS,
29
33
  holdsManifest,
30
34
  inInstalledPackages,
31
35
  manifestAt,
32
36
  readJSON,
33
- } from "./fs/manifest.ts";
34
- import { readCommands } from "./commands/read.ts";
35
- import { manifestCommands } from "./manifest.ts";
37
+ } from "../fs/manifest.ts";
38
+ import { readCommands } from "../commands/read.ts";
39
+ import { manifestCommands } from "../roots/manifest.ts";
40
+ import { APPENDED_EXTENSIONS, extensionOf, MODULE_EXTENSIONS } from "../extensions.ts";
41
+
42
+ /** The extensions of a configuration module, as an expression's alternatives. */
43
+ const MODULE_NAME = MODULE_EXTENSIONS.map((one) => one.slice(1)).join("|");
36
44
 
37
45
  /** A configuration module's name, each form with the spelling a root reports it by. */
38
46
  const MODULE_FORMS: readonly { readonly name: RegExp; readonly form: string }[] = [
39
- { name: /^[\w-]+\.config\.(?:js|mjs|cjs|ts|mts|cts)$/u, form: "<stem>.config.<ext>" },
40
47
  {
41
- name: /^[\w-]+\.[\w-]+\.config\.(?:js|mjs|cjs|ts|mts|cts)$/u,
48
+ name: new RegExp(String.raw`^[\w-]+\.config\.(?:${MODULE_NAME})$`, "u"),
49
+ form: "<stem>.config.<ext>",
50
+ },
51
+ {
52
+ name: new RegExp(String.raw`^[\w-]+\.[\w-]+\.config\.(?:${MODULE_NAME})$`, "u"),
42
53
  form: "<stem>.<qualifier>.config.<ext>",
43
54
  },
44
55
  { name: /^\.[\w-]+rc\.(?:js|mjs|cjs)$/u, form: ".<stem>rc.<ext>" },
@@ -47,9 +58,6 @@ const MODULE_FORMS: readonly { readonly name: RegExp; readonly form: string }[]
47
58
  /** A JSON configuration file's name. */
48
59
  const DOCUMENT_NAME = /^(?:[\w-]+(?:\.[\w-]+)?\.config\.json|\.[\w-]+rc(?:\.json)?)$/u;
49
60
 
50
- /** The prefixes a string names a file with, relative to the file that writes it. */
51
- const RELATIVE_PREFIXES = ["./", "../"] as const;
52
-
53
61
  /** The JavaScript extensions a relative specifier from a configuration file stands for TypeScript under. */
54
62
  const COUNTERPARTS: readonly (readonly [string, readonly string[]])[] = [
55
63
  [".js", [".ts", ".tsx"]],
@@ -58,9 +66,6 @@ const COUNTERPARTS: readonly (readonly [string, readonly string[]])[] = [
58
66
  [".cjs", [".cts"]],
59
67
  ];
60
68
 
61
- /** The extensions appended to a relative specifier from a configuration file, in order. */
62
- const APPENDED = [".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mjs", ".cjs"] as const;
63
-
64
69
  /** The extensions the program's module resolution appends to a specifier written without one. */
65
70
  export const RESOLVED_EXTENSIONS = [
66
71
  ".ts",
@@ -116,9 +121,6 @@ export interface OutsideModule {
116
121
  readonly manifestDirs: readonly string[];
117
122
  }
118
123
 
119
- /** The extensions of a module a configuration flag may name. */
120
- const MODULE_EXTENSIONS = [".js", ".mjs", ".cjs", ".ts", ".mts", ".cts"] as const;
121
-
122
124
  /**
123
125
  * The files the command strings of the manifest in one directory name after a configuration
124
126
  * flag, as `commands/read.ts` reads them against the directory each command runs in, each a
@@ -143,7 +145,7 @@ function scriptConfigurations(host: Host, root: string, dir: string): readonly s
143
145
  }
144
146
 
145
147
  /** The configuration files one project holds and sits beside. */
146
- interface ConfigurationFiles {
148
+ export interface ConfigurationFiles {
147
149
  /**
148
150
  * Every own file that is a configuration module, with the form its name has and the
149
151
  * directory of the manifest whose dependencies its strings are read against.
@@ -273,9 +275,7 @@ export function configurationFiles(
273
275
  }
274
276
  document.manifestDirs.push(next.manifestDir);
275
277
  for (const text of document.strings) {
276
- const path = RELATIVE_PREFIXES.some((prefix) => text.startsWith(prefix))
277
- ? resolvePath(dirnamePath(next.path), text)
278
- : undefined;
278
+ const path = startsRelativePath(text) ? resolvePath(dirnamePath(next.path), text) : undefined;
279
279
  if (
280
280
  path?.endsWith(".json") === true &&
281
281
  isProjectPath(root, path) &&
@@ -295,55 +295,6 @@ export function configurationFiles(
295
295
  };
296
296
  }
297
297
 
298
- /** The literal module specifier one `require(...)` or `import(...)` call names, if any. */
299
- function calledSpecifier(node: Node): Node | undefined {
300
- if (!isCallExpression(node) || node.arguments.length !== 1) {
301
- return undefined;
302
- }
303
- const callee = node.expression;
304
- const loads =
305
- callee.kind === SyntaxKind.ImportKeyword || (isIdentifier(callee) && callee.text === "require");
306
- return loads ? node.arguments[0] : undefined;
307
- }
308
-
309
- /**
310
- * The relative specifiers one file's imports and re-exports name, and those its
311
- * `require(...)` and `import(...)` calls name by a literal.
312
- */
313
- export function relativeSpecifiers(file: SourceFile): readonly string[] {
314
- const known = specifiersOf.get(file);
315
- if (known !== undefined) {
316
- return known;
317
- }
318
- const found: string[] = [];
319
- const named = (specifier: Node | undefined): void => {
320
- if (
321
- specifier !== undefined &&
322
- (isStringLiteral(specifier) || isNoSubstitutionTemplateLiteral(specifier)) &&
323
- RELATIVE_PREFIXES.some((prefix) => specifier.text.startsWith(prefix))
324
- ) {
325
- found.push(specifier.text);
326
- }
327
- };
328
- const visit = (node: Node): void => {
329
- named(calledSpecifier(node));
330
- node.forEachChild(visit);
331
- };
332
- for (const statement of file.statements) {
333
- named(
334
- isImportDeclaration(statement) || isExportDeclaration(statement)
335
- ? statement.moduleSpecifier
336
- : undefined,
337
- );
338
- visit(statement);
339
- }
340
- specifiersOf.set(file, found);
341
- return found;
342
- }
343
-
344
- /** What {@link relativeSpecifiers} found in each file, which every project of a run reads alike. */
345
- const specifiersOf = new WeakMap<SourceFile, readonly string[]>();
346
-
347
298
  /**
348
299
  * The files no program holds that a chain from `seeds` reads: each seed, and each file
349
300
  * below the target root one imports, re-exports or loads by a relative specifier that no
@@ -371,7 +322,7 @@ export function outsideChain(
371
322
  export function specifierCandidates(dir: string, specifier: string): readonly string[] {
372
323
  const path = resolvePath(dir, specifier);
373
324
  const candidates: string[] = [];
374
- if (APPENDED.some((extension) => path.endsWith(extension))) {
325
+ if (extensionOf(path, APPENDED_EXTENSIONS) !== undefined) {
375
326
  candidates.push(path);
376
327
  }
377
328
  for (const [extension, counterparts] of COUNTERPARTS) {
@@ -380,8 +331,8 @@ export function specifierCandidates(dir: string, specifier: string): readonly st
380
331
  candidates.push(...counterparts.map((one) => stem + one));
381
332
  }
382
333
  }
383
- candidates.push(...APPENDED.map((extension) => path + extension));
384
- candidates.push(...APPENDED.map((extension) => joinPath(path, `index${extension}`)));
334
+ candidates.push(...APPENDED_EXTENSIONS.map((extension) => path + extension));
335
+ candidates.push(...APPENDED_EXTENSIONS.map((extension) => joinPath(path, `index${extension}`)));
385
336
  return candidates;
386
337
  }
387
338
 
@@ -477,7 +428,7 @@ export function dependenciesNamed(text: string, declared: readonly string[]): re
477
428
  * none.
478
429
  */
479
430
  export function filesNamedBy(files: SourceFiles, dir: string, text: string): readonly SourceFile[] {
480
- if (text === "" || text.startsWith("/") || /[*?[{]/u.test(text)) {
431
+ if (text === "" || isAbsolutePath(text) || /[*?[{]/u.test(text)) {
481
432
  return [];
482
433
  }
483
434
  const path = resolvePath(dir, text);