-
-
Notifications
You must be signed in to change notification settings - Fork 572
Various improvements for writing ESM components #7462
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
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7462 +/- ##
==========================================
+ Coverage 82.30% 82.36% +0.06%
==========================================
Files 338 338
Lines 50819 50893 +74
==========================================
+ Hits 41825 41918 +93
+ Misses 8994 8975 -19 ☔ View full report in Codecov by Sentry. |
|
ESM Components are AWESOME! I've been thrilled for this capability for a while now!! While you're in here making ESM improvements, I noticed a few
Comments added pointing out issues for component in components:
name = component.__name__
esm_path = component._esm_path(compiled=False)
if esm_path:
ext = esm_path.suffix # ISSUE: this returns `.js` for a standard esm js file
else:
ext = 'jsx' if issubclass(component, ReactComponent) else 'js' # ISSUE: this seems to assume ext won't have a dot in the suffix
code, component_deps = extract_dependencies(component)
# Detect default export in component code and handle import accordingly
if _EXPORT_DEFAULT_RE.search(code):
index += f'import {name} from "./{name}"\n'
else:
index += f'import * as {name} from "./{name}"\n'
with open(path / f'{name}.{ext}', 'w') as component_file: # ISSUE: when ext is '.js', the output file is `<name>..js` which breaks build
component_file.write(code)I think the fix is just to adjust as such: for component in components:
name = component.__name__
esm_path = component._esm_path(compiled=False)
if esm_path:
ext = esm_path.suffix
else:
ext = '.jsx' if issubclass(component, ReactComponent) else '.js'
code, component_deps = extract_dependencies(component)
# Detect default export in component code and handle import accordingly
if _EXPORT_DEFAULT_RE.search(code):
index += f'import {name} from "./{name}"\n'
else:
index += f'import * as {name} from "./{name}"\n'
with open(path / f'{name}{ext}', 'w') as component_file:
component_file.write(code) |
|
Thanks, @griffinmilsap. I believe 2. was already fixed in #7446 and I'm about to push up fixes for 1. |
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This PR provides a number of fixes and improvements for ESM components that I encountered as I was building a library with many components. This includes:
_constantsdict on a component to modify the behavior of a component without having to define (public) parametersNamedListPanelinterfaces.