Skip to content

Commit a885570

Browse files
committed
feat: export the build constants from qwik core
1 parent cbd2c7c commit a885570

File tree

7 files changed

+45
-16
lines changed

7 files changed

+45
-16
lines changed

.changeset/itchy-masks-admire.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@builder.io/qwik': minor
3+
---
4+
5+
FEAT: The build constants `isDev`, `isBrowser` and `isServer` are now exported from `@builder.io/qwik` directly, so they are more discoverable and easier to add. `@builder.io/qwik/build` still remains.

packages/docs/src/routes/api/qwik/api.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3473,4 +3473,4 @@
34733473
"mdFile": "qwik.webviewhtmlattributes.md"
34743474
}
34753475
]
3476-
}
3476+
}

packages/qwik/src/core/api.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
```ts
66

77
import * as CSS_2 from 'csstype';
8+
import { isBrowser } from '@builder.io/qwik/build';
9+
import { isDev } from '@builder.io/qwik/build';
10+
import { isServer } from '@builder.io/qwik/build';
811
import type { JSXNode as JSXNode_2 } from '@builder.io/qwik/jsx-runtime';
912

1013
// @public
@@ -401,6 +404,12 @@ export type IntrinsicSVGElements = {
401404
[K in keyof Omit<SVGElementTagNameMap, keyof HTMLElementTagNameMap>]: LenientSVGProps<SVGElementTagNameMap[K]>;
402405
};
403406

407+
export { isBrowser }
408+
409+
export { isDev }
410+
411+
export { isServer }
412+
404413
// @public
405414
export const isSignal: <T = unknown>(obj: any) => obj is Signal<T>;
406415

packages/qwik/src/core/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export type {
1313
_Only$,
1414
} from './component/component.public';
1515

16+
export { isBrowser, isDev, isServer } from '@builder.io/qwik/build';
17+
1618
//////////////////////////////////////////////////////////////////////////////////////////
1719
// Developer Event API
1820
//////////////////////////////////////////////////////////////////////////////////////////

packages/qwik/src/optimizer/core/src/const_replace.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ pub struct ConstReplacerVisitor {
99
pub is_server_ident: Option<Id>,
1010
pub is_browser_ident: Option<Id>,
1111
pub is_dev_ident: Option<Id>,
12+
pub is_core_server_ident: Option<Id>,
13+
pub is_core_browser_ident: Option<Id>,
14+
pub is_core_dev_ident: Option<Id>,
1215
}
1316

1417
impl ConstReplacerVisitor {
@@ -21,6 +24,10 @@ impl ConstReplacerVisitor {
2124
is_browser_ident: global_collector
2225
.get_imported_local(&IS_BROWSER, &BUILDER_IO_QWIK_BUILD),
2326
is_dev_ident: global_collector.get_imported_local(&IS_DEV, &BUILDER_IO_QWIK_BUILD),
27+
is_core_server_ident: global_collector.get_imported_local(&IS_SERVER, &BUILDER_IO_QWIK),
28+
is_core_browser_ident: global_collector
29+
.get_imported_local(&IS_BROWSER, &BUILDER_IO_QWIK),
30+
is_core_dev_ident: global_collector.get_imported_local(&IS_DEV, &BUILDER_IO_QWIK),
2431
}
2532
}
2633
}
@@ -50,6 +57,12 @@ impl VisitMut for ConstReplacerVisitor {
5057
ConstVariable::IsBrowser
5158
} else if id_eq!(ident, &self.is_dev_ident) {
5259
ConstVariable::IsDev
60+
} else if id_eq!(ident, &self.is_core_server_ident) {
61+
ConstVariable::IsServer
62+
} else if id_eq!(ident, &self.is_core_browser_ident) {
63+
ConstVariable::IsBrowser
64+
} else if id_eq!(ident, &self.is_core_dev_ident) {
65+
ConstVariable::IsDev
5366
} else {
5467
ConstVariable::None
5568
}

packages/qwik/src/optimizer/core/src/snapshots/qwik_core__test__example_build_server.snap

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ snapshot_kind: text
77
==INPUT==
88

99

10-
import { component$, useStore } from '@builder.io/qwik';
11-
import { isServer, isBrowser } from '@builder.io/qwik/build';
10+
import { component$, useStore, isDev, isServer as isServer2 } from '@builder.io/qwik';
11+
import { isServer, isBrowser as isb } from '@builder.io/qwik/build';
1212
import { mongodb } from 'mondodb';
1313
import { threejs } from 'threejs';
1414

1515
import L from 'leaflet';
1616

1717
export const functionThatNeedsWindow = () => {
18-
if (isBrowser) {
18+
if (isb) {
1919
console.log('l', L);
2020
console.log('hey');
2121
window.alert('hey');
@@ -27,14 +27,14 @@ export const App = component$(() => {
2727
if (isServer) {
2828
console.log('server', mongodb());
2929
}
30-
if (isBrowser) {
30+
if (isb) {
3131
console.log('browser', new threejs());
3232
}
3333
});
3434
return (
3535
<Cmp>
36-
{isServer && <p>server</p>}
37-
{isBrowser && <p>server</p>}
36+
{isServer2 && <p>server</p>}
37+
{isb && <p>server</p>}
3838
</Cmp>
3939
);
4040
});
@@ -62,7 +62,7 @@ export const s_ckEPmXZlub0 = ()=>{
6262
};
6363

6464

65-
Some("{\"version\":3,\"sources\":[\"/user/qwik/src/test.tsx\"],\"names\":[],\"mappings\":\";6BAgB8B;IAC1B,UAAU;QAEF,QAAQ,GAAG,CAAC,UAAU;IAK9B;IACA,QACK,IAAI;YACD,EAAc,EAAE,MAAM,EAAE,GAAG;YAC3B,OAA4B;QAChC,EAAE;AAEV\"}")
65+
Some("{\"version\":3,\"sources\":[\"/user/qwik/src/test.tsx\"],\"names\":[],\"mappings\":\";6BAgB8B;IAC1B,UAAU;QAEF,QAAQ,GAAG,CAAC,UAAU;IAK9B;IACA,QACK,IAAI;YACD,EAAe,EAAE,MAAM,EAAE,GAAG;YAC5B,OAAsB;QAC1B,EAAE;AAEV\"}")
6666
/*
6767
{
6868
"origin": "test.tsx",
@@ -78,8 +78,8 @@ Some("{\"version\":3,\"sources\":[\"/user/qwik/src/test.tsx\"],\"names\":[],\"ma
7878
"ctxName": "component$",
7979
"captures": false,
8080
"loc": [
81-
396,
82-
731
81+
427,
82+
751
8383
]
8484
}
8585
*/

packages/qwik/src/optimizer/core/src/test.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2619,15 +2619,15 @@ export const foo = () => console.log('foo');
26192619
fn example_build_server() {
26202620
test_input!(TestInput {
26212621
code: r#"
2622-
import { component$, useStore } from '@builder.io/qwik';
2623-
import { isServer, isBrowser } from '@builder.io/qwik/build';
2622+
import { component$, useStore, isDev, isServer as isServer2 } from '@builder.io/qwik';
2623+
import { isServer, isBrowser as isb } from '@builder.io/qwik/build';
26242624
import { mongodb } from 'mondodb';
26252625
import { threejs } from 'threejs';
26262626
26272627
import L from 'leaflet';
26282628
26292629
export const functionThatNeedsWindow = () => {
2630-
if (isBrowser) {
2630+
if (isb) {
26312631
console.log('l', L);
26322632
console.log('hey');
26332633
window.alert('hey');
@@ -2639,14 +2639,14 @@ export const App = component$(() => {
26392639
if (isServer) {
26402640
console.log('server', mongodb());
26412641
}
2642-
if (isBrowser) {
2642+
if (isb) {
26432643
console.log('browser', new threejs());
26442644
}
26452645
});
26462646
return (
26472647
<Cmp>
2648-
{isServer && <p>server</p>}
2649-
{isBrowser && <p>server</p>}
2648+
{isServer2 && <p>server</p>}
2649+
{isb && <p>server</p>}
26502650
</Cmp>
26512651
);
26522652
});

0 commit comments

Comments
 (0)