@rise-x/apps-sdk 0.8.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +209 -21
- package/build/rsbuild/index.d.ts +36 -0
- package/build/rsbuild/index.js +225 -0
- package/build/ui/classes.json +209 -0
- package/build/ui/components/ai.d.ts +33 -1
- package/build/ui/components/app-frame.d.ts +19 -0
- package/build/ui/components/chat-input.d.ts +28 -0
- package/build/ui/components/message-scroller.d.ts +34 -10
- package/build/ui/components/nav.d.ts +2 -1
- package/build/ui/components/sheet.d.ts +10 -0
- package/build/ui/components/thinking-rings.d.ts +4 -0
- package/build/ui/demo.html +26794 -0
- package/build/ui/index.d.ts +3 -0
- package/build/ui/standalone.js +59 -58
- package/build/ui/styles.css +1 -1
- package/package.json +24 -3
- package/rsbuild/package.json +8 -0
- package/template/AGENTS.md +18 -10
- package/template/README.md +5 -5
- package/template/package.json +8 -9
- package/template/rsbuild.config.mts +17 -0
- package/template/src/App.tsx +21 -11
- package/template/tsconfig.json +3 -1
- package/build/ui/reference/README.md +0 -11
- package/build/ui/reference/components/accordion.tsx +0 -85
- package/build/ui/reference/components/ai.tsx +0 -291
- package/build/ui/reference/components/alert-dialog.tsx +0 -213
- package/build/ui/reference/components/alert.tsx +0 -112
- package/build/ui/reference/components/aspect-ratio.tsx +0 -28
- package/build/ui/reference/components/avatar.tsx +0 -158
- package/build/ui/reference/components/badge.tsx +0 -160
- package/build/ui/reference/components/button-group.tsx +0 -77
- package/build/ui/reference/components/button.tsx +0 -107
- package/build/ui/reference/components/calendar.tsx +0 -119
- package/build/ui/reference/components/card.tsx +0 -144
- package/build/ui/reference/components/carousel.tsx +0 -248
- package/build/ui/reference/components/chart.tsx +0 -704
- package/build/ui/reference/components/checkbox.tsx +0 -44
- package/build/ui/reference/components/collapsible.tsx +0 -43
- package/build/ui/reference/components/combobox.tsx +0 -141
- package/build/ui/reference/components/command.tsx +0 -181
- package/build/ui/reference/components/context-menu.tsx +0 -243
- package/build/ui/reference/components/data-table.tsx +0 -650
- package/build/ui/reference/components/date-picker.tsx +0 -218
- package/build/ui/reference/components/dialog.tsx +0 -172
- package/build/ui/reference/components/direction.tsx +0 -22
- package/build/ui/reference/components/dropdown-menu.tsx +0 -245
- package/build/ui/reference/components/empty-state.tsx +0 -63
- package/build/ui/reference/components/field.tsx +0 -252
- package/build/ui/reference/components/file-upload.tsx +0 -116
- package/build/ui/reference/components/hover-card.tsx +0 -64
- package/build/ui/reference/components/input-group.tsx +0 -157
- package/build/ui/reference/components/input-otp.tsx +0 -106
- package/build/ui/reference/components/input.tsx +0 -86
- package/build/ui/reference/components/item.tsx +0 -188
- package/build/ui/reference/components/kbd.tsx +0 -43
- package/build/ui/reference/components/label.tsx +0 -19
- package/build/ui/reference/components/list.tsx +0 -191
- package/build/ui/reference/components/map.css +0 -251
- package/build/ui/reference/components/map.tsx +0 -294
- package/build/ui/reference/components/menubar.tsx +0 -275
- package/build/ui/reference/components/message-scroller.tsx +0 -141
- package/build/ui/reference/components/message.tsx +0 -171
- package/build/ui/reference/components/nav.tsx +0 -122
- package/build/ui/reference/components/navigation-menu.tsx +0 -191
- package/build/ui/reference/components/page-header.tsx +0 -245
- package/build/ui/reference/components/popover.tsx +0 -76
- package/build/ui/reference/components/progress.tsx +0 -31
- package/build/ui/reference/components/radio.tsx +0 -65
- package/build/ui/reference/components/resizable.tsx +0 -40
- package/build/ui/reference/components/scroll-area.tsx +0 -55
- package/build/ui/reference/components/segmented.tsx +0 -45
- package/build/ui/reference/components/select.tsx +0 -188
- package/build/ui/reference/components/separator.tsx +0 -26
- package/build/ui/reference/components/sheet.tsx +0 -184
- package/build/ui/reference/components/skeleton.tsx +0 -15
- package/build/ui/reference/components/slider.tsx +0 -161
- package/build/ui/reference/components/snackbar.tsx +0 -27
- package/build/ui/reference/components/sonner.tsx +0 -43
- package/build/ui/reference/components/spinner.tsx +0 -27
- package/build/ui/reference/components/statistic.tsx +0 -122
- package/build/ui/reference/components/stepper.tsx +0 -138
- package/build/ui/reference/components/switch.tsx +0 -47
- package/build/ui/reference/components/table.tsx +0 -246
- package/build/ui/reference/components/textarea.tsx +0 -28
- package/build/ui/reference/components/timeline.tsx +0 -101
- package/build/ui/reference/components/toggle-group.tsx +0 -86
- package/build/ui/reference/components/toggle.tsx +0 -46
- package/build/ui/reference/components/tooltip.tsx +0 -53
- package/build/ui/reference/index.ts +0 -68
- package/build/ui/reference/lib/utils.ts +0 -34
- package/template/webpack.config.js +0 -112
- package/template/webpack.local.config.js +0 -68
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ pnpm start
|
|
|
22
22
|
| Flag | Default | Meaning |
|
|
23
23
|
| --- | --- | --- |
|
|
24
24
|
| `--pm=<npm\|yarn\|pnpm>` | auto-detected | package manager used for `install` |
|
|
25
|
-
| `--port=<n>` | `5101` |
|
|
25
|
+
| `--port=<n>` | `5101` | dev-server port in the generated app |
|
|
26
26
|
| `--skip-install` | off | skip `<pm> install` after scaffolding |
|
|
27
27
|
| `--json` | off | emit `{ path, slug, scope, pkgName, port, pm }` on stdout |
|
|
28
28
|
|
|
@@ -32,13 +32,49 @@ The package ships what an agent needs to build **static single-file HTML
|
|
|
32
32
|
design mocks** without repo access:
|
|
33
33
|
|
|
34
34
|
- `build/ui/styles.css` — the compiled design-system stylesheet, **Inter font
|
|
35
|
-
embedded** — inline it into the mock.
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
embedded**, **Tailwind preflight included** — inline it into the mock. The
|
|
36
|
+
preflight matters: a standalone HTML file has no host to establish
|
|
37
|
+
`box-sizing: border-box`, and without it every `w-full` control with
|
|
38
|
+
horizontal padding renders wider than its container.
|
|
39
|
+
- `build/ui/demo.html` — the Shell design-system demo page, pre-rendered to
|
|
40
|
+
static HTML: ground-truth markup for every component, generated at build
|
|
41
|
+
time from `Shell/src/components/__demo__`. Fully self-contained — it inlines
|
|
42
|
+
`styles.css` above, the same file you inline into your mock, so markup
|
|
43
|
+
copied out of the demo renders in your mock exactly as it renders there.
|
|
44
|
+
Utilities you invent for the mock's own scaffolding are a different matter:
|
|
45
|
+
only classes used by the design system or by the demo page have rules, so
|
|
46
|
+
write mock layout as plain CSS. Specimens styled by CSS outside the design
|
|
47
|
+
system (the map's leaflet sheet, the Ask Diana animations) render unstyled
|
|
48
|
+
in the demo and in mocks.
|
|
49
|
+
- `build/ui/classes.json` — the exact class string for every variant of every
|
|
50
|
+
variant-bearing component, generated from the components' own cva functions
|
|
51
|
+
and merged the way the component merges them. Use it for a combination the
|
|
52
|
+
demo doesn't happen to render (a `default` button at size `sm`) instead of
|
|
53
|
+
splicing fragments from two specimens. Each entry names its `dimensions`, and
|
|
54
|
+
keys join their values in that order: `button.classes["default|sm"]`. Entries
|
|
55
|
+
are named after the cva function, not the file it lives in — `trend` and
|
|
56
|
+
`confidence`, not `statistic` and `ai`.
|
|
38
57
|
- `template/src/App.tsx` — the canonical app layout (left-rail chrome +
|
|
39
58
|
screens); scaffolded apps start from it, and design mocks follow the same
|
|
40
59
|
composition.
|
|
41
60
|
|
|
61
|
+
### Navigating demo.html (for agents)
|
|
62
|
+
|
|
63
|
+
The file is pretty-printed and starts with a navigation guide plus a JSON
|
|
64
|
+
table of contents (`<script type="application/json" id="demo-toc">`) listing
|
|
65
|
+
every section, screen, and the `data-slot` components each section
|
|
66
|
+
demonstrates. Read the first ~80 lines for the TOC, then grep:
|
|
67
|
+
|
|
68
|
+
| To find | Grep for |
|
|
69
|
+
| --- | --- |
|
|
70
|
+
| a section (component family / pattern) | `data-section="<id>"` |
|
|
71
|
+
| a full screen (app layout, AI chat, dashboard, ...) | `data-screen-panel="<id>"` |
|
|
72
|
+
| one component's real markup | `data-slot="<name>"` |
|
|
73
|
+
|
|
74
|
+
Component props and variants live in the shipped types —
|
|
75
|
+
`build/ui/components/<name>.d.ts`, named to match the `data-slot` prefixes
|
|
76
|
+
(in the rise-x-app monorepo, the sources are `packages/ui/src/components/`).
|
|
77
|
+
|
|
42
78
|
## Use in app code
|
|
43
79
|
|
|
44
80
|
```ts
|
|
@@ -65,6 +101,56 @@ re-exported for apps:
|
|
|
65
101
|
import { Button, Dialog, DialogContent, Input, cn } from '@rise-x/apps-sdk/ui';
|
|
66
102
|
```
|
|
67
103
|
|
|
104
|
+
#### App layout (`AppFrame` / `AppRail` / `AppContent`)
|
|
105
|
+
|
|
106
|
+
The root layout contract, scaffolded into every new app:
|
|
107
|
+
|
|
108
|
+
```tsx
|
|
109
|
+
<AppFrame mobileNav="tabs">
|
|
110
|
+
<AppRail>{/* Nav / NavItem rail */}</AppRail>
|
|
111
|
+
<AppContent>{/* screens; the app's ONE scroll container */}</AppContent>
|
|
112
|
+
</AppFrame>
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
The next-gen shell hands the app a full-height region that extends under its
|
|
116
|
+
floating top bar and publishes the bar's height as `--topbar-h` on the
|
|
117
|
+
document. `AppRail` stays fixed on the left and starts below the bar;
|
|
118
|
+
`AppContent` owns the scroll and slides content **behind** the bar's blur.
|
|
119
|
+
Both pad with `var(--topbar-h, 0px)`, so in hosts without a floating bar
|
|
120
|
+
(the classic shell, standalone dev) the frame degrades to a plain
|
|
121
|
+
rail-plus-content layout. Never hardcode a bar height and never add a second
|
|
122
|
+
page-level scroller.
|
|
123
|
+
|
|
124
|
+
The frame is responsive by default, and it measures **itself**, not the window:
|
|
125
|
+
`AppFrame` is a CSS container, so the layout answers to the region the app was
|
|
126
|
+
given (the shell's chrome takes space the app never gets). Below the frame's
|
|
127
|
+
`2xl` container width (672px) it stacks and `NavSection` headers hide.
|
|
128
|
+
|
|
129
|
+
Being a container also makes the frame the containing block for `position:
|
|
130
|
+
fixed` descendants, in every mode: a fixed action bar or FAB you render inside
|
|
131
|
+
`AppFrame` pins to the app's region, not to the browser window. That is
|
|
132
|
+
usually what you want. For something that genuinely belongs to the window,
|
|
133
|
+
portal it to `document.body` the way the kit's `Dialog`, `Sheet` and `Popover`
|
|
134
|
+
already do.
|
|
135
|
+
|
|
136
|
+
`mobileNav` picks what the rail becomes at that width:
|
|
137
|
+
|
|
138
|
+
| Value | Narrow rail |
|
|
139
|
+
| --- | --- |
|
|
140
|
+
| `"strip"` (default) | A horizontal, scrollable nav strip under the top bar. |
|
|
141
|
+
| `"tabs"` | A bottom tab bar, the native phone pattern — icon over label, one equal share each, safe-area padding. The scaffold sets this. |
|
|
142
|
+
|
|
143
|
+
In `tabs` mode an app with **more than five** nav items shows the first four and
|
|
144
|
+
a **More** tab that opens the rest in a bottom sheet; the wide rail still lists
|
|
145
|
+
everything. Pass `moreLabel` on `AppRail` to localise the label. Don't hand-roll
|
|
146
|
+
a tab bar, and don't write your own breakpoints around the frame; compose inside
|
|
147
|
+
it.
|
|
148
|
+
|
|
149
|
+
Rendering an `AppFrame` anywhere in the app is the signal that the app owns
|
|
150
|
+
its layout: the next-gen shell detects it and hands over the full-bleed
|
|
151
|
+
region. Apps without one are compensated — the host pads and scrolls the
|
|
152
|
+
region itself — so pre-frame bundles keep working, minus the fixed rail.
|
|
153
|
+
|
|
68
154
|
How it works: the SDK ships the **typings**; the **runtime** is the shell's own
|
|
69
155
|
copy of `@rise-x/ui`, delivered through the Module Federation share scope —
|
|
70
156
|
exactly how apps already consume React. That is deliberate: the components are
|
|
@@ -73,14 +159,14 @@ correctly, and there is never a second React/component instance.
|
|
|
73
159
|
|
|
74
160
|
Requirements in the app:
|
|
75
161
|
|
|
76
|
-
1.
|
|
162
|
+
1. It must be a Module Federation share. The preset does this for you:
|
|
77
163
|
|
|
78
164
|
```js
|
|
79
165
|
'@rise-x/ui': { singleton: true, requiredVersion: false, import: false },
|
|
80
166
|
```
|
|
81
167
|
|
|
82
|
-
2. Federated, components render from the shell's copy. The standalone
|
|
83
|
-
|
|
168
|
+
2. Federated, components render from the shell's copy. The preset's standalone
|
|
169
|
+
branch aliases `@rise-x/ui` to the SDK's own
|
|
84
170
|
compiled bundle (`./ui/standalone`) instead — a self-contained snapshot
|
|
85
171
|
with its CSS self-injected, so components render for real with no shell.
|
|
86
172
|
It's a snapshot, not the source of truth: verify in a host (or deployed)
|
|
@@ -132,7 +218,7 @@ cards and list rows, and children render over the map as overlays.
|
|
|
132
218
|
|
|
133
219
|
### Lifecycle hooks
|
|
134
220
|
|
|
135
|
-
Expose a `./lifecycle` module
|
|
221
|
+
Expose a `./lifecycle` module — the preset exposes it by default — and export any subset of the three hooks:
|
|
136
222
|
|
|
137
223
|
```ts
|
|
138
224
|
// src/lifecycle.ts
|
|
@@ -153,15 +239,12 @@ export const onUninstall: UninstallHook = async ({ manifest }) => {
|
|
|
153
239
|
};
|
|
154
240
|
```
|
|
155
241
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
},
|
|
163
|
-
// ...
|
|
164
|
-
});
|
|
242
|
+
`./App` and `./lifecycle` are exposed by `defineAppConfig()` already; pass
|
|
243
|
+
`exposes` only to add more:
|
|
244
|
+
|
|
245
|
+
```ts
|
|
246
|
+
// rsbuild.config.mts
|
|
247
|
+
defineAppConfig({ pkg, port: 5101, exposes: { './Widget': './src/Widget' } });
|
|
165
248
|
```
|
|
166
249
|
|
|
167
250
|
The shell invokes hooks best-effort: errors are logged, 10s timeout per hook, missing hooks skip silently. Hooks run inside the shell's page — `getShellApi()` / `getShellApiV4()` work from inside them.
|
|
@@ -587,9 +670,9 @@ function MyPanel({ flowOriginId }: { flowOriginId: string }) {
|
|
|
587
670
|
`QueryClient` from React context: federated apps get a **per-app client the
|
|
588
671
|
shell mounts** around them (isolated from the shell's own persisted cache and
|
|
589
672
|
from other apps), and everywhere else — standalone dev, older shells — the
|
|
590
|
-
hooks fall back to a per-bundle client automatically. The one requirement:
|
|
591
|
-
|
|
592
|
-
|
|
673
|
+
hooks fall back to a per-bundle client automatically. The one requirement:
|
|
674
|
+
react-query must be a share so the shell's context can cross the federation
|
|
675
|
+
boundary — the preset does this for you:
|
|
593
676
|
|
|
594
677
|
```js
|
|
595
678
|
shared: {
|
|
@@ -703,6 +786,111 @@ per-app `QueryClient` (built with `createAppQueryClient` from
|
|
|
703
786
|
`@rise-x/apps-sdk/query`), which is what the SDK's query hooks pick up
|
|
704
787
|
through context in federated apps.
|
|
705
788
|
|
|
789
|
+
## Build config (`@rise-x/apps-sdk/rsbuild`)
|
|
790
|
+
|
|
791
|
+
Apps build with [Rsbuild](https://rsbuild.dev), and the Module Federation
|
|
792
|
+
contract with the shell lives in this preset rather than in each app's config.
|
|
793
|
+
|
|
794
|
+
```ts
|
|
795
|
+
// rsbuild.config.mts
|
|
796
|
+
import { defineConfig } from '@rsbuild/core';
|
|
797
|
+
import { defineAppConfig } from '@rise-x/apps-sdk/rsbuild';
|
|
798
|
+
import pkg from './package.json';
|
|
799
|
+
|
|
800
|
+
export default defineConfig(({ envMode }) =>
|
|
801
|
+
defineAppConfig({ pkg, port: 5102, standalone: envMode === 'standalone' }),
|
|
802
|
+
);
|
|
803
|
+
```
|
|
804
|
+
|
|
805
|
+
```bash
|
|
806
|
+
pnpm rsbuild build # federated bundle -> dist/
|
|
807
|
+
pnpm rsbuild dev # federated, served for a host to load
|
|
808
|
+
pnpm rsbuild dev --env-mode standalone # standalone, no shell -> dist-local/
|
|
809
|
+
```
|
|
810
|
+
|
|
811
|
+
Requires all three of `@rsbuild/core`, `@rsbuild/plugin-react` and
|
|
812
|
+
`@rsbuild/plugin-type-check` in the app — the preset imports each at module
|
|
813
|
+
level, so a missing one fails at config load with `MODULE_NOT_FOUND`. They are
|
|
814
|
+
optional peers here, so hosts that never import this subpath get no unmet-peer
|
|
815
|
+
noise; the scaffolder puts all three in a new app's devDependencies.
|
|
816
|
+
|
|
817
|
+
| Option | Required | Purpose |
|
|
818
|
+
|---|---|---|
|
|
819
|
+
| `pkg` | yes | the app's `package.json`. `name` derives the MF scope (`@rise-x-apps/vendor-hub` → `app_vendor_hub`); `version` is baked as `__APP_VERSION__` |
|
|
820
|
+
| `port` | yes | dev-server port. Must be unique across apps |
|
|
821
|
+
| `standalone` | no | no shell, no MF, React bundled in |
|
|
822
|
+
| `exposes` | no | extra MF exposes, merged over `./App` + `./lifecycle` |
|
|
823
|
+
| `define` | no | extra `source.define` entries, merged into the preset's own |
|
|
824
|
+
|
|
825
|
+
`__APP_VERSION__` is a `define`, so TypeScript needs to be told it exists. Add
|
|
826
|
+
`declare const __APP_VERSION__: string;` to the app if you read it.
|
|
827
|
+
|
|
828
|
+
The converse is the trap `define` exists for: a `declare const` in the app's
|
|
829
|
+
`global.d.ts` makes TypeScript accept the identifier whether or not the build
|
|
830
|
+
substitutes it. Declare one without passing it here and the app compiles clean,
|
|
831
|
+
then throws `ReferenceError` on load with nothing in the build output pointing
|
|
832
|
+
at the cause.
|
|
833
|
+
|
|
834
|
+
Values are raw code, not data — the same contract as webpack's `DefinePlugin` —
|
|
835
|
+
so a string arrives quoted. And because the option takes a fixed object, a value
|
|
836
|
+
that depends on the build has to be derived in the `defineConfig` callback:
|
|
837
|
+
|
|
838
|
+
```ts
|
|
839
|
+
export default defineConfig(({ envMode }) =>
|
|
840
|
+
defineAppConfig({
|
|
841
|
+
pkg,
|
|
842
|
+
port: 5101,
|
|
843
|
+
standalone: envMode === 'standalone',
|
|
844
|
+
define: {
|
|
845
|
+
__USE_SAMPLE_DATA__: String(envMode !== 'production'),
|
|
846
|
+
__API_LABEL__: JSON.stringify(envMode ?? 'development'),
|
|
847
|
+
},
|
|
848
|
+
}),
|
|
849
|
+
);
|
|
850
|
+
```
|
|
851
|
+
|
|
852
|
+
Passing `__APP_VERSION__` throws: it is derived from `pkg.version` so it always
|
|
853
|
+
matches the deployed manifest.
|
|
854
|
+
|
|
855
|
+
What the federated branch sets, and why it matters:
|
|
856
|
+
|
|
857
|
+
- **`ModuleFederationPluginV1`**, never the enhanced plugin — V1 emits the
|
|
858
|
+
container shape (`window[scope].init/get`) that both hosts' runtime loaders
|
|
859
|
+
speak.
|
|
860
|
+
- **`output.uniqueName = scope`** via `tools.rspack`. Rsbuild has no
|
|
861
|
+
`output.uniqueName` of its own, and it names the chunk-loading global — left
|
|
862
|
+
at the default it collides with the host's.
|
|
863
|
+
- **React, its JSX runtimes and `@rise-x/ui` are consume-only**
|
|
864
|
+
(`import: false`): the host provides the single copy. `@tanstack/react-query`
|
|
865
|
+
deliberately keeps its bundled fallback, so an app still works on a host that
|
|
866
|
+
does not share it.
|
|
867
|
+
- **React is shared as `^18.0.0 || ^19.0.0`**, because the two hosts are on
|
|
868
|
+
different majors (ClientApp 18, Shell 19) and one bundle must load on both.
|
|
869
|
+
That is a build-level permission, not a licence to use React 19 APIs — write
|
|
870
|
+
app code against the **React 18-compatible API surface**, since ClientApp is
|
|
871
|
+
still the production host.
|
|
872
|
+
- **Flat `dist/`** — `remoteEntry.js` beside its chunks *and every emitted
|
|
873
|
+
asset*, because `tools/apps-dev-server` probes `dist/remoteEntry.js` and the
|
|
874
|
+
deploy zips the *contents* of `dist/`. Rsbuild would otherwise route assets
|
|
875
|
+
into `static/<kind>/`; the preset flattens all of them, which is also what the
|
|
876
|
+
webpack configs it replaces did.
|
|
877
|
+
- **`assetPrefix: 'auto'` on both `output` and `dev`** so one bundle works on
|
|
878
|
+
the dev port and when the shell loads `remoteEntry.js` from the CDN. Rsbuild
|
|
879
|
+
splits what webpack had as a single `output.publicPath`, and the dev half
|
|
880
|
+
defaults to `/` — a remote served by `rsbuild dev` would otherwise resolve
|
|
881
|
+
its async chunks against the *host's* origin.
|
|
882
|
+
- **Production source maps**, which Rsbuild otherwise defaults off.
|
|
883
|
+
|
|
884
|
+
The preset's own `standalone` specs resolve `@rise-x/apps-sdk/ui/standalone`,
|
|
885
|
+
so run `pnpm build` in this package before `pnpm test` on a clean checkout (CI
|
|
886
|
+
already builds first).
|
|
887
|
+
|
|
888
|
+
Set `APP_SCOPE` to override the derived scope. That is only for registering two
|
|
889
|
+
builds of one app side by side (an old and a redesigned version, to compare
|
|
890
|
+
them) — two registrations may not share a scope, because the shell caches
|
|
891
|
+
loaded remotes by URL and the second `remoteEntry.js` would overwrite the
|
|
892
|
+
first's global. Leave it unset for normal releases.
|
|
893
|
+
|
|
706
894
|
## Local development against the SDK
|
|
707
895
|
|
|
708
896
|
In-repo consumers (ClientApp, apps/\*) declare `"@rise-x/apps-sdk": "workspace:*"`,
|
|
@@ -722,7 +910,7 @@ pnpm add @rise-x/apps-sdk
|
|
|
722
910
|
|
|
723
911
|
## Publishing
|
|
724
912
|
|
|
725
|
-
Publishes to the public npm registry (`registry.npmjs.org`) under the `rise-x` org, per `publishConfig` in `package.json`.
|
|
913
|
+
Publishes to the public npm registry (`registry.npmjs.org`) under the `rise-x` org, per `publishConfig` in `package.json`. Releases are manual: run the **Publish @rise-x/apps-sdk** workflow (`.github/workflows/publish-apps-sdk.yml`) via workflow dispatch, from `main` or a `release/*` branch — it publishes the version in `package.json`, and fails if that version is already on the registry.
|
|
726
914
|
|
|
727
915
|
To publish manually you need an npmjs account with publish rights in the `rise-x` org (`npm login`), then:
|
|
728
916
|
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { RsbuildConfig } from '@rsbuild/core';
|
|
2
|
+
export interface AppPackageJson {
|
|
3
|
+
name: string;
|
|
4
|
+
version?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface DefineAppConfigOptions {
|
|
7
|
+
/** The app's own package.json. `name` derives the Module Federation scope. */
|
|
8
|
+
pkg: AppPackageJson;
|
|
9
|
+
/**
|
|
10
|
+
* Dev-server port. Must be unique across apps — two apps on one port cannot
|
|
11
|
+
* be served side by side during development.
|
|
12
|
+
*/
|
|
13
|
+
port: number;
|
|
14
|
+
/**
|
|
15
|
+
* Standalone dev: no shell, no Module Federation, React bundled in.
|
|
16
|
+
* Drive it with `rsbuild dev --env-mode standalone`.
|
|
17
|
+
*
|
|
18
|
+
* Do NOT use `--env-mode local`: Rsbuild rejects that value outright,
|
|
19
|
+
* because `.env.local` is reserved as a temporary local file. The mode
|
|
20
|
+
* name is refused whether or not such a file exists.
|
|
21
|
+
*/
|
|
22
|
+
standalone?: boolean;
|
|
23
|
+
/** Extra Module Federation exposes, merged over `./App` + `./lifecycle`. */
|
|
24
|
+
exposes?: Record<string, string>;
|
|
25
|
+
/**
|
|
26
|
+
* Extra `source.define` entries. Values are raw code, so strings arrive
|
|
27
|
+
* quoted: `{ __MODE__: JSON.stringify('sample') }`. `__APP_VERSION__` throws.
|
|
28
|
+
*/
|
|
29
|
+
define?: Record<string, string>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Derive an app's Module Federation scope from its package name:
|
|
33
|
+
* `@rise-x-apps/vendor-hub` -> `app_vendor_hub`.
|
|
34
|
+
*/
|
|
35
|
+
export declare function deriveAppScope(packageName: string): string;
|
|
36
|
+
export declare function defineAppConfig({ pkg, port, standalone, exposes, define, }: DefineAppConfigOptions): RsbuildConfig;
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deriveAppScope = deriveAppScope;
|
|
4
|
+
exports.defineAppConfig = defineAppConfig;
|
|
5
|
+
const node_module_1 = require("node:module");
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
const plugin_react_1 = require("@rsbuild/plugin-react");
|
|
8
|
+
const plugin_type_check_1 = require("@rsbuild/plugin-type-check");
|
|
9
|
+
const lifecycle_1 = require("../lifecycle");
|
|
10
|
+
// The shell validates an app's scope against this, and `uniqueName` (the
|
|
11
|
+
// chunk-loading global) is the same string — so an invalid scope fails at
|
|
12
|
+
// runtime in ways that are hard to trace. Fail at config time instead.
|
|
13
|
+
const SCOPE_PATTERN = /^[a-z][a-z0-9_]*$/;
|
|
14
|
+
// React and its JSX runtimes are CONSUMED from the shell and never bundled.
|
|
15
|
+
// `import: false` prevents the duplicate-React-instance failure where Module
|
|
16
|
+
// Federation's singleton dedup picks the higher version after the host has
|
|
17
|
+
// already bound its react-dom to a lower one. The jsx-runtime entries are
|
|
18
|
+
// required because React 18's automatic JSX transform emits
|
|
19
|
+
// `import 'react/jsx-runtime'`; unshared, the bundled runtime would
|
|
20
|
+
// sync-require('react') and fail. A config with these shares only runs inside
|
|
21
|
+
// a host — standalone dev takes the `standalone` branch below, which bundles
|
|
22
|
+
// React itself.
|
|
23
|
+
//
|
|
24
|
+
// The version range must cover BOTH hosts: ClientApp resolves React 18, Shell
|
|
25
|
+
// resolves 19. Most apps' webpack configs carry a literal '^18.0.0', which Shell
|
|
26
|
+
// does not satisfy — it logs one warning per shared entry on every app load, and
|
|
27
|
+
// it states a constraint the apps do not actually have. Both hosts DERIVE the
|
|
28
|
+
// version they provide from the resolved package precisely so it cannot rot
|
|
29
|
+
// (see ClientApp/webpack.config.js).
|
|
30
|
+
//
|
|
31
|
+
// The range matches this package's own `react` peer range, and
|
|
32
|
+
// apps/medication-identifier already ships it in production. Be precise about
|
|
33
|
+
// what it does: with `singleton` and no `strictVersion` it does NOT reject a
|
|
34
|
+
// host on another React major — the host's copy is consumed either way. The
|
|
35
|
+
// range documents intent and silences the warning. Anyone adding
|
|
36
|
+
// `strictVersion` later is changing that, deliberately.
|
|
37
|
+
//
|
|
38
|
+
// Accepting both majors is a build-level permission, not a licence to use
|
|
39
|
+
// React 19 APIs. ClientApp is still the production host on React 18, so app
|
|
40
|
+
// code must stay on the React 18-compatible API surface (see AGENTS.md).
|
|
41
|
+
const CONSUMED_REACT_SHARE = {
|
|
42
|
+
singleton: true,
|
|
43
|
+
requiredVersion: '^18.0.0 || ^19.0.0',
|
|
44
|
+
import: false,
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Derive an app's Module Federation scope from its package name:
|
|
48
|
+
* `@rise-x-apps/vendor-hub` -> `app_vendor_hub`.
|
|
49
|
+
*/
|
|
50
|
+
function deriveAppScope(packageName) {
|
|
51
|
+
const slug = packageName.replace(/^@[^/]+\//, '');
|
|
52
|
+
const scope = `app_${slug.replace(/-/g, '_')}`;
|
|
53
|
+
if (!SCOPE_PATTERN.test(scope)) {
|
|
54
|
+
throw new Error(`[apps-sdk] Cannot derive a valid Module Federation scope from package name "${packageName}" ` +
|
|
55
|
+
`(got "${scope}", which must match ${SCOPE_PATTERN}). Rename the package, or set APP_SCOPE.`);
|
|
56
|
+
}
|
|
57
|
+
return scope;
|
|
58
|
+
}
|
|
59
|
+
function defineAppConfig({ pkg, port, standalone = false, exposes, define, }) {
|
|
60
|
+
// APP_SCOPE overrides the derived scope, for the case where an app must be
|
|
61
|
+
// registered ALONGSIDE another build of itself (e.g. an old and a redesigned
|
|
62
|
+
// version, side by side, to compare them). Two registrations may not share a
|
|
63
|
+
// scope: the shell resolves the container from `window[manifest.scope]` and
|
|
64
|
+
// caches loaded scripts by URL, so once the second remoteEntry.js has
|
|
65
|
+
// overwritten the global, the first registration re-uses the cached script
|
|
66
|
+
// promise and serves the SECOND app's container for both. Leave it unset for
|
|
67
|
+
// normal releases — the derived value is the app's identity.
|
|
68
|
+
const override = process.env.APP_SCOPE;
|
|
69
|
+
if (override && !SCOPE_PATTERN.test(override)) {
|
|
70
|
+
throw new Error(`[apps-sdk] APP_SCOPE="${override}" is not a valid Module Federation scope ` +
|
|
71
|
+
`(it must match ${SCOPE_PATTERN}).`);
|
|
72
|
+
}
|
|
73
|
+
const scope = override || deriveAppScope(pkg.name);
|
|
74
|
+
if (define && '__APP_VERSION__' in define) {
|
|
75
|
+
throw new Error('defineAppConfig: __APP_VERSION__ cannot be set through `define` — it is derived ' +
|
|
76
|
+
'from pkg.version so it always matches the deployed manifest. Change the version ' +
|
|
77
|
+
'in package.json instead.');
|
|
78
|
+
}
|
|
79
|
+
const base = {
|
|
80
|
+
// pluginTypeCheck is NOT optional polish. The webpack configs this preset
|
|
81
|
+
// replaces used ts-loader, which type-checked on every build, and that pass
|
|
82
|
+
// was each app's ONLY type gate: no workflow runs an app's `tsc` — the PR
|
|
83
|
+
// check builds ClientApp and Shell only, build-workspace-packages
|
|
84
|
+
// deliberately excludes apps/, and the pre-commit hook covers Shell,
|
|
85
|
+
// packages/ui and ClientApp. Rsbuild transpiles with SWC, which strips
|
|
86
|
+
// types without checking them, so without this `pnpm build` would happily
|
|
87
|
+
// produce a deploy artifact from code that does not compile.
|
|
88
|
+
plugins: [(0, plugin_react_1.pluginReact)(), (0, plugin_type_check_1.pluginTypeCheck)()],
|
|
89
|
+
source: {
|
|
90
|
+
entry: { index: './src/index.tsx' },
|
|
91
|
+
define: {
|
|
92
|
+
...define,
|
|
93
|
+
__APP_VERSION__: JSON.stringify(pkg.version ?? '0.0.0'),
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
html: { template: './public/index.html' },
|
|
97
|
+
server: {
|
|
98
|
+
port,
|
|
99
|
+
historyApiFallback: true,
|
|
100
|
+
// `public/` holds only the HTML template, which `html.template` already
|
|
101
|
+
// consumes. Left enabled, Rsbuild would also copy it to the dist root and
|
|
102
|
+
// clobber the generated index.html.
|
|
103
|
+
publicDir: false,
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
if (standalone) {
|
|
107
|
+
// Resolve React from the APP, not from the SDK — apps live at varying
|
|
108
|
+
// depths and pnpm hoists unpredictably.
|
|
109
|
+
const appRequire = (0, node_module_1.createRequire)((0, node_path_1.join)(process.cwd(), 'package.json'));
|
|
110
|
+
return {
|
|
111
|
+
...base,
|
|
112
|
+
output: {
|
|
113
|
+
distPath: { root: 'dist-local' },
|
|
114
|
+
assetPrefix: '/',
|
|
115
|
+
},
|
|
116
|
+
resolve: {
|
|
117
|
+
alias: {
|
|
118
|
+
// No shell means no share scope, so bundle the SDK's own compiled
|
|
119
|
+
// snapshot of the design system (CSS self-injected, Inter included).
|
|
120
|
+
// The federated build still gets the host's copy via the share scope.
|
|
121
|
+
'@rise-x/ui': require.resolve('@rise-x/apps-sdk/ui/standalone'),
|
|
122
|
+
// ONE React copy in the bundle. The workspace hoists react@18 to the
|
|
123
|
+
// root, but lucide-react, radix-ui and sonner all peer on React 19 and
|
|
124
|
+
// pnpm nests react@19 under each of them. The federated build is
|
|
125
|
+
// immune — Module Federation's `shared` rewires every `react` request
|
|
126
|
+
// in the compilation, including those inside node_modules. Standalone
|
|
127
|
+
// dev has no share scope, so without these aliases lucide's icons are
|
|
128
|
+
// built by React 19's createElement and the app's React 18 renderer
|
|
129
|
+
// rejects them outright ("Objects are not valid as a React child").
|
|
130
|
+
react: (0, node_path_1.dirname)(appRequire.resolve('react/package.json')),
|
|
131
|
+
'react-dom': (0, node_path_1.dirname)(appRequire.resolve('react-dom/package.json')),
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
...base,
|
|
138
|
+
output: {
|
|
139
|
+
// Flat dist: remoteEntry.js plus its sibling chunks at the archive root.
|
|
140
|
+
// tools/apps-dev-server probes `dist/remoteEntry.js`, and the deploy zips
|
|
141
|
+
// the CONTENTS of dist/ with remoteEntry.js at the top level.
|
|
142
|
+
// Every asset bucket flattened, matching the webpack configs this replaces;
|
|
143
|
+
// Rsbuild would otherwise nest them under `static/<kind>/`. Tracks Rsbuild's
|
|
144
|
+
// own distPath keys, so revisit on a major. `html` already defaults to root.
|
|
145
|
+
distPath: {
|
|
146
|
+
root: 'dist',
|
|
147
|
+
js: '',
|
|
148
|
+
jsAsync: '',
|
|
149
|
+
css: '',
|
|
150
|
+
cssAsync: '',
|
|
151
|
+
svg: '',
|
|
152
|
+
font: '',
|
|
153
|
+
image: '',
|
|
154
|
+
media: '',
|
|
155
|
+
assets: '',
|
|
156
|
+
wasm: '',
|
|
157
|
+
},
|
|
158
|
+
// 'auto' derives the chunk base URL from document.currentScript.src at
|
|
159
|
+
// runtime, so one bundle works both in dev and when the shell loads
|
|
160
|
+
// remoteEntry.js from the CDN under /apps/<id>/<version>/.
|
|
161
|
+
assetPrefix: 'auto',
|
|
162
|
+
},
|
|
163
|
+
// `output.assetPrefix` above is the PRODUCTION value only — the dev server
|
|
164
|
+
// reads `dev.assetPrefix`, which otherwise defaults to `/`. Without this,
|
|
165
|
+
// a remote served by `rsbuild dev` resolves its async chunks against the
|
|
166
|
+
// HOST's origin and 404s, because webpack's single `output.publicPath`
|
|
167
|
+
// covered both modes and Rsbuild's does not.
|
|
168
|
+
dev: { assetPrefix: 'auto' },
|
|
169
|
+
server: {
|
|
170
|
+
...base.server,
|
|
171
|
+
// The shell's dev server fetches remoteEntry.js cross-origin.
|
|
172
|
+
headers: { 'Access-Control-Allow-Origin': '*' },
|
|
173
|
+
},
|
|
174
|
+
tools: {
|
|
175
|
+
rspack: (config, { rspack, appendPlugins, isProd }) => {
|
|
176
|
+
// Rsbuild defaults production source maps OFF; the webpack configs this
|
|
177
|
+
// replaces shipped them, and without them a deployed app is unreadable
|
|
178
|
+
// in a devtools stack trace. Set here rather than via
|
|
179
|
+
// `output.sourceMap`, which is mode-agnostic and would also downgrade
|
|
180
|
+
// dev rebuilds to the slowest option.
|
|
181
|
+
if (isProd) {
|
|
182
|
+
config.devtool = 'source-map';
|
|
183
|
+
}
|
|
184
|
+
// Rsbuild has no `output.uniqueName`, and it is load-bearing: it names
|
|
185
|
+
// the chunk-loading global, which must not collide with the host's.
|
|
186
|
+
config.output.uniqueName = scope;
|
|
187
|
+
appendPlugins(
|
|
188
|
+
// V1 = the webpack-aligned Module Federation implementation. It emits
|
|
189
|
+
// the container shape (`window[scope].init/get`) that BOTH hosts'
|
|
190
|
+
// runtime loaders speak. Never the enhanced plugin.
|
|
191
|
+
new rspack.container.ModuleFederationPluginV1({
|
|
192
|
+
name: scope,
|
|
193
|
+
filename: 'remoteEntry.js',
|
|
194
|
+
exposes: {
|
|
195
|
+
'./App': './src/App',
|
|
196
|
+
[lifecycle_1.LIFECYCLE_MODULE_NAME]: './src/lifecycle',
|
|
197
|
+
...exposes,
|
|
198
|
+
},
|
|
199
|
+
shared: {
|
|
200
|
+
react: CONSUMED_REACT_SHARE,
|
|
201
|
+
'react-dom': CONSUMED_REACT_SHARE,
|
|
202
|
+
'react/jsx-runtime': CONSUMED_REACT_SHARE,
|
|
203
|
+
'react/jsx-dev-runtime': CONSUMED_REACT_SHARE,
|
|
204
|
+
// The design system, imported via `@rise-x/apps-sdk/ui`. The host
|
|
205
|
+
// provides the only copy — and the compiled Tailwind CSS that
|
|
206
|
+
// styles it — so never bundle a fallback.
|
|
207
|
+
'@rise-x/ui': {
|
|
208
|
+
singleton: true,
|
|
209
|
+
requiredVersion: false,
|
|
210
|
+
import: false,
|
|
211
|
+
},
|
|
212
|
+
// Unlike react, KEEP the bundled fallback: the app loads through
|
|
213
|
+
// an async MF boundary so there is no eager sync-require hazard,
|
|
214
|
+
// and the fallback keeps the app working on hosts that do not
|
|
215
|
+
// share react-query.
|
|
216
|
+
'@tanstack/react-query': {
|
|
217
|
+
singleton: true,
|
|
218
|
+
requiredVersion: '^5.0.0',
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
}));
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
}
|