@venizia/dev-configs 0.4.8-8 → 0.4.8-9

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.
@@ -2,6 +2,8 @@
2
2
  export declare class ConnectorSpecifiers {
3
3
  static readonly SUBPATHS: ReadonlyArray<string>;
4
4
  static readonly MOVES: ReadonlyMap<string, string>;
5
+ /** The same table backward, for a downgrade. */
6
+ static readonly REVERSE_MOVES: ReadonlyMap<string, string>;
5
7
  }
6
8
  export interface IConnectorImportsResult {
7
9
  output: string;
@@ -15,6 +17,8 @@ export declare class ConnectorImports {
15
17
  typescript: typeof import('typescript');
16
18
  fileName: string;
17
19
  source: string;
20
+ /** Move `@venizia/ignis-connectors/<sub-path>` back to `@venizia/ignis/<sub-path>`. */
21
+ reverse?: boolean;
18
22
  }): IConnectorImportsResult;
19
23
  /**
20
24
  * The `package.json` nearest to `file` (not above `root`), and whether it lists the connectors package; `undefined` when
@@ -34,7 +38,7 @@ export declare class ConnectorImports {
34
38
  * is given. `--check` is the same dry run, and exits 1 while a file would change.
35
39
  */
36
40
  export declare class ConnectorImportsCommand {
37
- static readonly USAGE = "Usage: devz codemod connector-imports [paths...] [--write | --check]\n\nMoves the connector sub-path imports of @venizia/ignis to @venizia/ignis-connectors. The sub-paths\n@venizia/ignis/postgres, /postgres/node-postgres, /postgres/postgres-js, /postgres/pglite,\n/postgres/supabase, /relational, /sqlite, /sqlite/libsql, /search, /search/controllers, /meilisearch,\n/typesense and /typesense/controllers are removed; each one is the same name under\n@venizia/ignis-connectors, so the rewrite changes only the specifier.\n\nIt reads TypeScript files (.ts, .tsx, .mts, .cts): import and export declarations, import(\"...\"),\nrequire(\"...\"), require.resolve(\"...\") and import.meta.resolve(\"...\"), import(\"...\") types, declare module\n\"...\" and the module name of mock.module(\"...\") style calls. A .js, .cjs or .mjs file is not read: edit it by hand. Other sub-paths of @venizia/ignis (mail, static-asset,\ntesting, websocket, ...) and the root are not touched. The app must list @venizia/ignis-connectors as a\ndirect dependency: it reports each package.json that does not.\n\n --write write the changed files (without it, nothing is written)\n --check dry run that exits 1 while a file would change (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.";
41
+ static readonly USAGE = "Usage: devz codemod connector-imports [paths...] [--write | --check] [--reverse]\n\nMoves the connector sub-path imports of @venizia/ignis to @venizia/ignis-connectors. The sub-paths\n@venizia/ignis/postgres, /postgres/node-postgres, /postgres/postgres-js, /postgres/pglite,\n/postgres/supabase, /relational, /sqlite, /sqlite/libsql, /search, /search/controllers, /meilisearch,\n/typesense and /typesense/controllers are removed; each one is the same name under\n@venizia/ignis-connectors, so the rewrite changes only the specifier.\n\nIt reads TypeScript files (.ts, .tsx, .mts, .cts): import and export declarations, import(\"...\"),\nrequire(\"...\"), require.resolve(\"...\") and import.meta.resolve(\"...\"), import(\"...\") types, declare module\n\"...\" and the module name of mock.module(\"...\") style calls. A .js, .cjs or .mjs file is not read: edit it by hand. Other sub-paths of @venizia/ignis (mail, static-asset,\ntesting, websocket, ...) and the root are not touched. The app must list @venizia/ignis-connectors as a\ndirect dependency: it reports each package.json that does not.\n\n --write write the changed files (without it, nothing is written)\n --check dry run that exits 1 while a file would change (for CI)\n --reverse move the specifiers back, for a downgrade: @venizia/ignis-connectors/<sub-path> becomes\n @venizia/ignis/<sub-path>\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.";
38
42
  static run(opts: {
39
43
  root: string;
40
44
  args: string[];
@@ -4,7 +4,7 @@ exports.ConnectorImportsCommand = exports.ConnectorImports = exports.ConnectorSp
4
4
  const node_fs_1 = require("node:fs");
5
5
  const node_path_1 = require("node:path");
6
6
  const files_1 = require("./files");
7
- const USAGE = `Usage: devz codemod connector-imports [paths...] [--write | --check]
7
+ const USAGE = `Usage: devz codemod connector-imports [paths...] [--write | --check] [--reverse]
8
8
 
9
9
  Moves the connector sub-path imports of @venizia/ignis to @venizia/ignis-connectors. The sub-paths
10
10
  @venizia/ignis/postgres, /postgres/node-postgres, /postgres/postgres-js, /postgres/pglite,
@@ -20,6 +20,8 @@ direct dependency: it reports each package.json that does not.
20
20
 
21
21
  --write write the changed files (without it, nothing is written)
22
22
  --check dry run that exits 1 while a file would change (for CI)
23
+ --reverse move the specifiers back, for a downgrade: @venizia/ignis-connectors/<sub-path> becomes
24
+ @venizia/ignis/<sub-path>
23
25
  --help print this text and exit
24
26
 
25
27
  With no flag it lists what would change and writes nothing. Inside a git repository it reads the
@@ -43,11 +45,13 @@ const MODULE_NAME_CALLS = new Set([
43
45
  class ConnectorImportsFlags {
44
46
  static { this.WRITE = '--write'; }
45
47
  static { this.CHECK = '--check'; }
48
+ static { this.REVERSE = '--reverse'; }
46
49
  static { this.HELP = '--help'; }
47
50
  static { this.HELP_SHORT = '-h'; }
48
51
  static { this.SCHEME_SET = new Set([
49
52
  this.WRITE,
50
53
  this.CHECK,
54
+ this.REVERSE,
51
55
  this.HELP,
52
56
  this.HELP_SHORT,
53
57
  ]); }
@@ -76,12 +80,15 @@ class ConnectorSpecifiers {
76
80
  `${OLD_PREFIX}${subpath}`,
77
81
  `${CONNECTORS_PACKAGE}/${subpath}`,
78
82
  ])); }
83
+ /** The same table backward, for a downgrade. */
84
+ static { this.REVERSE_MOVES = new Map([...ConnectorSpecifiers.MOVES].map(([from, to]) => [to, from])); }
79
85
  }
80
86
  exports.ConnectorSpecifiers = ConnectorSpecifiers;
81
87
  /** Rewrites the module specifiers of the removed connector sub-paths. */
82
88
  class ConnectorImports {
83
89
  static rewrite(opts) {
84
- const { typescript: ts, fileName, source } = opts;
90
+ const { typescript: ts, fileName, source, reverse = false } = opts;
91
+ const moves = reverse ? ConnectorSpecifiers.REVERSE_MOVES : ConnectorSpecifiers.MOVES;
85
92
  const scriptKind = fileName.endsWith('.tsx') ? ts.ScriptKind.TSX : ts.ScriptKind.TS;
86
93
  const file = ts.createSourceFile(fileName, source, ts.ScriptTarget.Latest, true, scriptKind);
87
94
  const edits = [];
@@ -89,7 +96,7 @@ class ConnectorImports {
89
96
  if (!literal || !ts.isStringLiteralLike(literal)) {
90
97
  return;
91
98
  }
92
- const moved = ConnectorSpecifiers.MOVES.get(literal.text);
99
+ const moved = moves.get(literal.text);
93
100
  if (moved === undefined) {
94
101
  return;
95
102
  }
@@ -205,6 +212,8 @@ class ConnectorImportsCommand {
205
212
  }
206
213
  const isWrite = flags.includes(ConnectorImportsFlags.WRITE);
207
214
  const isCheck = flags.includes(ConnectorImportsFlags.CHECK);
215
+ const isReverse = flags.includes(ConnectorImportsFlags.REVERSE);
216
+ const marker = isReverse ? `${CONNECTORS_PACKAGE}/` : OLD_PREFIX;
208
217
  if (isWrite && isCheck) {
209
218
  console.error(`devz codemod: ${ConnectorImportsFlags.WRITE} and ${ConnectorImportsFlags.CHECK} contradict each other\n${USAGE}`);
210
219
  return USAGE_ERROR_CODE;
@@ -231,10 +240,15 @@ class ConnectorImportsCommand {
231
240
  }
232
241
  for (const file of files) {
233
242
  const source = (0, node_fs_1.readFileSync)(file, 'utf8');
234
- if (!source.includes(OLD_PREFIX)) {
243
+ if (!source.includes(marker)) {
235
244
  continue;
236
245
  }
237
- const result = ConnectorImports.rewrite({ typescript, fileName: file, source });
246
+ const result = ConnectorImports.rewrite({
247
+ typescript,
248
+ fileName: file,
249
+ source,
250
+ reverse: isReverse,
251
+ });
238
252
  if (!result.changed) {
239
253
  continue;
240
254
  }
@@ -248,7 +262,7 @@ class ConnectorImportsCommand {
248
262
  specifierCount += result.rewritten;
249
263
  console.log(`${isWrite ? 'changed' : 'would change'} ${shown} (${result.rewritten} specifier(s))`);
250
264
  const manifest = ConnectorImports.findManifest({ file, root });
251
- if (manifest && !manifest.hasConnectors) {
265
+ if (!isReverse && manifest && !manifest.hasConnectors) {
252
266
  missing.add((0, node_path_1.relative)(root, manifest.path).split('\\').join('/') || manifest.path);
253
267
  }
254
268
  if (isWrite) {
@@ -262,7 +276,7 @@ class ConnectorImportsCommand {
262
276
  console.warn(`${manifestPath} does not list ${CONNECTORS_PACKAGE}: add it as a dependency, because the imports now come from it`);
263
277
  }
264
278
  if (!isWrite && changedCount > 0) {
265
- console.log(`Nothing was written. Run again with ${ConnectorImportsFlags.WRITE} to apply, then add the dependency and run your typecheck.`);
279
+ console.log(`Nothing was written. Run again with ${ConnectorImportsFlags.WRITE} to apply, then ${isReverse ? 'remove the dependency if nothing else uses it and ' : 'add the dependency and '}run your typecheck.`);
266
280
  }
267
281
  if (isWrite && refusedCount > 0) {
268
282
  return 1;
@@ -1 +1 @@
1
- {"version":3,"file":"connector-imports.js","sourceRoot":"","sources":["../../../src/cli/codemod/connector-imports.ts"],"names":[],"mappings":";;;AAAA,qCAAkE;AAClE,yCAA6D;AAC7D,mCAAuC;AAEvC,MAAM,KAAK,GAAG;;;;;;;;;;;;;;;;;;;;uFAoByE,CAAC;AAExF,kDAAkD;AAClD,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAE3B,MAAM,kBAAkB,GAAG,2BAA2B,CAAC;AACvD,MAAM,UAAU,GAAG,iBAAiB,CAAC;AAErC,uGAAuG;AACvG,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IAChC,QAAQ;IACR,MAAM;IACN,QAAQ;IACR,QAAQ;IACR,cAAc;IACd,eAAe;IACf,YAAY;IACZ,aAAa;CACd,CAAC,CAAC;AAEH,MAAM,qBAAqB;aACT,UAAK,GAAG,SAAS,CAAC;aAClB,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,KAAK;QACV,IAAI,CAAC,IAAI;QACT,I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CAAC,OAAO,CAAC,CAAC,CAAC,gBAAgB,EAAE;YACvK,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,YAAY,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CACxD,CAAC;QAEF,KAAK,MAAM,YAAY,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;YAC/C,OAAO,CAAC,IAAI,CACV,GAAG,YAAY,mBAAmB,kBAAkB,gEAAgE,CACrH,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,OAAO,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC;YACjC,OAAO,CAAC,GAAG,CACT,uCAAuC,qBAAqB,CAAC,KAAK,4DAA4D,CAC/H,CAAC;QACJ,CAAC;QAED,IAAI,OAAO,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC;YAChC,OAAO,CAAC,CAAC;QACX,CAAC;QAED,OAAO,OAAO,IAAI,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7C,CAAC;;AAjIH,0DAkIC","sourcesContent":["import { existsSync, readFileSync, writeFileSync } from 'node:fs';\nimport { dirname, join, relative, resolve } from 'node:path';\nimport { CodemodFiles } from './files';\n\nconst USAGE = `Usage: devz codemod connector-imports [paths...] [--write | --check]\n\nMoves the connector sub-path imports of @venizia/ignis to @venizia/ignis-connectors. The sub-paths\n@venizia/ignis/postgres, /postgres/node-postgres, /postgres/postgres-js, /postgres/pglite,\n/postgres/supabase, /relational, /sqlite, /sqlite/libsql, /search, /search/controllers, /meilisearch,\n/typesense and /typesense/controllers are removed; each one is the same name under\n@venizia/ignis-connectors, so the rewrite changes only the specifier.\n\nIt reads TypeScript files (.ts, .tsx, .mts, .cts): import and export declarations, import(\"...\"),\nrequire(\"...\"), require.resolve(\"...\") and import.meta.resolve(\"...\"), import(\"...\") types, declare module\n\"...\" and the module name of mock.module(\"...\") style calls. A .js, .cjs or .mjs file is not read: edit it by hand. Other sub-paths of @venizia/ignis (mail, static-asset,\ntesting, websocket, ...) and the root are not touched. The app must list @venizia/ignis-connectors as a\ndirect dependency: it reports each package.json that does not.\n\n --write write the changed files (without it, nothing is written)\n --check dry run that exits 1 while a file would change (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\nconst CONNECTORS_PACKAGE = '@venizia/ignis-connectors';\nconst OLD_PREFIX = '@venizia/ignis/';\n\n/** The call names that take a module name as their first argument besides `require` and `import()`. */\nconst MODULE_NAME_CALLS = new Set([\n 'module',\n 'mock',\n 'doMock',\n 'unmock',\n 'importActual',\n 'requireActual',\n 'importMock',\n 'requireMock',\n]);\n\nclass ConnectorImportsFlags {\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/** The removed `@venizia/ignis/<sub-path>` specifiers and the `@venizia/ignis-connectors/<sub-path>` they became. */\nexport class ConnectorSpecifiers {\n static readonly SUBPATHS: ReadonlyArray<string> = [\n 'postgres',\n 'postgres/node-postgres',\n 'postgres/postgres-js',\n 'postgres/pglite',\n 'postgres/supabase',\n 'relational',\n 'sqlite',\n 'sqlite/libsql',\n 'search',\n 'search/controllers',\n 'meilisearch',\n 'typesense',\n 'typesense/controllers',\n ];\n\n static readonly MOVES: ReadonlyMap<string, string> = new Map(\n ConnectorSpecifiers.SUBPATHS.map((subpath) => [\n `${OLD_PREFIX}${subpath}`,\n `${CONNECTORS_PACKAGE}/${subpath}`,\n ]),\n );\n}\n\nexport interface IConnectorImportsResult {\n output: string;\n changed: boolean;\n /** How many specifiers were moved. */\n rewritten: number;\n}\n\n/** Rewrites the module specifiers of the removed connector sub-paths. */\nexport class ConnectorImports {\n static rewrite(opts: {\n typescript: typeof import('typescript');\n fileName: string;\n source: string;\n }): IConnectorImportsResult {\n const { typescript: ts, fileName, source } = opts;\n const scriptKind = fileName.endsWith('.tsx') ? ts.ScriptKind.TSX : ts.ScriptKind.TS;\n const file = ts.createSourceFile(fileName, source, ts.ScriptTarget.Latest, true, scriptKind);\n const edits: Array<{ start: number; end: number; text: string }> = [];\n\n const consider = (literal: import('typescript').Node | undefined) => {\n if (!literal || !ts.isStringLiteralLike(literal)) {\n return;\n }\n\n const moved = ConnectorSpecifiers.MOVES.get(literal.text);\n\n if (moved === undefined) {\n return;\n }\n\n const start = literal.getStart(file);\n const quote = source[start];\n edits.push({ start, end: literal.getEnd(), text: `${quote}${moved}${quote}` });\n };\n\n const isModuleNameCall = (call: import('typescript').CallExpression): boolean => {\n const callee = call.expression;\n\n if (callee.kind === ts.SyntaxKind.ImportKeyword) {\n return true;\n }\n\n if (ts.isIdentifier(callee)) {\n return callee.text === 'require';\n }\n\n if (!ts.isPropertyAccessExpression(callee)) {\n return false;\n }\n\n if (callee.name.text === 'resolve') {\n return (\n (ts.isIdentifier(callee.expression) && callee.expression.text === 'require') ||\n ts.isMetaProperty(callee.expression)\n );\n }\n\n return MODULE_NAME_CALLS.has(callee.name.text);\n };\n\n const visit = (node: import('typescript').Node): void => {\n if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) {\n consider(node.moduleSpecifier);\n } else if (ts.isImportEqualsDeclaration(node)) {\n if (ts.isExternalModuleReference(node.moduleReference)) {\n consider(node.moduleReference.expression);\n }\n } else if (ts.isCallExpression(node)) {\n if (isModuleNameCall(node)) {\n consider(node.arguments[0]);\n }\n } else if (ts.isModuleDeclaration(node)) {\n consider(node.name);\n } else if (ts.isImportTypeNode(node)) {\n if (ts.isLiteralTypeNode(node.argument)) {\n consider(node.argument.literal);\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 };\n }\n\n let output = source;\n\n for (const edit of edits.sort((a, b) => b.start - a.start)) {\n output = output.slice(0, edit.start) + edit.text + output.slice(edit.end);\n }\n\n return { output, changed: true, rewritten: edits.length };\n }\n\n /**\n * The `package.json` nearest to `file` (not above `root`), and whether it lists the connectors package; `undefined` when\n * there is none to read.\n */\n static findManifest(opts: {\n file: string;\n root: string;\n }): { path: string; hasConnectors: boolean } | undefined {\n const { file, root } = opts;\n let directory = dirname(file);\n\n for (;;) {\n const candidate = join(directory, 'package.json');\n\n if (existsSync(candidate)) {\n let manifest: unknown;\n\n try {\n manifest = JSON.parse(readFileSync(candidate, 'utf8'));\n } catch (error) {\n console.warn(\n `${candidate} is not valid JSON, so its dependencies were not checked | ${error instanceof Error ? error.message : String(error)}`,\n );\n\n return undefined;\n }\n\n const listed =\n typeof manifest === 'object' &&\n manifest !== null &&\n ['dependencies', 'devDependencies', 'peerDependencies'].some((field) => {\n const group: unknown = Reflect.get(manifest, field);\n\n return typeof group === 'object' && group !== null && CONNECTORS_PACKAGE in group;\n });\n\n return { path: candidate, hasConnectors: listed };\n }\n\n if (directory === root || dirname(directory) === directory) {\n return undefined;\n }\n\n directory = dirname(directory);\n }\n }\n}\n\n/**\n * `devz codemod connector-imports [paths...] [--write | --check]`: moves the removed\n * `@venizia/ignis/<connector sub-path>` specifiers to `@venizia/ignis-connectors`. It is a dry run unless `--write`\n * is given. `--check` is the same dry run, and exits 1 while a file would change.\n */\nexport class ConnectorImportsCommand {\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 (\n args.includes(ConnectorImportsFlags.HELP) ||\n args.includes(ConnectorImportsFlags.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) => !ConnectorImportsFlags.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(ConnectorImportsFlags.WRITE);\n const isCheck = flags.includes(ConnectorImportsFlags.CHECK);\n\n if (isWrite && isCheck) {\n console.error(\n `devz codemod: ${ConnectorImportsFlags.WRITE} and ${ConnectorImportsFlags.CHECK} contradict each other\\n${USAGE}`,\n );\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 const missing = new Set<string>();\n let changedCount = 0;\n let specifierCount = 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 (!source.includes(OLD_PREFIX)) {\n continue;\n }\n\n const result = ConnectorImports.rewrite({ typescript, fileName: file, source });\n\n if (!result.changed) {\n continue;\n }\n\n const shown = relative(root, file).split('\\\\').join('/') || file;\n\n if (dirty?.has(file)) {\n refusedCount += 1;\n console.warn(\n `refused ${shown} has local changes (commit or stash them, then run again)`,\n );\n continue;\n }\n\n changedCount += 1;\n specifierCount += result.rewritten;\n console.log(\n `${isWrite ? 'changed' : 'would change'} ${shown} (${result.rewritten} specifier(s))`,\n );\n\n const manifest = ConnectorImports.findManifest({ file, root });\n\n if (manifest && !manifest.hasConnectors) {\n missing.add(relative(root, manifest.path).split('\\\\').join('/') || manifest.path);\n }\n\n if (isWrite) {\n writeFileSync(file, result.output);\n }\n }\n }\n\n console.log(\n `devz codemod connector-imports: ${changedCount} file(s) ${isWrite ? 'changed' : 'would change'}, ${specifierCount} specifier(s) ${isWrite ? 'moved' : 'would be moved'}` +\n (refusedCount > 0 ? `, ${refusedCount} refused` : ''),\n );\n\n for (const manifestPath of [...missing].sort()) {\n console.warn(\n `${manifestPath} does not list ${CONNECTORS_PACKAGE}: add it as a dependency, because the imports now come from it`,\n );\n }\n\n if (!isWrite && changedCount > 0) {\n console.log(\n `Nothing was written. Run again with ${ConnectorImportsFlags.WRITE} to apply, then add the dependency and run your typecheck.`,\n );\n }\n\n if (isWrite && refusedCount > 0) {\n return 1;\n }\n\n return isCheck && changedCount > 0 ? 1 : 0;\n }\n}\n"]}
1
+ {"version":3,"file":"connector-imports.js","sourceRoot":"","sources":["../../../src/cli/codemod/connector-imports.ts"],"names":[],"mappings":";;;AAAA,qCAAkE;AAClE,yCAA6D;AAC7D,mCAAuC;AAEvC,MAAM,KAAK,GAAG;;;;;;;;;;;;;;;;;;;;;;uFAsByE,CAAC;AAExF,kDAAkD;AAClD,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAE3B,MAAM,kBAAkB,GAAG,2BAA2B,CAAC;AACvD,MAAM,UAAU,GAAG,iBAAiB,CAAC;AAErC,uGAAuG;AACvG,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IAChC,QAAQ;IACR,MAAM;IACN,QAAQ;IACR,QAAQ;IACR,cAAc;IACd,eAAe;IACf,YAAY;IACZ,aAAa;CACd,CAAC,CAAC;AAEH,MAAM,qBAAqB;aACT,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,CA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AAI,YAAY,GAAG,CAAC,EAAE,CAAC;YAChC,OAAO,CAAC,CAAC;QACX,CAAC;QAED,OAAO,OAAO,IAAI,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7C,CAAC;;AAxIH,0DAyIC","sourcesContent":["import { existsSync, readFileSync, writeFileSync } from 'node:fs';\nimport { dirname, join, relative, resolve } from 'node:path';\nimport { CodemodFiles } from './files';\n\nconst USAGE = `Usage: devz codemod connector-imports [paths...] [--write | --check] [--reverse]\n\nMoves the connector sub-path imports of @venizia/ignis to @venizia/ignis-connectors. The sub-paths\n@venizia/ignis/postgres, /postgres/node-postgres, /postgres/postgres-js, /postgres/pglite,\n/postgres/supabase, /relational, /sqlite, /sqlite/libsql, /search, /search/controllers, /meilisearch,\n/typesense and /typesense/controllers are removed; each one is the same name under\n@venizia/ignis-connectors, so the rewrite changes only the specifier.\n\nIt reads TypeScript files (.ts, .tsx, .mts, .cts): import and export declarations, import(\"...\"),\nrequire(\"...\"), require.resolve(\"...\") and import.meta.resolve(\"...\"), import(\"...\") types, declare module\n\"...\" and the module name of mock.module(\"...\") style calls. A .js, .cjs or .mjs file is not read: edit it by hand. Other sub-paths of @venizia/ignis (mail, static-asset,\ntesting, websocket, ...) and the root are not touched. The app must list @venizia/ignis-connectors as a\ndirect dependency: it reports each package.json that does not.\n\n --write write the changed files (without it, nothing is written)\n --check dry run that exits 1 while a file would change (for CI)\n --reverse move the specifiers back, for a downgrade: @venizia/ignis-connectors/<sub-path> becomes\n @venizia/ignis/<sub-path>\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\nconst CONNECTORS_PACKAGE = '@venizia/ignis-connectors';\nconst OLD_PREFIX = '@venizia/ignis/';\n\n/** The call names that take a module name as their first argument besides `require` and `import()`. */\nconst MODULE_NAME_CALLS = new Set([\n 'module',\n 'mock',\n 'doMock',\n 'unmock',\n 'importActual',\n 'requireActual',\n 'importMock',\n 'requireMock',\n]);\n\nclass ConnectorImportsFlags {\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/** The removed `@venizia/ignis/<sub-path>` specifiers and the `@venizia/ignis-connectors/<sub-path>` they became. */\nexport class ConnectorSpecifiers {\n static readonly SUBPATHS: ReadonlyArray<string> = [\n 'postgres',\n 'postgres/node-postgres',\n 'postgres/postgres-js',\n 'postgres/pglite',\n 'postgres/supabase',\n 'relational',\n 'sqlite',\n 'sqlite/libsql',\n 'search',\n 'search/controllers',\n 'meilisearch',\n 'typesense',\n 'typesense/controllers',\n ];\n\n static readonly MOVES: ReadonlyMap<string, string> = new Map(\n ConnectorSpecifiers.SUBPATHS.map((subpath) => [\n `${OLD_PREFIX}${subpath}`,\n `${CONNECTORS_PACKAGE}/${subpath}`,\n ]),\n );\n\n /** The same table backward, for a downgrade. */\n static readonly REVERSE_MOVES: ReadonlyMap<string, string> = new Map(\n [...ConnectorSpecifiers.MOVES].map(([from, to]) => [to, from]),\n );\n}\n\nexport interface IConnectorImportsResult {\n output: string;\n changed: boolean;\n /** How many specifiers were moved. */\n rewritten: number;\n}\n\n/** Rewrites the module specifiers of the removed connector sub-paths. */\nexport class ConnectorImports {\n static rewrite(opts: {\n typescript: typeof import('typescript');\n fileName: string;\n source: string;\n /** Move `@venizia/ignis-connectors/<sub-path>` back to `@venizia/ignis/<sub-path>`. */\n reverse?: boolean;\n }): IConnectorImportsResult {\n const { typescript: ts, fileName, source, reverse = false } = opts;\n const moves = reverse ? ConnectorSpecifiers.REVERSE_MOVES : ConnectorSpecifiers.MOVES;\n const scriptKind = fileName.endsWith('.tsx') ? ts.ScriptKind.TSX : ts.ScriptKind.TS;\n const file = ts.createSourceFile(fileName, source, ts.ScriptTarget.Latest, true, scriptKind);\n const edits: Array<{ start: number; end: number; text: string }> = [];\n\n const consider = (literal: import('typescript').Node | undefined) => {\n if (!literal || !ts.isStringLiteralLike(literal)) {\n return;\n }\n\n const moved = moves.get(literal.text);\n\n if (moved === undefined) {\n return;\n }\n\n const start = literal.getStart(file);\n const quote = source[start];\n edits.push({ start, end: literal.getEnd(), text: `${quote}${moved}${quote}` });\n };\n\n const isModuleNameCall = (call: import('typescript').CallExpression): boolean => {\n const callee = call.expression;\n\n if (callee.kind === ts.SyntaxKind.ImportKeyword) {\n return true;\n }\n\n if (ts.isIdentifier(callee)) {\n return callee.text === 'require';\n }\n\n if (!ts.isPropertyAccessExpression(callee)) {\n return false;\n }\n\n if (callee.name.text === 'resolve') {\n return (\n (ts.isIdentifier(callee.expression) && callee.expression.text === 'require') ||\n ts.isMetaProperty(callee.expression)\n );\n }\n\n return MODULE_NAME_CALLS.has(callee.name.text);\n };\n\n const visit = (node: import('typescript').Node): void => {\n if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) {\n consider(node.moduleSpecifier);\n } else if (ts.isImportEqualsDeclaration(node)) {\n if (ts.isExternalModuleReference(node.moduleReference)) {\n consider(node.moduleReference.expression);\n }\n } else if (ts.isCallExpression(node)) {\n if (isModuleNameCall(node)) {\n consider(node.arguments[0]);\n }\n } else if (ts.isModuleDeclaration(node)) {\n consider(node.name);\n } else if (ts.isImportTypeNode(node)) {\n if (ts.isLiteralTypeNode(node.argument)) {\n consider(node.argument.literal);\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 };\n }\n\n let output = source;\n\n for (const edit of edits.sort((a, b) => b.start - a.start)) {\n output = output.slice(0, edit.start) + edit.text + output.slice(edit.end);\n }\n\n return { output, changed: true, rewritten: edits.length };\n }\n\n /**\n * The `package.json` nearest to `file` (not above `root`), and whether it lists the connectors package; `undefined` when\n * there is none to read.\n */\n static findManifest(opts: {\n file: string;\n root: string;\n }): { path: string; hasConnectors: boolean } | undefined {\n const { file, root } = opts;\n let directory = dirname(file);\n\n for (;;) {\n const candidate = join(directory, 'package.json');\n\n if (existsSync(candidate)) {\n let manifest: unknown;\n\n try {\n manifest = JSON.parse(readFileSync(candidate, 'utf8'));\n } catch (error) {\n console.warn(\n `${candidate} is not valid JSON, so its dependencies were not checked | ${error instanceof Error ? error.message : String(error)}`,\n );\n\n return undefined;\n }\n\n const listed =\n typeof manifest === 'object' &&\n manifest !== null &&\n ['dependencies', 'devDependencies', 'peerDependencies'].some((field) => {\n const group: unknown = Reflect.get(manifest, field);\n\n return typeof group === 'object' && group !== null && CONNECTORS_PACKAGE in group;\n });\n\n return { path: candidate, hasConnectors: listed };\n }\n\n if (directory === root || dirname(directory) === directory) {\n return undefined;\n }\n\n directory = dirname(directory);\n }\n }\n}\n\n/**\n * `devz codemod connector-imports [paths...] [--write | --check]`: moves the removed\n * `@venizia/ignis/<connector sub-path>` specifiers to `@venizia/ignis-connectors`. It is a dry run unless `--write`\n * is given. `--check` is the same dry run, and exits 1 while a file would change.\n */\nexport class ConnectorImportsCommand {\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 (\n args.includes(ConnectorImportsFlags.HELP) ||\n args.includes(ConnectorImportsFlags.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) => !ConnectorImportsFlags.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(ConnectorImportsFlags.WRITE);\n const isCheck = flags.includes(ConnectorImportsFlags.CHECK);\n const isReverse = flags.includes(ConnectorImportsFlags.REVERSE);\n const marker = isReverse ? `${CONNECTORS_PACKAGE}/` : OLD_PREFIX;\n\n if (isWrite && isCheck) {\n console.error(\n `devz codemod: ${ConnectorImportsFlags.WRITE} and ${ConnectorImportsFlags.CHECK} contradict each other\\n${USAGE}`,\n );\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 const missing = new Set<string>();\n let changedCount = 0;\n let specifierCount = 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 (!source.includes(marker)) {\n continue;\n }\n\n const result = ConnectorImports.rewrite({\n typescript,\n fileName: file,\n source,\n reverse: isReverse,\n });\n\n if (!result.changed) {\n continue;\n }\n\n const shown = relative(root, file).split('\\\\').join('/') || file;\n\n if (dirty?.has(file)) {\n refusedCount += 1;\n console.warn(\n `refused ${shown} has local changes (commit or stash them, then run again)`,\n );\n continue;\n }\n\n changedCount += 1;\n specifierCount += result.rewritten;\n console.log(\n `${isWrite ? 'changed' : 'would change'} ${shown} (${result.rewritten} specifier(s))`,\n );\n\n const manifest = ConnectorImports.findManifest({ file, root });\n\n if (!isReverse && manifest && !manifest.hasConnectors) {\n missing.add(relative(root, manifest.path).split('\\\\').join('/') || manifest.path);\n }\n\n if (isWrite) {\n writeFileSync(file, result.output);\n }\n }\n }\n\n console.log(\n `devz codemod connector-imports: ${changedCount} file(s) ${isWrite ? 'changed' : 'would change'}, ${specifierCount} specifier(s) ${isWrite ? 'moved' : 'would be moved'}` +\n (refusedCount > 0 ? `, ${refusedCount} refused` : ''),\n );\n\n for (const manifestPath of [...missing].sort()) {\n console.warn(\n `${manifestPath} does not list ${CONNECTORS_PACKAGE}: add it as a dependency, because the imports now come from it`,\n );\n }\n\n if (!isWrite && changedCount > 0) {\n console.log(\n `Nothing was written. Run again with ${ConnectorImportsFlags.WRITE} to apply, then ${isReverse ? 'remove the dependency if nothing else uses it and ' : 'add the dependency and '}run your typecheck.`,\n );\n }\n\n if (isWrite && refusedCount > 0) {\n return 1;\n }\n\n return isCheck && changedCount > 0 ? 1 : 0;\n }\n}\n"]}
@@ -14,20 +14,31 @@ const USAGE = [
14
14
  connector_imports_1.ConnectorImportsCommand.USAGE,
15
15
  ].join('\n\n');
16
16
  /** The codemods `devz codemod <name>` runs. */
17
- const NAMES = [
17
+ const NAME_LIST = [
18
18
  'drop-redundant-casts',
19
19
  'const-classes',
20
20
  'async-style',
21
21
  'namespace-functions',
22
22
  'connector-imports',
23
- ].join(', ');
23
+ ];
24
+ const NAMES = NAME_LIST.join(', ');
24
25
  /** A usage error: nothing was read or written. */
25
26
  const USAGE_ERROR_CODE = 2;
27
+ /** The codemods that are style rewrites, not migrations: there is no downgrade of them. */
28
+ const NOT_REVERSIBLE = new Set(['drop-redundant-casts', 'const-classes', 'async-style']);
26
29
  /** `devz codemod <name> [args]`: hands the arguments to the codemod called `name`. */
27
30
  class CodemodCommand {
28
31
  static async run(opts) {
29
32
  const { args } = opts;
30
33
  const [name, ...rest] = args;
34
+ if (name === '--list') {
35
+ console.log(NAME_LIST.join('\n'));
36
+ return 0;
37
+ }
38
+ if (name !== undefined && NOT_REVERSIBLE.has(name) && rest.includes('--reverse')) {
39
+ console.error(`devz codemod ${name}: not reversible`);
40
+ return USAGE_ERROR_CODE;
41
+ }
31
42
  if (name === 'drop-redundant-casts') {
32
43
  return drop_redundant_casts_1.DropRedundantCastsCommand.run({ root: opts.root, args: rest });
33
44
  }
@@ -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,CAAC;AAEb,kDAAkD;AAClD,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAE3B,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,sBAAsB,EAAE,CAAC;YACpC,OAAO,gDAAyB,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QACxE,CAAC;QAED,IAAI,IAAI,KAAK,eAAe,EAAE,CAAC;YAC7B,OAAO,mCAAmB,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QAClE,CAAC;QAED,IAAI,IAAI,KAAK,aAAa,EAAE,CAAC;YAC3B,OAAO,+BAAiB,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QAChE,CAAC;QAED,IAAI,IAAI,KAAK,qBAAqB,EAAE,CAAC;YACnC,OAAO,+CAAyB,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QACxE,CAAC;QAED,IAAI,IAAI,KAAK,mBAAmB,EAAE,CAAC;YACjC,OAAO,2CAAuB,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QACtE,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;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,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,SAAS,GAAG;IAChB,sBAAsB;IACtB,eAAe;IACf,aAAa;IACb,qBAAqB;IACrB,mBAAmB;CACpB,CAAC;AACF,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEnC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I,EAAE,CAAC,CAAC;QAChE,CAAC;QAED,IAAI,IAAI,KAAK,qBAAqB,EAAE,CAAC;YACnC,OAAO,+CAAyB,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QACxE,CAAC;QAED,IAAI,IAAI,KAAK,mBAAmB,EAAE,CAAC;YACjC,OAAO,2CAAuB,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QACtE,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;AAjDD,wCAiDC","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 NAME_LIST = [\n 'drop-redundant-casts',\n 'const-classes',\n 'async-style',\n 'namespace-functions',\n 'connector-imports',\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(['drop-redundant-casts', 'const-classes', 'async-style']);\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 (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,CAAC;aAChB,eAAU,GAAG,IAAI,CAAC;aAElB,eAAU,GAAG,IAAI,GAAG,CAAS;QAC3C,IAAI,CAAC,KAAK;Q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AAI,CACV,YAAY,KAAK,4DAA4D,CAC9E,CAAC;oBACF,SAAS;gBACX,CAAC;gBAED,YAAY,IAAI,CAAC,CAAC;gBAClB,SAAS,IAAI,MAAM,CAAC,SAAS,CAAC;gBAC9B,OAAO,CAAC,GAAG,CACT,GAAG,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,cAAc,KAAK,KAAK,MAAM,MAAM,CAAC,SAAS,WAAW,CACnF,CAAC;gBAEF,IAAI,OAAO,EAAE,CAAC;oBACZ,IAAA,uBAAa,EAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;gBACrC,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,CAAC,GAAG,CACT,qCAAqC,YAAY,YAAY,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,cAAc,KAAK,SAAS,YAAY,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,oBAAoB,KAAK,WAAW,iBAAiB;YACtM,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,uBAAuB,CAAC,KAAK,mDAAmD,CACxH,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;;AAlKH,8DAmKC","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 { 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,OAAO;QACZ,IAAI,CAAC,IAAI;QACT,IAAI,CAAC,UAAU;KAChB,CAAC,CAAC;IAEH,MAAM,CAAC,OAAO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C;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
@@ -0,0 +1,348 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NamespaceFunctionsReverse = void 0;
4
+ const rewriter_1 = require("./rewriter");
5
+ /** Passes a file takes at most: each one converts the calls that hold no other convertible call. */
6
+ const MAX_PASSES = 32;
7
+ /**
8
+ * The inverse of {@link NamespaceFunctions}: `ClassName.method({ first: a, second: b })` goes back to
9
+ * `oldName(a, b)` by the same table, and the import follows. Syntactic, one file, text edits by position.
10
+ *
11
+ * It follows a named import of the class from a module the entry lists. It leaves, and reports, a call
12
+ * whose argument is not one object literal of the entry's keys (a spread, a method, a computed key, a key
13
+ * the entry does not know, a missing required key), and a file that already declares the old name.
14
+ */
15
+ class NamespaceFunctionsReverse {
16
+ static rewrite(opts) {
17
+ const { typescript, fileName, mappings } = opts;
18
+ const needed = new Map();
19
+ let source = opts.source;
20
+ let rewritten = 0;
21
+ let reports = [];
22
+ for (let pass = 0; pass < MAX_PASSES; pass += 1) {
23
+ const parsed = NamespaceFunctionsReverse.pass({ typescript, fileName, source, mappings });
24
+ reports = parsed.reports;
25
+ if (parsed.calls === 0) {
26
+ break;
27
+ }
28
+ source = parsed.output;
29
+ rewritten += parsed.calls;
30
+ for (const mapping of parsed.used) {
31
+ needed.set(mapping.oldName, mapping);
32
+ }
33
+ }
34
+ if (rewritten === 0) {
35
+ return { output: opts.source, changed: false, rewritten: 0, reports };
36
+ }
37
+ const imported = NamespaceFunctionsReverse.fixImports({
38
+ typescript,
39
+ fileName,
40
+ source,
41
+ mappings,
42
+ needed: [...needed.values()],
43
+ });
44
+ return {
45
+ output: imported.output,
46
+ changed: imported.output !== opts.source,
47
+ rewritten,
48
+ reports: [...reports, ...imported.reports],
49
+ };
50
+ }
51
+ /** One pass: converts every convertible call that holds no other convertible call. */
52
+ static pass(opts) {
53
+ const { typescript: t, fileName, source, mappings } = opts;
54
+ const sourceFile = t.createSourceFile(fileName, source, t.ScriptTarget.Latest, true);
55
+ const reports = [];
56
+ const bindings = NamespaceFunctionsReverse.findBindings({
57
+ typescript: t,
58
+ sourceFile,
59
+ mappings,
60
+ });
61
+ const edits = [];
62
+ const used = [];
63
+ const report = (node, reason) => {
64
+ const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
65
+ reports.push({ line: line + 1, column: character + 1, reason });
66
+ };
67
+ const target = (call) => {
68
+ const callee = call.expression;
69
+ if (!t.isPropertyAccessExpression(callee) || !t.isIdentifier(callee.expression)) {
70
+ return undefined;
71
+ }
72
+ const binding = bindings.get(`${callee.expression.text}.${callee.name.text}`);
73
+ return binding;
74
+ };
75
+ const holdsTarget = (node) => {
76
+ let isFound = false;
77
+ const walk = (child) => {
78
+ if (isFound) {
79
+ return;
80
+ }
81
+ if (t.isCallExpression(child) && target(child)) {
82
+ isFound = true;
83
+ return;
84
+ }
85
+ t.forEachChild(child, walk);
86
+ };
87
+ t.forEachChild(node, walk);
88
+ return isFound;
89
+ };
90
+ const visit = (node) => {
91
+ if (t.isCallExpression(node)) {
92
+ const binding = target(node);
93
+ if (binding && !node.arguments.some(holdsTarget)) {
94
+ const text = NamespaceFunctionsReverse.convert({
95
+ typescript: t,
96
+ sourceFile,
97
+ call: node,
98
+ mapping: binding.mapping,
99
+ report,
100
+ });
101
+ if (text !== undefined) {
102
+ edits.push({ start: node.getStart(sourceFile), end: node.end, text });
103
+ used.push(binding.mapping);
104
+ }
105
+ return;
106
+ }
107
+ }
108
+ t.forEachChild(node, visit);
109
+ };
110
+ visit(sourceFile);
111
+ let output = source;
112
+ for (const edit of edits.sort((a, b) => b.start - a.start)) {
113
+ output = output.slice(0, edit.start) + edit.text + output.slice(edit.end);
114
+ }
115
+ return { output, calls: edits.length, used, reports };
116
+ }
117
+ /** `Local.method` to the entry, for every named import of a class an entry moved to. */
118
+ static findBindings(opts) {
119
+ const { typescript: t, sourceFile, mappings } = opts;
120
+ const bindings = new Map();
121
+ for (const statement of sourceFile.statements) {
122
+ const named = t.isImportDeclaration(statement)
123
+ ? statement.importClause?.namedBindings
124
+ : undefined;
125
+ if (!t.isImportDeclaration(statement) ||
126
+ !t.isStringLiteral(statement.moduleSpecifier) ||
127
+ statement.importClause?.isTypeOnly ||
128
+ !named ||
129
+ !t.isNamedImports(named)) {
130
+ continue;
131
+ }
132
+ const module = statement.moduleSpecifier.text;
133
+ for (const element of named.elements) {
134
+ if (element.isTypeOnly) {
135
+ continue;
136
+ }
137
+ const className = (element.propertyName ?? element.name).text;
138
+ for (const mapping of mappings) {
139
+ if (mapping.className !== className ||
140
+ !(mapping.newModules ?? mapping.modules).includes(module)) {
141
+ continue;
142
+ }
143
+ const key = `${element.name.text}.${mapping.method}`;
144
+ if (!bindings.has(key)) {
145
+ bindings.set(key, { mapping, local: element.name.text });
146
+ }
147
+ }
148
+ }
149
+ }
150
+ return bindings;
151
+ }
152
+ /** The text of the old call, or `undefined` (reported) when the argument is not what the entry wrote. */
153
+ static convert(opts) {
154
+ const { typescript: t, sourceFile, call, mapping, report } = opts;
155
+ const text = (node) => node.getText(sourceFile);
156
+ const callee = `${mapping.oldName}${call.questionDotToken ? '?.' : ''}`;
157
+ if (mapping.keepsOptions) {
158
+ return `${callee}(${call.arguments.map(text).join(', ')})`;
159
+ }
160
+ const [argument] = call.arguments;
161
+ const label = `${mapping.className}.${mapping.method}`;
162
+ const isBare = call.arguments.length === 0;
163
+ if (!isBare &&
164
+ (call.arguments.length !== 1 || !argument || !t.isObjectLiteralExpression(argument))) {
165
+ report(call, `\`${label}\` is not called with one object literal, so it stays; rewrite it by hand`);
166
+ return undefined;
167
+ }
168
+ const values = new Map();
169
+ const properties = argument && t.isObjectLiteralExpression(argument) ? argument.properties : [];
170
+ for (const property of properties) {
171
+ const key = property.name && t.isIdentifier(property.name) ? property.name.text : undefined;
172
+ if (t.isShorthandPropertyAssignment(property)) {
173
+ values.set(property.name.text, property.name.text);
174
+ }
175
+ else if (t.isPropertyAssignment(property) && key !== undefined) {
176
+ values.set(key, text(property.initializer));
177
+ }
178
+ else {
179
+ report(property, `\`${label}\` has an argument it cannot read (a spread, a method or a computed key), so it stays`);
180
+ return undefined;
181
+ }
182
+ }
183
+ const known = new Set([
184
+ ...mapping.params.map((parameter) => parameter.key),
185
+ ...(mapping.restKey ? [mapping.restKey] : []),
186
+ ]);
187
+ const unknown = [...values.keys()].filter((key) => !known.has(key));
188
+ if (unknown.length > 0) {
189
+ report(call, `\`${label}\` has the key ${unknown.map((key) => `"${key}"`).join(', ')} that the entry does not know, so it stays`);
190
+ return undefined;
191
+ }
192
+ const positional = [];
193
+ for (const parameter of mapping.params) {
194
+ const value = values.get(parameter.key);
195
+ if (value === undefined && !parameter.optional) {
196
+ report(call, `\`${label}\` lacks the required key "${parameter.key}", so it stays`);
197
+ return undefined;
198
+ }
199
+ positional.push(value);
200
+ }
201
+ const rest = mapping.restKey === undefined
202
+ ? undefined
203
+ : NamespaceFunctionsReverse.restValues({
204
+ typescript: t,
205
+ sourceFile,
206
+ properties,
207
+ key: mapping.restKey,
208
+ });
209
+ while (positional.length > 0 && positional[positional.length - 1] === undefined) {
210
+ positional.pop();
211
+ }
212
+ const list = [...positional.map((value) => value ?? 'undefined'), ...(rest ?? [])];
213
+ return `${callee}(${list.join(', ')})`;
214
+ }
215
+ /** The rest arguments: an array literal's elements, or `...expression` for any other value. */
216
+ static restValues(opts) {
217
+ const { typescript: t, sourceFile, properties, key } = opts;
218
+ for (const property of properties) {
219
+ const name = property.name && t.isIdentifier(property.name) ? property.name.text : undefined;
220
+ if (name !== key) {
221
+ continue;
222
+ }
223
+ if (t.isShorthandPropertyAssignment(property)) {
224
+ return [`...${key}`];
225
+ }
226
+ if (t.isPropertyAssignment(property)) {
227
+ return t.isArrayLiteralExpression(property.initializer)
228
+ ? property.initializer.elements.map((element) => element.getText(sourceFile))
229
+ : [`...${property.initializer.getText(sourceFile)}`];
230
+ }
231
+ }
232
+ return [];
233
+ }
234
+ /** Imports the old names the converted calls use and drops a class nothing uses any more. */
235
+ static fixImports(opts) {
236
+ const { typescript: t, fileName, source, needed } = opts;
237
+ const sourceFile = t.createSourceFile(fileName, source, t.ScriptTarget.Latest, true);
238
+ const reports = [];
239
+ const report = (reportOpts) => {
240
+ const { line, character } = sourceFile.getLineAndCharacterOfPosition(reportOpts.node.getStart(sourceFile));
241
+ reports.push({ line: line + 1, column: character + 1, reason: reportOpts.reason });
242
+ };
243
+ const counts = new Map();
244
+ const declared = new Set();
245
+ const count = (node) => {
246
+ if (t.isIdentifier(node)) {
247
+ counts.set(node.text, (counts.get(node.text) ?? 0) + 1);
248
+ }
249
+ const isDeclaration = t.isVariableDeclaration(node) ||
250
+ t.isFunctionDeclaration(node) ||
251
+ t.isClassDeclaration(node) ||
252
+ t.isParameter(node) ||
253
+ t.isBindingElement(node) ||
254
+ t.isImportSpecifier(node) ||
255
+ t.isImportClause(node);
256
+ if (isDeclaration && node.name && t.isIdentifier(node.name)) {
257
+ declared.add(node.name.text);
258
+ }
259
+ t.forEachChild(node, count);
260
+ };
261
+ count(sourceFile);
262
+ const edits = [];
263
+ const additions = new Map();
264
+ const removals = new Map();
265
+ const orphans = [];
266
+ // A class nothing but its import mentions: the import goes, and the old name takes its place in it.
267
+ const home = new Map();
268
+ for (const statement of sourceFile.statements) {
269
+ const named = t.isImportDeclaration(statement)
270
+ ? statement.importClause?.namedBindings
271
+ : undefined;
272
+ if (!t.isImportDeclaration(statement) ||
273
+ !named ||
274
+ !t.isNamedImports(named) ||
275
+ statement.importClause?.isTypeOnly) {
276
+ continue;
277
+ }
278
+ for (const element of named.elements) {
279
+ const className = (element.propertyName ?? element.name).text;
280
+ const moved = needed.filter((candidate) => candidate.className === className);
281
+ if (moved.length > 0 && !element.isTypeOnly && (counts.get(element.name.text) ?? 0) === 1) {
282
+ removals.set(statement, (removals.get(statement) ?? new Set()).add(element));
283
+ for (const mapping of moved) {
284
+ home.set(mapping.oldName, statement);
285
+ }
286
+ }
287
+ }
288
+ }
289
+ for (const mapping of needed) {
290
+ const isDeclared = declared.has(mapping.oldName);
291
+ const existing = rewriter_1.NamespaceFunctions.findNamedImport({
292
+ typescript: t,
293
+ sourceFile,
294
+ modules: mapping.modules,
295
+ });
296
+ const alreadyImported = existing?.importClause?.namedBindings &&
297
+ t.isNamedImports(existing.importClause.namedBindings) &&
298
+ existing.importClause.namedBindings.elements.some((element) => element.name.text === mapping.oldName);
299
+ if (alreadyImported) {
300
+ continue;
301
+ }
302
+ if (isDeclared) {
303
+ report({
304
+ node: sourceFile,
305
+ reason: `\`${mapping.oldName}\` is already declared in this file, so its import was not added; check the calls just converted`,
306
+ });
307
+ continue;
308
+ }
309
+ const homeDeclaration = home.get(mapping.oldName);
310
+ const homeModule = homeDeclaration && t.isStringLiteral(homeDeclaration.moduleSpecifier)
311
+ ? homeDeclaration.moduleSpecifier.text
312
+ : '';
313
+ const target = homeDeclaration && mapping.modules.includes(homeModule) ? homeDeclaration : existing;
314
+ if (target) {
315
+ additions.set(target, [...(additions.get(target) ?? []), mapping.oldName]);
316
+ continue;
317
+ }
318
+ orphans.push(`import { ${mapping.oldName} } from '${mapping.modules[0]}';`);
319
+ }
320
+ for (const declaration of new Set([...additions.keys(), ...removals.keys()])) {
321
+ edits.push(...rewriter_1.NamespaceFunctions.planImport({
322
+ typescript: t,
323
+ sourceFile,
324
+ declaration,
325
+ removals: removals.get(declaration) ?? new Set(),
326
+ additions: additions.get(declaration) ?? [],
327
+ report,
328
+ }));
329
+ }
330
+ if (orphans.length > 0) {
331
+ const imports = sourceFile.statements.filter((statement) => t.isImportDeclaration(statement));
332
+ const last = imports[imports.length - 1];
333
+ const at = last ? last.end : 0;
334
+ edits.push({
335
+ start: at,
336
+ end: at,
337
+ text: `${last ? '\n' : ''}${orphans.join('\n')}${last ? '' : '\n'}`,
338
+ });
339
+ }
340
+ let output = source;
341
+ for (const edit of edits.sort((a, b) => b.start - a.start)) {
342
+ output = output.slice(0, edit.start) + edit.text + output.slice(edit.end);
343
+ }
344
+ return { output, reports };
345
+ }
346
+ }
347
+ exports.NamespaceFunctionsReverse = NamespaceFunctionsReverse;
348
+ //# sourceMappingURL=reverse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reverse.js","sourceRoot":"","sources":["../../../../src/cli/codemod/namespace-functions/reverse.ts"],"names":[],"mappings":";;;AAEA,yCAAgF;AAIhF,oGAAoG;AACpG,MAAM,UAAU,GAAG,EAAE,CAAC;AAiBtB;;;;;;;GAOG;AACH,MAAa,yBAAyB;IACpC,MAAM,CAAC,OAAO,CAAC,IAKd;QACC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QAChD,MAAM,MAAM,GAAG,IAAI,GAAG,EAA6B,CAAC;QACpD,IAAI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,CAAC;YAC9F,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YACzC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YAC/B,KAAK,CAAC,IAAI,CAAC;gBACT,KAAK,EAAE,EAAE;gBACT,GAAG,EAAE,EAAE;gBACP,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE;aACpE,CAAC,CAAC;QACL,CAAC;QAED,IAAI,MAAM,GAAG,MAAM,CAAC;QAEpB,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3D,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC5E,CAAC;QAED,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;IAC7B,CAAC;CACF;AAzeD,8DAyeC","sourcesContent":["import type ts from 'typescript';\nimport type { INamespaceMapping } from './mapping';\nimport { type INamespaceFunctionsReport, NamespaceFunctions } from './rewriter';\n\ntype TTypeScript = typeof ts;\n\n/** Passes a file takes at most: each one converts the calls that hold no other convertible call. */\nconst MAX_PASSES = 32;\n\nexport interface INamespaceFunctionsReverseResult {\n output: string;\n changed: boolean;\n /** How many calls went back to the old function. */\n rewritten: number;\n /** What was left for a person, with where. */\n reports: INamespaceFunctionsReport[];\n}\n\ninterface IBinding {\n mapping: INamespaceMapping;\n /** The local name of the class. */\n local: string;\n}\n\n/**\n * The inverse of {@link NamespaceFunctions}: `ClassName.method({ first: a, second: b })` goes back to\n * `oldName(a, b)` by the same table, and the import follows. Syntactic, one file, text edits by position.\n *\n * It follows a named import of the class from a module the entry lists. It leaves, and reports, a call\n * whose argument is not one object literal of the entry's keys (a spread, a method, a computed key, a key\n * the entry does not know, a missing required key), and a file that already declares the old name.\n */\nexport class NamespaceFunctionsReverse {\n static rewrite(opts: {\n typescript: TTypeScript;\n fileName: string;\n source: string;\n mappings: ReadonlyArray<INamespaceMapping>;\n }): INamespaceFunctionsReverseResult {\n const { typescript, fileName, mappings } = opts;\n const needed = new Map<string, INamespaceMapping>();\n let source = opts.source;\n let rewritten = 0;\n let reports: INamespaceFunctionsReport[] = [];\n\n for (let pass = 0; pass < MAX_PASSES; pass += 1) {\n const parsed = NamespaceFunctionsReverse.pass({ typescript, fileName, source, mappings });\n reports = parsed.reports;\n\n if (parsed.calls === 0) {\n break;\n }\n\n source = parsed.output;\n rewritten += parsed.calls;\n\n for (const mapping of parsed.used) {\n needed.set(mapping.oldName, mapping);\n }\n }\n\n if (rewritten === 0) {\n return { output: opts.source, changed: false, rewritten: 0, reports };\n }\n\n const imported = NamespaceFunctionsReverse.fixImports({\n typescript,\n fileName,\n source,\n mappings,\n needed: [...needed.values()],\n });\n\n return {\n output: imported.output,\n changed: imported.output !== opts.source,\n rewritten,\n reports: [...reports, ...imported.reports],\n };\n }\n\n /** One pass: converts every convertible call that holds no other convertible call. */\n private static pass(opts: {\n typescript: TTypeScript;\n fileName: string;\n source: string;\n mappings: ReadonlyArray<INamespaceMapping>;\n }): {\n output: string;\n calls: number;\n used: INamespaceMapping[];\n reports: INamespaceFunctionsReport[];\n } {\n const { typescript: t, fileName, source, mappings } = opts;\n const sourceFile = t.createSourceFile(fileName, source, t.ScriptTarget.Latest, true);\n const reports: INamespaceFunctionsReport[] = [];\n const bindings = NamespaceFunctionsReverse.findBindings({\n typescript: t,\n sourceFile,\n mappings,\n });\n const edits: Array<{ start: number; end: number; text: string }> = [];\n const used: INamespaceMapping[] = [];\n\n const report = (node: ts.Node, reason: string) => {\n const { line, character } = sourceFile.getLineAndCharacterOfPosition(\n node.getStart(sourceFile),\n );\n reports.push({ line: line + 1, column: character + 1, reason });\n };\n\n const target = (call: ts.CallExpression): IBinding | undefined => {\n const callee = call.expression;\n\n if (!t.isPropertyAccessExpression(callee) || !t.isIdentifier(callee.expression)) {\n return undefined;\n }\n\n const binding = bindings.get(`${callee.expression.text}.${callee.name.text}`);\n\n return binding;\n };\n\n const holdsTarget = (node: ts.Node): boolean => {\n let isFound = false;\n\n const walk = (child: ts.Node) => {\n if (isFound) {\n return;\n }\n\n if (t.isCallExpression(child) && target(child)) {\n isFound = true;\n\n return;\n }\n\n t.forEachChild(child, walk);\n };\n\n t.forEachChild(node, walk);\n\n return isFound;\n };\n\n const visit = (node: ts.Node): void => {\n if (t.isCallExpression(node)) {\n const binding = target(node);\n\n if (binding && !node.arguments.some(holdsTarget)) {\n const text = NamespaceFunctionsReverse.convert({\n typescript: t,\n sourceFile,\n call: node,\n mapping: binding.mapping,\n report,\n });\n\n if (text !== undefined) {\n edits.push({ start: node.getStart(sourceFile), end: node.end, text });\n used.push(binding.mapping);\n }\n\n return;\n }\n }\n\n t.forEachChild(node, visit);\n };\n\n visit(sourceFile);\n\n let output = source;\n\n for (const edit of edits.sort((a, b) => b.start - a.start)) {\n output = output.slice(0, edit.start) + edit.text + output.slice(edit.end);\n }\n\n return { output, calls: edits.length, used, reports };\n }\n\n /** `Local.method` to the entry, for every named import of a class an entry moved to. */\n private static findBindings(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n mappings: ReadonlyArray<INamespaceMapping>;\n }): Map<string, IBinding> {\n const { typescript: t, sourceFile, mappings } = opts;\n const bindings = new Map<string, IBinding>();\n\n for (const statement of sourceFile.statements) {\n const named = t.isImportDeclaration(statement)\n ? statement.importClause?.namedBindings\n : undefined;\n\n if (\n !t.isImportDeclaration(statement) ||\n !t.isStringLiteral(statement.moduleSpecifier) ||\n statement.importClause?.isTypeOnly ||\n !named ||\n !t.isNamedImports(named)\n ) {\n continue;\n }\n\n const module = statement.moduleSpecifier.text;\n\n for (const element of named.elements) {\n if (element.isTypeOnly) {\n continue;\n }\n\n const className = (element.propertyName ?? element.name).text;\n\n for (const mapping of mappings) {\n if (\n mapping.className !== className ||\n !(mapping.newModules ?? mapping.modules).includes(module)\n ) {\n continue;\n }\n\n const key = `${element.name.text}.${mapping.method}`;\n\n if (!bindings.has(key)) {\n bindings.set(key, { mapping, local: element.name.text });\n }\n }\n }\n }\n\n return bindings;\n }\n\n /** The text of the old call, or `undefined` (reported) when the argument is not what the entry wrote. */\n private static convert(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n call: ts.CallExpression;\n mapping: INamespaceMapping;\n report: (node: ts.Node, reason: string) => void;\n }): string | undefined {\n const { typescript: t, sourceFile, call, mapping, report } = opts;\n const text = (node: ts.Node) => node.getText(sourceFile);\n const callee = `${mapping.oldName}${call.questionDotToken ? '?.' : ''}`;\n\n if (mapping.keepsOptions) {\n return `${callee}(${call.arguments.map(text).join(', ')})`;\n }\n\n const [argument] = call.arguments;\n const label = `${mapping.className}.${mapping.method}`;\n\n const isBare = call.arguments.length === 0;\n\n if (\n !isBare &&\n (call.arguments.length !== 1 || !argument || !t.isObjectLiteralExpression(argument))\n ) {\n report(\n call,\n `\\`${label}\\` is not called with one object literal, so it stays; rewrite it by hand`,\n );\n\n return undefined;\n }\n\n const values = new Map<string, string>();\n\n const properties = argument && t.isObjectLiteralExpression(argument) ? argument.properties : [];\n\n for (const property of properties) {\n const key = property.name && t.isIdentifier(property.name) ? property.name.text : undefined;\n\n if (t.isShorthandPropertyAssignment(property)) {\n values.set(property.name.text, property.name.text);\n } else if (t.isPropertyAssignment(property) && key !== undefined) {\n values.set(key, text(property.initializer));\n } else {\n report(\n property,\n `\\`${label}\\` has an argument it cannot read (a spread, a method or a computed key), so it stays`,\n );\n\n return undefined;\n }\n }\n\n const known = new Set([\n ...mapping.params.map((parameter) => parameter.key),\n ...(mapping.restKey ? [mapping.restKey] : []),\n ]);\n const unknown = [...values.keys()].filter((key) => !known.has(key));\n\n if (unknown.length > 0) {\n report(\n call,\n `\\`${label}\\` has the key ${unknown.map((key) => `\"${key}\"`).join(', ')} that the entry does not know, so it stays`,\n );\n\n return undefined;\n }\n\n const positional: Array<string | undefined> = [];\n\n for (const parameter of mapping.params) {\n const value = values.get(parameter.key);\n\n if (value === undefined && !parameter.optional) {\n report(call, `\\`${label}\\` lacks the required key \"${parameter.key}\", so it stays`);\n\n return undefined;\n }\n\n positional.push(value);\n }\n\n const rest =\n mapping.restKey === undefined\n ? undefined\n : NamespaceFunctionsReverse.restValues({\n typescript: t,\n sourceFile,\n properties,\n key: mapping.restKey,\n });\n\n while (positional.length > 0 && positional[positional.length - 1] === undefined) {\n positional.pop();\n }\n\n const list = [...positional.map((value) => value ?? 'undefined'), ...(rest ?? [])];\n\n return `${callee}(${list.join(', ')})`;\n }\n\n /** The rest arguments: an array literal's elements, or `...expression` for any other value. */\n private static restValues(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n properties: ReadonlyArray<ts.ObjectLiteralElementLike>;\n key: string;\n }): string[] {\n const { typescript: t, sourceFile, properties, key } = opts;\n\n for (const property of properties) {\n const name = property.name && t.isIdentifier(property.name) ? property.name.text : undefined;\n\n if (name !== key) {\n continue;\n }\n\n if (t.isShorthandPropertyAssignment(property)) {\n return [`...${key}`];\n }\n\n if (t.isPropertyAssignment(property)) {\n return t.isArrayLiteralExpression(property.initializer)\n ? property.initializer.elements.map((element) => element.getText(sourceFile))\n : [`...${property.initializer.getText(sourceFile)}`];\n }\n }\n\n return [];\n }\n\n /** Imports the old names the converted calls use and drops a class nothing uses any more. */\n private static fixImports(opts: {\n typescript: TTypeScript;\n fileName: string;\n source: string;\n mappings: ReadonlyArray<INamespaceMapping>;\n needed: INamespaceMapping[];\n }): { output: string; reports: INamespaceFunctionsReport[] } {\n const { typescript: t, fileName, source, needed } = opts;\n const sourceFile = t.createSourceFile(fileName, source, t.ScriptTarget.Latest, true);\n const reports: INamespaceFunctionsReport[] = [];\n\n const report = (reportOpts: { node: ts.Node; reason: string }) => {\n const { line, character } = sourceFile.getLineAndCharacterOfPosition(\n reportOpts.node.getStart(sourceFile),\n );\n reports.push({ line: line + 1, column: character + 1, reason: reportOpts.reason });\n };\n\n const counts = new Map<string, number>();\n const declared = new Set<string>();\n\n const count = (node: ts.Node): void => {\n if (t.isIdentifier(node)) {\n counts.set(node.text, (counts.get(node.text) ?? 0) + 1);\n }\n\n const isDeclaration =\n t.isVariableDeclaration(node) ||\n t.isFunctionDeclaration(node) ||\n t.isClassDeclaration(node) ||\n t.isParameter(node) ||\n t.isBindingElement(node) ||\n t.isImportSpecifier(node) ||\n t.isImportClause(node);\n\n if (isDeclaration && node.name && t.isIdentifier(node.name)) {\n declared.add(node.name.text);\n }\n\n t.forEachChild(node, count);\n };\n\n count(sourceFile);\n\n const edits: Array<{ start: number; end: number; text: string }> = [];\n const additions = new Map<ts.ImportDeclaration, string[]>();\n const removals = new Map<ts.ImportDeclaration, Set<ts.ImportSpecifier>>();\n const orphans: string[] = [];\n\n // A class nothing but its import mentions: the import goes, and the old name takes its place in it.\n const home = new Map<string, ts.ImportDeclaration>();\n\n for (const statement of sourceFile.statements) {\n const named = t.isImportDeclaration(statement)\n ? statement.importClause?.namedBindings\n : undefined;\n\n if (\n !t.isImportDeclaration(statement) ||\n !named ||\n !t.isNamedImports(named) ||\n statement.importClause?.isTypeOnly\n ) {\n continue;\n }\n\n for (const element of named.elements) {\n const className = (element.propertyName ?? element.name).text;\n const moved = needed.filter((candidate) => candidate.className === className);\n\n if (moved.length > 0 && !element.isTypeOnly && (counts.get(element.name.text) ?? 0) === 1) {\n removals.set(statement, (removals.get(statement) ?? new Set()).add(element));\n\n for (const mapping of moved) {\n home.set(mapping.oldName, statement);\n }\n }\n }\n }\n\n for (const mapping of needed) {\n const isDeclared = declared.has(mapping.oldName);\n const existing = NamespaceFunctions.findNamedImport({\n typescript: t,\n sourceFile,\n modules: mapping.modules,\n });\n const alreadyImported =\n existing?.importClause?.namedBindings &&\n t.isNamedImports(existing.importClause.namedBindings) &&\n existing.importClause.namedBindings.elements.some(\n (element) => element.name.text === mapping.oldName,\n );\n\n if (alreadyImported) {\n continue;\n }\n\n if (isDeclared) {\n report({\n node: sourceFile,\n reason: `\\`${mapping.oldName}\\` is already declared in this file, so its import was not added; check the calls just converted`,\n });\n continue;\n }\n\n const homeDeclaration = home.get(mapping.oldName);\n const homeModule =\n homeDeclaration && t.isStringLiteral(homeDeclaration.moduleSpecifier)\n ? homeDeclaration.moduleSpecifier.text\n : '';\n const target =\n homeDeclaration && mapping.modules.includes(homeModule) ? homeDeclaration : existing;\n\n if (target) {\n additions.set(target, [...(additions.get(target) ?? []), mapping.oldName]);\n continue;\n }\n\n orphans.push(`import { ${mapping.oldName} } from '${mapping.modules[0]}';`);\n }\n\n for (const declaration of new Set([...additions.keys(), ...removals.keys()])) {\n edits.push(\n ...NamespaceFunctions.planImport({\n typescript: t,\n sourceFile,\n declaration,\n removals: removals.get(declaration) ?? new Set(),\n additions: additions.get(declaration) ?? [],\n report,\n }),\n );\n }\n\n if (orphans.length > 0) {\n const imports = sourceFile.statements.filter((statement) => t.isImportDeclaration(statement));\n const last = imports[imports.length - 1];\n const at = last ? last.end : 0;\n edits.push({\n start: at,\n end: at,\n text: `${last ? '\\n' : ''}${orphans.join('\\n')}${last ? '' : '\\n'}`,\n });\n }\n\n let output = source;\n\n for (const edit of edits.sort((a, b) => b.start - a.start)) {\n output = output.slice(0, edit.start) + edit.text + output.slice(edit.end);\n }\n\n return { output, reports };\n }\n}\n"]}
@@ -14,6 +14,11 @@ export interface INamespaceFunctionsResult {
14
14
  /** What the codemod found and left for a person, with where. */
15
15
  reports: INamespaceFunctionsReport[];
16
16
  }
17
+ interface IEdit {
18
+ start: number;
19
+ end: number;
20
+ text: string;
21
+ }
17
22
  /**
18
23
  * Rewrites the calls of functions that moved into a class, `oldName(a, b)` to
19
24
  * `ClassName.method({ first: a, second: b })`, from a mapping table. Syntactic: it reads one file and
@@ -44,7 +49,11 @@ export declare class NamespaceFunctions {
44
49
  /** The local name of a value import of the class from one of `modules`. */
45
50
  private static findClassImport;
46
51
  /** The first value import with braces from one of `modules`, to add a class to. */
47
- private static findNamedImport;
52
+ static findNamedImport(opts: {
53
+ typescript: TTypeScript;
54
+ sourceFile: ts.SourceFile;
55
+ modules: string[];
56
+ }): ts.ImportDeclaration | undefined;
48
57
  /** `statement` as an import that is not `import type`, from one of `modules`. */
49
58
  private static asValueImport;
50
59
  private static moduleOf;
@@ -53,7 +62,17 @@ export declare class NamespaceFunctions {
53
62
  * the first removed one. Braces that hold a comment are not rewritten: the classes are appended
54
63
  * and the old names stay, reported. An import left with nothing is removed.
55
64
  */
56
- private static planImport;
65
+ static planImport(opts: {
66
+ typescript: TTypeScript;
67
+ sourceFile: ts.SourceFile;
68
+ declaration: ts.ImportDeclaration;
69
+ removals: Set<ts.ImportSpecifier>;
70
+ additions: string[];
71
+ report: (reportOpts: {
72
+ node: ts.Node;
73
+ reason: string;
74
+ }) => void;
75
+ }): IEdit[];
57
76
  /** The call the old one becomes, for a report: `ParseUtility.toFloat({ input, digit })`. */
58
77
  private static describeTarget;
59
78
  }
@@ -1 +1 @@
1
- {"version":3,"file":"rewriter.js","sourceRoot":"","sources":["../../../../src/cli/codemod/namespace-functions/rewriter.ts"],"names":[],"mappings":";;;AA6CA;;;;;GAKG;AACH,MAAa,kBAAkB;IAC7B,MAAM,CAAC,OAAO,CAAC,IAKd;QACC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QACxD,MAAM,UAAU,GAAG,UAAU,CAAC,gBAAgB,CAC5C,QAAQ,EACR,MAAM,EACN,UAAU,CA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AAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;QAC5D,MAAM,IAAI,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAE1F,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC;YACtB,CAAC,CAAC,GAAG,SAAS,IAAI,MAAM,IAAI;YAC5B,CAAC,CAAC,GAAG,SAAS,IAAI,MAAM,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;IACvD,CAAC;CACF;AAnxBD,gDAmxBC","sourcesContent":["import type ts from 'typescript';\nimport type { INamespaceMapping } from './mapping';\n\ntype TTypeScript = typeof ts;\n\nexport interface INamespaceFunctionsReport {\n line: number;\n column: number;\n reason: string;\n}\n\nexport interface INamespaceFunctionsResult {\n output: string;\n changed: boolean;\n /** How many calls were rewritten. */\n rewritten: number;\n /** What the codemod found and left for a person, with where. */\n reports: INamespaceFunctionsReport[];\n}\n\ninterface IEdit {\n start: number;\n end: number;\n text: string;\n}\n\n/** One way the file reaches an old name: a named import of it, or a namespace import of its module. */\ninterface IBinding {\n mapping: INamespaceMapping;\n declaration: ts.ImportDeclaration;\n module: string;\n /** The local name: of the imported function, or of the namespace. */\n local: string;\n /** The identifier that declares `local`. */\n declarationName: ts.Identifier;\n /** The named import; `undefined` for `import * as name`. */\n specifier?: ts.ImportSpecifier;\n}\n\n/** A matched use of an old name: a call to rewrite, or any other use, which is reported. */\ninterface IUses {\n calls: ts.CallExpression[];\n values: ts.Node[];\n}\n\n/**\n * Rewrites the calls of functions that moved into a class, `oldName(a, b)` to\n * `ClassName.method({ first: a, second: b })`, from a mapping table. Syntactic: it reads one file and\n * needs no type checker, so it only follows names imported from a module the table lists. Every edit\n * is a text edit by position: the argument text, its comments and the untouched code stay as they are.\n */\nexport class NamespaceFunctions {\n static rewrite(opts: {\n typescript: TTypeScript;\n fileName: string;\n source: string;\n mappings: ReadonlyArray<INamespaceMapping>;\n }): INamespaceFunctionsResult {\n const { typescript, fileName, source, mappings } = opts;\n const sourceFile = typescript.createSourceFile(\n fileName,\n source,\n typescript.ScriptTarget.Latest,\n true,\n );\n const reports: INamespaceFunctionsReport[] = [];\n\n const report = (reportOpts: { node: ts.Node; reason: string }) => {\n const { line, character } = sourceFile.getLineAndCharacterOfPosition(\n reportOpts.node.getStart(sourceFile),\n );\n reports.push({ line: line + 1, column: character + 1, reason: reportOpts.reason });\n };\n\n const lineOf = (node: ts.Node) =>\n sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line + 1;\n\n const byModule = new Map<string, INamespaceMapping[]>();\n\n for (const mapping of mappings) {\n for (const module of mapping.modules) {\n byModule.set(module, [...(byModule.get(module) ?? []), mapping]);\n }\n }\n\n const bindings = NamespaceFunctions.findBindings({\n typescript,\n sourceFile,\n byModule,\n report,\n });\n\n if (bindings.length === 0) {\n return { output: source, changed: false, rewritten: 0, reports };\n }\n\n const identifiers = NamespaceFunctions.collectIdentifiers({ typescript, sourceFile });\n const declarationsOf = (name: string) =>\n (identifiers.get(name) ?? []).filter((identifier) =>\n NamespaceFunctions.isDeclarationName({ typescript, identifier }),\n );\n\n const edits: IEdit[] = [];\n const removals = new Set<ts.ImportSpecifier>();\n /** The imports that lose an old name. */\n const trimmed = new Set<ts.ImportDeclaration>();\n const additions = new Map<ts.ImportDeclaration, Set<string>>();\n const newImports = new Map<string, { anchor: ts.ImportDeclaration; names: Set<string> }>();\n /** The class names this run imports, and from which module. */\n const planned = new Map<string, string>();\n let rewritten = 0;\n\n for (const binding of bindings) {\n const { mapping } = binding;\n const uses = NamespaceFunctions.findUses({ typescript, binding, identifiers });\n\n if (uses.calls.length === 0 && uses.values.length === 0) {\n continue;\n }\n\n const target = NamespaceFunctions.describeTarget({ mapping });\n\n for (const value of uses.values) {\n report({\n node: value,\n reason: `\\`${mapping.oldName}\\` is used as a value (passed, stored, exported or in typeof), so its import stays; change it by hand to ${mapping.className}.${mapping.method}`,\n });\n }\n\n if (uses.calls.length === 0) {\n continue;\n }\n\n const shadow = declarationsOf(binding.local).find(\n (identifier) => identifier !== binding.declarationName,\n );\n\n if (shadow) {\n report({\n node: shadow,\n reason: `\\`${binding.local}\\` is declared again in this file, so a call cannot be told apart from the import; rewrite the calls of \\`${mapping.oldName}\\` by hand as ${target}`,\n });\n continue;\n }\n\n const classModules = mapping.newModules ?? [binding.module];\n const isNamespaceReach = !binding.specifier && classModules.includes(binding.module);\n let classReference = `${binding.local}.${mapping.className}`;\n let needsImport = false;\n\n if (!isNamespaceReach) {\n const existing = NamespaceFunctions.findClassImport({\n typescript,\n sourceFile,\n className: mapping.className,\n modules: classModules,\n });\n const plannedModule = planned.get(mapping.className);\n const conflict = existing\n ? declarationsOf(existing.text).find((identifier) => identifier !== existing)\n : plannedModule === undefined\n ? declarationsOf(mapping.className)[0]\n : undefined;\n\n if (conflict) {\n report({\n node: uses.calls[0] ?? conflict,\n reason: `the name \\`${conflict.text}\\` is already declared in this file (line ${lineOf(conflict)}), so \\`${mapping.oldName}\\` is left; rewrite its calls by hand as ${target}`,\n });\n continue;\n }\n\n if (!existing && plannedModule !== undefined && !classModules.includes(plannedModule)) {\n report({\n node: uses.calls[0] ?? binding.declaration,\n reason: `\\`${mapping.className}\\` would be imported from both ${plannedModule} and ${classModules[0]}; rewrite the calls of \\`${mapping.oldName}\\` by hand as ${target}`,\n });\n continue;\n }\n\n classReference = existing?.text ?? mapping.className;\n needsImport = !existing && plannedModule === undefined;\n }\n\n let count = 0;\n let left = uses.values.length;\n\n for (const call of uses.calls) {\n const problem = NamespaceFunctions.checkCall({ typescript, call, mapping });\n\n if (problem) {\n left += 1;\n report({ node: call, reason: `${problem}; rewrite it by hand as ${target}` });\n continue;\n }\n\n edits.push(\n ...NamespaceFunctions.planCall({\n typescript,\n sourceFile,\n call,\n mapping,\n callee: `${classReference}.${mapping.method}`,\n }),\n );\n count += 1;\n }\n\n rewritten += count;\n\n if (count === 0) {\n continue;\n }\n\n if (needsImport) {\n const sameDeclaration =\n binding.specifier && classModules.includes(binding.module)\n ? binding.declaration\n : undefined;\n const declaration =\n sameDeclaration ??\n NamespaceFunctions.findNamedImport({ typescript, sourceFile, modules: classModules });\n\n if (declaration) {\n additions.set(\n declaration,\n new Set([...(additions.get(declaration) ?? []), mapping.className]),\n );\n planned.set(\n mapping.className,\n sameDeclaration ? binding.module : NamespaceFunctions.moduleOf({ declaration }),\n );\n } else {\n const module = classModules[0] ?? binding.module;\n const entry = newImports.get(module) ?? {\n anchor: binding.declaration,\n names: new Set<string>(),\n };\n entry.names.add(mapping.className);\n newImports.set(module, entry);\n planned.set(mapping.className, module);\n }\n }\n\n if (binding.specifier && left === 0) {\n removals.add(binding.specifier);\n trimmed.add(binding.declaration);\n }\n }\n\n if (rewritten === 0) {\n return { output: source, changed: false, rewritten: 0, reports };\n }\n\n for (const declaration of new Set([...additions.keys(), ...trimmed])) {\n edits.push(\n ...NamespaceFunctions.planImport({\n typescript,\n sourceFile,\n declaration,\n removals,\n additions: [...(additions.get(declaration) ?? [])],\n report,\n }),\n );\n }\n\n for (const [module, { anchor, names }] of newImports) {\n const quote = source.charAt(anchor.moduleSpecifier.getStart(sourceFile));\n edits.push({\n start: anchor.getStart(sourceFile),\n end: anchor.getStart(sourceFile),\n text: `import { ${[...names].join(', ')} } from ${quote}${module}${quote};\\n`,\n });\n }\n\n // At one position a replacement (the longer range) is applied before an insertion, so the\n // inserted key of an outer call lands in front of the rewritten callee of an inner one.\n let output = source;\n\n for (const edit of edits.sort((a, b) => b.start - a.start || b.end - a.end)) {\n output = output.slice(0, edit.start) + edit.text + output.slice(edit.end);\n }\n\n return { output, changed: output !== source, rewritten, reports };\n }\n\n /** The named and namespace imports of an old name; reports the type-only imports and the re-exports. */\n private static findBindings(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n byModule: Map<string, INamespaceMapping[]>;\n report: (reportOpts: { node: ts.Node; reason: string }) => void;\n }): IBinding[] {\n const { typescript, sourceFile, byModule, report } = opts;\n const bindings: IBinding[] = [];\n\n for (const statement of sourceFile.statements) {\n if (\n typescript.isExportDeclaration(statement) &&\n statement.moduleSpecifier &&\n typescript.isStringLiteral(statement.moduleSpecifier) &&\n statement.exportClause &&\n typescript.isNamedExports(statement.exportClause)\n ) {\n const candidates = byModule.get(statement.moduleSpecifier.text) ?? [];\n\n for (const element of statement.exportClause.elements) {\n const name = (element.propertyName ?? element.name).text;\n const mapping = candidates.find((candidate) => candidate.oldName === name);\n\n if (mapping) {\n report({\n node: element,\n reason: `re-exports \\`${name}\\`; re-export ${mapping.className} as well, by hand`,\n });\n }\n }\n\n continue;\n }\n\n if (\n !typescript.isImportDeclaration(statement) ||\n !typescript.isStringLiteral(statement.moduleSpecifier) ||\n !statement.importClause\n ) {\n continue;\n }\n\n const module = statement.moduleSpecifier.text;\n const candidates = byModule.get(module);\n const clause = statement.importClause;\n const named = clause.namedBindings;\n\n if (!candidates || !named) {\n continue;\n }\n\n if (typescript.isNamespaceImport(named)) {\n if (clause.isTypeOnly) {\n continue;\n }\n\n for (const mapping of candidates) {\n bindings.push({\n mapping,\n declaration: statement,\n module,\n local: named.name.text,\n declarationName: named.name,\n });\n }\n\n continue;\n }\n\n for (const element of named.elements) {\n const imported = (element.propertyName ?? element.name).text;\n const mapping = candidates.find((candidate) => candidate.oldName === imported);\n\n if (!mapping) {\n continue;\n }\n\n if (clause.isTypeOnly || element.isTypeOnly) {\n report({\n node: element,\n reason: `\\`${imported}\\` is imported as a type only; change it by hand to \\`typeof ${mapping.className}.${mapping.method}\\``,\n });\n continue;\n }\n\n bindings.push({\n mapping,\n declaration: statement,\n module,\n local: element.name.text,\n declarationName: element.name,\n specifier: element,\n });\n }\n }\n\n return bindings;\n }\n\n /** Every identifier of the file by its text; JSDoc is not walked, so a `{@link name}` never counts. */\n private static collectIdentifiers(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n }): Map<string, ts.Identifier[]> {\n const { typescript, sourceFile } = opts;\n const identifiers = new Map<string, ts.Identifier[]>();\n\n const walk = (node: ts.Node): void => {\n if (typescript.isIdentifier(node)) {\n identifiers.set(node.text, [...(identifiers.get(node.text) ?? []), node]);\n }\n\n typescript.forEachChild(node, walk);\n };\n\n walk(sourceFile);\n\n return identifiers;\n }\n\n /** The calls of the old name, and every other use of it. */\n private static findUses(opts: {\n typescript: TTypeScript;\n binding: IBinding;\n identifiers: Map<string, ts.Identifier[]>;\n }): IUses {\n const { typescript, binding, identifiers } = opts;\n const uses: IUses = { calls: [], values: [] };\n\n for (const identifier of identifiers.get(binding.local) ?? []) {\n if (\n identifier === binding.declarationName ||\n !NamespaceFunctions.isReference({ typescript, identifier })\n ) {\n continue;\n }\n\n if (!binding.specifier) {\n const parent = identifier.parent;\n const isMember =\n typescript.isPropertyAccessExpression(parent) &&\n parent.expression === identifier &&\n parent.name.text === binding.mapping.oldName;\n\n if (isMember) {\n const call = parent.parent;\n\n if (typescript.isCallExpression(call) && call.expression === parent) {\n uses.calls.push(call);\n } else {\n uses.values.push(parent);\n }\n\n continue;\n }\n\n if (\n typescript.isQualifiedName(parent) &&\n parent.left === identifier &&\n parent.right.text === binding.mapping.oldName\n ) {\n uses.values.push(parent);\n }\n\n continue;\n }\n\n const parent = identifier.parent;\n\n if (typescript.isCallExpression(parent) && parent.expression === identifier) {\n uses.calls.push(parent);\n continue;\n }\n\n uses.values.push(identifier);\n }\n\n return uses;\n }\n\n /** The identifier names a declaration: a variable, a parameter, a function, a class, an import, a type. */\n private static isDeclarationName(opts: {\n typescript: TTypeScript;\n identifier: ts.Identifier;\n }): boolean {\n const { typescript, identifier } = opts;\n const parent = identifier.parent;\n\n if (\n typescript.isVariableDeclaration(parent) ||\n typescript.isParameter(parent) ||\n typescript.isBindingElement(parent) ||\n typescript.isFunctionDeclaration(parent) ||\n typescript.isFunctionExpression(parent) ||\n typescript.isClassDeclaration(parent) ||\n typescript.isClassExpression(parent) ||\n typescript.isEnumDeclaration(parent) ||\n typescript.isInterfaceDeclaration(parent) ||\n typescript.isTypeAliasDeclaration(parent) ||\n typescript.isModuleDeclaration(parent) ||\n typescript.isImportSpecifier(parent) ||\n typescript.isImportClause(parent) ||\n typescript.isNamespaceImport(parent) ||\n typescript.isImportEqualsDeclaration(parent) ||\n typescript.isTypeParameterDeclaration(parent)\n ) {\n return parent.name === identifier;\n }\n\n return false;\n }\n\n /** The identifier reads a binding: not a property name, a label, a declaration or a lowercase JSX tag. */\n private static isReference(opts: {\n typescript: TTypeScript;\n identifier: ts.Identifier;\n }): boolean {\n const { typescript, identifier } = opts;\n const parent = identifier.parent;\n\n if (NamespaceFunctions.isDeclarationName({ typescript, identifier })) {\n return false;\n }\n\n if (typescript.isPropertyAccessExpression(parent) || typescript.isQualifiedName(parent)) {\n return typescript.isPropertyAccessExpression(parent)\n ? parent.name !== identifier\n : parent.right !== identifier;\n }\n\n if (\n typescript.isPropertyAssignment(parent) ||\n typescript.isPropertyDeclaration(parent) ||\n typescript.isPropertySignature(parent) ||\n typescript.isMethodDeclaration(parent) ||\n typescript.isMethodSignature(parent) ||\n typescript.isGetAccessorDeclaration(parent) ||\n typescript.isSetAccessorDeclaration(parent) ||\n typescript.isEnumMember(parent) ||\n typescript.isJsxAttribute(parent)\n ) {\n return parent.name !== identifier;\n }\n\n if (typescript.isBindingElement(parent)) {\n return parent.propertyName !== identifier;\n }\n\n if (typescript.isExportSpecifier(parent)) {\n return (\n !parent.parent.parent.moduleSpecifier && (parent.propertyName ?? parent.name) === identifier\n );\n }\n\n if (\n typescript.isLabeledStatement(parent) ||\n typescript.isBreakOrContinueStatement(parent) ||\n typescript.isMetaProperty(parent)\n ) {\n return false;\n }\n\n if (\n (typescript.isJsxOpeningElement(parent) ||\n typescript.isJsxSelfClosingElement(parent) ||\n typescript.isJsxClosingElement(parent)) &&\n parent.tagName === identifier\n ) {\n return !/^[a-z]/.test(identifier.text);\n }\n\n return true;\n }\n\n /** Why a call cannot be rewritten, or `undefined` when it can. */\n private static checkCall(opts: {\n typescript: TTypeScript;\n call: ts.CallExpression;\n mapping: INamespaceMapping;\n }): string | undefined {\n const { typescript, call, mapping } = opts;\n const { params, restKey, oldName } = mapping;\n const count = call.arguments.length;\n\n if (mapping.keepsOptions) {\n return undefined;\n }\n\n if (call.arguments.some((argument) => typescript.isSpreadElement(argument))) {\n return `this call of \\`${oldName}\\` has a spread argument`;\n }\n\n const required = params.reduce(\n (last, parameter, index) => (parameter.optional ? last : index + 1),\n 0,\n );\n\n if (count < required) {\n return `this call of \\`${oldName}\\` passes ${count} argument(s), fewer than the ${required} it needs`;\n }\n\n if (restKey === undefined && count > params.length) {\n return `this call of \\`${oldName}\\` passes ${count} argument(s), more than its ${params.length} parameter(s)`;\n }\n\n return undefined;\n }\n\n /** The edits that turn one call into the class form; the arguments keep their text and comments. */\n private static planCall(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n call: ts.CallExpression;\n mapping: INamespaceMapping;\n callee: string;\n }): IEdit[] {\n const { typescript, sourceFile, call, mapping, callee } = opts;\n const { params, restKey } = mapping;\n const edits: IEdit[] = [\n { start: call.expression.getStart(sourceFile), end: call.expression.end, text: callee },\n ];\n\n if (call.questionDotToken) {\n edits.push({\n start: call.questionDotToken.getStart(sourceFile),\n end: call.questionDotToken.end,\n text: '',\n });\n }\n\n if (mapping.keepsOptions) {\n return edits;\n }\n\n const argumentList = [...call.arguments];\n\n if (argumentList.length === 0) {\n if (params.length > 0 || restKey !== undefined) {\n const text = restKey === undefined ? '{}' : `{ ${restKey}: [] }`;\n edits.push({ start: call.arguments.pos, end: call.arguments.pos, text });\n }\n\n return edits;\n }\n\n const insert = (insertOpts: { at: number; text: string }) => {\n if (insertOpts.text !== '') {\n edits.push({ start: insertOpts.at, end: insertOpts.at, text: insertOpts.text });\n }\n };\n\n const positional = argumentList.slice(0, params.length);\n const rest = argumentList.slice(params.length);\n\n positional.forEach((argument, index) => {\n const key = params[index]?.key ?? '';\n const isShorthand = typescript.isIdentifier(argument) && argument.text === key;\n insert({\n at: argument.getStart(sourceFile),\n text: `${index === 0 ? '{ ' : ''}${isShorthand ? '' : `${key}: `}`,\n });\n });\n\n const first = rest[0];\n const last = argumentList[argumentList.length - 1];\n let suffix = ' }';\n\n if (first && restKey !== undefined) {\n insert({\n at: first.getStart(sourceFile),\n text: `${positional.length === 0 ? '{ ' : ''}${restKey}: [`,\n });\n suffix = '] }';\n } else if (restKey !== undefined) {\n suffix = `, ${restKey}: [] }`;\n }\n\n insert({ at: last?.end ?? call.arguments.end, text: suffix });\n\n return edits;\n }\n\n /** The local name of a value import of the class from one of `modules`. */\n private static findClassImport(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n className: string;\n modules: string[];\n }): ts.Identifier | undefined {\n const { typescript, sourceFile, className, modules } = opts;\n\n for (const statement of sourceFile.statements) {\n const declaration = NamespaceFunctions.asValueImport({ typescript, statement, modules });\n const named = declaration?.importClause?.namedBindings;\n\n if (!named || !typescript.isNamedImports(named)) {\n continue;\n }\n\n const element = named.elements.find(\n (candidate) =>\n !candidate.isTypeOnly && (candidate.propertyName ?? candidate.name).text === className,\n );\n\n if (element) {\n return element.name;\n }\n }\n\n return undefined;\n }\n\n /** The first value import with braces from one of `modules`, to add a class to. */\n private static findNamedImport(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n modules: string[];\n }): ts.ImportDeclaration | undefined {\n const { typescript, sourceFile, modules } = opts;\n\n for (const statement of sourceFile.statements) {\n const declaration = NamespaceFunctions.asValueImport({ typescript, statement, modules });\n const named = declaration?.importClause?.namedBindings;\n\n if (declaration && named && typescript.isNamedImports(named)) {\n return declaration;\n }\n }\n\n return undefined;\n }\n\n /** `statement` as an import that is not `import type`, from one of `modules`. */\n private static asValueImport(opts: {\n typescript: TTypeScript;\n statement: ts.Statement;\n modules: string[];\n }): ts.ImportDeclaration | undefined {\n const { typescript, statement, modules } = opts;\n\n if (\n typescript.isImportDeclaration(statement) &&\n typescript.isStringLiteral(statement.moduleSpecifier) &&\n modules.includes(statement.moduleSpecifier.text) &&\n statement.importClause &&\n !statement.importClause.isTypeOnly\n ) {\n return statement;\n }\n\n return undefined;\n }\n\n private static moduleOf(opts: { declaration: ts.ImportDeclaration }): string {\n const specifier = opts.declaration.moduleSpecifier;\n\n return 'text' in specifier && typeof specifier.text === 'string' ? specifier.text : '';\n }\n\n /**\n * The edit of one import's braces: the removed old names go, the added classes take the place of\n * the first removed one. Braces that hold a comment are not rewritten: the classes are appended\n * and the old names stay, reported. An import left with nothing is removed.\n */\n private static planImport(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n declaration: ts.ImportDeclaration;\n removals: Set<ts.ImportSpecifier>;\n additions: string[];\n report: (reportOpts: { node: ts.Node; reason: string }) => void;\n }): IEdit[] {\n const { typescript, sourceFile, declaration, removals, additions, report } = opts;\n const clause = declaration.importClause;\n const named = clause?.namedBindings;\n\n if (!clause || !named || !typescript.isNamedImports(named)) {\n return [];\n }\n\n const source = sourceFile.text;\n const elements = [...named.elements];\n const braces = source.slice(named.getStart(sourceFile), named.end);\n\n if (/\\/\\*|\\/\\//.test(braces)) {\n for (const element of elements.filter((candidate) => removals.has(candidate))) {\n report({\n node: element,\n reason: `the braces of this import hold a comment, so \\`${element.name.text}\\` stays imported; remove it by hand`,\n });\n }\n\n const last = elements[elements.length - 1];\n\n if (!last || additions.length === 0) {\n return [];\n }\n\n return [{ start: last.end, end: last.end, text: `, ${additions.join(', ')}` }];\n }\n\n const items: string[] = [];\n let isPlaced = false;\n\n for (const element of elements) {\n if (!removals.has(element)) {\n items.push(element.getText(sourceFile));\n continue;\n }\n\n if (!isPlaced) {\n items.push(...additions);\n isPlaced = true;\n }\n }\n\n if (!isPlaced) {\n items.push(...additions);\n }\n\n if (items.length > 0) {\n const start = named.getStart(sourceFile);\n const lineStart = source.lastIndexOf('\\n', declaration.getStart(sourceFile)) + 1;\n const indent = /^[ \\t]*/.exec(source.slice(lineStart))?.[0] ?? '';\n const text = braces.includes('\\n')\n ? `{\\n${indent} ${items.join(`,\\n${indent} `)},\\n${indent}}`\n : `{ ${items.join(', ')} }`;\n\n return [{ start, end: named.end, text }];\n }\n\n if (clause.name) {\n return [{ start: clause.name.end, end: named.end, text: '' }];\n }\n\n const start = declaration.getStart(sourceFile);\n const newline = /^\\r?\\n/.exec(source.slice(declaration.end))?.[0] ?? '';\n\n return [{ start, end: declaration.end + newline.length, text: '' }];\n }\n\n /** The call the old one becomes, for a report: `ParseUtility.toFloat({ input, digit })`. */\n private static describeTarget(opts: { mapping: INamespaceMapping }): string {\n const { className, method, params, restKey } = opts.mapping;\n const keys = [...params.map((parameter) => parameter.key), ...(restKey ? [restKey] : [])];\n\n return keys.length === 0\n ? `${className}.${method}()`\n : `${className}.${method}({ ${keys.join(', ')} })`;\n }\n}\n"]}
1
+ {"version":3,"file":"rewriter.js","sourceRoot":"","sources":["../../../../src/cli/codemod/namespace-functions/rewriter.ts"],"names":[],"mappings":";;;AA6CA;;;;;GAKG;AACH,MAAa,kBAAkB;IAC7B,MAAM,CAAC,OAAO,CAAC,IAKd;QACC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QACxD,MAAM,UAAU,GAAG,UAAU,CAAC,gBAAgB,CAC5C,QAAQ,EACR,MAAM,EACN,UAAU,CAAC,YAAY,CAAC,MAAM,EAC9B,IAAI,CACL,CAAC;QACF,MAAM,OAAO,GAAgC,EAAE,CAAC;QAEhD,MAAM,MAAM,GAAG,CAAC,UAA6C,EAAE,EAAE;YAC/D,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,UAAU,CAAC,6BAA6B,CAClE,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CACrC,CAAC;YACF,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CAAC;QAE1F,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC;YACtB,CAAC,CAAC,GAAG,SAAS,IAAI,MAAM,IAAI;YAC5B,CAAC,CAAC,GAAG,SAAS,IAAI,MAAM,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;IACvD,CAAC;CACF;AAnxBD,gDAmxBC","sourcesContent":["import type ts from 'typescript';\nimport type { INamespaceMapping } from './mapping';\n\ntype TTypeScript = typeof ts;\n\nexport interface INamespaceFunctionsReport {\n line: number;\n column: number;\n reason: string;\n}\n\nexport interface INamespaceFunctionsResult {\n output: string;\n changed: boolean;\n /** How many calls were rewritten. */\n rewritten: number;\n /** What the codemod found and left for a person, with where. */\n reports: INamespaceFunctionsReport[];\n}\n\ninterface IEdit {\n start: number;\n end: number;\n text: string;\n}\n\n/** One way the file reaches an old name: a named import of it, or a namespace import of its module. */\ninterface IBinding {\n mapping: INamespaceMapping;\n declaration: ts.ImportDeclaration;\n module: string;\n /** The local name: of the imported function, or of the namespace. */\n local: string;\n /** The identifier that declares `local`. */\n declarationName: ts.Identifier;\n /** The named import; `undefined` for `import * as name`. */\n specifier?: ts.ImportSpecifier;\n}\n\n/** A matched use of an old name: a call to rewrite, or any other use, which is reported. */\ninterface IUses {\n calls: ts.CallExpression[];\n values: ts.Node[];\n}\n\n/**\n * Rewrites the calls of functions that moved into a class, `oldName(a, b)` to\n * `ClassName.method({ first: a, second: b })`, from a mapping table. Syntactic: it reads one file and\n * needs no type checker, so it only follows names imported from a module the table lists. Every edit\n * is a text edit by position: the argument text, its comments and the untouched code stay as they are.\n */\nexport class NamespaceFunctions {\n static rewrite(opts: {\n typescript: TTypeScript;\n fileName: string;\n source: string;\n mappings: ReadonlyArray<INamespaceMapping>;\n }): INamespaceFunctionsResult {\n const { typescript, fileName, source, mappings } = opts;\n const sourceFile = typescript.createSourceFile(\n fileName,\n source,\n typescript.ScriptTarget.Latest,\n true,\n );\n const reports: INamespaceFunctionsReport[] = [];\n\n const report = (reportOpts: { node: ts.Node; reason: string }) => {\n const { line, character } = sourceFile.getLineAndCharacterOfPosition(\n reportOpts.node.getStart(sourceFile),\n );\n reports.push({ line: line + 1, column: character + 1, reason: reportOpts.reason });\n };\n\n const lineOf = (node: ts.Node) =>\n sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line + 1;\n\n const byModule = new Map<string, INamespaceMapping[]>();\n\n for (const mapping of mappings) {\n for (const module of mapping.modules) {\n byModule.set(module, [...(byModule.get(module) ?? []), mapping]);\n }\n }\n\n const bindings = NamespaceFunctions.findBindings({\n typescript,\n sourceFile,\n byModule,\n report,\n });\n\n if (bindings.length === 0) {\n return { output: source, changed: false, rewritten: 0, reports };\n }\n\n const identifiers = NamespaceFunctions.collectIdentifiers({ typescript, sourceFile });\n const declarationsOf = (name: string) =>\n (identifiers.get(name) ?? []).filter((identifier) =>\n NamespaceFunctions.isDeclarationName({ typescript, identifier }),\n );\n\n const edits: IEdit[] = [];\n const removals = new Set<ts.ImportSpecifier>();\n /** The imports that lose an old name. */\n const trimmed = new Set<ts.ImportDeclaration>();\n const additions = new Map<ts.ImportDeclaration, Set<string>>();\n const newImports = new Map<string, { anchor: ts.ImportDeclaration; names: Set<string> }>();\n /** The class names this run imports, and from which module. */\n const planned = new Map<string, string>();\n let rewritten = 0;\n\n for (const binding of bindings) {\n const { mapping } = binding;\n const uses = NamespaceFunctions.findUses({ typescript, binding, identifiers });\n\n if (uses.calls.length === 0 && uses.values.length === 0) {\n continue;\n }\n\n const target = NamespaceFunctions.describeTarget({ mapping });\n\n for (const value of uses.values) {\n report({\n node: value,\n reason: `\\`${mapping.oldName}\\` is used as a value (passed, stored, exported or in typeof), so its import stays; change it by hand to ${mapping.className}.${mapping.method}`,\n });\n }\n\n if (uses.calls.length === 0) {\n continue;\n }\n\n const shadow = declarationsOf(binding.local).find(\n (identifier) => identifier !== binding.declarationName,\n );\n\n if (shadow) {\n report({\n node: shadow,\n reason: `\\`${binding.local}\\` is declared again in this file, so a call cannot be told apart from the import; rewrite the calls of \\`${mapping.oldName}\\` by hand as ${target}`,\n });\n continue;\n }\n\n const classModules = mapping.newModules ?? [binding.module];\n const isNamespaceReach = !binding.specifier && classModules.includes(binding.module);\n let classReference = `${binding.local}.${mapping.className}`;\n let needsImport = false;\n\n if (!isNamespaceReach) {\n const existing = NamespaceFunctions.findClassImport({\n typescript,\n sourceFile,\n className: mapping.className,\n modules: classModules,\n });\n const plannedModule = planned.get(mapping.className);\n const conflict = existing\n ? declarationsOf(existing.text).find((identifier) => identifier !== existing)\n : plannedModule === undefined\n ? declarationsOf(mapping.className)[0]\n : undefined;\n\n if (conflict) {\n report({\n node: uses.calls[0] ?? conflict,\n reason: `the name \\`${conflict.text}\\` is already declared in this file (line ${lineOf(conflict)}), so \\`${mapping.oldName}\\` is left; rewrite its calls by hand as ${target}`,\n });\n continue;\n }\n\n if (!existing && plannedModule !== undefined && !classModules.includes(plannedModule)) {\n report({\n node: uses.calls[0] ?? binding.declaration,\n reason: `\\`${mapping.className}\\` would be imported from both ${plannedModule} and ${classModules[0]}; rewrite the calls of \\`${mapping.oldName}\\` by hand as ${target}`,\n });\n continue;\n }\n\n classReference = existing?.text ?? mapping.className;\n needsImport = !existing && plannedModule === undefined;\n }\n\n let count = 0;\n let left = uses.values.length;\n\n for (const call of uses.calls) {\n const problem = NamespaceFunctions.checkCall({ typescript, call, mapping });\n\n if (problem) {\n left += 1;\n report({ node: call, reason: `${problem}; rewrite it by hand as ${target}` });\n continue;\n }\n\n edits.push(\n ...NamespaceFunctions.planCall({\n typescript,\n sourceFile,\n call,\n mapping,\n callee: `${classReference}.${mapping.method}`,\n }),\n );\n count += 1;\n }\n\n rewritten += count;\n\n if (count === 0) {\n continue;\n }\n\n if (needsImport) {\n const sameDeclaration =\n binding.specifier && classModules.includes(binding.module)\n ? binding.declaration\n : undefined;\n const declaration =\n sameDeclaration ??\n NamespaceFunctions.findNamedImport({ typescript, sourceFile, modules: classModules });\n\n if (declaration) {\n additions.set(\n declaration,\n new Set([...(additions.get(declaration) ?? []), mapping.className]),\n );\n planned.set(\n mapping.className,\n sameDeclaration ? binding.module : NamespaceFunctions.moduleOf({ declaration }),\n );\n } else {\n const module = classModules[0] ?? binding.module;\n const entry = newImports.get(module) ?? {\n anchor: binding.declaration,\n names: new Set<string>(),\n };\n entry.names.add(mapping.className);\n newImports.set(module, entry);\n planned.set(mapping.className, module);\n }\n }\n\n if (binding.specifier && left === 0) {\n removals.add(binding.specifier);\n trimmed.add(binding.declaration);\n }\n }\n\n if (rewritten === 0) {\n return { output: source, changed: false, rewritten: 0, reports };\n }\n\n for (const declaration of new Set([...additions.keys(), ...trimmed])) {\n edits.push(\n ...NamespaceFunctions.planImport({\n typescript,\n sourceFile,\n declaration,\n removals,\n additions: [...(additions.get(declaration) ?? [])],\n report,\n }),\n );\n }\n\n for (const [module, { anchor, names }] of newImports) {\n const quote = source.charAt(anchor.moduleSpecifier.getStart(sourceFile));\n edits.push({\n start: anchor.getStart(sourceFile),\n end: anchor.getStart(sourceFile),\n text: `import { ${[...names].join(', ')} } from ${quote}${module}${quote};\\n`,\n });\n }\n\n // At one position a replacement (the longer range) is applied before an insertion, so the\n // inserted key of an outer call lands in front of the rewritten callee of an inner one.\n let output = source;\n\n for (const edit of edits.sort((a, b) => b.start - a.start || b.end - a.end)) {\n output = output.slice(0, edit.start) + edit.text + output.slice(edit.end);\n }\n\n return { output, changed: output !== source, rewritten, reports };\n }\n\n /** The named and namespace imports of an old name; reports the type-only imports and the re-exports. */\n private static findBindings(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n byModule: Map<string, INamespaceMapping[]>;\n report: (reportOpts: { node: ts.Node; reason: string }) => void;\n }): IBinding[] {\n const { typescript, sourceFile, byModule, report } = opts;\n const bindings: IBinding[] = [];\n\n for (const statement of sourceFile.statements) {\n if (\n typescript.isExportDeclaration(statement) &&\n statement.moduleSpecifier &&\n typescript.isStringLiteral(statement.moduleSpecifier) &&\n statement.exportClause &&\n typescript.isNamedExports(statement.exportClause)\n ) {\n const candidates = byModule.get(statement.moduleSpecifier.text) ?? [];\n\n for (const element of statement.exportClause.elements) {\n const name = (element.propertyName ?? element.name).text;\n const mapping = candidates.find((candidate) => candidate.oldName === name);\n\n if (mapping) {\n report({\n node: element,\n reason: `re-exports \\`${name}\\`; re-export ${mapping.className} as well, by hand`,\n });\n }\n }\n\n continue;\n }\n\n if (\n !typescript.isImportDeclaration(statement) ||\n !typescript.isStringLiteral(statement.moduleSpecifier) ||\n !statement.importClause\n ) {\n continue;\n }\n\n const module = statement.moduleSpecifier.text;\n const candidates = byModule.get(module);\n const clause = statement.importClause;\n const named = clause.namedBindings;\n\n if (!candidates || !named) {\n continue;\n }\n\n if (typescript.isNamespaceImport(named)) {\n if (clause.isTypeOnly) {\n continue;\n }\n\n for (const mapping of candidates) {\n bindings.push({\n mapping,\n declaration: statement,\n module,\n local: named.name.text,\n declarationName: named.name,\n });\n }\n\n continue;\n }\n\n for (const element of named.elements) {\n const imported = (element.propertyName ?? element.name).text;\n const mapping = candidates.find((candidate) => candidate.oldName === imported);\n\n if (!mapping) {\n continue;\n }\n\n if (clause.isTypeOnly || element.isTypeOnly) {\n report({\n node: element,\n reason: `\\`${imported}\\` is imported as a type only; change it by hand to \\`typeof ${mapping.className}.${mapping.method}\\``,\n });\n continue;\n }\n\n bindings.push({\n mapping,\n declaration: statement,\n module,\n local: element.name.text,\n declarationName: element.name,\n specifier: element,\n });\n }\n }\n\n return bindings;\n }\n\n /** Every identifier of the file by its text; JSDoc is not walked, so a `{@link name}` never counts. */\n private static collectIdentifiers(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n }): Map<string, ts.Identifier[]> {\n const { typescript, sourceFile } = opts;\n const identifiers = new Map<string, ts.Identifier[]>();\n\n const walk = (node: ts.Node): void => {\n if (typescript.isIdentifier(node)) {\n identifiers.set(node.text, [...(identifiers.get(node.text) ?? []), node]);\n }\n\n typescript.forEachChild(node, walk);\n };\n\n walk(sourceFile);\n\n return identifiers;\n }\n\n /** The calls of the old name, and every other use of it. */\n private static findUses(opts: {\n typescript: TTypeScript;\n binding: IBinding;\n identifiers: Map<string, ts.Identifier[]>;\n }): IUses {\n const { typescript, binding, identifiers } = opts;\n const uses: IUses = { calls: [], values: [] };\n\n for (const identifier of identifiers.get(binding.local) ?? []) {\n if (\n identifier === binding.declarationName ||\n !NamespaceFunctions.isReference({ typescript, identifier })\n ) {\n continue;\n }\n\n if (!binding.specifier) {\n const parent = identifier.parent;\n const isMember =\n typescript.isPropertyAccessExpression(parent) &&\n parent.expression === identifier &&\n parent.name.text === binding.mapping.oldName;\n\n if (isMember) {\n const call = parent.parent;\n\n if (typescript.isCallExpression(call) && call.expression === parent) {\n uses.calls.push(call);\n } else {\n uses.values.push(parent);\n }\n\n continue;\n }\n\n if (\n typescript.isQualifiedName(parent) &&\n parent.left === identifier &&\n parent.right.text === binding.mapping.oldName\n ) {\n uses.values.push(parent);\n }\n\n continue;\n }\n\n const parent = identifier.parent;\n\n if (typescript.isCallExpression(parent) && parent.expression === identifier) {\n uses.calls.push(parent);\n continue;\n }\n\n uses.values.push(identifier);\n }\n\n return uses;\n }\n\n /** The identifier names a declaration: a variable, a parameter, a function, a class, an import, a type. */\n private static isDeclarationName(opts: {\n typescript: TTypeScript;\n identifier: ts.Identifier;\n }): boolean {\n const { typescript, identifier } = opts;\n const parent = identifier.parent;\n\n if (\n typescript.isVariableDeclaration(parent) ||\n typescript.isParameter(parent) ||\n typescript.isBindingElement(parent) ||\n typescript.isFunctionDeclaration(parent) ||\n typescript.isFunctionExpression(parent) ||\n typescript.isClassDeclaration(parent) ||\n typescript.isClassExpression(parent) ||\n typescript.isEnumDeclaration(parent) ||\n typescript.isInterfaceDeclaration(parent) ||\n typescript.isTypeAliasDeclaration(parent) ||\n typescript.isModuleDeclaration(parent) ||\n typescript.isImportSpecifier(parent) ||\n typescript.isImportClause(parent) ||\n typescript.isNamespaceImport(parent) ||\n typescript.isImportEqualsDeclaration(parent) ||\n typescript.isTypeParameterDeclaration(parent)\n ) {\n return parent.name === identifier;\n }\n\n return false;\n }\n\n /** The identifier reads a binding: not a property name, a label, a declaration or a lowercase JSX tag. */\n private static isReference(opts: {\n typescript: TTypeScript;\n identifier: ts.Identifier;\n }): boolean {\n const { typescript, identifier } = opts;\n const parent = identifier.parent;\n\n if (NamespaceFunctions.isDeclarationName({ typescript, identifier })) {\n return false;\n }\n\n if (typescript.isPropertyAccessExpression(parent) || typescript.isQualifiedName(parent)) {\n return typescript.isPropertyAccessExpression(parent)\n ? parent.name !== identifier\n : parent.right !== identifier;\n }\n\n if (\n typescript.isPropertyAssignment(parent) ||\n typescript.isPropertyDeclaration(parent) ||\n typescript.isPropertySignature(parent) ||\n typescript.isMethodDeclaration(parent) ||\n typescript.isMethodSignature(parent) ||\n typescript.isGetAccessorDeclaration(parent) ||\n typescript.isSetAccessorDeclaration(parent) ||\n typescript.isEnumMember(parent) ||\n typescript.isJsxAttribute(parent)\n ) {\n return parent.name !== identifier;\n }\n\n if (typescript.isBindingElement(parent)) {\n return parent.propertyName !== identifier;\n }\n\n if (typescript.isExportSpecifier(parent)) {\n return (\n !parent.parent.parent.moduleSpecifier && (parent.propertyName ?? parent.name) === identifier\n );\n }\n\n if (\n typescript.isLabeledStatement(parent) ||\n typescript.isBreakOrContinueStatement(parent) ||\n typescript.isMetaProperty(parent)\n ) {\n return false;\n }\n\n if (\n (typescript.isJsxOpeningElement(parent) ||\n typescript.isJsxSelfClosingElement(parent) ||\n typescript.isJsxClosingElement(parent)) &&\n parent.tagName === identifier\n ) {\n return !/^[a-z]/.test(identifier.text);\n }\n\n return true;\n }\n\n /** Why a call cannot be rewritten, or `undefined` when it can. */\n private static checkCall(opts: {\n typescript: TTypeScript;\n call: ts.CallExpression;\n mapping: INamespaceMapping;\n }): string | undefined {\n const { typescript, call, mapping } = opts;\n const { params, restKey, oldName } = mapping;\n const count = call.arguments.length;\n\n if (mapping.keepsOptions) {\n return undefined;\n }\n\n if (call.arguments.some((argument) => typescript.isSpreadElement(argument))) {\n return `this call of \\`${oldName}\\` has a spread argument`;\n }\n\n const required = params.reduce(\n (last, parameter, index) => (parameter.optional ? last : index + 1),\n 0,\n );\n\n if (count < required) {\n return `this call of \\`${oldName}\\` passes ${count} argument(s), fewer than the ${required} it needs`;\n }\n\n if (restKey === undefined && count > params.length) {\n return `this call of \\`${oldName}\\` passes ${count} argument(s), more than its ${params.length} parameter(s)`;\n }\n\n return undefined;\n }\n\n /** The edits that turn one call into the class form; the arguments keep their text and comments. */\n private static planCall(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n call: ts.CallExpression;\n mapping: INamespaceMapping;\n callee: string;\n }): IEdit[] {\n const { typescript, sourceFile, call, mapping, callee } = opts;\n const { params, restKey } = mapping;\n const edits: IEdit[] = [\n { start: call.expression.getStart(sourceFile), end: call.expression.end, text: callee },\n ];\n\n if (call.questionDotToken) {\n edits.push({\n start: call.questionDotToken.getStart(sourceFile),\n end: call.questionDotToken.end,\n text: '',\n });\n }\n\n if (mapping.keepsOptions) {\n return edits;\n }\n\n const argumentList = [...call.arguments];\n\n if (argumentList.length === 0) {\n if (params.length > 0 || restKey !== undefined) {\n const text = restKey === undefined ? '{}' : `{ ${restKey}: [] }`;\n edits.push({ start: call.arguments.pos, end: call.arguments.pos, text });\n }\n\n return edits;\n }\n\n const insert = (insertOpts: { at: number; text: string }) => {\n if (insertOpts.text !== '') {\n edits.push({ start: insertOpts.at, end: insertOpts.at, text: insertOpts.text });\n }\n };\n\n const positional = argumentList.slice(0, params.length);\n const rest = argumentList.slice(params.length);\n\n positional.forEach((argument, index) => {\n const key = params[index]?.key ?? '';\n const isShorthand = typescript.isIdentifier(argument) && argument.text === key;\n insert({\n at: argument.getStart(sourceFile),\n text: `${index === 0 ? '{ ' : ''}${isShorthand ? '' : `${key}: `}`,\n });\n });\n\n const first = rest[0];\n const last = argumentList[argumentList.length - 1];\n let suffix = ' }';\n\n if (first && restKey !== undefined) {\n insert({\n at: first.getStart(sourceFile),\n text: `${positional.length === 0 ? '{ ' : ''}${restKey}: [`,\n });\n suffix = '] }';\n } else if (restKey !== undefined) {\n suffix = `, ${restKey}: [] }`;\n }\n\n insert({ at: last?.end ?? call.arguments.end, text: suffix });\n\n return edits;\n }\n\n /** The local name of a value import of the class from one of `modules`. */\n private static findClassImport(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n className: string;\n modules: string[];\n }): ts.Identifier | undefined {\n const { typescript, sourceFile, className, modules } = opts;\n\n for (const statement of sourceFile.statements) {\n const declaration = NamespaceFunctions.asValueImport({ typescript, statement, modules });\n const named = declaration?.importClause?.namedBindings;\n\n if (!named || !typescript.isNamedImports(named)) {\n continue;\n }\n\n const element = named.elements.find(\n (candidate) =>\n !candidate.isTypeOnly && (candidate.propertyName ?? candidate.name).text === className,\n );\n\n if (element) {\n return element.name;\n }\n }\n\n return undefined;\n }\n\n /** The first value import with braces from one of `modules`, to add a class to. */\n static findNamedImport(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n modules: string[];\n }): ts.ImportDeclaration | undefined {\n const { typescript, sourceFile, modules } = opts;\n\n for (const statement of sourceFile.statements) {\n const declaration = NamespaceFunctions.asValueImport({ typescript, statement, modules });\n const named = declaration?.importClause?.namedBindings;\n\n if (declaration && named && typescript.isNamedImports(named)) {\n return declaration;\n }\n }\n\n return undefined;\n }\n\n /** `statement` as an import that is not `import type`, from one of `modules`. */\n private static asValueImport(opts: {\n typescript: TTypeScript;\n statement: ts.Statement;\n modules: string[];\n }): ts.ImportDeclaration | undefined {\n const { typescript, statement, modules } = opts;\n\n if (\n typescript.isImportDeclaration(statement) &&\n typescript.isStringLiteral(statement.moduleSpecifier) &&\n modules.includes(statement.moduleSpecifier.text) &&\n statement.importClause &&\n !statement.importClause.isTypeOnly\n ) {\n return statement;\n }\n\n return undefined;\n }\n\n private static moduleOf(opts: { declaration: ts.ImportDeclaration }): string {\n const specifier = opts.declaration.moduleSpecifier;\n\n return 'text' in specifier && typeof specifier.text === 'string' ? specifier.text : '';\n }\n\n /**\n * The edit of one import's braces: the removed old names go, the added classes take the place of\n * the first removed one. Braces that hold a comment are not rewritten: the classes are appended\n * and the old names stay, reported. An import left with nothing is removed.\n */\n static planImport(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n declaration: ts.ImportDeclaration;\n removals: Set<ts.ImportSpecifier>;\n additions: string[];\n report: (reportOpts: { node: ts.Node; reason: string }) => void;\n }): IEdit[] {\n const { typescript, sourceFile, declaration, removals, additions, report } = opts;\n const clause = declaration.importClause;\n const named = clause?.namedBindings;\n\n if (!clause || !named || !typescript.isNamedImports(named)) {\n return [];\n }\n\n const source = sourceFile.text;\n const elements = [...named.elements];\n const braces = source.slice(named.getStart(sourceFile), named.end);\n\n if (/\\/\\*|\\/\\//.test(braces)) {\n for (const element of elements.filter((candidate) => removals.has(candidate))) {\n report({\n node: element,\n reason: `the braces of this import hold a comment, so \\`${element.name.text}\\` stays imported; remove it by hand`,\n });\n }\n\n const last = elements[elements.length - 1];\n\n if (!last || additions.length === 0) {\n return [];\n }\n\n return [{ start: last.end, end: last.end, text: `, ${additions.join(', ')}` }];\n }\n\n const items: string[] = [];\n let isPlaced = false;\n\n for (const element of elements) {\n if (!removals.has(element)) {\n items.push(element.getText(sourceFile));\n continue;\n }\n\n if (!isPlaced) {\n items.push(...additions);\n isPlaced = true;\n }\n }\n\n if (!isPlaced) {\n items.push(...additions);\n }\n\n if (items.length > 0) {\n const start = named.getStart(sourceFile);\n const lineStart = source.lastIndexOf('\\n', declaration.getStart(sourceFile)) + 1;\n const indent = /^[ \\t]*/.exec(source.slice(lineStart))?.[0] ?? '';\n const text = braces.includes('\\n')\n ? `{\\n${indent} ${items.join(`,\\n${indent} `)},\\n${indent}}`\n : `{ ${items.join(', ')} }`;\n\n return [{ start, end: named.end, text }];\n }\n\n if (clause.name) {\n return [{ start: clause.name.end, end: named.end, text: '' }];\n }\n\n const start = declaration.getStart(sourceFile);\n const newline = /^\\r?\\n/.exec(source.slice(declaration.end))?.[0] ?? '';\n\n return [{ start, end: declaration.end + newline.length, text: '' }];\n }\n\n /** The call the old one becomes, for a report: `ParseUtility.toFloat({ input, digit })`. */\n private static describeTarget(opts: { mapping: INamespaceMapping }): string {\n const { className, method, params, restKey } = opts.mapping;\n const keys = [...params.map((parameter) => parameter.key), ...(restKey ? [restKey] : [])];\n\n return keys.length === 0\n ? `${className}.${method}()`\n : `${className}.${method}({ ${keys.join(', ')} })`;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@venizia/dev-configs",
3
- "version": "0.4.8-8",
3
+ "version": "0.4.8-9",
4
4
  "description": "Shareable development configurations for TypeScript projects: oxlint presets with per-rule builders, the ESLint naming-convention rule, the legacy ESLint flat config, and TypeScript compiler options with critical decorator support (experimentalDecorators, emitDecoratorMetadata, useDefineForClassFields). Single source of truth for consistent code style, type checking, and build settings across monorepo packages.",
5
5
  "keywords": [
6
6
  "build-tools",