From dc95f2e065a8403b5fcf55c19a467ee0a61b83c8 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Thu, 18 Apr 2024 14:35:24 +0100 Subject: [PATCH 1/2] Phoenix: Support older Node versions in test harness This brings Phoenix's minimum required version from 20.x down to 16.x. ReadableStream.from() is deemed experimental, and requires Node 20.x (or at least, something higher than 18.x). This was the only code that made us require version 20.x. ReadableStream and WritableStream are available from Node 16.5, but require that they be explicitly imported. --- packages/phoenix/test/coreutils/harness.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/phoenix/test/coreutils/harness.js b/packages/phoenix/test/coreutils/harness.js index 339b9b9d..08ea91c2 100644 --- a/packages/phoenix/test/coreutils/harness.js +++ b/packages/phoenix/test/coreutils/harness.js @@ -19,8 +19,9 @@ import { Context } from "contextlink"; import { SyncLinesReader } from '../../src/ansi-shell/ioutil/SyncLinesReader.js'; import { CommandStdinDecorator } from '../../src/ansi-shell/pipeline/iowrappers.js'; +import { ReadableStream, WritableStream } from 'stream/web' -export class WritableStringStream extends WritableStream { +class WritableStringStream extends WritableStream { constructor() { super({ write: (chunk) => { @@ -42,8 +43,23 @@ export class WritableStringStream extends WritableStream { // TODO: Flesh this out as needed. export const MakeTestContext = (command, { positionals = [], values = {}, stdinInputs = [], env = {} }) => { + // This is a replacement to ReadableStream.from() in earlier Node versions + // Sourece: https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream#convert_an_iterator_or_async_iterator_to_a_stream + function iteratorToStream(iterator) { + return new ReadableStream({ + async pull(controller) { + const { value, done } = await iterator.next(); - let in_ = ReadableStream.from(stdinInputs).getReader(); + if (done) { + controller.close(); + } else { + controller.enqueue(value); + } + }, + }); + } + + let in_ = iteratorToStream(stdinInputs.values()).getReader(); if (command.input?.syncLines) { in_ = new SyncLinesReader({ delegate: in_ }); } From 5ad78a5ebb15164347b73aa3745016b6957803eb Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Thu, 18 Apr 2024 14:40:24 +0100 Subject: [PATCH 2/2] Expand supported versions that we test in CI Phoenix now only requires 16.x or above, and so does Puter itself, so let's include that, and also 18.x as the other LTS version. --- .github/workflows/build-and-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index b05b5e25..c6e731cc 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: - node-version: [20.x, 21.x] + node-version: [16.x, 18.x, 20.x, 21.x] # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ steps: