Closed slifty closed 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.
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!
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 subsequentrequire
.That seems to mean I need to require it? (E.g.(Correction: it's therequire('module-alias/register')
)./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: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 everynpm install
oryarn
. 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