@brust/core 2.0.0-alpha.10 → 2.0.0-alpha.12
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 +54 -54
- package/package.json +9 -9
- package/src/build/build-eval.ts +28 -17
- package/src/build/bundle.ts +88 -17
- package/src/build/compile.ts +3 -1
- package/src/build/index.ts +3 -2
- package/src/build/manifest.ts +29 -0
- package/src/cli.ts +20 -0
- package/src/run.ts +13 -3
- package/src/shadcn/init.ts +254 -0
- package/src/shadcn/jsonc.ts +129 -0
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.
|
|
93
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
92
|
+
if (bindingPackageVersion !== '2.0.0-alpha.12' && 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.12 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.
|
|
109
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
108
|
+
if (bindingPackageVersion !== '2.0.0-alpha.12' && 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.12 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.
|
|
130
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
129
|
+
if (bindingPackageVersion !== '2.0.0-alpha.12' && 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.12 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.
|
|
146
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
145
|
+
if (bindingPackageVersion !== '2.0.0-alpha.12' && 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.12 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.
|
|
163
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
162
|
+
if (bindingPackageVersion !== '2.0.0-alpha.12' && 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.12 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.
|
|
179
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
178
|
+
if (bindingPackageVersion !== '2.0.0-alpha.12' && 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.12 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.
|
|
198
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
197
|
+
if (bindingPackageVersion !== '2.0.0-alpha.12' && 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.12 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.
|
|
214
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
213
|
+
if (bindingPackageVersion !== '2.0.0-alpha.12' && 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.12 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.
|
|
230
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
229
|
+
if (bindingPackageVersion !== '2.0.0-alpha.12' && 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.12 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.
|
|
250
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
249
|
+
if (bindingPackageVersion !== '2.0.0-alpha.12' && 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.12 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.
|
|
266
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
265
|
+
if (bindingPackageVersion !== '2.0.0-alpha.12' && 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.12 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.
|
|
287
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
286
|
+
if (bindingPackageVersion !== '2.0.0-alpha.12' && 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.12 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.
|
|
303
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
302
|
+
if (bindingPackageVersion !== '2.0.0-alpha.12' && 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.12 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.
|
|
321
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
320
|
+
if (bindingPackageVersion !== '2.0.0-alpha.12' && 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.12 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.
|
|
337
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
336
|
+
if (bindingPackageVersion !== '2.0.0-alpha.12' && 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.12 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.
|
|
355
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
354
|
+
if (bindingPackageVersion !== '2.0.0-alpha.12' && 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.12 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.
|
|
371
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
370
|
+
if (bindingPackageVersion !== '2.0.0-alpha.12' && 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.12 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.
|
|
389
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
388
|
+
if (bindingPackageVersion !== '2.0.0-alpha.12' && 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.12 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.
|
|
405
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
404
|
+
if (bindingPackageVersion !== '2.0.0-alpha.12' && 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.12 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.
|
|
423
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
422
|
+
if (bindingPackageVersion !== '2.0.0-alpha.12' && 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.12 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.
|
|
439
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
438
|
+
if (bindingPackageVersion !== '2.0.0-alpha.12' && 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.12 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.
|
|
456
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
455
|
+
if (bindingPackageVersion !== '2.0.0-alpha.12' && 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.12 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.
|
|
472
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
471
|
+
if (bindingPackageVersion !== '2.0.0-alpha.12' && 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.12 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.
|
|
492
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
491
|
+
if (bindingPackageVersion !== '2.0.0-alpha.12' && 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.12 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.
|
|
508
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
507
|
+
if (bindingPackageVersion !== '2.0.0-alpha.12' && 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.12 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.
|
|
524
|
-
throw new Error(`Native binding package version mismatch, expected 2.0.0-alpha.
|
|
523
|
+
if (bindingPackageVersion !== '2.0.0-alpha.12' && 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.12 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.
|
|
665
|
-
throw new Error(`WASI binding package version mismatch, expected 2.0.0-alpha.
|
|
664
|
+
if (bindingPackageVersion !== '2.0.0-alpha.12') {
|
|
665
|
+
throw new Error(`WASI binding package version mismatch, expected 2.0.0-alpha.12 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.
|
|
3
|
+
"version": "2.0.0-alpha.12",
|
|
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.
|
|
58
|
+
"@brust/runtime-dom": "2.0.0-alpha.12"
|
|
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.
|
|
97
|
-
"@brust/native-darwin-arm64": "2.0.0-alpha.
|
|
98
|
-
"@brust/native-linux-x64-gnu": "2.0.0-alpha.
|
|
99
|
-
"@brust/native-linux-arm64-gnu": "2.0.0-alpha.
|
|
100
|
-
"@brust/native-linux-x64-musl": "2.0.0-alpha.
|
|
101
|
-
"@brust/native-linux-arm64-musl": "2.0.0-alpha.
|
|
102
|
-
"@brust/core-cf": "2.0.0-alpha.
|
|
96
|
+
"@brust/native-darwin-x64": "2.0.0-alpha.12",
|
|
97
|
+
"@brust/native-darwin-arm64": "2.0.0-alpha.12",
|
|
98
|
+
"@brust/native-linux-x64-gnu": "2.0.0-alpha.12",
|
|
99
|
+
"@brust/native-linux-arm64-gnu": "2.0.0-alpha.12",
|
|
100
|
+
"@brust/native-linux-x64-musl": "2.0.0-alpha.12",
|
|
101
|
+
"@brust/native-linux-arm64-musl": "2.0.0-alpha.12",
|
|
102
|
+
"@brust/core-cf": "2.0.0-alpha.12"
|
|
103
103
|
}
|
|
104
104
|
}
|
package/src/build/build-eval.ts
CHANGED
|
@@ -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
|
-
|
|
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(
|
|
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]}`)
|
package/src/build/bundle.ts
CHANGED
|
@@ -76,6 +76,9 @@ export function sourceDirPlugin(sourceOf: SourceOf, appRoot: string, external: s
|
|
|
76
76
|
return src === undefined ? undefined : { path: Bun.resolveSync(a.path, dirname(src)) }
|
|
77
77
|
})
|
|
78
78
|
b.onResolve({ filter: /^[^./]/ }, (a) => {
|
|
79
|
+
// A package source imported as itself (a React component revived from it): its bare imports are the package's.
|
|
80
|
+
const own = sourceOf.has(a.importer) ? undefined : packageDirOf(a.importer)
|
|
81
|
+
if (own !== undefined && !matchesExternal(a.path, external)) return { path: Bun.resolveSync(a.path, own) }
|
|
79
82
|
if (!sourceOf.has(a.importer) || matchesExternal(a.path, external)) return undefined
|
|
80
83
|
// F153c: an artifact compiled from a package's source imports what that package sees.
|
|
81
84
|
const pkg = packageDirOf(sourceOf.get(a.importer)!)
|
|
@@ -383,9 +386,31 @@ export function nestedOf(compiled: Map<string, Compiled>, id: string, routeRoots
|
|
|
383
386
|
}
|
|
384
387
|
}
|
|
385
388
|
}
|
|
389
|
+
// F148a (R34.121): a wrapper whose island renders `{children}` (a `$c` hole) is handed a tree by each call site; the
|
|
390
|
+
// components those trees name are revived by the island inside the wrapper, so its chunk and job import them.
|
|
391
|
+
for (const w of compiled.values()) {
|
|
392
|
+
if (!(w.ir.children ?? []).some((r) => r.id === id && (r.holes ?? []).some((h) => h.startsWith('$c')))) continue
|
|
393
|
+
for (const c of compiled.values()) {
|
|
394
|
+
for (const ref of c.ir.children ?? []) {
|
|
395
|
+
if (ref.id === w.id && ref.nested) {
|
|
396
|
+
out ??= new Set()
|
|
397
|
+
for (const n of ref.nested) out.add(n)
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
386
402
|
return out && [...out].sort()
|
|
387
403
|
}
|
|
388
404
|
|
|
405
|
+
/** F148a (R34.120): the island props the compiler wrote for the values its children read from props (`$p<N>`: a
|
|
406
|
+
* primitive, `$c<N>`: a tree a wrapper's call site bound), at any call site of the island `id`. The only `$` keys,
|
|
407
|
+
* besides `$x`, its revive accepts. */
|
|
408
|
+
export function holesOf(compiled: Map<string, Compiled>, id: string): string[] {
|
|
409
|
+
const out = new Set<string>()
|
|
410
|
+
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)
|
|
411
|
+
return [...out].sort()
|
|
412
|
+
}
|
|
413
|
+
|
|
389
414
|
/** F158 (R34.71): the element-prop names (`$x`) the compiler wrote at any call site of the island `id`: the only names
|
|
390
415
|
* its revive may revive. */
|
|
391
416
|
export function xOf(compiled: Map<string, Compiled>, id: string): string[] {
|
|
@@ -409,25 +434,43 @@ export const reviveSource = (reg: string): string =>
|
|
|
409
434
|
`const __own = Object.prototype.hasOwnProperty\n` +
|
|
410
435
|
// The tree is compiler output, but props travel in page markup: read it as untrusted. A tag must be a plain element
|
|
411
436
|
// name, a component must be in this island's registry (own keys only), and the raw-HTML prop is never revived.
|
|
412
|
-
`
|
|
437
|
+
// `hv` holds the island's hole values (F148a, R34.116): the props the compiler declared (`$p<N>` primitives, `$c<N>`
|
|
438
|
+
// 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);
|
|
439
|
+
// anything else renders nothing, and is never walked, so request data can fill a leaf but never shape the tree.
|
|
440
|
+
`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` +
|
|
441
|
+
`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` +
|
|
442
|
+
`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
443
|
// `x` (on a component node) and `$x` (on the island's props) are the compiler's list of props that hold an element
|
|
414
444
|
// 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
|
|
445
|
+
`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` +
|
|
446
|
+
`const __kids = (c: any, hv: any): any[] => Array.isArray(c) ? c.map((k: any) => __rv(k, hv)) : []\n` +
|
|
447
|
+
`const __rv = (n: any, hv: any): any => {\n` +
|
|
417
448
|
` if (n === null || typeof n !== 'object') return n\n` +
|
|
418
|
-
|
|
449
|
+
// A text leaf is a string or a finite number; an array of them (React renders each) keeps those items. Anything else
|
|
450
|
+
// renders nothing and is never walked.
|
|
451
|
+
` 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` +
|
|
452
|
+
// A condition is the truthiness of the declared own hole, as in React, without reading into the value. `a` is the
|
|
453
|
+
// `cond && <X/>` form: React renders a falsy number there (0) as text.
|
|
454
|
+
` 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` +
|
|
455
|
+
// The caller's tree: compile-time, bound by the wrapper's call site. It holds no hole of its own, so it is revived
|
|
456
|
+
// with none (a tree that named one would render nothing, and cannot recurse).
|
|
457
|
+
` 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` +
|
|
458
|
+
` const kids = __kids(n.c, hv)\n` +
|
|
419
459
|
` 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` +
|
|
460
|
+
` 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` +
|
|
461
|
+
` 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
462
|
` throw new Error('brust: island children hold an unknown node')\n` +
|
|
423
463
|
`}\n` +
|
|
424
464
|
// `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
|
|
426
|
-
|
|
427
|
-
`
|
|
465
|
+
// `H` is its declared hole names (R34.120). A `$`-key that is neither `$x` nor in `H` is never the compiler's (R34.72):
|
|
466
|
+
// it throws instead of rendering (a 500, not a revive). Hole props are the revive's, not the component's.
|
|
467
|
+
`const __mk = (C: any, props: any, X: string[] = [], H: string[] = []) => {\n` +
|
|
468
|
+
` 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
469
|
` const { children, $x, ...rest } = props\n` +
|
|
429
|
-
`
|
|
430
|
-
`
|
|
470
|
+
` const hv: any = Object.create(null)\n` +
|
|
471
|
+
` for (const k of H) if (__own.call(rest, k)) { hv[k] = rest[k]; delete rest[k] }\n` +
|
|
472
|
+
` __xs(rest, Array.isArray($x) ? $x.filter((k: any) => X.includes(k)) : undefined, hv)\n` +
|
|
473
|
+
` return createElement(C, rest, ...(children === undefined ? [] : Array.isArray(children) ? children : [children]).map((k: any) => __rv(k, hv)))\n` +
|
|
431
474
|
`}\n`
|
|
432
475
|
|
|
433
476
|
/** A helper component its module does not export (`ir.unexported`: `function SheetOverlay() {…}` rendered by an exported
|
|
@@ -459,7 +502,7 @@ export function exposePlugin(compiled: Map<string, Compiled>): BunPlugin {
|
|
|
459
502
|
export function islandShim(c: Compiled, compiled?: Map<string, Compiled>, routeRoots?: ReadonlySet<string>): string {
|
|
460
503
|
const clientOnly = c.ir.tier?.React?.client_only === true
|
|
461
504
|
const nested = compiled && nestedOf(compiled, c.id, routeRoots)
|
|
462
|
-
const element = nested ? `__mk(Comp, props, ${JSON.stringify(xOf(compiled!, c.id))})` : 'createElement(Comp, props)'
|
|
505
|
+
const element = nested ? `__mk(Comp, props, ${JSON.stringify(xOf(compiled!, c.id))}, ${JSON.stringify(holesOf(compiled!, c.id))})` : 'createElement(Comp, props)'
|
|
463
506
|
const [api, mount] = clientOnly
|
|
464
507
|
? ['createRoot', `createRoot(host, { identifierPrefix: ${JSON.stringify(c.id)} }).render(${element})`]
|
|
465
508
|
: ['hydrateRoot', `hydrateRoot(host, ${element}, { identifierPrefix: ${JSON.stringify(c.id)} })`]
|
|
@@ -559,6 +602,22 @@ export async function buildCacheAdapter(dist: string, entry: string, cssMaps: Ma
|
|
|
559
602
|
return 'cache-adapter.js'
|
|
560
603
|
}
|
|
561
604
|
|
|
605
|
+
/** R34.96: a parent's job calls the job of each child fused into it through `brust-job:<component id>`, resolved here to
|
|
606
|
+
* that child's staged job module (`fileOf`). Only a compiled component's id resolves: anything else fails the bundle. */
|
|
607
|
+
export function jobImportPlugin(fileOf: (id: string) => string | undefined): BunPlugin {
|
|
608
|
+
return {
|
|
609
|
+
name: 'brust-job-import',
|
|
610
|
+
setup(b) {
|
|
611
|
+
b.onResolve({ filter: /^brust-job:/ }, (a) => {
|
|
612
|
+
const id = a.path.slice('brust-job:'.length)
|
|
613
|
+
const file = /^[A-Za-z0-9_$-]+$/.test(id) ? fileOf(id) : undefined
|
|
614
|
+
if (file === undefined) throw new BuildError('bundle', `${a.importer}: no job module for ${JSON.stringify(id)}`)
|
|
615
|
+
return { path: file }
|
|
616
|
+
})
|
|
617
|
+
},
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
|
|
562
621
|
/** `dist/jobs.js` (`target: 'bun'`, React and `@brust/core` external): default export
|
|
563
622
|
* `{ [componentId]: { precompute?, ssr? } }`; `ssr` only for react-tier, non-client_only components. */
|
|
564
623
|
export async function buildJobs(
|
|
@@ -569,6 +628,8 @@ export async function buildJobs(
|
|
|
569
628
|
stores: string[] = [],
|
|
570
629
|
cssMaps: Map<string, Record<string, string>> = new Map(),
|
|
571
630
|
routeRoots?: ReadonlySet<string>,
|
|
631
|
+
/** F183 (`reachedJobs`): only these entries are written; every one when absent. */
|
|
632
|
+
reached?: { planned: ReadonlySet<string>; ssr: ReadonlySet<string> },
|
|
572
633
|
): Promise<void> {
|
|
573
634
|
const imports: string[] = ["import { createElement } from 'react'", "import { renderToString } from 'react-dom/server'"]
|
|
574
635
|
const entries: string[] = []
|
|
@@ -592,17 +653,20 @@ export async function buildJobs(
|
|
|
592
653
|
for (const c of compiled.values()) {
|
|
593
654
|
const fns: string[] = []
|
|
594
655
|
if (c.serverTs !== undefined) {
|
|
656
|
+
// Staged even when unreached: a parent's fused job imports it (`brust-job:<id>`, R34.96).
|
|
595
657
|
const file = join(dist, 'jobs', `${c.id}.server.ts`)
|
|
596
658
|
write(file, c.serverTs)
|
|
597
659
|
stage(sourceOf, file, c)
|
|
598
|
-
|
|
599
|
-
|
|
660
|
+
if (reached === undefined || reached.planned.has(c.id)) {
|
|
661
|
+
imports.push(`import * as j${n} from ${JSON.stringify(file)}`)
|
|
662
|
+
fns.push(`precompute: j${n}.precompute`)
|
|
663
|
+
}
|
|
600
664
|
}
|
|
601
|
-
if (isReact(c) && !c.ir.tier.React.client_only) {
|
|
665
|
+
if (isReact(c) && !c.ir.tier.React.client_only && (reached === undefined || reached.ssr.has(c.id))) {
|
|
602
666
|
imports.push(componentImport(c, `C${n}`))
|
|
603
667
|
// Ruling 2bf3775a (R1): the island's component id prefixes React's useId on BOTH sides
|
|
604
668
|
// (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)} })`)
|
|
669
|
+
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
670
|
}
|
|
607
671
|
if (fns.length > 0) entries.push(` ${JSON.stringify(c.id)}: { ${fns.join(', ')} },`)
|
|
608
672
|
n++
|
|
@@ -615,7 +679,14 @@ export async function buildJobs(
|
|
|
615
679
|
format: 'esm',
|
|
616
680
|
define: PRODUCTION,
|
|
617
681
|
external: JOBS_EXTERNALS,
|
|
618
|
-
plugins: [
|
|
682
|
+
plugins: [
|
|
683
|
+
jobImportPlugin((id) => (compiled.get(id)?.serverTs !== undefined ? join(dist, 'jobs', `${id}.server.ts`) : undefined)),
|
|
684
|
+
serverOnlyEmptyPlugin(),
|
|
685
|
+
cssPlugin(cssMaps),
|
|
686
|
+
workerStorePlugin,
|
|
687
|
+
sourceDirPlugin(sourceOf, appRoot, JOBS_EXTERNALS),
|
|
688
|
+
exposePlugin(compiled),
|
|
689
|
+
],
|
|
619
690
|
})
|
|
620
691
|
if (!res.success) throw new BuildError('bundle', `jobs: ${res.logs.map(String).join('\n')}`)
|
|
621
692
|
write(join(dist, 'jobs.js'), await res.outputs[0]!.text())
|
package/src/build/compile.ts
CHANGED
|
@@ -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 {
|
package/src/build/index.ts
CHANGED
|
@@ -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, reachedJobs, 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'
|
|
@@ -289,13 +289,14 @@ async function buildInto(
|
|
|
289
289
|
const files = [...new Set((routeCss.get(r.id) ?? []).flatMap((s) => (css.file.has(s) ? [css.file.get(s)!] : [])))]
|
|
290
290
|
if (files.length > 0) r.css = files
|
|
291
291
|
}
|
|
292
|
-
await buildJobs(out, compiled, ctx.sourceOf, appRoot, storeModules(manifest), css.maps, routeRoots)
|
|
292
|
+
await buildJobs(out, compiled, ctx.sourceOf, appRoot, storeModules(manifest), css.maps, routeRoots, reachedJobs(manifest))
|
|
293
293
|
manifest.actions =
|
|
294
294
|
o.actions && o.actionsEntry
|
|
295
295
|
? { entry: await buildActions(out, o.actionsEntry, css.maps), prefix: o.actions.prefix, maxBodyBytes: o.actions.maxBodyBytes, maxResponseBytes: o.actions.maxResponseBytes, crossSite: o.actions.crossSite }
|
|
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')
|
package/src/build/manifest.ts
CHANGED
|
@@ -88,6 +88,33 @@ 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). Only the jobs a request can plan count (`reachedJobs`, F183). */
|
|
99
|
+
export function needsWorkers(m: Pick<ManifestJson, 'routes' | 'components' | 'actions' | 'cache'>): boolean {
|
|
100
|
+
const planned = [...reachedJobs(m).planned].some((id) => (m.components[id]?.jobs.length ?? 0) > 0)
|
|
101
|
+
return planned || m.routes.some((r) => r.loaders.length > 0) || m.actions !== null || m.cache !== undefined
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** F183: the jobs a request can call, as brust-core plans them (`collect_jobs`, pipeline.rs): every job of each
|
|
105
|
+
* route chain component and of each of its direct `children[]` records (`planned`; nothing deeper has a job,
|
|
106
|
+
* `linkNativeChunks`), and the `ssr` of each component one of those jobs targets (`ssr`; the worker runs the
|
|
107
|
+
* target's, handlers.ts). `jobs.js` leaves out every other entry: no request reaches it. */
|
|
108
|
+
export function reachedJobs(m: Pick<ManifestJson, 'routes' | 'components'>): { planned: Set<string>; ssr: Set<string> } {
|
|
109
|
+
const planned = new Set<string>()
|
|
110
|
+
for (const r of m.routes)
|
|
111
|
+
for (const id of r.chain) {
|
|
112
|
+
planned.add(id)
|
|
113
|
+
for (const ch of m.components[id]?.children ?? []) planned.add(ch.id)
|
|
114
|
+
}
|
|
115
|
+
const ssr = new Set<string>()
|
|
116
|
+
for (const id of planned) for (const j of m.components[id]?.jobs ?? []) if (j.kind === 'ssr' && j.target !== undefined) ssr.add(j.target)
|
|
117
|
+
return { planned, ssr }
|
|
91
118
|
}
|
|
92
119
|
|
|
93
120
|
/** `manifest.cache` / `CONFIG.cache`: the adapter the runtime loads (`cache-adapter/load.ts`). */
|
|
@@ -346,6 +373,8 @@ function linkNativeChunks(routes: RouteRecord[], compiled: Map<string, Compiled>
|
|
|
346
373
|
const chainIds = new Set(routes.flatMap((r) => r.chain))
|
|
347
374
|
for (const root of chainIds) {
|
|
348
375
|
const rec = components[root]!
|
|
376
|
+
// A React root renders its whole subtree itself: whatever native chunks its IR lists are not served.
|
|
377
|
+
if (rec.tier === 'react') continue
|
|
349
378
|
const linked = new Set(rec.children.map((ch) => ch.id))
|
|
350
379
|
const seen = new Set([root])
|
|
351
380
|
const walk = (id: string) => {
|
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
|
|
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 <
|
|
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 (${
|
|
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,254 @@
|
|
|
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, lstatSync, 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
|
+
/**
|
|
13
|
+
* The packages the components import (R41.5), each pinned to the exact version the transcript ran
|
|
14
|
+
* (`docs/transcripts/shadcn-init-guide.md`, F181). They move together with `SHADCN_VERSION`: a release that moves one
|
|
15
|
+
* re-runs the transcript. A package the project already depends on, at any version, is left alone.
|
|
16
|
+
*/
|
|
17
|
+
export const SHADCN_DEP_PINS = {
|
|
18
|
+
'radix-ui': '1.8.1',
|
|
19
|
+
'lucide-react': '1.57.0',
|
|
20
|
+
'class-variance-authority': '0.7.1',
|
|
21
|
+
'tw-animate-css': '1.4.0',
|
|
22
|
+
} as const
|
|
23
|
+
export const SHADCN_DEPS = Object.keys(SHADCN_DEP_PINS) as (keyof typeof SHADCN_DEP_PINS)[]
|
|
24
|
+
|
|
25
|
+
/** Runs `argv` in `cwd` with the terminal attached; resolves to the exit code. Never a shell string. */
|
|
26
|
+
export type Runner = (argv: string[], cwd: string) => Promise<number>
|
|
27
|
+
|
|
28
|
+
export interface InitOptions {
|
|
29
|
+
/** Project root (cwd). */
|
|
30
|
+
root: string
|
|
31
|
+
components: string[]
|
|
32
|
+
force?: boolean
|
|
33
|
+
css?: string
|
|
34
|
+
baseColor?: string
|
|
35
|
+
shadcnVersion?: string
|
|
36
|
+
run: Runner
|
|
37
|
+
out: (line: string) => void
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const COMPONENT = /^[a-z0-9][a-z0-9-]*$/
|
|
41
|
+
const REGISTRY_URL = /^https:\/\/[^\s]+$/
|
|
42
|
+
const VERSION = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/
|
|
43
|
+
const COLOR = /^[a-z]+$/
|
|
44
|
+
|
|
45
|
+
/** True for a symlink, also a dangling one (`existsSync` follows links and says false for those). */
|
|
46
|
+
function isLink(path: string): boolean {
|
|
47
|
+
try {
|
|
48
|
+
return lstatSync(path).isSymbolicLink()
|
|
49
|
+
} catch {
|
|
50
|
+
return false
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The name a registry URL installs: its last path segment without `.json`; undefined when it is not a plain name. */
|
|
55
|
+
function urlItemName(url: string): string | undefined {
|
|
56
|
+
try {
|
|
57
|
+
const seg = new URL(url).pathname.split('/').filter(Boolean).pop()?.replace(/\.json$/, '')
|
|
58
|
+
return seg !== undefined && COMPONENT.test(seg) ? seg : undefined
|
|
59
|
+
} catch {
|
|
60
|
+
return undefined
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The `components.json` of the tested fixture (`tests/fixtures/shadcn/components.json`), for `css` and `baseColor` (R41.2). */
|
|
65
|
+
export function componentsJson(css: string, baseColor: string): string {
|
|
66
|
+
return `{
|
|
67
|
+
"$schema": "https://ui.shadcn.com/schema.json",
|
|
68
|
+
"style": "new-york",
|
|
69
|
+
"rsc": false,
|
|
70
|
+
"tsx": true,
|
|
71
|
+
"tailwind": { "config": "", "css": ${JSON.stringify(css)}, "baseColor": ${JSON.stringify(baseColor)}, "cssVariables": true, "prefix": "" },
|
|
72
|
+
"iconLibrary": "lucide",
|
|
73
|
+
"aliases": { "components": "@/components", "utils": "@/lib/utils", "ui": "@/components/ui", "lib": "@/lib", "hooks": "@/hooks" }
|
|
74
|
+
}
|
|
75
|
+
`
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export type PathEdit =
|
|
79
|
+
| { kind: 'added'; text: string }
|
|
80
|
+
| { kind: 'present' }
|
|
81
|
+
| { kind: 'other'; target: string }
|
|
82
|
+
| { kind: 'unparseable'; why: string }
|
|
83
|
+
|
|
84
|
+
const ENTRY = '"@/*": ["./*"]'
|
|
85
|
+
|
|
86
|
+
/** The separator before a non-empty object's first member, so the new entry takes the same line and indent. */
|
|
87
|
+
function lead(text: string, o: ObjectNode): string {
|
|
88
|
+
const first = o.members[0]
|
|
89
|
+
if (!first) return ' '
|
|
90
|
+
const nl = text.lastIndexOf('\n', first.keyStart)
|
|
91
|
+
const indent = nl > o.open ? text.slice(nl + 1, first.keyStart) : ''
|
|
92
|
+
if (nl > o.open && /^\s*$/.test(indent)) return `\n${indent}`
|
|
93
|
+
const same = text.slice(o.open + 1, first.keyStart)
|
|
94
|
+
return /^\s*$/.test(same) ? same : ' '
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Adds `"@/*": ["./*"]` to `compilerOptions.paths` as a text splice (R41.4): comments and layout are kept. */
|
|
98
|
+
export function addAliasPath(text: string): PathEdit {
|
|
99
|
+
let top: ObjectNode
|
|
100
|
+
try {
|
|
101
|
+
top = readObject(text)
|
|
102
|
+
} catch (e) {
|
|
103
|
+
return { kind: 'unparseable', why: (e as Error).message }
|
|
104
|
+
}
|
|
105
|
+
const co = top.members.find((m) => m.key === 'compilerOptions')?.object
|
|
106
|
+
if (!co) return { kind: 'unparseable', why: 'no compilerOptions object' }
|
|
107
|
+
const pathsMember = co.members.find((m) => m.key === 'paths')
|
|
108
|
+
if (!pathsMember) {
|
|
109
|
+
const ws = lead(text, co)
|
|
110
|
+
const body = co.members.length > 0 ? `${ws}"paths": { ${ENTRY} },` : ` "paths": { ${ENTRY} } `
|
|
111
|
+
return { kind: 'added', text: text.slice(0, co.open + 1) + body + text.slice(co.open + 1) }
|
|
112
|
+
}
|
|
113
|
+
const paths = pathsMember.object
|
|
114
|
+
if (!paths) return { kind: 'unparseable', why: 'compilerOptions.paths is not an object' }
|
|
115
|
+
const existing = paths.members.find((m) => m.key === '@/*')
|
|
116
|
+
if (existing) {
|
|
117
|
+
const target = raw(text, existing)
|
|
118
|
+
return target.replace(/\s+/g, '') === '["./*"]' ? { kind: 'present' } : { kind: 'other', target }
|
|
119
|
+
}
|
|
120
|
+
const ws = lead(text, paths)
|
|
121
|
+
const body = paths.members.length > 0 ? `${ws}${ENTRY},` : ` ${ENTRY} `
|
|
122
|
+
return { kind: 'added', text: text.slice(0, paths.open + 1) + body + text.slice(paths.open + 1) }
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** The Tailwind entry CSS: `--css`, else the one top-level `*.css` that imports `tailwindcss` (R41.3). */
|
|
126
|
+
function tailwindEntry(root: string, css: string | undefined): { css: string } | { error: string } {
|
|
127
|
+
if (css !== undefined) {
|
|
128
|
+
const abs = resolve(root, css)
|
|
129
|
+
const rel = relative(root, abs)
|
|
130
|
+
if (css.startsWith('-') || isAbsolute(css) || rel.startsWith('..') || !existsSync(abs)) {
|
|
131
|
+
return { error: `--css ${JSON.stringify(css)} must be an existing CSS file inside the project` }
|
|
132
|
+
}
|
|
133
|
+
return { css: rel.split('\\').join('/') }
|
|
134
|
+
}
|
|
135
|
+
const hit = ['app.css', 'styles.css', 'global.css', 'globals.css', 'index.css'].filter((f) => {
|
|
136
|
+
const p = join(root, f)
|
|
137
|
+
return existsSync(p) && /@import\s+["']tailwindcss["']/.test(readFileSync(p, 'utf8'))
|
|
138
|
+
})
|
|
139
|
+
if (hit.length === 1) return { css: hit[0]! }
|
|
140
|
+
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>` }
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
type Step = 'done' | 'skipped' | 'failed'
|
|
144
|
+
|
|
145
|
+
/** Returns the process exit code: 0 ok, 2 usage / not a brust project, else the failing child's code. */
|
|
146
|
+
export async function shadcnInit(o: InitOptions): Promise<number> {
|
|
147
|
+
const { root, out } = o
|
|
148
|
+
const fail2 = (msg: string): number => {
|
|
149
|
+
out(`error shadcn-init ${msg}`)
|
|
150
|
+
return 2
|
|
151
|
+
}
|
|
152
|
+
// R41.1: a brust project root.
|
|
153
|
+
const pkgPath = join(root, 'package.json')
|
|
154
|
+
if (!existsSync(pkgPath)) return fail2('no package.json here: run it in the root of a brust project')
|
|
155
|
+
let pkg: { dependencies?: Record<string, string>; devDependencies?: Record<string, string> }
|
|
156
|
+
try {
|
|
157
|
+
pkg = JSON.parse(readFileSync(pkgPath, 'utf8'))
|
|
158
|
+
} catch {
|
|
159
|
+
return fail2('package.json is not valid JSON')
|
|
160
|
+
}
|
|
161
|
+
if (!pkg.dependencies?.['@brust/core'] && !pkg.devDependencies?.['@brust/core']) {
|
|
162
|
+
return fail2('package.json does not depend on @brust/core: run it in the root of a brust project')
|
|
163
|
+
}
|
|
164
|
+
// R41.8: validate everything that reaches an argv before anything is written.
|
|
165
|
+
for (const c of o.components) {
|
|
166
|
+
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`)
|
|
167
|
+
}
|
|
168
|
+
const version = o.shadcnVersion ?? SHADCN_VERSION
|
|
169
|
+
if (!VERSION.test(version)) return fail2(`--shadcn-version ${JSON.stringify(version)} must be an exact version like ${SHADCN_VERSION}`)
|
|
170
|
+
const baseColor = o.baseColor ?? 'neutral'
|
|
171
|
+
if (!COLOR.test(baseColor)) return fail2(`--base-color ${JSON.stringify(baseColor)} must be a lowercase colour name`)
|
|
172
|
+
const entry = tailwindEntry(root, o.css)
|
|
173
|
+
if ('error' in entry) return fail2(entry.error)
|
|
174
|
+
// F181: never write through a symlink (the target may be outside the project, e.g. a shared tsconfig). Fail-safe:
|
|
175
|
+
// refuse before the first write, even with --force; the reader edits the real file by hand.
|
|
176
|
+
const cj = join(root, 'components.json')
|
|
177
|
+
const tsPath = join(root, 'tsconfig.json')
|
|
178
|
+
if (isLink(tsPath)) return fail2('tsconfig.json is a symbolic link; refusing to write through it. Add "@/*": ["./*"] to compilerOptions.paths of the real file yourself, then run again')
|
|
179
|
+
if (isLink(cj) && (!existsSync(cj) || o.force)) return fail2('components.json is a symbolic link; refusing to write through it. Replace it with a real file or remove the link, then run again')
|
|
180
|
+
|
|
181
|
+
const report = (name: string, step: Step, why = ''): void => out(`${step === 'done' ? '✓' : step === 'skipped' ? '-' : '✗'} ${name}: ${step}${why ? ` (${why})` : ''}`)
|
|
182
|
+
const stop = (name: string, code: number): number => {
|
|
183
|
+
report(name, 'failed', `exit ${code}`)
|
|
184
|
+
out(`error shadcn-init ${name} failed with exit code ${code}; fix it and run the command again (finished steps are skipped)`)
|
|
185
|
+
return code
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// R41.2: components.json.
|
|
189
|
+
if (!existsSync(cj) || o.force) {
|
|
190
|
+
writeFileSync(cj, componentsJson(entry.css, baseColor))
|
|
191
|
+
report('components.json', 'done', entry.css)
|
|
192
|
+
} else report('components.json', 'skipped', 'exists; --force replaces it')
|
|
193
|
+
|
|
194
|
+
// R41.4: the `@/*` path.
|
|
195
|
+
if (!existsSync(tsPath)) {
|
|
196
|
+
report('tsconfig.json', 'skipped', `no tsconfig.json; add ${JSON.stringify({ compilerOptions: { paths: { '@/*': ['./*'] } } })}`)
|
|
197
|
+
} else {
|
|
198
|
+
const edit = addAliasPath(readFileSync(tsPath, 'utf8'))
|
|
199
|
+
if (edit.kind === 'added') {
|
|
200
|
+
writeFileSync(tsPath, edit.text)
|
|
201
|
+
report('tsconfig.json', 'done', 'added "@/*": ["./*"] under compilerOptions.paths')
|
|
202
|
+
} else if (edit.kind === 'present') report('tsconfig.json', 'skipped', '"@/*" is already there')
|
|
203
|
+
else if (edit.kind === 'other') report('tsconfig.json', 'skipped', `warning: "@/*" already points at ${edit.target}; shadcn's imports need ["./*"]`)
|
|
204
|
+
else report('tsconfig.json', 'skipped', `not edited (${edit.why}); add this line to compilerOptions.paths yourself: ${ENTRY}`)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// R41.5: dependencies.
|
|
208
|
+
const have = { ...pkg.devDependencies, ...pkg.dependencies }
|
|
209
|
+
const missing = SHADCN_DEPS.filter((d) => !have[d])
|
|
210
|
+
if (missing.length === 0) report('dependencies', 'skipped', 'all four are installed')
|
|
211
|
+
else {
|
|
212
|
+
const specs = missing.map((d) => `${d}@${SHADCN_DEP_PINS[d]}`)
|
|
213
|
+
const code = await o.run(['bun', 'add', ...specs], root)
|
|
214
|
+
if (code !== 0) return stop('bun add', code)
|
|
215
|
+
report('dependencies', 'done', specs.join(' '))
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// R41.6 / R41.7: the pinned shadcn CLI. `bun x` is `bunx`; argv only.
|
|
219
|
+
const shadcn = (...args: string[]): string[] => ['bun', 'x', `shadcn@${version}`, ...args]
|
|
220
|
+
const cssText = readFileSync(join(root, entry.css), 'utf8')
|
|
221
|
+
if (cssText.includes('shadcn/tailwind.css') && !o.force) report('theme', 'skipped', `${entry.css} already has the shadcn theme; --force runs it again`)
|
|
222
|
+
else {
|
|
223
|
+
const code = await o.run(shadcn('add', 'index', '-y'), root)
|
|
224
|
+
if (code !== 0) return stop('shadcn add index', code)
|
|
225
|
+
report('theme', 'done', `shadcn@${version} add index`)
|
|
226
|
+
}
|
|
227
|
+
// A component whose file is already in components/ui is not added again (idempotent). A registry URL is judged by
|
|
228
|
+
// the item name in its path (`.../acme-card.json` → `acme-card`), looked up in components/ui and components.
|
|
229
|
+
const present = (c: string): boolean => {
|
|
230
|
+
const name = REGISTRY_URL.test(c) ? urlItemName(c) : c
|
|
231
|
+
if (name === undefined) return false
|
|
232
|
+
return existsSync(join(root, 'components/ui', `${name}.tsx`)) || (name !== c && existsSync(join(root, 'components', `${name}.tsx`)))
|
|
233
|
+
}
|
|
234
|
+
const todo = o.components.filter((c) => o.force || !present(c))
|
|
235
|
+
for (const c of o.components) if (!todo.includes(c)) report(c, 'skipped', REGISTRY_URL.test(c) ? 'its item is already in components; --force adds it again' : 'components/ui already has it')
|
|
236
|
+
for (const c of todo) if (REGISTRY_URL.test(c)) out(`warning shadcn-init ${c} is third-party code: it is written into your project and runs in your build and in the browser. Read it before you ship`)
|
|
237
|
+
if (todo.length > 0) {
|
|
238
|
+
const code = await o.run(shadcn('add', ...todo, '-y'), root)
|
|
239
|
+
if (code !== 0) return stop(`shadcn add ${todo.join(' ')}`, code)
|
|
240
|
+
for (const c of todo) report(c, 'done')
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
out('')
|
|
244
|
+
out('next:')
|
|
245
|
+
out(" import the components from './components/ui/<name>' in a page and add the route to routes.tsx")
|
|
246
|
+
out(' bun run build')
|
|
247
|
+
return 0
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** The real runner: argv spawn with the terminal attached, no shell. */
|
|
251
|
+
export const spawnRunner: Runner = async (argv, cwd) => {
|
|
252
|
+
const p = Bun.spawn(argv, { cwd, stdin: 'inherit', stdout: 'inherit', stderr: 'inherit' })
|
|
253
|
+
return await p.exited
|
|
254
|
+
}
|
|
@@ -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
|
+
}
|