Replace barrel-file ternaries with webpack platform aliases and usePlatformFeatures (HMS-10834)#4531
Closed
kingsleyzissou wants to merge 9 commits into
Closed
Replace barrel-file ternaries with webpack platform aliases and usePlatformFeatures (HMS-10834)#4531kingsleyzissou wants to merge 9 commits into
kingsleyzissou wants to merge 9 commits into
Conversation
Collaborator
Author
|
This is probably a more elegant solution than: |
kingsleyzissou
force-pushed
the
webpack-aliases
branch
3 times, most recently
from
June 16, 2026 10:04
6c8390d to
86ed954
Compare
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## main #4531 +/- ##
==========================================
+ Coverage 75.51% 75.75% +0.23%
==========================================
Files 225 227 +2
Lines 7214 7219 +5
Branches 2673 2667 -6
==========================================
+ Hits 5448 5469 +21
+ Misses 1519 1505 -14
+ Partials 247 245 -2
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
Collaborator
Author
|
/jira-epic HMS-10502 |
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The new
usePlatformFeatureshook is starting to accumulate a broad set of unrelated flags; consider grouping by concern (e.g. release-selection, architecture, security/labels, export behavior) or splitting into smaller hooks to keep call sites and future additions easier to reason about. - There are several duplicated alias configurations across
fec.config.js,cockpit/webpack.config.ts,vitest.config.ts, andtsconfig.json(backend/contentSources/useGetEnvironment); it may be worth centralizing or at least co-locating these definitions to reduce the risk of the platform-specific resolution getting out of sync. - The new type assertions like
requestBody as CreateBlueprintRequestandonPremRequest as ApiContentUnitSearchRequestsuggest the API typings don’t quite match real call shapes; if possible, tighten the shared types or introduce narrower request types instead of relying onascasts at the call sites.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `usePlatformFeatures` hook is starting to accumulate a broad set of unrelated flags; consider grouping by concern (e.g. release-selection, architecture, security/labels, export behavior) or splitting into smaller hooks to keep call sites and future additions easier to reason about.
- There are several duplicated alias configurations across `fec.config.js`, `cockpit/webpack.config.ts`, `vitest.config.ts`, and `tsconfig.json` (backend/contentSources/useGetEnvironment); it may be worth centralizing or at least co-locating these definitions to reduce the risk of the platform-specific resolution getting out of sync.
- The new type assertions like `requestBody as CreateBlueprintRequest` and `onPremRequest as ApiContentUnitSearchRequest` suggest the API typings don’t quite match real call shapes; if possible, tighten the shared types or introduce narrower request types instead of relying on `as` casts at the call sites.
## Individual Comments
### Comment 1
<location path="src/Components/CreateImageWizard/steps/Packages/components/PackageSearch.tsx" line_range="261-269" />
<code_context>
+ // On-prem uses a different request shape with `packages` field;
+ // this branch is unreachable in the hosted build but the code
+ // is shared across targets.
+ const onPremRequest = {
+ packages: [debouncedSearchTerm],
+ architecture: arch,
+ distribution,
+ };
searchDistroRpms({
- apiContentUnitSearchRequest: {
- packages: [debouncedSearchTerm],
- architecture: arch,
- distribution,
- },
+ apiContentUnitSearchRequest:
+ onPremRequest as ApiContentUnitSearchRequest,
});
</code_context>
<issue_to_address>
**suggestion:** Avoid the loose type assertion when building the on-prem search request.
The loose cast here means future changes to `ApiContentUnitSearchRequest` (e.g., renamed fields or different shapes) won’t be caught at compile time and could fail at runtime. Instead, either type `onPremRequest` directly as `ApiContentUnitSearchRequest`:
```ts
const onPremRequest: ApiContentUnitSearchRequest = {
packages: [debouncedSearchTerm],
architecture: arch,
distribution,
};
```
or create a small helper that returns `ApiContentUnitSearchRequest` for the on-prem branch so the compiler enforces the contract.
```suggestion
const onPremRequest: ApiContentUnitSearchRequest = {
packages: [debouncedSearchTerm],
architecture: arch,
distribution,
};
searchDistroRpms({
apiContentUnitSearchRequest: onPremRequest,
});
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Co-authored-by: Claude Sonnet 4 <noreply@anthropic.com>
…olution Co-authored-by: Claude Sonnet 4 <noreply@anthropic.com>
…solution Co-authored-by: Claude Sonnet 4 <noreply@anthropic.com>
Co-authored-by: Claude Sonnet 4 <noreply@anthropic.com>
Co-authored-by: Claude Sonnet 4 <noreply@anthropic.com>
Co-authored-by: Claude Sonnet 4 <noreply@anthropic.com>
…atures Co-authored-by: Claude Sonnet 4 <noreply@anthropic.com>
…o usePlatformFeatures Co-authored-by: Claude Sonnet 4 <noreply@anthropic.com>
The webpack/tsconfig aliases for backend, contentSources, and useGetEnvironment resolve to different index files per build target. Importing the platform-specific files directly bypasses this switching and can silently break the cockpit build. The rule is disabled for the alias test directories that legitimately test both variants. Co-authored-by: Claude Sonnet 4 <noreply@anthropic.com>
kingsleyzissou
force-pushed
the
webpack-aliases
branch
from
June 16, 2026 16:31
86ed954 to
4202097
Compare
kingsleyzissou
marked this pull request as draft
June 17, 2026 09:03
Collaborator
Author
|
More elegant than the other PR, but introduces other problems. Maybe we stick with the status quo or try figure out how to run some of the test suite for on-prem (not trivial) |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace the 19
process.env.IS_ON_PREMISEternaries in barrel files with build-time webpack alias resolution, and introduce ausePlatformFeatureshook that translates the rawisOnPremiseboolean into semantic capability flags for component-level branching.Changes
Webpack alias swap for hook resolution — Paired alias files (
index.hosted.ts/index.onprem.ts) replace the ternary-laden barrel files inbackend/,contentSources/, anduseGetEnvironment. Each webpack config resolves@/store/api/backendto the correct platform file at build time, so consumers don't change and the other platform's code never enters the module graph.usePlatformFeatureshook — A thin hook that mapsisOnPremiseto named capabilities (canCrossArchBuild,showDevelopmentReleases,securitySectionLabel, etc.). Migrated 5 components as proof-of-concept; remaining components can adopt incrementally.Cleanup of
process.env.IS_ON_PREMISEin shared hooks —contentSources/hooks.tsxandbackend/hooks.tsxnow use the existingselectIsOnPremiseselector instead of reading the env var directly.Test coverage — Export-surface tests for both alias files, alias-resolution tests verifying vitest wiring,
usePlatformFeaturesunit tests, and updated component tests covering both platform behaviors viapreloadedState.Notes
Build-time platform file resolution is a well-established pattern across the ecosystem:
.ios.ts/.android.tsextensions automatically per target platform.web.tsfor browser targetspackage.jsonexportsfield resolves different entry points based on conditions ("browser","node","import")preact/compatstory is aresolve.aliasswap for Reactresolve.aliasis explicitly recommended for environment-specific buildsJIRA: HMS-10834