@brust/core 2.0.0-alpha.10 → 2.0.0-alpha.11

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.10' && 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.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
92
+ if (bindingPackageVersion !== '2.0.0-alpha.11' && 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.11 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.10' && 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.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
108
+ if (bindingPackageVersion !== '2.0.0-alpha.11' && 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.11 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.10' && 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.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
129
+ if (bindingPackageVersion !== '2.0.0-alpha.11' && 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.11 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.10' && 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.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
145
+ if (bindingPackageVersion !== '2.0.0-alpha.11' && 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.11 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.10' && 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.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
162
+ if (bindingPackageVersion !== '2.0.0-alpha.11' && 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.11 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.10' && 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.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
178
+ if (bindingPackageVersion !== '2.0.0-alpha.11' && 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.11 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.10' && 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.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
197
+ if (bindingPackageVersion !== '2.0.0-alpha.11' && 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.11 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.10' && 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.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
213
+ if (bindingPackageVersion !== '2.0.0-alpha.11' && 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.11 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.10' && 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.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
229
+ if (bindingPackageVersion !== '2.0.0-alpha.11' && 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.11 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.10' && 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.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
249
+ if (bindingPackageVersion !== '2.0.0-alpha.11' && 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.11 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.10' && 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.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
265
+ if (bindingPackageVersion !== '2.0.0-alpha.11' && 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.11 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.10' && 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.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
286
+ if (bindingPackageVersion !== '2.0.0-alpha.11' && 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.11 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.10' && 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.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
302
+ if (bindingPackageVersion !== '2.0.0-alpha.11' && 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.11 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.10' && 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.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
320
+ if (bindingPackageVersion !== '2.0.0-alpha.11' && 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.11 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.10' && 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.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
336
+ if (bindingPackageVersion !== '2.0.0-alpha.11' && 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.11 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.10' && 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.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
354
+ if (bindingPackageVersion !== '2.0.0-alpha.11' && 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.11 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.10' && 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.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
370
+ if (bindingPackageVersion !== '2.0.0-alpha.11' && 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.11 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.10' && 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.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
388
+ if (bindingPackageVersion !== '2.0.0-alpha.11' && 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.11 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.10' && 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.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
404
+ if (bindingPackageVersion !== '2.0.0-alpha.11' && 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.11 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.10' && 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.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
422
+ if (bindingPackageVersion !== '2.0.0-alpha.11' && 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.11 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.10' && 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.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
438
+ if (bindingPackageVersion !== '2.0.0-alpha.11' && 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.11 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.10' && 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.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
455
+ if (bindingPackageVersion !== '2.0.0-alpha.11' && 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.11 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.10' && 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.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
471
+ if (bindingPackageVersion !== '2.0.0-alpha.11' && 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.11 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.10' && 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.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
491
+ if (bindingPackageVersion !== '2.0.0-alpha.11' && 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.11 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.10' && 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.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
507
+ if (bindingPackageVersion !== '2.0.0-alpha.11' && 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.11 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.10' && 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.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
523
+ if (bindingPackageVersion !== '2.0.0-alpha.11' && 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.11 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.10') {
665
- throw new Error(`WASI binding package version mismatch, expected 2.0.0-alpha.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
664
+ if (bindingPackageVersion !== '2.0.0-alpha.11') {
665
+ throw new Error(`WASI binding package version mismatch, expected 2.0.0-alpha.11 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.10",
3
+ "version": "2.0.0-alpha.11",
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.10"
58
+ "@brust/runtime-dom": "2.0.0-alpha.11"
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.10",
97
- "@brust/native-darwin-arm64": "2.0.0-alpha.10",
98
- "@brust/native-linux-x64-gnu": "2.0.0-alpha.10",
99
- "@brust/native-linux-arm64-gnu": "2.0.0-alpha.10",
100
- "@brust/native-linux-x64-musl": "2.0.0-alpha.10",
101
- "@brust/native-linux-arm64-musl": "2.0.0-alpha.10",
102
- "@brust/core-cf": "2.0.0-alpha.10"
96
+ "@brust/native-darwin-x64": "2.0.0-alpha.11",
97
+ "@brust/native-darwin-arm64": "2.0.0-alpha.11",
98
+ "@brust/native-linux-x64-gnu": "2.0.0-alpha.11",
99
+ "@brust/native-linux-arm64-gnu": "2.0.0-alpha.11",
100
+ "@brust/native-linux-x64-musl": "2.0.0-alpha.11",
101
+ "@brust/native-linux-arm64-musl": "2.0.0-alpha.11",
102
+ "@brust/core-cf": "2.0.0-alpha.11"
103
103
  }
104
104
  }
@@ -12,7 +12,7 @@
12
12
  import { realpathSync } from 'node:fs'
13
13
  import { join } from 'node:path'
14
14
  import type { BunPlugin } from 'bun'
15
- import { type SourceOf, PRODUCTION, sourceDirPlugin, stage, write } from './bundle'
15
+ import { jobImportPlugin, type SourceOf, PRODUCTION, sourceDirPlugin, stage, write } from './bundle'
16
16
  import type { Compiled } from './compile'
17
17
  import { BuildError } from './errors'
18
18
  import { serverOnlyEmptyPlugin } from './server-only'
@@ -247,27 +247,38 @@ async function evaluateInstances(
247
247
  const modules = new Map<string, string>()
248
248
  const stubs = new Map<string, Map<string, string>>()
249
249
  const imports: string[] = []
250
+ /** Component id -> its staged job module; written once, with the stubs its own imports are served by. */
251
+ const staged = new Map<string, string>()
252
+ const stageJob = (c: Compiled, served: { source: string; code: string }[]) => {
253
+ if (staged.has(c.id)) return
254
+ const file = join(dist, '.stage', 'eval', `${c.id}.job.ts`)
255
+ write(file, c.serverTs!)
256
+ stage(sourceOf, file, c)
257
+ const map = new Map<string, string>()
258
+ for (const [i, st] of served.entries()) {
259
+ const stub = join(dist, '.stage', 'eval', 'stubs', c.id, `${i}.ts`)
260
+ write(stub, st.code)
261
+ stage(sourceOf, stub, c)
262
+ map.set(st.source, stub)
263
+ }
264
+ if (map.size > 0) {
265
+ stubs.set(file, map)
266
+ stubs.set(realpathSync(file), map)
267
+ }
268
+ staged.set(c.id, file)
269
+ }
250
270
  for (const c of compiled.values()) {
251
271
  for (const inst of c.ir.build_eval_instances ?? []) {
252
272
  const child = compiled.get(inst.child_id)
253
273
  if (child?.serverTs === undefined) continue
274
+ // R34.96 (A1): the job modules fused into this child's job, which it imports through `brust-job:<id>`.
275
+ const fused = (inst.fused ?? []).map((f) => ({ f, c: compiled.get(f.child_id) }))
276
+ if (fused.some(({ c }) => c?.serverTs === undefined)) continue
277
+ for (const { f, c } of fused) stageJob(c!, f.stubs ?? [])
254
278
  if (!modules.has(child.id)) {
255
- const file = join(dist, '.stage', 'eval', `${child.id}.job.ts`)
256
- write(file, child.serverTs)
257
- stage(sourceOf, file, child)
258
- const served = new Map<string, string>()
259
- for (const [i, st] of (inst.stubs ?? []).entries()) {
260
- const stub = join(dist, '.stage', 'eval', 'stubs', child.id, `${i}.ts`)
261
- write(stub, st.code)
262
- stage(sourceOf, stub, child)
263
- served.set(st.source, stub)
264
- }
265
- if (served.size > 0) {
266
- stubs.set(file, served)
267
- stubs.set(realpathSync(file), served)
268
- }
279
+ stageJob(child, inst.stubs ?? [])
269
280
  modules.set(child.id, `j${modules.size}`)
270
- imports.push(`import { precompute as ${modules.get(child.id)} } from ${JSON.stringify(file)}`)
281
+ imports.push(`import { precompute as ${modules.get(child.id)} } from ${JSON.stringify(staged.get(child.id))}`)
271
282
  }
272
283
  const id = `${inst.child_id}\0${JSON.stringify(inst.inputs)}`
273
284
  const where = `${c.file.slice(appRoot.length + 1)}:${inst.line}:${inst.col}`
@@ -285,7 +296,7 @@ async function evaluateInstances(
285
296
  target: 'bun',
286
297
  format: 'esm',
287
298
  define: PRODUCTION,
288
- plugins: [stubPlugin(stubs), sourceDirPlugin(sourceOf, appRoot)],
299
+ plugins: [jobImportPlugin((id) => staged.get(id)), stubPlugin(stubs), sourceDirPlugin(sourceOf, appRoot)],
289
300
  })
290
301
  if (!res.success) {
291
302
  log(`warning build-eval the instance jobs could not be bundled for build evaluation, they stay per-request jobs: ${res.logs.map(String).join(' | ').split('\n')[0]}`)
@@ -383,9 +383,31 @@ export function nestedOf(compiled: Map<string, Compiled>, id: string, routeRoots
383
383
  }
384
384
  }
385
385
  }
386
+ // F148a (R34.121): a wrapper whose island renders `{children}` (a `$c` hole) is handed a tree by each call site; the
387
+ // components those trees name are revived by the island inside the wrapper, so its chunk and job import them.
388
+ for (const w of compiled.values()) {
389
+ if (!(w.ir.children ?? []).some((r) => r.id === id && (r.holes ?? []).some((h) => h.startsWith('$c')))) continue
390
+ for (const c of compiled.values()) {
391
+ for (const ref of c.ir.children ?? []) {
392
+ if (ref.id === w.id && ref.nested) {
393
+ out ??= new Set()
394
+ for (const n of ref.nested) out.add(n)
395
+ }
396
+ }
397
+ }
398
+ }
386
399
  return out && [...out].sort()
387
400
  }
388
401
 
402
+ /** F148a (R34.120): the island props the compiler wrote for the values its children read from props (`$p<N>`: a
403
+ * primitive, `$c<N>`: a tree a wrapper's call site bound), at any call site of the island `id`. The only `$` keys,
404
+ * besides `$x`, its revive accepts. */
405
+ export function holesOf(compiled: Map<string, Compiled>, id: string): string[] {
406
+ const out = new Set<string>()
407
+ for (const c of compiled.values()) for (const ref of c.ir.children ?? []) if (ref.id === id) for (const k of ref.holes ?? []) out.add(k)
408
+ return [...out].sort()
409
+ }
410
+
389
411
  /** F158 (R34.71): the element-prop names (`$x`) the compiler wrote at any call site of the island `id`: the only names
390
412
  * its revive may revive. */
391
413
  export function xOf(compiled: Map<string, Compiled>, id: string): string[] {
@@ -409,25 +431,43 @@ export const reviveSource = (reg: string): string =>
409
431
  `const __own = Object.prototype.hasOwnProperty\n` +
410
432
  // The tree is compiler output, but props travel in page markup: read it as untrusted. A tag must be a plain element
411
433
  // name, a component must be in this island's registry (own keys only), and the raw-HTML prop is never revived.
412
- `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` +
434
+ // `hv` holds the island's hole values (F148a, R34.116): the props the compiler declared (`$p<N>` primitives, `$c<N>`
435
+ // trees). A value node reads one and renders it only when it is a string or a finite number (an attribute: also a boolean; text: also an array of them);
436
+ // anything else renders nothing, and is never walked, so request data can fill a leaf but never shape the tree.
437
+ `const __hole = (hv: any, k: any): any => hv == null || typeof k !== 'string' || !/^[$]p[0-9]+$/.test(k) || !__own.call(hv, k) ? undefined : hv[k]\n` +
438
+ `const __prim = (hv: any, k: any, bool: boolean): any => { const x = __hole(hv, k); return typeof x === 'string' || (typeof x === 'number' && Number.isFinite(x)) || (bool && typeof x === 'boolean') ? x : undefined }\n` +
439
+ `const __props = (p: any, hv: 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') { const v = p[k]; if (v !== null && typeof v === 'object' && v.$brust === 'v') { const x = __prim(hv, v.k, true); if (x !== undefined) o[k] = x } else o[k] = v } return o }\n` +
413
440
  // `x` (on a component node) and `$x` (on the island's props) are the compiler's list of props that hold an element
414
441
  // tree. Only those names are revived, and only when the prop is an own key of the copy; data is never revived.
415
- `const __xs = (o: any, x: any): any => { if (Array.isArray(x)) for (const k of x) if (typeof k === 'string' && k.charAt(0) !== '$' && __own.call(o, k)) o[k] = __rv(o[k]); return o }\n` +
416
- `const __rv = (n: any): any => {\n` +
442
+ `const __xs = (o: any, x: any, hv: any): any => { if (Array.isArray(x)) for (const k of x) if (typeof k === 'string' && k.charAt(0) !== '$' && __own.call(o, k)) o[k] = __rv(o[k], hv); return o }\n` +
443
+ `const __kids = (c: any, hv: any): any[] => Array.isArray(c) ? c.map((k: any) => __rv(k, hv)) : []\n` +
444
+ `const __rv = (n: any, hv: any): any => {\n` +
417
445
  ` if (n === null || typeof n !== 'object') return n\n` +
418
- ` const kids = Array.isArray(n.c) ? n.c.map(__rv) : []\n` +
446
+ // A text leaf is a string or a finite number; an array of them (React renders each) keeps those items. Anything else
447
+ // renders nothing and is never walked.
448
+ ` if (n.$brust === 'v') { const x = __hole(hv, n.k); if (Array.isArray(x)) return createElement(Fragment, null, ...x.filter((e: any) => typeof e === 'string' || (typeof e === 'number' && Number.isFinite(e)))); const p = __prim(hv, n.k, false); return p === undefined ? null : p }\n` +
449
+ // A condition is the truthiness of the declared own hole, as in React, without reading into the value. `a` is the
450
+ // `cond && <X/>` form: React renders a falsy number there (0) as text.
451
+ ` if (n.$brust === 'if') { const x = __hole(hv, n.k); return createElement(Fragment, null, ...(!x && n.a === true && typeof x === 'number' ? [x] : __kids(x ? n.c : n.e, hv))) }\n` +
452
+ // The caller's tree: compile-time, bound by the wrapper's call site. It holds no hole of its own, so it is revived
453
+ // with none (a tree that named one would render nothing, and cannot recurse).
454
+ ` if (n.$brust === 'slot') return typeof n.k === 'string' && /^[$]c[0-9]+$/.test(n.k) && hv != null && __own.call(hv, n.k) ? __rv(hv[n.k], null) : null\n` +
455
+ ` const kids = __kids(n.c, hv)\n` +
419
456
  ` if (n.$brust === 'fr') return createElement(Fragment, null, ...kids)\n` +
420
- ` 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` +
421
- ` 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` +
457
+ ` 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, hv), ...kids) }\n` +
458
+ ` 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, hv), n.x, hv), ...kids) }\n` +
422
459
  ` throw new Error('brust: island children hold an unknown node')\n` +
423
460
  `}\n` +
424
461
  // `X` is the host's compiler-declared element-prop names (R34.71): a `$x` from the props can only select among them.
425
- // A `$`-key other than `$x` is never the compiler's (R34.72): it throws instead of rendering (a 500, not a revive).
426
- `const __mk = (C: any, props: any, X: string[] = []) => {\n` +
427
- ` 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` +
462
+ // `H` is its declared hole names (R34.120). A `$`-key that is neither `$x` nor in `H` is never the compiler's (R34.72):
463
+ // it throws instead of rendering (a 500, not a revive). Hole props are the revive's, not the component's.
464
+ `const __mk = (C: any, props: any, X: string[] = [], H: string[] = []) => {\n` +
465
+ ` for (const k of Object.keys(props)) if (k.charAt(0) === '$' && k !== '$x' && !H.includes(k)) throw new Error('brust: island props hold the reserved key ' + k)\n` +
428
466
  ` const { children, $x, ...rest } = props\n` +
429
- ` __xs(rest, Array.isArray($x) ? $x.filter((k: any) => X.includes(k)) : undefined)\n` +
430
- ` return createElement(C, rest, ...(children === undefined ? [] : Array.isArray(children) ? children : [children]).map(__rv))\n` +
467
+ ` const hv: any = Object.create(null)\n` +
468
+ ` for (const k of H) if (__own.call(rest, k)) { hv[k] = rest[k]; delete rest[k] }\n` +
469
+ ` __xs(rest, Array.isArray($x) ? $x.filter((k: any) => X.includes(k)) : undefined, hv)\n` +
470
+ ` return createElement(C, rest, ...(children === undefined ? [] : Array.isArray(children) ? children : [children]).map((k: any) => __rv(k, hv)))\n` +
431
471
  `}\n`
432
472
 
433
473
  /** A helper component its module does not export (`ir.unexported`: `function SheetOverlay() {…}` rendered by an exported
@@ -459,7 +499,7 @@ export function exposePlugin(compiled: Map<string, Compiled>): BunPlugin {
459
499
  export function islandShim(c: Compiled, compiled?: Map<string, Compiled>, routeRoots?: ReadonlySet<string>): string {
460
500
  const clientOnly = c.ir.tier?.React?.client_only === true
461
501
  const nested = compiled && nestedOf(compiled, c.id, routeRoots)
462
- const element = nested ? `__mk(Comp, props, ${JSON.stringify(xOf(compiled!, c.id))})` : 'createElement(Comp, props)'
502
+ const element = nested ? `__mk(Comp, props, ${JSON.stringify(xOf(compiled!, c.id))}, ${JSON.stringify(holesOf(compiled!, c.id))})` : 'createElement(Comp, props)'
463
503
  const [api, mount] = clientOnly
464
504
  ? ['createRoot', `createRoot(host, { identifierPrefix: ${JSON.stringify(c.id)} }).render(${element})`]
465
505
  : ['hydrateRoot', `hydrateRoot(host, ${element}, { identifierPrefix: ${JSON.stringify(c.id)} })`]
@@ -559,6 +599,22 @@ export async function buildCacheAdapter(dist: string, entry: string, cssMaps: Ma
559
599
  return 'cache-adapter.js'
560
600
  }
561
601
 
602
+ /** R34.96: a parent's job calls the job of each child fused into it through `brust-job:<component id>`, resolved here to
603
+ * that child's staged job module (`fileOf`). Only a compiled component's id resolves: anything else fails the bundle. */
604
+ export function jobImportPlugin(fileOf: (id: string) => string | undefined): BunPlugin {
605
+ return {
606
+ name: 'brust-job-import',
607
+ setup(b) {
608
+ b.onResolve({ filter: /^brust-job:/ }, (a) => {
609
+ const id = a.path.slice('brust-job:'.length)
610
+ const file = /^[A-Za-z0-9_$-]+$/.test(id) ? fileOf(id) : undefined
611
+ if (file === undefined) throw new BuildError('bundle', `${a.importer}: no job module for ${JSON.stringify(id)}`)
612
+ return { path: file }
613
+ })
614
+ },
615
+ }
616
+ }
617
+
562
618
  /** `dist/jobs.js` (`target: 'bun'`, React and `@brust/core` external): default export
563
619
  * `{ [componentId]: { precompute?, ssr? } }`; `ssr` only for react-tier, non-client_only components. */
564
620
  export async function buildJobs(
@@ -602,7 +658,7 @@ export async function buildJobs(
602
658
  imports.push(componentImport(c, `C${n}`))
603
659
  // Ruling 2bf3775a (R1): the island's component id prefixes React's useId on BOTH sides
604
660
  // (the shim's hydrateRoot passes the same prefix), so ids differ across islands.
605
- 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)} })`)
661
+ fns.push(`ssr: (props: any) => renderToString(${hosts.has(c.id) ? `__mk(C${n}, props, ${JSON.stringify(xOf(compiled, c.id))}, ${JSON.stringify(holesOf(compiled, c.id))})` : `createElement(C${n}, props)`}, { identifierPrefix: ${JSON.stringify(c.id)} })`)
606
662
  }
607
663
  if (fns.length > 0) entries.push(` ${JSON.stringify(c.id)}: { ${fns.join(', ')} },`)
608
664
  n++
@@ -615,7 +671,14 @@ export async function buildJobs(
615
671
  format: 'esm',
616
672
  define: PRODUCTION,
617
673
  external: JOBS_EXTERNALS,
618
- plugins: [serverOnlyEmptyPlugin(), cssPlugin(cssMaps), workerStorePlugin, sourceDirPlugin(sourceOf, appRoot, JOBS_EXTERNALS), exposePlugin(compiled)],
674
+ plugins: [
675
+ jobImportPlugin((id) => (compiled.get(id)?.serverTs !== undefined ? join(dist, 'jobs', `${id}.server.ts`) : undefined)),
676
+ serverOnlyEmptyPlugin(),
677
+ cssPlugin(cssMaps),
678
+ workerStorePlugin,
679
+ sourceDirPlugin(sourceOf, appRoot, JOBS_EXTERNALS),
680
+ exposePlugin(compiled),
681
+ ],
619
682
  })
620
683
  if (!res.success) throw new BuildError('bundle', `jobs: ${res.logs.map(String).join('\n')}`)
621
684
  write(join(dist, 'jobs.js'), await res.outputs[0]!.text())
@@ -38,6 +38,8 @@ export type ComponentIR = Record<string, any> & {
38
38
  inputs: Record<string, unknown>
39
39
  outputs: string[]
40
40
  stubs?: { source: string; code: string }[]
41
+ /** R34.96: the job modules fused into the child's job, which it imports (`FusedEvalJob`). */
42
+ fused?: { child_id: string; stubs?: { source: string; code: string }[] }[]
41
43
  line: number
42
44
  col: number
43
45
  }[]
@@ -52,7 +54,7 @@ export type ComponentIR = Record<string, any> & {
52
54
  /** The binding a React island imports this component by from `source` (absent: the default export). */
53
55
  export?: string
54
56
  /** Child components; `nested` is set when this file passes lowered JSX children to that child, an island (shadcn S1). */
55
- children?: { id: string | null; nested?: string[]; x?: string[]; [field: string]: unknown }[]
57
+ children?: { id: string | null; nested?: string[]; x?: string[]; holes?: string[]; [field: string]: unknown }[]
56
58
  }
57
59
 
58
60
  export interface Compiled {
@@ -19,7 +19,7 @@ import { buildCss, CssGraph, directCss, resolveGlobals, routeCssSources } from '
19
19
  import { type ActionsBuildConfig, type CacheBuildConfig, loadBuildConfig } from './config'
20
20
  import { BuildError } from './errors'
21
21
  import { importsStore } from './features'
22
- import { type CacheRecord, type ManifestJson, tierOf, writeManifest } from './manifest'
22
+ import { type CacheRecord, type ManifestJson, needsWorkers, tierOf, writeManifest } from './manifest'
23
23
  import { scanRoutes } from './scan'
24
24
  import { type ExprReads, prepareStatic, writeStatic } from './static'
25
25
  import { writeStaticWorker } from './static-worker'
@@ -296,6 +296,7 @@ async function buildInto(
296
296
  : null
297
297
  if (o.actionsRemote !== null) manifest.actions_remote = { prefix: o.actionsRemote }
298
298
  if (o.cache) manifest.cache = await cacheRecord(out, manifest, o.cache, o.cacheModule, css.maps)
299
+ manifest.needs_workers = needsWorkers(manifest)
299
300
  writeFileSync(join(out, 'manifest.json'), `${JSON.stringify(manifest, null, 2)}\n`)
300
301
  if (o.dev) writeFileSync(join(out, 'dev.json'), `${JSON.stringify(devJson(appRoot, compiled), null, 2)}\n`)
301
302
  writeFileSync(join(out, MARKER), 'generated by `brust build`: this directory is replaced on every build\n')
@@ -88,6 +88,16 @@ export interface ManifestJson {
88
88
  actions_remote?: { prefix: string }
89
89
  /** `[cache]` (cache adapters); absent without one (the manifest is then byte-identical). */
90
90
  cache?: CacheRecord
91
+ /** F165 (R40.1): `brust start` spawns its worker pool (`needsWorkers`). Read by `run.ts` only; an
92
+ * absent value (an older or actions-only manifest) means the pool is needed. */
93
+ needs_workers?: boolean
94
+ }
95
+
96
+ /** F165 (R40.1): whether any request can call a worker. Workers answer four kinds of call
97
+ * (worker.ts): `loader`, `jobs` (precompute and SSR), `fetch` (the local actions app) and `cache`
98
+ * (the adapter). Every component's jobs count, reached by a route or not (F166 prunes those later). */
99
+ export function needsWorkers(m: Pick<ManifestJson, 'routes' | 'components' | 'actions' | 'cache'>): boolean {
100
+ return Object.values(m.components).some((c) => c.jobs.length > 0) || m.routes.some((r) => r.loaders.length > 0) || m.actions !== null || m.cache !== undefined
91
101
  }
92
102
 
93
103
  /** `manifest.cache` / `CONFIG.cache`: the adapter the runtime loads (`cache-adapter/load.ts`). */
package/src/cli.ts CHANGED
@@ -6,12 +6,14 @@ import { BuildError, runBuild } from './build'
6
6
  import { runBunDev } from './dev/bun'
7
7
  import { runDev } from './dev'
8
8
  import { run } from './run'
9
+ import { shadcnInit, spawnRunner } from './shadcn/init'
9
10
 
10
11
  const USAGE = `usage:
11
12
  brust build [entry=routes.tsx] [--out-dir dist] [--force] [--target bun|cloudflare|static] [--actions-only] [--strict] [--wasm-from-source] [--dev]
12
13
  brust dev [entry=routes.tsx] [--port N] [--workers N] (Bun target: proxy + hot reload + inline TUI)
13
14
  brust dev [entry=routes.tsx] --target cloudflare [--out-dir dist] [--port N] [--wasm-from-source] [-- <wrangler args>]
14
15
  brust start [--port N] [--workers N] [--dist-dir dist] [--entry routes.tsx]
16
+ brust shadcn init [component ...] [--force] [--css <file>] [--base-color <name>] [--shadcn-version <x.y.z>]
15
17
 
16
18
  Config precedence for start: env (BRUST_ADDR, BRUST_PORT, BRUST_WORKERS, BRUST_RENDER_SLOTS,
17
19
  BRUST_DRAIN_TIMEOUT_MS, BRUST_BOOT_TIMEOUT_MS, BRUST_DIST_DIR, BRUST_APP_ENTRY) > flags
@@ -53,6 +55,9 @@ export async function main(argv: string[]): Promise<void> {
53
55
  port: { type: 'string' },
54
56
  workers: { type: 'string' },
55
57
  force: { type: 'boolean' },
58
+ css: { type: 'string' },
59
+ 'base-color': { type: 'string' },
60
+ 'shadcn-version': { type: 'string' },
56
61
  strict: { type: 'boolean' },
57
62
  target: { type: 'string' },
58
63
  'wasm-from-source': { type: 'boolean' },
@@ -127,6 +132,21 @@ export async function main(argv: string[]): Promise<void> {
127
132
  process.exit(1)
128
133
  }
129
134
  }
135
+ if (cmd === 'shadcn') {
136
+ const [sub, ...components] = positionals
137
+ if (sub !== 'init') usage(`shadcn takes a subcommand: init (got ${sub === undefined ? 'none' : JSON.stringify(sub)})`)
138
+ const code = await shadcnInit({
139
+ root: process.cwd(),
140
+ components,
141
+ force: values.force === true,
142
+ ...(str('css') !== undefined && { css: str('css') }),
143
+ ...(str('base-color') !== undefined && { baseColor: str('base-color') }),
144
+ ...(str('shadcn-version') !== undefined && { shadcnVersion: str('shadcn-version') }),
145
+ run: spawnRunner,
146
+ out: (s) => console.log(s),
147
+ })
148
+ process.exit(code)
149
+ }
130
150
  if (cmd === 'start') {
131
151
  if (positionals.length > 0) usage(`start takes no positional arguments (got ${positionals.join(' ')})`)
132
152
  const port = intFlag('port', str('port'), 0)
package/src/run.ts CHANGED
@@ -4,6 +4,8 @@
4
4
  // once (130 / 143); a signal before every worker registered exits 0 at once (nothing is being
5
5
  // served yet, and the server's drain only starts once it accepts). A worker that dies (error,
6
6
  // process.exit, OOM) → drain → exit 1: M2 does not respawn, the supervisor restarts the process.
7
+ // F165: a build whose manifest says `needs_workers: false` (no loader, job, actions app or cache
8
+ // adapter) spawns none; the server then serves at once and a stray worker call answers 503.
7
9
  // Nothing here returns on its own: a started server keeps the process alive and a drained one
8
10
  // does not end it, so every exit is an explicit `process.exit`.
9
11
  import { existsSync, readFileSync } from 'node:fs'
@@ -32,6 +34,13 @@ export interface RunManifest {
32
34
  actions_remote?: { prefix: string } | null
33
35
  /** `[cache]`: the server's L2 settings (the workers load the adapter itself). */
34
36
  cache?: { adapter: string; getTimeoutMs: number; maxBodyBytes: number; namespace: string; buildId: string } | null
37
+ /** F165: `false` = no route can call a worker; absent (older manifests) = the pool is needed. */
38
+ needs_workers?: boolean
39
+ }
40
+
41
+ /** F165 (R40.1): the pool size `run` spawns: none only when the build said no request needs one. */
42
+ export function workerCount(cfg: BrustConfig, m: RunManifest): number {
43
+ return m.needs_workers === false ? 0 : cfg.workers
35
44
  }
36
45
 
37
46
  /** Pure: the napi `StartOptions`. No actions/cors/cache → exactly the pre-actions keys. */
@@ -40,7 +49,7 @@ export function startOptions(cfg: BrustConfig, distDir: string, m: RunManifest,
40
49
  host: cfg.host,
41
50
  port: cfg.port,
42
51
  distDir,
43
- workers: cfg.workers,
52
+ workers: workerCount(cfg, m),
44
53
  callTimeoutMs: cfg.callTimeoutMs,
45
54
  ...(cfg.maxLoaderResponseBytes !== undefined && cfg.maxLoaderResponseBytes !== DEFAULT_MAX_LOADER_RESPONSE_BYTES ? { maxLoaderResponseBytes: cfg.maxLoaderResponseBytes } : {}),
46
55
  workerThreads: cfg.ioThreads,
@@ -134,8 +143,9 @@ export async function run(opts: RunOptions = {}): Promise<void> {
134
143
  .finally(() => exit(failed ? 1 : code))
135
144
  }
136
145
 
146
+ const workers = workerCount(cfg, m)
137
147
  const url = new URL('./worker.ts', import.meta.url)
138
- for (let i = 0; i < cfg.workers; i++) {
148
+ for (let i = 0; i < workers; i++) {
139
149
  // The response buffer is owned HERE, for the process lifetime: the Rust dispatcher keeps a raw
140
150
  // pointer into it, so it must not be freed with the worker (crates/brust-napi dispatch.rs).
141
151
  const sab = new SharedArrayBuffer(cfg.slotBytes * cfg.renderSlots)
@@ -180,7 +190,7 @@ export async function run(opts: RunOptions = {}): Promise<void> {
180
190
  fail(`workers not ready: ${String((e as Error).message ?? e)} (BRUST_BOOT_TIMEOUT_MS=${cfg.bootTimeoutMs})`)
181
191
  }
182
192
  ready = true
183
- console.log(`[brust] ready (${cfg.workers} worker${cfg.workers === 1 ? '' : 's'})`)
193
+ console.log(`[brust] ready (${workers} worker${workers === 1 ? '' : 's'})`)
184
194
  if (opts.onReady) {
185
195
  let code = 1
186
196
  try {
@@ -0,0 +1,213 @@
1
+ // `brust shadcn init [component ...]`: sets a brust project up for shadcn/ui and adds components (F175, R41.1-R41.10).
2
+ // shadcn's own `init` does not detect brust, so this writes what `add` needs (components.json, the `@/*` path),
3
+ // installs the four packages the components import, and runs ONE pinned shadcn CLI for the theme and the components.
4
+ // Every child process is spawned from an argv array, never through a shell; the runner is injected for tests.
5
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs'
6
+ import { isAbsolute, join, relative, resolve } from 'node:path'
7
+ import { type ObjectNode, raw, readObject } from './jsonc'
8
+
9
+ /** The shadcn CLI version this command runs (R41.6). A release that moves it re-runs the transcript. */
10
+ export const SHADCN_VERSION = '4.21.4'
11
+
12
+ /** The packages the components import (R41.5). */
13
+ export const SHADCN_DEPS = ['radix-ui', 'lucide-react', 'class-variance-authority', 'tw-animate-css'] as const
14
+
15
+ /** Runs `argv` in `cwd` with the terminal attached; resolves to the exit code. Never a shell string. */
16
+ export type Runner = (argv: string[], cwd: string) => Promise<number>
17
+
18
+ export interface InitOptions {
19
+ /** Project root (cwd). */
20
+ root: string
21
+ components: string[]
22
+ force?: boolean
23
+ css?: string
24
+ baseColor?: string
25
+ shadcnVersion?: string
26
+ run: Runner
27
+ out: (line: string) => void
28
+ }
29
+
30
+ const COMPONENT = /^[a-z0-9][a-z0-9-]*$/
31
+ const REGISTRY_URL = /^https:\/\/[^\s]+$/
32
+ const VERSION = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/
33
+ const COLOR = /^[a-z]+$/
34
+
35
+ /** The `components.json` of the tested fixture (`tests/fixtures/shadcn/components.json`), for `css` and `baseColor` (R41.2). */
36
+ export function componentsJson(css: string, baseColor: string): string {
37
+ return `{
38
+ "$schema": "https://ui.shadcn.com/schema.json",
39
+ "style": "new-york",
40
+ "rsc": false,
41
+ "tsx": true,
42
+ "tailwind": { "config": "", "css": ${JSON.stringify(css)}, "baseColor": ${JSON.stringify(baseColor)}, "cssVariables": true, "prefix": "" },
43
+ "iconLibrary": "lucide",
44
+ "aliases": { "components": "@/components", "utils": "@/lib/utils", "ui": "@/components/ui", "lib": "@/lib", "hooks": "@/hooks" }
45
+ }
46
+ `
47
+ }
48
+
49
+ export type PathEdit =
50
+ | { kind: 'added'; text: string }
51
+ | { kind: 'present' }
52
+ | { kind: 'other'; target: string }
53
+ | { kind: 'unparseable'; why: string }
54
+
55
+ const ENTRY = '"@/*": ["./*"]'
56
+
57
+ /** The separator before a non-empty object's first member, so the new entry takes the same line and indent. */
58
+ function lead(text: string, o: ObjectNode): string {
59
+ const first = o.members[0]
60
+ if (!first) return ' '
61
+ const nl = text.lastIndexOf('\n', first.keyStart)
62
+ const indent = nl > o.open ? text.slice(nl + 1, first.keyStart) : ''
63
+ if (nl > o.open && /^\s*$/.test(indent)) return `\n${indent}`
64
+ const same = text.slice(o.open + 1, first.keyStart)
65
+ return /^\s*$/.test(same) ? same : ' '
66
+ }
67
+
68
+ /** Adds `"@/*": ["./*"]` to `compilerOptions.paths` as a text splice (R41.4): comments and layout are kept. */
69
+ export function addAliasPath(text: string): PathEdit {
70
+ let top: ObjectNode
71
+ try {
72
+ top = readObject(text)
73
+ } catch (e) {
74
+ return { kind: 'unparseable', why: (e as Error).message }
75
+ }
76
+ const co = top.members.find((m) => m.key === 'compilerOptions')?.object
77
+ if (!co) return { kind: 'unparseable', why: 'no compilerOptions object' }
78
+ const pathsMember = co.members.find((m) => m.key === 'paths')
79
+ if (!pathsMember) {
80
+ const ws = lead(text, co)
81
+ const body = co.members.length > 0 ? `${ws}"paths": { ${ENTRY} },` : ` "paths": { ${ENTRY} } `
82
+ return { kind: 'added', text: text.slice(0, co.open + 1) + body + text.slice(co.open + 1) }
83
+ }
84
+ const paths = pathsMember.object
85
+ if (!paths) return { kind: 'unparseable', why: 'compilerOptions.paths is not an object' }
86
+ const existing = paths.members.find((m) => m.key === '@/*')
87
+ if (existing) {
88
+ const target = raw(text, existing)
89
+ return target.replace(/\s+/g, '') === '["./*"]' ? { kind: 'present' } : { kind: 'other', target }
90
+ }
91
+ const ws = lead(text, paths)
92
+ const body = paths.members.length > 0 ? `${ws}${ENTRY},` : ` ${ENTRY} `
93
+ return { kind: 'added', text: text.slice(0, paths.open + 1) + body + text.slice(paths.open + 1) }
94
+ }
95
+
96
+ /** The Tailwind entry CSS: `--css`, else the one top-level `*.css` that imports `tailwindcss` (R41.3). */
97
+ function tailwindEntry(root: string, css: string | undefined): { css: string } | { error: string } {
98
+ if (css !== undefined) {
99
+ const abs = resolve(root, css)
100
+ const rel = relative(root, abs)
101
+ if (css.startsWith('-') || isAbsolute(css) || rel.startsWith('..') || !existsSync(abs)) {
102
+ return { error: `--css ${JSON.stringify(css)} must be an existing CSS file inside the project` }
103
+ }
104
+ return { css: rel.split('\\').join('/') }
105
+ }
106
+ const hit = ['app.css', 'styles.css', 'global.css', 'globals.css', 'index.css'].filter((f) => {
107
+ const p = join(root, f)
108
+ return existsSync(p) && /@import\s+["']tailwindcss["']/.test(readFileSync(p, 'utf8'))
109
+ })
110
+ if (hit.length === 1) return { css: hit[0]! }
111
+ return { error: hit.length === 0 ? 'cannot tell which CSS file is the Tailwind entry; pass --css <file>' : `more than one Tailwind entry (${hit.join(', ')}); pass --css <file>` }
112
+ }
113
+
114
+ type Step = 'done' | 'skipped' | 'failed'
115
+
116
+ /** Returns the process exit code: 0 ok, 2 usage / not a brust project, else the failing child's code. */
117
+ export async function shadcnInit(o: InitOptions): Promise<number> {
118
+ const { root, out } = o
119
+ const fail2 = (msg: string): number => {
120
+ out(`error shadcn-init ${msg}`)
121
+ return 2
122
+ }
123
+ // R41.1: a brust project root.
124
+ const pkgPath = join(root, 'package.json')
125
+ if (!existsSync(pkgPath)) return fail2('no package.json here: run it in the root of a brust project')
126
+ let pkg: { dependencies?: Record<string, string>; devDependencies?: Record<string, string> }
127
+ try {
128
+ pkg = JSON.parse(readFileSync(pkgPath, 'utf8'))
129
+ } catch {
130
+ return fail2('package.json is not valid JSON')
131
+ }
132
+ if (!pkg.dependencies?.['@brust/core'] && !pkg.devDependencies?.['@brust/core']) {
133
+ return fail2('package.json does not depend on @brust/core: run it in the root of a brust project')
134
+ }
135
+ // R41.8: validate everything that reaches an argv before anything is written.
136
+ for (const c of o.components) {
137
+ if (!COMPONENT.test(c) && !REGISTRY_URL.test(c)) return fail2(`component ${JSON.stringify(c)} must match ^[a-z0-9][a-z0-9-]*$ or be an https:// registry URL`)
138
+ }
139
+ const version = o.shadcnVersion ?? SHADCN_VERSION
140
+ if (!VERSION.test(version)) return fail2(`--shadcn-version ${JSON.stringify(version)} must be an exact version like ${SHADCN_VERSION}`)
141
+ const baseColor = o.baseColor ?? 'neutral'
142
+ if (!COLOR.test(baseColor)) return fail2(`--base-color ${JSON.stringify(baseColor)} must be a lowercase colour name`)
143
+ const entry = tailwindEntry(root, o.css)
144
+ if ('error' in entry) return fail2(entry.error)
145
+
146
+ const report = (name: string, step: Step, why = ''): void => out(`${step === 'done' ? '✓' : step === 'skipped' ? '-' : '✗'} ${name}: ${step}${why ? ` (${why})` : ''}`)
147
+ const stop = (name: string, code: number): number => {
148
+ report(name, 'failed', `exit ${code}`)
149
+ out(`error shadcn-init ${name} failed with exit code ${code}; fix it and run the command again (finished steps are skipped)`)
150
+ return code
151
+ }
152
+
153
+ // R41.2: components.json.
154
+ const cj = join(root, 'components.json')
155
+ if (!existsSync(cj) || o.force) {
156
+ writeFileSync(cj, componentsJson(entry.css, baseColor))
157
+ report('components.json', 'done', entry.css)
158
+ } else report('components.json', 'skipped', 'exists; --force replaces it')
159
+
160
+ // R41.4: the `@/*` path.
161
+ const tsPath = join(root, 'tsconfig.json')
162
+ if (!existsSync(tsPath)) {
163
+ report('tsconfig.json', 'skipped', `no tsconfig.json; add ${JSON.stringify({ compilerOptions: { paths: { '@/*': ['./*'] } } })}`)
164
+ } else {
165
+ const edit = addAliasPath(readFileSync(tsPath, 'utf8'))
166
+ if (edit.kind === 'added') {
167
+ writeFileSync(tsPath, edit.text)
168
+ report('tsconfig.json', 'done', 'added "@/*": ["./*"] under compilerOptions.paths')
169
+ } else if (edit.kind === 'present') report('tsconfig.json', 'skipped', '"@/*" is already there')
170
+ else if (edit.kind === 'other') report('tsconfig.json', 'skipped', `warning: "@/*" already points at ${edit.target}; shadcn's imports need ["./*"]`)
171
+ else report('tsconfig.json', 'skipped', `not edited (${edit.why}); add this line to compilerOptions.paths yourself: ${ENTRY}`)
172
+ }
173
+
174
+ // R41.5: dependencies.
175
+ const have = { ...pkg.devDependencies, ...pkg.dependencies }
176
+ const missing = SHADCN_DEPS.filter((d) => !have[d])
177
+ if (missing.length === 0) report('dependencies', 'skipped', 'all four are installed')
178
+ else {
179
+ const code = await o.run(['bun', 'add', ...missing], root)
180
+ if (code !== 0) return stop('bun add', code)
181
+ report('dependencies', 'done', missing.join(' '))
182
+ }
183
+
184
+ // R41.6 / R41.7: the pinned shadcn CLI. `bun x` is `bunx`; argv only.
185
+ const shadcn = (...args: string[]): string[] => ['bun', 'x', `shadcn@${version}`, ...args]
186
+ const cssText = readFileSync(join(root, entry.css), 'utf8')
187
+ if (cssText.includes('shadcn/tailwind.css') && !o.force) report('theme', 'skipped', `${entry.css} already has the shadcn theme; --force runs it again`)
188
+ else {
189
+ const code = await o.run(shadcn('add', 'index', '-y'), root)
190
+ if (code !== 0) return stop('shadcn add index', code)
191
+ report('theme', 'done', `shadcn@${version} add index`)
192
+ }
193
+ // A component whose file is already in components/ui is not added again (idempotent); a URL always is.
194
+ const todo = o.components.filter((c) => o.force || REGISTRY_URL.test(c) || !existsSync(join(root, 'components/ui', `${c}.tsx`)))
195
+ for (const c of o.components) if (!todo.includes(c)) report(c, 'skipped', 'components/ui already has it')
196
+ if (todo.length > 0) {
197
+ const code = await o.run(shadcn('add', ...todo, '-y'), root)
198
+ if (code !== 0) return stop(`shadcn add ${todo.join(' ')}`, code)
199
+ for (const c of todo) report(c, 'done')
200
+ }
201
+
202
+ out('')
203
+ out('next:')
204
+ out(" import the components from './components/ui/<name>' in a page and add the route to routes.tsx")
205
+ out(' bun run build')
206
+ return 0
207
+ }
208
+
209
+ /** The real runner: argv spawn with the terminal attached, no shell. */
210
+ export const spawnRunner: Runner = async (argv, cwd) => {
211
+ const p = Bun.spawn(argv, { cwd, stdin: 'inherit', stdout: 'inherit', stderr: 'inherit' })
212
+ return await p.exited
213
+ }
@@ -0,0 +1,129 @@
1
+ // A minimal JSONC reader that keeps byte offsets, so a file can be edited with a text splice (comments, trailing
2
+ // commas and formatting survive). It does not build values; it finds object members. Anything it cannot read throws.
3
+
4
+ export interface Member {
5
+ key: string
6
+ /** Offset of the member's key (its opening quote). */
7
+ keyStart: number
8
+ /** Offset of the member's value (the `{` of an object value). */
9
+ value: number
10
+ /** Offset just past the value. */
11
+ end: number
12
+ /** Parsed object when the value is an object, else `undefined`. */
13
+ object?: ObjectNode
14
+ }
15
+
16
+ export interface ObjectNode {
17
+ /** Offset of `{`. */
18
+ open: number
19
+ /** Offset of `}`. */
20
+ close: number
21
+ members: Member[]
22
+ }
23
+
24
+ class Reader {
25
+ i = 0
26
+ constructor(readonly s: string) {}
27
+
28
+ ws(): void {
29
+ const { s } = this
30
+ for (;;) {
31
+ const c = s[this.i]
32
+ if (c === ' ' || c === '\t' || c === '\n' || c === '\r' || c === '') this.i++
33
+ else if (c === '/' && s[this.i + 1] === '/') {
34
+ while (this.i < s.length && s[this.i] !== '\n') this.i++
35
+ } else if (c === '/' && s[this.i + 1] === '*') {
36
+ const e = s.indexOf('*/', this.i + 2)
37
+ if (e < 0) throw new Error('unterminated comment')
38
+ this.i = e + 2
39
+ } else return
40
+ }
41
+ }
42
+
43
+ string(): string {
44
+ const { s } = this
45
+ if (s[this.i] !== '"') throw new Error(`expected a string at ${this.i}`)
46
+ let j = this.i + 1
47
+ let out = ''
48
+ while (j < s.length && s[j] !== '"') {
49
+ if (s[j] === '\\') {
50
+ out += s[j + 1] ?? ''
51
+ j += 2
52
+ } else if (s[j] === '\n') throw new Error('newline in a string')
53
+ else out += s[j++]
54
+ }
55
+ if (s[j] !== '"') throw new Error('unterminated string')
56
+ this.i = j + 1
57
+ return out
58
+ }
59
+
60
+ /** Skips one value; returns its object node when it is an object. */
61
+ value(): ObjectNode | undefined {
62
+ this.ws()
63
+ const c = this.s[this.i]
64
+ if (c === '{') return this.object()
65
+ if (c === '[') {
66
+ this.i++
67
+ for (;;) {
68
+ this.ws()
69
+ if (this.s[this.i] === ']') {
70
+ this.i++
71
+ return undefined
72
+ }
73
+ this.value()
74
+ this.ws()
75
+ if (this.s[this.i] === ',') this.i++
76
+ else if (this.s[this.i] !== ']') throw new Error(`expected , or ] at ${this.i}`)
77
+ }
78
+ }
79
+ if (c === '"') {
80
+ this.string()
81
+ return undefined
82
+ }
83
+ const m = /^(?:-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?|true|false|null)/.exec(this.s.slice(this.i, this.i + 40))
84
+ if (!m) throw new Error(`unexpected character at ${this.i}`)
85
+ this.i += m[0].length
86
+ return undefined
87
+ }
88
+
89
+ object(): ObjectNode {
90
+ const open = this.i
91
+ this.i++
92
+ const members: Member[] = []
93
+ for (;;) {
94
+ this.ws()
95
+ if (this.s[this.i] === '}') {
96
+ this.i++
97
+ return { open, close: this.i - 1, members }
98
+ }
99
+ const keyStart = this.i
100
+ const key = this.string()
101
+ this.ws()
102
+ if (this.s[this.i] !== ':') throw new Error(`expected : at ${this.i}`)
103
+ this.i++
104
+ this.ws()
105
+ const value = this.i
106
+ const object = this.value()
107
+ members.push({ key, keyStart, value, end: this.i, ...(object && { object }) })
108
+ this.ws()
109
+ if (this.s[this.i] === ',') this.i++
110
+ else if (this.s[this.i] !== '}') throw new Error(`expected , or } at ${this.i}`)
111
+ }
112
+ }
113
+ }
114
+
115
+ /** The top-level object of a JSONC text. Throws on anything that is not JSONC. */
116
+ export function readObject(text: string): ObjectNode {
117
+ const r = new Reader(text)
118
+ r.ws()
119
+ if (text[r.i] !== '{') throw new Error('not an object')
120
+ const o = r.object()
121
+ r.ws()
122
+ if (r.i !== text.length) throw new Error('trailing content')
123
+ return o
124
+ }
125
+
126
+ /** The raw text of a member's value. */
127
+ export function raw(text: string, m: Member): string {
128
+ return text.slice(m.value, m.end)
129
+ }