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 Himself65
parent 7e8169c4b8
commit fb9d200dd3
81 changed files with 434 additions and 241 deletions

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.5.4-beta.2"

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