@venizia/dev-configs 0.4.8-8 → 0.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env-get.js","sourceRoot":"","sources":["../../../src/cli/codemod/env-get.ts"],"names":[],"mappings":";;;AAAA,qCAAsD;AACtD,yCAA8C;AAC9C,mCAAuC;AAEvC,MAAM,KAAK,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gEA2CkD,CAAC;AAEjE,kDAAkD;AAClD,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAE3B,oGAAoG;AACpG,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,CAAC,wBAAwB,EAAE,SAAS,CAAC,CAAC,CAAC;AAEjE,4GAA4G;AAC5G,MAAM,YAAY,GAAG,yCAAyC,CAAC;AAE/D,MAAM,WAAW;aACC,UAAK,GAAG,SAAS,CAAC;aAClB,QAAG,GAAG,OAAO,CAAC;aACd,YAAO,GAAG,WAAW,CAAC;aACtB,UAAK,GAAG,SAAS,CAAC;aAClB,SAAI,GAAG,QAAQ,CAAC;aAChB,eAAU,GAAG,IAAI,CAAC;aAElB,eAAU,GAAG,IAAI,GAAG,CAAS;QAC3C,IAAI,CAAC,KAAK;QACV,IAAI,CAAC,GAAG;QACR,IAAI,CAAC,OAAO;QACZ,IAAI,CAAC,KAAK;QACV,IAAI,CAAC,IAAI;QACT,IAAI,CAAC,UAAU;KAChB,CAAC,CAAC;IAEH,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AAgBH,2EAA2E;AAC3E,MAAa,MAAM;IACjB,0HAA0H;IAClH,MAAM,CAAC,aAAa,CAAC,IAI5B;QACC,MAAM,EAAE,UAAU,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI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ync } from 'node:fs';\nimport { relative, resolve } from 'node:path';\nimport { CodemodFiles } from './files';\n\nconst USAGE = `Usage: devz codemod env-get [paths...] [--write [--all] | --check]\n\nRewrites the type arguments of applicationEnvironment.get() (and its alias AppEnvs.get()) for the\n@venizia/ignis-helpers release where get() reads strings:\n\n get<string>(key) becomes get(key)\n get<string | undefined>(key) becomes get(key)\n get<string>(key, { defaultValue }) becomes get(key, { defaultValue })\n get<R, B>(key, { transform }) becomes get<R>(key, { transform })\n\nAny other type argument (get<number>(key), get<boolean>(key)) was a cast the new get() no longer allows:\nthe codemod lists it as \"manual\" and leaves it. Move the conversion into a transform, or read the\nstring and convert it where you use it: get(key, { transform: Number }).\n\nA call already in the new form (one type argument and an options literal with a transform) is left alone\nand not listed, and a second run changes nothing.\n\nIt reads TypeScript files (.ts, .tsx, .mts, .cts) and rewrites only calls whose receiver resolves, from the\nscope of the call, to the store: a name imported as applicationEnvironment or AppEnvs from @venizia/ignis,\n@venizia/ignis-helpers (or a sub-path), under any local name (import { AppEnvs as Envs } ...), or a const\ninitialised from such a name in the same or an enclosing scope. A parameter, a local variable, an import from\nanywhere else (a barrel of your own included) and a name nothing declares are not the store. Every other\nget<...>(key) call (a property, an optional chain, those names) is printed as skipped with its file and line,\nand a call with a type argument it cannot place as manual, so run your typecheck after it. A call with one type argument and options\nthat are not a literal (a variable) is left alone and not listed; one with two type arguments and such options is listed as manual, and so is a number read with such options under --numbers (the codemod cannot see what the options hold). A var declared in a nested block counts as block-scoped (a hoisted one is not followed). A comment between the method name and the parenthesis is dropped. A .js, .cjs or .mjs file\nis 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 --numbers also rewrite the number reads: get<number>(key) and get<number>(key, { defaultValue }) become\n get(key, { transform: (raw) => ParseUtility.toNumber({ input: raw }), defaultValue }) and\n ParseUtility joins the import of the store. Every rewrite is listed (\"numbers\"). The old call returned\n the environment STRING typed as a number: after the rewrite the read converts it to a number, an unset\n variable still answers undefined (or the default), and a non-numeric value throws at the read\n instead of flowing on as a string. A boolean (the \"false\" string is truthy) stays manual. So does a number\n read the rewrite would not compile: a defaultValue that is a literal but not a number ('10'), options that\n are a variable, a ParseUtility name the file already declares for something else (an import from another\n module, a type-only import, a local), and a parameter or local named ParseUtility at the call.\n --check dry run that exits 1 while a file would change or a manual call remains (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/** The names the environment store is exported under, and so the receivers `get()` is called on. */\nconst RECEIVERS = new Set(['applicationEnvironment', 'AppEnvs']);\n\n/** A module that exports the store: the root package and the helpers package, with or without a subpath. */\nconst STORE_MODULE = /^@venizia\\/ignis(?:-helpers)?(?:\\/.*)?$/;\n\nclass EnvGetFlags {\n static readonly WRITE = '--write';\n static readonly ALL = '--all';\n static readonly NUMBERS = '--numbers';\n static readonly CHECK = '--check';\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.NUMBERS,\n this.CHECK,\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 IEnvGetResult {\n output: string;\n changed: boolean;\n /** How many calls were rewritten. */\n rewritten: number;\n /** The store calls the codemod cannot rewrite: file line (1-based), the first type argument and, when the cause is not the type argument itself, the reason. */\n manual: Array<{ line: number; type: string; reason?: string }>;\n /** With `--numbers`: the lines of the number reads rewritten to a transform (they are counted in `rewritten` too). */\n numbered: number[];\n /** The `get<...>(key)` calls on a receiver the file does not bind to the store (or through an optional chain), left alone and listed: file line (1-based) and the receiver text. */\n skipped: Array<{ line: number; receiver: string }>;\n}\n\n/** Rewrites the type arguments of `applicationEnvironment.get()` calls. */\nexport class EnvGet {\n /** The names a declaration in `node` binds, for `node` a scope: a block or file, a function, a loop or a catch clause. */\n private static declarationIn(opts: {\n typescript: typeof import('typescript');\n scope: import('typescript').Node;\n name: string;\n }): import('typescript').Node | undefined {\n const { typescript: ts, scope, name } = opts;\n\n const bindingNames = (node: import('typescript').BindingName): string[] => {\n if (ts.isIdentifier(node)) {\n return [node.text];\n }\n\n return node.elements.flatMap((element) =>\n ts.isBindingElement(element) ? bindingNames(element.name) : [],\n );\n };\n\n const inDeclarations = (\n declarations: ReadonlyArray<import('typescript').VariableDeclaration>,\n ): import('typescript').Node | undefined =>\n declarations.find((declaration) => bindingNames(declaration.name).includes(name));\n\n if (\n ts.isSourceFile(scope) ||\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 if (ts.isVariableStatement(statement)) {\n const found = inDeclarations(statement.declarationList.declarations);\n\n if (found !== undefined) {\n return found;\n }\n } else if (\n (ts.isFunctionDeclaration(statement) ||\n ts.isClassDeclaration(statement) ||\n ts.isEnumDeclaration(statement)) &&\n statement.name?.text === name\n ) {\n return statement;\n } else if (ts.isImportDeclaration(statement) && statement.importClause !== undefined) {\n const clause = statement.importClause;\n\n if (clause.name?.text === name) {\n return clause;\n }\n\n const bindings = clause.namedBindings;\n\n if (\n bindings !== undefined &&\n ts.isNamespaceImport(bindings) &&\n bindings.name.text === name\n ) {\n return bindings;\n }\n\n if (bindings !== undefined && ts.isNamedImports(bindings)) {\n const element = bindings.elements.find((candidate) => candidate.name.text === name);\n\n if (element !== undefined) {\n return element;\n }\n }\n }\n }\n\n return undefined;\n }\n\n if (ts.isFunctionLike(scope)) {\n const parameter = scope.parameters.find((candidate) =>\n bindingNames(candidate.name).includes(name),\n );\n\n if (parameter !== undefined) {\n return parameter;\n }\n\n return ts.isFunctionExpression(scope) && scope.name?.text === name ? scope : undefined;\n }\n\n if (\n (ts.isForStatement(scope) || ts.isForOfStatement(scope) || ts.isForInStatement(scope)) &&\n scope.initializer !== undefined &&\n ts.isVariableDeclarationList(scope.initializer)\n ) {\n return inDeclarations(scope.initializer.declarations);\n }\n\n if (ts.isCatchClause(scope) && scope.variableDeclaration !== undefined) {\n return inDeclarations([scope.variableDeclaration]);\n }\n\n return undefined;\n }\n\n /**\n * Whether `identifier` refers to the environment store: the binding the name resolves to, from the\n * innermost scope outwards, is an import of `applicationEnvironment` or `AppEnvs` from the store module\n * (aliased or not), or a `const` that is initialised from such a name. A parameter, a local, an import\n * from anywhere else and a name nothing declares are not the store.\n */\n static isStore(opts: {\n typescript: typeof import('typescript');\n identifier: import('typescript').Identifier;\n }): boolean {\n return EnvGet.storeImport(opts) !== undefined;\n }\n\n /** The import specifier of the store that `identifier` resolves to (through const aliases), or `undefined` when it is not the store. */\n static storeImport(opts: {\n typescript: typeof import('typescript');\n identifier: import('typescript').Identifier;\n seen?: Set<import('typescript').Node>;\n }): import('typescript').ImportSpecifier | undefined {\n const { typescript: ts, identifier } = opts;\n const seen = opts.seen ?? new Set<import('typescript').Node>();\n\n if (seen.has(identifier)) {\n return undefined;\n }\n\n seen.add(identifier);\n\n for (\n let scope: import('typescript').Node | undefined = identifier.parent;\n scope !== undefined;\n scope = scope.parent\n ) {\n const declaration = EnvGet.declarationIn({ typescript: ts, scope, name: identifier.text });\n\n if (declaration === undefined) {\n continue;\n }\n\n if (ts.isImportSpecifier(declaration)) {\n const importDeclaration = declaration.parent.parent.parent;\n\n return ts.isStringLiteral(importDeclaration.moduleSpecifier) &&\n STORE_MODULE.test(importDeclaration.moduleSpecifier.text) &&\n RECEIVERS.has((declaration.propertyName ?? declaration.name).text)\n ? declaration\n : undefined;\n }\n\n if (\n ts.isVariableDeclaration(declaration) &&\n (ts.getCombinedNodeFlags(declaration) & ts.NodeFlags.Const) !== 0 &&\n ts.isIdentifier(declaration.name) &&\n declaration.initializer !== undefined &&\n ts.isIdentifier(declaration.initializer)\n ) {\n return EnvGet.storeImport({ typescript: ts, identifier: declaration.initializer, seen });\n }\n\n return undefined;\n }\n\n return undefined;\n }\n\n static rewrite(opts: {\n typescript: typeof import('typescript');\n fileName: string;\n source: string;\n /** `--numbers`: rewrite `get<number>(key)` and `get<number>(key, { defaultValue })` to a `ParseUtility.toNumber` transform. */\n numbers?: boolean;\n }): IEnvGetResult {\n const { typescript: ts, fileName, source, numbers = false } = opts;\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; type: string; reason?: string }> = [];\n const skipped: Array<{ line: number; receiver: string }> = [];\n const numbered: number[] = [];\n let rewrittenCalls = 0;\n let isParseUtilityImported = false;\n const lineOf = (node: import('typescript').Node): number =>\n file.getLineAndCharacterOfPosition(node.getStart(file)).line + 1;\n\n /** `string`, or `string | undefined` (the type `get(key)` already answers): the type argument can go. */\n const isStringType = (node: import('typescript').TypeNode): boolean => {\n if (node.kind === ts.SyntaxKind.StringKeyword) {\n return true;\n }\n\n if (ts.isParenthesizedTypeNode(node)) {\n return isStringType(node.type);\n }\n\n if (ts.isUnionTypeNode(node) && node.types.length === 2) {\n const parts = node.types.map((part) => part.kind);\n\n return (\n parts.includes(ts.SyntaxKind.StringKeyword) &&\n parts.includes(ts.SyntaxKind.UndefinedKeyword)\n );\n }\n\n return false;\n };\n\n /** An options literal that already carries a `transform`: the call is in the new form. */\n const hasTransform = (node: import('typescript').Expression | undefined): boolean =>\n node !== undefined &&\n ts.isObjectLiteralExpression(node) &&\n node.properties.some(\n (property) =>\n property.name !== undefined &&\n ts.isIdentifier(property.name) &&\n property.name.text === 'transform',\n );\n\n /** `number`, or `number | undefined`: the types `--numbers` rewrites. */\n const isNumberType = (node: import('typescript').TypeNode): boolean => {\n if (node.kind === ts.SyntaxKind.NumberKeyword) {\n return true;\n }\n\n if (ts.isParenthesizedTypeNode(node)) {\n return isNumberType(node.type);\n }\n\n if (ts.isUnionTypeNode(node) && node.types.length === 2) {\n const parts = node.types.map((part) => part.kind);\n\n return (\n parts.includes(ts.SyntaxKind.NumberKeyword) &&\n parts.includes(ts.SyntaxKind.UndefinedKeyword)\n );\n }\n\n return false;\n };\n\n /** A literal that is not a number: a `defaultValue` of this kind matches no overload of the rewritten call. */\n const isNonNumericLiteral = (node: import('typescript').Expression): boolean =>\n ts.isStringLiteral(node) ||\n ts.isNoSubstitutionTemplateLiteral(node) ||\n ts.isTemplateExpression(node) ||\n ts.isRegularExpressionLiteral(node) ||\n ts.isArrayLiteralExpression(node) ||\n ts.isObjectLiteralExpression(node) ||\n node.kind === ts.SyntaxKind.TrueKeyword ||\n node.kind === ts.SyntaxKind.FalseKeyword ||\n node.kind === ts.SyntaxKind.NullKeyword;\n\n /** An options literal whose `defaultValue` is a literal that is not a number (`{ defaultValue: '10' }`). */\n const hasNonNumericDefault = (node: import('typescript').Expression | undefined): boolean =>\n node !== undefined &&\n ts.isObjectLiteralExpression(node) &&\n node.properties.some(\n (property) =>\n ts.isPropertyAssignment(property) &&\n (ts.isIdentifier(property.name) || ts.isStringLiteral(property.name)) &&\n property.name.text === 'defaultValue' &&\n isNonNumericLiteral(property.initializer),\n );\n\n /** The import specifier the file already has for `ParseUtility`: a value import from the store module, under any local name. */\n const findParseUtilityImport = (): import('typescript').ImportSpecifier | undefined => {\n for (const statement of file.statements) {\n if (\n ts.isImportDeclaration(statement) &&\n ts.isStringLiteral(statement.moduleSpecifier) &&\n STORE_MODULE.test(statement.moduleSpecifier.text) &&\n statement.importClause?.namedBindings !== undefined &&\n ts.isNamedImports(statement.importClause.namedBindings)\n ) {\n const element = statement.importClause.namedBindings.elements.find(\n (candidate) =>\n (candidate.propertyName ?? candidate.name).text === 'ParseUtility' &&\n !candidate.isTypeOnly &&\n !statement.importClause?.isTypeOnly,\n );\n\n if (element !== undefined) {\n return element;\n }\n }\n }\n\n return undefined;\n };\n\n /**\n * The local name `call` can use for `ParseUtility`, or the reason it cannot. The name resolves from the\n * scope of the call, the way the store receiver does: the file's own import of `ParseUtility` from the store\n * module (under any local name) when it is the binding the call sees, a new `ParseUtility` import when\n * nothing in the file or in a scope around the call declares that name. Another module's `ParseUtility`, a\n * type-only import of it, a local declaration of it and a parameter that shadows it all leave the call manual,\n * because the rewrite would not compile (TS2300, TS2339).\n */\n const resolveParseUtility = (\n call: import('typescript').CallExpression,\n ): { name: string } | { reason: string } => {\n const existing = findParseUtilityImport();\n const name = existing?.name.text ?? 'ParseUtility';\n let found: import('typescript').Node | undefined;\n let isFileLevel = false;\n\n for (\n let scope: import('typescript').Node | undefined = call.parent;\n scope !== undefined && found === undefined;\n scope = scope.parent\n ) {\n found = EnvGet.declarationIn({ typescript: ts, scope, name });\n isFileLevel = ts.isSourceFile(scope);\n }\n\n if (found === existing) {\n return { name };\n }\n\n return {\n reason: isFileLevel\n ? `${name} is already declared in this file by something other than a value import from @venizia/ignis-helpers (an import from another module, a type-only import or a local declaration): the rewrite would not compile, so import ParseUtility from @venizia/ignis-helpers under a free name and write the transform by hand`\n : `a parameter or local declaration named ${name} hides the ParseUtility import at this call: the rewrite would not compile, so write the transform by hand or rename the local`,\n };\n };\n\n /** Adds `ParseUtility` to the import of the store, once per file: on its own line inside a multi-line import, after the last name in a one-line one, in a new import beside a type-only one. */\n const addParseUtilityImport = (storeImport: import('typescript').ImportSpecifier): void => {\n if (isParseUtilityImported || findParseUtilityImport() !== undefined) {\n return;\n }\n\n isParseUtilityImported = true;\n\n const declaration = storeImport.parent.parent.parent;\n const named = storeImport.parent;\n\n if (declaration.importClause?.isTypeOnly) {\n edits.push({\n start: declaration.getEnd(),\n end: declaration.getEnd(),\n text: `\\nimport { ParseUtility } from ${declaration.moduleSpecifier.getText(file)};`,\n });\n\n return;\n }\n\n const last = named.elements[named.elements.length - 1];\n const lastLine = file.getLineAndCharacterOfPosition(last.getStart(file)).line;\n const isMultiLine = file.getLineAndCharacterOfPosition(named.getStart(file)).line < lastLine;\n\n if (!isMultiLine) {\n edits.push({ start: last.getEnd(), end: last.getEnd(), text: ', ParseUtility' });\n\n return;\n }\n\n const lineStart = file.getLineStarts()[lastLine];\n const indent = source.slice(lineStart, last.getStart(file)).match(/^\\s*/)?.[0] ?? '';\n const lineBreak = source.includes('\\r\\n') ? '\\r\\n' : '\\n';\n\n edits.push({\n start: last.getEnd(),\n end: last.getEnd(),\n text: `,${lineBreak}${indent}ParseUtility`,\n });\n };\n\n /** Puts `transform` first in the options literal, keeping its layout: `{}` becomes `{ transform }`, a multi-line literal gets the property on its own line. */\n const insertTransform = (\n options: import('typescript').ObjectLiteralExpression,\n transform: string,\n ): void => {\n const open = options.getStart(file) + 1;\n const [first] = options.properties;\n\n if (first === undefined) {\n const inner = source.slice(open, options.getEnd() - 1);\n\n edits.push(\n inner.trim() === ''\n ? { start: open, end: options.getEnd() - 1, text: ` ${transform} ` }\n : { start: open, end: open, text: ` ${transform}` },\n );\n\n return;\n }\n\n const between = source.slice(open, first.getStart(file));\n\n if (between.includes('\\n')) {\n const firstLineStart =\n file.getLineStarts()[file.getLineAndCharacterOfPosition(first.getStart(file)).line];\n const indent = source.slice(firstLineStart, first.getStart(file)).match(/^\\s*/)?.[0] ?? '';\n const lineBreak = between.includes('\\r\\n') ? '\\r\\n' : '\\n';\n\n edits.push({ start: open, end: open, text: `${lineBreak}${indent}${transform},` });\n\n return;\n }\n\n edits.push({\n start: open,\n end: open,\n text: ` ${transform},${/^\\s/.test(between) ? '' : ' '}`,\n });\n };\n\n const visit = (node: import('typescript').Node): void => {\n if (\n ts.isCallExpression(node) &&\n node.typeArguments !== undefined &&\n ts.isPropertyAccessExpression(node.expression) &&\n node.expression.name.text === 'get'\n ) {\n const callee = node.expression;\n const isOptional =\n node.questionDotToken !== undefined || callee.questionDotToken !== undefined;\n\n const storeImport =\n !isOptional && ts.isIdentifier(callee.expression)\n ? EnvGet.storeImport({ typescript: ts, identifier: callee.expression })\n : undefined;\n\n if (storeImport !== undefined) {\n const [first] = node.typeArguments;\n const start = callee.name.getEnd();\n const end = node.arguments.pos - 1;\n const options = node.arguments[1];\n const isTwo = node.typeArguments.length === 2;\n const isPlainLiteral =\n options !== undefined &&\n ts.isObjectLiteralExpression(options) &&\n !hasTransform(options);\n // `get<number>(key)`, `get<number>(key, { defaultValue })` and `get<number, B>(key, { defaultValue })` are one read.\n const isNumberRead =\n numbers &&\n isNumberType(first) &&\n ((!isTwo &&\n !hasTransform(options) &&\n (options === undefined || ts.isObjectLiteralExpression(options))) ||\n (isTwo && isPlainLiteral));\n // `--numbers`: a number read (one type argument or two) with options the codemod cannot read. It cannot see\n // whether they hold a transform, so the call is listed, not left silently.\n const isNumberReadWithVariableOptions =\n numbers &&\n isNumberType(first) &&\n options !== undefined &&\n !ts.isObjectLiteralExpression(options);\n\n if (isNumberReadWithVariableOptions) {\n manual.push({\n line: lineOf(node),\n type: first.getText(file),\n reason:\n 'the options are not an object literal, so the codemod cannot see whether they hold a transform: put the number transform in them by hand, for example { ...options, transform: (raw) => ParseUtility.toNumber({ input: raw }) }',\n });\n } else if (isNumberRead) {\n const parseUtility = resolveParseUtility(node);\n\n if ('reason' in parseUtility) {\n manual.push({\n line: lineOf(node),\n type: first.getText(file),\n reason: parseUtility.reason,\n });\n } else if (hasNonNumericDefault(options)) {\n manual.push({\n line: lineOf(node),\n type: first.getText(file),\n reason:\n 'the defaultValue is a literal that is not a number: the rewritten call matches no overload (and would return that value as it is), so give it a number or convert it where you use it',\n });\n } else {\n addParseUtilityImport(storeImport);\n\n const transform = `transform: (raw) => ${parseUtility.name}.toNumber({ input: raw })`;\n\n edits.push({ start, end, text: '' });\n\n if (options !== undefined && ts.isObjectLiteralExpression(options)) {\n insertTransform(options, transform);\n } else {\n const insertAt = node.arguments[0].getEnd();\n\n edits.push({ start: insertAt, end: insertAt, text: `, { ${transform} }` });\n }\n\n numbered.push(lineOf(node));\n rewrittenCalls += 1;\n }\n } else if (isTwo && options !== undefined && !ts.isObjectLiteralExpression(options)) {\n // `get<R, B>(key, options)` with options in a variable: the codemod cannot see whether they hold a\n // transform or a default of the right type, and `get<R>(key, options)` may not compile with them.\n manual.push({\n line: lineOf(node),\n type: first.getText(file),\n reason:\n 'two type arguments and options that are not an object literal, so the codemod cannot see what they hold: drop the second type argument by hand once the options carry a transform',\n });\n } else if (isTwo && hasTransform(options)) {\n // `get<R, B>(key, { transform })` keeps R, even when R is `string`: a second run leaves\n // `get<string>(key, { transform })` alone.\n edits.push({ start, end, text: `<${first.getText(file)}>` });\n rewrittenCalls += 1;\n } else if (\n !isTwo &&\n options !== undefined &&\n (hasTransform(options) || !ts.isObjectLiteralExpression(options))\n ) {\n // One type argument and a transform: the new form. One type argument and options that are not a\n // literal (a variable): the codemod cannot see what they hold, and what it just left in\n // `get<R, B>(key, options)` would otherwise be listed on the next run; the typecheck names a bad one.\n // Nothing to do and nothing to list.\n } else if (isStringType(first) && (!isTwo || isPlainLiteral)) {\n // `string` is what get() returns without a transform, so the type arguments carry nothing: a literal\n // without a transform reads the same with one type argument or two.\n edits.push({ start, end, text: '' });\n rewrittenCalls += 1;\n } else {\n manual.push({ line: lineOf(node), type: first.getText(file) });\n }\n } else if (node.arguments.length > 0 && !ts.isObjectLiteralExpression(node.arguments[0])) {\n // Every other `x.get<T>(key)` is listed, never hidden: a name the file does not bind to the store, a\n // property, a parameter or an optional chain. A container lookup shares the shape (its first\n // argument is an object literal, so it is not listed).\n skipped.push({ line: lineOf(node), receiver: callee.expression.getText(file) });\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, numbered, skipped };\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 {\n output,\n changed: output !== source,\n rewritten: rewrittenCalls,\n manual,\n numbered,\n skipped,\n };\n }\n}\n\n/** `devz codemod env-get [paths...] [--write | --check]`: rewrites the type arguments of `applicationEnvironment.get()`. */\nexport class EnvGetCommand {\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(EnvGetFlags.HELP) || args.includes(EnvGetFlags.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) => !EnvGetFlags.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(EnvGetFlags.WRITE);\n const isCheck = flags.includes(EnvGetFlags.CHECK);\n const isNumbers = flags.includes(EnvGetFlags.NUMBERS);\n\n if (isWrite && isCheck) {\n console.error(\n `devz codemod: ${EnvGetFlags.WRITE} and ${EnvGetFlags.CHECK} contradict each other\\n${USAGE}`,\n );\n\n return USAGE_ERROR_CODE;\n }\n\n const refusal = CodemodFiles.refusal({\n command: 'env-get',\n isWrite,\n isAll: flags.includes(EnvGetFlags.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 callCount = 0;\n let manualCount = 0;\n let skippedCount = 0;\n let numberedCount = 0;\n const manualByType = new Map<string, number>();\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 (!/\\.\\s*get\\b/.test(source)) {\n continue;\n }\n\n const result = EnvGet.rewrite({\n typescript,\n fileName: file,\n source,\n numbers: isNumbers,\n });\n const shown = relative(root, file).split('\\\\').join('/') || file;\n\n for (const item of result.manual) {\n manualCount += 1;\n manualByType.set(item.type, (manualByType.get(item.type) ?? 0) + 1);\n console.warn(\n `manual ${shown}:${item.line} get<${item.type}>: ${\n item.reason ??\n 'a type argument the rewrite cannot place (not string or string | undefined, or two type arguments without an options argument): a number or other conversion goes in a transform, for example get(key, { transform: Number })'\n }`,\n );\n }\n\n for (const line of result.numbered) {\n numberedCount += 1;\n console.log(\n `numbers ${shown}:${line} get<number> rewritten to a transform: the value is now a real number and a non-numeric value throws at the read`,\n );\n }\n\n for (const call of result.skipped) {\n skippedCount += 1;\n console.warn(\n `skipped ${shown}:${call.line} ${call.receiver}.get<...>(): the receiver is not bound to applicationEnvironment or AppEnvs in this file (a property, a parameter, an optional chain or another object): check it by hand if it is the environment store`,\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 callCount += result.rewritten;\n console.log(\n `${isWrite ? 'changed' : 'would change'} ${shown} (${result.rewritten} call(s))`,\n );\n\n if (isWrite) {\n writeFileSync(file, result.output);\n }\n }\n }\n\n console.log(\n `devz codemod env-get: ${changedCount} file(s) ${isWrite ? 'changed' : 'would change'}, ${callCount} call(s) ${isWrite ? 'rewritten' : 'would be rewritten'}, ${manualCount} manual, ${skippedCount} skipped` +\n (isNumbers ? `, ${numberedCount} number read(s) rewritten` : '') +\n (refusedCount > 0 ? `, ${refusedCount} refused` : ''),\n );\n\n if (manualByType.size > 0) {\n const counts = [...manualByType.entries()]\n .sort((left, right) => right[1] - left[1])\n .map(([typeText, count]) => `${typeText} x${count}`)\n .join(', ');\n\n console.log(`manual by type argument: ${counts}`);\n }\n\n if (!isWrite && changedCount > 0) {\n console.log(\n `Nothing was written. Run again with ${EnvGetFlags.WRITE} to apply, then run your typecheck.`,\n );\n }\n\n if (isWrite && refusedCount > 0) {\n return 1;\n }\n\n return isCheck && (changedCount > 0 || manualCount > 0) ? 1 : 0;\n }\n}\n"]}
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CodemodCommand = void 0;
4
+ const any_aliases_1 = require("./any-aliases");
4
5
  const async_style_1 = require("./async-style");
5
6
  const connector_imports_1 = require("./connector-imports");
6
7
  const const_classes_1 = require("./const-classes");
8
+ const env_get_1 = require("./env-get");
7
9
  const drop_redundant_casts_1 = require("./drop-redundant-casts");
8
10
  const namespace_functions_1 = require("./namespace-functions");
9
11
  const USAGE = [
@@ -12,22 +14,43 @@ const USAGE = [
12
14
  async_style_1.AsyncStyleCommand.USAGE,
13
15
  namespace_functions_1.NamespaceFunctionsCommand.USAGE,
14
16
  connector_imports_1.ConnectorImportsCommand.USAGE,
17
+ env_get_1.EnvGetCommand.USAGE,
18
+ any_aliases_1.AnyAliasesCommand.USAGE,
15
19
  ].join('\n\n');
16
20
  /** The codemods `devz codemod <name>` runs. */
17
- const NAMES = [
21
+ const NAME_LIST = [
18
22
  'drop-redundant-casts',
19
23
  'const-classes',
20
24
  'async-style',
21
25
  'namespace-functions',
22
26
  'connector-imports',
23
- ].join(', ');
27
+ 'env-get',
28
+ 'any-aliases',
29
+ ];
30
+ const NAMES = NAME_LIST.join(', ');
24
31
  /** A usage error: nothing was read or written. */
25
32
  const USAGE_ERROR_CODE = 2;
33
+ /** The codemods that are style rewrites, not migrations: there is no downgrade of them. */
34
+ const NOT_REVERSIBLE = new Set([
35
+ 'drop-redundant-casts',
36
+ 'const-classes',
37
+ 'async-style',
38
+ 'env-get',
39
+ 'any-aliases',
40
+ ]);
26
41
  /** `devz codemod <name> [args]`: hands the arguments to the codemod called `name`. */
27
42
  class CodemodCommand {
28
43
  static async run(opts) {
29
44
  const { args } = opts;
30
45
  const [name, ...rest] = args;
46
+ if (name === '--list') {
47
+ console.log(NAME_LIST.join('\n'));
48
+ return 0;
49
+ }
50
+ if (name !== undefined && NOT_REVERSIBLE.has(name) && rest.includes('--reverse')) {
51
+ console.error(`devz codemod ${name}: not reversible`);
52
+ return USAGE_ERROR_CODE;
53
+ }
31
54
  if (name === 'drop-redundant-casts') {
32
55
  return drop_redundant_casts_1.DropRedundantCastsCommand.run({ root: opts.root, args: rest });
33
56
  }
@@ -43,6 +66,12 @@ class CodemodCommand {
43
66
  if (name === 'connector-imports') {
44
67
  return connector_imports_1.ConnectorImportsCommand.run({ root: opts.root, args: rest });
45
68
  }
69
+ if (name === 'env-get') {
70
+ return env_get_1.EnvGetCommand.run({ root: opts.root, args: rest });
71
+ }
72
+ if (name === 'any-aliases') {
73
+ return any_aliases_1.AnyAliasesCommand.run({ root: opts.root, args: rest });
74
+ }
46
75
  if (args.includes('--help') || args.includes('-h')) {
47
76
  console.log(USAGE);
48
77
  return 0;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cli/codemod/index.ts"],"names":[],"mappings":";;;AAAA,+CAAkD;AAClD,2DAA8D;AAC9D,mDAAsD;AACtD,iEAAmE;AACnE,+DAAkE;AAElE,MAAM,KAAK,GAAG;IACZ,gDAAyB,CAAC,KAAK;IAC/B,mCAAmB,CAAC,KAAK;IACzB,+BAAiB,CAAC,KAAK;IACvB,+CAAyB,CAAC,KAAK;IAC/B,2CAAuB,CAAC,KAAK;CAC9B,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAEf,+CAA+C;AAC/C,MAAM,KAAK,GAAG;IACZ,sBAAsB;IACtB,eAAe;IACf,aAAa;IACb,qBAAqB;IACrB,mBAAmB;CACpB,CAAC,IAAI,CAAC,IAAI,CAAC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O,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YAEnB,OAAO,CAAC,CAAC;QACX,CAAC;QAED,OAAO,CAAC,KAAK,CACX,kCAAkC,IAAI,IAAI,EAAE,yBAAyB,KAAK,OAAO,KAAK,EAAE,CACzF,CAAC;QAEF,OAAO,gBAAgB,CAAC;IAC1B,CAAC;CACF;AArCD,wCAqCC","sourcesContent":["import { AsyncStyleCommand } from './async-style';\nimport { ConnectorImportsCommand } from './connector-imports';\nimport { ConstClassesCommand } from './const-classes';\nimport { DropRedundantCastsCommand } from './drop-redundant-casts';\nimport { NamespaceFunctionsCommand } from './namespace-functions';\n\nconst USAGE = [\n DropRedundantCastsCommand.USAGE,\n ConstClassesCommand.USAGE,\n AsyncStyleCommand.USAGE,\n NamespaceFunctionsCommand.USAGE,\n ConnectorImportsCommand.USAGE,\n].join('\\n\\n');\n\n/** The codemods `devz codemod <name>` runs. */\nconst NAMES = [\n 'drop-redundant-casts',\n 'const-classes',\n 'async-style',\n 'namespace-functions',\n 'connector-imports',\n].join(', ');\n\n/** A usage error: nothing was read or written. */\nconst USAGE_ERROR_CODE = 2;\n\n/** `devz codemod <name> [args]`: hands the arguments to the codemod called `name`. */\nexport class CodemodCommand {\n static async run(opts: { root: string; args: string[] }): Promise<number> {\n const { args } = opts;\n const [name, ...rest] = args;\n\n if (name === 'drop-redundant-casts') {\n return DropRedundantCastsCommand.run({ root: opts.root, args: rest });\n }\n\n if (name === 'const-classes') {\n return ConstClassesCommand.run({ root: opts.root, args: rest });\n }\n\n if (name === 'async-style') {\n return AsyncStyleCommand.run({ root: opts.root, args: rest });\n }\n\n if (name === 'namespace-functions') {\n return NamespaceFunctionsCommand.run({ root: opts.root, args: rest });\n }\n\n if (name === 'connector-imports') {\n return ConnectorImportsCommand.run({ root: opts.root, args: rest });\n }\n\n if (args.includes('--help') || args.includes('-h')) {\n console.log(USAGE);\n\n return 0;\n }\n\n console.error(\n `devz codemod: unknown codemod \"${name ?? ''}\" | the codemods are: ${NAMES}\\n\\n${USAGE}`,\n );\n\n return USAGE_ERROR_CODE;\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cli/codemod/index.ts"],"names":[],"mappings":";;;AAAA,+CAAkD;AAClD,+CAAkD;AAClD,2DAA8D;AAC9D,mDAAsD;AACtD,uCAA0C;AAC1C,iEAAmE;AACnE,+DAAkE;AAElE,MAAM,KAAK,GAAG;IACZ,gDAAyB,CAAC,KAAK;IAC/B,mCAAmB,CAAC,KAAK;IACzB,+BAAiB,CAAC,KAAK;IACvB,+CAAyB,CAAC,KAAK;IAC/B,2CAAuB,CAAC,KAAK;IAC7B,uBAAa,CAAC,KAAK;IACnB,+BAAiB,CAAC,KAAK;CACxB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAEf,+CAA+C;AAC/C,MAAM,SAAS,GAAG;IAChB,sBAAsB;IACtB,eAAe;IACf,aAAa;IACb,qBAAqB;IACrB,mBAAmB;IACnB,SAAS;IACT,aAAa;CACd,CAAC;AACF,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEnC,kDAAkD;AAClD,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAE3B,2FAA2F;AAC3F,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC;IAC7B,sBAAsB;IACtB,eAAe;IACf,aAAa;IACb,SAAS;IACT,aAAa;CACd,CAAC,CAAC;AAEH,sFAAsF;AACtF,MAAa,cAAc;IACzB,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,IAAsC;QACrD,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;QACtB,MAAM,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;QAE7B,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;YACtB,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;YAElC,OAAO,CAAC,CAAC;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,IAAI,EAAE,CAAC,CAAC;QAC5D,CAAC;QAED,IAAI,IAAI,KAAK,aAAa,EAAE,CAAC;YAC3B,OAAO,+BAAiB,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QAChE,CAAC;QAED,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YACnD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YAEnB,OAAO,CAAC,CAAC;QACX,CAAC;QAED,OAAO,CAAC,KAAK,CACX,kCAAkC,IAAI,IAAI,EAAE,yBAAyB,KAAK,OAAO,KAAK,EAAE,CACzF,CAAC;QAEF,OAAO,gBAAgB,CAAC;IAC1B,CAAC;CACF;AAzDD,wCAyDC","sourcesContent":["import { AnyAliasesCommand } from './any-aliases';\nimport { AsyncStyleCommand } from './async-style';\nimport { ConnectorImportsCommand } from './connector-imports';\nimport { ConstClassesCommand } from './const-classes';\nimport { EnvGetCommand } from './env-get';\nimport { DropRedundantCastsCommand } from './drop-redundant-casts';\nimport { NamespaceFunctionsCommand } from './namespace-functions';\n\nconst USAGE = [\n DropRedundantCastsCommand.USAGE,\n ConstClassesCommand.USAGE,\n AsyncStyleCommand.USAGE,\n NamespaceFunctionsCommand.USAGE,\n ConnectorImportsCommand.USAGE,\n EnvGetCommand.USAGE,\n AnyAliasesCommand.USAGE,\n].join('\\n\\n');\n\n/** The codemods `devz codemod <name>` runs. */\nconst NAME_LIST = [\n 'drop-redundant-casts',\n 'const-classes',\n 'async-style',\n 'namespace-functions',\n 'connector-imports',\n 'env-get',\n 'any-aliases',\n];\nconst NAMES = NAME_LIST.join(', ');\n\n/** A usage error: nothing was read or written. */\nconst USAGE_ERROR_CODE = 2;\n\n/** The codemods that are style rewrites, not migrations: there is no downgrade of them. */\nconst NOT_REVERSIBLE = new Set([\n 'drop-redundant-casts',\n 'const-classes',\n 'async-style',\n 'env-get',\n 'any-aliases',\n]);\n\n/** `devz codemod <name> [args]`: hands the arguments to the codemod called `name`. */\nexport class CodemodCommand {\n static async run(opts: { root: string; args: string[] }): Promise<number> {\n const { args } = opts;\n const [name, ...rest] = args;\n\n if (name === '--list') {\n console.log(NAME_LIST.join('\\n'));\n\n return 0;\n }\n\n if (name !== undefined && NOT_REVERSIBLE.has(name) && rest.includes('--reverse')) {\n console.error(`devz codemod ${name}: not reversible`);\n\n return USAGE_ERROR_CODE;\n }\n\n if (name === 'drop-redundant-casts') {\n return DropRedundantCastsCommand.run({ root: opts.root, args: rest });\n }\n\n if (name === 'const-classes') {\n return ConstClassesCommand.run({ root: opts.root, args: rest });\n }\n\n if (name === 'async-style') {\n return AsyncStyleCommand.run({ root: opts.root, args: rest });\n }\n\n if (name === 'namespace-functions') {\n return NamespaceFunctionsCommand.run({ root: opts.root, args: rest });\n }\n\n if (name === 'connector-imports') {\n return ConnectorImportsCommand.run({ root: opts.root, args: rest });\n }\n\n if (name === 'env-get') {\n return EnvGetCommand.run({ root: opts.root, args: rest });\n }\n\n if (name === 'any-aliases') {\n return AnyAliasesCommand.run({ root: opts.root, args: rest });\n }\n\n if (args.includes('--help') || args.includes('-h')) {\n console.log(USAGE);\n\n return 0;\n }\n\n console.error(\n `devz codemod: unknown codemod \"${name ?? ''}\" | the codemods are: ${NAMES}\\n\\n${USAGE}`,\n );\n\n return USAGE_ERROR_CODE;\n }\n}\n"]}
