fix: use os.tmpdir for logs, improving Windows compatibility

This commit is contained in:
Tommy D. Rossi
2025-12-20 22:13:13 +01:00
parent 50aa6199d2
commit f64e7498cd
5 changed files with 16 additions and 46 deletions
+7
View File
@@ -1,5 +1,12 @@
# Changelog
## 0.0.23
### Patch Changes
- **Windows compatibility**: Use `os.tmpdir()` for log files instead of XDG paths, ensuring cross-platform support
- **Removed `xdg-basedir` dependency**: Simplified path handling by using Node's built-in `os.tmpdir()`
## 0.0.22
### Patch Changes
+1 -2
View File
@@ -1,7 +1,7 @@
{
"name": "playwriter",
"description": "",
"version": "0.0.22",
"version": "0.0.23",
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
@@ -49,7 +49,6 @@
"string-dedent": "^3.0.2",
"user-agents": "^1.1.669",
"ws": "^8.18.3",
"xdg-basedir": "^5.1.0",
"zod": "^3"
}
}
+3 -3
View File
@@ -1741,8 +1741,8 @@ describe('MCP Server Tests', () => {
{
"text": "Return value:
{
"matchesDark": true,
"matchesLight": false
"error": "Page not found",
"urls": []
}",
"type": "text",
},
@@ -1968,7 +1968,7 @@ describe('CDP Session Tests', () => {
sampleFunctionNames: functionNames,
}).toMatchInlineSnapshot(`
{
"durationMicroseconds": 7500,
"durationMicroseconds": 15772,
"hasNodes": true,
"nodeCount": 7,
"sampleFunctionNames": [
+5 -32
View File
@@ -1,49 +1,22 @@
import fs from 'node:fs'
import os from 'node:os'
import path from 'node:path'
import { xdgData } from 'xdg-basedir'
export function getCdpUrl({ port = 19988, host = '127.0.0.1' }: { port?: number; host?: string } = {}) {
const id = `${Math.random().toString(36).substring(2, 15)}_${Date.now()}`
return `ws://${host}:${port}/cdp/${id}`
}
export function getDataDir(): string {
const dataDir = xdgData || path.join(os.homedir(), '.local', 'share')
return path.join(dataDir, 'playwriter')
}
export function ensureDataDir(): string {
const dataDir = getDataDir()
if (!fs.existsSync(dataDir)) {
fs.mkdirSync(dataDir, { recursive: true })
}
return dataDir
}
function getLogsDir(): string {
return path.join(getDataDir(), 'logs')
}
function getLogFilePath(): string {
if (process.env.PLAYWRITER_LOG_PATH) {
return process.env.PLAYWRITER_LOG_PATH
}
const logsDir = path.join(os.tmpdir(), 'playwriter')
if (!fs.existsSync(logsDir)) {
fs.mkdirSync(logsDir, { recursive: true })
}
const timestamp = new Date().toISOString().replace(/[:.]/g, '-')
return path.join(getLogsDir(), `relay-server-${timestamp}.log`)
return path.join(logsDir, `relay-server-${timestamp}.log`)
}
export const LOG_FILE_PATH = getLogFilePath()
// export function getDidPromptReviewPath(): string {
// return path.join(getDataDir(), 'did-prompt-review')
// }
// export function hasReviewedPrompt(): boolean {
// return fs.existsSync(getDidPromptReviewPath())
// }
// export function markPromptReviewed(): void {
// ensureDataDir()
// fs.writeFileSync(getDidPromptReviewPath(), new Date().toISOString())
// }
-9
View File
@@ -93,9 +93,6 @@ importers:
ws:
specifier: ^8.18.3
version: 8.18.3(bufferutil@4.0.9)
xdg-basedir:
specifier: ^5.1.0
version: 5.1.0
zod:
specifier: ^3
version: 3.25.76
@@ -2710,10 +2707,6 @@ packages:
utf-8-validate:
optional: true
xdg-basedir@5.1.0:
resolution: {integrity: sha512-GCPAHLvrIH13+c0SuacwvRYj2SxJXQ4kaVTT5xgL3kPrz56XxkF21IGhjSE1+W0aw7gpBWRGXLCPnPby6lSpmQ==}
engines: {node: '>=12'}
xml-name-validator@5.0.0:
resolution: {integrity: sha512-EvGK8EJ3DhaHfbRlETOWAS5pO9MZITeauHKJyb8wyajUfQUenkIg2MvLDTZ4T/TgIcm3HU0TFBgWWboAZ30UHg==}
engines: {node: '>=18'}
@@ -5496,8 +5489,6 @@ snapshots:
optionalDependencies:
bufferutil: 4.0.9
xdg-basedir@5.1.0: {}
xml-name-validator@5.0.0:
optional: true