{"id":25800,"library":"js-to-sh","title":"js-to-sh","description":"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.","status":"active","version":"1.2.1","language":"javascript","source_language":"en","source_url":"https://github.com/Ashu11-A/Transpiler-JS-Shell","tags":["javascript","transpiler","transpiler-js","transpilers","builder","shellscript","js-to-sh","ast","typescript"],"install":[{"cmd":"npm install js-to-sh","lang":"bash","label":"npm"},{"cmd":"yarn add js-to-sh","lang":"bash","label":"yarn"},{"cmd":"pnpm add js-to-sh","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Requires Node.js >=20 for runtime execution and file system access.","package":"node","optional":false}],"imports":[{"note":"ESM recommended; CommonJS also works but is not recommended by the package.","wrong":"const { Transpiler } = require('js-to-sh')","symbol":"Transpiler","correct":"import { Transpiler } from 'js-to-sh'"},{"note":"Global helper functions (isCommand, isDir, etc.) are added to the global scope via side-effect import; they are not exported as named exports.","wrong":"import { isCommand } from 'js-to-sh'","symbol":"global side-effect","correct":"import 'js-to-sh'"},{"note":"TypeScript types are included; use type import for type-only usage.","wrong":"","symbol":"Transpiler type","correct":"import type { Transpiler } from 'js-to-sh'"}],"quickstart":{"code":"// File: test.js\nfunction add(a, b) {\n  return a + b;\n}\nconsole.log(add(1, 2));\n\n// Terminal:\n// npx js-to-sh -f test.js -o test.sh\n","lang":"typescript","description":"This shows basic transpilation of a JavaScript file with a function and console.log into a bash script using CLI."},"warnings":[{"fix":"Test generated scripts thoroughly. Contribute to fix unsupported features.","message":"Package is experimental; complex JS features (classes, async/await, modules) may produce incorrect or incomplete shell scripts.","severity":"gotcha","affected_versions":">=0"},{"fix":"Use `import 'js-to-sh'` or `require('js-to-sh')` once to inject globals.","message":"Global helper functions (isCommand, isDir, etc.) are only available after a side-effect import. They are not exported as named exports.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Switch to ESM imports: `import { Transpiler } from 'js-to-sh'`.","message":"CommonJS require is not recommended by the package; preferring ESM imports.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Upgrade Node.js to version 20 or higher.","message":"CLI requires Node.js >=20. Older Node versions will fail to run.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Rewrite code to avoid ?. and ?? operators, or manually handle in output script.","cause":"Using optional chaining or nullish coalescing which is not supported by the transpiler.","error":"SyntaxError: Unexpected token '.'"},{"fix":"Add `import 'js-to-sh'` at the top of your entry file.","cause":"Forgot to import the side-effect module to inject global helper functions.","error":"TypeError: isCommand is not defined"},{"fix":"Run `npm install js-to-sh` (or `npm install -g js-to-sh` for CLI usage).","cause":"Package not installed globally or locally.","error":"Error: Cannot find module 'js-to-sh'"},{"fix":"Review generated .sh file; simplify original JavaScript to avoid complex constructs.","cause":"Transpiled script contains invalid shell syntax due to unsupported JS feature.","error":"bash: syntax error near unexpected token `('"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}