@stateward/core 1.2.1 → 1.3.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 (75) hide show
  1. package/dist/analyses.d.ts +37 -0
  2. package/dist/analyses.js +57 -0
  3. package/dist/backend/program-record.d.ts +7 -0
  4. package/dist/backend/typescript6.d.ts +35 -32
  5. package/dist/backend/typescript6.js +3804 -163
  6. package/dist/baseline.d.ts +1 -1
  7. package/dist/baseline.js +14 -10
  8. package/dist/cache.d.ts +89 -5
  9. package/dist/cache.js +271 -40
  10. package/dist/checker.d.ts +11 -1
  11. package/dist/checker.js +32 -2
  12. package/dist/class-id.d.ts +34 -0
  13. package/dist/class-id.js +93 -0
  14. package/dist/code-text.d.ts +8 -0
  15. package/dist/code-text.js +66 -0
  16. package/dist/config-file.js +7 -5
  17. package/dist/config.d.ts +10 -2
  18. package/dist/config.js +541 -49
  19. package/dist/define.d.ts +8 -2
  20. package/dist/disk-cache.d.ts +2 -0
  21. package/dist/disk-cache.js +77 -11
  22. package/dist/engine.d.ts +51 -1
  23. package/dist/engine.js +517 -42
  24. package/dist/fact-lines.d.ts +31 -0
  25. package/dist/fact-lines.js +197 -0
  26. package/dist/facts-versions.d.ts +27 -0
  27. package/dist/facts-versions.js +99 -0
  28. package/dist/fixes.js +9 -4
  29. package/dist/guarantees.d.ts +63 -11
  30. package/dist/guarantees.js +151 -21
  31. package/dist/ignores.d.ts +11 -0
  32. package/dist/ignores.js +74 -27
  33. package/dist/implementation.d.ts +0 -6
  34. package/dist/implementation.js +0 -17
  35. package/dist/index.d.ts +10 -9
  36. package/dist/index.js +14 -7
  37. package/dist/internal.d.ts +9 -5
  38. package/dist/internal.js +6 -3
  39. package/dist/lazy.d.ts +8 -1
  40. package/dist/lazy.js +27 -2
  41. package/dist/ledger.d.ts +77 -0
  42. package/dist/ledger.js +423 -0
  43. package/dist/off-by-default.d.ts +13 -0
  44. package/dist/off-by-default.js +15 -0
  45. package/dist/options.d.ts +21 -5
  46. package/dist/options.js +22 -7
  47. package/dist/package-facts.d.ts +211 -17
  48. package/dist/package-facts.js +520 -38
  49. package/dist/plan.d.ts +1 -1
  50. package/dist/plan.js +7 -2
  51. package/dist/release.d.ts +12 -21
  52. package/dist/release.js +28 -38
  53. package/dist/renamed.d.ts +22 -3
  54. package/dist/renamed.js +50 -16
  55. package/dist/rollout.js +7 -4
  56. package/dist/safe-calls.d.ts +26 -0
  57. package/dist/safe-calls.js +345 -0
  58. package/dist/severity.d.ts +1 -1
  59. package/dist/severity.js +17 -3
  60. package/dist/stated.d.ts +37 -0
  61. package/dist/stated.js +123 -0
  62. package/dist/test-runner.d.ts +18 -0
  63. package/dist/test-runner.js +483 -0
  64. package/dist/testing-tsc.d.ts +16 -0
  65. package/dist/testing-tsc.js +86 -0
  66. package/dist/testing.d.ts +5 -4
  67. package/dist/testing.js +6 -6
  68. package/dist/timing.d.ts +15 -0
  69. package/dist/timing.js +41 -2
  70. package/dist/types.d.ts +1068 -16
  71. package/dist/unread.d.ts +90 -0
  72. package/dist/unread.js +405 -0
  73. package/dist/vocabulary.d.ts +1 -1
  74. package/dist/vocabulary.js +1 -1
  75. package/package.json +4 -2
