Remove Barrel Files

Decision

Prefer to not use barrel files in our codebase (mainly Client Dashboard 2). Instead, we should use named exports and imports.

Problems

Jest internally uses a custom require implementation that enables it to mock modules. This implementation needs to parse all the imported files from barrel files resulting in a performance penalty.

Context

While profiling our test suite, we noticed that the majority of the time was spent in the jest setup phase, parsing the barrel files. This issue does alleviate when running all the tests after the modules are loaded due to caching, but running one test file is still impacted. This is a known issue in Jest and there is an open issue to fix it:

Reasoning

The benefits of barrel files are mostly to reduce import statements and make it easier to write them when adding new components, but tooling can now auto import files without the need to manually write them. Because this comes with a performance penalty, we should prefer to not use them.

References:

Consequences

How do we implement this change?

In the client-dashboard-2 project we need to remove the index.ts file from our ui module, services, containers and hooks folders.

Who will implement the change?

The main responsibility will be on the Create team, but the change will impact all the teams that use the client-dashboard-2 project.

What could go wrong?

We could cause merge conflicts if teams have work in progress that will be impacted by the import changes.

What do we do if something goes wrong?

If there are merge conflicts, a quick way to resolve them is to remove all imports and let the IDE auto import the files again.