isorun 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 449f967639023a251a8cfcec98f35e462eb6a7533bc458aac507077edd8bf37f
4
- data.tar.gz: 35847f70f1430dc9c0d03d6aeb333d44fcdeedda5651a6f7d9d102470e135e0f
3
+ metadata.gz: 420234426bc37f5156c255fbc0e458e25379847729ad40b4d2ce7f61c2251ad6
4
+ data.tar.gz: 222c11ca81c54fb7b8cb1a3783b2caa33e1b5bb4d670ed4b8d67620fabb648f8
5
5
  SHA512:
6
- metadata.gz: f4f282c3aa42b7c5ac85343a8c4e3f5299accb5b5d82371e7f406a6e4601c9b5b89e1ba0468afc3b19d187a854ff73b581df070ab431b872329d660d4dca3458
7
- data.tar.gz: 05f836db2859335c73eb476b913cc5ccdfe3002da9b866479ad7f9a629e994e02e46d1c64625651e3836b07a34ffd065e69d80bd8ed198f4d75a9e4edc9f9873
6
+ metadata.gz: acee923f0800c7d0c47e77d6f61a4fed10d32d7e715145af1ecd8d1dfa25c47e1e58e24bcc65e886fd725a53d8f0ca3fab68b4e7ec91e4cf1ba83c1a8ea07b64
7
+ data.tar.gz: 5988611ab658bf3345b37a1fb0516e5c236f14bbc773ce1c364759b185ec1f1207c4bba3d448b52f93e2852834f4ad6cc4b6291ff00f3e651ac293cc5ba01749
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Isorun
4
+ module ViteAppHelper
5
+ # The isorun_vite_app helper is the most convenient way to server-side
6
+ # render a JavaScript application built with vite, including state
7
+ # extraction and automatic rehydration. The helper tries to render the
8
+ # application and will also inject the client-side code immediately after
9
+ # the rendered result.
10
+ #
11
+ # @example Renders a JavaScript application
12
+ # <html>
13
+ # <body>
14
+ # <%= isorun_vite_app("my_app") %>
15
+ # </body>
16
+ # </html>
17
+ #
18
+ # @param id [String] An ID representing both, the asset bundle, and by
19
+ # convention, the target node (e.g. `<div id="my_app">`)
20
+ # @return [String]
21
+ def isorun_vite_app(id) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
22
+ ActiveSupport::Notifications.instrument "start.render.isorun", { ts: Time.current }
23
+
24
+ # if id has a file extension, we extract the extension and reduce the ID
25
+ # to the basename
26
+ extension = (File.extname(id) || ".js").delete_prefix(".")
27
+ id = File.basename(id, ".*")
28
+
29
+ module_path = Isorun.config.module_resolver.call(id)
30
+
31
+ ssr_html = Isorun::Context.create(receiver: Isorun.config.receiver) do |context|
32
+ render_context = { environment: Rails.env.to_s }
33
+ render_function = context.import.from(module_path)
34
+
35
+ if render_function.blank?
36
+ Rails.logger.warn("[ISORUN] the requested app does not exist or " \
37
+ "does not have a server entrypoint. Please " \
38
+ "check if an asset with filename " + "
39
+ `public/vite-ssr/ssr.js` exists.")
40
+ return ""
41
+ end
42
+
43
+ html = render_function.call(render_context)
44
+
45
+ ActiveSupport::Notifications.instrument "finish.render.isorun", { ts: Time.current }
46
+ ActiveSupport::Notifications.instrument "stats.isorun", Isorun.stats
47
+
48
+ html
49
+ end
50
+
51
+ html = if ssr_html.present?
52
+ tag.div id: id do
53
+ ssr_html.html_safe # rubocop:disable Rails/OutputSafety
54
+ end
55
+ else
56
+ Rails.logger.warn("[ISORUN] The server-side rendered result is empty.")
57
+ ""
58
+ end
59
+
60
+ html += "\n"
61
+ case extension
62
+ when "js", "jsx"
63
+ html += vite_javascript_tag("#{id}.#{extension}")
64
+ when "ts", "tsx"
65
+ html += vite_typescript_tag("#{id}.#{extension}")
66
+ else
67
+ Rails.logger.warn("[ISORUN] unsupported client application extension: `#{extension}`")
68
+ end
69
+ html.html_safe # rubocop:disable Rails/OutputSafety
70
+ end
71
+ end
72
+ end
@@ -1,26 +1,26 @@
1
1
  [package]
2
2
  name = "isorun"
3
- version = "0.1.8"
3
+ version = "0.1.9"
4
4
  edition = "2021"
5
5
  authors = ["Hannes Moser <box@hannesmoser.at>"]
6
6
  homepage = "https://github.com/eliias/isorun"
7
7
  repository = "https://github.com/eliias/isorun"
8
8
 
9
9
  [dependencies]
10
- deno_console = "0.83.0"
11
- deno_core = "0.165.0"
12
- deno_fetch = "0.107.0"
13
- deno_runtime = "0.91.0"
14
- deno_url = "0.83.0"
15
- deno_web = "0.114.0"
16
- deno_webidl = "0.83.0"
10
+ deno_console = "0.86.0"
11
+ deno_core = "0.168.0"
12
+ deno_fetch = "0.110.0"
13
+ deno_runtime = "0.94.0"
14
+ deno_url = "0.86.0"
15
+ deno_web = "0.117.0"
16
+ deno_webidl = "0.86.0"
17
17
  lazy_static = "1.4.0"
18
- magnus = { git = "https://github.com/eliias/magnus", rev = "5220756ca0ab4f2bc32d38310c26f7dda2be9bd6" }
18
+ magnus = { git = "https://github.com/eliias/magnus", rev = "75e2ba89d12af8c51d2bbbb137da2eac3fc966e3" }
19
19
  tokio = { version = "1.21.1", features = ["full"] }
20
- v8 = "0.60.0"
20
+ v8 = "0.60.1"
21
21
 
22
22
  [dev-dependencies]
23
- magnus = { git = "https://github.com/eliias/magnus", rev = "5220756ca0ab4f2bc32d38310c26f7dda2be9bd6", features = ["embed"] }
23
+ magnus = { git = "https://github.com/eliias/magnus", rev = "75e2ba89d12af8c51d2bbbb137da2eac3fc966e3", features = ["embed"] }
24
24
 
25
25
  [lib]
26
26
  name = "isorun"
@@ -3,7 +3,7 @@ use deno_core::error::AnyError;
3
3
  use deno_core::serde_v8::from_v8;
4
4
  use deno_core::{op, serde_v8, Extension, FsModuleLoader, JsRealm, ModuleId};
5
5
  use deno_runtime::deno_broadcast_channel::InMemoryBroadcastChannel;
6
- use deno_runtime::permissions::Permissions;
6
+ use deno_runtime::permissions::PermissionsContainer;
7
7
  use deno_runtime::worker::{MainWorker, WorkerOptions};
8
8
  use deno_runtime::BootstrapOptions;
9
9
  use deno_web::BlobStore;
@@ -207,7 +207,7 @@ impl Default for Worker {
207
207
  todo!("Web workers are not supported in the example");
208
208
  });
