@venizia/dev-configs 0.5.0-2 → 0.5.0-4
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 +2 -2
- package/dist/cli/codemod/binding-keys.d.ts +28 -1
- package/dist/cli/codemod/binding-keys.js +189 -43
- package/dist/cli/codemod/binding-keys.js.map +1 -1
- package/dist/cli/codemod/class-renames.d.ts +39 -0
- package/dist/cli/codemod/class-renames.js +279 -0
- package/dist/cli/codemod/class-renames.js.map +1 -0
- package/dist/cli/codemod/index.js +6 -0
- package/dist/cli/codemod/index.js.map +1 -1
- package/dist/cli/codemod/namespace-functions/mappings/dev-configs.js +3 -3
- package/dist/cli/codemod/namespace-functions/mappings/dev-configs.js.map +1 -1
- package/dist/testing/index.d.ts +2 -2
- package/dist/testing/index.js +2 -2
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/{rejection.helper.d.ts → rejection.utility.d.ts} +4 -4
- package/dist/testing/{rejection.helper.js → rejection.utility.js} +7 -7
- package/dist/testing/rejection.utility.js.map +1 -0
- package/dist/testing/{spawn.helper.d.ts → spawn.utility.d.ts} +2 -2
- package/dist/testing/{spawn.helper.js → spawn.utility.js} +5 -5
- package/dist/testing/spawn.utility.js.map +1 -0
- package/package.json +1 -1
- package/dist/testing/rejection.helper.js.map +0 -1
- package/dist/testing/spawn.helper.js.map +0 -1
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClassRenamesCommand = exports.ClassRenames = exports.ClassRenameTable = void 0;
|
|
4
|
+
const node_fs_1 = require("node:fs");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const files_1 = require("./files");
|
|
7
|
+
const USAGE = `Usage: devz codemod class-renames [paths...] [--write [--all] | --check] [--reverse]
|
|
8
|
+
|
|
9
|
+
Renames the classes IGNIS renamed, at the import and at every use in the file: RetryHelper, SlugHelper
|
|
10
|
+
and CredentialHelper (@venizia/ignis-helpers) become RetryUtility, SlugUtility and CredentialUtility,
|
|
11
|
+
RejectionHelper and SpawnHelper (@venizia/dev-configs/testing) become RejectionUtility and SpawnUtility. One
|
|
12
|
+
table, in this file; a later rename adds a row.
|
|
13
|
+
|
|
14
|
+
It reads TypeScript files (.ts, .tsx, .mts, .cts): a named import or re-export from the package that owns
|
|
15
|
+
the class is renamed, and so is each use of the name it brought in (an aliased import, "Old as Alias", keeps
|
|
16
|
+
its alias and changes only the imported name). A namespace import's member ("ns.Old") is renamed too. A .js,
|
|
17
|
+
.cjs or .mjs file is not read, and neither is "import('pkg').Old": edit those by hand. A property or method that
|
|
18
|
+
has the same name as a class is left alone.
|
|
19
|
+
|
|
20
|
+
--write write the changed files (without it, nothing is written); it needs a path, or --all
|
|
21
|
+
--all with --write and no path: rewrite every source file under the working directory
|
|
22
|
+
--check dry run that exits 1 while a file would change (for CI)
|
|
23
|
+
--reverse rename back, for a downgrade
|
|
24
|
+
--help print this text and exit
|
|
25
|
+
|
|
26
|
+
With no flag it lists what would change and writes nothing. Inside a git repository it reads the files git
|
|
27
|
+
knows (tracked, or untracked and not ignored), and --write refuses a file with local changes (changed,
|
|
28
|
+
staged or untracked): commit or stash it first, so git can undo the codemod.`;
|
|
29
|
+
/** A usage error: nothing was read or written. */
|
|
30
|
+
const USAGE_ERROR_CODE = 2;
|
|
31
|
+
class ClassRenameFlags {
|
|
32
|
+
static { this.WRITE = '--write'; }
|
|
33
|
+
static { this.ALL = '--all'; }
|
|
34
|
+
static { this.CHECK = '--check'; }
|
|
35
|
+
static { this.REVERSE = '--reverse'; }
|
|
36
|
+
static { this.HELP = '--help'; }
|
|
37
|
+
static { this.HELP_SHORT = '-h'; }
|
|
38
|
+
static { this.SCHEME_SET = new Set([
|
|
39
|
+
this.WRITE,
|
|
40
|
+
this.ALL,
|
|
41
|
+
this.CHECK,
|
|
42
|
+
this.REVERSE,
|
|
43
|
+
this.HELP,
|
|
44
|
+
this.HELP_SHORT,
|
|
45
|
+
]); }
|
|
46
|
+
static isValid(value) {
|
|
47
|
+
return this.SCHEME_SET.has(value);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/** `@venizia/ignis` re-exports the helpers as types only, so a value import of these classes comes from `@venizia/ignis-helpers`. */
|
|
51
|
+
const HELPERS = ['@venizia/ignis-helpers', '@venizia/ignis'];
|
|
52
|
+
const TESTING = ['@venizia/dev-configs/testing'];
|
|
53
|
+
/** The renamed classes: add a row for the next rename. */
|
|
54
|
+
class ClassRenameTable {
|
|
55
|
+
static { this.ROWS = [
|
|
56
|
+
{ oldName: 'RetryHelper', newName: 'RetryUtility', packages: HELPERS },
|
|
57
|
+
{ oldName: 'SlugHelper', newName: 'SlugUtility', packages: HELPERS },
|
|
58
|
+
{ oldName: 'CredentialHelper', newName: 'CredentialUtility', packages: HELPERS },
|
|
59
|
+
{ oldName: 'RejectionHelper', newName: 'RejectionUtility', packages: TESTING },
|
|
60
|
+
{ oldName: 'SpawnHelper', newName: 'SpawnUtility', packages: TESTING },
|
|
61
|
+
]; }
|
|
62
|
+
}
|
|
63
|
+
exports.ClassRenameTable = ClassRenameTable;
|
|
64
|
+
/** Renames the classes of `ClassRenameTable` where a file imports them. */
|
|
65
|
+
class ClassRenames {
|
|
66
|
+
static rewrite(opts) {
|
|
67
|
+
const { typescript: ts, fileName, source, reverse = false } = opts;
|
|
68
|
+
const rows = ClassRenameTable.ROWS.map((row) => reverse ? { ...row, oldName: row.newName, newName: row.oldName } : row);
|
|
69
|
+
const scriptKind = fileName.endsWith('.tsx') ? ts.ScriptKind.TSX : ts.ScriptKind.TS;
|
|
70
|
+
const file = ts.createSourceFile(fileName, source, ts.ScriptTarget.Latest, true, scriptKind);
|
|
71
|
+
const edits = new Map();
|
|
72
|
+
const rowsOf = (specifier) => rows.filter((row) => row.packages.some((name) => specifier === name || specifier.startsWith(`${name}/`)));
|
|
73
|
+
const rename = (node, row, text = row.newName) => {
|
|
74
|
+
const start = node.getStart(file);
|
|
75
|
+
edits.set(start, { start, end: node.getEnd(), text });
|
|
76
|
+
};
|
|
77
|
+
/** The local names to rename everywhere in the file, and the namespace imports whose members are renamed. */
|
|
78
|
+
const locals = new Map();
|
|
79
|
+
const namespaces = new Map();
|
|
80
|
+
for (const statement of file.statements) {
|
|
81
|
+
if ((ts.isImportDeclaration(statement) || ts.isExportDeclaration(statement)) &&
|
|
82
|
+
statement.moduleSpecifier &&
|
|
83
|
+
ts.isStringLiteralLike(statement.moduleSpecifier)) {
|
|
84
|
+
const owned = rowsOf(statement.moduleSpecifier.text);
|
|
85
|
+
if (owned.length === 0) {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (ts.isImportDeclaration(statement)) {
|
|
89
|
+
const bindings = statement.importClause?.namedBindings;
|
|
90
|
+
if (bindings && ts.isNamespaceImport(bindings)) {
|
|
91
|
+
namespaces.set(bindings.name.text, owned);
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (!bindings || !ts.isNamedImports(bindings)) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
for (const element of bindings.elements) {
|
|
98
|
+
const imported = element.propertyName ?? element.name;
|
|
99
|
+
const row = owned.find((entry) => entry.oldName === imported.text);
|
|
100
|
+
if (!row) {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
rename(imported, row);
|
|
104
|
+
if (!element.propertyName) {
|
|
105
|
+
locals.set(element.name.text, row);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else if (statement.exportClause && ts.isNamedExports(statement.exportClause)) {
|
|
110
|
+
for (const element of statement.exportClause.elements) {
|
|
111
|
+
const exported = element.propertyName ?? element.name;
|
|
112
|
+
const row = owned.find((entry) => entry.oldName === exported.text);
|
|
113
|
+
if (row) {
|
|
114
|
+
rename(exported, row);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (locals.size === 0 && namespaces.size === 0 && edits.size === 0) {
|
|
121
|
+
return { output: source, changed: false, rewritten: 0 };
|
|
122
|
+
}
|
|
123
|
+
/** An identifier that names a property, member or attribute, not the class. */
|
|
124
|
+
const isMemberName = (node) => {
|
|
125
|
+
const parent = node.parent;
|
|
126
|
+
if (ts.isPropertyAccessExpression(parent)) {
|
|
127
|
+
return parent.name === node;
|
|
128
|
+
}
|
|
129
|
+
if (ts.isQualifiedName(parent)) {
|
|
130
|
+
return parent.right === node;
|
|
131
|
+
}
|
|
132
|
+
if (ts.isBindingElement(parent)) {
|
|
133
|
+
return parent.propertyName === node;
|
|
134
|
+
}
|
|
135
|
+
return ((ts.isPropertyAssignment(parent) ||
|
|
136
|
+
ts.isPropertyDeclaration(parent) ||
|
|
137
|
+
ts.isPropertySignature(parent) ||
|
|
138
|
+
ts.isMethodDeclaration(parent) ||
|
|
139
|
+
ts.isMethodSignature(parent) ||
|
|
140
|
+
ts.isGetAccessorDeclaration(parent) ||
|
|
141
|
+
ts.isSetAccessorDeclaration(parent) ||
|
|
142
|
+
ts.isEnumMember(parent) ||
|
|
143
|
+
ts.isJsxAttribute(parent)) &&
|
|
144
|
+
parent.name === node);
|
|
145
|
+
};
|
|
146
|
+
const visit = (node) => {
|
|
147
|
+
if (ts.isImportDeclaration(node) || (ts.isExportDeclaration(node) && node.moduleSpecifier)) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (ts.isIdentifier(node)) {
|
|
151
|
+
const row = locals.get(node.text);
|
|
152
|
+
if (row && !isMemberName(node)) {
|
|
153
|
+
// `{ Old }` in an object literal or a destructuring keeps its key: `{ Old: New }`.
|
|
154
|
+
const isShorthand = (ts.isShorthandPropertyAssignment(node.parent) && node.parent.name === node) ||
|
|
155
|
+
(ts.isBindingElement(node.parent) &&
|
|
156
|
+
!node.parent.propertyName &&
|
|
157
|
+
node.parent.name === node);
|
|
158
|
+
rename(node, row, isShorthand ? `${node.text}: ${row.newName}` : row.newName);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (ts.isPropertyAccessExpression(node) || ts.isQualifiedName(node)) {
|
|
162
|
+
const [scope, member] = ts.isPropertyAccessExpression(node)
|
|
163
|
+
? [node.expression, node.name]
|
|
164
|
+
: [node.left, node.right];
|
|
165
|
+
const owned = ts.isIdentifier(scope) ? namespaces.get(scope.text) : undefined;
|
|
166
|
+
const row = owned?.find((entry) => entry.oldName === member.text);
|
|
167
|
+
if (row) {
|
|
168
|
+
rename(member, row);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
ts.forEachChild(node, visit);
|
|
172
|
+
};
|
|
173
|
+
visit(file);
|
|
174
|
+
let output = source;
|
|
175
|
+
for (const edit of [...edits.values()].sort((a, b) => b.start - a.start)) {
|
|
176
|
+
output = output.slice(0, edit.start) + edit.text + output.slice(edit.end);
|
|
177
|
+
}
|
|
178
|
+
return { output, changed: output !== source, rewritten: edits.size };
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
exports.ClassRenames = ClassRenames;
|
|
182
|
+
/**
|
|
183
|
+
* `devz codemod class-renames [paths...] [--write [--all] | --check] [--reverse]`: renames the classes IGNIS
|
|
184
|
+
* renamed. It is a dry run unless `--write` is given. `--check` is the same dry run, and exits 1 while a file
|
|
185
|
+
* would change.
|
|
186
|
+
*/
|
|
187
|
+
class ClassRenamesCommand {
|
|
188
|
+
static { this.USAGE = USAGE; }
|
|
189
|
+
static async run(opts) {
|
|
190
|
+
const { root, args } = opts;
|
|
191
|
+
if (args.includes(ClassRenameFlags.HELP) || args.includes(ClassRenameFlags.HELP_SHORT)) {
|
|
192
|
+
console.log(USAGE);
|
|
193
|
+
return 0;
|
|
194
|
+
}
|
|
195
|
+
const flags = args.filter((argument) => argument.startsWith('-'));
|
|
196
|
+
const paths = args.filter((argument) => !argument.startsWith('-'));
|
|
197
|
+
const unknown = flags.filter((flag) => !ClassRenameFlags.isValid(flag));
|
|
198
|
+
if (unknown.length > 0) {
|
|
199
|
+
console.error(`devz codemod: unknown option ${unknown.map((flag) => `"${flag}"`).join(', ')}\n${USAGE}`);
|
|
200
|
+
return USAGE_ERROR_CODE;
|
|
201
|
+
}
|
|
202
|
+
const isWrite = flags.includes(ClassRenameFlags.WRITE);
|
|
203
|
+
const isCheck = flags.includes(ClassRenameFlags.CHECK);
|
|
204
|
+
const isReverse = flags.includes(ClassRenameFlags.REVERSE);
|
|
205
|
+
if (isWrite && isCheck) {
|
|
206
|
+
console.error(`devz codemod: ${ClassRenameFlags.WRITE} and ${ClassRenameFlags.CHECK} contradict each other\n${USAGE}`);
|
|
207
|
+
return USAGE_ERROR_CODE;
|
|
208
|
+
}
|
|
209
|
+
const refusal = files_1.CodemodFiles.refusal({
|
|
210
|
+
command: 'class-renames',
|
|
211
|
+
isWrite,
|
|
212
|
+
isAll: flags.includes(ClassRenameFlags.ALL),
|
|
213
|
+
paths,
|
|
214
|
+
});
|
|
215
|
+
if (refusal) {
|
|
216
|
+
console.error(`${refusal}\n${USAGE}`);
|
|
217
|
+
return USAGE_ERROR_CODE;
|
|
218
|
+
}
|
|
219
|
+
let typescript;
|
|
220
|
+
try {
|
|
221
|
+
const loaded = await import('typescript');
|
|
222
|
+
typescript = loaded.default;
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
console.error('devz codemod: the "typescript" package is required to read your sources');
|
|
226
|
+
return 1;
|
|
227
|
+
}
|
|
228
|
+
const names = ClassRenameTable.ROWS.map((row) => (isReverse ? row.newName : row.oldName));
|
|
229
|
+
const targets = (paths.length > 0 ? paths : ['.']).map((path) => (0, node_path_1.resolve)(root, path));
|
|
230
|
+
let changedCount = 0;
|
|
231
|
+
let renamedCount = 0;
|
|
232
|
+
let refusedCount = 0;
|
|
233
|
+
for (const target of targets) {
|
|
234
|
+
const files = files_1.CodemodFiles.collect({ target });
|
|
235
|
+
const dirty = isWrite ? files_1.CodemodFiles.dirty({ target }) : undefined;
|
|
236
|
+
if (files.length === 0 && paths.length > 0) {
|
|
237
|
+
console.warn(`devz codemod: no source files under "${(0, node_path_1.relative)(root, target) || target}" (git ignores the path, or it holds none): nothing was read`);
|
|
238
|
+
}
|
|
239
|
+
for (const file of files) {
|
|
240
|
+
const source = (0, node_fs_1.readFileSync)(file, 'utf8');
|
|
241
|
+
if (!names.some((name) => source.includes(name))) {
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
const result = ClassRenames.rewrite({
|
|
245
|
+
typescript,
|
|
246
|
+
fileName: file,
|
|
247
|
+
source,
|
|
248
|
+
reverse: isReverse,
|
|
249
|
+
});
|
|
250
|
+
if (!result.changed) {
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
const shown = (0, node_path_1.relative)(root, file).split('\\').join('/') || file;
|
|
254
|
+
if (dirty?.has(file)) {
|
|
255
|
+
refusedCount += 1;
|
|
256
|
+
console.warn(`refused ${shown} has local changes (commit or stash them, then run again)`);
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
changedCount += 1;
|
|
260
|
+
renamedCount += result.rewritten;
|
|
261
|
+
console.log(`${isWrite ? 'changed' : 'would change'} ${shown} (${result.rewritten} name(s))`);
|
|
262
|
+
if (isWrite) {
|
|
263
|
+
(0, node_fs_1.writeFileSync)(file, result.output);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
console.log(`devz codemod class-renames: ${changedCount} file(s) ${isWrite ? 'changed' : 'would change'}, ${renamedCount} name(s) ${isWrite ? 'renamed' : 'would be renamed'}` +
|
|
268
|
+
(refusedCount > 0 ? `, ${refusedCount} refused` : ''));
|
|
269
|
+
if (!isWrite && changedCount > 0) {
|
|
270
|
+
console.log(`Nothing was written. Run again with ${ClassRenameFlags.WRITE} to apply, then run your typecheck.`);
|
|
271
|
+
}
|
|
272
|
+
if (isWrite && refusedCount > 0) {
|
|
273
|
+
return 1;
|
|
274
|
+
}
|
|
275
|
+
return isCheck && changedCount > 0 ? 1 : 0;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
exports.ClassRenamesCommand = ClassRenamesCommand;
|
|
279
|
+
//# sourceMappingURL=class-renames.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"class-renames.js","sourceRoot":"","sources":["../../../src/cli/codemod/class-renames.ts"],"names":[],"mappings":";;;AAAA,qCAAsD;AACtD,yCAA8C;AAC9C,mCAAuC;AAEvC,MAAM,KAAK,GAAG;;;;;;;;;;;;;;;;;;;;;6EAqB+D,CAAC;AAE9E,kDAAkD;AAClD,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAE3B,MAAM,gBAAgB;aACJ,UAAK,GAAG,SAAS,CAAC;aAClB,QAAG,GAAG,OAAO,CAAC;aACd,UAAK,GAAG,SAAS,CAAC;aAClB,YAAO,GAAG,WAAW,CAAC;aACtB,SAAI,GAAG,QAAQ,CAAC;aAChB,eAAU,GAAG,IAAI,CAAC;aAElB,eAAU,GAAG,IAAI,GAAG,CAAS;QAC3C,IAAI,CAAC,KAAK;QACV,IAAI,CAAC,GAAG;QACR,IAAI,CAAC,KAAK;QACV,IAAI,CAAC,OAAO;QACZ,IAAI,CAAC,IAAI;QACT,IAAI,CAAC,UAAU;KAChB,CAAC,CAAC;IAEH,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AAUH,qIAAqI;AACrI,MAAM,OAAO,GAAG,CAAC,wBAAwB,EAAE,gBAAgB,CAAC,CAAC;AAC7D,MAAM,OAAO,GAAG,CAAC,8BAA8B,CAAC,CAAC;AAEjD,0DAA0D;AAC1D,MAAa,gBAAgB;aACX,SAAI,GAAgC;QAClD,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,OAAO,EAAE;QACtE,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,aAAa,EAAE,Q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AAC,EAAE,CAAC;oBACrB,YAAY,IAAI,CAAC,CAAC;oBAClB,OAAO,CAAC,IAAI,CACV,YAAY,KAAK,4DAA4D,CAC9E,CAAC;oBACF,SAAS;gBACX,CAAC;gBAED,YAAY,IAAI,CAAC,CAAC;gBAClB,YAAY,IAAI,MAAM,CAAC,SAAS,CAAC;gBACjC,OAAO,CAAC,GAAG,CACT,GAAG,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,cAAc,KAAK,KAAK,MAAM,MAAM,CAAC,SAAS,WAAW,CACnF,CAAC;gBAEF,IAAI,OAAO,EAAE,CAAC;oBACZ,IAAA,uBAAa,EAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;gBACrC,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,CAAC,GAAG,CACT,+BAA+B,YAAY,YAAY,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,cAAc,KAAK,YAAY,YAAY,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,kBAAkB,EAAE;YAChK,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,YAAY,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CACxD,CAAC;QAEF,IAAI,CAAC,OAAO,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC;YACjC,OAAO,CAAC,GAAG,CACT,uCAAuC,gBAAgB,CAAC,KAAK,qCAAqC,CACnG,CAAC;QACJ,CAAC;QAED,IAAI,OAAO,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC;YAChC,OAAO,CAAC,CAAC;QACX,CAAC;QAED,OAAO,OAAO,IAAI,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7C,CAAC;;AApIH,kDAqIC","sourcesContent":["import { readFileSync, writeFileSync } from 'node:fs';\nimport { relative, resolve } from 'node:path';\nimport { CodemodFiles } from './files';\n\nconst USAGE = `Usage: devz codemod class-renames [paths...] [--write [--all] | --check] [--reverse]\n\nRenames the classes IGNIS renamed, at the import and at every use in the file: RetryHelper, SlugHelper\nand CredentialHelper (@venizia/ignis-helpers) become RetryUtility, SlugUtility and CredentialUtility,\nRejectionHelper and SpawnHelper (@venizia/dev-configs/testing) become RejectionUtility and SpawnUtility. One\ntable, in this file; a later rename adds a row.\n\nIt reads TypeScript files (.ts, .tsx, .mts, .cts): a named import or re-export from the package that owns\nthe class is renamed, and so is each use of the name it brought in (an aliased import, \"Old as Alias\", keeps\nits alias and changes only the imported name). A namespace import's member (\"ns.Old\") is renamed too. A .js,\n.cjs or .mjs file is not read, and neither is \"import('pkg').Old\": edit those by hand. A property or method that\nhas the same name as a class is left alone.\n\n --write write the changed files (without it, nothing is written); it needs a path, or --all\n --all with --write and no path: rewrite every source file under the working directory\n --check dry run that exits 1 while a file would change (for CI)\n --reverse rename back, for a downgrade\n --help print this text and exit\n\nWith no flag it lists what would change and writes nothing. Inside a git repository it reads the files git\nknows (tracked, or untracked and not ignored), and --write refuses a file with local changes (changed,\nstaged or untracked): commit or stash it first, so git can undo the codemod.`;\n\n/** A usage error: nothing was read or written. */\nconst USAGE_ERROR_CODE = 2;\n\nclass ClassRenameFlags {\n static readonly WRITE = '--write';\n static readonly ALL = '--all';\n static readonly CHECK = '--check';\n static readonly REVERSE = '--reverse';\n static readonly HELP = '--help';\n static readonly HELP_SHORT = '-h';\n\n static readonly SCHEME_SET = new Set<string>([\n this.WRITE,\n this.ALL,\n this.CHECK,\n this.REVERSE,\n this.HELP,\n this.HELP_SHORT,\n ]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\nexport interface IClassRename {\n oldName: string;\n newName: string;\n /** The packages that export it; a module specifier is theirs when it is the package or a sub-path of it. */\n packages: ReadonlyArray<string>;\n}\n\n/** `@venizia/ignis` re-exports the helpers as types only, so a value import of these classes comes from `@venizia/ignis-helpers`. */\nconst HELPERS = ['@venizia/ignis-helpers', '@venizia/ignis'];\nconst TESTING = ['@venizia/dev-configs/testing'];\n\n/** The renamed classes: add a row for the next rename. */\nexport class ClassRenameTable {\n static readonly ROWS: ReadonlyArray<IClassRename> = [\n { oldName: 'RetryHelper', newName: 'RetryUtility', packages: HELPERS },\n { oldName: 'SlugHelper', newName: 'SlugUtility', packages: HELPERS },\n { oldName: 'CredentialHelper', newName: 'CredentialUtility', packages: HELPERS },\n { oldName: 'RejectionHelper', newName: 'RejectionUtility', packages: TESTING },\n { oldName: 'SpawnHelper', newName: 'SpawnUtility', packages: TESTING },\n ];\n}\n\nexport interface IClassRenamesResult {\n output: string;\n changed: boolean;\n /** How many identifiers were renamed. */\n rewritten: number;\n}\n\n/** Renames the classes of `ClassRenameTable` where a file imports them. */\nexport class ClassRenames {\n static rewrite(opts: {\n typescript: typeof import('typescript');\n fileName: string;\n source: string;\n /** Rename the new names back to the old ones. */\n reverse?: boolean;\n }): IClassRenamesResult {\n const { typescript: ts, fileName, source, reverse = false } = opts;\n const rows = ClassRenameTable.ROWS.map((row) =>\n reverse ? { ...row, oldName: row.newName, newName: row.oldName } : row,\n );\n const scriptKind = fileName.endsWith('.tsx') ? ts.ScriptKind.TSX : ts.ScriptKind.TS;\n const file = ts.createSourceFile(fileName, source, ts.ScriptTarget.Latest, true, scriptKind);\n const edits = new Map<number, { start: number; end: number; text: string }>();\n\n const rowsOf = (specifier: string): ReadonlyArray<IClassRename> =>\n rows.filter((row) =>\n row.packages.some((name) => specifier === name || specifier.startsWith(`${name}/`)),\n );\n\n const rename = (node: import('typescript').Node, row: IClassRename, text = row.newName) => {\n const start = node.getStart(file);\n edits.set(start, { start, end: node.getEnd(), text });\n };\n\n /** The local names to rename everywhere in the file, and the namespace imports whose members are renamed. */\n const locals = new Map<string, IClassRename>();\n const namespaces = new Map<string, ReadonlyArray<IClassRename>>();\n\n for (const statement of file.statements) {\n if (\n (ts.isImportDeclaration(statement) || ts.isExportDeclaration(statement)) &&\n statement.moduleSpecifier &&\n ts.isStringLiteralLike(statement.moduleSpecifier)\n ) {\n const owned = rowsOf(statement.moduleSpecifier.text);\n\n if (owned.length === 0) {\n continue;\n }\n\n if (ts.isImportDeclaration(statement)) {\n const bindings = statement.importClause?.namedBindings;\n\n if (bindings && ts.isNamespaceImport(bindings)) {\n namespaces.set(bindings.name.text, owned);\n continue;\n }\n\n if (!bindings || !ts.isNamedImports(bindings)) {\n continue;\n }\n\n for (const element of bindings.elements) {\n const imported = element.propertyName ?? element.name;\n const row = owned.find((entry) => entry.oldName === imported.text);\n\n if (!row) {\n continue;\n }\n\n rename(imported, row);\n\n if (!element.propertyName) {\n locals.set(element.name.text, row);\n }\n }\n } else if (statement.exportClause && ts.isNamedExports(statement.exportClause)) {\n for (const element of statement.exportClause.elements) {\n const exported = element.propertyName ?? element.name;\n const row = owned.find((entry) => entry.oldName === exported.text);\n\n if (row) {\n rename(exported, row);\n }\n }\n }\n }\n }\n\n if (locals.size === 0 && namespaces.size === 0 && edits.size === 0) {\n return { output: source, changed: false, rewritten: 0 };\n }\n\n /** An identifier that names a property, member or attribute, not the class. */\n const isMemberName = (node: import('typescript').Identifier): boolean => {\n const parent = node.parent;\n\n if (ts.isPropertyAccessExpression(parent)) {\n return parent.name === node;\n }\n\n if (ts.isQualifiedName(parent)) {\n return parent.right === node;\n }\n\n if (ts.isBindingElement(parent)) {\n return parent.propertyName === node;\n }\n\n return (\n (ts.isPropertyAssignment(parent) ||\n ts.isPropertyDeclaration(parent) ||\n ts.isPropertySignature(parent) ||\n ts.isMethodDeclaration(parent) ||\n ts.isMethodSignature(parent) ||\n ts.isGetAccessorDeclaration(parent) ||\n ts.isSetAccessorDeclaration(parent) ||\n ts.isEnumMember(parent) ||\n ts.isJsxAttribute(parent)) &&\n parent.name === node\n );\n };\n\n const visit = (node: import('typescript').Node): void => {\n if (ts.isImportDeclaration(node) || (ts.isExportDeclaration(node) && node.moduleSpecifier)) {\n return;\n }\n\n if (ts.isIdentifier(node)) {\n const row = locals.get(node.text);\n\n if (row && !isMemberName(node)) {\n // `{ Old }` in an object literal or a destructuring keeps its key: `{ Old: New }`.\n const isShorthand =\n (ts.isShorthandPropertyAssignment(node.parent) && node.parent.name === node) ||\n (ts.isBindingElement(node.parent) &&\n !node.parent.propertyName &&\n node.parent.name === node);\n\n rename(node, row, isShorthand ? `${node.text}: ${row.newName}` : row.newName);\n }\n }\n\n if (ts.isPropertyAccessExpression(node) || ts.isQualifiedName(node)) {\n const [scope, member] = ts.isPropertyAccessExpression(node)\n ? [node.expression, node.name]\n : [node.left, node.right];\n const owned = ts.isIdentifier(scope) ? namespaces.get(scope.text) : undefined;\n const row = owned?.find((entry) => entry.oldName === member.text);\n\n if (row) {\n rename(member, row);\n }\n }\n\n ts.forEachChild(node, visit);\n };\n\n visit(file);\n\n let output = source;\n\n for (const edit of [...edits.values()].sort((a, b) => b.start - a.start)) {\n output = output.slice(0, edit.start) + edit.text + output.slice(edit.end);\n }\n\n return { output, changed: output !== source, rewritten: edits.size };\n }\n}\n\n/**\n * `devz codemod class-renames [paths...] [--write [--all] | --check] [--reverse]`: renames the classes IGNIS\n * renamed. It is a dry run unless `--write` is given. `--check` is the same dry run, and exits 1 while a file\n * would change.\n */\nexport class ClassRenamesCommand {\n static readonly USAGE = USAGE;\n\n static async run(opts: { root: string; args: string[] }): Promise<number> {\n const { root, args } = opts;\n\n if (args.includes(ClassRenameFlags.HELP) || args.includes(ClassRenameFlags.HELP_SHORT)) {\n console.log(USAGE);\n\n return 0;\n }\n\n const flags = args.filter((argument) => argument.startsWith('-'));\n const paths = args.filter((argument) => !argument.startsWith('-'));\n const unknown = flags.filter((flag) => !ClassRenameFlags.isValid(flag));\n\n if (unknown.length > 0) {\n console.error(\n `devz codemod: unknown option ${unknown.map((flag) => `\"${flag}\"`).join(', ')}\\n${USAGE}`,\n );\n\n return USAGE_ERROR_CODE;\n }\n\n const isWrite = flags.includes(ClassRenameFlags.WRITE);\n const isCheck = flags.includes(ClassRenameFlags.CHECK);\n const isReverse = flags.includes(ClassRenameFlags.REVERSE);\n\n if (isWrite && isCheck) {\n console.error(\n `devz codemod: ${ClassRenameFlags.WRITE} and ${ClassRenameFlags.CHECK} contradict each other\\n${USAGE}`,\n );\n\n return USAGE_ERROR_CODE;\n }\n\n const refusal = CodemodFiles.refusal({\n command: 'class-renames',\n isWrite,\n isAll: flags.includes(ClassRenameFlags.ALL),\n paths,\n });\n\n if (refusal) {\n console.error(`${refusal}\\n${USAGE}`);\n\n return USAGE_ERROR_CODE;\n }\n\n let typescript: typeof import('typescript');\n\n try {\n const loaded = await import('typescript');\n typescript = loaded.default;\n } catch {\n console.error('devz codemod: the \"typescript\" package is required to read your sources');\n\n return 1;\n }\n\n const names = ClassRenameTable.ROWS.map((row) => (isReverse ? row.newName : row.oldName));\n const targets = (paths.length > 0 ? paths : ['.']).map((path) => resolve(root, path));\n let changedCount = 0;\n let renamedCount = 0;\n let refusedCount = 0;\n\n for (const target of targets) {\n const files = CodemodFiles.collect({ target });\n const dirty = isWrite ? CodemodFiles.dirty({ target }) : undefined;\n\n if (files.length === 0 && paths.length > 0) {\n console.warn(\n `devz codemod: no source files under \"${relative(root, target) || target}\" (git ignores the path, or it holds none): nothing was read`,\n );\n }\n\n for (const file of files) {\n const source = readFileSync(file, 'utf8');\n\n if (!names.some((name) => source.includes(name))) {\n continue;\n }\n\n const result = ClassRenames.rewrite({\n typescript,\n fileName: file,\n source,\n reverse: isReverse,\n });\n\n if (!result.changed) {\n continue;\n }\n\n const shown = relative(root, file).split('\\\\').join('/') || file;\n\n if (dirty?.has(file)) {\n refusedCount += 1;\n console.warn(\n `refused ${shown} has local changes (commit or stash them, then run again)`,\n );\n continue;\n }\n\n changedCount += 1;\n renamedCount += result.rewritten;\n console.log(\n `${isWrite ? 'changed' : 'would change'} ${shown} (${result.rewritten} name(s))`,\n );\n\n if (isWrite) {\n writeFileSync(file, result.output);\n }\n }\n }\n\n console.log(\n `devz codemod class-renames: ${changedCount} file(s) ${isWrite ? 'changed' : 'would change'}, ${renamedCount} name(s) ${isWrite ? 'renamed' : 'would be renamed'}` +\n (refusedCount > 0 ? `, ${refusedCount} refused` : ''),\n );\n\n if (!isWrite && changedCount > 0) {\n console.log(\n `Nothing was written. Run again with ${ClassRenameFlags.WRITE} to apply, then run your typecheck.`,\n );\n }\n\n if (isWrite && refusedCount > 0) {\n return 1;\n }\n\n return isCheck && changedCount > 0 ? 1 : 0;\n }\n}\n"]}
|
|
@@ -4,6 +4,7 @@ exports.CodemodCommand = void 0;
|
|
|
4
4
|
const any_aliases_1 = require("./any-aliases");
|
|
5
5
|
const async_style_1 = require("./async-style");
|
|
6
6
|
const binding_keys_1 = require("./binding-keys");
|
|
7
|
+
const class_renames_1 = require("./class-renames");
|
|
7
8
|
const connector_imports_1 = require("./connector-imports");
|
|
8
9
|
const const_classes_1 = require("./const-classes");
|
|
9
10
|
const env_get_1 = require("./env-get");
|
|
@@ -18,6 +19,7 @@ const USAGE = [
|
|
|
18
19
|
env_get_1.EnvGetCommand.USAGE,
|
|
19
20
|
any_aliases_1.AnyAliasesCommand.USAGE,
|
|
20
21
|
binding_keys_1.BindingKeysCommand.USAGE,
|
|
22
|
+
class_renames_1.ClassRenamesCommand.USAGE,
|
|
21
23
|
].join('\n\n');
|
|
22
24
|
/** The codemods `devz codemod <name>` runs. */
|
|
23
25
|
const NAME_LIST = [
|
|
@@ -29,6 +31,7 @@ const NAME_LIST = [
|
|
|
29
31
|
'env-get',
|
|
30
32
|
'any-aliases',
|
|
31
33
|
'binding-keys',
|
|
34
|
+
'class-renames',
|
|
32
35
|
];
|
|
33
36
|
const NAMES = NAME_LIST.join(', ');
|
|
34
37
|
/** A usage error: nothing was read or written. */
|
|
@@ -79,6 +82,9 @@ class CodemodCommand {
|
|
|
79
82
|
if (name === 'binding-keys') {
|
|
80
83
|
return binding_keys_1.BindingKeysCommand.run({ root: opts.root, args: rest });
|
|
81
84
|
}
|
|
85
|
+
if (name === 'class-renames') {
|
|
86
|
+
return class_renames_1.ClassRenamesCommand.run({ root: opts.root, args: rest });
|
|
87
|
+
}
|
|
82
88
|
if (args.includes('--help') || args.includes('-h')) {
|
|
83
89
|
console.log(USAGE);
|
|
84
90
|
return 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cli/codemod/index.ts"],"names":[],"mappings":";;;AAAA,+CAAkD;AAClD,+CAAkD;AAClD,iDAAoD;AACpD,2DAA8D;AAC9D,mDAAsD;AACtD,uCAA0C;AAC1C,iEAAmE;AACnE,+DAAkE;AAElE,MAAM,KAAK,GAAG;IACZ,gDAAyB,CAAC,KAAK;IAC/B,mCAAmB,CAAC,KAAK;IACzB,+BAAiB,CAAC,KAAK;IACvB,+CAAyB,CAAC,KAAK;IAC/B,2CAAuB,CAAC,KAAK;IAC7B,uBAAa,CAAC,KAAK;IACnB,+BAAiB,CAAC,KAAK;IACvB,iCAAkB,CAAC,KAAK;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cli/codemod/index.ts"],"names":[],"mappings":";;;AAAA,+CAAkD;AAClD,+CAAkD;AAClD,iDAAoD;AACpD,mDAAsD;AACtD,2DAA8D;AAC9D,mDAAsD;AACtD,uCAA0C;AAC1C,iEAAmE;AACnE,+DAAkE;AAElE,MAAM,KAAK,GAAG;IACZ,gDAAyB,CAAC,KAAK;IAC/B,mCAAmB,CAAC,KAAK;IACzB,+BAAiB,CAAC,KAAK;IACvB,+CAAyB,CAAC,KAAK;IAC/B,2CAAuB,CAAC,KAAK;IAC7B,uBAAa,CAAC,KAAK;IACnB,+BAAiB,CAAC,KAAK;IACvB,iCAAkB,CAAC,KAAK;IACxB,mCAAmB,CAAC,KAAK;CAC1B,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAEf,+CAA+C;AAC/C,MAAM,SAAS,GAAG;IAChB,sBAAsB;IACtB,eAAe;IACf,aAAa;IACb,qBAAqB;IACrB,mBAAmB;IACnB,SAAS;IACT,aAAa;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AQ,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YACnD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YAEnB,OAAO,CAAC,CAAC;QACX,CAAC;QAED,OAAO,CAAC,KAAK,CACX,kCAAkC,IAAI,IAAI,EAAE,yBAAyB,KAAK,OAAO,KAAK,EAAE,CACzF,CAAC;QAEF,OAAO,gBAAgB,CAAC;IAC1B,CAAC;CACF;AAjED,wCAiEC","sourcesContent":["import { AnyAliasesCommand } from './any-aliases';\nimport { AsyncStyleCommand } from './async-style';\nimport { BindingKeysCommand } from './binding-keys';\nimport { ClassRenamesCommand } from './class-renames';\nimport { ConnectorImportsCommand } from './connector-imports';\nimport { ConstClassesCommand } from './const-classes';\nimport { EnvGetCommand } from './env-get';\nimport { DropRedundantCastsCommand } from './drop-redundant-casts';\nimport { NamespaceFunctionsCommand } from './namespace-functions';\n\nconst USAGE = [\n DropRedundantCastsCommand.USAGE,\n ConstClassesCommand.USAGE,\n AsyncStyleCommand.USAGE,\n NamespaceFunctionsCommand.USAGE,\n ConnectorImportsCommand.USAGE,\n EnvGetCommand.USAGE,\n AnyAliasesCommand.USAGE,\n BindingKeysCommand.USAGE,\n ClassRenamesCommand.USAGE,\n].join('\\n\\n');\n\n/** The codemods `devz codemod <name>` runs. */\nconst NAME_LIST = [\n 'drop-redundant-casts',\n 'const-classes',\n 'async-style',\n 'namespace-functions',\n 'connector-imports',\n 'env-get',\n 'any-aliases',\n 'binding-keys',\n 'class-renames',\n];\nconst NAMES = NAME_LIST.join(', ');\n\n/** A usage error: nothing was read or written. */\nconst USAGE_ERROR_CODE = 2;\n\n/** The codemods that are style rewrites, not migrations: there is no downgrade of them. */\nconst NOT_REVERSIBLE = new Set([\n 'drop-redundant-casts',\n 'const-classes',\n 'async-style',\n 'env-get',\n 'any-aliases',\n 'binding-keys',\n]);\n\n/** `devz codemod <name> [args]`: hands the arguments to the codemod called `name`. */\nexport class CodemodCommand {\n static async run(opts: { root: string; args: string[] }): Promise<number> {\n const { args } = opts;\n const [name, ...rest] = args;\n\n if (name === '--list') {\n console.log(NAME_LIST.join('\\n'));\n\n return 0;\n }\n\n if (name !== undefined && NOT_REVERSIBLE.has(name) && rest.includes('--reverse')) {\n console.error(`devz codemod ${name}: not reversible`);\n\n return USAGE_ERROR_CODE;\n }\n\n if (name === 'drop-redundant-casts') {\n return DropRedundantCastsCommand.run({ root: opts.root, args: rest });\n }\n\n if (name === 'const-classes') {\n return ConstClassesCommand.run({ root: opts.root, args: rest });\n }\n\n if (name === 'async-style') {\n return AsyncStyleCommand.run({ root: opts.root, args: rest });\n }\n\n if (name === 'namespace-functions') {\n return NamespaceFunctionsCommand.run({ root: opts.root, args: rest });\n }\n\n if (name === 'connector-imports') {\n return ConnectorImportsCommand.run({ root: opts.root, args: rest });\n }\n\n if (name === 'env-get') {\n return EnvGetCommand.run({ root: opts.root, args: rest });\n }\n\n if (name === 'any-aliases') {\n return AnyAliasesCommand.run({ root: opts.root, args: rest });\n }\n\n if (name === 'binding-keys') {\n return BindingKeysCommand.run({ root: opts.root, args: rest });\n }\n\n if (name === 'class-renames') {\n return ClassRenamesCommand.run({ root: opts.root, args: rest });\n }\n\n if (args.includes('--help') || args.includes('-h')) {\n console.log(USAGE);\n\n return 0;\n }\n\n console.error(\n `devz codemod: unknown codemod \"${name ?? ''}\" | the codemods are: ${NAMES}\\n\\n${USAGE}`,\n );\n\n return USAGE_ERROR_CODE;\n }\n}\n"]}
|
|
@@ -137,14 +137,14 @@ exports.DEV_CONFIGS_MAPPINGS = [
|
|
|
137
137
|
{
|
|
138
138
|
modules: TESTING,
|
|
139
139
|
oldName: 'rejectionOf',
|
|
140
|
-
className: '
|
|
140
|
+
className: 'RejectionUtility',
|
|
141
141
|
method: 'rejectionOf',
|
|
142
142
|
params: [{ key: 'task' }],
|
|
143
143
|
},
|
|
144
144
|
{
|
|
145
145
|
modules: TESTING,
|
|
146
146
|
oldName: 'expectRejection',
|
|
147
|
-
className: '
|
|
147
|
+
className: 'RejectionUtility',
|
|
148
148
|
method: 'expectRejection',
|
|
149
149
|
params: [],
|
|
150
150
|
keepsOptions: true,
|
|
@@ -167,7 +167,7 @@ exports.DEV_CONFIGS_MAPPINGS = [
|
|
|
167
167
|
{
|
|
168
168
|
modules: TESTING,
|
|
169
169
|
oldName: 'spawnSyncBounded',
|
|
170
|
-
className: '
|
|
170
|
+
className: 'SpawnUtility',
|
|
171
171
|
method: 'spawnSyncBounded',
|
|
172
172
|
params: [],
|
|
173
173
|
keepsOptions: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev-configs.js","sourceRoot":"","sources":["../../../../../src/cli/codemod/namespace-functions/mappings/dev-configs.ts"],"names":[],"mappings":";;;AAEA,MAAM,MAAM,GAAG,CAAC,6BAA6B,CAAC,CAAC;AAC/C,MAAM,OAAO,GAAG,CAAC,8BAA8B,CAAC,CAAC;AACjD,MAAM,OAAO,GAAG,CAAC,sBAAsB,EAAE,8BAA8B,CAAC,CAAC;AAEzE;;;GAGG;AACU,QAAA,oBAAoB,GAAqC;IACpE;QACE,OAAO,EAAE,MAAM;QACf,OAAO,EAAE,qBAAqB;QAC9B,SAAS,EAAE,cAAc;QACzB,MAAM,EAAE,MAAM;QACd,MAAM,EAAE,EAAE;QACV,YAAY,EAAE,IAAI;KACnB;IACD;QACE,OAAO,EAAE,MAAM;QACf,OAAO,EAAE,iBAAiB;QAC1B,SAAS,EAAE,mBAAmB;QAC9B,MAAM,EAAE,KAAK;QACb,MAAM,EAAE,EAAE;QACV,YAAY,EAAE,IAAI;KACnB;IACD;QACE,OAAO,EAAE,MAAM;QACf,OAAO,EAAE,2BAA2B;QACpC,SAAS,EAAE,gBAAgB;QAC3B,MAAM,EAAE,2BAA2B;QACnC,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE,EAAE,GAAG,EAAE,gBAAgB,EAAE,QAAQ,EAAE,IAAI,EAAE,CA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AE;QACV,YAAY,EAAE,IAAI;KACnB;IACD;QACE,OAAO,EAAE,MAAM;QACf,OAAO,EAAE,kBAAkB;QAC3B,SAAS,EAAE,mBAAmB;QAC9B,MAAM,EAAE,MAAM;QACd,MAAM,EAAE,EAAE;QACV,YAAY,EAAE,IAAI;KACnB;IACD;QACE,OAAO,EAAE,MAAM;QACf,OAAO,EAAE,cAAc;QACvB,SAAS,EAAE,iBAAiB;QAC5B,MAAM,EAAE,cAAc;QACtB,MAAM,EAAE,EAAE;QACV,YAAY,EAAE,IAAI;KACnB;IACD;QACE,OAAO,EAAE,MAAM;QACf,OAAO,EAAE,qBAAqB;QAC9B,SAAS,EAAE,iBAAiB;QAC5B,MAAM,EAAE,qBAAqB;QAC7B,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC;KAC7B;IACD;QACE,OAAO,EAAE,MAAM;QACf,OAAO,EAAE,cAAc;QACvB,SAAS,EAAE,iBAAiB;QAC5B,MAAM,EAAE,cAAc;QACtB,MAAM,EAAE,EAAE;QACV,YAAY,EAAE,IAAI;KACnB;IACD;QACE,OAAO,EAAE,MAAM;QACf,OAAO,EAAE,kBAAkB;QAC3B,SAAS,EAAE,iBAAiB;QAC5B,MAAM,EAAE,cAAc;QACtB,MAAM,EAAE,EAAE;QACV,YAAY,EAAE,IAAI;KACnB;IACD;QACE,OAAO,EAAE,OAAO;QAChB,OAAO,EAAE,aAAa;QACtB,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"dev-configs.js","sourceRoot":"","sources":["../../../../../src/cli/codemod/namespace-functions/mappings/dev-configs.ts"],"names":[],"mappings":";;;AAEA,MAAM,MAAM,GAAG,CAAC,6BAA6B,CAAC,CAAC;AAC/C,MAAM,OAAO,GAAG,CAAC,8BAA8B,CAAC,CAAC;AACjD,MAAM,OAAO,GAAG,CAAC,sBAAsB,EAAE,8BAA8B,CAAC,CAAC;AAEzE;;;GAGG;AACU,QAAA,oBAAoB,GAAqC;IACpE;QAC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jB,MAAM,EAAE,EAAE;QACV,YAAY,EAAE,IAAI;KACnB;CACF,CAAC","sourcesContent":["import type { INamespaceMapping } from '../mapping';\n\nconst CHECKS = ['@venizia/dev-configs/checks'];\nconst TESTING = ['@venizia/dev-configs/testing'];\nconst LINTERS = ['@venizia/dev-configs', '@venizia/dev-configs/linters'];\n\n/**\n * The functions of `@venizia/dev-configs` that moved into a class. An entry with `keepsOptions` is a\n * function that already took ONE options object: its class method takes the same one.\n */\nexport const DEV_CONFIGS_MAPPINGS: ReadonlyArray<INamespaceMapping> = [\n {\n modules: CHECKS,\n oldName: 'findCatalogProblems',\n className: 'CatalogCheck',\n method: 'find',\n params: [],\n keepsOptions: true,\n },\n {\n modules: CHECKS,\n oldName: 'runModuleCycles',\n className: 'ModuleCyclesCheck',\n method: 'run',\n params: [],\n keepsOptions: true,\n },\n {\n modules: CHECKS,\n oldName: 'assertNoWorkspaceExternal',\n className: 'PurityManifest',\n method: 'assertNoWorkspaceExternal',\n params: [{ key: 'manifest' }, { key: 'workspaceScope', optional: true }],\n },\n {\n modules: CHECKS,\n oldName: 'deriveEntries',\n className: 'PurityManifest',\n method: 'deriveEntries',\n params: [],\n keepsOptions: true,\n },\n {\n modules: CHECKS,\n oldName: 'assertBrowserEsmEntry',\n className: 'PurityManifest',\n method: 'assertBrowserEsmEntry',\n params: [],\n keepsOptions: true,\n },\n {\n modules: CHECKS,\n oldName: 'buildManifest',\n className: 'PurityManifest',\n method: 'build',\n params: [],\n keepsOptions: true,\n },\n {\n modules: CHECKS,\n oldName: 'stripBundlerPathComments',\n className: 'PurityProbe',\n method: 'stripBundlerPathComments',\n params: [{ key: 'text' }],\n },\n {\n modules: CHECKS,\n oldName: 'probeEntry',\n className: 'PurityProbe',\n method: 'probeEntry',\n params: [],\n keepsOptions: true,\n },\n {\n modules: CHECKS,\n oldName: 'checkPurity',\n className: 'PurityCheck',\n method: 'run',\n params: [],\n keepsOptions: true,\n },\n {\n modules: CHECKS,\n oldName: 'listTestTitles',\n className: 'TestControlsCheck',\n method: 'listTitles',\n params: [],\n keepsOptions: true,\n },\n {\n modules: CHECKS,\n oldName: 'checkControls',\n className: 'TestControlsCheck',\n method: 'run',\n params: [],\n keepsOptions: true,\n },\n {\n modules: CHECKS,\n oldName: 'findDeadTestCode',\n className: 'DeadTestCodeCheck',\n method: 'find',\n params: [],\n keepsOptions: true,\n },\n {\n modules: CHECKS,\n oldName: 'replayLedger',\n className: 'TestMutateCheck',\n method: 'replayLedger',\n params: [],\n keepsOptions: true,\n },\n {\n modules: CHECKS,\n oldName: 'formatLedgerResults',\n className: 'TestMutateCheck',\n method: 'formatLedgerResults',\n params: [{ key: 'results' }],\n },\n {\n modules: CHECKS,\n oldName: 'analyseJunit',\n className: 'TestWeightCheck',\n method: 'analyseJunit',\n params: [],\n keepsOptions: true,\n },\n {\n modules: CHECKS,\n oldName: 'formatTestWeight',\n className: 'TestWeightCheck',\n method: 'formatReport',\n params: [],\n keepsOptions: true,\n },\n {\n modules: TESTING,\n oldName: 'rejectionOf',\n className: 'RejectionUtility',\n method: 'rejectionOf',\n params: [{ key: 'task' }],\n },\n {\n modules: TESTING,\n oldName: 'expectRejection',\n className: 'RejectionUtility',\n method: 'expectRejection',\n params: [],\n keepsOptions: true,\n },\n {\n modules: TESTING,\n oldName: 'findRepositoryRoot',\n className: 'RepoTmp',\n method: 'findRoot',\n params: [{ key: 'start', optional: true }],\n },\n {\n modules: TESTING,\n oldName: 'useRepoTmp',\n className: 'RepoTmp',\n method: 'apply',\n params: [],\n keepsOptions: true,\n },\n {\n modules: TESTING,\n oldName: 'spawnSyncBounded',\n className: 'SpawnUtility',\n method: 'spawnSyncBounded',\n params: [],\n keepsOptions: true,\n },\n {\n modules: LINTERS,\n oldName: 'readField',\n className: 'AstNode',\n method: 'readField',\n params: [],\n keepsOptions: true,\n },\n {\n modules: LINTERS,\n oldName: 'nodeType',\n className: 'AstNode',\n method: 'getType',\n params: [],\n keepsOptions: true,\n },\n];\n"]}
|
package/dist/testing/index.d.ts
CHANGED
package/dist/testing/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./rejection.
|
|
17
|
+
__exportStar(require("./rejection.utility"), exports);
|
|
18
18
|
__exportStar(require("./repo-tmp"), exports);
|
|
19
|
-
__exportStar(require("./spawn.
|
|
19
|
+
__exportStar(require("./spawn.utility"), exports);
|
|
20
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC;AACpC,6CAA2B;AAC3B,kDAAgC","sourcesContent":["export * from './rejection.utility';\nexport * from './repo-tmp';\nexport * from './spawn.utility';\n"]}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/** Test helpers for asserting that a promise rejects, without the typing and un-awaited-assertion pitfalls of `expect(task).rejects`. */
|
|
2
|
-
export declare class
|
|
2
|
+
export declare class RejectionUtility {
|
|
3
3
|
/**
|
|
4
4
|
* Awaits a task that must reject and returns what it rejected with; throws when the task resolves.
|
|
5
5
|
*
|
|
6
6
|
* bun types the async matchers (`expect(task).rejects` / `.resolves`) as `void`, so
|
|
7
7
|
* `await expect(task).rejects.toThrow()` is refused by `await-thenable` - and left un-awaited the
|
|
8
8
|
* assertion never runs. Awaiting the task itself needs no matcher and no cast:
|
|
9
|
-
* `
|
|
10
|
-
* `expect(await
|
|
9
|
+
* `RejectionUtility.expectRejection({ task, message })` or
|
|
10
|
+
* `expect(await RejectionUtility.rejectionOf({ task })).toBeInstanceOf(Error)`,
|
|
11
11
|
* and for a resolution `expect(await task).toMatchObject(...)`.
|
|
12
12
|
*/
|
|
13
13
|
static rejectionOf(opts: {
|
|
@@ -24,4 +24,4 @@ export declare class RejectionHelper {
|
|
|
24
24
|
message: string | RegExp;
|
|
25
25
|
}): Promise<void>;
|
|
26
26
|
}
|
|
27
|
-
//# sourceMappingURL=rejection.
|
|
27
|
+
//# sourceMappingURL=rejection.utility.d.ts.map
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.RejectionUtility = void 0;
|
|
4
4
|
const bun_test_1 = require("bun:test");
|
|
5
5
|
/** Test helpers for asserting that a promise rejects, without the typing and un-awaited-assertion pitfalls of `expect(task).rejects`. */
|
|
6
|
-
class
|
|
6
|
+
class RejectionUtility {
|
|
7
7
|
/**
|
|
8
8
|
* Awaits a task that must reject and returns what it rejected with; throws when the task resolves.
|
|
9
9
|
*
|
|
10
10
|
* bun types the async matchers (`expect(task).rejects` / `.resolves`) as `void`, so
|
|
11
11
|
* `await expect(task).rejects.toThrow()` is refused by `await-thenable` - and left un-awaited the
|
|
12
12
|
* assertion never runs. Awaiting the task itself needs no matcher and no cast:
|
|
13
|
-
* `
|
|
14
|
-
* `expect(await
|
|
13
|
+
* `RejectionUtility.expectRejection({ task, message })` or
|
|
14
|
+
* `expect(await RejectionUtility.rejectionOf({ task })).toBeInstanceOf(Error)`,
|
|
15
15
|
* and for a resolution `expect(await task).toMatchObject(...)`.
|
|
16
16
|
*/
|
|
17
17
|
static async rejectionOf(opts) {
|
|
@@ -31,10 +31,10 @@ class RejectionHelper {
|
|
|
31
31
|
*/
|
|
32
32
|
static async expectRejection(opts) {
|
|
33
33
|
const { task, message } = opts;
|
|
34
|
-
const reason = await
|
|
34
|
+
const reason = await RejectionUtility.rejectionOf({ task });
|
|
35
35
|
(0, bun_test_1.expect)(reason).toBeInstanceOf(Error);
|
|
36
36
|
(0, bun_test_1.expect)(reason instanceof Error ? reason.message : String(reason)).toMatch(message);
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
exports.
|
|
40
|
-
//# sourceMappingURL=rejection.
|
|
39
|
+
exports.RejectionUtility = RejectionUtility;
|
|
40
|
+
//# sourceMappingURL=rejection.utility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rejection.utility.js","sourceRoot":"","sources":["../../src/testing/rejection.utility.ts"],"names":[],"mappings":";;;AAAA,uCAAkC;AAElC,yIAAyI;AACzI,MAAa,gBAAgB;IAC3B;;;;;;;;;OASG;IACH,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,IAAgC;QACvD,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,IAAI,CAAC;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,iBAAM,CAAC,WAAW,CAAC,8CAA8C,CAAC,CAAC;IAC5E,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,IAG5B;QACC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;QAC/B,MAAM,MAAM,GAAG,MAAM,gBAAgB,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;QAE5D,IAAA,iBAAM,EAAC,MAAM,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QACrC,IAAA,iBAAM,EAAC,MAAM,YAAY,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACrF,CAAC;CACF;AArCD,4CAqCC","sourcesContent":["import { expect } from 'bun:test';\n\n/** Test helpers for asserting that a promise rejects, without the typing and un-awaited-assertion pitfalls of `expect(task).rejects`. */\nexport class RejectionUtility {\n /**\n * Awaits a task that must reject and returns what it rejected with; throws when the task resolves.\n *\n * bun types the async matchers (`expect(task).rejects` / `.resolves`) as `void`, so\n * `await expect(task).rejects.toThrow()` is refused by `await-thenable` - and left un-awaited the\n * assertion never runs. Awaiting the task itself needs no matcher and no cast:\n * `RejectionUtility.expectRejection({ task, message })` or\n * `expect(await RejectionUtility.rejectionOf({ task })).toBeInstanceOf(Error)`,\n * and for a resolution `expect(await task).toMatchObject(...)`.\n */\n static async rejectionOf(opts: { task: Promise<unknown> }): Promise<unknown> {\n try {\n await opts.task;\n } catch (error) {\n return error;\n }\n\n return expect.unreachable('Expected the task to reject, but it resolved');\n }\n\n /**\n * The task rejects with an Error whose message contains `message` (a string) or matches it (a\n * RegExp). The message is compared as a string on purpose: bun 1.4.2 `toMatchObject` with an\n * asymmetric matcher overwrites the matched property on the object it checks, so a later read of\n * `error.message` gets the matcher back.\n */\n static async expectRejection(opts: {\n task: Promise<unknown>;\n message: string | RegExp;\n }): Promise<void> {\n const { task, message } = opts;\n const reason = await RejectionUtility.rejectionOf({ task });\n\n expect(reason).toBeInstanceOf(Error);\n expect(reason instanceof Error ? reason.message : String(reason)).toMatch(message);\n }\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** Long enough for a cold `bun build` under a loaded parallel run; it bounds a stall, not a slow run. */
|
|
2
2
|
export declare const SPAWN_TIMEOUT_MS = 120000;
|
|
3
3
|
/** Bounded wrappers around `Bun.spawn*` for tests, so a stuck child cannot stall a suite. */
|
|
4
|
-
export declare class
|
|
4
|
+
export declare class SpawnUtility {
|
|
5
5
|
/**
|
|
6
6
|
* `Bun.spawnSync`, bounded. A sync spawn blocks the worker thread, so bun's own test timeout cannot
|
|
7
7
|
* fire while it waits: the `timeout` option is the only bound. Its default signal, SIGTERM, can be
|
|
@@ -13,4 +13,4 @@ export declare class SpawnHelper {
|
|
|
13
13
|
onExit?: undefined;
|
|
14
14
|
}): Bun.SyncSubprocess<Out, Err>;
|
|
15
15
|
}
|
|
16
|
-
//# sourceMappingURL=spawn.
|
|
16
|
+
//# sourceMappingURL=spawn.utility.d.ts.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.SpawnUtility = exports.SPAWN_TIMEOUT_MS = void 0;
|
|
4
4
|
/** Long enough for a cold `bun build` under a loaded parallel run; it bounds a stall, not a slow run. */
|
|
5
5
|
exports.SPAWN_TIMEOUT_MS = 120_000;
|
|
6
6
|
/** Bounded wrappers around `Bun.spawn*` for tests, so a stuck child cannot stall a suite. */
|
|
7
|
-
class
|
|
7
|
+
class SpawnUtility {
|
|
8
8
|
/**
|
|
9
9
|
* `Bun.spawnSync`, bounded. A sync spawn blocks the worker thread, so bun's own test timeout cannot
|
|
10
10
|
* fire while it waits: the `timeout` option is the only bound. Its default signal, SIGTERM, can be
|
|
@@ -20,10 +20,10 @@ class SpawnHelper {
|
|
|
20
20
|
});
|
|
21
21
|
if (result.exitedDueToTimeout) {
|
|
22
22
|
// eslint-disable-next-line venizia/no-new-error -- getError would be a dev-configs -> inversion cycle
|
|
23
|
-
throw new Error(`[
|
|
23
|
+
throw new Error(`[SpawnUtility.spawnSyncBounded] did not exit within ${timeout} ms, killed | cmd: ${opts.cmd.join(' ').slice(0, 200)}`);
|
|
24
24
|
}
|
|
25
25
|
return result;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
exports.
|
|
29
|
-
//# sourceMappingURL=spawn.
|
|
28
|
+
exports.SpawnUtility = SpawnUtility;
|
|
29
|
+
//# sourceMappingURL=spawn.utility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spawn.utility.js","sourceRoot":"","sources":["../../src/testing/spawn.utility.ts"],"names":[],"mappings":";;;AAAA,yGAAyG;AAC5F,QAAA,gBAAgB,GAAG,OAAO,CAAC;AAExC,6FAA6F;AAC7F,MAAa,YAAY;IACvB;;;;;OAKG;IACH,MAAM,CAAC,gBAAgB,CAIrB,IAA6F;QAC7F,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,wBAAgB,CAAC;QACjD,MAAM,MAAM,GAAG,GAAG,CAAC,SAAS,CAAe;YACzC,GAAG,IAAI;YACP,OAAO;YACP,UAAU,EAAE,SAAkB;SAC/B,CAAC,CAAC;QAEH,IAAI,MAAM,CAAC,kBAAkB,EAAE,CAAC;YAC9B,sGAAsG;YACtG,MAAM,IAAI,KAAK,CACb,uDAAuD,OAAO,sBAAsB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CACvH,CAAC;QACJ,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA5BD,oCA4BC","sourcesContent":["/** Long enough for a cold `bun build` under a loaded parallel run; it bounds a stall, not a slow run. */\nexport const SPAWN_TIMEOUT_MS = 120_000;\n\n/** Bounded wrappers around `Bun.spawn*` for tests, so a stuck child cannot stall a suite. */\nexport class SpawnUtility {\n /**\n * `Bun.spawnSync`, bounded. A sync spawn blocks the worker thread, so bun's own test timeout cannot\n * fire while it waits: the `timeout` option is the only bound. Its default signal, SIGTERM, can be\n * outlived by a stuck child - one such child once stalled a whole suite for 770s - so this kills with\n * SIGKILL, and throws naming the command instead of returning a half-finished result.\n */\n static spawnSyncBounded<\n const In extends Bun.SpawnOptions.Writable = 'ignore',\n const Out extends Bun.SpawnOptions.Readable = 'pipe',\n const Err extends Bun.SpawnOptions.Readable = 'pipe',\n >(opts: Bun.SpawnOptions.SpawnSyncOptions<In, Out, Err> & { cmd: string[]; onExit?: undefined }) {\n const timeout = opts.timeout ?? SPAWN_TIMEOUT_MS;\n const result = Bun.spawnSync<In, Out, Err>({\n ...opts,\n timeout,\n killSignal: 'SIGKILL' as const,\n });\n\n if (result.exitedDueToTimeout) {\n // eslint-disable-next-line venizia/no-new-error -- getError would be a dev-configs -> inversion cycle\n throw new Error(\n `[SpawnUtility.spawnSyncBounded] did not exit within ${timeout} ms, killed | cmd: ${opts.cmd.join(' ').slice(0, 200)}`,\n );\n }\n\n return result;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@venizia/dev-configs",
|
|
3
|
-
"version": "0.5.0-
|
|
3
|
+
"version": "0.5.0-4",
|
|
4
4
|
"description": "Shareable development configurations for TypeScript projects: oxlint presets with per-rule builders, the ESLint naming-convention rule, the legacy ESLint flat config, and TypeScript compiler options with critical decorator support (experimentalDecorators, emitDecoratorMetadata, useDefineForClassFields). Single source of truth for consistent code style, type checking, and build settings across monorepo packages.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"build-tools",
|