index.ts files that re-export) and tsconfig path aliases. You’ll rename the shared toMoment to toDayjs everywhere it is used, and leave a different toMoment alone. You need Node.js 22.18 or later and Git.
1. The project
A small monorepo.toMoment is declared in packages/shared/src/dates.ts and re-exported by the barrel packages/shared/src/index.ts. api imports it through a relative path to the barrel, web through the @shared alias. web/src/legacy.ts has its own toMoment, which must stay.
packages/shared/src/dates.ts
packages/shared/src/index.ts
packages/shared/src/format.ts
packages/api/src/orders.ts
packages/web/src/app.ts
packages/web/src/legacy.ts
tsconfig.json
2. The workflow
workflow.ts
semanticAnalysis: "workspace"letsdefinition()look into other files of the project. The default,"file", only sees the file itself.containing: "toMoment"skips files that don’t mention the name, so only those files are parsed.node.definition()returns where a name is declared:def.rootis that file anddef.nodethe declaration. It follows re-exports,export *and path aliases to any depth.- A use of an imported name resolves to its import first (
kind: "local", animport_specifier); callingdefinition()on that follows the import to the exported function. - The callback renames a name only when it leads to
dates.ts, and logs where each one leads.
3. Dry run
Commit the project, then preview:dates.ts:3, through the barrel and the alias. Both names in legacy.ts lead to legacy.ts:2, so they stay. Files run in parallel, so the log lines can come in another order.
4. Apply it
Next
- Semantic analysis:
definition(),references()and the analysis modes. - To find every use from the declaration instead, call
references()on the declared name.