Skip to content
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

replace call to shellwords with a call to system passing an array #4

Merged
merged 1 commit into from
Dec 26, 2021

Conversation

rubys
Copy link
Owner

@rubys rubys commented Dec 25, 2021

Shellwords is not compatible with Windows.

While --help works, other common esbuild options do not, for example:

Shellwords.escape('--loader=ts')
=> "--loader\\=ts"

The most obvious fix, namely calling exec with an array of arguments curiously fails on windows with an error of the executable not being found.

Surprisingly, the exact same invocation using system instead of exec works.

@rubys rubys requested a review from flavorjones December 25, 2021 23:07
Copy link
Collaborator

@flavorjones flavorjones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL that this pattern doesn't work on Windows! This PR's code is simpler and easier to read.

I have a slight preference for exec rather than system (they both work with a splat of arguments) to avoid an additional process being created, but that's not a terribly good reason and in a development environment it's unlikely to make much difference either way.

@rubys
Copy link
Owner Author

rubys commented Dec 26, 2021

If it becomes important later, we can use os.windows? and use exec on all non-windows platforms.

I'm still puzzled why I couldn't get exec to work on Windows.

@rubys rubys merged commit 2c18177 into main Dec 26, 2021
@rubys rubys deleted the avoid_shellwords branch December 26, 2021 14:54
flavorjones added a commit to rails/tailwindcss-rails that referenced this pull request Sep 3, 2022
Note that this is a pretty heavy refactoring, where code was moved
from `exe/tailwindcss` to `lib/tailwindcss/commands.rb` where we can
more easily run unit tests on it.

Note also that we no longer use Shellwords to build command strings, a
library which does not generate correct strings on Windows
platforms. Instead we consistently use arrays of command arguments,
which can be passed to `exec` or `system` however we see fit.

The wrapper script conditionally uses `system` on windows platforms
because `exec` can't find the executable (see related issue at
rubys/sprockets-esbuild#4).

Finally, note that the rake tasks no longer use the `exe/tailwindcss`
wrapper script, and instead use the binary executable directly. We can
reverse this decision if we ever decide to support manually-installed
tailwindcss somewhere on the $PATH; but because previously the rake
tasks hardcoded the path/to/exe/tailwindcss, we're not introducing any
new constraints by skipping the wrapper.
anderscain63 added a commit to anderscain63/tailwindcss-rails that referenced this pull request Dec 20, 2022
Note that this is a pretty heavy refactoring, where code was moved
from `exe/tailwindcss` to `lib/tailwindcss/commands.rb` where we can
more easily run unit tests on it.

Note also that we no longer use Shellwords to build command strings, a
library which does not generate correct strings on Windows
platforms. Instead we consistently use arrays of command arguments,
which can be passed to `exec` or `system` however we see fit.

The wrapper script conditionally uses `system` on windows platforms
because `exec` can't find the executable (see related issue at
rubys/sprockets-esbuild#4).

Finally, note that the rake tasks no longer use the `exe/tailwindcss`
wrapper script, and instead use the binary executable directly. We can
reverse this decision if we ever decide to support manually-installed
tailwindcss somewhere on the $PATH; but because previously the rake
tasks hardcoded the path/to/exe/tailwindcss, we're not introducing any
new constraints by skipping the wrapper.
titan2gman added a commit to titan2gman/tailwindcss-rails that referenced this pull request Dec 27, 2022
Note that this is a pretty heavy refactoring, where code was moved
from `exe/tailwindcss` to `lib/tailwindcss/commands.rb` where we can
more easily run unit tests on it.

Note also that we no longer use Shellwords to build command strings, a
library which does not generate correct strings on Windows
platforms. Instead we consistently use arrays of command arguments,
which can be passed to `exec` or `system` however we see fit.

The wrapper script conditionally uses `system` on windows platforms
because `exec` can't find the executable (see related issue at
rubys/sprockets-esbuild#4).

Finally, note that the rake tasks no longer use the `exe/tailwindcss`
wrapper script, and instead use the binary executable directly. We can
reverse this decision if we ever decide to support manually-installed
tailwindcss somewhere on the $PATH; but because previously the rake
tasks hardcoded the path/to/exe/tailwindcss, we're not introducing any
new constraints by skipping the wrapper.
smartech7 pushed a commit to smartech7/rails-tailwind-css that referenced this pull request Aug 4, 2023
Note that this is a pretty heavy refactoring, where code was moved
from `exe/tailwindcss` to `lib/tailwindcss/commands.rb` where we can
more easily run unit tests on it.

Note also that we no longer use Shellwords to build command strings, a
library which does not generate correct strings on Windows
platforms. Instead we consistently use arrays of command arguments,
which can be passed to `exec` or `system` however we see fit.

The wrapper script conditionally uses `system` on windows platforms
because `exec` can't find the executable (see related issue at
rubys/sprockets-esbuild#4).

Finally, note that the rake tasks no longer use the `exe/tailwindcss`
wrapper script, and instead use the binary executable directly. We can
reverse this decision if we ever decide to support manually-installed
tailwindcss somewhere on the $PATH; but because previously the rake
tasks hardcoded the path/to/exe/tailwindcss, we're not introducing any
new constraints by skipping the wrapper.
XLoopLion added a commit to XLoopLion/tailwindcss-rails that referenced this pull request Jun 12, 2024
Note that this is a pretty heavy refactoring, where code was moved
from `exe/tailwindcss` to `lib/tailwindcss/commands.rb` where we can
more easily run unit tests on it.

Note also that we no longer use Shellwords to build command strings, a
library which does not generate correct strings on Windows
platforms. Instead we consistently use arrays of command arguments,
which can be passed to `exec` or `system` however we see fit.

The wrapper script conditionally uses `system` on windows platforms
because `exec` can't find the executable (see related issue at
rubys/sprockets-esbuild#4).

Finally, note that the rake tasks no longer use the `exe/tailwindcss`
wrapper script, and instead use the binary executable directly. We can
reverse this decision if we ever decide to support manually-installed
tailwindcss somewhere on the $PATH; but because previously the rake
tasks hardcoded the path/to/exe/tailwindcss, we're not introducing any
new constraints by skipping the wrapper.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants