Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extra re-exports for default modules #2288

Merged
merged 4 commits into from
Oct 23, 2021
Merged

Add extra re-exports for default modules #2288

merged 4 commits into from
Oct 23, 2021

Conversation

garrettjstevens
Copy link
Collaborator

There are some inconsistencies in the way things are re-exported from core. For example, most of the pluggable element types look something like this:

import TrackType from '../pluggableElementTypes/TrackType'
const libs = { '@jbrowse/core/pluggableElementTypes/TrackType': TrackType, /* ...all the other libs */ }

But the render type looks like this:

import * as RendererType from '../pluggableElementTypes/renderers/RendererType'
const libs = { '@jbrowse/core/pluggableElementTypes/renderers/RendererType': RendererType, /* ...all the other libs */ }

Most of the renderers are like that, but the chord renderer is different:

import * as ServerSideRendererType from '../pluggableElementTypes/renderers/ServerSideRendererType'
import CircularChordRendererType from '../pluggableElementTypes/renderers/CircularChordRendererType'
import * as BoxRendererType from '../pluggableElementTypes/renderers/BoxRendererType'
import * as FeatureRendererType from '../pluggableElementTypes/renderers/FeatureRendererType'
import * as RendererType from '../pluggableElementTypes/renderers/RendererType'

This has some implications for how these are used at runtime. To properly get the TrackType at runtime, you have to do:

const TrackType = JBrowseExports['@jbrowse/core/pluggableElementTypes/TrackType']

But for RendererType you have to add a .default

const RendererType = JBrowseExports['@jbrowse/core/pluggableElementTypes/renderers/RendererType'].default

The real problem gets to be when a build system is trying to compile a plugin. These two imports looks similar:

import TrackType from '@jbrowse/core/pluggableElementTypes/TrackType'
import RendererType from '@jbrowse/core/pluggableElementTypes/renderers/RendererType'

but have to get compiled differently to use the global JBrowseExports properly. Our current UMD plugin build does some things to try to smooth this out, which work most of the time, but building to other targets doesn't work as well. Also, if core were ever used directly as a module running in Node, you'd have to worry about putting .defaults in the right places as well.

The change in this PR doesn't change any of this behavior, since I didn't want to break anything, but it does add some exports for the renderers so there is a consistent and named (not default) way of importing them that build systems can understand more easily.

@garrettjstevens garrettjstevens self-assigned this Sep 3, 2021
@github-actions github-actions bot added the needs label triage Needs a label to show in changelog (breaking, enhancement, bug, documentation, or internal) label Sep 3, 2021
@cmdcolin
Copy link
Collaborator

Why is circularchordrenderer different? Would a breaking change be possible to sync it up?

@cmdcolin
Copy link
Collaborator

Notably that renderer class is an empty stub so could also be...removed?

@garrettjstevens
Copy link
Collaborator Author

Why is circularchordrenderer different? Would a breaking change be possible to sync it up?

I'm not sure why it's different. I think it might be good to add this as a non-breaking change that allows a consistent way of accessing the renderers for now, and then think about doing a breaking change later.

@garrettjstevens garrettjstevens marked this pull request as draft September 15, 2021 18:04
@garrettjstevens garrettjstevens marked this pull request as ready for review October 22, 2021 21:21
@garrettjstevens
Copy link
Collaborator Author

As discussed in a previous meeting, this now adds these re-exports so they are only a single level deep in the package, i.e. @jbrowse/core/pluggableElementTypes and @jbrowse/core/util.

@codecov
Copy link

codecov bot commented Oct 22, 2021

Codecov Report

Merging #2288 (7a822e1) into main (72f2892) will decrease coverage by 0.07%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2288      +/-   ##
==========================================
- Coverage   61.17%   61.09%   -0.08%     
==========================================
  Files         538      538              
  Lines       25079    25079              
  Branches     5857     5857              
==========================================
- Hits        15341    15322      -19     
- Misses       9420     9439      +19     
  Partials      318      318              
Impacted Files Coverage Δ
packages/core/ReExports/modules.ts 75.00% <ø> (ø)
packages/core/util/index.ts 84.48% <ø> (ø)
...inearGenomeView/components/RefNameAutocomplete.tsx 75.26% <0.00%> (-10.76%) ⬇️
...nts/src/SNPCoverageRenderer/SNPCoverageRenderer.ts 80.24% <0.00%> (-7.41%) ⬇️
...r-view/src/BaseChordDisplay/components/Loading.tsx 95.00% <0.00%> (-5.00%) ⬇️
packages/core/TextSearch/TextSearchManager.ts 96.55% <0.00%> (-3.45%) ⬇️
products/jbrowse-web/src/util.ts 27.27% <0.00%> (-3.04%) ⬇️

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 72f2892...7a822e1. Read the comment docs.

@cmdcolin cmdcolin merged commit 195c635 into main Oct 23, 2021
@cmdcolin cmdcolin added internal and removed needs label triage Needs a label to show in changelog (breaking, enhancement, bug, documentation, or internal) labels Oct 23, 2021
@cmdcolin cmdcolin deleted the adjust_reexports branch October 24, 2021 12:31
cmdcolin pushed a commit that referenced this pull request Nov 1, 2021
* Add extra re-exports for default modules

* Make re-exports not so deep in the package

* Fix name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants