@venizia/dev-configs 0.5.0-4 → 0.5.0-6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/codemod/any-aliases.d.ts +1 -1
- package/dist/cli/codemod/any-aliases.js +2 -2
- package/dist/cli/codemod/any-aliases.js.map +1 -1
- package/dist/cli/codemod/async-style.d.ts +1 -1
- package/dist/cli/codemod/async-style.js +2 -2
- package/dist/cli/codemod/async-style.js.map +1 -1
- package/dist/cli/codemod/binding-keys.d.ts +1 -1
- package/dist/cli/codemod/binding-keys.js +27 -3
- package/dist/cli/codemod/binding-keys.js.map +1 -1
- package/dist/cli/codemod/class-renames.d.ts +1 -1
- package/dist/cli/codemod/class-renames.js +2 -3
- package/dist/cli/codemod/class-renames.js.map +1 -1
- package/dist/cli/codemod/connector-imports.d.ts +1 -1
- package/dist/cli/codemod/connector-imports.js +2 -2
- package/dist/cli/codemod/connector-imports.js.map +1 -1
- package/dist/cli/codemod/const-class-sets.d.ts +55 -0
- package/dist/cli/codemod/const-class-sets.js +219 -0
- package/dist/cli/codemod/const-class-sets.js.map +1 -0
- package/dist/cli/codemod/const-classes.d.ts +21 -3
- package/dist/cli/codemod/const-classes.js +135 -21
- package/dist/cli/codemod/const-classes.js.map +1 -1
- package/dist/cli/codemod/env-get.d.ts +1 -1
- package/dist/cli/codemod/env-get.js +2 -2
- package/dist/cli/codemod/env-get.js.map +1 -1
- package/dist/cli/codemod/files.d.ts +4 -2
- package/dist/cli/codemod/files.js +5 -6
- package/dist/cli/codemod/files.js.map +1 -1
- package/dist/cli/codemod/namespace-functions/index.d.ts +1 -1
- package/dist/cli/codemod/namespace-functions/index.js +2 -2
- package/dist/cli/codemod/namespace-functions/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -26,7 +26,7 @@ export declare class AnyAliases {
|
|
|
26
26
|
}
|
|
27
27
|
/** `devz codemod any-aliases`: reads the sources, prints what changes, writes with `--write`. */
|
|
28
28
|
export declare class AnyAliasesCommand {
|
|
29
|
-
static readonly USAGE = "Usage: devz codemod any-aliases [paths...] [--strict] [--write [--all] | --check]\n\nReplaces the AnyType and AnyObject aliases the @venizia/ignis-helpers and @venizia/ignis-inversion\nreleases deleted, by what they stood for, so a bump changes no type in your code:\n\n AnyType becomes any\n AnyObject becomes Record<string | symbol | number, any>\n\nin every file that imports them from @venizia/ignis, @venizia/ignis-helpers, @venizia/ignis-inversion,\n@venizia/ardor or @venizia/ardor-kernel (ARDOR re-exported the same two names; a sub-path such as\n@venizia/ignis-helpers/common too), whatever local name the import gives them\n(import { AnyType as Loose } ...). The names leave the import, and an import left empty is dropped.\n\nWith --strict it writes the tighter types instead of the default ones, for code that wants to stop using any:\n\n AnyType becomes unknown\n AnyObject becomes Record<string, unknown>\n\n--strict surfaces errors that any hid: an unknown value cannot be read, or passed as a narrower type, without a\ncheck; an interface-typed value is not assignable to Record<string, unknown> (an interface has no implicit\nindex signature); and a symbol key on a former AnyObject fails (TS2538). Declare the shape as a type\nalias, spread the value, or narrow it; run your typecheck after it.\n--strict acts only on the alias names: a file already rewritten to any is left alone, so run it instead of\nthe default run, on a path at a time, and tighten the rest by hand.\n\nIt lists, and leaves alone:\n manual a re-export (export { AnyType }, export type { AnyObject } from ...), an import(\"...\").AnyType\n type, and AnyType in a heritage clause (extends any and extends unknown are not valid)\n local a same-named type the file declares (in any scope: a namespace, a function, a block, a type\n parameter) or imports from somewhere else; a use that such a declaration shadows is left alone\n\nA name used in a heritage clause keeps its import, and so keeps all its other uses in that file: once you\nreplace the heritage use by hand, run the codemod again and the other uses are rewritten.\n\nIt reads TypeScript files (.ts, .tsx, .mts, .cts) and is idempotent: a second run changes nothing.\n\n --strict write unknown and Record<string, unknown> instead of any\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 case is left (for CI)\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\ngit knows, and --write refuses a file with local changes: commit or
|
|
29
|
+
static readonly USAGE = "Usage: devz codemod any-aliases [paths...] [--strict] [--write [--all] | --check]\n\nReplaces the AnyType and AnyObject aliases the @venizia/ignis-helpers and @venizia/ignis-inversion\nreleases deleted, by what they stood for, so a bump changes no type in your code:\n\n AnyType becomes any\n AnyObject becomes Record<string | symbol | number, any>\n\nin every file that imports them from @venizia/ignis, @venizia/ignis-helpers, @venizia/ignis-inversion,\n@venizia/ardor or @venizia/ardor-kernel (ARDOR re-exported the same two names; a sub-path such as\n@venizia/ignis-helpers/common too), whatever local name the import gives them\n(import { AnyType as Loose } ...). The names leave the import, and an import left empty is dropped.\n\nWith --strict it writes the tighter types instead of the default ones, for code that wants to stop using any:\n\n AnyType becomes unknown\n AnyObject becomes Record<string, unknown>\n\n--strict surfaces errors that any hid: an unknown value cannot be read, or passed as a narrower type, without a\ncheck; an interface-typed value is not assignable to Record<string, unknown> (an interface has no implicit\nindex signature); and a symbol key on a former AnyObject fails (TS2538). Declare the shape as a type\nalias, spread the value, or narrow it; run your typecheck after it.\n--strict acts only on the alias names: a file already rewritten to any is left alone, so run it instead of\nthe default run, on a path at a time, and tighten the rest by hand.\n\nIt lists, and leaves alone:\n manual a re-export (export { AnyType }, export type { AnyObject } from ...), an import(\"...\").AnyType\n type, and AnyType in a heritage clause (extends any and extends unknown are not valid)\n local a same-named type the file declares (in any scope: a namespace, a function, a block, a type\n parameter) or imports from somewhere else; a use that such a declaration shadows is left alone\n\nA name used in a heritage clause keeps its import, and so keeps all its other uses in that file: once you\nreplace the heritage use by hand, run the codemod again and the other uses are rewritten.\n\nIt reads TypeScript files (.ts, .tsx, .mts, .cts) and is idempotent: a second run changes nothing.\n\n --strict write unknown and Record<string, unknown> instead of any\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 case is left (for CI)\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\ngit knows, and --write refuses a file with local changes: commit, stash or \"git add\" it first, so git can undo it.\nThere is no --reverse: a downgrade restores the files from git.";
|
|
30
30
|
static run(opts: {
|
|
31
31
|
root: string;
|
|
32
32
|
args: string[];
|
|
@@ -47,7 +47,7 @@ It reads TypeScript files (.ts, .tsx, .mts, .cts) and is idempotent: a second ru
|
|
|
47
47
|
--help print this text and exit
|
|
48
48
|
|
|
49
49
|
With no flag it lists what would change and writes nothing. Inside a git repository it reads the files
|
|
50
|
-
git knows, and --write refuses a file with local changes: commit or
|
|
50
|
+
git knows, and --write refuses a file with local changes: commit, stash or "git add" it first, so git can undo it.
|
|
51
51
|
There is no --reverse: a downgrade restores the files from git.`;
|
|
52
52
|
/** A usage error: nothing was read or written. */
|
|
53
53
|
const USAGE_ERROR_CODE = 2;
|
|
@@ -518,7 +518,7 @@ class AnyAliasesCommand {
|
|
|
518
518
|
}
|
|
519
519
|
if (dirty?.has(file)) {
|
|
520
520
|
refusedCount += 1;
|
|
521
|
-
console.warn(`refused ${shown} has local changes (commit or
|
|
521
|
+
console.warn(`refused ${shown} has local changes (commit, stash or "git add" them, then run again)`);
|
|
522
522
|
continue;
|
|
523
523
|
}
|
|
524
524
|
changedCount += 1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"any-aliases.js","sourceRoot":"","sources":["../../../src/cli/codemod/any-aliases.ts"],"names":[],"mappings":";;;AAAA,qCAAsD;AACtD,yCAA8C;AAC9C,mCAAuC;AAEvC,MAAM,KAAK,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gEA4CkD,CAAC;AAEjE,kDAAkD;AAClD,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAE3B;;;GAGG;AACH,MAAM,cAAc,GAAG;IACrB,gBAAgB;IAChB,wBAAwB;IACxB,0BAA0B;IAC1B,gBAAgB;IAChB,uBAAuB;CACxB,CAAC;AAEF,MAAM,YAAY,GAAG,IAAI,MAAM,CAC7B,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C,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAClE,CAAC;;AA3IH,8CA4IC","sourcesContent":["import { readFileSync, writeFileSync } from 'node:fs';\nimport { relative, resolve } from 'node:path';\nimport { CodemodFiles } from './files';\n\nconst USAGE = `Usage: devz codemod any-aliases [paths...] [--strict] [--write [--all] | --check]\n\nReplaces the AnyType and AnyObject aliases the @venizia/ignis-helpers and @venizia/ignis-inversion\nreleases deleted, by what they stood for, so a bump changes no type in your code:\n\n AnyType becomes any\n AnyObject becomes Record<string | symbol | number, any>\n\nin every file that imports them from @venizia/ignis, @venizia/ignis-helpers, @venizia/ignis-inversion,\n@venizia/ardor or @venizia/ardor-kernel (ARDOR re-exported the same two names; a sub-path such as\n@venizia/ignis-helpers/common too), whatever local name the import gives them\n(import { AnyType as Loose } ...). The names leave the import, and an import left empty is dropped.\n\nWith --strict it writes the tighter types instead of the default ones, for code that wants to stop using any:\n\n AnyType becomes unknown\n AnyObject becomes Record<string, unknown>\n\n--strict surfaces errors that any hid: an unknown value cannot be read, or passed as a narrower type, without a\ncheck; an interface-typed value is not assignable to Record<string, unknown> (an interface has no implicit\nindex signature); and a symbol key on a former AnyObject fails (TS2538). Declare the shape as a type\nalias, spread the value, or narrow it; run your typecheck after it.\n--strict acts only on the alias names: a file already rewritten to any is left alone, so run it instead of\nthe default run, on a path at a time, and tighten the rest by hand.\n\nIt lists, and leaves alone:\n manual a re-export (export { AnyType }, export type { AnyObject } from ...), an import(\"...\").AnyType\n type, and AnyType in a heritage clause (extends any and extends unknown are not valid)\n local a same-named type the file declares (in any scope: a namespace, a function, a block, a type\n parameter) or imports from somewhere else; a use that such a declaration shadows is left alone\n\nA name used in a heritage clause keeps its import, and so keeps all its other uses in that file: once you\nreplace the heritage use by hand, run the codemod again and the other uses are rewritten.\n\nIt reads TypeScript files (.ts, .tsx, .mts, .cts) and is idempotent: a second run changes nothing.\n\n --strict write unknown and Record<string, unknown> instead of any\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 case is left (for CI)\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\ngit knows, and --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/**\n * The packages the aliases were exported from, each with or without a sub-path: the IGNIS root package, helpers and\n * inversion, and the ARDOR packages that re-exported the same two names (same names, same meaning).\n */\nconst ALIAS_PACKAGES = [\n '@venizia/ignis',\n '@venizia/ignis-helpers',\n '@venizia/ignis-inversion',\n '@venizia/ardor',\n '@venizia/ardor-kernel',\n];\n\nconst ALIAS_MODULE = new RegExp(\n `^(?:${ALIAS_PACKAGES.map((name) => name.replace(/[/.-]/g, '\\\\$&')).join('|')})(?:/.*)?$`,\n);\n\n/** The deleted aliases and what each becomes by default: what they stood for, so the types of the code do not change. */\nconst REPLACEMENTS = new Map<string, string>([\n ['AnyType', 'any'],\n ['AnyObject', 'Record<string | symbol | number, any>'],\n]);\n\n/** With `--strict`: the tighter types, for code that wants to stop using `any`. */\nconst STRICT_REPLACEMENTS = new Map<string, string>([\n ['AnyType', 'unknown'],\n ['AnyObject', 'Record<string, unknown>'],\n]);\n\n/** What `AnyType` becomes in either mode: neither `extends any` nor `extends unknown` is valid, so a heritage use is left. */\nconst HERITAGE_BLOCKED = new Set(['any', 'unknown']);\n\nclass AnyAliasesFlags {\n static readonly WRITE = '--write';\n static readonly ALL = '--all';\n static readonly CHECK = '--check';\n static readonly STRICT = '--strict';\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.STRICT,\n this.HELP,\n this.HELP_SHORT,\n ]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\nexport interface IAnyAliasesResult {\n output: string;\n changed: boolean;\n /** How many type references were rewritten. */\n rewritten: number;\n /** What the codemod cannot place: file line (1-based) and why. */\n manual: Array<{ line: number; reason: string }>;\n /** Same-named types that are not the IGNIS aliases: file line (1-based) and the name. */\n local: Array<{ line: number; name: string }>;\n}\n\n/** Replaces the deleted `AnyType` and `AnyObject` aliases by what they stood for (`any`), or with `isStrict` by the tighter types. */\nexport class AnyAliases {\n static rewrite(opts: {\n typescript: typeof import('typescript');\n fileName: string;\n source: string;\n /** Write `unknown` and `Record<string, unknown>` instead of `any`. */\n isStrict?: boolean;\n }): IAnyAliasesResult {\n const { typescript: ts, fileName, source, isStrict = false } = opts;\n const replacements = isStrict ? STRICT_REPLACEMENTS : REPLACEMENTS;\n const language = fileName.endsWith('.tsx') ? ts.ScriptKind.TSX : ts.ScriptKind.TS;\n const file = ts.createSourceFile(fileName, source, ts.ScriptTarget.Latest, true, language);\n const edits: Array<{ start: number; end: number; text: string }> = [];\n const manual: Array<{ line: number; reason: string }> = [];\n const local: Array<{ line: number; name: string }> = [];\n let rewritten = 0;\n\n const lineOf = (node: import('typescript').Node): number =>\n file.getLineAndCharacterOfPosition(node.getStart(file)).line + 1;\n\n const addReplacement = (node: import('typescript').Node, replacement: string): void => {\n edits.push({ start: node.getStart(file), end: node.getEnd(), text: replacement });\n rewritten += 1;\n };\n\n // The local names bound to an alias (name -> replacement), the namespace imports of a module that held them\n // and the names the file exports.\n const aliasNames = new Map<string, string>();\n const namespaces = new Set<string>();\n const exportedNames = new Set<string>();\n\n /**\n * Whether a declaration in a scope that encloses `node` (below the file: a namespace, a function, a block, a\n * type parameter) binds `name`, so the name there is not the file-level import. `isNamespace` is what the use needs:\n * a namespace (the left side of `H.AnyType`) rather than a type.\n */\n const isShadowed = (\n node: import('typescript').Node,\n name: string,\n isNamespace: boolean,\n ): boolean => {\n const hasInfer = (type: import('typescript').Node): boolean =>\n (ts.isInferTypeNode(type) && type.typeParameter.name.text === name) ||\n ts.forEachChild(type, (child) => (hasInfer(child) ? true : undefined)) === true;\n\n // `child` is the node the walk came from: an `infer` name is bound in the true branch of its conditional type only.\n let child: import('typescript').Node = node;\n\n for (let scope: import('typescript').Node | undefined = node.parent; scope !== undefined;) {\n if (ts.isSourceFile(scope)) {\n return false;\n }\n\n if (!isNamespace) {\n if (\n (ts.isFunctionLike(scope) ||\n ts.isClassLike(scope) ||\n ts.isInterfaceDeclaration(scope) ||\n ts.isTypeAliasDeclaration(scope)) &&\n scope.typeParameters?.some((parameter) => parameter.name.text === name)\n ) {\n return true;\n }\n\n if (ts.isMappedTypeNode(scope) && scope.typeParameter.name.text === name) {\n return true;\n }\n\n if (\n ts.isConditionalTypeNode(scope) &&\n child === scope.trueType &&\n hasInfer(scope.extendsType)\n ) {\n return true;\n }\n }\n\n if (\n ts.isBlock(scope) ||\n ts.isModuleBlock(scope) ||\n ts.isCaseClause(scope) ||\n ts.isDefaultClause(scope)\n ) {\n for (const statement of scope.statements) {\n let declared: import('typescript').Node | undefined;\n\n if (\n ts.isTypeAliasDeclaration(statement) ||\n ts.isInterfaceDeclaration(statement) ||\n ts.isClassDeclaration(statement)\n ) {\n declared = !isNamespace ? statement.name : undefined;\n } else if (ts.isEnumDeclaration(statement) || ts.isImportEqualsDeclaration(statement)) {\n declared = statement.name;\n } else if (ts.isModuleDeclaration(statement)) {\n declared = isNamespace ? statement.name : undefined;\n }\n\n if (declared !== undefined && ts.isIdentifier(declared) && declared.text === name) {\n return true;\n }\n }\n }\n\n child = scope;\n scope = scope.parent;\n }\n\n return false;\n };\n\n // `export { AnyType }` keeps the import alive: that name is left to the user (reported below).\n for (const statement of file.statements) {\n if (\n ts.isExportDeclaration(statement) &&\n statement.moduleSpecifier === undefined &&\n statement.exportClause !== undefined &&\n ts.isNamedExports(statement.exportClause)\n ) {\n for (const element of statement.exportClause.elements) {\n exportedNames.add((element.propertyName ?? element.name).text);\n }\n }\n }\n\n // `extends any`, `extends unknown` and `implements` of either are not valid TypeScript: an alias used in a heritage\n // clause whose replacement is `any` or `unknown` is left (import and references) and reported where it is used.\n const heritageBlocked = new Set<string>();\n const importedReplacement = new Map<string, string>();\n\n for (const statement of file.statements) {\n if (\n ts.isImportDeclaration(statement) &&\n ts.isStringLiteral(statement.moduleSpecifier) &&\n ALIAS_MODULE.test(statement.moduleSpecifier.text) &&\n statement.importClause?.namedBindings !== undefined &&\n ts.isNamedImports(statement.importClause.namedBindings)\n ) {\n for (const element of statement.importClause.namedBindings.elements) {\n const replacement = replacements.get((element.propertyName ?? element.name).text);\n\n if (replacement !== undefined) {\n importedReplacement.set(element.name.text, replacement);\n }\n }\n }\n }\n\n const scanHeritage = (node: import('typescript').Node): void => {\n if (\n ts.isExpressionWithTypeArguments(node) &&\n ts.isIdentifier(node.expression) &&\n HERITAGE_BLOCKED.has(importedReplacement.get(node.expression.text) ?? '') &&\n !isShadowed(node, node.expression.text, false)\n ) {\n heritageBlocked.add(node.expression.text);\n }\n\n ts.forEachChild(node, scanHeritage);\n };\n\n scanHeritage(file);\n\n const removedRanges: Array<{ start: number; end: number }> = [];\n\n // Imports: which local names are the aliases, and how each import is rewritten.\n for (const statement of file.statements) {\n if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)) {\n continue;\n }\n\n const clause = statement.importClause;\n const isAliasSource = ALIAS_MODULE.test(statement.moduleSpecifier.text);\n\n if (clause === undefined) {\n continue;\n }\n\n if (clause.namedBindings !== undefined && ts.isNamespaceImport(clause.namedBindings)) {\n if (isAliasSource) {\n namespaces.add(clause.namedBindings.name.text);\n }\n\n continue;\n }\n\n if (clause.namedBindings === undefined || !ts.isNamedImports(clause.namedBindings)) {\n if (clause.name !== undefined && replacements.has(clause.name.text) && !isAliasSource) {\n local.push({ line: lineOf(clause.name), name: clause.name.text });\n }\n\n continue;\n }\n\n const named = clause.namedBindings;\n const kept: Array<{ text: string; trailing: string }> = [];\n\n // A comment that follows an element on its line (after its comma) belongs to that element: it goes with it\n // when the element is removed, and it is not part of the next element's leading comments.\n const trailings = named.elements.map((element) => {\n const match = /^[ \\t]*,?[ \\t]*(\\/\\/[^\\r\\n]*|\\/\\*[^\\r\\n]*?\\*\\/)/.exec(\n source.slice(element.getEnd()),\n );\n\n return { comment: match?.[1] ?? '', end: element.getEnd() + (match?.[0].length ?? 0) };\n });\n\n /** An element as it is kept: its text with its own leading comments, and the comment that follows it on its line. */\n const keep = (element: import('typescript').ImportSpecifier, index: number) => {\n const previous = trailings[index - 1];\n const from =\n previous === undefined || previous.comment === ''\n ? element.getFullStart()\n : Math.max(element.getFullStart(), previous.end);\n\n kept.push({\n text: source.slice(from, element.getEnd()).trim(),\n trailing: trailings[index]?.comment ?? '',\n });\n };\n\n let removed = 0;\n\n for (const [index, element] of named.elements.entries()) {\n const imported = (element.propertyName ?? element.name).text;\n const localName = element.name.text;\n const replacement = replacements.get(imported);\n\n if (replacement === undefined) {\n keep(element, index);\n\n continue;\n }\n\n if (!isAliasSource) {\n keep(element, index);\n local.push({ line: lineOf(element), name: localName });\n\n continue;\n }\n\n if (exportedNames.has(localName)) {\n keep(element, index);\n manual.push({\n line: lineOf(element),\n reason: `${localName}${localName === imported ? '' : ` (the alias ${imported})`} is re-exported by this file: the alias is gone, export the type you meant`,\n });\n\n continue;\n }\n\n if (heritageBlocked.has(localName)) {\n keep(element, index);\n\n continue;\n }\n\n aliasNames.set(localName, replacement);\n removed += 1;\n }\n\n if (removed === 0) {\n continue;\n }\n\n if (kept.length === 0 && clause.name === undefined) {\n const start = statement.getStart(file);\n let end = statement.getEnd();\n\n if (source.startsWith('\\r\\n', end)) {\n end += 2;\n } else if (source[end] === '\\n') {\n end += 1;\n }\n\n // A blank line that only separated this import from the next code (or from the top of the file) goes with it.\n // The imports removed before this one are not there any more: a file that starts with a removed import\n // must not start with a blank line.\n let before = source.slice(0, start);\n\n for (const range of [...removedRanges].reverse()) {\n before = before.slice(0, range.start) + before.slice(range.end);\n }\n\n const isOnlyLeading = before.trim() === '' || /\\n\\s*\\n$/.test(before);\n const blank = /^[ \\t]*\\r?\\n/.exec(source.slice(end));\n\n if (isOnlyLeading && blank !== null) {\n end += blank[0].length;\n }\n\n edits.push({ start, end, text: '' });\n removedRanges.push({ start, end });\n } else if (kept.length === 0 && clause.name !== undefined) {\n // A default import stays: `import Default, { AnyType } from ...` -> `import Default from ...`.\n edits.push({ start: clause.name.getEnd(), end: named.getEnd(), text: '' });\n } else {\n const isMultiline = /\\r?\\n/.test(source.slice(named.getStart(file), named.getEnd()));\n const hasTrailingComma = named.elements.hasTrailingComma;\n const lines = kept.map((item, index) => {\n const comma = index < kept.length - 1 || hasTrailingComma ? ',' : '';\n\n return ` ${item.text}${comma}${item.trailing === '' ? '' : ` ${item.trailing}`}`;\n });\n const text = isMultiline\n ? `{\\n${lines.join('\\n')}\\n}`\n : `{ ${kept.map((item) => item.text).join(', ')} }`;\n\n edits.push({ start: named.getStart(file), end: named.getEnd(), text });\n }\n }\n\n // Declarations of a same-named type that is not an import of the aliases.\n for (const statement of file.statements) {\n if (\n (ts.isTypeAliasDeclaration(statement) ||\n ts.isInterfaceDeclaration(statement) ||\n ts.isClassDeclaration(statement) ||\n ts.isEnumDeclaration(statement)) &&\n statement.name !== undefined &&\n replacements.has(statement.name.text) &&\n !aliasNames.has(statement.name.text)\n ) {\n local.push({ line: lineOf(statement.name), name: statement.name.text });\n }\n }\n\n const visit = (node: import('typescript').Node): void => {\n // A same-named type declared below the file level (a namespace, a function, a block, a type parameter) is a\n // different type: it is listed, and the uses it shadows are left alone (see isShadowed).\n if (\n (ts.isTypeAliasDeclaration(node) ||\n ts.isInterfaceDeclaration(node) ||\n ts.isClassDeclaration(node) ||\n ts.isEnumDeclaration(node) ||\n ts.isTypeParameterDeclaration(node)) &&\n node.name !== undefined &&\n replacements.has(node.name.text) &&\n !ts.isSourceFile(node.parent)\n ) {\n local.push({ line: lineOf(node.name), name: node.name.text });\n }\n\n if (ts.isTypeReferenceNode(node) && node.typeArguments === undefined) {\n const { typeName } = node;\n const byName =\n ts.isIdentifier(typeName) && !isShadowed(node, typeName.text, false)\n ? aliasNames.get(typeName.text)\n : undefined;\n const byNamespace =\n ts.isQualifiedName(typeName) &&\n ts.isIdentifier(typeName.left) &&\n namespaces.has(typeName.left.text) &&\n !isShadowed(node, typeName.left.text, true)\n ? replacements.get(typeName.right.text)\n : undefined;\n const replacement = byName ?? byNamespace;\n\n if (replacement !== undefined) {\n addReplacement(node, replacement);\n\n return;\n }\n }\n\n if (ts.isExpressionWithTypeArguments(node) && node.typeArguments === undefined) {\n const { expression } = node;\n const byName =\n ts.isIdentifier(expression) && !isShadowed(node, expression.text, false)\n ? aliasNames.get(expression.text)\n : undefined;\n const byNamespace =\n ts.isPropertyAccessExpression(expression) &&\n ts.isIdentifier(expression.expression) &&\n namespaces.has(expression.expression.text) &&\n !isShadowed(node, expression.expression.text, true)\n ? replacements.get(expression.name.text)\n : undefined;\n const replacement = byName ?? byNamespace;\n\n if (replacement !== undefined && HERITAGE_BLOCKED.has(replacement)) {\n manual.push({\n line: lineOf(node),\n reason: `${node.getText(file)} in a heritage clause: extends any, extends unknown and implements are not valid, name the members you mean`,\n });\n\n return;\n }\n\n if (replacement !== undefined) {\n addReplacement(node, replacement);\n\n return;\n }\n\n if (\n ts.isIdentifier(expression) &&\n heritageBlocked.has(expression.text) &&\n !isShadowed(node, expression.text, false)\n ) {\n manual.push({\n line: lineOf(node),\n reason: `${expression.text} in a heritage clause: extends any, extends unknown and implements are not valid, name the members you mean`,\n });\n\n return;\n }\n }\n\n if (\n ts.isImportTypeNode(node) &&\n node.qualifier !== undefined &&\n ts.isIdentifier(node.qualifier) &&\n replacements.has(node.qualifier.text) &&\n ts.isLiteralTypeNode(node.argument) &&\n ts.isStringLiteral(node.argument.literal) &&\n ALIAS_MODULE.test(node.argument.literal.text)\n ) {\n manual.push({\n line: lineOf(node),\n reason: `import(\"${node.argument.literal.text}\").${node.qualifier.text}: replace the whole type by hand`,\n });\n }\n\n if (\n ts.isExportDeclaration(node) &&\n node.exportClause !== undefined &&\n ts.isNamedExports(node.exportClause)\n ) {\n const isIgnisSource =\n node.moduleSpecifier !== undefined &&\n ts.isStringLiteral(node.moduleSpecifier) &&\n ALIAS_MODULE.test(node.moduleSpecifier.text);\n\n for (const element of node.exportClause.elements) {\n const exported = (element.propertyName ?? element.name).text;\n\n if (replacements.has(exported) && isIgnisSource) {\n manual.push({\n line: lineOf(element),\n reason: `a re-export of ${exported}: the alias is gone, export the type you meant`,\n });\n }\n }\n }\n\n ts.forEachChild(node, visit);\n };\n\n visit(file);\n\n if (edits.length === 0) {\n return { output: source, changed: false, rewritten: 0, manual, local };\n }\n\n let output = source;\n\n for (const edit of [...edits].sort((left, right) => right.start - left.start)) {\n output = output.slice(0, edit.start) + edit.text + output.slice(edit.end);\n }\n\n return { output, changed: output !== source, rewritten, manual, local };\n }\n}\n\n/** `devz codemod any-aliases`: reads the sources, prints what changes, writes with `--write`. */\nexport class AnyAliasesCommand {\n static readonly USAGE = USAGE;\n\n static async run(opts: { root: string; args: string[] }): Promise<number> {\n const { root, args } = opts;\n\n if (args.includes(AnyAliasesFlags.HELP) || args.includes(AnyAliasesFlags.HELP_SHORT)) {\n console.log(USAGE);\n\n return 0;\n }\n\n const flags = args.filter((argument) => argument.startsWith('-'));\n const paths = args.filter((argument) => !argument.startsWith('-'));\n const unknown = flags.filter((flag) => !AnyAliasesFlags.isValid(flag));\n\n if (unknown.length > 0) {\n console.error(\n `devz codemod: unknown option ${unknown.map((flag) => `\"${flag}\"`).join(', ')}\\n${USAGE}`,\n );\n\n return USAGE_ERROR_CODE;\n }\n\n const isWrite = flags.includes(AnyAliasesFlags.WRITE);\n const isCheck = flags.includes(AnyAliasesFlags.CHECK);\n const isStrict = flags.includes(AnyAliasesFlags.STRICT);\n\n if (isWrite && isCheck) {\n console.error(\n `devz codemod: ${AnyAliasesFlags.WRITE} and ${AnyAliasesFlags.CHECK} contradict each other\\n${USAGE}`,\n );\n\n return USAGE_ERROR_CODE;\n }\n\n const refusal = CodemodFiles.refusal({\n command: 'any-aliases',\n isWrite,\n isAll: flags.includes(AnyAliasesFlags.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 referenceCount = 0;\n let manualCount = 0;\n let localCount = 0;\n let refusedCount = 0;\n\n for (const target of targets) {\n const files = CodemodFiles.collect({ target });\n const dirty = isWrite ? CodemodFiles.dirty({ target }) : undefined;\n\n if (files.length === 0 && paths.length > 0) {\n console.warn(\n `devz codemod: no source files under \"${relative(root, target) || target}\" (git ignores the path, or it holds none): nothing was read`,\n );\n }\n\n for (const file of files) {\n const source = readFileSync(file, 'utf8');\n\n if (!/\\bAny(?:Type|Object)\\b/.test(source)) {\n continue;\n }\n\n const result = AnyAliases.rewrite({ typescript, fileName: file, source, isStrict });\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 item of result.local) {\n localCount += 1;\n console.warn(\n `local ${shown}:${item.line} ${item.name} is not the IGNIS alias (declared here or imported from elsewhere): left alone`,\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 referenceCount += result.rewritten;\n console.log(\n `${isWrite ? 'changed' : 'would change'} ${shown} (${result.rewritten} reference(s))`,\n );\n\n if (isWrite) {\n writeFileSync(file, result.output);\n }\n }\n }\n\n console.log(\n `devz codemod any-aliases: ${changedCount} file(s) ${isWrite ? 'changed' : 'would change'}, ${referenceCount} reference(s) ${isWrite ? 'rewritten' : 'would be rewritten'}, ${manualCount} manual, ${localCount} local` +\n (refusedCount > 0 ? `, ${refusedCount} refused` : ''),\n );\n\n if (!isWrite && changedCount > 0) {\n console.log(\n `Nothing was written. Run again with ${AnyAliasesFlags.WRITE} to apply, then run your typecheck${isStrict ? ': a value an alias used to accept may need a type alias, a spread or a narrowing' : ''}.`,\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"]}
|
|
1
|
+
{"version":3,"file":"any-aliases.js","sourceRoot":"","sources":["../../../src/cli/codemod/any-aliases.ts"],"names":[],"mappings":";;;AAAA,qCAAsD;AACtD,yCAA8C;AAC9C,mCAAuC;AAEvC,MAAM,KAAK,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gEA4CkD,CAAC;AAEjE,kDAAkD;AAClD,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAE3B;;;GAGG;AACH,MAAM,cAAc,GAAG;IACrB,gBAAgB;IAChB,wBAAwB;IACxB,0BAA0B;IAC1B,gBAAgB;IAChB,uBAAuB;CACxB,CAAC;AAEF,MAAM,YAAY,GAAG,IAAI,MAAM,CAC7B,OAAO,cAAc,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAC1F,CAAC;AAEF,yHAAyH;AACzH,MAAM,YAAY,GAAG,IAAI,GAAG,CAAiB;IAC3C,CAAC,SAAS,EAAE,KAAK,CAAC;IAClB,CAAC,WAAW,EAAE,uCAAuC,CAAC;CACvD,CAAC,CAAC;AAEH,mFAAmF;AACnF,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAiB;IAClD,CAAC,SAAS,EAAE,SAAS,CAAC;IACtB,CAAC,WAAW,EAAE,yBAAyB,CAAC;CACzC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AAa,EAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;gBACrC,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,CAAC,GAAG,CACT,6BAA6B,YAAY,YAAY,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,cAAc,KAAK,cAAc,iBAAiB,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,oBAAoB,KAAK,WAAW,YAAY,UAAU,QAAQ;YACrN,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,YAAY,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CACxD,CAAC;QAEF,IAAI,CAAC,OAAO,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC;YACjC,OAAO,CAAC,GAAG,CACT,uCAAuC,eAAe,CAAC,KAAK,qCAAqC,QAAQ,CAAC,CAAC,CAAC,kFAAkF,CAAC,CAAC,CAAC,EAAE,GAAG,CACvM,CAAC;QACJ,CAAC;QAED,IAAI,OAAO,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC;YAChC,OAAO,CAAC,CAAC;QACX,CAAC;QAED,OAAO,OAAO,IAAI,CAAC,YAAY,GAAG,CAAC,IAAI,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAClE,CAAC;;AA3IH,8CA4IC","sourcesContent":["import { readFileSync, writeFileSync } from 'node:fs';\nimport { relative, resolve } from 'node:path';\nimport { CodemodFiles } from './files';\n\nconst USAGE = `Usage: devz codemod any-aliases [paths...] [--strict] [--write [--all] | --check]\n\nReplaces the AnyType and AnyObject aliases the @venizia/ignis-helpers and @venizia/ignis-inversion\nreleases deleted, by what they stood for, so a bump changes no type in your code:\n\n AnyType becomes any\n AnyObject becomes Record<string | symbol | number, any>\n\nin every file that imports them from @venizia/ignis, @venizia/ignis-helpers, @venizia/ignis-inversion,\n@venizia/ardor or @venizia/ardor-kernel (ARDOR re-exported the same two names; a sub-path such as\n@venizia/ignis-helpers/common too), whatever local name the import gives them\n(import { AnyType as Loose } ...). The names leave the import, and an import left empty is dropped.\n\nWith --strict it writes the tighter types instead of the default ones, for code that wants to stop using any:\n\n AnyType becomes unknown\n AnyObject becomes Record<string, unknown>\n\n--strict surfaces errors that any hid: an unknown value cannot be read, or passed as a narrower type, without a\ncheck; an interface-typed value is not assignable to Record<string, unknown> (an interface has no implicit\nindex signature); and a symbol key on a former AnyObject fails (TS2538). Declare the shape as a type\nalias, spread the value, or narrow it; run your typecheck after it.\n--strict acts only on the alias names: a file already rewritten to any is left alone, so run it instead of\nthe default run, on a path at a time, and tighten the rest by hand.\n\nIt lists, and leaves alone:\n manual a re-export (export { AnyType }, export type { AnyObject } from ...), an import(\"...\").AnyType\n type, and AnyType in a heritage clause (extends any and extends unknown are not valid)\n local a same-named type the file declares (in any scope: a namespace, a function, a block, a type\n parameter) or imports from somewhere else; a use that such a declaration shadows is left alone\n\nA name used in a heritage clause keeps its import, and so keeps all its other uses in that file: once you\nreplace the heritage use by hand, run the codemod again and the other uses are rewritten.\n\nIt reads TypeScript files (.ts, .tsx, .mts, .cts) and is idempotent: a second run changes nothing.\n\n --strict write unknown and Record<string, unknown> instead of any\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 case is left (for CI)\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\ngit knows, and --write refuses a file with local changes: commit, stash or \"git add\" 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/**\n * The packages the aliases were exported from, each with or without a sub-path: the IGNIS root package, helpers and\n * inversion, and the ARDOR packages that re-exported the same two names (same names, same meaning).\n */\nconst ALIAS_PACKAGES = [\n '@venizia/ignis',\n '@venizia/ignis-helpers',\n '@venizia/ignis-inversion',\n '@venizia/ardor',\n '@venizia/ardor-kernel',\n];\n\nconst ALIAS_MODULE = new RegExp(\n `^(?:${ALIAS_PACKAGES.map((name) => name.replace(/[/.-]/g, '\\\\$&')).join('|')})(?:/.*)?$`,\n);\n\n/** The deleted aliases and what each becomes by default: what they stood for, so the types of the code do not change. */\nconst REPLACEMENTS = new Map<string, string>([\n ['AnyType', 'any'],\n ['AnyObject', 'Record<string | symbol | number, any>'],\n]);\n\n/** With `--strict`: the tighter types, for code that wants to stop using `any`. */\nconst STRICT_REPLACEMENTS = new Map<string, string>([\n ['AnyType', 'unknown'],\n ['AnyObject', 'Record<string, unknown>'],\n]);\n\n/** What `AnyType` becomes in either mode: neither `extends any` nor `extends unknown` is valid, so a heritage use is left. */\nconst HERITAGE_BLOCKED = new Set(['any', 'unknown']);\n\nclass AnyAliasesFlags {\n static readonly WRITE = '--write';\n static readonly ALL = '--all';\n static readonly CHECK = '--check';\n static readonly STRICT = '--strict';\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.STRICT,\n this.HELP,\n this.HELP_SHORT,\n ]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\nexport interface IAnyAliasesResult {\n output: string;\n changed: boolean;\n /** How many type references were rewritten. */\n rewritten: number;\n /** What the codemod cannot place: file line (1-based) and why. */\n manual: Array<{ line: number; reason: string }>;\n /** Same-named types that are not the IGNIS aliases: file line (1-based) and the name. */\n local: Array<{ line: number; name: string }>;\n}\n\n/** Replaces the deleted `AnyType` and `AnyObject` aliases by what they stood for (`any`), or with `isStrict` by the tighter types. */\nexport class AnyAliases {\n static rewrite(opts: {\n typescript: typeof import('typescript');\n fileName: string;\n source: string;\n /** Write `unknown` and `Record<string, unknown>` instead of `any`. */\n isStrict?: boolean;\n }): IAnyAliasesResult {\n const { typescript: ts, fileName, source, isStrict = false } = opts;\n const replacements = isStrict ? STRICT_REPLACEMENTS : REPLACEMENTS;\n const language = fileName.endsWith('.tsx') ? ts.ScriptKind.TSX : ts.ScriptKind.TS;\n const file = ts.createSourceFile(fileName, source, ts.ScriptTarget.Latest, true, language);\n const edits: Array<{ start: number; end: number; text: string }> = [];\n const manual: Array<{ line: number; reason: string }> = [];\n const local: Array<{ line: number; name: string }> = [];\n let rewritten = 0;\n\n const lineOf = (node: import('typescript').Node): number =>\n file.getLineAndCharacterOfPosition(node.getStart(file)).line + 1;\n\n const addReplacement = (node: import('typescript').Node, replacement: string): void => {\n edits.push({ start: node.getStart(file), end: node.getEnd(), text: replacement });\n rewritten += 1;\n };\n\n // The local names bound to an alias (name -> replacement), the namespace imports of a module that held them\n // and the names the file exports.\n const aliasNames = new Map<string, string>();\n const namespaces = new Set<string>();\n const exportedNames = new Set<string>();\n\n /**\n * Whether a declaration in a scope that encloses `node` (below the file: a namespace, a function, a block, a\n * type parameter) binds `name`, so the name there is not the file-level import. `isNamespace` is what the use needs:\n * a namespace (the left side of `H.AnyType`) rather than a type.\n */\n const isShadowed = (\n node: import('typescript').Node,\n name: string,\n isNamespace: boolean,\n ): boolean => {\n const hasInfer = (type: import('typescript').Node): boolean =>\n (ts.isInferTypeNode(type) && type.typeParameter.name.text === name) ||\n ts.forEachChild(type, (child) => (hasInfer(child) ? true : undefined)) === true;\n\n // `child` is the node the walk came from: an `infer` name is bound in the true branch of its conditional type only.\n let child: import('typescript').Node = node;\n\n for (let scope: import('typescript').Node | undefined = node.parent; scope !== undefined;) {\n if (ts.isSourceFile(scope)) {\n return false;\n }\n\n if (!isNamespace) {\n if (\n (ts.isFunctionLike(scope) ||\n ts.isClassLike(scope) ||\n ts.isInterfaceDeclaration(scope) ||\n ts.isTypeAliasDeclaration(scope)) &&\n scope.typeParameters?.some((parameter) => parameter.name.text === name)\n ) {\n return true;\n }\n\n if (ts.isMappedTypeNode(scope) && scope.typeParameter.name.text === name) {\n return true;\n }\n\n if (\n ts.isConditionalTypeNode(scope) &&\n child === scope.trueType &&\n hasInfer(scope.extendsType)\n ) {\n return true;\n }\n }\n\n if (\n ts.isBlock(scope) ||\n ts.isModuleBlock(scope) ||\n ts.isCaseClause(scope) ||\n ts.isDefaultClause(scope)\n ) {\n for (const statement of scope.statements) {\n let declared: import('typescript').Node | undefined;\n\n if (\n ts.isTypeAliasDeclaration(statement) ||\n ts.isInterfaceDeclaration(statement) ||\n ts.isClassDeclaration(statement)\n ) {\n declared = !isNamespace ? statement.name : undefined;\n } else if (ts.isEnumDeclaration(statement) || ts.isImportEqualsDeclaration(statement)) {\n declared = statement.name;\n } else if (ts.isModuleDeclaration(statement)) {\n declared = isNamespace ? statement.name : undefined;\n }\n\n if (declared !== undefined && ts.isIdentifier(declared) && declared.text === name) {\n return true;\n }\n }\n }\n\n child = scope;\n scope = scope.parent;\n }\n\n return false;\n };\n\n // `export { AnyType }` keeps the import alive: that name is left to the user (reported below).\n for (const statement of file.statements) {\n if (\n ts.isExportDeclaration(statement) &&\n statement.moduleSpecifier === undefined &&\n statement.exportClause !== undefined &&\n ts.isNamedExports(statement.exportClause)\n ) {\n for (const element of statement.exportClause.elements) {\n exportedNames.add((element.propertyName ?? element.name).text);\n }\n }\n }\n\n // `extends any`, `extends unknown` and `implements` of either are not valid TypeScript: an alias used in a heritage\n // clause whose replacement is `any` or `unknown` is left (import and references) and reported where it is used.\n const heritageBlocked = new Set<string>();\n const importedReplacement = new Map<string, string>();\n\n for (const statement of file.statements) {\n if (\n ts.isImportDeclaration(statement) &&\n ts.isStringLiteral(statement.moduleSpecifier) &&\n ALIAS_MODULE.test(statement.moduleSpecifier.text) &&\n statement.importClause?.namedBindings !== undefined &&\n ts.isNamedImports(statement.importClause.namedBindings)\n ) {\n for (const element of statement.importClause.namedBindings.elements) {\n const replacement = replacements.get((element.propertyName ?? element.name).text);\n\n if (replacement !== undefined) {\n importedReplacement.set(element.name.text, replacement);\n }\n }\n }\n }\n\n const scanHeritage = (node: import('typescript').Node): void => {\n if (\n ts.isExpressionWithTypeArguments(node) &&\n ts.isIdentifier(node.expression) &&\n HERITAGE_BLOCKED.has(importedReplacement.get(node.expression.text) ?? '') &&\n !isShadowed(node, node.expression.text, false)\n ) {\n heritageBlocked.add(node.expression.text);\n }\n\n ts.forEachChild(node, scanHeritage);\n };\n\n scanHeritage(file);\n\n const removedRanges: Array<{ start: number; end: number }> = [];\n\n // Imports: which local names are the aliases, and how each import is rewritten.\n for (const statement of file.statements) {\n if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)) {\n continue;\n }\n\n const clause = statement.importClause;\n const isAliasSource = ALIAS_MODULE.test(statement.moduleSpecifier.text);\n\n if (clause === undefined) {\n continue;\n }\n\n if (clause.namedBindings !== undefined && ts.isNamespaceImport(clause.namedBindings)) {\n if (isAliasSource) {\n namespaces.add(clause.namedBindings.name.text);\n }\n\n continue;\n }\n\n if (clause.namedBindings === undefined || !ts.isNamedImports(clause.namedBindings)) {\n if (clause.name !== undefined && replacements.has(clause.name.text) && !isAliasSource) {\n local.push({ line: lineOf(clause.name), name: clause.name.text });\n }\n\n continue;\n }\n\n const named = clause.namedBindings;\n const kept: Array<{ text: string; trailing: string }> = [];\n\n // A comment that follows an element on its line (after its comma) belongs to that element: it goes with it\n // when the element is removed, and it is not part of the next element's leading comments.\n const trailings = named.elements.map((element) => {\n const match = /^[ \\t]*,?[ \\t]*(\\/\\/[^\\r\\n]*|\\/\\*[^\\r\\n]*?\\*\\/)/.exec(\n source.slice(element.getEnd()),\n );\n\n return { comment: match?.[1] ?? '', end: element.getEnd() + (match?.[0].length ?? 0) };\n });\n\n /** An element as it is kept: its text with its own leading comments, and the comment that follows it on its line. */\n const keep = (element: import('typescript').ImportSpecifier, index: number) => {\n const previous = trailings[index - 1];\n const from =\n previous === undefined || previous.comment === ''\n ? element.getFullStart()\n : Math.max(element.getFullStart(), previous.end);\n\n kept.push({\n text: source.slice(from, element.getEnd()).trim(),\n trailing: trailings[index]?.comment ?? '',\n });\n };\n\n let removed = 0;\n\n for (const [index, element] of named.elements.entries()) {\n const imported = (element.propertyName ?? element.name).text;\n const localName = element.name.text;\n const replacement = replacements.get(imported);\n\n if (replacement === undefined) {\n keep(element, index);\n\n continue;\n }\n\n if (!isAliasSource) {\n keep(element, index);\n local.push({ line: lineOf(element), name: localName });\n\n continue;\n }\n\n if (exportedNames.has(localName)) {\n keep(element, index);\n manual.push({\n line: lineOf(element),\n reason: `${localName}${localName === imported ? '' : ` (the alias ${imported})`} is re-exported by this file: the alias is gone, export the type you meant`,\n });\n\n continue;\n }\n\n if (heritageBlocked.has(localName)) {\n keep(element, index);\n\n continue;\n }\n\n aliasNames.set(localName, replacement);\n removed += 1;\n }\n\n if (removed === 0) {\n continue;\n }\n\n if (kept.length === 0 && clause.name === undefined) {\n const start = statement.getStart(file);\n let end = statement.getEnd();\n\n if (source.startsWith('\\r\\n', end)) {\n end += 2;\n } else if (source[end] === '\\n') {\n end += 1;\n }\n\n // A blank line that only separated this import from the next code (or from the top of the file) goes with it.\n // The imports removed before this one are not there any more: a file that starts with a removed import\n // must not start with a blank line.\n let before = source.slice(0, start);\n\n for (const range of [...removedRanges].reverse()) {\n before = before.slice(0, range.start) + before.slice(range.end);\n }\n\n const isOnlyLeading = before.trim() === '' || /\\n\\s*\\n$/.test(before);\n const blank = /^[ \\t]*\\r?\\n/.exec(source.slice(end));\n\n if (isOnlyLeading && blank !== null) {\n end += blank[0].length;\n }\n\n edits.push({ start, end, text: '' });\n removedRanges.push({ start, end });\n } else if (kept.length === 0 && clause.name !== undefined) {\n // A default import stays: `import Default, { AnyType } from ...` -> `import Default from ...`.\n edits.push({ start: clause.name.getEnd(), end: named.getEnd(), text: '' });\n } else {\n const isMultiline = /\\r?\\n/.test(source.slice(named.getStart(file), named.getEnd()));\n const hasTrailingComma = named.elements.hasTrailingComma;\n const lines = kept.map((item, index) => {\n const comma = index < kept.length - 1 || hasTrailingComma ? ',' : '';\n\n return ` ${item.text}${comma}${item.trailing === '' ? '' : ` ${item.trailing}`}`;\n });\n const text = isMultiline\n ? `{\\n${lines.join('\\n')}\\n}`\n : `{ ${kept.map((item) => item.text).join(', ')} }`;\n\n edits.push({ start: named.getStart(file), end: named.getEnd(), text });\n }\n }\n\n // Declarations of a same-named type that is not an import of the aliases.\n for (const statement of file.statements) {\n if (\n (ts.isTypeAliasDeclaration(statement) ||\n ts.isInterfaceDeclaration(statement) ||\n ts.isClassDeclaration(statement) ||\n ts.isEnumDeclaration(statement)) &&\n statement.name !== undefined &&\n replacements.has(statement.name.text) &&\n !aliasNames.has(statement.name.text)\n ) {\n local.push({ line: lineOf(statement.name), name: statement.name.text });\n }\n }\n\n const visit = (node: import('typescript').Node): void => {\n // A same-named type declared below the file level (a namespace, a function, a block, a type parameter) is a\n // different type: it is listed, and the uses it shadows are left alone (see isShadowed).\n if (\n (ts.isTypeAliasDeclaration(node) ||\n ts.isInterfaceDeclaration(node) ||\n ts.isClassDeclaration(node) ||\n ts.isEnumDeclaration(node) ||\n ts.isTypeParameterDeclaration(node)) &&\n node.name !== undefined &&\n replacements.has(node.name.text) &&\n !ts.isSourceFile(node.parent)\n ) {\n local.push({ line: lineOf(node.name), name: node.name.text });\n }\n\n if (ts.isTypeReferenceNode(node) && node.typeArguments === undefined) {\n const { typeName } = node;\n const byName =\n ts.isIdentifier(typeName) && !isShadowed(node, typeName.text, false)\n ? aliasNames.get(typeName.text)\n : undefined;\n const byNamespace =\n ts.isQualifiedName(typeName) &&\n ts.isIdentifier(typeName.left) &&\n namespaces.has(typeName.left.text) &&\n !isShadowed(node, typeName.left.text, true)\n ? replacements.get(typeName.right.text)\n : undefined;\n const replacement = byName ?? byNamespace;\n\n if (replacement !== undefined) {\n addReplacement(node, replacement);\n\n return;\n }\n }\n\n if (ts.isExpressionWithTypeArguments(node) && node.typeArguments === undefined) {\n const { expression } = node;\n const byName =\n ts.isIdentifier(expression) && !isShadowed(node, expression.text, false)\n ? aliasNames.get(expression.text)\n : undefined;\n const byNamespace =\n ts.isPropertyAccessExpression(expression) &&\n ts.isIdentifier(expression.expression) &&\n namespaces.has(expression.expression.text) &&\n !isShadowed(node, expression.expression.text, true)\n ? replacements.get(expression.name.text)\n : undefined;\n const replacement = byName ?? byNamespace;\n\n if (replacement !== undefined && HERITAGE_BLOCKED.has(replacement)) {\n manual.push({\n line: lineOf(node),\n reason: `${node.getText(file)} in a heritage clause: extends any, extends unknown and implements are not valid, name the members you mean`,\n });\n\n return;\n }\n\n if (replacement !== undefined) {\n addReplacement(node, replacement);\n\n return;\n }\n\n if (\n ts.isIdentifier(expression) &&\n heritageBlocked.has(expression.text) &&\n !isShadowed(node, expression.text, false)\n ) {\n manual.push({\n line: lineOf(node),\n reason: `${expression.text} in a heritage clause: extends any, extends unknown and implements are not valid, name the members you mean`,\n });\n\n return;\n }\n }\n\n if (\n ts.isImportTypeNode(node) &&\n node.qualifier !== undefined &&\n ts.isIdentifier(node.qualifier) &&\n replacements.has(node.qualifier.text) &&\n ts.isLiteralTypeNode(node.argument) &&\n ts.isStringLiteral(node.argument.literal) &&\n ALIAS_MODULE.test(node.argument.literal.text)\n ) {\n manual.push({\n line: lineOf(node),\n reason: `import(\"${node.argument.literal.text}\").${node.qualifier.text}: replace the whole type by hand`,\n });\n }\n\n if (\n ts.isExportDeclaration(node) &&\n node.exportClause !== undefined &&\n ts.isNamedExports(node.exportClause)\n ) {\n const isIgnisSource =\n node.moduleSpecifier !== undefined &&\n ts.isStringLiteral(node.moduleSpecifier) &&\n ALIAS_MODULE.test(node.moduleSpecifier.text);\n\n for (const element of node.exportClause.elements) {\n const exported = (element.propertyName ?? element.name).text;\n\n if (replacements.has(exported) && isIgnisSource) {\n manual.push({\n line: lineOf(element),\n reason: `a re-export of ${exported}: the alias is gone, export the type you meant`,\n });\n }\n }\n }\n\n ts.forEachChild(node, visit);\n };\n\n visit(file);\n\n if (edits.length === 0) {\n return { output: source, changed: false, rewritten: 0, manual, local };\n }\n\n let output = source;\n\n for (const edit of [...edits].sort((left, right) => right.start - left.start)) {\n output = output.slice(0, edit.start) + edit.text + output.slice(edit.end);\n }\n\n return { output, changed: output !== source, rewritten, manual, local };\n }\n}\n\n/** `devz codemod any-aliases`: reads the sources, prints what changes, writes with `--write`. */\nexport class AnyAliasesCommand {\n static readonly USAGE = USAGE;\n\n static async run(opts: { root: string; args: string[] }): Promise<number> {\n const { root, args } = opts;\n\n if (args.includes(AnyAliasesFlags.HELP) || args.includes(AnyAliasesFlags.HELP_SHORT)) {\n console.log(USAGE);\n\n return 0;\n }\n\n const flags = args.filter((argument) => argument.startsWith('-'));\n const paths = args.filter((argument) => !argument.startsWith('-'));\n const unknown = flags.filter((flag) => !AnyAliasesFlags.isValid(flag));\n\n if (unknown.length > 0) {\n console.error(\n `devz codemod: unknown option ${unknown.map((flag) => `\"${flag}\"`).join(', ')}\\n${USAGE}`,\n );\n\n return USAGE_ERROR_CODE;\n }\n\n const isWrite = flags.includes(AnyAliasesFlags.WRITE);\n const isCheck = flags.includes(AnyAliasesFlags.CHECK);\n const isStrict = flags.includes(AnyAliasesFlags.STRICT);\n\n if (isWrite && isCheck) {\n console.error(\n `devz codemod: ${AnyAliasesFlags.WRITE} and ${AnyAliasesFlags.CHECK} contradict each other\\n${USAGE}`,\n );\n\n return USAGE_ERROR_CODE;\n }\n\n const refusal = CodemodFiles.refusal({\n command: 'any-aliases',\n isWrite,\n isAll: flags.includes(AnyAliasesFlags.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 referenceCount = 0;\n let manualCount = 0;\n let localCount = 0;\n let refusedCount = 0;\n\n for (const target of targets) {\n const files = CodemodFiles.collect({ target });\n const dirty = isWrite ? CodemodFiles.dirty({ target }) : undefined;\n\n if (files.length === 0 && paths.length > 0) {\n console.warn(\n `devz codemod: no source files under \"${relative(root, target) || target}\" (git ignores the path, or it holds none): nothing was read`,\n );\n }\n\n for (const file of files) {\n const source = readFileSync(file, 'utf8');\n\n if (!/\\bAny(?:Type|Object)\\b/.test(source)) {\n continue;\n }\n\n const result = AnyAliases.rewrite({ typescript, fileName: file, source, isStrict });\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 item of result.local) {\n localCount += 1;\n console.warn(\n `local ${shown}:${item.line} ${item.name} is not the IGNIS alias (declared here or imported from elsewhere): left alone`,\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, stash or \"git add\" them, then run again)`,\n );\n continue;\n }\n\n changedCount += 1;\n referenceCount += result.rewritten;\n console.log(\n `${isWrite ? 'changed' : 'would change'} ${shown} (${result.rewritten} reference(s))`,\n );\n\n if (isWrite) {\n writeFileSync(file, result.output);\n }\n }\n }\n\n console.log(\n `devz codemod any-aliases: ${changedCount} file(s) ${isWrite ? 'changed' : 'would change'}, ${referenceCount} reference(s) ${isWrite ? 'rewritten' : 'would be rewritten'}, ${manualCount} manual, ${localCount} local` +\n (refusedCount > 0 ? `, ${refusedCount} refused` : ''),\n );\n\n if (!isWrite && changedCount > 0) {\n console.log(\n `Nothing was written. Run again with ${AnyAliasesFlags.WRITE} to apply, then run your typecheck${isStrict ? ': a value an alias used to accept may need a type alias, a spread or a narrowing' : ''}.`,\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"]}
|
|
@@ -53,7 +53,7 @@ export declare class AsyncStyle {
|
|
|
53
53
|
* change or is left unfixed.
|
|
54
54
|
*/
|
|
55
55
|
export declare class AsyncStyleCommand {
|
|
56
|
-
static readonly USAGE = "Usage: devz codemod async-style [paths...] [--write | --check]\n\nApplies the fixers of four house lint rules, so a repository can sweep them without a lint pass:\n\n venizia/no-inline-await `expect(await f())` becomes `const result = await f(); expect(result)`\n venizia/no-return-await `return await f()` becomes `return f()` (`const result = await f(); return result;` in a try)\n venizia/no-await-new-chain `await new Runner(options).run()` becomes\n `const runner = new Runner(options); await runner.run();`\n venizia/no-await-promise-chain `const x = await f().catch(() => null)` becomes\n `let x; try { x = await f(); } catch (error) { x = null; }`\n\nIt changes only what the fixers can change safely, and lists the rest with its file, line and rule:\nan `await` inside a ternary or logical operand, a loop test, an unbraced `if` branch, or after a call\nthat may have effects; an awaited `.then` or `.finally`, a `.catch` whose handler has a block body or\ncalls something, and an awaited chain that is not the whole initializer of a `const` or `let`; and\nevery venizia/no-silent-catch finding (a handler or catch block that swallows the error), which it never\nfixes: what to log is your decision.\n\n --write write the changed files (without it, nothing is written)\n --check dry run that exits 1 when anything would change or is left unfixed (for CI)\n --all with --write and no path: rewrite every source file under the working directory (--write needs a path or --all)\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\nfiles git knows (tracked, or untracked and not ignored), and --write refuses a file with local changes\n(changed
|
|
56
|
+
static readonly USAGE = "Usage: devz codemod async-style [paths...] [--write | --check]\n\nApplies the fixers of four house lint rules, so a repository can sweep them without a lint pass:\n\n venizia/no-inline-await `expect(await f())` becomes `const result = await f(); expect(result)`\n venizia/no-return-await `return await f()` becomes `return f()` (`const result = await f(); return result;` in a try)\n venizia/no-await-new-chain `await new Runner(options).run()` becomes\n `const runner = new Runner(options); await runner.run();`\n venizia/no-await-promise-chain `const x = await f().catch(() => null)` becomes\n `let x; try { x = await f(); } catch (error) { x = null; }`\n\nIt changes only what the fixers can change safely, and lists the rest with its file, line and rule:\nan `await` inside a ternary or logical operand, a loop test, an unbraced `if` branch, or after a call\nthat may have effects; an awaited `.then` or `.finally`, a `.catch` whose handler has a block body or\ncalls something, and an awaited chain that is not the whole initializer of a `const` or `let`; and\nevery venizia/no-silent-catch finding (a handler or catch block that swallows the error), which it never\nfixes: what to log is your decision.\n\n --write write the changed files (without it, nothing is written)\n --check dry run that exits 1 when anything would change or is left unfixed (for CI)\n --all with --write and no path: rewrite every source file under the working directory (--write needs a path or --all)\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\nfiles git knows (tracked, or untracked and not ignored), and --write refuses a file with local changes\n(changed since staged, or untracked): commit, stash or \"git add\" it first, so git can undo the codemod.";
|
|
57
57
|
static run(opts: {
|
|
58
58
|
root: string;
|
|
59
59
|
args: string[];
|
|
@@ -29,7 +29,7 @@ fixes: what to log is your decision.
|
|
|
29
29
|
|
|
30
30
|
With no flag it lists what would change and writes nothing. Inside a git repository it reads the
|
|
31
31
|
files git knows (tracked, or untracked and not ignored), and --write refuses a file with local changes
|
|
32
|
-
(changed
|
|
32
|
+
(changed since staged, or untracked): commit, stash or "git add" it first, so git can undo the codemod.`;
|
|
33
33
|
/** A usage error: nothing was read or written. */
|
|
34
34
|
const USAGE_ERROR_CODE = 2;
|
|
35
35
|
/** A file that can hold an `await` or a `catch`. */
|
|
@@ -237,7 +237,7 @@ class AsyncStyleCommand {
|
|
|
237
237
|
}
|
|
238
238
|
if (dirty?.has(file)) {
|
|
239
239
|
refusedCount += 1;
|
|
240
|
-
console.warn(`refused ${shown} has local changes (commit or
|
|
240
|
+
console.warn(`refused ${shown} has local changes (commit, stash or "git add" them, then run again)`);
|
|
241
241
|
continue;
|
|
242
242
|
}
|
|
243
243
|
changedCount += 1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-style.js","sourceRoot":"","sources":["../../../src/cli/codemod/async-style.ts"],"names":[],"mappings":";;;AAAA,qCAAsD;AACtD,yCAA8C;AAE9C,mCAAuC;AAEvC,MAAM,KAAK,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;uFAyByE,CAAC;AAExF,kDAAkD;AAClD,MAAM,gB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EAAE,CAAC;oBACZ,IAAA,uBAAa,EAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;gBACrC,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,CAAC,GAAG,CACT,6BAA6B,YAAY,YAAY,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,cAAc,KAAK,QAAQ,YAAY,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,kBAAkB,KAAK,WAAW,eAAe;YACvL,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,YAAY,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CACxD,CAAC;QAEF,IAAI,CAAC,OAAO,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC;YACjC,OAAO,CAAC,GAAG,CAAC,uCAAuC,eAAe,CAAC,KAAK,YAAY,CAAC,CAAC;QACxF,CAAC;QAED,IAAI,OAAO,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC;YAChC,OAAO,CAAC,CAAC;QACX,CAAC;QAED,OAAO,OAAO,IAAI,CAAC,YAAY,GAAG,CAAC,IAAI,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAClE,CAAC;;AAnIH,8CAoIC","sourcesContent":["import { readFileSync, writeFileSync } from 'node:fs';\nimport { relative, resolve } from 'node:path';\nimport type { Linter } from 'eslint';\nimport { CodemodFiles } from './files';\n\nconst USAGE = `Usage: devz codemod async-style [paths...] [--write | --check]\n\nApplies the fixers of four house lint rules, so a repository can sweep them without a lint pass:\n\n venizia/no-inline-await \\`expect(await f())\\` becomes \\`const result = await f(); expect(result)\\`\n venizia/no-return-await \\`return await f()\\` becomes \\`return f()\\` (\\`const result = await f(); return result;\\` in a try)\n venizia/no-await-new-chain \\`await new Runner(options).run()\\` becomes\n \\`const runner = new Runner(options); await runner.run();\\`\n venizia/no-await-promise-chain \\`const x = await f().catch(() => null)\\` becomes\n \\`let x; try { x = await f(); } catch (error) { x = null; }\\`\n\nIt changes only what the fixers can change safely, and lists the rest with its file, line and rule:\nan \\`await\\` inside a ternary or logical operand, a loop test, an unbraced \\`if\\` branch, or after a call\nthat may have effects; an awaited \\`.then\\` or \\`.finally\\`, a \\`.catch\\` whose handler has a block body or\ncalls something, and an awaited chain that is not the whole initializer of a \\`const\\` or \\`let\\`; and\nevery venizia/no-silent-catch finding (a handler or catch block that swallows the error), which it never\nfixes: what to log is your decision.\n\n --write write the changed files (without it, nothing is written)\n --check dry run that exits 1 when anything would change or is left unfixed (for CI)\n --all with --write and no path: rewrite every source file under the working directory (--write needs a path or --all)\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\nfiles git knows (tracked, or untracked and not ignored), and --write refuses a file with local changes\n(changed, staged or untracked): commit or stash it first, so git can undo the codemod.`;\n\n/** A usage error: nothing was read or written. */\nconst USAGE_ERROR_CODE = 2;\n\n/** A file that can hold an `await` or a `catch`. */\nconst ASYNC_TEXT = /\\b(await|catch)\\b/;\n\nclass AsyncStyleFlags {\n static readonly WRITE = '--write';\n static readonly CHECK = '--check';\n static readonly ALL = '--all';\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.CHECK,\n this.ALL,\n this.HELP,\n this.HELP_SHORT,\n ]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\nexport interface IAsyncStyleReport {\n line: number;\n column: number;\n /** The rule id, or `undefined` for a file ESLint could not parse. */\n ruleId: string | null;\n message: string;\n}\n\nexport interface IAsyncStyleResult {\n output: string;\n changed: boolean;\n /** How many findings of the original source carried a fix, once the fixers changed it. */\n fixes: number;\n /** What is still reported after every pass. */\n reports: IAsyncStyleReport[];\n}\n\n/** Runs the async-style rules, and only those, over source text with ESLint's own fixer loop. */\nexport class AsyncStyle {\n /** The `Linter` config: the TypeScript parser and the rules of `asyncRuleConfigs`, at error. */\n static async createConfig(): Promise<Linter.Config[]> {\n const { default: tseslint } = await import('typescript-eslint');\n const { asyncRuleConfigs } = await import('../../linters/house/async-rules.js');\n\n return [\n {\n files: ['**/*.{ts,tsx,mts,cts}'],\n languageOptions: { parser: tseslint.parser },\n // Only the async-style rules run here, so a `// eslint-disable-next-line` for any other rule looks unused and\n // ESLint's fixer would delete it. A codemod never touches a directive.\n linterOptions: { reportUnusedDisableDirectives: 'off' },\n },\n ...asyncRuleConfigs,\n ];\n }\n\n /**\n * The self-check's config: four scope rules, run on the text before and after the fixers. A hoisted name must be\n * declared once, shadow nothing, be used after it is declared and be used at all; when the fixers break one of these\n * the count of that rule goes up, and the file is left as it was.\n */\n static async createChecks(): Promise<Linter.Config[]> {\n const { default: tseslint } = await import('typescript-eslint');\n\n return [\n {\n files: ['**/*.{ts,tsx,mts,cts}'],\n languageOptions: { parser: tseslint.parser },\n linterOptions: { reportUnusedDisableDirectives: 'off' },\n plugins: { '@typescript-eslint': tseslint.plugin as never },\n rules: {\n '@typescript-eslint/no-redeclare': 'error',\n '@typescript-eslint/no-shadow': 'error',\n '@typescript-eslint/no-use-before-define': [\n 'error',\n { functions: false, classes: false },\n ],\n '@typescript-eslint/no-unused-vars': ['error', { args: 'none', caughtErrors: 'none' }],\n },\n },\n ];\n }\n\n /** What got worse between `source` and `output` by the self-check's rules: empty when nothing did. */\n static selfCheck(opts: {\n linter: Linter;\n checks: Linter.Config[];\n source: string;\n output: string;\n filename: string;\n }): string[] {\n const { linter, checks, source, output, filename } = opts;\n\n const count = (text: string): Map<string, number> => {\n const found = new Map<string, number>();\n\n for (const message of linter.verify(text, checks, { filename })) {\n const key = message.ruleId ?? 'parse error';\n found.set(key, (found.get(key) ?? 0) + 1);\n }\n\n return found;\n };\n\n const was = count(source);\n const now = count(output);\n\n return [...now]\n .filter(([rule, total]) => total > (was.get(rule) ?? 0))\n .map(([rule, total]) => `${rule}: ${was.get(rule) ?? 0} before, ${total} after`);\n }\n\n /**\n * Fixes `source` (ESLint applies up to ten passes) and returns the text and what is left. `filename` is relative to\n * the linter's `cwd`. The fixed text is checked against the original (`checks`): if it has more redeclarations,\n * shadowed names, uses before declaration or unused variables than the original, no fix is returned and the file is\n * reported as `self-check`, so a hoisted name that does not match the expression it replaced never reaches a file.\n */\n static fix(opts: {\n linter: Linter;\n config: Linter.Config[];\n checks: Linter.Config[];\n source: string;\n filename: string;\n }): IAsyncStyleResult {\n const { linter, config, checks, source, filename } = opts;\n // A fix can leave a new finding behind (the try/catch of no-await-promise-chain is a silent catch when the\n // fallback is a constant), so the count is of the fixable findings, not of the findings that went away.\n const fixable = linter\n .verify(source, config, { filename })\n .filter((message) => message.fix !== undefined).length;\n const result = linter.verifyAndFix(source, config, { filename });\n\n if (result.output !== source) {\n const broken = AsyncStyle.selfCheck({\n linter,\n checks,\n source,\n output: result.output,\n filename,\n });\n\n if (broken.length > 0) {\n return {\n output: source,\n changed: false,\n fixes: 0,\n reports: [\n {\n line: 1,\n column: 1,\n ruleId: 'self-check',\n message: `the fixers would have made this file worse (${broken.join('; ')}); it is left as it was - fix it by hand`,\n },\n ],\n };\n }\n }\n\n return {\n output: result.output,\n changed: result.output !== source,\n fixes: result.fixed ? fixable : 0,\n reports: result.messages.map((message) => ({\n line: message.line,\n column: message.column,\n ruleId: message.ruleId,\n message: message.message,\n })),\n };\n }\n}\n\n/**\n * `devz codemod async-style [paths...] [--write | --check]`: applies the fixers of `no-inline-await`,\n * `no-return-await`, `no-await-new-chain` and `no-await-promise-chain`, and lists what is left of those and of `no-silent-catch`.\n * It is a dry run unless `--write` is given. `--check` is the same dry run, and exits 1 when anything would\n * change or is left unfixed.\n */\nexport class AsyncStyleCommand {\n static readonly USAGE = USAGE;\n\n static async run(opts: { root: string; args: string[] }): Promise<number> {\n const { root, args } = opts;\n\n if (args.includes(AsyncStyleFlags.HELP) || args.includes(AsyncStyleFlags.HELP_SHORT)) {\n console.log(USAGE);\n\n return 0;\n }\n\n const flags = args.filter((argument) => argument.startsWith('-'));\n const paths = args.filter((argument) => !argument.startsWith('-'));\n\n const unknown = flags.filter((flag) => !AsyncStyleFlags.isValid(flag));\n\n if (unknown.length > 0) {\n console.error(\n `devz codemod: unknown option ${unknown.map((flag) => `\"${flag}\"`).join(', ')}\\n${USAGE}`,\n );\n\n return USAGE_ERROR_CODE;\n }\n\n const isWrite = flags.includes(AsyncStyleFlags.WRITE);\n const isCheck = flags.includes(AsyncStyleFlags.CHECK);\n\n if (isWrite && isCheck) {\n console.error(\n `devz codemod: ${AsyncStyleFlags.WRITE} and ${AsyncStyleFlags.CHECK} contradict each other\\n${USAGE}`,\n );\n\n return USAGE_ERROR_CODE;\n }\n\n const refusal = CodemodFiles.refusal({\n command: 'async-style',\n isWrite,\n isAll: flags.includes(AsyncStyleFlags.ALL),\n paths,\n });\n\n if (refusal) {\n console.error(`${refusal}\\n${USAGE}`);\n\n return USAGE_ERROR_CODE;\n }\n\n let linter: Linter;\n\n try {\n const { Linter: EslintLinter } = await import('eslint');\n linter = new EslintLinter({ cwd: root });\n } catch {\n console.error('devz codemod: the \"eslint\" package is required to run the lint fixers');\n\n return 1;\n }\n\n const config = await AsyncStyle.createConfig();\n const checks = await AsyncStyle.createChecks();\n const targets = (paths.length > 0 ? paths : ['.']).map((path) => resolve(root, path));\n let changedCount = 0;\n let fixCount = 0;\n let reportCount = 0;\n let refusedCount = 0;\n\n for (const target of targets) {\n const files = CodemodFiles.collect({ target });\n const dirty = isWrite ? CodemodFiles.dirty({ target }) : undefined;\n\n if (files.length === 0 && paths.length > 0) {\n console.warn(\n `devz codemod: no source files under \"${relative(root, target) || target}\" (git ignores the path, or it holds none): nothing was read`,\n );\n }\n\n for (const file of files) {\n const source = readFileSync(file, 'utf8');\n\n if (!ASYNC_TEXT.test(source)) {\n continue;\n }\n\n const shown = relative(root, file).split('\\\\').join('/');\n const result = AsyncStyle.fix({ linter, config, checks, source, filename: shown });\n\n for (const report of result.reports) {\n reportCount += 1;\n console.warn(\n `${shown}:${report.line}:${report.column} ${report.ruleId ?? 'parse error'} ${report.message}`,\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 fixCount += result.fixes;\n console.log(`${isWrite ? 'changed' : 'would change'} ${shown} (${result.fixes} fix(es))`);\n\n if (isWrite) {\n writeFileSync(file, result.output);\n }\n }\n }\n\n console.log(\n `devz codemod async-style: ${changedCount} file(s) ${isWrite ? 'changed' : 'would change'}, ${fixCount} fix(es) ${isWrite ? 'applied' : 'would be applied'}, ${reportCount} left unfixed` +\n (refusedCount > 0 ? `, ${refusedCount} refused` : ''),\n );\n\n if (!isWrite && changedCount > 0) {\n console.log(`Nothing was written. Run again with ${AsyncStyleFlags.WRITE} to apply.`);\n }\n\n if (isWrite && refusedCount > 0) {\n return 1;\n }\n\n return isCheck && (changedCount > 0 || reportCount > 0) ? 1 : 0;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"async-style.js","sourceRoot":"","sources":["../../../src/cli/codemod/async-style.ts"],"names":[],"mappings":";;;AAAA,qCAAsD;AACtD,yCAA8C;AAE9C,mCAAuC;AAEvC,MAAM,KAAK,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;wGAyB0F,CAAC;AAEzG,kDAAkD;AAClD,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAE3B,oDAAoD;AACpD,MAAM,UAAU,GAAG,mBAAmB,CAAC;AAEvC,MAAM,eAAe;aACH,UAAK,GAAG,SAAS,CAAC;aAClB,UAAK,GAAG,SAAS,CAAC;aAClB,QAAG,GAAG,OAAO,CAAC;aACd,SAAI,GAAG,QAAQ,CAAC;aAChB,eAAU,GAAG,IAAI,CAAC;aAElB,eAAU,GAAG,IAAI,GAAG,CAAS;QAC3C,IAAI,CAAC,KAAK;QACV,IAAI,CAAC,KAAK;QACV,IAAI,CAAC,GAAG;QACR,IAAI,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YAAY,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CACxD,CAAC;QAEF,IAAI,CAAC,OAAO,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC;YACjC,OAAO,CAAC,GAAG,CAAC,uCAAuC,eAAe,CAAC,KAAK,YAAY,CAAC,CAAC;QACxF,CAAC;QAED,IAAI,OAAO,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC;YAChC,OAAO,CAAC,CAAC;QACX,CAAC;QAED,OAAO,OAAO,IAAI,CAAC,YAAY,GAAG,CAAC,IAAI,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAClE,CAAC;;AAnIH,8CAoIC","sourcesContent":["import { readFileSync, writeFileSync } from 'node:fs';\nimport { relative, resolve } from 'node:path';\nimport type { Linter } from 'eslint';\nimport { CodemodFiles } from './files';\n\nconst USAGE = `Usage: devz codemod async-style [paths...] [--write | --check]\n\nApplies the fixers of four house lint rules, so a repository can sweep them without a lint pass:\n\n venizia/no-inline-await \\`expect(await f())\\` becomes \\`const result = await f(); expect(result)\\`\n venizia/no-return-await \\`return await f()\\` becomes \\`return f()\\` (\\`const result = await f(); return result;\\` in a try)\n venizia/no-await-new-chain \\`await new Runner(options).run()\\` becomes\n \\`const runner = new Runner(options); await runner.run();\\`\n venizia/no-await-promise-chain \\`const x = await f().catch(() => null)\\` becomes\n \\`let x; try { x = await f(); } catch (error) { x = null; }\\`\n\nIt changes only what the fixers can change safely, and lists the rest with its file, line and rule:\nan \\`await\\` inside a ternary or logical operand, a loop test, an unbraced \\`if\\` branch, or after a call\nthat may have effects; an awaited \\`.then\\` or \\`.finally\\`, a \\`.catch\\` whose handler has a block body or\ncalls something, and an awaited chain that is not the whole initializer of a \\`const\\` or \\`let\\`; and\nevery venizia/no-silent-catch finding (a handler or catch block that swallows the error), which it never\nfixes: what to log is your decision.\n\n --write write the changed files (without it, nothing is written)\n --check dry run that exits 1 when anything would change or is left unfixed (for CI)\n --all with --write and no path: rewrite every source file under the working directory (--write needs a path or --all)\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\nfiles git knows (tracked, or untracked and not ignored), and --write refuses a file with local changes\n(changed since staged, or untracked): commit, stash or \"git add\" it first, so git can undo the codemod.`;\n\n/** A usage error: nothing was read or written. */\nconst USAGE_ERROR_CODE = 2;\n\n/** A file that can hold an `await` or a `catch`. */\nconst ASYNC_TEXT = /\\b(await|catch)\\b/;\n\nclass AsyncStyleFlags {\n static readonly WRITE = '--write';\n static readonly CHECK = '--check';\n static readonly ALL = '--all';\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.CHECK,\n this.ALL,\n this.HELP,\n this.HELP_SHORT,\n ]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\nexport interface IAsyncStyleReport {\n line: number;\n column: number;\n /** The rule id, or `undefined` for a file ESLint could not parse. */\n ruleId: string | null;\n message: string;\n}\n\nexport interface IAsyncStyleResult {\n output: string;\n changed: boolean;\n /** How many findings of the original source carried a fix, once the fixers changed it. */\n fixes: number;\n /** What is still reported after every pass. */\n reports: IAsyncStyleReport[];\n}\n\n/** Runs the async-style rules, and only those, over source text with ESLint's own fixer loop. */\nexport class AsyncStyle {\n /** The `Linter` config: the TypeScript parser and the rules of `asyncRuleConfigs`, at error. */\n static async createConfig(): Promise<Linter.Config[]> {\n const { default: tseslint } = await import('typescript-eslint');\n const { asyncRuleConfigs } = await import('../../linters/house/async-rules.js');\n\n return [\n {\n files: ['**/*.{ts,tsx,mts,cts}'],\n languageOptions: { parser: tseslint.parser },\n // Only the async-style rules run here, so a `// eslint-disable-next-line` for any other rule looks unused and\n // ESLint's fixer would delete it. A codemod never touches a directive.\n linterOptions: { reportUnusedDisableDirectives: 'off' },\n },\n ...asyncRuleConfigs,\n ];\n }\n\n /**\n * The self-check's config: four scope rules, run on the text before and after the fixers. A hoisted name must be\n * declared once, shadow nothing, be used after it is declared and be used at all; when the fixers break one of these\n * the count of that rule goes up, and the file is left as it was.\n */\n static async createChecks(): Promise<Linter.Config[]> {\n const { default: tseslint } = await import('typescript-eslint');\n\n return [\n {\n files: ['**/*.{ts,tsx,mts,cts}'],\n languageOptions: { parser: tseslint.parser },\n linterOptions: { reportUnusedDisableDirectives: 'off' },\n plugins: { '@typescript-eslint': tseslint.plugin as never },\n rules: {\n '@typescript-eslint/no-redeclare': 'error',\n '@typescript-eslint/no-shadow': 'error',\n '@typescript-eslint/no-use-before-define': [\n 'error',\n { functions: false, classes: false },\n ],\n '@typescript-eslint/no-unused-vars': ['error', { args: 'none', caughtErrors: 'none' }],\n },\n },\n ];\n }\n\n /** What got worse between `source` and `output` by the self-check's rules: empty when nothing did. */\n static selfCheck(opts: {\n linter: Linter;\n checks: Linter.Config[];\n source: string;\n output: string;\n filename: string;\n }): string[] {\n const { linter, checks, source, output, filename } = opts;\n\n const count = (text: string): Map<string, number> => {\n const found = new Map<string, number>();\n\n for (const message of linter.verify(text, checks, { filename })) {\n const key = message.ruleId ?? 'parse error';\n found.set(key, (found.get(key) ?? 0) + 1);\n }\n\n return found;\n };\n\n const was = count(source);\n const now = count(output);\n\n return [...now]\n .filter(([rule, total]) => total > (was.get(rule) ?? 0))\n .map(([rule, total]) => `${rule}: ${was.get(rule) ?? 0} before, ${total} after`);\n }\n\n /**\n * Fixes `source` (ESLint applies up to ten passes) and returns the text and what is left. `filename` is relative to\n * the linter's `cwd`. The fixed text is checked against the original (`checks`): if it has more redeclarations,\n * shadowed names, uses before declaration or unused variables than the original, no fix is returned and the file is\n * reported as `self-check`, so a hoisted name that does not match the expression it replaced never reaches a file.\n */\n static fix(opts: {\n linter: Linter;\n config: Linter.Config[];\n checks: Linter.Config[];\n source: string;\n filename: string;\n }): IAsyncStyleResult {\n const { linter, config, checks, source, filename } = opts;\n // A fix can leave a new finding behind (the try/catch of no-await-promise-chain is a silent catch when the\n // fallback is a constant), so the count is of the fixable findings, not of the findings that went away.\n const fixable = linter\n .verify(source, config, { filename })\n .filter((message) => message.fix !== undefined).length;\n const result = linter.verifyAndFix(source, config, { filename });\n\n if (result.output !== source) {\n const broken = AsyncStyle.selfCheck({\n linter,\n checks,\n source,\n output: result.output,\n filename,\n });\n\n if (broken.length > 0) {\n return {\n output: source,\n changed: false,\n fixes: 0,\n reports: [\n {\n line: 1,\n column: 1,\n ruleId: 'self-check',\n message: `the fixers would have made this file worse (${broken.join('; ')}); it is left as it was - fix it by hand`,\n },\n ],\n };\n }\n }\n\n return {\n output: result.output,\n changed: result.output !== source,\n fixes: result.fixed ? fixable : 0,\n reports: result.messages.map((message) => ({\n line: message.line,\n column: message.column,\n ruleId: message.ruleId,\n message: message.message,\n })),\n };\n }\n}\n\n/**\n * `devz codemod async-style [paths...] [--write | --check]`: applies the fixers of `no-inline-await`,\n * `no-return-await`, `no-await-new-chain` and `no-await-promise-chain`, and lists what is left of those and of `no-silent-catch`.\n * It is a dry run unless `--write` is given. `--check` is the same dry run, and exits 1 when anything would\n * change or is left unfixed.\n */\nexport class AsyncStyleCommand {\n static readonly USAGE = USAGE;\n\n static async run(opts: { root: string; args: string[] }): Promise<number> {\n const { root, args } = opts;\n\n if (args.includes(AsyncStyleFlags.HELP) || args.includes(AsyncStyleFlags.HELP_SHORT)) {\n console.log(USAGE);\n\n return 0;\n }\n\n const flags = args.filter((argument) => argument.startsWith('-'));\n const paths = args.filter((argument) => !argument.startsWith('-'));\n\n const unknown = flags.filter((flag) => !AsyncStyleFlags.isValid(flag));\n\n if (unknown.length > 0) {\n console.error(\n `devz codemod: unknown option ${unknown.map((flag) => `\"${flag}\"`).join(', ')}\\n${USAGE}`,\n );\n\n return USAGE_ERROR_CODE;\n }\n\n const isWrite = flags.includes(AsyncStyleFlags.WRITE);\n const isCheck = flags.includes(AsyncStyleFlags.CHECK);\n\n if (isWrite && isCheck) {\n console.error(\n `devz codemod: ${AsyncStyleFlags.WRITE} and ${AsyncStyleFlags.CHECK} contradict each other\\n${USAGE}`,\n );\n\n return USAGE_ERROR_CODE;\n }\n\n const refusal = CodemodFiles.refusal({\n command: 'async-style',\n isWrite,\n isAll: flags.includes(AsyncStyleFlags.ALL),\n paths,\n });\n\n if (refusal) {\n console.error(`${refusal}\\n${USAGE}`);\n\n return USAGE_ERROR_CODE;\n }\n\n let linter: Linter;\n\n try {\n const { Linter: EslintLinter } = await import('eslint');\n linter = new EslintLinter({ cwd: root });\n } catch {\n console.error('devz codemod: the \"eslint\" package is required to run the lint fixers');\n\n return 1;\n }\n\n const config = await AsyncStyle.createConfig();\n const checks = await AsyncStyle.createChecks();\n const targets = (paths.length > 0 ? paths : ['.']).map((path) => resolve(root, path));\n let changedCount = 0;\n let fixCount = 0;\n let reportCount = 0;\n let refusedCount = 0;\n\n for (const target of targets) {\n const files = CodemodFiles.collect({ target });\n const dirty = isWrite ? CodemodFiles.dirty({ target }) : undefined;\n\n if (files.length === 0 && paths.length > 0) {\n console.warn(\n `devz codemod: no source files under \"${relative(root, target) || target}\" (git ignores the path, or it holds none): nothing was read`,\n );\n }\n\n for (const file of files) {\n const source = readFileSync(file, 'utf8');\n\n if (!ASYNC_TEXT.test(source)) {\n continue;\n }\n\n const shown = relative(root, file).split('\\\\').join('/');\n const result = AsyncStyle.fix({ linter, config, checks, source, filename: shown });\n\n for (const report of result.reports) {\n reportCount += 1;\n console.warn(\n `${shown}:${report.line}:${report.column} ${report.ruleId ?? 'parse error'} ${report.message}`,\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, stash or \"git add\" them, then run again)`,\n );\n continue;\n }\n\n changedCount += 1;\n fixCount += result.fixes;\n console.log(`${isWrite ? 'changed' : 'would change'} ${shown} (${result.fixes} fix(es))`);\n\n if (isWrite) {\n writeFileSync(file, result.output);\n }\n }\n }\n\n console.log(\n `devz codemod async-style: ${changedCount} file(s) ${isWrite ? 'changed' : 'would change'}, ${fixCount} fix(es) ${isWrite ? 'applied' : 'would be applied'}, ${reportCount} left unfixed` +\n (refusedCount > 0 ? `, ${refusedCount} refused` : ''),\n );\n\n if (!isWrite && changedCount > 0) {\n console.log(`Nothing was written. Run again with ${AsyncStyleFlags.WRITE} to apply.`);\n }\n\n if (isWrite && refusedCount > 0) {\n return 1;\n }\n\n return isCheck && (changedCount > 0 || reportCount > 0) ? 1 : 0;\n }\n}\n"]}
|
|
@@ -60,7 +60,7 @@ export declare class BindingKeysCodemod {
|
|
|
60
60
|
}
|
|
61
61
|
/** `devz codemod binding-keys [paths...] [--write | --check]`: rewrites raw binding keys to `BindingKeys.build<T>`. */
|
|
62
62
|
export declare class BindingKeysCommand {
|
|
63
|
-
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 held in a name (MAILER, Keys.MAILER) is built where it is declared, in any file of the run: a const, a\nreadonly property or a property of an object literal, with a string initializer and no type annotation. Its type is the\none type its use sites claim (get<Mailer>, the type of a decorated parameter), else unknown (listed as \"type\"); the use\nsites are not edited. A name declared another way (a let, an annotation, a parameter, a call, a package you do not own)\nis listed as \"manual\". build throws on an empty key, so a computed constant that comes out '' now throws when its class loads.\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
|
|
63
|
+
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 written Foo.name or this.constructor.name (a string TypeScript's own lib declares) is wrapped in\nplace. A key held in a name (MAILER, Keys.MAILER) is built where it is declared, in any file of the run: a const, a\nreadonly property or a property of an object literal, with a string initializer and no type annotation. Its type is the\none type its use sites claim (get<Mailer>, the type of a decorated parameter), else unknown (listed as \"type\"); the use\nsites are not edited. A name declared another way (a let, an annotation, a parameter, a call, a package you do not own)\nis listed as \"manual\". build throws on an empty key, so a computed constant that comes out '' now throws when its class loads.\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, stash or \"git add\" it first, so git can undo it.\nThere is no --reverse: a downgrade restores the files from git.";
|
|
64
64
|
/**
|
|
65
65
|
* The program the checker answers from: the project's own tsconfig (the nearest one above `root`) with the files the
|
|
66
66
|
* codemod reads added, so a receiver resolves the way the project's typecheck resolves it.
|
|
@@ -28,7 +28,8 @@ It rewrites a call named get, gets, getBinding, bind, isBound or unbind whose ar
|
|
|
28
28
|
test. A string key, a substitution-free template literal, a { namespace, key } literal and a template written
|
|
29
29
|
\${namespace}.Name or \${namespace}.\${name} are rewritten. These are listed
|
|
30
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
|
|
31
|
+
longer keys). A key written Foo.name or this.constructor.name (a string TypeScript's own lib declares) is wrapped in
|
|
32
|
+
place. A key held in a name (MAILER, Keys.MAILER) is built where it is declared, in any file of the run: a const, a
|
|
32
33
|
readonly property or a property of an object literal, with a string initializer and no type annotation. Its type is the
|
|
33
34
|
one type its use sites claim (get<Mailer>, the type of a decorated parameter), else unknown (listed as "type"); the use
|
|
34
35
|
sites are not edited. A name declared another way (a let, an annotation, a parameter, a call, a package you do not own)
|
|
@@ -47,7 +48,7 @@ It reads TypeScript files (.ts, .tsx, .mts, .cts). A .js, .cjs or .mjs file is n
|
|
|
47
48
|
--help print this text and exit
|
|
48
49
|
|
|
49
50
|
With no flag it lists what would change and writes nothing. Inside a git repository it reads the files git knows, and
|
|
50
|
-
--write refuses a file with local changes: commit or
|
|
51
|
+
--write refuses a file with local changes: commit, stash or "git add" it first, so git can undo it.
|
|
51
52
|
There is no --reverse: a downgrade restores the files from git.`;
|
|
52
53
|
/** A usage error: nothing was read or written. */
|
|
53
54
|
const USAGE_ERROR_CODE = 2;
|
|
@@ -60,6 +61,8 @@ const KEY_DECORATORS = new Set(['inject', 'provide']);
|
|
|
60
61
|
/** Where a file already imports the container API from. */
|
|
61
62
|
const IGNIS_MODULE = /^@venizia\/ignis(?:-kernel|-inversion)?$/;
|
|
62
63
|
const BUILDER = 'BindingKeys';
|
|
64
|
+
/** A declaration file of TypeScript's own `lib` (where `Function.name` is declared). */
|
|
65
|
+
const LIB_FILE = /[\\/]typescript[\\/]lib[\\/]lib\.[^\\/]*\.d\.ts$/;
|
|
63
66
|
/** The classes and interfaces whose key methods are the container's. */
|
|
64
67
|
const CONTAINER_TYPES = new Set([
|
|
65
68
|
'IContainer',
|
|
@@ -251,6 +254,19 @@ class BindingKeysCodemod {
|
|
|
251
254
|
ts.isTypeReferenceNode(node.parent.type) &&
|
|
252
255
|
ts.isIdentifier(node.parent.type.typeName) &&
|
|
253
256
|
node.parent.type.typeName.text === 'const';
|
|
257
|
+
/** `Foo.name`, `this.constructor.name`: the `name` that TypeScript's own lib declares, so there is no constant of yours to build. Another lib string (`err.message`, `location.href`) is not a key. */
|
|
258
|
+
const isLibString = (value) => {
|
|
259
|
+
if (checker === undefined ||
|
|
260
|
+
!ts.isPropertyAccessExpression(value) ||
|
|
261
|
+
value.name.text !== 'name') {
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
const declared = checker.getSymbolAtLocation(value.name)?.declarations?.[0]?.getSourceFile();
|
|
265
|
+
return (declared !== undefined &&
|
|
266
|
+
declared.isDeclarationFile &&
|
|
267
|
+
LIB_FILE.test(declared.fileName) &&
|
|
268
|
+
(checker.getTypeAtLocation(value).flags & ts.TypeFlags.StringLike) !== 0);
|
|
269
|
+
};
|
|
254
270
|
/**
|
|
255
271
|
* The declaration of a key held in a name (`MAILER`, `Keys.MAILER`) that the codemod may build where it is made: a const, a
|
|
256
272
|
* readonly property or a property of an object literal, with a string initializer, no type annotation, in a file of the
|
|
@@ -376,6 +392,14 @@ class BindingKeysCodemod {
|
|
|
376
392
|
claims.set(held.key, entry);
|
|
377
393
|
return false;
|
|
378
394
|
}
|
|
395
|
+
else if (isLibString(value)) {
|
|
396
|
+
// `Foo.name` is wrapped in place, like a literal: the type the call claimed moves into build<T>.
|
|
397
|
+
edits.push({
|
|
398
|
+
start: value.getStart(file),
|
|
399
|
+
end: value.getEnd(),
|
|
400
|
+
text: `${builder}.build<${text}>({ key: ${value.getText(file)} })`,
|
|
401
|
+
});
|
|
402
|
+
}
|
|
379
403
|
else if (isBuilderCall(value)) {
|
|
380
404
|
if (value.typeArguments !== undefined) {
|
|
381
405
|
return false;
|
|
@@ -839,7 +863,7 @@ class BindingKeysCommand {
|
|
|
839
863
|
}
|
|
840
864
|
if (dirty?.has(file)) {
|
|
841
865
|
refusedCount += 1;
|
|
842
|
-
console.warn(`refused ${shown} has local changes (commit or
|
|
866
|
+
console.warn(`refused ${shown} has local changes (commit, stash or "git add" them, then run again)`);
|
|
843
867
|
continue;
|
|
844
868
|
}
|
|
845
869
|
changedCount += 1;
|