mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
refactor!: remove next.js (#3267)
This commit is contained in:
1
packages/env/package.json
vendored
1
packages/env/package.json
vendored
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"name": "@affine/env",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./src/index.ts",
|
||||
"module": "./src/index.ts",
|
||||
"types": "./src/global.ts",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, test } from 'vitest';
|
||||
|
||||
import { isValidIPAddress } from '../is-valid-ip-address';
|
||||
import { isValidIPAddress } from '../is-valid-ip-address.js';
|
||||
|
||||
describe('isValidIpAddress', () => {
|
||||
test('should return true for valid IP address', () => {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { fileURLToPath } from 'url';
|
||||
import { describe, expect, test } from 'vitest';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import { migrateToSubdoc } from '../blocksuite';
|
||||
import { migrateToSubdoc } from '../blocksuite/index.js';
|
||||
|
||||
const fixturePath = resolve(
|
||||
dirname(fileURLToPath(import.meta.url)),
|
||||
|
||||
8
packages/env/src/blocksuite/index.ts
vendored
8
packages/env/src/blocksuite/index.ts
vendored
@@ -2,7 +2,11 @@ import type { Page } from '@blocksuite/store';
|
||||
|
||||
export async function initPageWithPreloading(page: Page) {
|
||||
const workspace = page.workspace;
|
||||
const { data } = await import('@affine/templates/preloading.json');
|
||||
const {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-expect-error
|
||||
data,
|
||||
} = await import('@affine/templates/preloading.json');
|
||||
await page.waitForLoaded();
|
||||
await workspace.importPageSnapshot(data['space:hello-world'], page.id);
|
||||
}
|
||||
@@ -17,4 +21,4 @@ export async function initEmptyPage(page: Page) {
|
||||
page.addBlock('affine:paragraph', {}, noteBlockId);
|
||||
}
|
||||
|
||||
export * from './subdoc-migration';
|
||||
export * from './subdoc-migration.js';
|
||||
|
||||
79
packages/env/src/global.ts
vendored
79
packages/env/src/global.ts
vendored
@@ -10,13 +10,11 @@ import type {
|
||||
UpdaterHandlerManager,
|
||||
WorkspaceHandlerManager,
|
||||
} from '@toeverything/infra';
|
||||
// fixme(himself65): remove `next/config` dependency
|
||||
import getConfig from 'next/config';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { isBrowser, isDesktop, isServer } from './constant';
|
||||
import { isValidIPAddress } from './is-valid-ip-address';
|
||||
import { UaHelper } from './ua-helper';
|
||||
import { isBrowser, isDesktop, isServer } from './constant.js';
|
||||
import { isValidIPAddress } from './is-valid-ip-address.js';
|
||||
import { UaHelper } from './ua-helper.js';
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
@@ -46,7 +44,7 @@ declare global {
|
||||
// eslint-disable-next-line no-var
|
||||
var environment: Environment;
|
||||
// eslint-disable-next-line no-var
|
||||
var runtimeConfig: PublicRuntimeConfig;
|
||||
var runtimeConfig: RuntimeConfig;
|
||||
// eslint-disable-next-line no-var
|
||||
var $AFFINE_SETUP: boolean | undefined;
|
||||
// eslint-disable-next-line no-var
|
||||
@@ -57,7 +55,18 @@ declare global {
|
||||
var websocketPrefixUrl: string;
|
||||
}
|
||||
|
||||
export const buildFlagsSchema = z.object({
|
||||
export const blockSuiteFeatureFlags = z.object({
|
||||
enable_database: z.boolean(),
|
||||
enable_drag_handle: z.boolean(),
|
||||
enable_surface: z.boolean(),
|
||||
enable_block_hub: z.boolean(),
|
||||
enable_slash_menu: z.boolean(),
|
||||
enable_edgeless_toolbar: z.boolean(),
|
||||
enable_linked_page: z.boolean(),
|
||||
enable_bookmark_operation: z.boolean(),
|
||||
});
|
||||
|
||||
export const runtimeFlagsSchema = z.object({
|
||||
enablePlugin: z.boolean(),
|
||||
enableTestProperties: z.boolean(),
|
||||
enableBroadcastChannelProvider: z.boolean(),
|
||||
@@ -72,41 +81,15 @@ export const buildFlagsSchema = z.object({
|
||||
enableNotificationCenter: z.boolean(),
|
||||
enableCloud: z.boolean(),
|
||||
enableMoveDatabase: z.boolean(),
|
||||
});
|
||||
|
||||
export const blockSuiteFeatureFlags = z.object({
|
||||
enable_database: z.boolean(),
|
||||
enable_drag_handle: z.boolean(),
|
||||
enable_surface: z.boolean(),
|
||||
enable_block_hub: z.boolean(),
|
||||
enable_slash_menu: z.boolean(),
|
||||
enable_edgeless_toolbar: z.boolean(),
|
||||
enable_linked_page: z.boolean(),
|
||||
enable_bookmark_operation: z.boolean(),
|
||||
serverAPI: z.string(),
|
||||
editorFlags: blockSuiteFeatureFlags,
|
||||
appVersion: z.string(),
|
||||
editorVersion: z.string(),
|
||||
});
|
||||
|
||||
export type BlockSuiteFeatureFlags = z.infer<typeof blockSuiteFeatureFlags>;
|
||||
|
||||
export type BuildFlags = z.infer<typeof buildFlagsSchema>;
|
||||
|
||||
export const publicRuntimeConfigSchema = buildFlagsSchema.extend({
|
||||
PROJECT_NAME: z.string(),
|
||||
BUILD_DATE: z.string(),
|
||||
gitVersion: z.string(),
|
||||
appVersion: z.string(),
|
||||
editorVersion: z.string(),
|
||||
hash: z.string(),
|
||||
serverAPI: z.string(),
|
||||
editorFlags: blockSuiteFeatureFlags,
|
||||
});
|
||||
|
||||
export type PublicRuntimeConfig = z.infer<typeof publicRuntimeConfigSchema>;
|
||||
|
||||
const { publicRuntimeConfig: config } = getConfig() as {
|
||||
publicRuntimeConfig: PublicRuntimeConfig;
|
||||
};
|
||||
|
||||
publicRuntimeConfigSchema.parse(config);
|
||||
export type RuntimeConfig = z.infer<typeof runtimeFlagsSchema>;
|
||||
|
||||
export const platformSchema = z.enum([
|
||||
'aix',
|
||||
@@ -175,27 +158,12 @@ interface Desktop extends ChromeBrowser {
|
||||
|
||||
export type Environment = Browser | Server | Desktop;
|
||||
|
||||
function printBuildInfo() {
|
||||
console.group('Build info');
|
||||
console.log('Project:', config.PROJECT_NAME);
|
||||
console.log(
|
||||
'Build date:',
|
||||
config.BUILD_DATE ? new Date(config.BUILD_DATE).toLocaleString() : 'Unknown'
|
||||
);
|
||||
|
||||
console.log('Version:', config.gitVersion);
|
||||
console.log(
|
||||
'AFFiNE is an open source project, you can view its source code on GitHub!'
|
||||
);
|
||||
console.log(`https://github.com/toeverything/AFFiNE/tree/${config.hash}`);
|
||||
console.groupEnd();
|
||||
}
|
||||
|
||||
export function setupGlobal() {
|
||||
if (globalThis.$AFFINE_SETUP) {
|
||||
return;
|
||||
}
|
||||
globalThis.runtimeConfig = config;
|
||||
runtimeFlagsSchema.parse(runtimeConfig);
|
||||
|
||||
let environment: Environment;
|
||||
const isDebug = process.env.NODE_ENV === 'development';
|
||||
if (isServer) {
|
||||
@@ -239,7 +207,6 @@ export function setupGlobal() {
|
||||
globalThis.environment = environment;
|
||||
|
||||
if (environment.isBrowser) {
|
||||
printBuildInfo();
|
||||
globalThis.editorVersion = global.editorVersion;
|
||||
}
|
||||
|
||||
|
||||
2
packages/env/src/workspace.ts
vendored
2
packages/env/src/workspace.ts
vendored
@@ -7,7 +7,7 @@ import type {
|
||||
} from '@blocksuite/store';
|
||||
import type { FC, PropsWithChildren } from 'react';
|
||||
|
||||
import type { Collection } from './filter';
|
||||
import type { Collection } from './filter.js';
|
||||
|
||||
export enum WorkspaceVersion {
|
||||
SubDoc = 2,
|
||||
|
||||
1
packages/env/tsconfig.json
vendored
1
packages/env/tsconfig.json
vendored
@@ -4,6 +4,7 @@
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"noEmit": false,
|
||||
"moduleResolution": "Node16",
|
||||
"outDir": "lib"
|
||||
},
|
||||
"references": [
|
||||
|
||||
Reference in New Issue
Block a user