Skip to content

Commit

Permalink
refactor: cleanup colors in output detection
Browse files Browse the repository at this point in the history
Signed-off-by: Jérôme Benoit <[email protected]>
  • Loading branch information
jerome-benoit committed Sep 29, 2024
1 parent fd39123 commit 551df36
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import {
os,
AsyncFunction,
checkBenchmarkArgs,
colors,
convertReportToBmf,
cpu,
gc,
measure,
mergeDeepRight,
noColor,
overrideBenchmarkDefaults,
version,
writeFileSync,
Expand Down Expand Up @@ -290,7 +290,7 @@ export async function run(opts = {}) {
opts = mergeDeepRight(
{
silent: false,
colors: !noColor,
colors,
size: table.size(benchmarks.map(benchmark => benchmark.name)),
},
opts
Expand Down
31 changes: 20 additions & 11 deletions src/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export const version = (() => {
return {
unknown: () => '',
browser: () => '',
node: () => process.version,
deno: () => Deno.version.deno,
bun: () => process.versions.bun,
node: () => globalThis.process.version,
deno: () => globalThis.Deno.version.deno,
bun: () => globalThis.process.versions.bun,
// hermes: () =>
// globalThis.HermesInternal?.getRuntimeProperties?.()?.[
// 'OSS Release Version'
Expand All @@ -33,9 +33,9 @@ export const os = (() => {
return {
unknown: () => 'unknown',
browser: () => 'unknown',
node: () => `${process.arch}-${process.platform}`,
node: () => `${globalThis.process.arch}-${globalThis.process.platform}`,
deno: () => Deno.build.target,
bun: () => `${process.arch}-${process.platform}`,
bun: () => `${globalThis.process.arch}-${globalThis.process.platform}`,
}[runtime]()
})()

Expand All @@ -49,13 +49,22 @@ export const cpu = await (async () => {
}[runtime]()
})()

export const noColor = (() => {
export const colors = (() => {
return {
unknown: () => false,
browser: () => true,
node: () => !!process.env.NO_COLOR,
deno: () => Deno.noColor,
bun: () => !!process.env.NO_COLOR,
unknown: () =>
globalThis.process?.env?.FORCE_COLOR != null ||
(!globalThis.process?.env?.NO_COLOR &&
!globalThis.process?.env?.NODE_DISABLE_COLORS),
browser: () => false,
node: () =>
globalThis.process.env.FORCE_COLOR != null ||
(!globalThis.process.env.NO_COLOR &&
!globalThis.process.env.NODE_DISABLE_COLORS),
deno: () => !Deno.noColor,
bun: () =>
globalThis.process.env.FORCE_COLOR != null ||
(!globalThis.process.env.NO_COLOR &&
!globalThis.process.env.NODE_DISABLE_COLORS),
}[runtime]()
})()

Expand Down

0 comments on commit 551df36

Please sign in to comment.