Registry / devops / js-to-sh

js-to-sh

JSON →
library1.2.1jsnpmunverified

js-to-sh (v1.2.1) is a JavaScript-to-ShellScript transpiler that uses abstract syntax trees (AST) to convert JavaScript syntax into bash scripts. It is experimental and unstable, with limited support for complex JavaScript features (classes are converted to functions but not fully implemented). The library provides a CLI tool and a programmatic API for transpiling .js/.ts files into .sh files. It includes built-in global helper functions for shellscript behaviors (file checks, command existence, etc.). The project is under active development with a small community, and it depends on Node.js >=20. Key differentiators: direct AST-based conversion, global variable injection for shell-style checks, and both ESM and CommonJS support.

npm install js-to-sh
INSTALL
IMPORT
SIG · JS-TO-SH
J
js-to-sh
devopsjavascriptv1.2.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Transpiler
import { Transpiler } from 'js-to-sh'
const { Transpiler } = require('js-to-sh')
ESM recommended; CommonJS also works but is not recommended by the package.
global side-effect
import 'js-to-sh'
import { isCommand } from 'js-to-sh'
Global helper functions (isCommand, isDir, etc.) are added to the global scope via side-effect import; they are not exported as named exports.
Transpiler type
import type { Transpiler } from 'js-to-sh'
TypeScript types are included; use type import for type-only usage.

This shows basic transpilation of a JavaScript file with a function and console.log into a bash script using CLI.

// File: test.js function add(a, b) { return a + b; } console.log(add(1, 2)); // Terminal: // npx js-to-sh -f test.js -o test.sh
js-to-sh --version
Debug
Known issues
gotchaPackage is experimental; complex JS features (classes, async/await, modules) may produce incorrect or incomplete shell scripts.
fix
Test generated scripts thoroughly. Contribute to fix unsupported features.
affects: >=0
breakingGlobal helper functions (isCommand, isDir, etc.) are only available after a side-effect import. They are not exported as named exports.
fix
Use `import 'js-to-sh'` or `require('js-to-sh')` once to inject globals.
affects: >=1.0.0
deprecatedCommonJS require is not recommended by the package; preferring ESM imports.
fix
Switch to ESM imports: `import { Transpiler } from 'js-to-sh'`.
affects: >=1.0.0
gotchaCLI requires Node.js >=20. Older Node versions will fail to run.
fix
Upgrade Node.js to version 20 or higher.
affects: >=1.0.0
Errors
Common errors & fixes
SyntaxError: Unexpected token '.'
Using optional chaining or nullish coalescing which is not supported by the transpiler.
fix
Rewrite code to avoid ?. and ?? operators, or manually handle in output script.
TypeError: isCommand is not defined
Forgot to import the side-effect module to inject global helper functions.
fix
Add `import 'js-to-sh'` at the top of your entry file.
Error: Cannot find module 'js-to-sh'
Package not installed globally or locally.
fix
Run `npm install js-to-sh` (or `npm install -g js-to-sh` for CLI usage).
bash: syntax error near unexpected token `('
Transpiled script contains invalid shell syntax due to unsupported JS feature.
fix
Review generated .sh file; simplify original JavaScript to avoid complex constructs.
Upgrade
Version history
1.2.1latest on npm
Audit
Dependencies
noderequiredRequires Node.js >=20 for runtime execution and file system access.
Agent activity
4 hits · last 30 days
node
4
Resources
js-to-sh — npm install js-to-sh · libregistry