dividab / tsconfig-paths

Load node modules according to tsconfig paths, in run-time or via API.
MIT License
1.82k stars 104 forks source link

refactor: avoid minimist if `register` receives explicit options #206

Closed aleclarson closed 2 years ago

aleclarson commented 2 years ago

⚠️ Please merge #205 before this one!

See https://github.com/dividab/tsconfig-paths/commit/3bc36fbfd00770faeabd4eea38cd86994744fa4c for the changes that aren't inherited from #205.

This is a follow-up to https://github.com/dividab/tsconfig-paths/pull/53#issuecomment-1099996457. The benefit is avoiding unintentional CLI parsing when tsconfig-paths is embedded into other CLIs, like Vite.

The idea is to avoid parsing --project and -P flags when register is being called programmatically. But when node -r tsconfig-paths/register is used, those flags will still be supported. WDYT?

jonaskello commented 2 years ago

The register.js file is just a shortcut into the compiled version of register.ts. So I think it would be confusing to put extra code within it. It has the same function as the new exports directive in package.json where you can export as /register.js from within /lib/register.js.

So I think it might be better to keep the register.js->register.ts mirroring and add a new programmatic api to avoid any extra parsing.

aleclarson commented 2 years ago

I don't see what's so confusing, but we can do it your way. What should the new function be called?

jonaskello commented 2 years ago

I looked a bit more into it now. An alternative to a new function might be to have register() disregard command line options when it receives the ExplicitParams as parameter. If you pass ExplicitParams they are the only params used, and the command line is disregarded. So it will only parse the command line if no parameter is passed. Would that work for what you need?

aleclarson commented 2 years ago

Sounds good to me! I'll update this PR

jonaskello commented 2 years ago

@aleclarson I merged #205. This PR now has some conflicts, could you take a look at those and then add an entry to the CHANGELOG? I guess this could be considered breaking since before you could pass explicit params and get the path from the commandline which is no longer possible?

aleclarson commented 2 years ago

Would you put this under Added or Fixed or smth else?

jonaskello commented 2 years ago

Do you think this change will be breaking? In that case it should go under "Changed" according to the changelog format. If we're doing a major release there might be some more PRs we could merge.

aleclarson commented 2 years ago

LGTM