@antelopejs/tooling-configs 0.2.4 → 0.2.5

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.
package/README.md CHANGED
@@ -188,7 +188,7 @@ Pass paths to check only those files, as the pre-commit hook does. The command a
188
188
 
189
189
  ### Cleanup proof
190
190
 
191
- A behaviour-preserving cleanup PR shows `antelopejs-api-diff <base-ref>` passing. It checks each tracked package with a `tsconfig.json` that publishes something (not private, and declaring `exports`, `main`, `types`, `typings` or `typesVersions`) and lists the others as `API: skipped <directory>, <reason>.`. Each package is analysed and bundled with its own installed TypeScript, falling back to the one `dts-bundle-generator` brings when the package has none; a TypeScript without the programmatic compiler API (7 and later) is reported as an execution error naming the package, and the other packages are still analysed. Large packages are bundled by several worker processes (up to 8, bounded by cpus and free memory); the output is the same as a single process. It emits declarations without comments, resolves published entries from `exports` (preferring `types`), `main`, `types`/`typings` and `typesVersions`, and bundles each entry's local declaration closure. External packages stay external. Stable top-level ordering ignores declaration moves between internal files while preserving overload order. Compiler errors fail the proof.
191
+ A behaviour-preserving cleanup PR shows `antelopejs-api-diff <base-ref>` passing. It checks each tracked package with a `tsconfig.json` that publishes something (not private, and declaring `exports`, `main`, `types`, `typings` or `typesVersions`) and lists the others as `API: skipped <directory>, <reason>.`. Each package is analysed and bundled with its own installed TypeScript, falling back to the one `dts-bundle-generator` brings when the package has none; a TypeScript without the programmatic compiler API (7 and later) is reported as an execution error naming the package, and the other packages are still analysed. Large packages are bundled by several worker processes (up to 8, bounded by cpus and free memory); the output is the same as a single process. It emits declarations without comments, resolves published entries from `exports` (preferring `types`), `main`, `types`/`typings` and `typesVersions`, and bundles each entry's local declaration closure. External packages stay external. Stable top-level ordering ignores declaration moves between internal files while preserving overload order. Members of object type literals, interfaces and classes are compared in a canonical order, because TypeScript can emit an inferred object type's properties in another order after a refactor; overloads, call and construct signatures, tuple elements, parameters, enum members and union constituents keep their written order. Compiler errors fail the proof.
192
192
 
193
193
  A comment-only PR shows `antelopejs-comment-proof <base-ref>` passing instead of a verifier. It includes private packages, ignores type diagnostics and compares comment-free JavaScript emit byte for byte. Both commands exclude test sources, fail on added or removed outputs, and print unified diffs for changes.
194
194
 
@@ -94,6 +94,85 @@ function bundleDeclarations(compilerRoot, scratch, entries, options, workers = w
94
94
  return generate(entries, options);
95
95
  }
96
96
  //#endregion
