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