build: perform TypeCheck for all packages (#2573)

Co-authored-by: himself65 <himself65@outlook.com>
Co-authored-by: Peng Xiao <pengxiao@outlook.com>
This commit is contained in:
LongYinan 2023-05-31 20:49:56 +08:00 committed by GitHub
parent 78410f531a
commit 1ea445ab15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
81 changed files with 434 additions and 241 deletions

View File

@ -5,3 +5,4 @@ out
storybook-static
affine-out
_next
lib

View File

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

2
.gitignore vendored
View File

@ -70,3 +70,5 @@ next-env.d.ts
# Rust
target
*.node
tsconfig.node.tsbuildinfo
lib

View File

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

View File

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

View File

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

View File

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

View File

@ -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<Database | undefined> {
const db = super.connect();
if (!this.firstConnected) {

View File

@ -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<SelectDBFileLocationResult
}
}
interface LoadDBFileResult {
export interface LoadDBFileResult {
workspaceId?: string;
error?: ErrorMessage;
canceled?: boolean;
@ -237,7 +237,7 @@ export async function loadDBFile(): Promise<LoadDBFileResult> {
}
}
interface MoveDBFileResult {
export interface MoveDBFileResult {
filePath?: string;
error?: ErrorMessage;
canceled?: boolean;

View File

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

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@ import { BehaviorSubject, Subject } from 'rxjs';
import type { MainEventListener } from '../type';
interface UpdateMeta {
export interface UpdateMeta {
version: string;
allowAutoUpdate: boolean;
}

View File

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

View File

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

View File

@ -1,10 +1,10 @@
/* 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';
import type { MainIPCEventMap, MainIPCHandlerMap } from '../../constraints';
type WithoutFirstParameter<T> = T extends (_: any, ...args: infer P) => infer R
? (...args: P) => R
: T;

View File

@ -1,7 +0,0 @@
export const isMacOS = () => {
return process.platform === 'darwin';
};
export const isWindows = () => {
return process.platform === 'win32';
};

View File

@ -2,7 +2,9 @@
"extends": "../../../tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"noEmit": true
"noEmit": true,
"target": "ESNext"
},
"references": [{ "path": "../../../tests/kit" }],
"include": ["**.spec.ts", "**.test.ts"]
}

View File

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

View File

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

View File

@ -10,7 +10,7 @@ declare global {
}
}
export const enum ExternalAccount {
export enum ExternalAccount {
github = 'github',
google = 'google',
firebase = 'firebase',

View File

@ -5,7 +5,8 @@
"module": "ESNext",
"resolveJsonModule": true,
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true
"allowSyntheticDefaultImports": true,
"outDir": "dist/scripts"
},
"include": ["scripts", "package.json"]
}

View File

View File

@ -36,7 +36,7 @@ export type BaseHeaderProps<
leftSlot?: ReactNode;
};
export const enum HeaderRightItemName {
export enum HeaderRightItemName {
EditorOptionMenu = 'editorOptionMenu',
TrashButtonGroup = 'trashButtonGroup',
SyncUser = 'syncUser',

View File

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

View File

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

View File

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

View File

@ -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<P = Record<string, unknown>, 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',

View File

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

View File

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

View File

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

View File

@ -6,7 +6,7 @@ import React from 'react';
import * as styles from './index.css';
interface MenuItemProps extends React.HTMLAttributes<HTMLDivElement> {
export interface MenuItemProps extends React.HTMLAttributes<HTMLDivElement> {
icon?: React.ReactElement;
active?: boolean;
disabled?: boolean;
@ -14,7 +14,9 @@ interface MenuItemProps extends React.HTMLAttributes<HTMLDivElement> {
onCollapsedChange?: (collapsed: boolean) => void;
}
interface MenuLinkItemProps extends MenuItemProps, Pick<LinkProps, 'href'> {}
export interface MenuLinkItemProps
extends MenuItemProps,
Pick<LinkProps, 'href'> {}
export const MenuItem = React.forwardRef<HTMLDivElement, MenuItemProps>(
(

View File

@ -30,7 +30,7 @@ const mockVariableMap = (vars: Partial<VariableMap>): 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 <Condition value={value} onChange={onChange} />;
};
const result = render(<Wrapper />);

View File

@ -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<BreadcrumbsProps> =
StyledMuiBreadcrumbs;

View File

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

View File

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

1
packages/debug/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
lib

View File

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

1
packages/env/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
lib

View File

@ -1,5 +1,8 @@
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path="../env.d.ts" />
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)

View File

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

View File

@ -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.7.0-canary.5"

View File

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

View File

@ -1,9 +1,11 @@
/// <reference types="@blocksuite/global" />
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path="./global.d.ts" />
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,

View File

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

5
packages/env/src/global.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
interface Window {
appInfo: {
electron: bool;
};
}

View File

@ -1,10 +0,0 @@
/// <reference types="@webpack/env"" />
// not using import because it will break the declare module line below
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path='../../../electron/layers/preload/preload.d.ts' />
declare module '*.md' {
const text: string;
export default text;
}

View File

@ -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<typeof getUa>) {
return Boolean(this.uaMap[isUseragent]);
}
public checkUseragent(isUseragent: keyof ReturnType<typeof getUa>) {
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,
};
};

11
packages/env/tsconfig.blocksuite.json vendored Normal file
View File

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

View File

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

View File

@ -4,5 +4,9 @@
"./*": "./src/*"
},
"private": true,
"dependencies": {
"@affine/env": "workspace:*",
"@toeverything/y-indexeddb": "workspace:*"
},
"version": "0.7.0-canary.5"
}

View File

@ -1,4 +1,10 @@
{
"extends": "../../tsconfig.json",
"include": ["./src"]
"compilerOptions": {
"outDir": "lib",
"composite": true,
"noEmit": false
},
"include": ["./src"],
"references": [{ "path": "../env" }, { "path": "../y-indexeddb" }]
}

1
packages/i18n/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
lib

View File

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

View File

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

1
packages/jotai/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
lib

View File

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

View File

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

View File

@ -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) */

View File

@ -3,7 +3,15 @@
"include": ["./src"],
"references": [
{
"path": "./tsconfig.node.json"
"path": "../component"
},
{
"path": "../workspace"
}
]
],
"compilerOptions": {
"noEmit": false,
"composite": true,
"outDir": "lib"
}
}

View File

@ -1,9 +0,0 @@
{
"compilerOptions": {
"composite": true,
"module": "ESNext",
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
}

1
packages/workspace/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
lib

View File

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

View File

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

View File

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

View File

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

View File

@ -11,7 +11,7 @@ import type { Workspace as RemoteWorkspace } from './affine/api';
export type JotaiStore = ReturnType<typeof createStore>;
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.

View File

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

1
packages/y-indexeddb/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
lib

View File

@ -1,9 +1,17 @@
{
"extends": "../../tsconfig.json",
"include": ["./src"],
"compilerOptions": {
"composite": true,
"noEmit": false,
"outDir": "lib"
},
"references": [
{
"path": "./tsconfig.node.json"
},
{
"path": "../env"
}
]
}

View File

@ -3,7 +3,8 @@
"composite": true,
"module": "ESNext",
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true
"allowSyntheticDefaultImports": true,
"outDir": "lib"
},
"include": ["vite.config.ts"]
}

View File

@ -1,3 +1,5 @@
import '@affine/env/config';
import { definePlugin } from '@toeverything/plugin-infra/manager';
import { ReleaseStage } from '@toeverything/plugin-infra/type';

View File

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

1
tests/fixtures/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
lib

View File

@ -1,4 +1,11 @@
{
"extends": "../../tsconfig.json",
"include": ["."]
"compilerOptions": {
"composite": true,
"noEmit": false,
"outDir": "lib",
"moduleResolution": "nodenext",
"resolveJsonModule": true
},
"include": [".", "./*.json"]
}

1
tests/kit/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
lib

View File

@ -1,4 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"composite": true,
"noEmit": false,
"outDir": "lib"
},
"include": ["./*.ts"]
}

View File

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

View File

@ -3,7 +3,8 @@
"composite": true,
"module": "ESNext",
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true
"allowSyntheticDefaultImports": true,
"outDir": "lib"
},
"include": ["vitest.config.ts", "scripts"]
}

View File

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