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

Fallback for Process.fork not being supported on Windows #221

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/hanami/cli/commands/app/assets/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module App
module Assets
# Base class for assets commands.
#
# Finds slices with assets present (anything in an `assets/` dir), then forks a child
# Finds slices with assets present (anything in an `assets/` dir), then forks or spawns a child
# process for each slice to run the assets command (`config/assets.js`) for the slice.
#
# Prefers the slice's own `config/assets.js` if present, otherwise falls back to the
Expand Down Expand Up @@ -85,6 +85,13 @@ def fork_child_assets_command(slice)
Process.fork do
cmd, *args = assets_command(slice)
system_call.call(cmd, *args, out_prefix: "[#{slice.slice_name}] ")
# Handle Process.fork not being implemented on non-POSIX OS's
# by only spawning a child process of the main process
rescue NotImplementedError
Thread.new do
cmd, *args = assets_command(slice)
system_call.call(cmd, *args, out_prefix: "[#{slice.slice_name}] ")
end
rescue Interrupt
# When this has been interrupted (by the Signal.trap handler in #call), catch the
# interrupt and exit cleanly, without showing the default full backtrace.
Expand Down
2 changes: 2 additions & 0 deletions lib/hanami/cli/generators/gem/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def generate_app(app, context) # rubocop:disable Metrics/AbcSize
fs.write("bin/dev", file("dev"))
fs.chmod("bin/dev", 0o755)

fs.write("bin/dev.bat", file("dev.bat")) if ::Gem.win_platform?

fs.write("config/app.rb", t("app.erb", context))
fs.write("config/settings.rb", t("settings.erb", context))
fs.write("config/routes.rb", t("routes.erb", context))
Expand Down
1 change: 1 addition & 0 deletions lib/hanami/cli/generators/gem/app/dev.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@bash.exe "%~dpn0" %*