RI-8216 [PoC] Shared UI/API code location (ri-shared)#6058
RI-8216 [PoC] Shared UI/API code location (ri-shared)#6058VaskoAtanasovRedis wants to merge 1 commit into
Conversation
🛡️ Jit Security Scan Results✅ No security findings were detected in this PR
Security scan by Jit
|
e28c074 to
af872f7
Compare
Proves out a single in-repo location for code consumed by both the UI and the API: the source lives at api/src/ri-shared/ (inside the api compile root, because nest build's tsc rootDir inference restructures dist/ when sources live outside it, breaking node dist/src/main and the desktop packaging) and the UI reaches it through a bare riShared/* alias, the same pattern as apiClient. The mirrored array-index helpers collapse into one module with one spec; gatekeeping rules live in ri-shared/README.md. References: #RI-8216 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
af872f7 to
b23fa6d
Compare
Code Coverage - Backend unit tests
Test suite run success3494 tests passing in 311 suites. Report generated by 🧪jest coverage report action from b23fa6d |
Code Coverage - Integration Tests
|
Code Coverage - Frontend unit tests
Test suite run success7150 tests passing in 814 suites. Report generated by 🧪jest coverage report action from b23fa6d |
| new URL('../redisinsight/api-client', import.meta.url), | ||
| ), | ||
| 'riShared': fileURLToPath( | ||
| new URL('../redisinsight/api/src/ri-shared', import.meta.url), |
There was a problem hiding this comment.
a shared package/dir should not be inside api folder, it would be in redisinsight/ri-shared
There was a problem hiding this comment.
Good instinct, and I went down that path — but there's a build constraint that makes a true top-level redisinsight/ri-shared much more involved than a relocation, so I've kept it at api/src/ri-shared for now. Reasoning:
The API actually consumes this util (the array-index validator imports it), so it has to be compiled into the api's dist. The api's tsconfig has no explicit rootDir, so tsc infers it from the common ancestor of all compiled files — today that's src, giving us dist/src/.... The moment a file from ../ri-shared enters the compile, the common ancestor becomes redisinsight/ and tsc emits dist/api/src/main.js + dist/ri-shared/... instead.
That breaks two things that hard-depend on the current layout:
node dist/src/main(thestart:prod/start:stageboot path)- the desktop app's hard-coded
api/dist/src/...imports —desktop/src/lib/server/server.tsdoesimport server from '../../../../api/dist/src/main', plus the azure / cloud-auth / window-auth modules
api-client gets to live top-level only because it's UI-consumed and never goes through nest build — ri-shared can't follow that pattern since the API compiles it.
To put it genuinely top-level we'd need to make ri-shared its own independently-built TS unit (project reference + own dist) and wire it into both api runtime resolution and desktop packaging — a real chunk of work + new CI surface for what's currently one small shared util. The api/src/ri-shared folder keeps the "shared, dependency-free, both-sides" boundary explicit (see its README) with zero packaging risk. If we accumulate enough shared code to justify the standalone package later, happy to revisit — flag it if you'd rather take that on now.
What
PoC for a single in-repo location for code shared between the UI and the API, prompted by the review discussion on #6053. Extracts the BigInt-as-string array-index helper (previously two mirrored modules) as the example — everything else is out of scope.
redisinsight/api/src/ri-shared/— inside the api compile root on purpose:nest build's tsc rootDir inference restructuresdist/when sources live outsideapi/src, breakingnode dist/src/mainand the desktop's hardcoded../api/dist/src. Inside it, the module ships like any other api file → zero new packaging surface.riShared/*alias (same pattern asapiClient), wired in ui tsconfig, Vite, root jest, Storybook, and the desktop type-check tsconfig.ri-shared/README.md.file:package — yarn-classic copies at install (stale during dev) and churns three lockfiles under the CI drift gate.Testing
yarn --cwd redisinsight/api test --testPathPattern "array-index"— 40 tests (shared module spec + decorator)vite build(production) resolves the aliasnest build: shared module emits insidedist/src/, imports rewritten to relative requires, compiled barrel smoke-tested under plain nodeyarn lint+yarn type-checkgreen across all projectsReferences: #RI-8216
🤖 Generated with Claude Code