Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move logger to common-universal #691

Merged
merged 22 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/app/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export default defineConfig({
// nodePolyfills needs to be first
nodePolyfills({
// buffer is needed when connecting with a coinbase wallet installed on a phone
include: ['buffer'],
// util and path is needed for common-universal's logger
include: ['buffer', 'util', 'path'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need these? I would prefer not to use node apis in browser

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Util is used for inspect to format objects, path isn't doing anything in browser. I tried to conditionally import a path depending if that's a browser or not, but nothing worked - logger would have to be async which we don't want to do

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway using util polyfill breaks frontend tests, so probably we need to figure out something else

}),
react(),
tsconfigPaths(),
Expand Down
32 changes: 1 addition & 31 deletions packages/common-nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,11 @@
"types": "./dist/types/env/index.d.ts",
"default": "./dist/cjs/env/index.js"
}
},
"./logger": {
"import": {
"@marsfoundation/local-spark-monorepo": "./src/logger/index.ts",
"types": "./dist/types/logger/index.d.ts",
"default": "./dist/esm/logger/index.js"
},
"require": {
"@marsfoundation/local-spark-monorepo": "./src/logger/index.ts",
"types": "./dist/types/logger/index.d.ts",
"default": "./dist/cjs/logger/index.js"
}
},
"./tracer": {
"import": {
"@marsfoundation/local-spark-monorepo": "./src/tracer/index.ts",
"types": "./dist/types/tracer/index.d.ts",
"default": "./dist/esm/tracer/index.js"
},
"require": {
"@marsfoundation/local-spark-monorepo": "./src/tracer/index.ts",
"types": "./dist/types/tracer/index.d.ts",
"default": "./dist/cjs/tracer/index.js"
}
}
},
"typesVersions": {
"*": {
"env": ["dist/types/env/index.d.ts"],
"logger": ["dist/types/logger/index.d.ts"],
"tracer": ["dist/types/tracer/index.d.ts"]
"env": ["dist/types/env/index.d.ts"]
}
},
"files": ["dist"],
Expand All @@ -72,7 +46,6 @@
"@sinonjs/fake-timers": "^13.0.5",
"@types/express": "^5.0.0",
"@types/mocha": "^10.0.10",
"@types/pretty-ms": "^5.0.1",
"@types/sinonjs__fake-timers": "^8.1.5",
"@types/uuid": "^10.0.0",
"earl": "^1.3.0",
Expand All @@ -81,10 +54,7 @@
"tinyspy": "^3.0.2"
},
"dependencies": {
"chalk": "^5.3.0",
"dotenv": "^16.3.1",
"error-stack-parser": "^2.1.4",
"pretty-ms": "^9.2.0",
"uuid": "^11.0.3"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/common-nodejs/src/http/HttpClient.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Logger } from '@marsfoundation/common-universal/logger'
import { MockObject, expect, mockFn, mockObject } from 'earl'
import { ZodError, z } from 'zod'
import { Logger } from '../logger/index.js'
import { HttpClient, HttpError } from './HttpClient.js'
import { HttpServerMock, PostBody, getResponseSchema, postBodySchema } from './HttpServer.mock.js'

Expand Down
2 changes: 1 addition & 1 deletion packages/common-nodejs/src/http/HttpClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Logger } from '@marsfoundation/common-universal/logger'
import { mergeDeep } from 'remeda'
import { z } from 'zod'
import { Logger } from '../logger/index.js'
import { RetryOptions, defaultRetryOptions, fetchRetry } from './fetchRetry.js'

export class HttpClient {
Expand Down
37 changes: 36 additions & 1 deletion packages/common-universal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,36 @@
"types": "./dist/types/index.d.ts",
"default": "./dist/cjs/index.js"
}
},
"./logger": {
"import": {
"@marsfoundation/local-spark-monorepo": "./src/logger/index.ts",
"types": "./dist/types/logger/index.d.ts",
"default": "./dist/esm/logger/index.js"
},
"require": {
"@marsfoundation/local-spark-monorepo": "./src/logger/index.ts",
"types": "./dist/types/logger/index.d.ts",
"default": "./dist/cjs/logger/index.js"
}
},
"./tracer": {
"import": {
"@marsfoundation/local-spark-monorepo": "./src/tracer/index.ts",
"types": "./dist/types/tracer/index.d.ts",
"default": "./dist/esm/tracer/index.js"
},
"require": {
"@marsfoundation/local-spark-monorepo": "./src/tracer/index.ts",
"types": "./dist/types/tracer/index.d.ts",
"default": "./dist/cjs/tracer/index.js"
}
}
},
"typesVersions": {
"*": {
"logger": ["dist/types/logger/index.d.ts"],
"tracer": ["dist/types/tracer/index.d.ts"]
}
},
"files": ["dist"],
Expand All @@ -48,13 +78,18 @@
"@sinonjs/fake-timers": "^13.0.5",
"@types/mocha": "^10.0.10",
"@types/ms": "^2.1.0",
"@types/node": "^22.13.9",
"@types/pretty-ms": "^5.0.1",
"@types/sinonjs__fake-timers": "^8.1.5",
"earl": "^1.3.0",
"mocha": "^10.8.2"
},
"dependencies": {
"chalk": "^5.3.0",
"error-stack-parser": "^2.1.4",
"fetch-retry": "^5.0.6",
"ms": "^2.1.3",
"p-limit": "^6.1.0"
"p-limit": "^6.1.0",
"pretty-ms": "^9.2.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { join } from 'node:path'

import { assertNever } from '@marsfoundation/common-universal'
import { assertNever } from '../assert/assertNever.js'
import { LogFormatterJson } from './LogFormatterJson.js'
import { LogFormatterPretty } from './LogFormatterPretty.js'
import { LEVEL, LogLevel } from './LogLevel.js'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PublicInterface } from '@marsfoundation/common-universal'
import { PublicInterface } from '../typeHelpers.js'
import { Tracer } from './Tracer.js'

export function TracerMock(): Tracer {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import prettyMilliseconds from 'pretty-ms'
import { ILogger } from '../logger/index.js'
import { ILogger } from '../logger/Logger.js'

interface TracerOptions {
service?: string
Expand Down
Loading
Loading