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
81 changed files with 434 additions and 241 deletions

View File

@@ -1,58 +0,0 @@
import { DebugLogger } from '@affine/debug';
import markdown from '@affine/templates/AFFiNE-beta-0.5.4.md';
import { ContentParser } from '@blocksuite/blocks/content-parser';
import type { Page } from '@blocksuite/store';
declare global {
interface Window {
lastImportedMarkdown: string;
}
}
const demoTitle = markdown
.split('\n')
.splice(0, 1)
.join('')
.replaceAll('#', '')
.trim();
const demoText = markdown.split('\n').slice(1).join('\n');
const logger = new DebugLogger('init-page');
export function initPage(page: Page): void {
logger.debug('initEmptyPage', page.id);
// Add page block and surface block at root level
const isFirstPage = page.meta.init === true;
if (isFirstPage) {
page.workspace.setPageMeta(page.id, {
init: false,
});
_initPageWithDemoMarkdown(page);
} else {
_initEmptyPage(page);
}
page.resetHistory();
}
export function _initEmptyPage(page: Page, title?: string): void {
const pageBlockId = page.addBlock('affine:page', {
title: new page.Text(title ?? ''),
});
page.addBlock('affine:surface', {}, pageBlockId);
const frameId = page.addBlock('affine:frame', {}, pageBlockId);
page.addBlock('affine:paragraph', {}, frameId);
}
export function _initPageWithDemoMarkdown(page: Page): void {
logger.debug('initPageWithDefaultMarkdown', page.id);
const pageBlockId = page.addBlock('affine:page', {
title: new page.Text(demoTitle),
});
page.addBlock('affine:surface', {}, pageBlockId);
const frameId = page.addBlock('affine:frame', {}, pageBlockId);
page.addBlock('affine:paragraph', {}, frameId);
const contentParser = new ContentParser(page);
contentParser.importMarkdown(demoText, frameId);
page.workspace.setPageMeta(page.id, { title: demoTitle });
}

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