Closed vilasmaciel closed 4 years ago
Merging #134 into master will increase coverage by
0.01%
. The diff coverage is100%
.
@@ Coverage Diff @@
## master #134 +/- ##
==========================================
+ Coverage 99.54% 99.55% +0.01%
==========================================
Files 37 38 +1
Lines 436 453 +17
==========================================
+ Hits 434 451 +17
Misses 2 2
Impacted Files | Coverage Δ | |
---|---|---|
lib/ContainerBuilder.js | 100% <ø> (ø) |
:arrow_up: |
lib/InstanceManager.js | 100% <100%> (ø) |
:arrow_up: |
lib/TagReference.js | 100% <100%> (ø) |
|
lib/Loader/FileLoader.js | 100% <100%> (ø) |
:arrow_up: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update cb5da7b...a8ae0db. Read the comment docs.
@vilasmaciel There is a problem with your solution. If "MultipleExports" exports a class called "MultipleExports" is still prioritized over default export even though the main is not specified.
This "problem" is due to the line 278:
const className = mainClassName || path.basename(classObject)
If there is no main, the file name is used as class name. I think that a better solution is:
fromDirectory = this.container.defaultDir || fromDirectory
const exportedModule = require(path.join(fromDirectory, classObject))
return exportedModule[mainClassName] || exportedModule.default || exportedModule[path.basename(classObject)]
In this case, the solution works fine in every scenario. First, you try to export the class defined by the main. Second, you try to export the default. Finally, you try to export using the file name.
I've updated the PR with the changes proposed by @rsaladocid, thanks for the comment!
awesome guys! nice job. If there is any change on documentation please make me a PR. Thanks
For definitions that contain the property
main
, the named export that indicates this main should be prioritized over the default export that the file could contain.For instance, a file that contains two exports:
A definition that uses the
ClassTwo
:Will end up getting an instance of
ClassDefault
as thedefault
export has priority over any named export, even when themain
property has been set.