@xh/hoist-dev-utils 16.0.0-SNAPSHOT.1790703934910 → 16.1.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 CHANGED
@@ -10,8 +10,8 @@ applications.
10
10
  The package.json file in this repository specifies a set of development dependencies required for
11
11
  building Hoist React applications. Those applications can specify `@xh/hoist-dev-utils` as a dev
12
12
  dependency and transitively bring in [Rsbuild](https://rsbuild.rs) (Rspack + SWC) and the plugins
13
- used in app builds, including the Rsbuild dev server, Sass, and Babel (for Hoist's legacy
14
- decorators).
13
+ used in app builds, including the Rsbuild dev server and Sass. SWC transpiles Hoist's TC39
14
+ (`2023-11`) decorators, so no Babel install is needed.
15
15
 
16
16
  While Hoist Dev Utils provides most essential dev dependencies for Hoist React, apps typically also include:
17
17
 
@@ -29,7 +29,8 @@ The `configureRsbuild.js` module exports a single `configureRsbuild()` function
29
29
  complete [Rsbuild](https://rsbuild.rs) (Rspack + SWC) configuration. This includes transpiling and
30
30
  bundling multiple client application entry points, styles (CSS/SASS), HTML index file generation,
31
31
  and pre-compressed assets for production builds. See the docs within `configureRsbuild.js` for
32
- supported arguments and additional details.
32
+ supported arguments and additional details. The package ships type declarations for both config
33
+ modules. Add `// @ts-check` to the top of `rsbuild.config.mjs` to have the IDE check its options.
33
34
 
34
35
  The generated configuration also sets the value of several XH globals within the built JS code, via
35
36
  Rspack's DefinePlugin. These include `XH.appCode` and `XH.appName` (both required), `XH.appVersion`
@@ -119,6 +120,92 @@ Dev-utils 16 is Rsbuild only - `configureWebpack()` is gone. To move an app:
119
120
  twins of compressible assets. Chunk boundaries differ from webpack's, so per-file names and sizes
120
121
  will not line up.
121
122
 
123
+ ## Unit tests with Vitest
124
+
125
+ The `configureVitest.js` module exports `configureVitest()`, a [Vitest](https://vitest.dev) preset
126
+ for app unit tests. It compiles specs with the SWC inside Rspack and the same settings as
127
+ `configureRsbuild()`, so tests run the code the app ships. It also sets the same `XH` constants and
128
+ loads hoist-react's test setup, which starts a fake hoist-core server for each test file.
129
+
130
+ **Requires hoist-react >= 89.** The preset loads `test-support/setup.ts` from the installed
131
+ `@xh/hoist`, and hoist-react ships its `test-support/` folder from v89. With an older hoist-react,
132
+ the preset fails with a message that names the version it found. Builds still work with that
133
+ version.
134
+
135
+ This package does not bring the test runners. Add them to the app as devDependencies:
136
+
137
+ ```bash
138
+ pnpm add -D vitest jsdom msw @testing-library/react @testing-library/dom
139
+ ```
140
+
141
+ Take the latest versions that fit the optional peer ranges in the `package.json` of `@xh/hoist`.
142
+ pnpm warns about any version outside those ranges. Then add scripts:
143
+
144
+ ```json
145
+ "scripts": {
146
+ "test": "vitest run",
147
+ "test:watch": "vitest",
148
+ "testWithHoist": "(cd ../../hoist-react && pnpm install) && pnpm install && XH_INLINE_HOIST=true vitest"
149
+ }
150
+ ```
151
+
152
+ hoist-react's test setup unmounts rendered components after each test, so it needs React Testing
153
+ Library even if the app's specs never render. Then add a `vitest.config.mts` next to
154
+ `rsbuild.config.mjs`:
155
+
156
+ ```typescript
157
+ import configureVitest from '@xh/hoist-dev-utils/configureVitest';
158
+ import {defineConfig} from 'vitest/config';
159
+
160
+ export default defineConfig(configureVitest({appCode: 'myApp'}));
161
+ ```
162
+
163
+ Import the preset by package name. Vite bundles a relative import of this CommonJS file, and the
164
+ bundled copy fails. The preset's type declarations let the IDE check its options. Put specs next to the code they test, as `src/**/*.spec.ts`. The build skips
165
+ `*.spec.*` and `*.test.*` files in `src/apps/`, so a spec there does not become an app entry.
166
+ See hoist-react's `docs/unit-testing.md` for how to write specs.
167
+
168
+ To add Vitest settings, wrap the result in `mergeConfig()` from `vitest/config`. A scalar setting
169
+ from the app wins. `mergeConfig()` joins arrays, so it cannot narrow a list: pass `include` and
170
+ `setupFiles` to the preset instead.
171
+
172
+ `configureVitest()` takes the same `env` object as `configureRsbuild()`, so an app can share one
173
+ object between its two configs. Add the test-only keys in the Vitest config alone, as in
174
+ `configureVitest({...env, setupFiles: ['./src/test-support/setup.ts']})`. `configureRsbuild()`
175
+ warns about keys it does not know.
176
+
177
+ | Option | In tests |
178
+ |---|---|
179
+ | `appCode` (required), `appName`, `appVersion`, `appBuild`, `baseUrl` | Set in `XH`, with the build defaults |
180
+ | `inlineHoist`, `extraIncludePaths`, `extraExcludePaths`, `resolveAliases`, `swcOptions` | As in the build. An alias value that starts with `.` is relative to the root. `swcOptions` drops any `env` key, which SWC rejects with `jsc.target`. |
181
+ | `extraModuleRules` | Ignored, with a warning. Rspack rules cannot run under Vite. |
182
+ | Other build options | Ignored |
183
+ | `root` | Project root. Default: the current directory. |
184
+ | `include` | Spec globs. Default: `['src/**/*.spec.{ts,tsx}']`. |
185
+ | `setupFiles` | App setup files, run after hoist-react's `test-support/setup.ts`. Default: `[]`. |
186
+ | `timeZone` | Sets `TZ` for the run. Default: `'America/New_York'`. `null` keeps the machine zone. |
187
+ | `selfHost` | For hoist-react's own config only. Aliases `@xh/hoist` to the project root. |
188
+
189
+ The preset gives hoist-react's test kit a fixed setup. `XH.isDevelopmentMode` is false, and client
190
+ app names come from `src/apps`, or `['app']` without that folder. Each test file runs isolated in
191
+ jsdom, with mocks, env stubs and global stubs restored after each test. Stylesheet imports resolve to
192
+ an empty module, and with `?inline`, `?raw` or `?url` to an empty string. `@xh/app-changelog.json`
193
+ resolves to `{}`, and a `.md` import to its text.
194
+
195
+ A run with `--no-isolate`, or in the `vmThreads` or `vmForks` pool, fails, because each test file
196
+ boots its own `XH`. If the installed `@xh/hoist` declares a `vitest` peer dependency, the preset also
197
+ fails on a Vitest major outside that range.
198
+
199
+ `XH_INLINE_HOIST=true` (or `inlineHoist: true`) runs the app's tests against a hoist-react
200
+ checkout at `../../hoist-react`, as `startWithHoist` does for the dev server. The preset aliases
201
+ `@xh/hoist` to the checkout. It dedupes React, ag-Grid, msw, React Testing Library and MobX to the
202
+ app's own copies, if the app has them. A Node resolve hook does the same for the checkout's
203
+ dependencies, which Vitest loads outside Vite. Inline mode works under pnpm. It is untested under
204
+ yarn and npm.
205
+
206
+ The name matches Vitest's own `configureVitest` plugin hook. The two are unrelated: this one is a
207
+ config factory, like `configureRsbuild()`.
208
+
122
209
  ## Favicons
123
210
 
124
211
  To include a favicon with your app, provide the `favicon` option to `configureRsbuild()`. This can be either
@@ -232,7 +319,8 @@ manager the app itself uses.
232
319
  This repo itself is managed with [pnpm](https://pnpm.io) - run `pnpm install` to install its
233
320
  dependencies. The required pnpm version is pinned via the `packageManager` field in `package.json`
234
321
  and will be provisioned automatically by [corepack](https://nodejs.org/api/corepack.html)
235
- (`corepack enable pnpm`) or by a standalone pnpm install of v10+.
322
+ (`corepack enable pnpm`) or by a standalone pnpm install of v10+. Run `pnpm test` for the
323
+ `node --test` specs under `test/`.
236
324
 
237
325
  ------------------------------------------
238
326
 
@@ -0,0 +1,190 @@
1
+ /*
2
+ * This file belongs to Hoist, an application development toolkit
3
+ * developed by Extremely Heavy Industries (www.xh.io | info@xh.io)
4
+ *
5
+ * Copyright © 2026 Extremely Heavy Industries Inc.
6
+ */
7
+
8
+ // Hand-written declarations for configureRsbuild.js. Keep in step with its JSDoc and with
9
+ // KNOWN_OPTIONS in lib/common.js - test/declarations.test.js checks the keys.
10
+
11
+ /**
12
+ * Consolidated Rsbuild (Rspack + SWC) configuration for both dev-time and production builds of
13
+ * Hoist React web applications. Apps consume it from an `rsbuild.config.mjs`:
14
+ *
15
+ * import {defineConfig} from '@rsbuild/core';
16
+ * import configureRsbuild from '@xh/hoist-dev-utils/configureRsbuild';
17
+ * export default defineConfig(({envMode}) => configureRsbuild({appCode: 'myApp', ...}));
18
+ *
19
+ * Build-time overrides flow in as `XH_*` environment variables - see `readCliEnv()`.
20
+ *
21
+ * @returns a complete Rsbuild config object, typed loosely. Rsbuild's `defineConfig()` checks it.
22
+ */
23
+ declare function configureRsbuild(env: configureRsbuild.RsbuildEnv): Promise<Record<string, any>>;
24
+
25
+ declare namespace configureRsbuild {
26
+ /** Also exported by name, for `import {configureRsbuild} from ...`. */
27
+ const configureRsbuild: (env: RsbuildEnv) => Promise<Record<string, any>>;
28
+
29
+ /**
30
+ * Read the standard `XH_*` environment variables into env options, for CLI-driven overrides.
31
+ * Spread the result into the config passed to `configureRsbuild()` after the app's own
32
+ * defaults. Rsbuild loads `.env`, `.env.local`, `.env.<mode>` and `.env.<mode>.local` into
33
+ * `process.env` before it evaluates the config, so the variables can live there too.
34
+ *
35
+ * 'true' and 'false' become booleans. Unset variables are omitted, so app defaults win.
36
+ */
37
+ function readCliEnv(processEnv?: Record<string, string | undefined>): Partial<RsbuildEnv>;
38
+
39
+ /** Options that `configureRsbuild()` and `configureVitest()` both honor. */
40
+ interface SharedEnv {
41
+ /**
42
+ * Short, internal code for the application - baked into client as `XH.appCode`. Should be
43
+ * lowercase, dash-separated, and should match the Gradle project name (e.g.
44
+ * portfolio-manager).
45
+ */
46
+ appCode: string;
47
+ /**
48
+ * User-facing display name for the application - baked into client as `XH.appName`.
49
+ * Defaults from appCode (portfolio-manager -> Portfolio Manager).
50
+ */
51
+ appName?: string;
52
+ /** Client version - baked into client as `XH.appVersion`. Default '1.0-SNAPSHOT'. */
53
+ appVersion?: string;
54
+ /** Build/git tag - baked into client as `XH.appBuild`. Default 'UNKNOWN'. */
55
+ appBuild?: string;
56
+ /**
57
+ * Root path prepended to all relative URLs called via FetchService. Defaults to `/api/`,
58
+ * which the dev server proxies to the Grails backend at `devHost:devGrailsPort`.
59
+ */
60
+ baseUrl?: string;
61
+ /**
62
+ * True to use a sibling hoist-react checkout at `../../hoist-react` in place of the
63
+ * installed package. Dev-mode only for the build.
64
+ */
65
+ inlineHoist?: boolean;
66
+ /** Additional paths to transpile with the settings used for app and hoist-react code. */
67
+ extraIncludePaths?: string[];
68
+ /** Paths to exclude from transpiling, e.g. a local package's nested node_modules. */
69
+ extraExcludePaths?: string[];
70
+ /** @deprecated renamed to `extraIncludePaths`. */
71
+ babelIncludePaths?: string[];
72
+ /** @deprecated renamed to `extraExcludePaths`. */
73
+ babelExcludePaths?: string[];
74
+ /**
75
+ * Module aliases. When inlineHoist=true, an alias from `@xh/hoist` to the checkout is
76
+ * added.
77
+ */
78
+ resolveAliases?: Record<string, string | string[] | false>;
79
+ /**
80
+ * Overrides for SWC options, applied on top of the defaults - either an object to
81
+ * deep-merge, or a function receiving the options to mutate or replace.
82
+ */
83
+ swcOptions?:
84
+ Record<string, any> | ((options: Record<string, any>) => Record<string, any> | void);
85
+ }
86
+
87
+ /** Options for `configureRsbuild()`. */
88
+ interface RsbuildEnv extends SharedEnv {
89
+ /** True for a production build, as opposed to a run of the dev server. */
90
+ prodBuild?: boolean;
91
+ /** True to use the production build of React when running the dev server. */
92
+ reactProdMode?: boolean;
93
+ /**
94
+ * Source map generation. `true` for defaults specific to dev vs. prod builds, `false` to
95
+ * disable, `'devOnly'` for the dev default only, or any valid Rspack `devtool` string.
96
+ * Default true.
97
+ */
98
+ sourceMaps?: boolean | string;
99
+ /**
100
+ * Browserslist queries for the target browsers, driving JS transpiling, polyfill
101
+ * selection and CSS prefixing.
102
+ */
103
+ targetBrowsers?: string[];
104
+ /** False to skip JS/CSS minification in production builds. Default true. */
105
+ minify?: boolean;
106
+ /**
107
+ * True to enable Rspack's persistent build cache, or Rsbuild's options object
108
+ * (`cacheDirectory`, `cacheDigest`, `buildDependencies`). Default false.
109
+ */
110
+ buildCache?: boolean | Record<string, any>;
111
+ /** Rsbuild log level. Default 'info'. */
112
+ logLevel?: 'info' | 'warn' | 'error' | 'silent';
113
+ /**
114
+ * Options to deep-merge onto the defaults for the SWC minimizer in production builds -
115
+ * `compress`, `mangle` and `format`, in the same shape as Terser's.
116
+ */
117
+ minifyOptions?: Record<string, any>;
118
+ /**
119
+ * Additional Rspack module rules, added ahead of the built-in rules. Declare any loaders
120
+ * they use as devDependencies of the app.
121
+ */
122
+ extraModuleRules?: Record<string, any>[];
123
+ /**
124
+ * True to load all BlueprintJs icons. Default false loads only the icons Hoist React
125
+ * needs, for a much smaller bundle.
126
+ */
127
+ loadAllBlueprintJsIcons?: boolean;
128
+ /** Root path from which the app will be served, used as the base path for static files. */
129
+ contextRoot?: string;
130
+ /**
131
+ * True to copy the `/client-app/public` contents into the root of the build, unprocessed.
132
+ * Required for favicons. Default true.
133
+ */
134
+ copyPublicAssets?: boolean;
135
+ /**
136
+ * True to parse a `CHANGELOG.md` in the project root into JSON for
137
+ * `XH.changelogService`. Default true.
138
+ */
139
+ parseChangelog?: boolean;
140
+ /**
141
+ * Pre-compressed `.br` and `.gz` copies of bundled assets, for nginx. `false` to disable,
142
+ * or an object to override the compression plugin defaults. Production builds only.
143
+ * Default true.
144
+ */
145
+ precompressAssets?:
146
+ | boolean
147
+ | {
148
+ test?: RegExp | string | (RegExp | string)[];
149
+ include?: RegExp | string | (RegExp | string)[];
150
+ exclude?: RegExp | string | (RegExp | string)[];
151
+ threshold?: number;
152
+ minRatio?: number;
153
+ };
154
+ /** Relative path to a primary favicon source image, `png` or `svg`. */
155
+ favicon?: string;
156
+ /** Override values for each app's manifest.json. */
157
+ manifestConfig?: Record<string, any>;
158
+ /** Background color for the preloader spinner. Default white. */
159
+ preloadBackgroundColor?: string;
160
+ /** Stroke color for the preloader spinner SVG. Default '#888'. */
161
+ preloadSpinnerColor?: string;
162
+ /**
163
+ * Dev-server overlay behavior, in webpack-dev-server's `{errors, runtimeErrors}` shape.
164
+ * Default shows compilation errors only. Dev-mode only.
165
+ */
166
+ devClientOverlay?: boolean | {errors?: boolean; runtimeErrors?: boolean};
167
+ /** Hostname for both the local Grails and dev servers. Default 'localhost'. Dev-mode only. */
168
+ devHost?: string;
169
+ /** Port of the local Grails server. Default 8080. Dev-mode only. */
170
+ devGrailsPort?: number | string;
171
+ /** Port on which to start the dev server (historic name). Default 3000. Dev-mode only. */
172
+ devWebpackPort?: number | string;
173
+ /** Path to open when the dev server starts. Unset to open nothing. Dev-mode only. */
174
+ devServerOpenPage?: string;
175
+ /**
176
+ * `true` to run the dev server over SSL with a self-signed cert, or Node
177
+ * `https.createServer` options for a custom cert/key. Default false. Dev-mode only.
178
+ */
179
+ devHttps?: boolean | Record<string, any>;
180
+ /**
181
+ * False to stop the dev server reloading the page when an edit cannot be hot-swapped.
182
+ * Default true. Dev-mode only.
183
+ */
184
+ devLiveReload?: boolean;
185
+ /** Options to spread onto the defaults for Rsbuild's `server` config. Dev-mode only. */
186
+ devServerOptions?: Record<string, any>;
187
+ }
188
+ }
189
+
190
+ export = configureRsbuild;
@@ -37,6 +37,14 @@ const {
37
37
  logMsg
38
38
  } = require('./lib/common');
39
39
 
40
+ const {
41
+ HOIST_SWC,
42
+ INLINE_HOIST_SINGLETONS,
43
+ resolveAppIdentity,
44
+ resolveHoistPath,
45
+ xhDefines
46
+ } = require('./lib/hoistCompile');
47
+
40
48
  // These are not deps of hoist-dev-utils but of the consuming app, so resolve them from the
41
49
  // app's own directory (basePath).
42
50
  const hoistReactPkg = resolveAppPackage('@xh/hoist', basePath),
@@ -147,14 +155,11 @@ const hoistReactPkg = resolveAppPackage('@xh/hoist', basePath),
147
155
  * @returns {Promise<Object>} a complete Rsbuild config object.
148
156
  */
149
157
  async function configureRsbuild(env) {
150
- if (!env.appCode) throw 'Missing required "appCode" config - cannot proceed';
158
+ // Identity defaults are shared with configureVitest(). Throws when `appCode` is missing.
159
+ const {appCode, appName, appVersion, appBuild, baseUrl} = resolveAppIdentity(env);
151
160
  rejectUnsupported(env);
152
161
 
153
- const appCode = env.appCode,
154
- appName = env.appName || _.startCase(appCode),
155
- appVersion = env.appVersion || '1.0-SNAPSHOT',
156
- appBuild = env.appBuild || 'UNKNOWN',
157
- prodBuild = parseFlag(env.prodBuild, false) === true,
162
+ const prodBuild = parseFlag(env.prodBuild, false) === true,
158
163
  inlineHoist = !prodBuild && parseFlag(env.inlineHoist, false) === true,
159
164
  reactProdMode = prodBuild || parseFlag(env.reactProdMode, false) === true,
160
165
  resolveAliases = Object.assign({}, env.resolveAliases),
@@ -169,7 +174,6 @@ async function configureRsbuild(env) {
169
174
  devGrailsPort = env.devGrailsPort || 8080,
170
175
  devWebpackPort = env.devWebpackPort || 3000,
171
176
  devServerOptions = env.devServerOptions || {},
172
- baseUrl = env.baseUrl || '/api/',
173
177
  extraIncludePaths = (env.extraIncludePaths || env.babelIncludePaths || []).map(
174
178
  safeRealpath
175
179
  ),
@@ -239,11 +243,7 @@ async function configureRsbuild(env) {
239
243
  // Resolve symlinks (a no-op for flat layouts) so the path matches the real module paths
240
244
  // Rspack produces via its default resolve.symlinks behavior - required for the transpile
241
245
  // include below to match under symlinking package managers (e.g. pnpm).
242
- const hoistPath = safeRealpath(
243
- inlineHoist
244
- ? path.resolve(basePath, '../../hoist-react')
245
- : path.resolve(basePath, 'node_modules/@xh/hoist')
246
- );
246
+ const hoistPath = resolveHoistPath(basePath, inlineHoist);
247
247
 
248
248
  // Check for and resolve standard/expected favicons.
249
249
  const {manifestIcons, appleTouchIconExists} = resolveIcons(
@@ -263,17 +263,11 @@ async function configureRsbuild(env) {
263
263
  if (inlineHoist) {
264
264
  resolveAliases['@xh/hoist'] = hoistPath;
265
265
 
266
- // This ensures that we use the same instance of libs in hoist-react as in the app - needed
267
- // to get hooks working since they will throw an error if the lib instance that the hook
268
- // was imported from is different than the instance that was used to render the component
269
- // (which will always be the instance hoist-react has when using element factories)
270
- resolveAliases['react'] = path.resolve('./node_modules/react');
271
- resolveAliases['react-dom'] = path.resolve('./node_modules/react-dom');
272
-
273
- // Also ensure a single instance of ag-Grid when Hoist is inline, needed to support use of
274
- // `useGridMenuItem` hook.
275
- resolveAliases['ag-grid-react'] = path.resolve('./node_modules/ag-grid-react');
276
- resolveAliases['ag-grid-community'] = path.resolve('./node_modules/ag-grid-community');
266
+ // Use the app's instance of each library hoist-react must share with it - React for hooks,
267
+ // ag-Grid for `useGridMenuItem`. See INLINE_HOIST_SINGLETONS.
268
+ INLINE_HOIST_SINGLETONS.forEach(name => {
269
+ resolveAliases[name] = path.resolve('./node_modules', name);
270
+ });
277
271
  }
278
272
 
279
273
  // When running inline, resolve inline Hoist's own node_modules so we can exclude them.
@@ -298,7 +292,8 @@ async function configureRsbuild(env) {
298
292
  // TS-only support - fail fast on any .jsx source.
299
293
  checkNoJsxFiles([srcPath, ...extraIncludePaths]);
300
294
 
301
- // Resolve app entry points - one for each file within src/apps/ - to create bundles below.
295
+ // Resolve app entry points - one for each script within src/apps/, minus unit tests - to create
296
+ // bundles below.
302
297
  const clientApps = discoverClientApps(srcPath),
303
298
  clientAppNames = clientApps.map(it => it.name),
304
299
  appEntryPoints = Object.fromEntries(clientApps.map(it => [it.name, it.path]));
@@ -340,7 +335,7 @@ async function configureRsbuild(env) {
340
335
  // `export const AppComponent = hoistCmp({...})`) - Hoist's camelCase element-factory
341
336
  // exports and model classes fall back to a (sub-second) full reload of the page.
342
337
  pluginReact({
343
- swcReactOptions: {runtime: 'automatic'},
338
+ swcReactOptions: {runtime: HOIST_SWC.reactRuntime},
344
339
  // Rsbuild's React-specific vendor chunking is tied to its own split presets.
345
340
  splitChunks: false,
346
341
  reactRefreshOptions: {
@@ -378,7 +373,7 @@ async function configureRsbuild(env) {
378
373
  // `@lookup` returning a field initializer. Also Rsbuild's own default, set explicitly
379
374
  // here because it is load-bearing: pointed at `legacy`, every `@observable` and
380
375
  // `@bindable` in a v88 app silently stops working.
381
- decorators: {version: '2023-11'},
376
+ decorators: {version: HOIST_SWC.decoratorVersion},
382
377
 
383
378
  // Avoid importing every FA icon ever made - rewrite named imports from the FontAwesome
384
379
  // icon packs to per-icon deep imports. See https://github.com/FortAwesome/react-fontawesome/issues/70
@@ -403,14 +398,16 @@ async function configureRsbuild(env) {
403
398
  // have no `process` global). Most-specific keys win, so NODE_ENV above still
404
399
  // resolves to its real value.
405
400
  'process.env': '{}',
406
- xhAppCode: JSON.stringify(appCode),
407
- xhAppName: JSON.stringify(appName),
408
- xhAppVersion: JSON.stringify(appVersion),
409
- xhAppBuild: JSON.stringify(appBuild),
410
- xhBaseUrl: JSON.stringify(baseUrl),
411
- xhBuildTimestamp: buildDate.getTime(),
412
- xhClientApps: JSON.stringify(clientAppNames),
413
- xhIsDevelopmentMode: !prodBuild
401
+ ...xhDefines({
402
+ appCode,
403
+ appName,
404
+ appVersion,
405
+ appBuild,
406
+ baseUrl,
407
+ buildTimestamp: buildDate.getTime(),
408
+ clientApps: clientAppNames,
409
+ isDevelopmentMode: !prodBuild
410
+ })
414
411
  }
415
412
  },
416
413
 
@@ -556,6 +553,9 @@ async function configureRsbuild(env) {
556
553
  : {
557
554
  host: devHost,
558
555
  port: devWebpackPort,
556
+ // Fail on a busy port, as webpack-dev-server did. Rsbuild otherwise moves to
557
+ // the next free port, breaking OAuth redirect URIs and fixed-port scripts.
558
+ strictPort: true,
559
559
  https: _.isPlainObject(devHttps) ? devHttps : undefined,
560
560
  open: env.devServerOpenPage ? [env.devServerOpenPage] : false,
561
561
  // Support HTML5 history routes for apps, with /appName/ as the base route for each
@@ -597,7 +597,7 @@ async function configureRsbuild(env) {
597
597
  // (`useDefineForClassFields: true`) and what TC39 decorators assume - `accessor`
598
598
  // fields desugar to a getter/setter pair over private storage, and plain fields
599
599
  // must still define rather than assign so they do not trip inherited setters.
600
- transform.useDefineForClassFields = true;
600
+ transform.useDefineForClassFields = HOIST_SWC.useDefineForClassFields;
601
601
 
602
602
  // Rewrite the `core-js/stable` import in hoist-react's polyfills.js (prepended to
603
603
  // every app entry above) into the polyfills needed for the target browsers.
@@ -0,0 +1,58 @@
1
+ /*
2
+ * This file belongs to Hoist, an application development toolkit
3
+ * developed by Extremely Heavy Industries (www.xh.io | info@xh.io)
4
+ *
5
+ * Copyright © 2026 Extremely Heavy Industries Inc.
6
+ */
7
+
8
+ // Hand-written declarations for configureVitest.js. Keep in step with its JSDoc and with
9
+ // TEST_OPTIONS there - test/declarations.test.js checks the keys. No vite or vitest types, as
10
+ // `vitest/config` does not resolve from this package under pnpm.
11
+
12
+ import configureRsbuild = require('./configureRsbuild');
13
+
14
+ /**
15
+ * Vitest preset for Hoist unit tests. Compiles app and hoist-react code with the same SWC settings
16
+ * as `configureRsbuild()`, sets the same `XH` constants, and loads hoist-react's test setup.
17
+ * Requires hoist-react >= 89. Apps consume it from a `vitest.config.mts`:
18
+ *
19
+ * import configureVitest from '@xh/hoist-dev-utils/configureVitest';
20
+ * import {defineConfig} from 'vitest/config';
21
+ * export default defineConfig(configureVitest({appCode: 'myApp'}));
22
+ *
23
+ * Wrap the result with `mergeConfig()` to add settings. `mergeConfig()` concatenates arrays, so
24
+ * pass `include` and `setupFiles` here.
25
+ *
26
+ * @returns a Vite + Vitest config object, typed loosely. Vitest's `defineConfig()` checks it.
27
+ */
28
+ declare function configureVitest(env: configureVitest.VitestEnv): Record<string, any>;
29
+
30
+ declare namespace configureVitest {
31
+ /** Also exported by name, for `import {configureVitest} from ...`. */
32
+ const configureVitest: (env: VitestEnv) => Record<string, any>;
33
+
34
+ /**
35
+ * Options for `configureVitest()`. Build options beyond these are ignored, so an app can share
36
+ * one `env` object between its two configs: `configureVitest({...env, setupFiles: [...]})`.
37
+ */
38
+ interface VitestEnv extends configureRsbuild.SharedEnv {
39
+ /** Project root. Defaults to the current directory. */
40
+ root?: string;
41
+ /** Spec globs. Default `['src/**\/*.spec.{ts,tsx}']`. */
42
+ include?: string[];
43
+ /** App setup files, run after hoist-react's `test-support/setup.ts`. */
44
+ setupFiles?: string | string[];
45
+ /**
46
+ * Time zone for the run, set as `TZ`. Default 'America/New_York'. Null keeps the
47
+ * machine's zone.
48
+ */
49
+ timeZone?: string | null;
50
+ /**
51
+ * True only for hoist-react's own config. Aliases `@xh/hoist` to the root and loads its
52
+ * `test-support/setup.ts`.
53
+ */
54
+ selfHost?: boolean;
55
+ }
56
+ }
57
+
58
+ export = configureVitest;