From aac7ba793f6574a28481a9306494e18369f482a2 Mon Sep 17 00:00:00 2001 From: Alexey Raspopov Date: Tue, 15 Aug 2023 13:28:44 -0400 Subject: [PATCH 1/3] fix color detection in edge runtime --- .github/workflows/benchmarks.yaml | 4 ++-- .github/workflows/testing.yaml | 5 +++-- picocolors.js | 14 +++++++------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/.github/workflows/benchmarks.yaml b/.github/workflows/benchmarks.yaml index a300285..f486bb4 100644 --- a/.github/workflows/benchmarks.yaml +++ b/.github/workflows/benchmarks.yaml @@ -2,9 +2,9 @@ name: Benchmarks on: push: - branches: [ main ] + branches: [main] pull_request: - branches: [ main ] + branches: [main] env: FORCE_COLOR: 3 diff --git a/.github/workflows/testing.yaml b/.github/workflows/testing.yaml index 6a949f3..9accbb0 100644 --- a/.github/workflows/testing.yaml +++ b/.github/workflows/testing.yaml @@ -2,9 +2,9 @@ name: Testing on: push: - branches: [ main ] + branches: [main] pull_request: - branches: [ main ] + branches: [main] jobs: modern: @@ -13,6 +13,7 @@ jobs: strategy: matrix: node-version: + - 18 - 16 - 14 - 12 diff --git a/picocolors.js b/picocolors.js index fdb6304..544b5db 100644 --- a/picocolors.js +++ b/picocolors.js @@ -1,12 +1,12 @@ -let tty = require("tty") - +let argv = process.argv || [], + env = process.env let isColorSupported = - !("NO_COLOR" in process.env || process.argv.includes("--no-color")) && - ("FORCE_COLOR" in process.env || - process.argv.includes("--color") || + !("NO_COLOR" in env || argv.includes("--no-color")) && + ("FORCE_COLOR" in env || + argv.includes("--color") || process.platform === "win32" || - (tty.isatty(1) && process.env.TERM !== "dumb") || - "CI" in process.env) + (require != null && require("tty").isatty(1) && env.TERM !== "dumb") || + "CI" in env) let formatter = (open, close, replace = open) => From ba9dcbdb5b3360fd179b2a8310ccafac92a2c5d2 Mon Sep 17 00:00:00 2001 From: Alexey Raspopov Date: Tue, 15 Aug 2023 13:54:01 -0400 Subject: [PATCH 2/3] add env test for the edge --- tests/environments.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/environments.js b/tests/environments.js index 89e3139..1a9fa3a 100644 --- a/tests/environments.js +++ b/tests/environments.js @@ -46,6 +46,12 @@ test("windows", () => { assert.equal(pc.red("text"), pc.createColors(true).red("text")) }) +test("edge runtime", () => { + let pc = initModuleEnv({ env: { FORCE_COLOR: "1" }, argv: undefined, require: undefined }) + assert.equal(pc.isColorSupported, true) + assert.equal(pc.red("text"), pc.createColors(true).red("text")) +}) + function test(name, fn) { try { fn() @@ -56,7 +62,7 @@ function test(name, fn) { } } -function initModuleEnv({ env, argv = [], platform = "darwin" }) { +function initModuleEnv({ env, argv = [], platform = "darwin", require = global.require }) { let process = { env, argv, platform } let context = vm.createContext({ require, process, module: { exports: {} } }) let script = new vm.Script(source) From 571ede8d08aadb7065ce5bed5887567893ba7165 Mon Sep 17 00:00:00 2001 From: Alexey Raspopov Date: Tue, 15 Aug 2023 13:55:03 -0400 Subject: [PATCH 3/3] use node lts for benchmarks --- .github/workflows/benchmarks.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/benchmarks.yaml b/.github/workflows/benchmarks.yaml index f486bb4..6ddbb36 100644 --- a/.github/workflows/benchmarks.yaml +++ b/.github/workflows/benchmarks.yaml @@ -17,7 +17,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: - node-version: 16 + node-version: 18 - run: npm install - name: Ensure color support detection run: node tests/environments.js