turbo-hmr 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/javascript/turbo-hmr.js +15 -6
- data/lib/turbo/hmr/engine.rb +2 -2
- data/lib/turbo/hmr/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d78f1140f5ff9dacba63f4e12179411e37d791be3f77d06e9fed0541e5aa6c56
|
|
4
|
+
data.tar.gz: accaeef06f24858b22805398c543818caae5630cf4116ec307ee9f24b5a027b7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6ef0326372951be494683776e414502f9bb922fa7c67832bc5fd422cdd5caa793c6f3c723d51845e9468a51833145bd45ec9c07776867c74adaaa98ff4a99849
|
|
7
|
+
data.tar.gz: e635500967145ec77204b73eb575326c657e0a6e7558162befe8d75f638026b99c3bb8770abb3e44c0a96da602b4b50955764e2db4b946452c12c970a469a659
|
data/app/javascript/turbo-hmr.js
CHANGED
|
@@ -8,7 +8,7 @@ class TurboHmr {
|
|
|
8
8
|
|
|
9
9
|
start(application) {
|
|
10
10
|
this.application = application
|
|
11
|
-
this.currentImportmap = this.
|
|
11
|
+
this.currentImportmap = this.extractImportmapFromDoc(document)
|
|
12
12
|
|
|
13
13
|
document.addEventListener("turbo:before-fetch-response", this.handleBeforeFetchResponse.bind(this))
|
|
14
14
|
document.addEventListener("turbo:before-render", this.handleBeforeRender.bind(this))
|
|
@@ -17,9 +17,7 @@ class TurboHmr {
|
|
|
17
17
|
async handleBeforeFetchResponse(event) {
|
|
18
18
|
const response = event.detail.fetchResponse
|
|
19
19
|
const html = await response.responseHTML
|
|
20
|
-
|
|
21
|
-
const doc = parser.parseFromString(html, "text/html")
|
|
22
|
-
this.pendingImportmap = this.extractImportmap(doc)
|
|
20
|
+
this.pendingImportmap = this.extractImportmapFromHtml(html)
|
|
23
21
|
}
|
|
24
22
|
|
|
25
23
|
handleBeforeRender(event) {
|
|
@@ -63,12 +61,23 @@ class TurboHmr {
|
|
|
63
61
|
}
|
|
64
62
|
}
|
|
65
63
|
|
|
66
|
-
|
|
64
|
+
extractImportmapFromDoc(doc) {
|
|
67
65
|
const importmapScript = doc.querySelector('script[type="importmap"]')
|
|
68
66
|
if (!importmapScript) return null
|
|
67
|
+
return this.parseImportmap(importmapScript.textContent)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
extractImportmapFromHtml(html) {
|
|
71
|
+
// Avoid DOMParser: parsing HTML with inline style="..." attributes triggers
|
|
72
|
+
// style-src CSP violations in Firefox. Extract the importmap <script> content via regex.
|
|
73
|
+
const match = html.match(/<script[^>]*\btype\s*=\s*["']importmap["'][^>]*>([\s\S]*?)<\/script>/i)
|
|
74
|
+
if (!match) return null
|
|
75
|
+
return this.parseImportmap(match[1])
|
|
76
|
+
}
|
|
69
77
|
|
|
78
|
+
parseImportmap(text) {
|
|
70
79
|
try {
|
|
71
|
-
return JSON.parse(
|
|
80
|
+
return JSON.parse(text)
|
|
72
81
|
} catch (e) {
|
|
73
82
|
console.error("turbo-hmr: Failed to parse importmap", e)
|
|
74
83
|
return null
|
data/lib/turbo/hmr/engine.rb
CHANGED
|
@@ -11,8 +11,8 @@ module Turbo
|
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
initializer "turbo_hmr.importmap_helper" do
|
|
14
|
-
ActiveSupport.on_load(:
|
|
15
|
-
helper Turbo::Hmr::ImportmapHelper
|
|
14
|
+
ActiveSupport.on_load(:action_controller) do
|
|
15
|
+
ActionController::Base.helper Turbo::Hmr::ImportmapHelper
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
end
|
data/lib/turbo/hmr/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: turbo-hmr
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 0.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Micah Geisel
|
|
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
91
91
|
- !ruby/object:Gem::Version
|
|
92
92
|
version: '0'
|
|
93
93
|
requirements: []
|
|
94
|
-
rubygems_version:
|
|
94
|
+
rubygems_version: 4.0.6
|
|
95
95
|
specification_version: 4
|
|
96
96
|
summary: Hot Module Replacement for Turbo
|
|
97
97
|
test_files: []
|