build: prevent tsconfig includes sources outside (#2643)

This commit is contained in:
LongYinan
2023-06-01 17:08:14 +08:00
committed by Himself65
parent 2a31af0973
commit 4ab5457a44
25 changed files with 160 additions and 107 deletions

View File

@@ -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

View File

@@ -1 +1,4 @@
pnpm-lock.yaml
target
lib
test-results

View File

@@ -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;

View File

@@ -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>)[]

View File

@@ -30,3 +30,7 @@ export const getExposedMeta = () => {
events: eventsMeta,
};
};
export type MainIPCHandlerMap = typeof handlers;
export type MainIPCEventMap = typeof events;

View File

@@ -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;
}

View File

@@ -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';

View File

@@ -11,7 +11,8 @@
"outDir": "dist",
"moduleResolution": "node",
"resolveJsonModule": true,
"noImplicitOverride": true
"noImplicitOverride": true,
"noEmit": false
},
"include": ["**/*.ts", "**/*.tsx"],
"exclude": ["node_modules", "out", "dist"],

View File

@@ -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';

View File

@@ -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",

View File

@@ -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 => {

View File

@@ -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 = ({

View File

@@ -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) => {

View File

@@ -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,

View File

@@ -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: {

View File

@@ -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[];
};

View File

@@ -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,

View File

@@ -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;

View File

@@ -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 = {

View File

@@ -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';

View File

@@ -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" }
]
}

View File

@@ -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"]
}

View File

@@ -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';

View File

@@ -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" }
]
}

View File

@@ -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"],