@xh/hoist-dev-utils 16.2.0 → 16.3.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 +25 -4
- package/configureRsbuild.d.ts +3 -2
- package/configureRsbuild.js +19 -8
- package/configureVitest.js +4 -3
- package/lib/common.js +46 -0
- package/lib/hoistCompile.js +37 -9
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -74,7 +74,7 @@ Typical `package.json` scripts:
|
|
|
74
74
|
|
|
75
75
|
```json
|
|
76
76
|
"start": "pnpm install && rsbuild dev",
|
|
77
|
-
"startWithHoist": "(cd
|
|
77
|
+
"startWithHoist": "(cd ${XH_HOIST_REACT_PATH:-../../hoist-react} && pnpm install) && pnpm install && rsbuild dev --env-mode inlineHoist",
|
|
78
78
|
"build": "rsbuild build --env-mode prod",
|
|
79
79
|
"buildAndAnalyze": "cross-env RSDOCTOR=true rsbuild build --env-mode prod"
|
|
80
80
|
```
|
|
@@ -92,6 +92,26 @@ and build with `RSDOCTOR=true`, and Rsbuild registers and launches
|
|
|
92
92
|
See the [Hoist React docs](https://github.com/xh/hoist-react/blob/develop/docs/build-and-deploy-app.md)
|
|
93
93
|
for step-by-step details on the build process.
|
|
94
94
|
|
|
95
|
+
### Inline Hoist
|
|
96
|
+
|
|
97
|
+
Inline mode builds the app against a local hoist-react checkout in place of the installed package,
|
|
98
|
+
so a library change shows up in the app as you make it. By default the checkout is a sibling of the
|
|
99
|
+
app's repo, at `../../hoist-react` from `client-app`.
|
|
100
|
+
|
|
101
|
+
Set `XH_HOIST_REACT_PATH` to an absolute path to use another checkout. This is how a git worktree of
|
|
102
|
+
an app runs against a worktree of hoist-react on a paired branch:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
XH_HOIST_REACT_PATH=~/dev/hoist-react-worktrees/my-feature pnpm startWithHoist
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Set it in the shell, not in a dotenv file. The `startWithHoist` and `testWithHoist` scripts read it
|
|
109
|
+
to install the checkout's dependencies, and Rsbuild's dotenv files do not reach them. A tool such as
|
|
110
|
+
direnv or mise can set it per worktree.
|
|
111
|
+
|
|
112
|
+
Inline mode fails fast when the path holds no hoist-react checkout. The Rsbuild build banner shows
|
|
113
|
+
the path and branch it builds from.
|
|
114
|
+
|
|
95
115
|
### Migrating from v15 (webpack)
|
|
96
116
|
|
|
97
117
|
Dev-utils 16 is Rsbuild only - `configureWebpack()` is gone. To move an app:
|
|
@@ -145,7 +165,7 @@ pnpm warns about any version outside those ranges. Then add scripts:
|
|
|
145
165
|
"scripts": {
|
|
146
166
|
"test": "vitest run",
|
|
147
167
|
"test:watch": "vitest",
|
|
148
|
-
"testWithHoist": "(cd
|
|
168
|
+
"testWithHoist": "(cd ${XH_HOIST_REACT_PATH:-../../hoist-react} && pnpm install) && pnpm install && XH_INLINE_HOIST=true vitest"
|
|
149
169
|
}
|
|
150
170
|
```
|
|
151
171
|
|
|
@@ -196,8 +216,9 @@ A run with `--no-isolate`, or in the `vmThreads` or `vmForks` pool, fails, becau
|
|
|
196
216
|
boots its own `XH`. If the installed `@xh/hoist` declares a `vitest` peer dependency, the preset also
|
|
197
217
|
fails on a Vitest major outside that range.
|
|
198
218
|
|
|
199
|
-
`XH_INLINE_HOIST=true` (or `inlineHoist: true`) runs the app's tests against a hoist-react
|
|
200
|
-
checkout
|
|
219
|
+
`XH_INLINE_HOIST=true` (or `inlineHoist: true`) runs the app's tests against a local hoist-react
|
|
220
|
+
checkout, as `startWithHoist` does for the dev server. See [Inline Hoist](#inline-hoist) for how the
|
|
221
|
+
checkout is found. The preset aliases
|
|
201
222
|
`@xh/hoist` to the checkout. It dedupes React, ag-Grid, msw, React Testing Library and MobX to the
|
|
202
223
|
app's own copies, if the app has them. A Node resolve hook does the same for the checkout's
|
|
203
224
|
dependencies, which Vitest loads outside Vite. Inline mode works under pnpm. It is untested under
|
package/configureRsbuild.d.ts
CHANGED
|
@@ -59,8 +59,9 @@ declare namespace configureRsbuild {
|
|
|
59
59
|
*/
|
|
60
60
|
baseUrl?: string;
|
|
61
61
|
/**
|
|
62
|
-
* True to use a
|
|
63
|
-
*
|
|
62
|
+
* True to use a local hoist-react checkout in place of the installed package - a sibling
|
|
63
|
+
* at `../../hoist-react`, or the absolute path in the `XH_HOIST_REACT_PATH` environment
|
|
64
|
+
* variable. Dev-mode only for the build.
|
|
64
65
|
*/
|
|
65
66
|
inlineHoist?: boolean;
|
|
66
67
|
/** Additional paths to transpile with the settings used for app and hoist-react code. */
|
package/configureRsbuild.js
CHANGED
|
@@ -22,6 +22,7 @@ const {
|
|
|
22
22
|
devUtilsPkg,
|
|
23
23
|
resolveAppPackage,
|
|
24
24
|
checkHoistReactVersion,
|
|
25
|
+
checkRspackVersion,
|
|
25
26
|
resolveIcons,
|
|
26
27
|
writeChangelogJson,
|
|
27
28
|
checkNoJsxFiles,
|
|
@@ -31,6 +32,7 @@ const {
|
|
|
31
32
|
blueprintIconModulePatterns,
|
|
32
33
|
generateBlueprintIconStubs,
|
|
33
34
|
safeRealpath,
|
|
35
|
+
gitBranch,
|
|
34
36
|
parseFlag,
|
|
35
37
|
warnUnknownOptions,
|
|
36
38
|
logSep,
|
|
@@ -78,7 +80,9 @@ const hoistReactPkg = resolveAppPackage('@xh/hoist', basePath),
|
|
|
78
80
|
* @param {boolean} [env.prodBuild=false] - true to indicate this is a build (as opposed to run of the dev server)
|
|
79
81
|
* @param {boolean} [env.inlineHoist=false] - true to use a locally checked-out copy of hoist-react
|
|
80
82
|
* when running the dev server, as opposed to using the downloaded dependency. This allows
|
|
81
|
-
* hoist-react developers to test plugin changes. Dev-mode only.
|
|
83
|
+
* hoist-react developers to test plugin changes. Dev-mode only. The checkout is a sibling of
|
|
84
|
+
* the app's repo at `../../hoist-react`, unless the `XH_HOIST_REACT_PATH` environment variable
|
|
85
|
+
* names another (absolute) path, e.g. a git worktree.
|
|
82
86
|
* @param {boolean} [env.reactProdMode=false] - true to use the production build of React
|
|
83
87
|
* when running the dev server.
|
|
84
88
|
* @param {Object} [env.resolveAliases] - object mapping for custom module resolution.
|
|
@@ -206,6 +210,14 @@ async function configureRsbuild(env) {
|
|
|
206
210
|
}
|
|
207
211
|
}
|
|
208
212
|
checkHoistReactVersion(hoistReactPkg, inlineHoist);
|
|
213
|
+
checkRspackVersion(rspack.rspackVersion);
|
|
214
|
+
|
|
215
|
+
// Resolve Hoist as either a local checkout (inline) or a downloaded package. Inline mode throws
|
|
216
|
+
// here, before any output, when the checkout is missing. Symlinks are resolved (a no-op for
|
|
217
|
+
// flat layouts) so the path matches the real module paths Rspack produces via its default
|
|
218
|
+
// resolve.symlinks behavior - required for the transpile include below to match under
|
|
219
|
+
// symlinking package managers (e.g. pnpm).
|
|
220
|
+
const hoistPath = resolveHoistPath(basePath, inlineHoist);
|
|
209
221
|
|
|
210
222
|
process.env.NODE_ENV = prodBuild ? 'production' : 'development';
|
|
211
223
|
process.env.REACT_NODE_ENV = reactProdMode ? 'production' : 'development';
|
|
@@ -223,7 +235,12 @@ async function configureRsbuild(env) {
|
|
|
223
235
|
if (prodBuild && precompressAssets) logMsg('🗜️ Asset pre-compression enabled');
|
|
224
236
|
logSep();
|
|
225
237
|
logMsg('📚 Key libraries:');
|
|
226
|
-
|
|
238
|
+
if (inlineHoist) {
|
|
239
|
+
const branch = gitBranch(hoistPath);
|
|
240
|
+
logMsg(` > @xh/hoist INLINE from ${hoistPath}${branch ? ` @ ${branch}` : ''}`);
|
|
241
|
+
} else {
|
|
242
|
+
logMsg(` > @xh/hoist v${hoistReactPkg.version}`);
|
|
243
|
+
}
|
|
227
244
|
logMsg(` > @xh/hoist-dev-utils v${devUtilsPkg.version}`);
|
|
228
245
|
logMsg(` > react v${reactPkg.version}`);
|
|
229
246
|
logMsg(` > @rsbuild/core v${rsbuildVersion}`);
|
|
@@ -240,12 +257,6 @@ async function configureRsbuild(env) {
|
|
|
240
257
|
// linked - avoids assuming the package is physically within the app's node_modules.
|
|
241
258
|
hoistDevUtilsPath = __dirname;
|
|
242
259
|
|
|
243
|
-
// Resolve Hoist as either a sibling (inline, checked-out) project or a downloaded package.
|
|
244
|
-
// Resolve symlinks (a no-op for flat layouts) so the path matches the real module paths
|
|
245
|
-
// Rspack produces via its default resolve.symlinks behavior - required for the transpile
|
|
246
|
-
// include below to match under symlinking package managers (e.g. pnpm).
|
|
247
|
-
const hoistPath = resolveHoistPath(basePath, inlineHoist);
|
|
248
|
-
|
|
249
260
|
// Check for and resolve standard/expected favicons.
|
|
250
261
|
const {manifestIcons, appleTouchIconExists} = resolveIcons(
|
|
251
262
|
publicAssetsPath,
|
package/configureVitest.js
CHANGED
|
@@ -57,7 +57,7 @@ const HOIST_IMPORT = /^@xh\/hoist(?=\/|$)/;
|
|
|
57
57
|
* Import it by package name - Vite bundles a relative import of this CommonJS file, which fails.
|
|
58
58
|
* Wrap the result with `mergeConfig()` to add settings. Note that `mergeConfig()` concatenates
|
|
59
59
|
* arrays, so `include` and `setupFiles` are options here. Requires hoist-react >= 89. Run tests
|
|
60
|
-
* against a
|
|
60
|
+
* against a local hoist-react checkout with `XH_INLINE_HOIST=true vitest`.
|
|
61
61
|
*
|
|
62
62
|
* Takes the same `env` object as `configureRsbuild()`. App identity, `baseUrl`, `inlineHoist`,
|
|
63
63
|
* `extraIncludePaths`, `extraExcludePaths`, `resolveAliases` and `swcOptions` apply as in the
|
|
@@ -70,8 +70,9 @@ const HOIST_IMPORT = /^@xh\/hoist(?=\/|$)/;
|
|
|
70
70
|
* @param {string} [env.appBuild] - as for configureRsbuild(). Defaults to 'UNKNOWN'.
|
|
71
71
|
* @param {string} [env.baseUrl] - as for configureRsbuild(). Defaults to '/api/', where the fake
|
|
72
72
|
* hoist-core in `@xh/hoist/test-support` serves.
|
|
73
|
-
* @param {boolean} [env.inlineHoist=false] - true to test against a
|
|
74
|
-
* `../../hoist-react
|
|
73
|
+
* @param {boolean} [env.inlineHoist=false] - true to test against a local hoist-react checkout, as
|
|
74
|
+
* for configureRsbuild() - a sibling at `../../hoist-react`, or the path in the
|
|
75
|
+
* `XH_HOIST_REACT_PATH` environment variable. Also on when `XH_INLINE_HOIST` is 'true'.
|
|
75
76
|
* @param {string[]} [env.extraIncludePaths] - custom packages to compile, as in the build.
|
|
76
77
|
* @param {string[]} [env.extraExcludePaths] - paths not to compile, as in the build.
|
|
77
78
|
* @param {Object} [env.resolveAliases] - module aliases, as in the build. A key ending in `$`
|
package/lib/common.js
CHANGED
|
@@ -17,6 +17,7 @@ const _ = require('lodash'),
|
|
|
17
17
|
path = require('path'),
|
|
18
18
|
fs = require('fs'),
|
|
19
19
|
crypto = require('crypto'),
|
|
20
|
+
{execFileSync} = require('child_process'),
|
|
20
21
|
parseChangelogMarkdown = require('changelog-parser').parseChangelog,
|
|
21
22
|
devUtilsPkg = require('../package');
|
|
22
23
|
|
|
@@ -67,6 +68,31 @@ function checkHoistReactVersion(hoistReactPkg, inlineHoist) {
|
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
70
|
|
|
71
|
+
// Rspack releases that break Hoist builds, each with the reason and the fix for that release. A
|
|
72
|
+
// published version never changes, so blocking an exact version is permanent and safe.
|
|
73
|
+
const BLOCKED_RSPACK_VERSIONS = {
|
|
74
|
+
'2.3.2':
|
|
75
|
+
'Its minifier breaks classes that reference themselves in a static initializer when ' +
|
|
76
|
+
'keep_classnames is set, so production builds crash on load ' +
|
|
77
|
+
'(web-infra-dev/rspack#16586). Use 2.3.0 until a fixed release ships - see ' +
|
|
78
|
+
'xh/hoist-dev-utils#85.'
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Fail the build, or the dev server, on an Rspack release known to break Hoist builds. The dev
|
|
83
|
+
* server fails too, even where it would run, so the problem shows up on the first local run rather
|
|
84
|
+
* than in a production build.
|
|
85
|
+
*/
|
|
86
|
+
function checkRspackVersion(rspackVersion) {
|
|
87
|
+
const detail = BLOCKED_RSPACK_VERSIONS[rspackVersion];
|
|
88
|
+
if (detail) {
|
|
89
|
+
throw (
|
|
90
|
+
`@rspack/core v${rspackVersion} is not supported by hoist-dev-utils - pin a ` +
|
|
91
|
+
`supported version with a pnpm override in the app. ${detail}`
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
70
96
|
/**
|
|
71
97
|
* True if `version` is below a 'major[.minor]' minimum. Any suffix (`-SNAPSHOT.<ts>`) is ignored,
|
|
72
98
|
* and a version with no numeric major (e.g. 'NOT_FOUND') is never below.
|
|
@@ -452,6 +478,24 @@ function logSep() {
|
|
|
452
478
|
console.log(':------------------------------------');
|
|
453
479
|
}
|
|
454
480
|
|
|
481
|
+
/**
|
|
482
|
+
* The branch checked out at `dir`, a short commit hash if HEAD is detached, or null if `dir` is not
|
|
483
|
+
* a git checkout or git is not available. Used to show which code an inline build runs against.
|
|
484
|
+
*/
|
|
485
|
+
function gitBranch(dir) {
|
|
486
|
+
const git = args =>
|
|
487
|
+
execFileSync('git', ['-C', dir, ...args], {
|
|
488
|
+
encoding: 'utf8',
|
|
489
|
+
stdio: 'pipe',
|
|
490
|
+
timeout: 5000
|
|
491
|
+
}).trim();
|
|
492
|
+
try {
|
|
493
|
+
return git(['branch', '--show-current']) || git(['rev-parse', '--short', 'HEAD']);
|
|
494
|
+
} catch (e) {
|
|
495
|
+
return null;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
455
499
|
function logMsg(msg) {
|
|
456
500
|
console.log(`: ${msg}`);
|
|
457
501
|
}
|
|
@@ -466,6 +510,7 @@ module.exports = {
|
|
|
466
510
|
resolveAppPackage,
|
|
467
511
|
isVersionBelow,
|
|
468
512
|
checkHoistReactVersion,
|
|
513
|
+
checkRspackVersion,
|
|
469
514
|
resolveIcons,
|
|
470
515
|
writeChangelogJson,
|
|
471
516
|
checkNoJsxFiles,
|
|
@@ -478,6 +523,7 @@ module.exports = {
|
|
|
478
523
|
generateBlueprintIconStubs,
|
|
479
524
|
findJsxFiles,
|
|
480
525
|
safeRealpath,
|
|
526
|
+
gitBranch,
|
|
481
527
|
parseFlag,
|
|
482
528
|
warnUnknownOptions,
|
|
483
529
|
logSep,
|
package/lib/hoistCompile.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
const _ = require('lodash'),
|
|
16
|
+
fs = require('fs'),
|
|
16
17
|
path = require('path'),
|
|
17
18
|
{safeRealpath} = require('./common');
|
|
18
19
|
|
|
@@ -92,16 +93,42 @@ const INLINE_HOIST_SINGLETONS = Object.freeze([
|
|
|
92
93
|
]);
|
|
93
94
|
|
|
94
95
|
/**
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
* module paths bundlers produce, as include rules need under pnpm.
|
|
96
|
+
* The environment variable that points inline mode at a specific hoist-react checkout, e.g. a git
|
|
97
|
+
* worktree on a paired feature branch. Must be an absolute path.
|
|
98
98
|
*/
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
99
|
+
const HOIST_REACT_PATH_VAR = 'XH_HOIST_REACT_PATH';
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Locate hoist-react. In inline mode, this is the checkout named by `XH_HOIST_REACT_PATH`, else a
|
|
103
|
+
* sibling of the app's repo at `../../hoist-react`. Inline mode fails fast unless the path holds a
|
|
104
|
+
* hoist-react checkout. Otherwise, this is the installed package. Symlinks are resolved (a no-op for
|
|
105
|
+
* flat layouts) so the path matches the real module paths bundlers produce, as include rules need
|
|
106
|
+
* under pnpm.
|
|
107
|
+
*/
|
|
108
|
+
function resolveHoistPath(basePath, inlineHoist, processEnv = process.env) {
|
|
109
|
+
if (!inlineHoist) return safeRealpath(path.resolve(basePath, 'node_modules/@xh/hoist'));
|
|
110
|
+
|
|
111
|
+
const override = processEnv[HOIST_REACT_PATH_VAR];
|
|
112
|
+
if (override && !path.isAbsolute(override)) {
|
|
113
|
+
throw `${HOIST_REACT_PATH_VAR} must be an absolute path - found "${override}".`;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const hoistPath = safeRealpath(override || path.resolve(basePath, '../../hoist-react'));
|
|
117
|
+
if (readPackageName(hoistPath) !== '@xh/hoist') {
|
|
118
|
+
throw override
|
|
119
|
+
? `${HOIST_REACT_PATH_VAR} points at ${hoistPath}, which is not a hoist-react checkout.`
|
|
120
|
+
: `Inline Hoist found no hoist-react checkout at ${hoistPath}. Clone hoist-react ` +
|
|
121
|
+
`there, or set ${HOIST_REACT_PATH_VAR} to the checkout to use.`;
|
|
122
|
+
}
|
|
123
|
+
return hoistPath;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function readPackageName(dir) {
|
|
127
|
+
try {
|
|
128
|
+
return JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8')).name;
|
|
129
|
+
} catch (e) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
105
132
|
}
|
|
106
133
|
|
|
107
134
|
module.exports = {
|
|
@@ -110,5 +137,6 @@ module.exports = {
|
|
|
110
137
|
resolveAppIdentity,
|
|
111
138
|
xhDefines,
|
|
112
139
|
INLINE_HOIST_SINGLETONS,
|
|
140
|
+
HOIST_REACT_PATH_VAR,
|
|
113
141
|
resolveHoistPath
|
|
114
142
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xh/hoist-dev-utils",
|
|
3
|
-
"version": "16.
|
|
3
|
+
"version": "16.3.0",
|
|
4
4
|
"description": "Rsbuild (Rspack + SWC) build configuration and shared dev dependencies for Hoist React applications.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
"@xh/eslint-config": "^8.1.0",
|
|
36
36
|
"changelog-parser": "~4.1.0",
|
|
37
37
|
"lodash": "^4.18.1",
|
|
38
|
-
"sass-embedded": "^1.
|
|
38
|
+
"sass-embedded": "^1.108.2",
|
|
39
39
|
"type-fest": "^5.10.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"prettier": "^3.
|
|
42
|
+
"prettier": "^3.10.1"
|
|
43
43
|
},
|
|
44
44
|
"packageManager": "pnpm@12.10.1+sha512.ba40a37eb1a370d60fea8c4cf1d364c13bcccef518e98ad2bcee954f539d38da37458e58261a3fa55e06523450ea0ffff9f497b135be41f2c15c1642bacace6c"
|
|
45
45
|
}
|