97
+ //#region src/guardrails/declaration-order.ts
98
+ const CALL = 0;
99
+ const CONSTRUCT = 1;
100
+ const INDEX = 2;
101
+ const CONSTRUCTOR = 3;
102
+ const INSTANCE = 4;
103
+ const STATIC = 5;
104
+ function nameText(compiler, name, source) {
105
+ return compiler.isIdentifier(name) || compiler.isStringLiteral(name) || compiler.isNumericLiteral(name) || compiler.isPrivateIdentifier(name) ? name.text : name.getText(source);
106
+ }
107
+ function memberKey(compiler, member, source) {
108
+ if (compiler.isCallSignatureDeclaration(member)) return {
109
+ rank: CALL,
110
+ name: ""
111
+ };
112
+ if (compiler.isConstructSignatureDeclaration(member)) return {
113
+ rank: CONSTRUCT,
114
+ name: ""
115
+ };
116
+ if (compiler.isConstructorDeclaration(member)) return {
117
+ rank: CONSTRUCTOR,
118
+ name: ""
119
+ };
120
+ if (compiler.isIndexSignatureDeclaration(member)) return {
121
+ rank: INDEX,
122
+ name: member.parameters[0]?.type?.getText(source) ?? ""
123
+ };
124
+ return {
125
+ rank: compiler.canHaveModifiers(member) && (compiler.getModifiers(member) ?? []).some(({ kind }) => kind === compiler.SyntaxKind.StaticKeyword) ? STATIC : INSTANCE,
126
+ name: member.name === void 0 ? "" : nameText(compiler, member.name, source)
127
+ };
128
+ }
129
+ function compareKeys(a, b) {
130
+ if (a.rank !== b.rank) return a.rank - b.rank;
131
+ if (a.name === b.name) return 0;
132
+ return a.name < b.name ? -1 : 1;
133
+ }
134
+ /** Orders `visited` by keys read from `original`, the same members before their children were rewritten. The sort is stable, so overloads of one name, call signatures and construct signatures keep their written order. */
135
+ function sortMembers(compiler, visited, original, source) {
136
+ const keyed = visited.map((member, index) => ({
137
+ member,
138
+ key: memberKey(compiler, original[index], source)
139
+ }));
140
+ keyed.sort((a, b) => compareKeys(a.key, b.key));
141
+ return compiler.factory.createNodeArray(keyed.map(({ member }) => member));
142
+ }
143
+ /** Rewrites every object type literal, interface and class in `file`, whose nodes were parsed from `source`, so its members appear in a canonical order. Member order does not change a type, so two declaration texts that differ only in it print identically. Tuple elements, parameters, overloads of one name, enum members, union and intersection constituents and statement bodies of namespaces keep the order they were written in. */
144
+ function sortDeclarationMembers(compiler, file, source) {
145
+ const { factory } = compiler;
146
+ const result = compiler.transform(file, [(context) => {
147
+ const visit = (node) => {
148
+ const visited = compiler.visitEachChild(node, visit, context);
149
+ if (compiler.isTypeLiteralNode(node) && compiler.isTypeLiteralNode(visited)) return factory.updateTypeLiteralNode(visited, sortMembers(compiler, visited.members, node.members, source));
150
+ if (compiler.isInterfaceDeclaration(node) && compiler.isInterfaceDeclaration(visited)) return factory.updateInterfaceDeclaration(visited, visited.modifiers, visited.name, visited.typeParameters, visited.heritageClauses, sortMembers(compiler, visited.members, node.members, source));
151
+ if (compiler.isClassDeclaration(node) && compiler.isClassDeclaration(visited)) return factory.updateClassDeclaration(visited, visited.modifiers, visited.name, visited.typeParameters, visited.heritageClauses, sortMembers(compiler, visited.members, node.members, source));
152
+ return visited;
153
+ };
154
+ return (root) => visit(root);
155
+ }]);
156
+ const [transformed] = result.transformed;
157
+ result.dispose();
158
+ return transformed;
159
+ }
160
+ function statementName(compiler, statement, source) {
161
+ if (compiler.isVariableStatement(statement)) return statement.declarationList.declarations[0]?.name.getText(source) ?? "";
162
+ if (compiler.isFunctionDeclaration(statement) || compiler.isClassDeclaration(statement) || compiler.isInterfaceDeclaration(statement) || compiler.isTypeAliasDeclaration(statement) || compiler.isEnumDeclaration(statement) || compiler.isModuleDeclaration(statement) || compiler.isImportEqualsDeclaration(statement)) return statement.name?.getText(source) ?? "default";
163
+ return statement.getText(source);
164
+ }
165
+ /** Prints a bundle in canonical form: top-level statements by name and object members in a fixed order. */
166
+ function normalizeBundle(compiler, text) {
167
+ const source = compiler.createSourceFile("bundle.d.ts", text, compiler.ScriptTarget.Latest, true);
168
+ const statements = [...source.statements].sort((a, b) => statementName(compiler, a, source).localeCompare(statementName(compiler, b, source)));
169
+ const normalized = sortDeclarationMembers(compiler, compiler.factory.updateSourceFile(source, statements), source);
170
+ return compiler.createPrinter({
171
+ removeComments: true,
172
+ newLine: compiler.NewLineKind.LineFeed
173
+ }).printFile(normalized);
174
+ }
175
+ //#endregion
97
176
  //#region src/guardrails/runtime-diff.ts
98
177
  const DESCRIBE = `
99
178
  const { readFileSync, existsSync } = require("node:fs");
@@ -369,20 +448,6 @@ function publishedEntries(directory, manifest, emitted, scratch) {
369
448
  }
370
449
  return entries.sort((a, b) => a.entry.localeCompare(b.entry));
371
450
  }
372
- function statementName(compiler, statement, source) {
373
- if (compiler.isVariableStatement(statement)) return statement.declarationList.declarations[0]?.name.getText(source) ?? "";
374
- if (compiler.isFunctionDeclaration(statement) || compiler.isClassDeclaration(statement) || compiler.isInterfaceDeclaration(statement) || compiler.isTypeAliasDeclaration(statement) || compiler.isEnumDeclaration(statement) || compiler.isModuleDeclaration(statement) || compiler.isImportEqualsDeclaration(statement)) return statement.name?.getText(source) ?? "default";
375
- return statement.getText(source);
376
- }
377
- function normalizeBundle(compiler, text) {
378
- const source = compiler.createSourceFile("bundle.d.ts", text, compiler.ScriptTarget.Latest, true);
379
- const statements = [...source.statements].sort((a, b) => statementName(compiler, a, source).localeCompare(statementName(compiler, b, source)));
380
- const normalized = compiler.factory.updateSourceFile(source, statements);
381
- return compiler.createPrinter({
382
- removeComments: true,
383
- newLine: compiler.NewLineKind.LineFeed
384
- }).printFile(normalized);
385
- }
386
451
  function bundleDependencies(directory, scratch) {
387
452
  let current = directory;
388
453
  while (!existsSync(join(current, "node_modules"))) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antelopejs/tooling-configs",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "Shared tooling presets for AntelopeJS repositories: oxlint (with the vendored anti-slop rules), oxfmt, ESLint for Nuxt layers, Knip, and an interface range check",
5
5
  "keywords": [
6
6
  "antelopejs",