@cplieger/deadset-ts 8.0.0-dev.14 → 8.0.0-dev.16

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 (149) hide show
  1. package/dist/src/alias-chain.js +2 -2
  2. package/dist/src/analysis.js +43 -38
  3. package/dist/src/commands/read.js +6 -7
  4. package/dist/src/conformance-record.js +1 -1
  5. package/dist/src/consumers.js +4 -2
  6. package/dist/src/contract/config.generated.js +1 -1
  7. package/dist/src/contract/contract.generated.js +120 -2
  8. package/dist/src/dependencies.js +81 -49
  9. package/dist/src/entries/build-scripts.js +222 -0
  10. package/dist/src/{configuration-files.js → entries/configuration-files.js} +20 -58
  11. package/dist/src/{convention-rows.js → entries/convention-rows.js} +120 -27
  12. package/dist/src/entries/conventions.js +739 -0
  13. package/dist/src/{html-entries.js → entries/html-entries.js} +3 -3
  14. package/dist/src/{mdx-entries.js → entries/mdx-entries.js} +2 -2
  15. package/dist/src/entries/run-directories.js +77 -0
  16. package/dist/src/entries/sources.js +144 -0
  17. package/dist/src/entries/static-module.js +669 -0
  18. package/dist/src/entries/test-runners.js +684 -0
  19. package/dist/src/{workflow-steps.js → entries/workflow-steps.js} +18 -8
  20. package/dist/src/extensions.js +37 -0
  21. package/dist/src/facts.js +38 -0
  22. package/dist/src/file-facts.js +1 -1
  23. package/dist/src/findings/emitters.js +5 -8
  24. package/dist/src/findings/self-check.js +36 -20
  25. package/dist/src/findings-pass.js +5 -6
  26. package/dist/src/framework-lifecycle.js +1 -1
  27. package/dist/src/fs/manifest.js +15 -20
  28. package/dist/src/generated-file.js +172 -29
  29. package/dist/src/graph.js +2 -5
  30. package/dist/src/index.js +1 -1
  31. package/dist/src/injection-container.js +1 -1
  32. package/dist/src/inventory/commonjs.js +507 -0
  33. package/dist/src/inventory/enumerate.js +167 -0
  34. package/dist/src/inventory/syntax.js +236 -0
  35. package/dist/src/inventory.js +305 -705
  36. package/dist/src/javascript-file.js +26 -11
  37. package/dist/src/load/classify.js +28 -9
  38. package/dist/src/load/diagnostics.js +8 -1
  39. package/dist/src/load/discover.js +16 -8
  40. package/dist/src/load/package-scope.js +56 -0
  41. package/dist/src/load/plan.js +2 -2
  42. package/dist/src/load/synthesize.js +5 -5
  43. package/dist/src/load/workspace-manifests.js +1 -1
  44. package/dist/src/matrix.js +6 -13
  45. package/dist/src/outside-tests.js +1 -1
  46. package/dist/src/paths.js +16 -0
  47. package/dist/src/platform-calls.js +78 -0
  48. package/dist/src/platform-symbols.js +140 -0
  49. package/dist/src/position.js +41 -0
  50. package/dist/src/ref.js +11 -20
  51. package/dist/src/references.js +281 -50
  52. package/dist/src/resolve.js +1 -1
  53. package/dist/src/{configured-declarations.js → roots/configured-declarations.js} +4 -4
  54. package/dist/src/{entry-point-gaps.js → roots/entry-point-gaps.js} +5 -8
  55. package/dist/src/{manifest.js → roots/manifest.js} +4 -4
  56. package/dist/src/roots/published-reach.js +412 -0
  57. package/dist/src/roots/root-set.js +489 -0
  58. package/dist/src/roots/unseen-loads.js +208 -0
  59. package/dist/src/serialization-contract.js +1 -1
  60. package/dist/src/session.js +3 -0
  61. package/dist/src/source-files.js +5 -9
  62. package/dist/src/suppress-inline.js +33 -81
  63. package/dist/src/suppress.js +30 -32
  64. package/dist/src/test-support.js +4 -2
  65. package/dist/src/verbs/analyze.js +13 -1
  66. package/dist/src/verbs/describe.js +5 -3
  67. package/jsr.json +1 -1
  68. package/package.json +3 -3
  69. package/src/alias-chain.ts +2 -2
  70. package/src/analysis.ts +77 -53
  71. package/src/automatic-types.ts +1 -1
  72. package/src/commands/read.ts +6 -8
  73. package/src/conformance-record.ts +1 -1
  74. package/src/consumers.ts +5 -1
  75. package/src/contract/config.generated.ts +1 -1
  76. package/src/contract/contract.generated.ts +139 -2
  77. package/src/dependencies.ts +98 -50
  78. package/src/entries/build-scripts.ts +292 -0
  79. package/src/{configuration-files.ts → entries/configuration-files.ts} +23 -75
  80. package/src/{convention-rows.ts → entries/convention-rows.ts} +167 -28
  81. package/src/{conventions.ts → entries/conventions.ts} +347 -522
  82. package/src/{html-entries.ts → entries/html-entries.ts} +5 -5
  83. package/src/{mdx-entries.ts → entries/mdx-entries.ts} +4 -4
  84. package/src/entries/run-directories.ts +108 -0
  85. package/src/entries/sources.ts +266 -0
  86. package/src/entries/static-module.ts +857 -0
  87. package/src/entries/test-runners.ts +868 -0
  88. package/src/{workflow-steps.ts → entries/workflow-steps.ts} +29 -11
  89. package/src/exempt.ts +3 -2
  90. package/src/extensions.ts +45 -0
  91. package/src/facts.ts +44 -0
  92. package/src/file-facts.ts +2 -2
  93. package/src/findings/emitters.ts +14 -10
  94. package/src/findings/self-check.ts +41 -22
  95. package/src/findings/visibility-narrowing.ts +1 -1
  96. package/src/findings-pass.ts +5 -12
  97. package/src/framework-lifecycle.ts +1 -1
  98. package/src/fs/manifest.ts +25 -21
  99. package/src/generated-file.ts +240 -36
  100. package/src/graph.ts +3 -6
  101. package/src/index.ts +1 -1
  102. package/src/injection-container.ts +1 -1
  103. package/src/inventory/commonjs.ts +696 -0
  104. package/src/inventory/enumerate.ts +203 -0
  105. package/src/inventory/syntax.ts +311 -0
  106. package/src/inventory.ts +424 -878
  107. package/src/javascript-file.ts +29 -12
  108. package/src/load/classify.ts +49 -13
  109. package/src/load/diagnostics.ts +11 -1
  110. package/src/load/discover.ts +28 -12
  111. package/src/load/package-scope.ts +74 -0
  112. package/src/load/plan.ts +11 -2
  113. package/src/load/synthesize.ts +6 -6
  114. package/src/load/test-globals.ts +1 -1
  115. package/src/load/workspace-manifests.ts +1 -1
  116. package/src/load/workspace-run.ts +1 -1
  117. package/src/matrix.ts +7 -14
  118. package/src/outside-tests.ts +1 -1
  119. package/src/paths.ts +18 -0
  120. package/src/platform-calls.ts +119 -0
  121. package/src/platform-symbols.ts +205 -0
  122. package/src/position.ts +42 -0
  123. package/src/ref.ts +11 -20
  124. package/src/references.ts +383 -73
  125. package/src/report.ts +1 -1
  126. package/src/resolve.ts +1 -1
  127. package/src/{configured-declarations.ts → roots/configured-declarations.ts} +7 -7
  128. package/src/{entry-point-gaps.ts → roots/entry-point-gaps.ts} +5 -8
  129. package/src/{manifest.ts → roots/manifest.ts} +5 -5
  130. package/src/roots/published-reach.ts +481 -0
  131. package/src/{roots.ts → roots/root-set.ts} +203 -630
  132. package/src/roots/unseen-loads.ts +307 -0
  133. package/src/serialization-contract.ts +1 -1
  134. package/src/session.ts +17 -1
  135. package/src/source-files.ts +5 -10
  136. package/src/suppress-inline.ts +53 -89
  137. package/src/suppress.ts +48 -33
  138. package/src/test-support.ts +8 -3
  139. package/src/verbs/analyze.ts +17 -4
  140. package/src/verbs/describe.ts +5 -2
  141. package/src/verbs/explain.ts +1 -1
  142. package/dist/src/build-scripts.js +0 -418
  143. package/dist/src/conventions.js +0 -907
  144. package/dist/src/entry-points.js +0 -513
  145. package/dist/src/roots.js +0 -865
  146. package/dist/src/unseen-loads.js +0 -100
  147. package/src/build-scripts.ts +0 -536
  148. package/src/entry-points.ts +0 -661
  149. package/src/unseen-loads.ts +0 -134
@@ -1,513 +0,0 @@
1
- /**
2
- * The files a tool or the platform enters without any import naming them: the
3
- * configuration files a tool loads by their file name and the files their strings
4
- * name, the test files the runner executes, and a worker a call addresses by a string
5
- * literal.
6
- *
7
- * Each rule is read from the program and nothing else: a file name the tool
8
- * itself looks for, a literal written in a configuration file, or a literal
9
- * argument of a call the checker resolves to the platform's own declaration. A
10
- * value that is not a literal is not evaluated and not guessed, so a file it would
11
- * have named is entered by nothing here.
12
- */
13
- import { isArrayLiteralExpression, isCallExpression, isExportAssignment, isIdentifier, isMetaProperty, isNewExpression, isNoSubstitutionTemplateLiteral, isObjectLiteralExpression, isPropertyAccessExpression, isPropertyAssignment, isStringLiteral, SyntaxKind, } from "@typescript/native/ast";
14
- import { SymbolFlags } from "@typescript/native/sync";
15
- import { configurationFiles, filesNamedBy, moduleStrings, } from "./configuration-files.js";
16
- import { buildScriptEntries } from "./build-scripts.js";
17
- import { htmlEntries } from "./html-entries.js";
18
- import { documentEntries } from "./mdx-entries.js";
19
- import { dirnamePath, relativePath, resolvePath } from "./paths.js";
20
- import { UNANSWERED } from "./query.js";
21
- import { computedLoadDirectory, leadingLiteral } from "./unseen-loads.js";
22
- import { workflowEntries } from "./workflow-steps.js";
23
- import { unwrapped } from "./unwrap.js";
24
- import { globExpression } from "./text/glob.js";
25
- /** The extensions the test runner and the browser-test runner load a configuration from. */
26
- const MODULE_EXTENSIONS = ["js", "mjs", "cjs", "ts", "mts", "cts"];
27
- /** The tool file names the configuration form does not cover. */
28
- const CONVENTIONS = [
29
- {
30
- rule: "test-runner",
31
- stems: ["vitest.workspace", "vitest.projects"],
32
- extensions: MODULE_EXTENSIONS,
33
- testRunner: true,
34
- },
35
- ];
36
- /** The stem of the browser-test runner's configuration, whose test directory is read. */
37
- const BROWSER_TEST_CONFIG = "playwright.config";
38
- /** The browser-test runner's own test-file pattern, which holds where a configuration names none. */
39
- const BROWSER_TEST_MATCH = "**/*.{spec,test}.{js,ts,jsx,tsx,cjs,cts,cjsx,ctsx,mjs,mts,mjsx,mtsx}";
40
- /** The members of a test-runner configuration's `test` object that name setup files. */
41
- const SETUP_MEMBERS = ["setupFiles", "globalSetup"];
42
- /** A member that moves the directory every path of a test-runner configuration is read from. */
43
- const ROOT_MEMBER = "root";
44
- /**
45
- * A URL reference's scheme. A reference with none that does not start with a solidus is
46
- * relative, the bare name included: https://url.spec.whatwg.org/#relative-url-string
47
- */
48
- const URL_SCHEME = /^[a-z][a-z\d+.-]*:/iu;
49
- /** The constructors whose first argument addresses a worker script. */
50
- const WORKER_CONSTRUCTORS = new Set(["Worker", "SharedWorker"]);
51
- /** The file's name, the last segment of its path. */
52
- function basename(path) {
53
- return path.slice(path.lastIndexOf("/") + 1);
54
- }
55
- /** The convention one file name is, with the spelling a root reports it by. */
56
- function conventionOf(name) {
57
- for (const convention of CONVENTIONS) {
58
- for (const stem of convention.stems) {
59
- if (convention.extensions.some((ext) => name === `${stem}.${ext}`)) {
60
- return { convention, spelled: `${stem}.*` };
61
- }
62
- }
63
- }
64
- return undefined;
65
- }
66
- /** The text a string literal or a template with no substitution denotes. */
67
- function literalOf(node) {
68
- if (node !== undefined && (isStringLiteral(node) || isNoSubstitutionTemplateLiteral(node))) {
69
- return node.text;
70
- }
71
- return undefined;
72
- }
73
- /**
74
- * The object literals one configuration file's default export is written as: the
75
- * literal itself, or each literal argument of the call it is, at any depth of calls.
76
- * A default export written as anything else, a name or a computation, yields none,
77
- * because its value is not in the file's text.
78
- */
79
- function configObjects(file) {
80
- const found = [];
81
- const collect = (node) => {
82
- const at = unwrapped(node);
83
- if (isObjectLiteralExpression(at)) {
84
- found.push(at);
85
- return;
86
- }
87
- if (isCallExpression(at)) {
88
- for (const argument of at.arguments) {
89
- collect(argument);
90
- }
91
- }
92
- };
93
- for (const statement of file.statements) {
94
- if (isExportAssignment(statement) && !statement.isExportEquals) {
95
- collect(statement.expression);
96
- }
97
- }
98
- return found;
99
- }
100
- /**
101
- * The value one member of an object literal is written with, when it is written as
102
- * `name: value`, and undefined where the literal writes no such member.
103
- */
104
- function memberOf(object, name) {
105
- if (!isObjectLiteralExpression(object)) {
106
- return undefined;
107
- }
108
- for (const property of object.properties) {
109
- if (isPropertyAssignment(property) &&
110
- isIdentifier(property.name) &&
111
- property.name.text === name) {
112
- return property.initializer;
113
- }
114
- }
115
- return undefined;
116
- }
117
- /**
118
- * The strings one member holds, when it is written as a literal or an array of
119
- * literals. `undefined` is a value the text does not state.
120
- */
121
- function literalsOf(value) {
122
- const at = unwrapped(value);
123
- const single = literalOf(at);
124
- if (single !== undefined) {
125
- return [single];
126
- }
127
- if (!isArrayLiteralExpression(at)) {
128
- return undefined;
129
- }
130
- const found = [];
131
- for (const element of at.elements) {
132
- const text = literalOf(unwrapped(element));
133
- if (text === undefined) {
134
- return undefined;
135
- }
136
- found.push(text);
137
- }
138
- return found;
139
- }
140
- /**
141
- * Whether a literal is a relative URL reference, which is also how the test runner reads a
142
- * setup file's path against its root.
143
- */
144
- function isRelative(text) {
145
- return text !== "" && !text.startsWith("/") && !URL_SCHEME.test(text);
146
- }
147
- /** Whether a module specifier is relative, which a bare name is not: it names a package. */
148
- function isModuleRelative(text) {
149
- return text.startsWith("./") || text.startsWith("../");
150
- }
151
- /** A URL reference with its query and its fragment removed, which name no part of the file. */
152
- function pathPart(text) {
153
- const cut = text.search(/[?#]/u);
154
- return cut < 0 ? text : text.slice(0, cut);
155
- }
156
- /** The own files one relative literal names, read against a directory. */
157
- function filesNamed(files, dir, text) {
158
- if (!isRelative(text)) {
159
- return [];
160
- }
161
- return files.named(resolvePath(dir, pathPart(text)));
162
- }
163
- /** Whether one file name is the browser-test runner's configuration. */
164
- function isBrowserTestConfig(name) {
165
- return MODULE_EXTENSIONS.some((ext) => name === `${BROWSER_TEST_CONFIG}.${ext}`);
166
- }
167
- /**
168
- * The files the configuration files of one project enter: each configuration module,
169
- * with what it exports, and each own file a relative string of a configuration module
170
- * or a JSON configuration file names, read against that file's directory. A string at a
171
- * selection key of an applied convention row names no file.
172
- */
173
- function configurationEntries(host, targetRoot, files, parse, selected) {
174
- const { modules, documents, outside } = configurationFiles(host, targetRoot, files, parse);
175
- const found = [];
176
- const unselected = (file) => {
177
- const starts = selected.get(file.fileName)?.starts;
178
- return moduleStrings(file)
179
- .filter((one) => starts?.has(one.node.getStart()) !== true)
180
- .map((one) => one.text);
181
- };
182
- const unselectedIn = (path, texts) => {
183
- const left = [...(selected.get(path)?.texts ?? [])];
184
- return texts.filter((text) => {
185
- const at = left.indexOf(text);
186
- if (at < 0) {
187
- return true;
188
- }
189
- left.splice(at, 1);
190
- return false;
191
- });
192
- };
193
- const strings = (dir, texts) => {
194
- for (const text of texts) {
195
- for (const file of filesNamedBy(files, dir, text)) {
196
- found.push({ file, rule: "configuration-string", source: text, exports: true });
197
- }
198
- }
199
- };
200
- for (const { file, form } of modules) {
201
- found.push({ file, rule: "configuration-file", source: form, exports: true });
202
- strings(dirnamePath(file.fileName), unselected(file));
203
- }
204
- for (const document of documents) {
205
- strings(dirnamePath(document.path), unselectedIn(document.path, document.strings));
206
- }
207
- for (const { file } of outside) {
208
- strings(dirnamePath(file.fileName), unselected(file));
209
- }
210
- return found;
211
- }
212
- /**
213
- * The setup files one test-runner configuration names: every literal under
214
- * `test.setupFiles` and `test.globalSetup`, read against the configuration's own
215
- * directory. A configuration that moves its root names them against a directory its
216
- * text may not state, so none is read from it.
217
- */
218
- function setupFilesOf(file, files) {
219
- const objects = configObjects(file);
220
- const tests = objects
221
- .map((object) => memberOf(object, "test"))
222
- .filter((value) => value !== undefined)
223
- .map(unwrapped);
224
- if ([...objects, ...tests].some((object) => memberOf(object, ROOT_MEMBER) !== undefined)) {
225
- return [];
226
- }
227
- const dir = dirnamePath(file.fileName);
228
- const found = [];
229
- for (const test of tests) {
230
- for (const name of SETUP_MEMBERS) {
231
- const value = memberOf(test, name);
232
- for (const text of value === undefined ? [] : (literalsOf(value) ?? [])) {
233
- for (const named of filesNamed(files, dir, text)) {
234
- found.push({ file: named, rule: "test-runner", source: text, exports: false });
235
- }
236
- }
237
- }
238
- }
239
- return found;
240
- }
241
- /**
242
- * The test files one browser-test configuration names: every own file below its
243
- * test directory that its test-file pattern matches. The directory is the literal
244
- * `testDir` reads against the configuration's directory, or that directory where no
245
- * object of the configuration writes one; the pattern is the literal `testMatch`, or
246
- * the runner's own where none is written. A member whose value is not a literal
247
- * leaves the set unknown, and an unknown set enters nothing.
248
- */
249
- function browserTestsOf(file, files) {
250
- const objects = configObjects(file);
251
- if (objects.length === 0) {
252
- return [];
253
- }
254
- let testDir = ".";
255
- let patterns = [BROWSER_TEST_MATCH];
256
- for (const object of objects) {
257
- const dir = memberOf(object, "testDir");
258
- if (dir !== undefined) {
259
- testDir = literalOf(unwrapped(dir));
260
- }
261
- const match = memberOf(object, "testMatch");
262
- if (match !== undefined) {
263
- patterns = literalsOf(match);
264
- }
265
- }
266
- if (testDir === undefined || patterns === undefined) {
267
- return [];
268
- }
269
- const under = resolvePath(dirnamePath(file.fileName), testDir);
270
- const found = [];
271
- for (const pattern of patterns) {
272
- const expression = globExpression(pattern);
273
- for (const candidate of files.byName.values()) {
274
- const below = relativePath(under, candidate.fileName);
275
- if (below !== undefined && expression.test(below)) {
276
- found.push({ file: candidate, rule: "browser-tests", source: pattern, exports: false });
277
- }
278
- }
279
- }
280
- return found;
281
- }
282
- /**
283
- * The address one worker argument writes: a relative literal, or a `URL` built from
284
- * a literal against `import.meta.url`. Any other argument is computed and addresses
285
- * nothing the text states.
286
- */
287
- function workerAddress(argument) {
288
- if (argument === undefined) {
289
- return undefined;
290
- }
291
- const at = unwrapped(argument);
292
- const literal = literalOf(at);
293
- if (literal !== undefined) {
294
- return { literal, names: [] };
295
- }
296
- if (!isNewExpression(at) || !isIdentifier(at.expression) || at.expression.text !== "URL") {
297
- return undefined;
298
- }
299
- const [reference, base] = at.arguments ?? [];
300
- const text = literalOf(reference === undefined ? undefined : unwrapped(reference));
301
- if (text === undefined || base === undefined) {
302
- return undefined;
303
- }
304
- const meta = unwrapped(base);
305
- if (!isPropertyAccessExpression(meta) ||
306
- !isMetaProperty(meta.expression) ||
307
- !isIdentifier(meta.name) ||
308
- meta.name.text !== "url") {
309
- return undefined;
310
- }
311
- return { literal: text, names: [at.expression] };
312
- }
313
- /**
314
- * Every call one file writes that addresses a worker: `new Worker(...)`,
315
- * `new SharedWorker(...)` and `navigator.serviceWorker.register(...)`, each with an
316
- * address its text states.
317
- */
318
- function workerSitesOf(file) {
319
- const found = [];
320
- const visit = (node) => {
321
- if (isNewExpression(node) &&
322
- isIdentifier(node.expression) &&
323
- WORKER_CONSTRUCTORS.has(node.expression.text)) {
324
- const address = workerAddress(node.arguments?.[0]);
325
- if (address !== undefined) {
326
- found.push({
327
- literal: address.literal,
328
- platformNames: [node.expression, ...address.names],
329
- });
330
- }
331
- }
332
- if (isCallExpression(node)) {
333
- const callee = node.expression;
334
- if (isPropertyAccessExpression(callee) &&
335
- isIdentifier(callee.name) &&
336
- callee.name.text === "register" &&
337
- isPropertyAccessExpression(callee.expression) &&
338
- isIdentifier(callee.expression.name) &&
339
- callee.expression.name.text === "serviceWorker" &&
340
- isIdentifier(callee.expression.expression) &&
341
- callee.expression.expression.text === "navigator") {
342
- const address = workerAddress(node.arguments[0]);
343
- if (address !== undefined) {
344
- found.push({
345
- literal: address.literal,
346
- platformNames: [callee.expression.expression, ...address.names],
347
- });
348
- }
349
- }
350
- }
351
- node.forEachChild(visit);
352
- };
353
- file.forEachChild(visit);
354
- return found;
355
- }
356
- /**
357
- * The workers one file addresses. A call's names must resolve to a symbol the platform
358
- * declares, which a file of the target may augment and no import brings in; a name only
359
- * the target declares is the target's own constructor or object, which addresses no
360
- * worker this rule knows. One batch per file that writes such a call.
361
- */
362
- function workersOf(project, file, files) {
363
- const sites = workerSitesOf(file);
364
- if (sites.length === 0) {
365
- return [];
366
- }
367
- const names = sites.flatMap((site) => site.platformNames);
368
- const symbols = project.symbolsAt(names.map((name) => project.handle(name)));
369
- const platform = new Set();
370
- // A name the checker could not resolve is read as the platform's, so a worker it
371
- // stands on is rooted rather than reported.
372
- names.forEach((name, index) => {
373
- const symbol = symbols[index];
374
- if (symbol === UNANSWERED) {
375
- platform.add(name);
376
- return;
377
- }
378
- if (symbol !== undefined &&
379
- (symbol.flags & SymbolFlags.Alias) === 0 &&
380
- symbol.declarations.some((handle) => !files.byName.has(handle.path))) {
381
- platform.add(name);
382
- }
383
- });
384
- const dir = dirnamePath(file.fileName);
385
- const found = [];
386
- for (const site of sites) {
387
- if (!site.platformNames.every((name) => platform.has(name))) {
388
- continue;
389
- }
390
- for (const named of filesNamed(files, dir, site.literal)) {
391
- found.push({ file: named, rule: "worker", source: site.literal, exports: false });
392
- }
393
- }
394
- return found;
395
- }
396
- /** Whether one call is `import.meta.glob(...)`. */
397
- function isMetaGlob(node) {
398
- if (!isCallExpression(node) || !isPropertyAccessExpression(node.expression)) {
399
- return false;
400
- }
401
- const { expression, name } = node.expression;
402
- return (isIdentifier(name) &&
403
- name.text === "glob" &&
404
- isMetaProperty(expression) &&
405
- expression.keywordToken === SyntaxKind.ImportKeyword);
406
- }
407
- /**
408
- * The files one file loads by a computed path, each with what exports: every own file
409
- * below the directory a relative literal start of an `import()` or `require()` argument
410
- * names, other than the calling file's own directory or one holding it, which would name
411
- * every sibling, and
412
- * every own file a relative literal glob of `import.meta.glob` matches, both read against
413
- * the calling file's directory, as a bundler's context module reads them.
414
- */
415
- function computedImportsOf(file, files) {
416
- const dir = dirnamePath(file.fileName);
417
- const found = [];
418
- const below = (prefix) => {
419
- const target = computedLoadDirectory(dir, prefix);
420
- if (target === undefined) {
421
- return;
422
- }
423
- for (const candidate of files.byName.values()) {
424
- if (candidate !== file && relativePath(target, candidate.fileName) !== undefined) {
425
- found.push({ file: candidate, rule: "computed-import", source: prefix, exports: true });
426
- }
427
- }
428
- };
429
- const globbed = (pattern) => {
430
- if (!isModuleRelative(pattern)) {
431
- return;
432
- }
433
- const expression = globExpression(resolvePath(dir, pattern));
434
- for (const candidate of files.byName.values()) {
435
- if (candidate !== file && expression.test(candidate.fileName)) {
436
- found.push({ file: candidate, rule: "computed-import", source: pattern, exports: true });
437
- }
438
- }
439
- };
440
- const visit = (node) => {
441
- if (isCallExpression(node)) {
442
- const [first] = node.arguments;
443
- const callee = node.expression;
444
- const loads = callee.kind === SyntaxKind.ImportKeyword ||
445
- (isIdentifier(callee) && callee.text === "require");
446
- if (loads && first !== undefined) {
447
- const prefix = leadingLiteral(first);
448
- if (prefix !== undefined) {
449
- below(prefix);
450
- }
451
- }
452
- else if (isMetaGlob(node) && first !== undefined) {
453
- for (const pattern of literalsOf(first) ?? []) {
454
- globbed(pattern);
455
- }
456
- }
457
- }
458
- node.forEachChild(visit);
459
- };
460
- file.forEachChild(visit);
461
- return found;
462
- }
463
- /**
464
- * Every file of one project the rules enter, in no particular order and possibly more
465
- * than once: a file two rules enter appears once per rule.
466
- *
467
- * `testFiles` is the configuration's test-file patterns, matched against each
468
- * file's path below the target root; a file one of them matches is a test file the
469
- * runner executes.
470
- */
471
- export function entryPoints(project, files, testFiles, host, targetRoot, parse, selected = new Map()) {
472
- const found = [...configurationEntries(host, targetRoot, files, parse, selected)];
473
- const tests = testFiles.map((pattern) => ({ pattern, expression: globExpression(pattern) }));
474
- for (const [path, file] of files.byPath) {
475
- const name = basename(path);
476
- const named = conventionOf(name);
477
- if (named !== undefined) {
478
- found.push({ file, rule: named.convention.rule, source: named.spelled, exports: true });
479
- if (named.convention.testRunner) {
480
- found.push(...setupFilesOf(file, files));
481
- }
482
- }
483
- if (isBrowserTestConfig(name)) {
484
- found.push(...browserTestsOf(file, files));
485
- }
486
- for (const { pattern, expression } of tests) {
487
- if (expression.test(path)) {
488
- found.push({ file, rule: "test-runner", source: pattern, exports: false });
489
- }
490
- }
491
- found.push(...workersOf(project, file, files));
492
- found.push(...computedImportsOf(file, files));
493
- }
494
- for (const { file, source } of htmlEntries(host, targetRoot, files, parse)) {
495
- found.push({ file, rule: "html-entry", source, exports: true });
496
- }
497
- for (const { file, source, names } of documentEntries(host, targetRoot, files)) {
498
- found.push({
499
- file,
500
- rule: "document-import",
501
- source,
502
- exports: true,
503
- ...(names === undefined ? {} : { names }),
504
- });
505
- }
506
- for (const { file, source } of buildScriptEntries(host, targetRoot, files, parse)) {
507
- found.push({ file, rule: "bundler-entry", source, exports: true });
508
- }
509
- for (const { file, source } of workflowEntries(host, targetRoot, files)) {
510
- found.push({ file, rule: "workflow-step", source, exports: true });
511
- }
512
- return found;
513
- }