From 85e11371f8ef66eed94e5a99c4db684494f1f66d Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Tue, 25 Jul 2023 11:50:44 +0100 Subject: [PATCH 1/2] fix: support for Node.js 20 --- .github/workflows/access-client.yml | 7 ++++++- .github/workflows/aggregate-client.yml | 7 ++++++- .github/workflows/upload-client.yml | 7 ++++++- .github/workflows/w3up-client.yml | 7 ++++++- packages/upload-client/src/car.js | 16 +++++++++++++--- 5 files changed, 37 insertions(+), 7 deletions(-) diff --git a/.github/workflows/access-client.yml b/.github/workflows/access-client.yml index d028e97f6..fe4b78979 100644 --- a/.github/workflows/access-client.yml +++ b/.github/workflows/access-client.yml @@ -18,6 +18,11 @@ on: jobs: test: runs-on: ubuntu-latest + strategy: + matrix: + node_version: + - 18 + - 20 steps: - uses: actions/checkout@v3 - uses: pnpm/action-setup@v2.2.3 @@ -25,7 +30,7 @@ jobs: version: 8 - uses: actions/setup-node@v3 with: - node-version: 18 + node-version: ${{ matrix.node_version }} cache: 'pnpm' - run: pnpm install - run: pnpm run build diff --git a/.github/workflows/aggregate-client.yml b/.github/workflows/aggregate-client.yml index 296f896e4..60df7c6c8 100644 --- a/.github/workflows/aggregate-client.yml +++ b/.github/workflows/aggregate-client.yml @@ -18,6 +18,11 @@ on: jobs: test: runs-on: ubuntu-latest + strategy: + matrix: + node_version: + - 18 + - 20 steps: - uses: actions/checkout@v3 - uses: pnpm/action-setup@v2.2.3 @@ -25,7 +30,7 @@ jobs: version: 8 - uses: actions/setup-node@v3 with: - node-version: 18 + node-version: ${{ matrix.node_version }} cache: 'pnpm' - run: pnpm install - run: pnpm run build diff --git a/.github/workflows/upload-client.yml b/.github/workflows/upload-client.yml index 63cb8fee0..55553c57b 100644 --- a/.github/workflows/upload-client.yml +++ b/.github/workflows/upload-client.yml @@ -18,6 +18,11 @@ on: jobs: test: runs-on: ubuntu-latest + strategy: + matrix: + node_version: + - 18 + - 20 steps: - uses: actions/checkout@v3 - uses: pnpm/action-setup@v2.2.3 @@ -25,7 +30,7 @@ jobs: version: 8 - uses: actions/setup-node@v3 with: - node-version: 18 + node-version: ${{ matrix.node_version }} cache: 'pnpm' - run: pnpm install - run: pnpm run build diff --git a/.github/workflows/w3up-client.yml b/.github/workflows/w3up-client.yml index 9b8c9166e..ef53073df 100644 --- a/.github/workflows/w3up-client.yml +++ b/.github/workflows/w3up-client.yml @@ -16,6 +16,11 @@ jobs: test: name: Test runs-on: ubuntu-latest + strategy: + matrix: + node_version: + - 18 + - 20 defaults: run: working-directory: ./packages/w3up-client @@ -29,7 +34,7 @@ jobs: - name: Setup uses: actions/setup-node@v3 with: - node-version: 18 + node-version: ${{ matrix.node_version }} registry-url: https://registry.npmjs.org/ cache: 'pnpm' - run: pnpm --filter '@web3-storage/w3up-client...' install diff --git a/packages/upload-client/src/car.js b/packages/upload-client/src/car.js index 2f76b1fce..e477bcea9 100644 --- a/packages/upload-client/src/car.js +++ b/packages/upload-client/src/car.js @@ -42,10 +42,20 @@ export class BlockStream extends ReadableStream { let blocksPromise = null const getBlocksIterable = () => { if (blocksPromise) return blocksPromise + // FIXME: remove when resolved: https://github.com/nodejs/node/issues/48916 + /* c8 ignore next 10 */ + if (parseInt(globalThis.process?.versions?.node) > 18) { + blocksPromise = (async () => { + // @ts-expect-error + const bytes = await car.arrayBuffer() + return CarBlockIterator.fromBytes(new Uint8Array(bytes)) + })() + return blocksPromise + } blocksPromise = CarBlockIterator.fromIterable(toIterable(car.stream())) return blocksPromise } - + /** @type {AsyncIterator?} */ let iterator = null super({ @@ -77,11 +87,11 @@ export class BlockStream extends ReadableStream { * @param {{ getReader: () => ReadableStreamDefaultReader } | AsyncIterable} stream * @returns {AsyncIterable} */ +/* c8 ignore next 16 */ function toIterable(stream) { return Symbol.asyncIterator in stream ? stream - : /* c8 ignore next 12 */ - (async function* () { + : (async function* () { const reader = stream.getReader() try { while (true) { From 266bd97878dca804750200341942086952c63e2a Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Tue, 25 Jul 2023 11:55:56 +0100 Subject: [PATCH 2/2] chore: remove whitespace --- packages/upload-client/src/car.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/upload-client/src/car.js b/packages/upload-client/src/car.js index e477bcea9..2749da4ee 100644 --- a/packages/upload-client/src/car.js +++ b/packages/upload-client/src/car.js @@ -55,7 +55,7 @@ export class BlockStream extends ReadableStream { blocksPromise = CarBlockIterator.fromIterable(toIterable(car.stream())) return blocksPromise } - + /** @type {AsyncIterator?} */ let iterator = null super({