bridgetown-lit-renderer 1.0.0 → 2.0.0.beta1

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: 0b433fc8ed4d01b4ffb96f041a894f48443331dcec6b9d95a892e2c302090642
4
- data.tar.gz: c9cdc7615999205a2b559ba20d1b0da57aa80c10469ee39a96edc1fa7d7b3301
3
+ metadata.gz: d79a4e35e5a22651e3072ad4cbc1b9d257fa455db19bcc74ce53de0083681700
4
+ data.tar.gz: 476e74d005b73dea3a92b648f2d9ef11a786b9401c0399462efc550f471f8ead
5
5
  SHA512:
6
- metadata.gz: 802f0cb11030c562403b66caf8748450c0e69fd1ec1aa2da6ffbb22be1e9b01801e340e398ea1ce674f2b3f56f252627cb47f30f5efccf05afa478ae873bfe28
7
- data.tar.gz: 54d46e263d8b89aca439f8bdd54e512fe27abed9e523a86dfaf1912d88d8e99d90907f3609b05c865ed578de6f347a77fb2f311d861082a7073c0f47908ce4a2
6
+ metadata.gz: a63d2c1a1e4954e59681999f218cf3170cbc994861861dbf883c511a9a0be569f6be080f64933d612bb0b84c46794a49e16ee416136d7167eadd4efc84b1ff21
7
+ data.tar.gz: ca21d55e857d7571e12800927779110d1b98b9a986019c1ba7d96984d112037321fed0a44a3f6c11f7292c948404b9a94b0fb9c0e22a56347ded2603f112468c
@@ -0,0 +1,31 @@
1
+ name: CI Test
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - "*"
7
+ push:
8
+ branches:
9
+ - main
10
+
11
+ jobs:
12
+ test:
13
+ runs-on: ubuntu-latest
14
+ env:
15
+ BUNDLE_JOBS: 4
16
+ BUNDLE_PATH: "vendor/bundle"
17
+ steps:
18
+ - uses: actions/checkout@v2
19
+ - name: Set up Ruby and Yarn
20
+ uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: "3.0"
23
+ bundler-cache: true
24
+ - uses: actions/setup-node@v2
25
+ with:
26
+ node-version: '15'
27
+ cache: 'yarn'
28
+ - name: Install NPM packages
29
+ run: yarn install
30
+ - name: Run tests
31
+ run: script/test # should be cibuild but Rubocop is acting weird
data/.rubocop.yml CHANGED
@@ -4,19 +4,8 @@ inherit_gem:
4
4
  rubocop-bridgetown: .rubocop.yml
5
5
 
6
6
  AllCops:
7
- TargetRubyVersion: 2.5
8
- Include:
9
- - lib/**/*.rb
10
- - test/**/*.rb
7
+ TargetRubyVersion: 2.7
11
8
 
12
9
  Exclude:
13
- - .gitignore
14
- - .rubocop.yml
15
-
16
- - Gemfile.lock
17
- - CHANGELOG.md
18
- - LICENSE.txt
19
- - README.md
20
-
21
- - script/**/*
22
- - vendor/**/*
10
+ - "*.gemspec"
11
+ - test/helper.rb
data/CHANGELOG.md CHANGED
@@ -5,10 +5,20 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
- ## Unreleased
8
+ ## [Unreleased]
9
9
 
10
- - ...
10
+ ## [2.0.0.beta1] - 2022-05-14
11
11
 
12
- ## 1.0.0 - 2021-09-25
12
+ - Various updates to the configuration flow, enhanced helper syntax, and a more robust sidecar infra
13
+
14
+ ## [1.1.0] - 2021-12-03
15
+
16
+ - Fix issue with loading project root's node_modules path
17
+
18
+ ## [1.1.0] - 2021-12-03
19
+
20
+ - Switch to processing SSR through Node sidecar server and various other performance & caching enhancements
21
+
22
+ ## [1.0.0] - 2021-09-25
13
23
 
14
24
  - First release (currently experimental stage).
data/Gemfile CHANGED
@@ -10,3 +10,5 @@ group :test do
10
10
  gem "minitest-reporters"
11
11
  gem "shoulda"
12
12
  end
13
+
14
+ gem "solargraph", "~> 0.44.2", group: :development
data/README.md CHANGED
@@ -1,36 +1,80 @@
1
1
  # Bridgetown Lit Renderer
2
2
 
3
- Simple pipeline for SSR + hydration of Lit components in your Bridgetown site.
3
+ [![lit][lit]][lit-url]
4
+ [![gem][gem]][gem-url]
5
+ [![npm][npm]][npm-url]
6
+ [![Demo Site](https://img.shields.io/badge/Demo%20Site-teal?style=for-the-badge&logo=safari)](https://bridgetown-lit-renderer.onrender.com)
7
+
8
+ This [Bridgetown](https://www.bridgetownrb.com) plugin provides you with an easy-to-use pipeline for SSR + hydration of Lit components. Create "islands" of interactivity using Lit-based web components which are fully supported in all major browsers, and take full advantage of scoped component styling via the shadow DOM.
9
+
10
+ [Check out the demo site repo](https://github.com/bridgetownrb/lit-renderer-example), or keep reading to get started.
4
11
 
5
12
  ## Installation
6
13
 
7
- Run this command to add this plugin to your site's Gemfile, along with Lit 2 and Lit's SSR support:
14
+ Starting in Bridgetown v1.1, you can install this plugin via a bundled configuration:
15
+
16
+ ```shell
17
+ $ bin/bridgetown configure lit
18
+ ```
19
+
20
+ Keep reading for a manual installation overview, or [skip this section](#take-lit-for-a-spin) to continue reading about plugin usage.
21
+
22
+ Run this command to add this plugin to your site's Gemfile, along with Lit and SSR support:
8
23
 
9
24
  ```shell
10
25
  $ bundle add bridgetown-lit-renderer -g bridgetown_plugins
11
26
 
12
- $ yarn add lit @lit-labs/ssr
27
+ $ yarn add bridgetown-lit-renderer lit @lit-labs/ssr
13
28
  ```
14
29
 
15
30
  Create a file in `config/lit-ssr.config.js` with the following:
16
31
 
17
32
  ```js
18
33
  const build = require("bridgetown-lit-renderer/build")
34
+ const { plugins } = require("./esbuild-plugins.js")
19
35
 
20
- // You can customize this as you wish, perhaps add new esbuild plugins
21
- const esbuildOptions = {}
36
+ const esbuildOptions = { plugins }
22
37
 
23
38
  build(esbuildOptions)
24
39
  ```
25
40
 
26
- Add the following to the top of your `frontend/javascript/index.js` file:
41
+ and `config/esbuild-plugins.js`:
42
+
43
+ ```js
44
+ // You can add esbuild plugins here you wish to share between the frontend bundles and Lit SSR:
45
+ module.exports = {
46
+ plugins: []
47
+ }
48
+ ```
49
+
50
+ and if you're using esbuild for your Bridgetown site, modify `esbuild.config.js``:
51
+
52
+ ```js
53
+ // at the top of your file:
54
+ const { plugins } = require("./config/esbuild-plugins.js")
55
+
56
+ const esbuildOptions = {
57
+ // other options
58
+
59
+ plugins: [...plugins]
60
+ }
61
+ ```
62
+
63
+ To ensure all `.lit.js`/`.lit.js.rb` files in your `src/_components` are automatically made available to the Lit SSR process, create the following `config/lit-components-entry.js` file:
64
+
65
+ ```js
66
+ import components from "bridgetownComponents/**/*.{lit.js,lit.js.rb}"
67
+ ```
68
+
69
+ Now add the following to the top of your `frontend/javascript/index.js` file:
27
70
 
28
71
  ```js
29
72
  import "bridgetown-lit-renderer"
30
- import "./lit-components"
31
73
  ```
32
74
 
33
- For the purposes of testing your install, add the following to `frontend/javascript/lit-components.js`:
75
+ ### Take Lit for a Spin
76
+
77
+ For the purposes of testing your install, create the `src/_components/happy-days.lit.js` file:
34
78
 
35
79
  ```js
36
80
  import "lit/experimental-hydrate-support.js"
@@ -41,9 +85,8 @@ export class HappyDaysElement extends LitElement {
41
85
  :host {
42
86
  display: block;
43
87
  border: 2px dashed gray;
44
- margin: 4px;
45
- padding: 4px;
46
- width: 20vw;
88
+ padding: 20px;
89
+ max-width: 300px;
47
90
  }
48
91
  `
49
92
 
@@ -61,21 +104,114 @@ export class HappyDaysElement extends LitElement {
61
104
  customElements.define('happy-days', HappyDaysElement)
62
105
  ```
63
106
 
64
- Finally, create a new `.erb` page somewhere in `src`, and add this somewhere in your template:
107
+ Finally, create a new `.erb` page somewhere in `src`, and add this to your template:
65
108
 
66
109
  ```erb
67
- <%= lit data: {hello: "there"} do %>
68
- <happy-days hello="${data.hello}"></happy-days>
69
- <% end %>
110
+ <%= lit :happy_days, hello: "there" %>
70
111
  ```
71
112
 
113
+ (The helper will know how to convert the tag name and attribute keywords to HTML output.)
114
+
72
115
  Now start up your Bridgetown site, visit the page, and if all goes well, you should see a box containing "Hello there!" and a timestamp when the page was first rendered.
73
116
 
74
- You can reload the page several times and see that the timestamp doesn't change, because Lit's SSR + Hydration support knows not to re-render the component. However, if you change the `hello` attribute in the HTML, you'll get a re-render and thus see a new timestamp. _How cool is that?!_
117
+ You can reload the page several times and see that the timestamp doesn't change, because Lit's SSR + Hydration support knows not to re-render the component. However, if you change the `hello` attribute, you'll get a re-render and thus see a new timestamp. _How cool is that?!_
118
+
119
+ ### Lit Helper Options
120
+
121
+ The `lit` helper works in any Ruby template language and let's you pass data down to the Lit SSR build process. Any value that's not alreadey a string will be converted to JSON (via Ruby's `to_json`). You can use a symbol or string for the tag name and underscores are automatically converted to dashes.
75
122
 
76
- ### Configuration options
123
+ ```erb
124
+ <%= lit :page_header, title: resource.data.title %>
125
+ ```
126
+
127
+ (Remember, all custom elements always must have at least one dash within the HTML.)
77
128
 
78
-
129
+ If you pass a block to `lit`, it will add that additional HTML into the Lit template output:
130
+
131
+ ```erb
132
+ <%= lit :ui_sidebar do %>
133
+ <h2 slot="title">Nice Sidebar</h2>
134
+ <% end %>
135
+ ```
136
+
137
+ You can also pass page/resource front matter and other data along via the `data` keyword, which then can be used in the block. In addition, if a tag name isn't present, you can add it yourself in within the block.
138
+
139
+ ```erb
140
+ <%= lit data: resource.data do %>
141
+ <page-header>
142
+ <h1>${data.title}</h1>
143
+ </page-header>
144
+ <% end %>
145
+ ```
146
+
147
+ When the component is hydrated, it will utilize the same data that was passed at build time and avoid a client-side re-render. However, from that point forward you're free to mutate component attribute/properties to trigger re-renders as normal. [Check out Lit's `firstUpdated` method](https://lit.dev/docs/components/lifecycle/#reactive-update-cycle-completing) as a good place to start.
148
+
149
+ You also have the option of choosing a different entry point (aka your JS file that contains or imports one or more Lit components). The default is `./config/lit-components-entry.js`, but you can specify any other file you wish (the path should be relative to your project root).
150
+
151
+ ```erb
152
+ <%= lit data: resource.data, entry: "./frontend/javascript/components/headers.js" do %>
153
+ <page-header title="${data.title}"></page-header>
154
+ <% end %>
155
+ ```
156
+
157
+ This would typically coincide with a strategy of having multiple esbuild/Webpack entry points, and loading different entry points on different parts of your site. An exercise left for the reader…
158
+
159
+ ### Sidecar CSS Files
160
+
161
+ The "default" manner in which you author styles in Lit components is to use `css` tagged template literals (as you saw in the `happy-days` example above). However, some people prefer authoring styles in dedicated CSS files.
162
+
163
+ The [esbuild-plugin-lit-css](https://github.com/bennypowers/lit-css/tree/main/packages/esbuild-plugin-lit-css) plugin allows you to author perfectly vanilla CSS files alongside your component files and import them.
164
+
165
+ In order to separate the "globally-accessible" stylesheets you may have in `src/_components` from the Lit component-specific stylesheets (which we only want to get instantiated within component shadow roots), we'll use the following file conventions:
166
+
167
+ * For global stylesheets, use a `.global.css` suffix.
168
+ * For Lit component stylesheets, use a `.lit.css` suffix.
169
+
170
+ If you used Bridgetown v1.1 or later's Lit bundled configuration, this is already installed and configured for you. Otherwise, you'll need to do just a bit of manual setup to get things working.
171
+
172
+ TBD
173
+
174
+ ### Technical and Performance Considerations
175
+
176
+ The Bridgetown Lit render helper works by compiling your entry point together with your code block via esbuild and caching the resulting JS snippet. A second pass combines your `data` with the snippet and executes it via a temporary "sidecar" Node server which utilizes Lit's SSR rendering pipeline.
177
+
178
+ This for performance reasons. If you have added a Lit template to a layout used by, say, a thousand products, your first build will indeed execute Lit SSR for those thousand products, but thereafter it will be cached. If you change the data for one product, such as a price, Lit SSR will reexecute _only_ for that one product. In addition, for a data-only change the previously compiled JS snippet via esbuild _won't_ need to be recompiled. Of course if you also modify either the HTML markup within the helper block or the entry point itself, recompilation must take place.
179
+
180
+ It's also recommended you don't include any Ruby template code _within_ the helper code block (e.g., using `<%= %>` tags) which results in constantly changing output, as that would necessitate recompiling with esbuild on a regular basis.
181
+
182
+ In v2.0 of this plugin, we only persist these caches during the build process and then the cache is cleared. To cache in a way which persists on-disk for use across builds, you can add `enable_lit_caching: true` to your Bridgetown config. For instance, if you're mainly working on content or other aspects of the site and not directly modifying Lit component code, you'll gain back some build performance by enabling full caching.
183
+
184
+ In summary—with a bit of careful planning of which entry point(s) you create, the data you provide, and the structure of your HTML markup within the `lit` helper, you can achieve good Lit SSR performance while still taking full advantage of the Ruby templates and components you know and love.
185
+
186
+ **A note about Lit templates:** in case you're wondering, the markup within the `lit` helper is actually executed inside Lit's `html` tagged template literal, and [all the usual rules of Lit templates apply](https://lit.dev/docs/templates/overview/). It's recommended you keep the markup within the helper block brief, and let the web component itself do most of the heavy lifting.
187
+
188
+ **Use only one root element.** Because of how the provided `hydrate-root` element works, which will wrap your markup in each `lit` code block, you should only have _one_ root element, and it should be a Lit component. For example, instead of doing this:
189
+
190
+ ```erb
191
+ <%= lit do %>
192
+ <div>
193
+ <h2>Hmm...</h2>
194
+ <my-component>This doesn't seem right.</my-component>
195
+ </div>
196
+ <p>Huh.</p>
197
+ <% end %>
198
+ ```
199
+
200
+ you should be doing this:
201
+
202
+ ```erb
203
+ <%= lit do %>
204
+ <wrapper-component>
205
+ <div>
206
+ <h2>Hmm...</h2>
207
+ <my-component>This doesn't seem right.</my-component>
208
+ </div>
209
+ <p>Huh.</p>
210
+ </wrapper-component>
211
+ <% end %>
212
+ ```
213
+
214
+ **Disabling hydration?** If for some reason you can't permit a `hydrate-root` element to wrap a Lit code block, you can pass a `hydrate_root: false` argument to the `lit` helper. This breaks hydration however, and likewise the [Declarative Shadow DOM (DSD)](https://web.dev/declarative-shadow-dom/) polyfill won't be loaded. (Currently DSD is only supported natively in Chromium-based browsers such as Chrome, Edge, and Brave.) It will thus be up to you to manage those features as you see fit.
79
215
 
80
216
  ## Testing
81
217
 
@@ -90,3 +226,10 @@ You can reload the page several times and see that the timestamp doesn't change,
90
226
  4. Commit your changes (`git commit -am 'Add some feature'`)
91
227
  5. Push to the branch (`git push origin my-new-feature`)
92
228
  6. Create a new Pull Request
229
+
230
+ [lit]: https://img.shields.io/badge/-Lit-324FFF?style=for-the-badge&logo=lit&logoColor=white"
231
+ [lit-url]: https://lit.dev
232
+ [gem]: https://img.shields.io/gem/v/bridgetown-lit-renderer.svg?style=for-the-badge&color=red
233
+ [gem-url]: https://rubygems.org/gems/bridgetown-lit-renderer
234
+ [npm]: https://img.shields.io/npm/v/bridgetown-lit-renderer.svg?style=for-the-badge
235
+ [npm-url]: https://npmjs.com/package/bridgetown-lit-renderer
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rake/testtask"
3
5
 
@@ -8,4 +10,4 @@ Rake::TestTask.new(:test) do |t|
8
10
  t.warning = false
9
11
  end
10
12
 
11
- task :default => :test
13
+ task default: :test
@@ -11,16 +11,20 @@ Gem::Specification.new do |spec|
11
11
  spec.homepage = "https://github.com/bridgetownrb/bridgetown-lit-renderer"
12
12
  spec.license = "MIT"
13
13
 
14
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test|script|spec|features|frontend)/!) }
14
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
15
+ f.match(%r!^(test|script|spec|features|frontend)/!)
16
+ end
15
17
  spec.test_files = spec.files.grep(%r!^test/!)
16
18
  spec.require_paths = ["lib"]
17
- spec.metadata = { "yarn-add" => "bridgetown-lit-renderer@#{BridgetownLitRenderer::VERSION}" }
19
+ spec.metadata = { "yarn-add" => "bridgetown-lit-renderer@#{BridgetownLitRenderer::VERSION}",
20
+ "rubygems_mfa_required" => "true", }
18
21
 
19
- spec.required_ruby_version = ">= 2.5.0"
22
+ spec.required_ruby_version = ">= 2.7.0"
20
23
 
21
- spec.add_dependency "bridgetown", ">= 0.15", "< 2.0"
24
+ spec.add_dependency "bridgetown", ">= 1.0", "< 2.0"
25
+ spec.add_dependency "random-port", ">= 0.5"
22
26
 
23
27
  spec.add_development_dependency "bundler"
24
- spec.add_development_dependency "rake", "~> 12.0"
25
- spec.add_development_dependency "rubocop-bridgetown", "~> 0.2"
28
+ spec.add_development_dependency "rake", "~> 13.0"
29
+ spec.add_development_dependency "rubocop-bridgetown", "~> 0.3"
26
30
  end
@@ -1,89 +1,75 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BridgetownLitRenderer
4
- module Renderer
5
- def self.reset_cache
6
- @code_cache = {}
7
- @lit_notice_printed = false
8
- end
4
+ class Builder < Bridgetown::Builder
5
+ def build # rubocop:todo Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
6
+ BridgetownLitRenderer::Renderer.instance.site = site
7
+ BridgetownLitRenderer::Renderer.instance.reset
9
8
 
10
- def self.esbuild(code, site)
11
- unless @lit_notice_printed
12
- Bridgetown.logger.info "Lit SSR:", "Bundling with esbuild..."
13
- @lit_notice_printed = true
9
+ hook :site, :post_read do
10
+ BridgetownLitRenderer::Renderer.instance.cache.clear unless site.config.enable_lit_caching
14
11
  end
15
12
 
16
- IO.popen(["node", site.in_root_dir("./config/lit-ssr.config.js")], "r+") do |pipe|
17
- pipe.puts({ code: code }.to_json)
18
- pipe.close_write
19
- pipe.read
13
+ hook :site, :post_render do
14
+ BridgetownLitRenderer::Renderer.stop_node_server
20
15
  end
21
- end
22
-
23
- def self.render(code, data:, entry:, site:) # rubocop:disable Metrics/MethodLength
24
- @code_cache ||= {}
25
- cache_key = "#{code}#{entry}"
26
-
27
- unless @code_cache[cache_key]
28
- build_code = <<~JS
29
- import { Readable } from "stream"
30
- import { render } from "@lit-labs/ssr/lib/render-with-global-dom-shim.js"
31
- import { html } from "lit"
32
- import #{entry.to_json}
33
16
 
34
- const ssrResult = render(html`
35
- #{code}
36
- `);
37
-
38
- const _tmplStream = Readable.from(ssrResult)
39
-
40
- let _tmplOutput = ""
41
- _tmplStream.on('data', function(chunk) {
42
- _tmplOutput += chunk;
43
- });
44
-
45
- _tmplStream.on('end',function() {
46
- process.stdout.write("====== SSR ======") // marker to ensure stray console outputs don't end up in HTML
47
- process.stdout.write(_tmplOutput)
48
- });
49
- JS
50
-
51
- @code_cache[cache_key] = esbuild(build_code, site)
17
+ hook :site, :server_shutdown do
18
+ BridgetownLitRenderer::Renderer.stop_node_server
52
19
  end
53
20
 
54
- IO.popen(["node"], "r+") do |pipe|
55
- pipe.puts "const data = #{data.to_json}; #{@code_cache[cache_key]}"
56
- pipe.close_write
57
- pipe.read
58
- end.partition("====== SSR ======").last.html_safe
59
- end
60
- end
21
+ process_tag = ->(tag, attributes, code) do
22
+ valid_tag = tag.to_s.tr("_", "-")
23
+ segments = ["<#{valid_tag}"]
24
+ attributes.each do |attr, _|
25
+ attr = attr.to_s.tr("_", "-")
26
+ segments << %( #{attr}="${data.#{attr}}")
27
+ end
28
+ segments << ">"
29
+ segments << code
30
+ segments << "</#{valid_tag}>"
31
+ segments.join
32
+ end
61
33
 
62
- class Builder < Bridgetown::Builder
63
- def self.cache
64
- @cache ||= Bridgetown::Cache.new("LitSSR")
65
- end
34
+ jsonify_data = ->(data) do
35
+ data.to_h do |k, v|
36
+ processed_value = case v
37
+ when String
38
+ v
39
+ else
40
+ v.to_json
41
+ end
42
+ [k, processed_value]
43
+ end
44
+ end
66
45
 
67
- def build
68
- BridgetownLitRenderer::Renderer.reset_cache
69
- helper "lit", helpers_scope: true do |
46
+ helper "lit", helpers_scope: true do | # rubocop:todo Metrics/ParameterLists
47
+ tag = nil,
70
48
  data: {},
71
49
  hydrate_root: true,
72
- entry: "./frontend/javascript/lit-components.js",
50
+ entry: "./config/lit-components-entry.js",
51
+ **kwargs,
73
52
  &block
74
53
  |
75
- code = view.capture(&block)
76
- if hydrate_root
77
- code = "<hydrate-root>#{code.sub(%r{\<([a-zA-Z]+-[a-zA-Z-]*)}, "<\\1 defer-hydration")}</hydrate-root>" # rubocop:disable Layout/LineLength
78
- end
54
+ code = block ? view.capture(&block) : ""
55
+ code = process_tag.(tag, kwargs, code) if tag
79
56
 
80
- if site.config.disable_lit_caching
81
- next BridgetownLitRenderer::Renderer.render(code, data: data, entry: entry, site: site)
57
+ if hydrate_root
58
+ code = "<hydrate-root>#{code.sub(%r{<([a-zA-Z]+-[a-zA-Z-]*)}, "<\\1 defer-hydration")}</hydrate-root>" # rubocop:disable Layout/LineLength
82
59
  end
83
60
 
84
- entry_key = entry.start_with?("./") ? File.stat(site.in_root_dir(entry)).mtime : entry
85
- BridgetownLitRenderer::Builder.cache.getset("#{code}#{data}#{entry_key}") do
86
- BridgetownLitRenderer::Renderer.render(code, data: data, entry: entry, site: site)
61
+ data = data.merge(kwargs)
62
+ data = jsonify_data.(data)
63
+
64
+ entry_key = BridgetownLitRenderer::Renderer.instance.entry_key(entry)
65
+ BridgetownLitRenderer::Renderer.instance.cache.getset(
66
+ "output-#{code}#{data}#{entry_key}"
67
+ ) do
68
+ BridgetownLitRenderer::Renderer.instance.render(
69
+ code,
70
+ data: data,
71
+ entry: entry
72
+ )
87
73
  end
88
74
  end
89
75
  end
@@ -0,0 +1,129 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "random-port"
4
+ require "singleton"
5
+
6
+ module BridgetownLitRenderer
7
+ class Renderer
8
+ include Singleton
9
+
10
+ class << self
11
+ attr_accessor :serverpid, :serverport, :authtoken
12
+ end
13
+
14
+ attr_accessor :site
15
+
16
+ def self.start_node_server(node_modules_path)
17
+ return if serverpid
18
+
19
+ self.authtoken = SecureRandom.hex(64)
20
+ self.serverport = RandomPort::Pool.new.acquire
21
+
22
+ self.serverpid = spawn(
23
+ {
24
+ "LIT_SSR_SERVER_PORT" => serverport.to_s,
25
+ "LIT_SSR_AUTH_TOKEN" => authtoken,
26
+ "NODE_PATH" => node_modules_path,
27
+ },
28
+ "node #{File.expand_path("../../src/serve.js", __dir__)}",
29
+ pgroup: true
30
+ )
31
+ Process.detach serverpid
32
+ sleep 0.5
33
+ end
34
+
35
+ def self.stop_node_server
36
+ return unless serverpid
37
+
38
+ Process.kill("SIGTERM", -Process.getpgid(serverpid))
39
+ self.serverpid = nil
40
+ self.serverport = nil
41
+ rescue Errno::ESRCH, Errno::EPERM, Errno::ECHILD # rubocop:disable Lint/SuppressedException
42
+ end
43
+
44
+ def entry_key(entry)
45
+ entry.start_with?("./") ? File.stat(site.in_root_dir(entry)).mtime : entry
46
+ end
47
+
48
+ def reset
49
+ @esbuild_notice_printed = false
50
+ @render_notice_printed = false
51
+ end
52
+
53
+ def cache
54
+ @cache ||= Bridgetown::Cache.new("LitSSR")
55
+ end
56
+
57
+ def call_http_server(payload)
58
+ Faraday.post(
59
+ "http://127.0.0.1:#{self.class.serverport}",
60
+ payload,
61
+ "Authorization" => "Bearer #{self.class.authtoken}"
62
+ ).body.force_encoding("utf-8")
63
+ end
64
+
65
+ def esbuild(code)
66
+ raise "You must first assign the `site' accessor" unless site
67
+
68
+ unless @esbuild_notice_printed
69
+ Bridgetown.logger.info "Lit SSR:", "Bundling with esbuild..."
70
+ @esbuild_notice_printed = true
71
+ end
72
+
73
+ # TODO: shouldn't this use the sidecar Node process as well?
74
+ IO.popen(["node", site.in_root_dir("./config/lit-ssr.config.js")], "r+") do |pipe|
75
+ pipe.puts({ code: code }.to_json)
76
+ pipe.close_write
77
+ pipe.read
78
+ end
79
+ end
80
+
81
+ def render(code, data:, entry:)
82
+ raise "You must first assign the `site' accessor" unless site
83
+
84
+ cache_key = "esbuild-#{code}#{entry}#{entry_key(entry)}"
85
+
86
+ built_code = cache.getset(cache_key) { esbuild(js_code_block(entry, code)) }
87
+
88
+ unless @render_notice_printed
89
+ Bridgetown.logger.info "Lit SSR:", "Rendering components..."
90
+ @render_notice_printed = true
91
+ end
92
+
93
+ self.class.start_node_server(site.in_root_dir("node_modules"))
94
+
95
+ output = call_http_server("const data = #{data.to_json}; #{built_code}")
96
+
97
+ if output == "SCRIPT NOT VALID!"
98
+ output = <<~HTML
99
+ <ssr-error style="display:block; padding:0.3em 0.5em; color:white; background:maroon; font-weight:bold">
100
+ Lit SSR error in #{entry}, see logs
101
+ </ssr-error>
102
+ HTML
103
+ cache.delete(cache_key)
104
+ end
105
+
106
+ output.html_safe
107
+ end
108
+
109
+ def js_code_block(entry, code)
110
+ entry_import = "import #{entry.to_json}"
111
+ <<~JS
112
+ import { render } from "@lit-labs/ssr/lib/render-with-global-dom-shim.js"
113
+ import { html } from "lit"
114
+ #{entry_import}
115
+
116
+ const ssrResult = render(html`
117
+ #{code}
118
+ `);
119
+
120
+ let ret = []
121
+ for (const chunk of ssrResult) {
122
+ ret.push(chunk)
123
+ }
124
+
125
+ ret.join("")
126
+ JS
127
+ end
128
+ end
129
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BridgetownLitRenderer
4
- VERSION = "1.0.0"
4
+ VERSION = "2.0.0.beta1"
5
5
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bridgetown"
4
+ require "bridgetown-lit-renderer/renderer"
4
5
  require "bridgetown-lit-renderer/builder"
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bridgetown-lit-renderer",
3
- "version": "1.0.0",
3
+ "version": "2.0.0.beta1",
4
4
  "main": "frontend/javascript/index.js",
5
5
  "exports": {
6
6
  ".": {
@@ -26,6 +26,12 @@
26
26
  ],
27
27
  "dependencies": {
28
28
  "@webcomponents/template-shadowroot": "^0.1.0",
29
- "esbuild": "^0.12"
29
+ "colors": "^1.4.0",
30
+ "esbuild": "^0.14",
31
+ "glob": "^7.2.0"
32
+ },
33
+ "devDependencies": {
34
+ "@lit-labs/ssr": "^2.1.0",
35
+ "lit": "^2.2.3"
30
36
  }
31
37
  }
data/src/build.js CHANGED
@@ -1,4 +1,50 @@
1
1
  const path = require("path")
2
+ const glob = require("glob")
3
+
4
+ // Glob plugin derived from:
5
+ // https://github.com/thomaschaaf/esbuild-plugin-import-glob
6
+ // https://github.com/xiaohui-zhangxh/jsbundling-rails/commit/b15025dcc20f664b2b0eb238915991afdbc7cb58
7
+ const importGlobPlugin = () => ({
8
+ name: "import-glob",
9
+ setup: (build) => {
10
+ build.onResolve({ filter: /\*/ }, async (args) => {
11
+ if (args.resolveDir === "") {
12
+ return; // Ignore unresolvable paths
13
+ }
14
+
15
+ const adjustedPath = args.path.replace(/^bridgetownComponents\//, "../src/_components/")
16
+
17
+ return {
18
+ path: adjustedPath,
19
+ namespace: "import-glob",
20
+ pluginData: {
21
+ path: adjustedPath,
22
+ resolveDir: args.resolveDir,
23
+ },
24
+ }
25
+ })
26
+
27
+ build.onLoad({ filter: /.*/, namespace: "import-glob" }, async (args) => {
28
+ const files = glob.sync(args.pluginData.path, {
29
+ cwd: args.pluginData.resolveDir,
30
+ }).sort()
31
+
32
+ const importerCode = `
33
+ ${files
34
+ .map((module, index) => `import * as module${index} from '${module}'`)
35
+ .join(';')}
36
+ const modules = {${files
37
+ .map((module, index) => `
38
+ "${module.replace("../src/_components/", "")}": module${index},`)
39
+ .join("")}
40
+ };
41
+ export default modules;
42
+ `
43
+
44
+ return { contents: importerCode, resolveDir: args.pluginData.resolveDir }
45
+ })
46
+ },
47
+ })
2
48
 
3
49
  module.exports = (esbuildOptions) => {
4
50
  let inputData = [];
@@ -13,6 +59,9 @@ module.exports = (esbuildOptions) => {
13
59
  process.stdin.on('end', () => {
14
60
  const inputValues = JSON.parse(inputData.join())
15
61
 
62
+ esbuildOptions.plugins = esbuildOptions.plugins || []
63
+ esbuildOptions.plugins.unshift(importGlobPlugin())
64
+
16
65
  require('esbuild').build({
17
66
  ...esbuildOptions,
18
67
  stdin: {
@@ -21,7 +70,7 @@ module.exports = (esbuildOptions) => {
21
70
  sourcefile: 'lit-ssr-output.js' // imaginary file
22
71
  },
23
72
  platform: "node",
24
- inject: [path.join(__dirname, "import-meta-url-shim.js")],
73
+ inject: [path.join(__dirname, "server", "import-meta-url-shim.js")],
25
74
  define: { "import.meta.url": "import_meta_url" },
26
75
  bundle: true,
27
76
  write: false,
data/src/serve.js ADDED
@@ -0,0 +1,30 @@
1
+ const http = require("http")
2
+ const litexec = require("./server/ssr_exec")
3
+
4
+ const server = http.createServer((req, res) => {
5
+ if (req.method === "POST" && req.headers.authorization?.endsWith(process.env.LIT_SSR_AUTH_TOKEN)) {
6
+ let body = ""
7
+ req.on("data", (chunk) => {
8
+ body += chunk.toString()
9
+ });
10
+ req.on("end", () => {
11
+ let ret = "";
12
+ try {
13
+ ret = litexec.execScript(body)
14
+ } catch (e) {
15
+ console.warn(e);
16
+ }
17
+ if (ret) {
18
+ res.end(ret.toString())
19
+ } else {
20
+ res.end("SCRIPT NOT VALID!")
21
+ }
22
+ })
23
+ } else {
24
+ res.statusCode = 400
25
+ res.end("Invalid Request!")
26
+ }
27
+ })
28
+
29
+ const port = process.env.LIT_SSR_SERVER_PORT
30
+ server.listen(port, "127.0.0.1")
@@ -0,0 +1,30 @@
1
+ const colors = require("colors/safe")
2
+
3
+ const originalConsoleLog = console.log
4
+
5
+ console.log = function () {
6
+ args = []
7
+ args.push(colors.rainbow("[LitSSR]"))
8
+ // Note: arguments is part of the prototype
9
+ for (let i = 0; i < arguments.length; i++) {
10
+ args.push(arguments[i])
11
+ }
12
+ originalConsoleLog.apply(console, args)
13
+ }
14
+
15
+ module.exports = {
16
+ execScript(str) {
17
+ const vm = require("vm")
18
+ const contextObject = {
19
+ require: require,
20
+ console: console,
21
+ process: process,
22
+ global: global,
23
+ URL: URL,
24
+ Buffer: Buffer,
25
+ __filename: "__lit_eval.js",
26
+ }
27
+
28
+ return vm.runInNewContext(str, contextObject)
29
+ },
30
+ }
data/yarn.lock CHANGED
@@ -2,12 +2,341 @@
2
2
  # yarn lockfile v1
3
3
 
4
4
 
5
+ "@lit-labs/ssr-client@^1.0.0":
6
+ version "1.0.1"
7
+ resolved "https://registry.yarnpkg.com/@lit-labs/ssr-client/-/ssr-client-1.0.1.tgz#b97e121184aa201bbe6f165f3a7dc919f67129a2"
8
+ integrity sha512-rr/UVhxbKWNUr+3qRyvZk+glC7v7ph8Gk/W0z96YG64COJKf9ilnWY6JGW77TRqhrRMmS2nsvAXOyQgcF+4jrA==
9
+ dependencies:
10
+ "@lit/reactive-element" "^1.0.0"
11
+ lit "^2.0.0"
12
+ lit-html "^2.0.0"
13
+
14
+ "@lit-labs/ssr@^2.1.0":
15
+ version "2.1.0"
16
+ resolved "https://registry.yarnpkg.com/@lit-labs/ssr/-/ssr-2.1.0.tgz#28de42723a9d7224d5e9ab53c420ae102502a033"
17
+ integrity sha512-Tnz/S99G57QKQkI+5QhpfOyVxdHM/IbSa3DZmbF5aeIugivONjurHOuMn6AHzzgdteae3ihcGV2eehKPJuG4/w==
18
+ dependencies:
19
+ "@lit-labs/ssr-client" "^1.0.0"
20
+ "@lit/reactive-element" "^1.1.0"
21
+ "@types/node" "^16.0.0"
22
+ lit "^2.1.0"
23
+ lit-element "^3.1.0"
24
+ lit-html "^2.1.0"
25
+ node-fetch "^2.6.0"
26
+ parse5 "^6.0.1"
27
+ resolve "^1.10.1"
28
+
29
+ "@lit/reactive-element@^1.0.0", "@lit/reactive-element@^1.1.0", "@lit/reactive-element@^1.3.0":
30
+ version "1.3.2"
31
+ resolved "https://registry.yarnpkg.com/@lit/reactive-element/-/reactive-element-1.3.2.tgz#43e470537b6ec2c23510c07812616d5aa27a17cd"
32
+ integrity sha512-A2e18XzPMrIh35nhIdE4uoqRzoIpEU5vZYuQN4S3Ee1zkGdYC27DP12pewbw/RLgPHzaE4kx/YqxMzebOpm0dA==
33
+
34
+ "@types/node@^16.0.0":
35
+ version "16.11.35"
36
+ resolved "https://registry.yarnpkg.com/@types/node/-/node-16.11.35.tgz#6642bdce5b5cee23314b91a7c069981c6bd68791"
37
+ integrity sha512-QXu45LyepgnhUfnIAj/FyT4uM87ug5KpIrgXfQtUPNAlx8w5hmd8z8emqCLNvG11QkpRSCG9Qg2buMxvqfjfsQ==
38
+
39
+ "@types/trusted-types@^2.0.2":
40
+ version "2.0.2"
41
+ resolved "https://registry.yarnpkg.com/@types/trusted-types/-/trusted-types-2.0.2.tgz#fc25ad9943bcac11cceb8168db4f275e0e72e756"
42
+ integrity sha512-F5DIZ36YVLE+PN+Zwws4kJogq47hNgX3Nx6WyDJ3kcplxyke3XIzB8uK5n/Lpm1HBsbGzd6nmGehL8cPekP+Tg==
43
+
5
44
  "@webcomponents/template-shadowroot@^0.1.0":
6
45
  version "0.1.0"
7
46
  resolved "https://registry.yarnpkg.com/@webcomponents/template-shadowroot/-/template-shadowroot-0.1.0.tgz#adb3438d0d9a18e8fced08abc253f56b7eadab00"
8
47
  integrity sha512-ry84Vft6xtRBbd4M/ptRodbOLodV5AD15TYhyRghCRgIcJJKmYmJ2v2BaaWxygENwh6Uq3zTfGPmlckKT/GXsQ==
9
48
 
10
- esbuild@^0.12:
11
- version "0.12.29"
12
- resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.12.29.tgz#be602db7c4dc78944a9dbde0d1ea19d36c1f882d"
13
- integrity sha512-w/XuoBCSwepyiZtIRsKsetiLDUVGPVw1E/R3VTFSecIy8UR7Cq3SOtwKHJMFoVqqVG36aGkzh4e8BvpO1Fdc7g==
49
+ balanced-match@^1.0.0:
50
+ version "1.0.2"
51
+ resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
52
+ integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==
53
+
54
+ brace-expansion@^1.1.7:
55
+ version "1.1.11"
56
+ resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
57
+ integrity sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==
58
+ dependencies:
59
+ balanced-match "^1.0.0"
60
+ concat-map "0.0.1"
61
+
62
+ colors@^1.4.0:
63
+ version "1.4.0"
64
+ resolved "https://registry.yarnpkg.com/colors/-/colors-1.4.0.tgz#c50491479d4c1bdaed2c9ced32cf7c7dc2360f78"
65
+ integrity sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==
66
+
67
+ concat-map@0.0.1:
68
+ version "0.0.1"
69
+ resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
70
+ integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=
71
+
72
+ esbuild-android-64@0.14.39:
73
+ version "0.14.39"
74
+ resolved "https://registry.yarnpkg.com/esbuild-android-64/-/esbuild-android-64-0.14.39.tgz#09f12a372eed9743fd77ff6d889ac14f7b340c21"
75
+ integrity sha512-EJOu04p9WgZk0UoKTqLId9VnIsotmI/Z98EXrKURGb3LPNunkeffqQIkjS2cAvidh+OK5uVrXaIP229zK6GvhQ==
76
+
77
+ esbuild-android-arm64@0.14.39:
78
+ version "0.14.39"
79
+ resolved "https://registry.yarnpkg.com/esbuild-android-arm64/-/esbuild-android-arm64-0.14.39.tgz#f608d00ea03fe26f3b1ab92a30f99220390f3071"
80
+ integrity sha512-+twajJqO7n3MrCz9e+2lVOnFplRsaGRwsq1KL/uOy7xK7QdRSprRQcObGDeDZUZsacD5gUkk6OiHiYp6RzU3CA==
81
+
82
+ esbuild-darwin-64@0.14.39:
83
+ version "0.14.39"
84
+ resolved "https://registry.yarnpkg.com/esbuild-darwin-64/-/esbuild-darwin-64-0.14.39.tgz#31528daa75b4c9317721ede344195163fae3e041"
85
+ integrity sha512-ImT6eUw3kcGcHoUxEcdBpi6LfTRWaV6+qf32iYYAfwOeV+XaQ/Xp5XQIBiijLeo+LpGci9M0FVec09nUw41a5g==
86
+
87
+ esbuild-darwin-arm64@0.14.39:
88
+ version "0.14.39"
89
+ resolved "https://registry.yarnpkg.com/esbuild-darwin-arm64/-/esbuild-darwin-arm64-0.14.39.tgz#247f770d86d90a215fa194f24f90e30a0bd97245"
90
+ integrity sha512-/fcQ5UhE05OiT+bW5v7/up1bDsnvaRZPJxXwzXsMRrr7rZqPa85vayrD723oWMT64dhrgWeA3FIneF8yER0XTw==
91
+
92
+ esbuild-freebsd-64@0.14.39:
93
+ version "0.14.39"
94
+ resolved "https://registry.yarnpkg.com/esbuild-freebsd-64/-/esbuild-freebsd-64-0.14.39.tgz#479414d294905055eb396ebe455ed42213284ee0"
95
+ integrity sha512-oMNH8lJI4wtgN5oxuFP7BQ22vgB/e3Tl5Woehcd6i2r6F3TszpCnNl8wo2d/KvyQ4zvLvCWAlRciumhQg88+kQ==
96
+
97
+ esbuild-freebsd-arm64@0.14.39:
98
+ version "0.14.39"
99
+ resolved "https://registry.yarnpkg.com/esbuild-freebsd-arm64/-/esbuild-freebsd-arm64-0.14.39.tgz#cedeb10357c88533615921ae767a67dc870a474c"
100
+ integrity sha512-1GHK7kwk57ukY2yI4ILWKJXaxfr+8HcM/r/JKCGCPziIVlL+Wi7RbJ2OzMcTKZ1HpvEqCTBT/J6cO4ZEwW4Ypg==
101
+
102
+ esbuild-linux-32@0.14.39:
103
+ version "0.14.39"
104
+ resolved "https://registry.yarnpkg.com/esbuild-linux-32/-/esbuild-linux-32-0.14.39.tgz#d9f008c4322d771f3958f59c1eee5a05cdf92485"
105
+ integrity sha512-g97Sbb6g4zfRLIxHgW2pc393DjnkTRMeq3N1rmjDUABxpx8SjocK4jLen+/mq55G46eE2TA0MkJ4R3SpKMu7dg==
106
+
107
+ esbuild-linux-64@0.14.39:
108
+ version "0.14.39"
109
+ resolved "https://registry.yarnpkg.com/esbuild-linux-64/-/esbuild-linux-64-0.14.39.tgz#ba58d7f66858913aeb1ab5c6bde1bbd824731795"
110
+ integrity sha512-4tcgFDYWdI+UbNMGlua9u1Zhu0N5R6u9tl5WOM8aVnNX143JZoBZLpCuUr5lCKhnD0SCO+5gUyMfupGrHtfggQ==
111
+
112
+ esbuild-linux-arm64@0.14.39:
113
+ version "0.14.39"
114
+ resolved "https://registry.yarnpkg.com/esbuild-linux-arm64/-/esbuild-linux-arm64-0.14.39.tgz#708785a30072702b5b1c16b65cf9c25c51202529"
115
+ integrity sha512-23pc8MlD2D6Px1mV8GMglZlKgwgNKAO8gsgsLLcXWSs9lQsCYkIlMo/2Ycfo5JrDIbLdwgP8D2vpfH2KcBqrDQ==
116
+
117
+ esbuild-linux-arm@0.14.39:
118
+ version "0.14.39"
119
+ resolved "https://registry.yarnpkg.com/esbuild-linux-arm/-/esbuild-linux-arm-0.14.39.tgz#4e8b5deaa7ab60d0d28fab131244ef82b40684f4"
120
+ integrity sha512-t0Hn1kWVx5UpCzAJkKRfHeYOLyFnXwYynIkK54/h3tbMweGI7dj400D1k0Vvtj2u1P+JTRT9tx3AjtLEMmfVBQ==
121
+
122
+ esbuild-linux-mips64le@0.14.39:
123
+ version "0.14.39"
124
+ resolved "https://registry.yarnpkg.com/esbuild-linux-mips64le/-/esbuild-linux-mips64le-0.14.39.tgz#6f3bf3023f711084e5a1e8190487d2020f39f0f7"
125
+ integrity sha512-epwlYgVdbmkuRr5n4es3B+yDI0I2e/nxhKejT9H0OLxFAlMkeQZxSpxATpDc9m8NqRci6Kwyb/SfmD1koG2Zuw==
126
+
127
+ esbuild-linux-ppc64le@0.14.39:
128
+ version "0.14.39"
129
+ resolved "https://registry.yarnpkg.com/esbuild-linux-ppc64le/-/esbuild-linux-ppc64le-0.14.39.tgz#900e718a4ea3f6aedde8424828eeefdd4b48d4b9"
130
+ integrity sha512-W/5ezaq+rQiQBThIjLMNjsuhPHg+ApVAdTz2LvcuesZFMsJoQAW2hutoyg47XxpWi7aEjJGrkS26qCJKhRn3QQ==
131
+
132
+ esbuild-linux-riscv64@0.14.39:
133
+ version "0.14.39"
134
+ resolved "https://registry.yarnpkg.com/esbuild-linux-riscv64/-/esbuild-linux-riscv64-0.14.39.tgz#dcbff622fa37047a75d2ff7a1d8d2949d80277e4"
135
+ integrity sha512-IS48xeokcCTKeQIOke2O0t9t14HPvwnZcy+5baG13Z1wxs9ZrC5ig5ypEQQh4QMKxURD5TpCLHw2W42CLuVZaA==
136
+
137
+ esbuild-linux-s390x@0.14.39:
138
+ version "0.14.39"
139
+ resolved "https://registry.yarnpkg.com/esbuild-linux-s390x/-/esbuild-linux-s390x-0.14.39.tgz#3f725a7945b419406c99d93744b28552561dcdfd"
140
+ integrity sha512-zEfunpqR8sMomqXhNTFEKDs+ik7HC01m3M60MsEjZOqaywHu5e5682fMsqOlZbesEAAaO9aAtRBsU7CHnSZWyA==
141
+
142
+ esbuild-netbsd-64@0.14.39:
143
+ version "0.14.39"
144
+ resolved "https://registry.yarnpkg.com/esbuild-netbsd-64/-/esbuild-netbsd-64-0.14.39.tgz#e10e40b6a765798b90d4eb85901cc85c8b7ff85e"
145
+ integrity sha512-Uo2suJBSIlrZCe4E0k75VDIFJWfZy+bOV6ih3T4MVMRJh1lHJ2UyGoaX4bOxomYN3t+IakHPyEoln1+qJ1qYaA==
146
+
147
+ esbuild-openbsd-64@0.14.39:
148
+ version "0.14.39"
149
+ resolved "https://registry.yarnpkg.com/esbuild-openbsd-64/-/esbuild-openbsd-64-0.14.39.tgz#935ec143f75ce10bd9cdb1c87fee00287eb0edbc"
150
+ integrity sha512-secQU+EpgUPpYjJe3OecoeGKVvRMLeKUxSMGHnK+aK5uQM3n1FPXNJzyz1LHFOo0WOyw+uoCxBYdM4O10oaCAA==
151
+
152
+ esbuild-sunos-64@0.14.39:
153
+ version "0.14.39"
154
+ resolved "https://registry.yarnpkg.com/esbuild-sunos-64/-/esbuild-sunos-64-0.14.39.tgz#0e7aa82b022a2e6d55b0646738b2582c2d72c3c0"
155
+ integrity sha512-qHq0t5gePEDm2nqZLb+35p/qkaXVS7oIe32R0ECh2HOdiXXkj/1uQI9IRogGqKkK+QjDG+DhwiUw7QoHur/Rwg==
156
+
157
+ esbuild-windows-32@0.14.39:
158
+ version "0.14.39"
159
+ resolved "https://registry.yarnpkg.com/esbuild-windows-32/-/esbuild-windows-32-0.14.39.tgz#3f1538241f31b538545f4b5841b248cac260fa35"
160
+ integrity sha512-XPjwp2OgtEX0JnOlTgT6E5txbRp6Uw54Isorm3CwOtloJazeIWXuiwK0ONJBVb/CGbiCpS7iP2UahGgd2p1x+Q==
161
+
162
+ esbuild-windows-64@0.14.39:
163
+ version "0.14.39"
164
+ resolved "https://registry.yarnpkg.com/esbuild-windows-64/-/esbuild-windows-64-0.14.39.tgz#b100c59f96d3c2da2e796e42fee4900d755d3e03"
165
+ integrity sha512-E2wm+5FwCcLpKsBHRw28bSYQw0Ikxb7zIMxw3OPAkiaQhLVr3dnVO8DofmbWhhf6b97bWzg37iSZ45ZDpLw7Ow==
166
+
167
+ esbuild-windows-arm64@0.14.39:
168
+ version "0.14.39"
169
+ resolved "https://registry.yarnpkg.com/esbuild-windows-arm64/-/esbuild-windows-arm64-0.14.39.tgz#00268517e665b33c89778d61f144e4256b39f631"
170
+ integrity sha512-sBZQz5D+Gd0EQ09tZRnz/PpVdLwvp/ufMtJ1iDFYddDaPpZXKqPyaxfYBLs3ueiaksQ26GGa7sci0OqFzNs7KA==
171
+
172
+ esbuild@^0.14:
173
+ version "0.14.39"
174
+ resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.14.39.tgz#c926b2259fe6f6d3a94f528fb42e103c5a6d909a"
175
+ integrity sha512-2kKujuzvRWYtwvNjYDY444LQIA3TyJhJIX3Yo4+qkFlDDtGlSicWgeHVJqMUP/2sSfH10PGwfsj+O2ro1m10xQ==
176
+ optionalDependencies:
177
+ esbuild-android-64 "0.14.39"
178
+ esbuild-android-arm64 "0.14.39"
179
+ esbuild-darwin-64 "0.14.39"
180
+ esbuild-darwin-arm64 "0.14.39"
181
+ esbuild-freebsd-64 "0.14.39"
182
+ esbuild-freebsd-arm64 "0.14.39"
183
+ esbuild-linux-32 "0.14.39"
184
+ esbuild-linux-64 "0.14.39"
185
+ esbuild-linux-arm "0.14.39"
186
+ esbuild-linux-arm64 "0.14.39"
187
+ esbuild-linux-mips64le "0.14.39"
188
+ esbuild-linux-ppc64le "0.14.39"
189
+ esbuild-linux-riscv64 "0.14.39"
190
+ esbuild-linux-s390x "0.14.39"
191
+ esbuild-netbsd-64 "0.14.39"
192
+ esbuild-openbsd-64 "0.14.39"
193
+ esbuild-sunos-64 "0.14.39"
194
+ esbuild-windows-32 "0.14.39"
195
+ esbuild-windows-64 "0.14.39"
196
+ esbuild-windows-arm64 "0.14.39"
197
+
198
+ fs.realpath@^1.0.0:
199
+ version "1.0.0"
200
+ resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
201
+ integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8=
202
+
203
+ function-bind@^1.1.1:
204
+ version "1.1.1"
205
+ resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d"
206
+ integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==
207
+
208
+ glob@^7.2.0:
209
+ version "7.2.2"
210
+ resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.2.tgz#29deb38e1ef90f132d5958abe9c3ee8e87f3c318"
211
+ integrity sha512-NzDgHDiJwKYByLrL5lONmQFpK/2G78SMMfo+E9CuGlX4IkvfKDsiQSNPwAYxEy+e6p7ZQ3uslSLlwlJcqezBmQ==
212
+ dependencies:
213
+ fs.realpath "^1.0.0"
214
+ inflight "^1.0.4"
215
+ inherits "2"
216
+ minimatch "^3.1.1"
217
+ once "^1.3.0"
218
+ path-is-absolute "^1.0.0"
219
+
220
+ has@^1.0.3:
221
+ version "1.0.3"
222
+ resolved "https://registry.yarnpkg.com/has/-/has-1.0.3.tgz#722d7cbfc1f6aa8241f16dd814e011e1f41e8796"
223
+ integrity sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==
224
+ dependencies:
225
+ function-bind "^1.1.1"
226
+
227
+ inflight@^1.0.4:
228
+ version "1.0.6"
229
+ resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9"
230
+ integrity sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=
231
+ dependencies:
232
+ once "^1.3.0"
233
+ wrappy "1"
234
+
235
+ inherits@2:
236
+ version "2.0.4"
237
+ resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
238
+ integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
239
+
240
+ is-core-module@^2.8.1:
241
+ version "2.9.0"
242
+ resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.9.0.tgz#e1c34429cd51c6dd9e09e0799e396e27b19a9c69"
243
+ integrity sha512-+5FPy5PnwmO3lvfMb0AsoPaBG+5KHUI0wYFXOtYPnVVVspTFUuMZNfNaNVRt3FZadstu2c8x23vykRW/NBoU6A==
244
+ dependencies:
245
+ has "^1.0.3"
246
+
247
+ lit-element@^3.1.0, lit-element@^3.2.0:
248
+ version "3.2.0"
249
+ resolved "https://registry.yarnpkg.com/lit-element/-/lit-element-3.2.0.tgz#9c981c55dfd9a8f124dc863edb62cc529d434db7"
250
+ integrity sha512-HbE7yt2SnUtg5DCrWt028oaU4D5F4k/1cntAFHTkzY8ZIa8N0Wmu92PxSxucsQSOXlODFrICkQ5x/tEshKi13g==
251
+ dependencies:
252
+ "@lit/reactive-element" "^1.3.0"
253
+ lit-html "^2.2.0"
254
+
255
+ lit-html@^2.0.0, lit-html@^2.1.0, lit-html@^2.2.0:
256
+ version "2.2.3"
257
+ resolved "https://registry.yarnpkg.com/lit-html/-/lit-html-2.2.3.tgz#dcb2744d0f0c1800b2eb2de37bc42384434a74f7"
258
+ integrity sha512-vI4j3eWwtQaR8q/O63juZVliBIFMio716X719/lSsGH4UWPy2/7Qf377jsNs4cx3gCHgIbx8yxFgXFQ/igZyXQ==
259
+ dependencies:
260
+ "@types/trusted-types" "^2.0.2"
261
+
262
+ lit@^2.0.0, lit@^2.1.0, lit@^2.2.3:
263
+ version "2.2.3"
264
+ resolved "https://registry.yarnpkg.com/lit/-/lit-2.2.3.tgz#77203d8f247de7c0d4955817f89e40c927349b9c"
265
+ integrity sha512-5/v+r9dH3Pw/o0rhp/qYk3ERvOUclNF31bWb0FiW6MPgwdQIr+/KCt/p3zcd8aPl8lIGnxdGrVcZA+gWS6oFOQ==
266
+ dependencies:
267
+ "@lit/reactive-element" "^1.3.0"
268
+ lit-element "^3.2.0"
269
+ lit-html "^2.2.0"
270
+
271
+ minimatch@^3.1.1:
272
+ version "3.1.2"
273
+ resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b"
274
+ integrity sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==
275
+ dependencies:
276
+ brace-expansion "^1.1.7"
277
+
278
+ node-fetch@^2.6.0:
279
+ version "2.6.7"
280
+ resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
281
+ integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
282
+ dependencies:
283
+ whatwg-url "^5.0.0"
284
+
285
+ once@^1.3.0:
286
+ version "1.4.0"
287
+ resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
288
+ integrity sha1-WDsap3WWHUsROsF9nFC6753Xa9E=
289
+ dependencies:
290
+ wrappy "1"
291
+
292
+ parse5@^6.0.1:
293
+ version "6.0.1"
294
+ resolved "https://registry.yarnpkg.com/parse5/-/parse5-6.0.1.tgz#e1a1c085c569b3dc08321184f19a39cc27f7c30b"
295
+ integrity sha512-Ofn/CTFzRGTTxwpNEs9PP93gXShHcTq255nzRYSKe8AkVpZY7e1fpmTfOyoIvjP5HG7Z2ZM7VS9PPhQGW2pOpw==
296
+
297
+ path-is-absolute@^1.0.0:
298
+ version "1.0.1"
299
+ resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
300
+ integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18=
301
+
302
+ path-parse@^1.0.7:
303
+ version "1.0.7"
304
+ resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.7.tgz#fbc114b60ca42b30d9daf5858e4bd68bbedb6735"
305
+ integrity sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==
306
+
307
+ resolve@^1.10.1:
308
+ version "1.22.0"
309
+ resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.0.tgz#5e0b8c67c15df57a89bdbabe603a002f21731198"
310
+ integrity sha512-Hhtrw0nLeSrFQ7phPp4OOcVjLPIeMnRlr5mcnVuMe7M/7eBn98A3hmFRLoFo3DLZkivSYwhRUJTyPyWAk56WLw==
311
+ dependencies:
312
+ is-core-module "^2.8.1"
313
+ path-parse "^1.0.7"
314
+ supports-preserve-symlinks-flag "^1.0.0"
315
+
316
+ supports-preserve-symlinks-flag@^1.0.0:
317
+ version "1.0.0"
318
+ resolved "https://registry.yarnpkg.com/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz#6eda4bd344a3c94aea376d4cc31bc77311039e09"
319
+ integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==
320
+
321
+ tr46@~0.0.3:
322
+ version "0.0.3"
323
+ resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
324
+ integrity sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=
325
+
326
+ webidl-conversions@^3.0.0:
327
+ version "3.0.1"
328
+ resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
329
+ integrity sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=
330
+
331
+ whatwg-url@^5.0.0:
332
+ version "5.0.0"
333
+ resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"
334
+ integrity sha1-lmRU6HZUYuN2RNNib2dCzotwll0=
335
+ dependencies:
336
+ tr46 "~0.0.3"
337
+ webidl-conversions "^3.0.0"
338
+
339
+ wrappy@1:
340
+ version "1.0.2"
341
+ resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
342
+ integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bridgetown-lit-renderer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bridgetown Team
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-25 00:00:00.000000000 Z
11
+ date: 2022-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bridgetown
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0.15'
19
+ version: '1.0'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '2.0'
@@ -26,10 +26,24 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '0.15'
29
+ version: '1.0'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '2.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: random-port
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0.5'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0.5'
33
47
  - !ruby/object:Gem::Dependency
34
48
  name: bundler
35
49
  requirement: !ruby/object:Gem::Requirement
@@ -50,34 +64,35 @@ dependencies:
50
64
  requirements:
51
65
  - - "~>"
52
66
  - !ruby/object:Gem::Version
53
- version: '12.0'
67
+ version: '13.0'
54
68
  type: :development
55
69
  prerelease: false
56
70
  version_requirements: !ruby/object:Gem::Requirement
57
71
  requirements:
58
72
  - - "~>"
59
73
  - !ruby/object:Gem::Version
60
- version: '12.0'
74
+ version: '13.0'
61
75
  - !ruby/object:Gem::Dependency
62
76
  name: rubocop-bridgetown
63
77
  requirement: !ruby/object:Gem::Requirement
64
78
  requirements:
65
79
  - - "~>"
66
80
  - !ruby/object:Gem::Version
67
- version: '0.2'
81
+ version: '0.3'
68
82
  type: :development
69
83
  prerelease: false
70
84
  version_requirements: !ruby/object:Gem::Requirement
71
85
  requirements:
72
86
  - - "~>"
73
87
  - !ruby/object:Gem::Version
74
- version: '0.2'
75
- description:
88
+ version: '0.3'
89
+ description:
76
90
  email: maintainers@bridgetownrb.com
77
91
  executables: []
78
92
  extensions: []
79
93
  extra_rdoc_files: []
80
94
  files:
95
+ - ".github/workflows/ci.yml"
81
96
  - ".gitignore"
82
97
  - ".rubocop.yml"
83
98
  - CHANGELOG.md
@@ -88,17 +103,21 @@ files:
88
103
  - bridgetown-lit-renderer.gemspec
89
104
  - lib/bridgetown-lit-renderer.rb
90
105
  - lib/bridgetown-lit-renderer/builder.rb
106
+ - lib/bridgetown-lit-renderer/renderer.rb
91
107
  - lib/bridgetown-lit-renderer/version.rb
92
108
  - package.json
93
109
  - src/build.js
94
- - src/import-meta-url-shim.js
110
+ - src/serve.js
111
+ - src/server/import-meta-url-shim.js
112
+ - src/server/ssr_exec.js
95
113
  - yarn.lock
96
114
  homepage: https://github.com/bridgetownrb/bridgetown-lit-renderer
97
115
  licenses:
98
116
  - MIT
99
117
  metadata:
100
- yarn-add: bridgetown-lit-renderer@1.0.0
101
- post_install_message:
118
+ yarn-add: bridgetown-lit-renderer@2.0.0.beta1
119
+ rubygems_mfa_required: 'true'
120
+ post_install_message:
102
121
  rdoc_options: []
103
122
  require_paths:
104
123
  - lib
@@ -106,15 +125,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
125
  requirements:
107
126
  - - ">="
108
127
  - !ruby/object:Gem::Version
109
- version: 2.5.0
128
+ version: 2.7.0
110
129
  required_rubygems_version: !ruby/object:Gem::Requirement
111
130
  requirements:
112
- - - ">="
131
+ - - ">"
113
132
  - !ruby/object:Gem::Version
114
- version: '0'
133
+ version: 1.3.1
115
134
  requirements: []
116
- rubygems_version: 3.1.4
117
- signing_key:
135
+ rubygems_version: 3.2.22
136
+ signing_key:
118
137
  specification_version: 4
119
138
  summary: Simple pipeline for SSR + hydration of Lit components
120
139
  test_files: []