209
209
 
210
- let extension_send = Extension::builder()
210
+ let extension_send = Extension::builder("isorun")
211
211
  .ops(vec![op_send_to_ruby::decl()])
212
212
  .build();
213
213
  let mut extensions = vec![extension_send];
@@ -263,7 +263,7 @@ impl Default for Worker {
263
263
 
264
264
  let main_module =
265
265
  deno_core::resolve_path(&js_path.to_string_lossy()).unwrap();
266
- let permissions = Permissions::allow_all();
266
+ let permissions = PermissionsContainer::allow_all();
267
267
  let mut worker = MainWorker::bootstrap_from_options(
268
268
  main_module.clone(),
269
269
  permissions,
@@ -10,6 +10,10 @@ module Isorun
10
10
  end
11
11
  }
12
12
 
13
+ SSR_VITE_APP_RESOLVER = lambda { |_bundle_id|
14
+ Rails.public_path.join("vite-ssr/ssr.js").to_s
15
+ }
16
+
13
17
  SIMPLE_RESOLVER = lambda { |bundle_id|
14
18
  if Rails.env.development?
15
19
  Rails.root.join("app", "assets", "builds", "#{bundle_id}.js").to_s
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Isorun
4
- VERSION = "0.1.8"
4
+ VERSION = "0.1.9"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isorun
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hannes Moser
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-13 00:00:00.000000000 Z
11
+ date: 2023-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -24,6 +24,7 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 6.0.0
27
+ force_ruby_platform: false
27
28
  - !ruby/object:Gem::Dependency
28
29
  name: rake
29
30
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +39,7 @@ dependencies:
38
39
  - - "~>"
39
40
  - !ruby/object:Gem::Version
40
41
  version: '13.0'
42
+ force_ruby_platform: false
41
43
  - !ruby/object:Gem::Dependency
42
44
  name: rb_sys
43
45
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +54,7 @@ dependencies:
52
54
  - - "~>"
53
55
  - !ruby/object:Gem::Version
54
56
  version: 0.9.46
57
+ force_ruby_platform: false
55
58
  - !ruby/object:Gem::Dependency
56
59
  name: rails
57
60
  requirement: !ruby/object:Gem::Requirement
@@ -154,6 +157,7 @@ files:
154
157
  - README.md
155
158
  - Rakefile
156
159
  - app/helpers/isorun/app_helper.rb
160
+ - app/helpers/isorun/vite_app_helper.rb
157
161
  - ext/isorun/Cargo.lock
158
162
  - ext/isorun/Cargo.toml
159
163
  - ext/isorun/extconf.rb
@@ -189,7 +193,7 @@ metadata:
189
193
  changelog_uri: https://github.com/eliias/isorun
190
194
  documentation_uri: https://eliias.github.io/isorun
191
195
  rubygems_mfa_required: 'true'
192
- post_install_message:
196
+ post_install_message:
193
197
  rdoc_options: []
194
198
  require_paths:
195
199
  - lib
@@ -204,8 +208,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
204
208
  - !ruby/object:Gem::Version
205
209
  version: '0'
206
210
  requirements: []
207
- rubygems_version: 3.3.22
208
- signing_key:
211
+ rubygems_version: 3.4.4
212
+ signing_key:
209
213
  specification_version: 4
210
214
  summary: Run JavaScript applications in your Rails application.
211
215
  test_files: []