-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: deno stderr, examples and tests
- Loading branch information
1 parent
da57cfe
commit 06feaf0
Showing
14 changed files
with
190 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
package-lock=false | ||
@jsr:registry=https://npm.jsr.io |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"lock": false, | ||
"imports": { | ||
"@denosaurs/log": "jsr:@denosaurs/log", | ||
"@std/json": "jsr:@std/json" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { assert } from "jsr:@std/assert"; | ||
import { assertIsLog, createJSONLineStream } from "../../utils/test.ts"; | ||
|
||
assert( | ||
(await new Deno.Command("npm", { | ||
args: ["install"], | ||
cwd: import.meta.dirname, | ||
}).spawn().status).success, | ||
); | ||
|
||
Deno.test("deno", async () => { | ||
const { success, stdout } = await new Deno.Command("deno", { | ||
args: ["run", "--quiet", "--no-npm", "main.js"], | ||
cwd: import.meta.dirname, | ||
}).output(); | ||
assert(success); | ||
for await (const line of createJSONLineStream(stdout)) { | ||
assertIsLog(line); | ||
} | ||
}); | ||
|
||
Deno.test("bun", async () => { | ||
const { success, stdout } = await new Deno.Command("bun", { | ||
args: ["main.js"], | ||
cwd: import.meta.dirname, | ||
}).output(); | ||
assert(success); | ||
for await (const line of createJSONLineStream(stdout)) { | ||
assertIsLog(line); | ||
} | ||
}); | ||
|
||
Deno.test("node", async () => { | ||
const { success, stdout } = await new Deno.Command("node", { | ||
args: ["main.js"], | ||
cwd: import.meta.dirname, | ||
}).output(); | ||
assert(success); | ||
for await (const line of createJSONLineStream(stdout)) { | ||
assertIsLog(line); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
package-lock=false | ||
@jsr:registry=https://npm.jsr.io |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"lock": false, | ||
"imports": { | ||
"@denosaurs/log": "jsr:@denosaurs/log", | ||
"@std/json": "jsr:@std/json" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Ensure Bun compatibility | ||
import "@denosaurs/log/transforms/text_encoder_stream"; | ||
|
||
import { ConsoleReadableStream } from "@denosaurs/log"; | ||
import { stderr } from "@denosaurs/log/writables/stderr"; | ||
import { stdout } from "@denosaurs/log/writables/stdout"; | ||
|
||
import { JsonStringifyStream } from "@std/json"; | ||
|
||
const stream = new ConsoleReadableStream(); | ||
const [a, b] = stream | ||
.pipeThrough(new JsonStringifyStream()) | ||
.pipeThrough(new TextEncoderStream()) | ||
.tee(); | ||
|
||
a.pipeTo(stderr); | ||
b.pipeTo(stdout); | ||
|
||
console.log("Hello, world!"); | ||
console.group("Group 1"); | ||
console.debug("Debug message"); | ||
console.groupEnd(); | ||
console.info("Info message"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "module", | ||
"dependencies": { | ||
"@std/json": "npm:@jsr/std__json", | ||
"@denosaurs/log": "npm:@jsr/denosaurs__log" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { assert } from "jsr:@std/assert"; | ||
import { assertIsLog, createJSONLineStream } from "../../utils/test.ts"; | ||
|
||
assert( | ||
(await new Deno.Command("npm", { | ||
args: ["install"], | ||
cwd: import.meta.dirname, | ||
}).spawn().status).success, | ||
); | ||
|
||
Deno.test("deno", async () => { | ||
const { success, stdout, stderr } = await new Deno.Command("deno", { | ||
args: ["run", "--quiet", "--no-npm", "main.js"], | ||
cwd: import.meta.dirname, | ||
}).output(); | ||
assert(success); | ||
for await (const line of createJSONLineStream(stdout)) { | ||
assertIsLog(line); | ||
} | ||
|
||
for await (const line of createJSONLineStream(stderr)) { | ||
assertIsLog(line); | ||
} | ||
}); | ||
|
||
Deno.test("bun", async () => { | ||
const { success, stdout, stderr } = await new Deno.Command("bun", { | ||
args: ["main.js"], | ||
cwd: import.meta.dirname, | ||
}).output(); | ||
assert(success); | ||
for await (const line of createJSONLineStream(stdout)) { | ||
assertIsLog(line); | ||
} | ||
|
||
for await (const line of createJSONLineStream(stderr)) { | ||
assertIsLog(line); | ||
} | ||
}); | ||
|
||
Deno.test("node", async () => { | ||
const { success, stdout, stderr } = await new Deno.Command("node", { | ||
args: ["main.js"], | ||
cwd: import.meta.dirname, | ||
}).output(); | ||
assert(success); | ||
for await (const line of createJSONLineStream(stdout)) { | ||
assertIsLog(line); | ||
} | ||
|
||
for await (const line of createJSONLineStream(stderr)) { | ||
assertIsLog(line); | ||
} | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
// deno-fmt-ignore-file | ||
|
||
export const isDeno = typeof Deno !== "undefined"; | ||
|
||
// @ts-expect-error: The type checking environment is deno, the bun types are not available | ||
export const isBun = typeof process?.versions?.bun !== "undefined" && | ||
"isBun" in process && process?.isBun; | ||
export const isBun = typeof process?.versions?.bun !== "undefined" && "isBun" in process && process?.isBun; | ||
|
||
// @ts-expect-error: The type checking environment is deno, the node types are not available | ||
export const isNode = typeof process !== "undefined" && !isDeno && !isBun; | ||
|
||
// @ts-expect-error: The type checking environment is deno, the browser types are not available | ||
export const isBrowser = typeof globalThis !== "undefined" && | ||
typeof globalThis.document?.createElement !== "undefined"; | ||
export const isBrowser = typeof globalThis !== "undefined" && typeof globalThis.document?.createElement !== "undefined"; | ||
|
||
export const environment = isDeno | ||
? "deno" | ||
: isBun | ||
? "bun" | ||
: isNode | ||
? "node" | ||
: isBrowser | ||
? "browser" | ||
: "unknown"; | ||
export const environment = | ||
isDeno ? "deno" | ||
: isBun ? "bun" | ||
: isNode ? "node" | ||
: isBrowser ? "browser" | ||
: "unknown"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { assert, assertStrictEquals } from "jsr:@std/assert"; | ||
import { TextLineStream } from "jsr:@std/streams"; | ||
import { JsonParseStream } from "jsr:@std/json"; | ||
import { Log, LOG_LEVELS } from "../mod.ts"; | ||
|
||
// deno-lint-ignore no-explicit-any | ||
export function assertIsLog(log: any): asserts log is Log { | ||
assertStrictEquals(typeof log, "object"); | ||
assertStrictEquals(typeof log.timestamp, "number"); | ||
assertStrictEquals(typeof log.level, "string"); | ||
assert(Object.keys(LOG_LEVELS).includes(log.level)); | ||
assert(Array.isArray(log.groups)); | ||
assert(Array.isArray(log.data)); | ||
} | ||
|
||
export function createJSONLineStream(...buffers: Uint8Array[]) { | ||
return ReadableStream.from(buffers) | ||
.pipeThrough(new TextDecoderStream()) | ||
.pipeThrough(new TextLineStream()) | ||
.pipeThrough(new JsonParseStream()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters