@venizia/dev-configs 0.4.8 → 0.5.0-1
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.
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** One site the codemod would change or cannot change. */
|
|
2
|
+
export interface IBindingKeysResult {
|
|
3
|
+
output: string;
|
|
4
|
+
changed: boolean;
|
|
5
|
+
rewritten: number;
|
|
6
|
+
/** Lines where `build<unknown>` was written because the call named no type. */
|
|
7
|
+
unnamed: number[];
|
|
8
|
+
manual: Array<{
|
|
9
|
+
line: number;
|
|
10
|
+
reason: string;
|
|
11
|
+
}>;
|
|
12
|
+
}
|
|
13
|
+
/** Rewrites raw binding keys to `BindingKeys.build<T>({ key })`. */
|
|
14
|
+
export declare class BindingKeysCodemod {
|
|
15
|
+
/** The module `BindingKeys` comes from in this file: an existing import, the module of `inject`, a @venizia/ignis import, or `fallback`. */
|
|
16
|
+
private static readIdentifierSource;
|
|
17
|
+
/** The local name `BindingKeys` is imported under (an alias included), or `BindingKeys` when the file does not import it. */
|
|
18
|
+
private static readBuilderName;
|
|
19
|
+
static rewrite(opts: {
|
|
20
|
+
typescript: typeof import('typescript');
|
|
21
|
+
fileName: string;
|
|
22
|
+
source: string;
|
|
23
|
+
/** The module `BindingKeys` is imported from when the file gives no better one. */
|
|
24
|
+
importFrom?: string;
|
|
25
|
+
/** The program's source file for `fileName` and its checker: a call is rewritten only when the checker resolves it to the container. */
|
|
26
|
+
program?: {
|
|
27
|
+
sourceFile: import('typescript').SourceFile;
|
|
28
|
+
checker: import('typescript').TypeChecker;
|
|
29
|
+
};
|
|
30
|
+
/** Reads a file for the package.json lookup; defaults to the file system. */
|
|
31
|
+
readFile?: (path: string) => string | undefined;
|
|
32
|
+
}): IBindingKeysResult;
|
|
33
|
+
}
|
|
34
|
+
/** `devz codemod binding-keys [paths...] [--write | --check]`: rewrites raw binding keys to `BindingKeys.build<T>`. */
|
|
35
|
+
export declare class BindingKeysCommand {
|
|
36
|
+
static readonly USAGE = "Usage: devz codemod binding-keys [paths...] [--write [--all] | --check] [--import-from <module>]\n\nRewrites the raw binding keys of the @venizia/ignis-inversion release where a key is made by BindingKeys.build<T>:\n\n container.get<Mailer>({ key: 'services.Mailer' }) becomes container.get({ key: BindingKeys.build<Mailer>({ key: 'services.Mailer' }) })\n container.bind({ key: 'services.Mailer' }) becomes container.bind({ key: BindingKeys.build<unknown>({ key: 'services.Mailer' }) })\n @inject({ key: 'services.Mailer' }) becomes @inject({ key: BindingKeys.build<unknown>({ key: 'services.Mailer' }) })\n container.get({ key: { namespace, key } }) becomes container.get({ key: BindingKeys.build<unknown>({ namespace, key }) })\n container.get({ key: `${namespace}.Name` }) becomes container.get({ key: BindingKeys.build<unknown>({ namespace, key: 'Name' }) })\n BindingKeys.build({ key }) becomes BindingKeys.build<unknown>({ key })\n\nThe key string is never changed.\n\nA call is rewritten only when the TypeScript checker resolves it to the framework's container (Container, IContainer,\nBinding) or to its inject and provide, under any local name. A redis.get<T>({ key }), a worker pool or a class of your own\nis left alone, type argument included. The checker reads your project through the nearest tsconfig.json, so run the codemod\nfrom the project root with the dependencies installed; a receiver it cannot resolve is listed as \"manual\". The call's own type argument moves into build<T>, so the caller keeps the type it\nclaimed; without one the codemod writes build<unknown> and lists the site (\"type\"): name the real type there.\n\nIt rewrites a call named get, gets, getBinding, bind, isBound or unbind whose argument is an object literal with a\n`key` (and, for get, `isOptional`), and a call of inject or provide. A container cannot be told from syntax, so the shape is the\ntest. A string key, a substitution-free template literal, a { namespace, key } literal and a template written\n${namespace}.Name or ${namespace}.${name} are rewritten. These are listed\nas \"manual\" and left alone: a key made at run time (a template with substitutions, a call) and a Symbol key (symbols are no\nlonger keys). A key that is a const of the file (const MAILER = 'services.Mailer') is rewritten where it is declared. Any\nother name or property (Keys.MAILER) is left alone without a line: it may already be a built key, and your typecheck\nnames a raw one.\n\nBindingKeys is imported from the module the file already takes inject from, else from the first @venizia/ignis import,\nor from --import-from <module>; a file with none of them is listed as manual and not rewritten. An existing import of\nBindingKeys is reused. A second run changes nothing.\n\nIt reads TypeScript files (.ts, .tsx, .mts, .cts). A .js, .cjs or .mjs file is not read: edit it by hand.\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 or a manual site remains (for CI)\n --import-from the module BindingKeys is imported from when the file gives no better one\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 knows, and\n--write refuses a file with local changes: commit or stash it first, so git can undo it.\nThere is no --reverse: a downgrade restores the files from git.";
|
|
37
|
+
/**
|
|
38
|
+
* The program the checker answers from: the project's own tsconfig (the nearest one above `root`) with the files the
|
|
39
|
+
* codemod reads added, so a receiver resolves the way the project's typecheck resolves it.
|
|
40
|
+
*/
|
|
41
|
+
static createProgram(opts: {
|
|
42
|
+
typescript: typeof import('typescript');
|
|
43
|
+
root: string;
|
|
44
|
+
files: string[];
|
|
45
|
+
}): import('typescript').Program;
|
|
46
|
+
static run(opts: {
|
|
47
|
+
root: string;
|
|
48
|
+
args: string[];
|
|
49
|
+
}): Promise<number>;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=binding-keys.d.ts.map
|
|
@@ -0,0 +1,719 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BindingKeysCommand = exports.BindingKeysCodemod = 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 binding-keys [paths...] [--write [--all] | --check] [--import-from <module>]
|
|
8
|
+
|
|
9
|
+
Rewrites the raw binding keys of the @venizia/ignis-inversion release where a key is made by BindingKeys.build<T>:
|
|
10
|
+
|
|
11
|
+
container.get<Mailer>({ key: 'services.Mailer' }) becomes container.get({ key: BindingKeys.build<Mailer>({ key: 'services.Mailer' }) })
|
|
12
|
+
container.bind({ key: 'services.Mailer' }) becomes container.bind({ key: BindingKeys.build<unknown>({ key: 'services.Mailer' }) })
|
|
13
|
+
@inject({ key: 'services.Mailer' }) becomes @inject({ key: BindingKeys.build<unknown>({ key: 'services.Mailer' }) })
|
|
14
|
+
container.get({ key: { namespace, key } }) becomes container.get({ key: BindingKeys.build<unknown>({ namespace, key }) })
|
|
15
|
+
container.get({ key: \`\${namespace}.Name\` }) becomes container.get({ key: BindingKeys.build<unknown>({ namespace, key: 'Name' }) })
|
|
16
|
+
BindingKeys.build({ key }) becomes BindingKeys.build<unknown>({ key })
|
|
17
|
+
|
|
18
|
+
The key string is never changed.
|
|
19
|
+
|
|
20
|
+
A call is rewritten only when the TypeScript checker resolves it to the framework's container (Container, IContainer,
|
|
21
|
+
Binding) or to its inject and provide, under any local name. A redis.get<T>({ key }), a worker pool or a class of your own
|
|
22
|
+
is left alone, type argument included. The checker reads your project through the nearest tsconfig.json, so run the codemod
|
|
23
|
+
from the project root with the dependencies installed; a receiver it cannot resolve is listed as "manual". The call's own type argument moves into build<T>, so the caller keeps the type it
|
|
24
|
+
claimed; without one the codemod writes build<unknown> and lists the site ("type"): name the real type there.
|
|
25
|
+
|
|
26
|
+
It rewrites a call named get, gets, getBinding, bind, isBound or unbind whose argument is an object literal with a
|
|
27
|
+
\`key\` (and, for get, \`isOptional\`), and a call of inject or provide. A container cannot be told from syntax, so the shape is the
|
|
28
|
+
test. A string key, a substitution-free template literal, a { namespace, key } literal and a template written
|
|
29
|
+
\${namespace}.Name or \${namespace}.\${name} are rewritten. These are listed
|
|
30
|
+
as "manual" and left alone: a key made at run time (a template with substitutions, a call) and a Symbol key (symbols are no
|
|
31
|
+
longer keys). A key that is a const of the file (const MAILER = 'services.Mailer') is rewritten where it is declared. Any
|
|
32
|
+
other name or property (Keys.MAILER) is left alone without a line: it may already be a built key, and your typecheck
|
|
33
|
+
names a raw one.
|
|
34
|
+
|
|
35
|
+
BindingKeys is imported from the module the file already takes inject from, else from the first @venizia/ignis import,
|
|
36
|
+
or from --import-from <module>; a file with none of them is listed as manual and not rewritten. An existing import of
|
|
37
|
+
BindingKeys is reused. A second run changes nothing.
|
|
38
|
+
|
|
39
|
+
It reads TypeScript files (.ts, .tsx, .mts, .cts). A .js, .cjs or .mjs file is not read: edit it by hand.
|
|
40
|
+
|
|
41
|
+
--write write the changed files (without it, nothing is written); it needs a path, or --all
|
|
42
|
+
--all with --write and no path: rewrite every source file under the working directory
|
|
43
|
+
--check dry run that exits 1 while a file would change or a manual site remains (for CI)
|
|
44
|
+
--import-from the module BindingKeys is imported from when the file gives no better one
|
|
45
|
+
--help print this text and exit
|
|
46
|
+
|
|
47
|
+
With no flag it lists what would change and writes nothing. Inside a git repository it reads the files git knows, and
|
|
48
|
+
--write refuses a file with local changes: commit or stash it first, so git can undo it.
|
|
49
|
+
There is no --reverse: a downgrade restores the files from git.`;
|
|
50
|
+
/** A usage error: nothing was read or written. */
|
|
51
|
+
const USAGE_ERROR_CODE = 2;
|
|
52
|
+
/** The methods whose options object carries a container key. */
|
|
53
|
+
const KEY_METHODS = new Set(['get', 'gets', 'getBinding', 'bind', 'isBound', 'unbind']);
|
|
54
|
+
/** The other properties a key options object may carry and still be one. */
|
|
55
|
+
const OPTION_NAMES = new Set(['key', 'isOptional', 'scope']);
|
|
56
|
+
/** The decorators that take a key options object. */
|
|
57
|
+
const KEY_DECORATORS = new Set(['inject', 'provide']);
|
|
58
|
+
/** Where a file already imports the container API from. */
|
|
59
|
+
const IGNIS_MODULE = /^@venizia\/ignis(?:-kernel|-inversion)?$/;
|
|
60
|
+
const BUILDER = 'BindingKeys';
|
|
61
|
+
/** The classes and interfaces whose key methods are the container's. */
|
|
62
|
+
const CONTAINER_TYPES = new Set([
|
|
63
|
+
'IContainer',
|
|
64
|
+
'AbstractContainer',
|
|
65
|
+
'BaseContainer',
|
|
66
|
+
'Container',
|
|
67
|
+
'Binding',
|
|
68
|
+
]);
|
|
69
|
+
/** The packages that declare the container: the framework is identified by name, wherever it is installed or checked out. */
|
|
70
|
+
const FRAMEWORK_PACKAGES = new Set([
|
|
71
|
+
'@venizia/ignis',
|
|
72
|
+
'@venizia/ignis-inversion',
|
|
73
|
+
'@venizia/ignis-kernel',
|
|
74
|
+
]);
|
|
75
|
+
/** A module of the framework: a file's own barrel is not a place to take `BindingKeys` from. */
|
|
76
|
+
const VENIZIA_MODULE = /^@venizia\//;
|
|
77
|
+
class BindingKeysFlags {
|
|
78
|
+
static { this.WRITE = '--write'; }
|
|
79
|
+
static { this.ALL = '--all'; }
|
|
80
|
+
static { this.CHECK = '--check'; }
|
|
81
|
+
static { this.IMPORT_FROM = '--import-from'; }
|
|
82
|
+
static { this.HELP = '--help'; }
|
|
83
|
+
static { this.HELP_SHORT = '-h'; }
|
|
84
|
+
static { this.SCHEME_SET = new Set([
|
|
85
|
+
this.WRITE,
|
|
86
|
+
this.ALL,
|
|
87
|
+
this.CHECK,
|
|
88
|
+
this.IMPORT_FROM,
|
|
89
|
+
this.HELP,
|
|
90
|
+
this.HELP_SHORT,
|
|
91
|
+
]); }
|
|
92
|
+
static isValid(value) {
|
|
93
|
+
return this.SCHEME_SET.has(value);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/** Rewrites raw binding keys to `BindingKeys.build<T>({ key })`. */
|
|
97
|
+
class BindingKeysCodemod {
|
|
98
|
+
/** The module `BindingKeys` comes from in this file: an existing import, the module of `inject`, a @venizia/ignis import, or `fallback`. */
|
|
99
|
+
static readIdentifierSource(opts) {
|
|
100
|
+
const { typescript: ts, file, fallback } = opts;
|
|
101
|
+
let injectModule;
|
|
102
|
+
let ignisModule;
|
|
103
|
+
let named;
|
|
104
|
+
let declared = false;
|
|
105
|
+
for (const statement of file.statements) {
|
|
106
|
+
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)) {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
const module = statement.moduleSpecifier.text;
|
|
110
|
+
const bindings = statement.importClause?.namedBindings;
|
|
111
|
+
const isTypeOnly = statement.importClause?.isTypeOnly === true;
|
|
112
|
+
if (bindings === undefined || !ts.isNamedImports(bindings)) {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
for (const element of bindings.elements) {
|
|
116
|
+
const imported = (element.propertyName ?? element.name).text;
|
|
117
|
+
if (imported === BUILDER && !isTypeOnly && !element.isTypeOnly) {
|
|
118
|
+
declared = true;
|
|
119
|
+
}
|
|
120
|
+
if (imported === 'inject' && injectModule === undefined && VENIZIA_MODULE.test(module)) {
|
|
121
|
+
injectModule = module;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (IGNIS_MODULE.test(module) && !isTypeOnly) {
|
|
125
|
+
ignisModule ??= module;
|
|
126
|
+
named ??= bindings;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return { module: injectModule ?? ignisModule ?? fallback, declared, named };
|
|
130
|
+
}
|
|
131
|
+
/** The local name `BindingKeys` is imported under (an alias included), or `BindingKeys` when the file does not import it. */
|
|
132
|
+
static readBuilderName(opts) {
|
|
133
|
+
const { typescript: ts, file } = opts;
|
|
134
|
+
for (const statement of file.statements) {
|
|
135
|
+
const bindings = ts.isImportDeclaration(statement)
|
|
136
|
+
? statement.importClause?.namedBindings
|
|
137
|
+
: undefined;
|
|
138
|
+
if (bindings === undefined || !ts.isNamedImports(bindings)) {
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
for (const element of bindings.elements) {
|
|
142
|
+
if ((element.propertyName ?? element.name).text === BUILDER) {
|
|
143
|
+
return element.name.text;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return BUILDER;
|
|
148
|
+
}
|
|
149
|
+
static rewrite(opts) {
|
|
150
|
+
const { typescript: ts, fileName, importFrom, program, readFile = (path) => ts.sys.readFile(path), } = opts;
|
|
151
|
+
const language = fileName.endsWith('.tsx') ? ts.ScriptKind.TSX : ts.ScriptKind.TS;
|
|
152
|
+
const file = program?.sourceFile ??
|
|
153
|
+
ts.createSourceFile(fileName, opts.source, ts.ScriptTarget.Latest, true, language);
|
|
154
|
+
const source = file.text;
|
|
155
|
+
const checker = program?.checker;
|
|
156
|
+
const builder = BindingKeysCodemod.readBuilderName({ typescript: ts, file });
|
|
157
|
+
const edits = [];
|
|
158
|
+
const manual = [];
|
|
159
|
+
const unnamed = [];
|
|
160
|
+
const handled = new Set();
|
|
161
|
+
/** `const NAME = 'literal'` declared once in the file: a key held in a constant is rewritten where it is declared. */
|
|
162
|
+
const constants = new Map();
|
|
163
|
+
const duplicates = new Set();
|
|
164
|
+
let rewritten = 0;
|
|
165
|
+
const lineOf = (node) => file.getLineAndCharacterOfPosition(node.getStart(file)).line + 1;
|
|
166
|
+
const propertyOf = (node, name) => {
|
|
167
|
+
for (const property of node.properties) {
|
|
168
|
+
if (ts.isPropertyAssignment(property) &&
|
|
169
|
+
(ts.isIdentifier(property.name) || ts.isStringLiteral(property.name)) &&
|
|
170
|
+
property.name.text === name) {
|
|
171
|
+
return property;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return undefined;
|
|
175
|
+
};
|
|
176
|
+
/** An object literal whose properties are all in `names` and that has a `key`: the shape of a key options object. */
|
|
177
|
+
const isKeyOptions = (node) => {
|
|
178
|
+
if (node === undefined || !ts.isObjectLiteralExpression(node)) {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
return (propertyOf(node, 'key') !== undefined &&
|
|
182
|
+
node.properties.every((property) => ts.isPropertyAssignment(property) &&
|
|
183
|
+
(ts.isIdentifier(property.name) || ts.isStringLiteral(property.name)) &&
|
|
184
|
+
OPTION_NAMES.has(property.name.text)));
|
|
185
|
+
};
|
|
186
|
+
const isBuilderCall = (node) => ts.isCallExpression(node) &&
|
|
187
|
+
ts.isPropertyAccessExpression(node.expression) &&
|
|
188
|
+
ts.isIdentifier(node.expression.expression) &&
|
|
189
|
+
node.expression.expression.text === builder &&
|
|
190
|
+
node.expression.name.text === 'build';
|
|
191
|
+
const isSymbolExpression = (node) => (ts.isCallExpression(node) &&
|
|
192
|
+
((ts.isIdentifier(node.expression) && node.expression.text === 'Symbol') ||
|
|
193
|
+
(ts.isPropertyAccessExpression(node.expression) &&
|
|
194
|
+
ts.isIdentifier(node.expression.expression) &&
|
|
195
|
+
node.expression.expression.text === 'Symbol'))) ||
|
|
196
|
+
(ts.isPropertyAccessExpression(node) &&
|
|
197
|
+
ts.isIdentifier(node.expression) &&
|
|
198
|
+
node.expression.text === 'Symbol');
|
|
199
|
+
/**
|
|
200
|
+
* The `{ namespace, key }` text of a template written as `${namespace}.Name` or `${namespace}.${name}` (the two
|
|
201
|
+
* shapes the framework's own keys take), or `undefined` for any other template.
|
|
202
|
+
*/
|
|
203
|
+
const namespaceKeyOf = (node) => {
|
|
204
|
+
const { head, templateSpans } = node;
|
|
205
|
+
if (head.text !== '') {
|
|
206
|
+
return undefined;
|
|
207
|
+
}
|
|
208
|
+
if (templateSpans.length === 1 && templateSpans[0].literal.text.startsWith('.')) {
|
|
209
|
+
const tail = templateSpans[0].literal.text.slice(1);
|
|
210
|
+
return tail === ''
|
|
211
|
+
? undefined
|
|
212
|
+
: `{ namespace: ${templateSpans[0].expression.getText(file)}, key: '${tail.replace(/'/g, "\\'")}' }`;
|
|
213
|
+
}
|
|
214
|
+
if (templateSpans.length === 2 &&
|
|
215
|
+
templateSpans[0].literal.text === '.' &&
|
|
216
|
+
templateSpans[1].literal.text === '') {
|
|
217
|
+
return `{ namespace: ${templateSpans[0].expression.getText(file)}, key: ${templateSpans[1].expression.getText(file)} }`;
|
|
218
|
+
}
|
|
219
|
+
return undefined;
|
|
220
|
+
};
|
|
221
|
+
/**
|
|
222
|
+
* Wraps the key of one options object. `typeText` is the value type the call already claimed, or `undefined` for
|
|
223
|
+
* `unknown`. Answers whether the key was rewritten.
|
|
224
|
+
*/
|
|
225
|
+
const rewriteKey = (options, typeText) => {
|
|
226
|
+
const property = propertyOf(options, 'key');
|
|
227
|
+
if (property === undefined) {
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
const value = property.initializer;
|
|
231
|
+
const text = typeText ?? 'unknown';
|
|
232
|
+
if (ts.isStringLiteral(value) || ts.isNoSubstitutionTemplateLiteral(value)) {
|
|
233
|
+
edits.push({
|
|
234
|
+
start: value.getStart(file),
|
|
235
|
+
end: value.getEnd(),
|
|
236
|
+
text: `${builder}.build<${text}>({ key: ${value.getText(file)} })`,
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
else if (ts.isObjectLiteralExpression(value) &&
|
|
240
|
+
propertyOf(value, 'key') !== undefined &&
|
|
241
|
+
value.properties.every((item) => ts.isPropertyAssignment(item) &&
|
|
242
|
+
ts.isIdentifier(item.name) &&
|
|
243
|
+
(item.name.text === 'key' || item.name.text === 'namespace'))) {
|
|
244
|
+
edits.push({
|
|
245
|
+
start: value.getStart(file),
|
|
246
|
+
end: value.getEnd(),
|
|
247
|
+
text: `${builder}.build<${text}>(${value.getText(file)})`,
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
else if (ts.isTemplateExpression(value) && namespaceKeyOf(value) !== undefined) {
|
|
251
|
+
edits.push({
|
|
252
|
+
start: value.getStart(file),
|
|
253
|
+
end: value.getEnd(),
|
|
254
|
+
text: `${builder}.build<${text}>(${namespaceKeyOf(value)})`,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
else if (ts.isIdentifier(value) &&
|
|
258
|
+
constants.has(value.text) &&
|
|
259
|
+
!duplicates.has(value.text)) {
|
|
260
|
+
const declaration = constants.get(value.text);
|
|
261
|
+
if (declaration?.initializer === undefined || handled.has(declaration)) {
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
handled.add(declaration);
|
|
265
|
+
edits.push({
|
|
266
|
+
start: declaration.initializer.getStart(file),
|
|
267
|
+
end: declaration.initializer.getEnd(),
|
|
268
|
+
text: `${builder}.build<${text}>({ key: ${declaration.initializer.getText(file)} })`,
|
|
269
|
+
});
|
|
270
|
+
if (typeText === undefined) {
|
|
271
|
+
unnamed.push(lineOf(declaration));
|
|
272
|
+
}
|
|
273
|
+
rewritten += 1;
|
|
274
|
+
return true;
|
|
275
|
+
}
|
|
276
|
+
else if (isBuilderCall(value)) {
|
|
277
|
+
if (value.typeArguments !== undefined) {
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
handled.add(value);
|
|
281
|
+
// `BindingKeys.build(` then the argument: the type argument goes between the name and the parenthesis.
|
|
282
|
+
edits.push({
|
|
283
|
+
start: value.expression.getEnd(),
|
|
284
|
+
end: value.expression.getEnd(),
|
|
285
|
+
text: `<${text}>`,
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
else if (isSymbolExpression(value)) {
|
|
289
|
+
manual.push({
|
|
290
|
+
line: lineOf(value),
|
|
291
|
+
reason: 'a Symbol key: symbols are no longer binding keys, use BindingKeys.build<T>({ key: "..." })',
|
|
292
|
+
});
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
// A name or a property (`MAILER`, `Keys.MAILER`) may already be a built key, and the typecheck names a raw
|
|
297
|
+
// one: only an expression that makes a string at run time is listed.
|
|
298
|
+
const isReference = ts.isIdentifier(value) ||
|
|
299
|
+
ts.isPropertyAccessExpression(value) ||
|
|
300
|
+
ts.isElementAccessExpression(value);
|
|
301
|
+
if (isReference && checker !== undefined) {
|
|
302
|
+
const type = checker.getTypeAtLocation(value);
|
|
303
|
+
if (type.flags & ts.TypeFlags.StringLike && type.getProperty('valueType') === undefined) {
|
|
304
|
+
manual.push({
|
|
305
|
+
line: lineOf(value),
|
|
306
|
+
reason: 'a string held in a name: build it with BindingKeys.build<T>({ key }) where it is defined (a key of a package you do not own is built by that package)',
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if (!isReference) {
|
|
311
|
+
manual.push({
|
|
312
|
+
line: lineOf(value),
|
|
313
|
+
reason: 'a key made at run time (a template with substitutions, a call): build it with BindingKeys.build<T>({ key }) where it is made',
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
318
|
+
rewritten += 1;
|
|
319
|
+
if (typeText === undefined) {
|
|
320
|
+
unnamed.push(lineOf(value));
|
|
321
|
+
}
|
|
322
|
+
return true;
|
|
323
|
+
};
|
|
324
|
+
/** The declaration the checker resolves a call to, or `undefined` when it cannot (an unresolved receiver). */
|
|
325
|
+
const declarationOf = (node) => checker?.getResolvedSignature(node)?.declaration;
|
|
326
|
+
const packageNames = new Map();
|
|
327
|
+
/**
|
|
328
|
+
* The name in the nearest package.json above `directory` that has one, or `undefined` when there is none. A package.json
|
|
329
|
+
* without a name does not end the walk: an installed package ships `dist/esm/package.json` (`{ "type": "module" }`) beside
|
|
330
|
+
* the declarations, and the package's own file is further up.
|
|
331
|
+
*/
|
|
332
|
+
const packageNameAbove = (directory) => {
|
|
333
|
+
if (packageNames.has(directory)) {
|
|
334
|
+
return packageNames.get(directory);
|
|
335
|
+
}
|
|
336
|
+
const text = readFile((0, node_path_1.join)(directory, 'package.json'));
|
|
337
|
+
const parent = (0, node_path_1.dirname)(directory);
|
|
338
|
+
let name;
|
|
339
|
+
if (text !== undefined) {
|
|
340
|
+
const parsed = JSON.parse(text);
|
|
341
|
+
if (typeof parsed === 'object' &&
|
|
342
|
+
parsed !== null &&
|
|
343
|
+
'name' in parsed &&
|
|
344
|
+
typeof parsed.name === 'string') {
|
|
345
|
+
name = parsed.name;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
if (name === undefined && parent !== directory) {
|
|
349
|
+
name = packageNameAbove(parent);
|
|
350
|
+
}
|
|
351
|
+
packageNames.set(directory, name);
|
|
352
|
+
return name;
|
|
353
|
+
};
|
|
354
|
+
/** A declaration of the framework: the nearest package.json above its file names one of the framework's packages. */
|
|
355
|
+
const isFrameworkFile = (declaration) => {
|
|
356
|
+
const name = packageNameAbove((0, node_path_1.dirname)(declaration.getSourceFile().fileName));
|
|
357
|
+
return name !== undefined && FRAMEWORK_PACKAGES.has(name);
|
|
358
|
+
};
|
|
359
|
+
/** `container.get(...)`: the checker resolves the method to the container's (or `Binding`'s), declared by the framework. */
|
|
360
|
+
const isContainerMethod = (declaration) => {
|
|
361
|
+
if (declaration === undefined || !isFrameworkFile(declaration)) {
|
|
362
|
+
return false;
|
|
363
|
+
}
|
|
364
|
+
const owner = declaration.parent;
|
|
365
|
+
return ((ts.isClassLike(owner) || ts.isInterfaceDeclaration(owner)) &&
|
|
366
|
+
owner.name !== undefined &&
|
|
367
|
+
CONTAINER_TYPES.has(owner.name.text));
|
|
368
|
+
};
|
|
369
|
+
/** `inject(...)` or `provide(...)` under any local name: the checker follows the import to the framework's. */
|
|
370
|
+
const isFrameworkDecorator = (callee) => {
|
|
371
|
+
if (checker === undefined || !ts.isIdentifier(callee)) {
|
|
372
|
+
return false;
|
|
373
|
+
}
|
|
374
|
+
const symbol = checker.getSymbolAtLocation(callee);
|
|
375
|
+
const target = symbol !== undefined && symbol.flags & ts.SymbolFlags.Alias
|
|
376
|
+
? checker.getAliasedSymbol(symbol)
|
|
377
|
+
: symbol;
|
|
378
|
+
const declaration = target?.declarations?.[0];
|
|
379
|
+
return (declaration !== undefined &&
|
|
380
|
+
KEY_DECORATORS.has(target?.name ?? '') &&
|
|
381
|
+
isFrameworkFile(declaration));
|
|
382
|
+
};
|
|
383
|
+
/** Whether a type mentions a type parameter of a function or class that encloses `from`. */
|
|
384
|
+
const mentionsScopedTypeParameter = (type, from) => {
|
|
385
|
+
const scoped = new Set();
|
|
386
|
+
for (let scope = from; scope !== undefined; scope = scope.parent) {
|
|
387
|
+
const parameters = ts.isFunctionLike(scope) || ts.isClassLike(scope) ? scope.typeParameters : undefined;
|
|
388
|
+
for (const parameter of parameters ?? []) {
|
|
389
|
+
scoped.add(parameter.name.text);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
const search = (node) => (ts.isTypeReferenceNode(node) &&
|
|
393
|
+
ts.isIdentifier(node.typeName) &&
|
|
394
|
+
scoped.has(node.typeName.text)) ||
|
|
395
|
+
ts.forEachChild(node, (child) => (search(child) ? true : undefined)) === true;
|
|
396
|
+
return search(type);
|
|
397
|
+
};
|
|
398
|
+
/** The text of a decorated parameter's type with `undefined` left out: the key names what is injected, not its absence. */
|
|
399
|
+
const liftedTypeText = (type) => {
|
|
400
|
+
if (!ts.isUnionTypeNode(type)) {
|
|
401
|
+
return type.getText(file);
|
|
402
|
+
}
|
|
403
|
+
const kept = type.types.filter((member) => member.kind !== ts.SyntaxKind.UndefinedKeyword);
|
|
404
|
+
return kept.map((member) => member.getText(file)).join(' | ');
|
|
405
|
+
};
|
|
406
|
+
const visit = (node) => {
|
|
407
|
+
if (ts.isCallExpression(node)) {
|
|
408
|
+
const callee = node.expression;
|
|
409
|
+
const first = node.arguments[0];
|
|
410
|
+
const methodName = ts.isPropertyAccessExpression(callee) && KEY_METHODS.has(callee.name.text)
|
|
411
|
+
? callee.name.text
|
|
412
|
+
: undefined;
|
|
413
|
+
if (isBuilderCall(node) &&
|
|
414
|
+
node.typeArguments === undefined &&
|
|
415
|
+
node.arguments.length === 1) {
|
|
416
|
+
if (handled.has(node)) {
|
|
417
|
+
ts.forEachChild(node, visit);
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
const argument = node.arguments[0];
|
|
421
|
+
if (ts.isObjectLiteralExpression(argument) && propertyOf(argument, 'key') !== undefined) {
|
|
422
|
+
edits.push({
|
|
423
|
+
start: node.expression.getEnd(),
|
|
424
|
+
end: node.expression.getEnd(),
|
|
425
|
+
text: '<unknown>',
|
|
426
|
+
});
|
|
427
|
+
rewritten += 1;
|
|
428
|
+
unnamed.push(lineOf(node));
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
else if (methodName !== undefined || ts.isIdentifier(callee)) {
|
|
432
|
+
const isGets = methodName === 'gets' && first !== undefined && ts.isObjectLiteralExpression(first);
|
|
433
|
+
const hasShape = isGets || isKeyOptions(first);
|
|
434
|
+
const declaration = methodName === undefined ? undefined : declarationOf(node);
|
|
435
|
+
const isContainer = methodName === undefined
|
|
436
|
+
? hasShape && isFrameworkDecorator(callee)
|
|
437
|
+
: hasShape && isContainerMethod(declaration);
|
|
438
|
+
if (hasShape && methodName !== undefined && !isContainer && declaration === undefined) {
|
|
439
|
+
manual.push({
|
|
440
|
+
line: lineOf(node),
|
|
441
|
+
reason: `${methodName}(...) with a key: the receiver's type is not resolved (no tsconfig reaches this file, or it is any), so it is not known to be the container: change it by hand if it is`,
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
if (isContainer && isGets && ts.isObjectLiteralExpression(first)) {
|
|
445
|
+
const list = propertyOf(first, 'bindings')?.initializer;
|
|
446
|
+
if (list !== undefined && ts.isArrayLiteralExpression(list)) {
|
|
447
|
+
for (const element of list.elements) {
|
|
448
|
+
if (isKeyOptions(element)) {
|
|
449
|
+
rewriteKey(element, undefined);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
else if (isContainer && isKeyOptions(first)) {
|
|
455
|
+
// `@inject({ key }) service: Mailer`: the type the parameter or property already claims is the key's type.
|
|
456
|
+
const decorated = methodName === undefined &&
|
|
457
|
+
ts.isDecorator(node.parent) &&
|
|
458
|
+
(ts.isParameter(node.parent.parent) || ts.isPropertyDeclaration(node.parent.parent))
|
|
459
|
+
? node.parent.parent.type
|
|
460
|
+
: undefined;
|
|
461
|
+
const callArgument = methodName !== undefined && node.typeArguments?.length === 1
|
|
462
|
+
? node.typeArguments[0]
|
|
463
|
+
: undefined;
|
|
464
|
+
const claimed = callArgument ?? decorated;
|
|
465
|
+
// A type that names a type parameter of the enclosing code cannot go into `build<T>`: the check on the type
|
|
466
|
+
// argument is made while it is still unresolved.
|
|
467
|
+
if (claimed !== undefined && mentionsScopedTypeParameter(claimed, node)) {
|
|
468
|
+
manual.push({
|
|
469
|
+
line: lineOf(node),
|
|
470
|
+
reason: 'a key whose type names a type parameter of the enclosing code: a generic key factory builds BindingKeys.build<unknown> and returns it typed as TBindingKey<T>',
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
else {
|
|
474
|
+
const isKeyBuilt = (() => {
|
|
475
|
+
const value = propertyOf(first, 'key')?.initializer;
|
|
476
|
+
return (value !== undefined && isBuilderCall(value) && value.typeArguments !== undefined);
|
|
477
|
+
})();
|
|
478
|
+
if (!isKeyBuilt) {
|
|
479
|
+
const typeText = callArgument !== undefined
|
|
480
|
+
? callArgument.getText(file)
|
|
481
|
+
: decorated === undefined
|
|
482
|
+
? undefined
|
|
483
|
+
: liftedTypeText(decorated);
|
|
484
|
+
const done = rewriteKey(first, typeText);
|
|
485
|
+
// The type argument moved into `build<T>`; the call no longer needs it. Comments inside it stay.
|
|
486
|
+
if (done && callArgument !== undefined) {
|
|
487
|
+
const open = node.expression.getEnd();
|
|
488
|
+
const close = source.indexOf('(', callArgument.getEnd());
|
|
489
|
+
const comments = source
|
|
490
|
+
.slice(open, close)
|
|
491
|
+
.match(/\/\*[\s\S]*?\*\/|\/\/[^\n]*\n?/g);
|
|
492
|
+
edits.push({ start: open, end: close, text: comments ? comments.join(' ') : '' });
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
ts.forEachChild(node, visit);
|
|
500
|
+
};
|
|
501
|
+
const collect = (node) => {
|
|
502
|
+
if (ts.isVariableDeclaration(node) &&
|
|
503
|
+
ts.isIdentifier(node.name) &&
|
|
504
|
+
node.initializer !== undefined &&
|
|
505
|
+
(ts.isStringLiteral(node.initializer) ||
|
|
506
|
+
ts.isNoSubstitutionTemplateLiteral(node.initializer)) &&
|
|
507
|
+
(ts.getCombinedNodeFlags(node) & ts.NodeFlags.Const) !== 0) {
|
|
508
|
+
if (constants.has(node.name.text)) {
|
|
509
|
+
duplicates.add(node.name.text);
|
|
510
|
+
}
|
|
511
|
+
constants.set(node.name.text, node);
|
|
512
|
+
}
|
|
513
|
+
ts.forEachChild(node, collect);
|
|
514
|
+
};
|
|
515
|
+
collect(file);
|
|
516
|
+
visit(file);
|
|
517
|
+
if (edits.length === 0) {
|
|
518
|
+
return { output: source, changed: false, rewritten, unnamed, manual };
|
|
519
|
+
}
|
|
520
|
+
const { module, declared, named } = BindingKeysCodemod.readIdentifierSource({
|
|
521
|
+
typescript: ts,
|
|
522
|
+
file,
|
|
523
|
+
fallback: importFrom,
|
|
524
|
+
});
|
|
525
|
+
if (!declared && module === undefined) {
|
|
526
|
+
return {
|
|
527
|
+
output: source,
|
|
528
|
+
changed: false,
|
|
529
|
+
rewritten: 0,
|
|
530
|
+
unnamed: [],
|
|
531
|
+
manual: [
|
|
532
|
+
...manual,
|
|
533
|
+
{
|
|
534
|
+
line: 1,
|
|
535
|
+
reason: `${rewritten} key(s) could be rewritten but the file imports nothing from @venizia/ignis to take BindingKeys from: pass --import-from <module>`,
|
|
536
|
+
},
|
|
537
|
+
],
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
if (!declared) {
|
|
541
|
+
if (named !== undefined && named.elements.length > 0) {
|
|
542
|
+
const last = named.elements[named.elements.length - 1];
|
|
543
|
+
edits.push({ start: last.getEnd(), end: last.getEnd(), text: `, ${BUILDER}` });
|
|
544
|
+
}
|
|
545
|
+
else {
|
|
546
|
+
const lastImport = [...file.statements]
|
|
547
|
+
.reverse()
|
|
548
|
+
.find((statement) => ts.isImportDeclaration(statement));
|
|
549
|
+
const position = lastImport === undefined ? 0 : lastImport.getEnd();
|
|
550
|
+
const text = `${lastImport === undefined ? '' : '\n'}import { ${builder} } from '${module}';${lastImport === undefined ? '\n' : ''}`;
|
|
551
|
+
edits.push({ start: position, end: position, text });
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
let output = source;
|
|
555
|
+
for (const edit of [...edits].sort((left, right) => right.start - left.start || right.end - left.end)) {
|
|
556
|
+
output = `${output.slice(0, edit.start)}${edit.text}${output.slice(edit.end)}`;
|
|
557
|
+
}
|
|
558
|
+
return { output, changed: output !== source, rewritten, unnamed, manual };
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
exports.BindingKeysCodemod = BindingKeysCodemod;
|
|
562
|
+
/** `devz codemod binding-keys [paths...] [--write | --check]`: rewrites raw binding keys to `BindingKeys.build<T>`. */
|
|
563
|
+
class BindingKeysCommand {
|
|
564
|
+
static { this.USAGE = USAGE; }
|
|
565
|
+
/**
|
|
566
|
+
* The program the checker answers from: the project's own tsconfig (the nearest one above `root`) with the files the
|
|
567
|
+
* codemod reads added, so a receiver resolves the way the project's typecheck resolves it.
|
|
568
|
+
*/
|
|
569
|
+
static createProgram(opts) {
|
|
570
|
+
const { typescript: ts, root, files } = opts;
|
|
571
|
+
const configPath = ts.findConfigFile(root, (path) => ts.sys.fileExists(path), 'tsconfig.json');
|
|
572
|
+
const read = configPath === undefined
|
|
573
|
+
? undefined
|
|
574
|
+
: ts.readConfigFile(configPath, (path) => ts.sys.readFile(path));
|
|
575
|
+
const parsed = configPath === undefined || read === undefined || read.error !== undefined
|
|
576
|
+
? undefined
|
|
577
|
+
: ts.parseJsonConfigFileContent(read.config, ts.sys, (0, node_path_1.resolve)(configPath, '..'));
|
|
578
|
+
const options = {
|
|
579
|
+
target: ts.ScriptTarget.ESNext,
|
|
580
|
+
module: ts.ModuleKind.ESNext,
|
|
581
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
582
|
+
experimentalDecorators: true,
|
|
583
|
+
...parsed?.options,
|
|
584
|
+
noEmit: true,
|
|
585
|
+
skipLibCheck: true,
|
|
586
|
+
incremental: false,
|
|
587
|
+
composite: false,
|
|
588
|
+
allowJs: false,
|
|
589
|
+
};
|
|
590
|
+
return ts.createProgram({ rootNames: files, options });
|
|
591
|
+
}
|
|
592
|
+
static async run(opts) {
|
|
593
|
+
const { root, args } = opts;
|
|
594
|
+
if (args.includes(BindingKeysFlags.HELP) || args.includes(BindingKeysFlags.HELP_SHORT)) {
|
|
595
|
+
console.log(USAGE);
|
|
596
|
+
return 0;
|
|
597
|
+
}
|
|
598
|
+
const flags = [];
|
|
599
|
+
const paths = [];
|
|
600
|
+
let importFrom;
|
|
601
|
+
let hasImportFlag = false;
|
|
602
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
603
|
+
const argument = args[index];
|
|
604
|
+
if (argument === BindingKeysFlags.IMPORT_FROM) {
|
|
605
|
+
hasImportFlag = true;
|
|
606
|
+
importFrom = args[index + 1];
|
|
607
|
+
index += 1;
|
|
608
|
+
}
|
|
609
|
+
else if (argument.startsWith('-')) {
|
|
610
|
+
flags.push(argument);
|
|
611
|
+
}
|
|
612
|
+
else {
|
|
613
|
+
paths.push(argument);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
const unknown = flags.filter((flag) => !BindingKeysFlags.isValid(flag));
|
|
617
|
+
if (hasImportFlag && (importFrom === undefined || importFrom.startsWith('-'))) {
|
|
618
|
+
console.error(`devz codemod: ${BindingKeysFlags.IMPORT_FROM} needs a module\n${USAGE}`);
|
|
619
|
+
return USAGE_ERROR_CODE;
|
|
620
|
+
}
|
|
621
|
+
if (unknown.length > 0) {
|
|
622
|
+
console.error(`devz codemod: unknown option ${unknown.map((flag) => `"${flag}"`).join(', ')}\n${USAGE}`);
|
|
623
|
+
return USAGE_ERROR_CODE;
|
|
624
|
+
}
|
|
625
|
+
const isWrite = flags.includes(BindingKeysFlags.WRITE);
|
|
626
|
+
const isCheck = flags.includes(BindingKeysFlags.CHECK);
|
|
627
|
+
if (isWrite && isCheck) {
|
|
628
|
+
console.error(`devz codemod: ${BindingKeysFlags.WRITE} and ${BindingKeysFlags.CHECK} contradict each other\n${USAGE}`);
|
|
629
|
+
return USAGE_ERROR_CODE;
|
|
630
|
+
}
|
|
631
|
+
const refusal = files_1.CodemodFiles.refusal({
|
|
632
|
+
command: 'binding-keys',
|
|
633
|
+
isWrite,
|
|
634
|
+
isAll: flags.includes(BindingKeysFlags.ALL),
|
|
635
|
+
paths,
|
|
636
|
+
});
|
|
637
|
+
if (refusal) {
|
|
638
|
+
console.error(`${refusal}\n${USAGE}`);
|
|
639
|
+
return USAGE_ERROR_CODE;
|
|
640
|
+
}
|
|
641
|
+
let typescript;
|
|
642
|
+
try {
|
|
643
|
+
const loaded = await import('typescript');
|
|
644
|
+
typescript = loaded.default;
|
|
645
|
+
}
|
|
646
|
+
catch {
|
|
647
|
+
console.error('devz codemod: the "typescript" package is required to read your sources');
|
|
648
|
+
return 1;
|
|
649
|
+
}
|
|
650
|
+
const targets = (paths.length > 0 ? paths : ['.']).map((path) => (0, node_path_1.resolve)(root, path));
|
|
651
|
+
let changedCount = 0;
|
|
652
|
+
let rewrittenCount = 0;
|
|
653
|
+
let manualCount = 0;
|
|
654
|
+
let unnamedCount = 0;
|
|
655
|
+
let refusedCount = 0;
|
|
656
|
+
const collected = targets.map((target) => files_1.CodemodFiles.collect({ target }));
|
|
657
|
+
const program = BindingKeysCommand.createProgram({
|
|
658
|
+
typescript,
|
|
659
|
+
root,
|
|
660
|
+
files: collected.flat(),
|
|
661
|
+
});
|
|
662
|
+
const checker = program.getTypeChecker();
|
|
663
|
+
for (const [index, target] of targets.entries()) {
|
|
664
|
+
const files = collected[index];
|
|
665
|
+
const dirty = isWrite ? files_1.CodemodFiles.dirty({ target }) : undefined;
|
|
666
|
+
if (files.length === 0 && paths.length > 0) {
|
|
667
|
+
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`);
|
|
668
|
+
}
|
|
669
|
+
for (const file of files) {
|
|
670
|
+
const source = (0, node_fs_1.readFileSync)(file, 'utf8');
|
|
671
|
+
if (!/\b(?:get|gets|getBinding|bind|isBound|unbind|inject|provide|build)\b/.test(source)) {
|
|
672
|
+
continue;
|
|
673
|
+
}
|
|
674
|
+
const sourceFile = program.getSourceFile(file);
|
|
675
|
+
const result = BindingKeysCodemod.rewrite({
|
|
676
|
+
typescript,
|
|
677
|
+
fileName: file,
|
|
678
|
+
source,
|
|
679
|
+
importFrom,
|
|
680
|
+
program: sourceFile === undefined ? undefined : { sourceFile, checker },
|
|
681
|
+
});
|
|
682
|
+
const shown = (0, node_path_1.relative)(root, file).split('\\').join('/') || file;
|
|
683
|
+
for (const item of result.manual) {
|
|
684
|
+
manualCount += 1;
|
|
685
|
+
console.warn(`manual ${shown}:${item.line} ${item.reason}`);
|
|
686
|
+
}
|
|
687
|
+
for (const line of result.unnamed) {
|
|
688
|
+
unnamedCount += 1;
|
|
689
|
+
console.warn(`type ${shown}:${line} BindingKeys.build<unknown>: name the type of the value bound under this key`);
|
|
690
|
+
}
|
|
691
|
+
if (!result.changed) {
|
|
692
|
+
continue;
|
|
693
|
+
}
|
|
694
|
+
if (dirty?.has(file)) {
|
|
695
|
+
refusedCount += 1;
|
|
696
|
+
console.warn(`refused ${shown} has local changes (commit or stash them, then run again)`);
|
|
697
|
+
continue;
|
|
698
|
+
}
|
|
699
|
+
changedCount += 1;
|
|
700
|
+
rewrittenCount += result.rewritten;
|
|
701
|
+
console.log(`${isWrite ? 'changed' : 'would change'} ${shown} (${result.rewritten} key(s))`);
|
|
702
|
+
if (isWrite) {
|
|
703
|
+
(0, node_fs_1.writeFileSync)(file, result.output);
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
console.log(`devz codemod binding-keys: ${changedCount} file(s) ${isWrite ? 'changed' : 'would change'}, ${rewrittenCount} key(s) ${isWrite ? 'rewritten' : 'would be rewritten'}, ${unnamedCount} to type, ${manualCount} manual` +
|
|
708
|
+
(refusedCount > 0 ? `, ${refusedCount} refused` : ''));
|
|
709
|
+
if (!isWrite && changedCount > 0) {
|
|
710
|
+
console.log(`Nothing was written. Run again with ${BindingKeysFlags.WRITE} to apply, then name each "type" site and run your typecheck.`);
|
|
711
|
+
}
|
|
712
|
+
if (isWrite && refusedCount > 0) {
|
|
713
|
+
return 1;
|
|
714
|
+
}
|
|
715
|
+
return isCheck && (changedCount > 0 || manualCount > 0) ? 1 : 0;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
exports.BindingKeysCommand = BindingKeysCommand;
|
|
719
|
+
//# sourceMappingURL=binding-keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binding-keys.js","sourceRoot":"","sources":["../../../src/cli/codemod/binding-keys.ts"],"names":[],"mappings":";;;AAAA,qCAAsD;AACtD,yCAA6D;AAC7D,mCAAuC;AAEvC,MAAM,KAAK,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gEA0CkD,CAAC;AAEjE,kDAAkD;AAClD,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAE3B,gEAAgE;AAChE,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC;AAExF,4EAA4E;AAC5E,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC,CAAC;AAE7D,qDAAqD;AACrD,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC;AAEtD,2DAA2D;AAC3D,MAAM,YAAY,GAAG,0CAA0C,CAAC;AAEhE,MAAM,OAAO,GAAG,aAAa,CAAC;AAE9B,wEAAwE;AACxE,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC;IAC9B,YAAY;IACZ,mBAAmB;IACnB,eAAe;IACf,WAAW;IACX,SAAS;CACV,CAAC,CAAC;AAEH,6HAA6H;AAC7H,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC;IACjC,gBAAgB;IAChB,0BAA0B;IAC1B,uBAAuB;CACxB,CAAC,CAAC;AAEH,gGAAgG;AAChG,MAAM,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,YAAY,GAAG,CAAC,IAAI,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAClE,CAAC;;AAnNH,gDAoNC","sourcesContent":["import { readFileSync, writeFileSync } from 'node:fs';\nimport { dirname, join, relative, resolve } from 'node:path';\nimport { CodemodFiles } from './files';\n\nconst USAGE = `Usage: devz codemod binding-keys [paths...] [--write [--all] | --check] [--import-from <module>]\n\nRewrites the raw binding keys of the @venizia/ignis-inversion release where a key is made by BindingKeys.build<T>:\n\n container.get<Mailer>({ key: 'services.Mailer' }) becomes container.get({ key: BindingKeys.build<Mailer>({ key: 'services.Mailer' }) })\n container.bind({ key: 'services.Mailer' }) becomes container.bind({ key: BindingKeys.build<unknown>({ key: 'services.Mailer' }) })\n @inject({ key: 'services.Mailer' }) becomes @inject({ key: BindingKeys.build<unknown>({ key: 'services.Mailer' }) })\n container.get({ key: { namespace, key } }) becomes container.get({ key: BindingKeys.build<unknown>({ namespace, key }) })\n container.get({ key: \\`\\${namespace}.Name\\` }) becomes container.get({ key: BindingKeys.build<unknown>({ namespace, key: 'Name' }) })\n BindingKeys.build({ key }) becomes BindingKeys.build<unknown>({ key })\n\nThe key string is never changed.\n\nA call is rewritten only when the TypeScript checker resolves it to the framework's container (Container, IContainer,\nBinding) or to its inject and provide, under any local name. A redis.get<T>({ key }), a worker pool or a class of your own\nis left alone, type argument included. The checker reads your project through the nearest tsconfig.json, so run the codemod\nfrom the project root with the dependencies installed; a receiver it cannot resolve is listed as \"manual\". The call's own type argument moves into build<T>, so the caller keeps the type it\nclaimed; without one the codemod writes build<unknown> and lists the site (\"type\"): name the real type there.\n\nIt rewrites a call named get, gets, getBinding, bind, isBound or unbind whose argument is an object literal with a\n\\`key\\` (and, for get, \\`isOptional\\`), and a call of inject or provide. A container cannot be told from syntax, so the shape is the\ntest. A string key, a substitution-free template literal, a { namespace, key } literal and a template written\n\\${namespace}.Name or \\${namespace}.\\${name} are rewritten. These are listed\nas \"manual\" and left alone: a key made at run time (a template with substitutions, a call) and a Symbol key (symbols are no\nlonger keys). A key that is a const of the file (const MAILER = 'services.Mailer') is rewritten where it is declared. Any\nother name or property (Keys.MAILER) is left alone without a line: it may already be a built key, and your typecheck\nnames a raw one.\n\nBindingKeys is imported from the module the file already takes inject from, else from the first @venizia/ignis import,\nor from --import-from <module>; a file with none of them is listed as manual and not rewritten. An existing import of\nBindingKeys is reused. A second run changes nothing.\n\nIt reads TypeScript files (.ts, .tsx, .mts, .cts). A .js, .cjs or .mjs file is not read: edit it by hand.\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 or a manual site remains (for CI)\n --import-from the module BindingKeys is imported from when the file gives no better one\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 knows, and\n--write refuses a file with local changes: commit or stash it first, so git can undo it.\nThere is no --reverse: a downgrade restores the files from git.`;\n\n/** A usage error: nothing was read or written. */\nconst USAGE_ERROR_CODE = 2;\n\n/** The methods whose options object carries a container key. */\nconst KEY_METHODS = new Set(['get', 'gets', 'getBinding', 'bind', 'isBound', 'unbind']);\n\n/** The other properties a key options object may carry and still be one. */\nconst OPTION_NAMES = new Set(['key', 'isOptional', 'scope']);\n\n/** The decorators that take a key options object. */\nconst KEY_DECORATORS = new Set(['inject', 'provide']);\n\n/** Where a file already imports the container API from. */\nconst IGNIS_MODULE = /^@venizia\\/ignis(?:-kernel|-inversion)?$/;\n\nconst BUILDER = 'BindingKeys';\n\n/** The classes and interfaces whose key methods are the container's. */\nconst CONTAINER_TYPES = new Set([\n 'IContainer',\n 'AbstractContainer',\n 'BaseContainer',\n 'Container',\n 'Binding',\n]);\n\n/** The packages that declare the container: the framework is identified by name, wherever it is installed or checked out. */\nconst FRAMEWORK_PACKAGES = new Set([\n '@venizia/ignis',\n '@venizia/ignis-inversion',\n '@venizia/ignis-kernel',\n]);\n\n/** A module of the framework: a file's own barrel is not a place to take `BindingKeys` from. */\nconst VENIZIA_MODULE = /^@venizia\\//;\n\nclass BindingKeysFlags {\n static readonly WRITE = '--write';\n static readonly ALL = '--all';\n static readonly CHECK = '--check';\n static readonly IMPORT_FROM = '--import-from';\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.IMPORT_FROM,\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\n/** One site the codemod would change or cannot change. */\nexport interface IBindingKeysResult {\n output: string;\n changed: boolean;\n rewritten: number;\n /** Lines where `build<unknown>` was written because the call named no type. */\n unnamed: number[];\n manual: Array<{ line: number; reason: string }>;\n}\n\n/** Rewrites raw binding keys to `BindingKeys.build<T>({ key })`. */\nexport class BindingKeysCodemod {\n /** The module `BindingKeys` comes from in this file: an existing import, the module of `inject`, a @venizia/ignis import, or `fallback`. */\n private static readIdentifierSource(opts: {\n typescript: typeof import('typescript');\n file: import('typescript').SourceFile;\n fallback?: string;\n }): { module: string | undefined; declared: boolean; named?: import('typescript').NamedImports } {\n const { typescript: ts, file, fallback } = opts;\n let injectModule: string | undefined;\n let ignisModule: string | undefined;\n let named: import('typescript').NamedImports | undefined;\n let declared = false;\n\n for (const statement of file.statements) {\n if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)) {\n continue;\n }\n\n const module = statement.moduleSpecifier.text;\n const bindings = statement.importClause?.namedBindings;\n const isTypeOnly = statement.importClause?.isTypeOnly === true;\n\n if (bindings === undefined || !ts.isNamedImports(bindings)) {\n continue;\n }\n\n for (const element of bindings.elements) {\n const imported = (element.propertyName ?? element.name).text;\n\n if (imported === BUILDER && !isTypeOnly && !element.isTypeOnly) {\n declared = true;\n }\n\n if (imported === 'inject' && injectModule === undefined && VENIZIA_MODULE.test(module)) {\n injectModule = module;\n }\n }\n\n if (IGNIS_MODULE.test(module) && !isTypeOnly) {\n ignisModule ??= module;\n named ??= bindings;\n }\n }\n\n return { module: injectModule ?? ignisModule ?? fallback, declared, named };\n }\n\n /** The local name `BindingKeys` is imported under (an alias included), or `BindingKeys` when the file does not import it. */\n private static readBuilderName(opts: {\n typescript: typeof import('typescript');\n file: import('typescript').SourceFile;\n }): string {\n const { typescript: ts, file } = opts;\n\n for (const statement of file.statements) {\n const bindings = ts.isImportDeclaration(statement)\n ? statement.importClause?.namedBindings\n : undefined;\n\n if (bindings === undefined || !ts.isNamedImports(bindings)) {\n continue;\n }\n\n for (const element of bindings.elements) {\n if ((element.propertyName ?? element.name).text === BUILDER) {\n return element.name.text;\n }\n }\n }\n\n return BUILDER;\n }\n\n static rewrite(opts: {\n typescript: typeof import('typescript');\n fileName: string;\n source: string;\n /** The module `BindingKeys` is imported from when the file gives no better one. */\n importFrom?: string;\n /** The program's source file for `fileName` and its checker: a call is rewritten only when the checker resolves it to the container. */\n program?: {\n sourceFile: import('typescript').SourceFile;\n checker: import('typescript').TypeChecker;\n };\n /** Reads a file for the package.json lookup; defaults to the file system. */\n readFile?: (path: string) => string | undefined;\n }): IBindingKeysResult {\n const {\n typescript: ts,\n fileName,\n importFrom,\n program,\n readFile = (path: string) => ts.sys.readFile(path),\n } = opts;\n const language = fileName.endsWith('.tsx') ? ts.ScriptKind.TSX : ts.ScriptKind.TS;\n const file =\n program?.sourceFile ??\n ts.createSourceFile(fileName, opts.source, ts.ScriptTarget.Latest, true, language);\n const source = file.text;\n const checker = program?.checker;\n const builder = BindingKeysCodemod.readBuilderName({ typescript: ts, file });\n const edits: Array<{ start: number; end: number; text: string }> = [];\n const manual: Array<{ line: number; reason: string }> = [];\n const unnamed: number[] = [];\n const handled = new Set<import('typescript').Node>();\n /** `const NAME = 'literal'` declared once in the file: a key held in a constant is rewritten where it is declared. */\n const constants = new Map<string, import('typescript').VariableDeclaration>();\n const duplicates = new Set<string>();\n let rewritten = 0;\n const lineOf = (node: import('typescript').Node): number =>\n file.getLineAndCharacterOfPosition(node.getStart(file)).line + 1;\n\n const propertyOf = (\n node: import('typescript').ObjectLiteralExpression,\n name: string,\n ): import('typescript').PropertyAssignment | undefined => {\n for (const property of node.properties) {\n if (\n ts.isPropertyAssignment(property) &&\n (ts.isIdentifier(property.name) || ts.isStringLiteral(property.name)) &&\n property.name.text === name\n ) {\n return property;\n }\n }\n\n return undefined;\n };\n\n /** An object literal whose properties are all in `names` and that has a `key`: the shape of a key options object. */\n const isKeyOptions = (\n node: import('typescript').Expression | undefined,\n ): node is import('typescript').ObjectLiteralExpression => {\n if (node === undefined || !ts.isObjectLiteralExpression(node)) {\n return false;\n }\n\n return (\n propertyOf(node, 'key') !== undefined &&\n node.properties.every(\n (property) =>\n ts.isPropertyAssignment(property) &&\n (ts.isIdentifier(property.name) || ts.isStringLiteral(property.name)) &&\n OPTION_NAMES.has(property.name.text),\n )\n );\n };\n\n const isBuilderCall = (\n node: import('typescript').Node,\n ): node is import('typescript').CallExpression =>\n ts.isCallExpression(node) &&\n ts.isPropertyAccessExpression(node.expression) &&\n ts.isIdentifier(node.expression.expression) &&\n node.expression.expression.text === builder &&\n node.expression.name.text === 'build';\n\n const isSymbolExpression = (node: import('typescript').Expression): boolean =>\n (ts.isCallExpression(node) &&\n ((ts.isIdentifier(node.expression) && node.expression.text === 'Symbol') ||\n (ts.isPropertyAccessExpression(node.expression) &&\n ts.isIdentifier(node.expression.expression) &&\n node.expression.expression.text === 'Symbol'))) ||\n (ts.isPropertyAccessExpression(node) &&\n ts.isIdentifier(node.expression) &&\n node.expression.text === 'Symbol');\n\n /**\n * The `{ namespace, key }` text of a template written as `${namespace}.Name` or `${namespace}.${name}` (the two\n * shapes the framework's own keys take), or `undefined` for any other template.\n */\n const namespaceKeyOf = (node: import('typescript').TemplateExpression): string | undefined => {\n const { head, templateSpans } = node;\n\n if (head.text !== '') {\n return undefined;\n }\n\n if (templateSpans.length === 1 && templateSpans[0].literal.text.startsWith('.')) {\n const tail = templateSpans[0].literal.text.slice(1);\n\n return tail === ''\n ? undefined\n : `{ namespace: ${templateSpans[0].expression.getText(file)}, key: '${tail.replace(/'/g, \"\\\\'\")}' }`;\n }\n\n if (\n templateSpans.length === 2 &&\n templateSpans[0].literal.text === '.' &&\n templateSpans[1].literal.text === ''\n ) {\n return `{ namespace: ${templateSpans[0].expression.getText(file)}, key: ${templateSpans[1].expression.getText(file)} }`;\n }\n\n return undefined;\n };\n\n /**\n * Wraps the key of one options object. `typeText` is the value type the call already claimed, or `undefined` for\n * `unknown`. Answers whether the key was rewritten.\n */\n const rewriteKey = (\n options: import('typescript').ObjectLiteralExpression,\n typeText: string | undefined,\n ): boolean => {\n const property = propertyOf(options, 'key');\n\n if (property === undefined) {\n return false;\n }\n\n const value = property.initializer;\n const text = typeText ?? 'unknown';\n\n if (ts.isStringLiteral(value) || ts.isNoSubstitutionTemplateLiteral(value)) {\n edits.push({\n start: value.getStart(file),\n end: value.getEnd(),\n text: `${builder}.build<${text}>({ key: ${value.getText(file)} })`,\n });\n } else if (\n ts.isObjectLiteralExpression(value) &&\n propertyOf(value, 'key') !== undefined &&\n value.properties.every(\n (item) =>\n ts.isPropertyAssignment(item) &&\n ts.isIdentifier(item.name) &&\n (item.name.text === 'key' || item.name.text === 'namespace'),\n )\n ) {\n edits.push({\n start: value.getStart(file),\n end: value.getEnd(),\n text: `${builder}.build<${text}>(${value.getText(file)})`,\n });\n } else if (ts.isTemplateExpression(value) && namespaceKeyOf(value) !== undefined) {\n edits.push({\n start: value.getStart(file),\n end: value.getEnd(),\n text: `${builder}.build<${text}>(${namespaceKeyOf(value)})`,\n });\n } else if (\n ts.isIdentifier(value) &&\n constants.has(value.text) &&\n !duplicates.has(value.text)\n ) {\n const declaration = constants.get(value.text);\n\n if (declaration?.initializer === undefined || handled.has(declaration)) {\n return false;\n }\n\n handled.add(declaration);\n edits.push({\n start: declaration.initializer.getStart(file),\n end: declaration.initializer.getEnd(),\n text: `${builder}.build<${text}>({ key: ${declaration.initializer.getText(file)} })`,\n });\n\n if (typeText === undefined) {\n unnamed.push(lineOf(declaration));\n }\n\n rewritten += 1;\n\n return true;\n } else if (isBuilderCall(value)) {\n if (value.typeArguments !== undefined) {\n return false;\n }\n\n handled.add(value);\n // `BindingKeys.build(` then the argument: the type argument goes between the name and the parenthesis.\n edits.push({\n start: value.expression.getEnd(),\n end: value.expression.getEnd(),\n text: `<${text}>`,\n });\n } else if (isSymbolExpression(value)) {\n manual.push({\n line: lineOf(value),\n reason:\n 'a Symbol key: symbols are no longer binding keys, use BindingKeys.build<T>({ key: \"...\" })',\n });\n\n return false;\n } else {\n // A name or a property (`MAILER`, `Keys.MAILER`) may already be a built key, and the typecheck names a raw\n // one: only an expression that makes a string at run time is listed.\n const isReference =\n ts.isIdentifier(value) ||\n ts.isPropertyAccessExpression(value) ||\n ts.isElementAccessExpression(value);\n\n if (isReference && checker !== undefined) {\n const type = checker.getTypeAtLocation(value);\n\n if (type.flags & ts.TypeFlags.StringLike && type.getProperty('valueType') === undefined) {\n manual.push({\n line: lineOf(value),\n reason:\n 'a string held in a name: build it with BindingKeys.build<T>({ key }) where it is defined (a key of a package you do not own is built by that package)',\n });\n }\n }\n\n if (!isReference) {\n manual.push({\n line: lineOf(value),\n reason:\n 'a key made at run time (a template with substitutions, a call): build it with BindingKeys.build<T>({ key }) where it is made',\n });\n }\n\n return false;\n }\n\n rewritten += 1;\n\n if (typeText === undefined) {\n unnamed.push(lineOf(value));\n }\n\n return true;\n };\n\n /** The declaration the checker resolves a call to, or `undefined` when it cannot (an unresolved receiver). */\n const declarationOf = (\n node: import('typescript').CallExpression,\n ): import('typescript').Declaration | undefined =>\n checker?.getResolvedSignature(node)?.declaration;\n\n const packageNames = new Map<string, string | undefined>();\n\n /**\n * The name in the nearest package.json above `directory` that has one, or `undefined` when there is none. A package.json\n * without a name does not end the walk: an installed package ships `dist/esm/package.json` (`{ \"type\": \"module\" }`) beside\n * the declarations, and the package's own file is further up.\n */\n const packageNameAbove = (directory: string): string | undefined => {\n if (packageNames.has(directory)) {\n return packageNames.get(directory);\n }\n\n const text = readFile(join(directory, 'package.json'));\n const parent = dirname(directory);\n let name: string | undefined;\n\n if (text !== undefined) {\n const parsed: unknown = JSON.parse(text);\n\n if (\n typeof parsed === 'object' &&\n parsed !== null &&\n 'name' in parsed &&\n typeof parsed.name === 'string'\n ) {\n name = parsed.name;\n }\n }\n\n if (name === undefined && parent !== directory) {\n name = packageNameAbove(parent);\n }\n\n packageNames.set(directory, name);\n\n return name;\n };\n\n /** A declaration of the framework: the nearest package.json above its file names one of the framework's packages. */\n const isFrameworkFile = (declaration: import('typescript').Node): boolean => {\n const name = packageNameAbove(dirname(declaration.getSourceFile().fileName));\n\n return name !== undefined && FRAMEWORK_PACKAGES.has(name);\n };\n\n /** `container.get(...)`: the checker resolves the method to the container's (or `Binding`'s), declared by the framework. */\n const isContainerMethod = (\n declaration: import('typescript').Declaration | undefined,\n ): boolean => {\n if (declaration === undefined || !isFrameworkFile(declaration)) {\n return false;\n }\n\n const owner = declaration.parent;\n\n return (\n (ts.isClassLike(owner) || ts.isInterfaceDeclaration(owner)) &&\n owner.name !== undefined &&\n CONTAINER_TYPES.has(owner.name.text)\n );\n };\n\n /** `inject(...)` or `provide(...)` under any local name: the checker follows the import to the framework's. */\n const isFrameworkDecorator = (callee: import('typescript').Expression): boolean => {\n if (checker === undefined || !ts.isIdentifier(callee)) {\n return false;\n }\n\n const symbol = checker.getSymbolAtLocation(callee);\n const target =\n symbol !== undefined && symbol.flags & ts.SymbolFlags.Alias\n ? checker.getAliasedSymbol(symbol)\n : symbol;\n const declaration = target?.declarations?.[0];\n\n return (\n declaration !== undefined &&\n KEY_DECORATORS.has(target?.name ?? '') &&\n isFrameworkFile(declaration)\n );\n };\n\n /** Whether a type mentions a type parameter of a function or class that encloses `from`. */\n const mentionsScopedTypeParameter = (\n type: import('typescript').TypeNode,\n from: import('typescript').Node,\n ): boolean => {\n const scoped = new Set<string>();\n\n for (\n let scope: import('typescript').Node | undefined = from;\n scope !== undefined;\n scope = scope.parent\n ) {\n const parameters =\n ts.isFunctionLike(scope) || ts.isClassLike(scope) ? scope.typeParameters : undefined;\n\n for (const parameter of parameters ?? []) {\n scoped.add(parameter.name.text);\n }\n }\n\n const search = (node: import('typescript').Node): boolean =>\n (ts.isTypeReferenceNode(node) &&\n ts.isIdentifier(node.typeName) &&\n scoped.has(node.typeName.text)) ||\n ts.forEachChild(node, (child) => (search(child) ? true : undefined)) === true;\n\n return search(type);\n };\n\n /** The text of a decorated parameter's type with `undefined` left out: the key names what is injected, not its absence. */\n const liftedTypeText = (type: import('typescript').TypeNode): string => {\n if (!ts.isUnionTypeNode(type)) {\n return type.getText(file);\n }\n\n const kept = type.types.filter((member) => member.kind !== ts.SyntaxKind.UndefinedKeyword);\n\n return kept.map((member) => member.getText(file)).join(' | ');\n };\n\n const visit = (node: import('typescript').Node): void => {\n if (ts.isCallExpression(node)) {\n const callee = node.expression;\n const first = node.arguments[0];\n const methodName =\n ts.isPropertyAccessExpression(callee) && KEY_METHODS.has(callee.name.text)\n ? callee.name.text\n : undefined;\n\n if (\n isBuilderCall(node) &&\n node.typeArguments === undefined &&\n node.arguments.length === 1\n ) {\n if (handled.has(node)) {\n ts.forEachChild(node, visit);\n\n return;\n }\n\n const argument = node.arguments[0];\n\n if (ts.isObjectLiteralExpression(argument) && propertyOf(argument, 'key') !== undefined) {\n edits.push({\n start: node.expression.getEnd(),\n end: node.expression.getEnd(),\n text: '<unknown>',\n });\n rewritten += 1;\n unnamed.push(lineOf(node));\n }\n } else if (methodName !== undefined || ts.isIdentifier(callee)) {\n const isGets =\n methodName === 'gets' && first !== undefined && ts.isObjectLiteralExpression(first);\n const hasShape = isGets || isKeyOptions(first);\n const declaration = methodName === undefined ? undefined : declarationOf(node);\n const isContainer =\n methodName === undefined\n ? hasShape && isFrameworkDecorator(callee)\n : hasShape && isContainerMethod(declaration);\n\n if (hasShape && methodName !== undefined && !isContainer && declaration === undefined) {\n manual.push({\n line: lineOf(node),\n reason: `${methodName}(...) with a key: the receiver's type is not resolved (no tsconfig reaches this file, or it is any), so it is not known to be the container: change it by hand if it is`,\n });\n }\n\n if (isContainer && isGets && ts.isObjectLiteralExpression(first)) {\n const list = propertyOf(first, 'bindings')?.initializer;\n\n if (list !== undefined && ts.isArrayLiteralExpression(list)) {\n for (const element of list.elements) {\n if (isKeyOptions(element)) {\n rewriteKey(element, undefined);\n }\n }\n }\n } else if (isContainer && isKeyOptions(first)) {\n // `@inject({ key }) service: Mailer`: the type the parameter or property already claims is the key's type.\n const decorated =\n methodName === undefined &&\n ts.isDecorator(node.parent) &&\n (ts.isParameter(node.parent.parent) || ts.isPropertyDeclaration(node.parent.parent))\n ? node.parent.parent.type\n : undefined;\n const callArgument =\n methodName !== undefined && node.typeArguments?.length === 1\n ? node.typeArguments[0]\n : undefined;\n const claimed = callArgument ?? decorated;\n\n // A type that names a type parameter of the enclosing code cannot go into `build<T>`: the check on the type\n // argument is made while it is still unresolved.\n if (claimed !== undefined && mentionsScopedTypeParameter(claimed, node)) {\n manual.push({\n line: lineOf(node),\n reason:\n 'a key whose type names a type parameter of the enclosing code: a generic key factory builds BindingKeys.build<unknown> and returns it typed as TBindingKey<T>',\n });\n } else {\n const isKeyBuilt = (() => {\n const value = propertyOf(first, 'key')?.initializer;\n\n return (\n value !== undefined && isBuilderCall(value) && value.typeArguments !== undefined\n );\n })();\n\n if (!isKeyBuilt) {\n const typeText =\n callArgument !== undefined\n ? callArgument.getText(file)\n : decorated === undefined\n ? undefined\n : liftedTypeText(decorated);\n const done = rewriteKey(first, typeText);\n\n // The type argument moved into `build<T>`; the call no longer needs it. Comments inside it stay.\n if (done && callArgument !== undefined) {\n const open = node.expression.getEnd();\n const close = source.indexOf('(', callArgument.getEnd());\n const comments = source\n .slice(open, close)\n .match(/\\/\\*[\\s\\S]*?\\*\\/|\\/\\/[^\\n]*\\n?/g);\n\n edits.push({ start: open, end: close, text: comments ? comments.join(' ') : '' });\n }\n }\n }\n }\n }\n }\n\n ts.forEachChild(node, visit);\n };\n\n const collect = (node: import('typescript').Node): void => {\n if (\n ts.isVariableDeclaration(node) &&\n ts.isIdentifier(node.name) &&\n node.initializer !== undefined &&\n (ts.isStringLiteral(node.initializer) ||\n ts.isNoSubstitutionTemplateLiteral(node.initializer)) &&\n (ts.getCombinedNodeFlags(node) & ts.NodeFlags.Const) !== 0\n ) {\n if (constants.has(node.name.text)) {\n duplicates.add(node.name.text);\n }\n\n constants.set(node.name.text, node);\n }\n\n ts.forEachChild(node, collect);\n };\n\n collect(file);\n visit(file);\n\n if (edits.length === 0) {\n return { output: source, changed: false, rewritten, unnamed, manual };\n }\n\n const { module, declared, named } = BindingKeysCodemod.readIdentifierSource({\n typescript: ts,\n file,\n fallback: importFrom,\n });\n\n if (!declared && module === undefined) {\n return {\n output: source,\n changed: false,\n rewritten: 0,\n unnamed: [],\n manual: [\n ...manual,\n {\n line: 1,\n reason: `${rewritten} key(s) could be rewritten but the file imports nothing from @venizia/ignis to take BindingKeys from: pass --import-from <module>`,\n },\n ],\n };\n }\n\n if (!declared) {\n if (named !== undefined && named.elements.length > 0) {\n const last = named.elements[named.elements.length - 1];\n\n edits.push({ start: last.getEnd(), end: last.getEnd(), text: `, ${BUILDER}` });\n } else {\n const lastImport = [...file.statements]\n .reverse()\n .find((statement) => ts.isImportDeclaration(statement));\n const position = lastImport === undefined ? 0 : lastImport.getEnd();\n const text = `${lastImport === undefined ? '' : '\\n'}import { ${builder} } from '${module}';${lastImport === undefined ? '\\n' : ''}`;\n\n edits.push({ start: position, end: position, text });\n }\n }\n\n let output = source;\n\n for (const edit of [...edits].sort(\n (left, right) => right.start - left.start || right.end - left.end,\n )) {\n output = `${output.slice(0, edit.start)}${edit.text}${output.slice(edit.end)}`;\n }\n\n return { output, changed: output !== source, rewritten, unnamed, manual };\n }\n}\n\n/** `devz codemod binding-keys [paths...] [--write | --check]`: rewrites raw binding keys to `BindingKeys.build<T>`. */\nexport class BindingKeysCommand {\n static readonly USAGE = USAGE;\n\n /**\n * The program the checker answers from: the project's own tsconfig (the nearest one above `root`) with the files the\n * codemod reads added, so a receiver resolves the way the project's typecheck resolves it.\n */\n static createProgram(opts: {\n typescript: typeof import('typescript');\n root: string;\n files: string[];\n }): import('typescript').Program {\n const { typescript: ts, root, files } = opts;\n const configPath = ts.findConfigFile(root, (path) => ts.sys.fileExists(path), 'tsconfig.json');\n const read =\n configPath === undefined\n ? undefined\n : ts.readConfigFile(configPath, (path) => ts.sys.readFile(path));\n const parsed =\n configPath === undefined || read === undefined || read.error !== undefined\n ? undefined\n : ts.parseJsonConfigFileContent(read.config, ts.sys, resolve(configPath, '..'));\n const options: import('typescript').CompilerOptions = {\n target: ts.ScriptTarget.ESNext,\n module: ts.ModuleKind.ESNext,\n moduleResolution: ts.ModuleResolutionKind.Bundler,\n experimentalDecorators: true,\n ...parsed?.options,\n noEmit: true,\n skipLibCheck: true,\n incremental: false,\n composite: false,\n allowJs: false,\n };\n\n return ts.createProgram({ rootNames: files, options });\n }\n\n static async run(opts: { root: string; args: string[] }): Promise<number> {\n const { root, args } = opts;\n\n if (args.includes(BindingKeysFlags.HELP) || args.includes(BindingKeysFlags.HELP_SHORT)) {\n console.log(USAGE);\n\n return 0;\n }\n\n const flags: string[] = [];\n const paths: string[] = [];\n let importFrom: string | undefined;\n let hasImportFlag = false;\n\n for (let index = 0; index < args.length; index += 1) {\n const argument = args[index];\n\n if (argument === BindingKeysFlags.IMPORT_FROM) {\n hasImportFlag = true;\n importFrom = args[index + 1];\n index += 1;\n } else if (argument.startsWith('-')) {\n flags.push(argument);\n } else {\n paths.push(argument);\n }\n }\n\n const unknown = flags.filter((flag) => !BindingKeysFlags.isValid(flag));\n\n if (hasImportFlag && (importFrom === undefined || importFrom.startsWith('-'))) {\n console.error(`devz codemod: ${BindingKeysFlags.IMPORT_FROM} needs a module\\n${USAGE}`);\n\n return USAGE_ERROR_CODE;\n }\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(BindingKeysFlags.WRITE);\n const isCheck = flags.includes(BindingKeysFlags.CHECK);\n\n if (isWrite && isCheck) {\n console.error(\n `devz codemod: ${BindingKeysFlags.WRITE} and ${BindingKeysFlags.CHECK} contradict each other\\n${USAGE}`,\n );\n\n return USAGE_ERROR_CODE;\n }\n\n const refusal = CodemodFiles.refusal({\n command: 'binding-keys',\n isWrite,\n isAll: flags.includes(BindingKeysFlags.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 targets = (paths.length > 0 ? paths : ['.']).map((path) => resolve(root, path));\n let changedCount = 0;\n let rewrittenCount = 0;\n let manualCount = 0;\n let unnamedCount = 0;\n let refusedCount = 0;\n\n const collected = targets.map((target) => CodemodFiles.collect({ target }));\n const program = BindingKeysCommand.createProgram({\n typescript,\n root,\n files: collected.flat(),\n });\n const checker = program.getTypeChecker();\n\n for (const [index, target] of targets.entries()) {\n const files = collected[index];\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 (!/\\b(?:get|gets|getBinding|bind|isBound|unbind|inject|provide|build)\\b/.test(source)) {\n continue;\n }\n\n const sourceFile = program.getSourceFile(file);\n const result = BindingKeysCodemod.rewrite({\n typescript,\n fileName: file,\n source,\n importFrom,\n program: sourceFile === undefined ? undefined : { sourceFile, checker },\n });\n const shown = relative(root, file).split('\\\\').join('/') || file;\n\n for (const item of result.manual) {\n manualCount += 1;\n console.warn(`manual ${shown}:${item.line} ${item.reason}`);\n }\n\n for (const line of result.unnamed) {\n unnamedCount += 1;\n console.warn(\n `type ${shown}:${line} BindingKeys.build<unknown>: name the type of the value bound under this key`,\n );\n }\n\n if (!result.changed) {\n continue;\n }\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 rewrittenCount += result.rewritten;\n console.log(\n `${isWrite ? 'changed' : 'would change'} ${shown} (${result.rewritten} key(s))`,\n );\n\n if (isWrite) {\n writeFileSync(file, result.output);\n }\n }\n }\n\n console.log(\n `devz codemod binding-keys: ${changedCount} file(s) ${isWrite ? 'changed' : 'would change'}, ${rewrittenCount} key(s) ${isWrite ? 'rewritten' : 'would be rewritten'}, ${unnamedCount} to type, ${manualCount} manual` +\n (refusedCount > 0 ? `, ${refusedCount} refused` : ''),\n );\n\n if (!isWrite && changedCount > 0) {\n console.log(\n `Nothing was written. Run again with ${BindingKeysFlags.WRITE} to apply, then name each \"type\" site and run your typecheck.`,\n );\n }\n\n if (isWrite && refusedCount > 0) {\n return 1;\n }\n\n return isCheck && (changedCount > 0 || manualCount > 0) ? 1 : 0;\n }\n}\n"]}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.CodemodCommand = void 0;
|
|
4
4
|
const any_aliases_1 = require("./any-aliases");
|
|
5
5
|
const async_style_1 = require("./async-style");
|
|
6
|
+
const binding_keys_1 = require("./binding-keys");
|
|
6
7
|
const connector_imports_1 = require("./connector-imports");
|
|
7
8
|
const const_classes_1 = require("./const-classes");
|
|
8
9
|
const env_get_1 = require("./env-get");
|
|
@@ -16,6 +17,7 @@ const USAGE = [
|
|
|
16
17
|
connector_imports_1.ConnectorImportsCommand.USAGE,
|
|
17
18
|
env_get_1.EnvGetCommand.USAGE,
|
|
18
19
|
any_aliases_1.AnyAliasesCommand.USAGE,
|
|
20
|
+
binding_keys_1.BindingKeysCommand.USAGE,
|
|
19
21
|
].join('\n\n');
|
|
20
22
|
/** The codemods `devz codemod <name>` runs. */
|
|
21
23
|
const NAME_LIST = [
|
|
@@ -26,6 +28,7 @@ const NAME_LIST = [
|
|
|
26
28
|
'connector-imports',
|
|
27
29
|
'env-get',
|
|
28
30
|
'any-aliases',
|
|
31
|
+
'binding-keys',
|
|
29
32
|
];
|
|
30
33
|
const NAMES = NAME_LIST.join(', ');
|
|
31
34
|
/** A usage error: nothing was read or written. */
|
|
@@ -37,6 +40,7 @@ const NOT_REVERSIBLE = new Set([
|
|
|
37
40
|
'async-style',
|
|
38
41
|
'env-get',
|
|
39
42
|
'any-aliases',
|
|
43
|
+
'binding-keys',
|
|
40
44
|
]);
|
|
41
45
|
/** `devz codemod <name> [args]`: hands the arguments to the codemod called `name`. */
|
|
42
46
|
class CodemodCommand {
|
|
@@ -72,6 +76,9 @@ class CodemodCommand {
|
|
|
72
76
|
if (name === 'any-aliases') {
|
|
73
77
|
return any_aliases_1.AnyAliasesCommand.run({ root: opts.root, args: rest });
|
|
74
78
|
}
|
|
79
|
+
if (name === 'binding-keys') {
|
|
80
|
+
return binding_keys_1.BindingKeysCommand.run({ root: opts.root, args: rest });
|
|
81
|
+
}
|
|
75
82
|
if (args.includes('--help') || args.includes('-h')) {
|
|
76
83
|
console.log(USAGE);
|
|
77
84
|
return 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cli/codemod/index.ts"],"names":[],"mappings":";;;AAAA,+CAAkD;AAClD,+CAAkD;AAClD,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;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vB,OAAO,uBAAa,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QAC5D,CAAC;QAED,IAAI,IAAI,KAAK,aAAa,EAAE,CAAC;YAC3B,OAAO,+BAAiB,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QAChE,CAAC;QAED,IAAI,IAAI,KAAK,cAAc,EAAE,CAAC;YAC5B,OAAO,iCAAkB,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QACjE,CAAC;QAED,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,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;AA7DD,wCA6DC","sourcesContent":["import { AnyAliasesCommand } from './any-aliases';\nimport { AsyncStyleCommand } from './async-style';\nimport { BindingKeysCommand } from './binding-keys';\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].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];\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 (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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@venizia/dev-configs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0-1",
|
|
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",
|