From fb9d200dd3a95667ce6f7b63d0b9e5b74b141375 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Wed, 31 May 2023 20:49:56 +0800 Subject: [PATCH] build: perform TypeCheck for all packages (#2573) Co-authored-by: himself65 Co-authored-by: Peng Xiao --- .eslintignore | 1 + .github/workflows/build.yml | 2 + .gitignore | 2 + .../{constraints.ts => constraints.d.ts} | 4 +- .../main/src/__tests__/integration.spec.ts | 2 - .../main/src/application-menu/create.ts | 2 +- .../layers/main/src/db/base-db-adapter.ts | 4 +- .../main/src/db/workspace-db-adapter.ts | 3 +- .../electron/layers/main/src/dialog/dialog.ts | 10 +- apps/electron/layers/main/src/export/pdf.ts | 2 +- apps/electron/layers/main/src/main-window.ts | 2 +- apps/electron/layers/main/src/ui/index.ts | 2 +- .../main/src/updater/electron-updater.ts | 2 +- .../electron/layers/main/src/updater/event.ts | 2 +- apps/electron/layers/main/src/utils.ts | 8 + apps/electron/layers/preload/preload.d.ts | 1 - .../layers/preload/src/affine-apis.ts | 6 +- apps/electron/layers/utils.ts | 7 - apps/electron/tests/tsconfig.json | 4 +- apps/electron/tsconfig.json | 11 +- apps/electron/tsconfig.node.json | 6 +- apps/server/src/config/def.ts | 2 +- apps/server/tsconfig.node.json | 3 +- apps/web/src/bootstrap/index.ts | 0 .../blocksuite/workspace-header/header.tsx | 2 +- .../components/pure/message-center/index.tsx | 4 +- apps/web/src/hooks/use-router-helper.ts | 2 +- apps/web/src/pages/_app.tsx | 2 +- apps/web/src/shared/index.ts | 8 +- apps/web/tsconfig.json | 34 +++- package.json | 3 +- packages/component/.storybook/preview.tsx | 6 +- .../app-sidebar/menu-item/index.tsx | 6 +- .../page-list/__tests__/filter.spec.tsx | 12 +- .../component/src/ui/breadcrumbs/index.ts | 7 +- packages/component/tsconfig.json | 29 +++- packages/component/tsconfig.node.json | 9 +- packages/debug/.gitignore | 1 + packages/debug/tsconfig.json | 10 +- packages/env/.gitignore | 1 + .../blocksuite.ts => blocksuite/index.ts} | 7 +- packages/env/env.d.ts | 1 - packages/env/package.json | 4 +- packages/env/src/bootstrap.ts | 11 -- packages/env/src/config.ts | 8 +- packages/env/src/constant.ts | 38 ++--- packages/env/src/global.d.ts | 5 + packages/env/src/types.d.ts | 10 -- packages/env/src/ua-helper.ts | 156 ++++++++---------- packages/env/tsconfig.blocksuite.json | 11 ++ packages/env/tsconfig.json | 8 +- packages/hooks/package.json | 4 + packages/hooks/tsconfig.json | 8 +- packages/i18n/.gitignore | 1 + packages/i18n/tsconfig.json | 9 +- packages/i18n/tsconfig.resources.json | 13 ++ packages/jotai/.gitignore | 1 + packages/jotai/tsconfig.json | 8 +- packages/native/__tests__/fs.spec.mts | 9 +- packages/native/index.d.ts | 2 +- packages/plugin-infra/tsconfig.json | 12 +- packages/plugin-infra/tsconfig.node.json | 9 - packages/workspace/.gitignore | 1 + packages/workspace/package.json | 4 +- .../src/affine/__tests__/api.spec.ts | 11 +- packages/workspace/src/affine/api/index.ts | 9 +- packages/workspace/src/affine/login.ts | 2 +- packages/workspace/src/type.ts | 8 +- packages/workspace/tsconfig.json | 16 +- packages/y-indexeddb/.gitignore | 1 + packages/y-indexeddb/tsconfig.json | 8 + packages/y-indexeddb/tsconfig.node.json | 3 +- plugins/copilot/src/index.ts | 2 + plugins/copilot/tsconfig.json | 18 +- tests/fixtures/.gitignore | 1 + tests/fixtures/tsconfig.json | 9 +- tests/kit/.gitignore | 1 + tests/kit/tsconfig.json | 5 + tsconfig.json | 8 +- tsconfig.node.json | 3 +- yarn.lock | 6 +- 81 files changed, 434 insertions(+), 241 deletions(-) rename apps/electron/layers/{constraints.ts => constraints.d.ts} (55%) delete mode 100644 apps/electron/layers/utils.ts create mode 100644 apps/web/src/bootstrap/index.ts create mode 100644 packages/debug/.gitignore create mode 100644 packages/env/.gitignore rename packages/env/{src/blocksuite.ts => blocksuite/index.ts} (87%) delete mode 100644 packages/env/src/bootstrap.ts create mode 100644 packages/env/src/global.d.ts delete mode 100644 packages/env/src/types.d.ts create mode 100644 packages/env/tsconfig.blocksuite.json create mode 100644 packages/i18n/.gitignore create mode 100644 packages/i18n/tsconfig.resources.json create mode 100644 packages/jotai/.gitignore delete mode 100644 packages/plugin-infra/tsconfig.node.json create mode 100644 packages/workspace/.gitignore create mode 100644 packages/y-indexeddb/.gitignore create mode 100644 tests/fixtures/.gitignore create mode 100644 tests/kit/.gitignore diff --git a/.eslintignore b/.eslintignore index b86c8d9e9c..42871b1461 100644 --- a/.eslintignore +++ b/.eslintignore @@ -5,3 +5,4 @@ out storybook-static affine-out _next +lib diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4bc457ee9a..0c6749f6d1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,6 +36,8 @@ jobs: - name: Setup Node.js uses: ./.github/actions/setup-node - run: | + yarn i18n-codegen gen + yarn typecheck yarn lint --max-warnings=0 yarn circular diff --git a/.gitignore b/.gitignore index f0f8ca3059..f789cacca8 100644 --- a/.gitignore +++ b/.gitignore @@ -70,3 +70,5 @@ next-env.d.ts # Rust target *.node +tsconfig.node.tsbuildinfo +lib diff --git a/apps/electron/layers/constraints.ts b/apps/electron/layers/constraints.d.ts similarity index 55% rename from apps/electron/layers/constraints.ts rename to apps/electron/layers/constraints.d.ts index 59df37c8f9..c5fac6ff58 100644 --- a/apps/electron/layers/constraints.ts +++ b/apps/electron/layers/constraints.d.ts @@ -2,6 +2,6 @@ // This file contains the main process events // It will guide preload and main process on the correct event types and payloads -export type MainIPCHandlerMap = typeof import('./main/src/exposed').handlers; +declare type MainIPCHandlerMap = typeof import('./main/src/exposed').handlers; -export type MainIPCEventMap = typeof import('./main/src/exposed').events; +declare type MainIPCEventMap = typeof import('./main/src/exposed').events; diff --git a/apps/electron/layers/main/src/__tests__/integration.spec.ts b/apps/electron/layers/main/src/__tests__/integration.spec.ts index d958cb43f8..2f4d25606f 100644 --- a/apps/electron/layers/main/src/__tests__/integration.spec.ts +++ b/apps/electron/layers/main/src/__tests__/integration.spec.ts @@ -6,8 +6,6 @@ import { v4 } from 'uuid'; import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'; import * as Y from 'yjs'; -import type { MainIPCHandlerMap } from '../../../constraints'; - const registeredHandlers = new Map< string, ((...args: any[]) => Promise)[] diff --git a/apps/electron/layers/main/src/application-menu/create.ts b/apps/electron/layers/main/src/application-menu/create.ts index 646d40dfcc..a3e096a623 100644 --- a/apps/electron/layers/main/src/application-menu/create.ts +++ b/apps/electron/layers/main/src/application-menu/create.ts @@ -1,8 +1,8 @@ import { app, Menu } from 'electron'; -import { isMacOS } from '../../../utils'; import { revealLogFile } from '../logger'; import { checkForUpdatesAndNotify } from '../updater'; +import { isMacOS } from '../utils'; import { applicationMenuSubjects } from './subject'; // Unique id for menuitems diff --git a/apps/electron/layers/main/src/db/base-db-adapter.ts b/apps/electron/layers/main/src/db/base-db-adapter.ts index a28e96b828..077b7483d3 100644 --- a/apps/electron/layers/main/src/db/base-db-adapter.ts +++ b/apps/electron/layers/main/src/db/base-db-adapter.ts @@ -44,9 +44,9 @@ export abstract class BaseSQLiteAdapter { } // todo: what if SQLite DB wrapper later is not sync? - connect() { + connect(): Database | undefined { if (this.db) { - return; + return this.db; } logger.log(`[SQLiteAdapter][${this.role}] open db`, this.path); const db = (this.db = sqlite(this.path)); diff --git a/apps/electron/layers/main/src/db/workspace-db-adapter.ts b/apps/electron/layers/main/src/db/workspace-db-adapter.ts index 598ec17c83..8116ffba9c 100644 --- a/apps/electron/layers/main/src/db/workspace-db-adapter.ts +++ b/apps/electron/layers/main/src/db/workspace-db-adapter.ts @@ -1,3 +1,4 @@ +import type { Database } from 'better-sqlite3'; import { Subject } from 'rxjs'; import * as Y from 'yjs'; @@ -33,7 +34,7 @@ export class WorkspaceSQLiteDB extends BaseSQLiteAdapter { return this.yDoc.getMap('space:meta').get('name') as string; }; - async init() { + async init(): Promise { const db = super.connect(); if (!this.firstConnected) { diff --git a/apps/electron/layers/main/src/dialog/dialog.ts b/apps/electron/layers/main/src/dialog/dialog.ts index fffcb39add..10e390a96f 100644 --- a/apps/electron/layers/main/src/dialog/dialog.ts +++ b/apps/electron/layers/main/src/dialog/dialog.ts @@ -29,7 +29,7 @@ export async function revealDBFile(workspaceId: string) { } // provide a backdoor to set dialog path for testing in playwright -interface FakeDialogResult { +export interface FakeDialogResult { canceled?: boolean; filePath?: string; filePaths?: string[]; @@ -63,7 +63,7 @@ const ErrorMessages = [ type ErrorMessage = (typeof ErrorMessages)[number]; -interface SaveDBFileResult { +export interface SaveDBFileResult { filePath?: string; canceled?: boolean; error?: ErrorMessage; @@ -122,7 +122,7 @@ export async function saveDBFileAs( } } -interface SelectDBFileLocationResult { +export interface SelectDBFileLocationResult { filePath?: string; error?: ErrorMessage; canceled?: boolean; @@ -154,7 +154,7 @@ export async function selectDBFileLocation(): Promise { } } -interface MoveDBFileResult { +export interface MoveDBFileResult { filePath?: string; error?: ErrorMessage; canceled?: boolean; diff --git a/apps/electron/layers/main/src/export/pdf.ts b/apps/electron/layers/main/src/export/pdf.ts index 1e1dba5ac2..40a06aa11f 100644 --- a/apps/electron/layers/main/src/export/pdf.ts +++ b/apps/electron/layers/main/src/export/pdf.ts @@ -5,7 +5,7 @@ import { logger } from '../logger'; import type { ErrorMessage } from './utils'; import { getFakedResult } from './utils'; -interface SavePDFFileResult { +export interface SavePDFFileResult { filePath?: string; canceled?: boolean; error?: ErrorMessage; diff --git a/apps/electron/layers/main/src/main-window.ts b/apps/electron/layers/main/src/main-window.ts index 3e1bdba5d2..9f6d885c13 100644 --- a/apps/electron/layers/main/src/main-window.ts +++ b/apps/electron/layers/main/src/main-window.ts @@ -2,9 +2,9 @@ import { BrowserWindow, nativeTheme } from 'electron'; import electronWindowState from 'electron-window-state'; import { join } from 'path'; -import { isMacOS, isWindows } from '../../utils'; import { getExposedMeta } from './exposed'; import { logger } from './logger'; +import { isMacOS, isWindows } from './utils'; const IS_DEV: boolean = process.env.NODE_ENV === 'development' && !process.env.CI; diff --git a/apps/electron/layers/main/src/ui/index.ts b/apps/electron/layers/main/src/ui/index.ts index 145ff10bb8..2ea0d7cd19 100644 --- a/apps/electron/layers/main/src/ui/index.ts +++ b/apps/electron/layers/main/src/ui/index.ts @@ -1,7 +1,7 @@ import { app, BrowserWindow, nativeTheme, session } from 'electron'; -import { isMacOS } from '../../../utils'; import type { NamespaceHandlers } from '../type'; +import { isMacOS } from '../utils'; import { getMetaData } from './get-meta-data'; import { getGoogleOauthCode } from './google-auth'; diff --git a/apps/electron/layers/main/src/updater/electron-updater.ts b/apps/electron/layers/main/src/updater/electron-updater.ts index 72533af68a..f1e50f97d4 100644 --- a/apps/electron/layers/main/src/updater/electron-updater.ts +++ b/apps/electron/layers/main/src/updater/electron-updater.ts @@ -2,8 +2,8 @@ import { app } from 'electron'; import type { AppUpdater } from 'electron-updater'; import { z } from 'zod'; -import { isMacOS } from '../../../utils'; import { logger } from '../logger'; +import { isMacOS } from '../utils'; import { updaterSubjects } from './event'; export const ReleaseTypeSchema = z.enum([ diff --git a/apps/electron/layers/main/src/updater/event.ts b/apps/electron/layers/main/src/updater/event.ts index 14aefd909e..8c95352945 100644 --- a/apps/electron/layers/main/src/updater/event.ts +++ b/apps/electron/layers/main/src/updater/event.ts @@ -2,7 +2,7 @@ import { BehaviorSubject, Subject } from 'rxjs'; import type { MainEventListener } from '../type'; -interface UpdateMeta { +export interface UpdateMeta { version: string; allowAutoUpdate: boolean; } diff --git a/apps/electron/layers/main/src/utils.ts b/apps/electron/layers/main/src/utils.ts index 658f6a5838..f2ac392fc4 100644 --- a/apps/electron/layers/main/src/utils.ts +++ b/apps/electron/layers/main/src/utils.ts @@ -1,3 +1,11 @@ export function getTime() { return new Date().getTime(); } + +export const isMacOS = () => { + return process.platform === 'darwin'; +}; + +export const isWindows = () => { + return process.platform === 'win32'; +}; diff --git a/apps/electron/layers/preload/preload.d.ts b/apps/electron/layers/preload/preload.d.ts index f96bb8445f..fbccb3c2b7 100644 --- a/apps/electron/layers/preload/preload.d.ts +++ b/apps/electron/layers/preload/preload.d.ts @@ -3,5 +3,4 @@ interface Window { apis: typeof import('./src/affine-apis').apis; events: typeof import('./src/affine-apis').events; - appInfo: typeof import('./src/affine-apis').appInfo; } diff --git a/apps/electron/layers/preload/src/affine-apis.ts b/apps/electron/layers/preload/src/affine-apis.ts index 8c3fb6089a..c8a6df18ee 100644 --- a/apps/electron/layers/preload/src/affine-apis.ts +++ b/apps/electron/layers/preload/src/affine-apis.ts @@ -1,10 +1,10 @@ /* eslint-disable @typescript-eslint/no-var-requires */ +// eslint-disable-next-line @typescript-eslint/triple-slash-reference +/// + // NOTE: we will generate preload types from this file - import { ipcRenderer } from 'electron'; -import type { MainIPCEventMap, MainIPCHandlerMap } from '../../constraints'; - type WithoutFirstParameter = T extends (_: any, ...args: infer P) => infer R ? (...args: P) => R : T; diff --git a/apps/electron/layers/utils.ts b/apps/electron/layers/utils.ts deleted file mode 100644 index af4871d2b5..0000000000 --- a/apps/electron/layers/utils.ts +++ /dev/null @@ -1,7 +0,0 @@ -export const isMacOS = () => { - return process.platform === 'darwin'; -}; - -export const isWindows = () => { - return process.platform === 'win32'; -}; diff --git a/apps/electron/tests/tsconfig.json b/apps/electron/tests/tsconfig.json index 4c43f890a3..d29c9c2e1b 100644 --- a/apps/electron/tests/tsconfig.json +++ b/apps/electron/tests/tsconfig.json @@ -2,7 +2,9 @@ "extends": "../../../tsconfig.json", "compilerOptions": { "baseUrl": ".", - "noEmit": true + "noEmit": true, + "target": "ESNext" }, + "references": [{ "path": "../../../tests/kit" }], "include": ["**.spec.ts", "**.test.ts"] } diff --git a/apps/electron/tsconfig.json b/apps/electron/tsconfig.json index 5c027b72cd..db9bb339a1 100644 --- a/apps/electron/tsconfig.json +++ b/apps/electron/tsconfig.json @@ -1,6 +1,7 @@ { "extends": "../../tsconfig.json", "compilerOptions": { + "composite": true, "skipLibCheck": true, "target": "ESNext", "module": "ESNext", @@ -12,15 +13,19 @@ "resolveJsonModule": true, "noImplicitOverride": true }, - "include": ["**/*.ts", "**/*.tsx", "package.json"], - "exclude": ["out", "dist", "node_modules"], + "include": ["**/*.ts", "**/*.tsx"], + "exclude": ["node_modules", "out", "dist"], "references": [ { "path": "./tsconfig.node.json" }, { "path": "../../packages/native" - } + }, + { + "path": "../../packages/env" + }, + { "path": "../../tests/kit" } ], "ts-node": { "esm": true, diff --git a/apps/electron/tsconfig.node.json b/apps/electron/tsconfig.node.json index b9e486d423..caf1aab7f6 100644 --- a/apps/electron/tsconfig.node.json +++ b/apps/electron/tsconfig.node.json @@ -1,11 +1,13 @@ { + "extends": "./tsconfig.json", "compilerOptions": { "composite": true, "target": "ESNext", "module": "ESNext", "resolveJsonModule": true, "moduleResolution": "Node", - "allowSyntheticDefaultImports": true + "allowSyntheticDefaultImports": true, + "noEmit": false }, - "include": ["./scripts", "package.json"] + "include": ["./scripts"] } diff --git a/apps/server/src/config/def.ts b/apps/server/src/config/def.ts index baf055329c..233ccf64ca 100644 --- a/apps/server/src/config/def.ts +++ b/apps/server/src/config/def.ts @@ -10,7 +10,7 @@ declare global { } } -export const enum ExternalAccount { +export enum ExternalAccount { github = 'github', google = 'google', firebase = 'firebase', diff --git a/apps/server/tsconfig.node.json b/apps/server/tsconfig.node.json index 4651f71bc1..c97171294c 100644 --- a/apps/server/tsconfig.node.json +++ b/apps/server/tsconfig.node.json @@ -5,7 +5,8 @@ "module": "ESNext", "resolveJsonModule": true, "moduleResolution": "Node", - "allowSyntheticDefaultImports": true + "allowSyntheticDefaultImports": true, + "outDir": "dist/scripts" }, "include": ["scripts", "package.json"] } diff --git a/apps/web/src/bootstrap/index.ts b/apps/web/src/bootstrap/index.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/apps/web/src/components/blocksuite/workspace-header/header.tsx b/apps/web/src/components/blocksuite/workspace-header/header.tsx index 6630fb1504..97621a6ce9 100644 --- a/apps/web/src/components/blocksuite/workspace-header/header.tsx +++ b/apps/web/src/components/blocksuite/workspace-header/header.tsx @@ -36,7 +36,7 @@ export type BaseHeaderProps< leftSlot?: ReactNode; }; -export const enum HeaderRightItemName { +export enum HeaderRightItemName { EditorOptionMenu = 'editorOptionMenu', TrashButtonGroup = 'trashButtonGroup', SyncUser = 'syncUser', diff --git a/apps/web/src/components/pure/message-center/index.tsx b/apps/web/src/components/pure/message-center/index.tsx index db8d71f30f..a038adcb58 100644 --- a/apps/web/src/components/pure/message-center/index.tsx +++ b/apps/web/src/components/pure/message-center/index.tsx @@ -10,7 +10,7 @@ import { toast } from '../../../utils'; declare global { interface DocumentEventMap { 'affine-error': CustomEvent<{ - code: MessageCode; + code: keyof typeof Messages; }>; } } @@ -21,7 +21,7 @@ export const MessageCenter: FC = memo(function MessageCenter() { useEffect(() => { const listener = ( event: CustomEvent<{ - code: MessageCode; + code: keyof typeof Messages; }> ) => { // fixme: need refactor diff --git a/apps/web/src/hooks/use-router-helper.ts b/apps/web/src/hooks/use-router-helper.ts index 4b991bebd2..57ee2d4aaa 100644 --- a/apps/web/src/hooks/use-router-helper.ts +++ b/apps/web/src/hooks/use-router-helper.ts @@ -2,7 +2,7 @@ import type { WorkspaceSubPath } from '@affine/workspace/type'; import type { NextRouter } from 'next/router'; import { useCallback } from 'react'; -export const enum RouteLogic { +export enum RouteLogic { REPLACE = 'replace', PUSH = 'push', } diff --git a/apps/web/src/pages/_app.tsx b/apps/web/src/pages/_app.tsx index 24c49fdf2e..5c8dad37e0 100644 --- a/apps/web/src/pages/_app.tsx +++ b/apps/web/src/pages/_app.tsx @@ -2,7 +2,7 @@ import '@affine/component/theme/global.css'; import '@affine/component/theme/theme.css'; import 'react-mosaic-component/react-mosaic-component.css'; // bootstrap code before everything -import '@affine/env/bootstrap'; +import '../bootstrap'; import { WorkspaceFallback } from '@affine/component/workspace'; import { config } from '@affine/env'; diff --git a/apps/web/src/shared/index.ts b/apps/web/src/shared/index.ts index feb715cdfc..7c97b2c06e 100644 --- a/apps/web/src/shared/index.ts +++ b/apps/web/src/shared/index.ts @@ -4,7 +4,6 @@ import type { } from '@affine/workspace/type'; import type { AffinePublicWorkspace } from '@affine/workspace/type'; import type { WorkspaceRegistry } from '@affine/workspace/type'; -import { WorkspaceSubPath } from '@affine/workspace/type'; import { Workspace as BlockSuiteWorkspace } from '@blocksuite/store'; import type { NextPage } from 'next'; import type { ReactElement, ReactNode } from 'react'; @@ -25,6 +24,13 @@ export type NextPageWithLayout

, IP = P> = NextPage< getLayout?: (page: ReactElement) => ReactNode; }; +export enum WorkspaceSubPath { + ALL = 'all', + SETTING = 'setting', + TRASH = 'trash', + SHARED = 'shared', +} + export const WorkspaceSubPathName = { [WorkspaceSubPath.ALL]: 'All Pages', [WorkspaceSubPath.SETTING]: 'Settings', diff --git a/apps/web/tsconfig.json b/apps/web/tsconfig.json index f70175678e..84f7241d65 100644 --- a/apps/web/tsconfig.json +++ b/apps/web/tsconfig.json @@ -1,8 +1,7 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "target": "ES2020", - "lib": ["dom", "dom.iterable", "esnext"], + "target": "ESNext", "allowJs": true, "skipLibCheck": true, "strict": true, @@ -18,6 +17,33 @@ "incremental": true, "experimentalDecorators": true }, - "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "src/types/types.d.ts"], - "exclude": ["node_modules"] + "include": [ + "next-env.d.ts", + "**/*.ts", + "**/*.tsx", + "src/types/types.d.ts", + "../../packages/graphql", + "../electron/layers" + ], + "exclude": ["node_modules"], + "references": [ + { + "path": "../../packages/env" + }, + { + "path": "../../packages/debug" + }, + { + "path": "../../packages/component" + }, + { + "path": "../../packages/i18n" + }, + { + "path": "../../packages/jotai" + }, + { + "path": "../../packages/hooks" + } + ] } diff --git a/package.json b/package.json index e27a0718bd..59aa84906c 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,8 @@ "test:unit:ui": "vitest --ui", "test:unit:coverage": "vitest run --coverage", "postinstall": "i18n-codegen gen && husky install", - "notify": "node scripts/notify.mjs" + "notify": "node scripts/notify.mjs", + "typecheck": "tsc -b tsconfig.json" }, "lint-staged": { "*": "prettier --write --ignore-unknown --cache", diff --git a/packages/component/.storybook/preview.tsx b/packages/component/.storybook/preview.tsx index 454b46fd3e..90cf0ac7f4 100644 --- a/packages/component/.storybook/preview.tsx +++ b/packages/component/.storybook/preview.tsx @@ -32,9 +32,9 @@ export const globalTypes = { }, }; -const createI18nDecorator = ({ options } = { options: {} }) => { - const i18n = createI18n(options); - const withI18n = (Story, context) => { +const createI18nDecorator = () => { + const i18n = createI18n(); + const withI18n = (Story: any, context: any) => { const locale = context.globals.locale; useEffect(() => { i18n.changeLanguage(locale); diff --git a/packages/component/src/components/app-sidebar/menu-item/index.tsx b/packages/component/src/components/app-sidebar/menu-item/index.tsx index 72b80b52df..98da84279a 100644 --- a/packages/component/src/components/app-sidebar/menu-item/index.tsx +++ b/packages/component/src/components/app-sidebar/menu-item/index.tsx @@ -6,7 +6,7 @@ import React from 'react'; import * as styles from './index.css'; -interface MenuItemProps extends React.HTMLAttributes { +export interface MenuItemProps extends React.HTMLAttributes { icon?: React.ReactElement; active?: boolean; disabled?: boolean; @@ -14,7 +14,9 @@ interface MenuItemProps extends React.HTMLAttributes { onCollapsedChange?: (collapsed: boolean) => void; } -interface MenuLinkItemProps extends MenuItemProps, Pick {} +export interface MenuLinkItemProps + extends MenuItemProps, + Pick {} export const MenuItem = React.forwardRef( ( diff --git a/packages/component/src/components/page-list/__tests__/filter.spec.tsx b/packages/component/src/components/page-list/__tests__/filter.spec.tsx index 17d24940ff..82fbde5cb8 100644 --- a/packages/component/src/components/page-list/__tests__/filter.spec.tsx +++ b/packages/component/src/components/page-list/__tests__/filter.spec.tsx @@ -30,7 +30,7 @@ const mockVariableMap = (vars: Partial): VariableMap => { return { Created: 0, Updated: 0, - Favorite: false, + 'Is Favourited': false, ...vars, }; }; @@ -103,10 +103,10 @@ describe('eval filter', () => { test('is', async () => { const is = filterMatcher.findData(v => v.name === 'is'); assertExists(is); - const filter1 = filter(is, ref('Favorite'), [false]); - const filter2 = filter(is, ref('Favorite'), [true]); + const filter1 = filter(is, ref('Is Favourited'), [false]); + const filter2 = filter(is, ref('Is Favourited'), [true]); const varMap = mockVariableMap({ - Favorite: true, + 'Is Favourited': true, }); expect(filterByFilterList([filter1], varMap)).toBe(false); expect(filterByFilterList([filter2], varMap)).toBe(true); @@ -118,7 +118,9 @@ describe('render filter', () => { const is = filterMatcher.match(tBoolean.create()); assertExists(is); const Wrapper = () => { - const [value, onChange] = useState(filter(is, ref('Favorite'), [true])); + const [value, onChange] = useState( + filter(is, ref('Is Favourited'), [true]) + ); return ; }; const result = render(); diff --git a/packages/component/src/ui/breadcrumbs/index.ts b/packages/component/src/ui/breadcrumbs/index.ts index 485a84558f..9a87e958a6 100644 --- a/packages/component/src/ui/breadcrumbs/index.ts +++ b/packages/component/src/ui/breadcrumbs/index.ts @@ -1,9 +1,14 @@ +import type { BreadcrumbsProps } from '@mui/material/Breadcrumbs'; import MuiBreadcrumbs from '@mui/material/Breadcrumbs'; +import type { ComponentType } from 'react'; import { styled } from '../../styles'; -export const Breadcrumbs = styled(MuiBreadcrumbs)(() => { +const StyledMuiBreadcrumbs = styled(MuiBreadcrumbs)(() => { return { color: 'var(--affine-text-primary-color)', }; }); + +export const Breadcrumbs: ComponentType = + StyledMuiBreadcrumbs; diff --git a/packages/component/tsconfig.json b/packages/component/tsconfig.json index f95ca73cf0..e6f93d217c 100644 --- a/packages/component/tsconfig.json +++ b/packages/component/tsconfig.json @@ -1,9 +1,34 @@ { "extends": "../../tsconfig.json", - "include": ["./src", "./.storybook/*.ts"], + "include": [ + "./src/**/*.ts", + "./src/**/*.tsx", + "./src/**/*.json", + "../workspace/src", + "../../apps/electron/layers/**/src" + ], + "compilerOptions": { + "composite": true, + "noEmit": false, + "outDir": "lib" + }, + "exclude": ["lib"], "references": [ + { + "path": "../debug" + }, + { + "path": "../i18n" + }, + { + "path": "../jotai" + }, + { + "path": "../hooks" + }, { "path": "./tsconfig.node.json" - } + }, + { "path": "../../tests/fixtures" } ] } diff --git a/packages/component/tsconfig.node.json b/packages/component/tsconfig.node.json index ad6c38576d..270a108650 100644 --- a/packages/component/tsconfig.node.json +++ b/packages/component/tsconfig.node.json @@ -1,11 +1,16 @@ { + "extends": "./tsconfig.json", "compilerOptions": { "composite": true, "module": "ESNext", "jsx": "react-jsx", "moduleResolution": "Node", "esModuleInterop": true, - "allowSyntheticDefaultImports": true + "allowSyntheticDefaultImports": true, + "noEmit": false, + "outDir": "lib/.storybook" }, - "include": [".storybook/**/*"] + "include": [".storybook/**/*"], + "exclude": ["lib"], + "references": [{ "path": "../i18n" }] } diff --git a/packages/debug/.gitignore b/packages/debug/.gitignore new file mode 100644 index 0000000000..a65b41774a --- /dev/null +++ b/packages/debug/.gitignore @@ -0,0 +1 @@ +lib diff --git a/packages/debug/tsconfig.json b/packages/debug/tsconfig.json index d55dc90ebc..7551cd781a 100644 --- a/packages/debug/tsconfig.json +++ b/packages/debug/tsconfig.json @@ -3,8 +3,16 @@ "compilerOptions": { "module": "ESNext", "target": "ESNext", - "sourceMap": true + "sourceMap": true, + "composite": true, + "noEmit": false, + "outDir": "lib" }, + "references": [ + { + "path": "../env" + } + ], "include": ["./src"], "exclude": ["node_modules"] } diff --git a/packages/env/.gitignore b/packages/env/.gitignore new file mode 100644 index 0000000000..a65b41774a --- /dev/null +++ b/packages/env/.gitignore @@ -0,0 +1 @@ +lib diff --git a/packages/env/src/blocksuite.ts b/packages/env/blocksuite/index.ts similarity index 87% rename from packages/env/src/blocksuite.ts rename to packages/env/blocksuite/index.ts index dd080e54c7..4f12dc3587 100644 --- a/packages/env/src/blocksuite.ts +++ b/packages/env/blocksuite/index.ts @@ -1,5 +1,8 @@ +// eslint-disable-next-line @typescript-eslint/triple-slash-reference +/// + import { DebugLogger } from '@affine/debug'; -import markdown from '@affine/templates/AFFiNE-beta-0.5.4.md'; +import markdownTemplate from '@affine/templates/AFFiNE-beta-0.5.4.md'; import { ContentParser } from '@blocksuite/blocks/content-parser'; import type { Page } from '@blocksuite/store'; @@ -9,6 +12,8 @@ declare global { } } +const markdown = markdownTemplate as unknown as string; + const demoTitle = markdown .split('\n') .splice(0, 1) diff --git a/packages/env/env.d.ts b/packages/env/env.d.ts index d023bf71f4..62cc8d30f0 100644 --- a/packages/env/env.d.ts +++ b/packages/env/env.d.ts @@ -1,3 +1,2 @@ -import '../../apps/electron/layers/preload/preload.d.ts'; // eslint-disable-next-line @typescript-eslint/no-restricted-imports import '../hooks/src/use-block-suite-page-meta.ts'; diff --git a/packages/env/package.json b/packages/env/package.json index d667127ac2..476d473a60 100644 --- a/packages/env/package.json +++ b/packages/env/package.json @@ -14,14 +14,12 @@ ".": "./src/index.ts", "./config": "./src/config.ts", "./constant": "./src/constant.ts", - "./blocksuite": "./src/blocksuite.ts" + "./blocksuite": "./blocksuite/index.ts" }, "peerDependencies": { "@blocksuite/global": "0.0.0-20230409084303-221991d4-nightly" }, "dependencies": { - "@affine/copilot": "workspace:*", - "@toeverything/plugin-infra": "workspace:*", "lit": "^2.7.4" }, "version": "0.5.4-beta.2" diff --git a/packages/env/src/bootstrap.ts b/packages/env/src/bootstrap.ts deleted file mode 100644 index 352d0a0902..0000000000 --- a/packages/env/src/bootstrap.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { config, setupGlobal } from './config'; - -setupGlobal(); - -if (config.enablePlugin && !environment.isServer) { - import('@affine/copilot'); -} - -if (!environment.isServer) { - import('@affine/bookmark-block'); -} diff --git a/packages/env/src/config.ts b/packages/env/src/config.ts index 5dc0358741..75e5b56f47 100644 --- a/packages/env/src/config.ts +++ b/packages/env/src/config.ts @@ -1,9 +1,11 @@ /// +// eslint-disable-next-line @typescript-eslint/triple-slash-reference +/// import { assertEquals } from '@blocksuite/global/utils'; import getConfig from 'next/config'; import { z } from 'zod'; -import { getUaHelper } from './ua-helper'; +import { UaHelper } from './ua-helper'; export const buildFlagsSchema = z.object({ /** @@ -111,7 +113,7 @@ export function getEnvironment() { return environment; } const isDebug = process.env.NODE_ENV === 'development'; - if (typeof window === 'undefined') { + if (typeof window === 'undefined' || typeof navigator === 'undefined') { environment = { isDesktop: false, isBrowser: false, @@ -119,7 +121,7 @@ export function getEnvironment() { isDebug, } satisfies Server; } else { - const uaHelper = getUaHelper(); + const uaHelper = new UaHelper(navigator); environment = { origin: window.location.origin, diff --git a/packages/env/src/constant.ts b/packages/env/src/constant.ts index 31096cb938..b12f8c4510 100644 --- a/packages/env/src/constant.ts +++ b/packages/env/src/constant.ts @@ -6,24 +6,24 @@ export const UNTITLED_WORKSPACE_NAME = 'Untitled'; export const DEFAULT_HELLO_WORLD_PAGE_ID = 'hello-world'; export const DEFAULT_SORT_KEY = 'updatedDate'; -export const enum MessageCode { - loginError, - noPermission, - loadListFailed, - getDetailFailed, - createWorkspaceFailed, - getMembersFailed, - updateWorkspaceFailed, - deleteWorkspaceFailed, - inviteMemberFailed, - removeMemberFailed, - acceptInvitingFailed, - getBlobFailed, - leaveWorkspaceFailed, - downloadWorkspaceFailed, - refreshTokenError, - blobTooLarge, -} +export const MessageCode = { + loginError: 0, + noPermission: 1, + loadListFailed: 2, + getDetailFailed: 3, + createWorkspaceFailed: 4, + getMembersFailed: 5, + updateWorkspaceFailed: 6, + deleteWorkspaceFailed: 7, + inviteMemberFailed: 8, + removeMemberFailed: 9, + acceptInvitingFailed: 10, + getBlobFailed: 11, + leaveWorkspaceFailed: 12, + downloadWorkspaceFailed: 13, + refreshTokenError: 14, + blobTooLarge: 15, +} as const; export const Messages = { [MessageCode.loginError]: { @@ -75,7 +75,7 @@ export const Messages = { message: 'Blob too large', }, } as const satisfies { - [key in MessageCode]: { + [key in (typeof MessageCode)[keyof typeof MessageCode]]: { message: string; }; }; diff --git a/packages/env/src/global.d.ts b/packages/env/src/global.d.ts new file mode 100644 index 0000000000..15750c0f60 --- /dev/null +++ b/packages/env/src/global.d.ts @@ -0,0 +1,5 @@ +interface Window { + appInfo: { + electron: bool; + }; +} diff --git a/packages/env/src/types.d.ts b/packages/env/src/types.d.ts deleted file mode 100644 index a459f45e71..0000000000 --- a/packages/env/src/types.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -/// - -// not using import because it will break the declare module line below -// eslint-disable-next-line @typescript-eslint/triple-slash-reference -/// - -declare module '*.md' { - const text: string; - export default text; -} diff --git a/packages/env/src/ua-helper.ts b/packages/env/src/ua-helper.ts index d15e1d80ba..66a685dce3 100644 --- a/packages/env/src/ua-helper.ts +++ b/packages/env/src/ua-helper.ts @@ -1,92 +1,78 @@ import { assertExists } from '@blocksuite/global/utils'; -export function getUaHelper() { - let uaHelper = null; - (function (navigator) { - const getUa = () => { - const ua = navigator.userAgent; - const uas = ua.toLowerCase(); - const mobile = /iPhone|iPad|iPod|Android/i.test(ua); - const android = - (mobile && - (uas.indexOf('android') > -1 || uas.indexOf('linux') > -1)) || - uas.indexOf('adr') > -1; - const ios = mobile && !android && /Mac OS/i.test(ua); - const mac = !mobile && /Mac OS/i.test(ua); - const iphone = ios && uas.indexOf('iphone') > -1; - const ipad = ios && !iphone; - const wx = /MicroMessenger/i.test(ua); - const chrome = /CriOS/i.test(ua) || /Chrome/i.test(ua); - const tiktok = mobile && /aweme/i.test(ua); - const weibo = mobile && /Weibo/i.test(ua); - const safari = - ios && - !chrome && - !wx && - !weibo && - !tiktok && - /Safari|Macintosh/i.test(ua); - const firefox = /Firefox/.test(ua); - const win = /windows|win32|win64|wow32|wow64/.test(uas); - const linux = /linux/.test(uas); - return { - ua, - mobile, - android, - ios, - mac, - wx, - chrome, - iphone, - ipad, - safari, - tiktok, - weibo, - win, - linux, - firefox, - }; - }; +export class UaHelper { + private uaMap; + public isLinux = false; + public isMacOs = false; + public isSafari = false; + public isWindows = false; + public isFireFox = false; + public isMobile = false; + public isChrome = false; + public isIOS = false; - class UaHelper { - private uaMap; - public isLinux = false; - public isMacOs = false; - public isSafari = false; - public isWindows = false; - public isFireFox = false; - public isMobile = false; - public isChrome = false; - public isIOS = false; + getChromeVersion = (): number => { + const raw = this.navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./); + assertExists(raw); + return parseInt(raw[2], 10); + }; - getChromeVersion = (): number => { - const raw = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./); - assertExists(raw); - return parseInt(raw[2], 10); - }; + constructor(private readonly navigator: Navigator) { + this.uaMap = getUa(navigator); + this.initUaFlags(); + } - constructor() { - this.uaMap = getUa(); - this.initUaFlags(); - } + public checkUseragent(isUseragent: keyof ReturnType) { + return Boolean(this.uaMap[isUseragent]); + } - public checkUseragent(isUseragent: keyof ReturnType) { - return Boolean(this.uaMap[isUseragent]); - } - - private initUaFlags() { - this.isLinux = this.checkUseragent('linux'); - this.isMacOs = this.checkUseragent('mac'); - this.isSafari = this.checkUseragent('safari'); - this.isWindows = this.checkUseragent('win'); - this.isFireFox = this.checkUseragent('firefox'); - this.isMobile = this.checkUseragent('mobile'); - this.isChrome = this.checkUseragent('chrome'); - this.isIOS = this.checkUseragent('ios'); - } - } - uaHelper = new UaHelper(); - })(navigator); - - return uaHelper; + private initUaFlags() { + this.isLinux = this.checkUseragent('linux'); + this.isMacOs = this.checkUseragent('mac'); + this.isSafari = this.checkUseragent('safari'); + this.isWindows = this.checkUseragent('win'); + this.isFireFox = this.checkUseragent('firefox'); + this.isMobile = this.checkUseragent('mobile'); + this.isChrome = this.checkUseragent('chrome'); + this.isIOS = this.checkUseragent('ios'); + } } + +const getUa = (navigator: Navigator) => { + const ua = navigator.userAgent; + const uas = ua.toLowerCase(); + const mobile = /iPhone|iPad|iPod|Android/i.test(ua); + const android = + (mobile && (uas.indexOf('android') > -1 || uas.indexOf('linux') > -1)) || + uas.indexOf('adr') > -1; + const ios = mobile && !android && /Mac OS/i.test(ua); + const mac = !mobile && /Mac OS/i.test(ua); + const iphone = ios && uas.indexOf('iphone') > -1; + const ipad = ios && !iphone; + const wx = /MicroMessenger/i.test(ua); + const chrome = /CriOS/i.test(ua) || /Chrome/i.test(ua); + const tiktok = mobile && /aweme/i.test(ua); + const weibo = mobile && /Weibo/i.test(ua); + const safari = + ios && !chrome && !wx && !weibo && !tiktok && /Safari|Macintosh/i.test(ua); + const firefox = /Firefox/.test(ua); + const win = /windows|win32|win64|wow32|wow64/.test(uas); + const linux = /linux/.test(uas); + return { + ua, + mobile, + android, + ios, + mac, + wx, + chrome, + iphone, + ipad, + safari, + tiktok, + weibo, + win, + linux, + firefox, + }; +}; diff --git a/packages/env/tsconfig.blocksuite.json b/packages/env/tsconfig.blocksuite.json new file mode 100644 index 0000000000..a18b66827e --- /dev/null +++ b/packages/env/tsconfig.blocksuite.json @@ -0,0 +1,11 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "composite": true, + "noEmit": false, + "outDir": "lib/blocksuite", + "target": "ESNext" + }, + "include": ["./blocksuite/*.ts", "src/types.d.ts", "env.d.ts"], + "references": [{ "path": "../debug" }] +} diff --git a/packages/env/tsconfig.json b/packages/env/tsconfig.json index 12e70c9ab1..1aba8b2f50 100644 --- a/packages/env/tsconfig.json +++ b/packages/env/tsconfig.json @@ -1,4 +1,10 @@ { "extends": "../../tsconfig.json", - "include": ["./src", "env.d.ts"] + "compilerOptions": { + "noEmit": false, + "composite": true, + "outDir": "lib" + }, + "include": ["./src", "env.d.ts", "./src/global.d.ts"], + "exclude": ["blocksuite", "lib"] } diff --git a/packages/hooks/package.json b/packages/hooks/package.json index 5fd6f99a84..c60848f691 100644 --- a/packages/hooks/package.json +++ b/packages/hooks/package.json @@ -4,5 +4,9 @@ "./*": "./src/*" }, "private": true, + "dependencies": { + "@affine/env": "workspace:*", + "@toeverything/y-indexeddb": "workspace:*" + }, "version": "0.5.4-beta.2" } diff --git a/packages/hooks/tsconfig.json b/packages/hooks/tsconfig.json index 7513033f03..f7940714cb 100644 --- a/packages/hooks/tsconfig.json +++ b/packages/hooks/tsconfig.json @@ -1,4 +1,10 @@ { "extends": "../../tsconfig.json", - "include": ["./src"] + "compilerOptions": { + "outDir": "lib", + "composite": true, + "noEmit": false + }, + "include": ["./src"], + "references": [{ "path": "../env" }, { "path": "../y-indexeddb" }] } diff --git a/packages/i18n/.gitignore b/packages/i18n/.gitignore new file mode 100644 index 0000000000..a65b41774a --- /dev/null +++ b/packages/i18n/.gitignore @@ -0,0 +1 @@ +lib diff --git a/packages/i18n/tsconfig.json b/packages/i18n/tsconfig.json index 7513033f03..38fbfa4aaf 100644 --- a/packages/i18n/tsconfig.json +++ b/packages/i18n/tsconfig.json @@ -1,4 +1,11 @@ { "extends": "../../tsconfig.json", - "include": ["./src"] + "include": ["./src"], + "exclude": ["src/resources"], + "compilerOptions": { + "noEmit": false, + "composite": true, + "outDir": "lib" + }, + "references": [{ "path": "./tsconfig.resources.json" }] } diff --git a/packages/i18n/tsconfig.resources.json b/packages/i18n/tsconfig.resources.json new file mode 100644 index 0000000000..f86b1e8fa7 --- /dev/null +++ b/packages/i18n/tsconfig.resources.json @@ -0,0 +1,13 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "composite": true, + "module": "ESNext", + "resolveJsonModule": true, + "moduleResolution": "nodenext", + "outDir": "lib/resources", + "noEmit": false + }, + "include": ["./src/resources/**/*.ts", "./src/resources/**/*.json"], + "exclude": ["dist", "lib"] +} diff --git a/packages/jotai/.gitignore b/packages/jotai/.gitignore new file mode 100644 index 0000000000..a65b41774a --- /dev/null +++ b/packages/jotai/.gitignore @@ -0,0 +1 @@ +lib diff --git a/packages/jotai/tsconfig.json b/packages/jotai/tsconfig.json index d55dc90ebc..8a07cd1e0c 100644 --- a/packages/jotai/tsconfig.json +++ b/packages/jotai/tsconfig.json @@ -3,8 +3,12 @@ "compilerOptions": { "module": "ESNext", "target": "ESNext", - "sourceMap": true + "sourceMap": true, + "noEmit": false, + "outDir": "lib", + "composite": true }, "include": ["./src"], - "exclude": ["node_modules"] + "exclude": ["node_modules"], + "references": [{ "path": "../env" }] } diff --git a/packages/native/__tests__/fs.spec.mts b/packages/native/__tests__/fs.spec.mts index 13e68d3020..09044b9e1c 100644 --- a/packages/native/__tests__/fs.spec.mts +++ b/packages/native/__tests__/fs.spec.mts @@ -7,21 +7,20 @@ import { fileURLToPath } from 'node:url'; import { lastValueFrom, Subject } from 'rxjs'; import { v4 } from 'uuid'; -import type { FSWatcher } from '../index'; -import { watch } from '../index.js'; +import { FsWatcher } from '../index'; test('fs watch', { concurrency: false }, async t => { - let watcher: FSWatcher; + let watcher: FsWatcher; let fixture: string; t.beforeEach(async () => { const fixtureName = `fs-${v4()}.fixture`; fixture = join(fileURLToPath(import.meta.url), '..', fixtureName); await fs.writeFile(fixture, '\n'); - watcher = watch(fixture); + watcher = FsWatcher.watch(fixture); }); t.afterEach(async () => { - watcher.close(); + FsWatcher.close(); await fs.unlink(fixture).catch(() => false); }); diff --git a/packages/native/index.d.ts b/packages/native/index.d.ts index 12317d87c6..ce480d989e 100644 --- a/packages/native/index.d.ts +++ b/packages/native/index.d.ts @@ -7,7 +7,7 @@ export interface WatchOptions { recursive?: boolean; } /** Watcher kind enumeration */ -export const enum WatcherKind { +export enum WatcherKind { /** inotify backend (linux) */ Inotify = 'Inotify', /** FS-Event backend (mac) */ diff --git a/packages/plugin-infra/tsconfig.json b/packages/plugin-infra/tsconfig.json index 49909da109..585d8f9c70 100644 --- a/packages/plugin-infra/tsconfig.json +++ b/packages/plugin-infra/tsconfig.json @@ -3,7 +3,15 @@ "include": ["./src"], "references": [ { - "path": "./tsconfig.node.json" + "path": "../component" + }, + { + "path": "../workspace" } - ] + ], + "compilerOptions": { + "noEmit": false, + "composite": true, + "outDir": "lib" + } } diff --git a/packages/plugin-infra/tsconfig.node.json b/packages/plugin-infra/tsconfig.node.json deleted file mode 100644 index 9d31e2aed9..0000000000 --- a/packages/plugin-infra/tsconfig.node.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "compilerOptions": { - "composite": true, - "module": "ESNext", - "moduleResolution": "Node", - "allowSyntheticDefaultImports": true - }, - "include": ["vite.config.ts"] -} diff --git a/packages/workspace/.gitignore b/packages/workspace/.gitignore new file mode 100644 index 0000000000..a65b41774a --- /dev/null +++ b/packages/workspace/.gitignore @@ -0,0 +1 @@ +lib diff --git a/packages/workspace/package.json b/packages/workspace/package.json index 6f975111d2..11df17000b 100644 --- a/packages/workspace/package.json +++ b/packages/workspace/package.json @@ -10,7 +10,8 @@ "./providers": "./src/providers/index.ts", "./affine/*": "./src/affine/*.ts", "./affine/api": "./src/affine/api/index.ts", - "./affine/keck": "./src/affine/keck/index.ts" + "./affine/keck": "./src/affine/keck/index.ts", + "./affine/shared": "./src/affine/shared.ts" }, "peerDependencies": { "@blocksuite/blocks": "*", @@ -18,7 +19,6 @@ }, "dependencies": { "@affine-test/fixtures": "workspace:*", - "@affine/component": "workspace:*", "@affine/debug": "workspace:*", "@affine/env": "workspace:*", "@toeverything/hooks": "workspace:*", diff --git a/packages/workspace/src/affine/__tests__/api.spec.ts b/packages/workspace/src/affine/__tests__/api.spec.ts index 613abf4b56..a3692e87e3 100644 --- a/packages/workspace/src/affine/__tests__/api.spec.ts +++ b/packages/workspace/src/affine/__tests__/api.spec.ts @@ -13,7 +13,6 @@ import { assertExists } from '@blocksuite/global/utils'; import type { Page, PageMeta } from '@blocksuite/store'; import { Workspace } from '@blocksuite/store'; import { faker } from '@faker-js/faker'; -import type {} from '@toeverything/hooks/use-block-suite-page-meta'; import { beforeEach, describe, expect, test, vi } from 'vitest'; import { WebSocket } from 'ws'; import { applyUpdate } from 'yjs'; @@ -36,6 +35,12 @@ import { setLoginStorage, } from '../login'; +declare module '@blocksuite/store' { + interface PageMeta { + isPublic?: boolean; + } +} + // @ts-expect-error globalThis.WebSocket = WebSocket; @@ -110,7 +115,7 @@ beforeEach(async () => { declare global { interface DocumentEventMap { 'affine-error': CustomEvent<{ - code: MessageCode; + code: (typeof MessageCode)[keyof typeof MessageCode]; }>; } } @@ -165,7 +170,7 @@ describe('api', () => { const listener = vi.fn( ( e: CustomEvent<{ - code: MessageCode; + code: (typeof MessageCode)[keyof typeof MessageCode]; }> ) => { expect(e.detail.code).toBe(MessageCode.loadListFailed); diff --git a/packages/workspace/src/affine/api/index.ts b/packages/workspace/src/affine/api/index.ts index 6d5d15d408..6dd9f77ac4 100644 --- a/packages/workspace/src/affine/api/index.ts +++ b/packages/workspace/src/affine/api/index.ts @@ -4,9 +4,12 @@ import { z } from 'zod'; import { checkLoginStorage } from '../login'; export class RequestError extends Error { - public readonly code: MessageCode; + public readonly code: (typeof MessageCode)[keyof typeof MessageCode]; - constructor(code: MessageCode, cause: unknown | null = null) { + constructor( + code: (typeof MessageCode)[keyof typeof MessageCode], + cause: unknown | null = null + ) { super(Messages[code].message); sendMessage(code); this.code = code; @@ -15,7 +18,7 @@ export class RequestError extends Error { } } -function sendMessage(code: MessageCode) { +function sendMessage(code: (typeof MessageCode)[keyof typeof MessageCode]) { document.dispatchEvent( new CustomEvent('affine-error', { detail: { diff --git a/packages/workspace/src/affine/login.ts b/packages/workspace/src/affine/login.ts index 0bb5c1ffd4..73dee13923 100644 --- a/packages/workspace/src/affine/login.ts +++ b/packages/workspace/src/affine/login.ts @@ -119,7 +119,7 @@ export const checkLoginStorage = async ( return getLoginStorage() as LoginResponse; }; -export const enum SignMethod { +export enum SignMethod { Google = 'Google', GitHub = 'GitHub', // Twitter = 'Twitter', diff --git a/packages/workspace/src/type.ts b/packages/workspace/src/type.ts index a100439f2d..4fef3cba96 100644 --- a/packages/workspace/src/type.ts +++ b/packages/workspace/src/type.ts @@ -11,7 +11,7 @@ import type { Workspace as RemoteWorkspace } from './affine/api'; export type JotaiStore = ReturnType; -export const enum WorkspaceSubPath { +export enum WorkspaceSubPath { ALL = 'all', SETTING = 'setting', TRASH = 'trash', @@ -115,19 +115,19 @@ export interface AffinePublicWorkspace { providers: Provider[]; } -export const enum ReleaseType { +export enum ReleaseType { // if workspace is not released yet, we will not show it in the workspace list UNRELEASED = 'unreleased', STABLE = 'stable', } -export const enum LoadPriority { +export enum LoadPriority { HIGH = 1, MEDIUM = 2, LOW = 3, } -export const enum WorkspaceFlavour { +export enum WorkspaceFlavour { /** * AFFiNE Workspace is the workspace * that hosted on the Legacy AFFiNE Cloud Server. diff --git a/packages/workspace/tsconfig.json b/packages/workspace/tsconfig.json index 7513033f03..438bf038ce 100644 --- a/packages/workspace/tsconfig.json +++ b/packages/workspace/tsconfig.json @@ -1,4 +1,18 @@ { "extends": "../../tsconfig.json", - "include": ["./src"] + "compilerOptions": { + "composite": true, + "noEmit": false, + "outDir": "lib" + }, + "include": ["./src", "./src/affine/api", "../../apps/electron/layers"], + "exclude": ["lib"], + "references": [ + { "path": "../../tests/fixtures" }, + { "path": "../y-indexeddb" }, + { "path": "../env" }, + { "path": "../debug" }, + { "path": "../hooks" }, + { "path": "../component" } + ] } diff --git a/packages/y-indexeddb/.gitignore b/packages/y-indexeddb/.gitignore new file mode 100644 index 0000000000..a65b41774a --- /dev/null +++ b/packages/y-indexeddb/.gitignore @@ -0,0 +1 @@ +lib diff --git a/packages/y-indexeddb/tsconfig.json b/packages/y-indexeddb/tsconfig.json index 49909da109..e3c960b4c0 100644 --- a/packages/y-indexeddb/tsconfig.json +++ b/packages/y-indexeddb/tsconfig.json @@ -1,9 +1,17 @@ { "extends": "../../tsconfig.json", "include": ["./src"], + "compilerOptions": { + "composite": true, + "noEmit": false, + "outDir": "lib" + }, "references": [ { "path": "./tsconfig.node.json" + }, + { + "path": "../env" } ] } diff --git a/packages/y-indexeddb/tsconfig.node.json b/packages/y-indexeddb/tsconfig.node.json index 9d31e2aed9..1b87925cbc 100644 --- a/packages/y-indexeddb/tsconfig.node.json +++ b/packages/y-indexeddb/tsconfig.node.json @@ -3,7 +3,8 @@ "composite": true, "module": "ESNext", "moduleResolution": "Node", - "allowSyntheticDefaultImports": true + "allowSyntheticDefaultImports": true, + "outDir": "lib" }, "include": ["vite.config.ts"] } diff --git a/plugins/copilot/src/index.ts b/plugins/copilot/src/index.ts index 6292af738a..c7efcbc8db 100644 --- a/plugins/copilot/src/index.ts +++ b/plugins/copilot/src/index.ts @@ -1,3 +1,5 @@ +import '@affine/env/config'; + import { definePlugin } from '@toeverything/plugin-infra/manager'; import { ReleaseStage } from '@toeverything/plugin-infra/type'; diff --git a/plugins/copilot/tsconfig.json b/plugins/copilot/tsconfig.json index 7513033f03..990965669e 100644 --- a/plugins/copilot/tsconfig.json +++ b/plugins/copilot/tsconfig.json @@ -1,4 +1,20 @@ { "extends": "../../tsconfig.json", - "include": ["./src"] + "include": ["./src"], + "compilerOptions": { + "noEmit": false, + "composite": true, + "outDir": "lib" + }, + "references": [ + { + "path": "../../packages/component" + }, + { + "path": "../../packages/plugin-infra" + }, + { + "path": "../../packages/env" + } + ] } diff --git a/tests/fixtures/.gitignore b/tests/fixtures/.gitignore new file mode 100644 index 0000000000..a65b41774a --- /dev/null +++ b/tests/fixtures/.gitignore @@ -0,0 +1 @@ +lib diff --git a/tests/fixtures/tsconfig.json b/tests/fixtures/tsconfig.json index bb542f3839..3e3c325947 100644 --- a/tests/fixtures/tsconfig.json +++ b/tests/fixtures/tsconfig.json @@ -1,4 +1,11 @@ { "extends": "../../tsconfig.json", - "include": ["."] + "compilerOptions": { + "composite": true, + "noEmit": false, + "outDir": "lib", + "moduleResolution": "nodenext", + "resolveJsonModule": true + }, + "include": [".", "./*.json"] } diff --git a/tests/kit/.gitignore b/tests/kit/.gitignore new file mode 100644 index 0000000000..a65b41774a --- /dev/null +++ b/tests/kit/.gitignore @@ -0,0 +1 @@ +lib diff --git a/tests/kit/tsconfig.json b/tests/kit/tsconfig.json index 1fcfc7ee75..e3aba77d49 100644 --- a/tests/kit/tsconfig.json +++ b/tests/kit/tsconfig.json @@ -1,4 +1,9 @@ { "extends": "../../tsconfig.json", + "compilerOptions": { + "composite": true, + "noEmit": false, + "outDir": "lib" + }, "include": ["./*.ts"] } diff --git a/tsconfig.json b/tsconfig.json index f0fde14179..bd6b52fa33 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { - "target": "ES2020", + "rootDir": ".", + "target": "ESNext", "lib": ["dom", "dom.iterable", "esnext"], "allowJs": true, "skipLibCheck": true, @@ -32,6 +33,7 @@ "@affine/graphql": ["./packages/graphql/src"], "@affine/copilot": ["./plugins/copilot/src"], "@affine/copilot/*": ["./plugins/copilot/src/*"], + "@affine/electron/layers/*": ["./apps/electron/layers/*"], "@affine-test/kit/*": ["./tests/kit/*"], "@affine-test/fixtures/*": ["./tests/fixtures/*"], "@toeverything/y-indexeddb": ["./packages/y-indexeddb/src"], @@ -42,6 +44,7 @@ "@affine/native/*": ["./packages/native/*"] } }, + "include": [], "references": [ { "path": "./tests" @@ -67,6 +70,9 @@ { "path": "./packages/env" }, + { + "path": "./packages/env/tsconfig.blocksuite.json" + }, { "path": "./packages/graphql" }, diff --git a/tsconfig.node.json b/tsconfig.node.json index 0f6d3ad3da..674cb5b3dd 100644 --- a/tsconfig.node.json +++ b/tsconfig.node.json @@ -3,7 +3,8 @@ "composite": true, "module": "ESNext", "moduleResolution": "Node", - "allowSyntheticDefaultImports": true + "allowSyntheticDefaultImports": true, + "outDir": "lib" }, "include": ["vitest.config.ts", "scripts"] } diff --git a/yarn.lock b/yarn.lock index a06b4d43e8..8b875f6237 100644 --- a/yarn.lock +++ b/yarn.lock @@ -212,9 +212,7 @@ __metadata: version: 0.0.0-use.local resolution: "@affine/env@workspace:packages/env" dependencies: - "@affine/copilot": "workspace:*" "@blocksuite/global": 0.0.0-20230531080915-ca9c55a2-nightly - "@toeverything/plugin-infra": "workspace:*" lit: ^2.7.4 next: =13.4.2 react: 18.3.0-canary-16d053d59-20230506 @@ -415,7 +413,6 @@ __metadata: resolution: "@affine/workspace@workspace:packages/workspace" dependencies: "@affine-test/fixtures": "workspace:*" - "@affine/component": "workspace:*" "@affine/debug": "workspace:*" "@affine/env": "workspace:*" "@toeverything/hooks": "workspace:*" @@ -9067,6 +9064,9 @@ __metadata: "@toeverything/hooks@workspace:*, @toeverything/hooks@workspace:packages/hooks": version: 0.0.0-use.local resolution: "@toeverything/hooks@workspace:packages/hooks" + dependencies: + "@affine/env": "workspace:*" + "@toeverything/y-indexeddb": "workspace:*" languageName: unknown linkType: soft