@xh/hoist-dev-utils 16.0.0 → 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.
@@ -0,0 +1,114 @@
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
+ 'use strict';
8
+
9
+ /**
10
+ * Compile settings shared by `configureRsbuild()` and `configureVitest()`, so an app's unit tests
11
+ * compile exactly as its build does. Pure values and helpers only - nothing in here may touch a
12
+ * bundler API, the same rule `lib/common.js` follows.
13
+ */
14
+
15
+ const _ = require('lodash'),
16
+ path = require('path'),
17
+ {safeRealpath} = require('./common');
18
+
19
+ /**
20
+ * Hoist's SWC settings - the one source for builds and tests. TC39 Stage 3 (`2023-11`) decorators
21
+ * with [[Define]] class fields are what hoist-react >= 88 is written against. Pointed back at
22
+ * `legacy`, every `@observable` and `@bindable` silently stops working, with no build error.
23
+ */
24
+ const HOIST_SWC = Object.freeze({
25
+ decoratorVersion: '2023-11',
26
+ useDefineForClassFields: true,
27
+ reactRuntime: 'automatic'
28
+ });
29
+
30
+ /** SWC `jsc.transform` options for `HOIST_SWC`. Returns a new object, safe to merge into. */
31
+ function hoistSwcTransform() {
32
+ return {
33
+ decoratorVersion: HOIST_SWC.decoratorVersion,
34
+ useDefineForClassFields: HOIST_SWC.useDefineForClassFields,
35
+ react: {runtime: HOIST_SWC.reactRuntime}
36
+ };
37
+ }
38
+
39
+ /** App identity from `env`, with the `configureRsbuild()` defaults. `appCode` is required. */
40
+ function resolveAppIdentity(env) {
41
+ const {appCode} = env;
42
+ if (!appCode) throw 'Missing required "appCode" config - cannot proceed';
43
+ return {
44
+ appCode,
45
+ appName: env.appName || _.startCase(appCode),
46
+ appVersion: env.appVersion || '1.0-SNAPSHOT',
47
+ appBuild: env.appBuild || 'UNKNOWN',
48
+ baseUrl: env.baseUrl || '/api/'
49
+ };
50
+ }
51
+
52
+ /**
53
+ * The `xh*` constants read by hoist-react's `core/XH.ts`, as code strings for the `define` option
54
+ * of both Rspack and Vite. Every value goes through `JSON.stringify()` - Vitest makes a global of a
55
+ * key with no dot only when its value parses as JSON.
56
+ */
57
+ function xhDefines({
58
+ appCode,
59
+ appName,
60
+ appVersion,
61
+ appBuild,
62
+ baseUrl,
63
+ buildTimestamp,
64
+ clientApps,
65
+ isDevelopmentMode
66
+ }) {
67
+ return _.mapValues(
68
+ {
69
+ xhAppCode: appCode,
70
+ xhAppName: appName,
71
+ xhAppVersion: appVersion,
72
+ xhAppBuild: appBuild,
73
+ xhBaseUrl: baseUrl,
74
+ xhBuildTimestamp: buildTimestamp,
75
+ xhClientApps: clientApps,
76
+ xhIsDevelopmentMode: isDevelopmentMode
77
+ },
78
+ v => JSON.stringify(v)
79
+ );
80
+ }
81
+
82
+ /**
83
+ * Packages that must be one instance when Hoist is a sibling checkout - the app's copy wins. React
84
+ * hooks throw when the hook's React differs from the one that renders the component (always
85
+ * hoist-react's, with element factories). ag-Grid's `useGridMenuItem` hook has the same need.
86
+ */
87
+ const INLINE_HOIST_SINGLETONS = Object.freeze([
88
+ 'react',
89
+ 'react-dom',
90
+ 'ag-grid-react',
91
+ 'ag-grid-community'
92
+ ]);
93
+
94
+ /**
95
+ * Locate hoist-react - a sibling checkout at `../../hoist-react` in inline mode, otherwise the
96
+ * installed package. Symlinks are resolved (a no-op for flat layouts) so the path matches the real
97
+ * module paths bundlers produce, as include rules need under pnpm.
98
+ */
99
+ function resolveHoistPath(basePath, inlineHoist) {
100
+ return safeRealpath(
101
+ inlineHoist
102
+ ? path.resolve(basePath, '../../hoist-react')
103
+ : path.resolve(basePath, 'node_modules/@xh/hoist')
104
+ );
105
+ }
106
+
107
+ module.exports = {
108
+ HOIST_SWC,
109
+ hoistSwcTransform,
110
+ resolveAppIdentity,
111
+ xhDefines,
112
+ INLINE_HOIST_SINGLETONS,
113
+ resolveHoistPath
114
+ };
@@ -0,0 +1,46 @@
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
+ /**
9
+ * First setup file of an inline-hoist test run, added by `configureVitest()`.
10
+ *
11
+ * Vite's `resolve.dedupe` reaches only the modules Vite resolves. Vitest externalizes the
12
+ * checkout's own dependencies (e.g. mobx-react-lite, Blueprint, ag-grid-react), so Node loads them
13
+ * and resolves their `react` from the checkout's node_modules - a second React, and hooks fail.
14
+ * This hook sends those imports to the app's copies instead, as the build's aliases do.
15
+ *
16
+ * Settings arrive in `XH_VITEST_INLINE_HOIST_CFG`, set by `configureVitest()`.
17
+ * `module.registerHooks()` needs Node >= 22.15.
18
+ */
19
+ import {createRequire, registerHooks} from 'node:module';
20
+ import path from 'node:path';
21
+ import {pathToFileURL} from 'node:url';
22
+
23
+ const cfg = JSON.parse(process.env.XH_VITEST_INLINE_HOIST_CFG ?? 'null');
24
+
25
+ if (cfg?.singletons?.length) {
26
+ const fromUrl = pathToFileURL(path.join(cfg.hoistNodeModules, '/')).href,
27
+ appParentUrl = pathToFileURL(path.join(cfg.appRoot, 'package.json')).href,
28
+ appRequire = createRequire(appParentUrl),
29
+ names = cfg.singletons.map(it => it.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&')).join('|'),
30
+ singletonRe = new RegExp(`^(?:${names})(?:/|$)`);
31
+
32
+ registerHooks({
33
+ resolve(specifier, context, nextResolve) {
34
+ if (!singletonRe.test(specifier) || !context.parentURL?.startsWith(fromUrl)) {
35
+ return nextResolve(specifier, context);
36
+ }
37
+ // An ESM import resolves from the app with its own conditions, so it still gets a
38
+ // package's ESM build (ag-Grid ships both). A changed parentURL does not redirect a
39
+ // CJS require(), so that resolves through the app's require instead.
40
+ if (context.conditions?.includes('import')) {
41
+ return nextResolve(specifier, {...context, parentURL: appParentUrl});
42
+ }
43
+ return {url: pathToFileURL(appRequire.resolve(specifier)).href, shortCircuit: true};
44
+ }
45
+ });
46
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xh/hoist-dev-utils",
3
- "version": "16.0.0",
3
+ "version": "16.1.0",
4
4
  "description": "Rsbuild (Rspack + SWC) build configuration and shared dev dependencies for Hoist React applications.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,28 +12,34 @@
12
12
  "license": "Apache-2.0",
13
13
  "files": [
14
14
  "configureRsbuild.js",
15
+ "configureRsbuild.d.ts",
16
+ "configureVitest.js",
17
+ "configureVitest.d.ts",
15
18
  "lib/**/*",
16
19
  "static/**/*"
17
20
  ],
21
+ "scripts": {
22
+ "test": "node --test \"test/**/*.test.js\""
23
+ },
18
24
  "engines": {
19
25
  "node": ">=22.15.0"
20
26
  },
21
27
  "dependencies": {
22
- "@rsbuild/core": "~2.2.7",
23
- "@rsbuild/plugin-basic-ssl": "~1.2.3",
24
- "@rsbuild/plugin-react": "~2.1.0",
28
+ "@rsbuild/core": "~2.2.11",
29
+ "@rsbuild/plugin-basic-ssl": "~2.0.0",
30
+ "@rsbuild/plugin-react": "~2.1.1",
25
31
  "@rsbuild/plugin-sass": "~2.0.1",
26
32
  "@types/lodash": "^4.17.25",
27
33
  "@types/react": "^19.3.0",
28
34
  "@types/react-dom": "^19.3.0",
29
- "@xh/eslint-config": "^8.0.1",
35
+ "@xh/eslint-config": "^8.1.0",
30
36
  "changelog-parser": "~4.1.0",
31
37
  "lodash": "^4.18.1",
32
- "sass-embedded": "^1.104.1",
38
+ "sass-embedded": "^1.105.1",
33
39
  "type-fest": "^5.10.0"
34
40
  },
35
41
  "devDependencies": {
36
- "prettier": "^3.9.7"
42
+ "prettier": "^3.9.9"
37
43
  },
38
- "packageManager": "pnpm@12.2.1+sha512.f55ca68aacb9eb5ab69c66f828a98af89a32286703aef1f8da131ca7eab4d677f34bfa85e186467a919c0799df8b6f4aa240f7dc2919b33b3273190104162616"
44
+ "packageManager": "pnpm@12.10.1+sha512.ba40a37eb1a370d60fea8c4cf1d364c13bcccef518e98ad2bcee954f539d38da37458e58261a3fa55e06523450ea0ffff9f497b135be41f2c15c1642bacace6c"
39
45
  }