Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transformer cannot be used programmatically #259

Open
asnaeb opened this issue Aug 30, 2024 Discussed in #258 · 0 comments
Open

Transformer cannot be used programmatically #259

asnaeb opened this issue Aug 30, 2024 Discussed in #258 · 0 comments

Comments

@asnaeb
Copy link

asnaeb commented Aug 30, 2024

I'm trying to use this transformer along with other transformers in a plugin but I couldn't seem to be able to make it work. I'm using ts-patch and other transformers (typia) work. This is how I'm plugging it in

// ./path/to/file.ts
import {Something} from "@/my-module.ts";
import _tsTransformPaths from "typescript-transform-paths";
import ts from "typescript";
import fs from "fs";

const tsTransformPaths = _tsTransformPaths as unknown as typeof import("typescript-transform-paths").default;

const fileName = "./path/to/file.ts";
const source = fs.readFileSync(fileName, "utf8");

const compilerOptions = {
  paths: {
    "@/*": ["./*"]
  },
  target: ts.ScriptTarget.ES2020
};

const mySourceFile = ts.createSourceFile(fileName, source, compilerOptions.target);

const {transformed: [transformedSource]} = ts.transform(
  mySourceFile,
  [
    tsTransformPaths(
      undefined,
      undefined,
      undefined,
      {compilerOptions, fileNames: [mySourceFile.fileName]},
    )
  ],
  compilerOptions
);

ts.createPrinter().printFile(transformedSource)) === source // true

The transformer doesn't seem to do anything to the input. Am I doing something wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant