zerkalica/zerollup

[ts-transform-paths] doesn't work when no paths is configured in tsconfig.json

dko-slapdash opened this issue · 1 comments

Thanks for this plugin!

Some feedback regarding ts-transform-paths vs. typescript-transform-paths.

  1. If no paths specified in tsconfig.json at all, ts-transform-paths does nothing (typescript-transform-paths does nothing as well btw). E.g.:
// tsconfig.json
"baseUrl": "src"
"plugins": [{ "transform": "@zerollup/ts-transform-paths" }],

// main.ts
import { app } from "electron";  // a module in node_modules
import { setMenu } from "main/menu";  // a module in the current dir

// output:
const electron_1 = require("electron");
const menu_1 = require("main/menu");  // <-- NOT ./main/menu
  1. Both plugins activate when I add a dummy paths entry to tsconfig.json. BUT your module doesn't differentiate between a module in node_modules and a local one, whilst typescript-transform-paths does:
// tsconfig.json
"baseUrl": "src"
"plugins": [{ "transform": "@zerollup/ts-transform-paths" }],
"paths": { "*": ["*"] },

// main.ts
import { app } from "electron";  // a module in node_modules
import { setMenu } from "main/menu";  // a module in the current dir

// output of ts-transform-paths (incorrect):
const electron_1 = require("./electron");  // <-- doesn't understand it's in node_modules
const menu_1 = require("./main/menu");

// output of typescript-transform-paths (correct):
const electron_1 = require("electron");  // <-- OK
const menu_1 = require("./main/menu"); // <-- OK

My IMHO about all that is following: it's a little strange to require "paths" to be present in tsconfig.json. I think in an ideal world, the transform plugin should do exactly the same as TS does when it interprets the entire configuration. If TS understands just baseUrl and shows no syntax errors in both tsc and in VSCode, if it allows to do import from "xyz/abc" where xyz is located in baseUrl, then the transform plugin should do no worse than that. (And I also think that in an ideal world, tsc should have a config option to alter paths natively; although I read their arguments, they still look very weak to me.)

Sorry for delay. Probably fixed in 1.7.4. Now plugin try to detect external and internal dependencies based on ts.Program.getSourceFile api.