Skip to content

Commit c5907a4

Browse files
committed
Generate playground command list from coreutils feat_wasm
Previously the list of WASM-bundled utilities was hardcoded in wasm-terminal.js and playground.md, which drifted from the actual feat_wasm feature in coreutils/Cargo.toml (e.g. dd, tty, yes were missing). The website workflow now parses feat_wasm at build time and emits static/wasm/commands.js, which the terminal prefers over its built-in fallback list.
1 parent 7ef8b73 commit c5907a4

3 files changed

Lines changed: 20 additions & 4 deletions

File tree

.github/workflows/website.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ jobs:
138138
echo "const WASM_LOCALES = [$(echo "$locales" | sed 's/[^,]*/\"&\"/g')];" \
139139
> ../uutils.github.io/static/wasm/locales.js
140140
echo "Available locales: $locales"
141+
# Generate the list of available commands from the feat_wasm feature
142+
# in Cargo.toml so the playground stays in sync with the WASM build.
143+
commands=$(sed -n '/^feat_wasm = \[/,/^\]/p' Cargo.toml \
144+
| grep -oE '"[a-zA-Z0-9_]+"' | tr -d '"' \
145+
| sort -u | paste -sd, -)
146+
echo "const WASM_COMMANDS = [$(echo "$commands" | sed 's/[^,]*/\"&\"/g')];" \
147+
> ../uutils.github.io/static/wasm/commands.js
148+
echo "Available commands: $commands"
141149
# Record the coreutils commit used to build the WASM binary
142150
commit_hash=$(git rev-parse HEAD)
143151
commit_short=$(git rev-parse --short HEAD)

content/playground.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ template = "page.html"
1919

2020
<script src="/wasm/locales.js" defer></script>
2121
<script src="/wasm/version.js" defer></script>
22+
<script src="/wasm/commands.js" defer></script>
2223
<script src="/js/wasm-terminal.js" defer></script>
2324
<script defer>
2425
document.addEventListener("DOMContentLoaded", function() {
@@ -104,7 +105,7 @@ Multiple commands can be separated by newlines (`%0A` in the URL):
104105
The following commands run as **real Rust coreutils compiled to WebAssembly**:
105106

106107
`arch` `b2sum` `base32` `base64` `basenc` `basename` `cat` `cksum`
107-
`comm` `cp` `csplit` `cut` `date` `dir` `dircolors` `dirname`
108+
`comm` `cp` `csplit` `cut` `date` `dd` `dir` `dircolors` `dirname`
108109
`echo` `expand` `expr` `factor` `false` `fmt` `fold` `head`
109110
`join` `link` `ln` `ls` `md5sum` `mkdir` `mv` `nl` `nproc` `numfmt`
110111
`od` `paste` `pathchk` `printenv` `printf` `pr` `ptx` `pwd`

static/js/wasm-terminal.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@ const SAMPLE_FILES = {
3333
"words.txt": "hello world\nfoo bar baz\nthe quick brown fox\njumps over the lazy dog\n",
3434
};
3535

36-
// Commands available in the feat_wasm build
37-
const AVAILABLE_COMMANDS = [
36+
// Commands available in the feat_wasm build.
37+
// The workflow generates /wasm/commands.js from coreutils' Cargo.toml feat_wasm
38+
// list and exposes it as `WASM_COMMANDS`. The hardcoded list below is a fallback
39+
// for local dev or when the generated file isn't available.
40+
const FALLBACK_COMMANDS = [
3841
"arch", "b2sum", "base32", "base64", "basenc", "basename", "cat", "cksum",
39-
"comm", "cp", "csplit", "cut", "date", "dir", "dircolors", "dirname",
42+
"comm", "cp", "csplit", "cut", "date", "dd", "dir", "dircolors", "dirname",
4043
"echo", "expand", "expr", "factor", "false", "fmt", "fold", "head",
4144
"join", "link", "ln", "ls", "md5sum", "mkdir", "mv", "nl", "numfmt",
4245
"nproc", "od", "paste", "pathchk", "printenv", "printf", "pr", "ptx", "pwd",
@@ -46,6 +49,10 @@ const AVAILABLE_COMMANDS = [
4649
"shred", "shuf", "sleep", "sum", "tee", "true", "truncate",
4750
"uname", "unexpand", "uniq", "unlink", "vdir", "wc",
4851
];
52+
const AVAILABLE_COMMANDS =
53+
(typeof WASM_COMMANDS !== "undefined" && Array.isArray(WASM_COMMANDS) && WASM_COMMANDS.length > 0)
54+
? WASM_COMMANDS
55+
: FALLBACK_COMMANDS;
4956

5057
// Shortcut mappings for locale command (e.g. "fr" -> "fr-FR")
5158
const LOCALE_SHORTCUTS = {

0 commit comments

Comments
 (0)