Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(qwik): export build constants from core #7138

Merged
merged 3 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"fixed": [["@builder.io/qwik", "@builder.io/qwik-city", "eslint-plugin-qwik", "create-qwik"]],
"linked": [],
"access": "public",
"baseBranch": "upcoming",
"baseBranch": "origin/upcoming",
"updateInternalDependencies": "minor",
"ignore": [
"qwik-docs",
Expand Down
5 changes: 5 additions & 0 deletions .changeset/itchy-masks-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@builder.io/qwik': minor
---

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.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { DocSearchHit } from './types';
import { identity } from './utils';
import { clearStalled, setStalled } from './utils/stalledControl';
import { AIButton } from './result';
import { isBrowser } from '@builder.io/qwik/build';
import { isBrowser } from '@builder.io/qwik';

export type ModalTranslations = Partial<{
searchBox: SearchBoxTranslations;
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/components/qwik-gpt/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { component$, useComputed$, useSignal } from '@builder.io/qwik';
// import { qwikGPT, rateResponse } from './search';
import { CodeBlock } from '../code-block/code-block';
// import { isBrowser } from '@builder.io/qwik/build';
// import { isBrowser } from '@builder.io/qwik';
import snarkdown from 'snarkdown';

const snarkdownEnhanced = (md: string) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/repl/monaco.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { EditorProps, EditorStore } from './editor';
import type { ReplStore } from './types';
import { getColorPreference } from '../components/theme-toggle/theme-toggle';
import { bundled, getNpmCdnUrl } from './bundled';
import { isServer } from '@builder.io/qwik/build';
import { isServer } from '@builder.io/qwik';
// We cannot use this, it causes the repl to use imports
// import { QWIK_REPL_DEPS_CACHE } from './worker/repl-constants';
const QWIK_REPL_DEPS_CACHE = 'QwikReplDeps';
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/repl/repl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { ReplDetailPanel } from './repl-detail-panel';
import { getReplVersion } from './repl-version';
import { updateReplOutput } from './repl-output-update';
import { QWIK_PKG_NAME, bundled, getNpmCdnUrl } from './bundled';
import { isServer } from '@builder.io/qwik/build';
import { isServer } from '@builder.io/qwik';

export const Repl = component$((props: ReplProps) => {
useStyles$(styles);
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/repl/worker/repl-service-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ self.oninstall = (ev) => {
self.onactivate = () => self.clients.claim();

export interface ReplGlobalApi {
qwikBuild?: typeof import('@builder.io/qwik/build');
qwikBuild?: typeof import('@builder.io/qwik');
qwikCore?: typeof import('@builder.io/qwik');
qwikOptimizer?: typeof import('@builder.io/qwik/optimizer');
qwikServer?: typeof import('@builder.io/qwik/server');
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/routes/api/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { $, component$, useOn, useSignal, useStore, useTask$ } from '@builder.io/qwik';
import { isBrowser } from '@builder.io/qwik/build';
import { isBrowser } from '@builder.io/qwik';
import { toSnakeCase } from '../../utils/utils';

// TODO: load the content of these files using fs instead of importing them
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/routes/api/qwik/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -3473,4 +3473,4 @@
"mdFile": "qwik.webviewhtmlattributes.md"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
useSignal,
useTask$,
} from '@builder.io/qwik';
import { isDev } from '@builder.io/qwik/build';
import { isDev } from '@builder.io/qwik';

const metaGlobComponents: Record<string, any> = import.meta.glob(
'/src/routes/demo/cookbook/glob-import/examples/*',
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/routes/demo/tasks/track-fn/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { component$, useSignal, useTask$ } from '@builder.io/qwik';
import { isServer } from '@builder.io/qwik/build';
import { isServer } from '@builder.io/qwik';

export default component$(() => {
const isUppercase = useSignal(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { component$, useSignal, useTask$ } from '@builder.io/qwik';
import { isServer } from '@builder.io/qwik/build';
import { isServer } from '@builder.io/qwik';

export default component$(() => {
const text = useSignal('Initial text');
Expand Down
3 changes: 1 addition & 2 deletions packages/docs/src/routes/demo/tasks/track/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { component$, useSignal, useTask$ } from '@builder.io/qwik';
import { isServer } from '@builder.io/qwik/build';
import { component$, useSignal, useTask$, isServer } from '@builder.io/qwik';

export default component$(() => {
const text = useSignal('Initial text');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ During SSR, each component will wait until all tasks are completed before output
<CodeSandbox src="/src/routes/demo/tasks/track/index.tsx" style={{ height: '6em' }} >
```tsx
import { component$, useSignal, useTask$ } from '@builder.io/qwik';
import { isServer } from '@builder.io/qwik/build';
import { isServer } from '@builder.io/qwik';

export default component$(() => {
const text = useSignal('Initial text');
Expand Down Expand Up @@ -237,7 +237,7 @@ const delay = (time: number) => new Promise((res) => setTimeout(res, time));
>
> - The `useTask$()` blocks rendering until it completes. If you don't want to block rendering, make sure that the task is resolved, and run the delay work on a separate unconnected promise. In this example, we don't await `delay()` because it would block rendering.

> Sometimes it is required to only run code either in the server or in the client. This can be achieved by using the `isServer` and `isBrowser` booleans exported from `@builder.io/qwik/build` as shown above.
> Sometimes it is required to only run code either in the server or in the client. This can be achieved by using the `isServer` and `isBrowser` booleans exported from `@builder.io/qwik` as shown above.


### `track()` as a function
Expand All @@ -247,7 +247,7 @@ In the above example, `track()` was used to track a specific signal. However, `t
<CodeSandbox src="/src/routes/demo/tasks/track-fn/index.tsx" style={{ height: '6em' }} >
```tsx
import { component$, useSignal, useTask$ } from '@builder.io/qwik';
import { isServer } from '@builder.io/qwik/build';
import { isServer } from '@builder.io/qwik';

export default component$(() => {
const isUppercase = useSignal(false);
Expand Down Expand Up @@ -338,7 +338,7 @@ Sometimes a task needs to run only on the browser and after rendering, in that c
> <CodeSandbox src="/src/routes/demo/tasks/track-server-guard/index.tsx" style={{ height: '6em' }}>
> ```tsx
> import { component$, useSignal, useTask$ } from '@builder.io/qwik';
> import { isServer } from '@builder.io/qwik/build';
> import { isServer } from '@builder.io/qwik';
>
> export default component$(() => {
> const text = useSignal('Initial text');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ src/

```typescript title="src/routes/[email protected]"
import type { RequestHandler } from "@builder.io/qwik-city";
import { isDev } from "@builder.io/qwik/build";
import { isDev } from "@builder.io/qwik";

export const onRequest: RequestHandler = event => {
if (isDev) return; // Will not return CSP headers in dev mode
Expand Down Expand Up @@ -79,7 +79,7 @@ import {
ServiceWorkerRegister,
} from "@builder.io/qwik-city";
import { RouterHead } from "./components/router-head/router-head";
import { isDev } from "@builder.io/qwik/build";
import { isDev } from "@builder.io/qwik";

import "./global.css";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ If you want to access browser APIs, such as `window`, `document`, `localStorage`

```tsx
import { component$, useTask$, useVisibleTask$, useSignal } from '@builder.io/qwik';
import { isBrowser } from '@builder.io/qwik/build';
import { isBrowser } from '@builder.io/qwik';

export default component$(() => {
const ref = useSignal<Element>();
Expand Down Expand Up @@ -667,7 +667,7 @@ Sometimes you need to run code only on the server, such as fetching data or acce
```tsx
import { component$, useTask$ } from '@builder.io/qwik';
import { server$, routeLoader$ } from '@builder.io/qwik/qwik-city';
import { isServer } from '@builder.io/qwik/build';
import { isServer } from '@builder.io/qwik';


export const useGetProducts = routeLoader$((requestEvent) => {
Expand Down Expand Up @@ -729,7 +729,7 @@ The `server$()` is a special way to declare functions that only run on the serve

### `isServer` & `isBrowser` conditionals

Instead of `if(typeof window !== 'undefined')`, it is recommended to use the `isServer` and `isBrowser` boolean helpers exported from `@builder.io/qwik/build` to ensure your code only runs in the browser. They contain slightly more robust checks to better detect the browser environment.
Instead of `if(typeof window !== 'undefined')`, it is recommended to use the `isServer` and `isBrowser` boolean helpers exported from `@builder.io/qwik` to ensure your code only runs in the browser. They contain slightly more robust checks to better detect the browser environment.

Here is the source code for reference:

Expand All @@ -746,7 +746,7 @@ export const isServer: boolean = !isBrowser;
Here is how you import these for reference:

```tsx
import {isServer, isBrowser} from '@builder.io/qwik/build';
import {isServer, isBrowser} from '@builder.io/qwik';

// inside component$

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ The problem with `import.meta.glob` in Qwik, is that it currently either works i

The reason for this behavior, is that `import.meta.glob` with `eager.false` breaks the production bundle as it creates lazy-loadable chunks that Qwik doesn't know how to handle. On the other hand, `eager:true` seemingly fixes the issue as it allows Qwik to normally bundle the files, but it also slows down the development server - especially when you import a lot of heavy components with it.

As a workaround for now, you can use the build time `isDev` boolean from `"@builder.io/qwik/build"`:
As a workaround for now, you can use the build time `isDev` boolean from `"@builder.io/qwik"`:

<CodeSandbox src="/src/routes/demo/cookbook/glob-import/">
```tsx
Expand All @@ -58,7 +58,7 @@ import {
useSignal,
useTask$,
} from '@builder.io/qwik';
import { isDev } from '@builder.io/qwik/build';
import { isDev } from '@builder.io/qwik';

const metaGlobComponents: Record<string, any> = import.meta.glob(
'/src/examples/*',
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/routes/examples/[...id]/index!.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import exampleSections, { type ExampleApp } from '@examples-data';
import type { ReplAppInput } from '../../../repl/types';
import { type DocumentHead, useLocation } from '@builder.io/qwik-city';
import { PanelToggle } from '../../../components/panel-toggle/panel-toggle';
import { isBrowser } from '@builder.io/qwik/build';
import { isBrowser } from '@builder.io/qwik';
import { createPlaygroundShareUrl, parsePlaygroundShareUrl } from '../../../repl/repl-share-url';

export default component$(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { component$, useTask$, useStore, useStyles$ } from '@builder.io/qwik';
import { isServer } from '@builder.io/qwik/build';
import { isServer } from '@builder.io/qwik';
import HackerNewsCSS from './hacker-news.css?inline';

export const HackerNews = component$(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/routes/playground/index!.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import playgroundApp from '@playground-data';
import type { ReplAppInput } from '../../repl/types';
import { createPlaygroundShareUrl, parsePlaygroundShareUrl } from '../../repl/repl-share-url';
import { PanelToggle } from '../../components/panel-toggle/panel-toggle';
import { isBrowser } from '@builder.io/qwik/build';
import { isBrowser } from '@builder.io/qwik';

export default component$(() => {
useStyles$(styles);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { component$, useSignal, useTask$ } from '@builder.io/qwik';
import { isServer } from '@builder.io/qwik/build';
import { isServer } from '@builder.io/qwik';

export const InsideTask = component$(() => {
const mySig = useSignal(0);
Expand Down
2 changes: 1 addition & 1 deletion packages/insights/src/db/logging.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isDev } from '@builder.io/qwik/build';
import { isDev } from '@builder.io/qwik';

const LOG_TIMING: boolean = isDev;

Expand Down
2 changes: 1 addition & 1 deletion packages/qwik-auth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
type RequestEvent,
type RequestEventCommon,
} from '@builder.io/qwik-city';
import { isServer } from '@builder.io/qwik/build';
import { isServer } from '@builder.io/qwik';
import { parseString, splitCookiesString } from 'set-cookie-parser';

export type GetSessionResult = Promise<{ data: Session | null; cookie: any }>;
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik-city/src/runtime/src/client-navigate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isBrowser } from '@builder.io/qwik/build';
import { isBrowser } from '@builder.io/qwik';
import type { NavigationType, ScrollState } from './types';
import { isSamePath, toPath } from './utils';
import { PREFETCHED_NAVIGATE_PATHS } from './constants';
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik-city/src/runtime/src/link-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getClientNavPath, shouldPrefetchData, shouldPrefetchSymbols } from './u
import { loadClientData } from './use-endpoint';
import { useLocation, useNavigate } from './use-functions';
import { prefetchSymbols } from './client-navigate';
import { isDev } from '@builder.io/qwik/build';
import { isDev } from '@builder.io/qwik';

/** @public */
export const Link = component$<LinkProps>((props) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
_waitUntilRendered,
type QRL,
} from '@builder.io/qwik';
import { isBrowser, isDev, isServer } from '@builder.io/qwik/build';
import { isBrowser, isDev, isServer } from '@builder.io/qwik';
import * as qwikCity from '@qwik-city-plan';
import { CLIENT_DATA_CACHE } from './constants';
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik-city/src/runtime/src/server-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import type {
} from './types';
import { useAction, useLocation, useQwikCityEnv } from './use-functions';

import { isDev, isServer } from '@builder.io/qwik/build';
import { isDev, isServer } from '@builder.io/qwik';

import type { FormSubmitCompletedDetail } from './form-component';

Expand Down
2 changes: 1 addition & 1 deletion packages/qwik-city/src/runtime/src/spa-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ClientSPAWindow } from './qwik-city-component';
import type { ScrollHistoryState } from './scroll-restoration';
import type { ScrollState } from './types';

import { isDev } from '@builder.io/qwik/build';
import { isDev } from '@builder.io/qwik';
import { event$ } from '@builder.io/qwik';

// TODO Dedupe handler code from here and QwikCityProvider?
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik-react/src/react/qwikify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
useStylesScoped$,
} from '@builder.io/qwik';

import { isBrowser, isServer } from '@builder.io/qwik/build';
import { isBrowser, isServer } from '@builder.io/qwik';
import type { Root } from 'react-dom/client';
import type { FunctionComponent as ReactFC } from 'react';
import * as client from './client';
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik-react/src/react/server-render.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type QRL, type Signal, Slot, SSRRaw, SSRStream } from '@builder.io/qwik';
import { getHostProps, mainExactProps, getReactProps } from './slot';
import { renderToString } from 'react-dom/server';
import { isServer } from '@builder.io/qwik/build';
import { isServer } from '@builder.io/qwik';

export async function renderFromServer(
Host: any,
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik-react/src/react/slot.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { $, useOn, useOnDocument, useSignal } from '@builder.io/qwik';
import { isServer } from '@builder.io/qwik/build';
import { isServer } from '@builder.io/qwik';
import { Component, createContext, createElement, createRef } from 'react';
import type { QwikifyOptions, QwikifyProps } from './types';

Expand Down
9 changes: 9 additions & 0 deletions packages/qwik/src/core/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
```ts

import * as CSS_2 from 'csstype';
import { isBrowser } from '@builder.io/qwik/build';
import { isDev } from '@builder.io/qwik/build';
import { isServer } from '@builder.io/qwik/build';
import type { JSXNode as JSXNode_2 } from '@builder.io/qwik/jsx-runtime';

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

export { isBrowser }

export { isDev }

export { isServer }

// @public
export const isSignal: <T = unknown>(obj: any) => obj is Signal<T>;

Expand Down
1 change: 1 addition & 0 deletions packages/qwik/src/core/components/prefetch.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// keep this import from qwik/build so the cjs build works
import { isDev } from '@builder.io/qwik/build';
import { _jsxC } from '../internal';
import type { JSXNode } from '@builder.io/qwik/jsx-runtime';
Expand Down
2 changes: 2 additions & 0 deletions packages/qwik/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export type {
_Only$,
} from './component/component.public';

export { isBrowser, isDev, isServer } from '@builder.io/qwik/build';

//////////////////////////////////////////////////////////////////////////////////////////
// Developer Event API
//////////////////////////////////////////////////////////////////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions packages/qwik/src/core/platform/platform.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// keep this import from qwik/build so the cjs build works
import { isServer } from '@builder.io/qwik/build';
import { qError, QError_qrlMissingChunk, QError_qrlMissingContainer } from '../error/error';
import { getSymbolHash } from '../qrl/qrl-class';
Expand Down
1 change: 1 addition & 0 deletions packages/qwik/src/core/render/dom/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
type VirtualElement,
} from './virtual-element';

// keep this import from qwik/build so the cjs build works
import { isBrowser } from '@builder.io/qwik/build';
import {
getProxyTarget,
Expand Down
1 change: 1 addition & 0 deletions packages/qwik/src/core/render/jsx/jsx-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { isPromise } from '../../util/promises';
import { SkipRender } from './utils.public';
import { EMPTY_OBJ } from '../../util/flyweight';
import { _IMMUTABLE } from '../../internal';
// keep this import from qwik/build so the cjs build works
import { isBrowser } from '@builder.io/qwik/build';
import { assertString } from '../../error/assert';
import { static_subtree } from '../execute-component';
Expand Down
1 change: 1 addition & 0 deletions packages/qwik/src/core/util/event.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// keep this import from qwik/build so the cjs build works
import { isBrowser } from '@builder.io/qwik/build';
import { qTest } from './qdev';

Expand Down
Loading
Loading