tynanbe / shellout

🐢 A Gleam library for cross-platform shell operations
Apache License 2.0
46 stars 1 forks source link

Gleam 0.26.0 workarounds / maybe deno support #1

Closed inoas closed 1 year ago

inoas commented 1 year ago

https://github.com/inoas/glacier uses shellout and I have had some issues on 0.26.0. One issue should be probably fixed inside gleam compiler, the others probably inside shellout.

inoas commented 1 year ago

My current info is that the files pushed into argv on JS target are to be expected and NodeJS/Deno specific implementation details?!

inoas commented 1 year ago
  1. Erlang specific? .spawn: Could not cd to dimension_x?

    ❯ gleam test --target erlang
     Compiling shellout
      Compiled in 0.00s
       Running shellout_test.main
    .spawn: Could not cd to dimension_x
    ...
    Finished in 0.037 seconds
    4 tests, 0 failures

    same with sudo:

    ❯ sudo gleam test --target erlang
    Password:
     Compiling shellout
      Compiled in 0.00s
       Running shellout_test.main
    .spawn: Could not cd to dimension_x
    ...
    Finished in 0.035 seconds
    4 tests, 0 failures
  2. deno requesting permissions on, I think, echo:

    ❯ gleam test --target javascript --runtime deno
     Compiling shellout
     Compiled in 0.00s
       Running shellout_test.main
    ✅ Granted env access to "PATHEXT".
    ✅ Granted env access to "PATH".
    ⚠️  ┌ Deno requests read access to "/Users/USERNAME_HERE/.asdf/installs/deno/1.
    ✅ Granted read access to "/Users/USERNAME_HERE/.asdf/installs/deno/1.29.4/bin/echo".
    ⚠️  ┌ Deno requests read access to "/Users/USERNAME_HERE/.asdf/installs/deno/1.
    ✅ Granted read access to "/Users/USERNAME_HERE/.asdf/installs/deno/1.29.4/.deno/bin/echo".
    ⚠️  ┌ Deno requests read access to "/Users/USERNAME_HERE/.asdf/installs/gleam/0
    ✅ Granted read access to "/Users/USERNAME_HERE/.asdf/installs/gleam/0.26.1/bin/echo".
    ⚠️  ┌ Deno requests read access to "/usr/local/opt/postgresql@11/bin/
    ✅ Granted read access to "/usr/local/opt/postgresql@11/bin/echo".
    ✅ Granted read access to "/Users/USERNAME_HERE/.asdf/shims/echo".
    ⚠️  ┌ Deno requests read access to "/usr/local/opt/asdf/libexec/bin/e
    ✅ Granted read access to "/usr/local/opt/asdf/libexec/bin/echo".
    ✅ Granted read access to "/usr/local/bin/echo".
    ✅ Granted read access to "/usr/bin/echo".
    ✅ Granted read access to "/bin/echo".
    ✅ Granted read access to "/usr/sbin/echo".
    ✅ Granted read access to "/sbin/echo".
    ✅ Granted read access to "/Library/Apple/usr/bin/echo".
    ✅ Granted read access to "/Users/USERNAME_HERE/.cargo/bin/echo".
    ✅ Granted read access to "/usr/local/sbin/echo".
    ✅ Granted read access to "/Users/USERNAME_HERE/.local/bin/echo".
    ✅ Granted read access to "/Users/USERNAME_HERE/bin/echo".
    ✅ Granted env access to all.
    ✅ Granted read access to <exec_path>.
    ✅ Granted run access to "echo".
    ⚠️  ┌ Deno requests read access to "/Users/USERNAME_HERE/.asdf/installs/deno/1.
    ✅ Granted read access to "/Users/USERNAME_HERE/.asdf/installs/deno/1.29.4/bin".
    ⚠️  ┌ Deno requests read access to "/Users/USERNAME_HERE/.asdf/installs/deno/1.
    ✅ Granted read access to "/Users/USERNAME_HERE/.asdf/installs/deno/1.29.4/.deno/bin".
    ⚠️  ┌ Deno requests read access to "/Users/USERNAME_HERE/.asdf/installs/gleam/0
    ✅ Granted read access to "/Users/USERNAME_HERE/.asdf/installs/gleam/0.26.1/bin".
    ⚠️  ┌ Deno requests read access to "/usr/local/opt/postgresql@11/bin"
    ✅ Granted read access to "/usr/local/opt/postgresql@11/bin".
    ✅ Granted read access to "/Users/USERNAME_HERE/.asdf/shims".
    ✅ Granted read access to "/usr/local/opt/asdf/libexec/bin".
    ✅ Granted read access to "/usr/local/bin".
    ✅ Granted read access to "/usr/bin".
    ✅ Granted read access to "/bin".
    ✅ Granted read access to "/usr/sbin".
    ❯ git commit -m 'remove unnecessary privilege settings that are already given by ./'
    ❯ gleam test --target javascript
     Compiling shellout
     Compiled in 0.00s
       Running shellout_test.main
    ....
    4 tests, 0 failures
    ❯ gleam test --target javascript --runtime deno
     Compiling shellout
     Compiled in 0.00s
       Running shellout_test.main
    ✅ Granted env access to "PATHEXT".
    ✅ Granted env access to "PATH".
    ⚠️  ┌ Deno requests read access to "/Users/USERNAME_HERE/.asdf/installs/deno/1.
    ✅ Granted read access to "/Users/USERNAME_HERE/.asdf/installs/deno/1.29.4/bin/echo".
    ⚠️  ┌ Deno requests read access to "/Users/USERNAME_HERE/.asdf/installs/deno/1.
    ✅ Granted read access to "/Users/USERNAME_HERE/.asdf/installs/deno/1.29.4/.deno/bin/echo".
    ⚠️  ┌ Deno requests read access to "/Users/USERNAME_HERE/.asdf/installs/gleam/0
    ✅ Granted read access to "/Users/USERNAME_HERE/.asdf/installs/gleam/0.26.1/bin/echo".
    ⚠️  ┌ Deno requests read access to "/usr/local/opt/postgresql@11/bin/
    ✅ Granted read access to "/usr/local/opt/postgresql@11/bin/echo".
    ✅ Granted read access to "/Users/USERNAME_HERE/.asdf/shims/echo".
    ⚠️  ┌ Deno requests read access to "/usr/local/opt/asdf/libexec/bin/e
    ✅ Granted read access to "/usr/local/opt/asdf/libexec/bin/echo".
    ✅ Granted read access to "/usr/local/bin/echo".
    ✅ Granted read access to "/usr/bin/echo".
    ✅ Granted read access to "/bin/echo".
    ✅ Granted read access to "/usr/sbin/echo".
    ✅ Granted read access to "/sbin/echo".
    ✅ Granted read access to "/Library/Apple/usr/bin/echo".
    ✅ Granted read access to "/Users/USERNAME_HERE/.cargo/bin/echo".
    ✅ Granted read access to "/usr/local/sbin/echo".
    ✅ Granted read access to "/Users/USERNAME_HERE/.local/bin/echo".
    ✅ Granted read access to "/Users/USERNAME_HERE/bin/echo".
    ✅ Granted env access to all.
    ✅ Granted read access to <exec_path>.
    ✅ Granted run access to "echo".
    ⚠️  ┌ Deno requests read access to "/Users/USERNAME_HERE/.asdf/installs/deno/1.
    ✅ Granted read access to "/Users/USERNAME_HERE/.asdf/installs/deno/1.29.4/bin".
    ⚠️  ┌ Deno requests read access to "/Users/USERNAME_HERE/.asdf/installs/deno/1.
    ✅ Granted read access to "/Users/USERNAME_HERE/.asdf/installs/deno/1.29.4/.deno/bin".
    ⚠️  ┌ Deno requests read access to "/Users/USERNAME_HERE/.asdf/installs/gleam/0
    ✅ Granted read access to "/Users/USERNAME_HERE/.asdf/installs/gleam/0.26.1/bin".
    ⚠️  ┌ Deno requests read access to "/usr/local/opt/postgresql@11/bin"
    ✅ Granted read access to "/usr/local/opt/postgresql@11/bin".
    ✅ Granted read access to "/Users/USERNAME_HERE/.asdf/shims".
    ✅ Granted read access to "/usr/local/opt/asdf/libexec/bin".
    ✅ Granted read access to "/usr/local/bin".
    ✅ Granted read access to "/usr/bin".
    ✅ Granted read access to "/bin".
    ✅ Granted read access to "/usr/sbin".
    ✅ Granted read access to "/sbin".
    ✅ Granted read access to "/Library/Apple/usr/bin".
    ✅ Granted read access to "/Users/USERNAME_HERE/.cargo/bin".
    ✅ Granted read access to "/usr/local/sbin".
    ✅ Granted read access to "/Users/USERNAME_HERE/.local/bin".
    ✅ Granted read access to "/Users/USERNAME_HERE/bin".
  3. Different test results for deno than for nodejs:

    ❯ gleam test --target javascript --runtime node
     Compiling shellout
      Compiled in 0.00s
       Running shellout_test.main
    ....
    4 tests, 0 failures
    gleam test --target javascript --runtime deno
    ❌ 
    shellout_test.command_test: Error: 
           Nil
           should equal 
           2
    ..
    4 tests, 1 failures

