Comment by throwaway290

Comment by throwaway290 4 days ago

7 replies

> I have definitelly crossed the line where writing a script makes sense

...and that was also the one concrete example where it makes sense to have extra dependency and abstraction layer on top of a shell script:)

say you know TS and even if you walk back to where $ is defined, can you tell immediately why $`ls {dir}` gets executed and not just logged?

supernes 4 days ago

You can make it more explicit by renaming the import to something like "shell_exec". Tagged templates are already pretty common in TS projects for things like gql or sql queries.

  • throwaway290 4 days ago

    tagged template does not cause execution of given string. tagged template is just a function and in this case it's simply a proxy for console.log() which also doesn't cause execution of given string.

    so how does it get executed?

    unless it was just an example and you are supposed to switch in $ from some third party library... which is another dependency in addition to deno... and which can be shai-huluded anytime or you may be offline and cannot install it when you run the script?

    • tracker1 3 days ago

      I've either imported or created a sql template function that does exactly that... takes the parameters, forms a parameterized query against the database and returns the results back. Easy enough to add Typescript types that should match your expected results (though not enforced/checked) still helpful.

      • throwaway290 a day ago

        I know. My point was that the original text of the article gave no explanation next to that example as to how $ executes given string. So either there is some magic or the example was wrong. Author added explanation after my comment

    • supernes 4 days ago

      Yes, it's another dependency (dax). The example with console.log is just that, an example. Standard dependency management practices apply, e.g. pinning a version/commit hash.