@venizia/dev-configs 0.4.7-1 → 0.4.7-3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/checks/purity/probe.d.ts.map +1 -1
  2. package/dist/checks/purity/probe.js +1 -2
  3. package/dist/checks/purity/probe.js.map +1 -1
  4. package/dist/checks/test-mutate.d.ts.map +1 -1
  5. package/dist/checks/test-mutate.js +1 -2
  6. package/dist/checks/test-mutate.js.map +1 -1
  7. package/dist/cli/codemod/async-style.d.ts +1 -1
  8. package/dist/cli/codemod/async-style.d.ts.map +1 -1
  9. package/dist/cli/codemod/async-style.js +13 -0
  10. package/dist/cli/codemod/async-style.js.map +1 -1
  11. package/dist/cli/codemod/const-classes.d.ts +1 -1
  12. package/dist/cli/codemod/const-classes.d.ts.map +1 -1
  13. package/dist/cli/codemod/const-classes.js +13 -0
  14. package/dist/cli/codemod/const-classes.js.map +1 -1
  15. package/dist/cli/codemod/drop-redundant-casts.d.ts +1 -1
  16. package/dist/cli/codemod/drop-redundant-casts.d.ts.map +1 -1
  17. package/dist/cli/codemod/drop-redundant-casts.js +13 -0
  18. package/dist/cli/codemod/drop-redundant-casts.js.map +1 -1
  19. package/dist/cli/codemod/files.d.ts +12 -0
  20. package/dist/cli/codemod/files.d.ts.map +1 -1
  21. package/dist/cli/codemod/files.js +18 -0
  22. package/dist/cli/codemod/files.js.map +1 -1
  23. package/dist/cli/codemod/namespace-functions/index.d.ts +1 -1
  24. package/dist/cli/codemod/namespace-functions/index.d.ts.map +1 -1
  25. package/dist/cli/codemod/namespace-functions/index.js +7 -5
  26. package/dist/cli/codemod/namespace-functions/index.js.map +1 -1
  27. package/dist/cli/codemod/namespace-functions/logger-scope.d.ts +31 -10
  28. package/dist/cli/codemod/namespace-functions/logger-scope.d.ts.map +1 -1
  29. package/dist/cli/codemod/namespace-functions/logger-scope.js +290 -43
  30. package/dist/cli/codemod/namespace-functions/logger-scope.js.map +1 -1
  31. package/dist/cli/codemod/namespace-functions/mappings/core-server.d.ts +4 -2
  32. package/dist/cli/codemod/namespace-functions/mappings/core-server.d.ts.map +1 -1
  33. package/dist/cli/codemod/namespace-functions/mappings/core-server.js +20 -2
  34. package/dist/cli/codemod/namespace-functions/mappings/core-server.js.map +1 -1
  35. package/dist/cli/codemod/namespace-functions/mappings/helpers.d.ts +2 -2
  36. package/dist/cli/codemod/namespace-functions/mappings/helpers.js +2 -2
  37. package/dist/cli/codemod/namespace-functions/mappings/helpers.js.map +1 -1
  38. package/package.json +1 -1
@@ -2,15 +2,20 @@ import type ts from 'typescript';
2
2
  import type { INamespaceFunctionsResult } from './rewriter';
3
3
  type TTypeScript = typeof ts;
4
4
  /**
5
- * The call-shape rule that goes with the table: `ApplicationLogger.get('scope')` is now
6
- * `ApplicationLogger.get({ scope: 'scope' })`. The call is on a class, not a function in a table, so the
7
- * table cannot carry it. It follows `ApplicationLogger` imported by name (aliased too) or reached through a
8
- * namespace import from `@venizia/ignis-helpers` or `@venizia/ignis`, and rewrites a single argument that is a
9
- * string literal, a template, an identifier or a property access. It leaves the object form alone, never
10
- * touches `Logger.get` or `HfLogger.get`, and lists a call it cannot decide with file and line.
5
+ * The call-shape rule that goes with the table. `ApplicationLogger` is removed: every form of it becomes
6
+ * `LoggerFactory.getLogger([scope])`, so `ApplicationLogger.get('scope')`, `ApplicationLogger.get(NAME)` and
7
+ * `ApplicationLogger.get({ scope: NAME })` all become `LoggerFactory.getLogger(['scope'])`, `...([NAME])`. The call is on a
8
+ * class, not a function in a table, so the table cannot carry it.
9
+ *
10
+ * It follows `ApplicationLogger` imported by name (aliased too) or reached through a namespace import from
11
+ * `@venizia/ignis-helpers` or `@venizia/ignis`, adds `LoggerFactory` to that import and drops `ApplicationLogger` once
12
+ * nothing else uses it. The argument may be a string literal, a template, an identifier, a property access, or an
13
+ * object literal that holds only `scope`. It never touches `Logger.get` or `HfLogger.get`, and it lists a call it cannot
14
+ * decide with file and line.
11
15
  */
12
16
  export declare class LoggerScopeRewriter {
13
17
  static readonly CLASS_NAME = "ApplicationLogger";
18
+ static readonly TARGET_NAME = "LoggerFactory";
14
19
  static readonly MODULES: ReadonlyArray<string>;
15
20
  /** Whether the file can hold such a call, so a file without it is not parsed. */
16
21
  static mentions(opts: {
@@ -21,12 +26,28 @@ export declare class LoggerScopeRewriter {
21
26
  fileName: string;
22
27
  source: string;
23
28
  }): INamespaceFunctionsResult;
24
- /** The local names that reach `ApplicationLogger`: the named imports, and the namespace imports of its modules. */
25
29
  private static findLocals;
26
- /** `<ApplicationLogger>.get(...)` or `<namespace>.ApplicationLogger.get(...)`. */
27
- private static isLoggerGet;
28
- /** One edit for a call that has a single scope argument, or a report when the call cannot be decided. */
30
+ /** The node that names the class in `<ApplicationLogger>.get(...)` or `<namespace>.ApplicationLogger.get(...)`, else undefined. */
31
+ private static loggerOwnerOf;
32
+ /** The scope expression of the call, as text, or a reason it cannot be decided. */
33
+ private static scopeOf;
34
+ /** One edit for a call whose scope is decided: the whole call text becomes `<owner replaced>.getLogger([scope])`. */
29
35
  private static plan;
36
+ /**
37
+ * `LoggerFactory` is added to the import that carried `ApplicationLogger`, and `ApplicationLogger` leaves it when no
38
+ * other use of it remains.
39
+ */
40
+ private static planImports;
41
+ /** A re-export of the removed class from a listed module, or a type-only import of it, is listed. */
42
+ private static reportDeclarations;
43
+ /** Where `LoggerFactory` stands in the file: imported from a listed module (under which local name), or a name clash. */
44
+ private static findFactory;
45
+ /** Every use of the removed class that is not a call this run rewrote (a type, a value, an export) is listed. */
46
+ private static reportLeftovers;
47
+ /** How many identifiers named `name` the file holds, the import specifier included. */
48
+ private static countReferences;
49
+ /** Removes one specifier from a named import together with its comma. */
50
+ private static dropSpecifier;
30
51
  }
31
52
  export {};
32
53
  //# sourceMappingURL=logger-scope.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger-scope.d.ts","sourceRoot":"","sources":["../../../../src/cli/codemod/namespace-functions/logger-scope.ts"],"names":[],"m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AAQ,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO;IAIlD,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE;QACnB,UAAU,EAAE,WAAW,CAAC;QACxB,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;KAChB,GAAG,yBAAyB;IA+F7B,OAAO,CAAC,MAAM,CAAC,UAAU;IAuCzB,mIAAmI;IACnI,OAAO,CAAC,MAAM,CAAC,aAAa;IA6B5B,mFAAmF;IACnF,OAAO,CAAC,MAAM,CAAC,OAAO;IAwDtB,qHAAqH;IACrH,OAAO,CAAC,MAAM,CAAC,IAAI;IAgCnB;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,WAAW;IAsD1B,qGAAqG;IACrG,OAAO,CAAC,MAAM,CAAC,kBAAkB;IAiDjC,yHAAyH;IACzH,OAAO,CAAC,MAAM,CAAC,WAAW;IAqD1B,iHAAiH;IACjH,OAAO,CAAC,MAAM,CAAC,eAAe;IA0C9B,uFAAuF;IACvF,OAAO,CAAC,MAAM,CAAC,eAAe;IAwB9B,yEAAyE;IACzE,OAAO,CAAC,MAAM,CAAC,aAAa;CAuB7B"}
@@ -2,15 +2,20 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LoggerScopeRewriter = void 0;
4
4
  /**
5
- * The call-shape rule that goes with the table: `ApplicationLogger.get('scope')` is now
6
- * `ApplicationLogger.get({ scope: 'scope' })`. The call is on a class, not a function in a table, so the
7
- * table cannot carry it. It follows `ApplicationLogger` imported by name (aliased too) or reached through a
8
- * namespace import from `@venizia/ignis-helpers` or `@venizia/ignis`, and rewrites a single argument that is a
9
- * string literal, a template, an identifier or a property access. It leaves the object form alone, never
10
- * touches `Logger.get` or `HfLogger.get`, and lists a call it cannot decide with file and line.
5
+ * The call-shape rule that goes with the table. `ApplicationLogger` is removed: every form of it becomes
6
+ * `LoggerFactory.getLogger([scope])`, so `ApplicationLogger.get('scope')`, `ApplicationLogger.get(NAME)` and
7
+ * `ApplicationLogger.get({ scope: NAME })` all become `LoggerFactory.getLogger(['scope'])`, `...([NAME])`. The call is on a
8
+ * class, not a function in a table, so the table cannot carry it.
9
+ *
10
+ * It follows `ApplicationLogger` imported by name (aliased too) or reached through a namespace import from
11
+ * `@venizia/ignis-helpers` or `@venizia/ignis`, adds `LoggerFactory` to that import and drops `ApplicationLogger` once
12
+ * nothing else uses it. The argument may be a string literal, a template, an identifier, a property access, or an
13
+ * object literal that holds only `scope`. It never touches `Logger.get` or `HfLogger.get`, and it lists a call it cannot
14
+ * decide with file and line.
11
15
  */
12
16
  class LoggerScopeRewriter {
13
17
  static { this.CLASS_NAME = 'ApplicationLogger'; }
18
+ static { this.TARGET_NAME = 'LoggerFactory'; }
14
19
  static { this.MODULES = ['@venizia/ignis-helpers', '@venizia/ignis']; }
15
20
  /** Whether the file can hold such a call, so a file without it is not parsed. */
16
21
  static mentions(opts) {
@@ -19,41 +24,76 @@ class LoggerScopeRewriter {
19
24
  static rewrite(opts) {
20
25
  const { typescript, fileName, source } = opts;
21
26
  const reports = [];
27
+ const unchanged = { output: source, changed: false, rewritten: 0, reports };
22
28
  if (!LoggerScopeRewriter.mentions({ source })) {
23
- return { output: source, changed: false, rewritten: 0, reports };
29
+ return unchanged;
24
30
  }
25
31
  const sourceFile = typescript.createSourceFile(fileName, source, typescript.ScriptTarget.Latest, true);
26
- const { classNames, namespaces } = LoggerScopeRewriter.findLocals({ typescript, sourceFile });
27
- if (classNames.size === 0 && namespaces.size === 0) {
28
- return { output: source, changed: false, rewritten: 0, reports };
29
- }
30
- const edits = [];
31
32
  const report = (node, reason) => {
32
33
  const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
33
34
  reports.push({ line: line + 1, column: character + 1, reason });
34
35
  };
36
+ // A re-export or a type-only import of the removed class is not a call: it is listed, never silently kept.
37
+ LoggerScopeRewriter.reportDeclarations({ typescript, sourceFile, report });
38
+ const locals = LoggerScopeRewriter.findLocals({ typescript, sourceFile });
39
+ if (locals.named.size === 0 && locals.namespaces.size === 0) {
40
+ return unchanged;
41
+ }
42
+ const factory = LoggerScopeRewriter.findFactory({ typescript, sourceFile });
43
+ if (factory.collision) {
44
+ report(factory.collision, '`LoggerFactory` is already declared in this file (or imported from another module): rewrite `ApplicationLogger` by hand as `LoggerFactory.getLogger([scope])`');
45
+ return unchanged;
46
+ }
47
+ const factoryName = factory.local ?? LoggerScopeRewriter.TARGET_NAME;
48
+ const edits = [];
49
+ /** Identifiers of the old class that a rewritten call replaced: what is left after them keeps the import. */
50
+ const rewrittenOwners = new Set();
35
51
  const visit = (node) => {
36
- if (typescript.isCallExpression(node) &&
37
- LoggerScopeRewriter.isLoggerGet({ typescript, call: node, classNames, namespaces })) {
38
- LoggerScopeRewriter.plan({ typescript, sourceFile, call: node, edits, report });
52
+ if (typescript.isCallExpression(node)) {
53
+ const owner = LoggerScopeRewriter.loggerOwnerOf({ typescript, call: node, locals });
54
+ if (owner) {
55
+ LoggerScopeRewriter.plan({
56
+ typescript,
57
+ sourceFile,
58
+ call: node,
59
+ owner,
60
+ factoryName,
61
+ edits,
62
+ rewrittenOwners,
63
+ report,
64
+ });
65
+ }
39
66
  }
40
67
  typescript.forEachChild(node, visit);
41
68
  };
42
69
  visit(sourceFile);
43
70
  if (edits.length === 0) {
44
- return { output: source, changed: false, rewritten: 0, reports };
71
+ return unchanged;
45
72
  }
73
+ LoggerScopeRewriter.planImports({
74
+ typescript,
75
+ sourceFile,
76
+ locals,
77
+ rewrittenOwners,
78
+ hasFactory: factory.local !== undefined,
79
+ edits,
80
+ });
81
+ LoggerScopeRewriter.reportLeftovers({
82
+ typescript,
83
+ sourceFile,
84
+ locals,
85
+ rewrittenOwners,
86
+ report,
87
+ });
46
88
  let output = source;
47
89
  for (const edit of [...edits].sort((first, second) => second.start - first.start)) {
48
90
  output = output.slice(0, edit.start) + edit.text + output.slice(edit.end);
49
91
  }
50
- return { output, changed: true, rewritten: edits.length, reports };
92
+ return { output, changed: true, rewritten: rewrittenOwners.size, reports };
51
93
  }
52
- /** The local names that reach `ApplicationLogger`: the named imports, and the namespace imports of its modules. */
53
94
  static findLocals(opts) {
54
95
  const { typescript, sourceFile } = opts;
55
- const classNames = new Set();
56
- const namespaces = new Set();
96
+ const locals = { named: new Map(), namespaces: new Set(), declarations: [] };
57
97
  for (const statement of sourceFile.statements) {
58
98
  if (!typescript.isImportDeclaration(statement) ||
59
99
  !typescript.isStringLiteral(statement.moduleSpecifier) ||
@@ -64,8 +104,9 @@ class LoggerScopeRewriter {
64
104
  if (!bindings || statement.importClause?.isTypeOnly) {
65
105
  continue;
66
106
  }
107
+ locals.declarations.push(statement);
67
108
  if (typescript.isNamespaceImport(bindings)) {
68
- namespaces.add(bindings.name.text);
109
+ locals.namespaces.add(bindings.name.text);
69
110
  continue;
70
111
  }
71
112
  for (const specifier of bindings.elements) {
@@ -73,38 +114,58 @@ class LoggerScopeRewriter {
73
114
  continue;
74
115
  }
75
116
  if ((specifier.propertyName ?? specifier.name).text === LoggerScopeRewriter.CLASS_NAME) {
76
- classNames.add(specifier.name.text);
117
+ locals.named.set(specifier.name.text, specifier);
77
118
  }
78
119
  }
79
120
  }
80
- return { classNames, namespaces };
121
+ return locals;
81
122
  }
82
- /** `<ApplicationLogger>.get(...)` or `<namespace>.ApplicationLogger.get(...)`. */
83
- static isLoggerGet(opts) {
84
- const { typescript, call, classNames, namespaces } = opts;
123
+ /** The node that names the class in `<ApplicationLogger>.get(...)` or `<namespace>.ApplicationLogger.get(...)`, else undefined. */
124
+ static loggerOwnerOf(opts) {
125
+ const { typescript, call, locals } = opts;
85
126
  const callee = call.expression;
86
127
  if (!typescript.isPropertyAccessExpression(callee) || callee.name.text !== 'get') {
87
- return false;
128
+ return undefined;
88
129
  }
89
130
  const owner = callee.expression;
90
- if (typescript.isIdentifier(owner)) {
91
- return classNames.has(owner.text);
131
+ if (typescript.isIdentifier(owner) && locals.named.has(owner.text)) {
132
+ return owner;
92
133
  }
93
- return (typescript.isPropertyAccessExpression(owner) &&
134
+ if (typescript.isPropertyAccessExpression(owner) &&
94
135
  owner.name.text === LoggerScopeRewriter.CLASS_NAME &&
95
136
  typescript.isIdentifier(owner.expression) &&
96
- namespaces.has(owner.expression.text));
137
+ locals.namespaces.has(owner.expression.text)) {
138
+ return owner;
139
+ }
140
+ return undefined;
97
141
  }
98
- /** One edit for a call that has a single scope argument, or a report when the call cannot be decided. */
99
- static plan(opts) {
100
- const { typescript, sourceFile, call, edits, report } = opts;
142
+ /** The scope expression of the call, as text, or a reason it cannot be decided. */
143
+ static scopeOf(opts) {
144
+ const { typescript, sourceFile, call } = opts;
101
145
  const [argument] = call.arguments;
102
146
  if (call.arguments.length !== 1 || !argument) {
103
- report(call, '`ApplicationLogger.get` is called with no argument or more than one: rewrite it by hand as `ApplicationLogger.get({ scope })`');
104
- return;
147
+ return {
148
+ reason: '`ApplicationLogger.get` is called with no argument or more than one: rewrite it by hand as `LoggerFactory.getLogger([scope])`',
149
+ };
105
150
  }
106
151
  if (typescript.isObjectLiteralExpression(argument)) {
107
- return;
152
+ const [property, ...rest] = argument.properties;
153
+ const isOnlyScope = rest.length === 0 &&
154
+ property !== undefined &&
155
+ (typescript.isShorthandPropertyAssignment(property) ||
156
+ typescript.isPropertyAssignment(property)) &&
157
+ typescript.isIdentifier(property.name) &&
158
+ property.name.text === 'scope';
159
+ if (!isOnlyScope) {
160
+ return {
161
+ reason: '`ApplicationLogger.get` gets an object that is not `{ scope: <expression> }`: rewrite it by hand as `LoggerFactory.getLogger([scope])`',
162
+ };
163
+ }
164
+ return {
165
+ text: typescript.isShorthandPropertyAssignment(property)
166
+ ? property.name.text
167
+ : property.initializer.getText(sourceFile),
168
+ };
108
169
  }
109
170
  const isDecidable = typescript.isStringLiteral(argument) ||
110
171
  typescript.isNoSubstitutionTemplateLiteral(argument) ||
@@ -112,16 +173,202 @@ class LoggerScopeRewriter {
112
173
  typescript.isIdentifier(argument) ||
113
174
  typescript.isPropertyAccessExpression(argument);
114
175
  if (!isDecidable) {
115
- report(argument, '`ApplicationLogger.get` gets an argument whose type the codemod cannot tell (a call, a spread or another expression): rewrite it by hand as `ApplicationLogger.get({ scope: <argument> })`');
176
+ return {
177
+ reason: '`ApplicationLogger.get` gets an argument whose type the codemod cannot tell (a call, a spread or another expression): rewrite it by hand as `LoggerFactory.getLogger([<argument>])`',
178
+ };
179
+ }
180
+ return { text: argument.getText(sourceFile) };
181
+ }
182
+ /** One edit for a call whose scope is decided: the whole call text becomes `<owner replaced>.getLogger([scope])`. */
183
+ static plan(opts) {
184
+ const { typescript, sourceFile, call, owner, factoryName, edits, rewrittenOwners, report } = opts;
185
+ const scope = LoggerScopeRewriter.scopeOf({ typescript, sourceFile, call });
186
+ if ('reason' in scope) {
187
+ report(call, scope.reason);
116
188
  return;
117
189
  }
118
- const text = argument.getText(sourceFile);
119
- const isShort = typescript.isIdentifier(argument) && argument.text === 'scope';
190
+ // `<namespace>.ApplicationLogger` keeps its namespace: `helpers.LoggerFactory.getLogger([...])`.
191
+ const ownerText = typescript.isIdentifier(owner)
192
+ ? factoryName
193
+ : `${owner.expression.getText(sourceFile)}.${LoggerScopeRewriter.TARGET_NAME}`;
120
194
  edits.push({
121
- start: argument.getStart(sourceFile),
122
- end: argument.getEnd(),
123
- text: isShort ? '{ scope }' : `{ scope: ${text} }`,
195
+ start: call.getStart(sourceFile),
196
+ end: call.getEnd(),
197
+ text: `${ownerText}.getLogger([${scope.text}])`,
124
198
  });
199
+ rewrittenOwners.add(owner);
200
+ }
201
+ /**
202
+ * `LoggerFactory` is added to the import that carried `ApplicationLogger`, and `ApplicationLogger` leaves it when no
203
+ * other use of it remains.
204
+ */
205
+ static planImports(opts) {
206
+ const { typescript, sourceFile, locals, rewrittenOwners, hasFactory, edits } = opts;
207
+ for (const [local, specifier] of locals.named) {
208
+ const used = LoggerScopeRewriter.countReferences({ typescript, sourceFile, name: local });
209
+ const replaced = [...rewrittenOwners].filter((owner) => typescript.isIdentifier(owner) && owner.text === local).length;
210
+ const declaration = specifier.parent.parent.parent;
211
+ const imported = declaration.importClause?.namedBindings;
212
+ if (!imported || !typescript.isNamedImports(imported)) {
213
+ continue;
214
+ }
215
+ const hasTarget = hasFactory;
216
+ const isLeft = used - replaced > 1; // the import specifier itself is one reference
217
+ if (isLeft) {
218
+ if (!hasTarget) {
219
+ edits.push({
220
+ start: specifier.getEnd(),
221
+ end: specifier.getEnd(),
222
+ text: `, ${LoggerScopeRewriter.TARGET_NAME}`,
223
+ });
224
+ }
225
+ continue;
226
+ }
227
+ if (hasTarget) {
228
+ LoggerScopeRewriter.dropSpecifier({
229
+ sourceFile,
230
+ specifier,
231
+ elements: imported.elements,
232
+ edits,
233
+ });
234
+ }
235
+ else {
236
+ edits.push({
237
+ start: specifier.getStart(sourceFile),
238
+ end: specifier.getEnd(),
239
+ text: LoggerScopeRewriter.TARGET_NAME,
240
+ });
241
+ }
242
+ }
243
+ }
244
+ /** A re-export of the removed class from a listed module, or a type-only import of it, is listed. */
245
+ static reportDeclarations(opts) {
246
+ const { typescript, sourceFile, report } = opts;
247
+ const named = (element) => (element.propertyName ?? element.name).text === LoggerScopeRewriter.CLASS_NAME;
248
+ for (const statement of sourceFile.statements) {
249
+ if (typescript.isExportDeclaration(statement) &&
250
+ statement.moduleSpecifier &&
251
+ typescript.isStringLiteral(statement.moduleSpecifier) &&
252
+ LoggerScopeRewriter.MODULES.includes(statement.moduleSpecifier.text) &&
253
+ statement.exportClause &&
254
+ typescript.isNamedExports(statement.exportClause) &&
255
+ statement.exportClause.elements.some(named)) {
256
+ report(statement, '`ApplicationLogger` no longer exists: this re-export has no replacement, remove it (`LoggerFactory` is the class)');
257
+ }
258
+ if (typescript.isImportDeclaration(statement) &&
259
+ typescript.isStringLiteral(statement.moduleSpecifier) &&
260
+ LoggerScopeRewriter.MODULES.includes(statement.moduleSpecifier.text)) {
261
+ const bindings = statement.importClause?.namedBindings;
262
+ const isNamed = bindings && typescript.isNamedImports(bindings);
263
+ const isTypeImport = statement.importClause?.isTypeOnly === true;
264
+ const typed = isNamed &&
265
+ bindings.elements.some((element) => named(element) && (isTypeImport || element.isTypeOnly));
266
+ if (typed) {
267
+ report(statement, '`ApplicationLogger` no longer exists: this type-only import has no replacement, use the type of what `LoggerFactory.getLogger` returns (`ILogger`)');
268
+ }
269
+ }
270
+ }
271
+ }
272
+ /** Where `LoggerFactory` stands in the file: imported from a listed module (under which local name), or a name clash. */
273
+ static findFactory(opts) {
274
+ const { typescript, sourceFile } = opts;
275
+ const found = {};
276
+ for (const statement of sourceFile.statements) {
277
+ if (typescript.isImportDeclaration(statement)) {
278
+ const bindings = statement.importClause?.namedBindings;
279
+ if (!bindings || !typescript.isNamedImports(bindings)) {
280
+ continue;
281
+ }
282
+ for (const element of bindings.elements) {
283
+ if ((element.propertyName ?? element.name).text !== LoggerScopeRewriter.TARGET_NAME) {
284
+ continue;
285
+ }
286
+ const isListed = typescript.isStringLiteral(statement.moduleSpecifier) &&
287
+ LoggerScopeRewriter.MODULES.includes(statement.moduleSpecifier.text);
288
+ if (isListed) {
289
+ found.local = element.name.text;
290
+ }
291
+ else {
292
+ found.collision = element;
293
+ }
294
+ }
295
+ continue;
296
+ }
297
+ const isNamedDeclaration = (typescript.isClassDeclaration(statement) ||
298
+ typescript.isFunctionDeclaration(statement) ||
299
+ typescript.isInterfaceDeclaration(statement) ||
300
+ typescript.isTypeAliasDeclaration(statement)) &&
301
+ statement.name?.text === LoggerScopeRewriter.TARGET_NAME;
302
+ const isNamedVariable = typescript.isVariableStatement(statement) &&
303
+ statement.declarationList.declarations.some((declaration) => typescript.isIdentifier(declaration.name) &&
304
+ declaration.name.text === LoggerScopeRewriter.TARGET_NAME);
305
+ if (isNamedDeclaration || isNamedVariable) {
306
+ found.collision = statement;
307
+ }
308
+ }
309
+ return found;
310
+ }
311
+ /** Every use of the removed class that is not a call this run rewrote (a type, a value, an export) is listed. */
312
+ static reportLeftovers(opts) {
313
+ const { typescript, sourceFile, locals, rewrittenOwners, report } = opts;
314
+ const visit = (node) => {
315
+ if (typescript.isIdentifier(node) && !rewrittenOwners.has(node)) {
316
+ const parent = node.parent;
317
+ const isImportName = typescript.isImportSpecifier(parent);
318
+ const isProperty = typescript.isPropertyAccessExpression(parent) && parent.name === node;
319
+ const isLocal = locals.named.has(node.text);
320
+ if (isLocal && !isImportName && !isProperty) {
321
+ report(node, '`ApplicationLogger` no longer exists and this use is not a call the codemod rewrites: change it by hand (`LoggerFactory` is the class, `ILogger` the type of a logger)');
322
+ }
323
+ }
324
+ if (typescript.isPropertyAccessExpression(node) &&
325
+ node.name.text === LoggerScopeRewriter.CLASS_NAME &&
326
+ typescript.isIdentifier(node.expression) &&
327
+ locals.namespaces.has(node.expression.text) &&
328
+ !rewrittenOwners.has(node)) {
329
+ report(node, '`ApplicationLogger` no longer exists and this use is not a call the codemod rewrites: change it by hand');
330
+ }
331
+ typescript.forEachChild(node, visit);
332
+ };
333
+ visit(sourceFile);
334
+ }
335
+ /** How many identifiers named `name` the file holds, the import specifier included. */
336
+ static countReferences(opts) {
337
+ const { typescript, sourceFile, name } = opts;
338
+ let count = 0;
339
+ const visit = (node) => {
340
+ if (typescript.isIdentifier(node) && node.text === name) {
341
+ // A property name (`x.name`) is not a reference to the import.
342
+ const parent = node.parent;
343
+ const isProperty = typescript.isPropertyAccessExpression(parent) && parent.name === node;
344
+ if (!isProperty) {
345
+ count += 1;
346
+ }
347
+ }
348
+ typescript.forEachChild(node, visit);
349
+ };
350
+ visit(sourceFile);
351
+ return count;
352
+ }
353
+ /** Removes one specifier from a named import together with its comma. */
354
+ static dropSpecifier(opts) {
355
+ const { sourceFile, specifier, elements, edits } = opts;
356
+ const index = elements.indexOf(specifier);
357
+ const next = elements[index + 1];
358
+ const previous = elements[index - 1];
359
+ if (next) {
360
+ edits.push({
361
+ start: specifier.getStart(sourceFile),
362
+ end: next.getStart(sourceFile),
363
+ text: '',
364
+ });
365
+ }
366
+ else if (previous) {
367
+ edits.push({ start: previous.getEnd(), end: specifier.getEnd(), text: '' });
368
+ }
369
+ else {
370
+ edits.push({ start: specifier.getStart(sourceFile), end: specifier.getEnd(), text: '' });
371
+ }
125
372
  }
126
373
  }
127
374
  exports.LoggerScopeRewriter = LoggerScopeRewriter;
@@ -1 +1 @@
1
- {"version":3,"file":"logger-scope.js","sourceRoot":"","sources":["../../../../src/cli/codemod/namespace-functions/logger-scope.ts"],"names":[],"mappings":";;;AAWA;;;;;;;GAOG;AACH,MAAa,mBAAmB;aACd,eAAU,GAAG,mBAAmB,CAAC;aACjC,YAAO,GAA0B,CAAC,wBAAwB,EAAE,gBAAgB,CAAC,CAAC;IAE9F,iFAAiF;IACjF,MAAM,CAAC,QAAQ,CAAC,IAAwB;QACtC,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAC9D,CAAC;IAED,MAAM,CAAC,OAAO,CAAC,IAId;QACC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QAC9C,MAAM,OAAO,GAAgC,EAAE,CAAC;QAEhD,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;YAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC;QACnE,CAAC;QAED,MAAM,UAAU,GAAG,UAAU,CAAC,gBAAgB,CAC5C,QAAQ,EACR,MAAM,EACN,UAAU,CAAC,YAAY,CAAC,MAAM,EAC9B,IAAI,CACL,CAAC;QAEF,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,mBAAmB,CAAC,UAAU,CAAC,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC;QAC9F,IAAI,UAAU,CAAC,IAAI,KAAK,CAAC,IAAI,UAAU,CAAC,IAAI,KAAK,C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":["import type ts from 'typescript';\nimport type { INamespaceFunctionsReport, INamespaceFunctionsResult } from './rewriter';\n\ntype TTypeScript = typeof ts;\n\ninterface IEdit {\n start: number;\n end: number;\n text: string;\n}\n\n/**\n * The call-shape rule that goes with the table: `ApplicationLogger.get('scope')` is now\n * `ApplicationLogger.get({ scope: 'scope' })`. The call is on a class, not a function in a table, so the\n * table cannot carry it. It follows `ApplicationLogger` imported by name (aliased too) or reached through a\n * namespace import from `@venizia/ignis-helpers` or `@venizia/ignis`, and rewrites a single argument that is a\n * string literal, a template, an identifier or a property access. It leaves the object form alone, never\n * touches `Logger.get` or `HfLogger.get`, and lists a call it cannot decide with file and line.\n */\nexport class LoggerScopeRewriter {\n static readonly CLASS_NAME = 'ApplicationLogger';\n static readonly MODULES: ReadonlyArray<string> = ['@venizia/ignis-helpers', '@venizia/ignis'];\n\n /** Whether the file can hold such a call, so a file without it is not parsed. */\n static mentions(opts: { source: string }): boolean {\n return opts.source.includes(LoggerScopeRewriter.CLASS_NAME);\n }\n\n static rewrite(opts: {\n typescript: TTypeScript;\n fileName: string;\n source: string;\n }): INamespaceFunctionsResult {\n const { typescript, fileName, source } = opts;\n const reports: INamespaceFunctionsReport[] = [];\n\n if (!LoggerScopeRewriter.mentions({ source })) {\n return { output: source, changed: false, rewritten: 0, reports };\n }\n\n const sourceFile = typescript.createSourceFile(\n fileName,\n source,\n typescript.ScriptTarget.Latest,\n true,\n );\n\n const { classNames, namespaces } = LoggerScopeRewriter.findLocals({ typescript, sourceFile });\n if (classNames.size === 0 && namespaces.size === 0) {\n return { output: source, changed: false, rewritten: 0, reports };\n }\n\n const edits: IEdit[] = [];\n const report = (node: ts.Node, reason: string) => {\n const { line, character } = sourceFile.getLineAndCharacterOfPosition(\n node.getStart(sourceFile),\n );\n reports.push({ line: line + 1, column: character + 1, reason });\n };\n\n const visit = (node: ts.Node): void => {\n if (\n typescript.isCallExpression(node) &&\n LoggerScopeRewriter.isLoggerGet({ typescript, call: node, classNames, namespaces })\n ) {\n LoggerScopeRewriter.plan({ typescript, sourceFile, call: node, edits, report });\n }\n\n typescript.forEachChild(node, visit);\n };\n visit(sourceFile);\n\n if (edits.length === 0) {\n return { output: source, changed: false, rewritten: 0, reports };\n }\n\n let output = source;\n for (const edit of [...edits].sort((first, second) => second.start - first.start)) {\n output = output.slice(0, edit.start) + edit.text + output.slice(edit.end);\n }\n\n return { output, changed: true, rewritten: edits.length, reports };\n }\n\n /** The local names that reach `ApplicationLogger`: the named imports, and the namespace imports of its modules. */\n private static findLocals(opts: { typescript: TTypeScript; sourceFile: ts.SourceFile }): {\n classNames: Set<string>;\n namespaces: Set<string>;\n } {\n const { typescript, sourceFile } = opts;\n const classNames = new Set<string>();\n const namespaces = new Set<string>();\n\n for (const statement of sourceFile.statements) {\n if (\n !typescript.isImportDeclaration(statement) ||\n !typescript.isStringLiteral(statement.moduleSpecifier) ||\n !LoggerScopeRewriter.MODULES.includes(statement.moduleSpecifier.text)\n ) {\n continue;\n }\n\n const bindings = statement.importClause?.namedBindings;\n if (!bindings || statement.importClause?.isTypeOnly) {\n continue;\n }\n\n if (typescript.isNamespaceImport(bindings)) {\n namespaces.add(bindings.name.text);\n continue;\n }\n\n for (const specifier of bindings.elements) {\n if (specifier.isTypeOnly) {\n continue;\n }\n\n if ((specifier.propertyName ?? specifier.name).text === LoggerScopeRewriter.CLASS_NAME) {\n classNames.add(specifier.name.text);\n }\n }\n }\n\n return { classNames, namespaces };\n }\n\n /** `<ApplicationLogger>.get(...)` or `<namespace>.ApplicationLogger.get(...)`. */\n private static isLoggerGet(opts: {\n typescript: TTypeScript;\n call: ts.CallExpression;\n classNames: Set<string>;\n namespaces: Set<string>;\n }): boolean {\n const { typescript, call, classNames, namespaces } = opts;\n const callee = call.expression;\n\n if (!typescript.isPropertyAccessExpression(callee) || callee.name.text !== 'get') {\n return false;\n }\n\n const owner = callee.expression;\n if (typescript.isIdentifier(owner)) {\n return classNames.has(owner.text);\n }\n\n return (\n typescript.isPropertyAccessExpression(owner) &&\n owner.name.text === LoggerScopeRewriter.CLASS_NAME &&\n typescript.isIdentifier(owner.expression) &&\n namespaces.has(owner.expression.text)\n );\n }\n\n /** One edit for a call that has a single scope argument, or a report when the call cannot be decided. */\n private static plan(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n call: ts.CallExpression;\n edits: IEdit[];\n report: (node: ts.Node, reason: string) => void;\n }): void {\n const { typescript, sourceFile, call, edits, report } = opts;\n const [argument] = call.arguments;\n\n if (call.arguments.length !== 1 || !argument) {\n report(\n call,\n '`ApplicationLogger.get` is called with no argument or more than one: rewrite it by hand as `ApplicationLogger.get({ scope })`',\n );\n return;\n }\n\n if (typescript.isObjectLiteralExpression(argument)) {\n return;\n }\n\n const isDecidable =\n typescript.isStringLiteral(argument) ||\n typescript.isNoSubstitutionTemplateLiteral(argument) ||\n typescript.isTemplateExpression(argument) ||\n typescript.isIdentifier(argument) ||\n typescript.isPropertyAccessExpression(argument);\n\n if (!isDecidable) {\n report(\n argument,\n '`ApplicationLogger.get` gets an argument whose type the codemod cannot tell (a call, a spread or another expression): rewrite it by hand as `ApplicationLogger.get({ scope: <argument> })`',\n );\n return;\n }\n\n const text = argument.getText(sourceFile);\n const isShort = typescript.isIdentifier(argument) && argument.text === 'scope';\n\n edits.push({\n start: argument.getStart(sourceFile),\n end: argument.getEnd(),\n text: isShort ? '{ scope }' : `{ scope: ${text} }`,\n });\n }\n}\n"]}
1
+ {"version":3,"file":"logger-scope.js","sourceRoot":"","sources":["../../../../src/cli/codemod/namespace-functions/logger-scope.ts"],"names":[],"mappings":";;;AAqBA;;;;;;;;;;;GAWG;AACH,MAAa,mBAAmB;aACd,eAAU,GAAG,mBAAmB,CAAC;aACjC,gBAAW,GAAG,eAAe,CAAC;aAC9B,YAAO,GAA0B,CAAC,wBAAwB,EAAE,gBAAgB,CAAC,CAAC;IAE9F,iFAAiF;IACjF,MAAM,CAAC,QAAQ,CAAC,IAAwB;QACtC,OAAO,IAAI,CAAC,MA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Q,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QACjC,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QAErC,IAAI,IAAI,EAAE,CAAC;YACT,KAAK,CAAC,IAAI,CAAC;gBACT,KAAK,EAAE,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC;gBACrC,GAAG,EAAE,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC;gBAC9B,IAAI,EAAE,EAAE;aACT,CAAC,CAAC;QACL,CAAC;aAAM,IAAI,QAAQ,EAAE,CAAC;YACpB,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,MAAM,EAAE,EAAE,GAAG,EAAE,SAAS,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;QAC9E,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,GAAG,EAAE,SAAS,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;QAC3F,CAAC;IACH,CAAC;;AAzgBH,kDA0gBC","sourcesContent":["import type ts from 'typescript';\nimport type { INamespaceFunctionsReport, INamespaceFunctionsResult } from './rewriter';\n\ntype TTypeScript = typeof ts;\n\ninterface IEdit {\n start: number;\n end: number;\n text: string;\n}\n\n/** How a file reaches `ApplicationLogger`: by a named import (aliased too), or through a namespace import. */\ninterface ILocals {\n /** Local name -> the import specifier that declares it. */\n named: Map<string, ts.ImportSpecifier>;\n /** Local name of `import * as name`. */\n namespaces: Set<string>;\n /** The import declarations of the listed modules, in order. */\n declarations: ts.ImportDeclaration[];\n}\n\n/**\n * The call-shape rule that goes with the table. `ApplicationLogger` is removed: every form of it becomes\n * `LoggerFactory.getLogger([scope])`, so `ApplicationLogger.get('scope')`, `ApplicationLogger.get(NAME)` and\n * `ApplicationLogger.get({ scope: NAME })` all become `LoggerFactory.getLogger(['scope'])`, `...([NAME])`. The call is on a\n * class, not a function in a table, so the table cannot carry it.\n *\n * It follows `ApplicationLogger` imported by name (aliased too) or reached through a namespace import from\n * `@venizia/ignis-helpers` or `@venizia/ignis`, adds `LoggerFactory` to that import and drops `ApplicationLogger` once\n * nothing else uses it. The argument may be a string literal, a template, an identifier, a property access, or an\n * object literal that holds only `scope`. It never touches `Logger.get` or `HfLogger.get`, and it lists a call it cannot\n * decide with file and line.\n */\nexport class LoggerScopeRewriter {\n static readonly CLASS_NAME = 'ApplicationLogger';\n static readonly TARGET_NAME = 'LoggerFactory';\n static readonly MODULES: ReadonlyArray<string> = ['@venizia/ignis-helpers', '@venizia/ignis'];\n\n /** Whether the file can hold such a call, so a file without it is not parsed. */\n static mentions(opts: { source: string }): boolean {\n return opts.source.includes(LoggerScopeRewriter.CLASS_NAME);\n }\n\n static rewrite(opts: {\n typescript: TTypeScript;\n fileName: string;\n source: string;\n }): INamespaceFunctionsResult {\n const { typescript, fileName, source } = opts;\n const reports: INamespaceFunctionsReport[] = [];\n const unchanged = { output: source, changed: false, rewritten: 0, reports };\n\n if (!LoggerScopeRewriter.mentions({ source })) {\n return unchanged;\n }\n\n const sourceFile = typescript.createSourceFile(\n fileName,\n source,\n typescript.ScriptTarget.Latest,\n true,\n );\n\n const report = (node: ts.Node, reason: string) => {\n const { line, character } = sourceFile.getLineAndCharacterOfPosition(\n node.getStart(sourceFile),\n );\n reports.push({ line: line + 1, column: character + 1, reason });\n };\n\n // A re-export or a type-only import of the removed class is not a call: it is listed, never silently kept.\n LoggerScopeRewriter.reportDeclarations({ typescript, sourceFile, report });\n\n const locals = LoggerScopeRewriter.findLocals({ typescript, sourceFile });\n if (locals.named.size === 0 && locals.namespaces.size === 0) {\n return unchanged;\n }\n\n const factory = LoggerScopeRewriter.findFactory({ typescript, sourceFile });\n if (factory.collision) {\n report(\n factory.collision,\n '`LoggerFactory` is already declared in this file (or imported from another module): rewrite `ApplicationLogger` by hand as `LoggerFactory.getLogger([scope])`',\n );\n return unchanged;\n }\n\n const factoryName = factory.local ?? LoggerScopeRewriter.TARGET_NAME;\n const edits: IEdit[] = [];\n /** Identifiers of the old class that a rewritten call replaced: what is left after them keeps the import. */\n const rewrittenOwners = new Set<ts.Node>();\n\n const visit = (node: ts.Node): void => {\n if (typescript.isCallExpression(node)) {\n const owner = LoggerScopeRewriter.loggerOwnerOf({ typescript, call: node, locals });\n\n if (owner) {\n LoggerScopeRewriter.plan({\n typescript,\n sourceFile,\n call: node,\n owner,\n factoryName,\n edits,\n rewrittenOwners,\n report,\n });\n }\n }\n\n typescript.forEachChild(node, visit);\n };\n visit(sourceFile);\n\n if (edits.length === 0) {\n return unchanged;\n }\n\n LoggerScopeRewriter.planImports({\n typescript,\n sourceFile,\n locals,\n rewrittenOwners,\n hasFactory: factory.local !== undefined,\n edits,\n });\n LoggerScopeRewriter.reportLeftovers({\n typescript,\n sourceFile,\n locals,\n rewrittenOwners,\n report,\n });\n\n let output = source;\n for (const edit of [...edits].sort((first, second) => second.start - first.start)) {\n output = output.slice(0, edit.start) + edit.text + output.slice(edit.end);\n }\n\n return { output, changed: true, rewritten: rewrittenOwners.size, reports };\n }\n\n private static findLocals(opts: { typescript: TTypeScript; sourceFile: ts.SourceFile }): ILocals {\n const { typescript, sourceFile } = opts;\n const locals: ILocals = { named: new Map(), namespaces: new Set(), declarations: [] };\n\n for (const statement of sourceFile.statements) {\n if (\n !typescript.isImportDeclaration(statement) ||\n !typescript.isStringLiteral(statement.moduleSpecifier) ||\n !LoggerScopeRewriter.MODULES.includes(statement.moduleSpecifier.text)\n ) {\n continue;\n }\n\n const bindings = statement.importClause?.namedBindings;\n if (!bindings || statement.importClause?.isTypeOnly) {\n continue;\n }\n\n locals.declarations.push(statement);\n\n if (typescript.isNamespaceImport(bindings)) {\n locals.namespaces.add(bindings.name.text);\n continue;\n }\n\n for (const specifier of bindings.elements) {\n if (specifier.isTypeOnly) {\n continue;\n }\n\n if ((specifier.propertyName ?? specifier.name).text === LoggerScopeRewriter.CLASS_NAME) {\n locals.named.set(specifier.name.text, specifier);\n }\n }\n }\n\n return locals;\n }\n\n /** The node that names the class in `<ApplicationLogger>.get(...)` or `<namespace>.ApplicationLogger.get(...)`, else undefined. */\n private static loggerOwnerOf(opts: {\n typescript: TTypeScript;\n call: ts.CallExpression;\n locals: ILocals;\n }): ts.Identifier | ts.PropertyAccessExpression | undefined {\n const { typescript, call, locals } = opts;\n const callee = call.expression;\n\n if (!typescript.isPropertyAccessExpression(callee) || callee.name.text !== 'get') {\n return undefined;\n }\n\n const owner = callee.expression;\n if (typescript.isIdentifier(owner) && locals.named.has(owner.text)) {\n return owner;\n }\n\n if (\n typescript.isPropertyAccessExpression(owner) &&\n owner.name.text === LoggerScopeRewriter.CLASS_NAME &&\n typescript.isIdentifier(owner.expression) &&\n locals.namespaces.has(owner.expression.text)\n ) {\n return owner;\n }\n\n return undefined;\n }\n\n /** The scope expression of the call, as text, or a reason it cannot be decided. */\n private static scopeOf(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n call: ts.CallExpression;\n }): { text: string } | { reason: string } {\n const { typescript, sourceFile, call } = opts;\n const [argument] = call.arguments;\n\n if (call.arguments.length !== 1 || !argument) {\n return {\n reason:\n '`ApplicationLogger.get` is called with no argument or more than one: rewrite it by hand as `LoggerFactory.getLogger([scope])`',\n };\n }\n\n if (typescript.isObjectLiteralExpression(argument)) {\n const [property, ...rest] = argument.properties;\n const isOnlyScope =\n rest.length === 0 &&\n property !== undefined &&\n (typescript.isShorthandPropertyAssignment(property) ||\n typescript.isPropertyAssignment(property)) &&\n typescript.isIdentifier(property.name) &&\n property.name.text === 'scope';\n\n if (!isOnlyScope) {\n return {\n reason:\n '`ApplicationLogger.get` gets an object that is not `{ scope: <expression> }`: rewrite it by hand as `LoggerFactory.getLogger([scope])`',\n };\n }\n\n return {\n text: typescript.isShorthandPropertyAssignment(property)\n ? property.name.text\n : property.initializer.getText(sourceFile),\n };\n }\n\n const isDecidable =\n typescript.isStringLiteral(argument) ||\n typescript.isNoSubstitutionTemplateLiteral(argument) ||\n typescript.isTemplateExpression(argument) ||\n typescript.isIdentifier(argument) ||\n typescript.isPropertyAccessExpression(argument);\n\n if (!isDecidable) {\n return {\n reason:\n '`ApplicationLogger.get` gets an argument whose type the codemod cannot tell (a call, a spread or another expression): rewrite it by hand as `LoggerFactory.getLogger([<argument>])`',\n };\n }\n\n return { text: argument.getText(sourceFile) };\n }\n\n /** One edit for a call whose scope is decided: the whole call text becomes `<owner replaced>.getLogger([scope])`. */\n private static plan(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n call: ts.CallExpression;\n owner: ts.Identifier | ts.PropertyAccessExpression;\n factoryName: string;\n edits: IEdit[];\n rewrittenOwners: Set<ts.Node>;\n report: (node: ts.Node, reason: string) => void;\n }): void {\n const { typescript, sourceFile, call, owner, factoryName, edits, rewrittenOwners, report } =\n opts;\n const scope = LoggerScopeRewriter.scopeOf({ typescript, sourceFile, call });\n\n if ('reason' in scope) {\n report(call, scope.reason);\n return;\n }\n\n // `<namespace>.ApplicationLogger` keeps its namespace: `helpers.LoggerFactory.getLogger([...])`.\n const ownerText = typescript.isIdentifier(owner)\n ? factoryName\n : `${owner.expression.getText(sourceFile)}.${LoggerScopeRewriter.TARGET_NAME}`;\n\n edits.push({\n start: call.getStart(sourceFile),\n end: call.getEnd(),\n text: `${ownerText}.getLogger([${scope.text}])`,\n });\n rewrittenOwners.add(owner);\n }\n\n /**\n * `LoggerFactory` is added to the import that carried `ApplicationLogger`, and `ApplicationLogger` leaves it when no\n * other use of it remains.\n */\n private static planImports(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n locals: ILocals;\n rewrittenOwners: Set<ts.Node>;\n /** `LoggerFactory` is already imported from a listed module (maybe under another name). */\n hasFactory: boolean;\n edits: IEdit[];\n }): void {\n const { typescript, sourceFile, locals, rewrittenOwners, hasFactory, edits } = opts;\n\n for (const [local, specifier] of locals.named) {\n const used = LoggerScopeRewriter.countReferences({ typescript, sourceFile, name: local });\n const replaced = [...rewrittenOwners].filter(\n (owner) => typescript.isIdentifier(owner) && owner.text === local,\n ).length;\n const declaration = specifier.parent.parent.parent;\n const imported = declaration.importClause?.namedBindings;\n\n if (!imported || !typescript.isNamedImports(imported)) {\n continue;\n }\n\n const hasTarget = hasFactory;\n const isLeft = used - replaced > 1; // the import specifier itself is one reference\n\n if (isLeft) {\n if (!hasTarget) {\n edits.push({\n start: specifier.getEnd(),\n end: specifier.getEnd(),\n text: `, ${LoggerScopeRewriter.TARGET_NAME}`,\n });\n }\n continue;\n }\n\n if (hasTarget) {\n LoggerScopeRewriter.dropSpecifier({\n sourceFile,\n specifier,\n elements: imported.elements,\n edits,\n });\n } else {\n edits.push({\n start: specifier.getStart(sourceFile),\n end: specifier.getEnd(),\n text: LoggerScopeRewriter.TARGET_NAME,\n });\n }\n }\n }\n\n /** A re-export of the removed class from a listed module, or a type-only import of it, is listed. */\n private static reportDeclarations(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n report: (node: ts.Node, reason: string) => void;\n }): void {\n const { typescript, sourceFile, report } = opts;\n const named = (element: { propertyName?: ts.ModuleExportName; name: ts.ModuleExportName }) =>\n (element.propertyName ?? element.name).text === LoggerScopeRewriter.CLASS_NAME;\n\n for (const statement of sourceFile.statements) {\n if (\n typescript.isExportDeclaration(statement) &&\n statement.moduleSpecifier &&\n typescript.isStringLiteral(statement.moduleSpecifier) &&\n LoggerScopeRewriter.MODULES.includes(statement.moduleSpecifier.text) &&\n statement.exportClause &&\n typescript.isNamedExports(statement.exportClause) &&\n statement.exportClause.elements.some(named)\n ) {\n report(\n statement,\n '`ApplicationLogger` no longer exists: this re-export has no replacement, remove it (`LoggerFactory` is the class)',\n );\n }\n\n if (\n typescript.isImportDeclaration(statement) &&\n typescript.isStringLiteral(statement.moduleSpecifier) &&\n LoggerScopeRewriter.MODULES.includes(statement.moduleSpecifier.text)\n ) {\n const bindings = statement.importClause?.namedBindings;\n const isNamed = bindings && typescript.isNamedImports(bindings);\n const isTypeImport = statement.importClause?.isTypeOnly === true;\n const typed =\n isNamed &&\n bindings.elements.some(\n (element) => named(element) && (isTypeImport || element.isTypeOnly),\n );\n\n if (typed) {\n report(\n statement,\n '`ApplicationLogger` no longer exists: this type-only import has no replacement, use the type of what `LoggerFactory.getLogger` returns (`ILogger`)',\n );\n }\n }\n }\n }\n\n /** Where `LoggerFactory` stands in the file: imported from a listed module (under which local name), or a name clash. */\n private static findFactory(opts: { typescript: TTypeScript; sourceFile: ts.SourceFile }): {\n local?: string;\n collision?: ts.Node;\n } {\n const { typescript, sourceFile } = opts;\n const found: { local?: string; collision?: ts.Node } = {};\n\n for (const statement of sourceFile.statements) {\n if (typescript.isImportDeclaration(statement)) {\n const bindings = statement.importClause?.namedBindings;\n if (!bindings || !typescript.isNamedImports(bindings)) {\n continue;\n }\n\n for (const element of bindings.elements) {\n if ((element.propertyName ?? element.name).text !== LoggerScopeRewriter.TARGET_NAME) {\n continue;\n }\n\n const isListed =\n typescript.isStringLiteral(statement.moduleSpecifier) &&\n LoggerScopeRewriter.MODULES.includes(statement.moduleSpecifier.text);\n if (isListed) {\n found.local = element.name.text;\n } else {\n found.collision = element;\n }\n }\n continue;\n }\n\n const isNamedDeclaration =\n (typescript.isClassDeclaration(statement) ||\n typescript.isFunctionDeclaration(statement) ||\n typescript.isInterfaceDeclaration(statement) ||\n typescript.isTypeAliasDeclaration(statement)) &&\n statement.name?.text === LoggerScopeRewriter.TARGET_NAME;\n const isNamedVariable =\n typescript.isVariableStatement(statement) &&\n statement.declarationList.declarations.some(\n (declaration) =>\n typescript.isIdentifier(declaration.name) &&\n declaration.name.text === LoggerScopeRewriter.TARGET_NAME,\n );\n\n if (isNamedDeclaration || isNamedVariable) {\n found.collision = statement;\n }\n }\n\n return found;\n }\n\n /** Every use of the removed class that is not a call this run rewrote (a type, a value, an export) is listed. */\n private static reportLeftovers(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n locals: ILocals;\n rewrittenOwners: Set<ts.Node>;\n report: (node: ts.Node, reason: string) => void;\n }): void {\n const { typescript, sourceFile, locals, rewrittenOwners, report } = opts;\n\n const visit = (node: ts.Node): void => {\n if (typescript.isIdentifier(node) && !rewrittenOwners.has(node)) {\n const parent = node.parent;\n const isImportName = typescript.isImportSpecifier(parent);\n const isProperty = typescript.isPropertyAccessExpression(parent) && parent.name === node;\n const isLocal = locals.named.has(node.text);\n\n if (isLocal && !isImportName && !isProperty) {\n report(\n node,\n '`ApplicationLogger` no longer exists and this use is not a call the codemod rewrites: change it by hand (`LoggerFactory` is the class, `ILogger` the type of a logger)',\n );\n }\n }\n\n if (\n typescript.isPropertyAccessExpression(node) &&\n node.name.text === LoggerScopeRewriter.CLASS_NAME &&\n typescript.isIdentifier(node.expression) &&\n locals.namespaces.has(node.expression.text) &&\n !rewrittenOwners.has(node)\n ) {\n report(\n node,\n '`ApplicationLogger` no longer exists and this use is not a call the codemod rewrites: change it by hand',\n );\n }\n\n typescript.forEachChild(node, visit);\n };\n visit(sourceFile);\n }\n\n /** How many identifiers named `name` the file holds, the import specifier included. */\n private static countReferences(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n name: string;\n }): number {\n const { typescript, sourceFile, name } = opts;\n let count = 0;\n\n const visit = (node: ts.Node): void => {\n if (typescript.isIdentifier(node) && node.text === name) {\n // A property name (`x.name`) is not a reference to the import.\n const parent = node.parent;\n const isProperty = typescript.isPropertyAccessExpression(parent) && parent.name === node;\n if (!isProperty) {\n count += 1;\n }\n }\n typescript.forEachChild(node, visit);\n };\n visit(sourceFile);\n\n return count;\n }\n\n /** Removes one specifier from a named import together with its comma. */\n private static dropSpecifier(opts: {\n sourceFile: ts.SourceFile;\n specifier: ts.ImportSpecifier;\n elements: ts.NodeArray<ts.ImportSpecifier>;\n edits: IEdit[];\n }): void {\n const { sourceFile, specifier, elements, edits } = opts;\n const index = elements.indexOf(specifier);\n const next = elements[index + 1];\n const previous = elements[index - 1];\n\n if (next) {\n edits.push({\n start: specifier.getStart(sourceFile),\n end: next.getStart(sourceFile),\n text: '',\n });\n } else if (previous) {\n edits.push({ start: previous.getEnd(), end: specifier.getEnd(), text: '' });\n } else {\n edits.push({ start: specifier.getStart(sourceFile), end: specifier.getEnd(), text: '' });\n }\n }\n}\n"]}
@@ -1,7 +1,9 @@
1
1
  import type { INamespaceMapping } from '../mapping';
2
2
  /**
3
- * The functions of `@venizia/ignis` that moved into a class. An entry with `keepsOptions` is a
4
- * function that already took ONE options object: its class method takes the same one.
3
+ * The functions of `@venizia/ignis` that moved into a class. An entry with `keepsOptions` keeps its
4
+ * arguments and only the callee changes: the function already took ONE options object and its class
5
+ * method takes the same one, or (the two mail type guards) the parameter stays positional because a
6
+ * type predicate narrows its own parameter.
5
7
  */
6
8
  export declare const CORE_SERVER_MAPPINGS: ReadonlyArray<INamespaceMapping>;
7
9
  //# sourceMappingURL=core-server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"core-server.d.ts","sourceRoot":"","sources":["../../../../../src/cli/codemod/namespace-functions/mappings/core-server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD;;;GAGG;AACH,eAAO,MAAM,oBAAoB,EAAE,aAAa,CAAC,iBAAiB,CAyJjE,CAAC"}
1
+ {"version":3,"file":"core-server.d.ts","sourceRoot":"","sources":["../../../../../src/cli/codemod/namespace-functions/mappings/core-server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,EAAE,aAAa,CAAC,iBAAiB,CAyKjE,CAAC"}