Skip to content

Feature request: Let resolveTsPaths function return the changes #384

@Spielboerg

Description

@Spielboerg

I use the resolveTsPaths function instead of the CLI. Unfortunately, it does not log anything or provide a way to know how many import paths were changed. It would be nice if this function could return the changes array, so I can add a console log myself in the toolchain.

https://github.com/benyap/resolve-tspaths/blob/main/src/index.ts#L20-L38

import type { Change } from "~/types";

...

export async function resolveTsPaths(
  options: ResolveTsPathOptions = {},
): Promise<Change[]> {  // Change return type
  const {
    project = "tsconfig.json",
    src = "src",
    ext = DEFAULT_EXTENSIONS,
    out,
  } = options;
  const tsConfig = loadTSConfig(project);
  const programPaths = resolvePaths({ project, src, out }, tsConfig);
  const aliases = computeAliases(
    programPaths.basePath,
    tsConfig?.options?.paths ?? {},
  );
  const files = getFilesToProcess(programPaths.outPath, ext);
  const changes = generateChanges(files, aliases, programPaths);
  applyChanges(changes);

  return changes;  // Add this return
}

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions