Skip to content

The npm module should work on CodeSandbox #864

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rob-myers opened this issue May 22, 2022 · 8 comments
Closed

The npm module should work on CodeSandbox #864

rob-myers opened this issue May 22, 2022 · 8 comments

Comments

@rob-myers
Copy link

rob-myers commented May 22, 2022

I have a demo using [email protected] working on CodeSandbox.

But I had to comment out two similar lines:

$r = os.$init(); /* */ $s = 5; case 5: if($c) { $c = false; $r = $r.$blk(); } if ($r && $r.$blk !== undefined) { break s; }
// ...
$r = os.$init(); /* */ $s = 7; case 7: if($c) { $c = false; $r = $r.$blk(); } if ($r && $r.$blk !== undefined) { break s; }

Otherwise, I see runtime error: makeslice: len out of range.
It is reproducible by switching the imports back in CodeSandbox link:

import Sh, { syntax } from "@rob-myers/mvdan-sh";
// import Sh, { syntax } from "mvdan-sh";

The error occurs simply by importing the module, and also occurs for [email protected].

@mvdan
Copy link
Owner

mvdan commented May 23, 2022

I wonder if this is a GopherJS bug, because we don't really control what JS code gets produced when transpiling.

Also, if WASM is an option, perhaps try https://github.com/rx-ts/sh-syntax. It does not use GopherJS, so it potentially sidesteps this bug. cc @JounQin

@JounQin
Copy link
Contributor

JounQin commented May 23, 2022

It seems the reproduction is using parser.Interactive inside, which is not available in sh-syntax yet.

@JounQin
Copy link
Contributor

JounQin commented May 23, 2022

image

This is because CodeSandbox is polyfillng globalThis.process unexpectedly, I think you should raise an issue for CodeSandbox instead.

@JounQin
Copy link
Contributor

JounQin commented May 24, 2022

Workaround: delete window.process before import 'mvdan-sh'

See https://codesandbox.io/s/tty-demo-1-forked-d6xg0p?file=/src/sh/parse/parse.service.ts

@JounQin
Copy link
Contributor

JounQin commented May 24, 2022

Also, there is also a fix in gopherjs gopherjs/gopherjs#1117 which has not been released.

@rob-myers
Copy link
Author

@JounQin thanks for looking into it. Great that there's a GopherJS fix in the works already.
I will try building using go get github.com/gopherjs/gopherjs@master and see if it works.

Generally speaking, it would be nice to have a bunch of CodeSandbox links demoing mvdan-sh on the web.
The example I provided is too complex, I'm thinking e.g. enter shell code and display AST etc.
Do such web-based examples exist anywhere at present?

@rob-myers
Copy link
Author

I want to use version 0.5.0, so I am using an old commit and go v1.2.17. Sadly, changing the build to go get github.com/gopherjs/gopherjs@master yields the following error:

package github.com/gopherjs/gopherjs@master: can only use path@version syntax with 'go get'

I guess I'll just wait for a fix.

@mvdan
Copy link
Owner

mvdan commented Apr 10, 2025

Apologies for the slowness here. The reality is that I don't have the time to properly maintain a JS port of this shell library, or to learn enough JS to be a good steward for it. Moreover, I built mvdan-sh on top of GopherJS, which is still somewhat maintained, but is struggling to support the latest versions of Go - which this library uses.

The good news is that someone else built a new JS library on top op of this one, which is actively maintained and uses WASM instead of GopherJS, seemingly bringing a speed-up of over 4x: https://github.com/un-ts/sh-syntax

I'd suggest that you give that a try, and re-raise any issues on that repo if they are still relevant. For now, given that I don't intend to further develop mvdan-sh, I am closing existing issues and deleting the code, but leaving notes in the README and the npm package's page so that any users get pointed in the right direction.

For more, see #1145.

Thanks for understanding :)

@mvdan mvdan closed this as not planned Won't fix, can't repro, duplicate, stale Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants