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

chore: use debug package for debug logging #3167

Open
wants to merge 6 commits into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
6 changes: 6 additions & 0 deletions .changeset/chilled-bulldogs-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@typescript/vfs": patch
"@typescript/twoslash": patch
KermanX marked this conversation as resolved.
Show resolved Hide resolved
---

Use `debug` package for debug logging
2 changes: 2 additions & 0 deletions packages/sandbox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@
"dependencies": {
"@typescript/ata": "workspace:*",
"@typescript/vfs": "workspace:*",
"debug": "^4.3.4",
"lz-string": "^1.5.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^25.0.7",
"@types/debug": "^4.1.12",
Copy link
Member

Choose a reason for hiding this comment

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

This seems to imply that sandbox needs a dep on debug; I think that's true given we vendor the vfs into this package?

Copy link
Author

Choose a reason for hiding this comment

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

Yes. The DTS build of @typescript/sandbox would fail unless @types/debug is installed, because @typescript/vfs is vendored.

Copy link
Member

Choose a reason for hiding this comment

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

Right but I mean that this package should also depend on "debug" too so the code doesn't crash.

"@types/jest": "^29.5.12",
"dts-cli": "^2.0.5",
"jest": "^29.5.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/ts-twoslasher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"lint": "dts lint"
},
"devDependencies": {
"@types/debug": "^4.1.12",
"@types/jest": "^29.5.12",
"@types/prettier": "^1.19.0",
"dts-cli": "^2.0.5",
Expand All @@ -53,7 +54,7 @@
},
"dependencies": {
"@typescript/vfs": "workspace:*",
"debug": "^4.1.1",
"debug": "^4.3.4",
"lz-string": "^1.5.0"
},
"peerDependencies": {
Expand Down
11 changes: 3 additions & 8 deletions packages/ts-twoslasher/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
let hasLocalStorage = false
try {
hasLocalStorage = typeof localStorage !== `undefined`
} catch (error) { }
const hasProcess = typeof process !== `undefined`
const shouldDebug = (hasLocalStorage && localStorage.getItem("DEBUG")) || (hasProcess && process.env.DEBUG)

type LZ = typeof import("lz-string")
type TS = typeof import("typescript")
type CompilerOptions = import("typescript").CompilerOptions
Expand All @@ -15,7 +8,9 @@ import { validateInput, validateCodeForErrors } from "./validation"

import { createSystem, createVirtualTypeScriptEnvironment, createFSBackedSystem } from "@typescript/vfs"

const log = shouldDebug ? console.log : (_message?: any, ..._optionalParams: any[]) => ""
import Debug from 'debug'

const log = Debug("typescript:twoslash")

// Hacking in some internal stuff
declare module "typescript" {
Expand Down
3 changes: 2 additions & 1 deletion packages/typescript-vfs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@
"typescript": false
},
"dependencies": {
"debug": "^4.1.1"
"debug": "^4.3.4"
},
"devDependencies": {
"@types/debug": "^4.1.12",
"@types/jest": "^29.5.12",
"babel-jest": "^29.7.0",
"cpy-cli": "^3.1.1",
Expand Down
11 changes: 3 additions & 8 deletions packages/typescript-vfs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,9 @@ interface LocalStorageLike {
declare var localStorage: LocalStorageLike | undefined;
declare var fetch: FetchLike | undefined;

let hasLocalStorage = false
try {
hasLocalStorage = typeof localStorage !== `undefined`
} catch (error) { }

const hasProcess = typeof process !== `undefined`
const shouldDebug = (hasLocalStorage && localStorage!.getItem("DEBUG")) || (hasProcess && process.env.DEBUG)
const debugLog = shouldDebug ? console.log : (_message?: any, ..._optionalParams: any[]) => ""
import Debug from 'debug'

const debugLog = Debug("typescript:vfs")

export interface VirtualTypeScriptEnvironment {
sys: System
Expand Down
28 changes: 26 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.