For 3rd point JS specific issue I have read that it might be due to calling cwd on a non existing directory. Maybe it is related to the 1st point in this issue?

inoas commented 1 year ago

For the last error:

  assert Error(#(status, message)) =
    shellout.command(run: "echo", with: [], in: "dimension_x", opt: [])

... returns: #(Nil, "")

EDIT:

It seems let result = child_process.spawnSync(command, args.toArray(), spawnOpts); crashes:

{
  result: {
    error: Error: spawnSync echo ENOENT
    at __node_internal_captureLargerStackTrace (https://deno.land/std@0.173.0/node/internal/errors.ts:113:11)
    at __node_internal_errnoException (https://deno.land/std@0.173.0/node/internal/errors.ts:194:10)
    at _createSpawnSyncError (https://deno.land/std@0.173.0/node/internal/child_process.ts:696:17)
    at spawnSync (https://deno.land/std@0.173.0/node/internal/child_process.ts:804:22)
    at Module.spawnSync (https://deno.land/std@0.173.0/node/child_process.ts:231:10)
    at os_command (file:///Users/USERNAME_HERE/local-dev/contrib/gleam/shellout/build/dev/javascript/shellout/shellout_ffi.mjs:84:30)
    at file:///Users/USERNAME_HERE/local-dev/contrib/gleam/shellout/build/dev/javascript/shellout/shellout.mjs:310:12
    at Module.command (file:///Users/USERNAME_HERE/local-dev/contrib/gleam/shellout/build/dev/javascript/shellout/shellout.mjs:311:5)
    at Module.command_test (file:///Users/USERNAME_HERE/local-dev/contrib/gleam/shellout/build/dev/javascript/shellout/shellout_test.mjs:97:22)
    at main (file:///Users/USERNAME_HERE/local-dev/contrib/gleam/shellout/build/dev/javascript/gleeunit/gleeunit_ffi.mjs:38:29)
  }
}
tynanbe commented 1 year ago

@inoas, can you rebase on latest main to see if CI will pass?

inoas commented 1 year ago

All issues as described above persist, after merge with latest main.

tynanbe commented 1 year ago

Thank you for your contributions! These issues should all be resolved in v1.1.0 (https://github.com/tynanbe/shellout/commit/4d895e353d6057769baf508ccd19a1a133236fb9).