@barqjs/compiler 0.0.0-stage → 0.2.0-next.0

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/index.d.ts ADDED
@@ -0,0 +1,563 @@
1
+ /* auto-generated by NAPI-RS */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * One entry of `boundaries`: a component whose JSX children render through
6
+ * another renderer than the JSX around it, the way a canvas component hosts a
7
+ * scene graph inside a document.
8
+ */
9
+ export interface BoundaryEntry {
10
+ /** The module the component is imported from. */
11
+ source: string
12
+ /** The name it is exported under. */
13
+ name: string
14
+ /** `"dom"` or `"universal"`: what its children compile for. */
15
+ target: string
16
+ /** The module its children import the renderer's helpers from. */
17
+ moduleSource: string
18
+ }
19
+
20
+ export declare function diagnosticCodes(): Array<JsCode>
21
+
22
+ /**
23
+ * One entry of `intrinsics`: lowercase tags a renderer claims, so a JSX tree
24
+ * rooted at one of them builds through that renderer wherever it is written.
25
+ */
26
+ export interface IntrinsicEntry {
27
+ tags: Array<string>
28
+ /**
29
+ * Also claim a lowercase tag without a hyphen that no renderer names and
30
+ * the document does not have.
31
+ * @default false
32
+ */
33
+ claimUnknown?: boolean
34
+ /** `"dom"` or `"universal"`. */
35
+ target: string
36
+ /** The module the claimed elements import the renderer's helpers from. */
37
+ moduleSource: string
38
+ }
39
+
40
+ /**
41
+ * Every diagnostic this build can raise, with its default level and its docs
42
+ * page. One resolution of the code table, shared by the Vite plugin and any
43
+ * CLI, so a listing cannot drift from what the compiler actually emits.
44
+ */
45
+ export interface JsCode {
46
+ code: string
47
+ level: string
48
+ summary: string
49
+ docs: string
50
+ }
51
+
52
+ /**
53
+ * One diagnostic, as structured data. The span survives the boundary: `pos` is
54
+ * what Rollup's `this.warn(warning, position)` takes, and that argument is the
55
+ * only thing that produces `pos`/`loc`/`frame`. Flattening this to a string is
56
+ * what left the pipeline with no code frame anywhere, in any mode.
57
+ */
58
+ export interface JsDiagnostic {
59
+ /** `BARQ001`; absent for a parser diagnostic, which is oxc's code space. */
60
+ code?: string
61
+ /** `note` | `warning` | `error` */
62
+ severity: string
63
+ message: string
64
+ file: string
65
+ /** 1-based */
66
+ line: number
67
+ /** 1-based, UTF-16 code units — what a source map counts */
68
+ column: number
69
+ endLine: number
70
+ endColumn: number
71
+ /**
72
+ * UTF-16 offset into the ORIGINAL source, which is the string index
73
+ * Rollup's `position` takes
74
+ */
75
+ pos: number
76
+ end: number
77
+ /** path of the docs page for this code, relative to the package root */
78
+ docs?: string
79
+ }
80
+
81
+ /** A dev-mode label: which JSX, in which component, produced a hoisted template. */
82
+ export interface JsTemplateLabel {
83
+ template: string
84
+ component?: string
85
+ line: number
86
+ column: number
87
+ }
88
+
89
+ /**
90
+ * The cascade layer order `sheets` between them declare, as one list.
91
+ *
92
+ * Read from the modules the compiler emitted rather than from the built
93
+ * assets, because a minifier has rewritten the statement by then: Lightning
94
+ * CSS drops the names that have a block in the same file, which is sound
95
+ * within one sheet and loses the order across several.
96
+ */
97
+ export declare function layerOrder(sheets: Array<string>): Array<string>
98
+
99
+ /**
100
+ * The CLIENT half of a module that declares middleware: `.server(…)` deleted,
101
+ * and any top-level declaration only it reached deleted with it.
102
+ *
103
+ * Returns the source unchanged when there is nothing to strip, so a caller can
104
+ * hand every module through without asking first.
105
+ *
106
+ * `middleware_split.rs` says why this has to exist: a middleware's client half
107
+ * runs in the browser, so the client stub imports the module that declares it —
108
+ * and a module holding a session check reaches whatever that check needs. The
109
+ * same import through a route's `middleware` once left a fully server-rendered
110
+ * page on which nothing was interactive.
111
+ */
112
+ export declare function middlewareSplit(source: string, filename: string, startSource?: string | undefined | null): string
113
+
114
+ /**
115
+ * The `Backend` trait's whole instruction set, by `Op` variant name, generated
116
+ * from the same macro list the trait and its dispatch are generated from
117
+ * (`codegen::backend::OPS`).
118
+ *
119
+ * It crosses the boundary so the reference backend's JS half can be checked
120
+ * against it in BOTH directions. Rust exhaustiveness makes a new `Op` a compile
121
+ * error in every `impl Backend`; nothing in the language can make it a compile
122
+ * error in `interp.ts`, so the name sets are asserted equal instead — the same
123
+ * bidirectional pinning discipline the rule IDs use.
124
+ */
125
+ export declare function opcodes(): Array<string>
126
+
127
+ /**
128
+ * A bundled stylesheet with its atoms ordered by tier.
129
+ *
130
+ * The compiler emits one stylesheet per MODULE and a bundler concatenates them
131
+ * in import order, so an atom's tier — the one thing that settles a base rule
132
+ * against the same property under an at-rule, since `@media` adds no
133
+ * specificity — held inside one `atoms` call and nowhere else. `collectCss`
134
+ * has always sorted globally, so dev was right and the production bundle was
135
+ * not; this is the same sort over the concatenated asset.
136
+ *
137
+ * Not a cascade layer, and it must never become one. A layer overrides
138
+ * specificity outright where a tier is a tie-breaker on top of it: measured in
139
+ * a browser, one sub-layer per tier moved 289 computed values on `@barqjs/ui`'s
140
+ * gallery and reordering moves 8, every one of them a rule under an at-rule
141
+ * that a later base rule was beating.
142
+ *
143
+ * `layers` is the document's cascade layer order, and it is declared in front
144
+ * of every asset that names a layer at all. A layer's position is fixed by its
145
+ * FIRST appearance across every stylesheet the page loads, so a code-split
146
+ * build cannot leave the statement in whichever chunk its module landed in:
147
+ * the chunk carrying `@layer barq.ui{ … }` may well be linked first, and then
148
+ * the components sit in front of the reset and Tailwind's preflight beats
149
+ * them. Repeating the statement is idempotent by specification.
150
+ *
151
+ * Idempotent, and safe over a stylesheet holding none of ours: a rule that is
152
+ * not an atom keeps its index.
153
+ */
154
+ export declare function orderCss(css: string, layers?: Array<string> | undefined | null): string
155
+
156
+ /**
157
+ * One entry of `renderers`: the files it matches compile for its target,
158
+ * importing from its module.
159
+ */
160
+ export interface RendererEntry {
161
+ /**
162
+ * Globs matched against the file name: `*` within one path segment, `**`
163
+ * across segments. A pattern that does not start with `/` matches at any
164
+ * directory, so `src/scene/**` matches `/home/salama/app/src/scene/a.tsx`.
165
+ */
166
+ include: Array<string>
167
+ /**
168
+ * `"dom"` or `"universal"`.
169
+ * @default `"universal"`
170
+ */
171
+ target?: string
172
+ /**
173
+ * The module these files import the renderer's helpers from.
174
+ * @default the top-level `moduleSource`
175
+ */
176
+ moduleSource?: string
177
+ }
178
+
179
+ /**
180
+ * One route's id and the source file it came from.
181
+ *
182
+ * The route table itself carries `src` per node, but a build wants the mapping
183
+ * WITHOUT parsing the module it just generated — a second reader of our own
184
+ * emit is a second thing to keep in step. `<link rel="modulepreload">` and the
185
+ * route-action manifest both start from this.
186
+ */
187
+ export interface RouteEntry {
188
+ /** The route id, as `RouteMap` keys it. */
189
+ id: string
190
+ /** Project-relative source path, without the leading slash the module uses. */
191
+ file: string
192
+ }
193
+
194
+ /**
195
+ * A route file whose id literal is out of date.
196
+ *
197
+ * The literal is generator-owned: it is derived from the filename, so a rename
198
+ * makes it wrong and hand-maintaining it is the chore `createFileRoute` exists
199
+ * to remove.
200
+ */
201
+ export interface RouteIdMismatch {
202
+ /** Project-relative source path. */
203
+ file: string
204
+ /** What the file says. */
205
+ declared: string
206
+ /** What its name derives. */
207
+ expected: string
208
+ }
209
+
210
+ /**
211
+ * Split a route module into the half the tree imports and the half it loads.
212
+ *
213
+ * The static route table is what makes a file route able to declare the whole
214
+ * option set — the router reads `validateSearch`, `beforeLoad` and the cache
215
+ * options synchronously — and the price is an eager component. This is where
216
+ * that price is paid back, and it is where TanStack pays it too
217
+ * (`router-plugin/src/core/constants.ts:4-16`).
218
+ *
219
+ * `specifier` is what the reference half will `import()`. The caller owns that
220
+ * spelling because the BUNDLER decides what a module id looks like, not the
221
+ * compiler.
222
+ *
223
+ * `for_client` also DELETES the `server` option, which holds a route's HTTP
224
+ * handlers. Without it a handler's body — and whatever it imports to reach a
225
+ * database — sits in the browser bundle. Theirs deletes the same node.
226
+ */
227
+ export declare function routeSplit(source: string, filename: string, specifier: string, forClient?: boolean | undefined | null, splitComponents?: boolean | undefined | null, coreSource?: string | undefined | null): RouteSplitResult
228
+
229
+ /** Both halves of a code-split route module. */
230
+ export interface RouteSplitResult {
231
+ /**
232
+ * The module the generated tree imports, with each split value replaced by
233
+ * a `lazy()` over the other half.
234
+ */
235
+ reference: string
236
+ /** The module `<file>?barq-split` serves. */
237
+ split: string
238
+ /**
239
+ * Why the route was NOT split. Both halves are the original source in that
240
+ * case, so a refusal costs bytes and never correctness.
241
+ */
242
+ refused?: string
243
+ }
244
+
245
+ /**
246
+ * Scan a directory of route files and emit the table and its types.
247
+ *
248
+ * The whole of file-based routing, in one call. The plugin asks and
249
+ * invalidates; it does not read the directory, derive a route from a filename,
250
+ * or build a string — so a route table cannot mean two things.
251
+ *
252
+ * `out_file` is where the caller will write `source`, project-relative — the
253
+ * import specifiers it emits are relative to that file's own directory.
254
+ *
255
+ * `write_ids` is the one thing here that TOUCHES the project: a route's id
256
+ * literal is generator-owned, so a rename makes it wrong, and dev rewrites it
257
+ * in place the way their plugin does (`transform.ts:133-140`). A BUILD does
258
+ * not — it reports the disagreement instead, so CI cannot pass on a file the
259
+ * build silently edited.
260
+ */
261
+ export declare function routeTree(root: string, dir: string, outFile?: string | undefined | null, writeIds?: boolean | undefined | null): RouteTreeResult
262
+
263
+ /** The generated route table, its types, and what produced them. */
264
+ export interface RouteTreeResult {
265
+ /**
266
+ * The contents of `routeTree.gen.ts` — the table AND its types.
267
+ *
268
+ * One file rather than a virtual module plus a `.d.ts`, which is
269
+ * TanStack's arrangement, whose generated tree defaults to
270
+ * `./src/routeTree.gen.ts`. The caller writes it where `out_file` said.
271
+ */
272
+ source: string
273
+ /**
274
+ * Every route file found, project-relative. The caller registers these
275
+ * with its watcher — file EVENTS are the one part of this that cannot move
276
+ * into the compiler, because the bundler owns them.
277
+ */
278
+ files: Array<string>
279
+ /** Every leaf pattern, which is what `routes` wants for `BARQ013`. */
280
+ patterns: Array<string>
281
+ /** Route id to source file, layouts included, for the build-time checks. */
282
+ entries: Array<RouteEntry>
283
+ /**
284
+ * Declarations a route made that are present but not literals. The caller
285
+ * reports these; the table cannot carry them and will not guess.
286
+ */
287
+ warnings: Array<string>
288
+ /**
289
+ * Route files whose `createFileRoute` id literal disagrees with the id
290
+ * their FILENAME derives, and that were not rewritten. Empty when
291
+ * `writeIds` asked for the rewrite and it succeeded.
292
+ */
293
+ mismatches: Array<RouteIdMismatch>
294
+ /** Route files whose id literal was rewritten on disk this call. */
295
+ rewritten: Array<string>
296
+ }
297
+
298
+ export declare function transform(code: string, options?: TransformOptions | undefined | null): TransformResult
299
+
300
+ /**
301
+ * `autoComputed` and the three component NAME LISTS the deleted Babel plugin
302
+ * took are not here and will not be. Nothing in this compiler could read them —
303
+ * every component and every reactive read resolves by `SymbolId` in P0,
304
+ * and `autoComputed` rewrote statements OUTSIDE JSX, which this pipeline never
305
+ * touches: lowering takes no `Program` and codegen only splices at the sites
306
+ * harvest recorded.
307
+ */
308
+ export interface TransformOptions {
309
+ filename?: string
310
+ sourcemap?: boolean
311
+ /**
312
+ * Module source for the renderer's helpers. Under `target: "universal"`
313
+ * it is the module that exports what `createRenderer` returned.
314
+ * @default `@barqjs/web`
315
+ */
316
+ moduleSource?: string
317
+ /**
318
+ * `"dom"` or `"universal"`. `"universal"` compiles for a renderer made
319
+ * with `@barqjs/universal`'s `createRenderer`, imported from
320
+ * `moduleSource`. `ssr`, `hydratable` and `interp` are document
321
+ * concepts, and asking for one of them with it is an error.
322
+ * @default `"dom"`
323
+ */
324
+ target?: string
325
+ /**
326
+ * Per-file renderer selection: a file matching an entry's `include`
327
+ * compiles for that entry's target and module, whatever `target`,
328
+ * `moduleSource`, `ssr` and `hydratable` say for the rest of the build.
329
+ * The first entry that matches wins.
330
+ */
331
+ renderers?: Array<RendererEntry>
332
+ /**
333
+ * Components whose children compile for another renderer. A JSX element
334
+ * whose tag is the import `name` from `source` compiles for the module's
335
+ * own target, and its children for the entry's `target` and
336
+ * `moduleSource`. Boundaries nest.
337
+ */
338
+ boundaries?: Array<BoundaryEntry>
339
+ /**
340
+ * Intrinsic tags a renderer claims. A tree of intrinsic elements outside
341
+ * every boundary whose root tag one entry claims, and the document does
342
+ * not have, compiles for that entry's `target` and `moduleSource`.
343
+ */
344
+ intrinsics?: Array<IntrinsicEntry>
345
+ /**
346
+ * Module source for the helpers every target shares and for the
347
+ * components and primitives an author imports.
348
+ * @default `@barqjs/core`
349
+ */
350
+ coreSource?: string
351
+ /**
352
+ * Module source for the string backend's helpers.
353
+ * @default `@barqjs/server`
354
+ */
355
+ serverSource?: string
356
+ /**
357
+ * Module source for `createServerFn`.
358
+ * @default `@barqjs/start`
359
+ */
360
+ startSource?: string
361
+ /**
362
+ * Where the emitted CLIENT stub imports `clientRpc` from. Not the same
363
+ * module as {@link start_source} — see `DEFAULT_CLIENT_SOURCE`.
364
+ * @default `@barqjs/start/client`
365
+ */
366
+ clientSource?: string
367
+ /**
368
+ * Module source for `Link` and `NavLink`.
369
+ * @default `@barqjs/router`
370
+ */
371
+ routerSource?: string
372
+ /**
373
+ * Module source for `css`, `keyframes` and `globalCss`.
374
+ * @default `@barqjs/css`
375
+ */
376
+ cssSource?: string
377
+ /**
378
+ * Every route pattern in the project, for `BARQ013` to check `<Link to>`
379
+ * against. The compiler sees ONE module; the route set is a whole-project
380
+ * fact, so it arrives as an option rather than being discovered.
381
+ *
382
+ * Absent (rather than empty) turns the check off, so a project without a
383
+ * route table does not get a warning on every link it writes.
384
+ */
385
+ routes?: Array<string>
386
+ /**
387
+ * `"client"` or `"server"`. Picks which half of the program this module is
388
+ * being compiled for, which is a different question from `ssr`'s backend.
389
+ * @default `"server"`
390
+ */
391
+ env?: string
392
+ /**
393
+ * Project root. Server-function ids are derived relative to it, so an id
394
+ * carries no absolute path — RedwoodSDK ships `/src/path.ts#name` verbatim
395
+ * in its client bundle, which hands an attacker the source tree layout.
396
+ */
397
+ root?: string
398
+ /**
399
+ * Emit the module's server-function exports alongside the code. A side
400
+ * artefact on the same terms as `ownership` and `addresses`: nothing it
401
+ * produces reaches lowering, the passes or codegen, so `code` is
402
+ * byte-identical either way.
403
+ */
404
+ serverFns?: boolean
405
+ dev?: boolean
406
+ templates?: boolean
407
+ ssr?: boolean
408
+ /**
409
+ * Emit for the reference backend instead of the DOM
410
+ * backend: the analysed IR is serialised beside the module and
411
+ * `@barqjs/web/interp` walks it. DEV and test only. Wins over `ssr`,
412
+ * because the two are different backends over the same IR and asking for
413
+ * both is a caller bug rather than a blend.
414
+ */
415
+ interp?: boolean
416
+ /**
417
+ * Run the source-level diagnostic rules (D1, D3). Defaults to `dev`: they
418
+ * are advice about reactivity, they are delivered through the dev channels,
419
+ * and a production build should not pay for analysis nobody reads. Set it
420
+ * explicitly to run them in CI.
421
+ */
422
+ diagnostics?: boolean
423
+ /**
424
+ * Per-code severity, `[[code, category]]`. `category` is one of `suppress`,
425
+ * `note`, `warning`, `error`. napi has no map type, so this is pairs.
426
+ */
427
+ checks?: Array<Array<string>>
428
+ /**
429
+ * Report what this module EXPORTS that another could fold against, and do
430
+ * it even when the module writes no CSS of its own.
431
+ *
432
+ * Off by default, because a normal transform has no use for it: an
433
+ * integration turns it on only for a file some other file imports from.
434
+ * @default false
435
+ */
436
+ cssExports?: boolean
437
+ /**
438
+ * What this module's imports resolve to, which an integration looked up
439
+ * and this compiler did not.
440
+ *
441
+ * `[specifier, exported name, kind, member, value]`, where `kind` is
442
+ * `text`, `group` or `layer` and `member` is the group key or empty. napi
443
+ * has no map type, so this is tuples.
444
+ *
445
+ * The pass stays a pure function of its inputs: it reads no file, it only
446
+ * reports which one it would have to (`cssImportsWanted`) and folds what
447
+ * it is handed. That is what keeps dev and a build identical — a name
448
+ * resolves to the same value in both, where StyleX's aggregate over every
449
+ * module does not.
450
+ */
451
+ cssImports?: Array<Array<string>>
452
+ /**
453
+ * Every CSS diagnostic is an error, so a call `@barqjs/css`'s runtime
454
+ * would have to evaluate fails the build instead.
455
+ *
456
+ * The point is what it makes provable rather than what it forbids: with
457
+ * no call falling back, nothing reaches the runtime's object walk, and a
458
+ * build can drop it. An explicit `checks` entry still wins over this.
459
+ * @default false
460
+ */
461
+ strictCss?: boolean
462
+ /** The category every code takes when `checks` does not name it. */
463
+ defaultCategory?: string
464
+ /**
465
+ * Emit the static ownership tree alongside the
466
+ * code. It is a side artefact: no field it produces reaches lowering, the
467
+ * passes or codegen, so `code` is byte-identical either way. Off by
468
+ * default — a production compile does not pay for the extra AST walk.
469
+ */
470
+ ownership?: boolean
471
+ /**
472
+ * Emit the compile-time address table alongside the code. A side artefact
473
+ * on the same terms as `ownership`: nothing it produces reaches lowering,
474
+ * the passes or codegen, so `code` is byte-identical either way. Its point
475
+ * is that the DOM and the string backend can be compiled from one source
476
+ * and their address sets diffed.
477
+ */
478
+ addresses?: boolean
479
+ /**
480
+ * Emit for CLAIM-BASED HYDRATION.
481
+ *
482
+ * Unlike `ownership` and `addresses` this one DOES change the emitted
483
+ * module, on both backends, and that is the point: the
484
+ * string backend writes `<!--[-->` … `<!--]-->` at every hole and
485
+ * `<!--[k-->` at every range, and the DOM backend walks through `child`
486
+ * and `sib` — a hydration-only logical index that steps over those ranges
487
+ * — instead of `.firstChild`/`.nextSibling`.
488
+ *
489
+ * Off by default, so a page that is never hydrated pays neither the wire
490
+ * bytes nor the indirection. H3's falsification procedure is exactly the
491
+ * diff between the two settings.
492
+ */
493
+ hydratable?: boolean
494
+ /**
495
+ * The optimisation level. `0` turns every optimisation off and is the
496
+ * oracle's reference; anything else is the optimising
497
+ * path, which is the default. It changes no semantics — `-O0` output is
498
+ * slower and larger and never different.
499
+ */
500
+ optimize?: number
501
+ /**
502
+ * Per-pass override on top of `optimize`, `[[name, "on"|"off"]]`. napi has
503
+ * no map type, so this is pairs. The names are `fold`, `dedup`, `anchor`,
504
+ * `fuse`, `walk`, `eta`, `hoist`, `splice`, `flow` — one flag per
505
+ * optimisation, because the -O0/-Ox differential's payoff is that every
506
+ * optimisation is individually bisectable.
507
+ */
508
+ passes?: Array<Array<string>>
509
+ }
510
+
511
+ export interface TransformResult {
512
+ code: string
513
+ map?: string
514
+ /**
515
+ * Every diagnostic, formatted as `file:line:col: CODE level: message`.
516
+ * Kept alongside `diagnostics` because a string is what a plain `this.warn`
517
+ * and a console sink both want; `diagnostics` is what a code frame needs.
518
+ */
519
+ warnings: Array<string>
520
+ diagnostics: Array<JsDiagnostic>
521
+ /** Populated under `dev` only. */
522
+ labels: Array<JsTemplateLabel>
523
+ /**
524
+ * The static ownership tree as JSON, under `ownership: true` only.
525
+ * The oracle's expected value, derived from the source rather than from a
526
+ * second execution.
527
+ */
528
+ ownership?: string
529
+ /**
530
+ * This module's export surface and which exports are server functions, as
531
+ * JSON, under `serverFns: true` only. The build reads it to know what to
532
+ * mount, and a reviewer reads it to see what is public.
533
+ */
534
+ serverFns?: string
535
+ /**
536
+ * The compile-time address table as JSON, under `addresses: true` only.
537
+ * `(module, unit, position)` for every
538
+ * position in the module, computed identically by every backend.
539
+ */
540
+ addresses?: string
541
+ /**
542
+ * This module's stylesheet, when it wrote any `css`. The build serves it
543
+ * from a virtual module the transformed code imports, so the bundler owns
544
+ * dev invalidation, the production asset and SSR collection — and one file
545
+ * edited invalidates one file's CSS.
546
+ */
547
+ css?: string
548
+ /**
549
+ * `[specifier, exported name]` for every imported binding a fold needed
550
+ * and did not have.
551
+ *
552
+ * Empty when the module folded on its own, which is the point: an
553
+ * integration resolves these and calls `transform` again with
554
+ * `cssImports`, so it pays for resolution only where it buys a fold.
555
+ */
556
+ cssWanted: Array<Array<string>>
557
+ /**
558
+ * `[exported name, kind, member, value]` for what this module exports that
559
+ * another can fold against, under `cssExports: true` or whenever the
560
+ * module writes CSS. `kind` is `text`, `number`, `group` or `layer`.
561
+ */
562
+ cssExports: Array<Array<string>>
563
+ }
package/index.js ADDED
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+
3
+ const { existsSync, readFileSync } = require("node:fs");
4
+ const { join } = require("node:path");
5
+
6
+ const { name, version } = require("./package.json");
7
+
8
+ const PREBUILT = [
9
+ "darwin-arm64",
10
+ "darwin-x64",
11
+ "linux-arm64-gnu",
12
+ "linux-x64-gnu",
13
+ "linux-x64-musl",
14
+ "win32-arm64-msvc",
15
+ "win32-x64-msvc",
16
+ ];
17
+
18
+ function isMusl() {
19
+ try {
20
+ return readFileSync("/usr/bin/ldd", "utf8").includes("musl");
21
+ } catch {
22
+ const report = typeof process.report?.getReport === "function" ? process.report.getReport() : null;
23
+ return report !== null && !report.header?.glibcVersionRuntime;
24
+ }
25
+ }
26
+
27
+ function platformKey() {
28
+ const { platform, arch } = process;
29
+ if (platform === "linux") return `linux-${arch}-${isMusl() ? "musl" : "gnu"}`;
30
+ if (platform === "win32") return `win32-${arch}-msvc`;
31
+ return `${platform}-${arch}`;
32
+ }
33
+
34
+ function load() {
35
+ const key = platformKey();
36
+
37
+ // A binary beside this file can only be a local `napi build`: `files` does
38
+ // not ship one. It wins over the installed platform package, and a broken one
39
+ // is an error rather than a fallback, so the workspace never silently tests
40
+ // the last published compiler.
41
+ const local = join(__dirname, `barq-compiler.${key}.node`);
42
+ if (existsSync(local)) return require(local);
43
+
44
+ const pkg = `${name}-${key}`;
45
+ if (!PREBUILT.includes(key)) {
46
+ throw new Error(
47
+ `${name} has no prebuilt native binding for ${key}. Prebuilt bindings exist for ` +
48
+ `${PREBUILT.join(", ")}. On another platform, build one from source with a Rust ` +
49
+ "toolchain: `napi build --platform --release --no-js` in this package's directory.",
50
+ );
51
+ }
52
+
53
+ let resolved;
54
+ try {
55
+ resolved = require.resolve(pkg);
56
+ } catch (error) {
57
+ if (error?.code !== "MODULE_NOT_FOUND") throw error;
58
+ throw new Error(
59
+ `${name} could not find its native binding for ${key}: the optional dependency ${pkg} ` +
60
+ "is not installed. Package managers skip it when optional dependencies are disabled " +
61
+ "(--no-optional, --omit=optional) or when the lockfile was written on another platform. " +
62
+ "Reinstall with optional dependencies enabled.",
63
+ { cause: error },
64
+ );
65
+ }
66
+
67
+ const installed = require(`${pkg}/package.json`).version;
68
+ if (installed !== version) {
69
+ throw new Error(
70
+ `${name}@${version} found ${pkg}@${installed}; the two are released together and must ` +
71
+ "match. Reinstall so the lockfile resolves both to the same version.",
72
+ );
73
+ }
74
+ return require(resolved);
75
+ }
76
+
77
+ const binding = load();
78
+
79
+ // One static assignment per export: node's CommonJS-to-ESM bridge finds named
80
+ // exports by scanning for this shape, so `import { transform }` needs it.
81
+
82
+ module.exports.diagnosticCodes = binding.diagnosticCodes;
83
+ module.exports.layerOrder = binding.layerOrder;
84
+ module.exports.middlewareSplit = binding.middlewareSplit;
85
+ module.exports.opcodes = binding.opcodes;
86
+ module.exports.orderCss = binding.orderCss;
87
+ module.exports.routeSplit = binding.routeSplit;
88
+ module.exports.routeTree = binding.routeTree;
89
+ module.exports.transform = binding.transform;