Skip to content

chore: Add subpath entry points for all components #611

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

Merged
merged 1 commit into from
Jul 16, 2025

Conversation

kurtdoherty
Copy link
Contributor

@kurtdoherty kurtdoherty commented Jul 16, 2025

Context

  • Barrel files result in long build times and slow test times because they force tools to process every module exported by the barrel file, even if many of those modules will eventually be tree-shaken away. Typically, we only want to use barrel files for related units of code (e.g. src/components/side-bar/index.ts is a barrel file, but it's okay to use one here because it exports units of code designed to be used together, which means the chances of one things being used by a consumer and not the others is much smaller than a barrel file for the whole component library).
  • Export maps provide a mechanism for specifying dedicated entry points for subsets of a library; we already use an export map in Elements to enable consumers to import:
    • Everything from the library via @reapit/elements;
    • The new icons via @reapit/elements/icons/*;
    • The main stylesheet via @reapit/elements/styles.css;
    • The CSS reset stylesheet via @reapit/elements/reset.css; and,
    • The new utilities for handling URLSearchParams via @reapit/elements/utils/url-search-params.
  • We also recently reorganised the src directory to separate v5 components (now exclusively in src/components) from deprecated v4 components (now exclusively in src/deprecated).
  • We now want to provide new entry points for each of the v5 and deprecated v4 components; namely, @reapit/elements/core for v5 components and @reapit/elements/deprecated for the deprecated v4 components.

This PR

  • Updates the package manifest's export map to include new entry points for ./core/* and ./deprecated/* subpaths.
  • Updates the Vite config to dynamically build the set of entry points for all v5 components and all deprecated v4 components. The existing utils/url-search-params entry point is also updated to a generalised solution.
  • Adds a missing barrel file for src/components/table.
  • Renames src/menu/index.tsx to src/menu/index.ts so that it matches the convention we expect for component barrel files.
  • Removes the src/pattern as it does not fit the convention required for directories within src/deprecated: it has no index.ts and it doesn't make sense to add one.

note: these changes are entirely backwards compatible. Consumers can continue to import from the package's root entry point (@reapit/elements).

@rpt-uk-github
Copy link

rpt-uk-github commented Jul 16, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

code/snyk check is complete. No issues have been found. (View Details)

Copy link

codacy-production bot commented Jul 16, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for b3ad1bb1
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (b3ad1bb) Report Missing Report Missing Report Missing
Head commit (e2c4c38) 7482 6762 90.38%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#611) 0 0 ∅ (not applicable)

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Footnotes

  1. Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

@kurtdoherty kurtdoherty marked this pull request as ready for review July 16, 2025 00:05
@kurtdoherty kurtdoherty force-pushed the chore-add-unique-entry-points-for-components branch from b45afb8 to a43afe0 Compare July 16, 2025 00:08
@kurtdoherty kurtdoherty force-pushed the chore-add-unique-entry-points-for-components branch from a43afe0 to e2c4c38 Compare July 16, 2025 00:49
@@ -27,9 +50,11 @@ export default defineConfig({
lib: {
cssFileName: 'style',
entry: {
index: fileURLToPath(new URL('./src/index.ts', import.meta.url)),
'utils/url-search-params': fileURLToPath(new URL('./src/utils/url-search-params/index.ts', import.meta.url)),
index: 'src/index.ts',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: simplified this; I think the use of fileURLToPath on previous versions of Vite, but it's been possible to use a plain string for a while now.

"types": "./dist/types/components/*/index.d.ts",
"import": "./dist/js/components/*.js",
"require": "./dist/js/components/*.cjs"
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: new "core" entry point. This will allow v5 components to be imported without relying on the giant barrel file.

e.g. import { Button } from '@reapit/elements/core/button

"types": "./dist/types/deprecated/*/index.d.ts",
"import": "./dist/js/deprecated/*.js",
"require": "./dist/js/deprecated/*.cjs"
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: new "deprecated" entry point. This will allow deprecated v4 components to be imported without relying on the giant barrel file.

e.g. import { Button } from '@reapit/elements/deprecated/button

export * from './table-row'
export * from './table-row-selection'
export * from './table-text'
export * from './table-toolbar'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: this barrel file for all the table components was previously missing. Added now to support the imports via @reapit/elements/core/table

@kurtdoherty kurtdoherty merged commit b52ce02 into main Jul 16, 2025
6 checks passed
@kurtdoherty kurtdoherty deleted the chore-add-unique-entry-points-for-components branch July 16, 2025 00:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants