Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

build: prevent tsconfig includes sources outside (#2643)

LongYinan602f79513319
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 22fcb47ecd..cd3263be8b 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -35,7 +35,8 @@ jobs:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: ./.github/actions/setup-node
- - run: |
+ - name: Run checks
+ run: |
yarn i18n-codegen gen
yarn typecheck
yarn lint --max-warnings=0
diff --git a/.prettierignore b/.prettierignore
index bd5535a603..fdd8efc41e 100644
--- a/.prettierignore
+++ b/.prettierignore
@@ -1 +1,4 @@
pnpm-lock.yaml
+target
+lib
+test-results
diff --git a/apps/electron/layers/constraints.d.ts b/apps/electron/layers/constraints.d.ts
deleted file mode 100644
index c5fac6ff58..0000000000
--- a/apps/electron/layers/constraints.d.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-/* eslint-disable @typescript-eslint/consistent-type-imports */
-// This file contains the main process events
-// It will guide preload and main process on the correct event types and payloads
-
-declare type MainIPCHandlerMap = typeof import('./main/src/exposed').handlers;
-
-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 2f4d25606f..1305c1826c 100644
--- a/apps/electron/layers/main/src/__tests__/integration.spec.ts
+++ b/apps/electron/layers/main/src/__tests__/integration.spec.ts
@@ -6,6 +6,8 @@ import { v4 } from 'uuid';
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
import * as Y from 'yjs';
+import type { MainIPCHandlerMap } from '../exposed';
+
const registeredHandlers = new Map<
string,
((...args: any[]) => Promise<any>)[]
diff --git a/apps/electron/layers/main/src/exposed.ts b/apps/electron/layers/main/src/exposed.ts
index 0ece84dbfa..3f1c4c447d 100644
--- a/apps/electron/layers/main/src/exposed.ts
+++ b/apps/electron/layers/main/src/exposed.ts
@@ -30,3 +30,7 @@ export const getExposedMeta = () => {
events: eventsMeta,
};
};
+
+export type MainIPCHandlerMap = typeof handlers;
+
+export type MainIPCEventMap = typeof events;
diff --git a/apps/electron/layers/preload/preload.d.ts b/apps/electron/layers/preload/preload.d.ts
index fbccb3c2b7..4ed0b0da0b 100644
--- a/apps/electron/layers/preload/preload.d.ts
+++ b/apps/electron/layers/preload/preload.d.ts
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/consistent-type-imports */
-interface Window {
- apis: typeof import('./src/affine-apis').apis;
- events: typeof import('./src/affine-apis').events;
+declare interface Window {
+ apis: import('./src/affine-apis').PreloadHandlers;
+ events: import('./src/affine-apis').MainIPCEventMap;
}
diff --git a/apps/electron/layers/preload/src/affine-apis.ts b/apps/electron/layers/preload/src/affine-apis.ts
index c8a6df18ee..b371611a11 100644
--- a/apps/electron/layers/preload/src/affine-apis.ts
+++ b/apps/electron/layers/preload/src/affine-apis.ts
@@ -1,10 +1,14 @@
/* eslint-disable @typescript-eslint/no-var-requires */
-// eslint-disable-next-line @typescript-eslint/triple-slash-reference
-/// <reference path="../../constraints.d.ts" />
// NOTE: we will generate preload types from this file
import { ipcRenderer } from 'electron';
+// eslint-disable-next-line @typescript-eslint/no-restricted-imports
+import type {
+ MainIPCEventMap,
+ MainIPCHandlerMap,
+} from '../../main/src/exposed';
+
type WithoutFirstParameter<T> = T extends (_: any, ...args: infer P) => infer R
? (...args: P) => R
: T;
@@ -15,7 +19,7 @@ type HandlersMap<N extends keyof MainIPCHandlerMap> = {
>;
};
-type PreloadHandlers = {
+export type PreloadHandlers = {
[N in keyof MainIPCHandlerMap]: HandlersMap<N>;
};
@@ -88,3 +92,6 @@ const appInfo = {
};
export { apis, appInfo, events };
+
+// eslint-disable-next-line @typescript-eslint/no-restricted-imports
+export type { MainIPCEventMap } from '../../main/src/exposed';
diff --git a/apps/electron/tsconfig.json b/apps/electron/tsconfig.json
index db9bb339a1..9253fde0ff 100644
--- a/apps/electron/tsconfig.json
+++ b/apps/electron/tsconfig.json
@@ -11,7 +11,8 @@
"outDir": "dist",
"moduleResolution": "node",
"resolveJsonModule": true,
- "noImplicitOverride": true
+ "noImplicitOverride": true,
+ "noEmit": false
},
"include": ["**/*.ts", "**/*.tsx"],
"exclude": ["node_modules", "out", "dist"],
diff --git a/apps/web/src/components/blocksuite/block-suite-page-list/index.tsx b/apps/web/src/components/blocksuite/block-suite-page-list/index.tsx
index e70de6ef82..5958cf8dc4 100644
--- a/apps/web/src/components/blocksuite/block-suite-page-list/index.tsx
+++ b/apps/web/src/components/blocksuite/block-suite-page-list/index.tsx
@@ -1,14 +1,11 @@
import { Empty } from '@affine/component';
-import type {
- ListData,
- TrashListData,
- View,
-} from '@affine/component/page-list';
+import type { ListData, TrashListData } from '@affine/component/page-list';
import {
filterByFilterList,
PageList,
PageListTrashView,
} from '@affine/component/page-list';
+import type { View } from '@affine/component/page-list/filter/shared-types';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { EdgelessIcon, PageIcon } from '@blocksuite/icons';
import type { PageMeta } from '@blocksuite/store';
diff --git a/package.json b/package.json
index 2616b38583..17295a647f 100644
--- a/package.json
+++ b/package.json
@@ -35,7 +35,7 @@
"test:unit:coverage": "vitest run --coverage",
"postinstall": "i18n-codegen gen && husky install",
"notify": "node scripts/notify.mjs",
- "typecheck": "tsc -b tsconfig.json"
+ "typecheck": "tsc -b tsconfig.json --diagnostics"
},
"lint-staged": {
"*": "prettier --write --ignore-unknown --cache",
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 82fbde5cb8..bb8e0fadae 100644
--- a/packages/component/src/components/page-list/__tests__/filter.spec.tsx
+++ b/packages/component/src/components/page-list/__tests__/filter.spec.tsx
@@ -12,12 +12,13 @@ import { Condition } from '../filter/condition';
import { tBoolean, tDate } from '../filter/logical/custom-type';
import type {
Filter,
- FilterMatcherDataType,
LiteralValue,
Ref,
VariableMap,
-} from '../filter/vars';
-import { filterMatcher, toLiteral } from '../filter/vars';
+} from '../filter/shared-types';
+import { toLiteral } from '../filter/shared-types';
+import type { FilterMatcherDataType } from '../filter/vars';
+import { filterMatcher } from '../filter/vars';
import { filterByFilterList } from '../use-all-page-setting';
const ref = (name: keyof VariableMap): Ref => {
diff --git a/packages/component/src/components/page-list/filter/condition.tsx b/packages/component/src/components/page-list/filter/condition.tsx
index 476dc1871f..bdfbf3db21 100644
--- a/packages/component/src/components/page-list/filter/condition.tsx
+++ b/packages/component/src/components/page-list/filter/condition.tsx
@@ -5,7 +5,7 @@ import { Menu, MenuItem } from '../../../ui/menu';
import * as styles from './index.css';
import { literalMatcher } from './literal-matcher';
import type { TFunction, TType } from './logical/typesystem';
-import type { Filter, Literal } from './vars';
+import type { Filter, Literal } from './shared-types';
import { filterMatcher, VariableSelect, vars } from './vars';
export const Condition = ({
diff --git a/packages/component/src/components/page-list/filter/eval.ts b/packages/component/src/components/page-list/filter/eval.ts
index 8b2d333aa6..f29c78ce9f 100644
--- a/packages/component/src/components/page-list/filter/eval.ts
+++ b/packages/component/src/components/page-list/filter/eval.ts
@@ -1,5 +1,4 @@
-import type { Filter, Literal, Ref } from './vars';
-import type { VariableMap } from './vars';
+import type { Filter, Literal, Ref, VariableMap } from './shared-types';
import { filterMatcher } from './vars';
const evalRef = (ref: Ref, variableMap: VariableMap) => {
diff --git a/packages/component/src/components/page-list/filter/filter-list.tsx b/packages/component/src/components/page-list/filter/filter-list.tsx
index e8d75f71b2..50d32160e8 100644
--- a/packages/component/src/components/page-list/filter/filter-list.tsx
+++ b/packages/component/src/components/page-list/filter/filter-list.tsx
@@ -3,7 +3,7 @@ import { CloseIcon, PlusIcon } from '@blocksuite/icons';
import { Menu } from '../../..';
import { Condition } from './condition';
import * as styles from './index.css';
-import type { Filter } from './vars';
+import type { Filter } from './shared-types';
import { CreateFilterMenu } from './vars';
export const FilterList = ({
value,
diff --git a/packages/component/src/components/page-list/filter/literal-matcher.tsx b/packages/component/src/components/page-list/filter/literal-matcher.tsx
index 0093a0e1d4..51dd62281d 100644
--- a/packages/component/src/components/page-list/filter/literal-matcher.tsx
+++ b/packages/component/src/components/page-list/filter/literal-matcher.tsx
@@ -6,7 +6,7 @@ import { tBoolean, tDate } from './logical/custom-type';
import { Matcher } from './logical/matcher';
import type { TType } from './logical/typesystem';
import { typesystem } from './logical/typesystem';
-import type { Literal } from './vars';
+import type { Literal } from './shared-types';
export const literalMatcher = new Matcher<{
render: (props: {
diff --git a/packages/component/src/components/page-list/filter/shared-types.tsx b/packages/component/src/components/page-list/filter/shared-types.tsx
new file mode 100644
index 0000000000..aadd7e630c
--- /dev/null
+++ b/packages/component/src/components/page-list/filter/shared-types.tsx
@@ -0,0 +1,66 @@
+import { DateTimeIcon, FavoritedIcon } from '@blocksuite/icons';
+import type { ReactElement } from 'react';
+
+import { tBoolean, tDate } from './logical/custom-type';
+import type { TType } from './logical/typesystem';
+
+export type Ref = {
+ type: 'ref';
+ name: keyof VariableMap;
+};
+
+export type Filter = {
+ type: 'filter';
+ left: Ref;
+ funcName: string;
+ args: Literal[];
+};
+export type LiteralValue =
+ | number
+ | string
+ | boolean
+ | { [K: string]: LiteralValue }
+ | Array<LiteralValue>;
+export const toLiteral = (value: LiteralValue): Literal => ({
+ type: 'literal',
+ value,
+});
+export type Literal = {
+ type: 'literal';
+ value: LiteralValue;
+};
+
+export type FilterVariable = {
+ name: keyof VariableMap;
+ type: TType;
+ icon: ReactElement;
+};
+
+export const variableDefineMap = {
+ Created: {
+ type: tDate.create(),
+ icon: <DateTimeIcon />,
+ },
+ Updated: {
+ type: tDate.create(),
+ icon: <DateTimeIcon />,
+ },
+ 'Is Favourited': {
+ type: tBoolean.create(),
+ icon: <FavoritedIcon />,
+ },
+ // Imported: {
+ // type: tBoolean.create(),
+ // },
+ // 'Daily Note': {
+ // type: tBoolean.create(),
+ // },
+} as const;
+export type VariableMap = {
+ [K in keyof typeof variableDefineMap]: LiteralValue;
+};
+export type View = {
+ id: string;
+ name: string;
+ filterList: Filter[];
+};
diff --git a/packages/component/src/components/page-list/filter/vars.tsx b/packages/component/src/components/page-list/filter/vars.tsx
index 5705884483..acafd3219a 100644
--- a/packages/component/src/components/page-list/filter/vars.tsx
+++ b/packages/component/src/components/page-list/filter/vars.tsx
@@ -1,68 +1,20 @@
-import { DateTimeIcon, FavoritedIcon } from '@blocksuite/icons';
import dayjs from 'dayjs';
-import type { ReactElement, ReactNode } from 'react';
+import type { ReactNode } from 'react';
import { MenuItem } from '../../../ui/menu';
import * as styles from './index.css';
import { tBoolean, tDate } from './logical/custom-type';
import { Matcher } from './logical/matcher';
-import type { TFunction, TType } from './logical/typesystem';
+import type { TFunction } from './logical/typesystem';
import { tFunction, typesystem } from './logical/typesystem';
+import type {
+ Filter,
+ FilterVariable,
+ LiteralValue,
+ VariableMap,
+} from './shared-types';
+import { variableDefineMap } from './shared-types';
-export type Ref = {
- type: 'ref';
- name: keyof VariableMap;
-};
-
-export type Filter = {
- type: 'filter';
- left: Ref;
- funcName: string;
- args: Literal[];
-};
-export type LiteralValue =
- | number
- | string
- | boolean
- | { [K: string]: LiteralValue }
- | Array<LiteralValue>;
-export const toLiteral = (value: LiteralValue): Literal => ({
- type: 'literal',
- value,
-});
-export type Literal = {
- type: 'literal';
- value: LiteralValue;
-};
-
-export type FilterVariable = {
- name: keyof VariableMap;
- type: TType;
- icon: ReactElement;
-};
-export const variableDefineMap = {
- Created: {
- type: tDate.create(),
- icon: <DateTimeIcon />,
- },
- Updated: {
- type: tDate.create(),
- icon: <DateTimeIcon />,
- },
- 'Is Favourited': {
- type: tBoolean.create(),
- icon: <FavoritedIcon />,
- },
- // Imported: {
- // type: tBoolean.create(),
- // },
- // 'Daily Note': {
- // type: tBoolean.create(),
- // },
-} as const;
-export type VariableMap = {
- [K in keyof typeof variableDefineMap]: LiteralValue;
-};
export const vars: FilterVariable[] = Object.entries(variableDefineMap).map(
([key, value]) => ({
name: key as keyof VariableMap,
diff --git a/packages/component/src/components/page-list/use-all-page-setting.ts b/packages/component/src/components/page-list/use-all-page-setting.ts
index 4abf06e46b..2ced020fae 100644
--- a/packages/component/src/components/page-list/use-all-page-setting.ts
+++ b/packages/component/src/components/page-list/use-all-page-setting.ts
@@ -8,13 +8,7 @@ import useSWRImmutable from 'swr/immutable';
import { NIL } from 'uuid';
import { evalFilterList } from './filter';
-import type { Filter, VariableMap } from './filter/vars';
-
-export type View = {
- id: string;
- name: string;
- filterList: Filter[];
-};
+import type { Filter, VariableMap, View } from './filter/shared-types';
type PersistenceView = View;
diff --git a/packages/component/src/components/page-list/view/create-view.tsx b/packages/component/src/components/page-list/view/create-view.tsx
index a14a2fc82a..cb8b290038 100644
--- a/packages/component/src/components/page-list/view/create-view.tsx
+++ b/packages/component/src/components/page-list/view/create-view.tsx
@@ -4,8 +4,7 @@ import { useState } from 'react';
import { Button, Input, Modal, ModalWrapper } from '../../..';
import { FilterList } from '../filter';
-import type { Filter } from '../filter/vars';
-import type { View } from '../use-all-page-setting';
+import type { Filter, View } from '../filter/shared-types';
import * as styles from './view-list.css';
type CreateViewProps = {
diff --git a/packages/component/src/index.ts b/packages/component/src/index.ts
index 2031c16b8c..56e85a7bb2 100644
--- a/packages/component/src/index.ts
+++ b/packages/component/src/index.ts
@@ -1,3 +1,6 @@
+// eslint-disable-next-line @typescript-eslint/triple-slash-reference
+/// <reference path="../../../apps/electron/layers/preload/preload.d.ts" />
+
export * from './components/list-skeleton';
export * from './styles';
export * from './ui/breadcrumbs';
diff --git a/packages/component/tsconfig.json b/packages/component/tsconfig.json
index e6f93d217c..6fee3173a6 100644
--- a/packages/component/tsconfig.json
+++ b/packages/component/tsconfig.json
@@ -1,18 +1,18 @@
{
"extends": "../../tsconfig.json",
- "include": [
- "./src/**/*.ts",
- "./src/**/*.tsx",
- "./src/**/*.json",
- "../workspace/src",
- "../../apps/electron/layers/**/src"
+ "exclude": [
+ "lib",
+ "./src/components/page-list/filter/shared-types.tsx",
+ "./src/components/page-list/filter/logic/custom-type.ts",
+ "./src/components/page-list/filter/logic/matcher.ts",
+ "./src/components/page-list/filter/logic/typesystem.ts"
],
+ "include": ["./src/**/*", "./src/**/*.json"],
"compilerOptions": {
"composite": true,
"noEmit": false,
"outDir": "lib"
},
- "exclude": ["lib"],
"references": [
{
"path": "../debug"
@@ -26,9 +26,14 @@
{
"path": "../hooks"
},
+ { "path": "../workspace" },
+ {
+ "path": "../../apps/electron"
+ },
{
"path": "./tsconfig.node.json"
},
+ { "path": "./tsconfig.workspace.json" },
{ "path": "../../tests/fixtures" }
]
}
diff --git a/packages/component/tsconfig.workspace.json b/packages/component/tsconfig.workspace.json
new file mode 100644
index 0000000000..12e0b004a2
--- /dev/null
+++ b/packages/component/tsconfig.workspace.json
@@ -0,0 +1,18 @@
+// to prevent the `@affine/components` contains circular references with `@affine/workspace`
+// the include files should be excluded in `./tsconfig.json`
+{
+ "extends": "../../tsconfig.json",
+ "compilerOptions": {
+ "composite": true,
+ "noEmit": false,
+ "outDir": "lib"
+ },
+ "include": [
+ "./src/components/page-list/filter/shared-types.tsx",
+ "./src/components/page-list/filter/logical/custom-type.ts",
+ "./src/components/page-list/filter/logical/matcher.ts",
+ "./src/components/page-list/filter/logical/typesystem.ts"
+ ],
+ "references": [{ "path": "../env" }],
+ "exclude": ["lib"]
+}
diff --git a/packages/workspace/src/type.ts b/packages/workspace/src/type.ts
index 4fef3cba96..5a56cc1dcb 100644
--- a/packages/workspace/src/type.ts
+++ b/packages/workspace/src/type.ts
@@ -1,6 +1,7 @@
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
-/// <reference path='../../../apps/electron/layers/preload/preload.d.ts' />
-import type { View } from '@affine/component/page-list';
+/// <reference path="../../../apps/electron/layers/preload/preload.d.ts" />
+
+import type { View } from '@affine/component/page-list/filter/shared-types';
import type { EditorContainer } from '@blocksuite/editor';
import type { Page } from '@blocksuite/store';
import type { Workspace as BlockSuiteWorkspace } from '@blocksuite/store';
diff --git a/packages/workspace/tsconfig.json b/packages/workspace/tsconfig.json
index 438bf038ce..9245f68830 100644
--- a/packages/workspace/tsconfig.json
+++ b/packages/workspace/tsconfig.json
@@ -5,7 +5,7 @@
"noEmit": false,
"outDir": "lib"
},
- "include": ["./src", "./src/affine/api", "../../apps/electron/layers"],
+ "include": ["./src", "./src/affine/api"],
"exclude": ["lib"],
"references": [
{ "path": "../../tests/fixtures" },
@@ -13,6 +13,7 @@
{ "path": "../env" },
{ "path": "../debug" },
{ "path": "../hooks" },
- { "path": "../component" }
+ { "path": "../component/tsconfig.workspace.json" },
+ { "path": "../../apps/electron" }
]
}
diff --git a/tsconfig.json b/tsconfig.json
index bd6b52fa33..6d3872e2aa 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -20,7 +20,10 @@
"baseUrl": ".",
"paths": {
"@affine/component": ["./packages/component/src/index"],
- "@affine/component/*": ["./packages/component/src/components/*/index"],
+ "@affine/component/*": [
+ "./packages/component/src/components/*/index",
+ "./packages/component/src/components/*"
+ ],
"@affine/templates/*": ["./packages/templates/src/*"],
"@affine/i18n": ["./packages/i18n/src"],
"@affine/i18n/hooks": ["./packages/i18n/src/i18n-generated"],
@@ -34,6 +37,9 @@
"@affine/copilot": ["./plugins/copilot/src"],
"@affine/copilot/*": ["./plugins/copilot/src/*"],
"@affine/electron/layers/*": ["./apps/electron/layers/*"],
+ "@affine/electron/preload": [
+ "./apps/electron/layers/preload/preload.d.ts"
+ ],
"@affine-test/kit/*": ["./tests/kit/*"],
"@affine-test/fixtures/*": ["./tests/fixtures/*"],
"@toeverything/y-indexeddb": ["./packages/y-indexeddb/src"],