Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ jobs:
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies (Node)
if: matrix.runtime == 'node'
working-directory: js
run: npm ci

- name: Test Node.js compatibility
if: matrix.runtime == 'node'
run: |
Expand All @@ -185,6 +190,7 @@ jobs:
process.exit(1);
});
"
node --test js/tests/node-terminal-artifacts.mjs

release:
name: Release JavaScript package
Expand Down
6 changes: 6 additions & 0 deletions js/.changeset/fuzzy-gifs-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'command-stream': patch
---

Fix GIF terminal artifact rendering on Node.js by supporting the CommonJS
default export exposed by `gifenc`.
9 changes: 6 additions & 3 deletions js/src/terminal-artifacts.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,12 @@ const renderRecordingSvg = ({ frames, options, font }) => {
};

const renderGif = async ({ frames, options, font }) => {
const [{ Resvg }, { GIFEncoder, applyPalette, quantize }] = await Promise.all(
[import('@resvg/resvg-js'), import('gifenc')]
);
const [{ Resvg }, gifencModule] = await Promise.all([
import('@resvg/resvg-js'),
import('gifenc'),
]);
const gifenc = gifencModule.GIFEncoder ? gifencModule : gifencModule.default;
const { GIFEncoder, applyPalette, quantize } = gifenc;
const { width, height } = dimensions(frames, options);
const { times } = frameTimes(frames, options.idleTimeLimit);
const sheet = svgShell({
Expand Down
33 changes: 33 additions & 0 deletions js/tests/node-terminal-artifacts.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import assert from 'node:assert/strict';
import { mkdtemp, readFile, rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { test } from 'node:test';

import { writeTerminalArtifacts } from '../src/terminal-artifacts.mjs';

test('writes GIF terminal artifacts in Node.js', async (context) => {
const directory = await mkdtemp(join(tmpdir(), 'command-stream-node-gif-'));
context.after(() => rm(directory, { force: true, recursive: true }));

await writeTerminalArtifacts({
directory,
frames: [
{
time: 0,
cols: 1,
rows: 1,
lines: [''],
cells: [[]],
},
],
transcript: '',
asciicast: {
header: { version: 2, width: 1, height: 1, timestamp: 0, env: {} },
events: [],
},
});

const gif = await readFile(join(directory, 'recording.gif'));
assert.equal(gif.subarray(0, 6).toString(), 'GIF89a');
});