Skip to content

fix(install): replace bash-specific syntax with cross-platform Node.js#95

Merged
pioug merged 1 commit intonfroidure:mainfrom
YevheniiKotyrlo:fix/cross-platform-install-script
Feb 19, 2026
Merged

fix(install): replace bash-specific syntax with cross-platform Node.js#95
pioug merged 1 commit intonfroidure:mainfrom
YevheniiKotyrlo:fix/cross-platform-install-script

Conversation

@YevheniiKotyrlo
Copy link
Contributor

@YevheniiKotyrlo YevheniiKotyrlo commented Jan 12, 2026

Summary

Replace bash-specific install script with a cross-platform Node.js script in a separate file, following the same pattern used by sharp and npm ecosystem best practices for portable package scripts.

Problem

The current install script uses bash subshell syntax:

((node-gyp configure && node-gyp build) > builderror.log) || (exit 0)

This syntax fails silently or errors in multiple environments:

1. Bun Package Manager (Windows)

oven-sh/bun#11124 - Bun's shell doesn't support subshells with redirections:

error: Subshells with redirections are currently not supported.

2. Alpine Linux / Docker (BusyBox ash)

Alpine's default shell is ash, not bash. The ((...)) subshell syntax causes:

syntax error: unexpected "("

This affects Docker deployments using node:alpine images.

3. Windows (cmd.exe / PowerShell)

Windows doesn't have bash. Complex bash syntax fails in cmd.exe, the default npm script shell on Windows.

4. Related ttf2woff2 Issues

Solution

Move the install logic to a dedicated install/try-build.js script:

import { execSync } from 'node:child_process';
import { writeFileSync } from 'node:fs';

let output = '';

try {
  output = execSync('node-gyp configure && node-gyp build 2>&1', {
    encoding: 'utf8',
  });
} catch (err) {
  output = err.stdout || err.stderr || err.message || '';
}

writeFileSync('builderror.log', output);
"install": "node install/try-build.js"

Why this works everywhere

Node.js execSync delegates to the platform's native shell:

  • Unix: /bin/sh -c
  • Windows: cmd.exe /d /s /c

Both shells support && and 2>&1. The complexity is handled by Node.js, not the package manager's shell.

Changes

  • install/try-build.js — new file with the build logic
  • package.json — updated install script + added install to files array

Comparison

Aspect Original New
Bash
Zsh
Windows cmd.exe
PowerShell
Alpine ash
Bun shell
Captures stdout
Captures stderr
Silent failure
builderror.log

Testing

Verified on:

  • ✅ Windows 11 + npm (node-gyp native build succeeds)
  • ✅ Linux/WSL + npm (node-gyp native build succeeds)
  • builderror.log created on both success and failure
  • ✅ Silent failure preserved (exit code 0, JS/WASM fallback works)
  • ✅ All existing tests pass (6/6)
  • npm pack --dry-run confirms install/try-build.js included in tarball

No breaking changes. The behavior is identical — only the implementation is more portable and readable.

@YevheniiKotyrlo
Copy link
Contributor Author

Hi @nfroidure! Just a friendly ping on this PR. It replaces the bash-specific install script with a cross-platform Node.js equivalent, fixing install failures on Windows, Bun, Alpine Docker, and CI environments. Would you have a chance to take a look when you get a moment? Happy to adjust anything. Thanks!

@pioug
Copy link
Collaborator

pioug commented Feb 19, 2026

@YevheniiKotyrlo What about a separate script file like in sharp? https://github.com/lovell/sharp/blob/main/package.json#L96

@YevheniiKotyrlo YevheniiKotyrlo force-pushed the fix/cross-platform-install-script branch from 8f01f8d to deeb2c4 Compare February 19, 2026 12:46
@YevheniiKotyrlo
Copy link
Contributor Author

Good suggestion — updated the PR to use a separate install/try-build.js file, similar to how sharp handles it. Also added install to the files array so it ships with the npm tarball.

@YevheniiKotyrlo YevheniiKotyrlo force-pushed the fix/cross-platform-install-script branch from deeb2c4 to 91befd2 Compare February 19, 2026 12:55
@pioug pioug merged commit 9ec6f4f into nfroidure:main Feb 19, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants