Skip to content

Commit ffaaa0a

Browse files
authored
Merge pull request #18 from alienfast/fix-cycle-global-configs
fix build cycle error, move system configs to globalThis
2 parents cdb2967 + 7fd75d0 commit ffaaa0a

9 files changed

Lines changed: 257 additions & 39 deletions

File tree

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
},
1212
"type": "module",
1313
"scripts": {
14-
"build": "run-s clean build:ide build:each",
14+
"build": "run-s clean build:each",
1515
"build:ide": "echo 'tsc -b' && tsc -b",
16-
"build:each": "lerna exec --stream --parallel -- yarn build",
16+
"build:each": "lerna exec --stream -- yarn build",
1717
"clean": "tsx ./scripts/clean.ts",
1818
"clean:yarn": "tsx ./scripts/clean-yarn.ts",
1919
"reset": "tsx ./scripts/reset.ts",
@@ -37,7 +37,7 @@
3737
]
3838
},
3939
"devDependencies": {
40-
"@alienfast/eslint-config": "^5.2.5",
40+
"@alienfast/eslint-config": "^5.2.6",
4141
"@alienfast/logger": "workspace:*",
4242
"@alienfast/prettier-config": "^1.0.2",
4343
"@alienfast/tsconfig": "^1.0.4",
@@ -55,16 +55,16 @@
5555
"@types/rimraf": "^4",
5656
"@vitejs/plugin-react": "^4.3.4",
5757
"auto": "^11.3.0",
58-
"eslint": "^9.19.0",
58+
"eslint": "^9.20.0",
5959
"execa": "^9.5.2",
6060
"husky": "^9.1.7",
6161
"lint-staged": "^15.4.3",
6262
"npm-run-all": "^4.1.5",
63-
"prettier": "^3.4.2",
63+
"prettier": "^3.5.0",
6464
"rimraf": "^6.0.1",
6565
"tsx": "^4.19.2",
6666
"typescript": "^5.7.3",
67-
"typescript-eslint": "^8.23.0",
67+
"typescript-eslint": "^8.24.0",
6868
"vite": "^6.1.0",
6969
"vite-plugin-dts": "^4.5.0",
7070
"vite-tsconfig-paths": "^5.1.4",

packages/logger-browser/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@alienfast/logger-browser",
3-
"version": "11.0.33",
3+
"version": "11.0.32",
44
"type": "module",
55
"main-types-note": "This is to appease tsc, types will be removed by clean-package. see https://github.com/rosskevin/ts-esm-workspaces/tree/bug-main-required-to-build#workaround ",
66
"main": "./dist/index.js",
@@ -19,7 +19,7 @@
1919
"postpack": "clean-package restore -c ../../.clean-package.json"
2020
},
2121
"devDependencies": {
22-
"@alienfast/logger": "^11.0.33",
22+
"@alienfast/logger": "workspace:*",
2323
"clean-package": "^2.2.0",
2424
"vite": "^6.1.0",
2525
"vitest": "^3.0.5"

packages/logger-node/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@alienfast/logger-node",
3-
"version": "11.0.33",
3+
"version": "11.0.32",
44
"type": "module",
55
"main-types-note": "This is to appease tsc, types will be removed by clean-package. see https://github.com/rosskevin/ts-esm-workspaces/tree/bug-main-required-to-build#workaround ",
66
"main": "./dist/index.js",
@@ -22,7 +22,7 @@
2222
"chalk": "^5.4.1"
2323
},
2424
"devDependencies": {
25-
"@alienfast/logger": "^11.0.33",
25+
"@alienfast/logger": "workspace:*",
2626
"clean-package": "^2.2.0",
2727
"vite": "^6.1.0",
2828
"vitest": "^3.0.5"

packages/logger/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"@types/node": "^22.13.1"
2424
},
2525
"devDependencies": {
26-
"@alienfast/logger-node": "workspace:*",
2726
"clean-package": "^2.2.0",
2827
"vite": "^6.1.0",
2928
"vitest": "^3.0.5"

packages/logger/src/Log.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-unsafe-enum-comparison */
22
/* eslint-disable @typescript-eslint/no-unsafe-argument */
33
/* eslint-disable no-console */
4-
/* eslint-disable @typescript-eslint/no-unsafe-call */
5-
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
64

75
import { jsonify } from './jsonify.js'
86
import { Level } from './Level.js'

packages/logger/src/Logger.ts

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,25 @@ import { Log } from './Log.js'
44
import { objectName } from './objects.js'
55
import { LevelOrBoolean, toLevel } from './toLevel.js'
66

7+
export interface LoggerConfig {
8+
/**
9+
* The default threshold for any new Log
10+
*/
11+
defaultThreshold: Level
12+
13+
/**
14+
* The minimum threshold for the system
15+
*/
16+
systemThreshold: Level
17+
}
18+
19+
if (!globalThis.loggerConfig) {
20+
globalThis.loggerConfig = {
21+
defaultThreshold: Level.INFO,
22+
systemThreshold: Level.DEBUG,
23+
}
24+
}
25+
726
if (!globalThis.logs) {
827
globalThis.logs = {}
928
}
@@ -12,12 +31,24 @@ export class Logger {
1231
/**
1332
* The default threshold for any new Log
1433
*/
15-
public static defaultThreshold: Level = Level.INFO
34+
public static setDefaultThreshold(level: Level) {
35+
globalThis.loggerConfig.defaultThreshold = level
36+
}
37+
38+
public static getDefaultThreshold() {
39+
return globalThis.loggerConfig.defaultThreshold
40+
}
1641

1742
/**
1843
* The minimum threshold for the system
1944
*/
20-
public static systemThreshold: Level = Level.DEBUG
45+
public static setSystemThreshold(level: Level) {
46+
globalThis.loggerConfig.systemThreshold = level
47+
}
48+
49+
public static getSystemThreshold() {
50+
return globalThis.loggerConfig.systemThreshold
51+
}
2152

2253
/**
2354
* Resolve a logger
@@ -33,14 +64,13 @@ export class Logger {
3364
}
3465
const name = objectName(object)
3566

36-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
3767
let log: Log | undefined = globalThis.logs[name]
3868
if (!log) {
3969
// need to delay resolution of LogWriter, so pass this in.
4070
log = new Log({
4171
name,
42-
systemThreshold: this.systemThreshold,
43-
threshold: toLevel(threshold, this.defaultThreshold),
72+
systemThreshold: this.getSystemThreshold(),
73+
threshold: toLevel(threshold, this.getDefaultThreshold()),
4474
})
4575
globalThis.logs[name] = log
4676
// console.log(`Log [${name}] set to ${threshold || this.defaultThreshold}`)
@@ -62,8 +92,8 @@ export class Logger {
6292
console.info('\tglobalThis.logWriter', globalThis.logWriter)
6393
// console.info('\tFORCE_LOG_WRITER', process && process.env && process.env.FORCE_LOG_WRITER)
6494
console.info('\tlocation', import.meta.url)
65-
console.info('\tsystemThreshold', this.systemThreshold)
66-
console.info('\tdefaultThreshold', this.defaultThreshold)
95+
console.info('\tsystemThreshold', this.getSystemThreshold())
96+
console.info('\tdefaultThreshold', this.getDefaultThreshold)
6797
console.info('\tDEBUG is', Level.DEBUG)
6898
console.info('\tINFO is', Level.INFO)
6999
console.info('\tConfigured logs:')

packages/logger/src/configureLoggers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function configureLoggers(loggers: LoggersConfig) {
1313
const threshold = loggers[component]
1414
Logger.get(
1515
component as string,
16-
toLevel(threshold as LevelString | Level, Logger.defaultThreshold),
16+
toLevel(threshold as LevelString | Level, Logger.getDefaultThreshold()),
1717
true,
1818
)
1919
}

typings/globalThis.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { LogWriter } from './LogWriter'
1+
import { Log, LogWriter, LoggerConfig } from '@alienfast/logger'
22

33
// Augment the globalThis interface
44
// @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-1-8.html#example-6
@@ -12,4 +12,5 @@ declare global {
1212
// eslint-disable-next-line no-var
1313
var logWriter: LogWriter
1414
var logs: Record<string, Log>
15+
var loggerConfig: LoggerConfig
1516
}

0 commit comments

Comments
 (0)