@@ -2,6 +2,7 @@ import { type INamespaceMapping } from './mapping';
2
2
  export * from './logger-scope';
3
3
  export * from './mapping';
4
4
  export * from './mappings';
5
+ export * from './reverse';
5
6
  export * from './rewriter';
6
7
  /**
7
8
  * `devz codemod namespace-functions [paths...] [--write | --check]`: rewrites the calls of the
@@ -9,7 +10,7 @@ export * from './rewriter';
9
10
  * `--check` is the same dry run, and exits 1 while a call can be rewritten or is left untouched.
10
11
  */
11
12
  export declare class NamespaceFunctionsCommand {
12
- static readonly USAGE = "Usage: devz codemod namespace-functions [paths...] [--write | --check]\n\nMoves calls of an IGNIS function that now lives in a class to the class form, with one options\nobject: `oldName(a, b)` becomes `ClassName.method({ first: a, second: b })`, and an argument named\nlike its key is written short (`{ first }`). The old names are removed from the packages, so run it\nonce after you upgrade. A table in @venizia/dev-configs names each moved function.\n\nIt follows a named import (aliased too) and a namespace import (`ns.oldName(...)`) from a module the\ntable lists, adds the class to that import, and drops the old name once nothing else uses it. It lists\nwith its file and line, and leaves for you: a call with a spread argument or the wrong number of\narguments, the old name used as a value (passed, stored, exported, in typeof), a re-export, a type-only\nimport, and a file that declares a name the rewrite would collide with.\n\nIt also moves the removed `ApplicationLogger`: `ApplicationLogger.get('scope')`, `.get(NAME)` and\n`.get({ scope: NAME })` become `LoggerFactory.getLogger(['scope'])`, `([NAME])`, and the import follows, when\n`ApplicationLogger` comes from `@venizia/ignis-helpers` or `@venizia/ignis`. `Logger.get` and\n`HfLogger.get` are not touched, and a call it cannot decide is listed, as is any other use of\n`ApplicationLogger` (a type, a re-export, a value). An identifier argument is taken for a scope: run your\ntypecheck afterwards.\n\n --write write the changed files (without it, nothing is written)\n --check dry run that exits 1 while a call can be rewritten or is left untouched (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\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.";
13
+ static readonly USAGE = "Usage: devz codemod namespace-functions [paths...] [--write | --check] [--reverse]\n\nMoves calls of an IGNIS function that now lives in a class to the class form, with one options\nobject: `oldName(a, b)` becomes `ClassName.method({ first: a, second: b })`, and an argument named\nlike its key is written short (`{ first }`). The old names are removed from the packages, so run it\nonce after you upgrade. A table in @venizia/dev-configs names each moved function.\n\nIt follows a named import (aliased too) and a namespace import (`ns.oldName(...)`) from a module the\ntable lists, adds the class to that import, and drops the old name once nothing else uses it. It lists\nwith its file and line, and leaves for you: a call with a spread argument or the wrong number of\narguments, the old name used as a value (passed, stored, exported, in typeof), a re-export, a type-only\nimport, and a file that declares a name the rewrite would collide with.\n\nIt also moves the removed `ApplicationLogger`: `ApplicationLogger.get('scope')`, `.get(NAME)` and\n`.get({ scope: NAME })` become `LoggerFactory.getLogger(['scope'])`, `([NAME])`, and the import follows, when\n`ApplicationLogger` comes from `@venizia/ignis-helpers` or `@venizia/ignis`. `Logger.get` and\n`HfLogger.get` are not touched, and a call it cannot decide is listed, as is any other use of\n`ApplicationLogger` (a type, a re-export, a value). An identifier argument is taken for a scope: run your\ntypecheck afterwards.\n\n --write write the changed files (without it, nothing is written)\n --check dry run that exits 1 while a call can be rewritten or is left untouched (for CI)\n --reverse apply the table backward, for a downgrade: `ClassName.method({ first: a })` becomes\n `oldName(a)` and the import follows. The `ApplicationLogger` rule is not reversed.\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.";
13
14
  static run(opts: {
14
15
  root: string;
15
16
  args: string[];
@@ -21,12 +21,14 @@ const files_1 = require("../files");
21
21
  const mapping_1 = require("./mapping");
22
22
  const mappings_1 = require("./mappings");
23
23
  const logger_scope_1 = require("./logger-scope");
24
+ const reverse_1 = require("./reverse");
24
25
  const rewriter_1 = require("./rewriter");
25
26
  __exportStar(require("./logger-scope"), exports);
26
27
  __exportStar(require("./mapping"), exports);
27
28
  __exportStar(require("./mappings"), exports);
29
+ __exportStar(require("./reverse"), exports);
28
30
  __exportStar(require("./rewriter"), exports);
29
- const USAGE = `Usage: devz codemod namespace-functions [paths...] [--write | --check]
31
+ const USAGE = `Usage: devz codemod namespace-functions [paths...] [--write | --check] [--reverse]
30
32
 
31
33
  Moves calls of an IGNIS function that now lives in a class to the class form, with one options
32
34
  object: \`oldName(a, b)\` becomes \`ClassName.method({ first: a, second: b })\`, and an argument named
@@ -48,6 +50,8 @@ typecheck afterwards.
48
50
 
49
51
  --write write the changed files (without it, nothing is written)
50
52
  --check dry run that exits 1 while a call can be rewritten or is left untouched (for CI)
53
+ --reverse apply the table backward, for a downgrade: \`ClassName.method({ first: a })\` becomes
54
+ \`oldName(a)\` and the import follows. The \`ApplicationLogger\` rule is not reversed.
51
55
  --help print this text and exit
52
56
 
53
57
  With no flag it lists what would change and writes nothing. Inside a git repository it reads the
@@ -58,11 +62,13 @@ const USAGE_ERROR_CODE = 2;
58
62
  class NamespaceFunctionsFlags {
59
63
  static { this.WRITE = '--write'; }
60
64
  static { this.CHECK = '--check'; }
65
+ static { this.REVERSE = '--reverse'; }
61
66
  static { this.HELP = '--help'; }
62
67
  static { this.HELP_SHORT = '-h'; }
63
68
  static { this.SCHEME_SET = new Set([
64
69
  this.WRITE,
65
70
  this.CHECK,
71
+ this.REVERSE,
66
72
  this.HELP,
67
73
  this.HELP_SHORT,
68
74
  ]); }
@@ -93,6 +99,7 @@ class NamespaceFunctionsCommand {
93
99
  }
94
100
  const isWrite = flags.includes(NamespaceFunctionsFlags.WRITE);
95
101
  const isCheck = flags.includes(NamespaceFunctionsFlags.CHECK);
102
+ const isReverse = flags.includes(NamespaceFunctionsFlags.REVERSE);
96
103
  if (isWrite && isCheck) {
97
104
  console.error(`devz codemod: ${NamespaceFunctionsFlags.WRITE} and ${NamespaceFunctionsFlags.CHECK} contradict each other\n${USAGE}`);
98
105
  return USAGE_ERROR_CODE;
@@ -116,7 +123,7 @@ class NamespaceFunctionsCommand {
116
123
  return 1;
117
124
  }
118
125
  // Identifiers only (the table is validated), so the names need no escaping.
119
- const nameText = new RegExp(`\\b(?:${[...new Set(mappings.map((mapping) => mapping.oldName))].join('|')})\\b`);
126
+ const nameText = new RegExp(`\\b(?:${[...new Set(mappings.map((mapping) => (isReverse ? mapping.className : mapping.oldName)))].join('|')})\\b`);
120
127
  const targets = (paths.length > 0 ? paths : ['.']).map((path) => (0, node_path_1.resolve)(root, path));
121
128
  let changedCount = 0;
122
129
  let callCount = 0;
@@ -130,14 +137,16 @@ class NamespaceFunctionsCommand {
130
137
  }
131
138
  for (const file of files) {
132
139
  const source = (0, node_fs_1.readFileSync)(file, 'utf8');
133
- if (!nameText.test(source) && !logger_scope_1.LoggerScopeRewriter.mentions({ source })) {
140
+ if (!nameText.test(source) && (isReverse || !logger_scope_1.LoggerScopeRewriter.mentions({ source }))) {
134
141
  continue;
135
142
  }
136
143
  const shown = (0, node_path_1.relative)(root, file).split('\\').join('/') || file;
137
144
  // The call-shape rule goes first, and its edits are inside one call, so the lines the table pass reports stay
138
145
  // those of the file unless a multi-line `ApplicationLogger.get({ ... })` collapsed onto one line.
139
- const scoped = logger_scope_1.LoggerScopeRewriter.rewrite({ typescript, fileName: file, source });
140
- const tabled = rewriter_1.NamespaceFunctions.rewrite({
146
+ const scoped = isReverse
147
+ ? { output: source, changed: false, rewritten: 0, reports: [] }
148
+ : logger_scope_1.LoggerScopeRewriter.rewrite({ typescript, fileName: file, source });
149
+ const tabled = (isReverse ? reverse_1.NamespaceFunctionsReverse : rewriter_1.NamespaceFunctions).rewrite({
141
150
  typescript,
142
151
  fileName: file,
143
152
  source: scoped.output,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/cli/codemod/namespace-functions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,qCAAsD;AACtD,yCAA8C;AAC9C,oCAAwC;AACxC,uCAAsE;AACtE,yCAA0C;AAC1C,iDAAqD;AACrD,yCAAgD;AAEhD,iDAA+B;AAC/B,4CAA0B;AAC1B,6CAA2B;AAC3B,6CAA2B;AAE3B,MAAM,KAAK,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;uFA0ByE,CAAC;AAExF,kDAAkD;AAClD,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAE3B,MAAM,uBAAuB;aACX,UAAK,GAAG,SAAS,CAAC;aAClB,UAAK,GAAG,SAAS,CAAC;aAClB,SAAI,GAAG,QAAQ,CAA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readFileSync, writeFileSync } from 'node:fs';\nimport { relative, resolve } from 'node:path';\nimport { CodemodFiles } from '../files';\nimport { type INamespaceMapping, NamespaceMappings } from './mapping';\nimport { ALL_MAPPINGS } from './mappings';\nimport { LoggerScopeRewriter } from './logger-scope';\nimport { NamespaceFunctions } from './rewriter';\n\nexport * from './logger-scope';\nexport * from './mapping';\nexport * from './mappings';\nexport * from './rewriter';\n\nconst USAGE = `Usage: devz codemod namespace-functions [paths...] [--write | --check]\n\nMoves calls of an IGNIS function that now lives in a class to the class form, with one options\nobject: \\`oldName(a, b)\\` becomes \\`ClassName.method({ first: a, second: b })\\`, and an argument named\nlike its key is written short (\\`{ first }\\`). The old names are removed from the packages, so run it\nonce after you upgrade. A table in @venizia/dev-configs names each moved function.\n\nIt follows a named import (aliased too) and a namespace import (\\`ns.oldName(...)\\`) from a module the\ntable lists, adds the class to that import, and drops the old name once nothing else uses it. It lists\nwith its file and line, and leaves for you: a call with a spread argument or the wrong number of\narguments, the old name used as a value (passed, stored, exported, in typeof), a re-export, a type-only\nimport, and a file that declares a name the rewrite would collide with.\n\nIt also moves the removed \\`ApplicationLogger\\`: \\`ApplicationLogger.get('scope')\\`, \\`.get(NAME)\\` and\n\\`.get({ scope: NAME })\\` become \\`LoggerFactory.getLogger(['scope'])\\`, \\`([NAME])\\`, and the import follows, when\n\\`ApplicationLogger\\` comes from \\`@venizia/ignis-helpers\\` or \\`@venizia/ignis\\`. \\`Logger.get\\` and\n\\`HfLogger.get\\` are not touched, and a call it cannot decide is listed, as is any other use of\n\\`ApplicationLogger\\` (a type, a re-export, a value). An identifier argument is taken for a scope: run your\ntypecheck afterwards.\n\n --write write the changed files (without it, nothing is written)\n --check dry run that exits 1 while a call can be rewritten or is left untouched (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\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\nclass NamespaceFunctionsFlags {\n static readonly WRITE = '--write';\n static readonly CHECK = '--check';\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.HELP,\n this.HELP_SHORT,\n ]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/**\n * `devz codemod namespace-functions [paths...] [--write | --check]`: rewrites the calls of the\n * functions the mapping table lists to their class form. It is a dry run unless `--write` is given.\n * `--check` is the same dry run, and exits 1 while a call can be rewritten or is left untouched.\n */\nexport class NamespaceFunctionsCommand {\n static readonly USAGE = USAGE;\n\n static async run(opts: {\n root: string;\n args: string[];\n /** The table to apply; the one this package ships by default. */\n mappings?: ReadonlyArray<INamespaceMapping>;\n }): Promise<number> {\n const { root, args, mappings = ALL_MAPPINGS } = opts;\n\n if (\n args.includes(NamespaceFunctionsFlags.HELP) ||\n args.includes(NamespaceFunctionsFlags.HELP_SHORT)\n ) {\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) => !NamespaceFunctionsFlags.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(NamespaceFunctionsFlags.WRITE);\n const isCheck = flags.includes(NamespaceFunctionsFlags.CHECK);\n\n if (isWrite && isCheck) {\n console.error(\n `devz codemod: ${NamespaceFunctionsFlags.WRITE} and ${NamespaceFunctionsFlags.CHECK} contradict each other\\n${USAGE}`,\n );\n\n return USAGE_ERROR_CODE;\n }\n\n const problems = NamespaceMappings.validate({ mappings });\n\n if (problems.length > 0) {\n console.error(\n `devz codemod namespace-functions: the mapping table is broken:\\n${problems.map((problem) => ` ${problem}`).join('\\n')}`,\n );\n\n return 1;\n }\n\n if (mappings.length === 0) {\n console.log(\n 'devz codemod namespace-functions: the mapping table of this version is empty, so there is nothing to rewrite',\n );\n\n return 0;\n }\n\n let typescript: typeof import('typescript');\n\n try {\n const result2 = await import('typescript');\n typescript = result2.default;\n } catch {\n console.error('devz codemod: the \"typescript\" package is required to read your sources');\n\n return 1;\n }\n\n // Identifiers only (the table is validated), so the names need no escaping.\n const nameText = new RegExp(\n `\\\\b(?:${[...new Set(mappings.map((mapping) => mapping.oldName))].join('|')})\\\\b`,\n );\n const targets = (paths.length > 0 ? paths : ['.']).map((path) => resolve(root, path));\n let changedCount = 0;\n let callCount = 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 (!nameText.test(source) && !LoggerScopeRewriter.mentions({ source })) {\n continue;\n }\n\n const shown = relative(root, file).split('\\\\').join('/') || file;\n // The call-shape rule goes first, and its edits are inside one call, so the lines the table pass reports stay\n // those of the file unless a multi-line `ApplicationLogger.get({ ... })` collapsed onto one line.\n const scoped = LoggerScopeRewriter.rewrite({ typescript, fileName: file, source });\n const tabled = NamespaceFunctions.rewrite({\n typescript,\n fileName: file,\n source: scoped.output,\n mappings,\n });\n const result = {\n output: tabled.output,\n changed: scoped.changed || tabled.changed,\n rewritten: scoped.rewritten + tabled.rewritten,\n reports: [...scoped.reports, ...tabled.reports],\n };\n\n for (const report of result.reports) {\n reportCount += 1;\n console.warn(`${shown}:${report.line}:${report.column} ${report.reason}`);\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 callCount += result.rewritten;\n console.log(\n `${isWrite ? 'changed' : 'would change'} ${shown} (${result.rewritten} call(s))`,\n );\n\n if (isWrite) {\n writeFileSync(file, result.output);\n }\n }\n }\n\n console.log(\n `devz codemod namespace-functions: ${changedCount} file(s) ${isWrite ? 'changed' : 'would change'}, ${callCount} call(s) ${isWrite ? 'rewritten' : 'would be rewritten'}, ${reportCount} left untouched` +\n (refusedCount > 0 ? `, ${refusedCount} refused` : ''),\n );\n\n if (!isWrite && changedCount > 0) {\n console.log(\n `Nothing was written. Run again with ${NamespaceFunctionsFlags.WRITE} to apply, then run your typecheck and formatter.`,\n );\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":"index.js","sourceRoot":"","sources":["../../../../src/cli/codemod/namespace-functions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,qCAAsD;AACtD,yCAA8C;AAC9C,oCAAwC;AACxC,uCAAsE;AACtE,yCAA0C;AAC1C,iDAAqD;AACrD,uCAAsD;AACtD,yCAAgD;AAEhD,iDAA+B;AAC/B,4CAA0B;AAC1B,6CAA2B;AAC3B,4CAA0B;AAC1B,6CAA2B;AAE3B,MAAM,KAAK,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;uFA4ByE,CAAC;AAExF,kDAAkD;AAClD,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAE3B,MAAM,uBAAuB;aACX,UAAK,GAAG,SAAS,CAAC;aAClB,UAAK,GAAG,SAAS,CAAC;aAClB,YAAO,GAAG,WAAW,CAAC;aACtB,SAAI,GAAG,QAAQ,CAAC;aAChB,eAAU,GAAG,IAAI,CAAC;aAElB,eAAU,GAAG,IAAI,GAAG,CAAS;QAC3C,IAAI,CAAC,KAAK;QACV,IAAI,CAAC,KAAK;QACV,IAAI,CAAC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H,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;;AArKH,8DAsKC","sourcesContent":["import { readFileSync, writeFileSync } from 'node:fs';\nimport { relative, resolve } from 'node:path';\nimport { CodemodFiles } from '../files';\nimport { type INamespaceMapping, NamespaceMappings } from './mapping';\nimport { ALL_MAPPINGS } from './mappings';\nimport { LoggerScopeRewriter } from './logger-scope';\nimport { NamespaceFunctionsReverse } from './reverse';\nimport { NamespaceFunctions } from './rewriter';\n\nexport * from './logger-scope';\nexport * from './mapping';\nexport * from './mappings';\nexport * from './reverse';\nexport * from './rewriter';\n\nconst USAGE = `Usage: devz codemod namespace-functions [paths...] [--write | --check] [--reverse]\n\nMoves calls of an IGNIS function that now lives in a class to the class form, with one options\nobject: \\`oldName(a, b)\\` becomes \\`ClassName.method({ first: a, second: b })\\`, and an argument named\nlike its key is written short (\\`{ first }\\`). The old names are removed from the packages, so run it\nonce after you upgrade. A table in @venizia/dev-configs names each moved function.\n\nIt follows a named import (aliased too) and a namespace import (\\`ns.oldName(...)\\`) from a module the\ntable lists, adds the class to that import, and drops the old name once nothing else uses it. It lists\nwith its file and line, and leaves for you: a call with a spread argument or the wrong number of\narguments, the old name used as a value (passed, stored, exported, in typeof), a re-export, a type-only\nimport, and a file that declares a name the rewrite would collide with.\n\nIt also moves the removed \\`ApplicationLogger\\`: \\`ApplicationLogger.get('scope')\\`, \\`.get(NAME)\\` and\n\\`.get({ scope: NAME })\\` become \\`LoggerFactory.getLogger(['scope'])\\`, \\`([NAME])\\`, and the import follows, when\n\\`ApplicationLogger\\` comes from \\`@venizia/ignis-helpers\\` or \\`@venizia/ignis\\`. \\`Logger.get\\` and\n\\`HfLogger.get\\` are not touched, and a call it cannot decide is listed, as is any other use of\n\\`ApplicationLogger\\` (a type, a re-export, a value). An identifier argument is taken for a scope: run your\ntypecheck afterwards.\n\n --write write the changed files (without it, nothing is written)\n --check dry run that exits 1 while a call can be rewritten or is left untouched (for CI)\n --reverse apply the table backward, for a downgrade: \\`ClassName.method({ first: a })\\` becomes\n \\`oldName(a)\\` and the import follows. The \\`ApplicationLogger\\` rule is not reversed.\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\nclass NamespaceFunctionsFlags {\n static readonly WRITE = '--write';\n static readonly CHECK = '--check';\n static readonly REVERSE = '--reverse';\n static readonly HELP = '--help';\n static readonly HELP_SHORT = '-h';\n\n static readonly SCHEME_SET = new Set<string>([\n this.WRITE,\n this.CHECK,\n this.REVERSE,\n this.HELP,\n this.HELP_SHORT,\n ]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/**\n * `devz codemod namespace-functions [paths...] [--write | --check]`: rewrites the calls of the\n * functions the mapping table lists to their class form. It is a dry run unless `--write` is given.\n * `--check` is the same dry run, and exits 1 while a call can be rewritten or is left untouched.\n */\nexport class NamespaceFunctionsCommand {\n static readonly USAGE = USAGE;\n\n static async run(opts: {\n root: string;\n args: string[];\n /** The table to apply; the one this package ships by default. */\n mappings?: ReadonlyArray<INamespaceMapping>;\n }): Promise<number> {\n const { root, args, mappings = ALL_MAPPINGS } = opts;\n\n if (\n args.includes(NamespaceFunctionsFlags.HELP) ||\n args.includes(NamespaceFunctionsFlags.HELP_SHORT)\n ) {\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) => !NamespaceFunctionsFlags.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(NamespaceFunctionsFlags.WRITE);\n const isCheck = flags.includes(NamespaceFunctionsFlags.CHECK);\n const isReverse = flags.includes(NamespaceFunctionsFlags.REVERSE);\n\n if (isWrite && isCheck) {\n console.error(\n `devz codemod: ${NamespaceFunctionsFlags.WRITE} and ${NamespaceFunctionsFlags.CHECK} contradict each other\\n${USAGE}`,\n );\n\n return USAGE_ERROR_CODE;\n }\n\n const problems = NamespaceMappings.validate({ mappings });\n\n if (problems.length > 0) {\n console.error(\n `devz codemod namespace-functions: the mapping table is broken:\\n${problems.map((problem) => ` ${problem}`).join('\\n')}`,\n );\n\n return 1;\n }\n\n if (mappings.length === 0) {\n console.log(\n 'devz codemod namespace-functions: the mapping table of this version is empty, so there is nothing to rewrite',\n );\n\n return 0;\n }\n\n let typescript: typeof import('typescript');\n\n try {\n const result2 = await import('typescript');\n typescript = result2.default;\n } catch {\n console.error('devz codemod: the \"typescript\" package is required to read your sources');\n\n return 1;\n }\n\n // Identifiers only (the table is validated), so the names need no escaping.\n const nameText = new RegExp(\n `\\\\b(?:${[...new Set(mappings.map((mapping) => (isReverse ? mapping.className : mapping.oldName)))].join('|')})\\\\b`,\n );\n const targets = (paths.length > 0 ? paths : ['.']).map((path) => resolve(root, path));\n let changedCount = 0;\n let callCount = 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 (!nameText.test(source) && (isReverse || !LoggerScopeRewriter.mentions({ source }))) {\n continue;\n }\n\n const shown = relative(root, file).split('\\\\').join('/') || file;\n // The call-shape rule goes first, and its edits are inside one call, so the lines the table pass reports stay\n // those of the file unless a multi-line `ApplicationLogger.get({ ... })` collapsed onto one line.\n const scoped = isReverse\n ? { output: source, changed: false, rewritten: 0, reports: [] }\n : LoggerScopeRewriter.rewrite({ typescript, fileName: file, source });\n const tabled = (isReverse ? NamespaceFunctionsReverse : NamespaceFunctions).rewrite({\n typescript,\n fileName: file,\n source: scoped.output,\n mappings,\n });\n const result = {\n output: tabled.output,\n changed: scoped.changed || tabled.changed,\n rewritten: scoped.rewritten + tabled.rewritten,\n reports: [...scoped.reports, ...tabled.reports],\n };\n\n for (const report of result.reports) {\n reportCount += 1;\n console.warn(`${shown}:${report.line}:${report.column} ${report.reason}`);\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 callCount += result.rewritten;\n console.log(\n `${isWrite ? 'changed' : 'would change'} ${shown} (${result.rewritten} call(s))`,\n );\n\n if (isWrite) {\n writeFileSync(file, result.output);\n }\n }\n }\n\n console.log(\n `devz codemod namespace-functions: ${changedCount} file(s) ${isWrite ? 'changed' : 'would change'}, ${callCount} call(s) ${isWrite ? 'rewritten' : 'would be rewritten'}, ${reportCount} left untouched` +\n (refusedCount > 0 ? `, ${refusedCount} refused` : ''),\n );\n\n if (!isWrite && changedCount > 0) {\n console.log(\n `Nothing was written. Run again with ${NamespaceFunctionsFlags.WRITE} to apply, then run your typecheck and formatter.`,\n );\n }\n\n if (isWrite && refusedCount > 0) {\n return 1;\n }\n\n return isCheck && (changedCount > 0 || reportCount > 0) ? 1 : 0;\n }\n}\n"]}
@@ -0,0 +1,40 @@
1
+ import type ts from 'typescript';
2
+ import type { INamespaceMapping } from './mapping';
3
+ import { type INamespaceFunctionsReport } from './rewriter';
4
+ type TTypeScript = typeof ts;
5
+ export interface INamespaceFunctionsReverseResult {
6
+ output: string;
7
+ changed: boolean;
8
+ /** How many calls went back to the old function. */
9
+ rewritten: number;
10
+ /** What was left for a person, with where. */
11
+ reports: INamespaceFunctionsReport[];
12
+ }
13
+ /**
14
+ * The inverse of {@link NamespaceFunctions}: `ClassName.method({ first: a, second: b })` goes back to
15
+ * `oldName(a, b)` by the same table, and the import follows. Syntactic, one file, text edits by position.
16
+ *
17
+ * It follows a named import of the class from a module the entry lists. It leaves, and reports, a call
18
+ * whose argument is not one object literal of the entry's keys (a spread, a method, a computed key, a key
19
+ * the entry does not know, a missing required key), and a file that already declares the old name.
20
+ */
21
+ export declare class NamespaceFunctionsReverse {
22
+ static rewrite(opts: {
23
+ typescript: TTypeScript;
24
+ fileName: string;
25
+ source: string;
26
+ mappings: ReadonlyArray<INamespaceMapping>;
27
+ }): INamespaceFunctionsReverseResult;
28
+ /** One pass: converts every convertible call that holds no other convertible call. */
29
+ private static pass;
30
+ /** `Local.method` to the entry, for every named import of a class an entry moved to. */
31
+ private static findBindings;
32
+ /** The text of the old call, or `undefined` (reported) when the argument is not what the entry wrote. */
33
+ private static convert;
34
+ /** The rest arguments: an array literal's elements, or `...expression` for any other value. */
35
+ private static restValues;
36
+ /** Imports the old names the converted calls use and drops a class nothing uses any more. */
37
+ private static fixImports;
38
+ }
39
+ export {};
40
+ //# sourceMappingURL=reverse.d.ts.map