-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Improved resolution of circularly dependent components (#316)" (
- Loading branch information
Showing
1 changed file
with
1 addition
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,7 @@ | ||
const merge = require('lodash/merge') | ||
|
||
// https://github.com/diegohaz/arc/wiki/Atomic-Design#do-not-worry | ||
const req = require.context('.', true, /\.\/[^/]+\/[^/]+\/index\.js$/) | ||
|
||
|
||
// This exports all components, resolving circular dependencies in two steps: | ||
// 1. export empty objects in place of each component | ||
// 2. require each component and merge it into the existing export for that module | ||
|
||
const componentPaths = [] | ||
|
||
// export an empty module for each component | ||
req.keys().forEach((key) => { | ||
const componentName = key.replace(/^.+\/([^/]+)\/index\.js/, '$1') | ||
componentPaths.push({ componentName, key }) | ||
module.exports[componentName] = {} | ||
}) | ||
|
||
// merge each component into its designated module | ||
componentPaths.forEach(({ componentName, key }) => { | ||
merge(module.exports[componentName], req(key).default) | ||
module.exports[componentName] = req(key).default | ||
}) |