Skip to content

Commit

Permalink
fix: don't print logs to the debug console
Browse files Browse the repository at this point in the history
Fixes #460
  • Loading branch information
sheremet-va committed Sep 8, 2024
1 parent b6082ca commit 50e6489
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
"release": "tsx ./scripts/release.mts && git update-ref refs/heads/release refs/heads/main && git push origin release",
"build": "tsup --minify --clean",
"package": "vsce package --no-dependencies",
"dev": "tsup --watch --sourcemap",
"dev": "NODE_ENV=dev tsup --watch --sourcemap",
"test": "vscode-test",
"test:watch": "vscode-test --watch-files src/**/*.ts --watch-files test/**/*.test.ts",
"test-e2e": "vitest --root test-e2e",
Expand Down
16 changes: 12 additions & 4 deletions src/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,22 @@ export const log = {
if (typeof args.at(-1) === 'string' && args.at(-1).endsWith('\n'))
args[args.length - 1] = args.at(-1).slice(0, process.platform === 'win32' ? -2 : -1)

console[type]('[Worker]', ...args)
if (process.env.NODE_ENV === 'dev') {
console[type]('[Worker]', ...args)
}
_log.appendLine(`[Worker] ${args.join(' ')}`)
},
info: (...args: any[]) => {
console.log(...args)
if (process.env.NODE_ENV === 'dev') {
console.log(...args)
}
const time = new Date().toLocaleTimeString()
_log.appendLine(`[INFO ${time}] ${args.join(' ')}`)
},
error: (...args: any[]) => {
console.error(...args)
if (process.env.NODE_ENV === 'dev') {
console.error(...args)
}
const time = new Date().toLocaleTimeString()
for (let i = 0; i < args.length; i++) {
if (args[i] instanceof Error) {
Expand All @@ -32,7 +38,9 @@ export const log = {
? undefined
: (...args: string[]) => {
const time = new Date().toLocaleTimeString()
console.log(`[${time}]`, ...args)
if (process.env.NODE_ENV === 'dev') {
console.log(`[${time}]`, ...args)
}
_log.appendLine(`[${time}] ${args.join(' ')}`)
},
workspaceInfo: (folder: string, ...args: any[]) => {
Expand Down
3 changes: 3 additions & 0 deletions tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export default defineConfig([
entry: ['./src/extension.ts'],
external: ['vscode'],
format: 'cjs',
define: {
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'production'),
},
},
{
entry: ['./src/worker/worker.ts', './src/worker/debug.ts'],
Expand Down

0 comments on commit 50e6489

Please sign in to comment.