@brust/core 2.0.0-alpha.7 → 2.0.0-alpha.9

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/native/index.d.ts CHANGED
@@ -64,8 +64,9 @@ export interface CompiledTree {
64
64
  /**
65
65
  * Compiles `path` (relative to `root`) and every child it reaches through lowering. `css_modules` (L20): the class
66
66
  * map of each `*.module.css`, keyed by its path relative to `root`; `styles.x` folds to the literal class.
67
+ * `packages` (F153c): the JSON resolution map of the package sources the build wrote (`pkg-src.ts`).
67
68
  */
68
- export declare function compileTree(path: string, root: string, runtimeImport: string, serverOnly: Array<string>, slotValues?: string | undefined | null, cssModules?: Record<string, Record<string, string>> | undefined | null, iconSvgs?: string | undefined | null): CompiledTree
69
+ export declare function compileTree(path: string, root: string, runtimeImport: string, serverOnly: Array<string>, slotValues?: string | undefined | null, cssModules?: Record<string, Record<string, string>> | undefined | null, iconSvgs?: string | undefined | null, routeRoots?: Array<string> | undefined | null, pathAliases?: string | undefined | null, packages?: string | undefined | null): CompiledTree
69
70
 
70
71
  /** The bound address as `host:port` (port 0 resolves here). */
71
72
  export declare function localAddr(): string
package/native/index.js CHANGED
@@ -89,8 +89,8 @@ function requireNative() {
89
89
  try {
90
90
  const binding = require('@brust/native-android-arm64')
91
91
  const bindingPackageVersion = require('@brust/native-android-arm64/package.json').version
92
- if (bindingPackageVersion !== '2.0.0-alpha.7' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
93
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.7 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
92
+ if (bindingPackageVersion !== '2.0.0-alpha.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
93
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
94
94
  }
95
95
  return binding
96
96
  } catch (e) {
@@ -105,8 +105,8 @@ function requireNative() {
105
105
  try {
106
106
  const binding = require('@brust/native-android-arm-eabi')
107
107
  const bindingPackageVersion = require('@brust/native-android-arm-eabi/package.json').version
108
- if (bindingPackageVersion !== '2.0.0-alpha.7' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
109
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.7 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
108
+ if (bindingPackageVersion !== '2.0.0-alpha.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
109
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
110
110
  }
111
111
  return binding
112
112
  } catch (e) {
@@ -126,8 +126,8 @@ function requireNative() {
126
126
  try {
127
127
  const binding = require('@brust/native-win32-x64-gnu')
128
128
  const bindingPackageVersion = require('@brust/native-win32-x64-gnu/package.json').version
129
- if (bindingPackageVersion !== '2.0.0-alpha.7' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
130
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.7 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
129
+ if (bindingPackageVersion !== '2.0.0-alpha.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
130
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
131
131
  }
132
132
  return binding
133
133
  } catch (e) {
@@ -142,8 +142,8 @@ function requireNative() {
142
142
  try {
143
143
  const binding = require('@brust/native-win32-x64-msvc')
144
144
  const bindingPackageVersion = require('@brust/native-win32-x64-msvc/package.json').version
145
- if (bindingPackageVersion !== '2.0.0-alpha.7' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
146
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.7 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
145
+ if (bindingPackageVersion !== '2.0.0-alpha.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
146
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
147
147
  }
148
148
  return binding
149
149
  } catch (e) {
@@ -159,8 +159,8 @@ function requireNative() {
159
159
  try {
160
160
  const binding = require('@brust/native-win32-ia32-msvc')
161
161
  const bindingPackageVersion = require('@brust/native-win32-ia32-msvc/package.json').version
162
- if (bindingPackageVersion !== '2.0.0-alpha.7' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
163
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.7 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
162
+ if (bindingPackageVersion !== '2.0.0-alpha.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
163
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
164
164
  }
165
165
  return binding
166
166
  } catch (e) {
@@ -175,8 +175,8 @@ function requireNative() {
175
175
  try {
176
176
  const binding = require('@brust/native-win32-arm64-msvc')
177
177
  const bindingPackageVersion = require('@brust/native-win32-arm64-msvc/package.json').version
178
- if (bindingPackageVersion !== '2.0.0-alpha.7' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
179
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.7 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
178
+ if (bindingPackageVersion !== '2.0.0-alpha.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
179
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
180
180
  }
181
181
  return binding
182
182
  } catch (e) {
@@ -194,8 +194,8 @@ function requireNative() {
194
194
  try {
195
195
  const binding = require('@brust/native-darwin-universal')
196
196
  const bindingPackageVersion = require('@brust/native-darwin-universal/package.json').version
197
- if (bindingPackageVersion !== '2.0.0-alpha.7' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
198
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.7 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
197
+ if (bindingPackageVersion !== '2.0.0-alpha.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
198
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
199
199
  }
200
200
  return binding
201
201
  } catch (e) {
@@ -210,8 +210,8 @@ function requireNative() {
210
210
  try {
211
211
  const binding = require('@brust/native-darwin-x64')
212
212
  const bindingPackageVersion = require('@brust/native-darwin-x64/package.json').version
213
- if (bindingPackageVersion !== '2.0.0-alpha.7' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
214
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.7 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
213
+ if (bindingPackageVersion !== '2.0.0-alpha.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
214
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
215
215
  }
216
216
  return binding
217
217
  } catch (e) {
@@ -226,8 +226,8 @@ function requireNative() {
226
226
  try {
227
227
  const binding = require('@brust/native-darwin-arm64')
228
228
  const bindingPackageVersion = require('@brust/native-darwin-arm64/package.json').version
229
- if (bindingPackageVersion !== '2.0.0-alpha.7' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
230
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.7 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
229
+ if (bindingPackageVersion !== '2.0.0-alpha.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
230
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
231
231
  }
232
232
  return binding
233
233
  } catch (e) {
@@ -246,8 +246,8 @@ function requireNative() {
246
246
  try {
247
247
  const binding = require('@brust/native-freebsd-x64')
248
248
  const bindingPackageVersion = require('@brust/native-freebsd-x64/package.json').version
249
- if (bindingPackageVersion !== '2.0.0-alpha.7' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
250
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.7 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
249
+ if (bindingPackageVersion !== '2.0.0-alpha.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
250
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
251
251
  }
252
252
  return binding
253
253
  } catch (e) {
@@ -262,8 +262,8 @@ function requireNative() {
262
262
  try {
263
263
  const binding = require('@brust/native-freebsd-arm64')
264
264
  const bindingPackageVersion = require('@brust/native-freebsd-arm64/package.json').version
265
- if (bindingPackageVersion !== '2.0.0-alpha.7' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
266
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.7 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
265
+ if (bindingPackageVersion !== '2.0.0-alpha.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
266
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
267
267
  }
268
268
  return binding
269
269
  } catch (e) {
@@ -283,8 +283,8 @@ function requireNative() {
283
283
  try {
284
284
  const binding = require('@brust/native-linux-x64-musl')
285
285
  const bindingPackageVersion = require('@brust/native-linux-x64-musl/package.json').version
286
- if (bindingPackageVersion !== '2.0.0-alpha.7' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
287
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.7 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
286
+ if (bindingPackageVersion !== '2.0.0-alpha.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
287
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
288
288
  }
289
289
  return binding
290
290
  } catch (e) {
@@ -299,8 +299,8 @@ function requireNative() {
299
299
  try {
300
300
  const binding = require('@brust/native-linux-x64-gnu')
301
301
  const bindingPackageVersion = require('@brust/native-linux-x64-gnu/package.json').version
302
- if (bindingPackageVersion !== '2.0.0-alpha.7' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
303
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.7 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
302
+ if (bindingPackageVersion !== '2.0.0-alpha.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
303
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
304
304
  }
305
305
  return binding
306
306
  } catch (e) {
@@ -317,8 +317,8 @@ function requireNative() {
317
317
  try {
318
318
  const binding = require('@brust/native-linux-arm64-musl')
319
319
  const bindingPackageVersion = require('@brust/native-linux-arm64-musl/package.json').version
320
- if (bindingPackageVersion !== '2.0.0-alpha.7' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
321
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.7 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
320
+ if (bindingPackageVersion !== '2.0.0-alpha.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
321
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
322
322
  }
323
323
  return binding
324
324
  } catch (e) {
@@ -333,8 +333,8 @@ function requireNative() {
333
333
  try {
334
334
  const binding = require('@brust/native-linux-arm64-gnu')
335
335
  const bindingPackageVersion = require('@brust/native-linux-arm64-gnu/package.json').version
336
- if (bindingPackageVersion !== '2.0.0-alpha.7' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
337
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.7 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
336
+ if (bindingPackageVersion !== '2.0.0-alpha.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
337
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
338
338
  }
339
339
  return binding
340
340
  } catch (e) {
@@ -351,8 +351,8 @@ function requireNative() {
351
351
  try {
352
352
  const binding = require('@brust/native-linux-arm-musleabihf')
353
353
  const bindingPackageVersion = require('@brust/native-linux-arm-musleabihf/package.json').version
354
- if (bindingPackageVersion !== '2.0.0-alpha.7' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
355
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.7 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
354
+ if (bindingPackageVersion !== '2.0.0-alpha.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
355
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
356
356
  }
357
357
  return binding
358
358
  } catch (e) {
@@ -367,8 +367,8 @@ function requireNative() {
367
367
  try {
368
368
  const binding = require('@brust/native-linux-arm-gnueabihf')
369
369
  const bindingPackageVersion = require('@brust/native-linux-arm-gnueabihf/package.json').version
370
- if (bindingPackageVersion !== '2.0.0-alpha.7' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
371
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.7 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
370
+ if (bindingPackageVersion !== '2.0.0-alpha.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
371
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
372
372
  }
373
373
  return binding
374
374
  } catch (e) {
@@ -385,8 +385,8 @@ function requireNative() {
385
385
  try {
386
386
  const binding = require('@brust/native-linux-loong64-musl')
387
387
  const bindingPackageVersion = require('@brust/native-linux-loong64-musl/package.json').version
388
- if (bindingPackageVersion !== '2.0.0-alpha.7' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
389
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.7 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
388
+ if (bindingPackageVersion !== '2.0.0-alpha.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
389
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
390
390
  }
391
391
  return binding
392
392
  } catch (e) {
@@ -401,8 +401,8 @@ function requireNative() {
401
401
  try {
402
402
  const binding = require('@brust/native-linux-loong64-gnu')
403
403
  const bindingPackageVersion = require('@brust/native-linux-loong64-gnu/package.json').version
404
- if (bindingPackageVersion !== '2.0.0-alpha.7' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
405
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.7 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
404
+ if (bindingPackageVersion !== '2.0.0-alpha.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
405
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
406
406
  }
407
407
  return binding
408
408
  } catch (e) {
@@ -419,8 +419,8 @@ function requireNative() {
419
419
  try {
420
420
  const binding = require('@brust/native-linux-riscv64-musl')
421
421
  const bindingPackageVersion = require('@brust/native-linux-riscv64-musl/package.json').version
422
- if (bindingPackageVersion !== '2.0.0-alpha.7' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
423
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.7 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
422
+ if (bindingPackageVersion !== '2.0.0-alpha.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
423
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
424
424
  }
425
425
  return binding
426
426
  } catch (e) {
@@ -435,8 +435,8 @@ function requireNative() {
435
435
  try {
436
436
  const binding = require('@brust/native-linux-riscv64-gnu')
437
437
  const bindingPackageVersion = require('@brust/native-linux-riscv64-gnu/package.json').version
438
- if (bindingPackageVersion !== '2.0.0-alpha.7' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
439
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.7 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
438
+ if (bindingPackageVersion !== '2.0.0-alpha.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
439
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
440
440
  }
441
441
  return binding
442
442
  } catch (e) {
@@ -452,8 +452,8 @@ function requireNative() {
452
452
  try {
453
453
  const binding = require('@brust/native-linux-ppc64-gnu')
454
454
  const bindingPackageVersion = require('@brust/native-linux-ppc64-gnu/package.json').version
455
- if (bindingPackageVersion !== '2.0.0-alpha.7' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
456
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.7 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
455
+ if (bindingPackageVersion !== '2.0.0-alpha.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
456
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
457
457
  }
458
458
  return binding
459
459
  } catch (e) {
@@ -468,8 +468,8 @@ function requireNative() {
468
468
  try {
469
469
  const binding = require('@brust/native-linux-s390x-gnu')
470
470
  const bindingPackageVersion = require('@brust/native-linux-s390x-gnu/package.json').version
471
- if (bindingPackageVersion !== '2.0.0-alpha.7' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
472
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.7 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
471
+ if (bindingPackageVersion !== '2.0.0-alpha.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
472
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
473
473
  }
474
474
  return binding
475
475
  } catch (e) {
@@ -488,8 +488,8 @@ function requireNative() {
488
488
  try {
489
489
  const binding = require('@brust/native-openharmony-arm64')
490
490
  const bindingPackageVersion = require('@brust/native-openharmony-arm64/package.json').version
491
- if (bindingPackageVersion !== '2.0.0-alpha.7' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
492
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.7 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
491
+ if (bindingPackageVersion !== '2.0.0-alpha.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
492
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
493
493
  }
494
494
  return binding
495
495
  } catch (e) {
@@ -504,8 +504,8 @@ function requireNative() {
504
504
  try {
505
505
  const binding = require('@brust/native-openharmony-x64')
506
506
  const bindingPackageVersion = require('@brust/native-openharmony-x64/package.json').version
507
- if (bindingPackageVersion !== '2.0.0-alpha.7' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
508
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.7 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
507
+ if (bindingPackageVersion !== '2.0.0-alpha.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
508
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
509
509
  }
510
510
  return binding
511
511
  } catch (e) {
@@ -520,8 +520,8 @@ function requireNative() {
520
520
  try {
521
521
  const binding = require('@brust/native-openharmony-arm')
522
522
  const bindingPackageVersion = require('@brust/native-openharmony-arm/package.json').version
523
- if (bindingPackageVersion !== '2.0.0-alpha.7' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
524
- throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.7 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
523
+ if (bindingPackageVersion !== '2.0.0-alpha.9' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
524
+ throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
525
525
  }
526
526
  return binding
527
527
  } catch (e) {
@@ -661,8 +661,8 @@ if (!nativeBinding || forceWasi) {
661
661
  if (!candidateFailed) {
662
662
  if (process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
663
663
  const bindingPackageVersion = require('@brust/native-wasm32-wasi/package.json').version
664
- if (bindingPackageVersion !== '2.0.0-alpha.7') {
665
- throw new Error(`WASI binding package version mismatch, expected 2.0.0-alpha.7 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
664
+ if (bindingPackageVersion !== '2.0.0-alpha.9') {
665
+ throw new Error(`WASI binding package version mismatch, expected 2.0.0-alpha.9 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
666
666
  }
667
667
  }
668
668
  wasiBinding = require('@brust/native-wasm32-wasi')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brust/core",
3
- "version": "2.0.0-alpha.7",
3
+ "version": "2.0.0-alpha.9",
4
4
  "description": "brust v2 — React components compiled to Rust-rendered templates",
5
5
  "license": "MIT",
6
6
  "homepage": "https://brust.dev",
@@ -55,7 +55,7 @@
55
55
  ]
56
56
  },
57
57
  "dependencies": {
58
- "@brust/runtime-dom": "2.0.0-alpha.7"
58
+ "@brust/runtime-dom": "2.0.0-alpha.9"
59
59
  },
60
60
  "peerDependencies": {
61
61
  "react": "^19.0.0",
@@ -93,12 +93,12 @@
93
93
  "access": "public"
94
94
  },
95
95
  "optionalDependencies": {
96
- "@brust/native-darwin-x64": "2.0.0-alpha.7",
97
- "@brust/native-darwin-arm64": "2.0.0-alpha.7",
98
- "@brust/native-linux-x64-gnu": "2.0.0-alpha.7",
99
- "@brust/native-linux-arm64-gnu": "2.0.0-alpha.7",
100
- "@brust/native-linux-x64-musl": "2.0.0-alpha.7",
101
- "@brust/native-linux-arm64-musl": "2.0.0-alpha.7",
102
- "@brust/core-cf": "2.0.0-alpha.7"
96
+ "@brust/native-darwin-x64": "2.0.0-alpha.9",
97
+ "@brust/native-darwin-arm64": "2.0.0-alpha.9",
98
+ "@brust/native-linux-x64-gnu": "2.0.0-alpha.9",
99
+ "@brust/native-linux-arm64-gnu": "2.0.0-alpha.9",
100
+ "@brust/native-linux-x64-musl": "2.0.0-alpha.9",
101
+ "@brust/native-linux-arm64-musl": "2.0.0-alpha.9",
102
+ "@brust/core-cf": "2.0.0-alpha.9"
103
103
  }
104
104
  }
@@ -15,6 +15,7 @@ import type { Compiled } from './compile'
15
15
  import { cssPlugin } from './css'
16
16
  import { BuildError } from './errors'
17
17
  import { RUNTIME_FEATURES } from './features'
18
+ import { packageDirOf } from './pkg-src'
18
19
 
19
20
  const REACT_EXTERNALS = ['react', 'react/*', 'react-dom', 'react-dom/*']
20
21
  /** Production React (and the production JSX transform: `react/jsx-runtime`, never `jsxDEV`). `brust dev` builds set
@@ -75,6 +76,9 @@ export function sourceDirPlugin(sourceOf: SourceOf, appRoot: string, external: s
75
76
  })
76
77
  b.onResolve({ filter: /^[^./]/ }, (a) => {
77
78
  if (!sourceOf.has(a.importer) || matchesExternal(a.path, external)) return undefined
79
+ // F153c: an artifact compiled from a package's source imports what that package sees.
80
+ const pkg = packageDirOf(sourceOf.get(a.importer)!)
81
+ if (pkg !== undefined) return { path: Bun.resolveSync(a.path, pkg) }
78
82
  // A package the staged file can see from where it sits resolves natively: the bundler then picks the package's ESM
79
83
  // entry (`module` / `exports.import`) and tree-shakes it. `Bun.resolveSync` answers with the CJS `main`, which
80
84
  // bundles the whole package (recharts: +85 KB gzip on the chart page). Packages only the app root sees (a staged
@@ -360,17 +364,30 @@ function memberImport(ext: { source: string; export: string; member: string[] },
360
364
 
361
365
  /** The component ids a React island receives inside its lowered JSX children (shadcn S1, R34.21): the union over
362
366
  * every file that passes children to it. `undefined` = no file does, the island has no revive code. */
363
- export function nestedOf(compiled: Map<string, Compiled>, id: string): string[] | undefined {
367
+ export function nestedOf(compiled: Map<string, Compiled>, id: string, routeRoots?: ReadonlySet<string>): string[] | undefined {
368
+ // F158 (R34.70): a route component's props are request data, so it is never a revive host, whatever a caller did.
369
+ if (routeRoots?.has(id)) return undefined
364
370
  let out: Set<string> | undefined
365
371
  for (const c of compiled.values()) {
366
372
  for (const ref of c.ir.children ?? []) {
367
- if (ref.id === id && ref.nested) for (const n of ref.nested) (out ??= new Set()).add(n)
368
- else if (ref.id === id && ref.nested !== undefined) out ??= new Set()
373
+ // `nested: []` (element-only children) still makes the island a host: its children are a JSON tree to revive.
374
+ if (ref.id === id && ref.nested !== undefined) {
375
+ out ??= new Set()
376
+ for (const n of ref.nested) out.add(n)
377
+ }
369
378
  }
370
379
  }
371
380
  return out && [...out].sort()
372
381
  }
373
382
 
383
+ /** F158 (R34.71): the element-prop names (`$x`) the compiler wrote at any call site of the island `id`: the only names
384
+ * its revive may revive. */
385
+ export function xOf(compiled: Map<string, Compiled>, id: string): string[] {
386
+ const out = new Set<string>()
387
+ for (const c of compiled.values()) for (const ref of c.ir.children ?? []) if (ref.id === id) for (const k of ref.x ?? []) out.add(k)
388
+ return [...out].sort()
389
+ }
390
+
374
391
  /** Every component some island revives (`nestedOf`), whatever its tier: its module must export it. */
375
392
  function revivedIds(compiled: Map<string, Compiled>): Set<string> {
376
393
  const out = new Set<string>()
@@ -398,7 +415,14 @@ export const reviveSource = (reg: string): string =>
398
415
  ` if (n.$brust === 'cmp') { if (typeof n.id !== 'string' || !__own.call(__reg, n.id)) throw new Error('brust: island children name the component ' + String(n.id) + ', which this island does not import'); return createElement(__reg[n.id], __xs(__props(n.p), n.x), ...kids) }\n` +
399
416
  ` throw new Error('brust: island children hold an unknown node')\n` +
400
417
  `}\n` +
401
- `const __mk = (C: any, props: any) => { const { children, $x, ...rest } = props; __xs(rest, $x); return createElement(C, rest, ...(children === undefined ? [] : Array.isArray(children) ? children : [children]).map(__rv)) }\n`
418
+ // `X` is the host's compiler-declared element-prop names (R34.71): a `$x` from the props can only select among them.
419
+ // A `$`-key other than `$x` is never the compiler's (R34.72): it throws instead of rendering (a 500, not a revive).
420
+ `const __mk = (C: any, props: any, X: string[] = []) => {\n` +
421
+ ` for (const k of Object.keys(props)) if (k.charAt(0) === '$' && k !== '$x') throw new Error('brust: island props hold the reserved key ' + k)\n` +
422
+ ` const { children, $x, ...rest } = props\n` +
423
+ ` __xs(rest, Array.isArray($x) ? $x.filter((k: any) => X.includes(k)) : undefined)\n` +
424
+ ` return createElement(C, rest, ...(children === undefined ? [] : Array.isArray(children) ? children : [children]).map(__rv))\n` +
425
+ `}\n`
402
426
 
403
427
  /** A helper component its module does not export (`ir.unexported`: `function SheetOverlay() {…}` rendered by an exported
404
428
  * `SheetContent`) that still renders as an island has nothing to import: the module is loaded with `export { Name }`
@@ -426,10 +450,10 @@ export function exposePlugin(compiled: Map<string, Compiled>): BunPlugin {
426
450
  /** The island entry of a react-tier component: registers `(host, props) => …` under its id. A
427
451
  * `client_only` component was never server-rendered (its host is empty), so it mounts with
428
452
  * `createRoot`; hydrating it would fail (React #418). Everything else hydrates the SSR markup. */
429
- export function islandShim(c: Compiled, compiled?: Map<string, Compiled>): string {
453
+ export function islandShim(c: Compiled, compiled?: Map<string, Compiled>, routeRoots?: ReadonlySet<string>): string {
430
454
  const clientOnly = c.ir.tier?.React?.client_only === true
431
- const nested = compiled && nestedOf(compiled, c.id)
432
- const element = nested ? '__mk(Comp, props)' : 'createElement(Comp, props)'
455
+ const nested = compiled && nestedOf(compiled, c.id, routeRoots)
456
+ const element = nested ? `__mk(Comp, props, ${JSON.stringify(xOf(compiled!, c.id))})` : 'createElement(Comp, props)'
433
457
  const [api, mount] = clientOnly
434
458
  ? ['createRoot', `createRoot(host, { identifierPrefix: ${JSON.stringify(c.id)} }).render(${element})`]
435
459
  : ['hydrateRoot', `hydrateRoot(host, ${element}, { identifierPrefix: ${JSON.stringify(c.id)} })`]
@@ -465,11 +489,11 @@ export function islandEntries(compiled: Map<string, Compiled>): Compiled[] {
465
489
  return [...compiled.values()].filter((c) => isReact(c) && (!c.ir.external || placed.has(c.id)))
466
490
  }
467
491
 
468
- export async function buildReactChunks(dist: string, compiled: Map<string, Compiled>, ctx: BrowserCtx, runtimeUrl: RuntimeUrls): Promise<Map<string, string>> {
492
+ export async function buildReactChunks(dist: string, compiled: Map<string, Compiled>, ctx: BrowserCtx, runtimeUrl: RuntimeUrls, routeRoots?: ReadonlySet<string>): Promise<Map<string, string>> {
469
493
  const entrypoints: string[] = []
470
494
  for (const c of islandEntries(compiled)) {
471
495
  const file = join(dist, '.stage', 'react', `react-${c.id}.tsx`)
472
- write(file, islandShim(c, compiled))
496
+ write(file, islandShim(c, compiled, routeRoots))
473
497
  stage(ctx.sourceOf, file, c)
474
498
  entrypoints.push(file)
475
499
  }
@@ -538,6 +562,7 @@ export async function buildJobs(
538
562
  appRoot: string,
539
563
  stores: string[] = [],
540
564
  cssMaps: Map<string, Record<string, string>> = new Map(),
565
+ routeRoots?: ReadonlySet<string>,
541
566
  ): Promise<void> {
542
567
  const imports: string[] = ["import { createElement } from 'react'", "import { renderToString } from 'react-dom/server'"]
543
568
  const entries: string[] = []
@@ -549,7 +574,7 @@ export async function buildJobs(
549
574
  imports.push(`import * as S${i} from ${JSON.stringify(resolve(appRoot, p))}`)
550
575
  }
551
576
  // Components an island revives from its lowered children (shadcn S1): one registry for every SSR job.
552
- const reviving = [...compiled.values()].filter((c) => nestedOf(compiled, c.id) !== undefined)
577
+ const reviving = [...compiled.values()].filter((c) => nestedOf(compiled, c.id, routeRoots) !== undefined)
553
578
  const revived = [...revivedIds(compiled)].map((id) => compiled.get(id)).filter((x): x is Compiled => x !== undefined)
554
579
  if (reviving.length > 0) {
555
580
  imports.push("import { Fragment } from 'react'")
@@ -571,7 +596,7 @@ export async function buildJobs(
571
596
  imports.push(componentImport(c, `C${n}`))
572
597
  // Ruling 2bf3775a (R1): the island's component id prefixes React's useId on BOTH sides
573
598
  // (the shim's hydrateRoot passes the same prefix), so ids differ across islands.
574
- fns.push(`ssr: (props: any) => renderToString(${hosts.has(c.id) ? `__mk(C${n}, props)` : `createElement(C${n}, props)`}, { identifierPrefix: ${JSON.stringify(c.id)} })`)
599
+ fns.push(`ssr: (props: any) => renderToString(${hosts.has(c.id) ? `__mk(C${n}, props, ${JSON.stringify(xOf(compiled, c.id))})` : `createElement(C${n}, props)`}, { identifierPrefix: ${JSON.stringify(c.id)} })`)
575
600
  }
576
601
  if (fns.length > 0) entries.push(` ${JSON.stringify(c.id)}: { ${fns.join(', ')} },`)
577
602
  n++
@@ -7,6 +7,8 @@ import { relative, sep } from 'node:path'
7
7
  import { type CompiledComponent, type CompiledTree, compileTree } from '../../native/index.js'
8
8
  import type { FlatRoute, Route } from '../routes'
9
9
  import { BuildError } from './errors'
10
+ import { checkAliasAgreement, readPathAliases } from './tsconfig-paths'
11
+ import type { PackageSources } from './pkg-src'
10
12
 
11
13
  /** `ComponentIR` as the compiler serialises it (snake_case), with the fields that are absent
12
14
  * when default (`ir/mod.rs`) normalised. The build reads it; it never rewrites it. */
@@ -39,7 +41,7 @@ export type ComponentIR = Record<string, any> & {
39
41
  /** The binding a React island imports this component by from `source` (absent: the default export). */
40
42
  export?: string
41
43
  /** Child components; `nested` is set when this file passes lowered JSX children to that child, an island (shadcn S1). */
42
- children?: { id: string | null; nested?: string[]; [field: string]: unknown }[]
44
+ children?: { id: string | null; nested?: string[]; x?: string[]; [field: string]: unknown }[]
43
45
  }
44
46
 
45
47
  export interface Compiled {
@@ -111,11 +113,17 @@ export function compileApp(opts: {
111
113
  iconsFinal?: boolean
112
114
  /** Values the build computed for `ir.build_eval` slots, by key (L2): the slots become literals. */
113
115
  slotValues?: Record<string, unknown>
116
+ /** F153c: the package sources this build wrote (`pkg-src.ts`); absent = package imports are islands. */
117
+ packages?: PackageSources
114
118
  }): { compiled: Map<string, Compiled>; routeComponent: Map<string, string> } {
115
119
  const { appRoot, leaves, componentFile } = opts
116
120
  const iconSvgsJson = opts.iconsFinal ? JSON.stringify({ final: true, svgs: opts.iconSvgs ?? {} }) : undefined
117
121
  const slotValuesJson = opts.slotValues && Object.keys(opts.slotValues).length > 0 ? JSON.stringify(opts.slotValues) : undefined
122
+ const packagesJson = opts.packages ? JSON.stringify(opts.packages) : undefined
118
123
  // The Rust side keys each map by its path relative to the app root (`/`-separated), like an import resolves.
124
+ const { aliases, notes } = readPathAliases(appRoot)
125
+ for (const n of notes) opts.log(`warning tsconfig-paths ${n}`)
126
+ const pathAliasesJson = aliases.length > 0 ? JSON.stringify(aliases) : undefined
119
127
  const cssModules = Object.fromEntries([...(opts.cssMaps ?? [])].map(([abs, map]) => [relative(realpathSync(appRoot), abs).split(sep).join('/'), map]))
120
128
  const seen = new Map<string, Seen>()
121
129
  const rootIdOfFile = new Map<string, string>()
@@ -124,6 +132,11 @@ export function compileApp(opts: {
124
132
  const nodes = new Map<string, Route>()
125
133
  for (const l of leaves) l.chain.forEach((r, i) => r.Component && nodes.set(l.chainIds[i]!, r))
126
134
 
135
+ // F158 (R34.69): the route components (pages and layouts) take request data as props, so the compiler never hands
136
+ // them lowered JSX from a caller. Keyed like an import resolves: relative to the app root, `/`-separated.
137
+ const rootRel = (f: string) => relative(appRoot, f).split(sep).join('/')
138
+ const routeRoots = [...new Set([...nodes.values()].flatMap((r) => componentFile.get(r.Component!) ?? []).flatMap((f) => [rootRel(f), relative(realpathSync(appRoot), realpathSync(f)).split(sep).join('/')]))]
139
+
127
140
  for (const [routeId, route] of nodes) {
128
141
  const file = componentFile.get(route.Component!)
129
142
  if (!file)
@@ -134,7 +147,7 @@ export function compileApp(opts: {
134
147
  let rootId = rootIdOfFile.get(file)
135
148
  if (!rootId) {
136
149
  const rel = relative(appRoot, file)
137
- const tree = compileTree(rel, appRoot, opts.runtimeImport, opts.serverOnly, slotValuesJson, cssModules, iconSvgsJson)
150
+ const tree = compileTree(rel, appRoot, opts.runtimeImport, opts.serverOnly, slotValuesJson, cssModules, iconSvgsJson, routeRoots, pathAliasesJson, packagesJson)
138
151
  if (tree.error) throw new BuildError(tree.error.rule, `${where(rel, tree.error)} ${tree.error.message}`)
139
152
  for (const [i, c] of tree.components.entries()) {
140
153
  // A lowering Error that came back as a diagnostic is a build error too (contract 9).
@@ -156,6 +169,7 @@ export function compileApp(opts: {
156
169
  for (const d of c.diagnostics)
157
170
  if (d.class === 'fallback' || d.class === 'warning') opts.log(`warning ${d.rule} ${where(c.source, d)} ${d.message}`)
158
171
  const ir = JSON.parse(c.ir) as ComponentIR
172
+ if (ir.alias_imports?.length) checkAliasAgreement(appRoot, ir.alias_imports)
159
173
  ir.use_id_slots ??= 0
160
174
  ir.uses_outlet ??= false
161
175
  ir.instances ??= []
@@ -8,11 +8,12 @@ import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, realpathSync,
8
8
  import { homedir } from 'node:os'
9
9
  import { basename, dirname, isAbsolute, join, parse, relative, resolve } from 'node:path'
10
10
  import { BrustRouteError, type FlatRoute, validateRoutes } from '../routes'
11
- import { type BrowserCtx, setDevBuild, buildActions, buildCacheAdapter, buildClientChunks, buildJobs, buildReactChunks, buildRuntime, storeModules } from './bundle'
11
+ import { type BrowserCtx, setDevBuild, buildActions, buildCacheAdapter, buildClientChunks, buildJobs, buildReactChunks, buildRuntime, nestedOf, storeModules } from './bundle'
12
12
  import { runActionsOnly } from './actions-only'
13
13
  import { type CfPrepared, buildCloudflare, prepareCloudflare } from './cloudflare'
14
14
  import { renderIcons } from './build-icons'
15
15
  import { evaluateBuildSlots } from './build-eval'
16
+ import { preparePackageSources } from './pkg-src'
16
17
  import { type Compiled, compileApp } from './compile'
17
18
  import { buildCss, CssGraph, directCss, resolveGlobals, routeCssSources } from './css'
18
19
  import { type ActionsBuildConfig, type CacheBuildConfig, loadBuildConfig } from './config'
@@ -248,6 +249,14 @@ async function buildInto(
248
249
  }
249
250
  const firstLog: string[] = []
250
251
  let { compiled, routeComponent } = compileApp({ ...compileOpts, log: (l) => firstLog.push(l) })
252
+ // F153c: the packages the app imports components from are compiled from their source when they publish it (and
253
+ // it matches what they publish); the app is compiled again with those sources. A refused package stays the island.
254
+ const external = [...new Set([...compiled.values()].flatMap((c) => (c.ir.external ? [c.ir.external.source] : [])))]
255
+ const packages = preparePackageSources(appRoot, external)
256
+ if (Object.keys(packages.scopes).length > 0) {
257
+ firstLog.length = 0
258
+ ;({ compiled, routeComponent } = compileApp({ ...compileOpts, packages, log: (l) => firstLog.push(l) }))
259
+ }
251
260
  // L23: lucide icons the compiler could inline are rendered here (react-dom/server); L2: slots that read
252
261
  // nothing request- or time-dependent are computed once, here. The app is compiled again with both (an icon with
253
262
  // no markup stays the L22 island; a slot with a value is a literal: no job, no worker). The first compile's
@@ -258,13 +267,20 @@ async function buildInto(
258
267
  const hasSlots = Object.keys(slotValues).length > 0
259
268
  if (hasIcons || hasSlots) {
260
269
  if (!hasIcons) firstLog.forEach((l) => o.log(l))
261
- ;({ compiled, routeComponent } = compileApp({ ...compileOpts, iconSvgs, iconsFinal: hasIcons, slotValues, log: hasIcons ? o.log : () => {} }))
270
+ ;({ compiled, routeComponent } = compileApp({ ...compileOpts, packages, iconSvgs, iconsFinal: hasIcons, slotValues, log: hasIcons ? o.log : () => {} }))
262
271
  } else firstLog.forEach((l) => o.log(l))
263
272
 
273
+ // F158 (R34.69/70): the compiler makes a caller of a route component fall back to React, so none is a revive host;
274
+ // if one is, the compiler missed it, and the build stops rather than let request data near the revive.
275
+ const routeRoots: ReadonlySet<string> = new Set(routeComponent.values())
276
+ for (const id of routeRoots) {
277
+ if (nestedOf(compiled, id) !== undefined) throw new BuildError('revive-host-route-root', `${id} is a page or layout and also receives lowered JSX children from a caller; this is a compiler bug (F158), please report it`)
278
+ }
279
+
264
280
  mkdirSync(join(out, 'jinja'), { recursive: true })
265
281
  for (const c of compiled.values()) writeFileSync(join(out, 'jinja', `${c.id}.jinja`), c.jinja)
266
282
 
267
- const chunks = new Map([...(await buildClientChunks(out, compiled, ctx, runtimeUrls)), ...(await buildReactChunks(out, compiled, ctx, runtimeUrls))])
283
+ const chunks = new Map([...(await buildClientChunks(out, compiled, ctx, runtimeUrls)), ...(await buildReactChunks(out, compiled, ctx, runtimeUrls, routeRoots))])
268
284
  const manifest = writeManifest({ leaves, routeComponent, compiled, runtime: { core: runtime.core, features: { ...runtime.features, store: runtime.store } }, chunks })
269
285
  // L33: a component whose chunk imports the store module (directly or through a shared chunk) has the page preload it.
270
286
  const readClient = (rel: string) => (existsSync(join(out, rel)) ? readFileSync(join(out, rel), 'utf8') : undefined)
@@ -273,7 +289,7 @@ async function buildInto(
273
289
  const files = [...new Set((routeCss.get(r.id) ?? []).flatMap((s) => (css.file.has(s) ? [css.file.get(s)!] : [])))]
274
290
  if (files.length > 0) r.css = files
275
291
  }
276
- await buildJobs(out, compiled, ctx.sourceOf, appRoot, storeModules(manifest), css.maps)
292
+ await buildJobs(out, compiled, ctx.sourceOf, appRoot, storeModules(manifest), css.maps, routeRoots)
277
293
  manifest.actions =
278
294
  o.actions && o.actionsEntry
279
295
  ? { entry: await buildActions(out, o.actionsEntry, css.maps), prefix: o.actions.prefix, maxBodyBytes: o.actions.maxBodyBytes, maxResponseBytes: o.actions.maxResponseBytes, crossSite: o.actions.crossSite }
@@ -0,0 +1,366 @@
1
+ // Package sources (shadcn S3 step 1, F153c, R34.61/R34.62): the compiler analyses a package component from the
2
+ // AUTHORED source its source map carries (`sourcesContent`), never from the published JS (G1, G2). This module runs
3
+ // no package code: sources are read, transpiled for the integrity check, and written, never imported; the compiler
4
+ // only parses them, and the build never evaluates a slot of a component compiled from them (L2). (The route scan
5
+ // imports the app graph, and with it the packages' published JS, as it always has: that is not new here.)
6
+ //
7
+ // For every bare import the app reaches (and, transitively, every bare import of a package source written here),
8
+ // the package's ESM entry is resolved, its `.map` read, and the `.ts`/`.tsx` sources written under
9
+ // `<app>/.brust/pkg-src/p-<hash>/` (the hash of the package's path: bun's store installs one copy per dependant; no
10
+ // text the package controls is ever part of a path). The compiler gets the resolution map (`PackageSources`), so it reads only what this build wrote:
11
+ // the directory is removed first, and a stale one is never consulted.
12
+ //
13
+ // Fail closed: a package with no ESM entry, no map, no source for its entry, a source outside the package, a
14
+ // relative import the map does not carry, a dynamic `import()` or `eval`, or a source whose literals and names are
15
+ // not all in the published JS (R34.62: the React build runs the dist, not the map; a containment check of literals and
16
+ // names, i.e. fidelity, not a security boundary: the author controls both files) is REFUSED, with the reason;
17
+ // the compiler then renders its components as React islands of the package export, exactly as before.
18
+ import { createHash } from 'node:crypto'
19
+ import { existsSync, mkdirSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync } from 'node:fs'
20
+ import { dirname, join, posix, relative, resolve, sep } from 'node:path'
21
+ import { BuildError } from './errors'
22
+
23
+ /** What the compiler reads (`AnalyzeOptions.packages`): per importing scope (`""` = the app, else the root-relative
24
+ * directory of a written package), each bare specifier → the root-relative path of its written entry source, or the
25
+ * reason it was refused. */
26
+ export interface PackageSources {
27
+ scopes: Record<string, Record<string, string>>
28
+ refused: Record<string, Record<string, string>>
29
+ /** Each written directory (root-relative) → the package's real directory: a bare import in an artifact compiled from
30
+ * a package source resolves from the package, as it does in a real install (not read by the compiler). */
31
+ dirs: Record<string, string>
32
+ }
33
+
34
+ /** The last build's written directories (absolute) → the package's real directory, for the bundler. */
35
+ const writtenDirs = new Map<string, string>()
36
+
37
+ /** The real directory of the package whose written source `file` (absolute) is, if it is one. */
38
+ export function packageDirOf(file: string): string | undefined {
39
+ for (const [dir, real] of writtenDirs) if (file.startsWith(dir + sep) || file.startsWith(`${dir}/`)) return real
40
+ return undefined
41
+ }
42
+
43
+ /** Where the sources go, relative to the app root. */
44
+ export const PKG_SRC_DIR = '.brust/pkg-src'
45
+
46
+ /** Never followed: the React runtime itself, brust, and platform modules. */
47
+ const NEVER = (spec: string) =>
48
+ /^(react|react-dom|scheduler)(\/|$)/.test(spec) ||
49
+ /^(@brust\/|brust(\/|$)|brustjs(\/|$))/.test(spec) ||
50
+ /^(node|bun):/.test(spec) ||
51
+ // L23 inlines lucide icons from the package export; the icons pass owns them.
52
+ /^lucide-react(\/|$)/.test(spec)
53
+
54
+ const LIMITS = { packages: 256, bytesPerPackage: 4 * 1024 * 1024, totalBytes: 64 * 1024 * 1024 }
55
+
56
+ type Outcome = { ok: true; dir: string; entry: string; imports: string[] } | { ok: false; reason: string }
57
+
58
+ /** `@scope/name/sub` → [`@scope/name`, `sub`]. */
59
+ export function splitSpecifier(spec: string): [string, string] {
60
+ const parts = spec.split('/')
61
+ const n = spec.startsWith('@') ? 2 : 1
62
+ return [parts.slice(0, n).join('/'), parts.slice(n).join('/')]
63
+ }
64
+
65
+ /** The first `node_modules/<name>` from `from` upwards, as a real path. */
66
+ function findPackage(name: string, from: string): string | null {
67
+ for (let dir = from; ; ) {
68
+ const p = join(dir, 'node_modules', name)
69
+ if (existsSync(join(p, 'package.json'))) return realpathSync(p)
70
+ const up = dirname(dir)
71
+ if (up === dir) return null
72
+ dir = up
73
+ }
74
+ }
75
+
76
+ /** The package's ESM entry for `import` (exports `.` → `import`/`module`/`default`, then `module`). */
77
+ function esmEntry(pj: Record<string, unknown>): string | null {
78
+ const pick = (x: unknown): string | null => {
79
+ if (typeof x === 'string') return x
80
+ if (!x || typeof x !== 'object') return null
81
+ const o = x as Record<string, unknown>
82
+ for (const k of ['import', 'module', 'default']) if (k in o) return pick(o[k])
83
+ return null
84
+ }
85
+ const exp = pj.exports
86
+ const dot = typeof exp === 'string' ? exp : exp && typeof exp === 'object' ? (exp as Record<string, unknown>)['.'] : undefined
87
+ const viaExports = dot === undefined ? null : pick(dot)
88
+ if (viaExports) return viaExports
89
+ return typeof pj.module === 'string' ? pj.module : null
90
+ }
91
+
92
+ /** The source map of `file`: its `sourceMappingURL` (a relative file), else `<file>.map`. */
93
+ function mapOf(file: string): string | null {
94
+ const text = readFileSync(file, 'utf8')
95
+ const m = /\/\/# sourceMappingURL=([^\s'"]+)\s*$/.exec(text)
96
+ if (m && !m[1]!.startsWith('data:') && !/^[a-z]+:/i.test(m[1]!)) {
97
+ const p = join(dirname(file), m[1]!)
98
+ if (existsSync(p)) return p
99
+ }
100
+ return existsSync(`${file}.map`) ? `${file}.map` : null
101
+ }
102
+
103
+ // ---------------------------------------------------------------------------------------------------------------
104
+ // Integrity (R34.62): every string/number literal and every name of the transpiled sources occurs in the published
105
+ // file the map belongs to. Both sides go through the same transpiler first, so quoting and type syntax agree.
106
+
107
+ /** Names the JSX transform and esbuild add or rename (`undefined` prints as `void 0`); not evidence either way. */
108
+ const JSX_NAMES = new Set(['createElement', '__name', '__defProp', 'React', 'undefined'])
109
+ const JSX_RUNTIME = /^(?:jsx|jsxs|jsxDEV|Fragment)(?:_[\w$]+)?$/
110
+ /** Keywords are syntax, not names: esbuild prints `const` as `var` and drops `type`/`interface` with the types. */
111
+ const KEYWORDS = new Set(
112
+ 'await break case catch class const continue debugger default delete do else enum export extends false finally for function if implements import in instanceof interface let new null package private protected public return static super switch this throw true try typeof var void while with yield async of get set as from type declare readonly abstract namespace module satisfies keyof infer is unique asserts override accessor'.split(' '),
113
+ )
114
+
115
+ export interface Skeleton {
116
+ strings: Set<string>
117
+ names: Set<string>
118
+ }
119
+
120
+ /** Literals and names of transpiled JS (a small lexer: strings, templates, comments, numbers, identifiers; a regex
121
+ * literal may be read as names, which only makes a mismatch more likely: fail closed). */
122
+ export function skeleton(js: string): Skeleton {
123
+ const strings = new Set<string>()
124
+ const names = new Set<string>()
125
+ let i = 0
126
+ const n = js.length
127
+ const templateDepth: number[] = []
128
+ let braces = 0
129
+ const readTemplateChunk = () => {
130
+ // at the char after '`' or after the '}' that closes `${`
131
+ let s = ''
132
+ while (i < n) {
133
+ const c = js[i]!
134
+ if (c === '\\') {
135
+ s += js.slice(i, i + 2)
136
+ i += 2
137
+ } else if (c === '`') {
138
+ i++
139
+ strings.add(s)
140
+ return
141
+ } else if (c === '$' && js[i + 1] === '{') {
142
+ i += 2
143
+ strings.add(s)
144
+ templateDepth.push(braces)
145
+ braces++
146
+ return
147
+ } else {
148
+ s += c
149
+ i++
150
+ }
151
+ }
152
+ }
153
+ while (i < n) {
154
+ const c = js[i]!
155
+ if (c === '/' && js[i + 1] === '/') {
156
+ while (i < n && js[i] !== '\n') i++
157
+ } else if (c === '/' && js[i + 1] === '*') {
158
+ const end = js.indexOf('*/', i + 2)
159
+ i = end < 0 ? n : end + 2
160
+ } else if (c === '"' || c === "'") {
161
+ let s = ''
162
+ i++
163
+ while (i < n && js[i] !== c) {
164
+ if (js[i] === '\\') {
165
+ s += js.slice(i, i + 2)
166
+ i += 2
167
+ } else s += js[i++]
168
+ }
169
+ i++
170
+ strings.add(s)
171
+ } else if (c === '`') {
172
+ i++
173
+ readTemplateChunk()
174
+ } else if (c === '{') {
175
+ braces++
176
+ i++
177
+ } else if (c === '}') {
178
+ braces--
179
+ i++
180
+ if (templateDepth.length && templateDepth[templateDepth.length - 1] === braces) {
181
+ templateDepth.pop()
182
+ readTemplateChunk()
183
+ }
184
+ } else if (/[0-9]/.test(c) || (c === '.' && /[0-9]/.test(js[i + 1] ?? ''))) {
185
+ const m = /^(?:0[xX][0-9a-fA-F_]+|0[bB][01_]+|0[oO][0-7_]+|(?:\d[\d_]*\.?\d*(?:[eE][+-]?\d+)?|\.\d+(?:[eE][+-]?\d+)?))n?/.exec(js.slice(i))
186
+ const tok = m ? m[0] : c
187
+ const num = Number(tok.replace(/_/g, '').replace(/n$/, ''))
188
+ strings.add(Number.isNaN(num) ? tok : `#${num}`)
189
+ i += tok.length
190
+ } else if (/[A-Za-z_$]/.test(c)) {
191
+ const m = /^[A-Za-z_$][\w$]*/.exec(js.slice(i))!
192
+ names.add(m[0])
193
+ i += m[0].length
194
+ } else i++
195
+ }
196
+ return { strings, names }
197
+ }
198
+
199
+ const transpile = (code: string, loader: 'tsx' | 'ts' | 'js') =>
200
+ new Bun.Transpiler({ loader, target: 'browser', minifyWhitespace: false, deadCodeElimination: false, trimUnusedImports: false }).transformSync(code)
201
+
202
+ /** What of `sources` is not in `published`; empty = the sources are what the published file was built from. */
203
+ export function integrityGaps(sources: { path: string; text: string }[], published: string): string[] {
204
+ const pub = skeleton(transpile(published, 'js'))
205
+ const gaps: string[] = []
206
+ for (const s of sources) {
207
+ const loader = s.path.endsWith('.tsx') ? 'tsx' : 'ts'
208
+ const sk = skeleton(transpile(s.text, loader))
209
+ // Import specifiers are module names, which bundling replaces; they are checked as imports instead.
210
+ for (const im of new Bun.Transpiler({ loader }).scanImports(s.text)) sk.strings.delete(im.path)
211
+ for (const v of sk.strings) if (!pub.strings.has(v)) gaps.push(`${s.path}: literal ${JSON.stringify(v.startsWith('#') ? v.slice(1) : v).slice(0, 60)}`)
212
+ for (const v of sk.names) if (!JSX_NAMES.has(v) && !JSX_RUNTIME.test(v) && !KEYWORDS.has(v) && !pub.names.has(v)) gaps.push(`${s.path}: name \`${v}\``)
213
+ }
214
+ return gaps
215
+ }
216
+
217
+ // ---------------------------------------------------------------------------------------------------------------
218
+
219
+ /** Reads one package (real directory `dir`), checks it, and writes its sources under `outRoot`. */
220
+ function writePackage(appRoot: string, dir: string, budget: { bytes: number }): Outcome {
221
+ const pj = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')) as Record<string, unknown>
222
+ const entryRel = esmEntry(pj)
223
+ if (!entryRel) return { ok: false, reason: 'no ESM entry (exports `import` or `module`)' }
224
+ const entry = join(dir, entryRel)
225
+ if (!existsSync(entry) || !statSync(entry).isFile()) return { ok: false, reason: `the ESM entry ${entryRel} is missing` }
226
+ const mapFile = mapOf(entry)
227
+ if (!mapFile) return { ok: false, reason: 'no source map for the ESM entry' }
228
+ let map: { sources?: unknown; sourcesContent?: unknown }
229
+ try {
230
+ map = JSON.parse(readFileSync(mapFile, 'utf8'))
231
+ } catch {
232
+ return { ok: false, reason: 'the source map is not JSON' }
233
+ }
234
+ const sources = Array.isArray(map.sources) ? (map.sources as unknown[]) : []
235
+ const contents = Array.isArray(map.sourcesContent) ? (map.sourcesContent as unknown[]) : []
236
+ // Each source as a path inside the package; anything outside it, or not TS/TSX, is not ours to read.
237
+ const files: { path: string; text: string }[] = []
238
+ for (const [k, s] of sources.entries()) {
239
+ const text = contents[k]
240
+ if (typeof s !== 'string' || typeof text !== 'string') continue
241
+ const abs = posix.normalize(posix.join(relative(dir, dirname(mapFile)).split(sep).join('/'), s))
242
+ if (abs.startsWith('..') || posix.isAbsolute(abs) || /^[a-z]+:/i.test(s)) return { ok: false, reason: `the source ${s} lies outside the package` }
243
+ if (!/\.tsx?$/.test(abs)) continue
244
+ files.push({ path: abs, text })
245
+ }
246
+ if (files.length === 0) return { ok: false, reason: 'the source map carries no TypeScript sources (`sourcesContent`)' }
247
+ const bytes = files.reduce((a, f) => a + f.text.length, 0)
248
+ if (bytes > LIMITS.bytesPerPackage) return { ok: false, reason: `the sources are ${bytes} bytes (limit ${LIMITS.bytesPerPackage})` }
249
+ if (budget.bytes + bytes > LIMITS.totalBytes) return { ok: false, reason: 'the package-source budget of this build is spent' }
250
+ // Imports: relative ones must be in the map (the compiler would otherwise fail on them), bare ones are followed.
251
+ const have = new Set(files.map((f) => f.path))
252
+ const bare = new Set<string>()
253
+ const imported = new Set<string>()
254
+ for (const f of files) {
255
+ if (/\beval\s*\(|\bnew\s+Function\b/.test(f.text)) return { ok: false, reason: `${f.path} calls eval or new Function` }
256
+ let imports: { path: string; kind: string }[]
257
+ try {
258
+ imports = new Bun.Transpiler({ loader: f.path.endsWith('.tsx') ? 'tsx' : 'ts' }).scanImports(f.text)
259
+ } catch (e) {
260
+ return { ok: false, reason: `${f.path} does not parse: ${String(e instanceof Error ? e.message : e).split('\n')[0]}` }
261
+ }
262
+ for (const im of imports) {
263
+ // The JSX transform's own runtime import (the transpiler adds it), and React itself.
264
+ if (NEVER(im.path)) continue
265
+ if (im.kind === 'dynamic-import' || im.kind === 'require-call' || im.kind === 'require-resolve') return { ok: false, reason: `${f.path} has a ${im.kind} (${im.path})` }
266
+ if (im.path.startsWith('./') || im.path.startsWith('../')) {
267
+ const base = posix.normalize(posix.join(posix.dirname(f.path), im.path))
268
+ const hit = [base, `${base}.tsx`, `${base}.ts`, `${base}/index.tsx`, `${base}/index.ts`].find((c) => have.has(c))
269
+ if (hit) imported.add(hit)
270
+ else return { ok: false, reason: `${f.path} imports ${im.path}, which the source map does not carry` }
271
+ } else if (im.path.startsWith('/') || /^[a-z]+:/i.test(im.path)) return { ok: false, reason: `${f.path} imports ${im.path}` }
272
+ else bare.add(im.path)
273
+ }
274
+ }
275
+ // The entry source: the one `package.json#source` names, else the only source no other source imports.
276
+ const declared = typeof pj.source === 'string' ? posix.normalize(pj.source.replace(/^\.\//, '')) : null
277
+ const roots = files.filter((f) => !imported.has(f.path))
278
+ const entrySrc = files.find((f) => f.path === declared) ?? (roots.length === 1 ? roots[0] : undefined)
279
+ if (!entrySrc) return { ok: false, reason: `the source map has ${files.length} sources and none is the entry (no \`source\` field, ${roots.length} unimported)` }
280
+ // R34.62: the published file must be what these sources were built into.
281
+ let gaps: string[]
282
+ try {
283
+ gaps = integrityGaps(files, readFileSync(entry, 'utf8'))
284
+ } catch (e) {
285
+ return { ok: false, reason: `the integrity check could not read the sources or ${entryRel}: ${String(e instanceof Error ? e.message : e).split('\n')[0]}` }
286
+ }
287
+ if (gaps.length > 0) return { ok: false, reason: `the sources do not match the published ${entryRel} (${gaps.length} differences, first: ${gaps[0]})` }
288
+ // Keyed on where the package sits relative to the app (stable across machines), not its absolute path.
289
+ // Review F1 (security): no package-controlled text in the path. The directory is named by a hash of where the package
290
+ // sits relative to the app (stable across machines), and every target must resolve inside the directory this build
291
+ // owns before anything is created; a `name`/`version` of `../..` cannot move a write.
292
+ const hash = createHash('sha256').update(relative(appRoot, dir).split(sep).join('/')).digest('hex').slice(0, 16)
293
+ const outRel = posix.join(PKG_SRC_DIR, `p-${hash}`)
294
+ const own = resolve(appRoot, PKG_SRC_DIR) + sep
295
+ const targets = files.map((f) => ({ f, target: resolve(appRoot, outRel, f.path) }))
296
+ const escaped = targets.find((t) => !t.target.startsWith(own))
297
+ if (escaped) return { ok: false, reason: `the source ${escaped.f.path} would be written outside ${PKG_SRC_DIR}` }
298
+ for (const { f, target } of targets) {
299
+ mkdirSync(dirname(target), { recursive: true })
300
+ // The directories just made are this build's: a real path elsewhere means a link was planted in between.
301
+ if (!`${realpathSync(dirname(target))}${sep}`.startsWith(realpathSync(resolve(appRoot, PKG_SRC_DIR)) + sep))
302
+ return { ok: false, reason: `the source ${f.path} would be written outside ${PKG_SRC_DIR}` }
303
+ writeFileSync(target, f.text)
304
+ }
305
+ budget.bytes += bytes
306
+ return { ok: true, dir: outRel, entry: posix.join(outRel, entrySrc.path), imports: [...bare].sort() }
307
+ }
308
+
309
+ /**
310
+ * Writes the sources of every package `specs` reaches from the app (and of every package those sources import),
311
+ * and returns the resolution map for the compiler. The directory is rebuilt from nothing on every call.
312
+ */
313
+ export function preparePackageSources(appRoot: string, specs: Iterable<string>): PackageSources {
314
+ const root = realpathSync(appRoot)
315
+ rmSync(join(root, PKG_SRC_DIR), { recursive: true, force: true })
316
+ mkdirSync(join(root, PKG_SRC_DIR), { recursive: true })
317
+ // The directory this build owns must itself be inside the app (`.brust` is not a link out of it).
318
+ if (!realpathSync(join(root, PKG_SRC_DIR)).startsWith(root + sep)) throw new BuildError('package-source', `${PKG_SRC_DIR} resolves outside the app root (a link?); remove it and build again`)
319
+ const out: PackageSources = { scopes: {}, refused: {}, dirs: {} }
320
+ writtenDirs.clear()
321
+ const byDir = new Map<string, Outcome>()
322
+ const budget = { bytes: 0 }
323
+ // (scope, the real directory bare imports resolve from, specifier)
324
+ const queue: [string, string, string][] = [...new Set(specs)].sort().map((s) => ['', root, s])
325
+ const seen = new Set<string>()
326
+ while (queue.length > 0) {
327
+ const [scope, from, spec] = queue.shift()!
328
+ const key = `${scope}\0${spec}`
329
+ if (seen.has(key) || NEVER(spec)) continue
330
+ seen.add(key)
331
+ const refuse = (reason: string) => {
332
+ ;(out.refused[scope] ??= {})[spec] = reason
333
+ }
334
+ const [name, sub] = splitSpecifier(spec)
335
+ if (sub) {
336
+ refuse('a package subpath import is not followed')
337
+ continue
338
+ }
339
+ const dir = findPackage(name, from)
340
+ if (!dir) {
341
+ refuse('not installed')
342
+ continue
343
+ }
344
+ let o = byDir.get(dir)
345
+ if (!o) {
346
+ try {
347
+ o = byDir.size >= LIMITS.packages ? { ok: false, reason: `more than ${LIMITS.packages} packages` } : writePackage(root, dir, budget)
348
+ } catch (e) {
349
+ // An unreadable package.json or map is a refusal: a package never fails the build here.
350
+ o = { ok: false, reason: `unreadable: ${String(e instanceof Error ? e.message : e).split('\n')[0]}` }
351
+ }
352
+ byDir.set(dir, o)
353
+ // A refusal is reported where it matters: the compiler names it on the island it leaves (`external-component`).
354
+ if (o.ok) {
355
+ out.dirs[o.dir] = dir
356
+ writtenDirs.set(join(root, o.dir), dir)
357
+ for (const im of o.imports) queue.push([o.dir, dir, im])
358
+ }
359
+ }
360
+ if (o.ok) (out.scopes[scope] ??= {})[spec] = o.entry
361
+ else refuse(o.reason)
362
+ }
363
+ mkdirSync(join(root, PKG_SRC_DIR), { recursive: true })
364
+ writeFileSync(join(root, PKG_SRC_DIR, 'index.json'), `${JSON.stringify(out, null, 2)}\n`)
365
+ return out
366
+ }
@@ -0,0 +1,67 @@
1
+ // `tsconfig` `paths` aliases (shadcn S1, R34.76): `import … from "@/components/ui/button"` is a file of the app. The compiler
2
+ // resolves the specifiers that match an alias to the relative import of the file they name, from root-relative templates
3
+ // this module reads out of the app's own `tsconfig.json` / `jsconfig.json`. v1 reads that one file: no `extends`, no
4
+ // `references` (a named fallback below); exact and single-`*` patterns only. The bundler resolves the same specifiers
5
+ // natively; `checkAliasAgreement` fails the build if the two ever disagree.
6
+ import { existsSync, readFileSync, realpathSync } from 'node:fs'
7
+ import { dirname, isAbsolute, join, normalize, relative, sep } from 'node:path'
8
+ import { BuildError } from './errors'
9
+
10
+ export interface PathAlias {
11
+ pattern: string
12
+ targets: string[]
13
+ }
14
+
15
+ const FILES = ['tsconfig.json', 'jsconfig.json']
16
+
17
+ /** The aliases of the app's tsconfig, as root-relative `/`-separated templates; `notes` says what was left out and why. */
18
+ export function readPathAliases(appRoot: string): { aliases: PathAlias[]; notes: string[] } {
19
+ const file = FILES.map((f) => join(appRoot, f)).find((f) => existsSync(f))
20
+ if (!file) return { aliases: [], notes: [] }
21
+ let json: { extends?: unknown; references?: unknown; compilerOptions?: { baseUrl?: unknown; paths?: unknown } }
22
+ try {
23
+ json = Bun.JSONC.parse(readFileSync(file, 'utf8')) as typeof json
24
+ } catch {
25
+ return { aliases: [], notes: [`${relative(appRoot, file)} could not be parsed; its \`paths\` aliases are not followed`] }
26
+ }
27
+ const notes: string[] = []
28
+ const paths = json?.compilerOptions?.paths
29
+ if (json?.extends !== undefined || json?.references !== undefined)
30
+ notes.push(
31
+ `${relative(appRoot, file)} uses \`${json.extends !== undefined ? 'extends' : 'references'}\`, which brust does not follow: \`paths\` aliases written in another tsconfig stay package imports (put \`paths\` in ${relative(appRoot, file)})`,
32
+ )
33
+ if (!paths || typeof paths !== 'object') return { aliases: [], notes }
34
+ const base = typeof json.compilerOptions?.baseUrl === 'string' ? json.compilerOptions.baseUrl : '.'
35
+ const aliases: PathAlias[] = []
36
+ for (const [pattern, raw] of Object.entries(paths as Record<string, unknown>)) {
37
+ const stars = pattern.split('*').length - 1
38
+ if (stars > 1 || !Array.isArray(raw)) {
39
+ notes.push(`the \`paths\` pattern "${pattern}" is not an exact or single-\`*\` pattern; it is not followed`)
40
+ continue
41
+ }
42
+ const targets: string[] = []
43
+ for (const t of raw) {
44
+ if (typeof t !== 'string' || (t.split('*').length - 1) > 1 || isAbsolute(t)) continue
45
+ const rel = normalize(join(base, t)).split(sep).join('/')
46
+ // Outside the app sources, or a package: not a file the compiler reads.
47
+ if (rel.startsWith('..') || rel.includes('node_modules/')) continue
48
+ targets.push(rel)
49
+ }
50
+ if (targets.length > 0) aliases.push({ pattern, targets })
51
+ }
52
+ return { aliases, notes }
53
+ }
54
+
55
+ /** The compiler's answer for every alias import must be the file the bundler resolves the same specifier to. */
56
+ export function checkAliasAgreement(appRoot: string, imports: { from: string; spec: string; target: string }[]): void {
57
+ for (const { from, spec, target } of imports) {
58
+ let got: string
59
+ try {
60
+ got = realpathSync(Bun.resolveSync(spec, dirname(join(appRoot, from))))
61
+ } catch {
62
+ throw new BuildError('alias-mismatch', `${from}: the compiler resolves "${spec}" to ${target}, but the bundler cannot resolve it (check tsconfig \`paths\`)`)
63
+ }
64
+ if (got !== realpathSync(join(appRoot, target)))
65
+ throw new BuildError('alias-mismatch', `${from}: "${spec}" resolves to ${target} for the compiler but to ${relative(appRoot, got)} for the bundler (tsconfig \`paths\` is read differently); fix the alias or use a relative import`)
66
+ }
67
+ }