refactor: avoid runtime config object (#8202)

This commit is contained in:
forehalo
2024-09-13 07:27:11 +00:00
parent c76b4d70b0
commit 25969a34e8
45 changed files with 117 additions and 156 deletions

View File

@@ -5,7 +5,7 @@ import { z } from 'zod';
import { isElectron } from './constant.js';
import { UaHelper } from './ua-helper.js';
export const runtimeFlagsSchema = z.object({
export const BUILD_CONFIG_SCHEMA = z.object({
// this is for the electron app
serverUrlPrefix: z.string(),
appVersion: z.string(),
@@ -27,14 +27,11 @@ export const runtimeFlagsSchema = z.object({
allowLocalWorkspace: z.boolean(),
enablePreloading: z.boolean(),
enableNewSettingUnstableApi: z.boolean(),
enableEnhanceShareMode: z.boolean(),
enableExperimentalFeature: z.boolean(),
enableInfoModal: z.boolean(),
enableOrganize: z.boolean(),
enableThemeEditor: z.boolean(),
});
export type RuntimeConfig = z.infer<typeof runtimeFlagsSchema>;
export type BUILD_CONFIG_TYPE = z.infer<typeof BUILD_CONFIG_SCHEMA>;
export type Environment = {
isDebug: boolean;
@@ -61,24 +58,11 @@ export type Environment = {
chromeVersion?: number;
};
function setupRuntimeConfig() {
if (!process.env.RUNTIME_CONFIG) {
return;
}
// registered by [webpack.DefinePlugin]
const runtimeConfig = JSON.parse(process.env.RUNTIME_CONFIG ?? '');
runtimeFlagsSchema.parse(runtimeConfig);
globalThis.runtimeConfig = runtimeConfig;
}
export function setupGlobal() {
if (globalThis.$AFFINE_SETUP) {
return;
}
setupRuntimeConfig();
let environment: Environment;
const isDebug = process.env.NODE_ENV === 'development';
@@ -103,10 +87,10 @@ export function setupGlobal() {
const uaHelper = new UaHelper(globalThis.navigator);
environment = {
isDesktopEdition: runtimeConfig.distribution !== 'mobile',
isMobileEdition: runtimeConfig.distribution === 'mobile',
isDesktopWeb: runtimeConfig.distribution === 'web',
isMobileWeb: runtimeConfig.distribution === 'mobile',
isDesktopEdition: BUILD_CONFIG.distribution !== 'mobile',
isMobileEdition: BUILD_CONFIG.distribution === 'mobile',
isDesktopWeb: BUILD_CONFIG.distribution === 'web',
isMobileWeb: BUILD_CONFIG.distribution === 'mobile',
isElectron,
isDebug,
isMobile: uaHelper.isMobile,

View File

@@ -1,8 +1,8 @@
import type { FlagInfo } from './types';
const isNotStableBuild = runtimeConfig.appBuildType !== 'stable';
const isNotStableBuild = BUILD_CONFIG.appBuildType !== 'stable';
const isDesktopEnvironment = environment.isElectron;
const isCanaryBuild = runtimeConfig.appBuildType === 'canary';
const isCanaryBuild = BUILD_CONFIG.appBuildType === 'canary';
export const AFFINE_FLAGS = {
enable_ai: {

View File

@@ -20,15 +20,16 @@ const appNames = {
beta: 'AFFiNE Beta',
internal: 'AFFiNE Internal',
} satisfies Record<Channel, string>;
const appName = appNames[BUILD_CONFIG.appBuildType];
const links = [
{
href: runtimeConfig.githubUrl,
href: BUILD_CONFIG.githubUrl,
icon: <GithubIcon size={20} />,
label: 'Star AFFiNE on GitHub',
},
{
href: runtimeConfig.githubUrl,
href: BUILD_CONFIG.githubUrl,
icon: <MailWarningIcon size={20} />,
label: 'Report an Issue',
},
@@ -45,9 +46,6 @@ const links = [
];
export function AboutAFFiNE() {
const { appBuildType, appVersion, editorVersion } = runtimeConfig;
const appName = appNames[appBuildType];
return (
<div className="flex flex-col h-full gap-3 py-5 px-6 w-full">
<div className="flex items-center">
@@ -80,8 +78,8 @@ export function AboutAFFiNE() {
</div>
</div>
<div className="space-y-3 text-sm font-normal text-gray-500">
<div>{`App Version: ${appName} ${appVersion}`}</div>
<div>{`Editor Version: ${editorVersion}`}</div>
<div>{`App Version: ${appName} ${BUILD_CONFIG.appVersion}`}</div>
<div>{`Editor Version: ${BUILD_CONFIG.editorVersion}`}</div>
</div>
</div>
);

View File

@@ -55,8 +55,8 @@ function main() {
],
});
setTags({
appVersion: runtimeConfig.appVersion,
editorVersion: runtimeConfig.editorVersion,
appVersion: BUILD_CONFIG.appVersion,
editorVersion: BUILD_CONFIG.editorVersion,
});
apis?.ui.handleNetworkChange(navigator.onLine);

View File

@@ -36,8 +36,8 @@ function main() {
],
});
setTags({
appVersion: runtimeConfig.appVersion,
editorVersion: runtimeConfig.editorVersion,
appVersion: BUILD_CONFIG.appVersion,
editorVersion: BUILD_CONFIG.editorVersion,
});
}
performanceMainLogger.info('setup done');

View File

@@ -112,21 +112,19 @@ const DetailPageImpl = () => {
// provide image proxy endpoint to blocksuite
editorHost?.std.clipboard.use(
customImageProxyMiddleware(runtimeConfig.imageProxyUrl)
customImageProxyMiddleware(BUILD_CONFIG.imageProxyUrl)
);
ImageBlockService.setImageProxyURL(runtimeConfig.imageProxyUrl);
ImageBlockService.setImageProxyURL(BUILD_CONFIG.imageProxyUrl);
// provide link preview endpoint to blocksuite
BookmarkBlockService.setLinkPreviewEndpoint(runtimeConfig.linkPreviewUrl);
BookmarkBlockService.setLinkPreviewEndpoint(BUILD_CONFIG.linkPreviewUrl);
EmbedGithubBlockService.setLinkPreviewEndpoint(
runtimeConfig.linkPreviewUrl
BUILD_CONFIG.linkPreviewUrl
);
EmbedYoutubeBlockService.setLinkPreviewEndpoint(
runtimeConfig.linkPreviewUrl
);
EmbedLoomBlockService.setLinkPreviewEndpoint(
runtimeConfig.linkPreviewUrl
BUILD_CONFIG.linkPreviewUrl
);
EmbedLoomBlockService.setLinkPreviewEndpoint(BUILD_CONFIG.linkPreviewUrl);
// provide page mode and updated date to blocksuite
const refNodeService = editorHost?.std.getOptional(RefNodeSlotsProvider);

View File

@@ -28,7 +28,7 @@ export const Component = () => {
}}
>
<ExplorerFavorites />
{runtimeConfig.enableOrganize && <ExplorerOrganize />}
<ExplorerOrganize />
<ExplorerMigrationFavorites />
<ExplorerCollections />
<ExplorerTags />

View File

@@ -3,19 +3,17 @@ import { useI18n } from '@affine/i18n';
import { SettingGroup } from '../group';
import { RowLayout } from '../row.layout';
const { appVersion, editorVersion } = runtimeConfig;
export const AboutGroup = () => {
const t = useI18n();
return (
<SettingGroup title={t['com.affine.mobile.setting.about.title']()}>
<RowLayout label={t['com.affine.mobile.setting.about.appVersion']()}>
{appVersion}
{BUILD_CONFIG.appVersion}
</RowLayout>
<RowLayout label={t['com.affine.mobile.setting.about.editorVersion']()}>
{editorVersion}
{BUILD_CONFIG.editorVersion}
</RowLayout>
</SettingGroup>
);

View File

@@ -43,8 +43,8 @@ function main() {
],
});
setTags({
appVersion: runtimeConfig.appVersion,
editorVersion: runtimeConfig.editorVersion,
appVersion: BUILD_CONFIG.appVersion,
editorVersion: BUILD_CONFIG.editorVersion,
});
}
performanceMainLogger.info('setup done');

View File

@@ -15,7 +15,7 @@ export const AffineOtherPageLayout = ({
const t = useI18n();
const openDownloadLink = useCallback(() => {
open(runtimeConfig.downloadUrl, '_blank');
open(BUILD_CONFIG.downloadUrl, '_blank');
}, []);
return (

View File

@@ -46,7 +46,7 @@ export async function createFirstAppData(workspacesService: WorkspacesService) {
return;
}
localStorage.setItem('is-first-open', 'false');
if (runtimeConfig.enablePreloading) {
if (BUILD_CONFIG.enablePreloading) {
const { meta, defaultDocId } = await buildShowcaseWorkspace(
workspacesService,
WorkspaceFlavour.LOCAL,

View File

@@ -23,7 +23,7 @@ export function registerAffineHelpCommands({
label: t['com.affine.cmdk.affine.whats-new'](),
run() {
track.$.cmdk.help.openChangelog();
popupWindow(runtimeConfig.changelogUrl);
popupWindow(BUILD_CONFIG.changelogUrl);
},
})
);

View File

@@ -50,7 +50,7 @@ function OAuthProvider({ provider }: { provider: OAuthProviderType }) {
const onClick = useCallback(() => {
let oauthUrl =
(environment.isElectron ? runtimeConfig.serverUrlPrefix : '') +
(environment.isElectron ? BUILD_CONFIG.serverUrlPrefix : '') +
`/oauth/login?provider=${provider}`;
if (environment.isElectron) {

View File

@@ -48,7 +48,7 @@ interface NameWorkspaceContentProps extends ConfirmModalProps {
) => void;
}
const shouldEnableCloud = !runtimeConfig.allowLocalWorkspace;
const shouldEnableCloud = !BUILD_CONFIG.allowLocalWorkspace;
const NameWorkspaceContent = ({
loading,
@@ -159,7 +159,7 @@ const NameWorkspaceContent = ({
{shouldEnableCloud ? (
<a
className={styles.cloudTips}
href={runtimeConfig.downloadUrl}
href={BUILD_CONFIG.downloadUrl}
target="_blank"
rel="noreferrer"
>
@@ -229,7 +229,7 @@ export const CreateWorkspaceModal = ({
// this will be the last step for web for now
// fix me later
if (runtimeConfig.enablePreloading) {
if (BUILD_CONFIG.enablePreloading) {
const { meta, defaultDocId } = await buildShowcaseWorkspace(
workspacesService,
workspaceFlavour,

View File

@@ -24,7 +24,7 @@ export const IssueFeedbackModal = () => {
onOpenChange={setOpen}
description={t['com.affine.issue-feedback.description']()}
cancelText={t['com.affine.issue-feedback.cancel']()}
to={`${runtimeConfig.githubUrl}/issues/new/choose`}
to={`${BUILD_CONFIG.githubUrl}/issues/new/choose`}
confirmText={t['com.affine.issue-feedback.confirm']()}
confirmButtonOptions={{
variant: 'primary',

View File

@@ -21,7 +21,7 @@ export const AboutAffine = () => {
const t = useI18n();
const { appSettings, updateSettings } = useAppSettingHelper();
const { toggleAutoCheck, toggleAutoDownload } = useAppUpdater();
const channel = runtimeConfig.appBuildType;
const channel = BUILD_CONFIG.appBuildType;
const appIcon = appIconMap[channel];
const appName = appNames[channel];
@@ -63,14 +63,14 @@ export const AboutAffine = () => {
<SettingWrapper title={t['com.affine.aboutAFFiNE.version.title']()}>
<SettingRow
name={appName}
desc={runtimeConfig.appVersion}
desc={BUILD_CONFIG.appVersion}
className={styles.appImageRow}
>
<img src={appIcon} alt={appName} width={56} height={56} />
</SettingRow>
<SettingRow
name={t['com.affine.aboutAFFiNE.version.editor.title']()}
desc={runtimeConfig.editorVersion}
desc={BUILD_CONFIG.editorVersion}
/>
{environment.isElectron ? (
<>
@@ -100,7 +100,7 @@ export const AboutAffine = () => {
desc={t['com.affine.aboutAFFiNE.changelog.description']()}
style={{ cursor: 'pointer' }}
onClick={() => {
popupWindow(runtimeConfig.changelogUrl);
popupWindow(BUILD_CONFIG.changelogUrl);
}}
>
<ArrowRightSmallIcon />

View File

@@ -98,7 +98,7 @@ export const AppearanceSettings = () => {
/>
</SettingRow>
) : null}
{runtimeConfig.enableNewSettingUnstableApi && environment.isElectron ? (
{BUILD_CONFIG.enableNewSettingUnstableApi && environment.isElectron ? (
<SettingRow
name={t['com.affine.appearanceSettings.windowFrame.title']()}
desc={t['com.affine.appearanceSettings.windowFrame.description']()}
@@ -118,11 +118,11 @@ export const AppearanceSettings = () => {
/>
</SettingRow>
) : null}
{runtimeConfig.enableThemeEditor ? <ThemeEditorSetting /> : null}
{BUILD_CONFIG.enableThemeEditor ? <ThemeEditorSetting /> : null}
</SettingWrapper>
{/* // TODO(@JimmFly): remove Page component when stable release */}
<Page />
{runtimeConfig.enableNewSettingUnstableApi ? (
{BUILD_CONFIG.enableNewSettingUnstableApi ? (
<SettingWrapper title={t['com.affine.appearanceSettings.date.title']()}>
<SettingRow
name={t['com.affine.appearanceSettings.dateFormat.title']()}

View File

@@ -107,7 +107,7 @@ export const useGeneralSettingList = (): GeneralSettingList => {
}
}
if (runtimeConfig.enableExperimentalFeature) {
if (BUILD_CONFIG.enableExperimentalFeature) {
settings.push({
key: 'experimental-features',
title: t['com.affine.settings.workspace.experimental-features'](),

View File

@@ -24,7 +24,7 @@ export const StarAFFiNEModal = () => {
onOpenChange={setOpen}
description={t['com.affine.star-affine.description']()}
cancelText={t['com.affine.star-affine.cancel']()}
to={runtimeConfig.githubUrl}
to={BUILD_CONFIG.githubUrl}
confirmButtonOptions={{
variant: 'primary',
}}

View File

@@ -89,22 +89,22 @@ const BlockSuiteEditorImpl = ({
// provide image proxy endpoint to blocksuite
editor.host?.std.clipboard.use(
customImageProxyMiddleware(runtimeConfig.imageProxyUrl)
customImageProxyMiddleware(BUILD_CONFIG.imageProxyUrl)
);
ImageBlockService.setImageProxyURL(runtimeConfig.imageProxyUrl);
ImageBlockService.setImageProxyURL(BUILD_CONFIG.imageProxyUrl);
// provide link preview endpoint to blocksuite
BookmarkBlockService.setLinkPreviewEndpoint(
runtimeConfig.linkPreviewUrl
BUILD_CONFIG.linkPreviewUrl
);
EmbedGithubBlockService.setLinkPreviewEndpoint(
runtimeConfig.linkPreviewUrl
BUILD_CONFIG.linkPreviewUrl
);
EmbedYoutubeBlockService.setLinkPreviewEndpoint(
runtimeConfig.linkPreviewUrl
BUILD_CONFIG.linkPreviewUrl
);
EmbedLoomBlockService.setLinkPreviewEndpoint(
runtimeConfig.linkPreviewUrl
BUILD_CONFIG.linkPreviewUrl
);
return editor.host?.updateComplete;

View File

@@ -2,7 +2,7 @@ import { AffineCanvasTextFonts, FontConfigExtension } from '@blocksuite/blocks';
export function getFontConfigExtension() {
return FontConfigExtension(
runtimeConfig.isSelfHosted
BUILD_CONFIG.isSelfHosted
? AffineCanvasTextFonts.map(font => ({
...font,
// self-hosted fonts are served from /assets

View File

@@ -304,16 +304,13 @@ export const PageHeaderMenuButton = ({
)}
<MenuSeparator />
{runtimeConfig.enableInfoModal && (
<MenuItem
prefixIcon={<InformationIcon />}
data-testid="editor-option-menu-info"
onSelect={openInfoModal}
>
{t['com.affine.page-properties.page-info.view']()}
</MenuItem>
)}
<MenuItem
prefixIcon={<InformationIcon />}
data-testid="editor-option-menu-info"
onSelect={openInfoModal}
>
{t['com.affine.page-properties.page-info.view']()}
</MenuItem>
{currentMode === 'page' ? (
<MenuItem
prefixIcon={<TocIcon />}

View File

@@ -173,11 +173,9 @@ export const PageOperationCell = ({
? t['com.affine.favoritePageOperation.remove']()
: t['com.affine.favoritePageOperation.add']()}
</MenuItem>
{runtimeConfig.enableInfoModal ? (
<MenuItem onClick={onOpenInfoModal} prefixIcon={<InformationIcon />}>
{t['com.affine.page-properties.page-info.view']()}
</MenuItem>
) : null}
<MenuItem onClick={onOpenInfoModal} prefixIcon={<InformationIcon />}>
{t['com.affine.page-properties.page-info.view']()}
</MenuItem>
<MenuItem onClick={onOpenInNewTab} prefixIcon={<OpenInNewIcon />}>
{t['com.affine.workbench.tab.page-menu-open']()}

View File

@@ -77,7 +77,7 @@ export const HelpIsland = () => {
<StyledIconWrapper
data-testid="right-bottom-change-log-icon"
onClick={() => {
popupWindow(runtimeConfig.changelogUrl);
popupWindow(BUILD_CONFIG.changelogUrl);
}}
>
<NewIcon />

View File

@@ -176,7 +176,7 @@ export const RootAppSidebar = (): ReactElement => {
</SidebarContainer>
<SidebarScrollableContainer>
<ExplorerFavorites />
{runtimeConfig.enableOrganize && <ExplorerOrganize />}
<ExplorerOrganize />
<ExplorerMigrationFavorites />
<ExplorerCollections />
<ExplorerTags />

View File

@@ -36,7 +36,7 @@ export const AddWorkspace = ({
className={styles.ItemContainer}
>
<div className={styles.ItemText}>
{runtimeConfig.allowLocalWorkspace
{BUILD_CONFIG.allowLocalWorkspace
? t['com.affine.workspaceList.addWorkspace.create']()
: t['com.affine.workspaceList.addWorkspace.create-cloud']()}
</div>

View File

@@ -88,7 +88,7 @@ const UserWithWorkspaceListInner = ({
}, [setOpenSignIn]);
const onNewWorkspace = useCallback(() => {
if (!isAuthenticated && !runtimeConfig.allowLocalWorkspace) {
if (!isAuthenticated && !BUILD_CONFIG.allowLocalWorkspace) {
return openSignInModal();
}
track.$.navigationPanel.workspaceList.createWorkspace();

View File

@@ -95,9 +95,7 @@ export function useRegisterBlocksuiteEditorCommands(editor: Editor) {
registerAffineCommand({
id: `editor:${mode}-view-info`,
preconditionStrategy: () =>
PreconditionStrategy.InPaperOrEdgeless &&
!trash &&
runtimeConfig.enableInfoModal,
PreconditionStrategy.InPaperOrEdgeless && !trash,
category: `editor:${mode}`,
icon: mode === 'page' ? <PageIcon /> : <EdgelessIcon />,
label: t['com.affine.page-properties.page-info.view'](),

View File

@@ -177,7 +177,7 @@ export const useAppUpdater = () => {
const openChangelog = useAsyncCallback(async () => {
track.$.navigationPanel.bottomButtons.openChangelog();
popupWindow(runtimeConfig.changelogUrl);
popupWindow(BUILD_CONFIG.changelogUrl);
await setChangelogUnread(true);
}, [setChangelogUnread]);

View File

@@ -32,10 +32,10 @@ function createMixpanel() {
const wrapped = {
init() {
mixpanel.register({
appVersion: runtimeConfig.appVersion,
environment: runtimeConfig.appBuildType,
editorVersion: runtimeConfig.editorVersion,
isSelfHosted: Boolean(runtimeConfig.isSelfHosted),
appVersion: BUILD_CONFIG.appVersion,
environment: BUILD_CONFIG.appBuildType,
editorVersion: BUILD_CONFIG.editorVersion,
isSelfHosted: Boolean(BUILD_CONFIG.isSelfHosted),
isDesktop: environment.isElectron,
});
},

View File

@@ -6,7 +6,7 @@ import { BackendError, NetworkError } from '../error';
export function getAffineCloudBaseUrl(): string {
if (environment.isElectron) {
return runtimeConfig.serverUrlPrefix;
return BUILD_CONFIG.serverUrlPrefix;
}
const { protocol, hostname, port } = window.location;
return `${protocol}//${hostname}${port ? `:${port}` : ''}`;

View File

@@ -35,7 +35,7 @@ interface NameWorkspaceContentProps extends ConfirmModalProps {
) => void;
}
const shouldEnableCloud = !runtimeConfig.allowLocalWorkspace;
const shouldEnableCloud = !BUILD_CONFIG.allowLocalWorkspace;
const NameWorkspaceContent = ({
loading,
@@ -146,7 +146,7 @@ const NameWorkspaceContent = ({
{shouldEnableCloud ? (
<a
className={styles.cloudTips}
href={runtimeConfig.downloadUrl}
href={BUILD_CONFIG.downloadUrl}
target="_blank"
rel="noreferrer"
>
@@ -213,7 +213,7 @@ const CreateWorkspaceDialog = () => {
// this will be the last step for web for now
// fix me later
if (runtimeConfig.enablePreloading) {
if (BUILD_CONFIG.enablePreloading) {
const { meta, defaultDocId } = await buildShowcaseWorkspace(
workspacesService,
workspaceFlavour,

View File

@@ -154,21 +154,17 @@ export const useExplorerDocNodeOperations = (
/>
),
},
...(runtimeConfig.enableInfoModal
? [
{
index: 50,
view: (
<MenuItem
prefixIcon={<InformationIcon />}
onClick={handleOpenInfoModal}
>
{t['com.affine.page-properties.page-info.view']()}
</MenuItem>
),
},
]
: []),
{
index: 50,
view: (
<MenuItem
prefixIcon={<InformationIcon />}
onClick={handleOpenInfoModal}
>
{t['com.affine.page-properties.page-info.view']()}
</MenuItem>
),
},
{
index: 99,
view: (

View File

@@ -11,7 +11,7 @@ export const useCustomTheme = (target: HTMLElement) => {
const { resolvedTheme } = useTheme();
useEffect(() => {
if (!runtimeConfig.enableThemeEditor) return;
if (!BUILD_CONFIG.enableThemeEditor) return;
if (_provided) return;
_provided = true;

View File

@@ -36,7 +36,7 @@ export class UserDBDocServer implements DocServer {
await this.socket.emitWithAck('space:join', {
spaceType: 'userspace',
spaceId: this.userId,
clientVersion: runtimeConfig.appVersion,
clientVersion: BUILD_CONFIG.appVersion,
});
}

View File

@@ -166,7 +166,7 @@ export class CloudAwarenessConnection implements AwarenessConnection {
spaceType: 'workspace',
spaceId: this.workspaceId,
docId: this.workspaceId,
clientVersion: runtimeConfig.appVersion,
clientVersion: BUILD_CONFIG.appVersion,
},
(res: any) => {
logger.debug('awareness handshake finished', res);

View File

@@ -37,7 +37,7 @@ export class CloudDocEngineServer implements DocServer {
await this.socket.emitWithAck('space:join', {
spaceType: 'workspace',
spaceId: this.workspaceId,
clientVersion: runtimeConfig.appVersion,
clientVersion: BUILD_CONFIG.appVersion,
});
}

View File

@@ -139,7 +139,7 @@ export function NormalPageHeader({ page, workspace }: PageHeaderProps) {
{hideCollect ? null : (
<>
<FavoriteButton pageId={page?.id} />
{runtimeConfig.enableInfoModal ? <InfoButton /> : null}
<InfoButton />
</>
)}
<PageHeaderMenuButton

View File

@@ -1,8 +1,8 @@
export function popupWindow(target: string) {
const url = new URL(runtimeConfig.serverUrlPrefix + '/redirect-proxy');
const url = new URL(BUILD_CONFIG.serverUrlPrefix + '/redirect-proxy');
target = /^https?:\/\//.test(target)
? target
: runtimeConfig.serverUrlPrefix + target;
: BUILD_CONFIG.serverUrlPrefix + target;
url.searchParams.set('redirect_uri', target);
return window.open(url, '_blank', `noreferrer noopener`);
}

View File

@@ -8,7 +8,7 @@ interface AppUrlOptions {
export function buildAppUrl(path: string, opts: AppUrlOptions = {}) {
// TODO(@EYHN): should use server base url
const webBase = runtimeConfig.serverUrlPrefix;
const webBase = BUILD_CONFIG.serverUrlPrefix;
// TODO(@pengx17): how could we know the corresponding app schema in web environment
if (opts.desktop && appInfo?.schema) {
const urlCtor = new URL(path, webBase);

View File

@@ -11,7 +11,7 @@ setupGlobal();
export function getBaseUrl(): string {
if (environment.isElectron) {
return runtimeConfig.serverUrlPrefix;
return BUILD_CONFIG.serverUrlPrefix;
}
if (typeof window === 'undefined') {
// is nodejs

View File

@@ -1,14 +1,12 @@
import { getRuntimeConfig } from '@affine/cli/src/webpack/runtime-config';
import { setupGlobal } from '@affine/env/global';
process.env.RUNTIME_CONFIG = JSON.stringify(
getRuntimeConfig({
distribution: 'web',
mode: 'development',
channel: 'canary',
static: false,
})
);
globalThis.BUILD_CONFIG = getRuntimeConfig({
distribution: 'web',
mode: 'development',
channel: 'canary',
static: false,
});
if (typeof window !== 'undefined') {
window.location.search = '?prefixUrl=http://127.0.0.1:3010/';

View File

@@ -1,4 +1,4 @@
import type { Environment, RuntimeConfig } from '@affine/env/global';
import type { BUILD_CONFIG_TYPE, Environment } from '@affine/env/global';
declare global {
// eslint-disable-next-line no-var
@@ -8,7 +8,7 @@ declare global {
// eslint-disable-next-line no-var
var environment: Environment;
// eslint-disable-next-line no-var
var runtimeConfig: RuntimeConfig;
var BUILD_CONFIG: BUILD_CONFIG_TYPE;
// eslint-disable-next-line no-var
var $AFFINE_SETUP: boolean | undefined;
/**

View File

@@ -1,7 +1,7 @@
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
import type { RuntimeConfig } from '@affine/env/global';
import type { BUILD_CONFIG_TYPE } from '@affine/env/global';
import { PerfseePlugin } from '@perfsee/webpack';
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
import { sentryWebpackPlugin } from '@sentry/webpack-plugin';
@@ -89,8 +89,8 @@ export const getPublicPath = (buildFlags: BuildFlags) => {
export const createConfiguration: (
cwd: string,
buildFlags: BuildFlags,
runtimeConfig: RuntimeConfig
) => webpack.Configuration = (cwd, buildFlags, runtimeConfig) => {
buildConfig: BUILD_CONFIG_TYPE
) => webpack.Configuration = (cwd, buildFlags, buildConfig) => {
const blocksuiteBaseDir = buildFlags.localBlockSuite;
const config = {
name: 'affine',
@@ -350,8 +350,12 @@ export const createConfiguration: (
process.env.MIXPANEL_TOKEN
),
'process.env.DEBUG_JOTAI': JSON.stringify(process.env.DEBUG_JOTAI),
'process.env.RUNTIME_CONFIG': JSON.stringify(
JSON.stringify(runtimeConfig)
...Object.entries(buildConfig).reduce(
(def, [k, v]) => {
def[`BUILD_CONFIG.${k}`] = JSON.stringify(v);
return def;
},
{} as Record<string, string>
),
}),
buildFlags.distribution === 'admin'

View File

@@ -1,10 +1,10 @@
import type { RuntimeConfig } from '@affine/env/global';
import type { BUILD_CONFIG_TYPE } from '@affine/env/global';
import packageJson from '../../package.json' assert { type: 'json' };
import type { BuildFlags } from '../config';
export function getRuntimeConfig(buildFlags: BuildFlags): RuntimeConfig {
const buildPreset: Record<BuildFlags['channel'], RuntimeConfig> = {
export function getRuntimeConfig(buildFlags: BuildFlags): BUILD_CONFIG_TYPE {
const buildPreset: Record<BuildFlags['channel'], BUILD_CONFIG_TYPE> = {
get stable() {
return {
distribution: buildFlags.distribution,
@@ -21,13 +21,10 @@ export function getRuntimeConfig(buildFlags: BuildFlags): RuntimeConfig {
enableExperimentalFeature: true,
allowLocalWorkspace:
buildFlags.distribution === 'desktop' ? true : false,
enableOrganize: true,
enableInfoModal: true,
enableThemeEditor: false,
// CAUTION(@forehalo): product not ready, do not enable it
enableNewSettingUnstableApi: false,
enableEnhanceShareMode: false,
enableThemeEditor: false,
};
},
get beta() {
@@ -53,8 +50,6 @@ export function getRuntimeConfig(buildFlags: BuildFlags): RuntimeConfig {
appBuildType: 'canary' as const,
serverUrlPrefix: 'https://affine.fail',
changelogUrl: 'https://github.com/toeverything/AFFiNE/releases',
enableInfoModal: true,
enableOrganize: true,
enableThemeEditor: true,
};
},
@@ -76,9 +71,6 @@ export function getRuntimeConfig(buildFlags: BuildFlags): RuntimeConfig {
enableNewSettingUnstableApi: process.env.ENABLE_NEW_SETTING_UNSTABLE_API
? process.env.ENABLE_NEW_SETTING_UNSTABLE_API === 'true'
: currentBuildPreset.enableNewSettingUnstableApi,
enableEnhanceShareMode: process.env.ENABLE_ENHANCE_SHARE_MODE
? process.env.ENABLE_ENHANCE_SHARE_MODE === 'true'
: currentBuildPreset.enableEnhanceShareMode,
allowLocalWorkspace: process.env.ALLOW_LOCAL_WORKSPACE
? process.env.ALLOW_LOCAL_WORKSPACE === 'true'
: buildFlags.mode === 'development'