bun-types 1.1.39-canary.20241208T140533 → 1.1.39-canary.20241210T140601
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/bun.d.ts +20 -0
- package/docs/bundler/index.md +107 -0
- package/docs/guides/test/testing-library.md +2 -2
- package/package.json +1 -1
package/bun.d.ts
CHANGED
|
@@ -1605,6 +1605,26 @@ declare module "bun" {
|
|
|
1605
1605
|
* https://nodejs.org/api/packages.html#exports
|
|
1606
1606
|
*/
|
|
1607
1607
|
conditions?: Array<string> | string;
|
|
1608
|
+
|
|
1609
|
+
/**
|
|
1610
|
+
* Controls how environment variables are handled during bundling.
|
|
1611
|
+
*
|
|
1612
|
+
* Can be one of:
|
|
1613
|
+
* - `"inline"`: Injects environment variables into the bundled output by converting `process.env.FOO`
|
|
1614
|
+
* references to string literals containing the actual environment variable values
|
|
1615
|
+
* - `"disable"`: Disables environment variable injection entirely
|
|
1616
|
+
* - A string ending in `*`: Inlines environment variables that match the given prefix.
|
|
1617
|
+
* For example, `"MY_PUBLIC_*"` will only include env vars starting with "MY_PUBLIC_"
|
|
1618
|
+
*
|
|
1619
|
+
* @example
|
|
1620
|
+
* ```ts
|
|
1621
|
+
* Bun.build({
|
|
1622
|
+
* env: "MY_PUBLIC_*",
|
|
1623
|
+
* entrypoints: ["src/index.ts"],
|
|
1624
|
+
* })
|
|
1625
|
+
* ```
|
|
1626
|
+
*/
|
|
1627
|
+
env?: "inline" | "disable" | `${string}*`;
|
|
1608
1628
|
minify?:
|
|
1609
1629
|
| boolean
|
|
1610
1630
|
| {
|
package/docs/bundler/index.md
CHANGED
|
@@ -546,6 +546,113 @@ export type ImportKind =
|
|
|
546
546
|
|
|
547
547
|
By design, the manifest is a simple JSON object that can easily be serialized or written to disk. It is also compatible with esbuild's [`metafile`](https://esbuild.github.io/api/#metafile) format. -->
|
|
548
548
|
|
|
549
|
+
### `env`
|
|
550
|
+
|
|
551
|
+
Controls how environment variables are handled during bundling. Internally, this uses `define` to inject environment variables into the bundle, but makes it easier to specify the environment variables to inject.
|
|
552
|
+
|
|
553
|
+
#### `env: "inline"`
|
|
554
|
+
|
|
555
|
+
Injects environment variables into the bundled output by converting `process.env.FOO` references to string literals containing the actual environment variable values.
|
|
556
|
+
|
|
557
|
+
{% codetabs group="a" %}
|
|
558
|
+
|
|
559
|
+
```ts#JavaScript
|
|
560
|
+
await Bun.build({
|
|
561
|
+
entrypoints: ['./index.tsx'],
|
|
562
|
+
outdir: './out',
|
|
563
|
+
env: "inline",
|
|
564
|
+
})
|
|
565
|
+
```
|
|
566
|
+
|
|
567
|
+
```bash#CLI
|
|
568
|
+
$ FOO=bar BAZ=123 bun build ./index.tsx --outdir ./out --env inline
|
|
569
|
+
```
|
|
570
|
+
|
|
571
|
+
{% /codetabs %}
|
|
572
|
+
|
|
573
|
+
For the input below:
|
|
574
|
+
|
|
575
|
+
```js#input.js
|
|
576
|
+
console.log(process.env.FOO);
|
|
577
|
+
console.log(process.env.BAZ);
|
|
578
|
+
```
|
|
579
|
+
|
|
580
|
+
The generated bundle will contain the following code:
|
|
581
|
+
|
|
582
|
+
```js#output.js
|
|
583
|
+
console.log("bar");
|
|
584
|
+
console.log("123");
|
|
585
|
+
```
|
|
586
|
+
|
|
587
|
+
#### `env: "PUBLIC_*"` (prefix)
|
|
588
|
+
|
|
589
|
+
Inlines environment variables matching the given prefix (the part before the `*` character), replacing `process.env.FOO` with the actual environment variable value. This is useful for selectively inlining environment variables for things like public-facing URLs or client-side tokens, without worrying about injecting private credentials into output bundles.
|
|
590
|
+
|
|
591
|
+
{% codetabs group="a" %}
|
|
592
|
+
|
|
593
|
+
```ts#JavaScript
|
|
594
|
+
await Bun.build({
|
|
595
|
+
entrypoints: ['./index.tsx'],
|
|
596
|
+
outdir: './out',
|
|
597
|
+
|
|
598
|
+
// Inline all env vars that start with "ACME_PUBLIC_"
|
|
599
|
+
env: "ACME_PUBLIC_*",
|
|
600
|
+
})
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
```bash#CLI
|
|
604
|
+
$ FOO=bar BAZ=123 ACME_PUBLIC_URL=https://acme.com bun build ./index.tsx --outdir ./out --env 'ACME_PUBLIC_*'
|
|
605
|
+
```
|
|
606
|
+
|
|
607
|
+
{% /codetabs %}
|
|
608
|
+
|
|
609
|
+
For example, given the following environment variables:
|
|
610
|
+
|
|
611
|
+
```bash
|
|
612
|
+
$ FOO=bar BAZ=123 ACME_PUBLIC_URL=https://acme.com
|
|
613
|
+
```
|
|
614
|
+
|
|
615
|
+
And source code:
|
|
616
|
+
|
|
617
|
+
```ts#index.tsx
|
|
618
|
+
console.log(process.env.FOO);
|
|
619
|
+
console.log(process.env.ACME_PUBLIC_URL);
|
|
620
|
+
console.log(process.env.BAZ);
|
|
621
|
+
```
|
|
622
|
+
|
|
623
|
+
The generated bundle will contain the following code:
|
|
624
|
+
|
|
625
|
+
```js
|
|
626
|
+
console.log(process.env.FOO);
|
|
627
|
+
console.log("https://acme.com");
|
|
628
|
+
console.log(process.env.BAZ);
|
|
629
|
+
```
|
|
630
|
+
|
|
631
|
+
#### `env: "disable"`
|
|
632
|
+
|
|
633
|
+
Disables environment variable injection entirely.
|
|
634
|
+
|
|
635
|
+
For example, given the following environment variables:
|
|
636
|
+
|
|
637
|
+
```bash
|
|
638
|
+
$ FOO=bar BAZ=123 ACME_PUBLIC_URL=https://acme.com
|
|
639
|
+
```
|
|
640
|
+
|
|
641
|
+
And source code:
|
|
642
|
+
|
|
643
|
+
```ts#index.tsx
|
|
644
|
+
console.log(process.env.FOO);
|
|
645
|
+
console.log(process.env.ACME_PUBLIC_URL);
|
|
646
|
+
console.log(process.env.BAZ);
|
|
647
|
+
```
|
|
648
|
+
|
|
649
|
+
The generated bundle will contain the following code:
|
|
650
|
+
|
|
651
|
+
```js
|
|
652
|
+
console.log(process.env.FOO);
|
|
653
|
+
console.log(process.env.BAZ);
|
|
654
|
+
```
|
|
655
|
+
|
|
549
656
|
### `sourcemap`
|
|
550
657
|
|
|
551
658
|
Specifies the type of sourcemap to generate.
|
|
@@ -49,7 +49,7 @@ Next, add these preload scripts to your `bunfig.toml` (you can also have everyth
|
|
|
49
49
|
|
|
50
50
|
```toml#bunfig.toml
|
|
51
51
|
[test]
|
|
52
|
-
preload = ["happydom.ts", "testing-library.ts"]
|
|
52
|
+
preload = ["./happydom.ts", "./testing-library.ts"]
|
|
53
53
|
```
|
|
54
54
|
---
|
|
55
55
|
|
|
@@ -84,4 +84,4 @@ test('Can use Testing Library', () => {
|
|
|
84
84
|
|
|
85
85
|
---
|
|
86
86
|
|
|
87
|
-
Refer to the [Testing Library docs](https://testing-library.com/), [Happy DOM repo](https://github.com/capricorn86/happy-dom) and [Docs > Test runner > DOM](https://bun.sh/docs/test/dom) for complete documentation on writing browser tests with Bun.
|
|
87
|
+
Refer to the [Testing Library docs](https://testing-library.com/), [Happy DOM repo](https://github.com/capricorn86/happy-dom) and [Docs > Test runner > DOM](https://bun.sh/docs/test/dom) for complete documentation on writing browser tests with Bun.
|
package/package.json
CHANGED