From cd433641372cacf7ffa10236506b5484f72f1c5a Mon Sep 17 00:00:00 2001 From: _Kerman Date: Fri, 28 Jun 2024 09:43:09 +0800 Subject: [PATCH 1/6] chore: use `debug` package for debug logging --- packages/ts-twoslasher/package.json | 3 ++- packages/ts-twoslasher/src/index.ts | 11 +++-------- packages/typescript-vfs/package.json | 3 ++- packages/typescript-vfs/src/index.ts | 11 +++-------- pnpm-lock.yaml | 22 ++++++++++++++++++++-- 5 files changed, 30 insertions(+), 20 deletions(-) diff --git a/packages/ts-twoslasher/package.json b/packages/ts-twoslasher/package.json index 1f4bbda45b12..61109a250aef 100755 --- a/packages/ts-twoslasher/package.json +++ b/packages/ts-twoslasher/package.json @@ -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", @@ -53,7 +54,7 @@ }, "dependencies": { "@typescript/vfs": "workspace:*", - "debug": "^4.1.1", + "debug": "^4.3.4", "lz-string": "^1.5.0" }, "peerDependencies": { diff --git a/packages/ts-twoslasher/src/index.ts b/packages/ts-twoslasher/src/index.ts index 0864bf3de185..8437b3d5779d 100755 --- a/packages/ts-twoslasher/src/index.ts +++ b/packages/ts-twoslasher/src/index.ts @@ -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 @@ -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:vfs") // Hacking in some internal stuff declare module "typescript" { diff --git a/packages/typescript-vfs/package.json b/packages/typescript-vfs/package.json index 36054f5fb85d..e3abee23f84b 100755 --- a/packages/typescript-vfs/package.json +++ b/packages/typescript-vfs/package.json @@ -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", diff --git a/packages/typescript-vfs/src/index.ts b/packages/typescript-vfs/src/index.ts index 8040f29ce242..073de1305005 100755 --- a/packages/typescript-vfs/src/index.ts +++ b/packages/typescript-vfs/src/index.ts @@ -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 diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d1741d0a94b1..f7e652f8b3ed 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -245,12 +245,15 @@ importers: specifier: workspace:* version: link:../typescript-vfs debug: - specifier: ^4.1.1 + specifier: ^4.3.4 version: 4.3.4 lz-string: specifier: ^1.5.0 version: 1.5.0 devDependencies: + '@types/debug': + specifier: ^4.1.12 + version: 4.1.12 '@types/jest': specifier: ^29.5.12 version: 29.5.12 @@ -303,9 +306,12 @@ importers: packages/typescript-vfs: dependencies: debug: - specifier: ^4.1.1 + specifier: ^4.3.4 version: 4.3.4 devDependencies: + '@types/debug': + specifier: ^4.1.12 + version: 4.1.12 '@types/jest': specifier: ^29.5.12 version: 29.5.12 @@ -2489,6 +2495,9 @@ packages: '@types/debug@0.0.30': resolution: {integrity: sha512-orGL5LXERPYsLov6CWs3Fh6203+dXzJkR7OnddIr2514Hsecwc8xRpzCapshBbKFImCsvS/mk6+FWiN5LyZJAQ==} + '@types/debug@4.1.12': + resolution: {integrity: sha512-vIChWdVG3LG1SMxEvI/AK+FWJthlrqlTu7fbrlywTkkaONwk/UAGaULXRlf8vkzFBLVm0zkMdCquhL5aOjhXPQ==} + '@types/eslint-scope@3.7.7': resolution: {integrity: sha512-MzMFlSLBqNF2gcHWO0G1vP/YQyfvrxZ0bF+u7mzUdZ1/xK4A4sru+nraZz5i3iEIk1l1uyicaDVTB4QbbEkAYg==} @@ -2585,6 +2594,9 @@ packages: '@types/mkdirp@0.5.2': resolution: {integrity: sha512-U5icWpv7YnZYGsN4/cmh3WD2onMY0aJIiTE6+51TwJCttdHvtCYmkBNOobHlXwrJRL0nkH9jH4kD+1FAdMN4Tg==} + '@types/ms@0.7.34': + resolution: {integrity: sha512-nG96G3Wp6acyAgJqGasjODb+acrI7KltPiRxzHPXnP3NgI28bpQDRv53olbqGXbfcgF5aiiHmO3xpwEpS5Ld9g==} + '@types/node-fetch@2.6.11': resolution: {integrity: sha512-24xFj9R5+rfQJLRyM56qh+wnVSYhyXC2tkoBndtY0U+vubqNsYXGjufB2nn8Q6gt0LrARwL6UBtMCSVCwl4B1g==} @@ -13056,6 +13068,10 @@ snapshots: '@types/debug@0.0.30': {} + '@types/debug@4.1.12': + dependencies: + '@types/ms': 0.7.34 + '@types/eslint-scope@3.7.7': dependencies: '@types/eslint': 7.29.0 @@ -13176,6 +13192,8 @@ snapshots: dependencies: '@types/node': 18.19.33 + '@types/ms@0.7.34': {} + '@types/node-fetch@2.6.11': dependencies: '@types/node': 18.19.33 From a375105c8d6cecd076959334e5d1d72c118feed7 Mon Sep 17 00:00:00 2001 From: _Kerman Date: Fri, 28 Jun 2024 12:42:52 +0800 Subject: [PATCH 2/6] fix: debug namespace --- packages/ts-twoslasher/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ts-twoslasher/src/index.ts b/packages/ts-twoslasher/src/index.ts index 8437b3d5779d..7d4baf954f82 100755 --- a/packages/ts-twoslasher/src/index.ts +++ b/packages/ts-twoslasher/src/index.ts @@ -10,7 +10,7 @@ import { createSystem, createVirtualTypeScriptEnvironment, createFSBackedSystem import Debug from 'debug' -const log = Debug("typescript:vfs") +const log = Debug("typescript:twoslash") // Hacking in some internal stuff declare module "typescript" { From 9aa85e68ad60fdde423266ceffa38dd2a8d7b100 Mon Sep 17 00:00:00 2001 From: _Kerman Date: Sat, 29 Jun 2024 09:17:47 +0800 Subject: [PATCH 3/6] docs: add changeset --- .changeset/chilled-bulldogs-cross.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/chilled-bulldogs-cross.md diff --git a/.changeset/chilled-bulldogs-cross.md b/.changeset/chilled-bulldogs-cross.md new file mode 100644 index 000000000000..284d2eb973fc --- /dev/null +++ b/.changeset/chilled-bulldogs-cross.md @@ -0,0 +1,6 @@ +--- +"@typescript/vfs": patch +"@typescript/twoslash": patch +--- + +Use `debug` package for debug logging From 5f00e054b97566ed1f4cbc5c12edcf0f47b9aa67 Mon Sep 17 00:00:00 2001 From: _Kerman Date: Sat, 29 Jun 2024 12:43:39 +0800 Subject: [PATCH 4/6] deps: add `@types/debug` to devDependencies of `@typescript/sandbox` --- packages/sandbox/package.json | 1 + pnpm-lock.yaml | 3 +++ 2 files changed, 4 insertions(+) diff --git a/packages/sandbox/package.json b/packages/sandbox/package.json index 487decc87c3b..b7655a27717c 100644 --- a/packages/sandbox/package.json +++ b/packages/sandbox/package.json @@ -49,6 +49,7 @@ }, "devDependencies": { "@rollup/plugin-commonjs": "^25.0.7", + "@types/debug": "^4.1.12", "@types/jest": "^29.5.12", "dts-cli": "^2.0.5", "jest": "^29.5.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f7e652f8b3ed..f5ff7059b982 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -217,6 +217,9 @@ importers: '@rollup/plugin-commonjs': specifier: ^25.0.7 version: 25.0.8(rollup@3.29.4) + '@types/debug': + specifier: ^4.1.12 + version: 4.1.12 '@types/jest': specifier: ^29.5.12 version: 29.5.12 From d1a14e5d07397ffd53df15f3e99d60fdebd45c21 Mon Sep 17 00:00:00 2001 From: _Kerman Date: Tue, 9 Jul 2024 13:49:40 +0800 Subject: [PATCH 5/6] deps: add `debug` to dependencies of `@typescript/sandbox` --- packages/sandbox/package.json | 1 + pnpm-lock.yaml | 3 +++ 2 files changed, 4 insertions(+) diff --git a/packages/sandbox/package.json b/packages/sandbox/package.json index b7655a27717c..c25a40d80fae 100644 --- a/packages/sandbox/package.json +++ b/packages/sandbox/package.json @@ -45,6 +45,7 @@ "dependencies": { "@typescript/ata": "workspace:*", "@typescript/vfs": "workspace:*", + "debug": "^4.3.4", "lz-string": "^1.5.0" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f5ff7059b982..8376455ad9e9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -210,6 +210,9 @@ importers: '@typescript/vfs': specifier: workspace:* version: link:../typescript-vfs + debug: + specifier: ^4.3.4 + version: 4.3.4 lz-string: specifier: ^1.5.0 version: 1.5.0 From ec8c23a5ce708b29462d4cc1148ed94faf4e547d Mon Sep 17 00:00:00 2001 From: _Kerman Date: Wed, 10 Jul 2024 01:20:15 +0800 Subject: [PATCH 6/6] Update .changeset/chilled-bulldogs-cross.md Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com> --- .changeset/chilled-bulldogs-cross.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.changeset/chilled-bulldogs-cross.md b/.changeset/chilled-bulldogs-cross.md index 284d2eb973fc..21e2195fead4 100644 --- a/.changeset/chilled-bulldogs-cross.md +++ b/.changeset/chilled-bulldogs-cross.md @@ -1,5 +1,6 @@ --- "@typescript/vfs": patch +"@typescript/sandbox": patch "@typescript/twoslash": patch ---