fix: remove dependencies in @affine/debug (#2708)

(cherry picked from commit cd5c4b5cb7)
This commit is contained in:
Himself65
2023-06-07 15:41:42 +08:00
committed by himself65
parent 8d22316644
commit bdabe656c3
5 changed files with 8 additions and 13 deletions

View File

@@ -20,7 +20,7 @@ export interface PageViewDBV1 extends DBSchema {
} }
const pageViewDBPromise: Promise<IDBPDatabase<PageViewDBV1>> = const pageViewDBPromise: Promise<IDBPDatabase<PageViewDBV1>> =
environment.isServer typeof window === 'undefined'
? // never resolve in SSR ? // never resolve in SSR
new Promise<any>(() => {}) new Promise<any>(() => {})
: openDB<PageViewDBV1>('page-view', 1, { : openDB<PageViewDBV1>('page-view', 1, {

View File

@@ -3,7 +3,6 @@
"private": true, "private": true,
"main": "./src/index.ts", "main": "./src/index.ts",
"dependencies": { "dependencies": {
"@affine/env": "workspace:*",
"debug": "^4.3.4" "debug": "^4.3.4"
}, },
"devDependencies": { "devDependencies": {

View File

@@ -1,12 +1,9 @@
import { env } from '@affine/env';
import debug from 'debug'; import debug from 'debug';
type LogLevel = 'debug' | 'info' | 'warn' | 'error'; type LogLevel = 'debug' | 'info' | 'warn' | 'error';
const SESSION_KEY = 'affine:debug'; const SESSION_KEY = 'affine:debug';
const development = env.isDebug;
if (env.isBrowser) { if (typeof window !== 'undefined') {
// enable debug logs if the URL search string contains `debug` // enable debug logs if the URL search string contains `debug`
// e.g. http://localhost:3000/?debug // e.g. http://localhost:3000/?debug
if (window.location.search.includes('debug')) { if (window.location.search.includes('debug')) {
@@ -15,11 +12,16 @@ if (env.isBrowser) {
// we need to store the debug flag in sessionStorage // we need to store the debug flag in sessionStorage
sessionStorage.setItem(SESSION_KEY, 'true'); sessionStorage.setItem(SESSION_KEY, 'true');
} }
if (sessionStorage.getItem(SESSION_KEY) === 'true' || development) { if (sessionStorage.getItem(SESSION_KEY) === 'true') {
// enable all debug logs by default // enable all debug logs by default
debug.enable('*'); debug.enable('*');
console.warn('Debug logs enabled'); console.warn('Debug logs enabled');
} }
} else {
if (process.env.NODE_ENV === 'development') {
debug.enable('*');
console.warn('Debug logs enabled');
}
} }
export class DebugLogger { export class DebugLogger {

View File

@@ -8,11 +8,6 @@
"noEmit": false, "noEmit": false,
"outDir": "lib" "outDir": "lib"
}, },
"references": [
{
"path": "../env"
}
],
"include": ["./src"], "include": ["./src"],
"exclude": ["node_modules"] "exclude": ["node_modules"]
} }

View File

@@ -158,7 +158,6 @@ __metadata:
version: 0.0.0-use.local version: 0.0.0-use.local
resolution: "@affine/debug@workspace:packages/debug" resolution: "@affine/debug@workspace:packages/debug"
dependencies: dependencies:
"@affine/env": "workspace:*"
"@types/debug": ^4.1.8 "@types/debug": ^4.1.8
debug: ^4.3.4 debug: ^4.3.4
languageName: unknown languageName: unknown