tvkitchen / countertop

The entry point for developers who want to set up a TV Kitchen.
https://tv.kitchen
GNU Lesser General Public License v3.0
6 stars 2 forks source link

Getting rid of module-alias #89

Closed slifty closed 4 years ago

slifty commented 4 years ago

Task

Description

Now that countertop is going to be a package, we need to remove module_alias. This was identified a while ago by @chriszs in #51.

To quote Chris:


module-alias theoretically supports imports, and does so under Babel, but the way it does so is to hijack every subsequent require. That seems to mean I need to require it? (E.g. require('module-alias/register')). (Correction: it's the /register part it doesn't seem to like. import register from 'module-alias' might work?) And it seems ineffective at rewriting imports if they don't go through Babel.

One pitfall of the require hijack approach (internally it uses a require hijacker called pirates, amusingly, according to my stack traces) is acknowledged in its README:

WARNING: This module should not be used in other npm modules since it modifies the default require behavior! It is designed to be used for development of final projects i.e. web-sites, applications etc.

This could be a barrier to adaptive reuse, even if the core TVKitchen module is primarily for running directly.

There are alternative approaches. One detailed here uses link-module-alias, which creates symlinks as a post-install step run after every npm install or yarn. That post also mentions yarn workspaces as an alternative, one already being used in this project elsewhere.

One benefit is those approaches might need fewer shims, e.g. for ESLint and Jest. But there may be other tradeoffs.


Relevant Resources / Research

Related Issues

None

slifty commented 4 years ago

It seems that link-module-alias is indeed our best bet here.

It isn't clear to me that yarn workspaces is an exact match, whereas link-module-alias would allow us to use our existing _moduleAlias stuff and simply remove the no-longer-necessary shims.

slifty commented 4 years ago

Oh nuts, link-module-alias has the same issue around published packages:

From its README: WARNING Use this module only in final applications. It will not work inside published npm packages.

Back to the exploration!