@brust/core 2.0.0-alpha.5 → 2.0.0-alpha.6

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.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.5' && 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.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
92
+ if (bindingPackageVersion !== '2.0.0-alpha.6' && 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.6 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.5' && 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.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
108
+ if (bindingPackageVersion !== '2.0.0-alpha.6' && 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.6 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.5' && 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.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
129
+ if (bindingPackageVersion !== '2.0.0-alpha.6' && 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.6 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.5' && 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.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
145
+ if (bindingPackageVersion !== '2.0.0-alpha.6' && 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.6 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.5' && 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.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
162
+ if (bindingPackageVersion !== '2.0.0-alpha.6' && 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.6 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.5' && 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.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
178
+ if (bindingPackageVersion !== '2.0.0-alpha.6' && 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.6 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.5' && 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.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
197
+ if (bindingPackageVersion !== '2.0.0-alpha.6' && 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.6 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.5' && 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.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
213
+ if (bindingPackageVersion !== '2.0.0-alpha.6' && 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.6 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.5' && 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.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
229
+ if (bindingPackageVersion !== '2.0.0-alpha.6' && 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.6 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.5' && 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.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
249
+ if (bindingPackageVersion !== '2.0.0-alpha.6' && 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.6 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.5' && 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.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
265
+ if (bindingPackageVersion !== '2.0.0-alpha.6' && 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.6 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.5' && 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.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
286
+ if (bindingPackageVersion !== '2.0.0-alpha.6' && 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.6 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.5' && 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.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
302
+ if (bindingPackageVersion !== '2.0.0-alpha.6' && 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.6 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.5' && 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.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
320
+ if (bindingPackageVersion !== '2.0.0-alpha.6' && 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.6 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.5' && 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.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
336
+ if (bindingPackageVersion !== '2.0.0-alpha.6' && 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.6 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.5' && 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.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
354
+ if (bindingPackageVersion !== '2.0.0-alpha.6' && 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.6 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.5' && 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.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
370
+ if (bindingPackageVersion !== '2.0.0-alpha.6' && 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.6 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.5' && 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.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
388
+ if (bindingPackageVersion !== '2.0.0-alpha.6' && 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.6 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.5' && 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.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
404
+ if (bindingPackageVersion !== '2.0.0-alpha.6' && 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.6 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.5' && 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.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
422
+ if (bindingPackageVersion !== '2.0.0-alpha.6' && 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.6 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.5' && 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.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
438
+ if (bindingPackageVersion !== '2.0.0-alpha.6' && 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.6 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.5' && 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.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
455
+ if (bindingPackageVersion !== '2.0.0-alpha.6' && 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.6 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.5' && 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.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
471
+ if (bindingPackageVersion !== '2.0.0-alpha.6' && 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.6 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.5' && 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.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
491
+ if (bindingPackageVersion !== '2.0.0-alpha.6' && 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.6 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.5' && 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.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
507
+ if (bindingPackageVersion !== '2.0.0-alpha.6' && 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.6 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.5' && 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.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
523
+ if (bindingPackageVersion !== '2.0.0-alpha.6' && 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.6 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.5') {
665
- throw new Error(`WASI binding package version mismatch, expected 2.0.0-alpha.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
664
+ if (bindingPackageVersion !== '2.0.0-alpha.6') {
665
+ throw new Error(`WASI binding package version mismatch, expected 2.0.0-alpha.6 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.5",
3
+ "version": "2.0.0-alpha.6",
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.5"
58
+ "@brust/runtime-dom": "2.0.0-alpha.6"
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.5",
97
- "@brust/native-darwin-arm64": "2.0.0-alpha.5",
98
- "@brust/native-linux-x64-gnu": "2.0.0-alpha.5",
99
- "@brust/native-linux-arm64-gnu": "2.0.0-alpha.5",
100
- "@brust/native-linux-x64-musl": "2.0.0-alpha.5",
101
- "@brust/native-linux-arm64-musl": "2.0.0-alpha.5",
102
- "@brust/core-cf": "2.0.0-alpha.5"
96
+ "@brust/native-darwin-x64": "2.0.0-alpha.6",
97
+ "@brust/native-darwin-arm64": "2.0.0-alpha.6",
98
+ "@brust/native-linux-x64-gnu": "2.0.0-alpha.6",
99
+ "@brust/native-linux-arm64-gnu": "2.0.0-alpha.6",
100
+ "@brust/native-linux-x64-musl": "2.0.0-alpha.6",
101
+ "@brust/native-linux-arm64-musl": "2.0.0-alpha.6",
102
+ "@brust/core-cf": "2.0.0-alpha.6"
103
103
  }
104
104
  }
@@ -43,7 +43,7 @@ export async function runActionsOnly(o: {
43
43
  version: MANIFEST_VERSION,
44
44
  routes: [],
45
45
  components: {},
46
- assets: { runtime: '' },
46
+ assets: { runtime: '', features: {} },
47
47
  jobs_module: 'jobs.js',
48
48
  actions: { entry: await buildActions(tmp, entry), prefix: actions.prefix, maxBodyBytes: actions.maxBodyBytes, maxResponseBytes: actions.maxResponseBytes, crossSite: actions.crossSite },
49
49
  actions_only: true,
@@ -14,6 +14,7 @@ import type { BunPlugin } from 'bun'
14
14
  import type { Compiled } from './compile'
15
15
  import { cssPlugin } from './css'
16
16
  import { BuildError } from './errors'
17
+ import { RUNTIME_FEATURES } from './features'
17
18
 
18
19
  const REACT_EXTERNALS = ['react', 'react/*', 'react-dom', 'react-dom/*']
19
20
  /** Production React (and the production JSX transform: `react/jsx-runtime`, never `jsxDEV`). `brust dev` builds set
@@ -208,52 +209,86 @@ async function browserBuild(
208
209
  return entries
209
210
  }
210
211
 
211
- /** D3/C6: one runtime instance per page. Island and native client builds resolve the reactive core and
212
- * the store API to the runtime bundle URL (external), exactly as the compiler's `runtimeImport`. The
213
- * React bridge (`useStore`) is bundled (it holds no module state), but ITS imports of the core are the
214
- * runtime too. Registered after `serverOnlyPlugin`, before `sourceDirPlugin` (which would resolve the
212
+ /** The client runtime's URLs (L33): the core every page loads, the `store` module (`defineStore` + the reactive
213
+ * primitives a store's code imports), and the feature modules. Core and features are single shared ESM files, so a
214
+ * page has one signal graph and one binder registry however many features it loads. */
215
+ export interface RuntimeUrls {
216
+ core: string
217
+ store: string
218
+ }
219
+
220
+ /** D3/C6: one runtime instance per page. Island and native client builds resolve the reactive core to the core URL
221
+ * and the store API to the store module's URL (external), exactly as the compiler's `runtimeImport` (the core). The
222
+ * React bridge (`useStore`) is bundled (it holds no module state), but ITS imports of the core are the store
223
+ * module too. Registered after `serverOnlyPlugin`, before `sourceDirPlugin` (which would resolve the
215
224
  * bare specifiers to files). */
216
- export function runtimeAliasPlugin(runtimeUrl: string): BunPlugin {
225
+ export function runtimeAliasPlugin(urls: RuntimeUrls): BunPlugin {
217
226
  return {
218
227
  name: 'brust-runtime-alias',
219
228
  setup(b) {
220
- b.onResolve({ filter: /^@brust\/(runtime-dom(\/store)?|core\/store)$/ }, () => ({ path: runtimeUrl, external: true }))
229
+ b.onResolve({ filter: /^@brust\/runtime-dom(\/core)?$/ }, () => ({ path: urls.core, external: true }))
230
+ b.onResolve({ filter: /^@brust\/(runtime-dom|core)\/store$/ }, () => ({ path: urls.store, external: true }))
221
231
  let bridge: string | undefined
222
232
  b.onResolve({ filter: /^@brust\/(runtime-dom|core)\/store\/react$/ }, () => {
223
233
  bridge ??= Bun.resolveSync('@brust/runtime-dom/store/react', import.meta.dir) // core lane file; resolved lazily
224
234
  return { path: bridge }
225
235
  })
226
- b.onResolve({ filter: /^\.\.?\// }, (a) => (bridge !== undefined && a.importer === bridge ? { path: runtimeUrl, external: true } : undefined))
236
+ b.onResolve({ filter: /^\.\.?\// }, (a) => (bridge !== undefined && a.importer === bridge ? { path: urls.store, external: true } : undefined))
227
237
  },
228
238
  }
229
239
  }
230
240
 
231
- /** `dist/client/runtime-<hex>.js`: runtime-dom, re-exported (client chunks import `signal`,
232
- * `defineBehavior`, … from this URL) and mounted on `document.documentElement` (contract 6). */
233
- export async function buildRuntime(dist: string, ctx: BrowserCtx): Promise<string> {
234
- const entry = join(dist, '.stage', 'runtime.ts')
235
- write(entry, "export * from '@brust/runtime-dom'\nimport { mount } from '@brust/runtime-dom'\nmount(document.documentElement)\n")
241
+ /** What `buildRuntime` wrote: `client/<file>` paths (relative to dist). */
242
+ export interface RuntimeAssets {
243
+ /** The core: `export *` of the runtime core + `mount(document.documentElement)` (contract 6). */
244
+ core: string
245
+ store: string
246
+ /** Feature module name → file; every module is built, a route links the ones its components need. */
247
+ features: Record<string, string>
248
+ }
249
+
250
+ /** `dist/client/runtime-<hex>.js` (the core; client chunks import `signal`, `defineBehavior`, … from this URL), then
251
+ * one `rt-<feature>-<hex>.js` per feature module and `rt-store-<hex>.js`, each importing the core by that URL. */
252
+ export async function buildRuntime(dist: string, ctx: BrowserCtx): Promise<RuntimeAssets> {
236
253
  // Resolved from this package (its dependency), not from wherever `dist/` sits.
237
- const runtimeDom = Bun.resolveSync('@brust/runtime-dom', import.meta.dir)
238
- const res = await browserBuild(dist, 'runtime', ctx, {
239
- entrypoints: [entry],
254
+ const dir = dirname(Bun.resolveSync('@brust/runtime-dom', import.meta.dir))
255
+ const coreEntry = join(dist, '.stage', 'runtime.ts')
256
+ write(coreEntry, "export * from '@brust/runtime-dom/core'\nimport { mount } from '@brust/runtime-dom/core'\nmount(document.documentElement)\n")
257
+ const core = (
258
+ await browserBuild(dist, 'runtime', ctx, {
259
+ entrypoints: [coreEntry],
260
+ plugins: [{ name: 'brust-runtime-dom', setup: (b) => void b.onResolve({ filter: /^@brust\/runtime-dom\/core$/ }, () => ({ path: join(dir, 'core.ts') })) }],
261
+ })
262
+ ).get('runtime')!
263
+ // Features import the core's API (`core-api`, and `core` for the store's re-exports) from the core file by URL.
264
+ const coreUrl = `/_brust/${core}`
265
+ const coreFiles = new Set(['core-api', 'core'].map((f) => join(dir, f)))
266
+ const names = [...RUNTIME_FEATURES, 'store'] as const
267
+ const entries = names.map((n) => {
268
+ const file = join(dist, '.stage', `rt-${n}.ts`)
269
+ write(file, `import ${JSON.stringify(join(dir, 'features', n))}\nexport * from ${JSON.stringify(join(dir, 'features', n))}\n`)
270
+ return file
271
+ })
272
+ const built = await browserBuild(dist, 'runtime features', ctx, {
273
+ entrypoints: entries,
240
274
  plugins: [
241
275
  {
242
- name: 'brust-runtime-dom',
243
- setup(b) {
244
- b.onResolve({ filter: /^@brust\/runtime-dom$/ }, () => ({ path: runtimeDom }))
245
- },
276
+ name: 'brust-runtime-core-external',
277
+ setup: (b) =>
278
+ void b.onResolve({ filter: /^\.\.?\/(core-api|core)$/ }, (a) => (coreFiles.has(resolve(dirname(a.importer), a.path)) ? { path: coreUrl, external: true } : undefined)),
246
279
  },
247
280
  ],
248
281
  })
249
- return res.get('runtime')!
282
+ const features: Record<string, string> = {}
283
+ for (const n of RUNTIME_FEATURES) features[n] = built.get(`rt-${n}`)!
284
+ return { core, store: built.get('rt-store')!, features }
250
285
  }
251
286
 
252
287
  /** One entry chunk per component with client JS (`<id>-<hex>.js`), split: a module two chunks
253
288
  * import (a store) lands once in a shared `chunk-<hex>.js`, so one page has one instance of it.
254
289
  * The runtime import stays the absolute `/_brust/client/runtime-<hex>.js` URL the compiler
255
290
  * printed (external: one runtime for every chunk). */
256
- export async function buildClientChunks(dist: string, compiled: Map<string, Compiled>, ctx: BrowserCtx, runtimeUrl: string): Promise<Map<string, string>> {
291
+ export async function buildClientChunks(dist: string, compiled: Map<string, Compiled>, ctx: BrowserCtx, runtimeUrl: RuntimeUrls): Promise<Map<string, string>> {
257
292
  const entrypoints: string[] = []
258
293
  for (const c of compiled.values()) {
259
294
  if (c.clientJs === undefined) continue
@@ -279,25 +314,114 @@ export function stage(sourceOf: SourceOf, file: string, c: Compiled): void {
279
314
 
280
315
  const isReact = (c: Compiled) => typeof c.ir.tier === 'object' && c.ir.tier !== null && 'React' in c.ir.tier
281
316
 
282
- /** The `import` line that brings a react-tier component's code in as `local`: its own module, or
283
- * for a package export (L22) the export itself. */
317
+ /** An import/export binding spelled as the module wrote it: bare when an identifier, else a string name. */
318
+ const bindingName = (name: string) => (/^[A-Za-z_$][\w$]*$/.test(name) ? name : JSON.stringify(name))
319
+
320
+ /** The `import` line that brings a react-tier component's code in as `local`: the binding its importer used
321
+ * (`import Foo` → the default export, `import { Foo }` / `export { A as Foo }` / `export const Foo` → `Foo`),
322
+ * or for a package export (L22) the export itself. Each component of a file with several is its own island
323
+ * entry; the bundler keeps ONE instance of the file for all of them (splitting). */
284
324
  export function componentImport(c: Compiled, local: string): string {
285
325
  const ext = c.ir.external
286
- if (!ext) return `import ${local} from ${JSON.stringify(c.file)}`
326
+ if (ext?.member?.length) return memberImport(ext as { source: string; export: string; member: string[] }, local)
327
+ const [from, binding] = ext ? [JSON.stringify(ext.source), ext.export] : [JSON.stringify(c.file), c.ir.export ?? 'default']
328
+ return binding === 'default' ? `import ${local} from ${from}` : `import { ${bindingName(binding)} as ${local} } from ${from}`
329
+ }
330
+
331
+ /** A member of a package import (`<DialogPrimitive.Root>`, S1.4 R34.35): the export (a name, `default`, or `*` for a
332
+ * namespace import) is bound once and the member is read off it. A path the package does not have is `undefined`
333
+ * (the bundler does not check member access), so it throws a named error when the island entry or the SSR job loads. */
334
+ function memberImport(ext: { source: string; export: string; member: string[] }, local: string): string {
335
+ const ns = `${local}__ns`
287
336
  const from = JSON.stringify(ext.source)
288
- return ext.export === 'default' ? `import ${local} from ${from}` : `import { ${JSON.stringify(ext.export).replace(/^"|"$/g, '')} as ${local} } from ${from}`
337
+ const head = ext.export === 'default' ? `import ${ns} from ${from}` : ext.export === '*' ? `import * as ${ns} from ${from}` : `import { ${bindingName(ext.export)} as ${ns} } from ${from}`
338
+ const path = (ext.export === '*' ? ext.member : [ext.export, ...ext.member]).join('.')
339
+ const read = ext.member.map((m) => (/^[A-Za-z_$][\w$]*$/.test(m) ? `.${m}` : `[${JSON.stringify(m)}]`)).join('')
340
+ return `${head}\nconst ${local} = ${ns}${read}\nif (${local} === undefined) throw new Error(${JSON.stringify(`brust: ${ext.source} has no export ${path}`)})`
341
+ }
342
+
343
+ /** The component ids a React island receives inside its lowered JSX children (shadcn S1, R34.21): the union over
344
+ * every file that passes children to it. `undefined` = no file does, the island has no revive code. */
345
+ export function nestedOf(compiled: Map<string, Compiled>, id: string): string[] | undefined {
346
+ let out: Set<string> | undefined
347
+ for (const c of compiled.values()) {
348
+ for (const ref of c.ir.children ?? []) {
349
+ if (ref.id === id && ref.nested) for (const n of ref.nested) (out ??= new Set()).add(n)
350
+ else if (ref.id === id && ref.nested !== undefined) out ??= new Set()
351
+ }
352
+ }
353
+ return out && [...out].sort()
354
+ }
355
+
356
+ /** Every component some island revives (`nestedOf`), whatever its tier: its module must export it. */
357
+ function revivedIds(compiled: Map<string, Compiled>): Set<string> {
358
+ const out = new Set<string>()
359
+ for (const c of compiled.values()) for (const ref of c.ir.children ?? []) for (const n of ref.nested ?? []) out.add(n)
360
+ return out
361
+ }
362
+
363
+ /** The code that turns an island's `children` prop (a JSON tree the compiler lowered, `{ $brust: 'el' | 'fr' | 'cmp' }`)
364
+ * back into React elements. One copy per entry that needs it, shared by the island chunk and the SSR job so both sides
365
+ * build the same tree. `reg` maps a component id to the component. */
366
+ export const reviveSource = (reg: string): string =>
367
+ `const __reg: Record<string, any> = Object.assign(Object.create(null), ${reg})\n` +
368
+ `const __own = Object.prototype.hasOwnProperty\n` +
369
+ // The tree is compiler output, but props travel in page markup: read it as untrusted. A tag must be a plain element
370
+ // name, a component must be in this island's registry (own keys only), and the raw-HTML prop is never revived.
371
+ `const __props = (p: any): any => { const o: any = {}; if (p && typeof p === 'object') for (const k of Object.keys(p)) if (k !== '__proto__' && k !== 'dangerouslySetInnerHTML' && k !== 'children' && k !== 'ref' && k !== 'key') o[k] = p[k]; return o }\n` +
372
+ `const __rv = (n: any): any => {\n` +
373
+ ` if (n === null || typeof n !== 'object') return n\n` +
374
+ ` const kids = Array.isArray(n.c) ? n.c.map(__rv) : []\n` +
375
+ ` if (n.$brust === 'fr') return createElement(Fragment, null, ...kids)\n` +
376
+ ` if (n.$brust === 'el') { if (typeof n.t !== 'string' || !/^[a-zA-Z][a-zA-Z0-9-]*$/.test(n.t)) throw new Error('brust: island children hold an invalid element name'); return createElement(n.t, __props(n.p), ...kids) }\n` +
377
+ ` 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], __props(n.p), ...kids) }\n` +
378
+ ` throw new Error('brust: island children hold an unknown node')\n` +
379
+ `}\n` +
380
+ `const __mk = (C: any, props: any) => { const { children, ...rest } = props; return createElement(C, rest, ...(children === undefined ? [] : Array.isArray(children) ? children : [children]).map(__rv)) }\n`
381
+
382
+ /** A helper component its module does not export (`ir.unexported`: `function SheetOverlay() {…}` rendered by an exported
383
+ * `SheetContent`) that still renders as an island has nothing to import: the module is loaded with `export { Name }`
384
+ * appended, for the island chunks and the SSR jobs alike (one module, one instance, either way). */
385
+ export function exposePlugin(compiled: Map<string, Compiled>): BunPlugin {
386
+ const names = new Map<string, Set<string>>()
387
+ const revived = revivedIds(compiled)
388
+ for (const c of compiled.values()) {
389
+ if (!(isReact(c) || revived.has(c.id)) || !c.ir.unexported || c.ir.external || !c.ir.export) continue
390
+ for (const f of new Set([c.file, realpathSync(c.file)])) names.set(f, (names.get(f) ?? new Set()).add(c.ir.export))
391
+ }
392
+ return {
393
+ name: 'brust-expose-local-islands',
394
+ setup(b) {
395
+ b.onLoad({ filter: /\.[cm]?[jt]sx?$/ }, async (a) => {
396
+ const exposed = names.get(a.path)
397
+ if (!exposed) return undefined
398
+ const loader = /\.[cm]?ts$/.test(a.path) ? 'ts' : /\.[cm]?js$/.test(a.path) ? 'js' : a.path.endsWith('.jsx') ? 'jsx' : 'tsx'
399
+ return { contents: `${await Bun.file(a.path).text()}\nexport { ${[...exposed].join(', ')} }\n`, loader }
400
+ })
401
+ },
402
+ }
289
403
  }
290
404
 
291
405
  /** The island entry of a react-tier component: registers `(host, props) => …` under its id. A
292
406
  * `client_only` component was never server-rendered (its host is empty), so it mounts with
293
407
  * `createRoot`; hydrating it would fail (React #418). Everything else hydrates the SSR markup. */
294
- export function islandShim(c: Compiled): string {
408
+ export function islandShim(c: Compiled, compiled?: Map<string, Compiled>): string {
295
409
  const clientOnly = c.ir.tier?.React?.client_only === true
410
+ const nested = compiled && nestedOf(compiled, c.id)
411
+ const element = nested ? '__mk(Comp, props)' : 'createElement(Comp, props)'
296
412
  const [api, mount] = clientOnly
297
- ? ['createRoot', `createRoot(host, { identifierPrefix: ${JSON.stringify(c.id)} }).render(createElement(Comp, props))`]
298
- : ['hydrateRoot', `hydrateRoot(host, createElement(Comp, props), { identifierPrefix: ${JSON.stringify(c.id)} })`]
413
+ ? ['createRoot', `createRoot(host, { identifierPrefix: ${JSON.stringify(c.id)} }).render(${element})`]
414
+ : ['hydrateRoot', `hydrateRoot(host, ${element}, { identifierPrefix: ${JSON.stringify(c.id)} })`]
415
+ let head = ''
416
+ if (nested && compiled) {
417
+ const comps = nested.map((id) => compiled.get(id)).filter((n): n is Compiled => n !== undefined)
418
+ head =
419
+ `import { Fragment } from 'react'\n` +
420
+ comps.map((n, i) => `${componentImport(n, `N${i}`)}\n`).join('') +
421
+ reviveSource(`{ ${comps.map((n, i) => `${JSON.stringify(n.id)}: N${i}`).join(', ')} }`)
422
+ }
299
423
  return (
300
- `import { ${api} } from 'react-dom/client'\nimport { createElement } from 'react'\n${componentImport(c, 'Comp')}\n` +
424
+ `import { ${api} } from 'react-dom/client'\nimport { createElement } from 'react'\n${componentImport(c, 'Comp')}\n${head}` +
301
425
  `;((globalThis as any).__brustIslands ||= []).push([${JSON.stringify(c.id)}, (host: Element, props: any) => { ${mount} }])\n` +
302
426
  `;(globalThis as any).__brustIslandReady?.()\n`
303
427
  )
@@ -305,12 +429,26 @@ export function islandShim(c: Compiled): string {
305
429
 
306
430
  /** One island chunk per react-tier component (`react-<id>-<hex>.js`, contract 3), React split
307
431
  * into a shared chunk the island chunks import relatively. */
308
- export async function buildReactChunks(dist: string, compiled: Map<string, Compiled>, ctx: BrowserCtx, runtimeUrl: string): Promise<Map<string, string>> {
432
+ /** The react-tier components that get an island entry: all of them, except a package export (S1.4: every member of a
433
+ * package import is one) that no static or native template places as an island. Inside a React component, or as a
434
+ * component an island revives from its lowered children (`nestedOf`, S1 R34.21: those sit in the parent's
435
+ * `ir.children` too), it is an ordinary element of that tree, not an island, and an entry for it only reshuffles the
436
+ * shared chunks (measured: +11-24 KB gzip on a page that never loads it). Placed = a `<brust-island data-id>` marker
437
+ * in the printed template, the one thing the server hydrates. */
438
+ export function islandEntries(compiled: Map<string, Compiled>): Compiled[] {
439
+ const placed = new Set<string>()
440
+ for (const p of compiled.values()) {
441
+ if (isReact(p)) continue
442
+ for (const m of p.jinja.matchAll(/<brust-island\b[^>]*\bdata-id="([^"]+)"/g)) placed.add(m[1]!)
443
+ }
444
+ return [...compiled.values()].filter((c) => isReact(c) && (!c.ir.external || placed.has(c.id)))
445
+ }
446
+
447
+ export async function buildReactChunks(dist: string, compiled: Map<string, Compiled>, ctx: BrowserCtx, runtimeUrl: RuntimeUrls): Promise<Map<string, string>> {
309
448
  const entrypoints: string[] = []
310
- for (const c of compiled.values()) {
311
- if (!isReact(c)) continue
449
+ for (const c of islandEntries(compiled)) {
312
450
  const file = join(dist, '.stage', 'react', `react-${c.id}.tsx`)
313
- write(file, islandShim(c))
451
+ write(file, islandShim(c, compiled))
314
452
  stage(ctx.sourceOf, file, c)
315
453
  entrypoints.push(file)
316
454
  }
@@ -319,7 +457,7 @@ export async function buildReactChunks(dist: string, compiled: Map<string, Compi
319
457
  entrypoints,
320
458
  splitting: true,
321
459
  external: ['/_brust/*'],
322
- plugins: [runtimeAliasPlugin(runtimeUrl), sourceDirPlugin(ctx.sourceOf, ctx.appRoot)],
460
+ plugins: [runtimeAliasPlugin(runtimeUrl), sourceDirPlugin(ctx.sourceOf, ctx.appRoot), exposePlugin(compiled)],
323
461
  })
324
462
  return new Map([...out].map(([stem, path]) => [stem.slice('react-'.length), path]))
325
463
  }
@@ -389,6 +527,15 @@ export async function buildJobs(
389
527
  }
390
528
  imports.push(`import * as S${i} from ${JSON.stringify(resolve(appRoot, p))}`)
391
529
  }
530
+ // Components an island revives from its lowered children (shadcn S1): one registry for every SSR job.
531
+ const reviving = [...compiled.values()].filter((c) => nestedOf(compiled, c.id) !== undefined)
532
+ const revived = [...revivedIds(compiled)].map((id) => compiled.get(id)).filter((x): x is Compiled => x !== undefined)
533
+ if (reviving.length > 0) {
534
+ imports.push("import { Fragment } from 'react'")
535
+ for (const [i, r] of revived.entries()) imports.push(componentImport(r, `N${i}`))
536
+ imports.push(reviveSource(`{ ${revived.map((r, i) => `${JSON.stringify(r.id)}: N${i}`).join(', ')} }`))
537
+ }
538
+ const hosts = new Set(reviving.map((c) => c.id))
392
539
  let n = 0
393
540
  for (const c of compiled.values()) {
394
541
  const fns: string[] = []
@@ -403,7 +550,7 @@ export async function buildJobs(
403
550
  imports.push(componentImport(c, `C${n}`))
404
551
  // Ruling 2bf3775a (R1): the island's component id prefixes React's useId on BOTH sides
405
552
  // (the shim's hydrateRoot passes the same prefix), so ids differ across islands.
406
- fns.push(`ssr: (props: any) => renderToString(createElement(C${n}, props), { identifierPrefix: ${JSON.stringify(c.id)} })`)
553
+ fns.push(`ssr: (props: any) => renderToString(${hosts.has(c.id) ? `__mk(C${n}, props)` : `createElement(C${n}, props)`}, { identifierPrefix: ${JSON.stringify(c.id)} })`)
407
554
  }
408
555
  if (fns.length > 0) entries.push(` ${JSON.stringify(c.id)}: { ${fns.join(', ')} },`)
409
556
  n++
@@ -416,7 +563,7 @@ export async function buildJobs(
416
563
  format: 'esm',
417
564
  define: PRODUCTION,
418
565
  external: JOBS_EXTERNALS,
419
- plugins: [cssPlugin(cssMaps), workerStorePlugin, sourceDirPlugin(sourceOf, appRoot, JOBS_EXTERNALS)],
566
+ plugins: [cssPlugin(cssMaps), workerStorePlugin, sourceDirPlugin(sourceOf, appRoot, JOBS_EXTERNALS), exposePlugin(compiled)],
420
567
  })
421
568
  if (!res.success) throw new BuildError('bundle', `jobs: ${res.logs.map(String).join('\n')}`)
422
569
  write(join(dist, 'jobs.js'), await res.outputs[0]!.text())
@@ -12,7 +12,7 @@ import { type CfConfigJson, cfEntrySource } from './cf-entry'
12
12
  import { type CoreCf, resolveCoreCf } from './cf-core'
13
13
  import { type CacheNeed, mergeWrangler, readUserWrangler, renderWrangler, type UserWrangler, verifyCacheBindings } from './cf-wrangler'
14
14
  import { type CloudflareBuildConfig, CF_MIN_COMPAT_DATE } from './config'
15
- import { PRODUCTION, type SourceOf, sourceDirPlugin } from './bundle'
15
+ import { exposePlugin, PRODUCTION, type SourceOf, sourceDirPlugin } from './bundle'
16
16
  import type { Compiled } from './compile'
17
17
  import { cssPlugin } from './css'
18
18
  import { BuildError } from './errors'
@@ -274,7 +274,7 @@ export async function buildCloudflare(out: string, ctx: CfBuildCtx, p: CfPrepare
274
274
  define: PRODUCTION,
275
275
  minify: false,
276
276
  external: ['node:*', 'cloudflare:*', glueSpec],
277
- plugins: [cssPlugin(ctx.cssMaps ?? new Map()), cfGuard(ctx.appRoot, violations), cfAlias(p.cfg.alias, ctx.sourceOf), cfNativeStub(Bun.resolveSync('@brust/core/server-handlers', ctx.appRoot)), cfStorePlugin(ctx.appRoot), sourceDirPlugin(ctx.sourceOf, ctx.appRoot, ['node:*', 'cloudflare:*'])],
277
+ plugins: [cssPlugin(ctx.cssMaps ?? new Map()), cfGuard(ctx.appRoot, violations), cfAlias(p.cfg.alias, ctx.sourceOf), cfNativeStub(Bun.resolveSync('@brust/core/server-handlers', ctx.appRoot)), cfStorePlugin(ctx.appRoot), sourceDirPlugin(ctx.sourceOf, ctx.appRoot, ['node:*', 'cloudflare:*']), exposePlugin(ctx.compiled)],
278
278
  })
279
279
  if (violations.length > 0) throw new BuildError('cf-unsupported', `${[...new Set(violations)].join('\n')}\nthese modules do not exist on Cloudflare Workers; swap them with [cloudflare] alias`)
280
280
  if (!res.success) throw new BuildError('bundle', `cloudflare: ${res.logs.map(String).join('\n')}`)
@@ -33,7 +33,11 @@ export type ComponentIR = Record<string, any> & {
33
33
  * unresolved (the component falls back). `module` is root-relative (C3). */
34
34
  stores?: { handle: string; resolved: { name: string; module: string } | null }[]
35
35
  /** A package export rendered as a React island (L22): `source` is then not a file. */
36
- external?: { source: string; export: string }
36
+ external?: { source: string; export: string; member?: string[] }
37
+ /** The binding a React island imports this component by from `source` (absent: the default export). */
38
+ export?: string
39
+ /** Child components; `nested` is set when this file passes lowered JSX children to that child, an island (shadcn S1). */
40
+ children?: { id: string | null; nested?: string[]; [field: string]: unknown }[]
37
41
  }
38
42
 
39
43
  export interface Compiled {
package/src/build/css.ts CHANGED
@@ -14,6 +14,7 @@ import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'nod
14
14
  import type { BunPlugin } from 'bun'
15
15
  import type { FlatRoute } from '../routes'
16
16
  import { BuildError } from './errors'
17
+ import { loadTailwind } from './tailwind'
17
18
 
18
19
  const hex = (b: string | Uint8Array) => createHash('sha256').update(b).digest('hex').slice(0, 10)
19
20
  const real = (p: string) => {
@@ -124,7 +125,15 @@ export async function buildCss(
124
125
  const tw = tailwindUse(sources)
125
126
  const plugins: BunPlugin[] = []
126
127
  if (tw.using.length > 0) {
127
- plugins.push(await loadTailwind(appRoot, tw.using[0]!))
128
+ // a stylesheet compiles with Tailwind when it, or a relative @import of it, uses Tailwind
129
+ const via = new Map<string, boolean>()
130
+ const uses = (f: string) => {
131
+ const k = real(f)
132
+ let hit = via.get(k)
133
+ if (hit === undefined) via.set(k, (hit = tailwindUse([k]).using.length > 0))
134
+ return hit
135
+ }
136
+ plugins.push(await loadTailwind(appRoot, tw.using[0]!, uses, o.log))
128
137
  if (tw.imports.length > 1)
129
138
  o.log?.(
130
139
  `[brust] warning tailwind @import "tailwindcss" is in ${tw.imports.length} files (${tw.imports.map((f) => relative(appRoot, f)).join(', ')}): each one ships the whole of Tailwind; import it once (e.g. app.css) and use @reference elsewhere`,
@@ -144,7 +153,6 @@ export async function buildCss(
144
153
  minify,
145
154
  naming: { entry: '[name]-[hash].[ext]', chunk: '[name]-[hash].[ext]', asset: '[name]-[hash].[ext]' },
146
155
  external: ['/public/*', '/_brust/*'],
147
- // L21: Tailwind's content detection scans the app (bun-plugin-tailwind reads `root`).
148
156
  root: appRoot,
149
157
  plugins,
150
158
  })
@@ -239,25 +247,6 @@ export function tailwindUse(sources: string[]): { using: string[]; imports: stri
239
247
  return { using, imports }
240
248
  }
241
249
 
242
- /** `bun-plugin-tailwind`, resolved from the app (R21.1: `tailwindcss@4` and the plugin are the app's own dev
243
- * dependencies). Missing → `tailwind-missing` with the exact install command. */
244
- export async function loadTailwind(appRoot: string, usedBy: string): Promise<BunPlugin> {
245
- const missing = ['tailwindcss', 'bun-plugin-tailwind'].filter((p) => {
246
- try {
247
- Bun.resolveSync(`${p}/package.json`, appRoot)
248
- return false
249
- } catch {
250
- return true
251
- }
252
- })
253
- if (missing.length > 0)
254
- throw new BuildError(
255
- 'tailwind-missing',
256
- `${relative(appRoot, usedBy)} uses Tailwind CSS, but ${missing.join(' and ')} ${missing.length > 1 ? 'are' : 'is'} not installed in the app: run \`bun add -d tailwindcss@4 bun-plugin-tailwind\``,
257
- )
258
- return (await import(Bun.resolveSync('bun-plugin-tailwind', appRoot))).default as BunPlugin
259
- }
260
-
261
250
  /** R19.4: the one CSS plugin of every JS build. A `.module.css` import is its class map
262
251
  * (`export default Object.freeze({…})`); any other `.css` import is an empty module, because the
263
252
  * stylesheet itself is linked by the server (R19.3), never bundled into JS. */
@@ -0,0 +1,73 @@
1
+ // Which client-runtime feature modules a component needs (L33, R35.2). The compiler's output is the source of truth:
2
+ // a native component's template carries one `x-*` attribute per directive it uses, a react-tier component is an island.
3
+ // The set is written per component into the manifest; the server unions it over a route's components and links the
4
+ // core plus exactly those modules. `packages/runtime-dom/README.md` ("Feature modules") owns the module list and the rule.
5
+ import { BuildError } from './errors'
6
+
7
+ /** Feature modules of `@brust/runtime-dom/features/*` the browser build ships, in load order. */
8
+ export const RUNTIME_FEATURES = ['basics', 'if', 'for', 'model', 'html', 'island'] as const
9
+ export type RuntimeFeature = (typeof RUNTIME_FEATURES)[number]
10
+
11
+ /** Directive attribute → the module that binds it. `null`: handled by the core (host, props, inert-markup marker). */
12
+ export function featureOfAttr(attr: string): RuntimeFeature | null | undefined {
13
+ switch (attr) {
14
+ case 'x-data':
15
+ case 'x-props':
16
+ case 'x-props-bind':
17
+ case 'x-raw':
18
+ return null
19
+ case 'x-text':
20
+ case 'x-show':
21
+ case 'x-ref':
22
+ return 'basics'
23
+ case 'x-if':
24
+ case 'x-for':
25
+ case 'x-model':
26
+ case 'x-html':
27
+ return attr.slice(2) as RuntimeFeature
28
+ default:
29
+ return /^x-(bind|on)-/.test(attr) ? 'basics' : undefined
30
+ }
31
+ }
32
+
33
+ /** The `x-*` attribute names on the elements of a template (tags only: prose that mentions `x-for` binds nothing). */
34
+ export function directiveAttrs(template: string): Set<string> {
35
+ const out = new Set<string>()
36
+ for (const tag of template.matchAll(/<[a-zA-Z][\w-]*((?:[^>"']|"[^"]*"|'[^']*')*)>/g))
37
+ for (const a of tag[1]!.matchAll(/(?:^|\s)(x-[a-z][a-z0-9-]*)(?==|\s|$|\/)/g)) out.add(a[1]!)
38
+ return out
39
+ }
40
+
41
+ /**
42
+ * The feature modules `template` needs, sorted in load order (`react` = the component is an island: `island`).
43
+ * An `x-*` attribute no module binds is a build error (a compiler that learned a directive before the runtime did):
44
+ * never a silent no-op in the browser.
45
+ */
46
+ export function featuresOf(id: string, template: string, react: boolean): RuntimeFeature[] {
47
+ const need = new Set<RuntimeFeature>()
48
+ if (react) need.add('island')
49
+ for (const attr of directiveAttrs(template)) {
50
+ const f = featureOfAttr(attr)
51
+ if (f === undefined) throw new BuildError('runtime-feature-missing', `${id}: the template uses ${attr}, which no client runtime feature binds`)
52
+ if (f !== null) need.add(f)
53
+ }
54
+ return RUNTIME_FEATURES.filter((f) => need.has(f))
55
+ }
56
+
57
+ /** Matches the `/_brust/<file>` URL of `file` in a built chunk's text. */
58
+ const mentions = (text: string, file: string) => text.includes(`/_brust/${file}`)
59
+
60
+ /**
61
+ * Whether the built client file `entry` (`client/<file>`) imports the store module `storeFile`, directly or through the
62
+ * shared `chunk-*.js` files it imports. A component whose chunk does gets `store` in its features: the page preloads
63
+ * the module (the chunk imports it itself, so it has no script tag).
64
+ */
65
+ export function importsStore(read: (rel: string) => string | undefined, entry: string, storeFile: string, seen = new Set<string>()): boolean {
66
+ if (seen.has(entry)) return false
67
+ seen.add(entry)
68
+ const text = read(entry)
69
+ if (text === undefined) return false
70
+ if (mentions(text, storeFile)) return true
71
+ for (const m of text.matchAll(/(?:from|import)\s*"\.\/([^"]+\.js)"/g)) if (importsStore(read, `client/${m[1]}`, storeFile, seen)) return true
72
+ return false
73
+ }
@@ -17,6 +17,7 @@ import { type Compiled, compileApp } from './compile'
17
17
  import { buildCss, CssGraph, directCss, resolveGlobals, routeCssSources } from './css'
18
18
  import { type ActionsBuildConfig, type CacheBuildConfig, loadBuildConfig } from './config'
19
19
  import { BuildError } from './errors'
20
+ import { importsStore } from './features'
20
21
  import { type CacheRecord, type ManifestJson, tierOf, writeManifest } from './manifest'
21
22
  import { scanRoutes } from './scan'
22
23
  import { type ExprReads, prepareStatic, writeStatic } from './static'
@@ -235,12 +236,13 @@ async function buildInto(
235
236
  const ctx: BrowserCtx = { sourceOf: new Map(), appRoot, serverOnly: o.serverOnly, serverFiles: o.actionsEntry ? [realpathSync(o.actionsEntry)] : [], cssMaps: css.maps }
236
237
  // The runtime first: its hashed URL is the `runtimeImport` every client chunk is compiled with.
237
238
  const runtime = await buildRuntime(out, ctx)
239
+ const runtimeUrls = { core: `/_brust/${runtime.core}`, store: `/_brust/${runtime.store}` }
238
240
  const compileOpts = {
239
241
  appRoot,
240
242
  leaves,
241
243
  componentFile: o.componentFile,
242
244
  componentIssue: o.componentIssue,
243
- runtimeImport: `/_brust/${runtime}`,
245
+ runtimeImport: runtimeUrls.core,
244
246
  serverOnly: o.serverOnly,
245
247
  cssMaps: css.maps,
246
248
  }
@@ -262,9 +264,11 @@ async function buildInto(
262
264
  mkdirSync(join(out, 'jinja'), { recursive: true })
263
265
  for (const c of compiled.values()) writeFileSync(join(out, 'jinja', `${c.id}.jinja`), c.jinja)
264
266
 
265
- const runtimeUrl = `/_brust/${runtime}`
266
- const chunks = new Map([...(await buildClientChunks(out, compiled, ctx, runtimeUrl)), ...(await buildReactChunks(out, compiled, ctx, runtimeUrl))])
267
- const manifest = writeManifest({ leaves, routeComponent, compiled, runtime, chunks })
267
+ const chunks = new Map([...(await buildClientChunks(out, compiled, ctx, runtimeUrls)), ...(await buildReactChunks(out, compiled, ctx, runtimeUrls))])
268
+ const manifest = writeManifest({ leaves, routeComponent, compiled, runtime: { core: runtime.core, features: { ...runtime.features, store: runtime.store } }, chunks })
269
+ // L33: a component whose chunk imports the store module (directly or through a shared chunk) has the page preload it.
270
+ const readClient = (rel: string) => (existsSync(join(out, rel)) ? readFileSync(join(out, rel), 'utf8') : undefined)
271
+ for (const rec of Object.values(manifest.components)) if (rec.client && importsStore(readClient, rec.client, runtime.store)) rec.features.push('store')
268
272
  for (const r of manifest.routes) {
269
273
  const files = [...new Set((routeCss.get(r.id) ?? []).flatMap((s) => (css.file.has(s) ? [css.file.get(s)!] : [])))]
270
274
  if (files.length > 0) r.css = files
@@ -6,6 +6,7 @@
6
6
  import type { FlatRoute } from '../routes'
7
7
  import type { Compiled, ComponentIR } from './compile'
8
8
  import { BuildError } from './errors'
9
+ import { featuresOf } from './features'
9
10
 
10
11
  export interface JobCache {
11
12
  key: string | null
@@ -44,6 +45,8 @@ export interface ComponentRecord {
44
45
  needs_worker: boolean
45
46
  use_id_slots: number
46
47
  stores: string[]
48
+ /** L33: the client runtime feature modules (`assets.features` keys) this component's output needs, in load order. */
49
+ features: string[]
47
50
  }
48
51
 
49
52
  export interface RouteRecord {
@@ -73,7 +76,8 @@ export interface ManifestJson {
73
76
  version: typeof MANIFEST_VERSION
74
77
  routes: RouteRecord[]
75
78
  components: Record<string, ComponentRecord>
76
- assets: { runtime: string }
79
+ /** `runtime` is the core; `features` maps each feature module name to its file (L33). */
80
+ assets: { runtime: string; features: Record<string, string> }
77
81
  jobs_module: string
78
82
  actions: ActionsRecord | null
79
83
  /** L16 R16.3: an actions-only build (no routes, no templates); everything but the prefix is a 404 problem+json. */
@@ -280,7 +284,8 @@ export function writeManifest(opts: {
280
284
  leaves: FlatRoute[]
281
285
  routeComponent: Map<string, string>
282
286
  compiled: Map<string, Compiled>
283
- runtime: string
287
+ /** The runtime files `buildRuntime` wrote: the core and the feature modules. */
288
+ runtime: { core: string; features: Record<string, string> }
284
289
  /** component id → `client/<file>` (client chunk or react island chunk). */
285
290
  chunks: Map<string, string>
286
291
  actions?: ActionsRecord | null
@@ -299,7 +304,10 @@ export function writeManifest(opts: {
299
304
  needs_worker: jobs.length > 0,
300
305
  use_id_slots: c.ir.use_id_slots ?? 0,
301
306
  stores: storesOf(compiled, c.id),
307
+ features: featuresOf(c.id, c.jinja, tierOf(c.ir) === 'react'),
302
308
  }
309
+ for (const f of components[c.id]!.features)
310
+ if (!(f in opts.runtime.features)) throw new BuildError('runtime-feature-missing', `${c.id}: needs the client runtime feature ${f}, which the build did not ship`)
303
311
  }
304
312
  const routes: RouteRecord[] = opts.leaves.map((l) => {
305
313
  // A node without a Component (a pure path/loader group) renders nothing: not a chain entry.
@@ -321,7 +329,7 @@ export function writeManifest(opts: {
321
329
  }
322
330
  })
323
331
  linkNativeChunks(routes, compiled, components)
324
- return { version: MANIFEST_VERSION, routes, components, assets: { runtime: opts.runtime }, jobs_module: 'jobs.js', actions: opts.actions ?? null }
332
+ return { version: MANIFEST_VERSION, routes, components, assets: { runtime: opts.runtime.core, features: opts.runtime.features }, jobs_module: 'jobs.js', actions: opts.actions ?? null }
325
333
  }
326
334
 
327
335
  /** S6 amendment (F66): the server's asset injection walks only each chain component's direct
@@ -0,0 +1,117 @@
1
+ // Tailwind CSS v4 for `brust build` (L32, F135, R33.1-R33.4): brust's own Bun plugin over the app's Tailwind.
2
+ // It does what the official integrations (@tailwindcss/vite, @tailwindcss/postcss) do: `compile()` from
3
+ // `@tailwindcss/node`, a `Scanner` from `@tailwindcss/oxide` over the compiler's sources (the app root unless the
4
+ // stylesheet says `source(...)`, plus every `@source` / `@source not`), then `build(candidates)`. Both packages are
5
+ // resolved from the APP, never bundled into or depended on by brust, so the compiler is the app's pinned
6
+ // `tailwindcss` (`@tailwindcss/node` depends on its own exact `tailwindcss`; the app installs all three at one
7
+ // version, and a mismatch is a loud warning with the command that aligns them).
8
+ import { readFileSync } from 'node:fs'
9
+ import { dirname, relative } from 'node:path'
10
+ import type { BunPlugin } from 'bun'
11
+ import { BuildError } from './errors'
12
+
13
+ /** The install set (R33.2): one exact version for all three. */
14
+ export const TAILWIND_PACKAGES = ['tailwindcss', '@tailwindcss/node', '@tailwindcss/oxide'] as const
15
+
16
+ interface SourceEntry {
17
+ base: string
18
+ pattern: string
19
+ negated: boolean
20
+ }
21
+ interface Compiler {
22
+ root: 'none' | { base: string; pattern: string } | null
23
+ sources: SourceEntry[]
24
+ build(candidates: string[]): string
25
+ }
26
+ interface TailwindNode {
27
+ compile(css: string, o: { base: string; from?: string; shouldRewriteUrls?: boolean; onDependency: (path: string) => void }): Promise<Compiler>
28
+ }
29
+ interface TailwindOxide {
30
+ Scanner: new (o: { sources: SourceEntry[] }) => { scan(): string[] }
31
+ }
32
+
33
+ /** The `version` of `pkg` as resolved from `from` (a directory), or undefined when it does not resolve. */
34
+ function versionFrom(pkg: string, from: string): string | undefined {
35
+ try {
36
+ return (JSON.parse(readFileSync(Bun.resolveSync(`${pkg}/package.json`, from), 'utf8')) as { version?: string }).version
37
+ } catch {
38
+ return undefined
39
+ }
40
+ }
41
+
42
+ /** The versions that decide what compiles (R33.3): the app's `tailwindcss`, the `tailwindcss` that
43
+ * `@tailwindcss/node` imports (the compiler), and the two integration packages. */
44
+ export function tailwindVersions(appRoot: string): { app?: string; compiler?: string; node?: string; oxide?: string } {
45
+ let compiler: string | undefined
46
+ try {
47
+ compiler = versionFrom('tailwindcss', dirname(Bun.resolveSync('@tailwindcss/node/package.json', appRoot)))
48
+ } catch {}
49
+ return { app: versionFrom('tailwindcss', appRoot), compiler, node: versionFrom('@tailwindcss/node', appRoot), oxide: versionFrom('@tailwindcss/oxide', appRoot) }
50
+ }
51
+
52
+ /** The oldest Tailwind this plugin runs (review F1): 4.0's `compile()` has no `sources` (it takes globs), so its build
53
+ * would crash mid-way; 4.1.0 is the first with the API the official integrations use today. */
54
+ export const TAILWIND_FLOOR = '4.1.0'
55
+ /** The version brust is tested with (create-app pins the same); the command that lifts an app off an old Tailwind names it. */
56
+ export const TAILWIND_TESTED = '4.3.3'
57
+
58
+ /** `a < b` for plain `major.minor.patch` versions (a pre-release suffix counts as its base version). */
59
+ export function versionBelow(a: string, b: string): boolean {
60
+ const n = (v: string) => v.split('-')[0]!.split('.').map((x) => Number(x) || 0)
61
+ const [x, y] = [n(a), n(b)]
62
+ for (let i = 0; i < 3; i++) if ((x[i] ?? 0) !== (y[i] ?? 0)) return (x[i] ?? 0) < (y[i] ?? 0)
63
+ return false
64
+ }
65
+
66
+ const addCommand = (v: string) => `bun add -d --exact ${TAILWIND_PACKAGES.map((p) => `${p}@${v}`).join(' ')}`
67
+
68
+ /** The Tailwind plugin of the CSS build, resolved from the app. Missing packages → `tailwind-missing` with the
69
+ * exact install command; versions that differ → one warning through `log` with the command that aligns them.
70
+ * `uses(file)` says whether a stylesheet needs the compiler (it, or a relative `@import` of it, uses Tailwind);
71
+ * other stylesheets stay Bun's. */
72
+ export async function loadTailwind(appRoot: string, usedBy: string, uses: (file: string) => boolean, log?: (s: string) => void): Promise<BunPlugin> {
73
+ const v = tailwindVersions(appRoot)
74
+ const missing = TAILWIND_PACKAGES.filter((p) => versionFrom(p, appRoot) === undefined)
75
+ if (missing.length > 0)
76
+ throw new BuildError(
77
+ 'tailwind-missing',
78
+ `${relative(appRoot, usedBy)} uses Tailwind CSS, but ${missing.join(', ')} ${missing.length > 1 ? 'are' : 'is'} not installed in the app: run \`${v.app ? addCommand(v.app) : `bun add -d ${TAILWIND_PACKAGES.map((p) => `${p}@4`).join(' ')}`}\``,
79
+ )
80
+ const old = (
81
+ [
82
+ ['tailwindcss', v.app],
83
+ ['the compiler tailwindcss', v.compiler],
84
+ ['@tailwindcss/node', v.node],
85
+ ['@tailwindcss/oxide', v.oxide],
86
+ ] as const
87
+ ).filter(([, ver]) => ver !== undefined && versionBelow(ver, TAILWIND_FLOOR))
88
+ if (old.length > 0)
89
+ throw new BuildError(
90
+ 'tailwind-version',
91
+ `${relative(appRoot, usedBy)} uses Tailwind CSS, but ${old.map(([p, ver]) => `${p} ${ver}`).join(', ')} ${old.length > 1 ? 'are' : 'is'} older than ${TAILWIND_FLOOR}, the oldest brust builds with: run \`${addCommand(TAILWIND_TESTED)}\``,
92
+ )
93
+ if (new Set([v.app, v.compiler, v.node, v.oxide]).size > 1)
94
+ log?.(
95
+ `[brust] warning tailwind-version the app has tailwindcss ${v.app}, but the compiler is tailwindcss ${v.compiler} (@tailwindcss/node ${v.node}, @tailwindcss/oxide ${v.oxide}): install one version of all three: ${addCommand(v.app!)}`,
96
+ )
97
+ const node = (await import(Bun.resolveSync('@tailwindcss/node', appRoot))) as TailwindNode
98
+ const oxide = (await import(Bun.resolveSync('@tailwindcss/oxide', appRoot))) as TailwindOxide
99
+ return {
100
+ name: 'brust-tailwind',
101
+ setup(b) {
102
+ b.onLoad({ filter: /\.css$/ }, async (a) => {
103
+ if (!uses(a.path)) return undefined // Bun's own loader (CSS Modules included)
104
+ const css = readFileSync(a.path, 'utf8')
105
+ const compiler = await node.compile(css, { base: dirname(a.path), from: a.path, shouldRewriteUrls: true, onDependency: () => {} })
106
+ const root: SourceEntry[] =
107
+ compiler.root === 'none' ? [] : compiler.root === null ? [{ base: appRoot, pattern: '**/*', negated: false }] : [{ ...compiler.root, negated: false }]
108
+ const scanner = new oxide.Scanner({ sources: [...root, ...compiler.sources] })
109
+ let out = compiler.build(scanner.scan())
110
+ // `@reference "./app.css"` pulls in Tailwind's license banner too; only the file that imports Tailwind ships it
111
+ // (one banner per page, as before)
112
+ if (!/@import\s+(?:url\(\s*)?["']tailwindcss["']/.test(css)) out = out.replace(/\/\*! tailwindcss v[^*]*\*\/\s*/g, '')
113
+ return { contents: out, loader: 'css' }
114
+ })
115
+ },
116
+ }
117
+ }