Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
opal-hot-reloader is a hot reloader for Opal. It has built in react.rb support and can be extended to support an arbitrary hook to be run after code is evaluted. It watches directories specified and when a file is modified it pushes the change via websocket to the client. opal-hot-reloader reloader will reload the following without reloading the whole page and destroying any state the page has.
Add this line to your application's Gemfile:
gem 'opal_hot_reloader'
And then execute:
$ bundle
Or install it yourself as:
$ gem install opal_hot_reloader
After adding gem "opal_hot_loader"
to your gemfile, you must start the server-side part. This will allow websocket connections, and whenever a file is changed it will send it via the socket to listening clients.
To start the server-side of the hotloader:
opal-hot-reloader -p 25222 -d dir1,dir2,dir3
Usage: opal-hot-reloader [options]
-p, --port [INTEGER] port to run on, defaults to 25222
-d, --directories x,y,z comma separated directories to watch
For a react.rb Rails app, opal-hot-reloader automatically includes app/assets/javascripts,app/views/components if they exist
Example adding 2 directories
opal-hot-reloader -d app/js,app/client/components
You may consider using foreman and starting the Rails server and hot reloader at the same time. If you are doing react.rb development w/Rails, you may already be doing so with the Rails server and webpack.
Require in an opal file (for opal-rails apps application.js.rb is a good place) and start listening for changes:
OpalHotReloader.listen() used to take a 2nd Boolean parameter to signify a reactrb app. This is deprecated and no longer needed.
require 'opal_hot_reloader'
# @param port [Integer] opal hot reloader port to connect to. Defaults to 25222 to match opal-hot-loader default
OpalHotReloader.listen(25222)
If you are using the default port then you can just call:
OpalHotReloader.listen
By default, if there is an error hot loading code, opal_hot_reloader will present an alert of the error. The following options can be used to turn the alerts on and off:
OpalHotReloader.alerts_on! # turns on alerts
OpalHotReloader.alerts_off! # turns off alerts
This will open up a websocket from the client to the server on the given port. The server-side should already be running.
Enjoy!
One way to run this only in development on Rails is to change your application.js.rb to application.js.rb.erb and add this to the bottom of the file
<% if Rails.env.development? %>
require 'opal_hot_reloader'
OpalHotReloader.listen
<% end %>
Some of you might be asking? Why do this, isn't this reinventing the wheel by programs like webpack, etc.? I should mention that reinventing the wheel seems happens all the time in the Javascript world.
Yes and no. opal-hot-reloader is an "All Ruby(Opal)", self contained system, so if you're doing any kind of Opal frontend/Ruby backend webserver type of project, you will be able to just drop in opal-hot-reloader and it will work out of the box without having install/configure webpack or similar.
I believe it will be most advantageous for Opal to be able to straddle a hybrid approach where:
While I do favor moving as much Javascript to webpack, following suit to React.js's lead, I see an "all webpack solution" for Opal apps being only one of a few permutations, and not particularly appealing to most Rails programmers - who I think is the largest demographic likely to want to do Opal programming.
While we wait for the other approaches to evolve and get implemented this solution is here and works now. It works with an "All Ruby" system, it works with a Rails app that is using webpack to provide react.js components to react.rb.
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/fkchang/opal_hot_reloader.
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that opal_hot_reloader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.