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

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

Closed
dko-slapdash opened this issue Oct 14, 2019 · 1 comment

Comments

@dko-slapdash
Copy link

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.)

zerkalica pushed a commit that referenced this issue Nov 7, 2019
@zerkalica
Copy link
Owner

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

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

No branches or pull requests

2 participants