@@ -0,0 +1,37 @@
1
+ import type { Plugin, PluginAnalysis } from "./types.js";
2
+ /** An analysis's name: kebab-case, like a rule's key (`throws`). */
3
+ export declare const ANALYSIS_NAME: RegExp;
4
+ /**
5
+ * What is wrong with a project rule's `reads`, as the end of a message, or undefined when it is
6
+ * absent or a list of analysis ids.
7
+ */
8
+ export declare function readsProblem(value: unknown): string | undefined;
9
+ /** Where a read id leads: the analysis, or why the rule cannot have it. */
10
+ export type ReadTarget = {
11
+ readonly kind: "found";
12
+ readonly plugin: string;
13
+ readonly analysis: PluginAnalysis;
14
+ }
15
+ /** The publisher is not in the config's plugins. */
16
+ | {
17
+ readonly kind: "no-plugin";
18
+ readonly plugin: string;
19
+ }
20
+ /** The publisher is there but publishes no analysis by that name (an older version of it). */
21
+ | {
22
+ readonly kind: "no-analysis";
23
+ readonly plugin: string;
24
+ readonly name: string;
25
+ };
26
+ /** Finds the analysis `id` names among the config's plugins. */
27
+ export declare function readTarget(plugins: readonly Plugin[], id: string): ReadTarget;
28
+ /** A rule that reads an analysis the config cannot give it: the "not checked" finding's text. */
29
+ export declare function missingAnalysis(ruleId: string, id: string, target: Exclude<ReadTarget, {
30
+ kind: "found";
31
+ }>): {
32
+ message: string;
33
+ hint: string;
34
+ };
35
+ /** The config error for a rule that reads an analysis its loaded publisher does not publish. */
36
+ export declare function unpublishedRead(plugin: string, key: string, id: string, publisher: string): string;
37
+ //# sourceMappingURL=analyses.d.ts.map
@@ -0,0 +1,57 @@
1
+ /*
2
+ * Analyses a pack publishes for the project rules of any pack: the names a
3
+ * plugin may give one, the ids a rule reads one by, and where a read id leads in the config.
4
+ */
5
+ /** An analysis's name: kebab-case, like a rule's key (`throws`). */
6
+ export const ANALYSIS_NAME = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
7
+ /** An analysis's id as a rule reads it: `"<plugin>/<name>"` (`errors/throws`). */
8
+ const ANALYSIS_ID = /^[^/\s]+\/[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
9
+ /**
10
+ * What is wrong with a project rule's `reads`, as the end of a message, or undefined when it is
11
+ * absent or a list of analysis ids.
12
+ */
13
+ export function readsProblem(value) {
14
+ if (value === undefined)
15
+ return undefined;
16
+ if (!Array.isArray(value)) {
17
+ return `reads must be a list of analysis ids, like ["errors/throws"]`;
18
+ }
19
+ for (const item of value) {
20
+ if (typeof item !== "string" || !ANALYSIS_ID.test(item)) {
21
+ return `reads: ${JSON.stringify(item)} is not an analysis id "<plugin>/<name>", like "errors/throws"`;
22
+ }
23
+ }
24
+ return undefined;
25
+ }
26
+ /** Finds the analysis `id` names among the config's plugins. */
27
+ export function readTarget(plugins, id) {
28
+ const slash = id.indexOf("/");
29
+ const pluginName = id.slice(0, slash);
30
+ const name = id.slice(slash + 1);
31
+ const plugin = plugins.find((one) => one.name === pluginName);
32
+ if (plugin === undefined)
33
+ return { kind: "no-plugin", plugin: pluginName };
34
+ const analyses = plugin.analyses;
35
+ const analysis = analyses !== undefined && Object.hasOwn(analyses, name) ? analyses[name] : undefined;
36
+ return analysis === undefined
37
+ ? { kind: "no-analysis", plugin: pluginName, name }
38
+ : { kind: "found", plugin: pluginName, analysis };
39
+ }
40
+ /** A rule that reads an analysis the config cannot give it: the "not checked" finding's text. */
41
+ export function missingAnalysis(ruleId, id, target) {
42
+ if (target.kind === "no-plugin") {
43
+ return {
44
+ message: `not checked: \`${ruleId}\` reads \`${id}\`, and the \`${target.plugin}\` pack is not in \`plugins\``,
45
+ hint: `add \`${target.plugin}()\` to \`plugins\``,
46
+ };
47
+ }
48
+ return {
49
+ message: `not checked: \`${ruleId}\` reads \`${id}\`, which the \`${target.plugin}\` pack in \`plugins\` does not publish`,
50
+ hint: `update the \`${target.plugin}\` pack to a version that publishes \`${target.name}\``,
51
+ };
52
+ }
53
+ /** The config error for a rule that reads an analysis its loaded publisher does not publish. */
54
+ export function unpublishedRead(plugin, key, id, publisher) {
55
+ return `plugin "${plugin}": rule "${key}" reads "${id}", which plugin "${publisher}" does not publish`;
56
+ }
57
+ //# sourceMappingURL=analyses.js.map
@@ -29,6 +29,13 @@ export type ProgramRecord = {
29
29
  * filled while the run that built the program asks for them.
30
30
  */
31
31
  readonly reads: Record<string, string>;
32
+ /** The package modules the own files import (`importedModules`), sorted. */
33
+ readonly imports: readonly string[];
34
+ /**
35
+ * What the config's `facts` keys resolve to in the program (`ProjectUnit.factKeys`), as JSON,
36
+ * by a digest of the facts: filled while the run that asks for them has the program.
37
+ */
38
+ readonly facts: Record<string, string>;
32
39
  };
33
40
  export declare function isQueryKind(value: unknown): value is QueryKind;
34
41
  /** Everything else a program depends on: its inputs, TypeScript's version and lib folder, the process folder. */
@@ -2,7 +2,8 @@ import ts from "typescript";
2
2
  import type { ResultCache } from "../cache.js";
3
3
  import type { MarkedComment } from "./comments.js";
4
4
  import type { DependenciesOf, IsPackageEntry, PackageOf } from "./fingerprints.js";
5
- import type { Config, FixForm, FixVerdict, SymbolRef, TextEdit, TypeQueries } from "../types.js";
5
+ import type { FactKeyCheck } from "../package-facts.js";
6
+ import type { Config, FixForm, FixVerdict, PackageFactsConfig, TextEdit, TypeQueries } from "../types.js";
6
7
  /** The tsconfig could not be read or is invalid. */
7
8
  export declare class TsconfigError extends Error {
8
9
  /** The one change that fixes it, shown on a `= fix:` line. */
@@ -81,11 +82,24 @@ export type ProjectUnit = {
81
82
  * TypeScript 6's default, on). Read from the tsconfig: no program is built for it.
82
83
  */
83
84
  readonly strictNullChecks: boolean;
85
+ /** The test-runner configs, absolute, whose test files could not be read (`test-runner.ts`). */
86
+ readonly unreadTestConfigs: readonly string[];
84
87
  /**
85
88
  * Whether `module` resolves to declarations (types) from the project's folder, by its options:
86
89
  * `react` does when `@types/react` or a typed `react` is installed. No program is built for it.
87
90
  */
88
91
  typesResolve(module: string): boolean;
92
+ /**
93
+ * What each key of the config's `facts` resolves to in this program (`checkFactKeys`). A
94
+ * project whose program a run proved unchanged answers from its record when the facts are the
95
+ * same; otherwise the program is built.
96
+ */
97
+ factKeys(facts: PackageFactsConfig): readonly FactKeyCheck[];
98
+ /**
99
+ * Whether an own file imports `module` or one of its subpaths (`importedModules`): a rule that
100
+ * reads a library by its types has nothing to say when no file uses the library.
101
+ */
102
+ importsModule(module: string): boolean;
89
103
  /**
90
104
  * Binds the program (creating its type checker), which gives every node its parent: call it
91
105
  * before a rule or a plugin sees a node of `files`. Parsing does not set parents.
@@ -133,6 +147,15 @@ export type UnresolvedImport = {
133
147
  readonly start: number;
134
148
  readonly end: number;
135
149
  };
150
+ /**
151
+ * The package modules one file imports, as TypeScript reads its imports (not its text): import
152
+ * and export declarations, `import x = require(…)`, `import(…)`, `require(…)`, `import("…")`
153
+ * types, and the JSX runtime a file with JSX uses by the project's `jsx` option. Relative and
154
+ * absolute paths are left out: they name the project's own files.
155
+ */
156
+ export declare function importedModules(sourceFile: ts.SourceFile, options: ts.CompilerOptions): string[];
157
+ /** Whether `imported` (as `importedModules` gives them) names `module` or one of its subpaths. */
158
+ export declare function importsModuleIn(imported: readonly string[], module: string): boolean;
136
159
  /** Whether a project with these options checks with `strictNullChecks` (TypeScript 6: on unless turned off). */
137
160
  export declare function checksNulls(options: ts.CompilerOptions): boolean;
138
161
  export type Backend = {
@@ -169,18 +192,21 @@ export declare function hostWithOverlays(options: ts.CompilerOptions, overlays:
169
192
  /** Serve a file that is not in `overlays` from `cache` without reading it from disk. */
170
193
  trustCache?: boolean,
171
194
  /** Parse the JSDoc of TypeScript files too: a rule that is on reads it (`RuleMeta.needsJsDoc`). */
172
- jsDoc?: boolean,
173
- /**
174
- * The files kept in the process-wide `libraryCache` rather than in `cache`. A package's own
175
- * JavaScript (`openPackageSource`) goes in `cache`, so it is freed with the package's program:
176
- * kept for the process, the packages a first run reads held over 500 MB on a large app.
177
- */
178
- shared?: (fileName: string) => boolean): ts.CompilerHost;
195
+ jsDoc?: boolean): ts.CompilerHost;
179
196
  /** A file's name in qualified ids: relative to the project, with forward slashes. */
180
197
  export declare function idFileNames(root: string): (fileName: string) => string;
198
+ /** The type questions the flow scan asks in one file before it stops (`TypeQueries.typedFlowsIn`). */
199
+ export declare const FLOW_BUDGET = 200000;
200
+ /**
201
+ * The platform's packages every project has: Node's types. TypeScript's own lib is the platform
202
+ * too; the config's `platform` adds more (`bun-types`, `@cloudflare/workers-types`).
203
+ */
204
+ export declare const PLATFORM_PACKAGES: readonly string[];
181
205
  export declare function createTypeQueries(program: ts.Program, own: ReadonlySet<string>,
182
206
  /** The project folder qualified ids are relative to. */
183
- root: string, packageOf: PackageOf, isEntry: IsPackageEntry, dependenciesOf: DependenciesOf): TypeQueries;
207
+ root: string, packageOf: PackageOf, isEntry: IsPackageEntry, dependenciesOf: DependenciesOf,
208
+ /** Packages the config adds to the platform (`Config.platform`). */
209
+ platform?: readonly string[]): TypeQueries;
184
210
  /**
185
211
  * Builds one TypeScript program per project of the config's tsconfig (see `collectConfigs`) and
186
212
  * serves the unsaved overlays. Later `open` calls reuse the previous programs.
@@ -193,28 +219,5 @@ export declare function createBackend({ config, cwd, cache, jsDoc, }: {
193
219
  /** Parse the JSDoc of TypeScript files (`hostWithOverlays`). */
194
220
  jsDoc?: boolean;
195
221
  }): Backend;
196
- /**
197
- * A package's own JavaScript, read as the project's own code is (the fourth source of library facts): a small program over the files one entry reaches by relative imports and requires, never
198
- * into other packages, with TypeScript's ES2022 library for the platform's globals. Plugins
199
- * summarize its files with the same code as the project's, through these `TypeQueries`.
200
- */
201
- export type PackageSource = {
202
- /** The package's files the program loaded, absolute, sorted: the entry and what it reaches. */
203
- readonly files: readonly string[];
204
- sourceFile(file: string): ts.SourceFile | undefined;
205
- /** Own files are the package's loaded files; qualified ids are relative to the package root. */
206
- readonly types: TypeQueries;
207
- /**
208
- * The declaration a module exports under `path` (`["remote"]`, `["Client", "get"]`): an ES
209
- * export, a CommonJS `exports.x = …` or `module.exports = { x }`, or `module.exports = fn` for
210
- * `["default"]` or its own name. Undefined when the module does not export it.
211
- */
212
- exported(file: string, path: readonly string[]): SymbolRef | undefined;
213
- };
214
- /**
215
- * Opens the package at `root` from `entry` (a JavaScript file in it). Its files are parsed with
216
- * the library files' cache, so a later package or project shares TypeScript's lib files.
217
- */
218
- export declare function openPackageSource(root: string, entry: string): PackageSource;
219
222
  export {};
220
223
  //# sourceMappingURL=typescript6.d.ts.map